var makes = new Array(); //var models = new Array(); //var details = new Array(); addMake(0,'All'); addModel(0,'All'); // addDetail("All",0,"All"); addMake(1,"ACURA"); addModel(1,"1.7 EL"); addModel(1,"MDX"); addModel(1,"TL"); addModel(1,"3.2 TL"); addModel(1,"1.6 EL"); addModel(1,"TSX"); addModel(1,"RSX"); addMake(7,"AUDI"); addModel(7,"A4"); addMake(11,"BMW"); addModel(11,"X3"); addModel(11,"325I"); addModel(11,"325CI SPORTS PKG"); addModel(11,"323 CI"); addModel(11,"330XI"); addModel(11,"X5"); addMake(41,"HONDA"); addModel(41,"ACCORD"); addModel(41,"ELEMENT"); addModel(41,"PILOT EXL"); addModel(41,"CIVIC"); addMake(43,"HYUNDAI"); addModel(43,"ACCENT"); addMake(44,"INFINITI"); addModel(44,"FX 35"); addModel(44,"G35"); addMake(51,"KIA"); addModel(51,"MAGENTS"); addMake(55,"LEXUS"); addModel(55,"ES300"); addMake(59,"MAZDA"); addModel(59,"MAZDA 3"); addModel(59,"MAZDA 6"); addMake(60,"MERCEDES-BENZ"); addModel(60,"CLK320"); addModel(60,"ML350"); addModel(60,"C230"); addMake(68,"NISSAN"); addModel(68,"ALTIMA"); addModel(68,"XTRIAL"); addModel(68,"MURANO"); addModel(68,"MAXIMA"); addMake(75,"PORSCHE"); addModel(75,"BOXSTER"); addMake(89,"TOYOTA"); addModel(89,"CAMRY"); addModel(89,"HIGHLANDER"); addMake(97,"JEEP"); addModel(97,"GRAND CHEROKEE"); addMake(106,"LAND ROVER"); addModel(106,"LR3"); addModel(106,"RANGE ROVER"); /************************************************** * make constructor is just holds the makes index * **************************************************/ function _make(make_index){ this.make_index = make_index; } /************************************************** * Create new Make and added it as an object to * * makes array. * **************************************************/ function addMake(make_index,make_name){ _make[make_name] = new _make(make_index); makes[make_index] = new _createMake(make_name,make_index); } /************************************************** * Create Make Constructor * **************************************************/ function _createMake(make_name,make_index){ this.make_name = make_name; this.make_index = make_index; this.models = new Array(); } /************************************************** * Create new model and added to models array in * * makes array. * **************************************************/ function addModel(model_index,model_name){ makes[model_index].models[model_name] = new _createModel(model_name,model_index); } /************************************************** * Add Model Constructor * **************************************************/ function _createModel(model_name,model_index){ this.model_name = model_name; this.model_index = model_index; this.details = new Array(); } /************************************************** * Create new detail and added to detail array in * * makes array. * **************************************************/ function addDetail(model_name,detail_index,detail_name){ makes[detail_index].models[model_name].details[detail_name] = new _createDetail(detail_name,detail_index); } /************************************************** * Add Detail Constructor * **************************************************/ function _createDetail(detail_name,detail_index){ this.detail_name = detail_name; this.detail_index = detail_index; } /* addMake(1,"dsfsdmaziar"); addModel(1,"hello"); addMake(2,"maziar"); addModel(2,"masoudi"); //addDetail("masoudi",2,"LX"); addMake(3,"ACURA"); addModel(3,"1.6 EL"); addDetail("1.6 EL",3,"SL"); */ //alert(makes[1].models['test'].details['LX'].detail_index); /************************************************** * Load the make menu when page is loaded * **************************************************/ function fillMake(){ var i = 0; try{ document.forms[0].make.options.length = 0; document.forms[0].make.options.selectedIndex = 0; var selectedMake = (makes); for(aMake in selectedMake){ var m_index = selectedMake[aMake].make_index; var m_name = selectedMake[aMake].make_name; document.forms[0].make.options[i++] = new Option(m_name, m_index); } document.forms[0].make.options[0].selected = true; }catch(e){ // alert(e); } //alert(0); } /************************************************** * Load the model menu when make menu is changed* **************************************************/ function fillModel(){ var i = 1; var msg; var menuIndex = document.forms[0].make.selectedIndex; var makeIndex = document.forms[0].make.options[document.forms[0].make.selectedIndex].value; //alert(document.forms[0].make.options[document.forms[0].make.selectedIndex].value); document.forms[0].make.options[menuIndex].selected = true; document.forms[0].model.options.length = 1;//(makeIndex == 0) ? 0 : 1; document.forms[0].model.options.selectedIndex = 0; //alert(makeIndex + " and length is " + document.forms[0].model.options.length); var selectedMake = (makes[makeIndex].models); for(t in selectedMake){ var mo_name = (selectedMake[t].model_name); var mo_index = (selectedMake[t].model_index); document.forms[0].model.options[i++] = new Option(mo_name,mo_index); } } /**************************************************** * Load the detail menu when model menu is changed* ****************************************************/ function fillDetail(){ var i = 1; var msg = ""; // var makeIndex = document.search.make.selectedIndex; // var modelIndex = document.search.model.options[document.search.model.selectedIndex].text; var makeIndex = document.search.make.options[document.search.make.selectedIndex].value; var modelIndex = document.search.model.options[document.search.model.selectedIndex].text; document.search.detail.options.length = 1; document.search.detail.options.selectedIndex = 0; var selectedModel = (makes[makeIndex].models[modelIndex].details); for(d in selectedModel){ var d_name = selectedModel[d].detail_name; var d_index = selectedModel[d].detail_index; document.search.detail.options[i++] = new Option(d_name,d_index); } if(document.search.detail.options[1].text == "None") document.search.detail.options[1].selected = true; } function debug(){ var msg = ""; for(m in makes){ msg += makes[m].make_name + " " +makes[m].make_index + "\n"; var model = (makes[m].models) for(mo in model){ msg += makes[m].models[mo].model_name + makes[m].models[mo].model_index + "\n"; } } alert(msg); }