<!--
//========================================================================
function ValidateDate(date){
	var aDateElements; //element 1 = year, element 2 = day, element 3 = year
	var ConvertedYear; //Holds year returned by ReturnConvertedYear function
	var isShortDate, myDate, intYear, intMonth;

	isShortDate = false;
	aDateElements = new Array()
	aDateElements = ReturnParsedArray(date, "/", aDateElements)

	if (aDateElements.length < 2){
		alert("You did not specify a valid Date.");
		return false;
	} else {
		if (aDateElements.length < 3){
		isShortDate = true; // it has 2 elements
		} else {
		if (aDateElements.length > 3){
			alert("You did not specify a valid Date.");
			return false;
		} else { // it has 3 elements
			ConvertedYear = ReturnConvertedYear(aDateElements[2]);
			if (isNaN(ConvertedYear)) {
				return false;
			}

			if (parseInt(ConvertedYear) != ConvertedYear
				|| parseInt(aDateElements[0]) != aDateElements[0]
				|| parseInt(aDateElements[1]) != aDateElements[1]) {
				alert ("Please enter a valid date");
				return false;
			}
			
			intYear = ConvertedYear;

			// IMPORTANT - subtract 1 from month, because JScript arrays are zero-based
			myDate = new Date(intYear, parseInt(aDateElements[0]) - 1, parseInt(aDateElements[1]));
			if (myDate.getDate() != parseInt(aDateElements[1])) {
				alert("Please enter a valid date");
				return false;
			} else {
				if (intYear < 1900){
				alert("Please enter a year after 1899.");
				return false;
				} else {
				return true;
				}
			}
		}
		}

		// if you've gotten this far, it's because it's a short date: only month and year.

		intYear = aDateElements[1];

		// check year
		if (InvalidCharacterExists("" + intYear,"1234567890")){
		alert("Date must contain only numbers and slashes '/'");
		return false;
		} else {
		// convert to 4 digit year
		intYear = ReturnConvertedYear(intYear);
		intMonth = aDateElements[0];

		if (InvalidCharacterExists(intMonth,"1234567890")){
			alert("Valid dates must contain only numbers and slashes '/'");
			return false;
		}

		if (InvalidCharacterExists(intYear,"1234567890")){
			alert("Valid dates must contain only numbers and slashes '/'");
			return false;
		}

		if ((intMonth > 12) || (intMonth < 1)){
			alert("Please enter a valid month.");
			return false;
		}

		if ((intYear > 999) && (intYear < 1900)){
			alert("Please enter a year after 1899.");
			return false;
		}
		return true;
		}
	}
}

function BeforeOrAfterToday (validdate) {
	var isShortDate = false;
	var aDate, dtToday = new Date();

	aDate = ReturnParsedArray(validdate, "/", new Array());

	if (aDate.length == 2) {
		isShortDate = true;
		intYear = ReturnConvertedYear(aDate[1]);
		intDay = 1;
	} else	{
		intYear = ReturnConvertedYear(aDate[2]);
		intDay = aDate[1];
	}
	intMonth = aDate[0] - 1;

	date = new Date(intYear, intMonth, intDay);
	dtToday = new Date();
	intYear = dtToday.getYear();
	intMonth = dtToday.getMonth();
	intDay = dtToday.getDate();

	// to compensate for netscape returning the number of years after 1900 for getYear()
	if ((intYear > 99) && (intYear < 1900)) {
		intYear = intYear + 1900;
	}

	today = new Date(intYear, intMonth, intDay);
	if (today.valueOf() < date.valueOf()){
		return "after";
	} else {
		return "before";
	}
}

function ReturnParsedArray(strToParse, strDelimiter, aArray) {
	var boolStillParsing = true;
	var i = 0;

	while(boolStillParsing) {
		intSlashLocation = strToParse.indexOf("/", 0)
		if (intSlashLocation == -1){
		boolStillParsing = false;
		aArray[i] = strToParse;
		} else {
		aArray[i] = strToParse.substring(0, intSlashLocation)
		strToParse = strToParse.substring(intSlashLocation + 1, strToParse.length)
		i = i + 1;
		}
	}
	return aArray;
}

