/* Gallery-Bibliothek */
var iMessageCount = -1;
var strSender = "";
var strFailedErrorTimeout = "";
var strFailedError = "";
var strWebService = "PruemWebService.asmx";
var strWindowTitle;
var speed = 10; //(greater=faster)

var dTimeout = 5000;

function Init() {
    Sys.Net.WebServiceProxy.invoke(strWebService,
        "Command", false, { "strCommand": "Init", "strParameter": "" }, OnSucceeded, OnFailed, null, dTimeout);
}

function Send(cmd, param) {

    Sys.Net.WebServiceProxy.invoke(strWebService,
        "Command", false, { "strCommand": cmd, "strParameter": param }, OnSucceeded, OnFailed, null, dTimeout);
}

// This is the callback function invoked 
// if the Web service succeeded.
function OnSucceeded(result, eventArgs) {
    Command_callback(result);
}

// This is the callback function invoked 
// if the Web service failed.
function OnFailed(error) {
    var strError = "";
    if (error.get_timedOut()) {
        strError = strFailedErrorTimeout;
    }
    else {
        strError = strFailedError;
        strError = strError.replace("@Error@", error.get_message());
    }
    if (strError != "") {
        var bResult = window.confirm(strError);
        if (bResult) {
            Init();
        }
    }
}

function CanMoveright(content, container) {
    var bRet = false;

    if (content && container) {
        objContent = document.getElementById(content);
        objContainer = document.getElementById(container);
    }
    if (parseInt(objContent.style.left) >= objContainer.offsetWidth - objContent.offsetWidth) {
        bRet = true;
    }
    return bRet;
}

function moveright(content, container) {
    if (content && container) {
        objContent = document.getElementById(content);
    }
    if (CanMoveright(content, container))
        objContent.style.left = parseInt(objContent.style.left) - speed + "px";
    timerRight = setTimeout("moveright()", 20);
}

function moveleft(content, container) {
    if (content) {
        objContent = document.getElementById(content);
        objContainer = document.getElementById(container);
    }

    if (parseInt(objContent.style.left) <= -5)
        objContent.style.left = parseInt(objContent.style.left) + speed + "px";
    timerLeft = setTimeout("moveleft()", 20);
}

//preload image for buttons
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

//reset image for buttons
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

//find image for buttons
function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

//swap image for buttons
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

//Show selection
function showselection() {
    alert('showselection')
}

//Show selection
function resetselection() {
    alert('resetselection')
}

// Nur zur Initialisierung
function Command_callback(res) {
    window.status = "";
    try {
        var stateMessage = res;

        if (-1 == iMessageCount || stateMessage._iMessageCount == iMessageCount + 1) {
            iMessageCount = stateMessage._iMessageCount;
            for (var iIdx = 0; iIdx < stateMessage._arrCmds.length; iIdx++) {
                var cmd = stateMessage._arrCmds[iIdx];
                var strCmd = cmd._strCommand;
                var strValue = cmd._strValue;
                var strParam = cmd._strParam;
                var elem = null;
                var arrClass = null;
                switch (strCmd) {
                    case "SetContent":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            elem.innerHTML = strParam;
                            if (elem.style.left != 0)
                                elem.style.left = 0;
                        }
                        break;
                    case "SetStyle":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            elem.className = strParam;
                        }
                        break;
                    case "SetFirstStyle":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            var strNewClass = elem.className;

                            arrClass = strNewClass.split(" ");
                            arrClass[0] = strParam;
                            strNewClass = ""
                            for (var i = 0; i < arrClass.length; i++) {
                                if (strNewClass.length > 0) {
                                    strNewClass += " ";
                                }
                                strNewClass += arrClass[i];
                            }
                            elem.className = strNewClass;
                        }
                        break;
                    case "ScrollIntoView":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            var arrParam = strParam.split("_");
                            if ("" != arrParam[0]) {
                                objContent = document.getElementById(arrParam[0]);
                                objContainer = document.getElementById(arrParam[1]);

                                var Offset = Math.min(objContainer.offsetWidth - elem.offsetLeft - elem.offsetWidth, parseInt(objContent.style.left));
                                Offset = Math.max(0 - elem.offsetLeft, Offset);
                                objContent.style.left = Offset + "px";
                            }
                        }
                        break;
                    case "SetVisibility":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            elem.style.visibility = strParam;
                        }
                        break;
                    case "SetSliderVisibility":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            arrClass = strParam.split("_");
                            if (CanMoveright(arrClass[0], arrClass[1])) {
                                elem.style.visibility = "visible";
                            }
                            else {
                                elem.style.visibility = "hidden";
                            }
                        }
                        break;
                    case "SetImg":
                        elem = document.getElementById(strValue);
                        if (null != elem) {
                            elem.src = strParam;
                            elem.imgNotHo = null;
                        }
                        break;
                    case "SetVar":
                        window[strValue] = strParam;
                        break;
                    case "ShowError":
                        alert(strValue);
                        break;
                }
            }
        }
        else if (null != stateMessage) {
            //Message verloren 
            iMessageCount = stateMessage._iMessageCount;
            window.setTimeout("Send('Init', '');", 10);
        }
    }
    catch (e) {
        window.status = "Fehler:" + e;
    }
}

