window.document.onkeypress = keypress_action;
function keypress_action(event)
{
  if (!event) event = window.event;
  if (event.which == 13 || event.keyCode == 13 || event.keyCode == 3)
  {
    register();
    return false;
  }
}
function register()
{
   if ((document.forms[1].password.value != document.forms[1].repeat_password.value) || (document.forms[1].password.value.length < 8))
   {
      document.getElementById("error").className = "item_red";
      if (document.forms[1].password.value.length < 8)
      {
         document.getElementById("error").innerHTML = "<h3>Password</h3><p>Your password must be at least 8 characters.</p>"
      }
      else
      {
         document.getElementById("error").innerHTML = "<h3>Password</h3><p>Your passwords do not match.</p>"
      }
   }
   else
   {
      document.getElementById("error").className = "object_invisible";
      tb_show('', '#tb_inline?width=0&height=29&width=424&modal=true&inlineId=process', false);
      document.forms[0].password.value = hex_sha256(hex_sha256(document.getElementsByName("password")[1].value));
      var encryption = new Encryption();
      encryption.create_keypair(document.getElementsByName("password")[1].value);
      document.getElementsByName("password")[1].value = "";
      document.getElementsByName("repeat_password")[0].value = "";
	  document.forms[0].key_public.value = encryption.key_public;
      document.forms[0].key_private.value = encryption.key_private;
      document.register.submit();
   }
}