//function to determine if blank:
function isBlank(s)
{
	for (var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

//function to verify form:
function VerifyForm(f)
{
	var msg;
	var empty_fields ="";
	var errors = "";
	
	//start for loop:
	for (var i =0; i < f.length; i++)
	{
	  var e = f.elements[i];
	  
	  //start element type test:
	  if (((e.type=="text")||(e.type=="password")||(e.type=="textarea")) && !e.optional)
	  {
	    //skip if the element is disabled or readonly and optional:
		if (((e.disabled) || (e.readonly)) && !e.optional) continue;
		
		 //first check if the field is empty:
	     if ((e.value == null) || (e.value =="") || isBlank(e.value))
		 {

			/*----------------------------------------------------------------------*/
		 	//1-17-2002: use the title of the element if there is one
			/*----------------------------------------------------------------------*/
			if ((e.title != null) && (e.title !=""))
			{
		 		empty_fields += "\n              " + e.title;
			}
			else
			{
		 		empty_fields += "\n              " + e.name;
			}
			/*----------------------------------------------------------------------*/
			
			continue;
		 }//end of empty check

		/*-------------------------------------------------------------------------------*/
		//now check fields that are supposed to be dates:
		/*-------------------------------------------------------------------------------*/
		if (e.isdate)
		{
			var dateNum = Date.parse(e.value);

			if (isNaN(dateNum) || 
			    ((e.min !=null) && (dateNum < Date.parse(e.min))) ||
				((e.max !=null) && (dateNum >Date.parse(e.max))))
			{
				/*----------------------------------------------------------------------*/
			 	//1-17-2002: use the title of the element if there is one
				/*----------------------------------------------------------------------*/
				if ((e.title != null) && (e.title !=""))
				{
			   		errors += "- The field " + e.title + " must be a valid date";
				}
				else
				{
			   		errors += "- The field " + e.name + " must be a valid date";
				}
				/*----------------------------------------------------------------------*/

			   if (e.min !=null)
				  errors += " that is greater than " + e.min;
			   if (e.max !=null && e.min !=null)
			      errors += " and less than " + e.max;
			   else if (e.max !=null)
			      errors += " that is less than " + e.max;
				
			   errors += ".\n";	 			 
			}
		}//end of date check:
		/*-------------------------------------------------------------------------------*/
		
		//now check for fields that are supposed to be numeric:
		//if (e.numeric || (e.min !=null) || (e.max !=null))
		if (e.numeric)
		{
			var v = parseFloat(e.value);
			if (isNaN(v) || 
			    ((e.min !=null) && (v < e.min)) ||
				((e.max !=null) && (v > e.max)))
			{
			   
				/*----------------------------------------------------------------------*/
			 	//1-17-2002: use the title of the element if there is one
				/*----------------------------------------------------------------------*/
				if ((e.title != null) && (e.title !=""))
				{
			   		errors += "- The field " + e.title + " must be a number";
				}
				else
				{
			   		errors += "- The field " + e.name + " must be a number";
				}
				/*----------------------------------------------------------------------*/
		   
			   if (e.min !=null)
				  errors += " that is greater than " + e.min;
			   if (e.max !=null && e.min !=null)
			      errors += " and less than " + e.max;
			   else if (e.max !=null)
			      errors += " that is less than " + e.max;
			   errors += ".\n";	 			 
			}
		}//end of numeric check if
		 
	  }//end of element type test
	  
	}//end of for loop;

	//display error messages if there were any:
	//other wise return true for no errors:
	//you would submit the form at this point
	if (!empty_fields && !errors) return true;
	
	
	//format message:
	msg = "___________________________________________________\n\n"
	msg += "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "___________________________________________________\n\n"
	
	if (empty_fields)
	{
		msg += "- The following required field(s) are empty:" + empty_fields + "\n";
		if (errors) msg += "\n";
	}

	msg += errors;
	alert (msg)
	return false;	
	
}//end of function



