// DEV domain for testing
// document.write ('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA8wMzik5KdA362AvfSf0l0RR88N1F2dDB_Wtw8BPE4Xot6eX31hSeqQPxcUe1XKj1Diz8mDb8Reatzw" type="text/javascript"></script>');
// live domain
 document.write ('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA8wMzik5KdA362AvfSf0l0RRKlSf5otERJMIBQ9DMYzOnEvz31BQDNHhf22z7pdkQjSsyqqqY5VnyeA" type="text/javascript"></script>');

// note
// page needs a div tag id="googleMap" optional div tag id="mapMsg"
 	
//<![CDATA[
// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addAddressToMap(response) {
  	map.clearOverlays();
	
	// success
	if (document.getElementById ("mapMsg")) {
		var successDiv = document.getElementById ("mapMsg");	
	}
	
	if (!response || response.Status.code != 200) {	 			
	 	if (document.getElementById) {
			if (document.getElementById ("mapMsg")) {	
				successDiv.innerHTML = "<p><strong>ADDRESS NOT LOCATED</strong></p>";
			} else {
				alert ("Sorry, unable to locate that address.  Example: Seattle, WA, USA");		
			}
		} else {
		   	alert ("Sorry, unable to locate that address.  Example: Seattle, WA, USA");
		}
  	} else {		
    	place = response.Placemark[0];
    	point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);												
    	marker = new GMarker(point);
   		map.addOverlay(marker);
    	marker.openInfoWindowHtml(place.address);
  }
}
function showLocation(address, zoom) {     			
 	geocoder.getLocations(address, addAddressToMap);
	map.setCenter(new GLatLng(50.120578,-122.958984), zoom);

}
function loader() {
  if (GBrowserIsCompatible()) {				  	
	geocoder = new GClientGeocoder();
   	map = new GMap2(document.getElementById("googleMap"));										
	map.addControl(new GLargeMapControl());
  
	// whistler marker
	showLocation("Churchill, MB, Canada", 2);	
	// add onunload event (prevent memory leaks)
	window.onunload = GUnload;
  }
}

var geocoder;
var map; 
addLoadEvent(loader);  

//]]>
