/******************* TEXT FIELD VALIDATION *******************/
function fnInvalidText(field, description, minLen, maxLen) { //Checks if field is between minLen and maxLen; 
	//-1 for minLen will prompt to fill in, but not require a min length.
	//-1 for maxLen allow unlimited characters to be entered.
	if (!field) //If field does not exist, exit
		return false;
    if (minLen==-1 && field.value=="") { alert("Please enter a value for the " + description + " field before proceeding."); field.focus(); return true; }
  	if (minLen>0 && field.value.length<minLen) { alert("Please enter at least " + minLen + " characters for the " + description + " field."); field.focus(); return true; }
	if (maxLen>0 && field.value.length>maxLen) { alert("Please enter at most " + maxLen + " characters for the " + description + " field."); field.focus(); return true; }
	return false;
}
/******************* MENU VALIDATION *******************/
function fnInvalidSelect(field,description) {
	if (field) {
		if (field.selectedIndex<1) { alert ("Please select one of the \"" + description + "\" options."); field.focus(); return true; }
	}
	return false;
}
/******************* CHECKBOX VALIDATION *******************/
function AnyCheck(field,description) {
	if (field){
		var total = 0;
		for (var i = 0; i < field.length; i++) {if (eval(field[i].checked) == true) {total += 1;}}
		if (total==0) {alert("Please choose at least one of the "+ description +" options."); field[0].focus(); return true;}
	}
	return false;
}

function fnIsEmpty(s)	// Returns true if string s is Empty
	{ return ( (s == null) || (s.length == 0)) }

/******************* RETURNS RADIO BUTTON VALUE *******************/
function fnGetRadioValue(radio) {
	var Value = ""
	if (isNaN(radio.length)) {
		if (radio.checked) Value = radio.value;
	} else {
		for (var i = 0; i < radio.length; i++){
			if (radio[i].checked) Value = radio[i].value;
		}
	}
	return Value
}
/******************** RADIO BUTTON VALIDATION ********************/
function fnInvalidRadio(field, description){
	if (fnIsEmpty(fnGetRadioValue(field))) {
		alert("Please choose at least one of the "+ description +" options."); 
		if (isNaN(field.length))
			field.focus(); 
		else 
			field[0].focus(); 
		return true;
	} else {
		return false;
	}
}
/******************** EMAIL VALIDATION ********************/
function fnIsValidEmail(s) { // Returns true if string s meets the basic format of an email address
	if (fnIsEmpty(s))
		return false;
	var i = 1;											// Look for @ starting with the second character in s												
	var sLen = s.length;
	while( (i < sLen ) && ( s.charAt(i) != "@" ) ) { i++; }
	if( ( i >= sLen ) || (s.charAt(i) != "@")) 
		return false;
    else 
		i += 2;
	while ((i < sLen) && (s.charAt(i) != ".")) { i++; }	// Look for a dot starting with the second character after the @
	if ((i >= sLen - 1) || (s.charAt(i) != "."))		// There must be at least one character after the dot
		return false;
	else 
		return true;
}