function OpenPopup(width, height, title, url, param) {
    if ('no' == param) {
        mywin = window.open(url, title);
    }
    else {
        var xsize = screen.availWidth;
        var ysize = screen.availHeight;

        var x = (xsize - width) / 2, y = (ysize - height) / 2;

        mywin = window.open(url, title, param + ', width=' + width + ', height=' + height + ', left=' + x + ', top=' + y);
    }

    if (null != mywin) {
        mywin.focus();
    }
}

function OpenPopupPos(width, height, x, y, title, url, param) {
    if ('no' == param) {
        mywin = window.open(url, title);
    }
    else {
        mywin = window.open(url, title, param + ', width=' + width + ', height=' + height + ', left=' + x + ', top=' + y);
    }

    if (null != mywin) {
        mywin.focus();
    }
}

function Argumente() {
    var arg = null;
    var location = window.location.search;

    if (location.length > 0) {
        arg = new Array()
        location = location.substr(1, location.length - 1);
        arg = location.split("&");
    }
    return arg;
}

function VArgumente() {
    var erg = null;
    var arg = new Array();

    erg = Argumente();

    if (null != erg) {
        for (i = 0; i < erg.length; i++) {
            var x = new Array();
            x = erg[i].split("=");
            arg[x[0]] = x[1];
        }
    }
    return arg;
}

function ZoomWindow() {
    var elem = document.getElementById("DynImage");
    if (null != elem) {
        var strImage = elem.src;
        var iPos = strImage.indexOf("?");
        var strTeil = null;
        if (0 <= iPos) {
            strTeil = strImage.substring(iPos, strImage.length - 1);
            strImage = strTeil;
        }
        iPos = strImage.indexOf("&");
        if (0 <= iPos) {
            strTeil = strImage.substring(0, iPos);
            strImage = strTeil;
        }
        if (null != strWindowTitle && "" != strWindowTitle) {
            strImage = strImage + "&" + "title=" + escape(strWindowTitle);
        }
        iPos = strImage.indexOf("?");
        if (0 > iPos)
        {
            strImage = "";
        }
        window.location.href = "Zoom.htm" + strImage;
    }
}

function checkKeycode(e, strCol, ID) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;

    if (keycode == 13) {
        OnEdit(strCol, ID);
        return false;
    }
    return true;
}

function ButtonClick(Obj) {
    if (null != Obj) {
        Send("ButtonClick", Obj.id);
    }
}

function CloseButtonClick() {
    window.close();
}

function ButtonHover(Obj) {
    if (null != Obj) {
        var strAttrib = Obj.getAttribute("imgHo");

        if (strAttrib) {
            Obj.setAttribute("imgNotHo", Obj.src);
            Obj.src = strAttrib;
        }
    }
}

function ButtonUnhover(Obj) {
    if (null != Obj) {
        var strAttrib = Obj.getAttribute("imgNotHo");

        if (strAttrib) {
            Obj.src = strAttrib;
            Obj.setAttribute("imgNotHo", null);
        }
    }
}

function SelChange(Obj, ColID) {
    if (null != Obj) {
        var strValue = Obj.options[Obj.selectedIndex].value;
        var strParam = strValue.split("#");

        if ("0" == strParam[0]) {
        }
        else if ("1" == strParam[0]) {
            Send("ButtonClick", "RESET_" + ColID);
        }
        else if ("2" == strParam[0]) {
            Send("ChangeChoice", ColID + ";" + strParam[1])
        }
    }
}

function ShowHandhabung() {

    OpenPopupPos(450, 490, 50, 50, "Fenster1", "handhabungshinweis.htm", "");
   
}

