﻿// Google Maps Helper Functions
// ****************************

var map;
var geocoder;

function loadGmap() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        //map.setCenter(new GLatLng(-33.752783, 151.248758), 14);

        geocoder = new GClientGeocoder();

        map.addControl(new GSmallMapControl());
        //map.addControl(new GMapTypeControl());
    }
}

function addAddressToMap(response) {
    map.clearOverlays();
    if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
        marker = new GMarker(point);
        GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml('<font color="black"><strong>Next Generation Health & Racquet Clubs</strong><br />' + place.address.replace(",", "<br/>") + '</font>'); });
        map.addOverlay(marker);
        map.setCenter(point, 15);
    }
}

function addLatLong(lat, long, address) {
    map.clearOverlays();

    point = new GLatLng(lat, long);
    marker = new GMarker(point);
    GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml('<font color="black"><strong>Next Generation Health & Racquet Clubs</strong><br />' + address.replace(",", "<br/>") + '</font>'); });
    map.addOverlay(marker);
    map.setCenter(point, 15);
}

function showLocation(address) {
    geocoder.getLocations(address, addAddressToMap);
}
