/*Function that Validates each field in the form*/
function validateForm(FormObject){
	var formValid = true;
		
	//validates all the values for required radio buttons, text inputs and checkboxes
	var theForm=document.getElementsByTagName("input");
	for(var i=0; i<theForm.length;i++){
		if(theForm[i].getAttribute("required")=="required"){
			var inputType = theForm[i].getAttribute("type");
			switch(inputType){
			//if the input is a textfield
				case "text":
					if(theForm[i].value==""){
						formValid=false;
						theForm[i].parentNode.style.color="#F00";
					}
					else
						theForm[i].parentNode.style.color="#000";
					
				break;
				
				//if the input is a rradio button
				case "radio":
					var radioSetName = theForm[i].getAttribute("name");
					var radioSet= eval("FormObject." + radioSetName);
					var isChecked=false;
					
					//checks to see if any of the radio buttons in the set are checked
					for(var k=0; k<radioSet.length; k++){
						if(radioSet[k].checked){
							isChecked=true;
						}
					}
					
					if(!isChecked){	
						formValid=false;
						theForm[i].parentNode.style.color="#F00";
					}
					else
						theForm[i].parentNode.style.color="#000";
					
				break;	
				
				case "checkbox":
					var radioSetName = theForm[i].getAttribute("name");
					var radioSet= eval("FormObject." + radioSetName);
					var isChecked=false;
					
					//checks to see if any of the radio buttons in the set are checked
					for(var k=0; k<radioSet.length; k++){
						if(radioSet[k].checked){
							isChecked=true;
							break;
						}
					}
					
					if(!isChecked){	
						formValid=false;
						theForm[i].parentNode.style.color="#F00";
					}
					else
						theForm[i].parentNode.style.color="#000";
				break;	
			}
		}
	}
	
	//validating all of the forms drop downs
	var formSelects=document.getElementsByTagName("select");
	for(i=0;i<formSelects.length; i++){
		if(formSelects[i].getAttribute("required")=="required"&&formSelects[i].selectedIndex==0){
			formValid=false;
			formSelects[i].parentNode.style.color="#F00";
			
		}	
		else
			formSelects[i].parentNode.style.color="";
			
	}
	
	//validating all of the forms drop downs
	var formTextAreas=document.getElementsByTagName("textarea");
	for(i=0;i<formTextAreas.length; i++){
		if(formTextAreas[i].getAttribute("required")=="required" && formTextAreas[i].value==""){
			formValid=false;
			formTextAreas[i].parentNode.style.color="#F00";	
		}
		else
			formTextAreas[i].parentNode.style.color="";
	}	
	//if there is no missing information, submit the form, other wise, write an alert
	if(formValid){ 
		var today = new Date();
		var month = today.getMonth() + 1;
		var day = today.getDate();
		var year = today.getFullYear();
		var dateString = month + "/" + day + "/" + year;
		try{
			FormObject.date.value = dateString;
		}
		catch(Exception){}
		FormObject.submit(); 
	}
	else{	//display message
		alert("Some information is either missing or filled out incorrectly. \n  These items have been highlighted for you." 	   				+  "  Please go back and correctly enter the information before submitting.");	
	}
	
	return formValid;

}			