RechercheAnalyse=Class.create();
RechercheAnalyse.prototype={

	initialize:function(idRecherche)
	{
		this.extend(new GestEvt(),this);
		this.id=idRecherche;
		this.layer=0;
		this.defaultTexte='Saisir une valeur';
		this.trouveTexte='élements trouvés';
		this.aucunTexte='aucun élement ne correspond à la recherche';
		this.erreurCritTexte='Veuillez sélectionner un critère de recherche';
		this.ajouteEvenement('RECHERCHE_ANALYSE_DONE');
		this.ajouteEvenement('RECHERCHE_ANALYSE_MESSAGE');
	},
	setRechercheInterface:function(){
		var inHtml='<select class="analyses_cond" id="opRech'+this.id+'" "opRech'+this.id+'" >'
		+'<option value="&gt;">&gt;</option>'
		+'<option value="&lt;">&lt;</option>'
		+'<option value="&gt;=">&gt;=</option>'
		+'<option value="&lt;=">&lt;=</option>'
		+'<option value="!=">!=</option>'
		+'<option value="=">=</option>'
		+'</select><span id="choixRa'+this.id+'"></span>';
		//alert(inHtml)
        $('rechercheA'+this.id).innerHTML=inHtml;  
        this.rech=$('opRech'+this.id);   
        this.rech.onchange = this.rechModified.bindAsEventListener(this);    
        $('choixRa'+this.id).innerHTML='<input type="text" name="filtreRa'+this.id+'" id="filtreRa'+this.id+'" value="'+this.defaultTexte+'" onClick="this.value=\'\';">';
	       
	} ,
	rechModified:function(){
		if(this.rech.options[this.rech.selectedIndex].value!='-'){
			$('choixRa'+this.id).innerHTML='<input type="text" name="filtreRa'+this.id+'" id="filtreRa'+this.id+'" value="'+this.defaultTexte+'" onClick="this.value=\'\';">';
		}else{
			$('choixRa'+this.id).innerHTML='';
		}
	},
	setA:function(a){
		this.layer=0;
		if(a.TYPE!='4'&&a.TYPE!='6'&& a.TYPE!='1' ){
			Element.show('rechInterfaceChoix'+this.id);
		}else{
		
			Element.hide('rechInterfaceChoix'+this.id);
		}
		this.a=a.ANALYSEID;
	},
	getListeRowidE:function(evt,typeR){
		this.getListeRowid(typeR);
	},
	getListeRowid:function(typeR){
		var strE='';
		this.typeR=typeR;
		var operateur=this.rech.options[this.rech.selectedIndex].value;
		var err=0;
		try{
			var criterium=$('filtreRa'+this.id).value;
			if(!criterium){
					err=1;
			}
		}catch(e){
			err=1;
		}
		//alert(err);
		if(err){
			this.lanceEvenement('RECHERCHE_ANALYSE_MESSAGE',[this.erreurCritTexte]);
		}else{
			StartTimer('recherche des élements en cours..','rechercheAnalyse');
			var url = '/dynmap/class/modules/mvccarte.php?operateur='+operateur+'&criterium='+criterium+'&cont=ANALYSERECHERCHE&event=doQuery';
			url+='&path_application='+path_application+'&idA='+this.a;
			var pars='';
			GestEvtDyn.lanceEvenement('DEBUGDYN','recherche sur analyse,url:'+url);
			var myAjax = new Ajax.Request(url, { method : "post", parameters : pars,  asynchronous : true,evalScripts:false,onComplete:this.a_getListe,objetLie: this});
		}
	},
	remFiltreE:function(){
		this.remFiltre();
	},
	remFiltre:function(){
		if(this.layerF!=undefined && this.layerF){
			removeFiltreCouche(this.layerF);
			GestEvtDyn.lanceEvenement('RMFILTREELEMENT',this.layerF);
		}
	},
	a_getListe:function(res){
		eval('res='+res.responseText);
		if(!res.ok){
			StopTimer('rechercheAnalyse');
			this.lanceEvenement('RECHERCHE_ANALYSE_MESSAGE',[this.aucunTexte]);
		}else{
			var resStr=res.tab.join(',');
			this.lanceEvenement('RECHERCHE_ANALYSE_MESSAGE',[res.nbRes+' '+this.trouveTexte]);
			if(this.typeR=='loca'){
				SetTypeFind('localisation',1);
				
				findAll(resStr,1);
				
			}else{
				addFiltreByElements(resStr);
				this.layerF=res.layer;
				this.lanceEvenement('RECHERCHE_FILTRE_ADDED',[res.layer]);
			}
			StopTimer('rechercheAnalyse');
		}
	}
}
