function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

  var map = null;
  var geocoder = null;
  var zoomLevel = 11;

  function load() {
    if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("ivmap"));
      //map.setCenter(new GLatLng(37.4419, -122.1419), 1);
      geocoder = new GClientGeocoder();
      map.addControl(new GSmallMapControl());
      //map.addControl(new GMapTypeControl());
    }
  }

  function zoomOutMap() {
    if (geocoder) {
      map.zoomOut();
    }
  }
  
  function showAddress(address) {
	  showAddressZoom(address, 11);
  }

  function showAddressZoom(address, zoom) {
	zoomLevel = zoom;
    if (geocoder) {
      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
			try {
				showAddressZoom(address.substring(address.indexOf(',') + 1), zoomLevel);
			}catch(ex){
				showAddress("USA");
			}
          } else {
            map.setCenter(point, zoomLevel);
            //map.zoomOut();
            //map.zoomOut();
            //var marker = new GMarker(point);
            //map.addOverlay(marker);
            //marker.openInfoWindowHtml(address);
            
          }
        }
      );
    }
	  //addLocationMarker("3000 highwoods blvd, raleigh, nc");
  }
  
        // A function to create the marker and set up the event window
      // Dont try to unroll this function. It has to be here for the function closure
      // Each instance of the function preserves the contends of a different instance
      // of the "marker" and "html" variables which will be needed later when the event triggers.    
      function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }
  
    function addLocationMarker(address, infoWindowText) {
    if (geocoder) {
      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
			//alert('test1')
		  } else {
            map.setCenter(point, 8);
            var marker = new GMarker(point);
			var marker = createMarker(point,"<div style='width: 180px;'>" + infoWindowText + "</div>");
            map.addOverlay(marker);
            //marker.openInfoWindowHtml(address);
          }
        }
      );
    }
  }
