$(document).ready(function() {
	$('form').submit(function() {
		var form = $(this).attr('name');
		if(FormCheck(form)){
			return true;
		} else return false;
	});					  
});

// TROUVE IMPLEMENTATION FOR THE FOOTER ON THE INDEX
//	siteURL ="https://www.carinsurancerates.com/rates/0leadaction.do";


function is_valid_zipcode(zipcode) {  
    var reg = /^([0-9]{5})$/;
    return reg.test(zipcode); 
}

function FormCheck(form) {
    var siteURL ="";
    var zipcode = $('form[name="'+ form +'"] input:text').val();
	siteURL ="http://www.carinsurancerates.com/auto/index.php";

	if(zipcode!=undefined) {

		if(is_valid_zipcode(zipcode)){
	
			siteURL = siteURL + '?zipCode=' + zipcode + '&curl=carinsurancerates.com&from=carinsurancerates&sid=TE-A-EMP-1&psv=1';
			
			window.open(siteURL,'quote',"top=0,left=0,width="+screen.width+",height="+screen.height+",fullscreen=yes,scrollbars=1");
			return true;

		}else{
			alert("Please enter a valid five digit zip code");
			return false;
		}

	}else{
		// This are for image only forms.
		siteURL = siteURL + '?zipCode=&curl=carinsurancerates.com&from=carinsurancerates&sid=TE-A-EMP-1&psv=1';

		window.open(siteURL,'quote',"top=0,left=0,width="+screen.width+",height="+screen.height+",fullscreen=yes,scrollbars=1");
		return true;
	}
	return false;

}      

