      // ====== 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.";




function mapLoad(id, address, city, region, country) {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById(id));
        setMapCenter(map, address, id, city, region, country);
      }
    }

function setMapCenter(map, address, id, city, region, country) {
  var geo = new GClientGeocoder();
  var mapresult = false;

	geo.getLocations(address,function(result) {
  	mapresult = processMapResult(map,result, id);
  	if (!mapresult && (region==null || country==null)) {
  		document.getElementById(id).style.display = 'none';
  	} else {
	  	if (!mapresult) {
	  		address = region+", "+country;
	    	geo.getLocations(address,function(result) {
	    		mapresult = processMapResult(map,result, id);
		    	if (!mapresult) {
		    		address = country;
			    	geo.getLocations(address,function(result) {processMapResult(map,result, id, true);});
		    	}
	    	});
	  	}
	  }
  });
}

function processMapResult(map, result, id, setHide) {
	if (result.Status.code == G_GEO_SUCCESS) {
  	var p = result.Placemark[0].Point.coordinates;
    map.setCenter(new GLatLng(p[1],p[0]),4);
    var marker = new GMarker(new GLatLng(p[1],p[0]));
    map.addOverlay(marker);
    //map.addControl(new GLargeMapControl());
    //map.addControl(new GMapTypeControl());
    map.addControl(new GSmallMapControl());
    return true;
	} else {
		if (setHide) {
			document.getElementById(id).style.display = 'none';
		} else {
			return false;
		}
		//alert(reasons[result.Status.code])
	};
}



