
<%
'
'*** Classe ItemMenu ********************************************************************
'
Class ItemMenu
	Public rotulo
	Public href
	Public largura
	Public status
	Public numFilhos
	Public visivel
	Public usuario ' referęncia para o usuário logado
	Private itensSubMenu()
	Private indItens
	
	'---------------------------------------------------------------------------------
	Private Sub Class_Initialize()
		rotulo = ""
		href = ""
		largura = 100
		status = ""
		visivel = true
		Redim itensSubMenu(5)
		indItens = 0
		numFilhos = 0
	End Sub
	
	'---------------------------------------------------------------------------------
	Private Sub Class_Terminate()
   	dim i
		for i = 0 to indItens - 1
			set itensSubMenu(i) = nothing
		next
		set usuario = nothing
	End Sub
	
	'---------------------------------------------------------------------------------
	Public Function GetSubItensCount()
		GetSubItensCount = indItens
	End Function
	
	'---------------------------------------------------------------------------------
	Public Function GetSubItem(indice)
		if indice >= 0 and indice <= indItens then
			set GetSubItem = itensSubMenu(indice)
		else
			set GetSubItem = nothing	
		end if	
	End Function 

	'---------------------------------------------------------------------------------
	Public Function AddItemSubMenu(rotulo, localhref, largura, status, programa, operacao)
		dim novo
		set novo = new ItemMenu
		novo.rotulo = rotulo
		novo.href = localhref
		novo.largura = largura
		novo.status = status
		set novo.usuario = usuario 'atribuir usuário logado
		
		'*** limpa campos do item que tem sub-itens
		href = ""
		visivel = true
		'***
		
		'Retorna um boleano com a autorizacao para o botao baseado em PROGRAMA e OPERACAO 
		novo.visivel = true 
		
		if indItens = UBound(itensSubMenu)-1 then
		redim preserve itensSubMenu(UBound(itensSubMenu)+5)
		end if
		set itensSubMenu(indItens) = novo
		indItens = indItens + 1
		
		set AddItemSubMenu = novo
	End Function

