var objFirstErrorField;   
var strAlertMessage;      

function NumericOnly(objField, lngLowestValue, lngHighestValue, strErrorMessage) {
	var lngNumber = "";
	var lngNumericTest;

	if (objField.type == "select-one")	{ //objField represents a list box
		if (objField.selectedIndex >= 0) 
			lngNumber = objField.options[objField.selectedIndex].value;
	}
	else 
		lngNumber = objField.value;
		
	if (lngNumber == "") return true;	//Empty string so ignore numeric check.
	
	lngNumericTest = Math.abs(lngNumber);

	if (lngNumericTest != lngNumericTest) { 
		FormatErrorMessage(objField, strErrorMessage);
		return false; //Not numeric
	}
	if ((lngNumber < lngLowestValue) || (lngNumber > lngHighestValue)) {
		FormatErrorMessage(objField, strErrorMessage);
		return false; //Out of valid range
	}
	return true;		
}		
function ValidDate(objField, strErrorMessage) {
	//Does simple "is it a valid date" verification.  It only validates the
	//date if it is not blank.  Otherwise it is considered ok.
	var lngCount;
	var lngParsedDate;
	var strCharCode;
	var strDate = "";
	var strFieldValue;

	if (objField.type == "select-one")	{ //objField represents a list box
		if (objField.selectedIndex >= 0) 
			strDate = objField.options[objField.selectedIndex].value;
	}
	else 
		strDate = objField.value;
		
	if (strDate == "") return true;	//Empty string so date check is ignored.

	//Examine each character in strDate looking for spaces or 
	//cararriage-return/line-feed characters.  If that's all you find then the date
	//field is blank so we don't bother verifying it.  Otherwise parse the date to
	//see if it's a valid.  Return false for invalid and true for valid.
	for (lngCount = 0; lngCount < strDate.length; lngCount++) {
		strCharCode = strDate.charCodeAt(lngCount);
		if ((strDate.charAt(lngCount) != " ") && (strCharCode != 10) && (strCharCode !=13)) {
			var strSplitDate = strDate.split("/");
			var strDate1 = new Date(Date.parse(strDate));
			var strDate1=(strDate1.getMonth()+1)+"/"+(strDate1.getDate())+"/"+(strDate1.getYear());
			var strDate2=(Math.abs(strSplitDate[0]))+"/"+(Math.abs(strSplitDate[1]))+"/"+(Math.abs(strSplitDate[2]));
			if ((Date.parse(strDate1) != Date.parse(strDate2)) || (strDate1=="NaN/NaN/NaN")) {
				FormatErrorMessage(objField, strErrorMessage);
				return false; //Invalid date
			}
			break;
		}
	}
	return true;	//date check didn't fail so it must be good (or all blanks)
}	
function RequiredField(objField, strErrorMessage) {
	//Checks for the absence of data in a field.
	var lngCount;
	var strCharCode;
	var strFieldValue = "";
	
	if (objField.type == "select-one")	{ //objField represents a list box
		if (objField.selectedIndex >= 0) 
			strFieldValue = objField.options[objField.selectedIndex].value;
	}
	else 
		strFieldValue = objField.value;
	//Examine each character in strFieldValue.  If there are any non-space 
	//and non-carriage-return/line-feed characters, it's valid (return true).
	//Otherwise the field is empty or all spaces so it's invalid (return false).
	for (lngCount = 0; lngCount < strFieldValue.length; lngCount++) {
		strCharCode = strFieldValue.charCodeAt(lngCount);
		if ((strFieldValue.charAt(lngCount) != " ") && (strCharCode != 10) && (strCharCode !=13)) {
			return true;	
			break; }
	}
	FormatErrorMessage(objField, strErrorMessage);
	return false;
}
function ValidatePassword(strPassword) {
	var lngCount;
	var strChar;
	
	if (strPassword.length < 4) {
		return false;
	}		
	for (lngCount = 0; lngCount < strPassword.length; lngCount++) {
		strChar = strPassword.charAt(lngCount).toUpperCase();
		//Allow only the characters A through Z and 0 through 9.
		if ((strChar < "A" || strChar > "Z") && (strChar < "0" || strChar > "9")) {
			return false; //Invalid character found
			break;
		}
	}
	return true;
}
function ValidateUserID(strUserID) {
	var lngCount;
	var strChar;
	
	for (lngCount = 0; lngCount < strUserID.length; lngCount++) {
		strChar = strUserID.charAt(lngCount).toUpperCase();
		//Allow only the characters A through Z and 0 through 9.
		if ((strChar < "A" || strChar > "Z") && (strChar < "0" || strChar > "9")) {
			return false; //Invalid character found
			break;
		}
	}
	return true;
}
function FormatErrorMessage(objField, strErrorMessage) {
	//Formats a single error message for each error message passed in strMsg.
	//Tracks the first field with an error.
	strAlertMessage = strAlertMessage + "\n" + strErrorMessage;
	if (objFirstErrorField == "") objFirstErrorField = objField;
}	