﻿// BrowserWindowHeight.js

// kmbwh_getBrowserWindowHeight()
//
// Gets the height of the browser window, regardless of the size of its content.
//
// This is sufficient for IE6/7 and Firefox2 when rendering as strict (which they are for ASP.NET thanks
// to the ASP.NET DTD line.) There are other factors that we're ignoring here. This site provides
// a good overview:
//
//     http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function kmbwh_getBrowserWindowHeight()
{
    return document.documentElement.clientHeight;
}

// makeElementTakeUpRestOfBrowserWindow()
//
function kmbwh_makeElementTakeUpRestOfBrowserWindow(theElement, pixelsToLeaveFotFooter)
{
    //var bodyTop = theElement.offsetTop;
    var PageHeaderBannerHeight = 137;  // the green logo banner height
    var bodyTop = kmbwh_findPos(theElement)[1];
    var windowHeight = kmbwh_getBrowserWindowHeight();
    var newBodyHeight = windowHeight - bodyTop - pixelsToLeaveFotFooter + PageHeaderBannerHeight;
    if (newBodyHeight < 1) { newBodyHeight = 1; }
    
    theElement.style.height = newBodyHeight + 'px';
}

// kmbwh_findPos()
//
// Finds the top left corner of the specified dom object.
//
// Thanks to http://www.quirksmode.org/js/findpos.html:
function kmbwh_findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}


