<!--
var strInptError = "";
var blnInptError = false;

function displayError() {
	var strMsg = "There seems to be some information that is either missing or incorrect.\nPlease check the following items.\n_____________________________\n\n";
	strInptError = strMsg + strInptError;
	alert (strInptError);
	strInptError = "";
	blnInptError = false;
	return false;
}

function appendError(strVal) {
	var i;
	if (strVal.indexOf("_") != -1 && strVal.length != -1) {
		for (var i = 0; i < strVal.length; i++){
			if (strVal.indexOf("_") != -1) { strVal = strVal.substring(0, strVal.indexOf("_")) + " " + strVal.substring(strVal.indexOf("_") + 1, strVal.length) }
		}
	} 
	strInptError = strInptError + strVal + "\n";
	blnInptError = true;
}

function validateInput(frmVal) {
	var elem = frmVal.elements;
	var counter = 0;
	aryCbGroup = new Array();

	for (var i = 0; i < elem.length; i++) {
		if (elem[i].name.indexOf("_verify") != -1 && elem[i].value == "group") {
			aryCbGroup[counter] = new Array(2);
			aryCbGroup[counter][0] = elem[i].name.substring(0, elem[i].name.indexOf("_verify"))
			counter++;
		}
	}

	for (var i = 0; i < elem.length; i++) {
		if (elem[i].type == "text") {
			var tmp = elem[i].name + "_verify";
			if (elem[tmp] != null) {
				if (elem[i].value.replace(/\s+/g, "") == "" || elem[i].value.replace(/\s+/g, "") == null) { appendError(elem[i].name); }
				else {
					if (elem[tmp].value == "email") {
						if (!validEmail(elem[i])) { appendError("Invalid Email Format"); }
					}
					if (elem[tmp].value == "usphone") {
						formatUSPhone(elem[i]);
						if (!validUSPhone(elem[i])) { appendError("Invalid U.S. Phone Format"); }
					}
					if (elem[tmp].value == "intlphone") {
						formatIntlPhone(elem[i]);
						if (!validIntlPhone(elem[i])) { appendError("Invalid International Phone Format"); }
					}
					if (elem[tmp].value == "uspostal") {
						formatUSPostal(elem[i]);
						if (!validUSPostal(elem[i])) { appendError("Invalid U.S. Postal Code"); }
					}
					if (elem[tmp].value == "ssn") {
						formatSSN(elem[i]);
						if (!validSSN(elem[i])) { appendError("Invalid Social Security Number"); }
					}
					if (elem[tmp].value == "dec-integer") {
						if (parseInt(elem[i].value, 10) == 0 || isNaN(parseInt(elem[i].value, 10))) { appendError(elem[i].name + " is not a valid integer"); }
						else { elem[i].value = Math.round(elem[i].value); }
					}
					if (elem[tmp].value == "cc") {
						var tmp2 = elem[i].name + "_type";
						if (elem[tmp2] != null) {
							formatCC(elem[i], elem[tmp2].options[elem[tmp2].selectedIndex].value);
							if (!validCCType(elem[i], elem[tmp2].options[elem[tmp2].selectedIndex].value)) { appendError("Credit Card does not match type selected"); }
							else if (!validCCNumber(elem[i], elem[tmp2].options[elem[tmp2].selectedIndex].value)) { appendError("Credit Card number is invalid"); }
						}
					}
					if (elem[tmp].value == "search") { validSearchTerms(elem[i]); }
				}
			}
		}
		
		if (elem[i].type == "password") {
			var tmp = elem[i].name + "_verify";
			if (elem[tmp] != null) {
				if (elem[i].value == "" || elem[i].value == null) { appendError(elem[i].name); }
				if (elem[tmp].value != "" && elem[tmp].value != null) {
					if (elem[i].value != elem[elem[tmp].value].value) { appendError("The passwords provided do not match."); }
				}
			}
		}

		if (elem[i].type == "textarea") {
			var tmp = elem[i].name + "_verify";
			if (elem[tmp] != null) {
				if (elem[i].value.replace(/\s+/g, "") == "" || elem[i].value.replace(/\s+/g, "") == null) { appendError(elem[i].name); }
				else {
					if (elem[tmp].value.length > 0) {
						if (elem[i].value.length > elem[tmp].value) { appendError(elem[i].name + " cannot exceed " + elem[tmp].value + " characters"); }
					}
				}
			}
		}
		
		if (elem[i].type == "select-multiple") {
			var tmp = elem[i].name + "_verify";
			if (elem[tmp] != null) {
				if (elem[tmp].value == "length") {
					if (elem[i].length == 0) { appendError(elem[i].name); }
				}
			}
		}

		if (elem[i].type == "select-one") {
			var tmp = elem[i].name + "_verify";
			if (elem[tmp] != null) {
				if (elem[tmp].value == "length") {
					if (elem[i].length == 0) { appendError(elem[i].name); }
				}
				else {
					if (elem[i].options[elem[i].selectedIndex].value == "" || elem[i].options[elem[i].selectedIndex].value == null) { appendError(elem[i].name); }
				}
			}
		}

		if (elem[i].type == "checkbox") {
			var tmp = elem[i].name + "_verify";
			if (elem[tmp] != null) {
				if (elem[tmp].value == "group") {
					if (elem[i].checked) {
						for (j = 0; j < aryCbGroup.length; j++) {
							if (aryCbGroup[j][0] == elem[tmp].name.substring(0, elem[tmp].name.indexOf("_verify"))) { aryCbGroup[j][1] = true; }
						}
					}
				}
				else {
					if (!elem[i].checked) { appendError(elem[i].name); }
				}
			}
		}
	}
	
	for (var i = 0; i < aryCbGroup.length; i++) {
		if (aryCbGroup[i][1] != true) { appendError(aryCbGroup[i][0]); }
	}

	if (blnInptError) { return displayError(); }
	
	return true;
}


