function validateRequiredFields(form){
   var alertMsg = "Please correct the following:\n\n";
   var alertMsgInitialLength = alertMsg.length;
   validEmailRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

   for (i=0; i<requiredFields.length; i++)
   {
      var tempObj = form.elements[requiredFields[i]];
      if (tempObj.type) //single field
		{
			switch(tempObj.type){ 
				case "text":
				case "textarea":
				case "password":
				case "select-one":
				case "select-multiple":
			  		if (!hasContent(tempObj.value))
         			alertMsg += fieldDescription[i] + " is required" + "\n";
      			else if (requiredFields[i].search(/email/i) >= 0)
      			{
      				if (tempObj.value.search(validEmailRegExp) == -1)
         				alertMsg += fieldDescription[i] + " is not valid" + "\n";
      			}
					break;
				case "checkbox":
				case "radio":
					if (!hasCheck(tempObj))
         			alertMsg += fieldDescription[i] + " is required" + "\n";
					break;
				default:
			}
		}
      else //array of fields
      {
   		var oneIsSelected = false;
			for(j = 0; j < tempObj.length; j++) {
				switch(tempObj[j].type){
				case "checkbox":
				case "radio":
					if (hasCheck(tempObj[j]))
						oneIsSelected = true;
					break;
				case "text":
				case "textarea":
				case "password":
				case "select-one":
				case "select-multiple":
					if (hasContent(tempObj[j].value))
						oneIsSelected = true;
					break;
				default:
				}	
         }
      	if (!oneIsSelected)
         	alertMsg += fieldDescription[i] + " is required" + "\n";
   	}
   }
   
   if (alertMsgInitialLength != alertMsg.length)
   {
      alert(alertMsg);
      return false;
   }
   else
   	return true;
}


function hasContent(value) {
if (Trim(value) == "" || Trim(value) == null)
	return false;
else
	return true;
}


function hasCheck(tempObj) {
if(tempObj.checked)
	return true;
else
	return false;
}


function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function


function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function


function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function
