//This code verify's a form prior to submitting it to the server
//code lifted from ora book :-)
// to use it, add these to your form:
//<form onSubmit="this.textfield.optional=true; // text/textarea field
// this.number.min=0; this.number.max=10; // number field
//alert("JavaScript form_verify loaded");

function isblank(s){ //checks for a blank string
	for (var i=0;i<s.length;i++){
		var c= s.charAt(i);
		if( (c!=' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}//end fucntion isblank(s)

function verify(f){ // verify's our form prior to submtting it to the server
	var msg;
	var empty_fields="";
	var errors="";
	//alert("verify fuction executed");
	//Verify text fields.
	for ( var i=0; i<f.length; i++){
		var e=f.elements[i];
		//check for empty text fields fields
		if( ((e.type == "text") || (e.type=="textarea"))
		   && e.optional){
			if( (e.value==null) || (e.value=="") 
			 || isblank(e.value) ){
				empty_fields +="\n          "+e.name;
				continue;
			} // end if (( e.value...
		//verify numrical feilds
		}//end if( ((e...
		if (e.numeric || (e.min != null) || (e.max !=null) ){
			var v=parseFloat(e.value);
			if(isNaN(v)||
			  ( (e.min !=null) && (v< e.min) ) ||
			  ( (e.max !=null) && (v >e.max) ) 
			  ){
				erors +="* The field " +e.name +
				"must be a number ";
				if( e.min !=null)
					errors +="greater than "+e.min+" " ;
				if(e.max !=null){
					if(e.min !=null)error+="and ";
					errors +="less than " +e.max;
				}//if (e.max!=null)//
				errors +="\n";
			}// if (IsNaN(V)) ...
		}//endif e.numeric
	}//end for(var i...
	
	
	if(!empty_fields && !errors) return true; // all clear, no errors!
	//print errors
	msg="Please correct the following errors and re-submit:\n\n"
	
	if(empty_fields){
		msg+="The following required field(s) are empty:\n"
		msg+=empty_fields +"\n\n";
	}//end if(empty_fields
	msg+=errors;
	alert(msg);
	return false;

}// end function verify(f)
