
var bDebugDisplayTagDivision = getClassCookieFlag('Debug', 'DisplayTagDivision');   //[test] make sure this is set to false
var bDebugDisplayAdjustListviewHeight = getClassCookieFlag('Debug', 'DisplayAdjustListviewHeight');   //[test] make sure this is set to false
var bDebugDisplayAdjustPopupListviewHeight = getClassCookieFlag('Debug', 'DisplayAdjustPopupListviewHeight');   //[test] make sure this is set to false

var nWindowWidth = 0;
var nWindowHeight = 0;
var nWindowSizeType = -1;
var strWindowSizeType = '';
var nHeaderHeight = 0;
var nHeaderWidth = 0;
var nSubHeaderHeight = 0;
var nContentWrapTop = 0;
var nContentContainerTop = 0;
var nFooterHeight = 0;
var nFooterWidth = 0;
var nCookieWidth = 0;
var nCookieHeight = 0;

    //row height and scroll bar sizes
var nListViewRowHeight = 22;                //list view row height (might be available via a style value)
var nVertScrollBarWidth = 17;               //vertical scroll bar width
var nHorzScrollBarHeight = 18;              //horizontal scroll bar height

    //ListView Table variables for Readjust
var bListViewHorzScrollBar = false;
var nListViewTBodyViewRows = 0;
var nListViewComputedDivHeight = 0;
var nListViewComputedTableHeight = 0;

var strContentDivision = null;
var strDisplayHTMLMessage = '';

    //Display Dual List variables
var bDisplayDualListEnabled = false;
var nDisplayDualListCheckboxCell = 0;
var strDisplayDualListTopListClassName = '';
var strDisplayDualListBottomListClassName = '';

