﻿//the map object
var map = null;

//load map
function Page_Load() {

    var latLon = new VELatLong(0, 0);
    var zoom = 1;
    var mapStyle = VEMapStyle.Hybrid;
    
    if (document.getElementById("DropDownListCountry") != null && document.getElementById("DropDownListCountry").value != null && document.getElementById("DropDownListCountry").value != "") {

        var country = document.getElementById("DropDownListCountry").value.split("_");

        if (country.length > 2) {

            latLon = new VELatLong(parseFloat(country[1]), parseFloat(country[2]));
            zoom = parseInt(country[3]);
        }

    }

    if (document.getElementById("HiddenFieldMapStyleGetParameter") != null && document.getElementById("HiddenFieldMapStyleGetParameter").value != null && document.getElementById("HiddenFieldMapStyleGetParameter").value != "") {

        switch (document.getElementById("HiddenFieldMapStyleGetParameter").value) {
            case "road": mapStyle = VEMapStyle.Shaded;
                break;

            case "aerial": mapStyle = VEMapStyle.Aerial;
                break;

            case "hybrid": mapStyle = VEMapStyle.Hybrid;
                break;
        }

    }
    
    try
    {
        var mapArgs = new tn_standorte.MapArgs("myMap", latLon, zoom, mapStyle, false, VEMapMode.Mode2D, VEDistanceUnit.Kilometers);
        map = new tn_standorte.Map(tn_standorte.Cluster.WebService_tn_standorte, mapArgs);
    }
    catch (ex) {
        alert("The following exception has occurred: " + ex.name + ", " + ex.message);
    }
    
}  

//Clean up all objects
function Page_Unload() {
    if (map!=null) {
        map.Dispose();
        map = null;
    }
}

function RouteOrFinderSwitch() {

    if (document.getElementById("showFinder").checked == true) {
        if (document.getElementById("divFinder") != null) {
            document.getElementById("divFinder").style.display = "inline";
        }
        if (document.getElementById("divRoutefinder") != null) {
            document.getElementById("divRoutefinder").style.display = "none";
        }
    }
    else if (document.getElementById("showRoutefinder").checked == true) {
        if (document.getElementById("divFinder") != null) {
            document.getElementById("divFinder").style.display = "none";
        }
        if (document.getElementById("divRoutefinder") != null) {
            document.getElementById("divRoutefinder").style.display = "inline";
        }
    }
}

function switchElements(activeElement, inactiveElement, callBackFunction) {

    if (document.getElementById(activeElement) != null) {
        document.getElementById(activeElement).checked = true;
    }
    if (document.getElementById(inactiveElement) != null) {
        document.getElementById(inactiveElement).checked = false;
    }

    callBackFunction();    
}


//set page event handlers
if (window.attachEvent) {
	window.attachEvent("onload", Page_Load);
	window.attachEvent("onunload", Page_Unload);
} 


if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
