// generic error checking procedures
// Diana Hyland - diana.hyland@doit.wisc.edu
// 7/1/2002

function lengthCheckFailed(thiselement, name, size){
	//returns TRUE if field over max size of field
	if(thiselement.value.length > size){
		var message = "The " + name +" field is longer than " + size + " characters.\nPlease limit the number of characters to less than " + size + " before submitting."; 
		alert(message);
		thiselement.focus();
		return true;
	}
	return false;
}

function CheckEmpty(thiselement, name, type, message){
	//returns TRUE if element is empty & sends alert message if param variable is 1
	if(type == "select"){
		if(thiselement.options[thiselement.selectedIndex].value == 0) {
			if(message == 1) {
				var message = "The " + name + " field is empty.  Please select the " + name + ".";
				alert(message);
				thiselement.focus();
			}
			return true;
		}
	}
	else {
		if(thiselement.value.length == 0) {
			if(message == 1) {
				message = "The " + name + " field is empty.  Please enter the " + name + ".";
				alert(message);
				thiselement.focus();
				}
			
			return true;
		}
	}
	return false;
}

function CheckNum(thiselement, name) {
  	//returns true if check FAILS - item is not numeric
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<thiselement.value.length; i++) 
	{
		temp = "" + thiselement.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}//end for	
	if (ok == "no") 
	{
		var message = "The " + name +" field is not numeric.\nPlease only enter whole numbers in this field, with no dashes or commas."; 
		alert(message);
		thiselement.focus();
		return true;
	} //end if(ok=="no")
  
	return false;
 }