function initializeWindowSize(bDisplayPopupWindow, strContentDivName)
{
    var strDisplayMessage = '';

    strContentDivision = strContentDivName;

    window.onresize = resizeWindow;

    strDisplayMessage += getBrowserWindowSize();

    if (nWindowSizeType != -1) {
        var oDivHeader = null;
        var oDivFooter = null;
        var oDivSubHeaderContentWrap = null;
        var oDivContentWrap = null;
        var oComputedStyleDivContentWrap = null;
        var oDivContentContainer = null;
        var oComputedStyleDivContentContainer = null;

        if ((oDivHeader = getDivisionRef('header')) == null) {
            nHeaderHeight = 0;
            nHeaderWidth = 0;
        } else {
            nHeaderHeight = oDivHeader.offsetHeight;
            nHeaderWidth = oDivHeader.offsetWidth;
        }

        if ((oDivSubHeaderContentWrap = getDivisionRef('sub-header-content-wrap')) == null)
            nSubHeaderHeight = 0;
        else
            nSubHeaderHeight = oDivSubHeaderContentWrap.offsetHeight;

        if ((oDivContentWrap = getDivisionRef('content-wrap')) == null)
            nContentWrapTop = 0;
        else {
            oComputedStyleDivContentWrap = getComputedStyleObject(oDivContentWrap);

            nContentWrapTop = oDivContentWrap.offsetTop + parseIntFromStyle(oComputedStyleDivContentWrap.borderTopWidth) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingTop) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingBottom) + parseIntFromStyle(oComputedStyleDivContentWrap.borderBottomWidth);
        }

        if ((oDivContentContainer = getDivisionRef('content-container')) == null)
            nContentContainerTop = 0;
        else {
            oComputedStyleDivContentContainer = getComputedStyleObject(oDivContentContainer);

            nContentContainerTop = oDivContentWrap.offsetTop + parseIntFromStyle(oComputedStyleDivContentWrap.borderTopWidth) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingTop) + parseIntFromStyle(oComputedStyleDivContentContainer.borderTopWidth) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingTop) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingBottom) + parseIntFromStyle(oComputedStyleDivContentContainer.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingBottom) + parseIntFromStyle(oComputedStyleDivContentWrap.borderBottomWidth);
        }

        if ((oDivFooter = getDivisionRef('footer')) == null) {
            nFooterHeight = 0;
            nFooterWidth = 0;
        } else {
            nFooterHeight = oDivFooter.offsetHeight;
            nFooterWidth = oDivFooter.offsetWidth;
        }

        var nContentDivisionWidth = 0;

        if (oDivContentContainer != null && oComputedStyleDivContentWrap != null && oDivFooter != null) {
            var nDivHeaderOffsetHeight = oDivHeader.offsetHeight; //[test]
            var nDivHeaderOffsetWidth = oDivHeader.offsetWidth; //[test]
            var nDivSubHeaderContentWrapOffsetHeight = oDivSubHeaderContentWrap.offsetHeight; //[test]
            var nDivSubHeaderContentWrapOffsetWidth = oDivSubHeaderContentWrap.offsetWidth; //[test]
            var nDivContentWrapOffsetHeight = oDivContentWrap.offsetHeight; //[test]
            var nDivContentWrapOffsetWidth = oDivContentWrap.offsetWidth; //[test]
            var nDivContentContainerOffsetHeight = oDivContentContainer.offsetHeight; //[test]
            var nDivContentContainerOffsetWidth = oDivContentContainer.offsetWidth; //[test]
            var nDivFooterOffsetHeight = oDivFooter.offsetHeight;
            var nDivFooterOffsetWidth = oDivFooter.offsetWidth;

            var nComputedContentContainerWidth = oDivFooter.offsetWidth - ((oDivContentWrap.offsetLeft - oDivHeader.offsetLeft) + parseIntFromStyle(oComputedStyleDivContentWrap.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingRight) + parseIntFromStyle(oComputedStyleDivContentWrap.borderRightWidth));
            var nAdjustedContentContainerWidth = nComputedContentContainerWidth - (parseIntFromStyle(oComputedStyleDivContentContainer.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingRight) + parseIntFromStyle(oComputedStyleDivContentContainer.borderRightWidth));

            setStyleWidth(oDivContentContainer, nAdjustedContentContainerWidth);

            if (nDivFooterOffsetWidth != oDivFooter.offsetWidth) {
                strDisplayMessage += '\n' + getDOMObjectName(oDivFooter) + ' width changed after adjusting ContentContainer : offsetWidth = ' + nDivFooterOffsetWidth + ' (orig) / ' + oDivFooter.offsetWidth + ' offsetHeight = ' + oDivFooter.offsetHeight + '\n        offsetTop = ' + oDivFooter.offsetTop + ' offsetLeft = ' + oDivFooter.offsetLeft; //[test]

                    //width changed, recalculate
                nDivFooterOffsetWidth = oDivFooter.offsetWidth;

                nComputedContentContainerWidth = oDivFooter.offsetWidth - ((oDivContentWrap.offsetLeft - oDivHeader.offsetLeft) + parseIntFromStyle(oComputedStyleDivContentWrap.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentWrap.paddingRight) + parseIntFromStyle(oComputedStyleDivContentWrap.borderRightWidth));
                nAdjustedContentContainerWidth = nComputedContentContainerWidth - (parseIntFromStyle(oComputedStyleDivContentContainer.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingRight) + parseIntFromStyle(oComputedStyleDivContentContainer.borderRightWidth));

                setStyleWidth(oDivContentContainer, nAdjustedContentContainerWidth);
            }

            if ((oDivContentDivision = getDivisionRef(strContentDivision)) != null) {
                if ((oComputedStyleDivContentDivision = getComputedStyleObject(oDivContentDivision)) != null) {
                    var nDivContentDivisionOffsetWidth = oDivContentDivision.offsetWidth; //[test]
                    var nDivContentDivisionOffsetHeight = oDivContentDivision.offsetHeight; //[test]

                    var nComputedContentDivisionWidth = oDivContentContainer.offsetWidth - (parseIntFromStyle(oComputedStyleDivContentContainer.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingRight) + parseIntFromStyle(oComputedStyleDivContentContainer.borderRightWidth));
                    var nAdjustedContentDivisionWidth = nComputedContentDivisionWidth - (parseIntFromStyle(oComputedStyleDivContentDivision.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentDivision.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentDivision.paddingRight) + parseIntFromStyle(oComputedStyleDivContentDivision.borderRightWidth));

                    setStyleWidth(oDivContentDivision, nAdjustedContentDivisionWidth);

                    strDisplayMessage += '\nComputedContentDivisionWidth = ' + nComputedContentDivisionWidth + ' AdjustedContentDivisionWidth = ' + nAdjustedContentDivisionWidth; //[test]

                    nContentDivisionWidth = nAdjustedContentDivisionWidth;

                    if (nDivFooterOffsetWidth != oDivFooter.offsetWidth)
                        strDisplayMessage += '\n' + getDOMObjectName(oDivFooter) + ' width changed after adjusting ContentDivision : offsetWidth = ' + nDivFooterOffsetWidth + ' (orig) / ' + oDivFooter.offsetWidth + ' offsetHeight = ' + oDivFooter.offsetHeight + '\n        offsetTop = ' + oDivFooter.offsetTop + ' offsetLeft = ' + oDivFooter.offsetLeft; //[test]

                    if (bDisplayDebugInfo) {
                            //[test]
                        var oComputedStyleDivHeader = getComputedStyleObject(oDivHeader);
                        var oComputedStyleDivSubHeaderContentWrap = getComputedStyleObject(oDivSubHeaderContentWrap);
                        var oComputedStyleDivFooter = getComputedStyleObject(oDivFooter);

                        strDisplayMessage += displayDebugDivInfo('Header', oDivHeader, oComputedStyleDivHeader, nDivHeaderOffsetWidth, nDivHeaderOffsetHeight);
                        strDisplayMessage += displayDebugDivInfo('Sub-Header Content Wrap', oDivSubHeaderContentWrap, oComputedStyleDivSubHeaderContentWrap, nDivSubHeaderContentWrapOffsetWidth, nDivSubHeaderContentWrapOffsetHeight);
                        strDisplayMessage += displayDebugDivInfo('Content Wrap', oDivContentWrap, oComputedStyleDivContentWrap, nDivContentWrapOffsetWidth, nDivContentWrapOffsetHeight);
                        strDisplayMessage += displayDebugDivInfo('Content Container', oDivContentContainer, oComputedStyleDivContentContainer, nDivContentContainerOffsetWidth, nDivContentContainerOffsetHeight);
                        strDisplayMessage += displayDebugDivInfo('Content Division', oDivContentDivision, oComputedStyleDivContentDivision, nDivContentDivisionOffsetWidth, nDivContentDivisionOffsetHeight);
                        strDisplayMessage += displayDebugDivInfo('Footer', oDivFooter, oComputedStyleDivFooter, nDivFooterOffsetWidth, nDivFooterOffsetHeight);
                        strDisplayMessage += '\n    x=' + window.pageXOffset + ' y=' + window.pageYOffset + ' scrollbars=' + window.scrollbars.visible;
                            //[test]
                    }
                }
            }
        }

        if (!bDisplayPopupWindow) {
                //we want to use cookies in because there is an advantage to having the window size before onbody is fired
            var nCookieWindowSizeType = getClassCookie('Window', 'SizeType');
            var nCookieWidth = getClassCookie('Window', 'Width');
            var nCookieHeight = getClassCookie('Window', 'Height');

            if (nCookieWidth == 0) {
                setClassCookie('Window', 'SizeType', nWindowSizeType, 0);
                setClassCookie('Window', 'Width', nWindowWidth, 0);
                setClassCookie('Window', 'Height', nWindowHeight, 0);
            } else {
                if (nCookieWindowSizeType != nWindowSizeType)
                    setClassCookie('Window', 'SizeType', nWindowSizeType, 0);

                if (nCookieWidth != nWindowWidth)
                    setClassCookie('Window', 'Width', nWindowWidth, 0);

                if (nCookieHeight != nWindowHeight) {
                    setClassCookie('Window', 'Height', nWindowHeight, 0);

                    eraseClassCookies('listview_div_width');
                    eraseClassCookies('listview_div_height');
                    eraseClassCookies('listview_table_height');
                    eraseClassCookies('listview_thead_height');
                }
            }

            var nCookieHeaderWidth = getClassCookie('Window', 'HeaderWidth');
            var nCookieContentWrapTop = getClassCookie('Window', 'ContentWrapTop');
            var nCookieContentContainerTop = getClassCookie('Window', 'ContentContainerTop');
            var nCookieContentDivisionWidth = getClassCookie('Window', 'ContentDivisionWidth');
            var nCookieFooterHeight = getClassCookie('Window', 'FooterHeight');

            if (nCookieHeaderWidth == 0) {
                setClassCookie('Window', 'HeaderWidth', nHeaderWidth, 0);
                setClassCookie('Window', 'ContentWrapTop', nContentWrapTop, 0);
                setClassCookie('Window', 'ContentContainerTop', nContentContainerTop, 0);
                setClassCookie('Window', 'ContentDivisionWidth', nContentDivisionWidth, 0);
                setClassCookie('Window', 'FooterHeight', nFooterHeight, 0);

                strDisplayMessage += '\nResetting all Cookies: HeaderWidth = ' + nHeaderWidth + ' ContentWrapTop = ' + nContentWrapTop + ' ContentContainerTop = ' + nContentContainerTop + ' ContentDivisionWidth = ' + nContentDivisionWidth + ' FooterHeight = ', nFooterHeight;
            } else {
                strDisplayMessage += '\nSetting changed Cookies:';

                if (nCookieHeaderWidth != nHeaderWidth) {
                    setClassCookie('Window', 'HeaderWidth', nHeaderWidth, 0);

                    strDisplayMessage += ' HeaderWidth = ' + nHeaderWidth;
                }

                if (nCookieContentWrapTop != nContentWrapTop) {
                    setClassCookie('Window', 'ContentWrapTop', nContentWrapTop, 0);

                    strDisplayMessage += ' ContentWrapTop = ' + nContentWrapTop;
                }

                if (nCookieContentContainerTop != nContentContainerTop) {
                    setClassCookie('Window', 'ContentContainerTop', nContentContainerTop, 0);

                    strDisplayMessage += ' ContentContainerTop = ' + nContentContainerTop;
                }

                if (nCookieContentDivisionWidth != nContentDivisionWidth) {
                    setClassCookie('Window', 'ContentDivisionWidth', nContentDivisionWidth, 0);

                    strDisplayMessage += ' ContentDivisionWidth = ' + nContentDivisionWidth;
                }

                if (nCookieFooterHeight != nFooterHeight) {
                    setClassCookie('Window', 'FooterHeight', nFooterHeight, 0);

                    strDisplayMessage += ' FooterHeight = ', nFooterHeight;
                }
            }
        }
    }

    if (document.body == null) {
        if (bDisplayDebugInfo)
            strDisplayMessage += '\nERROR: document.body not defined';
        else
            window.alert('ERROR: document.body not defined');
    } else {
        if (bDisplayDebugInfo && bDebugDisplayTagDivision) {
            strDisplayMessage += '\ngetElementsByTagName division: ';

            var nodeDivisionArray = document.getElementsByTagName('div');

            if (nodeDivisionArray == null)
                strDisplayMessage += ' ERROR: no divisions found!';
            else {
                strDisplayMessage += ' division nodes = ' + nodeDivisionArray.length;

                for (var nDivCtr = 0; nDivCtr < nodeDivisionArray.length; nDivCtr++)
                    strDisplayMessage += '\n    ' + getDOMObjectName(nodeDivisionArray[nDivCtr]) + ': offsetWidth = ' + nodeDivisionArray[nDivCtr].offsetWidth + ' offsetHeight = ' + nodeDivisionArray[nDivCtr].offsetHeight + ' offsetTop = ' + nodeDivisionArray[nDivCtr].offsetTop + ' offsetLeft = ' + nodeDivisionArray[nDivCtr].offsetLeft;
            }

            strDisplayMessage += '\n\ngetElementsByTagName table: ';

            var nodeDivisionArray = document.getElementsByTagName('table');

            if (nodeDivisionArray == null)
                strDisplayMessage += ' ERROR: no tables found!';
            else {
                strDisplayMessage += ' table nodes = ' + nodeDivisionArray.length;

                for (var nDivCtr = 0; nDivCtr < nodeDivisionArray.length; nDivCtr++)
                    strDisplayMessage += '\n    ' + getDOMObjectName(nodeDivisionArray[nDivCtr]) + ': offsetWidth = ' + nodeDivisionArray[nDivCtr].offsetWidth + ' offsetHeight = ' + nodeDivisionArray[nDivCtr].offsetHeight + ' offsetTop = ' + nodeDivisionArray[nDivCtr].offsetTop + ' offsetLeft = ' + nodeDivisionArray[nDivCtr].offsetLeft;
            }
        }

        if (strDisplayMessage != '' || bDebugDisplayTagDivision) {
            strDisplayMessage += '\nDOM Document available:';

            if (document.getElementById)
                strDisplayMessage += ' getElementById';

            if (document.all)
                strDisplayMessage += ' document.all';

            if (document.layers)
                strDisplayMessage += ' document.layers';
        }
    }

    if (bDisplayDebugInfo && strDisplayMessage != '')
        displayDebugMessage(true, 'initializeWindowSize\r\n' + strDisplayMessage);
}

