//Support routines for the SiteScape Forum div_tree function

//
//   Copyright (c) 2002 / SiteScape, Inc.  All Rights Reserved.
//
//  This information in this document is subject to change without notice 
//  and should not be construed as a commitment by SiteScape, Inc.  
//  SiteScape, Inc. assumes no responsibility for any errors that may appear 
//  in this document.
//
//  Restricted Rights:  Use, duplication, or disclosure by the U.S. Government 
//  is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the
//  Rights in Technical Data and Computer Software clause at DFARS 252.227-7013.
//
//  SiteScape and SiteScape Forum are trademarks of SiteScape, Inc.
//
//


var mouseX = 0;
var mouseY = 0;
var mousePosX = 0;
var mousePosY = 0;
var treeX = new Array;
var treeY = new Array;
var treeBranchBeingShown = null;
var topTreeBeingShown = null;
var divBeingShown = null;
var lastDivBeingShown = null;
var divToBeHidden = new Array;
var divToBeDelayHidden = new Array;

//Enable the event handler
createEventObj('captureXY', 'MOUSEUP')

//General routine to show a div given its name
function ShowHideDiv(divName, x, y, hd) {
    if (divBeingShown == divName) {
        hideDiv(divBeingShown)
        divBeingShown = null;
        lastDivBeingShown = null;
    } else {
        if (lastDivBeingShown == divName) {
            lastDivBeingShown = null;
            return
        }
        lastDivBeingShown = null;
        if (divBeingShown != null) {
            hideDiv(divBeingShown)
        }
        divBeingShown = divName;
        lastDivBeingShown = divName;
        positionDiv(divBeingShown, x, y)
        showDiv(divBeingShown, hd)
    }
}

//General routine to show a div given its name
function HideDivIfActivated(divName) {
    if (divBeingShown == divName) {
        hideDiv(divBeingShown)
        divBeingShown = null;
        lastDivBeingShown = null;
    }
}

//Routine to make div's be hidden on next click
function HideDivOnSecondClick(divName) {
    divToBeHidden[divName] = true;
}

//Routine to make div's be hidden on next click
function NoHideDivOnNextClick(divName) {
    divToBeDelayHidden[divName] = true;
}

function hideDiv(divName) {
    hideElement(divName);
    divToBeDelayHidden[divBeingShown] = null
    divBeingShown = null;
    
    //Show any spanned areas that may have been turned off
    showSpannedAreas()
}

function hideElement(divName) { 
    if (isNSN6) {
        //positionDiv(divName, -10000, -10000)
        document.getElementById(divName).style.visibility = "hidden";
    } else if (isMoz5) {
        document.getElementById(divName).style.visibility = "hidden";
    } else if (isNSN) {
        var nn4obj = getNN4DivObject(divName)
        nn4obj.visibility = "hidden"
    } else {
        self.document.all[divName].style.visibility = "hidden"
    }
}

function showDiv(divName, hd) {
    //Hide any area that has elements that might bleed through
    if (hd == null) {
        hideSpannedAreas()
    }
    showElement(divName);
}

function showElement(divName) {
    if (isNSN6 || isMoz5) {
        document.getElementById(divName).style.visibility = "visible";
    } else if (isNSN) {
        var nn4obj = getNN4DivObject(divName)
        nn4obj.visibility = "visible";
    } else {
        self.document.all[divName].style.visibility = "visible";
    }
}

function positionDiv(divName, x, y) {
    if (isNSN6 || isMoz5) {
        self.document.getElementById(divName).style.left= (x - parseInt(self.document.getElementById(divName).offsetParent.offsetLeft)) + "px"
        self.document.getElementById(divName).style.top= (y - parseInt(self.document.getElementById(divName).offsetParent.offsetTop)) + "px"
        if (z != 0) {self.document.getElementById(divName).style.zIndex = z}
    } else if (isNSN) {
        var nn4obj = getNN4DivObject(divName)
        nn4obj.left=x
        nn4obj.top=y
    } else {
        self.document.all[divName].style.left=x - self.document.all[divName].offsetParent.offsetLeft
        self.document.all[divName].style.top=y - self.document.all[divName].offsetParent.offsetTop
        if (z != 0) {self.document.all[divName].style.zIndex = z}
    }
}

function getClickPositionX() {
    return mousePosX;
}

function getClickPositionY() {
    if (isNSN6 || isMoz5) {
        return mousePosY;
    } else {
        return mousePosY + document.documentElement.scrollTop; 
    }
}

