﻿function winpageLoad() {
    var bw = 0;
    var myHeight;
    var h_header, h_menu, h_navbar, h_footer;
    var h_header_val, h_menu_val, h_navbar_val, h_footer_val;
    
    if (typeof (window.innerHeight) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
        bw = 1;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    }
    //var ht = myHeight;
    
    oHeader = document.getElementById("header");
    oMainContent = document.getElementById("maincontent");
    oContent = document.getElementById("content_all");
    oContentLeft = document.getElementById("content_left");
    oContentRight = document.getElementById("content_right");
    oMenu = document.getElementById("menu");
    oNavBar = document.getElementById("navbar");
    oFooter = document.getElementById("footer");

    if (bw == 1) {
        // non IE
        h_header = document.defaultView.getComputedStyle(oHeader, null).getPropertyValue("height");
        h_menu = document.defaultView.getComputedStyle(oMenu, null).getPropertyValue("height");
        h_navbar = document.defaultView.getComputedStyle(oNavBar, null).getPropertyValue("height");
        h_footer = document.defaultView.getComputedStyle(oFooter, null).getPropertyValue("height");
        h_contentLeft = document.defaultView.getComputedStyle(oContentLeft, null).getPropertyValue("height");
        h_contentRight = document.defaultView.getComputedStyle(oContentRight, null).getPropertyValue("height");
        ht = convertHeight(myHeight, h_header, h_menu, h_navbar, h_footer, h_contentLeft, h_contentRight);
        var h_style_apply = "height:" + ht + "px";
        oContentRight.setAttribute("style", h_style_apply);
    }
    else {
        // IE
        h_header = oHeader.currentStyle.height;
        h_menu = oMenu.currentStyle.height;
        h_navbar = oNavBar.currentStyle.height;
        h_footer = oFooter.currentStyle.height;
        h_contentLeft = oContentLeft.offsetHeight + "px";
        h_contentRight = oContentRight.offsetHeight + "px";
        ht = convertHeight(myHeight, h_header, h_menu, h_navbar, h_footer, h_contentLeft, h_contentRight);
        oContentRight.style.height = ht;
    }
}

function convertHeight(myHeight, h_header, h_menu, h_navbar, h_footer, h_contentLeft, h_contentRight) {
    // remove the 'px' from property values
    h_header_val = stringLength(h_header);
    h_menu_val = stringLength(h_menu);
    h_navbar_val = stringLength(h_navbar);
    h_footer_val = stringLength(h_footer);
    h_contentLeft_val = stringLength(h_contentLeft);
    h_contentRight_val = stringLength(h_contentRight);
    if (h_contentLeft_val > myHeight) {
        myHeight = h_contentLeft_val;
        ht = myHeight;

    }
    if (h_contentRight_val > myHeight) {
        myHeight = h_contentRight_val;
        ht = myHeight;
    } 
    else {
        ht = myHeight - h_header_val - h_menu_val - h_navbar_val - h_footer_val;
        //alert(myHeight + "," + h_header_val + "," + h_menu_val  + "," + h_navbar_val  + "," + h_footer_val);
    }
    //alert(h_contentLeft_val + "," + h_contentRight_val);
    return ht;
}

function stringLength(orgstring) {
    var resstr;
        var slen = orgstring.length;
        switch (slen) {
            case 3:
                resstr = orgstring.substr(0, 1);
                break;
            case 4:
                resstr = orgstring.substr(0, 2);
                break;
            case 5:
                resstr = orgstring.substr(0, 3);
                break;
            case 6:
                resstr = orgstring.substr(0, 4);
                break;
            case 7:
                resstr = orgstring.substr(0, 5);
                break;
        }
    return resstr;
}

