// JavaScript Document
//<![CDATA[

var map;
var gdir;
var geocoder = null;
var lat;
var lng;
var zoom
var locHtml;

function initialize(lat,lng) {
  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.setUIToDefault();
	map.setMapType(G_HYBRID_MAP);

	
	map.setCenter(new GLatLng(lat,lng), zoom);
	var marker = new GMarker(new GLatLng(lat,lng));
	map.addOverlay(marker);
	marker.openInfoWindowHtml(locHtml);

  }
}

function setDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress, 
			{ "locale": locale });
}

function handleErrors(){
   if (gdir.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. Please re-enter the address.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	 alert("Your request could not be successfully processed due to a server error. Please re-enter the address.\n Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	 alert("You must enter an address in the 'From' field to get directions.\n Error code: " + gdir.getStatus().code);

	else if (gdir.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: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	 alert("Your request could not be successfully processed. Please re-enter the address.\n Error code: " + gdir.getStatus().code);
	
   else alert("Your request could not be successfully processed. Please re-enter the address.");
   
}

function onGDirectionsLoad(){ 
	   // events that occur when the directions load
}

//]]>