function showTopTree(treeName, offsetX, offsetY) {
    if (topTreeBeingShown == treeName) {
        hideTreeBranch(treeBranchBeingShown)
        topTreeBeingShown = null;
    } else {
        treeX[treeName] = mouseX + offsetX
        treeY[treeName] = getImageTop('img_'+treeName) + offsetY
        showTreeBranch(treeName, treeName)
        topTreeBeingShown = treeName;
    }
}

function showTreeBranch(topTreeName, treeName) {
    mouseX = treeX[topTreeName]
    mouseY = treeY[topTreeName]
    positionTreeBranch(topTreeName, treeName)
    if (treeBranchBeingShown != null) {
        hideTreeBranch(treeBranchBeingShown)
        treeBranchBeingShown = null;
    }

    //Hide any area that has elements that might bleed through
    hideSpannedAreas()

    //Show the tree div
    showDiv(treeName)
    treeBranchBeingShown = treeName;
}

function hideTreeBranch(treeName) {
    //Hide the tree div
    //hideDiv(treeName)
    treeBranchBeingShown = null;
    HideDivOnSecondClick(treeName);
    //Show any spanned areas that may have been turned off
    showSpannedAreas()
}

function positionTreeBranch(topTreeName, treeName) {
    var x = treeX[topTreeName]
    var y = treeY[topTreeName]
    //positionDiv(treeName, x, y)
    ShowHideDiv(treeName, x, y-5);
    HideDivOnSecondClick(treeName);
}

//Routines to get an object handle given the id name of a div
function getNN4DivObject(divName) {
    for (var n = 0; n < self.document.layers.length; n++) {
        var obj = getNN4DivObjectObj(self.document.layers[n], divName)
        if (obj != null) {return obj}
    }
    alert('Template error: unknown div id - '+divName)
    return self.document
}

function getNN4DivObjectObj(obj, divName) {
    if (obj.name == divName) {return obj}
    for (var n = 0; n < obj.document.layers.length; n++) {
        var obj1 = getNN4DivObjectObj(obj.document.layers[n], divName)
        if (obj1 != null) {return obj1}
    }
    return null
}

function captureXY(e) {
    if (!e) e = window.contents.event;

    //Is this click a "right click"? If yes, ignore it
    if (e && e.which && (e.which == 3 || e.which == 2)) {
        return false;
    } else if (e && e.button && (e.button == 2 || e.button == 3)) {
        return false;
    }

    //See if there is a div to be hidden
    lastDivBeingShown = divBeingShown;
    if (divBeingShown != null) {
        if (divToBeHidden[divBeingShown]) {
            if (divToBeDelayHidden[divBeingShown]) {
                divToBeDelayHidden[divBeingShown] = null
            } else {
                hideDiv(divBeingShown)
                divBeingShown = null;
            }
        }
    }
    if (isNSN6 || isMoz5) {
        mousePosX = e.pageX
        mousePosY = e.pageY
        mouseX = e.layerX
        mouseY = e.layerY
        return(true)
    } else if (isNSN) {
        mousePosX = e.x
        mousePosY = e.y
        mouseX = e.layerX
        mouseY = e.layerY
        var imgObj = getNN4ImgObject(e.layerX, e.layerY)
        if (imgObj != null) {
            mouseX = imgObj.x
            mouseY = imgObj.y
        }
        return(true)
    } else {
        mousePosX = event.x + self.document.body.scrollLeft
        mousePosY = event.y + self.document.body.scrollTop
        mouseX = event.clientX;
        mouseY = event.clientY;
        var imgObj = window.event.srcElement
        if (imgObj.name != null && !isMacIE) {
            mouseX = getImageLeft(imgObj.name)
            mouseY = getImageTop(imgObj.name)
        }
    }
}

//Routines to get an object handle given the x,y coordinates of the image
function getNN4ImgObject(imgX, imgY) {
    var imgObj = getNN4ImgObjectObj(self, imgX, imgY)
    return imgObj
}

function getNN4ImgObjectObj(divObj, imgX, imgY) {
    //Look in this div for the image
    for (var i = 0; i < divObj.document.images.length; i++) {
        var testImgObj = divObj.document.images[i]
        if ( testImgObj && testImgObj.x &&   (imgX >= testImgObj.x) && 
                (imgX <= testImgObj.x + testImgObj.width) && 
                (imgY >= testImgObj.y) && 
                (imgY <= testImgObj.y + testImgObj.height)    ) {
                return(testImgObj)
        }
    }
    //The image isn't in this div, look in the children divs
    for (var n = 0; n < divObj.document.layers.length; n++) {
        var testObj = divObj.document.layers[n]
        var imgObj = getNN4ImgObjectObj(testObj, imgX, imgY)
        if (imgObj != null) {return imgObj}
    }
    return null
}

