//
// This is used by all of the ajaxPostABC functions below.
// It re-enables the submit button and removes the spinner class and puts back the normal btn_submit class.
//
// NOTE: This function requires the Prototype.js library
//
function enableSubmitButton(button_id, bEnabled) {
  if (bEnabled == true) {
    $(button_id).removeClassName('btn_submit_spinner').addClassName('btn_submit').enable();
  } else {
    $(button_id).removeClassName('btn_submit').addClassName('btn_submit_spinner').disable();
  }
  return true;
}

//
// This function is used to create a timer for a form that was submitted.
// If the timer fires then we know we've exceeded the maximum allowed time for the
// server to process the request. IE, we never got a response back from the server
// so we need to re-enable the submit button and tell the user so they can submit
// the request again if they want to.
//
function startTimeout(sSubmitButtonID) {
  var timer = new PeriodicalExecuter(function(peObject) {
    enableSubmitButton(sSubmitButtonID, true);
    peObject.stop();
  }, 30);
  return timer;
}


function ajaxPostPokerForm(frmId, sConfirmationDivID, sSubmitButtonID) {
  enableSubmitButton(sSubmitButtonID, false);
  var tmr = startTimeout(sSubmitButtonID);
  $(sConfirmationDivID).hide();

  //Form validation
  if ($F('first_name') == '') { alert("Please input your first name."); $('first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('last_name') == '') { alert("Please input your last name."); $('last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('address1') == '') { alert("Please input your address."); $('address1').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('city') == '') { alert("Please input your city."); $('city').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('state') == '') { alert("Please input your state."); $('state').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('zip') == '') { alert("Please input your zip."); $('zip').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sEmail = $F('email');
  if (sEmail == '') { alert("Please input your email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('phone') == '') { alert("Please input your phone number."); $('phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('poker_security_code') == '') { alert("Please input the Verification Code that's displayed on your screen."); $('poker_security_code').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Submit the form via AJAX
  $(frmId).request ({
    onSuccess: function(transport) {
      tmr.stop(); //Since we got a response we can stop the timeout timer
      if (transport.responseText.trim() == '1') {
        $(sConfirmationDivID).removeClassName('warning_note').addClassName('confirmation_note').update("<p>Thank you for registering. Please complete your registration by making a Paypal payment using the button below.</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
        new PeriodicalExecuter(function(pePokerReg) {
          pePokerReg.stop();
        }, 10);
      } else {
        $(sConfirmationDivID).removeClassName('confirmation_note').addClassName('warning_note').update("<p>" + transport.responseText.trim() + "</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
      }
      enableSubmitButton(sSubmitButtonID, true);
    }
  });
}

function ajaxPostClinicRegistrationForm(frmId, sConfirmationDivID, sSubmitButtonID) {
  enableSubmitButton(sSubmitButtonID, false);
  var tmr = startTimeout(sSubmitButtonID);
  $(sConfirmationDivID).hide();
  $('divError').hide();

  //Form validation
  if ($F('first_name') == '') { alert("Please input your first name."); $('first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('last_name') == '') { alert("Please input your last name."); $('last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('grade') == '') { alert("Please input the player's grade."); $('grade').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('tshirt') == '') { alert("Please input the player's t-shirt size."); $('tshirt').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('address1') == '') { alert("Please input your address."); $('address1').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('city') == '') { alert("Please input your city."); $('city').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('state') == '') { alert("Please input your state."); $('state').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('zip') == '') { alert("Please input your zip."); $('zip').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sEmail = $F('email');
  if (sEmail == '') { alert("Please input your email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('phone') == '') { alert("Please input your phone number."); $('phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

//  if (!$('agree').checked) { alert("You must agree to the outlined terms and conditions."); $('agree').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('clinicreg_security_code') == '') { alert("Please input the Verification Code that's displayed on your screen."); $('clinicreg_security_code').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Submit the form via AJAX
  $(frmId).request ({
    onSuccess: function(transport) {
      tmr.stop(); //Since we got a response we can stop the timeout timer
      if (transport.responseText.trim() == '1') {
        //$(sConfirmationDivID).removeClassName('warning_note').addClassName('confirmation_note').update("<p>Thank you for registering.</p>");
        $(sConfirmationDivID).addClassName('confirmation_note');
        Effect.Appear(sConfirmationDivID, {duration:.5});
        new PeriodicalExecuter(function(peClinicReg) {
          peClinicReg.stop();
        }, 10);
      } else {
        //$(sConfirmationDivID).removeClassName('confirmation_note').addClassName('warning_note').update("<p>" + transport.responseText.trim() + "</p>");
        $('divError').update("<p>" + transport.responseText.trim() + "</p>");
        Effect.Appear('divError', {duration:.5});
        //alert(transport.responseText.trim()); //response contains error text - display it
      }
      enableSubmitButton(sSubmitButtonID, true);
    }
  });
}

function ajaxPostLeagueTeamRegForm(frmId, sConfirmationDivID, sSubmitButtonID) {
  enableSubmitButton(sSubmitButtonID, false);
  var tmr = startTimeout(sSubmitButtonID);
  $(sConfirmationDivID).hide();
  $(sConfirmationDivID+"2").hide();

  //Chaperone validation
  if ($F('team_contact_first_name') == '') { alert("Please input the team chaperone's first name."); $('team_contact_first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('team_contact_last_name') == '') { alert("Please input the team chaperone's last name."); $('team_contact_last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('team_contact_phone') == '') { alert("Please input the team chaperone's phone number."); $('team_contact_phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sEmail = $F('team_contact_email');
  if (sEmail == '') { alert("Please input the team chaperone's email address."); $('team_contact_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('team_contact_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Team Info validation
  if ($F('team_name') == '') { alert("Please input the desired team name."); $('team_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

//  for(var index=1; index<9; index++) {
  for(var index=1; index<7; index++) {
    if ($F('first_name_player_'+index) == '') { alert("Please input player #" + index + "'s first name."); $('first_name_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
    if ($F('last_name_player_'+index) == '') { alert("Please input player #" + index + "'s last name."); $('last_name_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
//    if ($F('grade_player_'+index) == '') { alert("Please input player #" + index + "'s grade in school."); $('grade_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
//    if ($F('tshirt_player_'+index) == '') { alert("Please input player #" + index + "'s tshirt size."); $('tshirt_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
//    if ($F('phone_player_'+index) == '') { alert("Please input player #" + index + "'s phone number."); $('phone_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  }

//  if (!$('agree').checked) { alert("You must agree to the outlined terms and conditions."); $('agree').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('leaguereg_security_code') == '') { alert("Please input the Verification Code that's displayed on your screen."); $('leaguereg_security_code').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Submit the form via AJAX
  $(frmId).request ({
    onSuccess: function(transport) {
      tmr.stop(); //Since we got a response we can stop the timeout timer
      if (transport.responseText == "1") {
        Effect.Appear(sConfirmationDivID, {duration:.5});
        new PeriodicalExecuter(function(peLeagueReg) {
          peLeagueReg.stop();
        }, 10);
      } else {
        $(sConfirmationDivID+"2").removeClassName('confirmation_note').addClassName('warning_note').update("<p>" + transport.responseText.trim() + "</p>");
        Effect.Appear(sConfirmationDivID+"2", {duration:.5});
        alert("Error");
        //alert(transport.responseText.trim()); //response contains error text - display it
      }
      enableSubmitButton(sSubmitButtonID, true);
    }
  });
}

function ajaxPostFastFourLeagueTeamRegForm(frmId, sConfirmationDivID, sSubmitButtonID) {
  enableSubmitButton(sSubmitButtonID, false);
  var tmr = startTimeout(sSubmitButtonID);
  $(sConfirmationDivID).hide();

  //Chaperone validation
  if ($F('team_contact_first_name') == '') { alert("Please input the team chaperone's first name."); $('team_contact_first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('team_contact_last_name') == '') { alert("Please input the team chaperone's last name."); $('team_contact_last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('team_contact_phone') == '') { alert("Please input the team chaperone's phone number."); $('team_contact_phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sEmail = $F('team_contact_email');
  if (sEmail == '') { alert("Please input the team chaperone's email address."); $('team_contact_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('team_contact_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Team Info validation
  if ($F('team_name') == '') { alert("Please input the desired team name."); $('team_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  for(var index=1; index<5; index++) {
    if ($F('first_name_player_'+index) == '') { alert("Please input player #" + index + "'s first name."); $('first_name_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
    if ($F('last_name_player_'+index) == '') { alert("Please input player #" + index + "'s last name."); $('last_name_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
    if ($F('grade_player_'+index) == '') { alert("Please input player #" + index + "'s last name."); $('grade_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
    if ($F('email_player_'+index) !== '') {
      sEmail = $F('email_player_'+index);
      if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('email_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
    }
    if ($F('phone_player_'+index) == '') { alert("Please input player #" + index + "'s phone number."); $('phone_player_'+index).activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  }

//  if (!$('agree').checked) { alert("You must agree to the outlined terms and conditions."); $('agree').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('leaguereg_security_code') == '') { alert("Please input the Verification Code that's displayed on your screen."); $('leaguereg_security_code').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Submit the form via AJAX
  $(frmId).request ({
    onSuccess: function(transport) {
      tmr.stop(); //Since we got a response we can stop the timeout timer
      if (transport.responseText.trim() == '1') {
        $(sConfirmationDivID).removeClassName('warning_note').addClassName('confirmation_note').update("<p>Thank you for registering.</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
      } else {
        $(sConfirmationDivID).removeClassName('confirmation_note').addClassName('warning_note').update("<p>" + transport.responseText.trim() + "</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
        alert("Error");
        //alert(transport.responseText.trim()); //response contains error text - display it
      }
      enableSubmitButton(sSubmitButtonID, true);
    }
  });
}

function ajaxPostFastFourLeagueFreeAgentRegForm(frmId, sConfirmationDivID, sSubmitButtonID) {
  enableSubmitButton(sSubmitButtonID, false);
  var tmr = startTimeout(sSubmitButtonID);
  $(sConfirmationDivID).hide();

  if ($F('first_name') == '') { alert("Please input first name."); $('first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('last_name') == '') { alert("Please input last name."); $('last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('grade') == '') { alert("Please input grade."); $('grade').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('email') == '') { alert("Please input email."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('email') !== '') {
    sEmail = $F('email');
    if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  }
  if ($F('phone') == '') { alert("Please input phone number."); $('phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if (!$('agree').checked) { alert("You must agree to the outlined terms and conditions."); $('agree').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('leaguereg_security_code') == '') { alert("Please input the Verification Code that's displayed on your screen."); $('leaguereg_security_code').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Submit the form via AJAX
  $(frmId).request ({
    onSuccess: function(transport) {
      tmr.stop(); //Since we got a response we can stop the timeout timer
      if (transport.responseText.trim() == '1') {
        $(sConfirmationDivID).removeClassName('warning_note').addClassName('confirmation_note').update("<p>Thank you for registering.</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
      } else {
        $(sConfirmationDivID).removeClassName('confirmation_note').addClassName('warning_note').update("<p>" + transport.responseText.trim() + "</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
        alert("Error");
        //alert(transport.responseText.trim()); //response contains error text - display it
      }
      enableSubmitButton(sSubmitButtonID, true);
    }
  });
}

function ajaxPostCoachAppForm(frmId, sConfirmationDivID, sSubmitButtonID) {
  enableSubmitButton(sSubmitButtonID, false);
  var tmr = startTimeout(sSubmitButtonID);
  $(sConfirmationDivID).hide();

  //Form validation
  if ($F('first_name') == '') { alert("Please input your first name."); $('first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('last_name') == '') { alert("Please input your last name."); $('last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('address1') == '') { alert("Please input your address."); $('address1').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('city') == '') { alert("Please input your city."); $('city').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('state') == '') { alert("Please input your state."); $('state').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('zip') == '') { alert("Please input your zip."); $('zip').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('hm_phone') == '') { alert("Please input your home phone number."); $('hm_phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('cell_phone') == '') { alert("Please input your home cell number."); $('cell_phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sEmail = $F('email');
  if (sEmail == '') { alert("Please input your email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('gender') == '') { alert("Please indicate your gender."); $('gender').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('dob_month') == '') { alert("Please indicate your birth month."); $('dob_month').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('dob_day') == '') { alert("Please indicate your birth day."); $('dob_day').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('dob_year') == '') { alert("Please indicate your birth year."); $('dob_year').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!$('coach_position_head').checked && !$('coach_position_assistant').checked && !$('coach_position_roamer').checked) { alert("You must select at least one position for which you're applying."); $('coach_position_head').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('certification') == '' && $F('certification_other') == '') { alert("Please indicate your certification level."); $('certification').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('coaching_experience') == '') { alert("Please indicate your coaching experience."); $('coaching_experience').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('playing_experience') == '') { alert("Please indicate your playing experience."); $('playing_experience').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('coaching_philosophy') == '') { alert("Please briefly indicate your coaching philosophy."); $('coaching_philosophy').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('ref_1_first_name') == '') { alert("Please input your first reference's first name."); $('ref_1_first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_1_last_name') == '') { alert("Please input your first reference's last name."); $('ref_1_last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_1_organization') == '') { alert("Please input your first reference's organization."); $('ref_1_organization').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_1_relation') == '') { alert("Please input your relation to your first reference."); $('ref_1_relation').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_1_phone') == '') { alert("Please input your first reference's phone number."); $('ref_1_phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sRefOneEmail = $F('ref_1_email');
  if (sRefOneEmail == '') { alert("Please input your first reference's email address."); $('ref_1_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sRefOneEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('ref_1_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('ref_2_first_name') == '') { alert("Please input your second reference's first name."); $('ref_2_first_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_2_last_name') == '') { alert("Please input your second reference's last name."); $('ref_2_last_name').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_2_organization') == '') { alert("Please input your second reference's organization."); $('ref_2_organization').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_2_relation') == '') { alert("Please input your relation to your second reference."); $('ref_2_relation').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if ($F('ref_2_phone') == '') { alert("Please input your second reference's phone number."); $('ref_2_phone').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  var sRefOneEmail = $F('ref_2_email');
  if (sRefOneEmail == '') { alert("Please input your second reference's email address."); $('ref_2_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }
  if (!sRefOneEmail.match(/^\b[A-Z0-9._%+-]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,4}\b$/i)) { alert("Invalid email address."); $('ref_2_email').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  if ($F('coach_app_security_code') == '') { alert("Please input the Verification Code that's displayed on your screen."); $('coach_app_security_code').activate(); enableSubmitButton(sSubmitButtonID, true); tmr.stop(); return false; }

  //Submit the form via AJAX
  $(frmId).request ({
    onSuccess: function(transport) {
      tmr.stop(); //Since we got a response we can stop the timeout timer
      if (transport.responseText.trim() == '1') {
        $(sConfirmationDivID).removeClassName('warning_note').addClassName('confirmation_note').update("<p>Thank you for applying. We'll be getting back to you shortly.</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
        new PeriodicalExecuter(function(peCoachApp) {
          peCoachApp.stop();
        }, 10);
      } else {
        $(sConfirmationDivID).removeClassName('confirmation_note').addClassName('warning_note').update("<p>" + transport.responseText.trim() + "</p>");
        Effect.Appear(sConfirmationDivID, {duration:.5});
        //alert(transport.responseText.trim()); //response contains error text - display it
      }
      enableSubmitButton(sSubmitButtonID, true);
    }
  });
}

