EVAMap.geocoder = new GClientGeocoder();

EVAMap.suggestZone=function(el,_c2){
	var _c3=el.value;
	if(typeof _c2=="number"){
		if(_c3.length<_c2){
			return;
		}
	}
	_c3=_c3.toLowerCase();
	_c3+=""+EVAMap.addZone;
	EVAMap.geocoder.getLocations(_c3,EVAMap.showLocations);
};

EVAMap.moveTo=function(lon,lat,_ce,_cf){
	document.getElementById("TX_INDIRIZZO").value = unescape(_cf);
	document.getElementById("NU_LON").value = lon.toFixed(6);
	document.getElementById("NU_LAT").value = lat.toFixed(6);
	map.clearOverlays() 
	var marker = new GMarker(new GLatLng(lat,lon));
	map.addOverlay(marker);
	map.checkResize();
	map.setCenter(new GLatLng(lat,lon),_ce);
	map.checkResize();
};

EVAMap.showLocations=function(_c4){
	if(!_c4||_c4.Status.code!=200){
		} else {
		var s="<p style='font-size: 12px;margin-top: 2px; margin-bottom: 2px;'><strong>Clicca sull\'indirizzo corretto:</strong></p>";
		var a=_c4.Placemark;
		for(var i=0;i<a.length;i++){
			var p=a[i].Point.coordinates;
			var _c9=12;
			try{
				var _ca=a[i].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
				if(_ca.length>0){
					_c9=15;
				}
			}
			catch(e){
			}
			var loc="";
			try{
				if(a[i].AddressDetails.Country.AdministrativeArea){
					loc=escape(a[i].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName);
				}else{
					loc=escape(a[i].AddressDetails.Country.Locality.LocalityName);
				}
			}
			catch(e){
			}
			s+="<p class='EVAplace' onmouseover='this.style.background = \"#93120d\"' onmouseout='this.style.background = \"#b3322d\"' onclick='EVAMap.moveTo("+p[0]+","+p[1]+","+_c9+",\""+escape(a[i].address)+"\");'>"+a[i].address+"</p>";
		}
		$("zoneResults").innerHTML=s;
	}
}
