//JavaScript
	function googleMapInit() {
		try
		{
			if (GBrowserIsCompatible())
			{
				map = new GMap2(document.getElementById("googleAdvancedMapCanvas"));
				geocoder = new GClientGeocoder();

				directionsPanel = document.getElementById("route");
				directions = new GDirections(map, directionsPanel);
							
				GEvent.addListener(directions, "error", handleErrors);

				map.addControl(new GHierarchicalMapTypeControl());
				map.addControl(new GLargeMapControl());
				//map.addControl(new GSmallMapControl()); 
				
				if( Location.Kml != "" )
				{
					geoXml = new GGeoXml("http://"+location.host+"/"+Location.Kml);
					map.addOverlay(geoXml);
				}
				else if(Location.Lat != 0 && Location.Long != 0)
				{
					var point = new GLatLng(Location.Lat,Location.Long);
					map.addOverlay(new GMarker(point));
				}
				map.setCenter(new GLatLng( Location.Lat, Location.Long ), Location.Zoom );

			}
		}catch(e){alert(e.message + "\n" + e.stack )}
	}


	function showAddress(address)
	{
		if (geocoder)
		{
			if( address == "-1")
			{
				return false;
			}
			else if( address == "-2")
			{
			    map.clearOverlays()
				map.addOverlay(geoXml);
			    map.setCenter(new GLatLng(Location.Lat, Location.Long), Location.Zoom);
			}
			else
			{
			   	geocoder.getLatLng(
					address,
					function(point)
					{
				    	if (!point) {
				    		alert(address + " not found");
				    	} else {
							map.clearOverlays()
							
							map.setCenter( point, (Location.Zoom+2) );
							
							var marker = new GMarker(point);
								map.addOverlay(marker);
								marker.openInfoWindowHtml(address);

							map.addOverlay(geoXml);
			    		}
					}
				);
			}
		}
		else
		{
		    alert('No gGeoCoder initialized. You should get on that.');
		}
	}

	function GetDirections( oSource )
	{

		var adr_from = oSource.value;
		var adr_to = document.getElementById( 'to_address_hidden').value;
		
		if( (adr_from != "") && (adr_to != "-1" && adr_to != "") )
		{
			directions.clear(); 
			directions.load("from: " +adr_from + " to: " + adr_to);
		}
		else
		{
			alert("Please enter a source address and select a destination from the menu above." );
		}

		return false;
	
	}
	
function handleErrors()
{
	if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);
	else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
		alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);

	else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
		alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);

	//   else if (directions.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + directions.getStatus().code);

	else if (directions.getStatus().code == G_GEO_BAD_KEY)
		alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);

	else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
		alert("A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);

	else alert("An unknown error occurred.");
}