function getBrowserWindowSize()
{
    if (typeof(window.innerWidth) == 'number') {
        nWindowSizeType = 0;                                  //0 indicates window.innerWidth/Height
        strWindowSizeType = 'Non-IE';
        nWindowWidth = window.innerWidth;
        nWindowHeight = window.innerHeight;
    } else if (document.documentElement != null && (document.documentElement.clientWidth != 0 || document.documentElement.clientHeight != 0)) {
        if (nWindowSizeType == -1) {
            nWindowSizeType = 1;                              //1 indicates document.documentElement.clientWidth/Height
            strWindowSizeType = 'IE 6+';
            nWindowWidth = document.documentElement.clientWidth;
            nWindowHeight = document.documentElement.clientHeight;
        }
    }

    if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        if (nWindowSizeType == -1) {
            nWindowSizeType = 2;                              //2 indicates document.body.clientWidth/Height
            strWindowSizeType = 'IE 4';
            nWindowWidth = document.body.clientWidth;
            nWindowHeight = document.body.clientHeight;
        }
    }

    return ('\nWindowSizeType = ' + nWindowSizeType + ' => ' + strWindowSizeType + ', Width=' + nWindowWidth + ', Height=' + nWindowHeight);
}

function resizeWindow()
{
    //[test] window.alert("Window has been resized"); //[test]
}

function adjustListviewTableHeight(strListviewTableName, nMaxRows)
{
    adjustListviewTableHeightWithGap(strListviewTableName, nMaxRows, 0);
}

function adjustListviewTableHeightWithGap(strListviewTableName, nMaxRows, nLeaveGapHeight)
{
    var strDisplayMessage = '';

    if (document.body == null)
        window.alert('ERROR: document.body not defined');
    else {
        if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight) {
            strDisplayMessage += '\nWindowSizeType = ' + nWindowSizeType + '=>' + strWindowSizeType + '\n        Width=' + nWindowWidth + ' Height=' + nWindowHeight;

            if (window.pageXOffset != null)
                strDisplayMessage += '\n        x=' + window.pageXOffset + ' y=' + window.pageYOffset + ' scrollbars=' + window.scrollbars.visible;
        }

        var oDivContentContainer = getDivisionRef('content-container');

        if (oDivContentContainer == null)
            strDisplayMessage += '\n    DIV content not found';
        else {
            var oComputedStyleDivContentContainer = getComputedStyleObject(oDivContentContainer);

            if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
                strDisplayMessage += displayDebugDivInfo('Content Container', oDivContentContainer, oComputedStyleDivContentContainer, null, null);
        }

        var oDivContentDivision = getDivisionRef(strContentDivision);

        if (oDivContentDivision == null)
            strDisplayMessage += '\n    DIV content ' + strContentDivision + ' not found';
        else {
            var oComputedStyleDivContentDivision = getComputedStyleObject(oDivContentDivision);

            if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
                strDisplayMessage += displayDebugDivInfo('Content Division', oDivContentDivision, oComputedStyleDivContentDivision, null, null);
        }

        var oDivListView = getElementByTagIdClass('div', 'listview', strListviewTableName);

        if (oDivListView == null)
            strDisplayMessage += '\n    DIV listview not found';
        else {
            var oComputedStyleDivListView = getComputedStyleObject(oDivListView);

            if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
                strDisplayMessage += displayDebugDivInfo('Listview', oDivListView, oComputedStyleDivListView, null, null);
        }

        var oTableListView = getElementByTagIdClass('table', 'listview', strListviewTableName);

        if (oTableListView == null)
            strDisplayMessage += '\n    TABLE listview not found';
        else {
            var oComputedStyleTableListView = getComputedStyleObject(oTableListView);

            if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
                strDisplayMessage += displayDebugTableInfo('Listview', oTableListView, oComputedStyleTableListView, null, null);
        }

        if (oDivContentContainer != null && oDivContentDivision != null && oDivListView != null && oTableListView != null) {
                //current values from DOM
            var nListViewDivWidth = (oDivListView.style == null ? oDivListView.width : oDivListView.offsetWidth);
            var nListViewDivHeight = (oDivListView.style == null ? oDivListView.height : oDivListView.offsetHeight);
            var nListViewTableWidth = (oTableListView.style == null ? oTableListView.width : oTableListView.offsetWidth);
            var nListViewTableHeight = (oTableListView.style == null ? oTableListView.height : oTableListView.offsetHeight);
            var nListViewTHeadHeight = oTableListView.tHead.offsetHeight;

                //number of rows, tbody height and number of viewable rows
            var nListViewTableRows = oTableListView.tBodies[0].rows.length;
            nListViewTBodyViewRows = 0;                 //global so it can be used to readjust table height

                //computed (calculated) division width, division height and table height
            var nComputedDivWidth = oDivContentDivision.offsetWidth - ((parseIntFromStyle(oComputedStyleDivContentDivision.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentDivision.paddingLeft) + parseIntFromStyle(oComputedStyleDivListView.marginLeft) + parseIntFromStyle(oComputedStyleDivListView.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivListView.paddingLeft) + parseIntFromStyle(oComputedStyleDivListView.paddingRight) + parseIntFromStyle(oComputedStyleDivListView.borderRightWidth) + parseIntFromStyle(oComputedStyleDivContentDivision.paddingRight) + parseIntFromStyle(oComputedStyleDivContentDivision.marginRight) + parseIntFromStyle(oComputedStyleDivContentDivision.paddingRight) + parseIntFromStyle(oComputedStyleDivContentDivision.borderRightWidth)) + (nWindowSizeType == 1 ? 19 : 0)); //the division footer width doesn't include the border left and right offsetting

            if (nListViewTableWidth < nComputedDivWidth)
                nComputedDivWidth = nListViewTableWidth;                                //set computed to be table width if table width is less than computed

            var nComputedDivHeight = 0;
            var nComputedTableHeight = 0;

            bListViewHorzScrollBar = nListViewDivWidth <= nListViewTableWidth ? true : false;   //set global value

            if (nMaxRows != 0) {
                nListViewTBodyViewRows = nListViewTableRows < nMaxRows ? nListViewTableRows : nMaxRows;     //viewable rows is the smaller of nMaxRows or total rows
                nComputedTableHeight = nListViewTHeadHeight + (nListViewTBodyViewRows * nListViewRowHeight);
                nListViewComputedTableHeight = nComputedTableHeight;        //save the computed table height as max height for readjust table height
            } else {
                nComputedTableHeight = nWindowHeight - (nHeaderHeight + nSubHeaderHeight + oDivListView.offsetTop + nFooterHeight
                                     + parseIntFromStyle(oComputedStyleDivContentContainer.marginTop) + parseIntFromStyle(oComputedStyleDivContentContainer.borderTopWidth) + parseIntFromStyle(oComputedStyleDivContentContainer.paddingTop)
                                     + parseIntFromStyle(oComputedStyleDivContentDivision.marginTop) + parseIntFromStyle(oComputedStyleDivContentDivision.borderTopWidth) + parseIntFromStyle(oComputedStyleDivContentDivision.paddingTop)
                                     + /* don't need marginTop because we use offsetTop parseIntFromStyle(oComputedStyleDivListView.marginTop) + */ parseIntFromStyle(oComputedStyleDivListView.borderTopWidth) + parseIntFromStyle(oComputedStyleDivListView.paddingTop)
                                     + parseIntFromStyle(oComputedStyleDivListView.paddingBottom) + parseIntFromStyle(oComputedStyleDivListView.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivListView.marginBottom)
                                     + parseIntFromStyle(oComputedStyleDivContentDivision.paddingBottom) + parseIntFromStyle(oComputedStyleDivContentDivision.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivContentDivision.marginBottom)
                                     + parseIntFromStyle(oComputedStyleDivContentContainer.paddingBottom) + parseIntFromStyle(oComputedStyleDivContentContainer.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivContentContainer.marginBottom)
                                     + nHorzScrollBarHeight + nLeaveGapHeight); //need to remove any listview division bottom margin or padding

                nListViewComputedTableHeight = nComputedTableHeight;        //save the computed table height as max height for readjust table height
                nListViewTBodyViewRows = (nComputedTableHeight - nListViewTHeadHeight - nHorzScrollBarHeight) / nListViewRowHeight;     //calculate number of viewable rows by taking the computed table height - thead height - horizontal scroll bar height and dividing it by row height

                if (nListViewTableRows <= nListViewTBodyViewRows)
                    nComputedTableHeight = nListViewTHeadHeight + (nListViewTableRows * nListViewRowHeight);    //the number of rows is less than the area we have for it
            }


            nComputedDivHeight = nComputedTableHeight + (!bListViewHorzScrollBar ? 0 : nHorzScrollBarHeight);
            nListViewComputedDivHeight = nComputedDivHeight;            //save the computed division height as max height for readjust table height

            /*
             *  Still need to adjust div height and table height and update them both...
             */
            if (bDisplayDebugInfo) {
                strDisplayMessage += '\nWidths:  DIV listview=' + nListViewDivWidth + ', Table listview=' + nListViewTableWidth + ', computed=' + nComputedDivWidth;
                strDisplayMessage += '\nRows:    Row height=' + nListViewRowHeight + ', Total=' + nListViewTableRows + ', Viewable=' + nListViewTBodyViewRows;
                strDisplayMessage += '\nHeights: Div listview=' + nListViewDivHeight + ', computed=' + nComputedDivHeight + ', Horz Scroll Bar=' + (bListViewHorzScrollBar ? 'true' : 'false');
                strDisplayMessage += '\n         Table listview=' + nListViewTableHeight + ', computed=' + nComputedTableHeight + ', THead=' + nListViewTHeadHeight;
            }

            if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
                strDisplayMessage += '\nDIV listview style ' + (oDivListView.style == null ? '=' : '!') + '= null';

            if (nListViewDivWidth != nComputedDivWidth) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewDivWidth from ' + nListViewDivWidth + ' to ' + nComputedDivWidth;

                nListViewDivWidth = nComputedDivWidth;

                setStyleWidth(oDivListView, nListViewDivWidth);
            }

            if (nListViewDivHeight != nComputedDivHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewDivHeight from ' + nListViewDivHeight + ' to ' + nComputedDivHeight;

                nListViewDivHeight = nComputedDivHeight;

                setStyleHeight(oDivListView, nListViewDivHeight);
            }

            if (nListViewTableHeight != nComputedTableHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewTableHeight from ' + nListViewTableHeight + ' to ' + nComputedTableHeight;

                nListViewTableHeight = nComputedTableHeight;

                setStyleHeight(oTableListView, nListViewTableHeight);
                setStyleHeight(oTableListView.tBodies[0], nComputedTableHeight - nListViewTHeadHeight);
            }

            if (bDisplayDebugInfo)
                strDisplayMessage += '\nUpdated Values:\n        Div listview width=' + nListViewDivWidth + ', Div listview height=' + nListViewDivHeight + ', Table height=' + nListViewTableHeight + '\n        Header height=' + nListViewTHeadHeight + ' body height=' + (nListViewTableHeight - nListViewTHeadHeight);

            setClassCookie('listview_div_width', oTableListView.className, nListViewDivWidth, 0);
            setClassCookie('listview_div_height', oTableListView.className, nListViewDivHeight, 0);
            setClassCookie('listview_table_height', oTableListView.className, nListViewTableHeight, 0);
            setClassCookie('listview_thead_height', oTableListView.className, nListViewTHeadHeight, 0);
        }

        if (bDisplayDebugInfo && strDisplayMessage != '')
            displayDebugMessage(true, 'adjustListviewTableHeight LVTblName= ' + (strListviewTableName == null ? '<null>' : strListviewTableName) + '\n        MaxRows=' + nMaxRows + ', LeaveGapHeight=' + nLeaveGapHeight + ', display=' + (bDebugDisplayAdjustListviewHeight ? 'true' : 'false - Error present') + '\n' + strDisplayMessage);
    }
}