//Routines to get a div handle of the owner of an image
function getNN4ImgDivObject(imgObj) {
    var divObj = getNN4ImgDivObjectObj(self, imgObj)
    return divObj
}

function getNN4ImgDivObjectObj(divObj, imgObj) {
    //Look in this div for the image
    for (var i = 0; i < divObj.document.images.length; i++) {
        var testImgObj = divObj.document.images[i]
        if (testImgObj == imgObj) {
            return(divObj)
        }
    }
    //The image isn't in this div, look in the children divs
    for (var n = 0; n < divObj.document.layers.length; n++) {
        var testDivObj = divObj.document.layers[n]
        var testImgObj = getNN4ImgDivObjectObj(testDivObj, imgObj)
        if (testImgObj != null) {return testDivObj}
    }
    return null
}

var globalHtml
var branchesBuilt = new Array

function showJsTopTreeOpen(treeName) {
    var treeId = treeName.substring(5,treeName.length)
    toc[treeId] = 'open'
    showJsTopTree(treeName, 15, 20)
}

function showJsTopTreeClosed(treeName) {
    var treeId = treeName.substring(5,treeName.length)
    toc[treeId] = 'closed'
    showJsTopTree(treeName, 15, 20)
}

function showJsTopTree(treeName, offsetX, offsetY) {
    var treeId = treeName.substring(5,treeName.length)
    var toptreeDiv = 'toptree_'+treeId
    //Build all the branches (if they haven't been built)
    if (!branchesBuilt[treeId]) {
        if (!tct[treeId]) {
            //Remember the source of the top tree
            if (isNSN6 || isMoz5) {
                tct[treeId] = document.getElementById(toptreeDiv).innerHTML
            } else {
                tct[treeId] = document.all[toptreeDiv].innerHTML
            }
        }
        var s = ''
        s += ' <tr>\n'
        s += '  <td colspan="2" class="content" valign="middle" nowrap>\n'
        s += '   <table cellspacing="0" cellpadding="0" style="display:inline;"><tr><td valign="middle">\n'
        s += '   <a href="javascript: ;" \n'
        s += '   onClick="showJsTopTreeClosed(\'tree_'+treeId+'\');">\n'
        s += '   <img name="img_'+treeId+'" border="0" alt="" \n'
        s += '   src="'+minusPic+'"></a>\&nbsp;\n'
        s += '   <img name="img_'+treeId+'" border="0" alt="" \n'
        s += '   src="'+openFolderPic+'">\&nbsp;</td><td valign="middle" nowrap>\n'
        s += '   '+tt[treeId]+'\n'
        s += '   </td></tr></table>\n'
        s += '  </td>\n'
        s += ' </tr>\n'
        tot[treeId] = s

        showJsTreeBranchAll(treeName, treeName)
        branchesBuilt[treeId] = 1
    }

    if (toc[treeId] == 'open') {
        var html = '<table border="0" cellspacing="0" cellpadding="0">\n<tbody>\n<tr>\n  <td valign="middle">\n'
        html += '<table border="0" cellspacing="0" cellpadding="0">\n<tbody>\n'

        globalHtml = ''
        showJsTreeBranchAllOpen(treeName, treeName)
        html += globalHtml

        html += '</tbody></table>\n'
        html += '\n  </td>\n</tr></tbody></table><br />\n'

    } else {
        var html = tct[treeId]
    }

    globalHtml = html;

    //Write out the div for this view
    if (isNSN6 || isMoz5) {
        document.getElementById(toptreeDiv).innerHTML = globalHtml;
    } else {
        document.all[toptreeDiv].innerHTML = globalHtml;
    }
    td[treeId] = 1

    if (0) {
        //Show this div
        if (!treeX[treeName]) {treeX[treeName] = mouseX + offsetX}
        if (!treeY[treeName]) {treeY[treeName] = mouseY + offsetY}
        positionDiv(treeName, treeX[treeName], treeY[treeName]-5);

        if (isNSN6 || isMoz5) {
            document.getElementById(treeName).style.visibility = "visible";
        } else if (isNSN) {
            nn4obj.visibility = "visible";
        } else {
            self.document.all[treeName].style.visibility = "visible";
        }
    }
}

