// javascript/email_validator-js.jssp


  var emailTestedValid = true;
  
  function isLastTestedEmailValid()
  {
    if (emailTestedValid)
    {
      return true;
    }
    
    return false;
  }

  function displayInvalidEmailAlert()
  {
    alert("The Email address is invalid.\nA correct email format is: username@domain.org with max length 64 for username, 255 for domain name.");
  }
  
  function isFirstResponder() {
    var loc = window.location;
    var path = loc.pathname.substring(0, loc.pathname.lastIndexOf('/'));
    var last = path.substring(path.lastIndexOf('/') + 1);
    if (last == "first_responder")
    {
      return true;
    }
    return false;
  }
  
  function isMedicare() {
    var loc = window.location;
    var path = loc.pathname.substring(0, loc.pathname.lastIndexOf('/'));
    var last = path.substring(path.lastIndexOf('/') + 1);
    if (last == "medicare")
    {
      return true;
    }
    return false;
  }
  
  jQuery(function(){
    $("#emailAddress").focusout(function(){
      var prefix = "";
      if ($("#emailPagePrefix").length > 0)
      {
        prefix = $("#emailPagePrefix").val();
      }
      else if (isFirstResponder() || isMedicare())
      {
        prefix = "../";
      }
      // make the remote call
      handleValidationReply($("#emailAddress").val());
      return false;
    });
  });

  function handleValidationReply(email) {
    if (validateEmailRegex(email)) {
      emailTestedValid = true;
      return;
    }
    // Otherwise we need to alert the user of the error
    emailTestedValid = false;
    displayInvalidEmailAlert();
  }
