
function setDirections(fromAddress, toAddress, locale) {
	//Pro plánovač
	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
}
function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("Nepodařilo se najít žádný bod na mapě dle zadaného místa. Je také možné, že adresa ještě nebyla zaindexována našim Google robotem.\nChybový kód: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) {
	    alert("Google server pro zpracování požadavků je momentálě mimo provoz, opakujte prosím Vaše zadání později.\nChybový kód: " + 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_GEO_BAD_REQUEST) {
	  	alert("Zadané místo se nepodařilo rozpoznat, zadávejte prosím adresu v klasickém formátu.\nChybový kód: " + gdir.getStatus().code);
	} else {
	    alert("Nastala neznámá chyba při generování trasy.");
	}
}

function onGDirectionsLoad(){}

function planbox(address) {
	if(document.getElementById('planbox').style.display == 'none') {
		document.getElementById('planbox').style.display = 'inline';
		var height = document.getElementById('content').clientHeight;
		document.getElementById('planbox').style.height = height - 70 + 'px';	
		if(typeof address != 'undefined') document.getElementById('plan_from').value = address;
	}
	else document.getElementById('planbox').style.display = 'none';
}

function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        var geocoder = new GClientGeocoder();			

        geocoder.getLocations(latlng, addAddressToMap);
      }
    }


function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(place.address + '<br><a target="_blank" class="inbox" href="http://www.lokola.cz/?where='+ place.address +'">Najdi v okolí</a>, <a href="#" class="inbox" onclick="planbox('+"'"+place.address+"'"+');">Naplánovat trasu</a>');
      }
    }

