﻿var _map = null;
var _sUrgentCareAddress = "19895 Detroit Rd, Rocky River OH, 44116";
var _sUrgentCareHtml = "<strong>Rocky Rive Urgent Care</strong><br/>440-356-5500<br/>19895 Detroit Rd<br/>Rocky River, OH";
var _directions = null;
var _spnErrorMessage = null;

function iniMaps() {
    if (GBrowserIsCompatible()) {
        _spnErrorMessage = document.getElementById("spnErrorMessage");
        _map = new GMap2(document.getElementById("map"));
        _map.addControl(new GLargeMapControl());
        _map.addControl(new GScaleControl());
        var point = new GLatLng(37.71859, 6.679688);
        _map.setCenter(point, 14);
        showaddress(_sUrgentCareAddress, _sUrgentCareHtml, false);
    }
}

function showaddress(sAddress, sInfoHtml, bAddDefault) {
    _map.clearOverlays();
    
    var oGeocoder = new GClientGeocoder();
    if (bAddDefault || bAddDefault == null)
        oGeocoder.getLatLng(_sUrgentCareAddress,
            function(gLatLn) {
                var marker1 = new GMarker(gLatLn);
                _map.panTo(gLatLn);
                _map.addOverlay(marker1);
            }
        );
        
    oGeocoder.getLatLng(sAddress,
            function(gLatLn) {
                var marker2 = new GMarker(gLatLn);
                _map.panTo(gLatLn);
                _map.addOverlay(marker2);
                _map.openInfoWindowHtml(gLatLn, sInfoHtml)
            });
    
}

function displayDirections(sStartAddress) {
      _spnErrorMessage.style.display = 'none';
      var directionsPanel = document.getElementById("drivingDirections");
      if (directionsPanel.hasChildNodes)
          directionsPanel.removeChild(directionsPanel.firstChild);
          
      _directions = new GDirections(_map, directionsPanel);

      _directions.load("from:" + sStartAddress + " to: " + _sUrgentCareAddress);
      setTimeout("checkDirections()", 2000);
}

function checkDirections() {
    if (_directions.getStatus().code != 200)
        _spnErrorMessage.style.display = 'block';
}

function plotVenueMarker(gLatLn, bShowWindow)
{
    if (gLatLn == null)
        return;
    var marker = new GMarker(gLatLn);

    _map.panTo(gLatLn);
    _map.addOverlay(marker);
}
