// Form validation funcs for the generic OOPs submission type pages

function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
		if (value != null) value = value.replace(/^\s*(\b.*\b|)\s*$/, "$1"); //JPX, 8/14/02
		
		// We don't allow a value of 0 (zero) in any form field, since this is a typical hacker value, and shouldn't be a normal end user response anyway.
		if (value==null || value=="" || value == "0") {
			if (alertbox!="") {
				alert(alertbox);
			} 
			return false;
		}
		else {
			return true;
		}
	}
}

// The msgErrText param contains the type of submission message for use in displaying the error message if it's missing.
function formvalidation(thisform)
{
	with (thisform)
	{	
		if (emptyvalidation(firstName, firstNameEmpty) == false) {
			firstName.focus(); 
			return false;
		}
		if (nameBPCheckCharacter(firstName.value,"First Name") == false) {
			firstName.focus(); 
			return false;
		}
		
		if (emptyvalidation(age, ageEmpty) == false) {
			age.focus(); 
			return false;
		}
		if (nameBPCheckDigits(age.value,"Age") == false) {
			age.focus(); 
			return false;
		}

		if (emptyvalidation(myState, stateEmpty) == false) {
			myState.focus(); 
			return false;
		}
					
		if (emptyvalidation(userMessage, commentEmpty) == false) {
			userMessage.focus(); 
			return false;
		} else if (userMessage >= 1000) {
			alert(commentTooLong);
			userMessage.focus();
			return false;
		}
	}
}

//Checks if a string is composed of the valid characters. 
function nameBPCheckCharacter(string, stringName) {

	if (string.match(/[^0-9A-Za-z_\-\. ]/)) {
		window.alert ("Only letters, numbers, dashes, underscores, spaces and dots"
			+ "\nare allowed in the " + stringName + " field. Please try again.");
		return false;
	}
	else 
		return true;
}

//Checks if a string is composed of only digits. 
function nameBPCheckDigits(string, stringName) {

	if (string.match(/[^0-9]/)) {
		window.alert ("Only numbers are allowed in the " + stringName + " field.\nPlease try again.");
		return false;
	}
	else 
		return true;
}
