/* Google Map Script */
function loadGoogleMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("google_map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
//38.93925007646853, 16.26577377319336


		center = new GLatLng(38.916314237449654, 16.277618408203125);
 		map.setCenter(center, 15);



		var directions;
  		directions = new GDirections(map);
//         GEvent.addListener(directions, "load", onGDirectionsLoad);
//         GEvent.addListener(directions, "error", handleErrors);

  		//directions.load("Reggio Calabria to Salerno");
      	directions.load("from: 38.918868595159566, 16.26577377319336 to: 38.91841783283312, 16.280193328857422",{preserveViewport: true, locale: "it_IT", getSteps: false});
// 		directions.loadFromWaypoints("38.91841783283312, 16.280193328857422")



 		var directions2;
   		directions2 = new GDirections(map);
//         GEvent.addListener(directions2, "load", onGDirectionsLoad);
//         GEvent.addListener(directions2, "error", handleErrors);
       	directions2.load("from: 38.91466136875998, 16.291276216506958 (from: Uscita A3) to: 38.91841783283312, 16.280193328857422 (Gruppo Adn Italia S.R.L. Unipersonale)",{preserveViewport: true,locale: "it_IT"});

//  		var directions3;
//    		directions3 = new GDirections(map, document.getElementById("google_dir3"));
// //         GEvent.addListener(directions2, "load", onGDirectionsLoad);
// //         GEvent.addListener(directions2, "error", handleErrors);
//        	directions2.load("from: 38.91466136875998, 16.291276216506958 to: 38.918868595159566, 16.26577377319336");
// 



		point = new GLatLng(38.91841783283312, 16.280193328857422);
		pointText = '<strong>Gruppo Adn Italia S.R.L. Unipersonale</strong><br />Indirizzo: Contrada Montesanti<br />88046 Lamezia Terme (CZ)<br />Tel: 0968 419567<br />';

		marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml(pointText);

		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(pointText);
		});
		
// 		GEvent.addListener(map, "movestart", function() {
// 			new_center = map.getCenter();
// 		});
// 		GEvent.addListener(map, "moveend", function() {
// 			var polyline = new GPolyline([new_center, map.getCenter()], "#ff0000", 6);
// 			map.addOverlay(polyline);
// 			var c_polyline = new GPolyline([center, map.getCenter()], "#0000ff", 4);
// 			map.addOverlay(c_polyline);
// 			document.getElementById("google_msg").innerHTML = map.getCenter().toString();
// 			map.addOverlay(new GPolygon(c_polyline, '#0000ff', 0, 0.8, '#0000ff', 0.1));
// 		});

	}
}


    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.\nError code: " + gdir.getStatus().code);
	   else if (gdir.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: " + gdir.getStatus().code);
	   
	   else if (gdir.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: " + gdir.getStatus().code);

	//   else if (gdir.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: " + 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("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
          // Use this function to access information about the latest load()
          // results.

          // e.g.
	  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}


// var map;
// var directionsPanel;
// var directions;
// 
// function main() {
//   map = new GMap2(document.getElementById("map"));
//   directionsPanel = document.getElementById("my_textual_div");
//   map.setCenter(new GLatLng(49.496675,-102.65625), 3);
//   directions = new GDirections(map, directionsPanel);
//   directions.load("New York, NY to Chicago, IL");
// }

window.onUnload = GUnload();
