// JavaScript Documentfunction validateFormOnSubmit(domForm) {var reason = "";  //Build a summary of errors  reason += validateFirstName(domForm.FirstName);  reason += validateLastName(domForm.LastName);  reason += validateCity(domForm.City);  reason += validateZip(domForm.ZipCode);  reason += validatePhone(domForm.Phone1);  reason += validateEmail(domForm.EmailAddress);  //if summary error is not empty display the errors  if (reason != "") {    //display errors in errurSummary    document.getElementById("errorSummary").innerHTML=reason;        //scroll to top of page - to view errors    window.scrollTo(0,0);   	    //stop processing the page    return false;          } else { //clear any error messages that may have been generated    	document.getElementById("errorSummary").innerHTML='';  	  }          //validate the employment questionaire section  //start with the radio buttons    var reason = "";    reason += rbValidation(domForm.rbPrevEmp);  reason += rbValidation(domForm.rbPrevApp);  reason += rbValidation(domForm.rbOver18);  reason += rbValidation(domForm.rbDL);  reason += rbValidation(domForm.rbPrevEmp);  reason += rbValidation(domForm.rbAuto);  reason += rbValidation(domForm.rbAutoIns);  reason += rbValidation(domForm.rbComputer);  reason += rbValidation(domForm.rbPrinter);  reason += rbValidation(domForm.rbInternet);  if (reason != "" ) {  	reason = "<li>Please review your selections, all fields are required.</li>";  	document.getElementById("incuestaSummary").innerHTML = reason;		  //scroll window to error message  	scrollToPosition()  	  	//stop processing the page  	return false;  	  } else { //clear any messages that have been generated    	document.getElementById("incuestaSummary").innerHTML = '';  	  }        //Validate the Drop Down Lists  reason = "";  reason = validateDDL(domForm);    if (reason != "" ){   	document.getElementById("rError").innerHTML = reason;    	return false;    }      //Validate the peformance checkbox  reason = "";  reason = validatePerf(domForm);  if( reason != "" ) {  	document.getElementById("pError").innerHTML = reason;  	return false;  }           return true; //continue processing the form}//Validation functions:function validateFirstName(fld) {  //first name validation    var error = "";    if (fld.value.length == 0) {        fld.style.background = '#FFCCCC';        error = "<li>First Name is a required field.</li>"    } else {        fld.style.background = 'White';    }    return error;}function validateLastName(fld) { //last name validation    var error = "";    if (fld.value.length == 0) {        fld.style.background = '#FFCCCC';        error = "<li>Last Name is a required field.</li>"    } else {        fld.style.background = 'White';    }        return error;    } function validateCity(fld) { //city validation	var error = "";		if( fld.value.length == 0 ){		fld.style.background = '#FFCCCC';		error = "<li>City is a required field.</li>"	} else {		fld.style.background = 'White';	}		return error;}function validateZip(fld) { //zip code valiation	var error = "";		if( fld.value.length == 0 ){		fld.style.background = '#FFCCCC';		error = "<li>Zip Code is a required field.</li>"	} else {		fld.style.background = 'White';	}		return error;}function trim(s) { //parses the provided string as listed below  return s.replace(/^\s+|\s+$/, '');  }function validateEmail(fld) { //email validation    var error = "";    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;    if (fld.value == "") {        fld.style.background = '#FFCCCC';        error = "<li>Email address is a required field.</li>";    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters        fld.style.background = '#FFCCCC';        error = "<li>Please enter a valid email address.</li>";    } else if (fld.value.match(illegalChars)) {        fld.style.background = '#FFCCCC';        error = "<li>The email address contains illegal characters.</li>";    } else {        fld.style.background = '#FFFFFF';    }    return error;}function validatePhone(fld) { //phone validation    var error = "";    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');   if (fld.value == "") {        error = "<li>Primary Phone is a required field.</li>";        fld.style.background = '#FFCCCC';    } else if (isNaN(parseInt(stripped))) {        error = "<li>The phone number contains illegal characters.</li>";        fld.style.background = '#FFCCCC';    } else if (!(stripped.length == 10)) {        error = "<li>The phone number is the wrong length. Make sure you included an area code.</li>";        fld.style.background = '#FFCCCC';     } else {        fld.style.background = '#FFFFFF';    }    return error;}function rbValidation(groupName) { //radio button validationvar rbChecked;var error = "";	for (var i=0; i < groupName.length; i++) {			if (groupName[i].checked) {		rbChecked = "1"		}			}			if(!rbChecked){ //if group1Checked does not equal null		error = "1";		} 	return error;}//Drop Down List Validation Functionsfunction validateDDL(objForm){	var error = "";	var ref = objForm.Referer.value	if (ref == 'd0') {		//handle employee referral default		return error = "<li><em>--Select--</em>, is not a valid selection. Please review your choice.</li>";	}		if (ref == 'd6') {		 	if (objForm.rEmpFName.value == '' || objForm.rEmpLName.value == '' || objForm.rEmpCity == '' ) {			//handle employee referral			return error = "<li>All Employee Referral fields are required.</li>";			}	}			if (ref == 'd4' && objForm.rNewspaper.value == '') {		//handle newspaper referral		return error = "<li>Please enter the name of the newspaper.</li>";			}		if (ref == 'd5' && objForm.rWebsite.value == '' ){		//handle other referral		return error = "<li>Please enter the website address.</li>";	}		if (ref == 'd8' && objForm.otherLabel.value == '' ){		//handle other referral		return error = "<li>Please specify <em>other</em>.</li>";	}		return error;}function validatePerf(objForm) {		var error = "";	var perf = objForm.cbPerform;	if (perf.checked == 1 && objForm.jobFunctionOther.value == '') {		//handle work capacity error		error = "<li>This is a required field.</li>";	}	return error;}function scrollToPosition(){  //This function scrolls to the indicated element on the form.  //var theElement = document.formName.elementName; // or document.getElementById("idName")  var theElement = document.getElementById("incuestaHeader")  elemPosX = theElement.offsetLeft  elemPosY = theElement.offsetTop;  theElement = theElement.offsetParent;  while(theElement != null){    elemPosX += theElement.offsetLeft     elemPosY += theElement.offsetTop;    theElement = theElement.offsetParent;  }  window.scrollTo(elemPosX ,elemPosY);}