function ReturnConvertedYear(intYear){

	if (parseInt(intYear) != intYear) {
		//Presumably the year has alpha characters, so it is invalid; we can proceed no further.
		return false;
	}
	
	if (intYear > 50){
		if (intYear <= 99){
		intYear = parseInt(intYear) + 1900;
		}
		else{ // > 99
		if (intYear <= 999){ // between 999 and 99
			intYear = parseInt(intYear) + 2000;
		}
		}
	}
	else{
	// <= 50
		intYear = parseInt(intYear) + 2000;
	}
	return intYear;
}
//========================================================================
function ValidateEmail(strEmail) {
	var EmailValue
	var ValidCharacters
	var AmpersandIndexOf
	var SubStringEnd
	var TempChar
	var LastTempChar
	var BlankIndexValue
	var PeriodLastIndexValue
	var AtSignIndexValue

	LastTempChar = "blank"
	EmailValue = strEmail
	ValidCharacters = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890@.-_"
	//InvalidCharacters = "~`!#$%^&*()+="|}{[]\"":;'?><,/"
	AtSignIndexValue = EmailValue.indexOf("@")
	PeriodLastIndexValue = EmailValue.lastIndexOf(".")
	BlankIndexValue = EmailValue.indexOf(" ")
	// this checks if there is at least one blank character.
	if (BlankIndexValue != -1) {
		alert("An email address cannot contain blanks.");
		return (false);
	}
	// this checks if there is at least one "@" and "."
	if ((AtSignIndexValue == -1) || (EmailValue.indexOf(".") == -1)) {
		alert("An email address must contain at least one '@' symbol, and one period.");
		return (false);
	}

	if (PeriodLastIndexValue < AtSignIndexValue) {
		alert("An email address must contain at least one period after the '@' symbol.");
		return (false);
	} else {
		// this checks if there are only alpha numeric characters
		if (allowInString(EmailValue, LastTempChar, ValidCharacters)) {
		// this checks if there is only one "@"
		if (atSignCount(EmailValue, AtSignIndexValue)) {
			return(true);
		} else {
			alert("An email address can contain no more than one '@' symbol.");
			return(false);
		}
		} else {
		return(false);
		}
	}

	return(true);
}

function allowInString (EmailValue, LastTempChar, ValidCharacters) {
	if (EmailValue.length == 0) {
		alert("The email address field is empty.")
		return (false);
	} else {
		FirstTimeThrough = "True" 
		for (Count=0; Count < EmailValue.length; Count++) { 
		TempChar= EmailValue.substring (Count, Count+1);

		//checks if @ is first character
		if ((TempChar == "@") && (FirstTimeThrough == "True")) {
			alert("You cannot have the '@' symbol as the first character of your email address.");
			return (false);
		}

		//checks if . is first character
		if ((TempChar == ".") && (FirstTimeThrough == "True")) {
			alert("You cannot have a period as the first character of your email address.");
			return (false);
		}

		//checks for two periods in a row
		if (TempChar == LastTempChar) {
			alert("You cannot have two periods in a row in an email address.");
			return (false);
		}

		// checks for .@
		if ((TempChar == "@") && (LastTempChar ==".")){
			alert("You cannot have a period followed by an '@' symbol in an email address.");
			return (false);
		}

		// checks for @.
		if ((TempChar == ".") && (LastTempChar =="@")){
			alert("You cannot have an '@' symbol followed by a period in an email address.");
			return (false);
		}

		// checks for an invalid character
		if (ValidCharacters.indexOf (TempChar, 0)==-1){
			alert("You have typed at least one invalid character in your email address.	Please type only alpha-numeric characters, the '@' symbol, and periods.");
			return (false);
		}

		// sets up temporary variables so it can check for ".@" or "@." //combinations in the next loop	 
		if ((TempChar == ".") || (TempChar == "@")){
			LastTempChar = TempChar;
		} else {
			LastTempChar = "blank";
		}

		FirstTimeThrough = "False"
		} // end of for loop

		//if last character is period or "@"
		if ((TempChar == ".") || (TempChar =="@")) {
		alert("You cannot have a period or '@' symbol as the last character in your email address.");
		return (false);
		}
	}
	return(true);
}

