// Locate a Vehicle common functions.

function goVLModel(src, year, modelID, pvc){

	if (modelID.toString().length == 2) {
		modelID = '0'+ modelID;
	}
	
	var url = BASE_CONTEXT + '/tools/vehiclelocator/results.do?year=' + year +
    						'&gmModelId='+modelID + '&searchType=0&proximity=50';

	if (typeof pvc != 'undefined') {
		url += '&pvc='+pvc
		url = url.replace('results.do', 'trimResults.do');
	}

	url += '&postalCode=';

	validateCookie(src, 'goToZipCodeUrl(\'' +url + '\')','vl', false);
}

function goVLModelSM(src, year, modelID, gmModelId, make, pvc, mmc){

	if (modelID.toString().length == 2) {
		modelID = '0'+ modelID;
	}
	console.log("model id: " + modelID);
	var url = BASE_CONTEXT + '/tools/vehiclelocator/results.do?year=' + year +
    						'&modelId='+ modelID +
    						'&make='+ make +
    						'&gmModelId='+ gmModelId + '&searchType=0&proximity=100';

	if (typeof pvc != 'undefined') {
		url += '&pvc='+pvc
		url = url.replace('results.do', 'trimResults.do');
	}

	if (typeof mmc != 'undefined' || mmc == 'undefined' ) url += '&mmcs='+mmc
	
	url += '&postalCode=';

	validateCookie(src, 'goToZipCodeUrl(\'' +url + '\')','vl', false);
}


function goVLModelSMComparator(src,year, modelName){
	var  now = new Date;
	currentYear=now.getYear();
	
	if (currentYear < 1900)
		currentYear=currentYear+1900;
	
	var url = "/";
	if(year == currentYear){
		url += modelName+"/build-to-locate.html";
	}else{
		url += modelName+"/"+year+"/build-to-locate.html";
	}
	
	url += '?postalCode=';

	validateCookie(src, 'goToZipCodeUrl(\'' +url + '\')','vl', false);
}

function goToZipCodeUrl(url){
	console.log("Forwarding to url: " + url);
	var cookieObjValue = getDefaultLocation();
	console.log(cookieObjValue)
	location.href=url+cookieObjValue.zipcode;
}

