// JavaScript Document

var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

function Gload() { 
 if (GBrowserIsCompatible()) {


function showAddress(address) {
  geocoder.getLatLng(address, function(point) {
   if (!point) {
     alert(address + "nie zostal odnaleziony");
     } else {
map.setCenter(point, 15);
 var marker = createMarker(point, tresc);
 map.addOverlay(marker);
      
      }
     }
    );
   }

 function createMarker(point,html) {
 var marker = new GMarker(point);
 GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
 });


 return marker;
 }

 var map = new GMap2(document.getElementById("map"));
 var trafficInfo = new GTrafficOverlay();
  map.addOverlay(trafficInfo);
 map.addControl(new GSmallMapControl());
 map.addControl(new GMapTypeControl());
 map.setCenter(new GLatLng(50.053210, 20.025050), 12);
 
var geocoder = new GClientGeocoder();
showAddress("Kraków, Algierska 9A");
 
 gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        //setDirections("Kraków, Śniadeckich 12", "");

var tresc = '<h2 style="color:#838080; font-size:14px; font-weight:bold;"><span style="color:#489c06!Important ">Najlepsze</span><span style="color:#f2be1f!Important ">Miejsce</span>.pl</h2><br/>' +
			'<p>ul. Algierska 9A</p>';



 }
    } 

	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...
	}

   function setDirections(fromAddress, toAddress) {
	   	if(toAddress=='') toAddress = 'Kraków, Algierska 9A';
	if(fromAddress!='')   
   gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": "pl_PL" });
   else
   alert("Podaj adres początkowy");
	  return false;
    }

    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("Błędny klucz. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Zapytanie nie może być poprawnie przetworzone.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("Nieznany błąd.");
	   
	}
	
	