function atSignCount(EmailValue, AtSignIndexValue) {
	SubStringEnd= EmailValue.substring (AtSignIndexValue + 1, EmailValue.length )

	if (SubStringEnd.indexOf("@") == -1) {
		return(true);
	} else {
		return(false);
	}
}
//========================================================================
function ValidatePhone(element) {
	phone = element.value;

	phone = ConvertCharacter(phone, " ", "") // gets rid of the space
	phone = ConvertCharacter(phone, "-", "") // gets rid of the dashes
	phone = ConvertCharacter(phone, ")", "") // gets rid of the ")"s
	phone = ConvertCharacter(phone, "(", "") // gets rid of the "("s

	validdigits = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";

	if (InvalidCharacterExists(phone, validdigits)) {
		alert("The number specified is invalid");
		return false;
	}

	cursor = parseInt(phone.length);

	if(cursor < 10) {
		alert("Phone numbers must have 10 digits.");
		return false;
	}

	last4 = phone.substring(cursor - 4, cursor);

	cursor = cursor - 4;

	middle3 = phone.substring(cursor - 3, cursor);
	cursor = cursor - 3;

	area3 = phone.substring(cursor - 3, cursor);
	cursor = cursor - 3

	firstdigit = phone.substring(0, cursor);

	// it's done this way so that the first digit can be 1, or it could start with the area code.
	if((firstdigit != "1") && (firstdigit != "")) {
		alert("The number specified is invalid");
		return false;
	}

	element.value = area3 + "-" + middle3 + "-" + last4;
	return true;
}

//========================================================================
// Checks the field value for alphabetic characters
function isAlpha(idx,msg) {
	var txtValue = idx.value;
	var txtLength = txtValue.length;
	for (var x=0; x!=txtLength; x++) {
		txtChar = txtValue.substring(x, x+1);
		txtChar = txtChar.toUpperCase();
		if(txtChar < "A" || txtChar > "Z") {
		idx.value="";
		alert("The entry for '" + msg + "' is invalid.\nPlease check your entries and try again.");;
		return false;
		}
	}
	return true;
}

//========================================================================
function isNum(idx,msg) {
	var boxValue = idx.value;
	var boxLength = boxValue.length;
	var boolAlreadyFoundDecimal = false;

	for (var i = 0; i != boxLength; i++) {
		aChar = boxValue.charAt(i);

		if (aChar == '.') {
		if (boolAlreadyFoundDecimal) {
			aChar = "a";	// set to something illegal for trap
		}
		boolAlreadyFoundDecimal = true;
		}

		if (((aChar < "0" || aChar > "9")	 // Allow characters between 0 and 9
		&& (aChar != '.' && aChar != ','))	// and decimal point and commas
		|| (aChar == "," && i == 0)) {	// as long as the comma isn't the first character

		idx.Value="";
		alert("The entry for '" + msg + "' is not numeric.\n Please try again");
		return false;
		}
	}
	return true;
}

//========================================================================
function validateZIP(field) {
	var valid = "0123456789-";
	var hyphencount = 0;

	if ((field.length!=5) && (field.length!=10)) {
		alert("Please enter your 5 digit or 5 digit+4 zip code.");
		return false;
	}

	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (temp == "-") hyphencount++;

		if (valid.indexOf(temp) == "-1") {
		alert("Invalid characters in your zip code.	Please try again.");
		return false;
		}

		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
		alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.\nPlease try again.");
		return false;
		}
	}

	return true;
}
//========================================================================
//-->
