/* onsubmit="return FormCheck(form_id, zipcode_id)"  --- This needs to go on the form once it is able to launch */

function FormCheck(form_id, zipcode_id) {

    var siteURL ="";
    siteURL ="https://secure.automobile.com/";
	if(zipcode_id == 'image') {
		zipcode = true;
	}else{
		zipcode = document.getElementById(zipcode_id).value
	}

	if(document.getElementById("model") && document.getElementById("year") && document.getElementById("make")) {
		year = document.getElementById("year").value;
		model = document.getElementById("model").value;
		make = document.getElementById("make").value;
		siteURL = siteURL + "?zip=" + zipcode + "&year=" + year + "&make=" + make + "&model=" + model;
	}else{
		if(document.getElementById("make")) {
			make = document.getElementById("make").value;
			siteURL = siteURL + "?zip=" + zipcode + "&make=" + make;
		}else{
			siteURL = siteURL + "?zip=" + zipcode;
		}
	}
    $('#' + zipcode_id).removeClass('error');


	if(zipcode == true) {
			window.open("https://secure.automobile.com/",null,"top=0,left=0,width="+screen.width+",height="+screen.height+",fullscreen=yes,scrollbars=1");
			document.getElementById(form_id).submit();
			return true;
	}else{
		if ( !is_valid_zipcode($('#' +zipcode_id).val()) ) {
			$('#' +zipcode_id).addClass('error');
			alert("Please enter a valid zip code.");
			return false;
			document.getElementById(zipcode_id).focus()
		}else{
			window.open(siteURL,null,"top=0,left=0,width="+screen.width+",height="+screen.height+",fullscreen=yes,scrollbars=1");
			document.getElementById(form_id).submit();
			return true;
		}
	}
}


function FormCheckTR(form_id, zipcode_id) {

    var siteURL ="";
    //siteURL ="http://www.automobile.com/AutoThree/0leadaction.do?curl=automobile.com&from=automobile&sid=TE-A-PCP-1&psv=1";

    //Trouve v2
    siteURL = "https://www.automobile.com/auto/quotes?curl=automobile.com&from=automobile&from=automobile&sid=TE-A-PCP-1&psv=1";

    if(zipcode_id == 'image') {
        zipcode = true;
    }else{
        zipcode = document.getElementById(zipcode_id).value
    }

    $('#' + zipcode_id).removeClass('error');


    if(zipcode != undefined){

        siteURL = siteURL + '&zipCode=' + zipcode;

        if ( !is_valid_zipcode($('#' +zipcode_id).val()) ) {
            $('#' +zipcode_id).addClass('error');
            alert("Please enter a valid zip code.");
            return false;
            document.getElementById(zipcode_id).focus()
        }else{
            window.open(siteURL,null,"top=0,left=0,width="+screen.width+",height="+screen.height+",fullscreen=yes,scrollbars=1");
            document.getElementById(form_id).submit();
            return true;
        }
    }
}

function FormValidation(form_id, zipcode_id) {

	if(zipcode_id == 'image') {
		zipcode = true;
	}else{
		zipcode = document.getElementById(zipcode_id).value
	}

    $('#' + zipcode_id).removeClass('error');



	if(zipcode == true) {
			document.getElementById(form_id).submit();
			return true;
	}else{
		if ( !is_valid_zipcode($('#' +zipcode_id).val()) ) {
			$('#' +zipcode_id).addClass('error');
			alert("Please enter a valid zip code.");
			return false;
			document.getElementById(zipcode_id).focus()
		}else{
			document.getElementById(form_id).submit();
			return true;
		}
	}
	return false;
}


