// validation.js contains javascript validation and utility functions
// include into HTML pages with the following TAG  AINT <HEAD> Section
// SEE validationsample.HTML for example on including
//--------------------- Functions ----------------------------------

/////////////////////////////////////////////////////////////////////////////
// isEmpty checks for an emoty string
//
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

///////////////////////////////////////////////////////////////////////////////
//  validate_form loops through all the fields looking for empty fields
//  req_sym, what symbol does the field name need in order to be validated
// 			such as  date* , thus * is the extension only those fields named with extension
function validate_form(req_sym)
{

var theform = document.forms[0]   //assume one form on this page
var form_ok = true;
var msg="\n The Following Fields are REQUIRED but were left blank, please correct \n"

for(i=0; i<theform.elements.length; i++)
{
		var field = theform.elements[i]
		//alert(theform.elements[i].type)
		
		var isReq = (field.name.indexOf(req_sym ) != -1 ) ? true : false //is it Required?
		
		if(isReq){
		 //for text type fields		
			if((field.type=="text" || field.type=="textarea" || field.type=="password") && field.value=="")
			{
			msg += field.name +"\n"
			form_ok = false;
			}
			
		//Select Boxes 
			if(field.type=="select-one" && field.selectedIndex == 0)
			{	
			msg +=  field.name +"\n. "
			form_ok = 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 && field.name == theform.elements[i+1].name)
				{
				rLength++
				i++ 
				}
				
				for(g = startingIndex; g < rLength+startingIndex; g++){
					if(theform.elements[g].checked){
					Checked++
					break
					}
				}
						
				if(Checked == 0){
				i=startingIndex
				msg +=field.name+ "' "+field.type+" group \n."			
				form_ok = false;				
				   }
				} //if
			
		}//isReq
	  
	}//for
	
	if  (form_ok == false)
	  alert( msg)
	
	return form_ok 
}  //end function

 
 //////////////////////////////////////
 /// more functions below