﻿// a singelton Behaviour !
var LightBoxBehavior = {
    obj: null, // a pointer to the lightbox overlay
    dlg: null, // the current displayed dialog element

    init: function() {
        if (this.obj != null)
            alert("The LightBox behavior can only be included once!");
        LightBoxBehavior.obj = this;
    }, // init


    term: function() {
        LightBoxBehavior.dlg = null;
        LightBoxBehavior.obj = null;
    },


    // open the current Dialog
    open: function(dlg) {
        if (LightBoxBehavior.dlg != null)
            LightBoxBehavior.hide();

        if ((dlg != null) && (dlg.constructor == String))
            dlg = document.getElementById(dlg);
        LightBoxBehavior.dlg = dlg;
        LightBoxBehavior.show();
    }, // open


    // show the current or a new dialog element
    show: function() {
        var obj = LightBoxBehavior.obj;
        var dlg = LightBoxBehavior.dlg;
//        var h = Math.max(document.documentElement.clientHeight, document.documentElement.scrollHeight) + "px";
        var H = (document.body.offsetHeight > document.body.scrollHeight) ? document.body.offsetHeight : document.body.scrollHeight;
        obj.style.height = H;
        obj.style.width = document.documentElement.scrollWidth + "px";

        window.scrollTo(0, 0);
        obj.style.zIndex = 98;
        obj.style.display = "block";
        obj.style.visibility = 'visible';

        if (dlg != null) {
            dlg.style.zIndex = 99;
            dlg.style.position = "absolute";
            dlg.style.display = "block";
            dlg.style.visibility = 'visible';

            //dlg.style.top = (document.documentElement.clientHeight - dlg.scrollHeight) / 2 + "px";
            //dlg.style.left = (document.documentElement.offsetWidth - dlg.scrollWidth) / 2 + "px";
//            dlg.style.top = '260px';
  //          dlg.style.left = '360px';
            //            dlg.focus();
        } // if
    }, // show


    // hide the current Dialog in msec milliseconds
    autoHide: function(msec) {
        window.setTimeout(LightBoxBehavior.hide, msec);
    }, // autoHide

    // hide the current Dialog
    hide: function() {
        var obj = LightBoxBehavior.obj;
        var dlg = LightBoxBehavior.dlg;

        obj.style.display = "none";
        obj.style.visibility = 'hidden';

        if (dlg != null) {
//            dlg.style.zIndex = null;
            dlg.style.display = "none";
            dlg.style.visibility = 'hidden';
            dlg.style.position = "";
            LightBoxBehavior.dlg = null;
        } // if
    }, // hide


    // show the current Dialog
    openUrl: function(url) {
        LightBoxBehavior.dlg.innerHTML = "<p>loading..." + url + "</p>";
        var f = LightBoxBehavior.frame;
        f.src = url;
        f.onreadystatechange = LightBoxBehavior.ready;
        f.onload = LightBoxBehavior.ready;
        LightBoxBehavior.show();
    }, // openUrl


    ready: function() {
        var f = LightBoxBehavior.frame;
        if ((f.readyState == null) || (f.readyState == "complete")) {
            var s = f.contentWindow.document.body.innerHTML;
            LightBoxBehavior.dlg.innerHTML = s; "<p>loading...<br /><br /><br /><br />....</p>";

            var dlg = LightBoxBehavior.dlg;
            dlg.style.width = dlg.scrollWidth;
            dlg.style.top = (document.documentElement.clientHeight - dlg.scrollHeight) / 2 + "px";
            dlg.style.left = (document.documentElement.offsetWidth - dlg.scrollWidth) / 2 + "px";
        }

    } // ready
} // LightBoxBehavior

    var x;
    var y;
    function GetCoordinates() {
        var myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            y = window.innerHeight;
            x = window.innerWidth;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            y = document.documentElement.clientHeight;
            x = document.documentElement.clientWidth;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            y = document.body.clientHeight;
            x = document.body.clientWidth;
        }
        if (document.documentElement && document.documentElement.clientHeight) {
            //        x = document.documentElement.clientWidth;
            //        y = document.documentElement.clientHeight;
        }
        else {
            //      x = document.body.clientWidth;
            //      y = document.body.clientHeight;
        }
        var w = document.body.clientWidth || innerWidth;
        var h = document.body.clientHeight || innerHeight;
        var W = (document.body.offsetWidth > document.body.scrollWidth) ? document.body.offsetWidth : document.body.scrollWidth;
        var H = (document.body.offsetHeight > document.body.scrollHeight) ? document.body.offsetHeight : document.body.scrollHeight;
        x = W;
        y = H;
        var d = document.createElement('P');
        d.innerHTML = 'View Port : width = ' + w + ' -- height = ' + h + '<br>' +
               'Window : width = ' + W + ' -- height = ' + H + '<br>';
        document.body.appendChild(d);
    }
    function OpenModalPopupSiegel() {
        var popUp = document.getElementById('ModalPopupSiegel');
        window.scrollTo(0, 0);
        LightBoxBehavior.open(popUp);
    }
    function OpenModalPopupMerkliste() {
        var popUp = document.getElementById('ModalPopupDiv');
        window.scrollTo(0, 0);
        LightBoxBehavior.open(popUp);
    }
    function OpenModalPopupNetzwerkliste(sTicket) {
        var sURL = "/GB/HelpPages/INetzwerkTags.aspx?Ticket=" + sTicket + "&rnd=" + Math.random();
        window.frames.iFrameTagsListe.location.href = sURL;
        var popUp = document.getElementById('ModalPopupDiv');
        window.scrollTo(0, 0);
        LightBoxBehavior.open(popUp);
    }

    function OpenModalPopupSuchliste() {
        var popUp = document.getElementById('ModalPopUpDiv2');
        window.scrollTo(0, 0);
        LightBoxBehavior.open(popUp);
    }
    function CloseModalPopupSiegel() {
        LightBoxBehavior.hide();
    }
    function CloseModalPopupParent() {
        LightBoxBehavior.hide();
    }
    function CloseModalPopupMerkliste() {
        LightBoxBehavior.hide();
    }

    function CloseModalPopupSuchliste() {
        LightBoxBehavior.hide();
    }
    function Submit() {
        if (document.getElementById('txtName').value != '') {
            document.getElementById('MaskedDiv').style.display = 'none';
            document.getElementById('ModalPopupDiv').style.display = 'none';
            document.getElementById('tdDisplayName').innerHTML = '<H1> Hi ' + document.getElementById('txtName').value + ' !</H1>';
        }
        else {
            alert('Please enter your name');
        }
    }
    function InitLightBox() {
        var maskedDIV = document.getElementById('MaskedDiv');
        LightBoxBehavior.obj = maskedDIV;
    }

    addHandler(window, 'load', InitLightBox);
