function ValidateForm()
{
	var strErr = "";
	
    //Clear any old error messages;     
    var zipCode = document.getElementById('ZipCode').value;
    var insuranceType = document.getElementById('InsuranceTypeID').value;
    if (insuranceType == "" && document.getElementById('InsuranceTypeID').type == "hidden"){
        insuranceType = document.getElementById('InsuranceTypeID').defaultValue;
    }
	
	var isValid = true;
	if (!IsValidInsuranceType(insuranceType)){	    
	    isValid = false;	    
	}
	if (!IsValidZip(zipCode)){
	    isValid = false;
	}
	
	
	if (!document.getQuoteForm.Insured[0].checked && !document.getQuoteForm.Insured[1].checked) {
		strErr = strErr + "Currently Insured is required and you must select Yes or No.\n";
	}
	if (strErr != "") {
		alert(strErr);
		return false;
	}
	preserveRefby();
	return true;
	return isValid;
}

function trim(str){
	return((" "+ str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,"$1"));
}
var insuranceTypes = new Array('auto', 'home', 'health', 'life', 'ltc', 'autohome');
function IsValidInsuranceType(type)
{    
    var isValid = false;    
    for (var i = 0; i < insuranceTypes.length && !isValid; i++)
    {
        var currentInsuranceID = insuranceTypes[i];
        if (type.toLowerCase() == currentInsuranceID){
            isValid = true;            
        }
    }
    if (isValid == false){
        var insuranceTypeIDElement = document.getElementById('InsuranceTypeID');        
        if (insuranceTypeIDElement.type != "hidden"){
            insuranceTypeIDElement.focus();
        }
        var errorMessageElement = document.getElementById('errorMessageNoInsTypeSelected');
        //If the user has already entered a correct insurance type they will not be shown the 
        //page that has this error message.
        if (errorMessageElement != undefined){
            document.getElementById('errorMessageNoInsTypeSelected').style.display = 'block';
            insuranceTypeIDElement.focus();
        }        
    }
    else {
        var errorMessageElement = document.getElementById('errorMessageNoInsTypeSelected');
        //If the user has already entered a correct insurance type they will not be shown the 
        //page that has this error message.
        if (errorMessageElement != undefined){
            document.getElementById('errorMessageNoInsTypeSelected').style.display = 'none';
        }
    }
    return isValid;
}