
// Replaces a script tag call with an actual link

function onSuccess(data, status){
  data = $.trim(data);
  statMsg = "";
  switch(data){
    case "SUCCESS":
      $("#emailRegisterForm").fadeOut('normal');
      statMsg = "Thank you!";
      break;
    case "SUCCWARNL":
    case "SUCCWARNC":
      $("#emailRegisterForm").fadeOut('normal');
      statMsg = "You already submitted an email";
      break;
    case "EMPTY":
      statMsg = "Please enter an email";
      break;
    case "INVALID":
      statMsg = "Please specify a correct email";
      break;
  }
  $("#emailRegistrationStatusMsg").html(statMsg);
}

function onError(data, status){
  $("#emailRegistrationStatusMsg").html("Please try again");
}        

$(document).ready(function(){
  $("#emailRegisterForm").submit(function(e){
    e.preventDefault();
  });
  
  $("#submitEmailRegisterForm").click(function(){
    
    $("#emailRegistrationStatusMsg").html("Please wait, one moment...");
    var formData = $("#emailRegisterForm").serialize();

    $.ajax({
      type: "POST",
      url: "/iContact/registerUsers.php",
      cache: false,
      timeout: 10000,
      data: formData,
      success: onSuccess,
      error: onError
    });
    return false;
  });
});

