	 var map;
	 var gdir;
	 var geocoder = null;
	 var addressMarker;
	 var localSearch = new GlocalSearch();

function initialize() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_canvas"));
	//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
	//map.setCenter(new GLatLng(51.772950,-0.324220), 13);	
	map.setCenter(new GLatLng(52.6746, -2.4426), 14);
	map.addControl(new GMapTypeControl());
	map.addControl(new GLargeMapControl());
	map.enableDoubleClickZoom();
	map.enableScrollWheelZoom();

	//var marker = new GMarker(new GLatLng(51.772950,-0.324220));
	var marker = new GMarker(new GLatLng(52.6746,-2.4426));
	map.addOverlay(marker);	
	marker.openInfoWindowHtml("<img src='http://wwem.cms-box.ilm/images/map_img.jpg' width='128' height='41'/> <br/><strong>WWEM 2010 Conference Centre :</strong> <br /> Telford International Centre,<br /> Telford,Shropshire, TF3 4JH, England");	
	//map.setUIToDefault();
	
	// Set driving directions
	gdir = new GDirections(map, document.getElementById("directions"));
	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);  	
  }
}

 function setDirections(fromAddress, toAddress, locale) 
     {
        usePointFromPostcode(fromAddress, getDirections, toAddress, locale);
     } 
     function getDirections(fromAddress, toAddress, locale)
     {
        var Lat = fromAddress.lat();
        var Long = fromAddress.lng();
        var address = Lat + ', ' + Long;
        
        gdir.load("from: " + address + " to: " + toAddress,
                { "locale": location.value});
     }
      function usePointFromPostcode(postcode, callbackFunction, toAddress, locale) 
        {
	        localSearch.setSearchCompleteCallback(null, function() {
			    if (localSearch.results[0])
			    {		
				    var resultLat = localSearch.results[0].lat;
				    var resultLng = localSearch.results[0].lng;
				    var point = new GLatLng(resultLat,resultLng);
				    callbackFunction(point, toAddress, locale);
			    }else{
				    alert("Postcode not found!");
			    }
		    });	
	        localSearch.execute(postcode + ", UK");
        }
     function handleErrors()
     {
           if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
             alert("Either the \"To\" or \"From\" geographic location cannot be found.\nPlease use a postal code or recognised city instead.\n Example : the postal code for WEEM Enviroment Techonolgy office is AL3 6PH.");
           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_GEO_BAD_KEY)
             alert("The given key is either invalid or does not match the domain for which it was given.");

           else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
             alert("A directions request could not be successfully parsed.");

           else alert("An unknown error occurred.");
    }
	 function onGDirectionsLoad()
    {
       
    }
