nReferrerNumber = 0; nDetailNumber = 0; AutoMakeName=new Array(0); AutoMakeNumber=new Array(0); AutoModels=new Array(0); Years=new Array(0); var strDefYear = ""; var strDefMake = ""; var strDefModel = ""; //Begin JS var nSelectorType = 1; nSelectorType = 5; var nCounter, nYear, nMakeIndex, strDefZip, nStartOffset; function initializeDVS() { strDefZip = ""; if (GetCookie("CkZip") != "") strDefZip = GetCookie("CkZip"); document.DealixVehicleSelector.refid.value = nReferrerNumber; document.DealixVehicleSelector.detid.value = nDetailNumber; if (strDefZip != "") document.DealixVehicleSelector.zip.value = strDefZip; nStartOffset = 1; //Check to see if default is valid model with(document.DealixVehicleSelector) { for(var i = 0; AutoMakeName[i] != null; i++) { if (AutoMakeName[i] == strDefMake || AutoMakeNumber[i] == strDefMake) { nStartOffset = 0; } } } PopulateMake(); } function ResetMenu() { with(document.DealixVehicleSelector) { if (nSelectorType != 3 && nSelectorType != 4 && nSelectorType != 5) { year.options[0] = new Option(strDefYear, 0); year.options.length = 1; year.options.selectedIndex = 0; year.disabled = true; } model.options[0] = new Option(strDefModel, 0); model.options.length = 1; model.options.selectedIndex = 0; model.disabled = true; } } function PopulateMake() { with(document.DealixVehicleSelector) { if (nStartOffset == 1) { make.options[0].text = strDefMake; } for(var i = 0; AutoMakeName[i] != null; i++) { make.options[i+nStartOffset] = new Option(AutoMakeName[i], AutoMakeNumber[i]); if (AutoMakeName[i] == strDefMake || AutoMakeNumber[i] == strDefMake) { make.options.selectedIndex = i; } } if (make.options.selectedIndex == -1) { make.options.selectedIndex = 0 } if (nSelectorType == 3 || nSelectorType == 4 || nSelectorType == 5) { PopulateSuperModel(); } else { PopulateYear(); } } } function PopulateYear() { nCounter = 0 with(document.DealixVehicleSelector) { if (make.options[make.options.selectedIndex].value == 0 || make.options[make.options.selectedIndex].value == "") { ResetMenu(); } else { //Test to see if strDefaultYear is valid year var bDefaultIsValid = false; for(var i = 0; Years[i] != null; i++) { if (Years[i] == strDefYear) bDefaultIsValid = true; } //Now populate & select default year.disabled = false; year.options.length = 1; for(var i = 0; Years[i] != null; i++) { if (AutoModels[make.options.selectedIndex-nStartOffset][Years[i]] != null) { year.options[nCounter] = new Option(Years[i], Years[i]); if (bDefaultIsValid) { if (Years[i] == strDefYear) year.options.selectedIndex = nCounter; } else { if (Years[i] == strCurrentModelYear) year.options.selectedIndex = nCounter; } nCounter++; } } if (year.options.selectedIndex == -1) { year.options.selectedIndex = 0 } PopulateModel(); } } } function PopulateModel() { with(document.DealixVehicleSelector) { model.disabled = false; model.options.length = 1; nCounter = 0 nYear = year.options[year.options.selectedIndex].value; nMakeIndex = make.options.selectedIndex-nStartOffset; if (nStartOffset == 1) { model.options[0].text = strDefModel; model.options[0].value = 0; } for(var i = 0; AutoModels[nMakeIndex][nYear][i] != null; i=i+2) { model.options[nCounter+nStartOffset] = new Option(AutoModels[nMakeIndex][nYear][i], AutoModels[nMakeIndex][nYear][i + 1]); if (AutoModels[nMakeIndex][nYear][i] == strDefModel && make.options[make.selectedIndex].text == strDefMake) model.options.selectedIndex = nCounter+nStartOffset; nCounter++; } if (model.options.selectedIndex == -1) { model.options.selectedIndex = 0 } } } function RefreshYear() { //Used when only 2 dropdowns are present (supermodel) with(document.DealixVehicleSelector) { nYear = model.options[model.options.selectedIndex].text.substring(0,4); year.value = nYear; } } function PopulateSuperModel() { with(document.DealixVehicleSelector) { model.disabled = false; model.options.length = 1; nCounter = 0 nMakeIndex = make.options.selectedIndex-nStartOffset; if (nStartOffset == 1) { model.options[0].text = strDefModel; model.options[0].value = 0; } if (make.options[make.options.selectedIndex].value == 0 || make.options[make.options.selectedIndex].value == "") { ResetMenu(); } else { //Loop through Years array for(var i = 0; Years[i] != null; i++) { nYear = Years[i]; if (AutoModels[nMakeIndex][nYear] != null) { if (nCounter == 0) year.value = nYear; //Loop through AutoModels array for each year in Years array for(var i2 = 0; AutoModels[nMakeIndex][nYear][i2] != null; i2=i2+2) { model.options[nCounter+nStartOffset] = new Option(nYear + " " + AutoModels[nMakeIndex][nYear][i2], AutoModels[nMakeIndex][nYear][i2 + 1]); //Auto-Select Defaults if (strDefModel == "NULL" && nYear == strDefYear && i2 == 0) { model.options.selectedIndex = nCounter+nStartOffset; year.value = nYear; } else if ((AutoModels[nMakeIndex][nYear][i2] == strDefModel && nYear == strDefYear && make.options[make.selectedIndex].text == strDefMake) || (AutoModels[nMakeIndex][nYear][i2 + 1] == strDefModel && make.options[make.selectedIndex].value == strDefMake && (nYear == strDefYear || isNaN(strDefYear) == true || strDefYear == ""))) { model.options.selectedIndex = nCounter+nStartOffset; year.value = nYear; } nCounter++; } } } if (model.options.selectedIndex == -1) { model.options.selectedIndex = 0 } } } } function SetCookies() { with(document.DealixVehicleSelector) { document.cookie = "CkZip=" + zip.value; } } function GetCookie(strName) { var strSearch = strName + "=" var strReturn = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(strSearch) if (offset != -1) { offset += strSearch.length end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; strReturn = unescape(document.cookie.substring(offset, end)) } } return strReturn; } function ClearZipText(strOriginalText) { if (document.DealixVehicleSelector.zip.value == strOriginalText) { document.DealixVehicleSelector.zip.value = ""; } } function RestoreZipText(strOriginalText) { if (document.DealixVehicleSelector.zip.value == "") { document.DealixVehicleSelector.zip.value = (strDefZip == "") ? strOriginalText : strDefZip; } } if (nSelectorType == 2) { //Year-Make-Model document.write("
"); document.write("
"); document.write("
"); document.write("
"); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write("
"); } else if (nSelectorType == 3) { //Make-Supermodel document.write("
"); document.write("
"); document.write("
"); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write("
"); } else if (nSelectorType == 4) { //Make-Supermodel document.write("
"); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write("
"); } initializeDVS();