<!--
var address = "Veranda 100, Hoorn, Nederland";
//var address = "52.64662,5.082012";
//-->

var map = null;
var gdir;
var geocoder = null;


function extInit() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("google_maps_vestiging"));
		map.addControl(new GSmallMapControl());
		
		gdir = new GDirections(map, document.getElementById("google_maps_directions"));
		GEvent.addListener(gdir, "error", handleErrors);
		
		geocoder = new GClientGeocoder();
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					// verwijderd routeplan formulier en de kaart als adres niet bekend is
					document.getElementById("google_maps_directions").style.visibility = "hidden";
					document.getElementById("google_maps_vestiging").style.visibility = "hidden";
				} else {
					icon = new GIcon();
					icon.image = "images/google_icon.png";
					icon.iconSize = new GSize(18, 18);	
					icon.iconAnchor = new GPoint(7, 7);
					
					map.setCenter(point, 14);
					var marker = new GMarker(point, icon);
					map.addOverlay(marker);
					
				}
			}
		);
	}

}


function preSubmit(toAddress,locale) {
	f = document.getElementById('routeForm');
	
	var fromLocation = "";
	if (f.postal_code.value == "") {
		fromLocation = f.address.value+','+ f.city.value + ",Nederland";
	} else {
		fromLocation = f.postal_code.value + ",Nederland";
	}
	
	if (fromLocation == "" || fromLocation == ",Nederland" || fromLocation == ",,Nederland") {
		return false;
	}
	
	gdir.load("from: " + fromLocation + " to: " + address, { "locale": locale});
}

function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		alert("De door u opgegeven startlocactie kan niet worden gevonden. Controleer of u alle velden correct hebt ingevuld en probeer het nogmaals.");
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		alert("Er heeft zich een onbekend probleem voorgedaan. Probeer het nogmaals.");
	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_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("Er heeft zich een onbekend probleem voorgedaan. Probeer het nogmaals.");
}