﻿function getDirections(lat, lon, start, end) 
{
  document.getElementById("directionsMapText").innerHTML= "";
  var map = new GMap2(document.getElementById("directionsMap"));
  var directionsPanel = document.getElementById("directionsMapText");
  map.setCenter(new GLatLng(lat,lon), 3);
  var directions = new GDirections(map, directionsPanel);
  directions.load("from: " + start + " to: " + end);
}

function setMapCoordinates(map, point) {
    if (map && point) {
        map.setCenter(point, 17);
        map.setMapType(G_SATELLITE_MAP);
        map.setUIToDefault();
    }
}

function LoadMap(lat, lon, address) {
    var isLatLonPresent = (lat != 0 || lon != 0);   
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById("mapContainer"));
        var directionsMap = new GMap2(document.getElementById("directionsMap"));
        
        if(isLatLonPresent)
        {
            setMapCoordinates(map, new GLatLng(lat, lon));
        }
        else
        {
            var geocoder = new GClientGeocoder();
            geocoder.getLatLng(address, function(point)
            {
                if(point)
                {
                    setMapCoordinates(map, point);
                }
                else
                {
                    $("#mapContainer").append("No map available");
                }
            });
        }
    }
}
