var map = null;
var geocoder = null;
var gdir = null;
var newpoint = null;


function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GMapTypeControl());
    map.addControl(new GLargeMapControl3D());    
    geocoder = new GClientGeocoder();
    geocoder.setBaseCountryCode("nl");
    gdir = new GDirections(map, document.getElementById("directions"));
    
    showAddress(address, popup);
	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);	
    
  }
}

function showAddress(address, text) {
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          alert(address + " not found");
        } else {
        	newpoint = point;
          map.setCenter(point, 15);
          var marker = new GMarker(point);
          map.addOverlay(marker);
          GEvent.addListener(marker, "click", function() {
          	marker.openInfoWindowHtml(text);
          });
          marker.openInfoWindowHtml(text);
        }
      }
    );
  }
}
function resetValue(element, defaultValue, newValue) {
	if (element.value == newValue) {
		element.value = defaultValue;
	}
}
function clearValue(element, defaultValue, newValue) {
	if (element.value == newValue) {
		element.value = defaultValue;
	}
}

function onGDirectionsLoad(){ 
	map.checkResize();
	map.setCenter(newpoint, 13);
}
	    


