function doValidation(theForm)
{
	/* Allows only valid Email address. */
	var checkStr=theForm.email.value;
	if(checkStr=="" || checkStr.lastIndexOf("@")==-1 || checkStr.lastIndexOf(".")==-1)
	{
	alert("Please enter a valid Email address");
	theForm.email.focus();
	return false;
	}

	var emailArr=checkStr.split("@");
	var user = new String( emailArr[0] );
	var domainAddress = new String( emailArr[1] );
	var domainAddressArr = domainAddress.split(".");
	var domain = new String( domainAddressArr[0] );
	var net = new String( domainAddressArr[1] );
	
	if(user.length==0)
	{
	alert("Please enter a valid Email address.");
	theForm.email.focus();
	return false;	
	}
	if(domain.length==0)
	{
	alert("Please enter a valid Email address.");
	theForm.email.focus();
	return false;
	}
	if(net.length==0)
	{
	alert("Please enter a valid Email address.");
	theForm.email.focus();
	return false;
	}
	/* name */
    var checkStr=theForm.firstname.value;
	if (checkStr == null || checkStr == "" || isNaN(checkStr)==false) {
		alert("Please enter a valid first name.");
		theForm.firstname.focus();
		return (false);
	}
	
	var checkStr=theForm.lastname.value;
	if (checkStr == null || checkStr == "" || isNaN(checkStr)==false) {
		alert("Please enter a valid last name.");
		theForm.lastname.focus();
		return (false);
	}

	if (!checkEmptyField (theForm.address, "Please enter a valid address.")) {
		return false;
	}

	if (!checkEmptyField (theForm.city, "Please enter a valid city.")) {
		return false;
	}
	/*  valid State */
	checkStr=theForm.state[ theForm.state.selectedIndex ].value;
	if (checkStr == null || checkStr == "") {
		alert("Please select a state.");
		theForm.state.focus();
		return (false);
	}
	/* valid Zip */
	if (!checkZip (theForm)) {
		return false;
	}

	checkStr=valRadioButtons(theForm.gender);
	if (checkStr == null || checkStr == "") {
		alert("Please select your gender.");
		return (false);
	}
	
	var filledOut = true;

	filledOut = checkEmptyField (theForm.bmonth, "Please select your date of birth.");
	if (!filledOut) {
		return false;
	}
	filledOut = checkEmptyField (theForm.bday, "Please select your date of birth.");
	if (!filledOut) {
		return false;
	}

	var currentTime = new Date()
	var year = currentTime.getFullYear()
	checkStr=theForm.byear.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=4 || checkStr<1920 || checkStr>year){
	alert("Please select your date of birth.");
	theForm.byear.focus();		
	return(false);
	}
	/* phones */
	checkStr=theForm.dayareacode.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=3){
	alert("Please enter a valid day phone number");
	theForm.dayareacode.focus();
	return(false);
	}

	checkStr=theForm.dayprefix.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=3){
	alert("Please enter a valid day phone number.");
	theForm.dayprefix.focus();
	return(false);
	}

	checkStr=theForm.dayphone.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=4){
	alert("Please enter a valid day phone number.");
	theForm.dayphone.focus();
	return(false);
	}

	checkStr=theForm.eveareacode.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=3){
	alert("Please enter valid evening phone number.");
	theForm.eveareacode.focus();
	return(false);
	}

	checkStr=theForm.eveprefix.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=3){
	alert("Please enter valid evening phone number.");
	theForm.eveprefix.focus();
	return(false);
	}

	checkStr=theForm.evephone.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr) || checkStr.length!=4){
	alert("Please enter valid evening phone number.");
	theForm.evephone.focus();
	return(false);
	}
	/* Best time */
	checkStr = theForm.bestime[ theForm.bestime.selectedIndex ].value;
	if (checkStr == null || checkStr == "") {
		alert("Please select the best time for contact.");
		theForm.bestime.focus();
		return (false);
	}
	/* hhincome */
	checkStr = theForm.hhincome[ theForm.hhincome.selectedIndex ].value;
	if (checkStr == null || checkStr == "") {
		alert("Please select the approximate household income.");
		theForm.hhincome.focus();
		return (false);
	}
	/* current res.status */
	checkStr = theForm.resstatus[ theForm.resstatus.selectedIndex ].value;
	if (checkStr == null || checkStr == "") {
		alert("Please select your current residence status.");
		theForm.resstatus.focus();
		return (false);
	}
	
	/* current res. years */
	checkStr = theForm.ycr[ theForm.ycr.selectedIndex ].value;
	if (checkStr == null || checkStr == "") {
		alert("Please select years/months at current residence.");
		theForm.ycr.focus();
		return (false);
	}
	/* current res. months */
	checkStr = theForm.mcr[ theForm.mcr.selectedIndex ].value;
	if (checkStr == null || checkStr == "") {
		alert("Please select years/months at current residence.");
		theForm.mcr.focus();
		return (false);
	}
	
	/* insurance? */
	checkStr=valRadioButtons(theForm.hownerins);
	if(checkStr == null || checkStr == ""){
		alert("Do you currenltly have Homeowner\'s Insurance?");
		return (false);
	}

	/* losses */
	checkStr=valRadioButtons(theForm.losses);
	if(checkStr == null || checkStr == ""){
		alert("Have you reported any claims of losses to your insurance company within the past 5 years?");
		return (false);
	}
	
	/* propery type */
	checkStr=theForm.proptype[ theForm.proptype.selectedIndex ].value;
	if(checkStr == null || checkStr == ""){
	alert("Please select your propery type.");
	theForm.proptype.focus();
	return(false);
	}

	/* owner? */
	checkStr=valRadioButtons(theForm.owner);
	if(checkStr == null || checkStr == ""){
		alert("Do you currently own this property?	");
		return (false);
	}

	/* property - year */
	var checkStr=theForm.ypb.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr)){
	alert("Year property build?");
	theForm.ypb.focus();
	return(false);
	}
	/* property - square footage */
	var checkStr=theForm.sfr.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr)){
	alert("Square footage of residence?");
	theForm.sfr.focus();
	return(false);
	}
	/* how many bedrooms */
	var checkStr=theForm.nbeds.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr)){
	alert("How many bedrooms?");
	theForm.nbeds.focus();
	return(false);
	}
	/* how many bathrooms */
	var checkStr=theForm.nbaths.value;
	if(checkStr == null || checkStr == "" || isNaN(checkStr)){
	alert("How many bathrooms?");
	theForm.nbeds.focus();
	return(false);
	}
	/* credit rating */
	checkStr=valRadioButtons(theForm.creditrating);
	if (checkStr == null || checkStr == "") {
		alert("Please select credit rating.");
		return (false);
	}
	
    return (true);
}

function checkEmptyField (fieldObj, message)
{
	var checkStr=fieldObj.value;

	if(checkStr == null || checkStr == "") {
		alert(message);
		fieldObj.focus();
		return false;
	}

	return true;
}

function checkZip (theForm)
{
	var objRegExp = /(^\d{5}$)/;
	//check for valid US Zipcode
	if (!objRegExp.test(theForm.zip.value)) {
		alert("Please enter a valid zip.");
		theForm.zip.focus();
		return false;
	}
	return true;
}

function addYearsCombo() {
	for (i=1920;i<=1982;i++) {
		document.write("<option value='"+i+"'>"+i+"</option>");
	}
}

function addHeightCombo() {
	for (i=80;i<=350;i++) {
		document.write("<option value='"+i+"'>"+i+"</option>");
	}
}

function valRadioButtons(btn)
{
	var cnt = -1;
	for (var i=btn.length-1; i > -1; i--) {
   		if (btn[i].checked) {cnt = i; i = -1;}
   	}
	if (cnt > -1) return btn[cnt].value;
	else return null;
}