function showJsTreeBranchAllOpen(topTreeName, treeName) {
    var treeId = treeName.substring(5,treeName.length)
    if (isNSN && !isNSN6 && !isMoz5) {
        //Get the handle of the div object (needed by Netscape 4 only)
        var nn4obj = getNN4DivObject(treeName)
    }
    
    //Show the open text for this branch
    if (ta[treeId]) {
        if (toc[treeId] == 'open') {
            if (tot[treeId]) {globalHtml += tot[treeId]}
        } else {
            if (tct[treeId]) {globalHtml += tct[treeId]}
        }

        //Now show the contents of the branch
        for (var n in ta[treeId]) {
            if (ta[n] != '') {
                if (toc[n] && toc[n] == 'open') {
                    showJsTreeBranchAllOpen(topTreeName, 'tree_'+n)
                } else {
                    if (ta[n] && ta[n] != '') {
                        if (tct[n]) {globalHtml += tct[n]}
                    } else {
                        if (tot[n]) {globalHtml += tot[n]}
                    }
                }
            } else {
                if (tot[n]) {globalHtml += tot[n]}
            }
        }
    } else {
        //Show the leaf if the parent is open
        if (tp[treeId] && tp[treeId] != '' && toc[tp[treeId]] == 'open') {
            //The parent is open, show this leaf's open text
            if (tot[treeId]) {globalHtml += tot[treeId]}
        } else {
            if (tct[treeId]) {globalHtml += tct[treeId]}
        }
    }
}

function showJsTreeBranchAll(topTreeName, treeName) {
    var treeId = treeName.substring(5,treeName.length)
    if (isNSN && !isNSN6 && !isMoz5) {
        //Get the handle of the div object (needed by Netscape 4 only)
        var nn4obj = getNN4DivObject(treeName)
    }
    
    //Build the html for this branch (if not already built)
    if (!td[treeId]) {
        //Show the navigation back up to the top
        var parent = treeId
        var indentation = 1
        while (tp[parent] != '') {
            indentation++
            parent = tp[parent]
        }

        parent = treeId
        var navHtml = ''
        var count = indentation
        while (tp[parent] != '') {
            var navLine = ''
            var parentId = tp[parent]
            var parentText = tt[parent]
            if (count == indentation) {
                navLine += '\n<tr>\n  <td class="content" valign="middle" nowrap>'
                for (var i = 1; i < count; i++) {
                    navLine += '<img src="'+spacerPic+'" alt="">'
                }
            } else {
                navLine += '<tr>\n  <td class="content" \nvalign="middle" nowrap>'
                for (var i = 1; i < count; i++) {
                    navLine += '<img src="'+spacerPic+'" alt="">'
                }
            }
            navLine += '<table cellspacing="0" cellpadding="0" style="display:inline;"><tr><td valign="middle">\n'
            navLine += '<a\n href="javascript:showJsTreeBranchClosed(\''+topTreeName+'\', \'tree_'+parent+'\')">'
            navLine += '<img src="'+minusPic+'" \nborder="0" alt="Hide the contents of this folder">'
            navLine += '</a>&nbsp;'
            navLine += '<img src="'+openFolderPic+'" \nborder="0" alt="Open folder">&nbsp;'
            navLine += '</td><td valign="middle" nowrap>\n'
            navLine += parentText
            navLine += '</td></tr></table>\n'
            navLine += '</td></tr>\n'
            navHtml = navLine + navHtml
            if (!tot[parent]) {
                tot[parent] = navLine
                toc[parent] = 'closed'
            }
            count--
            td[parent] = 1
            parent = tp[parent]
        }

        //Now show the contents of the branch
        for (var n in ta[treeId]) {
            var line = ''
            line += '<tr>\n  <td class="content" valign="middle">'
            if (ta[treeId][n]) {
                for (var i = 0; i < indentation; i++) {
                   line += '<img src="'+spacerPic+'" alt="">'
                }
                line += '<table cellspacing="0" cellpadding="0" style="display:inline;"><tr><td valign="middle">\n'
                line += '<a\n href="javascript:showJsTreeBranchOpen(\''+topTreeName+'\', \'tree_'+n+'\')">'
                line += '<img src="'+plusPic+'" border="0" \nalt="Show the contents of this folder">'
                line += '</a>&nbsp;'
                line += '<img src="'+closedFolderPic+'" \nborder="0" alt="Closed folder">&nbsp;'
                line += '</td><td valign="middle" nowrap>\n'
                line += tt[n]
                line += '</td></tr></table>\n'
            } else {
                for (var i = 0; i < indentation; i++) {
                   line += '<img src="'+spacerPic+'" alt="">'
                }
                line += '<table cellspacing="0" cellpadding="0" style="display:inline;"><tr><td valign="middle">\n'
                line += '<img src="'+picBase+'/'+ti[n]+'" \nborder="0" alt="File">&nbsp;'
                line += '</td><td valign="middle" nowrap>\n'
                line += tt[n]
                line += '</td></tr></table>\n'
            }
            line += '\n  </td>\n</tr>\n'
            if (ta[treeId][n]) {
                tct[n] = line
            } else {
                tot[n] = line
            }
            if (!toc[n]) {toc[n] = 'closed'}

            if (ta[treeId][n]) {
                showJsTreeBranchAll(topTreeName, 'tree_'+n)
            }
        }
    }
}