function formatUSPhone(strVal) {
	strVal.value = strVal.value.replace(/\D+/g, "");
	if (strVal.value.length > 0) { strVal.value = "(" + strVal.value.substring(0, 3) + ") " + strVal.value.substring(3, 6) + "-" + strVal.value.substring(6, 10); }
}

function validUSPhone(strVal) {
	if (strVal.value.length > 0) {
		if (strVal.value.match(/^(\({1,1})(\d{3,3})(\) {1,1})(\d{3,3})(-{1,1})(\d{4,4})$/) == null) { return false; }
		else { return true; }
	}
}

function formatIntlPhone(strVal) {
	strVal.value = strVal.value.replace(/\D+/g, "");
	if (strVal.value.length > 0) { strVal.value = "+" + strVal.value.substring(0, 2) + " (" + strVal.value.substring(2, 5) + ") " + strVal.value.substring(5, 8) + "-" + strVal.value.substring(8, 12); }
}

function validIntlPhone(strVal) {
	if (strVal.value.length > 0) {
		if (strVal.value.match(/^(\+{1,1})(\d{2,2})(\ {1,1})(\({1,1})(\d{3,3})(\) {1,1})(\d{3,3})(-{1,1})(\d{4,4})$/) == null) { return false; }
		else { return true; }
	}
}

function formatUSPostal(strVal) {
	strVal.value = strVal.value.replace(/[^\d]+/g, "");
	if (strVal.value.length > 5) { strVal.value = strVal.value.substring(0, 5) + "-" + strVal.value.substring(5, 9); }
}

function validUSPostal(strVal) {
	if (strVal.value.length > 0) {
		if (strVal.value.match(/^(\d{5,5})((-{1,1}\d{4,4})?)$/) == null) { return false; }
		else { return true; }
	}
}

function formatCC(strVal, strType) {
	/******************************************************************************
	Purpose:
		Formats a credit card number depending on the type of card
		16 digit cards have the form ####-####-####-####
		13 digit cards have the form ###-###-###-####
		15 digit cards have the form ####-######-#####

	Input:
		strVal - Form Element Object - object who's value is the Credit Card Number to be formatted
		strType - String Object - Type of Card to format
	
	Notes:
		strType must be one of the following case sensitive names:
		*	MasterCard, Visa, Discover, AMEX
	******************************************************************************/
	
	strVal.value = strVal.value.replace(/\D+/g, "");
	if (strVal.value.length > 0) {
		if (strType == "MasterCard" || strType == "Discover" || (strType == "Visa" && strVal.value.length == 16)) {
			strVal = strVal.value.substring(0, 4) + "-" + strVal.value.substring(4, 8) + "-" + strVal.value.substring(8, 12) + "-" + strVal.value.substring(12, 16);
		}
		if (strType == "Visa" && strVal.value.length == 13) {
			strVal = strVal.value.substring(0, 3) + "-" + strVal.value.substring(3, 6) + "-" + strVal.value.substring(6, 9) + "-" + strVal.value.substring(9, 13);
		}
		if (strType == "AMEX") {
			strVal = strVal.value.substring(0, 4) + "-" + strVal.value.substring(4, 10) + "-" + strVal.value.substring(10, 15);
		}
	}
}

function validCCType(strVal, strType) {
	/******************************************************************************
	Purpose:
		Verifies the first number of a credit card number against the type of card it's
		supposed to be

	Input:
		strVal - Form Element Object - object who's value is the Credit Card Number
		strType - String Object - Type of Card to check against

	Output:
		true if the first digit of the card matches the type
		false otherwise

	Notes:
		strType must be one of the following case sensitive names:
		*	MasterCard, Visa, Discover, AMEX
	******************************************************************************/

	if (strVal.value.length > 0) {
		if (strVal.value.substring(0, 1) == "3" && strType != "AMEX") { return false; }
		if (strVal.value.substring(0, 1) == "4" && strType != "Visa") { return false; }
		if (strVal.value.substring(0, 1) == "5" && strType != "MasterCard") { return false; }
		if (strVal.value.substring(0, 1) == "6" && strType != "Discover") { return false; }
	}
	return true;
}

