Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(c===0)return-1;var d=0;arguments.length>0&&(d=Number(arguments[1]),d!==d?d=0:d!==0&&d!==1/0&&d!==-Infinity&&(d=(d>0||-1)*Math.floor(Math.abs(d))));if(d>=c)return-1;var e=d>=0?d:Math.max(c-Math.abs(d),0);for(;e<c;e++)if(e in b&&b[e]===a)return e;return-1}),jQuery(function(a){var b={cat:!1,constr:!1,mod:!1,prixMin:!1},c=[],d=[],e=[],f=[],g=[],h=function(b,c,d){d=d||[],b.empty(),b.append(a("<option/>").text(c).val("")),a.each(d,function(c,d){b.append(a("<option/>").text(d[0]).val(d[1]))}),b.attr("selectedIndex",0),b.prev("span").text(b.find("option").eq(0).text())},i=function(a,b){return a[0]<b[0]?-1:a[0]>b[0]?1:0},j=function(a,b){return a[1]<b[1]?-1:a[1]>b[1]?1:0},k=function(a,b){a.text(b.substring(0,15)+(b.length>15?"...":""))},l=function(a){return(""+a).replace(/(\d*)(\d{3})$/,"$1 $2")};fromCat=function(e,f){k($spanCat,typeof f!="undefined"?$selectCat.find("option").eq(f).text():$selectCat.find("option").eq(0).text());var g=[],j=[],l=[],m=0;typeof e=="undefined"||e==""?b.cat=e=!1:b.cat=e,a.each(raw.constructeurs,function(b,f){a.each(f.modeles,function(b,h){m++,a.each(h.vehicules,function(a,b){if(e===!1||b.categorie==d[c.indexOf(e)][0])l.indexOf(h.id)<0&&l.push(h.id),j.indexOf(f.id)<0&&(j.push(f.id),g.push([f.name,f.id]))})})}),$fieldParent.val(e===!1?"":l.join(",")),g.sort(i),h($selectMarq,"Marque",g),g.length===0?$selectMarq.attr("disabled","disabled"):$selectMarq.removeAttr("disabled"),g.length===0?$spanMarq.parent().addClass("disabled"):$spanMarq.parent().removeClass("disabled"),h($selectModel,"Mod\u00e8le"),$selectModel.attr("disabled","disabled"),$spanModel.parent().addClass("disabled")},fromMarq=function(e,f){k($spanMarq,typeof f!="undefined"?$selectMarq.find("option").eq(f).text():$selectMarq.find("option").eq(0).text());var g=[],j=[],l=[],m;typeof e=="undefined"||e==""?(b.constr=!1,fromCat(b.cat,$selectCat[0].selectedIndex)):(a.each(raw.constructeurs,function(a,c){c.id==e&&(b.constr=e=c)}),m=b.cat,a.each(e.modeles,function(b,e){a.each(e.vehicules,function(a,b){(m===!1||b.categorie==d[c.indexOf(m)][0])&&l.indexOf(e.id)<0&&(l.push(e.id),j.push(e.id),g.push([e.name,e.id]))})}),$fieldParent.val(j.join(",")),g.sort(i),g.length===0?$selectModel.attr("disabled","disabled"):$selectModel.removeAttr("disabled"),g.length===0?$spanModel.parent().addClass("disabled"):$spanModel.parent().removeClass("disabled"),h($selectModel,"Mod\u00e8le",g))},fromModel=function(c,d){k($spanModel,typeof d!="undefined"?$selectModel.find("option").eq(d).text():$selectModel.find("option").eq(0).text());var e,f,g=[];e=b.cat;typeof c=="undefined"||c==""?(b.mod=!1,fromMarq(b.constr&&b.constr.id,$selectMarq[0].selectedIndex)):(a.each(raw.constructeurs,function(d,e){a.each(e.modeles,function(a,d){d.id==c&&(b.mod=c=d)})}),$fieldParent.val(c.id))},$form=a("#accueil-search form").eq(0),$fieldParent=a('<input type="hidden"/>').appendTo($form).attr({name:searchid+"field_parent"}).val(""),$divCat=a("<div>").addClass("select-like").appendTo($form),$spanCat=a("<span>").appendTo($divCat).text("Cat\u00e9gorie"),$selectCat=a("<select>").appendTo($divCat).attr("name",searchid+"field_carosserie"),$divMarq=a("<div>").addClass("select-like").appendTo($form),$spanMarq=a("<span>").appendTo($divMarq).text("Marque"),$selectMarq=a("<select>").appendTo($divMarq).attr({name:"marque"}),$divModel=a("<div>").addClass("select-like").appendTo($form),$spanModel=a("<span>").appendTo($divModel).text("Mod\u00e8le"),$selectModel=a("<select>").appendTo($divModel).attr({name:"modele"}),$divEnergie=a("<div>").addClass("select-like").appendTo($form),$spanEnergie=a("<span>").appendTo($divEnergie).text("Energie"),$selectEnergie=a("<select>").appendTo($divEnergie).attr({name:searchid+"field_energie"}),$fieldsetPrix=a("<fieldset>").addClass("prix").appendTo($form),$divPrixMin=a("<div>").addClass("select-like min").appendTo($fieldsetPrix),$spanPrixMin=a("<span>").appendTo($divPrixMin).text("Prix mini."),$selectPrixMin=a("<select>").appendTo($divPrixMin).attr({name:searchid+"field_prix_min"}),$divPrixMax=a("<div>").addClass("select-like max").appendTo($fieldsetPrix),$spanPrixMax=a("<span>").appendTo($divPrixMax).text("Prix maxi."),$selectPrixMax=a("<select>").appendTo($divPrixMax).attr({name:searchid+"field_prix_max"}),$submit=a('<input type="submit"/>').appendTo($form).attr({id:searchid+"submitsearch",name:searchid+"submitsearch",className:"submit",value:"Lancer la recherche"}),$selectCat.append(a("<option/>").text("Cat\u00e9gorie").val("")),a.each(raw.constructeurs,function(b,g){a.each(g.modeles,function(b,g){a.each(g.vehicules,function(a,b){c.indexOf(b.catid)<0&&b.catid!=""&&(c.push(b.catid),d.push([b.categorie,b.catid])),e.indexOf(b.energieid)<0&&b.energieid!=""&&(e.push(b.energieid),f.push([b.energie,b.energieid]))})})});var m=[].concat(d).sort(i);h($selectCat,"Cat\u00e9gorie",m),f.sort(i),h($selectEnergie,"Energie",f);for(var n=3e3;n<1e5;n+=1500)g.push([l(n)+" \u20ac",n]);h($selectPrixMin,"Prix mini.",g),h($selectPrixMax,"Prix maxi.",g),fromCat(),$selectCat.change(function(){fromCat(a(this).val(),this.selectedIndex)}),$selectMarq.change(function(){fromMarq(a(this).val(),this.selectedIndex)}),$selectModel.change(function(){fromModel(a(this).val(),this.selectedIndex)}),$selectEnergie.change(function(){k($spanEnergie,$selectEnergie.find("option").eq(this.selectedIndex).text())}),$selectPrixMin.change(function(){k($spanPrixMin,$selectPrixMin.find("option").eq(this.selectedIndex).text())}),$selectPrixMax.change(function(){k($spanPrixMax,$selectPrixMax.find("option").eq(this.selectedIndex).text())})})
