﻿// Init the Live.com map control
var map = null;

function pageLoad(sender, args) {

    //if (setupSilverlight()) {
        // initialize Live map
        InitMap();
    //}
    //else {
        // hide Live map 
      //  HideLiveMap();
    //}
}

function InitMap() {
    try {
        map = new VEMap('LiveMapContainer');
        map.LoadMap();
        HideLiveMap(true); //Hide Map until SL app is ready to display it.
    } catch (e) {
        HideLiveMap(false);
    }
}

function HideLiveMap(enableLiveMap) {
    $get('LiveMapContainer').style.display = 'none';
    ENABLE_LIVE_MAP = enableLiveMap;
}

// Use the Live.com map control to find a location.     
function FindLocation(location) {
    map.Find(null, location, null, null, 0, 1, true, true, false, true, FindComplete);
}

// Callback for the find location method.
function FindComplete(layer, resultsArray, places, hasMore, veErrorMessage) {
    map.DeleteAllShapes();
    map.AddShape(new VEShape(VEShapeType.Pushpin, map.GetCenter()));
}


// Display a specific location using Latitude & Longitude in the Live.com map control.
function GoToLocation(Latitude, Longitude, streetLine, streetLine2, primaryCity, state, postalCode, countryRegion) {

    // Set location in the map control
    map.DeleteAllShapes();
    map.SetCenterAndZoom(new VELatLong(Latitude, Longitude), 15);

    // Build customer address to display
    var customerAddress = '<div class=pushPinTooltip>' + streetLine;
    if (streetLine2 != null) {
        customerAddress += '<br />' + streetLine2;
    }
    customerAddress += '<br /> ' + primaryCity
    if (state != null) {
        customerAddress += ' ' + state;
    }
    customerAddress += ' ' + postalCode;
    customerAddress += '<br /> ' + countryRegion + '</div>'

    // Add a pushpin to display the customer's location        
    var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter())
    shape.SetTitle('<div class=pushPinTitle>Address</div>');
    shape.SetDescription(customerAddress);
    map.AddShape(shape);
}