function readjustListviewTableHeight(strListviewTableName, nListViewTableDisplayRows, nDisplayedRows)
{
    var strDisplayMessage = '';

    if (document.body == null)
        window.alert('ERROR: document.body not defined');
    else {
        var oDivListView = getElementByTagIdClass('div', 'listview', strListviewTableName);

        if (oDivListView == null)
            strDisplayMessage += '\n    DIV listview not found';

        var oTableListView = getElementByTagIdClass('table', 'listview', strListviewTableName);

        if (oTableListView == null)
            strDisplayMessage += '\n    TABLE listview not found';
        else if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
            strDisplayMessage += '\n' + getDOMObjectName(oTableListView) + ':\n        listview rows = ' + oTableListView.tBodies[0].rows.length + ', offsetWidth = ' + oTableListView.offsetWidth + ', offsetHeight = ' + oTableListView.offsetHeight + '\n        offsetTop = ' + oTableListView.offsetTop + ', offsetLeft = ' + oTableListView.offsetLeft;

        if (oDivListView != null && oTableListView != null) {
                //current values from DOM
            var nListViewDivHeight = (oDivListView.style == null ? oDivListView.height : oDivListView.offsetHeight);
            var nListViewTableHeight = (oTableListView.style == null ? oTableListView.height : oTableListView.offsetHeight);
            var nListViewTHeadHeight = oTableListView.tHead.offsetHeight;

                //number of rows, tbody height and number of viewable rows
            var nListViewTableRows = oTableListView.tBodies[0].rows.length;

            var nComputedDivHeight = 0;
            var nComputedTableHeight = 0;

            if (nListViewTableDisplayRows != 0) {
                if (nDisplayedRows < nListViewTableDisplayRows)
                    nComputedTableHeight = nListViewTHeadHeight + (nDisplayedRows * nListViewRowHeight);
                else
                    nComputedTableHeight = nListViewTHeadHeight + (nListViewTableDisplayRows * nListViewRowHeight);

                nComputedDivHeight = nListViewTHeadHeight + (nListViewTableDisplayRows * nListViewRowHeight) + (!bListViewHorzScrollBar ? 0 : nHorzScrollBarHeight);
            } else {
                if (nDisplayedRows < nListViewTBodyViewRows)
                    nComputedTableHeight = nListViewTHeadHeight + (nDisplayedRows * nListViewRowHeight);
                else
                    nComputedTableHeight = nListViewComputedTableHeight;       //this is set from adjustListviewTableHeightWithGap

                nComputedDivHeight = nListViewComputedDivHeight;
            }

            /*
             *  Still need to adjust div height and table height and update them both...
             */
            if (bDisplayDebugInfo) {
                strDisplayMessage += '\nRows:    Row height=' + nListViewRowHeight + ', Total=' + nListViewTableRows + ', Displayed=' + nDisplayedRows + ', Viewable=' + (nListViewTableDisplayRows != 0 ? nListViewTableDisplayRows : nListViewTBodyViewRows);
                strDisplayMessage += '\nHeights: Div listview=' + nListViewDivHeight + ', computed=' + nComputedDivHeight + ', Horz Scroll Bar=' + (bListViewHorzScrollBar ? 'true' : 'false');
                strDisplayMessage += '\n         Table listview=' + nListViewTableHeight + ', computed=' + nComputedTableHeight + ', THead=' + nListViewTHeadHeight;
            }

            if (bDisplayDebugInfo && bDebugDisplayAdjustListviewHeight)
                strDisplayMessage += '\nDIV listview style ' + (oDivListView.style == null ? '=' : '!') + '= null';

            if (nListViewDivHeight != nComputedDivHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewDivHeight from ' + nListViewDivHeight + ' to ' + nComputedDivHeight;

                nListViewDivHeight = nComputedDivHeight;

                setStyleHeight(oDivListView, nListViewDivHeight);
            }

            if (nListViewTableHeight != nComputedTableHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewTableHeight from ' + nListViewTableHeight + ' to ' + nComputedTableHeight;

                nListViewTableHeight = nComputedTableHeight;

                setStyleHeight(oTableListView, nListViewTableHeight);
                setStyleHeight(oTableListView.tBodies[0], nComputedTableHeight - nListViewTHeadHeight);
            }

            if (bDisplayDebugInfo)
                strDisplayMessage += '\nUpdated Values:\n        Div listview height=' + nListViewDivHeight + ', Table height=' + nListViewTableHeight + '\n        Header height=' + nListViewTHeadHeight + ' body height=' + (nListViewTableHeight - nListViewTHeadHeight);
        }

        if (bDisplayDebugInfo && strDisplayMessage != '')
            displayDebugMessage(true, 'readjustListviewTableHeight LVTblName= ' + (strListviewTableName == null ? '<null>' : strListviewTableName) + '\n' + strDisplayMessage);
    }
}

