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

function load() {

if (GBrowserIsCompatible()) {
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GSmallZoomControl3D());
  map.setCenter(new GLatLng(50.83772,5.713367), 5);
  GTileLayer.prototype.getCopyright= function(){};  

  //Forum 100, Maastricht, nl
  var point = new GLatLng(50.83772,5.713367);
 		    
  var icon = new GIcon();
  icon.image = "/pics/logomaps.png"
  icon.iconSize = new GSize(81,75);
  icon.iconAnchor = new GPoint(26,75);	
  
  var marker = new GMarker(point,icon);
  map.addOverlay(marker);
  }
}
	

function MakeMap(fromAddress) {
	document.getElementById("directions").innerHTML = "";
	
  if (GBrowserIsCompatible()) { 
    map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallZoomControl3D());
		map.addControl(new GMapTypeControl());

    gdir = new GDirections(map, document.getElementById("directions"));
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);

		toAddress = "Forum 100, Maastricht, NL";

    setDirections(fromAddress,toAddress);
  }
}

function setDirections(fromAddress, toAddress) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": "EN" });
}

function handleErrors(){
 if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
   alert("The address does not exist. Try for example, 'NL' behind the city to continue." + gdir.getStatus().code);
 } else {
 	 alert("The route can not be shown, try again.");
 }
}

function onGDirectionsLoad(){
	gdir.getMarker(gdir.getNumGeocodes()-1).getIcon().image = "/pics/logomaps.png"; 
	gdir.getMarker(gdir.getNumGeocodes()-1).getIcon().iconSize = new GSize(81,75); 
	gdir.getMarker(gdir.getNumGeocodes()-1).getIcon().iconAnchor = new GPoint(26,75);
	
	gdir.getMarker(gdir.getNumGeocodes()-1).getIcon().printImage = "/pics/logomaps.png"; 
	gdir.getMarker(gdir.getNumGeocodes()-1).getIcon().mozPrintImage = "/pics/logomaps.png"; 
}