﻿    var divMapCanvasControlID;
    var hdnLatitudeControlID;
    var hdnLongitudeControlID;
    var hdnZoomLevelControlID;
    
    function InitializeGoogleMaps() 
    {      
      if (GBrowserIsCompatible()) 
      {
        var objMarker;
        var txtLatitude;
        var txtLongitude;
        var hdnZoomLevel;
        var objMarkerLatLng;                
        var map, divMapCanvas;
        
        //If the map canvas control id is not initialized in the code then consider this as default
        if(divMapCanvasControlID == null)
            divMapCanvasControlID = "ctl00_cphBody_divGoogleMapCanvas";
        //Get reference to Map Canvas div and create a GMap2 object
        divMapCanvas = document.getElementById(divMapCanvasControlID);        
        //Exit if the canvas is not available
        if(divMapCanvas == null)
            return;
        map = new GMap2(divMapCanvas);
        //Exit the function if the division for hosting google maps is not visible
        if( map == null)
            return ;
            //
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());                
        //map.addControl(new GOverviewMapControl());
        map.enableDoubleClickZoom();    
        //
        if(hdnLatitudeControlID == null)
            hdnLatitudeControlID = "ctl00_cphBody_hdnLatitude";
        txtLatitude = document.getElementById(hdnLatitudeControlID);
        //
        if(hdnLongitudeControlID == null)
                hdnLongitudeControlID = "ctl00_cphBody_hdnLongitude";                
        txtLongitude = document.getElementById(hdnLongitudeControlID);
        //
        if(hdnZoomLevelControlID == null)
            hdnZoomLevelControlID = "ctl00_cphBody_hdnZoomLevel"
        hdnZoomLevel = document.getElementById(hdnZoomLevelControlID);
        //
        if(txtLatitude.value == null || txtLatitude.value =="")
            txtLatitude.value = "51.750715";
            
        if(txtLongitude.value == null || txtLongitude.value =="")
            txtLongitude.value = "-1.257291";        
        objMarkerLatLng = new GLatLng(txtLatitude.value, txtLongitude.value)                                 
        //Center the map on marker position
        map.setCenter(objMarkerLatLng, parseInt(hdnZoomLevel.value) );         
        //Create a marker
        objMarker = new GMarker(objMarkerLatLng, {draggable: false} );
        map.addOverlay(objMarker);                 
      }
    }    