Critere.prototype.constructor = Critere; function Critere(curcat,brand,model,min_price,max_price,mileage,cubic,energy,is_admin,level,ss_categorie){ this.curcat = curcat; this.level = level; this.prefered_brand = (brand?brand.toUpperCase():''); this.prefered_model = (model?model.toUpperCase():''); this.prefered_min_price = min_price; this.prefered_max_price = max_price; this.prefered_mileage = mileage; this.cubic = cubic; this.energy = energy; this.ss_cat_found = ';'; this.is_admin=is_admin; this.ss_cat = (ss_categorie ? ss_categorie:''); this.combo_brand = document.getElementById('brand'); this.combo_pro = document.getElementById('pro_only'); this.combo_model = document.getElementById('model'); this.combo_prix_maxi = document.getElementById('prix_maxi'); this.combo_prix_mini = document.getElementById('prix_mini'); this.combo_mileage = document.getElementById('mileage'); this.combo_cubic = document.getElementById('cubic'); this.combo_Energy = document.getElementById('energie'); this.combo_ss_cat = document.getElementById('SS_CATEGORIE'); this.combo_prix= document.getElementById('prix'); if((curcat=='auto'||curcat=='moto'||curcat=='utils')&& !this.is_admin) this.ob_cat = new Category(curcat,'re',(this.ss_cat!='' ? this.ss_cat:(curcat=='auto'? '40,41,42,43,44,45,46,47,48,49':(curcat=='utils'? '80,81,82,83,84':'60,61,62,63,64,65,66,67,68,69,70,71,72')))); this.setPro(); this.fill_make(); if(level!='1') { this.fill_min_price(); this.fill_max_price(); } else this.fill_price(); if (this.combo_mileage) this.fill_mileage(); if (this.combo_cubic) this.fill_cubic(); this.Init(); } //------------------partie publique-----------------------// Critere.prototype.Init = function() { this.fill_energy(); this.check_crit_categorie(); } Critere.prototype.MakeChange = function() { this.setPrefBrand(); this.fill_model(); } Critere.prototype.CatChange = function(curcat) { if(curcat)this.curcat = curcat; this.fill_make(); this.check_crit_categorie(); if (!this.is_admin) document.form.action = (document.getElementById('galerie')? 'galerie_':'listing_')+(this.curcat=='loisir'?'camping_car-caravane':(this.curcat=='utils'?'utilitaire':(this.curcat=='bateau-moteur') ? 'bateau_moteur':this.curcat))+'.php'; } Critere.prototype.curCatChange = function(cu_ref) { var curc = document.getElementById('CAT').value; if(!curc) return; var locate; locate = '/'+cu_ref+'/admin/Iframe_listing.php?admin='+document.getElementById('admin').value+'&CAT='+curc+'&init=0&SS_CATEGORIE='+ (curc=='auto'? '33,267,269,270,388,40,41,42,43,44,45,46,47,48,49': (curc=='loisir'? '506,507,508,509,510,423,425,426,427,428': (curc=='utils'? '80,81,82,83,84': (curc=='moto' ? '1,605,575,60,61,62,63,64,65,66,67,68,69,72': (curc=='scooter' ? '607,71': (curc=='quad' ? '606,70': (curc=='bateau-moteur' ? '2077,2080,2082,2096,2081,2636,2617,2088,2633,2083,2084,2085,2086,2616,2087,2091': (curc=='voilier' ? '2066,2618,2070,2068,2075,2069,2071,2072,2073,2074,2615,2076': (curc=='moteur' ? '2089':'2090,2060,2199,2092,2094,2095,2097,2065'))))))))); window.location = locate; } Critere.prototype.ModelChange = function() { this.setPrefModel(); } Critere.prototype.MaxPriceChange = function() { this.setPrefMaxPrice(); } Critere.prototype.MinPriceChange = function() { this.fill_max_price(); } Critere.prototype.go_and_submit = function() { if(!document.form) return; document.form.submit(); } Critere.prototype.ProChange = function() { this.setPro(); this.fill_make(); } //------------------partie privée-----------------------// //-----ne doit pas être utilisé par les templates-------// Critere.prototype.setPro = function() { if(!this.combo_pro) return; if (this.combo_pro.options) this.pro = this.combo_pro.value; else if (this.is_admin==1) this.pro=1; else this.pro = (this.combo_pro.checked?'1':'0'); } Critere.prototype.setPrefBrand = function() { this.prefered_brand = this.combo_brand.options[this.combo_brand.selectedIndex].value; } Critere.prototype.setPrefModel = function() { this.prefered_model = this.combo_model.options[this.combo_model.selectedIndex].value; } Critere.prototype.setPrefMaxPrice = function() { this.prefered_max_price = this.combo_prix_maxi.options[this.combo_prix_maxi.selectedIndex].value; } Critere.prototype.fill_cubic = function() { var cat=this.get_cat(); var i; while((i = this.combo_cubic.options.length)>1) this.combo_cubic.options[i-1]=null;/*vide la combo*/ if (this.combo_cubic.options.length==0) this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'Cylindrée', '' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'jusqu\'à 50 cm3', '-1|50' ); if(cat=='607') { this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 51 à 125 cm3', '51|125' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'plus de 125 cm3', '126|-1' ); } else { this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 51 à 80 cm3', '51|80' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 81 à 125 cm3', '81|125' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 126 à 250 cm3', '126|250' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 251 à 400 cm3', '251|400' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 401 à 500 cm3', '401|500' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 501 à 600 cm3', '501|600' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 601 à 750 cm3', '601|750' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 751 à 900 cm3', '751|900' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 901 à 1000 cm3', '901|1000' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 1001 à 1100 cm3','1001|1100' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'de 1101 à 1200 cm3','1101|1200' ); this.combo_cubic.options[this.combo_cubic.options.length] = new Option ( 'plus 1200 cm3', '1201|-1' ); } for(i=0;i=0) { cat_found = false; j=0; while (j0) this.combo_brand.options[i]=null;/*vide la combo*/ var ss_cat; if(document.getElementById('SS_CATEGORIE')){ ss_cat = document.getElementById('SS_CATEGORIE').value; var nb = ss_cat.split(',').length; } var brands=new Array(); if(this.pro=='1') prefix ='[|,P]'; else prefix = '[|,P_]'; idx=this.combo_brand.options.length-1; if (this.combo_brand) idx=this.combo_brand.options.length-1; Ttemp_cat = cat.split(new RegExp(',')); if((this.curcat=='auto'||this.curcat=='moto'||this.curcat=='utils')&& !this.is_admin) compteur = this.ob_cat.getnbCat(); for (i=0;i0) this.combo_model.options[i-1]=null;/*vide la combo*/ this.combo_model.options[0] = new Option ( 'Modèle', '' ); idx=0; Ttemp_cat = cat.split(new RegExp(',')); if(this.pro=='1') prefix ='[|,P]'; else prefix = '[|,P_]'; for (i=0;i1) this.combo_prix_mini.options[i-1]=null;/*vide la combo*/ if (this.combo_prix_mini.options.length==0) this.combo_prix_mini.options[this.combo_prix_mini.options.length] = new Option ( 'Prix minimum' , ''); this.combo_prix_mini.options[this.combo_prix_mini.options.length] = new Option ( 'Moins de ' + min + ' €' , 0 ); if(this.prefered_min_price=='0') this.combo_prix_mini.options[this.combo_prix_mini.options.length-1].selected=true; for(i=min;i<=max;i+=step) { this.combo_prix_mini.options[this.combo_prix_mini.options.length] = new Option ( format(i) + ' €' , i ); if((this.prefered_min_price!='')&&(i==this.prefered_min_price))this.combo_prix_mini.options[this.combo_prix_mini.options.length-1].selected=true; } if(this.curcat=='voilier'||this.curcat=='moteur'||this.curcat=='bateau-moteur') { this.combo_prix_mini.options[this.combo_prix_mini.options.length] = new Option ('Plus de '+format(500000)+' €' , 500000 ); if((this.prefered_min_price!='')&&(this.prefered_min_price==500000))this.combo_prix_mini.options[this.combo_prix_mini.options.length-1].selected=true; } } Critere.prototype.fill_max_price = function() { /*fill max price combo*/ if (!this.combo_prix_maxi) return; var min_price; if (this.combo_prix_mini.selectedIndex >-1) min_price = this.combo_prix_mini.options[this.combo_prix_mini.selectedIndex].value; else min_price=0; if (this.combo_prix_mini.selectedIndex==1) { this.combo_prix_maxi.selectedIndex=-1; this.combo_prix_maxi.disabled=true; } else this.combo_prix_maxi.disabled=false; var step = (this.curcat!='voilier'&&this.curcat!='bateau-moteur'&&this.curcat!='moteur'&&this.curcat!='divers') ? 1500 : 1000; var max = (this.curcat!='voilier'&&this.curcat!='bateau-moteur'&&this.curcat!='moteur'&&this.curcat!='divers') ? 100500 : 500000 ; var min = (min_price>0)?parseInt(min_price,10) + step:3000; while((i = this.combo_prix_maxi.options.length)>1) this.combo_prix_maxi.options[i-1]=null; if (this.combo_prix_maxi.options.length==0) this.combo_prix_maxi.options[this.combo_prix_maxi.options.length] = new Option ( 'Prix maximum' , ''); /*build list starting from price min + step and trying to restore old value*/ for(i=min;i<=max;i+=step) { this.combo_prix_maxi.options[this.combo_prix_maxi.options.length] = new Option ( format(i) + ' €' , i ); if(this.prefered_max_price && i == this.prefered_max_price && this.combo_prix_mini.selectedIndex!=1)this.combo_prix_maxi.options[this.combo_prix_maxi.options.length-1].selected=true; } } Critere.prototype.fill_mileage = function() { /*fill maxi km combo*/ var min = 10000; var max = 200000; var step = 10000; var i; if(this.combo_mileage!=null){ while((i = this.combo_mileage.options.length)>1) this.combo_mileage.options[i-1]=null; if (this.combo_mileage.options.length==0) this.combo_mileage.options[this.combo_mileage.options.length] = new Option ( 'Kilométrage maximum' , ''); for(i=min;i<=max;i+=step) { this.combo_mileage.options[this.combo_mileage.options.length] = new Option ( format(i) + ' km' , i ); if((this.prefered_mileage!='')&&(i==this.prefered_mileage)) this.combo_mileage.options[this.combo_mileage.options.length-1].selected=true; } } } function format(the_string){ /*return a well formated string 3000 => 3 000*/ var str = ''+the_string; var step = 3; var tmp = ''; var i; var nbspace=0; for(i=str.length-1;i>=0;i--) { tmp=str.charAt(i)+tmp; if(((tmp.length-nbspace)%step==0)&&(i>0)){tmp=' '+tmp;nbspace++;} } return tmp; } function decode(the_string) { return the_string.replace(new RegExp('\\*','g'),'/').replace(new RegExp('~','g'),'+').replace(new RegExp('`','g'),'\'').replace(new RegExp('_','g'),'-').replace(new RegExp('\\^','g'),'&'); } Critere.prototype.get_cat = function() { var cat,i; if (document.getElementById('SS_CATEGORIE')!=null) { if (document.getElementById('SS_CATEGORIE').options!=null) cat = document.getElementById('SS_CATEGORIE').options[document.getElementById('SS_CATEGORIE').selectedIndex].value; else cat = document.getElementById('SS_CATEGORIE').value; } else { for (i=0;i<=3;i++) { if (document.getElementById('SS_CATEGORIE['+i+']') && document.getElementById('SS_CATEGORIE['+i+']').checked) cat = document.getElementById('SS_CATEGORIE['+i+']').value; } } return cat; } Critere.prototype.fill_energy = function(){ if(this.combo_Energy==null) return; var Tnrj = new Array(new Array('Énergie',''), new Array('Essence','1'),new Array('Diesel','2'),new Array('Bicarburation essence / gpl','3'), new Array('Hybride électrique / électrique','4,8,9'),new Array('Autres énergies alternatives','5,6,7,10,11') ); for(var i=0;i