function validCCNumber(strVal, strType) {
	/******************************************************************************
	Purpose:
		Checks a credit card number against an algorhythm

	Input:
		strVal - Form Element Object - object who's value is the Credit Card Number
		strType - String Object - Type of Card to check against

	Output:
		true if the card number matches the algorhythm
		false otherwise

	Notes:
		strType must be one of the following case sensitive names:
		*	MasterCard, Visa, Discover, AMEX
	******************************************************************************/

	var strTmp = strVal.value;
	var intTotal = 0;
	var intTmp = 0;
	strTmp = strTmp.replace(/\D+/g, "");

	if (strType == "MasterCard" || strType == "Discover") {
		if (strVal.value.match(/^(\d{4,4})(-{1,1})(\d{4,4})(-{1,1})(\d{4,4})(-{1,1})(\d{4,4})$/) == null) { return false; }
	}
	if (strType == "Visa") {
		if (strVal.value.match(/^(\d{4,4})(-{1,1})(\d{4,4})(-{1,1})(\d{4,4})(-{1,1})(\d{4,4})$/) == null && strVal.value.match(/^(\d{3,3})(-{1,1})(\d{3,3})(-{1,1})(\d{3,3})(-{1,1})(\d{4,4})$/) == null) { return false; }
	}
	if (strType == "AMEX") {
		if (strVal.value.match(/^(\d{4,4})(-{1,1})(\d{6,6})(-{1,1})(\d{5,5})$/) == null) { return false; }
	}

	for (var i = 0; i < strTmp.length; i++) {
		var j = 0;
		intTmp = strTmp.substring(strTmp.length - i - 1, strTmp.length - i);
		if (((i) % 2) != 0) {
			intTmp = strTmp.substring(strTmp.length - i - 1, strTmp.length - i) * 2;
			if (intTmp >= 10) { intTmp = (intTmp - 10) + 1; }
		}
		intTotal = (intTotal - 0) + (intTmp - 0);
	}
	if (intTotal % 10 != 0) { return false; }
	return true;
}

function formatSSN(strVal) {
	strVal.value = strVal.value.replace(/\D+/g, "");
	if (strVal.value.length > 0) { strVal.value = strVal.value.substring(0, 3) + "-" + strVal.value.substring(3, 5) + "-" + strVal.value.substring(5, 9); }
}

function validSSN(strVal) {
	if (strVal.value.length > 0) {
		if (strVal.value.match(/^(\d{3,3})(-{1,1})(\d{2,2})(-{1,1})(\d{4,4})$/) == null) { return false; }
		else { return true; }
	}
}

function validEmail(strVal) {
	if (strVal.value.length > 0) {
		if (strVal.value.match(/^((([a-zA-Z0-9-_]*)([.]{0,1})){1,9})(@{1,1})(([a-zA-Z0-9-]*[.]{1,1}){1,9})(\w{2,3})$/) == null) { return false; }
		else { return true; }
	}
}

function validDate(dateStr) {
	// the following line checks for these date formats: MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	// to force a four digit year, comment the previous line and uncomment the following:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = dateStr.match(datePat);
	if (matchArray == null) { return false; }
	month = matchArray[1];
	day = matchArray[3];
	year = matchArray[4];
	if ((month < 1 || month > 12)  || (day < 1 || day > 31) || ((month==4 || month==6 || month==9 || month==11) && day==31)) { return false; }
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day == 29 && !isleap)) { return false; }
	}
	return true;
}

var strSearchNoiseWords = "";
var strSearchOperators = "";

function validSearchTerms(strVal) {
	/******************************************************************************
	Purpose:
		Remove ignored words and make sure the first and last words aren't operators

	Input:
		strVal - Form Element Object - object who's value is to be checked

	Notes:
		the variables strSearchNoiseWords and strSearchOperators must be set in the page
		after this file has been included, otherwise this function will simply be passed over
	******************************************************************************/

	strVal.value = strVal.value.toLowerCase();
	var aryTerms = strVal.value.split(" ");
	var strTerms = "";
	for (var i = 0; i < aryTerms.length; i++) {
		if (strSearchNoiseWords.indexOf(" " + aryTerms[i] + " ") == -1) { strTerms = strTerms + aryTerms[i] + " " }
	}
	strVal.value = strTerms;
	if (strTerms.replace(/\s+/g, "") == "" || strTerms.replace(/\s+/g, "") == null) { appendError("Your search contains only ignored words"); return false; }
	var aryTerms = strVal.value.split(" ");
	if (strSearchOperators.indexOf(" " + aryTerms[0] + " ") != -1 || strSearchOperators.indexOf(" " + aryTerms[aryTerms.length - 2] + " ") != -1) { appendError("Your search begins or ends with an operator"); return false;}
	return true;
}

// -->