function showJsTreeBranchOpen(topTreeName, treeName) {
    var treeId = treeName.substring(5,treeName.length)
    toc[treeId] = 'open'
    showJsTopTree(topTreeName, 15, 20)
}

function showJsTreeBranchClosed(topTreeName, treeName) {
    var treeId = treeName.substring(5,treeName.length)
    toc[treeId] = 'closed'
    showJsTopTree(topTreeName, 15, 20)
}

function showJsTreeBranch(topTreeName, treeName) {
    var treeId = treeName.substring(5,treeName.length)
    if (isNSN && !isNSN6 && !isMoz5) {
        //Get the handle of the div object (needed by Netscape 4 only)
        var nn4obj = getNN4DivObject(treeName)
    }
    
    //Build the div for this branch (if not already built)
    if (!td[treeId]) {
        var html = '<table border="0" cellspacing="2" cellpadding="2">\n<tbody><tr>\n<td valign="middle">\n'
 
        html += '<table border="0" cellspacing="0" cellpadding="0">\n<tbody>'

        //Show the navigation back up to the top
        var parent = treeId
        var indentation = 0
        while (tp[parent] != '') {
            indentation++
            parent = tp[parent]
        }

        parent = treeId
        var navHtml = ''
        var count = indentation
        while (tp[parent] != '') {
            var navLine = ''
            var parentId = tp[parent]
            var parentText = tt[parent]
            if (count == indentation) {
                navLine += '\n<tr><td class="content" valign="middle">'
                for (var i = 1; i < count; i++) {
                    navLine += '<img src="'+spacerPic+'" alt="">'
                }
                navLine += '</td>\n<td class="content" valign="middle">'
            } else {
                navLine += '<tr><td colspan="2" class="content" \nvalign="middle">'
                for (var i = 1; i < count; i++) {
                    navLine += '<img src="'+spacerPic+'" alt="">'
                }
            }
            navLine += '<a\n href="javascript:showJsTreeBranchClosed(\''+topTreeName+'\', \'tree_'+parentId+'\')">'
            navLine += '<img src="'+minusPic+'" \nborder="0" alt="Hide the contents of this folder">'
            navLine += '</a>&nbsp;'
            navLine += '<img src="'+openFolderPic+'" \nborder="0" alt="Open folder">&nbsp;'
            navLine += parentText
            navLine += '</td></tr>\n'
            navHtml = navLine + navHtml
            tct[parent] = navLine
            count--
            parent = tp[parent]
        }
        html += navHtml

        //Now show the contents of the branch
        for (var n in ta[treeId]) {
            var line = ''
            line += '<tr><td class="content" valign="middle"></td>\n<td class="content" valign="middle">'
            if (ta[treeId][n]) {
                for (var i = 0; i < indentation; i++) {
                   line += '<img src="'+spacerPic+'" alt="">'
                }
                line += '<a\n href="javascript:showJsTreeBranchOpen(\''+topTreeName+'\', \'tree_'+n+'\')">'
                line += '<img src="'+plusPic+'" border="0" \nalt="Show the contents of this folder">'
                line += '</a>&nbsp;'
                line += '<img src="'+closedFolderPic+'" \nborder="0" alt="Closed folder">&nbsp;'
                line += tt[n]
            } else {
                if (indentation > 0) {
                   line += '<img src="'+spacerPic+'" alt="">'
                }
                line += '<img src="'+picBase+'/'+ti[n]+'" \nborder="0" alt="File">&nbsp;'
                line += tt[n]
            }
            line += '</td></tr>\n'
            html += line;
            tot[n] = line
        }
        html += '</tbody></table>\n'
        html += '</td></tr></tbody></table><br />\n'

        globalHtml = html;
    }
}

