

		
function load(mapID, dealername, streetcitycountry, geocodeString) 
{
	if (GBrowserIsCompatible()) 
	{
		// initiate map
		var map = new GMap2(document.getElementById(mapID));
		
		// Display the map, with some controls and set the initial location 
      	map.addControl(new GLargeMapControl());
      	map.addControl(new GMapTypeControl());
      	map.setCenter(new GLatLng(20,0),2);
	  
	  	if (geocodeString != "") 
		{
			//Do not search but place marker with geocodes
			
			// remove whitespace
			geocodeString = geocodeString.replace(" ", "");
			
			// separate latitude from longitude
			var positionOfComma = geocodeString.indexOf(",");
			var intLatitude = geocodeString.substring(0, positionOfComma);
			var intLongitude = geocodeString.substring(positionOfComma+1);
			
			var objLatLng = new GLatLng(intLatitude, intLongitude);
			
			markerHTML = '<b>'+dealername+'</b> ';
			  
			var marker = createMarker(objLatLng,markerHTML)
	        map.addOverlay(marker);
	        map.setCenter(objLatLng,15);
			
		} 
		else 
		{
			
			// ====== Create a Client Geocoder ======
			var objClientGeoCoder = new GClientGeocoder(new GGeocodeCache()); 
			
			// ====== Array for decoding the failure codes ======
			var reasons=[];
			reasons[G_GEO_SUCCESS]            = "Success";
			reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
			reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
			reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
			reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
			reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
			reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
	
		  	var searchString = streetcitycountry;
	      	
			// ====== Perform the Geocoding ======        
	        objClientGeoCoder.getLatLng(searchString, function (objLatLng)
	        { 
	          // ===== If that was successful, plot the point and centre the map ======
	          if (objLatLng) {
			  
			  	var i = 0;
			  	markerHTML = '<b>'+dealername+'</b> ';
			  
			  	var marker = createMarker(objLatLng,markerHTML)
	            map.addOverlay(marker);
	            map.setCenter(objLatLng,15);
				
	          }
	          // ====== Decode the error status ======
	          else {
	            // ==Look to see if the query was cached ==
	            var result = objClientGeoCoder.getCache().get(searchString);
	            if (result) {
	              var reason="Code "+result.Status.code;
	              if (reasons[result.Status.code]) {
	                reason = reasons[result.Status.code]
	              }
	            } else {
	              var reason = "";
	            } 
	            alert('Could not find "'+searchString+ '" ' + reason);
	          }
	        }
	      );
		
		
		}
	}
}


// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var htmls = [];
var i = 0;
// arrays to hold variants of the info window html with get direction forms open
var to_htmls = [];
var from_htmls = [];

// A function to create the marker and set up the event window
function createMarker(objLatLng,html) {
  var marker = new GMarker(objLatLng);

  // The info window version with the "to here" form open
  to_htmls[i] = html + '<br>Directions: <b>To here</b> ' +
     '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
     '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
     '<INPUT value="Get Directions" TYPE="SUBMIT">' +
     '<input type="hidden" name="daddr" value="' + objLatLng.lat() + ',' + objLatLng.lng() + 
            // "(" + name + ")" + 
     '"/>';
 
  // The inactive version of the direction info
  html = html + '<br>Directions: <a href="javascript:tohere('+i+')">To here</a>';

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  // save the info we need to use later for the side_bar
  gmarkers[i] = marker;
  htmls[i] = html;


  i++;
  return marker;
}


// This function picks up the click and opens the corresponding info window
function myclick(i) {
  gmarkers[i].openInfoWindowHtml(htmls[i]);
}

// functions that open the directions forms
function tohere(i) {
  gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}
function fromhere(i) {
  gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}


