function validateForm(theForm){ 
var err = 0;
var check = 0;
var Max = 0;
var Desc = "";
var Value = "";
var msg = "Please make sure you fill out all required fields.  Thank you. \n";


//loop through all form elements
 for (var e = 0; e < theForm.elements.length; e++)
 {
 //if the required attribute is set to Y then do the validation

if(theForm.elements[e].required == "Y")
 { 
 Desc = theForm.elements[e].id;
 theName = theForm.elements[e].name;

 // Text Box, Text Area, or Password - check for value
	if (theForm.elements[e].type == "text" | theForm.elements[e].type == "textarea" | theForm.elements[e].type == "password" | theForm.elements[e].type == "file") 
	{
 		Value = theForm.elements[e].value;
 		check = 0;
		
 		var ValueLength = Value.length;
		//loops through each character in the value and makes sure at least one is not a space (charcode 32)
 		for (var t = 0; t < ValueLength; t++)
  		{if (Value.charCodeAt(t) != 32) {check = 1}}
  
 		if (check == 0){err = 1;
		 document.getElementById(Desc).style.backgroundColor = '#FFFFCC';
		 //document.getElementById(Desc).style.color = 'white';
		 msg = msg + "Required Input: " + Desc + "\n";}
     }
	
	// Select Box - check for value not equal to "Select One"
	if (theForm.elements[e].type == "select-one" ) {
	   var thisVal = theForm.elements[e].options[theForm.elements[e].selectedIndex].value;
	   if (thisVal == "null" || thisVal == ""){
	 		err = 1; 
	 		document.getElementById(Desc).style.backgroundColor = '#FFFFCC';
	 		msg = msg + "Required Input: " + Desc + "\n";} 
	 
	 }
	 
	// Select Multiple - check for value not equal to "Select One"
	
	if (theForm.elements[e].type == "select-multiple" && theForm.elements[e].options.value == "null" | theForm.elements[e].options.value == "")
	 {err = 1; 
	 document.getElementById(Desc).style.backgroundColor = '#FFFFCC';
	 msg = msg + "Required Input: " + Desc + "\n";} 
	 
	//Radio or checkbox -check for at least one checked
	if (theForm.elements[e].type == "radio" | theForm.elements[e].type == "checkbox")
	{
	 var ok = 0;
	 //loop through every check box or radio with the same name
	 for (var CE = 0; theForm.elements[e + CE].name == theName; CE++)
	  {if (theForm.elements[e + CE].checked) {ok = 1;}}
	  
	  if (ok == 0) {
	  
	  err = 1; 
	  document.getElementById(Desc).style.backgroundColor = '#FFFFCC';
	  
	  msg = msg + "Required Input: " + Desc + "\n";}
	  //reset e because we've skipped ahead in the elements sequence 
	  e = e + CE - 1;
     } 
	
    //check that max length is not exceeded
    if(theForm.elements[e].maxlength)
     {
	 	Max = theForm.elements[e].maxlength;
	 	Chars = theForm.elements[e].value.length;
	 	if( Chars > Max)
	    { err = 1;
		  msg = msg + "Maximum of " + Max + " Characters Exceeded: " + Desc + " has " + Chars + " Characters \n";} 
	 }
	 
   //check that a correct email address is entered when specified
    if(theForm.elements[e].email)
     {
	 
	
		var str = theForm.elements[e].value;

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var thisErr = 0;
		
		if (str.indexOf(at)==-1){
		
		   thisErr = 1;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	
		   thisErr = 1;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
			thisErr = 1;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    
			thisErr = 1;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
			thisErr = 1;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		  
			thisErr = 1;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    
			thisErr = 1;
		 }					

        if (thisErr == 1){
	
		  document.getElementById(Desc).style.backgroundColor = '#FFFFCC';
		  err = 1;
		  msg = msg + "Invalid Email Address: " + Desc + "\n";
	    }
		
	  } // email check  */
	  
	  //phone number
	 //phone number
	
	if(theForm.elements[e].phone)
     { 
	   
	     
		  var thisError = 0;
		  
		  var numval = theForm.elements[e].value;
		  var valid1 = numval.search(/^\d\d\d-\d\d\d-\d\d\d\d$/);
		  var valid2 = numval.search(/^\d\d\d \d\d\d \d\d\d\d$/);
		 	if (valid1 != 0 && valid2 !=0) {
				thisError = 1;
			}
         
			
		  if (thisError == 1){
	
		  			document.getElementById(Desc).style.backgroundColor = '#FFFFCC';
		  			err = 1;
		  			msg = msg + "The field: " + Desc + " requires a valid format phone/fax number. \n\n eg:\n123 456 7890\n123-456-7890\n";
	  		}
		
			  
	   } //if phone
	  // if phone number
	  


  } //if required

}  //loop


 if (err > 0) {
 	alert(msg); 
 	return false; }
 else
 {	return true;}
 
 
} //function