﻿var map = null;
var defaultZoomLevel = 12;

function DisplayLocationInformation(info) {
    $('#LocationInfo').html(info);
    alert(info);
}

function LoadMarkers() {
    var l = new VEShapeLayer();
    var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/global/Contact/LocationList", l);
    map.ImportShapeLayerData(veLayerSpec, ShowCurrentLocation);
}

function DoChangeLocation(lat,lon) {
    map.SetCenterAndZoom(new VELatLong(lat,lon),defaultZoomLevel);
}

function ShowCurrentLocation() {
    map.SetCenterAndZoom(currentLocation,defaultZoomLevel);
}

function LoadMap(lat,lon) {
    options = new VEMapOptions();            
    map = new VEMap("ContactMap");
    map.onLoadMap = LoadMarkers;       
    map.LoadMap(new VELatLong(lat,lon),8,VEMapStyle.Road,false,VEMapMode.Mode2D,false,2,null);          
}

function UpdateLocation(id) {

    $.getJSON("/global/contact/getlocationdata", { Id: id }, function(data) {
        UpdateDisplay(data);
    });

}

function UpdateDisplay(data) {
    $('#Phone').html(data.Phone);

    if (data.WebsiteUrl != '' && data.WebsiteUrl != null) {
        $('#WebsiteUrl').show();
        $('#WebsiteUrl').html('<a target="_blank" href="' + data.WebsiteUrl + '" target="_self">Office Website</a>');
    }
    else if (data.WebsiteActive) {
        $('#WebsiteUrl').show();
        $('#WebsiteUrl').html('<a target="_blank" href="/' + data.Alias + '" target="_self">Office Website</a>');
    }
    else {
        $('#WebsiteUrl').hide();
        $('#WebsiteUrl').html('');
    }

    if (data.Email != '' || data.Email != null) {
        $('#Email').show();
        $('#Email').html('<a href="mailto:' + data.Email + '">' + data.Email + '</a>');
    }
    else {
        $('#Email').hide();
        $('#Email').html('');
    }

    $('#LocationName').html(data.Name);
    $('#LocationAddress').html(data.Address);
    // $('#ContactInformation').html(data.ContactInformation);
    DoChangeLocation(data.Latitude, data.Longitude);
}