/*
	Created by BBSI WebHelp Writer of Buenaflor Better Softwares International 
	www.buenaflorsoft.com
*/
function doSection (secNum, butNum, CloseNode, OpenNode)
{
	if (secNum.style.display=="none")
		{secNum.style.display="";butNum.innerHTML = OpenNode;}
	else
		{secNum.style.display="none";butNum.innerHTML = CloseNode;}
}

var SectionsForUpdate = new Array();
var PopTablesForUpdate = new Array();

function ResizeAll()
{
	if (SectionsForUpdate)
	{
		var limit = SectionsForUpdate.length;
		for (var index = 0; index < limit; index++)
			SectionsForUpdate[index].OnResizeMenu();
	}
	if (PopTablesForUpdate)
	{
		var limit = PopTablesForUpdate.length;
		for (var index = 0; index < limit; index++)
		PopTablesForUpdate[index].Resize();
	}
}

function doMenu(UserMenu, lIndex)
{
	if (UserMenu.lOpenMember == lIndex)
		{UserMenu.CloseChild(lIndex);}
	else
		{UserMenu.OpenChild(lIndex);}
}

function doPopTable(UserPopTable)
{
	if (UserPopTable.bIsOpen)
		{UserPopTable.ClosePopTable();}
	else
		{UserPopTable.OpenPopTable();}
}

