﻿/// <reference name="MicrosoftAjax.js"/>

// add this \\exchange\AdminShare\CustomTools .. Csv.dll

var customerMap = null;
var customers = null;
var allMarkers = null;

function pageLoad(sender, args) {
    customers = getCustomers();
    customerMap = getMap();
    allMarkers = getAllMarkers(customers);
};


// Load the customers into a variable from the JSON provided by the server
function getCustomers() {
    return eval('(' + $get('locations').innerText + ')');
};

// Create all the markers on the map
function getAllMarkers(customers) {
    var _allMarkers = new Array(customers.length);
    
    for (var i in customers) {
        _allMarkers[i] = createMarker(customers[i],customerMap);
    };

    return _allMarkers
};

// Create a Marker with the location, image, and title set. It is automatically added to the supplied map.
function createMarker(customer, map) {
    var _markerLocation = new google.maps.LatLng(customer.Latitude,customer.Longitude);     // Position on the map
    var _markerOptions = {
                            map: map,
                            position: _markerLocation,
                            clickable: false,   // Can't click the marker, (nothing to do on a click)
                            draggable: false,   // Can't move the marker
                            flat: true,         // Don't display the shadow for performance reasons
                            icon: 'http://thydzik.com/thydzikGoogleMap/markerlink.php?text=' + customer.NumberOfCustomers + '&color=5680FC',  // The image of the marker 
                            title: customer.NumberOfCustomers + ' customers in ' + customer.PostalCode + ', ' + customer.Region.FullCode,
                            zIndex: customer.NumberOfCustomers  // Ensure that the markers with more customers show up on top
                        };
    return new google.maps.Marker(_markerOptions);
};

// Create the Google map
function getMap() {

    var mapCenter = new google.maps.LatLng(39, -121)
    var mapOptions = { 
                        mapTypeId: google.maps.MapTypeId.HYBRID,    // Show the satelite view with landmarks (States, Cities, etc but no roads)
                        center: mapCenter,
                        zoom: 2
                    };
    var _customerMap = new google.maps.Map($get('map_canvas'),mapOptions);

    return _customerMap;
};
