<!-- Begin

function notEmpty(input, name){
	//take care of select form objects
	var inputFocus = input;
	
	if(input.type == "select-one")
		input = input.options[input.selectedIndex];
	
	//check if empty
	if(input.value == "" || input.value.search(/[\w]+/)==-1  || input.value == null) {
		alert( name + " must contain a value.");
		inputFocus.focus();
		return false;
	}
	return true;
}


function validLength(input, len, name){
	var inputFocus = input;
	
	if(input.value.length > len){
		alert( name + " must be less than " + len + " characters. " + name + " is currently " + input.value.length + " characters long.");
		inputFocus.focus();
		return false;
	}
	return true;
}


function isEmpty(x) {
	if(x == "" || x == null)
		return true;
	else
		return false;
}


function notEmptyList(inputList, inputname){
	if(inputList.options.length == 0){
		alert(inputname + " must contain a value.");
		return false;
	}
	return true;
}
		
function checkDate(date, type){
	if(date.value != null && date.value != ""){

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = date.value.match(datePat);
	
	if(matchArray == null){
			alert("The "+type+ " Date should be in the form: ##/##/####");
			return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	alert("Month must be between 1 and 12.");
	return false;
	}
	if (day < 1 || day > 31) {
	alert("Day must be between 1 and 31.");
	return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("Month "+month+" doesn't have 31 days!")
	return false;
	}
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
	alert("February " + year + " doesn't have " + day + " days!");
	return false;
    }}
	}
	return true;  // date is valid
}



function checkTermForm(form){
	//all fields on form are required.
	if(notEmpty(form.term, "Term")){
	if(validLength(form.term, "255", "Term")){
	if(notEmpty(form.definition, "Definition")){
	if(validLength(form.definition, "500", "Definition")){
	if(notEmpty(form.citation, "Citation")){
	if(validLength(form.citation, "750", "Citation")){
	if(notEmpty(form.created_by, "Name")){
	if(checkEmail(form.creator_email)){
		return true;
	}}}}}}}}
	return false;

}


   
function isInteger(strString, name){
   //  check for valid currency strings	
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

 //  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
      	strChar = strString.charAt(i);

      if (strValidChars.indexOf(strChar) == -1){
      	blnResult = false;
      }
	}
	  
  	if (blnResult == false){
		alert(name + " must be an integer.");
	}
   	return blnResult;
}

function validateNumber(num, lBound, uBound, name) {
	if (num != "" && num != null) {
		//first remove commas and dollar signs
		num = num.replace(",", "");
		num = num.replace("$", "");
		//conver to decimal numbers
		num = parseFloat(num);
		lBound = parseFloat(lBound);
		uBound = parseFloat(uBound);
		
		if(num < lBound || num > uBound){
			alert(name + " must be between " + lBound + " and " + uBound);
			return false;
		}
	}
	return true;
}

////////////////////check email function//////////////////////// 
function checkEmail(email){

	if(email.value != "" && email.value != null) {
		if(email.value.indexOf("@") == -1 || email.value.indexOf("@") >= email.value.length - 3){
			alert("Your email address is not in the correct format, please enter your full email address (ex: bob@internet.com).");
			email.focus();
			return false;
		}
		return true;
	}
	else{
		alert("You must provide an email.");
		email.focus();
		return false;
		}
			
	return true;	

}//checkEmail

//--!>


