
/**
 * Versteckt das, mit 'showImgPopup()' angezeigte Inline-Popup-Fenster.
 *
 * @return void
 */
function hideImgPopup(oEvent)
{
    if (!isProDHTML) {
        return;
    }

    if (oEvent && typeof oEvent.stopPropagation != 'undefined') {
        oEvent.stopPropagation();
    } else {
        oEvent = window.event;
        if (oEvent && typeof oEvent.cancelBubble != 'undefined') {
            oEvent.cancelBubble = true;
        }
    }

    var oTarget = document.getElementById('boxImgPopup');
    if (!oTarget) {
        return;
    }

    window.setTimeout('removeDocClickListener(hideImgPopup)', 1); // main.js

    if (oTarget.style.display == 'block') {
        with (oTarget.style) {
            display = 'none';
            top = '-9999px';
        }
    }
}

/**
 * Zeigt ein Inline-Popup-Fenster (Iframe-Basis) fuer die Ausgabe eines frei definierbaren
 * ('src', 'width', 'height') Bildes an.
 *
 * @param object oElement (required) Das HTML-Objekt, das die Anzeige des Popups angefordert hat.
 * @param string sImgSrc (required) Der Pfad zum Bild, das im Popup angezeigt werden soll.
 * @param integer iImgWidth (required) Die Breite des Bildes.
 * @param integer iImgHeight (required) Die Hoehe des Bildes.
 * @param string sHeadline (required) Der Titel des Bildes (wird im Popup-Fenster als Headline
 *                                    angezeigt).
 * @param bool blPageCenter (default false) Soll das Bild im Zentrum des Browser-Fensters
                                            angezeigt werden (Standard: Zentriert ueber dem
                                            aufrufenden Objekt).
 * @param bool blPrinter (default false) Soll ein Print-Button über dem Bild angezeigt werden.
 * @return void
 */
