

var strTrim;
var modelBox;
function deeplink(){
    modelBox = document.paymentEstimatorForm.vehicle;
    var h = new Object();
    h = keyVals(document.cookie);
    h = keyVals(window.location.search.substring(1).replace(/\+/g, ' '));
    if (typeof h["vehicle"] != "undefined") {
        for (i=0; i<modelBox.options.length; i++){
            if (modelBox.options[i].text == h["vehicle"]) modelBox.selectedIndex = i;
        }
        modelTrigger(h["vehicle"], $('drpTrim'), $('txtZipcode'), DWRUtil.getValue('vehicle'));
    }
    strTrim = h["model"];
//    document.paymentEstimatorForm.txtZipcode.value = typeof h["zip"] != "undefined" ? h["zip"] : "";
    
    if(crmGetCookie('zip'))  //to remove null from the text box and to add the zipcode from cookie
	{
			document.paymentEstimatorForm.txtZipcode.value = crmGetCookie('zip');
			if(crmGetCookie('zip')==null)
				document.paymentEstimatorForm.txtZipcode.value = "";		
	}
}
function keyVals(s){
    var h = new Object();
    var p = s.split(/[&;]/);
    for (var i=0; i<p.length; i++) {
        var n = p[i].split('=');
        while (n[0].charAt(0)==' ') n[0] = n[0].substring(1,n[0].length);
        var k = unescape(n[0]);
        if (n.length == 2) var v = unescape(n[1]);
        h[k] = v;
    }
    return h;        
}
function modelTrigger2(strM, tBox, zBox, yBox) {
	strModel = strM;
	trimBox = tBox;
	zipBox = zBox;
	strYear = yBox;
    
       $('mainCarImageTR').style.visibility = 'visible';
       $('mainCarImage').style.visibility = 'visible';

       $('mainCarImage').src = largeImages[strModel];
	if((strModel != null) && (strModel != SELECT_PROMPT)) PaymentEstimatorFacade.getTrimDataForTheVehicle(strModel, selectTrims);
}
function selectTrims(dwrTrimObj) {
    if(debugMode) alert(DWRUtil.toDescriptiveString(dwrTrimObj, 2));

	try {
		trimBox.options.length = 0;	
		trimBox.options[0] = new Option(TRIM_PROMPT, '');
	
		for(var i = 0; i < dwrTrimObj.length; i++){
			trimBox.options[i+1] = new Option(dwrTrimObj[i], dwrTrimObj[i]);
		    if (dwrTrimObj[i] == strTrim) trimBox.selectedIndex = [i+1];
		}
	} catch(err) {
		//alert(GENERAL_ERROR);
	}
}
addLoadEvent(deeplink);
