// DO NOT MODIFY THIS FILE
// Use a ServerSide Include to include this at the top of your form.
//
// Add an * at the beginning of any field name you want to be a required field
// Field Name Example:
//	<input type="text" name="*FirstName"> 
//
// Add the following code into your form action:
//	onsubmit="return checkFields()" onreset="return Reset()"
// Form action example:
//	<form method="POST" action="mailer.asp" onsubmit="return checkFields()" onreset="return Reset()">
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Reset(){
return confirmIt = confirm("Are you sure you want to reset the form?")
}	


function checkFields(){

var theform = document.forms[0]

for(i=0; i<theform.elements.length; i++){
		var field = theform.elements[i]
		//alert(theform.elements[i].type)
		var isReq = (field.name.charAt(0)=="*") ? true : false
		if(isReq){
		
			if((field.type=="text" || field.type=="textarea" || field.type=="password") && field.value==""){
			alert("Please fill in the '"+field.name+ "' field.")
			setTimeout("document.forms[0].elements["+i+"].focus()", 10)
			return false
			}
			
			if(field.type=="select-one" && field.selectedIndex == 0){	
			alert("Please select a value for the '"+field.name+ "' field.")
			setTimeout("document.forms[0].elements["+i+"].focus()", 10)
			return false
			}
			
			if(field.type=="select-multiple"){	
			Sel=0
				for(o=0; o<field.options.length; o++){
					if(field.options[o].selected){
					Sel++
					break
					}
				}
				if(Sel == 0){
				alert("Please select a value for the '"+field.name+ "' field.")
				setTimeout("document.forms[0].elements["+i+"].focus()", 10)
				return false
				}			
			}
			
			if(field.type=="checkbox" || field.type=="radio"){
			var startingIndex = i	
			var Checked = 0
			var rLength=1
				while(field.type == theform.elements[i+1].type){
				rLength++
				i++ 
				}
				
				for(g = startingIndex; g < rLength+startingIndex; g++){
					if(theform.elements[g].checked){
					Checked++
					break
					}
				}		
				if(Checked == 0){
				i=startingIndex
				alert("Please select a value for the '"+field.name+ "' "+field.type+" group")				
				setTimeout("document.forms[0].elements["+i+"].focus()", 10)
				return false
				}
			}
			
		}//isReq
	  
	}//for
	return true
}
