<!--
	function stripSpaces(istrUserEntry){
	// Strips string of spaces
		var strStrippedEntry = '';
		for (var i = 0; i < istrUserEntry.length; i++){
			if (!(istrUserEntry.charAt(i) == ' ')){
				strStrippedEntry += istrUserEntry.charAt(i);
			}
		}
		return strStrippedEntry;
	}
	function isBlank(istrUserEntry){
	// Validates input string is not blank
		for (var i = 0; i < istrUserEntry.length; i++){
			var strChar = istrUserEntry.charAt(i);
			if ((strChar != ' ') && (strChar != '\n') && (strChar != '')){return false;}
		}
		return true;
	}
	function isEmpty(istrUserEntry){
	// Validates input string is not empty
		if ((istrUserEntry == null) || (istrUserEntry == "") || (isBlank(istrUserEntry))){return true;}
		return false;
	}
	function isAllZeros(istrUserEntry){
		for (var i = 0; i < istrUserEntry.length; i++){
			if (istrUserEntry.charAt(i) != "0"){return false;}
		} 
		return true;
	}
	function validateZipTariff(istrZipOrg, istrZipDest, istrTariffOrg, istrTariffDest){
	// Validates against combined zip and tariff searches
		var strMsg						= "";
		var blnZipEmpty				= isEmpty(istrZipOrg) && isEmpty(istrZipDest)
		var blnTariffEmpty		= isEmpty(istrTariffOrg) && isEmpty(istrTariffDest)
			
		if (!(blnZipEmpty || blnTariffEmpty)){
			strMsg += "You may search on ZIPs or Tariff Points but not both.\n\n";
		}
		return strMsg;
	}
	function validateAcctNbr(istrAcctNbr){
	// Validates Account Number against pattern matches
		var strMsg						= "";

		if (!isEmpty(istrAcctNbr)){
			if (isNaN(istrAcctNbr)){
				strMsg += "Please enter up to 11 digits for Customer Number.\n\n";
			}
			else{
				if (isAllZeros(istrAcctNbr)){
					strMsg += "Customer Number may not be all zeros.\n\n";
				}
			}
		}
		return strMsg;
	}
	function validateZip(istrZip, istrDesc){
	// Validates ZIP Code against pattern matches
		var strMsg						= "";
		var objZipPattern			= /\d{5}/;
		var objZipExceptions	= /00000/;

		if (!isEmpty(istrZip)){
			if (!objZipPattern.test(istrZip)){
				strMsg += "Please enter a 5-digit " + istrDesc + " ZIP.\n\n";
			}
			else if (objZipExceptions.test(istrZip)){
				strMsg += "You have entered an invalid " + istrDesc + " ZIP.\n\n";
			}
		}
		return strMsg;
	}
	function validateDateEntry(istrMonth, istrDay, istrYear, istrDesc){
	// Validates date is a valid selection.
		var strMsg						= "";
		if ((istrMonth == 4 || istrMonth == 6 || istrMonth == 9 || istrMonth == 11) && (istrDay > 30)){
			strMsg += "You have entered an invalid " + istrDesc + " Ship Date.\n\n";
		}
		if ((istrMonth == 2) && ((isLeapYear(istrYear) && (istrDay > 29)) || (istrDay > 28))){
			strMsg += "You have entered an invalid " + istrDesc + " Ship Date.\n\n";
		}
		return strMsg;
	}
	function validateDateOrder(istrDateFrom, istrDateTo, istrDesc){
	// Validates istrDateFrom is before istrDateTo.
		var strMsg						= "";
		if (Date.parse(istrDateTo) < Date.parse(istrDateFrom)){
			if (isEmpty(istrDesc)){
				strMsg += "Beginning Ship Date cannot be after the Ending Ship Date.\n\n";
			}
			else{
				strMsg += istrDesc + " Ship Date cannot be a future date.\n\n";
			}
		}
		return strMsg;
	}
	function getTodaysDate(){	
		var dteToday	= new Date();
		var strMonth	= dteToday.getMonth() + 1;
		var strDay		= dteToday.getDate();
		var strYear		= dteToday.getFullYear();
		return (strMonth + "/" + strDay + "/" + strYear);
	}	
	function isLeapYear(istrYear){
		if (istrYear % 100 == 0){
			if (istrYear % 400 == 0){return true;}
		}
		else{
			if ((istrYear % 4) == 0){return true;}
		}
		return false;
	}
	function validateRefNbr(istrUserEntry){
	// Validates Reference Number against pattern matches
		var strMsg						= ""
		var objRefNbrPattern	= /.{1,25}/;

		if (!objRefNbrPattern.test(istrUserEntry)){
			strMsg += "Please enter a Shipper's Reference.\n\n";
		}
		return strMsg
	}
	function validateEntries(){
	// High-level validation function
		var strErrMsg				= "";
		var objForm					= document.frmTrackByRef;
		var strRefNbr				= stripSpaces(objForm.txtReferenceNbr.value);
		var strFromMonth		= objForm.selFromMonth.options[objForm.selFromMonth.selectedIndex].value
		var strFromDay			= objForm.selFromDay.options[objForm.selFromDay.selectedIndex].value
		var strFromYear 		= objForm.selFromYear.options[objForm.selFromYear.selectedIndex].value
		var strToMonth			= objForm.selToMonth.options[objForm.selToMonth.selectedIndex].value
		var strToDay				= objForm.selToDay.options[objForm.selToDay.selectedIndex].value
		var strToYear				= objForm.selToYear.options[objForm.selToYear.selectedIndex].value
		var strAcctNbr			= objForm.txtCustomerNbr.value
		if (objForm.optCustType[0].checked){
			var strCustType = objForm.optCustType[0].value;
		}
		else{
			var strCustType = objForm.optCustType[1].value;
		}
		var strZipOrg				= objForm.txtZipOrg.value;
		var strZipDest			= objForm.txtZipDest.value;
		var strTariffOrg		= objForm.txtTariffOrg.value;
		var strTariffDest		= objForm.txtTariffDest.value;
		var strDateToday		= getTodaysDate();
		var strDateBeg			= strFromMonth + "/" + strFromDay + "/" + strFromYear;
		var strDateEnd			= strToMonth + "/" + strToDay + "/" + strToYear;

		strErrMsg += validateRefNbr(strRefNbr);
		strErrMsg += validateDateEntry(strFromMonth, strFromDay, strFromYear, "Beginning");
		strErrMsg += validateDateEntry(strToMonth, strToDay, strToYear, "Ending");
		strErrMsg += validateDateOrder(strDateBeg, strDateToday, "Beginning");
		strErrMsg += validateDateOrder(strDateEnd, strDateToday, "Ending");
		strErrMsg += validateDateOrder(strDateBeg, strDateEnd, "");
		strErrMsg += validateAcctNbr(strAcctNbr);
		strErrMsg += validateZip(strZipOrg, "U.S. Origin");
		strErrMsg += validateZip(strZipDest, "U.S. Destination");
		strErrMsg += validateZipTariff(strZipOrg, strZipDest, strTariffOrg, strTariffDest);

		// Show errors and return false
		if (!isEmpty(strErrMsg)){
			strErrMsg = strErrMsg.substring(0, strErrMsg.length - 2)
			alert(strErrMsg);
			return false;
		}
		// No errors
		else {return true;}
	}
//-->
