﻿/// <reference path="Contact.aspx" />
/// <reference path="~/Client_Script/GMAPJSHelper_Release.js" />

var map;

$(document).ready(function() {
    PageMethods.GetLocationList(onSuccess);
});

function onSuccess(result) {
    map = new GMap2(document.getElementById('map_canvas'));
    map.setCenter(new GLatLng(38.208353, -99.155383), 4);
    map.setUIToDefault();

    var baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);

    var i;
    for (i in result) {
        var locationInfoString = '';
        
        locationInfoString += '<span style="font-weight:bold;">'
        locationInfoString += result[i].Name;
        locationInfoString += '</span><br />'
        locationInfoString += '<span style="font-weight:normal;">'
        locationInfoString += result[i].Address1;
        locationInfoString += '<br />'
        if (result[i].Address2 != '') {
            locationInfoString += result[i].Address2 + '<br/>';
        }
        locationInfoString += result[i].City + ', ' + result[i].State + ' ' + result[i].PostalCode + '<br/>';
        locationInfoString += result[i].Country + '<br />'
        if (result[i].PhoneMain != '') {
            locationInfoString += result[i].PhoneMain + ' - Main<br/>';
        }
        if (result[i].PhoneTollFree != '') {
            locationInfoString += result[i].PhoneTollFree + ' - Toll Free<br/>';
        }
        if (result[i].Fax != '') {
            locationInfoString += result[i].Fax + ' - Fax';
        }
    
        var letteredIcon = new GIcon(baseIcon);
        letteredIcon.image = "http://www.google.com/mapfiles/marker" + result[i].MapMarkerID + ".png";
        markerOptions = { icon: letteredIcon };
        
        var point = new GLatLng(result[i].Latitude, result[i].Longitude);
        var locationMarker = new GMarker(point, markerOptions);
        locationMarker.bindInfoWindowHtml(locationInfoString);

        map.addOverlay(locationMarker);
    }
}

function onFailure(result) {

}

function setMapCenter(lat, lon) {
    map.setZoom(10);
    map.panTo(new GLatLng(lat, lon));
}