var OPEN, CLOSE, ArrayOfMenus, Index, TOP
var CLEANCOOKIES;

OPEN 	=	0;
CLOSE 	=	1;

Index = 0 ;

function Menu(pPai, pStatus, pLayer, pImagem, pUrl, pLnk, pHaveSons, pTd)
{
	this.Pai = pPai;
	this.Status = pStatus;
	this.Layer = pLayer;
	this.Imagem = pImagem;
	this.Url = pUrl;
	this.Lnk = pLnk;
	this.HaveSons = pHaveSons;
	this.Td = pTd;
}
		 
function CreateArray(pLen)
{
	ArrayOfMenus = new Array(pLen);
	TOP = pLen;
}

function AddMenu(pPai, pStatus, pLayer, pImagem, pUrl, pLnk, pHaveSons, pTd)
{
	lNovoMenu = new Menu(pPai, pStatus, pLayer, pImagem, pUrl, pLnk, pHaveSons, pTd);
	ArrayOfMenus[Index] = lNovoMenu;
	OpenOrCloseMenu(pLayer, false);
	Index ++;
}


function OpenSelected()
{
	var lIndex;
	
	if(CLEANCOOKIES == 1)
		ClearAllCookies();

	for(lIndex=0; lIndex < TOP; lIndex++)
	{
		if(ArrayOfMenus[lIndex] != null)
		{
			Selected = readCookie("Selected");
			
			if(readCookie(ArrayOfMenus[lIndex].Layer) == 1)
				OpenOrCloseMenu(ArrayOfMenus[lIndex].Layer, false, false)
			
			if(Selected == ArrayOfMenus[lIndex].Layer)
				if(document.getElementById(ArrayOfMenus[lIndex].Lnk) != null)
				{
					document.getElementById(ArrayOfMenus[lIndex].Lnk).className = 'MenuBold';

					if(!ArrayOfMenus[lIndex].HaveSons)
						document.getElementById(ArrayOfMenus[lIndex].Td).className = 'TdSelected';
					
				}
		}
	}
}

function Show(Value)
{	
	Dummy = document.getElementById&&!document.all?document.getElementById(Value) : document.all[Value];
	Dummy.style.visibility = 'Visible'
	Dummy.style.display = ''
}

function Hide(Value)
{	
	Dummy = document.getElementById&&!document.all?document.getElementById(Value) : document.all[Value];
	Dummy.style.visibility = 'Hidden'
	Dummy.style.display = 'None'
}

function OpenOrCloseMenu(Name, Cookies, GoToUrl)
{
	var lIndex, WriteCookies, GoTo;

	if(Cookies == undefined)
		WriteCookies = true;
	else
		WriteCookies = Cookies;
		
		
	if(GoToUrl == undefined)
		GoTo = true;
	else
		GoTo = GoToUrl;
	

	for(lIndex=0; lIndex < TOP; lIndex++)
		if(ArrayOfMenus[lIndex] != null)
			if(ArrayOfMenus[lIndex].Layer == Name)
			{
				if(ArrayOfMenus[lIndex].HaveSons)
				{
					switch(ArrayOfMenus[lIndex].Status)
					{
						case CLOSE:
							Show(ArrayOfMenus[lIndex].Layer);
							ArrayOfMenus[lIndex].Status = OPEN;
							document.images[ArrayOfMenus[lIndex].Imagem].src = './img/seta_down.gif';
				
							if(document.getElementById(ArrayOfMenus[lIndex].Lnk) != null)		
								document.getElementById(ArrayOfMenus[lIndex].Lnk).className = 'MenuBold';
							
							if(WriteCookies) writeCookie(Name, 1, 90000);

							if(ArrayOfMenus[lIndex].Url != '' && GoTo) Go(ArrayOfMenus[lIndex].Url, Name)
								
							break;
						case OPEN:
							Hide(ArrayOfMenus[lIndex].Layer);
							ArrayOfMenus[lIndex].Status = CLOSE;
							document.images[ArrayOfMenus[lIndex].Imagem].src = './img/seta.gif';
							
							if(WriteCookies)
								writeCookie(Name, -1, 90000);
							
							if(WriteCookies)
								if(ArrayOfMenus[lIndex].Url != '' && GoTo) Go(ArrayOfMenus[lIndex].Url, Name)
							
							break;
					}
				}
				else if(WriteCookies) Go(ArrayOfMenus[lIndex].Url, Name);
			}
}

function Go(GoTo, Name)
{
	deleteCookie("Selected");
	writeCookie("Selected", Name, 90000);
	window.location = GoTo;
}

function ClearAllCookies()
{
	deleteCookie("Selected");
	var lIndex;

	for(lIndex=0; lIndex < TOP; lIndex++)
		if(ArrayOfMenus[lIndex] != null)
			deleteCookie(ArrayOfMenus[lIndex].Layer);
}

function MakeDiv(pId)
{
	document.write('<Span style="position:relative; left:0px; top:0px; bottom:0px; width:228px;z-index:1; visibility:hidden;overflow: hidden; display:none" id="' + pId + '">');
}

function CloseDiv()
{
	document.write('</Span>');
}	


