﻿window.onload = resize;
window.onresize = resize;
function resize() {
    var contentpane = document.getElementById("RightPane");
    var height = getWindowHeight() - getElementHeight("TopPane") - getElementHeight("footer") - 45;
    var body = document.getElementsByTagName("body")[0];
    var html = document.getElementsByTagName("html")[0];
    body.style.height = getWindowHeight();
    html.style.height = getWindowHeight();
    var leftpane = document.getElementById("LeftPane");
    try { contentpane.style.height = height + "px"; leftpane.style.height = height + "px"; }
    catch (err) { }
    if (parseFloat(navigator.appVersion.split("MSIE")[1]) == 7) {document.getElementById("Footer").style.position = "static";}
}
function getWindowHeight() {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {windowHeight = document.documentElement.clientHeight; }
        else if (document.body && document.body.clientHeight) { windowHeight = document.body.clientHeight;}
        }
    return windowHeight;
}

function getElementHeight(Elem) {
    try { return document.getElementById(Elem).offsetHeight; }
    catch (err) { return 0; }
    }
function togglesub(el) {
    var target;
    for (var i = 0; i < el.childNodes.length; i++) {
        if (el.childNodes[i].tagName) {
            if (el.childNodes[i].tagName.toLowerCase() == 'ul') {
                target = el.childNodes[i];
            }
        }
    }
    if (target.className == 'moved') { target.className = 'hidden'; }
    else {
        target.className = 'moved';
        var elHeight = parseInt(target.offsetHeight);
        var elpos = parseInt(findPos(target).y);
        var windowHeight = parseInt(getWindowHeight());
        while ((elHeight + elpos) > windowHeight) {
            elpos = parseInt(findPos(target).y);
            target.style.top = (getIntValue(target.style.top) - 1) + "px";
        }    
    }   
}
function getIntValue(value) {
    if (value == '') {return 0; }
    else {return parseInt(value.substring(0, value.indexOf("px")));}
}
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent)
        return { x: curleft, y: curtop };
    }
}

