var RechercheAnalyse = Class.create();
RechercheAnalyse.prototype={
    map:false,
    contener :false,
    initialize:function(idRecherche,options)
    {
        this.extend(new GestEvt(),this);
        if(arguments.length<2){
            options={};
        }
        Object.extend (this,options);
        if(!this.map){
            this.map=mainCarte;
        }
        if(!this.contener){
            this.contener=window;
        }
        this.test=1;
        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>';
        $('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;
        }
        
        if(err){
            this.lanceEvenement('RECHERCHE_ANALYSE_MESSAGE',[this.erreurCritTexte]);
        }else{
			
            this.map.notifyBusy('rechercheAnalyse','recherche des élements en cours..');
            
            var url = '/dynmap/class/modules/mvccarte.php?operateur='+operateur+'&criterium='+criterium+'&cont=ANALYSERECHERCHE&event=doQuery';
            url+='&path_application='+this.map.path_application+'&idA='+this.a;
            var pars='';
                        
                         
                        
			
            var myAjax = new Ajax.Request(url, {
                method : "post",
                parameters : pars,
                asynchronous : true,
                evalScripts:false,
                onComplete:this.a_getListe.bind(this)
                });
        }
    },
    remFiltreE:function(){
        this.remFiltre();
    },
    remFiltre:function(){
        if(this.layerF!=undefined && this.layerF){
            this.map.removeFiltreCouche(this.layerF);
            this.map.eventHandler().lanceEvenement('RMFILTREELEMENT',this.layerF);
        }
    },
    a_getListe:function(res){
        eval('res='+res.responseText);
            
        if(!res.ok){
                        
            this.map.endNotifyBusy('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'){
                                
                this.map.setTypeFind('localisation',1);
                this.map.findAndSelect(resStr,1);
                               
            }else{
                                
                this.map.addFiltreByElements(resStr);
				
                this.layerF=res.layer;
                this.map.eventHandler().lanceEvenement('RECHERCHE_FILTRE_ADDED',[res.layer]);
            }
                       
            this.map.endNotifyBusy('rechercheAnalyse');
                        
        }
    }
};

