gestAlphabet=Class.create();

gestAlphabet.prototype={

	initialize:function(tabSearch,inp,paramsVue)
	{

		this.extend(new GestEvt(),this);
		// tabsearch contient un tableau layerid/colanme
		this.tabSearch = tabSearch;
	//	this.colName = colName;
		this.toito = 1;
		this.inp=$(inp);
		this.strT=new Array();
		//lettres possibles
		this.strPos=new Array();
	
		
		if(paramsVue['cible']==undefined){
			paramsVue['cible']= 1 ;
		}
		if(paramsVue['selection']==undefined){
			paramsVue['selection']= 0 ;
		}
		this.paramsVue=paramsVue;
		this.ajouteEvenement('RECHERCHE_ALPHA_MODIFIED');
		this.ajouteEvenement('RECHERCHE_ALPHA_POSS');
	}
	,
	getListeFromAlphabet:function(lettre,mode,typeReset)
	{
		if(typeof mode=="undefined")mode = "lettre";

		//Element.hide('Alphabet_'+this.layerId+'_'+this.colName);
		Element.show(this.paramsVue['wait']);
		searchstr='';    
		for(var i=0;i<this.tabSearch.length;i++){
			uneCol=this.tabSearch[i];
			searchstr+='tabSearch[]='+this.tabSearch[i]['layerId']+'--'+this.tabSearch[i]['colName']+'&';
		}
  		var url = '/dynmap/class/modules/mvccarte.php?'+searchstr+'arg='+lettre+'&mode='+mode+'&cont=SEARCH_ALPHABET';
		
		url+='&event=getListeFromAlphabet';
		url+='&path_application='+path_application;
		url+='&type_recherche='+mode;
		url+='&fiche='+this.paramsVue.fiche;
		url+='&precision='+this.paramsVue.precision;
		url+='&maxResults='+this.paramsVue.maxResults;
		url+='&cible='+this.paramsVue.cible;
		url+='&selection='+this.paramsVue.selection;
		//alert('test');
		if(typeReset!=undefined){
				url+='&reset=1';
		}
		if(this.requeteClient){
			url+='&requeteClient='+this.requeteClient;
		}
		//$('debugAlphga').innerHTML=url;
		var pars='';
		var myAjax = new Ajax.Request(url, { method : "post", parameters : pars,  asynchronous : true,evalScripts:false,onComplete:this.a_getListe,objetLie: this});

	}
	,
	a_getListe:function(t){
		
		Element.hide(this.paramsVue['wait']);
		if(t.responseText.charAt(0)!='{'){
			this.liste_alphabet_complete(t);
		}else{
			//alert(t.responseText);
			eval('resp='+t.responseText);
		
			this.lanceEvenement('RECHERCHE_ALPHA_POSS',[resp.data])
		}
		//alert(t.responseText);
	},
	liste_alphabet_complete:function(t)
	{
		$(this.paramsVue['result']).innerHTML = t.responseText;
		Element.show(this.paramsVue['result']);
		Element.show(this.paramsVue['retour']);
		Element.hide(this.paramsVue['alphabet']);
	}
	 ,
	retourAlphabet:function()
	{
		Element.hide(this.paramsVue['retour']);
		Element.hide(this.paramsVue['result']);
		Element.show(this.paramsVue['alphabet']);
		this.reset(1);

	},
	reset:function(typeReset){
		this.strT=new Array();
		this.getListeFromAlphabet('','lettre',typeReset);
		this.lanceEvenement('RECHERCHE_ALPHA_MODIFIED',[this.strT]);
	},
	addLettre:function(let,objM){
		if(objM.className!='noselectab'){
			this.strT[this.strT.length]=let;
			this.lanceEvenement('RECHERCHE_ALPHA_MODIFIED',[this.strT]);
			this.getListeFromAlphabet(this.strT.join(''),'lettre')
		}

	}
}
alphabetViewer=Class.create();
alphabetViewer.prototype=(new ViewerGestDyn()).extend({

	initialize:function(tabAplha,alph){
			tabAplha=$(tabAplha);
			tags=tabAplha.getElementsByTagName('li');
			len=tags.length;
			var key='';
			this.tabs=new Array();
			for(var i=0;i<len;i++){
				key=tags[i].getAttribute('alf')	;
				
					this.tabs[key]=tags[i];
				
			}
			this.alph=alph;
			this.ecoute(this.alph,'RECHERCHE_ALPHA_MODIFIED',this.maj);
			this.ecoute(this.alph,'RECHERCHE_ALPHA_POSS',this.majPos);
	},
	majPos:function(objR){
		for(var i=0;i<objR.letters.length;i++){
			let=objR.letters[i];
			//if(this.tabs[let].className!='selectabc'){
				if(this.tabs[let]!=undefined){
				this.tabs[let].className='canselectabc';
				}
			//}
		}
		for(var obj in this.tabs){
			if(obj!='extend'){
				if(this.tabs[obj]!=undefined){
					curLi=this.tabs[obj];
	
					if(curLi.className!='selectabc'&&curLi.className!='canselectabc'){
	
						curLi.className='noselectab';
					}
				}
			}
			//alert(obj);
		}

	},
	maj:function(tab){
		for(var obj in this.tabs){
			if(obj!='extend'){
				//alert (obj);
				curLi=this.tabs[obj];
				curLi.className='';
			}
			//alert(obj);
		}
		var let='';
/*
		for(var i=0;i<tab.length;i++){
			let=tab[i];
			//alert(let);
			//this.tabs[let].className='selectabc';
		}
		* */
	}

});
inputViewer=Class.create();
inputViewer.prototype=(new ViewerGestDyn()).extend({

	initialize:function(objInput,alph){
			this.objInput=$(objInput);

			this.alph=alph;
			this.test=1;
			this.ecoute(this.alph,'RECHERCHE_ALPHA_MODIFIED',this.maj);
	},
	maj:function(tab){

		this.objInput.innerHTML=tab.join('');
	}

});