﻿function addBodyOnLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}
function fixBodyHeight() {
    // firefox only
    if (document.getElementById && navigator.userAgent.indexOf('Firefox') >= 0) {
        var wrapper, contentH, windowH;
        wrapper = document.getElementById('wrapper');
        if (wrapper != null) {
            contentH = wrapper.offsetHeight;
            windowH = document.documentElement.clientHeight;
            if (contentH > 0 && contentH < windowH) {
                // extend the wrapper to the bottom of window to extend the body
                wrapper.style.height = windowH;
            }
        }
    }   
}
function fixFooterWidth() {
    if (document.getElementById) {
        var mainT, footer, widthOffset;
        mainT = document.getElementById('maintable');
        footer = document.getElementById('footer');
        if (mainT !== null && footer !== null && mainT.offsetWidth != footer.offsetWidth) {
            // set the width of footer to match the width of content minus border
            widthOffset = (navigator.userAgent.indexOf('MSIE') > 0) ? 0 : 2;
            footer.style.width = (mainT.offsetWidth - widthOffset) + 'px';
        }
    }
}
// HACK: should be removed after tables are removed
function fixLayoutIssues() {
    fixFooterWidth();
    fixBodyHeight();
}
addBodyOnLoadEvent(fixLayoutIssues);