﻿///<reference path="ms_core.js" />
///<reference path="ms_common.js" />

/*
    JAVASCRIPT FUNKTIONEN FÜR DIE MAPSERVER-ENGINE.
    
    | Interface-Funktionen >> 2010-01-15 by Stefan Kowalczyk |
    
    In dieser Code-Datei sind hauptsächlich Funktionen eingebunden, welche für das Zusammenspiel zwischen Benutzercontrols
    (RadControls, HTML controls) und Karte zuständig sind. Der Inhalt dieser Datei wird sich in anderen MapServer-Applikation
    durchaus ändern können.
*/

function MS_Interface_OpenDialog(nMode) {
    ///<summary>Öffnet je nach Modus das entsprechende neue Fenster.</summary>
    ///<param name="nMode">Modus der zu öffnenden Programmfunktionalität. 0 = Infos, 1 = SaveMap-Tool</param>
    var cPage = "";
    var cWindowName = "";

    switch (nMode) {
        case 0:
            cPage = "MapsInfo.htm";
            cWindowName = "InfoWin";
            break;
        case 1:
            cPage = "../MapEngine/Tools/SaveMap.aspx?guid=" + document.getElementById(cGlobalPlaceHolderName + "_CurrentGUID").value;
            cWindowName = "SaveMap";
            break;
    }

    if (cPage != "") {
        window.radopen(cPage, cWindowName);
    }

    return false;
}   

function MS_Interface_ToolbarCheckedStateChanged(sender, args) {
    ///<summary>Setzt den Mausmodus (ZoomIn oder Pan) ausgehend von den gedrückten Buttons in der Toolbar.</summary>
    var oBtn = args.get_item();

    var cBtnValue = oBtn.get_value();
    if (!oBtn.get_isSeparator() && (cBtnValue == "ZoomIn" || cBtnValue == "PanMap")) {

        var nMM = 0;
        if (cBtnValue == "ZoomIn")
            nMM = 1;
        else if (cBtnValue == "PanMap")
            nMM = 3;

        if (oBtn.get_checked())
            MS_Interface_SetMouseMode(nMM);
        else
            MS_Interface_SetMouseMode(0);
    }
}

function MS_Interface_ToolbarButtonClicked(sender, args) {
    ///<summary>Event-Funktion die beim Klicken eines Buttons in der Toolbar ausgelöst wird.</summary>
    var oBtn = args.get_item();

    if (oBtn.get_value() == "SaveMap")
        MS_Interface_OpenDialog(1);
    else if (oBtn.get_value() == "ClearMap") {
        if (confirm("This function clears the currently generated map. Furthermore, all created layers and history entries will be discarded. Are you sure you want to do this?"))
            window.location = "Maps.aspx";
    }
}

function MS_Interface_SetSymbolSize2Label(sender, eventArgs) {
    ///<summary>Aktualisiert das Label, welches die gewählte Symbolgröße als Zahlwert darstellt.</summary>
    document.getElementById(cGlobalPlaceHolderName + "LabelSymbolSize").innerHTML = "Symbol size (" + sender.get_value() + "):";
    return false;
}

function MS_Interface_ShowMiniMap() {
    ///<summary>Zeigt die MiniMap als ToolTip an.</summary>
    var cFontFace = "Verdana, Arial";
    var cText = "<table><tr><td style='padding: 6px; text-align:center'><img style='border: 1px solid #000000' src='../MapEngine/Temp/_Maps/" + document.getElementById(cGlobalPlaceHolderName + "_CurrentMM").value + "' /></td></tr></table>";
    var cTitleText = "Mini map (overall look)";
    var nWidth = 235;
    var cTextAlign = "center";
    var cTitle = "<span style='font-weight:normal; color:#000000'>&nbsp;" + cTitleText + "</span>";

    Tip(cText, TITLEFONTSIZE, '10px', TITLE, cTitle, TITLEFONTSIZE, '12px', TITLEFONTFACE, cFontFace, TITLEBGCOLOR, '#89AEE2', BORDERCOLOR, '#89AEE2', FONTFACE, cFontFace, FONTSIZE, '11px', FONTCOLOR, '#333333', WIDTH, nWidth, TEXTALIGN, cTextAlign);
}

function MS_Interface_SetMouseMode(nMouseMode) {
    ///<summary>Setzt den entsprechenden Mausmodus global und selektiert bzw. deselektiert die entsprechenden Toolbar-Buttons</summary>
    ///<param name="nMouseMode">1 = ZoomIn (Crosshair); 2 = Identify (Help); 3 = Pan (Move); 0 = Standard.</param>
    if (nMouseMode == 1) {    
        oMapControl.style.cursor = "crosshair";
        nGlobalMouseMode = 1;
    }
    else if (nMouseMode == 2) {
        oMapControl.style.cursor = "help";
        nGlobalMouseMode = 2;
    }
    else if (nMouseMode == 3) {
        oMapControl.style.cursor = "move";
        nGlobalMouseMode = 3;
    }
    else {
        oMapControl.style.cursor = "default";
        nGlobalMouseMode = 0;
    }
}

function MS_Interface_AdaptCurrentXYLabelPosition() {
    ///<summary>Kleine Hilfsfunktion, welche die Position der XY-Statusbar für nicht IE-Browser feinjustiert.</summary>
    if (!MS_Browser_isIE()) {
        var cAdaptStyle = "left:17px; top:582px";

        document.getElementById("Label_CurrentXY_Background").setAttribute("style", cAdaptStyle);
        document.getElementById("Label_CurrentXY").setAttribute("style", cAdaptStyle);
    }    
}
