// Set email address displays
Domain = 'tsmacademy.org';
LivingAt = '@';
Address11 = '<font face="Times New Roman" size="+1" color="blue"><u>register201' + LivingAt + Domain + '</u></font>';
Address12 = '<font face="Times New Roman" size="+1" color="blue"><u>contact' + LivingAt + Domain + '</u></font>';
Address21 = '<font face="Times New Roman" size="+1" color="blue"><u>register202' + LivingAt + Domain + '</u></font>';
Address22 = '<font face="Times New Roman" size="+1" color="blue"><u>contact' + LivingAt + Domain + '</u></font>';
Address31 = '<font face="Times New Roman" size="+1" color="blue"><u>register203' + LivingAt + Domain + '</u></font>';
Address32 = '<font face="Times New Roman" size="+1" color="blue"><u>contact' + LivingAt + Domain + '</u></font>';
Address41 = '<font face="Times New Roman" size="+1" color="blue"><u>register204' + LivingAt + Domain + '</u></font>';
Address42 = '<font face="Times New Roman" size="+1" color="blue"><u>contact' + LivingAt + Domain + '</u></font>';

// Verify email address -->
function validateEmail() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var em1 = document.FrontPage_Form1.Email.value;
var em2 = document.FrontPage_Form1.Email2.value;
// check for a value in both fields.
if (em1 == '' || em2 == '') {
alert('Please enter your Email address twice.');
document.FrontPage_Form1.Email.select();
return false;
}
// check for minimum length
if (document.FrontPage_Form1.Email.value.length < minLength) {
alert('Your email address must be at least ' + minLength + ' characters long. Try again.');
document.FrontPage_Form1.Email.select();
return false;
}
// check for spaces
if (document.FrontPage_Form1.Email.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
document.FrontPage_Form1.Email.select();
return false;
}
else {
if (em1 != em2) {
alert ("The two email addresses do not match. Please re-enter your email address.");
document.FrontPage_Form1.Email.select();
return false;
}
else {
return true;
      }
   }
}
//  End Email verify


// One Submit -->
function hijackValidator() {
  // loop through all the Forms in the document
  for (i=0; i<document.forms.length; i++) {

/* create a new property of the Form that tracks whether the Form has been submitted*/

   document.forms[i].notSubmittedYet = true;
   if (document.forms[i].onsubmit) {
    var oldHandler = new String(document.forms[i].onsubmit)

/*  oldHandler will be something like this, depending on the browser in use,
*   and the name of the Form:
*
*   "function anonymous() { return FrontPage_Form1_Validator(this); }"
*
*   We need to extract just the "FrontPage_Form1_Validator(this)" part
*/

    //find "Validator"
    var validatorIndex = oldHandler.indexOf("Validator");

    //if "Validator" not found, then abort
    if (validatorIndex<0) return;

    //find space before name of validator function
    var startIndex = oldHandler.lastIndexOf(" ",validatorIndex)

    // if space not found, abort
    if (startIndex<0) return;

    // find final parenthesis
    var endIndex = oldHandler.indexOf(")",validatorIndex);

    //if parenthesis not found, abort
    if (endIndex<0) return;

    // create a String for the name of the validator function,
    // and store it as a new property of the Form
    document.forms[i].oldValidator = new String(oldHandler.slice(startIndex,endIndex+1));

    /* oldValidator is something like this:
    * "FrontPage_Form1_Validator(this);"

    */
   }

   else {  //Form did not have an onSubmit handler previously
   	 document.forms[i].oldValidator = new String("true;");
	}

   //substitute our own onSubmit handler for the one FrontPage created
   document.forms[i].onsubmit = enhancedValidator;

  } //end for

} //end hijackValidator()

function enhancedValidator() {

 /* This is our new validator function.
 * It first calls the FrontPage validator for the Form.
 * If that returns TRUE, it then checks whether the Form
 * has already been submitted.
 * If it has been, we do not submit it again.
 */

 if (eval(this.oldValidator.valueOf())) { // is FrontPage validation successful?

  if (this.notSubmittedYet) {  //did user click Submit already?
   this.notSubmittedYet = false;
   return true; // submit form
  }

  else { // form already submitted; complain to user
   alert("Your Registration form has already been submitted.  Please wait... \nThe Internet traffic is heavy at this time. As soon as things catch up, a confirmation page will appear.");   return false;  // don't submit form
  }

 }

 else { // FrontPage validator found error
  return false;  // don't submit form
 }

} // end enhancedValidator()
//  End Validator

// On Enter key move to next field
nextfield = "First_Name"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) { // handles keypress
// determines whether Netscape or Internet Explorer
k = (netscape) ? DnEvents.which : window.event.keyCode;
if (k == 13) { // enter key pressed
if (nextfield == 'done') return true; // submit, we finished all fields
else { // we're not done yet, send focus to next box
eval('document.FrontPage_Form1.' + nextfield + '.focus()');
return false;
      }
   }
}
document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);
//  End of Next field on enter

