// JavaScript Document
//Google Maps
//Globals
var map;
var panel;
var dir;
	
function gLoad() {
  if (GBrowserIsCompatible()) {
		
	map = new GMap2(document.getElementById("map"));
	panel = document.getElementById("panel");
	dir = new GDirections(map, panel);
	//mino location
	var point = new GLatLng(37.404341,-121.978905);	
	
	map.enableDoubleClickZoom();
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(point, 15);
	
	//icon
	var icon = new GIcon();
	icon.image = "http://www.minowireless.com/mino/images/logo_maps.gif";
	icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	icon.iconSize = new GSize(43, 14);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	//add icon to point
	var marker = new GMarker(point, icon);		
	map.addOverlay(marker);
	
	var htmlMarker = "<div style=\"background-color:#d1d5bd;font-family:Arial, Helvetica, sans-serif;\">"+
						"<strong>MiNO Wireless, Inc</strong><br/>"+
						"<span style=\"font-size:10px;\"> 2901 Tasman Dr Suite 210<br/>"+
						"Santa Clara, CA 95054</span>"+
						"</div>";
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(htmlMarker);
	});
	GEvent.addListener(dir, "error", handleErrors);
	


  }
}
function setDirections(fromAddress, mino){		
	dir.load("from: " + fromAddress + " to: " + mino);
}
function handleErrors(){
	if (dir.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: " + dir.getStatus().code);
	else if (dir.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: " + dir.getStatus().code);
	   
	else if (dir.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: " + dir.getStatus().code);

	else if (dir.getStatus().code == G_GEO_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: " + dir.getStatus().code);
	     
	else if (dir.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS)
	     alert("The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region. \n Error code: " + dir.getStatus().code);

	else if (dir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + dir.getStatus().code);
	    
    else alert("An unknown error occurred."+dir.getStatus().code);
}
