//<![CDATA[
			var map = null;
			var gdir;
			var startPoint = null;
			var geocoder = null;
			var markers = null;
			var addressMarker;

			var Yicon = new GIcon();
			Yicon.image = 'img/Yicon.png'; // percorso assoluto ??
			Yicon.shadow = 'img/Yicon_shadow.png';
			Yicon.iconSize = new GSize(22, 26);
			Yicon.shadowSize = new GSize(36, 26);
			Yicon.iconAnchor = new GPoint(1, 24);
			Yicon.infoWindowAnchor = new GPoint(22, 1);

			function initialize() {
					if (GBrowserIsCompatible()) {
							map = new GMap2(document.getElementById("map_canvas"));
							gdir = new GDirections(map, document.getElementById("directions"));
							GEvent.addListener(gdir, "load", onGDirectionsLoad);
							GEvent.addListener(gdir, "error", handleErrors);
							map.addControl(new GSmallMapControl());
							map.addControl(new GMapTypeControl());
							map.setCenter(new GLatLng(41.895466, 12.482324), 6);
							geocoder = new GClientGeocoder();
					}
			}

		 function searchLocations() {
			 var address = document.getElementById('address').value;
			 geocoder.getLatLng(address, function(latlng) {
				 if (!latlng) {
					 alert(address + ' not found');
				 } else {
					 startPoint=latlng;
					 searchLocationsNear(latlng);
				 }
			 });
		 }


		 function searchLocationsNear(center) {
			 //var radius = document.getElementById('radiusSelect').value;
			 var radius = 100; // selezione del raggio di ricerca
			 var searchUrl = 'getResultsMarkers.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
			 GDownloadUrl(searchUrl, function(data) {
				 var xml = GXml.parse(data);
				 markers = xml.documentElement.getElementsByTagName('marker');
				 map.clearOverlays();

				 var sidebar = document.getElementById('sidebar');
				 sidebar.innerHTML = '';
				 if (markers.length == 0) {
					 sidebar.innerHTML = 'Nessun risultato.';
					 map.setCenter(new GLatLng(41.895466, 12.482324), 6); // centrare su negozio principale
					 return;
				 }

				 var bounds = new GLatLngBounds();
				 for (var i = 0; i < markers.length; i++) {
					 var city = markers[i].getAttribute('city');
					 var address = markers[i].getAttribute('address');
					 var phone = markers[i].getAttribute('phone');
					 var fax = markers[i].getAttribute('fax');
					 var distance = parseFloat(markers[i].getAttribute('distance'));
					 var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
																	 parseFloat(markers[i].getAttribute('lng')));
					 
					 var marker = createMarker(point, city, address, phone, i);
					 map.addOverlay(marker);
					 var sidebarEntry = createSidebarEntry(marker, city, address, phone, fax, distance,i);
					 sidebar.appendChild(sidebarEntry);
					 bounds.extend(point);
				 }
				 map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
			 });
		 }

			function createMarker(point, city, address, phone, i) {
				var marker = new GMarker(point,Yicon);
				var html = '<b>' + city + '</b> ';
				if (phone)
						html+='<br/>Tel: ' + phone
				html +='<br/>' + address;
				html +='<br/><br /><a href="javascript:toHere('+ i + ')">Mostra percorso</a>';
				GEvent.addListener(marker, 'click', function() {
					marker.openInfoWindowHtml(html);
				});
				return marker;
			}

			function createSidebarEntry(marker, city, address, phone, fax, distance,i) {
				var div = document.createElement('div');
				var html = '<b>' + city + '</b><br/>' + address;
				if (phone)
						html+='<br/> Tel: ' + phone;
				if (fax)
						html+='<br/> Fax: ' + fax;
				html +='<br/><a href="javascript:toHere('+i+')" class="link_all">Mostra percorso</a>'
				div.innerHTML = html;
				div.style.cursor = 'pointer';
				div.style.marginBottom = '5px'; 
				div.style.marginTop = '7px'; 
				GEvent.addDomListener(div, 'click', function() {
					GEvent.trigger(marker, 'click');
				});
				GEvent.addDomListener(div, 'mouseover', function() {
					div.style.backgroundColor = '#505157';
				});
				GEvent.addDomListener(div, 'mouseout', function() {
					div.style.backgroundColor = '#505157';
				});
				return div;
			}


			function setDirections(fromAddress, toAddress) {
				gdir.load("from: " + fromAddress + " to: " + toAddress,
									{ "locale": "it" });
			}

			function handleErrors(){
				 if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
					 alert("Indirizzo non trovato.\nError code: " + gdir.getStatus().code);
				 else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
					 alert("Indirizzo errato.\n Error code: " + gdir.getStatus().code);
				 
				 else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
					 alert("Non avete inserito l\'indirizzo di partenza.\n Error code: " + gdir.getStatus().code);
					 
				 else if (gdir.getStatus().code == G_GEO_BAD_KEY)
					 alert("Errore di comunicazione con il server di mapping. \n Error code: " + gdir.getStatus().code);

				 else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
					 alert("L\'indirizzo non e\' nel formato corretto'.\n Error code: " + gdir.getStatus().code);
					
				 else alert("Errore di ricerca.");
				 
			}

			function onGDirectionsLoad(){ 
				// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
			}
			function toHere(indice) {
					var newpoint = markers[indice].getAttribute('lat') +',' +
							markers[indice].getAttribute('lng');
					setDirections(startPoint.toUrlValue(),newpoint);
			}
	//]]> 