End Class
'
'*** Classe BarraMenu ********************************************************************
'
Class BarraMenu
	Private hiBgColor
	Private lowBgColor
	Private borderColor
	Private borderMain
	Private borderSub
	Private fontFamily
	Private fontSize
	Private fontBold
	Private fontItalic
	Private hiFontColor
	Private lowFontColor
	Private frameName
	Private frameTarget
	Private frameHorizontal
	Private topPosition
	Private leftPosition
	Private useArrows
	Private useSeguranca
	Private itensMenu()
	Private indItens
	
	Private usuario 'Referęncia para usuário logado
	
	'---------------------------------------------------------------------------------
	Private Sub Class_Initialize()
		Redim itensMenu(5)
		indItens = 0
		hiBgColor = "#CCDDDD"
		lowBgColor = "#669999"
		borderColor = "#000000"
		borderMain = true
		borderSub = true
		fontFamily = "Verdana, Arial, Times"
		fontSize = 8
		fontBold = true
		fontItalic = false
		hiFontColor = "#000000"
		lowFontColor = "#FFFFFF"
		frameName = "titulo"
		frameTarget = "corpo"
		frameHorizontal = true
		useArrows = true
		useSeguranca = false
		topPosition = 0
		leftPosition = 0
		' Deveria setar o usuário que está logado
		set usuario = nothing
	End Sub
	
	'---------------------------------------------------------------------------------
	Private Sub Class_Terminate()
   	dim i
		for i = 0 to indItens - 1
			set itensMenu(i) = nothing
		next
		set usuario = nothing
	End Sub
	
	'---------------------------------------------------------------------------------
	Public Function AddItemMenu(rotulo, href, largura, status, programa, operacao)
		dim imenu
		set imenu = new ItemMenu
		
		imenu.rotulo = rotulo
		imenu.href = href
		imenu.largura = largura
		imenu.status = status
		'Usuário é uma classe que deveria conter uma referęncia para o usuário logado
		set imenu.usuario = usuario 
		
		'substituir por um método que verifique se o usuário logado pode ter acesso a este botăo
		imenu.visivel = true
		
		if indItens = UBound(itensMenu)-1 then
			redim preserve itensMenu(UBound(itensMenu)+5)
		end if
		set itensMenu(indItens) = imenu
		indItens = indItens + 1
		set AddItemMenu = imenu
	End Function
	
	'---------------------------------------------------------------------------------
	Public Sub SetCores(fonteAtivo, fonteInativo, fundoAtivo, fundoInativo, borda)
		hiBgColor = fundoAtivo
		lowBgColor = fundoInativo
		borderColor = borda
		hiFontColor = fonteAtivo
		lowFontColor = fonteInativo
	End Sub
	
	'---------------------------------------------------------------------------------
	Public Sub SetFonte(familia, tamanho, negrito, italico)
		fontFamily = familia
		fontSize = tamanho
		fontBold = negrito
		fontItalic = italico
	End Sub
	
	'---------------------------------------------------------------------------------
	Public Sub Configura(frame, target, horizontal, bordaMenu, bordaSubmenu, topPos, leftPos, setas, seguranca)
		borderMain = bordaMenu
		borderSub = bordaSubMenu
		frameName = frame
		frameTarget = target
		frameHorizontal = horizontal
		useArrows = setas
		useSeguranca = seguranca
		topPosition = topPos
		leftPosition = leftPos
		
		if useSeguranca then 
			'Ativar seguranca
		end if	
	End Sub

	'---------------------------------------------------------------------------------
	Public Sub Monta()
	%>
	<script type='text/javascript'>function Go(){return}</script>
	<script type='text/javascript'>
	var LowBgColor="<%= lowBgColor %>";
	var HighBgColor="<%= hiBgColor %>";
	var FontLowColor="<%= lowFontColor %>";
	var FontHighColor="<%= hiFontColor %>";
	var BorderColor="<%= borderColor %>";
	var BorderWidthMain=1;
	var BorderWidthSub=1;
 	var BorderBtwnMain=<% if borderMain then response.write("1") else response.write("0") %>;
	var BorderBtwnSub=<% if borderSub then response.write("1") else response.write("0") %>;
	var FontFamily="<%= fontFamily %>";
	var FontSize=<%= fontSize %>;
	var FontBold=<% if fontBold then response.write("1") else response.write("0") %>;
	var FontItalic=<% if fontItalic then response.write("1") else response.write("0") %>;
	var MenuTextCentered="left";
	var MenuCentered="<% if frameHorizontal then response.write("left") else response.write("center")%>";
	var MenuVerticalCentered="<% if frameHorizontal then response.write("bottom") else response.write("top") %>";
	var ChildOverlap=.2;
	var ChildVerticalOverlap=.2;
	var StartTop=<%=topPosition%>;
	var StartLeft=<%=leftPosition%>;
	var VerCorrect=0;
	var HorCorrect=0;
	var LeftPaddng=3;
	var TopPaddng=2;
	var FirstLineHorizontal=<% if frameHorizontal then response.write("1") else response.write("0") %>;
	var MenuFramesVertical=<% if frameHorizontal then response.write("0") else response.write("1") %>;
	var DissapearDelay=500;
	var UnfoldDelay=100;
	var TakeOverBgColor=0;
	var FirstLineFrame="<%= frameName %>";
	var SecLineFrame="<%= frameTarget %>";
	var DocTargetFrame="<%= frameTarget %>";
	var TargetLoc="";
	var MenuWrap=0;
	var RightToLeft=0;
	var BottomUp=0;
	var UnfoldsOnClick=0;
	var BaseHref="";
	<% if useArrows then %>
			var Arrws=[BaseHref+"menu/img/tri.gif",5,10,BaseHref+"menu/img/tridown.gif",10,5,BaseHref+"menu/img/trileft.gif",5,10,BaseHref+"menu/img/triup.gif",10,5];
	<% else %>
			var Arrws=[BaseHref+"",5,10,BaseHref+"",10,5,BaseHref+"",5,10,BaseHref+"",10,5];
	<% end if %>		
	var MenuUsesFrames=1;
	var RememberStatus=0;
	var PartOfWindow=1;
	var BuildOnDemand=1;
	var MenuSlide="";
	var MenuShadow="";
	var MenuOpacity="";

	function BeforeStart(){return}
	function AfterBuild(){return}
	function BeforeFirstOpen(){return}
	function AfterCloseAll(){return}

	<%
	'***********************************************************
		MontaNodos	
	'***********************************************************
	%>
	</script>
	<script type='text/javascript' src='menu/menu9_com.js'></script>
	<%
	End Sub
	
	'---------------------------------------------------------------------------------
	Private Sub MontaNodos
		contador = 1
		for i = 0 to indItens - 1
			Visivel(itensMenu(i))
			if MontaLinhas(itensMenu(i), cStr(contador)) then
				contador = contador + 1
			end if	
		next
		if frameHorizontal then
			response.write("Menu"+cStr(contador)+"=new Array('','','',0,20,1000,'','"+lowBgColor+"','','','','',-1,-1,-1,'','');")
			response.write("var NoOffFirstLineMenus="+cStr(contador)+";	// Number of main menu items")
		else
			response.write("var NoOffFirstLineMenus="+cStr(contador-1)+";	// Number of main menu items")
		end if	
	End Sub	
		
	'---------------------------------------------------------------------------------
	Private Function Visivel(refnodo)
		set nodo = refnodo
		if nodo.GetSubItensCount > 0 then
			nodo.visivel = false
			for i = 0 to nodo.GetSubItensCount-1
				ehvisivel = Visivel(nodo.GetSubItem(i))
				if ehvisivel then nodo.numFilhos = nodo.numFilhos + 1
				nodo.visivel = nodo.visivel or ehvisivel
			next
		end if
		Visivel = nodo.visivel
		set nodo = nothing			
	End Function
	
	'---------------------------------------------------------------------------------
	Private Function MontaLinhas(refnodo, nivel)
		set nodo = refnodo
		if nodo.visivel then
			response.write("Menu"+nivel+"=new Array('"+nodo.rotulo+"','"+nodo.href+"','',"+cStr(nodo.numFilhos)+",20,"+cStr(nodo.largura)+",'','','','','','',-1,-1,-1,'','"+nodo.status+"');")
			if nodo.GetSubItensCount > 0 then
				contador = 1
				for i = 0 to nodo.GetSubItensCount-1
					if MontaLinhas(nodo.GetSubItem(i), nivel+"_"+cStr(contador)) then
						contador = contador + 1
					end if	
				next
			end if
			MontaLinhas = true
		end if
	End Function
	
End Class
%>