﻿$(document).ready(function() { 

$("#regComplete").click(function() { AsirraValidate(); });
$("#regProceed").click(function() { 

if (ValidateFormInput()) { 

$("#divReg").hide();
$("#divVal").show();

}

});

});

var returnURL = "/";

function DoRegister() { 

$('#buttons').slideUp(500, function() { 
$('#buttons').hide(); 
$('#divRegistration').slideDown(1000);
});
}

function ValidateFormInput() { 
   
 $("#lblMessage").css("font-weight","normal");
 $("#lblMessage").css("color","red");
 
 var name = $("#txtFirstName").val();
 var lname = $("#txtLastName").val();
 
 var email = $("#txtEmail").val();
 var password = $("#txtPasswordReg").val();
 var passconfirm = $("#txtPassConfirm").val();
 
 if ((name == "") || (name.length < 3)) { msg("Please enter your name");$("#txtFirstName").focus();return false; }
 if ((lname == "") || (lname.length < 3)) { msg("Please enter your last name");$("#txtLastName").focus();return false; }
 
 if ((email == "") || (email.length < 3)) { msg("Please enter your e-mail address");$("#txtEmail").focus();return false; }
 if (!isEmailValid(email)) { msg("Invalid e-mail address entered.");$("#txtEmail").focus();return false;   }
 
 if ((password == "") || (password.length < 5)) { msg("Please choose a password.<br />At least 5 characters long.");$("#txtPasswordReg").focus();return false; }
 if ((password == "") || (passconfirm.length < 5)) {msg("Please confirm your password.");$("#txtPassConfirm").focus();return false; }
 if (password != passconfirm) { alert("Your entered password and confirmation field do not match");$("#txtPassConfirm").focus();return false;  }
   
 msg("");
   
 return true;
   
 }
 
function isEmailValid(email) { 
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email)) {return false;} return true;
}
 
 function msg(text) {$("#lblMessage").html(text); }
 function msg2(text) {$("#lblMessage2").html(text); }
 
 function AsirraValidate() { 
  if (passThroughFormSubmit) {
          return true;
     }
     // Do site-specific form validation here, then...
     Asirra_CheckIfHuman(HumanCheckComplete);
     return false;
 }

function DoSignIn() { 
if($('#window').css('display') == 'none') {
$('#windowOpen').TransferTo({to:'window',className:'transferer2', duration: 300, complete: function() { 
$('#window').show();
}});}this.blur();return false;

}

function sLogin(e) { var keycode;var keychar;var numcheck;if(window.event) {keycode = e.keyCode;}else if(e.which) {keycode = e.which;} else { return true; }if (keycode == 13){doLogin();return false;}else return true;}
function redirect(url) { var version = parseInt(navigator.appVersion); if (version>=4 || window.location.replace) { window.location.replace(url); } else { window.location.href = url; }}
function doLogin() { var txtUser = $("#txtuser").val(); var txtPassword = $("#txtpass").val(); 
if ((txtUser.length >= 3) && (txtPassword.length >= 2)) {$('#divsignin').hide();$('#divsigninprocess').show(); $.getIfModified("/authenticate/", { u:txtUser, p: txtPassword }, function(data){if (data != "no_auth") {$.getIfModified("/authenticate/", {at:data},  function(data) { redirect(returnURL);});} else {alert('Could not log-in. \r\n \r\n Invalid e-mail address or password was entered \r\n or your account is not activated. \r\n \r\n Please try again.');$('#txtuser').val('');$('#txtpass').val('');$('#divsignin').show();$('#divsigninprocess').hide(); } });}}

var passThroughFormSubmit = false;

function HumanCheckComplete(isHuman)
{
     if (!isHuman)
     {
          $("#lblMessage2").css("font-weight","bold");
           $("#lblMessage2").css("color","red");
          msg2("Please correctly identify the cats in the box displayed below<br />(click all the cat images to proceed).");
     }
     else
     {
          passThroughFormSubmit = true;
          
          $("#lblMessage2").css("color","green");
          msg2("All right! Now proceeding with registration...");
          
          $.get("/controls/getasirraresponse.aspx", { ticket:$("#Asirra_Ticket").val()}, function(data){
          
          if (data=="Pass") { 

          $.get("/controls/ajaxregister.aspx", { fn:$("#txtFirstName").val(), ln:$("#txtLastName").val(), email:$("#txtEmail").val(), cn: $("#txtCompany").val(), pass:$("#txtPasswordReg").val(), sal:$("#ddlSalutation").val()  }, function(data){
          
          if (data == "ok"){ 
          
        n("/my/");
          
          }  else { 
          $("#lblMessage2").css("font-weight","normal");
          $("#lblMessage2").css("color","red");
          msg2(data);
          }
          
          });
          
          } else { 
           msg("Hmm.. could not validate the cats and dogs<br /> related security ticket at the moment. <br /> Can't proceed with registration right now...<br />Please try again later or contact us at info@xpatloop.com<br />Sorry for the temporary inconvenience...");
          }
     });
}
}

function ShowThankYou() { 

$('#divRegistration').slideUp(500, function() { 
$('#divRegistration').hide(); 
$('#divThankYou').slideDown(1000);
});

}
