﻿
//the map object
var map = null;
var latcontrolname = null;
var loncontrolname = null;

//set page event handlers
if (window.attachEvent) {
    window.attachEvent("onload", Page_Load);
    //window.attachEvent("onresize", MapResize);
    window.attachEvent("onunload", Page_Unload);
} else {
    window.addEventListener("DOMContentLoaded", Page_Load, false);
    window.addEventListener("unload", Page_Unload, false);
    //window.addEventListener("onresize", MapResize, false);
}

//load map    
function Page_Load() {
    qs();
    map = new VEMap("locationmap");
    var mapcenter;
    var zoomLevel = 18;
    var mapStyle = "h";
    var findaddress = false;

    if ($n("hidMapStyle") != null) {
        mapStyle = $n("hidMapStyle").value;
    }

    if ($n("hidZoomLevel") != null) {
        zoomLevel = $n("hidZoomLevel").value;
    }

    if ($n("hidDashboardSize") != null) {
        map.SetDashboardSize($n("hidDashboardSize").value);
    }

    mapcenter = new VELatLong($n("hidLatitude").value, $n("hidLongitude").value);
    var options = new VEMapOptions();
    options.EnableBirdseye = false;
    map.LoadMap(mapcenter, zoomLevel, mapStyle, false, null, null, null, options);
    addIcon(mapcenter);
}

function addIcon(position) {
    var shape = new VEShape(VEShapeType.Pushpin, position);
    shape.SetTitle($n("hidName").value);
    var AddressField = $n("hidAddress");
    if (AddressField != null) {
        shape.SetDescription(AddressField.value.replace(/\|/g,"<br />"));
    }

    //Set the icon
    var icon = new VECustomIconSpecification();
    icon.Image = "/images/LocationMapIcon.gif";
    icon.TextContent = " ";
    shape.SetCustomIcon(icon);

    map.AddShape(shape);
}

//Clean up all objects
function Page_Unload() {
    if (map != null) {
        map.Dispose();
        map = null;
    }
}

function MapResize() //resize
{
    if (map != null) {
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            map.Resize(window.innerWidth, window.innerHeight);
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            map.Resize(document.documentElement.clientWidth, document.documentElement.clientHeight);
        }
    }
}

var qsParm = new Array();
function qs() {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i = 0; i < parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            var key = parms[i].substring(0, pos);
            var val = parms[i].substring(pos + 1);
            qsParm[key] = val;
        }
    }
}




