﻿var map = null;
var geocoder = null;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        geocoder = new GClientGeocoder();
        
        if ($('input[name=address]').val() != "") {
            showAddress($('input[name=address]').val());
        }
        else {
            map.setCenter(new GLatLng(37.4419, -94.1419), 3);
        }
        
    }
}


function initializedisplay() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        geocoder = new GClientGeocoder();

        if (contactAddress) {
            showAddress(contactAddress);
        }
        else {
            map.setCenter(new GLatLng(37.4419, -94.1419), 3);
        }

    }
}

function showAddress(address) {
    if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
                if(address != "")            
                    alert("Location: '" + address + "' not found.  Please try again with an address in format of '1600 Amphitheatre Pky, Mountain View, CA'");
                return false;
            } else {
                map.setCenter(point, 12);
                var marker = new GMarker(point);
                map.addOverlay(marker);
                marker.openInfoWindowHtml("<br />" + address);
                marker.bindInfoWindowHtml("<br />" + address);
                return true;
            }
        }
        );
    }
}
