
GestGeoCodeDynmap=Class.create();

GestGeoCodeDynmap.prototype={
	initialize:function(url){
		this.url=url;
		this.extend(new GestEvt(),this);
		//this.ajouteEvenement('GEOCODE_DONE');
	},
	getLocationGeo:function(address,commune,callBack)
	{
	
	
		searchstr='';    
		var pars='';
		this.callBack=callBack;
		pars+='&commune='+commune+'&adresse='+address;
		
		var myAjax = new Ajax.Request(this.url, { method : "get", parameters : pars,  asynchronous : true,evalScripts:false,onComplete:this.a_getListe,objetLie: this});

	}
	,
	a_getListe:function(t){
		
		eval('res='+t.responseText);
		
		this.callBack(res);
	}


}
GestGeoCodeGoogle=Class.create();
GestGeoCodeGoogle.prototype={
	initialize:function(geocode){
		this.module= geocode;
		this.extend(new GestEvt(),this);
		//this.ajouteEvenement('GEOCODE_DONE');
	},
	getLocationGeo:function(address,commune,callBack)
	{
	
	
		var adresse=address;
		if(commune!=''){
			adresse+=', '+commune;
		}
		this.callBackOk=callBack;
		this.module.getLocations(adresse,this.a_getListe.bind(this));
	}
	,
	a_getListe:function(t){
		var res={};
		var liste=[];
		if(t.Status.code==200){
			for(var i=0; i< t.Placemark.length;i++){
				onePlace= t.Placemark[i];
				var objTemp={'street':onePlace.address,'x':onePlace.Point.coordinates[0],'y':onePlace.Point.coordinates[1],'coords':'EPSG:4326'};
				liste[liste.length]=objTemp;
			}
			res['results']=liste;
		}else{
			res={'results':[]}
		}
		this.callBackOk(res);
	}


}

GestGeoCodeView=Class.create();

GestGeoCodeView.prototype={

	initialize:function(inp,com,paramsVue,geocoder)
	{
	
		this.inp=inp;
		this.com=com;
		this.paramsVue=paramsVue;
		Element.hide(this.paramsVue['retour']);
		this.stratGeocode=geocoder;
	}
	,
	getLocationGeo:function(address,commune)
	{
//	alert('aa'+this.paramsVue['wait']);
	var fonc=this.a_getLocations.bind(this);
		//Element.show(this.paramsVue['wait']);
		
		this.stratGeocode.getLocationGeo(address,commune,fonc);
		
	
	},
	a_getLocations:function(result)
	{
	
		Element.hide(this.paramsVue['wait']);
		Element.hide(this.paramsVue['search']);
		Element.show(this.paramsVue['retour']);
		Element.show(this.paramsVue['result']);

		this.showResult(result);
	},
	showResult:function(result){
	
		var st='';
		var coords='';
		st+='<ul class="alphabet_result"> ';
		if(result.results.length>0){
		
			for(i=0;i<result.results.length;i++){
				oA=result.results[i];
				st+='<li class="alphabet_res_1">';
				
				var adrLib='';
				if(oA.numero){
					adrLib+=oA.numero+',';
				}
				if(oA.type){
					adrLib+=oA.type+' ';
				}
				if(oA.coords!=undefined){
					coords=oA.coords;
				}else{
					coords='real';
				}
				adrLib+=oA.street;
				if(oA.commune){
					adrLib+=', '+oA.commune;
				}
			
				st+='<a class="layer_1" href="javascript:;"  title="Localiser '+adrLib+'"';
			
				st+=' onclick="localiseXY(\''+oA.x+'\',\''+oA.y+'\',true,0,{\'scaleMode\':\'localisation\',\'coords\':\''+coords+'\'});">'+adrLib+'</a>';
				
				st+='</li>';
			
			}
				
		
		}else{
				st+='<li>Aucun résultat</li>';
		}
		st+='</ul>';

		$(this.paramsVue['result']).innerHTML=st;
		Element.show(this.paramsVue['result']);
	
	}
	 ,
	retourAlphabet:function()
	{
		Element.hide(this.paramsVue['result']);
		Element.show(this.paramsVue['search']);
		Element.hide(this.paramsVue['retour']);

	}
}