function showTreeBranchNow(topTreeName, treeName) {
    var treeId = treeName.substring(5,treeName.length)

    //Write out the div for this branch (if not already built)
    if (!td[treeId]) {
        if (isNSN6 || isMoz5) {
            document.getElementById(treeName).innerHTML = globalHtml;
        } else if (isNSN) {
            nn4obj.document.open()
            nn4obj.document.write(globalHtml)
            nn4obj.document.close()
        } else {
            document.all[treeName].innerHTML = globalHtml;
        }
        td[treeId] = 1
    }

    //Hide the previous tree
    if (treeBranchBeingShown != null) {
        hideTreeBranch(treeBranchBeingShown)
        treeBranchBeingShown = null;
    }

    //Hide any spanned areas that might show through
    hideSpannedAreas()

    //Show this div
    positionTreeBranch(topTreeName, treeName)
    if (isNSN6 || isMoz5) {
        document.getElementById(treeName).style.visibility = "visible";
    } else if (isNSN) {
        nn4obj.visibility = "visible";
    } else {
        self.document.all[treeName].style.visibility = "visible";
    }
    treeBranchBeingShown = treeName;
    
}

// this function is used for the calendar entry popups (forms)
// assumes a cancel/close button to hide the div
var z = 0;
function activateTextlayer(divId) {
    // don't do anything if the divs aren't loaded yet
   if (isNSN6 || isMoz5) {
        if (document.getElementById(divId) == null) {
            return;
        }
   } else if (isNSN) {
        var nn4obj = getNN4DivObject(divId);
        if (nn4obj == null) {
            return;
        }
    } else if (self.document.all[divId] == null) {
        return;
    }
    var x = getClickPositionX();
    var y = getClickPositionY();
    var maxWidth = 0;
    var divWidth = 0;
    if (isNSN6 || isMoz5) {
        // need to bump layer an extra bit to the right to avoid horiz scrollbar
        divWidth = parseInt(document.getElementById(divId).offsetWidth) + 25;
        maxWidth = parseInt(window.innerWidth);
    } else if (isNSN) {
        var nn4obj = getNN4DivObject(divId)
        divWidth = parseInt(nn4obj.clip.width);   
        maxWidth = parseInt(window.innerWidth);
    } else {
        maxWidth = parseInt(document.body.scrollWidth);
        divWidth = self.document.all[divId].clientWidth;
    }
    if (x + divWidth >= maxWidth) {
        x = maxWidth - divWidth;
    } 
    z += 1;
    positionDiv(divId, x, y);  
    showDiv(divId);
}

// this function is used for the menu, help, text only popups
// clicking anywhere will hide the div
function activateMenulayer(divId, hd) {
    // don't do anything if the divs aren't loaded yet
    if (isNSN6 || isMoz5) {
        if (self.document.getElementById(divId) == null) {return}
    } else if (isNSN) {
        var nn4obj = getNN4DivObject(divId)
        if (nn4obj == null) {return}
    } else {
        if (self.document.all[divId] == null) {return}
    }

    var x = getClickPositionX();
    var y = getClickPositionY();
    //Add a little to the y position so the div isn't occluding too much
    y = parseInt(y) + 9

    var maxWidth = 0;
    var divWidth = 0;

    if (isNSN6 || isMoz5) {
        // need to bump layer an extra bit to the right to avoid horiz scrollbar
        divWidth = parseInt(self.document.getElementById(divId).offsetWidth) + 25;
        maxWidth = parseInt(window.innerWidth);
    } else if (isNSN) {    
        var nn4obj = getNN4DivObject(divId)
        divWidth = parseInt(nn4obj.clip.width);
        maxWidth = parseInt(window.innerWidth);
    } else {
        divWidth = parseInt(self.document.all[divId].clientWidth) + 25;
        maxWidth = parseInt(document.body.scrollWidth);
    }

    if (x + divWidth > maxWidth) {
        x = maxWidth - divWidth;
    } 
  
    ShowHideDiv(divId, x, y, hd);
    HideDivOnSecondClick(divId);
}
