﻿$(function() { 
$("#btnSend").click(function() { DoSend(); });
});

var returnURL = "/";

function DoRegister() { 

$('#buttons').slideUp(500, function() { 
$('#buttons').hide(); 
$('#divRegistration').slideDown(1000);
});
}

function DoSend() {

if (ValidateFormInput()) {
  $(this).attr("disabled", "disabled");
  AsirraValidate();
  
  }

 }
 
 function ValidateFormInput() { 
 
 $("#MessageLabel").css("font-weight","normal");
 $("#MessageLabel").css("color","red");
 
 var subject = $("#txtSubject").val();
 var email = $("#txtEmail").val();
 var message = $("#txtMessage").val();
 
 if ((email == "") || (email.length < 3)) { msg("Please enter your e-mail address so that we can reply to you");$("#txtEmail").focus();return false; }
 if (!isEmailValid(email)) { msg("Please provide us with a valid e-mail address.");$("#txtEmail").focus();return false;   }
 
 if ((subject == "") || (subject.length < 3)) { msg("Please enter a subject line for your message");$("#txtSubject").focus();return false; }
 
 if ((message == "") || (message.length < 5)) { msg("Please enter your message.");$("#txtMessage").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) {
 
 $("#MessageLabel").html(text);
 
  }
 
 function AsirraValidate() { 
  if (passThroughFormSubmit) {
          return true;
     }
     // Do site-specific form validation here, then...
     Asirra_CheckIfHuman(HumanCheckComplete);
     return false;
 }

function redirect(url) { var version = parseInt(navigator.appVersion); if (version>=4 || window.location.replace) { window.location.replace(url); } else { window.location.href = url; }}
var passThroughFormSubmit = false;

function HumanCheckComplete(isHuman)
{
     if (!isHuman)
     {
          $("#MessageLabel").css("font-weight","bold");
          msg("Please correctly identify the cats in the box displayed above<br />Click on all the cat images to proceed...");
     }
     else
     {
          passThroughFormSubmit = true;
          
          $("#MessageLabel").css("color","green");
          msg("Good stuff! Now sending your message...");
          
          $.get("/controls/getasirraresponse.aspx", { ticket:$("#Asirra_Ticket").val()}, function(data){
          
          if (data=="Pass") { 

          var doNewsletterSignup = $("#cbSignup").attr("checked");
          
          $.post("/controls/ajaxsend.aspx", { subject:$("#txtSubject").val(), email:$("#txtEmail").val(), message:$("#txtMessage").val(), ticket:$("#Asirra_Ticket").val()  }, function(data){
          
          if (data == "ok"){ 
          
          //Display thank you message
          ShowThankYou();
          
          }  else { 
          $("#MessageLabel").css("font-weight","normal");
          $("#MessageLabel").css("color","red");
          msg(data);
          }
          
          });
          
          } else { 
           msg("Hmm.. could not validate the cats and dogs related security ticket at the moment. <br /> Can't proceed right now... Please try again later or contact us at support@livesportsdirect.com<br />Sorry for the temporary inconvenience...");
          }
     });
}
}

function ShowThankYou() { 

$('#divContact').slideUp(500, function() { 
$('#divContact').hide(); 
$('#divThankYou').slideDown(1000);
});

}
