//Makes any row scrollable
//Usage:    Add " <tr id="HeaderRow"> " to any row or element that needs to be scrolled
//          Add " HeaderRowId = 'HeaderRow'; "  and  " HeaderRowOffset = 130; "
//          in header script block if the default 140 is not acceptable



var HeaderRowId = 'HeaderRow'; //default value
var HeaderRowOffset = 132; //default value
window.onscroll = document.documentElement.onscroll = function scrollHeader() {
    //alert('hi');
    var header = document.getElementById(HeaderRowId);
    if (header != null) {
        header.style.position = 'relative';
        //IE 7 or IE 8 in "Compatibility Mode" cannot set position for TH properly, so only set it for IE 8 - VB
        if (engine > 7) {
            SetRowToRelativePosition(header);
        }
        header.style.top = 0;
    }
    var currentOffset = document.body.scrollTop || document.documentElement.scrollTop;
    if (header && header.style && header.style.top) {
        if (currentOffset > HeaderRowOffset) {
            header.style.top = (currentOffset - HeaderRowOffset);

            SetRowTopPosition(header, header.style.top);
        } else {
            header.style.top = 0;
            SetRowTopPosition(header, 0);
        }
    }
}

function SetRowTopPosition(row, top) {
 
    var cells = row.getElementsByTagName("TH");
    for (var i = 0; i < cells.length; i++) 
    cells[i].style.top = top;
}

function SetRowToRelativePosition(row) 
{
    var cells = row.getElementsByTagName("TH");
    for (var i = 0; i < cells.length; i++) 
    cells[i].style.position = 'relative';
}


engine = null;
if (window.navigator.appName == "Microsoft Internet Explorer") {
    // This is an IE browser. What mode is the engine in?
    if (document.documentMode) // IE8
        engine = document.documentMode;
    else // IE 5-7
    {
        engine = 5; // Assume quirks mode unless proven otherwise
        if (document.compatMode) {
            if (document.compatMode == "CSS1Compat")
                engine = 7; // standards mode
        }
    }
    //alert(engine);
    // the engine variable now contains the document compatibility mode.
}




