/* JavaScript Library */
var ns4 = (document.layers)?1:0;
var dom = (document.getElementById && !document.all);
var ie4 = (document.all)?1:0;
var opr = (navigator.userAgent.indexOf("Opera") == 0) && (!ie6);
var moz = navigator.appName=="Netscape" && navigator.appCodeName=="Mozilla" && !document.all;
var mac = navigator.userAgent.indexOf("Mac")!= -1;
var ie6 =(navigator.userAgent.indexOf("Opera") < 0) && (!moz);

var hoehe = 0;

window.status = "DB Schenker"; // writes Javascript default message in browser status bar

// calculate the height of a layer
function getDivsHeight() {
    var iDivsHeight = 0;
    for(var i=0; i < arguments.length; i++) {
        if (document.getElementById(arguments[i])) {
            iDivsHeight += document.getElementById(arguments[i]).offsetHeight;
        }
    }
    return iDivsHeight;
}

// set the height of the back main layer in order to move the footer
function setDivContentMinHeight() {
    var oDivcontent, iWinInnerHeight, tmpHeight;
    var mozCorrection = moz ? -1 : 0;
    oDivcontent = document.getElementById(arguments[0]); //assumes first passed object as name for the content area layer
    oStopperDiv = document.getElementById(arguments[1]); // retrieve stopper div object
    oAddColumn = document.getElementById(arguments[4]);

    iWinInnerHeight = document.body.clientHeight; // store window height of the inner browser area temporarily

    // calculate the height of the page elements except the content area; using the getDivsHeight function
    if (arguments.length > 5) {
        // called from initPopup.
        tmpHeight = getDivsHeight(arguments[2], arguments[3], arguments[4]);
        mozCorrection = moz ? arguments[5] : 0;
    } else if (arguments.length == 5) {
        tmpHeight = getDivsHeight(arguments[2], arguments[3]); // header, footer
    } else if (arguments.length == 4) {
        tmpHeight = getDivsHeight(arguments[2]);
    }

    //if there is more space on the page than the header and footer height, than the main layer is set to a new height
    if(oStopperDiv) {
        if (iWinInnerHeight > (tmpHeight + oStopperDiv.offsetTop + oStopperDiv.offsetHeight)) {
            if (oAddColumn) {
                if ((iWinInnerHeight - tmpHeight + mozCorrection) < oAddColumn.offsetHeight) {
                    oDivcontent.style.height = oAddColumn.offsetHeight + oStopperDiv.offsetHeight + mozCorrection;
                } else {
                    oDivcontent.style.height = iWinInnerHeight - tmpHeight + mozCorrection;
                }
            } else {
                oDivcontent.style.height = iWinInnerHeight - tmpHeight + mozCorrection;
            }
        } else {
            if (oAddColumn) {
                if ((oStopperDiv.offsetTop + oStopperDiv.offsetHeight + mozCorrection) < oAddColumn.offsetHeight) {
                    oDivcontent.style.height = oAddColumn.offsetHeight + oStopperDiv.offsetHeight + mozCorrection;
                } else {
                    oDivcontent.style.height = oStopperDiv.offsetTop + oStopperDiv.offsetHeight + mozCorrection;
                }
            } else {
                oDivcontent.style.height = oStopperDiv.offsetTop + oStopperDiv.offsetHeight + mozCorrection;
            }
        }
    }
}

