// Add google map clean up functions, this is called if there is at least one map on the page
function GoogleMapsInit() 
{
    var oldOnUnload = window.onunload;
    if (typeof window.onunload != 'function')
    {
        window.onunload = GUnload;
    }
    else 
    {
        window.onunload = function() 
        {
            oldOnUnload();
            GUnload();
        }
    }
}

// Add google map start up calls
// This function is called to add individual map initialization function to OnLoad event.
function AddGoogleMapStart(mapStart)
{
    if (!GBrowserIsCompatible())
    {
        return;
    }

    var oldOnLoad = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = mapStart;
    }
    else 
    {
        window.onload = function() 
        {
            oldOnLoad();
            mapStart();
        }
    }
}

// Add a Geo marker to the current map
function addGeoMarker(map, lat, lng, description, center, zoom, show)
{   
    var point = new GLatLng(lat, lng);
    
    if (center)
    {
        map.setCenter(point, zoom);
    }
    
    var marker = new GMarker(point);
    map.addOverlay(marker);
    marker.bindInfoWindowHtml(description);
    
    if (show)
    {
        marker.openInfoWindow(description);
    }
}

// Add an address marker to the current map
function addAddressMarker(map, geoCoder, address, description, center, zoom, show)
{   
    // Make sure the geo coder is valid
    if (!geoCoder)
    {
        return;
    }
    
    geoCoder.getLatLng (
        address,
        function(point)
        {
            if (!point)
            {
                return;
            }
            
            if (center)
            {
                map.setCenter(point, zoom);
            }
            
            var marker = new GMarker(point);
            map.addOverlay(marker);
            marker.bindInfoWindowHtml(description);

            if (show)
            {
                marker.openInfoWindow(description);
            }
       }
   );
}
