﻿var map = null;
var geocoder = null;
var LatLng = null;

function showAddress(address, id, mapType, defaultText) 
{          
    if (GBrowserIsCompatible()) 
    {         
        var div = null;
        div = document.getElementById(id)
        map = new GMap2(div);  
        switch(mapType)
        {
            case "Hybrid":
                map.setMapType(G_HYBRID_MAP); break;    
            case "Image":
                map.setMapType(G_SATELLITE_MAP); break;
            case "Normal":
                map.setMapType(G_NORMAL_MAP); break;          
            default:
                map.setMapType(G_HYBRID_MAP); break;
        }                           
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
        if (geocoder) 
        {   
            geocoder.getLatLng(
            address,
            function(point) 
            {         
                LatLng = point;     
                if (!point)  
                {                
                    div.value = defaultText;
                    div.style.height = '100px';
                    document.getElementById(id).style.display = 'none';
                }
                else 
                {      
                    map.setCenter(point, 15);                    
                    var marker = new GMarker(point, {draggable: false});                   
                    map.addOverlay(marker);                                                 
                    document.getElementById(id).style.visibility='visible';          
                }
            });
        }
    }
}

function initializeGoogleMaps()
{    
    if (GBrowserIsCompatible() && googleMapsContainerId && document.getElementById(googleMapsContainerId)) 
    {            
        map = new GMap2(document.getElementById(googleMapsContainerId));
        map.setMapType(G_HYBRID_MAP);                
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();                        
    }
}

function showMap()
{
    if(geocoder)                    
        showAddressLocal();
}