function adjustPopupListviewTableHeight(strListviewTableName, nFixedRows, nDisplayedRows)
{
    var strDisplayMessage = '';

    if (document.body == null)
        window.alert('ERROR: document.body not defined');
    else {
        if (nWindowSizeType == -1)
            strDisplayMessage += getBrowserWindowSize();        //need window size information in case initializeWindowSize was not called

        if ((oDivContentPopup = getDivisionRef('content-popup')) == null)
            strDisplayMessage += '\n    DIV content-popup not found';
        else {
            var oComputedStyleDivContentPopup = getComputedStyleObject(oDivContentPopup);

            if (bDisplayDebugInfo && bDebugDisplayAdjustPopupListviewHeight)
                strDisplayMessage += displayDebugDivInfo('Content-Popup', oDivContentPopup, oComputedStyleDivContentPopup, null, null);
        }

        var oDivListView = getElementByTagIdClass('div', 'listview', strListviewTableName);

        if (oDivListView == null)
            strDisplayMessage += '\n    DIV listview not found';
        else {
            var oComputedStyleDivListView = getComputedStyleObject(oDivListView);

            if (bDisplayDebugInfo && bDebugDisplayAdjustPopupListviewHeight)
                strDisplayMessage += displayDebugDivInfo('List View', oDivListView, oComputedStyleDivListView, null, null);
        }

        oTableListView = null;

        var oTableListView = getElementByTagIdClass('table', 'listview', strListviewTableName);

        if (oTableListView == null)
            strDisplayMessage += '\n    TABLE listview not found';
        else
            strDisplayMessage += '\n' + getDOMObjectName(oTableListView) + ':\n        listview rows = ' + oTableListView.tBodies[0].rows.length + ', offsetWidth = ' + oTableListView.offsetWidth + ', offsetHeight = ' + oTableListView.offsetHeight + '\n        offsetTop = ' + oTableListView.offsetTop + ', offsetLeft = ' + oTableListView.offsetLeft;

        if (oDivContentPopup != null && oDivListView != null && oTableListView != null) {
            var nContentPopupWidth = (oDivContentPopup.style == null ? oDivContentPopup.width : oDivContentPopup.offsetWidth);
            var nContentPopupHeight = (oDivContentPopup.style == null ? oDivContentPopup.height : oDivContentPopup.offsetHeight);
            var nListViewDivWidth = (oDivListView.style == null ? oDivListView.width : parseIntFromStyle(oComputedStyleDivListView.width));
            var nListViewDivHeight = (oDivListView.style == null ? oDivListView.height : parseIntFromStyle(oComputedStyleDivListView.height));
            var nListViewTableWidth = (oTableListView.style == null ? oTableListView.width : oTableListView.offsetWidth);
            var nListViewTableHeight = (oTableListView.style == null ? oTableListView.height : oTableListView.offsetHeight);
            var nListViewTHeadHeight = oTableListView.tHead.offsetHeight;

            //NOTE: this needs to be checked over as style width=nnnpx is inside size and offsetWidth includes borders and padding.  To make them the same you have to subtract

            var nComputedContentPopupHeight = nWindowHeight - (oDivContentPopup.offsetTop + nFooterHeight
                                            + /* don't need marginTop because we use offsetTop parseIntFromStyle(oComputedStyleDivContentPopup.marginTop) + */ parseIntFromStyle(oComputedStyleDivContentPopup.borderTopWidth) + parseIntFromStyle(oComputedStyleDivContentPopup.paddingTop)
                                            + parseIntFromStyle(oComputedStyleDivContentPopup.paddingBottom) + parseIntFromStyle(oComputedStyleDivContentPopup.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivContentPopup.marginBottom));

            if (nContentPopupHeight != nComputedContentPopupHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted content-popup div height from ' + nContentPopupHeight + ' to ' + nComputedContentPopupHeight;

                nContentPopupHeight = nComputedContentPopupHeight;

                setStyleHeight(oDivContentPopup, nContentPopupHeight);
            }

                //number of rows, tbody height and number of viewable rows
            var nListViewTableRows = oTableListView.tBodies[0].rows.length;
            nListViewTBodyViewRows = 0;

                //computed (calculated) division width, division height and table height
            var nComputedDivWidth = nListViewDivWidth;
            var nListViewDivBordersWidth = parseIntFromStyle(oComputedStyleDivListView.paddingLeft) + parseIntFromStyle(oComputedStyleDivListView.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivListView.borderRightWidth) + parseIntFromStyle(oComputedStyleDivListView.paddingRight);
            var nListViewDivBordersHeight = parseIntFromStyle(oComputedStyleDivListView.paddingTop) + parseIntFromStyle(oComputedStyleDivListView.borderTopWidth) + parseIntFromStyle(oComputedStyleDivListView.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivListView.paddingBottom);
            var nContentPopupBordersWidth = parseIntFromStyle(oComputedStyleDivContentPopup.paddingLeft) + parseIntFromStyle(oComputedStyleDivContentPopup.borderLeftWidth) + parseIntFromStyle(oComputedStyleDivContentPopup.borderRightWidth) + parseIntFromStyle(oComputedStyleDivContentPopup.paddingRight);

            if (nListViewTableWidth < nComputedDivWidth - nListViewDivBordersWidth) {
                nComputedDivWidth = nListViewTableWidth + nListViewDivBordersWidth;     //set computed to be table width if table width is less than computed
                strDisplayMessage += '\n    ComputedDivWidth1 = ' + nComputedDivWidth;
            } else if (nListViewTableWidth > nComputedDivWidth - nListViewDivBordersWidth && nComputedDivWidth < nContentPopupWidth - nContentPopupBordersWidth) {
                nComputedDivWidth = nContentPopupWidth - nContentPopupBordersWidth;     //set computed to be max content-popup div width

                if (nListViewTableWidth < nComputedDivWidth - nListViewDivBordersWidth)
                    nComputedDivWidth = nListViewTableWidth + nListViewDivBordersWidth;     //set computed to be table width if table width is less than computed

                strDisplayMessage += '\n    ComputedDivWidth2 = ' + nComputedDivWidth;
            }

            var nComputedDivHeight = 0;
            var nComputedTableHeight = 0;

            bListViewHorzScrollBar = nListViewDivWidth <= nListViewTableWidth ? true : false;

            var nComputedTableHeight = nWindowHeight - (oDivListView.offsetTop + nFooterHeight
                                     + /* don't need marginTop because we use offsetTop parseIntFromStyle(oComputedStyleDivListView.marginTop) + */ parseIntFromStyle(oComputedStyleDivListView.borderTopWidth) + parseIntFromStyle(oComputedStyleDivListView.paddingTop)
                                     + parseIntFromStyle(oComputedStyleDivListView.paddingBottom) + parseIntFromStyle(oComputedStyleDivListView.borderBottomWidth) + parseIntFromStyle(oComputedStyleDivListView.marginBottom)
                                     + (!bListViewHorzScrollBar ? 4 : nHorzScrollBarHeight));

            nListViewComputedTableHeight = nComputedTableHeight;        //save the computed table height as max height for readjust table height

            nListViewTBodyViewRows = (nComputedTableHeight - nListViewTHeadHeight - nHorzScrollBarHeight) / nListViewRowHeight;     //calculate number of viewable rows by taking the computed table height - thead height - horizontal scroll bar height and dividing it by row height

            if (nListViewTableRows <= nListViewTBodyViewRows) {
                nListViewTBodyViewRows = nListViewTableRows;                        //the number of rows is less than the area we have for it
                nComputedTableHeight = nListViewTHeadHeight + (nListViewTBodyViewRows * nListViewRowHeight);
            }

            if (nFixedRows == 0)
                nComputedDivHeight = nComputedTableHeight + (!bListViewHorzScrollBar ? 0 : nHorzScrollBarHeight);
            else {
                nComputedTableHeight = nListViewTHeadHeight + ((nDisplayedRows < nFixedRows ? nDisplayedRows : nFixedRows) * nListViewRowHeight);
                nComputedDivHeight = nListViewTHeadHeight + (nFixedRows * nListViewRowHeight) + (!bListViewHorzScrollBar ? 0 : nHorzScrollBarHeight);
            }

            nListViewComputedDivHeight = nComputedDivHeight;            //save the computed division height as max height for readjust table height

            if (nListViewDivWidth != nComputedDivWidth) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewDivWidth from ' + nListViewDivWidth + ' to ' + nComputedDivWidth;

                nListViewDivWidth = nComputedDivWidth;

                setStyleWidth(oDivListView, nListViewDivWidth);
            }

            if (nListViewDivHeight != nComputedDivHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewDivHeight from ' + nListViewDivHeight + ' to ' + nComputedDivHeight;

                nListViewDivHeight = nComputedDivHeight;

                setStyleHeight(oDivListView, nListViewDivHeight);
            }

            if (nListViewTableHeight != nComputedTableHeight) {
                if (bDisplayDebugInfo)
                    strDisplayMessage += '\nAdjusted ListViewTableHeight from ' + nListViewTableHeight + ' to ' + nComputedTableHeight;

                nListViewTableHeight = nComputedTableHeight;

                setStyleHeight(oTableListView.tBodies[0], nListViewTableHeight);
            }

            setClassCookie('listview_popup_content_height', oTableListView.className, nContentPopupHeight, 0);
            setClassCookie('listview_popup_div_height', oTableListView.className, nListViewDivHeight, 0);
            setClassCookie('listview_popup_div_width', oTableListView.className, nListViewDivWidth, 0);
            setClassCookie('listview_popup_table_height', oTableListView.className, nListViewTableHeight, 0);
            setClassCookie('listview_popup_thead_height', oTableListView.className, nListViewTHeadHeight, 0);
        }

        if (bDisplayDebugInfo && strDisplayMessage != '') {
            strDisplayMessage = 'adjustPopupListviewTableHeight(' + strListviewTableName + ', ' + nFixedRows + ')\n    debug display=' + (bDebugDisplayAdjustPopupListviewHeight ? 'true' : 'false') + '\n' + strDisplayMessage;

            displayDebugMessage(true, strDisplayMessage);
        }
    }
}

