// This is to support scrolling on the areas of HTML document.
// The scrolling may be implemented by using "overflow" style of <div> element.
// However different browsers do it differently.
// In Internet Explorer it is enough to set the style to
// "height:100%;width:100%;overflow:auto" and
// the div element will take all the available space, showing scrollbars if needed.
//
// Firefox does not work this way. <div> needs the width and height to be
// explisitly set in pixels, otherwise it never shows scrollbars. Intead, the
// whole browser window becomes scrollable.

// This library supports scrolling be setting the size of the elements in pixels.
// The JSP pages should regster the elements that require scrolling.
// after that the script will resize all the registsred elements when the page
// reloads, or when the browser window resizes.

// the elements to resize; each row keeps the information about one element:
// 1) name of the element;
// 2) what should be height of the element relative to available height of
// <body> element. This is typically a negative value.

var elementsToResize = new Array();

function registerScrollElement(name, sizeDiff) {
    elementsToResize[elementsToResize.length] = new Array(name, sizeDiff);
}

function performResize() {
    if (!(agent.ie4up)) {
        var windowsHeight = getWindowHeight();
        for (var i = 0; i < elementsToResize.length; i++) {
            var tmp = elementsToResize[i];
            var name = tmp[0];
            var sizeDif = tmp[1];
            var e = findElementById(name);
            e.style.height = windowsHeight + sizeDif;
        }

        // window.resizeBy(0,0);
    }
}

function initScrollSupport() {
    if (!(agent.ie4up)) {
        // for non-microsoft browsers: register "onresize" event
        if (document.body) {
            document.body.setAttribute('onresize', "return performResize()");
        }
    }
}
