// Creating a custom object called objFloatPanel with the properties "name", "panelExist",
// "xOffset", "yOffset", "bXFloat", "bYFloat" for positioning management
function objFloatPanel(name, panelExist, xOffset, yOffset, xFloat, yFloat) {
    this.name = name;
    this.menuExist = panelExist;
    this.xOffset = xOffset;
    this.yOffset = yOffset;
    this.bXFloat = xFloat;
    this.bYFloat = yFloat;
    this.xTopLock = 0;
    this.xBottomLock = -58;
    this.yLeftLock = 0;
    this.yRightLock = 0;
}

// support for non-DHTML compliant CSS-enabled browsers to keep "phantom" panels from occuring
function setPosType( strPanelName )
{
	if( document.all )
	{
		document.all['P'+strPanelName].className = 'stFloatPanel posAbsolute';
	}
}

function unsetPosType( strPanelName )
{
	if( document.all )
	{
		document.all['P'+strPanelName].className = 'stFloatPanel';
	}
}

// Simple metrix initiallization function
function initPanelMetrix( panelID, objPanel )
{
    if(document.all)
    {
        // find the top offset and bottom values of the parent and save them to the object
		var test='P' + panelID;
		var objEl;
		var objOrigEl;
		objEl = objOrigEl = document.all[test].parentElement;
		var lLeft = 0;
		var lTop = 0;

        while (objEl.tagName != 'DIV') {
			lLeft+= objEl.offsetLeft;
			if( (objEl.tagName != 'TR') )   // JEL work-around/fix to keep from double counting row content height
            {
                lTop+= objEl.offsetTop;
            }
            // lTopList += " + " + objEl.offsetTop + " (" + objEl.tagName + ")";
            // lLeftList += " + " + objEl.offsetLeft + " (" + objEl.tagName + ")";
			objEl = objEl.parentElement;
		}
        // Reset tothe parent of the panel
		objEl = objOrigEl = document.all[test].parentElement;
        
        // get the parent's height and subtract the height of the panel
        var lParentHeight = objEl.clientHeight;
        var lPanelHeight = document.all[test].clientHeight;
        objPanel.xTopLock += lTop;
        objPanel.xBottomLock += lParentHeight;
        // alert("lParentHeight : "+lParentHeight+"\n lPanelHeight : "+lPanelHeight);
    }
}

// Simple function to move a <DIV> to the appropriate coordinates on a screen
function updatePanelPos( panelID, objPanel ) {
	if (document.all) {
		var test='P' + panelID;
		var objEl;
		var objOrigEl;
		objEl = objOrigEl = document.all[test].parentElement;
		var lLeft = 0;
		var lTop = 34;
		// var lTopList = "0 + ";
		// var lLeftList = "0 + ";
        
        while (objEl.tagName != 'DIV') {
			lLeft+= objEl.offsetLeft;
			if( (objEl.tagName != 'TR') )   // JEL work-around/fix to keep from double counting row content height
            {
                lTop+= objEl.offsetTop;
            }
            // lTopList += " + " + objEl.offsetTop + " (" + objEl.tagName + ")";
            // lLeftList += " + " + objEl.offsetLeft + " (" + objEl.tagName + ")";
			objEl = objEl.parentElement;
		}
		
        if( objPanel.bXFloat )
        {
            var nInitialLeft = lLeft;
            lLeft += document.body.scrollLeft;
            lLeft -= nInitialLeft;
        }
        
        if( objPanel.bYFloat )
        {
            var nInitialTop = lTop;
            lTop += document.body.scrollTop;
            lTop -= nInitialTop;
            if(lTop < objPanel.xTopLock)
            { lTop = objPanel.xTopLock; }

            if(lTop > objPanel.xBottomLock)
            { lTop = objPanel.xBottomLock; }
        }
        
		document.all[test].style.display = 'block';
		document.all[test].style.pixelLeft = lLeft;
		document.all[test].style.pixelTop = lTop;
        // alert("lTop : "+lTop + "\n lLeft : " + lLeft + "\n ScrollTop : " + document.body.scrollTop + "\n ScrollLeft : " + document.body.scrollLeft + "\n xTopLock: " + objPanel.xTopLock + "\n xBottomLock: " + objPanel.xBottomLock );
	}
}