function adjustFormviewTableHeight()
{
    var strDisplayMessage = '';

    strDisplayMessage += 'adjustFormviewTableHeight\n';

    if ((oDivContentContainer = getDivisionRef('content-container')) == null)
        strDisplayMessage += '\nDIV content-container not found';
    else
        strDisplayMessage += '\n' + getDOMObjectName(oDivContentContainer) + ':\n        offsetWidth = ' + oDivContentContainer.offsetWidth + ' offsetHeight = ' + oDivContentContainer.offsetHeight + ' offsetTop = ' + oDivContentContainer.offsetTop + ' offsetLeft = ' + oDivContentContainer.offsetLeft;

    if ((oDivFooter = getDivisionRef('footer')) == null)
        strDisplayMessage += '\nDIV footer not found';
    else
        strDisplayMessage += '\n' + getDOMObjectName(oDivFooter) + ':\n        offsetWidth = ' + oDivFooter.offsetWidth + ' offsetHeight = ' + oDivFooter.offsetHeight + ' offsetTop = ' + oDivFooter.offsetTop + ' offsetLeft = ' + oDivFooter.offsetLeft;

    if ((oDivListView = getDivisionRef('formview')) == null)
        strDisplayMessage += '\nDIV formview not found';
    else
        strDisplayMessage += '\n' + getDOMObjectName(oDivListView) + ':\n        offsetWidth = ' + oDivListView.offsetWidth + ' offsetHeight = ' + oDivListView.offsetHeight + ' offsetTop = ' + oDivListView.offsetTop + ' offsetLeft = ' + oDivListView.offsetLeft;

    if (bDisplayDebugInfo)
        displayDebugMessage(true, strDisplayMessage);
}

    //functions to support different browsers and how elements and properties/methods of elements are handled

function getDivisionRef(strDivisionId)
{
    if (document.getElementById != null)
        return (document.getElementById(strDivisionId));
    else if (document.all != null)
        return (document.all[strDivisionId]);

    if (document.layers != null) {
        var oDocument = document;

        if (oDocument.layers[strDivisionId])
            return (oDocument.layers[strDivisionId]);
        else {
                //repeatedly run through all child layers
            for (var nLayerCtr = 0, oDivision = null; oDivision == null && nLayerCtr < oDocument.layers.length; nLayerCtr++)
                oDivision = getDivisionLayerRef(strDivisionId, oDocument.layers[nLayerCtr].document);   //on success, return that layer, else return nothing

            return (oDivision);
        }
    }

    return (null);
}

function getDivisionLayerRef(strDivisionId, oDocument)
{
    if (oDocument.layers[strDivisionId] != null)
        return (oDocument.layers[strDivisionId]);

    return (null);
}

function getElementByTagIdClass(strTagName, strId, strClassName)
{
    var oTagIdClassElement = null;
    var nodeTagArray = document.getElementsByTagName(strTagName);

    if (nodeTagArray != null) {
        for (var nTableCtr = 0; nTableCtr < nodeTagArray.length; nTableCtr++) {
            if (nodeTagArray[nTableCtr].id == strId && (strClassName == null || nodeTagArray[nTableCtr].className == strClassName)) {
                oTagIdClassElement = nodeTagArray[nTableCtr];
                break;
            }
        }
    }

    return (oTagIdClassElement);
}

function getDOMObjectName(oDOMObject)
{
    strName = oDOMObject.nodeName + '#' + oDOMObject.id;

    if (oDOMObject.className != '')
        strName = strName + '.' + oDOMObject.className;

    return (strName);
}

function getComputedStyleObject(oElement)
{
    var oComputedStyleObject = null;

    if (window.getComputedStyle != null)
        oComputedStyleObject = window.getComputedStyle(oElement, null);
    else if (oElement.currentStyle != null)
        oComputedStyleObject = oElement.currentStyle;

    return (oComputedStyleObject);
}

function parseIntFromStyle(strStyleValue)
{
        //wrote this to handle empty or null strings.  It could also do pixel conversions if desired.
    var iStyleValue = 0;

    if (strStyleValue != null && strStyleValue != "") {
        if (isNaN(iStyleValue = parseInt(strStyleValue)))
            iStyleValue = 0;
    }

    return (iStyleValue);
}

function setStyleWidth(oElement, nWidth)
{
    if (oElement.style == null)
        oElement.width = nWidth;
    else
        oElement.style.width = nWidth + 'px';
}

function setStyleHeight(oElement, nHeight)
{
    if (oElement.style == null)
        oElement.height = nHeight;
    else
        oElement.style.height = nHeight + 'px';
}

function openPopupWindow(strURL, strWindowName, strPosElementName, nHeight, nWidth, strAdditionalSpecs)
{
    var strSpecsList = '';

    strSpecsList = getOpenWindowPositionAndSize(strPosElementName, nHeight, nWidth);

    if (strAdditionalSpecs != '') {
        if (strSpecsList != '')
            strSpecsList += ', ';

        strSpecsList += strAdditionalSpecs;
    }

    return (window.open(strURL, strWindowName, strSpecsList));
}

function getOpenWindowPositionAndSize(strPosElementName, nHeight, nWidth)
{
    var strPosAndSize = 'height=' + nHeight + ', width=' + nWidth;

    var coordinatesWindowPos = getAnchorWindowPosition(strPosElementName);

    strPosAndSize += ', top=' + coordinatesWindowPos.y + ', left=' + coordinatesWindowPos.x;

    return (strPosAndSize);
}

function getElementWindowPositionAndSize(strPosElementName)
{
    var strPosAndSize = '';

    var coordinatesWindowSize = new Object();
    coordinatesWindowSize.nHeight = 0;
    coordinatesWindowSize.nWidth = 0;

    var coordinatesWindowSize = getElementWindowSizeCooridinates(strPosElementName);
    var coordinatesWindowPos = getAnchorWindowPosition(strPosElementName);

    strPosAndSize += 'height=' + coordinatesWindowSize.nHeight + ', width=' + coordinatesWindowSize.nWidth;
    strPosAndSize += ', top=' + coordinatesWindowPos.y + ', left=' + coordinatesWindowPos.x;

    return (strPosAndSize);
}

