var root_dir = "/pyro/";

function ValidateForm()
{
	var strErr = "";
	var typeId = "";
	if (document.getQuoteForm.Type.value == "none") {
		strErr = strErr + "You must select an insurance type.\n";
	}
	var tmpZip = trim(document.getQuoteForm.zip.value);
	document.getQuoteForm.zip.value = tmpZip;
	if(($("#Type").val()!="Canadian") && ($("#Type").val()!="Motorcycle") && ($("#Type").val()!="Dental"))
	{
		if (tmpZip.search(/^\d{5}/) == -1 ||  tmpZip.length > 5) {
			strErr = strErr + "Zip Code is required and must be in the format 00000.\n";
		}
	}
	if (strErr != "") {
		alert(strErr);
		return false;
	}
	typeId = $("#Type").val();
	var show=document.getQuoteForm.showAPI.value;
	if(show==1)
	if(typeId=="Home" | typeId=="Auto" | typeId=="Health")
		window.open('http://quickquotesite.com/Common/Landing.php?Type='+typeId+'&zip='+tmpZip);	
	if(typeId=="Motorcycle")
	{
		window.open('http://www.dpbolvw.net/click-2859423-10472177');
		//location.replace("http://www.dpbolvw.net/click-2859423-10472177");
		return false;

	}else if(typeId=="Dental"){
		window.open('http://www.dentalplans.com/afftracker.asp?affid=14586');
		//location.replace("http://www.dentalplans.com/afftracker.asp?affid=14586");
		return false;
	}else if(typeId=="Canadian"){
		window.open('http://www.kanetix.ca/affsho?ClickID=086766');
		//location.replace("http://www.kanetix.ca/affsho?ClickID=086766");
		return false;
	}else{
		swapRefby();
		//document.getQuoteForm.submit();
		return true;
	}
}

function trim(str){
    return((" "+ str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,"$1"));
}

function swapRefby(){
    switch(document.getQuoteForm.Type.value){
        case "Auto":
            document.getElementById("Refby").value = "609996";
            break;
        case "Home":
            document.getElementById("Refby").value = "609997";
            break;
        case "AutoHome":
            document.getElementById("Refby").value = "609938";
            break;
        case "Health":
            document.getElementById("Refby").value = "609998";
            break;
        case "Life":
            document.getElementById("Refby").value = "610000";
            break;
        case "LTC":
            document.getElementById("Refby").value = "610001";
            break;
		case "Motorcycle":
          	location.replace("http://www.dpbolvw.net/click-2859423-10472177");
            break;
		case "Dental":
          	location.replace("http://www.dentalplans.com/afftracker.asp?affid=14586");
            break;
		case "Canadian":
          	location.replace("http://www.kanetix.ca/affsho?ClickID=086766");
            break;
        default:
    }
}

$(document).ready(function(){
	$("#get-a-quote-action").click(function(){
		if($("#get-a-quote").length>=1)
		{
			return true;
		}else{
			location.replace(root_dir);
		}
	});
});