// set the height of the back main layer in order to move the footer -- Popup version
function setDivContentMinHeightPopup() {
    var hoehe = window.opener.hoehe;
    var oDivcontent, iWinInnerHeight, tmpHeight;
    var mozCorrection = moz ? -1 : 0;

    oDivcontent = document.getElementById(arguments[0]); //assumes first passed object as name for the content area layer
    tmpHeight = oDivcontent.offsetHeight;
    oStopperDiv = document.getElementById(arguments[1]); // retrieve stopper div object
    // wenn Video, dann nimm Element 'videoBrd', wenn Bildergallerie 'galleryBrd', sonst nichts.
    oBrdDiv = document.getElementById(arguments[6]);
    if(!oBrdDiv) oBrdDiv = document.getElementById(arguments[7]);

    iWinInnerHeight = document.body.clientHeight; // store window height of the inner browser area temporarily

    // calculate the height of the page elements except the content area; using the getDivsHeight function
    // called from initPopup.
    mozCorrection = moz ? arguments[5] : 0;
    headerHeight = getDivsHeight(arguments[2]);
    buttonHeight = getDivsHeight(arguments[3]);
    footerHeight = getDivsHeight(arguments[4]);
    //if (tmpHeight > hoehe) {
    //  tmpHeight = hoehe - headerHeight - footerHeight - buttonHeight;
    //}

    //if there is more space on the page than the header and footer height, than the main layer is set to a new height
    if(oStopperDiv) {
        //if (iWinInnerHeight > (footerHeight + buttonHeight + oStopperDiv.offsetTop + oStopperDiv.offsetHeight)) {
        if (iWinInnerHeight > (footerHeight + buttonHeight + headerHeight + oDivcontent.offsetHeight)) {
            // Fenster größer als Contentbereich, Footer wird runter geschoben
            if(ie6) {
                oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 13;
            }
            if(moz) {
                oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 20;
            }
            if(opr) {
                oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 13;
                if(oBrdDiv) {
                    oBrdDiv.style.height = iWinInnerHeight - footerHeight - headerHeight;
                }
                if(!oBrdDiv) {
                    if (ie6) {
                        //oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight -13;
                    } else {
                        //oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight -20;
                    }
                }
            } else {
                if(oBrdDiv) {
                    oBrdDiv.style.height = iWinInnerHeight - footerHeight - headerHeight;
                }
                if(!oBrdDiv) {
                    //oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight;
                }
            }
        } else {
            if (!ie6) mozCorrection = 7;
            if (hoehe <= 455) {
                if (opr) {
                    oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 7;
                }
                if (moz) {
                    if (iWinInnerHeight < hoehe) {
                        oDivcontent.style.height = hoehe - buttonHeight - footerHeight - headerHeight - 20;
                    } else {
                        oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 20;
                    }
                }
                if (ie6) {
                    oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 20;
                }
            } else {
                if(moz) {
                    if (iWinInnerHeight < hoehe) {
                        //oDivcontent.style.height = hoehe - headerHeight - 20;
                        oDivcontent.style.height = tmpHeight;
                    } else {
                        //oDivcontent.style.height = iWinInnerHeight - headerHeight;
                        oDivcontent.style.height = tmpHeight - headerheight;
                    }
                } else {
                    oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 20;
                }
            }
            if(oBrdDiv) {
                if(moz) {
                    oBrdDiv.style.height = iWinInnerHeight - footerHeight - headerHeight;
                }
                if(ie6) {
                    oBrdDiv.style.height = hoehe - headerHeight - footerHeight;
                }
                if(opr) {
                    oBrdDiv.style.height = hoehe - footerHeight - headerHeight + 13;
                }
            } else {
                if (hoehe <= 455) {
                    if (opr) {
                        oDivcontent.style.height = iWinInnerHeight - buttonHeight - footerHeight - headerHeight - 13;
                    }
                }
            }
        }
    }
}

// Wrapper function to apply the changes to the footer on the startpage
// only used in startpage because of different div-container structure
function initStart(loadEvent) {
    if (!ns4) {
        setDivContentMinHeight('maincontainer', 'stopper', 'header', 'footer', 'addColumnStartPage');
        footero=document.getElementById('footer');
        footero.style.visibility='visible';
    }
    if (loadEvent && ie4 && !ns4 && ((navigator.appVersion.indexOf("MSIE 5.0")!= -1) || (mac))) {
        window.resizeBy(1,1);
        window.resizeBy(-1,-1);
    }
}

// onMouseOvers for the PortalNavigation
var initSet = false;

function initImages() {
    if (numPortalImages && imgInactNames && imgActNames) {
        for (var i=0; i< numPortalImages; i++) {
            var tempImage = new Image();
            tempImage.src = imgInactNames[i];
            tempImage.src = imgActNames[i];
        }
    }
}

function actImg(obj, num) {
    if (document.images && !ns4 && imgActNames) {
        document.getElementById(obj.id).src = imgActNames[num];
    }
}

function inActImg(obj, num) {
    if (document.images && !ns4 && imgInactNames) {
        document.getElementById(obj.id).src = imgInactNames[num];
    }
}

function resizeToInnerSize(newWidth, newHeight){
    curWidth = document.body.clientWidth;
    curHeight = document.body.clientHeight;

    var mozCorrection = moz ? 1 : 0;

    var wDiff = newWidth - curWidth;
    wDiff += mozCorrection;
    var hDiff = newHeight - curHeight;

    resizeBy(wDiff, hDiff);
}