function getElementWindowSizeCooridinates(strPosElementName)
{
    var coordinates = new Object();

    var nHeight = 0;
    var nWidth = 0;

    if (document.getElementById != null) {
        if ((objElement = document.getElementById(strPosElementName)) != null) {
          nHeight = objElement.offsetHeight;
          nWidth = objElement.offsetWidth;
        }
    }

    coordinates.nHeight = nHeight;
    coordinates.nWidth = nWidth;

    return (coordinates);
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/*
AnchorPosition.js
Author: Matt Kruse
Last modified: 10/11/02

DESCRIPTION: These functions find the position of an <A> tag in a document,
so other elements can be positioned relative to it.

COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the
Macintosh platform.

FUNCTIONS:
getAnchorPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor. Position is relative to the PAGE.

getAnchorWindowPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.

NOTES:

1) For popping up separate browser windows, use getAnchorWindowPosition.
   Otherwise, use getAnchorPosition

2) Your anchor tag MUST contain both NAME and ID attributes which are the
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the
   anchor tag correctly. Do not do <A></A> with no space.
*/

// getAnchorWindowSize(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname)
{
    var coordinates = new Object();

    var x = 0;
    var y = 0;

    if (document.getElementById) {
        if (isNaN(window.screenX)) {
            x = coordinates.x - document.body.scrollLeft + window.screenLeft;
            y = coordinates.y - document.body.scrollTop + window.screenTop;
        } else {
            x = coordinates.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
            y = coordinates.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
        }
    } else if (document.all) {
        x = coordinates.x - document.body.scrollLeft + window.screenLeft;
        y = coordinates.y - document.body.scrollTop + window.screenTop;
    } else if (document.layers) {
        x = coordinates.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
        y = coordinates.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
    }

    coordinates.x = x;
    coordinates.y = y;

    return (coordinates);
}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname)
{
    var coordinates = getAnchorPosition(anchorname);

    var x = 0;
    var y = 0;

    if (document.getElementById) {
        if (isNaN(window.screenX)) {
            x = coordinates.x - document.body.scrollLeft + window.screenLeft;
            y = coordinates.y - document.body.scrollTop + window.screenTop;
        } else {
            x = coordinates.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
            y = coordinates.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
        }
    } else if (document.all) {
        x = coordinates.x - document.body.scrollLeft + window.screenLeft;
        y = coordinates.y - document.body.scrollTop + window.screenTop;
    } else if (document.layers) {
        x = coordinates.x + window.screenX + (window.outerWidth - window.innerWidth) - window.pageXOffset;
        y = coordinates.y + window.screenY + (window.outerHeight - 24 - window.innerHeight) - window.pageYOffset;
    }

    coordinates.x = x;
    coordinates.y = y;

    return (coordinates);
}

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname)
{
    // This function will return an Object with x and y properties
    var useWindow = false;
    var coordinates = new Object();
    var x = 0, y = 0;

    // Browser capability sniffing
    var use_gebi = false, use_css = false, use_layers = false;

    if (document.getElementById)
        use_gebi = true;
    else if (document.all)
        use_css = true;
    else if (document.layers)
        use_layers = true;

    // Logic to find position
    if (use_gebi && document.all) {
        x = anchorPosition_getPageOffsetLeft(document.all[anchorname]);
        y = anchorPosition_getPageOffsetTop(document.all[anchorname]);
    } else if (use_gebi) {
        var o = document.getElementById(anchorname);

        if (o != null) {
            x = anchorPosition_getPageOffsetLeft(o);
            y = anchorPosition_getPageOffsetTop(o);
        }
    } else if (use_css) {
        x = anchorPosition_getPageOffsetLeft(document.all[anchorname]);
        y = anchorPosition_getPageOffsetTop(document.all[anchorname]);
    } else if (use_layers) {
        var found = false;

        for (var i = 0; i < document.anchors.length; i++) {
            if (document.anchors[i].name == anchorname) {
                found = true;
                break;
            }
        }

        if (!found) {
            coordinates.x = 0;
            coordinates.y = 0;

            return (coordinates);
        }

        x = document.anchors[i].x;
        y = document.anchors[i].y;
    } else {
        coordinates.x = 0;
        coordinates.y = 0;

        return (coordinates);
    }

    coordinates.x = x;
    coordinates.y = y;

    return (coordinates);
}

// Functions for IE to get position of an object
function anchorPosition_getPageOffsetLeft(el)
{
    var ol = el.offsetLeft;

    while ((el = el.offsetParent) != null)
        ol += el.offsetLeft;

    return (ol);
}

function anchorPosition_getWindowOffsetLeft(el)
{
    return (anchorPosition_getPageOffsetLeft(el) - document.body.scrollLeft);
}

function anchorPosition_getPageOffsetTop(el)
{
    var ot = el.offsetTop;

    while ((el = el.offsetParent) != null)
        ot += el.offsetTop;

    return (ot);
}

function anchorPosition_getWindowOffsetTop(el)
{
    return (anchorPosition_getPageOffsetTop(el) - document.body.scrollTop);
}

function processConsumeEnterKey(passed_event)
{
    bEnterKey = false;

    evnt = passed_event != null ? passed_event : event;

    if (document.all) {
        if (evnt.keyCode == 13) {
            evnt.returnValue = false;
            evnt.cancel = true;
            bEnterKey = true;
        }
    } else if (document.getElementById) {
        if (evnt.which == 13) {
            if (evnt.preventDefault != null)
                evnt.preventDefault();
            else
                evnt.returnValue = false;

            if (evnt.stopPropagation != null)
                evnt.stopPropagation();
            else
                evnt.cancelBubble = false;

            bEnterKey = true;
        }
    } else if (document.layers) {
        if (evnt.which == 13) {
            evnt.returnValue = false;
            evnt.cancel = true;
            bEnterKey = true;
        }
    }

    return (bEnterKey);
}

function processDisplayListSelectCheckbox(oCheckboxElement)
{
    if (oCheckboxElement != null) {
        if (bDisplayDualListEnabled)
            processDisplayDualListSelectCheckbox(oCheckboxElement);
        else if (oCheckboxElement.name == '')
            oCheckboxElement.name = oCheckboxElement.id;
    }
}

function enableDisplayDualListSelect(strTopListClassName, strBottomListClassName)
{
    strDisplayDualListTopListClassName = strTopListClassName;
    strDisplayDualListBottomListClassName = strBottomListClassName;

    var oTableListViewTop = getElementByTagIdClass('table', 'listview', strDisplayDualListTopListClassName);

    if (oTableListViewTop == null) {
        var oCurrentHeaderRow = oTableListViewTop.tHead.rows[0];

        for (nDisplayDualListCheckboxCell = 0; nDisplayDualListCheckboxCell < oCurrentHeaderRow.cells.length && oCurrentHeaderRow.cells[nDisplayDualListCheckboxCell].innerHTML != 'Add'; nDisplayDualListCheckboxCell++);
    }

    bDisplayDualListEnabled = true;
}