function MenuData(ParentMD, lSize, Element, Label, CloseNode, OpenNode, nSide)
{
	this.ParentMD = (ParentMD ? ParentMD : this);
	if (lSize <= 0)
		lSize = 1;
	this.lSize = lSize;
	this.Element = Element;
	Element.style.display = "";
	if (ParentMD)
		Element.style.position = "absolute";
	else
	{
		Element.style.position = "relative";
		if (SectionsForUpdate)
			SectionsForUpdate[SectionsForUpdate.length] = this;
		else
			SectionsForUpdate = this;
	}
	this.Label= Label;
	this.CloseNode = CloseNode;
	this.OpenNode = OpenNode;
	this.nSide = nSide;
	this.lOpenMember = -1;
	this.MembersMD = new Array(lSize);
	var i;
	for (i = 0; i < lSize; i++)
		this.MembersMD[i] = null;

	this.IsTopLevel = function()
	{
		return (this.ParentMD == this);
	}

	this.CreateChildMD = function(lIndex, lSize, Element, Label)
	{
		if ((lIndex < 0) || (lIndex >= this.lSize))
			return null;
		this.MembersMD[lIndex] = new MenuData(this, lSize, Element, Label, this.CloseNode, this.OpenNode, this.nSide);
		if (this.MembersMD[lIndex])
			Element.style.display = "none";
		return this.MembersMD[lIndex];
	}

	this.OnOpen = function()
	{
		if (this.Label)
			this.Label.innerHTML = this.OpenNode;
		this.Element.style.display = "";
		this.ParentMD.ResizeChild();
	}

	this.OnClose = function()
	{
		this.Element.style.display = "none";
		if (this.Label)
			this.Label.innerHTML = this.CloseNode;
	}

	this.CloseChild = function()
	{
		if (this.lOpenMember > -1)
		{
			this.MembersMD[this.lOpenMember].CloseChild();
			this.MembersMD[this.lOpenMember].OnClose();
			this.lOpenMember = -1;
		}
		
	}

	this.OpenChild = function(lIndex)
	{
		if ((lIndex < 0) || (lIndex >= this.lSize))
			return this;
		if (this.MembersMD[lIndex] == null)
			return this;
		if (this.lOpenMember == lIndex)
			return this.MembersMD[lIndex];			
		this.CloseChild();
		this.lOpenMember = lIndex;
		this.MembersMD[lIndex].OnOpen();
		return this.MembersMD[lIndex];
	}

	this.MenuOpened = function()
	{
		if (this.lOpenMember < 0)
			return null;
		return this.MembersMD[this.lOpenMember];
	}

	this.IsOpen = function()
	{
		return (this.ParentMD.MenuOpened() == this);
	}

	this.CloseMenu = function()
	{
		if (!this.IsOpen())
			return this;
		this.ParentMD.CloseChild();
		return this.ParentMD;
	}

	this.CollapseAll = function()
	{
		this.CloseChild();
		if (this.ParentMD != this)
			return this.ParentMD.CollapseAll();
		else
			return this;
	}

	this.ResizeChild = function()
	{
		if (this.lOpenMember >= 0)
		{
			var subject = this.MembersMD[this.lOpenMember];
			if (this.nSide == 0) // top-to-right
			{
				if (this.IsTopLevel())
				{
					subject.Element.style.left = (this.Element.offsetLeft + subject.Label.parentNode.offsetLeft) + "px";
					subject.Element.style.top = (this.Element.offsetTop + this.Element.offsetHeight + 1) + "px";
				}
				else
				{
					subject.Element.style.left = (this.Element.offsetLeft + this.Element.offsetWidth +1) + "px";
					subject.Element.style.top = (this.Element.offsetTop + subject.Label.parentNode.parentNode.offsetTop + 1) + "px";
				}
			}
			else if (this.nSide == 1) // top-to-left
			{
				if (this.IsTopLevel())
				{
					subject.Element.style.left = (this.Element.offsetLeft + subject.Label.parentNode.offsetLeft + subject.Label.parentNode.offsetWidth - subject.Element.offsetWidth) + "px";
					subject.Element.style.top = (this.Element.offsetTop + this.Element.offsetHeight + 1) + "px";
				}
				else
				{
					subject.Element.style.left = (this.Element.offsetLeft - 1 - subject.Element.offsetWidth) + "px";
					subject.Element.style.top = (this.Element.offsetTop + subject.Label.parentNode.parentNode.offsetTop + 1) + "px";
				}
			}
			else if (this.nSide == 2) // left
			{
				subject.Element.style.left = (this.Element.offsetLeft + this.Element.offsetWidth + 1) + "px";
				subject.Element.style.top = (this.Element.offsetTop + subject.Label.parentNode.parentNode.offsetTop + 1) + "px";
			}
			else if (this.nSide == 3) // right
			{
				subject.Element.style.left = (this.Element.offsetLeft - 1 - subject.Element.offsetWidth) + "px";
				subject.Element.style.top = (this.Element.offsetTop + subject.Label.parentNode.parentNode.offsetTop + 1) + "px";
			}
			this.MembersMD[this.lOpenMember].ResizeChild();
		}
	}

	this.OnResizeMenu = function()
	{
		if (this.IsTopLevel())
			this.ResizeChild();
	}
}

function PopTableData(PopTable, PopBase, nSide)
{
	this.PopTable = PopTable;
	this.PopBase = PopBase;
	this.nSide = nSide;
	this.PopTable.style.display = "none";
	this.PopTable.style.position = "absolute";
	this.bIsOpen = false;
	if (PopTablesForUpdate)
		PopTablesForUpdate[PopTablesForUpdate.length] = this;
	else
		PopTablesForUpdate = this;

	this.OpenPopTable = function()
	{
		if (this.bIsOpen)
			return;
		this.PopTable.style.display = "";
		this.bIsOpen = true;
		this.Resize();
	}

	this.ClosePopTable = function()
	{
		if (!this.bIsOpen)
			return;
		this.PopTable.style.display = "none";
		this.bIsOpen = false;
	}

	this.Resize = function()
	{
		if (!this.bIsOpen)
			return;
		if (this.nSide == 0)
			this.PopTable.style.left = (this.PopBase.offsetLeft) + "px";
		else
			this.PopTable.style.left = (this.PopBase.offsetLeft + this.PopBase.offsetWidth) + "px";
		this.PopTable.style.top = (this.PopBase.offsetTop + this.PopBase.offsetHeight + 1) + "px";
	}
}
