var omyVLD=null;omyVL={DEBUG:false,COOKIE_MYVEHICLES:"owners.myvehicles",COOKIE_SELECTED:"owners.selected",COOKIE_DURATION:"730",SELECTMYSAVED:"mysaved",SAVED_VEHICLES_FORM:"o-my-vehicle-saved",SELECT_VEHICLES_FORM:oVL.SELECT_VEHICLES_FORM,START_HERE_MESSAGE:"o-my-vehicle-start-here",SELECT_INDX:0,IMAGE_PATH:"/shared/images/owners/vehicles/",DEFAULT_IMAGE:"dodge_placeholder.jpg",ADD:"add",myOBI:-1,myOYI:-1,myOVI:-1,myOMI:-1,init:function(){var myVehicles=Cookie.get(this.COOKIE_MYVEHICLES);var mySelected=Cookie.get(this.COOKIE_SELECTED);if(mySelected){this.DEBUG?(alert("cookie value:\n\n "+mySelected)):null;this.SELECT_INDX=mySelected;}if(myVehicles){$(this.START_HERE_MESSAGE).setStyle("display","none");$(this.SELECT_VEHICLES_FORM).setStyle("display","none");$(this.SAVED_VEHICLES_FORM).setStyle("display","block");omyVLD=eval(myVehicles);this.DEBUG?(alert("cookie value:\n\n "+myVehicles)):null;this.DEBUG?(alert("We heard that you own these vehicles\n\n "+this.toString())):null;this.loadMyVehicleList();}else{$(this.SAVED_VEHICLES_FORM).setStyle("display","none");$(this.SELECT_VEHICLES_FORM).setStyle("display","block");$(this.START_HERE_MESSAGE).setStyle("display","block");}},saveVehicle:function(b){this.insertVehicle(b.myyear[b.myyear.selectedIndex].text,b.mybrand[b.mybrand.selectedIndex].text,b.myvehicle[b.myvehicle.selectedIndex].text);this.setMyVehiclesCookie();this.loadMyVehicleList();this.DEBUG?(alert("From Save Vehicle\n\nloaded.length: "+omyVLD.length+"\nloaded[0].year: "+omyVLD[0].year)):null;$(this.START_HERE_MESSAGE).setStyle("display","none");$(this.SELECT_VEHICLES_FORM).setStyle("display","none");$(this.SAVED_VEHICLES_FORM).setStyle("display","block");return false;},addVehicle:function(h,g,f){var e=0;if(omyVLD){e=omyVLD.length;}else{omyVLD=new Array();}omyVLD[e]={brand:g,year:h,nameplate:f};this.DEBUG?(alert("Added Vehicle\n\nomyVLD.length: "+omyVLD.length+"\ni: "+e+"\nYear: "+omyVLD[e].year+"\nBrand: "+omyVLD[e].brand+"\nNameplate: "+omyVLD[e].nameplate)):null;},insertVehicle:function(k,h,g){var f=0;var j=0;if(omyVLD){j=omyVLD.length;for(f=omyVLD.length;f>0;f--){if((omyVLD[f-1].year>k)||((omyVLD[f-1].year==k)&&(omyVLD[f-1].nameplate>g))){omyVLD[f]=omyVLD[f-1];j=f-1;this.DEBUG?(alert("omyVLD[i-1].year > year\n"+omyVLD[f-1].year+" > "+k+"\n\n"+this.toString())):null;}}}else{omyVLD=new Array();}omyVLD[j]={brand:h,year:k,nameplate:g};this.SELECT_INDX=j;this.setCookie(this.SELECT_INDX);},removeSelectedVehicle:function(){var c=$("mysaved").selectedIndex;var d=$("mysaved").options[c].value;if(d!=this.ADD){this.removeVehicle(c);}},removeVehicle:function(h){var e=0;var f=0;var g=new Array();this.SELECT_INDX=h;if(omyVLD){for(e=0;e<omyVLD.length;e++){if(e!=h){g[f++]=omyVLD[e];}}}this.DEBUG?(alert("vehIndx: "+h+"\ntmpVLD.length: "+g.length+"\nomyVLD.length: "+omyVLD.length)):null;omyVLD=null;omyVLD=g;this.DEBUG?(alert("Removed Vehicle\n\nomyVLD.toString: "+this.toString())):null;if(omyVLD&&omyVLD.length==0){this.DEBUG?(alert("Reset EMPTY start")):null;omyVLD=null;this.SELECT_INDX=0;Cookie.remove(this.COOKIE_SELECTED);Cookie.remove(this.COOKIE_MYVEHICLES);oVL.resetForm();this.myOBI=-1;this.myOYI=-1;this.myOVI=-1;this.myOMI=-1;$(this.SAVED_VEHICLES_FORM).setStyle("display","none");$(this.SELECT_VEHICLES_FORM).setStyle("display","block");$(this.START_HERE_MESSAGE).setStyle("display","block");oVL.resetForm();$("o-vehicle-specs-link-known").setStyle("display","none");$("o-vehicle-specs-link").setStyle("display","inline");this.DEBUG?(alert("Reset EMPTY end")):null;}else{this.setMyVehiclesCookie();this.loadMyVehicleList();}},loadMyVehicleList:function(){var g=$(this.SELECTMYSAVED);var f=null;this.clearOptList(this.SELECTMYSAVED,0);if(omyVLD){for(var h=0;h<omyVLD.length;h++){f=document.createElement("option");f.setAttribute("value",h);f.text=omyVLD[h].year+" "+omyVLD[h].brand+" "+omyVLD[h].nameplate;try{g.add(f,null);}catch(e){g.add(f);}}}f=document.createElement("option");f.setAttribute("value",this.ADD);f.text="-- Add Vehicle --";try{g.add(f,null);}catch(e){g.add(f);}if(this.SELECT_INDX>=g.length-1&&g.length>1){this.SELECT_INDX=g.length-2;}this.DEBUG?(alert("load vehicles\n\nthis.SELECT_INDX: "+this.SELECT_INDX+"\nlist.length: "+g.length)):null;g.selectedIndex=this.SELECT_INDX;this.getMySelectedVehicleIndex();},clearOptList:function(g,e){var h=$(g);var f=(e==null)?1:e;this.DEBUG?(alert("Clear Vehicles\n\nselectObj: "+g+"\ni: "+f+"\nstartPoint: "+e+"\nlist.length: "+h.length)):null;while(f<h.length){h.options[f]=null;}this.DEBUG?(alert("Cleared Vehicles")):null;},actionVehicle:function(d){var c=$(this.SELECTMYSAVED);this.DEBUG?(alert("Action Vehicle\n\nindx: "+d+"\nlist.selected.text: "+c[d].text)):null;if(c[d].value==this.ADD){this.DEBUG?(alert("Action Add Vehicle")):null;oVL.resetForm();}else{this.SELECT_INDX=d;}this.setCookie(d);this.getMySelectedVehicleIndex();},setCookie:function(b){Cookie.set(this.COOKIE_SELECTED,b,{duration:this.COOKIE_DURATION});},setMyVehiclesCookie:function(){if(omyVLD){Cookie.set(this.COOKIE_MYVEHICLES,this.toString(),{duration:this.COOKIE_DURATION});}},getMySelectedVehicleIndex:function(){this.myOBI=this.getMyBrandIndex(omyVLD[this.SELECT_INDX].brand);this.myOYI=this.getMyYearIndex(this.myOBI,omyVLD[this.SELECT_INDX].year);this.myOVI=this.getMyVehicleIndex(this.myOBI,this.myOYI,omyVLD[this.SELECT_INDX].nameplate);this.updateMyVehicleSpecsLink();this.updateMyVehicleImage("o-my-vehicle-image");this.DEBUG?(this.alertMySelected()):null;},updateMyVehicleImage:function(b){imgtag='<img src="';imgtag+=this.myImageHref();imgtag+='" alt="'+this.myYear()+" "+this.myBrand()+" "+this.myNameplate()+'" />';$(b).setHTML(imgtag);},updateMyVehicleSpecsLink:function(){if(this.hasSpecs()){$("o-vehicle-specs-link").setStyle("display","none");$("o-vehicle-specs-wrapper").setStyle("display","none");$("o-vehicle-specs-link-known").setStyle("display","inline");$("o-vehicle-specs-link-known").href=this.mySpecsHref();}else{$("o-vehicle-specs-link").setStyle("display","none");$("o-vehicle-specs-wrapper").setStyle("display","none");$("o-vehicle-specs-link-known").setStyle("display","inline");$("o-vehicle-specs-link-known").href="javascript:popupMessageLayer(320,75,$('o-popup-non-support').innerHTML);";}},getMyBrandIndex:function(b){if(oVLD){for(i=0;i<oVLD.length;i++){if(oVLD[i].brand==b){return i;}}}},getMyYearIndex:function(c,d){if(oVLD){for(i=0;i<oVLD[c].years.length;i++){if(oVLD[c].years[i].year==d){return i;}}}},getMyVehicleIndex:function(f,d,e){if(oVLD){for(i=0;i<oVLD[f].years[d].vehicles.length;i++){if(oVLD[f].years[d].vehicles[i].nameplate==e){return i;}}}},myBrand:function(){if(oVLD&&this.myOBI!=-1){return oVLD[this.myOBI].brand;}else{return"";}},myBrandID:function(){if(oVLD&&this.myOBI!=-1){return oVLD[this.myOBI].brand_id;}else{return"";}},myYear:function(){if(oVLD&&this.myOYI!=-1){return oVLD[this.myOBI].years[this.myOYI].year;}else{return"";}},myFamily:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].family;}else{return"";}},myNameplate:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].nameplate;}else{return"";}},myImage:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].image;}else{return"";}},myImageHref:function(){tmp=this.myImage();if(tmp==""){tmp=this.DEFAULT_IMAGE;}return this.IMAGE_PATH+tmp;},myWarranty:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].warranty;}else{return"";}},hasWarranty:function(){if(oVLD&&this.myOVI!=-1){if(oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].warranty!=""){return true;}}return false;},myWarrantyHref:function(){var b="";if(this.hasWarranty()){b="/crossbrand/warranty/?brand="+this.myBrandID().toUpperCase()+"&modelyear="+this.myYear()+"&nameplate="+this.myWarranty();}else{b="/crossbrand/warranty/?brand="+this.myBrandID().toUpperCase();}return b;},hasSchedule:function(){if(oVLD&&this.myOVI!=-1){if(oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].schedule!=""){return true;}}return false;},mySchedule:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].schedule;}else{return"";}},myScheduleHref:function(){var b="";if(this.hasSchedule()){b="/download/pdf/maintenance_schedules/"+this.mySchedule();}return b;},hasSpecs:function(){if(oVLD&&this.myOVI!=-1){if(oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].specs!=""){return true;}}return false;},mySpecs:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].specs;}else{return"";}},mySpecsHref:function(){var c="";if(this.hasSpecs()){var d=this.mySpecs();if(d=="autosrc"){c="vehicle_specs/index.html?year="+this.myYear()+"&specs="+escape(this.myNameplate());}else{if(d=="active"){c="/bridge/index.html?app=vehiclespecs&family="+this.myFamily()+"&model=Standard&year="+this.myYear();}else{c="/download/pdf/vehicle_specs/"+d;}}}return c;},hasTowing:function(){if(oVLD&&this.myOVI!=-1){if(oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].towing!=""){return true;}}return false;},myTowing:function(){if(oVLD&&this.myOVI!=-1){return oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].towing;}else{return"";}},myTowingHref:function(){var b="";if(this.hasTowing()){if(this.myTowing()=="active"){b="/bridge/index.html?app=towing&family="+this.myFamily()+"&model=Standard&year="+this.myYear();}else{if(this.myTowing()=="historical"){b="/towing5/D/vehicle_to_weight.jsp";}else{b="";}}}return b;},myManual:function(){if(oVLD&&this.myOVI!=-1){return(oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].manual||oVLD[this.myOBI].years[this.myOYI].vehicles[this.myOVI].qrg);}else{return"";}},myManualHref:function(){var b="/en/owners/manuals/index.html";if(this.myManual()!=""){b="/en/owners/manuals/index.html?year="+this.myYear()+"&nameplate="+escape(this.myNameplate());}return b;},alertMySelected:function(){als="Selected Vehicle";als+="\nBrand: "+this.myBrand();als+="\nYear: "+this.myYear();als+="\nNameplate: "+this.myNameplate();als+="\nFamily: "+this.myFamily();als+="\nImage: "+this.myImage();als+="\nImageHref: "+this.myImageHref();als+="\nWarrantyHref: "+this.myWarrantyHref();als+="\nSpecsHref: "+this.mySpecsHref();als+="\nTowingHref: "+this.myTowingHref();als+="\nManualHref: "+this.myManualHref();alert(als);},toString:function(){var c=null;if(omyVLD){c="[";for(var d=0;d<omyVLD.length;d++){c+='{"brand":"'+omyVLD[d].brand+'",';c+='"year":"'+omyVLD[d].year+'",';c+='"nameplate":"'+omyVLD[d].nameplate+'"},';}c=c.substr(0,c.length-1);c+="]";}return c;}};