function processDisplayDualListSelectCheckbox(oCheckboxElement)
{
    var oChkbxTableListView = null;
    var oChkbxTableRowListView = null;
    var oParentNode = oCheckboxElement;

    while ((oParentNode = oParentNode.parentNode) != null) {
        if (oParentNode.nodeName == 'TR')
            oChkbxRowListView = oParentNode;
        else if (oParentNode.nodeName == 'TABLE') {
            oChkbxTableListView = oParentNode;
            break;
        }
    }

    if (oChkbxTableListView != null) {
        var strListViewRowId = oCheckboxElement.id;
        var oTableListViewTop = getElementByTagIdClass('table', 'listview', strDisplayDualListTopListClassName);
        var oTableListViewBottom = getElementByTagIdClass('table', 'listview', strDisplayDualListBottomListClassName);

        if (oChkbxTableListView.className == strDisplayDualListTopListClassName) {
            var oTableListViewBottomChkboxRow = null;
            var nRowCount = oTableListViewBottom.tBodies[0].rows.length;

            for (var nRowCtr = 0; nRowCtr < nRowCount; nRowCtr++) {
                oCurrentRow = oTableListViewBottom.tBodies[0].rows[nRowCtr];

                if (oCurrentRow.cells[nDisplayDualListCheckboxCell].firstChild.id == strListViewRowId)
                    oTableListViewBottomChkboxRow = oCurrentRow;
            }

            var nVisibleRows = getTableRowVisibleCount(oTableListViewTop);

            if (!oCheckboxElement.checked) {
                oChkbxRowListView.style.display = 'none';

                if (oTableListViewBottomChkboxRow != null) {
                    oTableListViewBottomChkboxRow.style.display = '';
                    oTableListViewBottomChkboxRow.cells[nDisplayDualListCheckboxCell].firstChild.checked = false;
                }
            }
        } else if (oChkbxTableListView.className == strDisplayDualListBottomListClassName) {
            var oTableListViewTopChkboxRow = null;
            var nRowCount = oTableListViewTop.tBodies[0].rows.length;

            for (var nRowCtr = 0; nRowCtr < nRowCount; nRowCtr++) {
                oCurrentRow = oTableListViewTop.tBodies[0].rows[nRowCtr];

                if (oCurrentRow.cells[nDisplayDualListCheckboxCell].firstChild.id == strListViewRowId)
                    oTableListViewTopChkboxRow = oCurrentRow;
            }

            if (oCheckboxElement.checked) {
                oChkbxRowListView.style.display = 'none';

                if (oTableListViewTopChkboxRow != null) {
                    oTableListViewTopChkboxRow.style.display = '';
                    oTableListViewTopChkboxRow.cells[nDisplayDualListCheckboxCell].firstChild.checked = true;
                    oTableListViewTopChkboxRow.cells[nDisplayDualListCheckboxCell].firstChild.name = oTableListViewTopChkboxRow.cells[nDisplayDualListCheckboxCell].firstChild.id;
                } else {
                    oTableListViewRowAddNode = oChkbxRowListView.cloneNode(true);

                    if (oTableListViewRowAddNode != null) {
                        oTableListViewRowAddNode.className = strDisplayDualListTopListClassName;
                        oTableListViewRowAddNode.style.display = '';
                        oTableListViewRowAddNode.cells[nDisplayDualListCheckboxCell].firstChild.checked = true;
                        oTableListViewRowAddNode.cells[nDisplayDualListCheckboxCell].firstChild.name = oTableListViewRowAddNode.cells[nDisplayDualListCheckboxCell].firstChild.id;
                        oTableListViewTop.tBodies[0].appendChild(oTableListViewRowAddNode);
                    }
                }

                var nVisibleRows = getTableRowVisibleCount(oTableListViewTop);

                readjustListviewTableHeight(strDisplayDualListTopListClassName, 5, nVisibleRows); //[test] using a fixed value, needs to be a variable
            }
        }
    }
}

function getTableRowVisibleCount(oTable)
{
    var nVisibleRows = 0;
    var nRowCount = oTable.tBodies[0].rows.length;

    for (var nRowCtr = 0; nRowCtr < nRowCount; nRowCtr++) {
        oCurrentRow = oTable.tBodies[0].rows[nRowCtr];

        if (oCurrentRow.style.display == '')
            nVisibleRows++;
    }

    return (nVisibleRows);
}

/* This would be cool if I had non-DOM objects */
/* I have found the Javascript debugger for Mozilla Firefox, which is better */

var MAX_DUMP_DEPTH = 10;

function dumpObj(obj, name, indent, depth)
{
    if (depth > MAX_DUMP_DEPTH)
        return (indent + name + ": <Maximum Depth Reached>\n");

    if (typeof obj != "object")
        return (obj);
    else {
        var child = null;
        var output = indent + name + "\n";

        indent += "\t";

        for (var item in obj) {
            try {
                child = obj[item];
            } catch (e) {
                child = "<Unable to Evaluate>";
            }

            if (typeof child == "object")
                output += dumpObj(child, item, indent, depth + 1);
            else
                output += indent + item + ": " + child + "\n";
        }

         return (output);
    }
}

function displayDebugMessage(bAppend, strMessage)
{
    winDebugWindow = window.open('', 'JavaScriptDebug', 'height=400, width=600, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no');

    if (winDebugWindow != null) {
        var strHTMLMessage = strMessage.replace(/ /g, '&nbsp;');
        strHTMLMessage = strHTMLMessage.replace(/\n/g, '<br />\n');

        var dCurrTime = new Date();

        strDisplayHTMLMessage += '<br />\n<br />\n' + dCurrTime.toLocaleString() + '<br />\n' + strHTMLMessage;

        winDebugWindow.document.body.innerHTML = '<span style="font-family: Arial, Verdana, Sans-Serif; font-size: 10pt;">\n' + strDisplayHTMLMessage + '</span>\n';
    }
}

function displayDebugDivInfo(strDescription, oDivision, oComputerStyleDivision, nOriginalDivsionOffsetWidth, nOriginalDivisionOffsetHeight)
{
    var strMessage = '';

    strMessage += '\n' + getDOMObjectName(oDivision) + ':\n    DIV ' + strDescription + ' offsetWidth = ' + (nOriginalDivsionOffsetWidth == null ? '' : nOriginalDivsionOffsetWidth + ' (orig) / ') + oDivision.offsetWidth + ' offsetHeight = ' + (nOriginalDivisionOffsetHeight == null ? '' : nOriginalDivisionOffsetHeight + ' (orig) / ') + oDivision.offsetHeight;
    strMessage += '\n        offsetTop = ' + oDivision.offsetTop + ' offsetLeft = ' + oDivision.offsetLeft;
    strMessage += '\n        width = ' + oComputerStyleDivision.width + ', height = ' + oComputerStyleDivision.height;
    strMessage += '\n        margin-top = ' + oComputerStyleDivision.marginTop + ', margin-bottom = ' + oComputerStyleDivision.marginBottom;
    strMessage += '\n        margin-left = ' + oComputerStyleDivision.marginLeft + ', margin-right = ' + oComputerStyleDivision.marginRight;
    strMessage += '\n        border-top = ' + oComputerStyleDivision.borderTopWidth + ', border-bottom = ' + oComputerStyleDivision.borderBottomWidth;
    strMessage += '\n        border-left = ' + oComputerStyleDivision.borderLeftWidth + ', border-right = ' + oComputerStyleDivision.borderRightWidth;
    strMessage += '\n        padding-top = ' + oComputerStyleDivision.paddingTop + ', padding-bottom = ' + oComputerStyleDivision.paddingBottom;
    strMessage += '\n        padding-left = ' + oComputerStyleDivision.paddingLeft + ', padding-right = ' + oComputerStyleDivision.paddingRight;
    strMessage += '\n        min-width = ' + oComputerStyleDivision.minWidth + ', min-height = ' + oComputerStyleDivision.minHeight;

    return (strMessage);

}

function displayDebugTableInfo(strDescription, oDivision, oComputerStyleDivision, nOriginalDivsionOffsetWidth, nOriginalDivisionOffsetHeight)
{
    var strMessage = '';

    strMessage += '\n' + getDOMObjectName(oDivision) + ':\n    Table ' + strDescription + ' offsetWidth = ' + (nOriginalDivsionOffsetWidth == null ? '' : nOriginalDivsionOffsetWidth + ' (orig) / ') + oDivision.offsetWidth + ' offsetHeight = ' + (nOriginalDivisionOffsetHeight == null ? '' : nOriginalDivisionOffsetHeight + ' (orig) / ') + oDivision.offsetHeight;
    strMessage += '\n        listview rows = ' + oDivision.tBodies[0].rows.length;
    strMessage += '\n        offsetTop = ' + oDivision.offsetTop + ' offsetLeft = ' + oDivision.offsetLeft;
    strMessage += '\n        width = ' + oComputerStyleDivision.width + ', height = ' + oComputerStyleDivision.height;
    strMessage += '\n        margin-top = ' + oComputerStyleDivision.marginTop + ', margin-bottom = ' + oComputerStyleDivision.marginBottom;
    strMessage += '\n        margin-left = ' + oComputerStyleDivision.marginLeft + ', margin-right = ' + oComputerStyleDivision.marginRight;
    strMessage += '\n        border-top = ' + oComputerStyleDivision.borderTopWidth + ', border-bottom = ' + oComputerStyleDivision.borderBottomWidth;
    strMessage += '\n        border-left = ' + oComputerStyleDivision.borderLeftWidth + ', border-right = ' + oComputerStyleDivision.borderRightWidth;
    strMessage += '\n        padding-top = ' + oComputerStyleDivision.paddingTop + ', padding-bottom = ' + oComputerStyleDivision.paddingBottom;
    strMessage += '\n        padding-left = ' + oComputerStyleDivision.paddingLeft + ', padding-right = ' + oComputerStyleDivision.paddingRight;
    strMessage += '\n        min-width = ' + oComputerStyleDivision.minWidth + ', min-height = ' + oComputerStyleDivision.minHeight;

    return (strMessage);

}