function showImgPopup(oElement, sImgSrc, iImgWidth, iImgHeight, sHeadline, blPageCenter, blPrinter)
{
    if (!isProDHTML) { // main.js
        return true;
    }
    var oTarget = document.getElementById('boxImgPopup');
    var oIframe = document.getElementById('imgPopup');
    var oTitleDiv = document.getElementById('imgPopupTitle');
    if (!oIframe || !oTarget || !oTitleDiv) {
        return true;
    }
    if (parseInt(oTarget.style.top) > -9999 && oTarget.style.display == 'block') {
        return false;
    }

    oTarget.style.display = 'block';

    /* Configuration */
    var iOverflowX = 15; // border-left + border-right
    var iOverflowY = 48; // border-bottom + border-top + tab-height
    var iRightScrollbarWidth = 16;
    var iBottomScrollbarWidth = 16;
    /* EOF Configuration */

    blPageCenter = blPageCenter ? true : false;
    blPrinter = blPrinter ? true : false;
    var blIsFullSize = true;
    var oIframeWin = frames['imgPopup'] ? frames['imgPopup'] : null;
    var oIframeDoc = oIframeWin && oIframeWin.document ? oIframeWin.document : null;
    var oRoot = typeof document.compatMode == 'string' && document.compatMode.toLowerCase().indexOf('css') != -1
                ? document.documentElement
                : document.getElementsByTagName('body')[0];

    var aElement = getNodeCoordinates(oElement);
    aElement['sHeadline'] = sHeadline || oElement.getAttribute('title') || '';
    aElement['iWidth'] = aElement[2];
    aElement['iHeight'] = aElement[3];
    aElement['iLeft'] = aElement[0];
    aElement['iTop'] = aElement[1];
    aElement['iCenterX'] = aElement['iLeft']+(aElement['iWidth']/2);
    aElement['iCenterY'] = aElement['iTop']+(aElement['iHeight']/2);

    var aImg = new Array();
    aImg['sSrc'] = sImgSrc || '';
    aImg['iWidth'] = iImgWidth || 0;
    aImg['iHeight'] = iImgHeight || 0;

    var aClient = new Array();
    aClient['iWidth'] = window.innerWidth
                        ? window.innerWidth-iRightScrollbarWidth
                        : (oRoot && oRoot.clientWidth ? oRoot.clientWidth : 0);
    aClient['iHeight'] = window.innerHeight
                         ? window.innerHeight-iBottomScrollbarWidth
                         : (oRoot && oRoot.clientHeight ? oRoot.clientHeight : 0);
    aClient['iLeft'] = window.pageXOffset || (oRoot ? oRoot.scrollLeft : 0) || 0;
    aClient['iTop'] = window.pageYOffset || (oRoot ? oRoot.scrollTop : 0) || 0;
    aClient['iRight'] = aClient['iLeft']+aClient['iWidth'];
    aClient['iBottom'] = aClient['iTop']+aClient['iHeight'];
    aClient['iCenterX'] = aClient['iLeft']+(aClient['iWidth']/2);
    aClient['iCenterY'] = aClient['iTop']+(aClient['iHeight']/2);

    var aTarget = new Array();
    var aIframe = new Array();
    if (aImg['iWidth']+iOverflowX <= aClient['iWidth']) {
        aTarget['iWidth'] = aImg['iWidth']+iOverflowX;
        aIframe['iWidth'] = aImg['iWidth'];
    } else {
        aTarget['iWidth'] = aClient['iWidth'];
        aIframe['iWidth'] = aClient['iWidth']-iOverflowX;
        blIsFullSize = false;
    }
    if (aImg['iHeight']+iOverflowY <= aClient['iHeight']) {
        aTarget['iHeight'] = aImg['iHeight']+iOverflowY;
        aIframe['iHeight'] = aImg['iHeight'];
    } else {
        aTarget['iHeight'] = aClient['iHeight'];
        aIframe['iHeight'] = aClient['iHeight']-iOverflowY;
        blIsFullSize = false;
    }
    if (blPageCenter) {
        aTarget['iLeft'] = aClient['iCenterX']-(aTarget['iWidth']/2);
        aTarget['iTop'] = aClient['iCenterY']-(aTarget['iHeight']/2);
    } else {
        aTarget['iLeft'] = aElement['iCenterX']+(aTarget['iWidth']/2) > aClient['iRight']
                           ? aClient['iRight']-aTarget['iWidth']
                           : (aElement['iCenterX']-(aTarget['iWidth']/2) < aClient['iLeft']
                              ? aClient['iLeft']
                              : aElement['iCenterX']-(aTarget['iWidth']/2));
        aTarget['iTop'] = aElement['iCenterY']+(aTarget['iHeight']/2) > aClient['iBottom']
                          ? aClient['iBottom']-aTarget['iHeight']
                          : (aElement['iCenterY']-(aTarget['iHeight']/2) < aClient['iTop']
                             ? aClient['iTop']
                             : aElement['iCenterY']-(aTarget['iHeight']/2));
    }

    if (oIframeDoc) {
        with (oTarget.style) {
            width = aTarget['iWidth'] + 'px';
            height = aTarget['iHeight'] + 'px';
        }
        with (oIframe.style) {
            width = aIframe['iWidth'] + 'px';
            height = aIframe['iHeight'] + 'px';
        }
        var oIframeBox = oIframeDoc.getElementById('boxImg');
        if (typeof oIframeBox.innerHTML == 'string') {
            // Mozilla-Hack. Umgeht Mozillas "Grafiken veraendern" Einstellung.
            oIframeBox.innerHTML = '<img id="oldImg" src="' + aImg['sSrc'] + '" alt=""'
                                   + 'style="display:block;width:' + aImg['iWidth'] + 'px;height:'
                                   + aImg['iHeight'] + 'px;border-style:none;border-width:0;">';
        } else {
            var oIframeOldImg = oIframeDoc.getElementById('oldImg');
            if (oIframeOldImg) {
                oIframeBox.removeChild(oIframeOldImg);
            }
            var oIframeImg = oIframeDoc.createElement('img');
            oIframeBox.appendChild(oIframeImg);
            with (oIframeImg) {
                setAttribute('id', 'oldImg');
                setAttribute('src', aImg['sSrc']);
                setAttribute('style', 'display:block;width:' + aImg['iWidth'] + 'px;height:'
                                      + aImg['iHeight'] + 'px;border-style:none;border-width:0;');
                setAttribute('alt', '');
            }
        }
        if (blIsFullSize && typeof oIframeWin.scrollbars == 'object' && oIframeWin.scrollbars.visible == true) {
            with (oIframe.style) { // Mozilla-Hack (muss vor Printer stehen!)
                overflow = 'hidden';
                overflow = 'auto';
            }
        }
        if (blPrinter) {
            var oIframeBoxPrinter = oIframeDoc.getElementById('boxPrinter');
            if (oIframeBoxPrinter) {
                with (oIframeBoxPrinter.style) {
                    display = 'none'; // Mozilla-Hack
                    display = 'block';
                }
            }
        }
        if (aElement['sHeadline']) {
            oTitleDiv.lastChild.nodeValue = aElement['sHeadline'];
            var oIframeDocTitle = oIframeDoc.getElementsByTagName('title')[0];
            if (typeof oIframeDocTitle.text == 'string') {
                oIframeDocTitle.text = aElement['sHeadline'];
            } else if (typeof oIframeDoc.title == 'string') {
                oIframeDoc.title = aElement['sHeadline'];
            }
        }
        with (oTarget.style) {
            left = aTarget['iLeft'] + 'px';
            top = aTarget['iTop'] + 'px';
        }

        window.setTimeout('addDocClickListener(hideImgPopup)', 100); // main.js
    }

    return false;
}