dim sTableParams 
dim sEscensParams 
Dim ChosenDate
Dim nDia, nMes, nAnnio
dim sParametros, sPeriodKey
dim items
dim bMainMenuAssigned
dim nMenuNumber
dim nLastShownMenu
dim sFuncion 
dim MenuFav
dim idDimPer, sSep
dim sTDMD
dim bIsapi
dim bCenterFlag
dim bCenterTopFlag
dim bShowMenuOnClick
dim nMaxLen
dim nMaxMM
dim nMenus
dim sPersonalizado
Dim nDimActual
dim nDataCount
dim MenuLeft
dim sAcciones
dim bANFCancel
dim favLabel
dim favDelLabel, favOpenLabel, favBatchLabel
dim rowWaiting, bNoWidth, bNoMenu
dim sPrintTableH, sPrintTableB, oNewWindow
dim sFilterstoApply, intIdaAlServer, sParamsPaso
dim nFixMenuX, nFixMenuY, bFixMenu
dim oInterval,sFuncInterval, nTimeInterval

class BITAMMenuItem
   dim label
   dim action
   dim clave
   dim SubOption	' este será un arreglo de tipo BITAMMenuItem si tiene submenúes...
   Dim nMenuNumber
   dim ticked
end class

Class BitamMenu
	dim Clave
	dim Desc
end Class

' Metadata de TD
sub InitializeTDMD
	sTDMD = Array()
	Redim sTDMD(0)
end sub

sub AddTDMD(iCons, sMD)
	dim i
	i = ubound(sTDMD)
	if iCons > i then
		redim preserve sTDMD(iCons)
	end if
	sTDMD(iCons) = sMD
end sub

sub ShowTDFloating(sCons)
	on error resume next
	dim sH, sB 	
	if left(sCons,1) = "P" then	
		sPrintTableH ="TDH" & mid(sCons,2)
		sPrintTableB ="TDB" & mid(sCons,2)
		call ShowInPrintFormat()
	else
		call ShowFloating(sTDMD(cint(sCons)))
	end if
	UnLoadMainMenu	
end sub

sub ShowFloating(sMD)
	UnLoadMainMenu
	call stage(-2, "T," & sMD)
end sub

sub ShowTDChartFloating(sCons)
	on error resume next
	UnLoadMainMenu
	call stage(-2, "T1," & sTDMD(cint(sCons)))
end sub

sub SetTDParams(iCons)
	on error resume next
	sTableParams = ""
	sTableParams = sTDMD(iCons)
end sub

sub ShowInPrintFormat()
	on error resume next
	set oNewWindow = window.open("printtable.htm")		
end sub

sub GetPrintTable
	on error resume next
	call oNewWindow.CT(window.document.all(sPrintTableH), window.document.all(sPrintTableB))
	sPrintTableH = ""
	sPrintTableB = ""
	set oNewWindow = nothing
end sub

sub TCMenu(op)
	on error resume next
	UnLoadMainMenu	
	if mid(op,1,1) = "1" then
		call PrintTC(mid(op,2))
	else
		call ExportToExcel(document.all("DIVTABLA" & mid(op,2)))
	end if
end sub
sub PrintTC(Index)
	sPrintTableH ="TABLAH" & Index
	sPrintTableB ="TABLAB" & Index
	call ShowInPrintFormat()
end sub

' ************************ Exportar a Excell
sub ExportToExcel(oDiv)	
	On Error Resume Next		
	dim sPaso
	sPaso = oDiv.innerhtml
	spaso = replace(sPaso,"<INPUT ","<font ")
	spaso = replace(sPaso,"type=checkbox"," ")
	spaso = replace(sPaso,"</INPUT>","</font>")	
	dim iPosIni, iPosFin, sAux
	iPosIni = instr(sPaso, " TCCols=")
	if iPosIni > 0 then
		sAux    = mid(sPaso, 1, iPosIni)
		iPosFin = instr(iPosIni+10, sPaso, chr(34))
		sAux    = sAux & mid(sPaso, iPosFin+1)	
		sPaso   = sAux
	end if
	
	clipboardData.setData "text", sPaso
		
	Dim objXL,oWorkBook,oSheet
	Set ObjXL = CreateObject("Excel.Application")
	if ObjXL is nothing then
		msgbox "Unable to Open Excel"
		exit sub
	end if
	Set oWorkBook = objXL.Workbooks.Add
    If oWorkBook.Worksheets.Count = 0 Then
        Set oSheet = oWorkBook.Worksheets.Add
    Else
        Set oSheet = oWorkBook.Worksheets(1)
    End If
    oSheet.Visible = False    
    Call oSheet.Paste
    oSheet.Visible = True
    oSheet.Activate
    set oSheet=nothing
    set oWorkBook = nothing
	ObjXL.visible = TRUE
	Set ObjXL = nothing
end sub

' ************************ Filtros Personalizados
sub ShowHideList(oList, oDim)	
	ON ERROR RESUME NEXT	
	if mydiv.name = "Esc" then	
		if PerDiv.style.visibility = "hidden" then
			if oList.style.visibility <> "visible" then
				oList.style.visibility = "visible" 		
			else
				oList.style.visibility = "hidden" 
			end if
		end if
	else
		if PerDiv.style.visibility = "hidden" then
			if oList.style.visibility <> "visible" then
				oList.style.visibility = "visible" 		
				window.document.all(oDim).style.posheight = 150
				window.document.all(oDim).style.zIndex = 1
			else
				oList.style.visibility = "hidden" 
				window.document.all(oDim).style.posheight = 21
			end if
		end if
	end if
end sub

sub SetSep(pSep)
	sSep = pSep
end sub
sub ExecDimension(pDim, sPadre)
	on error resume next
	dim spaso, i
	
	pDim.style.visibility = "hidden"
	if sPadre <> "Same" then
		window.document.all(sPadre).style.posheight = 21
	end if
	window.document.all(pdim.id & "TEXT").innerText = pdim.options(pdim.selectedindex).Text
	if pDim.value = "ShowPerSelect" then	
		spaso = "<select id=PerSelect class=comboStyle onkeydown=""vbscript: AcceptPerDiv"" multiple style=""LEFT: 0px; WIDTH: " & _
				pDim.style.posWidth & "px; POSITION: absolute; TOP: 0px; Height:100px"">" & chr(13)
		for i = 2 to pDim.length -1
			spaso = spaso & "<OPTION value=""" & pDim.options(i).value & """>" & pDim.options(i).Text & "</OPTION>" & chr(13)
		next
		spaso = spaso & "</select>"
		spaso = spaso & "<input  type=submit value=Ok onclick=""vbscript: AcceptPerDivButton 1"""
		spaso = spaso & " style = ""position:absolute;Left:0px;Top=102px;width:" & clng(pDim.style.posWidth*.4) & "px;height:20px"" ></input>"
		spaso = spaso & "<input  type=submit value=Cancel onclick=""vbscript: AcceptPerDivButton 0"""
		spaso = spaso & " style = ""position:absolute;Left:" & clng(pDim.style.posWidth/2) & "px;Top=102px;width:" & _
				clng(pDim.style.posWidth*.4) & "px;height:20px"" ></input>"
		if sPadre <> "Same" then
			idDimPer = window.document.all(sPadre).id
			PerDiv.style.posLeft = window.document.all(sPadre).style.posLeft 
			PerDiv.style.poswidth = window.document.all(sPadre).style.posWidth 
			PerDiv.style.posTop = window.document.all(sPadre).style.posTop + window.document.all(sPadre).style.posheight
		else
			idDimPer = pDim.id
			PerDiv.style.posLeft = pDim.style.posLeft
			PerDiv.style.poswidth = pDim.style.posWidth 			
			PerDiv.style.posTop = pDim.style.posTop + 2			
		end if
		PerDiv.style.posHeight = 130
		PerDiv.innerHTML = spaso
		PerDiv.style.backgroundColor = white
		PerDiv.style.visibility = "visible"
		PerDiv.style.zIndex = 1
		PerSelect.style.zIndex = 1
	else				
		PerDiv.style.visibility = "hidden"								
		if mydiv.name = "Esc" then			
			if trim(pDim.value) <> "" then
				UPDStage pDim.value			
			end if
		end if
	end if
end sub

sub AcceptPerDivButton(bOk)
	on error resume next
	dim sPaso, i, Index
	if bOk=1 then
		sPaso = ""
		if mydiv.name = "Esc" then
			for i = 0 to PerSelect.length - 1
				if PerSelect.options(i).selected then
					if sPaso <>  "" then
						sPaso = sPaso & "_AWDim_"
					end if
					sPaso = sPaso & PerSelect.options(i).value
				end if
			next
			if sPaso <> "" Then
				PerDiv.style.visibility = "hidden"
				UPDStage sPaso
			end if
		elseif mydiv.name = "FILTERFORM" Then
			Index = 0
			Index = cint(mid(idDimPer,4))			
			sPaso = ""
			if index > 0 then
				for i = 0 to PerSelect.length - 1
					if PerSelect.options(i).selected then
						if sPaso <>  "" then
							sPaso = sPaso & sSep
						end if
						sPaso = sPaso & PerSelect.Options(i).value
					end if
				next
				CustomFilter(Index) = sPaso
			end if
			
		end if		
		PerDiv.style.visibility = "hidden"
		idDimPer = ""
	else
		PerDiv.style.visibility = "hidden"
		idDimPer = ""
	end if
end sub


sub AcceptPerDiv
	on error resume next
	dim sPaso, i, Index
	if window.event.keyCode = 13 then
		sPaso = ""
		if mydiv.name = "Esc" then
			for i = 0 to PerSelect.length - 1
				if PerSelect.options(i).selected then
					if sPaso <>  "" then
						sPaso = sPaso & "_AWDim_"
					end if
					sPaso = sPaso & PerSelect.options(i).value
				end if
			next
			if sPaso <> "" Then
				PerDiv.style.visibility = "hidden"
				UPDStage sPaso
			end if
		elseif mydiv.name = "FILTERFORM" Then
			Index = 0
			Index = cint(mid(idDimPer,4))			
			sPaso = ""
			if index > 0 then
				for i = 0 to PerSelect.length - 1
					if PerSelect.options(i).selected then
						if sPaso <>  "" then
							sPaso = sPaso & sSep
						end if
						sPaso = sPaso & PerSelect.Options(i).value
					end if
				next
				CustomFilter(Index) = sPaso
			end if
			
		end if		
		PerDiv.style.visibility = "hidden"
		idDimPer = ""
	elseif  window.event.keyCode = 13 then
		PerDiv.style.visibility = "hidden"
		idDimPer = ""
	end if
end sub

' ************************ Menu Principal
sub InitializeMenuFav
	MenuFav = Array()
	Redim MenuFav(0)
end sub

sub SetFavLabels(aString, aString2, a3, a4)
	favLabel = aString
	favDelLabel = aString2
	favOpenLabel = a3
	favBatchLabel = a4
end sub

sub AddMenuFav(sClave, sDesc)
	dim i
	i = ubound(MenuFav) + 1
	redim preserve MenuFav(i)
	set MenuFav(i) = new BitamMenu
	MenuFav(i).Clave = sClave
	MenuFav(i).Desc = sDesc
end sub

sub DeleteMenuFav(sClave)
	dim i
	for i = 1 to ubound(MenuFav)
		if MenuFav(i).Clave = sClave then
			MenuFav(i).Clave = ""
			exit sub
		end if
	next
end sub

function GetMenuFavArray()
	on error resume next
	GetMenuFavArray=""

	dim i, top, sArray
	top = ubound(MenuFav)
	for i = 1 to top
  		sArray = MenuFav(i).Clave & ":" & MenuFav(i).Desc
		if i<top then
		sArray = sArray & "|"      
		end if
		GetMenuFavArray = GetMenuFavArray & sArray
	next   
end function

sub ShowMainMenu(sMainClaves, sMainDims, sFavText, sDelText, sOpenText, sBatchText)
	on error resume next

	dim sClaves, sDims, i, x, top, y
	if trim(sMainClaves) <> "" then
		sClaves = sMainClaves
		sDims = sMainDims
	else
		sClaves = ""
		sDims = ""
	end if
	' Favoritos
	InitializeMenuFav
	SetFavLabels sFavText, sDelText, sOpenText, sBatchText
	AddMenuFav "-1", "Loading..."
	x = 0
	top = 0
	top = ubound(MenuFav)
	for i = 1 to top
		if trim(MenuFav(i).Clave) <> "" then
			x = x + 1
			if trim(sclaves) <> "" then
				sclaves = sclaves & ","
				sdims = sdims & ","
			end  if
			if x = 1 then
				sClaves = sClaves & " ["
				sdims = sdims & sFavText & "["
				
				sClaves = sClaves & " ["
				sdims = sdims & favOpenLabel & "["
			end if
			sClaves = sClaves & "F" & MenuFav(i).Clave
			sdims = sdims & MenuFav(i).Desc
		end if
	next
	if x > 0 then
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if
	
	' Batch
	if x > 0 then
		sClaves = sClaves & ", ["
		sdims = sdims & "," & favBatchLabel & "["
		for y = 1 to 3
			x = 0
			for i = 1 to top
				if trim(MenuFav(i).Clave) <> "" then
					x = x + 1
					if trim(sclaves) <> "" then
						sclaves = sclaves & ","
						sdims = sdims & ","
					end  if
					if x = 1 then					
						sClaves = sClaves & " ["
						if y = 1 then
							sdims = sdims & "HTML" & "["
						else
							if y = 2 then
								sdims = sdims & "Excel" & "["
							else
								sdims = sdims & "Pocket" & "["
							end if
						end if						
					end if
					sdims = sdims & MenuFav(i).Desc
					sClaves = sClaves & "FB" & y & MenuFav(i).Clave					
				end if
			next
			if x > 0 then
				sClaves = sClaves & "]"
				sdims = sdims & "]"
			end if
		next
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if	
	' Borrar	
	y = 0
	for i = 1 to top
		if trim(MenuFav(i).Clave) <> "" and left(MenuFav(i).desc,3) <> "(P)" and cint(MenuFav(i).Clave) > 0 then
			y = y+1
			if trim(sclaves) <> "" then
				sclaves = sclaves & ","
				sdims = sdims & ","
			end  if
			if y = 1 then
				sClaves = sClaves & " ["
				sdims = sdims & sDelText & "["
			end if
			sClaves = sClaves &  "D" & MenuFav(i).Clave
			sdims = sdims & MenuFav(i).Desc
		end if
	next
	if y > 0 then
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if
	if x > 0 then
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if
	if trim(sclaves) <> "" then
		AddMenu "ExecMainMenu","",sdims,sclaves
	end if
end sub

sub ExecMainMenu(nStage)	
	on error resume next
	if left(nStage,15) = "ShowTreeScsMenu" then		
           call window.parent.sendcommand(-1, nStage & "," & window.event.clientX & "," & window.event.clientY)
           exit sub
        end if

	if trim(nStage) = "" then exit sub	
	call UnLoadMainMenu()
	If left(nStage,2) = "FB" then
		call window.parent.sendcommand(-2, nStage)
	elseIf left(nStage,1) = "F" or  left(nStage,1) = "G" or left(nStage,1) = "W"  or left(nStage,1) = "R" then
		call stage(-2, nStage)	
	elseif left(nStage,1) = "D" then
		call DeleteMenuFav(mid(nStage,2))
		call stage(-2, nStage)
	elseif trim(nstage) = "-4" then
		window.history.back
	elseif trim(nstage) = "A" then
		Call window.open("about.htm")
	elseif nStage = "PDF" or nStage = "PDB" or nStage = "PPT" then		
		call ExportStage(nStage)
	elseif left(nStage,9) = "LANGUAJE=" or left(nStage,18) = "AWDEvent:LANGUAJE=" then
		call UpdStage(nStage)
	elseif left(nStage,1) = "S" then
		call window.close
	elseif left(nStage,1) = "Z" then	
		call window.parent.close
	elseif left(nStage,4) = "HELP" then
		call window.open(nStage & "AWebH.htm")
	elseif nStage = "Adv" then
		openAdvisorDialog
		if not isNull(window.returnValue) then
			call AdvisorEsc(window.returnValue)
		end if
	elseif nStage = "AdE" then
		call stage(-13, "")
	elseif nStage = "PubFav" then
		openPublishANF
		if not isNull(window.returnValue) then
			call FavPublish(window.returnValue)			
		end if				
	elseif nStage = "PubScs" then
		openPublishSCS
		if not isNull(window.returnValue) then
			call ScsPublish(window.returnValue)			
		end if								
	elseif nStage = "-8"  then
		call stage(-8, "")
	elseif nStage = "-17"  then
		call stage(-17, "")
	elseif nStage = "-2" then
		SetNodeEscDefault
		call stage(-1, "AWDEvent:" & sEscensParams)
	elseif nstage = "MOE" then		
		call window.parent.showHideTree
	elseif nstage = "MOH" then		
		call window.parent.showHideHL
	elseif left(nStage,2) = "BP" then	
	    call ExportStage("BOOKPRINTER" & nStage)
	Else
		call ChangeStage(nStage)
	End if
end sub

sub AdvisorEsc(sNewParam)
	document.ScenForm.txtParametros.value  = "Adv"  & sNewParam 
	document.ScenForm.txtNumEsc.value = document.ScenForm.txtEscActual.value
	document.ScenForm.Target = "_self"
	document.ScenForm.submit()
end sub

sub FavPublish(sNewParam)
	document.ScenForm.txtParametros.value  = "FavPub"  & sNewParam 
	document.ScenForm.txtNumEsc.value = document.ScenForm.txtEscActual.value
	document.ScenForm.Target = "_self"
	document.ScenForm.submit()
end sub

sub ScsPublish(sNewParam)
	document.ScenForm.txtParametros.value  = "ScsPub"  & sNewParam 
	document.ScenForm.txtNumEsc.value = document.ScenForm.txtEscActual.value
	document.ScenForm.Target = "_self"
	document.ScenForm.submit()
end sub

' *******************************   INICIO SUBMENUS
Sub CreateMenu(strParam, strDim, strClaves)
	on error resume next
	m0.style.posheight = 0
	m0.style.poswidth = 0
	if not IsEmpty(nLastShownMenu) then
		if nLastShownMenu >= 0 then 
			call UnloadMainMenu()
		end if
	end if	
	window.event.cancelBubble = true
	sParametros = strParam
	nMenuNumber = 0
	nMenus = 0	
    items = CreateMenuArray(strDim, strClaves)
	bMainMenuAssigned = false	
    call CreateMenuDivs(items, 0, 0)    
    call ShowMenu(m0,Nothing)
End Sub

sub AddMenu(strFuncion, strParam, strDim, strClaves)	
	on error resume next	
	sFuncion = strFuncion
	call CreateMenu(strParam, strDim, strClaves)
end sub

Function CreateMenuArray(strDim, strClaves)
    Dim sMenu
    Dim sSubMenu
    Dim sMenuDim
    Dim sSubMenuDim
    Dim sValue
    Dim nPos
    Dim aMenu
    Dim aSubMenu
    Dim vLastChar
    on error resume next
    nPos = 0
    aMenu = Array()
    nMenus = nMenus + 1
    While strClaves <> ""
        Call GetItem(strClaves, sMenu, sSubMenu)
        Call GetItem(strDim, sMenuDim, sSubMenuDim)
        If sMenu <> "" Then			
            ReDim Preserve aMenu(nPos)
            Set aMenu(nPos) = New BITAMMenuItem
            vLastChar = Mid(sMenuDim, Len(sMenuDim), 1)
            If vLastChar = "*" Then
				aMenu(nPos).ticked = true
				aMenu(nPos).label = Mid(sMenuDim, 1, Len(sMenuDim) - 1)
			else
				aMenu(nPos).ticked = false
				aMenu(nPos).label = sMenuDim
			End If
            aMenu(nPos).clave = sMenu
			aMenu(nPos).action = sFuncion
			If sSubMenu <> "" Then
				nMenuNumber = nMenuNumber + 1
				aMenu(nPos).nMenuNumber = nMenuNumber
				aMenu(nPos).SubOption = CreateMenuArray(sSubMenuDim, sSubMenu)
			else
				aMenu(nPos).nMenuNumber = 0
			End If
            nPos = nPos + 1
        End If
    Wend    
    CreateMenuArray = aMenu
End Function

Function GetItem(sAll, sMenu, sSubMenu)
    Dim i, Top 
    Dim nPars
    Dim nFirstPar
    Dim nLastPar
    Dim bFirstParFound
    on error resume next
    nPars = 0
    nFirstPar = 0
    nLastPar = 0    
    If InStr(1, sAll, "[") + InStr(1, sAll, ",") = 0 Then
        sMenu = sAll
        sSubMenu = ""
        sAll = ""        
        Exit Function
    End If
    Top = Len(sAll)
    For i = 1 To Top
        Select Case Mid(sAll, i, 1)
            Case "[":
                If nPars = 0 Then
                    sMenu = Mid(sAll, 1, i - 1)
                    nFirstPar = i
                    bFirstParFound = True
                End If
                nPars = nPars + 1
            Case "]": nPars = nPars - 1
                If nPars = 0 Then nLastPar = i
            Case ",":
                If nPars = 0 Then
                    If bFirstParFound Then
                        sSubMenu = Mid(sAll, nFirstPar + 1, nLastPar - nFirstPar - 1)
                        sAll = Mid(sAll, i + 1)
                    Else
                        sMenu = Mid(sAll, 1, i - 1)
                        sSubMenu = ""
                        sAll = Mid(sAll, i + 1)
                    End If
                    Exit Function
                End If
        End Select
    Next        
    sSubMenu = Mid(sAll, nFirstPar + 1, nLastPar - nFirstPar - 1)
    sAll = ""
End Function
 
Sub CreateMenuDivs(arre,n, nLeft)
	on error resume next
	dim nHeight, NewLeft, nScrollHeight
	bNoWidth = 0
	nMaxLen=0
	nScrollHeight = mybody.scrollheight - 20	
	if not bMainMenuAssigned then				
		m0.innerHTML = ""
		m0.style.overflow = ""
		m0.innerHTML = CreateMenuCode(arre)
		nMaxMM = nMaxLen
		bMainMenuAssigned = true		
		m0.style.position = "absolute"
		m0.style.posleft = nLeft
		call FitToWindow(m0)
		m0.style.posWidth = m0.clientWidth
		NewLeft = NewLeft + m0.style.posWidth
		nHeight = (ubound(arre) * 21) + 20					
		if nHeight <  nScrollHeight or mydiv.name <> "DSS" then
			m0.style.posheight = nHeight
		else
			m0.style.posheight = nScrollHeight
		end if		
		m0.style.overflow = "auto"						
	else
		sNewDiv = "<div id=m" & n & " class=menuskin>"
		set ptrDiv = document.createElement(sNewDiv)
		ptrDiv.innerHTML = CreateMenuCode(arre)		
		
		ptrDiv.style.position = "absolute"
		ptrDiv.style.posleft = nLeft		
				
		
		NewLeft = NewLeft + ptrDiv.style.posWidth
		
		nHeight = (ubound(arre) * 21) + 20							
		if nHeight <  nScrollHeight or mydiv.name <> "DSS"  then
			ptrDiv.style.posheight = nHeight
		else
			ptrDiv.style.posheight = nScrollHeight
		end if		
		
		ptrDiv.style.overflow = "auto"
		
		call mybody.insertAdjacentElement("BeforeEnd", ptrDiv)
		
		call FitToWindow(ptrDiv)
		ptrDiv.style.posWidth = ptrDiv.clientWidth		
	end if
    For i = 0 To UBound(arre)
		If arre(i).nMenuNumber > 0 Then 
			Call CreateMenuDivs(arre(i).SubOption, arre(i).nMenuNumber, NewLeft)
		end if
    Next    
End Sub

sub hidemenu(ptrDiv)
	if ptrDiv is nothing then exit sub
	ptrDiv.style.visibility = "hidden"
	call SetLastShownMenuValue()
end sub

sub SetLastShownMenuValue()
	for i = nMenuNumber to 0 step -1
		on error resume next
		set tmpDiv = Document.all("m" & i)
		if not tmpDiv is nothing then
			if tmpDiv.style.visibility = "visible" then 
				nLastShownMenu = i
				exit sub
			end if
		end if
	next
end sub

sub row_mouseover(whichRow)
	on error resume next		
	whichRow.className="optionOn"
	
	set thisDiv = whichRow.parentElement.parentElement.parentElement
	nCurMenuNr = CInt(Mid(thisDiv.id, 2))		
	for i = nCurMenuNr + 1 to nMenuNumber
		'set whichOne = Document.All("m" & i)
		Document.All("m" & i).style.visibility = "hidden"
		'call hidemenu(whichOne)
	next
	nLastShownMenu = nCurMenuNr
	
	if whichRow.menutodisplay <> "" then
		if trim(whichRow.innerText) = favLabel then
			dim menuLoaded
			menuLoaded = whichRow.getAttribute("MenuLoaded")
			if isNull(menuLoaded) then
				menuLoaded = "false"
			end if
			if menuLoaded <> "true" then
				set rowWaiting = whichRow
				iFrameFav.window.document.forms.FAVForm.txtParametros.value = "GETFAVORITES"
				iFrameFav.window.document.forms.FAVForm.submit()
			end if
		end if
		set currentmenu = nothing		
		set currentMenu = mybody.all(whichRow.menutodisplay)
		if not currentmenu is nothing then
			if currentMenu.style.visibility = "visible" then exit sub
			call ShowMenu(currentMenu,whichRow)
		end if
	end if
end sub

sub LoadedFav()
	on error resume next
	if IsEmpty(rowWaiting) then exit sub
	dim sClaves, sDims, x, y, top, items, currentMenu, newFav, nHeight
	newFav = iFrameFav.getFavorites
	InitializeMenuFav
	for i=0 to ubound(newFav)
		call AddMenuFav(newFav(i)(0), newFav(i)(1))
	next
	sClaves = ""
	sDims = ""
	x = 0
	top = 0
	top = ubound(MenuFav)
	for i = 1 to top
		if trim(MenuFav(i).Clave) <> "" then
			x = x+1
			if trim(sclaves) <> "" then
				sclaves = sclaves & ","
				sdims = sdims & ","
			end  if			
			if x = 1 then
				sClaves = sClaves & " ["
				sdims = sdims & favOpenLabel & "["
			end if
			sClaves = sClaves & "F" & MenuFav(i).Clave
			sdims = sdims & MenuFav(i).Desc
		end if
	next
	if x > 0 then
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if	
	
	' Batch
	if x > 0 then
		sClaves = sClaves & ", ["
		sdims = sdims & "," & favBatchLabel & "["
		for y = 1 to 3
			x = 0
			for i = 1 to top
				if trim(MenuFav(i).Clave) <> "" then
					x = x + 1
					if trim(sclaves) <> "" then
						sclaves = sclaves & ","
						sdims = sdims & ","
					end  if
					if x = 1 then					
						sClaves = sClaves & " ["
						if y = 1 then
							sdims = sdims & "HTML" & "["
						else
							if y = 2 then
								sdims = sdims & "Excel" & "["
							else
								sdims = sdims & "Pocket" & "["
							end if
						end if
					end if					
					sdims = sdims & MenuFav(i).Desc
					sClaves = sClaves & "FB" & y & MenuFav(i).Clave					
				end if
			next
			if x > 0 then
				sClaves = sClaves & "]"
				sdims = sdims & "]"
			end if
		next
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if	
	' Borrar
	y = 0
	for i = 1 to top
		if trim(MenuFav(i).Clave) <> "" and left(MenuFav(i).desc,3) <> "(P)" and cint(MenuFav(i).Clave) > 0 then
			y = y+1
			if trim(sclaves) <> "" then
				sclaves = sclaves & ","
				sdims = sdims & ","
			end  if
			if y = 1 then
				sClaves = sClaves & " ["
				sdims = sdims & favDelLabel & "["
			end if
			sClaves = sClaves &  "D" & MenuFav(i).Clave
			sdims = sdims & MenuFav(i).Desc
		end if
	next
	if y > 0 then
		sClaves = sClaves & "]"
		sdims = sdims & "]"
	end if	
	items = CreateMenuArray(sdims, sClaves)
	For i = 0 To UBound(items)
		If items(i).nMenuNumber > 0 Then 
			Call CreateMenuDivs(items(i).SubOption, items(i).nMenuNumber,0)
		end if
    Next
    
    call rowWaiting.setAttribute("MenuLoaded", "true")
    
    set currentmenu = nothing 
    set currentMenu = mybody.all(rowWaiting.menutodisplay)
    if not currentmenu is nothing then		
		currentMenu.innerHTML = CreateMenuCode(items)				
		
		currentMenu.style.position = "absolute"					
		currentMenu.style.overflow = ""			
		
		nHeight = (ubound(items) * 21) + 20							
		if nHeight <  mybody.scrollheight - 20 then
			currentMenu.style.posheight = nHeight
		else
			currentMenu.style.posheight = mybody.scrollheight -20		
		end if	
		
		
		call FitToWindow(currentMenu)				
		
		currentMenu.style.posWidth = currentMenu.clientWidth + 3
		
		currentMenu.style.overflow = "auto"		
		if currentMenu.style.visibility = "visible" then exit sub				
		call ShowMenu(currentMenu,whichRow)				
	end if
end sub

function CreateMenuCode(arre)	
	' retrieve the max string lenght in this options
	bSubs = false
	nMaxLen = 0
	for i=0 to ubound(arre)
		if arre(i).nMenuNumber > 0 then bSubs = true
		if len(arre(i).label) > nMaxLen then nMaxLen = len(arre(i).label)
	next
	if bSubs then
		nMaxLen = nMaxLen + 10	' un espacio antes de la flecha
	end if	
	
	stringOptions ="<table id=menutable cellpadding=0px cellspacing=0px class=menuborderstyle>"	
	for i=0 to ubound(arre)
		stringOptions = stringOptions & "<tr height=""16px"" "
        if arre(i).nMenuNumber = 0 then
			stringOptions = stringOptions & "menutodisplay="""""
		else
			stringOptions = stringOptions & "menutodisplay=m" & arre(i).nMenuNumber
		end if
		stringOptions = stringOptions & " class=optionOff onmouseover=""vbscript:row_mouseover me"" onmouseout=""vbscript:me.className='optionOff'"""		
		stringOptions = stringOptions & " onclick=""vbscript:" & arre(i).action & " '" & arre(i).clave & "'"">"
		
		stringOptions = stringOptions & "<td width=""11px"">"
		if arre(i).ticked then
			stringOptions = stringOptions & "<img src=tick.gif align=middle></img>"
		end if
		
		stringOptions = stringOptions & "</td><td>"
		stringOptions = stringOptions & FillWithSpaces(arre(i).label,nMaxLen)
		if arre(i).nMenuNumber > 0 then 
			stringOptions = stringOptions & "</td><td width=""10px""><img src=newoption.gif align=middle></img>"
		else
			stringOptions = stringOptions & "</td><td width=""10px"">&nbsp;"
		end if
		stringOptions = stringOptions & "</td></tr>"
	next  
	stringOptions = stringOptions & "</table>"
	CreateMenuCode = stringOptions	
end function

function FillWithSpaces(strx,n)
	for i = len(strx) to n
		strx = strx & chr(32)
	next
	FillWithSpaces = "&nbsp;" &  strx
end function

sub SetCenterFlag	
	bCenterFlag = 1
end sub
sub ResetCenterFlag
	bCenterFlag = 0
end sub

sub SetCenterTopFlag
	bCenterTopFlag = 1
end sub

sub ResetCenterTopFlag
	bCenterTopFlag = 0
end sub

sub SetShowMenuOnClick
	bShowMenuOnClick = 1
end sub

sub ResetShowMenuOnClick
	bShowMenuOnClick = 0
end sub

sub ShowMenu(ptrDiv,ptrParent)
	on error resume next
	dim nCenter, nScrollHeight
	nScrollHeight = mybody.scrollheight	- 20		
	if ptrParent is nothing then			
		if bCenterTopFlag = 1 then
			nCenter = ((mybody.clientwidth-mybody.clientLeft)/2) - 200			
			if nCenter < 0 then
				nCenter  = 0			
			end if
			nCenter = nCenter +  mybody.scrollLeft
			ptrDiv.style.posLeft = nCenter 
			ptrDiv.style.posTop = window.event.clientY + mybody.scrollTop
			bCenterTopFlag = 0
			bCenterFlag = 0
			if mydiv.name = "DSS" then
				ptrDiv.style.overflow = ""
				ptrDiv.style.height = ""
				ptrDiv.style.width = ""
			end if
		elseif bFixMenu = 1 then
			ptrDiv.style.posLeft = nFixMenuX + mybody.scrollLeft 
			ptrDiv.style.posTop = nFixMenuY + mybody.scrollTop			
			bFixMenu = 0
			if mydiv.name = "DSS" then
				ptrDiv.style.overflow = ""
				ptrDiv.style.height = ""
				ptrDiv.style.width = ""
			end if
		elseif bShowMenuOnClick = 1 then			
			ptrDiv.style.posLeft = window.event.clientX + mybody.scrollLeft 
			ptrDiv.style.posTop = window.event.clientY + mybody.scrollTop			
			bShowMenuOnClick = 0
			if mydiv.name = "DSS" then
				ptrDiv.style.overflow = ""
				ptrDiv.style.height = ""
				ptrDiv.style.width = ""
			end if
		elseif mydiv.name = "Esc" or bCenterFlag = 1 then				
			nCenter = ((mybody.clientwidth-mybody.clientLeft)/2) - 200			
			if nCenter < 0 then
				nCenter  = 0			
			end if
			nCenter = nCenter +  mybody.scrollLeft
			ptrDiv.style.posLeft = nCenter 
			
			nCenter = ((mybody.clientHeight-mybody.clientTop)/2) - 75
			if nCenter < 0 then
				nCenter = 0			
			end if			
			nCenter = nCenter +  mybody.scrollTop
			ptrDiv.style.posTop = nCenter
			bCenterFlag = 0
			if mydiv.name = "DSS" then
				ptrDiv.style.overflow = ""
				ptrDiv.style.height = ""
				ptrDiv.style.width = ""
			end if
		else	
			ptrDiv.style.posLeft = window.event.clientX + mybody.scrollLeft 								
			if mydiv.name = "DSS" then								
				if MenuLeft > 0 then
					ptrDiv.style.posLeft = MenuLeft		
					ptrDiv.style.posTop = 0
					MenuLeft = 0
				end if													
			end if			
			ptrDiv.style.posTop = window.event.clientY + mybody.scrollTop
		end if						
		
		if ptrDiv.style.posHeight > nScrollHeight  then
			ptrDiv.style.posTop = mybody.scrollTop
			ptrDiv.style.posHeight = nScrollHeight 
		elseif  ptrDiv.style.posHeight + ptrDiv.style.posTop > nScrollHeight then
			ptrDiv.style.posTop = ptrDiv.style.posTop - (ptrDiv.style.posHeight + ptrDiv.style.posTop - nScrollHeight)
		end if
	else		
		set tmpDiv = Document.all("m" & nLastShownMenu)		
		ptrDiv.style.posLeft = tmpDiv.style.posLeft + tmpDiv.clientWidth						
		if mydiv.name = "DSS"  then									
			'nCenter = tmpDiv.style.posTop + ptrParent.offsetTop	+ ptrDiv.style.posHeight + 20			
			'nCenter = mybody.scrollheight - nCenter
			'if nCenter < 0 then
			'	if (tmpDiv.style.posTop + ptrParent.offsetTop) + nCenter < 0 then
			'		ptrDiv.style.posTop = 0
			'	else
		    '		ptrDiv.style.posTop = tmpDiv.style.posTop + ptrParent.offsetTop + nCenter
			'	end if
			'else				
				ptrDiv.style.posTop = tmpDiv.style.posTop + ptrParent.offsetTop - tmpDiv.scrollTop				
				x = mybody.clientHeight - ptrDiv.style.posTop - ptrDiv.style.posHeight
				if x < 0 then
					if ptrDiv.style.posHeight > mybody.clientHeight then
						ptrDiv.style.posTop = 0
					else
						ptrDiv.style.posTop = mybody.clientHeight - ptrDiv.style.posHeight
					end if
				end if
			'end if
		else			 				
			ptrDiv.style.posTop = tmpDiv.style.posTop + ptrParent.offsetTop	
		end if								
		'if ptrDiv.style.posheight > ptrDiv.clientHeight then				
		'	ptrDiv.style.posWidth = ptrDiv.clientWidth + 20		
		'end if		
	end if	
	
	nLastShownMenu = CInt(Mid(ptrDiv.id,2))
	ptrDiv.style.visibility = "visible" 
end sub

sub BodyResize()
	if IsEmpty(nLastShownMenu) then exit sub
	if nLastShownMenu >= 0 then
		for i = 0 to nLastShownMenu
			set tmpDiv = Document.all("m" & i)
			if not tmpDiv is nothing then
				call FitIntoWindow(tmpDiv)
			end if
		next
	end if
end sub

sub bodyClick(e)
	on error resume next
	dim sElem
	sElem = typename(e.srcElement) 
	if sElem = "HTMLBody" or (mydiv.name = "DSS" and sElem = "HTMLDivElement" ) then
		call HideMenus
	end if
end sub

sub HideMenus()
	on error resume next
	
	do while  nLastShownMenu > 0 		
		on error resume next
		set ptrDiv = nothing
		set ptrDiv = Document.all("m" & nLastShownMenu)
		if not ptrDiv is nothing then 
			call hidemenu(ptrDiv)
		else
			exit do
		end if			
	loop	
	call UnloadMainMenu()
	if calendarDiv.style.visibility = "visible"  then
		call HideCalendar()	
	end if
	if PerDiv.style.visibility = "visible" then
		PerDiv.style.visibility = "hidden"
	end if
end sub

sub bodyKeyDown(e)
	on error resume next
	mykey = e.keyCode
	if mykey = 27 then
		call HideMenus
	end if
end sub

sub UnloadMainMenu()
	' menú principal
	if IsEmpty(nLastShownMenu) then exit sub
	if nLastShownMenu < 0 then exit sub
	' resto de los menús
	i = nMenuNumber
	do while i >= 1
		set ptrDiv = Document.all("m" & i)
		if not ptrDiv is nothing then
			call hidemenu(ptrDiv)
			call ptrDiv.removeNode(true)
		end if 
		i = i - 1
	loop
	m0.innerHTML = ""
	call hidemenu(m0)
	call ClearMenuStruct(items)
	nLastShownMenu = -1	
end sub 

Sub ClearMenuStruct(arre)
    For i = 0 To UBound(arre)
        If IsArray(arre(i).SubOption) Then Call ClearMenuStruct(arre(i).SubOption)
        Set arre(i) = Nothing
    Next
End Sub

' *******************************   FIN SUBMENUS
function GetTableMinWidth(nWidth)
	If nWidth < 585 Then 
		GetTableMinWidth = 585
	else
		GetTableMinWidth =nWidth
	end if
end function

function GetTableMinWidthDIP(nWidth)
	If nWidth < 650 Then 
		GetTableMinWidth = 650
	else
		GetTableMinWidth =nWidth
	end if
end function

function GetGraphMinWidth(nWidth)
	If nWidth < 680 Then 
		GetGraphMinWidth = 680
	else
		GetGraphMinWidth =nWidth
	end if	
end function

sub PositionWindow(Width, Height)
	if Height < 270 then
		Height = 270
	end if
	Call window.resizeTo(Width ,Height)
end sub

sub setTableParams(sParams)
	sTableParams = sParams
end sub

sub setEscensParams(sParams)	
	on error resume next
	sEscensParams = sParams
	sFilterstoApply = ""	
end sub

sub GetArtusHelpPage()
	Call window.open("www.bitam.com")	
end sub

sub GetDSSHelpPage()
	Call window.open("www.bitam.com")	
end sub

' ***************** ANF

sub Drilldown(clave)	
	if trim(clave) <> "" then		
		if left(clave,1) <> "T" and left(clave,1) <> "A" then
			call UnLoadMainMenu()
			sParametros = "DSSxDIM" & "," & clave & "," & sParametros
			call Stage(-3, sParametros)	
		end if
	end if
end sub

sub DrilldownM(clave)
	if left(clave,1) <> "T" then
		call UnLoadMainMenu()
		sParametros = "DSSxDIM" & "," & clave & "," & sParametros
		call Stage(-11, sParametros)
		bNoMenu = 0
	end if
end sub

sub DrilldownTC(clave)
	if left(clave,1) <> "T" then
		call UnLoadMainMenu()
		sParametros = "DDTC" & "," & clave & "," & sParametros
		call Stage(-3, sParametros)	
	end if
end sub

sub AddColParam(clave)
	on error resume next	
	sPaso = "DSSADD" 
	if difH <> 0 then
		sPaso= sPaso & ",HW," & window.mybody.scrollHeight + difH & "," & _
				window.mybody.scrollWidth + difW	
	end if			
	if sAcciones <> "" then
		sPaso = sPaso & ",AC," & sAcciones
	end if	
	sParametros=GetSelectedRows
	if sParametros <> "" then
		sPaso = sPaso & ",PARAM," & sParametros & "_AWSep_"
	else
		sPaso = sPaso & ","
	end if
	sPaso= sPaso & clave &  "," & sTableParams	
	call Stage(-3, sPaso)	
end sub

sub AddCol(clave)
	on error resume next
	
	call UnloadMainMenu
	if left(clave,10) = "SHOWPERFIL" then
		call showCustomFilter(mid(clave,11))
	elseif left(clave,8) = "ANFTREND" then
		call ANFTrendSub(mid(clave,9))			
	elseif left(clave,9) = "DUPLICATE" then		
		call Stage(-2,sTableParams)		
	elseif left(clave,10) = "EDITCALCOL" then
		call EditCalcColumn(clave)
	elseif left(clave,1) = "Y" then
		if sAcciones <> "" then 
			sAcciones = sAcciones & ":" & clave
		else
			sAcciones = clave		
		end if
	elseif left(clave,7) = "COLPER_" then
		call SHOWCOLPER(mid(clave,8))	
	elseif left(clave,7) = "DIMALA_" then
		call SHOWDIMALARM(mid(clave,8))	
	elseif left(clave,7) = "ORDENAV" then
		CALL EASAdvSort
	elseif left(clave,8) = "STRATEGO" then
		CALL ADDSTRATEGO(Clave)	
	elseif left(clave,9) = "DESCRANGE" then
		call DimDescRange(mid(clave,10))
	elseif trim(clave) <> "" then
		dim sPaso
		if left(clave, 8) = "PropDin_" then
			openPropDinDialog(mid(clave,9))
			if not isNull(window.returnValue) then
				clave = clave & "," & window.returnValue & "@PropDin@"
			else
				exit sub
			end if		
		elseif clave = "M3" then 
			'Titulo para la grafica
			openAskChartTitle
			if not isNull(window.returnValue) then
				clave = clave & "," & window.returnValue & "@Title@"
			else
				exit sub
			end if								
		elseif clave = "M11_2" then 
			'Escala Manual, pedir valores
			openAskParameters
			if not isNull(window.returnValue) then
				clave = clave & "," & window.returnValue & "@ScaleManual@"
			else
				exit sub
			end if					
		end if
				
		if mydiv.name = "DSS" then
			sPaso = "DSSADD" 
			if difH <> 0 then
				sPaso= sPaso & ",HW," & window.mybody.scrollHeight + difH & "," & _
						window.mybody.scrollWidth + difW	
			end if			
			if sAcciones <> "" then
				sPaso = sPaso & ",AC," & sAcciones
			end if
			sPaso= sPaso & "," & clave  & "," & sTableParams			
		else
			sPaso = "DSSADD" & "," & clave & "," & sTableParams
		end if		
		call Stage(-3, sPaso)	
	end if
end sub

sub RowNav(sParam)
	if trim(sParam) <> "" then
		if left(sParam,1) <> "T" and left(sParam,1) <> "A" then
			dim sPaso
			call UnloadMainMenu
			if trim(sTableParams) <> "" then
				sPaso = "ROWNAV" 
				if difH <> 0 then
					sPaso= sPaso & ",HW," & window.mybody.scrollHeight + difH & "," & _
									window.mybody.scrollWidth + difW						
				end if		
				sPaso= sPaso & "," & sParam  & "|" & sParametros & "_AWSep_" & sTableParams
			end if			
			call Stage(-3, sPaso)
		end if
	else
		call UnloadMainMenu
	end if
end sub

sub RowNavM(sParam)
	if trim(sParam) <> "" then
		if left(sParam,1) <> "T" and left(sParam,1) <> "A" then
			dim sPaso
			call UnloadMainMenu
			if trim(sTableParams) <> "" then
				sPaso = "ROWNAV" 
				if difH <> 0 then
					sPaso= sPaso & ",HW," & window.mybody.scrollHeight + difH & "," & _
									window.mybody.scrollWidth + difW						
				end if		
				sPaso= sPaso & "," & sParam  & "|" & sParametros & "_AWSep_" & sTableParams
			end if			
			call Stage(-11, sPaso)
			bNoMenu = 0
		end if
	else
		call UnloadMainMenu
	end if
end sub
	
sub SaveANF(sName)
	dim sPaso
	call UnloadMainMenu
	IF trim(sTableParams) <> "" then
		sPaso = "SAVEANF" & "," & sName & "|" & sTableParams
		call Stage(-3, sPaso)
	end if
end sub 

sub SaveAdvisorANF(sName, sAdvisorInf)
	dim sPaso
	call UnloadMainMenu
	IF trim(sTableParams) <> "" then
		sPaso = "SAVEANF" & "," & sName & "|" & sTableParams & "_@ADVISORINF@_" & sAdvisorInf
		call Stage(-3, sPaso)
	end if
end sub 

sub Filter(sNiveles, sWhere)
	dim sPaso
	sPaso = "FILTER," & sniveles & "_AWSep_" & sWhere & "_AWSep_" & sTableParams
	call Stage(-3, sPaso)
end sub

sub AddCalCol(Cons, sTipo, sNombre, sFormula, sFormato)
	dim sPaso
	sPaso = "CALCOL," & Cons & "," & sTipo & "," & sNombre & "_AWSep_" & sFormula & "_AWSep_" & sFormato & "_AWSep_" & sTableParams
	call Stage(-3, sPaso)
end sub 

sub EditCol( Cons, sMD )	
	call Stage(-3, "EDITCOL," & Cons & "," & sMD & "_AWSep_" & sTableParams)
end sub

' ****************** Cambios de Escenario
' Filtros de Dimension Capturables
sub CaptureKeyDim( sKey, sValue)
	on error resume next	
	dim sPaso
	if window.event.keyCode = 13 then
		sPaso = ""
		sPaso = sValue
		if sPaso <> "" then
			sPaso = sKey & sValue
			call UpdStage(sPaso)
		else
			sPaso = sKey & "ArtusRemoveParam"
			call UpdStage(sPaso)
		end if
	end if
end sub
' Celdas What If
sub ExecWhatIf( sKey, sValue)
	on error resume next	
	dim sPaso
	if window.event.keyCode = 13 then
		sPaso = ""
		sPaso = trim(sValue)
		if sPaso <> "" then
			sPaso = sKey & sValue
			call UpdStage(sPaso)
		end if
	end if
end sub

sub ChangeStage(nStage)
	call stage(nStage, sEscensParams)
end sub

sub UpdStage(sNewParam)	
	dim sParams 	
	sParams = GetParamsforUpd
	if trim(sParams) <> "" then
		document.ScenForm.txtParametros.value  = sNewParam & "_AWSep_" & sParams
	else
		document.ScenForm.txtParametros.value  = sNewParam
	end if
	document.ScenForm.txtNumEsc.value = document.ScenForm.txtEscActual.value
	document.ScenForm.Target = "_self"	
	document.ScenForm.submit()	
end sub

sub UpdChangeStage(nStage, sNewParam)
	dim sParams 
	sParams = GetParamsforUpd
	if trim(sParams) <> "" then
		document.ScenForm.txtParametros.value  = sNewParam & "_AWSep_" & sParams
	else
		document.ScenForm.txtParametros.value  = sNewParam
	end if
	document.ScenForm.txtNumEsc.value = nStage
	document.ScenForm.Target = "_self"	
	document.ScenForm.submit()
end sub

sub UpdStageFromTD(nStage, sNewParam)
	on error resume next
	bNoMenu = 1
	call UpdChangeStage(nStage, sNewParam)
end sub

sub GetFavFromTD(sMD)
	bNoMenu = 1
	call Stage(-2, sMD)
end sub

sub ANFCancel()
	call Stage(-3, "CANCELANF")
end sub

sub Stage(nStage, strParametros) 
    Dim x, y    
    on error resume next            
    if not IsEmpty(oInterval) then
		call window.clearInterval(oInterval)
		oInterval = window.setInterval(sFuncInterval, nTimeInterval)
	end if
    call UnLoadMainMenu()    
    document.ScenForm.txtNumEsc.value = nStage
    document.ScenForm.txtParametros.value = strParametros            
    if mydiv.name = "NewDSS" then		
		document.ScenForm.Target = "_self"
	elseif mydiv.name = "ChangePwd" or mydiv.name = "OPENANF" then
		document.ScenForm.Target = "_self"
    elseif (mydiv.name = "Esc"  and  nstage = -3 )  or nstage = -2 or nstage = -8 or _
		nStage = -11 or nStage = -13  or nStage = -17  or nstage = -15 or nStage = -23 then
		x = Now
		y  = "mywindow"
		y = y & CStr(Hour(x)) & CStr(Minute(x)) & CStr(Second(x))		
		document.ScenForm.txtParametros.value = "FRAME" & strParametros		
		if nStage = -15 then
			Call window.open(loadingpage, y, "menubar=no,toolbar=no,status=no,resizable=yes,scrollbars=yes",1)
		else			
			Call window.open(loadingpage, y, "menubar=no,toolbar=no,status=no,resizable=yes,scrollbars=no",1)
		end if
		document.ScenForm.Target = y
		if nStage = -11 or nStage = -13 then
			bNoMenu = 1
		end if
	elseif mydiv.name = "DSS" then
		if strParametros = "CANCELANF" then
			window.parent.HideANFCancel
		else
			if bANFCancel <> 1 then
				bANFCancel = 1
				window.parent.ShowANFCancel
			else
				exit sub
			end if			
		end if		
		document.ScenForm.Target = "_self"		
	else
		document.ScenForm.Target = "_self"
	end if	
    document.ScenForm.submit()    
end sub

sub settimerbanners()
   call window.setInterval("execbanners", 3000,"vbscript")
end sub

sub SetChosenDate(nNewDay)
	call HideCalendar()
	if len(nMes) = 1 then nMes = "0" & nMes
	if nNewDay = "" then nNewDay = nDia
	if len(nNewDay) = 1 then nNewDay = "0" & nNewDay
	ChosenDate = nAnnio & nMes & nNewDay	
	
	if (mydiv <> Empty) then
		if mydiv.name = "Esc" then
			sparametros = sparametros & sPeriodKey & ChosenDate 
			call UpdStage(sparametros)
		elseif mydiv.name = "NewDSS" then
			dfPeriodo.innerText = nAnnio & "-" & nMes & "-" & nNewDay
		else
			sparametros = "DSSADD" & ",P" & ChosenDate  & "," & sTableParams
			call Stage(-3, sparametros)
		end if
	else
		call datesDiv.all(datesDiv.AWFieldName).setAttribute("realDate", ChosenDate)
		datesDiv.all(datesDiv.AWFieldName).value = formatDate(ChosenDate)
	end if
end sub

sub HideCalendar()
	ChosenDate = ""
	calendarDiv.innerHTML = ""
	calendarDiv.style.visibility = "hidden"
	if mydiv <> Empty then
		if mydiv.name = "NewDSS" then
			call RemoveCalendar
		end if
	end if
end sub

sub BuildCalendar(theDate, pPeriodKey, sParam, Top, Middle)	' theDate must be: YYYYMMDD
	Dim dFechaActual, nDiaSemana, nContDia
	Dim diasMes
	Dim sCalendarCode
	' Inicializo los parametros
	if Top <> -1 then
		sParametros = sParam
		sPeriodKey = pPeriodKey
	end if
	
	' limpiar el código anterior
	ChosenDate = ""
	calendarDiv.innerHTML = ""
	
	diasMes = Array(31,28,31,30,31,30,31,31,30,31,30,31)
	' convertir la fecha
	theDate = Trim(theDate)
	select case theDate
		case "":
			dFechaActual = Date()
		case "b":
			if nMes = 1 then 
				nMes = 12
				nAnnio = nAnnio - 1
			else 
				nMes = nMes - 1
			end if
			dFechaActual = DateSerial(nAnnio, nMes, nDia)
			do while nMes <> Month(dFechaActual)
				nDia = nDia -1
				dFechaActual = DateSerial(nAnnio, nMes, nDia)
			loop
		case "c"
			nAnnio = nAnnio - 1
			dFechaActual = DateSerial(nAnnio, nMes, nDia)
			do while nMes <> Month(dFechaActual)
				nDia = nDia -1
				dFechaActual = DateSerial(nAnnio, nMes, nDia)
			loop
		case "g"
			nAnnio = nAnnio + 1
			dFechaActual = DateSerial(nAnnio, nMes, nDia)
			do while nMes <> Month(dFechaActual)
				nDia = nDia -1
				dFechaActual = DateSerial(nAnnio, nMes, nDia)
			loop
		case "f":
			if nMes = 12 then 
				nMes = 1
				nAnnio = nAnnio + 1
			else 
				nMes = nMes + 1
			end if
			dFechaActual = DateSerial(nAnnio, nMes, nDia)
			do while nMes <> Month(dFechaActual)
				nDia = nDia -1
				dFechaActual = DateSerial(nAnnio, nMes, nDia)
			loop
		case else
			dFechaActual = DateSerial(mid(theDate,1,4), mid(theDate,5,2), mid(theDate,7,2))
	end select
	nDia = Day(dFechaActual)
	nMes = Month(dFechaActual)
	nAnnio = Year(dFechaActual)

	' año bisiesto?
	if ((nAnnio mod 400 = 0) or ((nAnnio mod 4 = 0) and (nAnnio mod 100 <> 0))) then diasMes(1) = 29

	' ver qué día de la semana es el primero del mes
	nContDia = 1	
	nDiaSemana = WeekDay(DateSerial(nAnnio,nMes,nContDia),0)

	' contruir el calendario
	sCalendarCode = "<table cellspacing=0px cellpadding=0px class=calendarBorderStyle><tr class=calendarHead>" & _
					"<th class=manita title=""Last Year"" " & _
					"onclick=""vbscript:BuildCalendar 'c','','',-1,0" & _
					"""><img src=""arrowsleft.gif""></img></th>" & _
					"<th class=manita title=""Last month"" " & _
					"onclick=""vbscript:BuildCalendar 'b','','',-1,0" & _
					"""><img src=""arrowleft.gif""></img></th>" & _
					"<th colspan=3 align=center>" & _
					MonthName(nMes) & " " & nAnnio & "</th>" & _
					"<th class=manita title=""Next month""" & _
					"onclick=""vbscript:BuildCalendar 'f','','',-1,0" & _
					"""><img src=""arrowright.gif""></img></th>" & _
					"<th class=manita title=""Next Year""" & _
					"onclick=""vbscript:BuildCalendar 'g','','',-1,0" & _
					"""><img src=""arrowsright.gif""></img></th>" & _
					"</tr>" & vbCrLf
	sCalendarCode = sCalendarCode & "<tr class=calendarHead>"
	for i = 1 to 7		
		sCalendarCode = sCalendarCode & "<th>" & WeekDayName(i,true,0) & "</th>"
	next
	sCalendarCode = sCalendarCode & "</tr>" & vbCrLf

	for i = 0 to 5 
		sCalendarCode = sCalendarCode & "<tr height=10px;>" & vbCrLf
		for j = 0 to 6
			if (i = 0 and j < nDiaSemana - 1) or (nContDia > diasMes(nMes-1)) then
				sCalendarCode = sCalendarCode & "<td width=14.28%><br></td>" & vbCrLf
			else
				sCalendarCode = sCalendarCode & "<td width=14.28% "
				if nContDia = nDia then
					sCalendarCode = sCalendarCode & "class=calendarToday"
				else
					sCalendarCode = sCalendarCode & "class=calendarOtherDay"
				end if
				sCalendarCode = sCalendarCode & " onclick=""vbscript:SetChosenDate(me.innerHTML)"">" & nContDia & "</td>" & vbCrLf
				nContDia = nContDia + 1
			end if
		next
		sCalendarCode = sCalendarCode & "</tr>" & vbCrLf
		if nContDia > diasMes(nMes-1) then i = 5
	next
	sCalendarCode = sCalendarCode & "</table>" & vbCrLf
	
	calendarDiv.innerHTML = sCalendarCode
	if Top <> -1 then
		calendarDiv.style.position = "absolute"
		calendarDiv.style.posTop = top
		if middle -106 < 0 then
			calendarDiv.style.posleft = 0
		else
			calendarDiv.style.posleft = middle -106
		end if
		calendarDiv.style.visibility = "visible"
	end if
end sub

' Funciones de Combos de Datos

sub UCDA(nDim)
	if document.all("DataAll" & nDim).checked then
		document.all("DataAll" & nDim).checked = False
	end if
end sub

sub UCDAOne(nDim, nValCheck)
	dim i
	for i = 1 to nDataCount
		if i <> nValCheck then
			document.all("Data" & nDim & "_" & i).checked = false
		else
			document.all("Data" & nDim & "_" & i).checked = true
		end if
	next	
end sub

sub DataAllClick(nDim)
	if document.all("DataAll" & nDim).checked then
		call UnCheckData(nDim)
	end if
end sub
sub UnCheckData(nDim)
	dim i
	document.all("DataAll" & nDim).checked = True
	for i = 1 to nDataCount
		document.all("Data" & nDim & "_" & i).checked = False
	next
end sub
sub CheckAll(nDim)
	dim i
	document.all("DataAll" & nDim).checked = False
	for i = 1 to nDataCount
		document.all("Data" & nDim & "_" & i).checked = true
	next
end sub

sub HideDataDiv(nDim)
	on error resume next
	document.all("DataDiv" & nDim).style.visibility = "hidden"
end sub

sub SaveDataDiv(nDim)
	dim i, sWherePaso, nCount, nChecked	
	if document.all("DataAll" & nDim).checked then		
		CustomFilter(nDim)= ""
		if Ucase(typename(document.all("Dim" & nDim))) <> "HTMLIFRAME" then
			document.all("Dim" & nDim).innerText = document.all("DataFAll" & nDim).innerText
		else
			document.frames("Dim" & nDim).Dim1.innerText = document.all("DataFAll" & nDim).innerText
		end if
	else
		sWherePaso = ""
		nCount = 0
		for i = 1 to nDataCount
			if document.all("Data" & nDim & "_" & i).checked then
				nCount = nCount + 1
				if nCount = 1 then
					sWherePaso = document.all("Data" & nDim & "_" & i).Value 
					nChecked = i
				else
					sWherePaso = sWherePaso & sSep & document.all("Data" & nDim & "_" & i).Value 
				end if
			end if
		next				
		if Ucase(typename(document.all("Dim" & nDim))) <> "HTMLIFRAME" then
			if nCount = 0 then
				document.all("Dim" & nDim).innerText =  document.all("DataFAll" & nDim).innerText
			elseif nCount = 1 then
				document.all("Dim" & nDim).innerText = document.all("DataF" & nDim & "_" & nChecked).innerText 
			else
				document.all("Dim" & nDim).innerText = sPersonalizado
			end if
		else												
			if nCount = 0 then
				document.frames("Dim" & nDim).Dim1.innerText = document.all("DataFAll" & nDim).innerText
			elseif nCount = 1 then
				document.frames("Dim" & nDim).Dim1.innerText = document.all("DataF" & nDim & "_" & nChecked).innerText 
			else
				document.frames("Dim" & nDim).Dim1.innerText = sPersonalizado
			end if
		end if
		CustomFilter(nDim)= sWherePaso
	end if
	HideDataDiv nDim
end sub

sub SaveDataDivEsc(nDim)
	on error resume next
	dim i, sWherePaso, nCount
	if document.all("DataAll" & nDim).checked then
		sWherePaso =  document.all("DataAll" & nDim).value		
	else
		sWherePaso = ""
		nCount = 0
		for i = 1 to nDataCount
			if document.all("Data" & nDim & "_" & i).checked then
				nCount = nCount + 1
				if nCount = 1 then
					sWherePaso = document.all("Data" & nDim & "_" & i).Value 
				else
					sWherePaso = sWherePaso & "_AWDim_" & document.all("Data" & nDim & "_" & i).Value 
				end if
			end if
		next				
		if nCount = 0 then
			sWherePaso =  document.all("DataAll" & nDim).value
		end if		
	end if
	HideDataDiv nDim
	
	if document.all("ckNOT" & nDim).checked then
		sWherePaso	= sWherePaso & "_AWDim_[EXCEPT]"
	end if
	
	UPDStage sWherePaso	
end sub

sub SaveDataDivEscDsg(nDim)
	dim i, sWherePaso, nCount
	if document.all("DataAll" & nDim).checked then
		sWherePaso =  document.all("DataAll" & nDim).value		
	else
		sWherePaso = ""
		nCount = 0
		for i = 1 to nDataCount
			if document.all("Data" & nDim & "_" & i).checked then
				nCount = nCount + 1				
				if nCount = 1 then
					sWherePaso = document.all("Data" & nDim & "_" & i).Value 
				else
					sWherePaso = sWherePaso & "_AWDim_" & document.all("Data" & nDim & "_" & i).Value 
				end if
			end if
		next				
		if nCount = 0 then
			sWherePaso =  document.all("DataAll" & nDim).value
		end if		
	end if
	HideDataDiv nDim		
	UPDStage "AWDEvent:" & sWherePaso	
end sub

sub EAS()		
end sub

sub PeriodFilter(sKey)	
	dim sSP
	call UnLoadMainMenu()
	if trim(skey) <> "" then				
		if sKey = "-1" then
			SetCenterFlag
			'BuildCalendar mid(sparametros,1,8), mid(sparametros,9,6), mid(sparametros,15), ((mybody.clientHeight-mybody.clientTop)/2) - 75, ((mybody.clientwidth-mybody.clientleft)/2) - 50
			BuildCalendar mid(sparametros,1,8), mid(sparametros,9,6), mid(sparametros,15), window.event.clientY , window.event.clientX + mybody.scrollleft
		elseif sKey = "-2" then
			if instr(1,sparametros, "SQ") = 0 then
				sSP = "SPD"
			else
				sSP = "SQD"
			end if
			if mid(sparametros,15,3) = "AWD" then					
				UPDStage "AWDEvent:" & sSP & mid(sparametros,27) & mid(sparametros,9,6) & mid(sparametros,1,8) & "_AWSep_SPR" & mid(sparametros,27) & scenform.txtEscActual.value
			else				
				UPDStage sSP & mid(sparametros,18) & mid(sparametros,9,6) & mid(sparametros,1,8) & "_AWSep_SPR" & mid(sparametros,18) & scenform.txtEscActual.value
			end if
		elseif sKey = "-3" then
			if instr(1,sparametros, "SQ") = 0 then
				sSP = "SPD"
			else
				sSP = "SQD"
			end if
			if mid(sparametros,15,3) = "AWD" then					
				UPDStage "AWDEvent:" & sSP & mid(sparametros,27) & "REMOVE"
			else				
				UPDStage sSP & mid(sparametros,18) & "REMOVE"
			end if
		else
			if mid(sparametros,15,3) = "AWD" then					
				UPDStage "AWDEvent:SPC" & mid(sparametros,27) & sKey
			else				
				UPDStage "SPC" & mid(sparametros,18) & sKey
			end if
		end if
	end if
end sub

sub UpdTD(sKey)
	call UnLoadMainMenu()
	if trim(skey) <> "" then
		UPDStage sparametros & sKey
	end if
end sub

' ********* Enlazador Aplicar Filtro ************
sub ExecuteAllFilters
	if trim(sFilterstoApply) <> "" then
		UPDStage sFilterstoApply
	end if
end sub

sub SaveDataDivEsctoApply(nDim)	
	on error resume next
	dim i, sWherePaso, nCount, sDesc
	sDesc = ""
	if document.all("DataAll" & nDim).checked then
		sWherePaso =  document.all("DataAll" & nDim).value		
		sDesc = document.all("DataFAll" & nDim).innerText
	else
		sWherePaso = ""
		nCount = 0
		for i = 1 to nDataCount
			if document.all("Data" & nDim & "_" & i).checked then
				nCount = nCount + 1
				if nCount = 1 then
					sWherePaso = document.all("Data" & nDim & "_" & i).Value 
					sDesc = document.all("DataF" & nDim & "_" & i).innerText
				else
					sWherePaso = sWherePaso & "_AWDim_" & document.all("Data" & nDim & "_" & i).Value 
					sDesc = sDesc & ", " & document.all("DataF" & nDim & "_" & i).innerText
				end if								
			end if
		next				
		if nCount = 0 then
			sWherePaso =  document.all("DataAll" & nDim).value
			sDesc = document.all("DataFAll" & nDim).innerText
		else
			if document.all("ckNOT" & nDim).checked then
				sWherePaso	= sWherePaso & "_AWDim_[EXCEPT]"
			end if
		end if		
	end if
	HideDataDiv nDim	
	if Ucase(typename(document.all("Dim" & nDim))) <> "HTMLIFRAME" then
		document.all("Dim" & nDim).innerText = sDesc
	else
		document.frames("Dim" & nDim).myfont.innerText = sDesc
	end if	
	if trim(sFilterstoApply) <> "" then
		sFilterstoApply  = sWherePaso & "_AWSep_" & sFilterstoApply
	else
		sFilterstoApply  = sWherePaso
	end if	
end sub

function GetFilterParams
	if trim(sFilterstoApply) <> "" then
		GetFilterParams  = sFilterstoApply & "_AWSep_" & sEscensParams
	else
		GetFilterParams  = sEscensParams
	end if
end function

sub HeaderBackImage(oHEI, oTH, oTB, FixRow, bColNum)   
 
  dim i, j  
  on error resume next
  for j = 0 to oTH.rows.length -1		
  	for i = 0 to oTH.rows(j).cells.length -1  		
  		if oTH.rows(j).cells(i).style.backgroundImage = "" then
  			oTH.rows(j).cells(i).style.backgroundImage  = oHEI.style.backgroundImage  		  		
  		end if
  	next
  next  
  if bColNum = 1 then
  	for i = 0 to oTB.rows.length -1			  		
  		oTB.rows(i).cells(0).style.backgroundImage  = oHEI.style.backgroundImage
  	next			
  end if
end sub

Sub DimDescRange(DimCons)
	Dim sIndCons, sMD
	sMD = ""
	sIndCons = Mid(DimCons, 7)
	DimCons = CInt(Mid(DimCons, 1, 5))
	sMD = ShowDimDescRange(DimCons, sIndCons)
	If Trim(sMD) <> "" Then
	    Call addcol(sMD)
	End If
end sub

sub PrintTD
	on error resume next
	sPrintTableH ="TDH1" 
	sPrintTableB ="TDB1" 
	i = 0
	i = window.document.all(sPrintTableH).rows
	if i > 0 then
		ShowInPrintFormat
	end if
end sub

sub Advisor
	dim sAdvInf, sANFName	
	openAdvisorDialog
	if not isNull(window.returnValue) then
		sAdvInf = window.returnValue
		sANFName = mid(sAdvInf, 1, instr(sAdvInf, "@")-1)
		call SaveAdvisorANF(sANFName, sAdvInf)
	end if	
end sub

sub addSubRows(OrigTable, nTable, nNewRowPos)	
	on error resume next	
	nTop = 0	
	set NewObjsTable = document.all("TDB" & nTable)
	nTop = 	OrigTable.rows.length -1	
	NewObjsTable.rows(nNewRowPos).onClick = ""	
	for intCont = 0 to nTop
		set oNewRow = OrigTable.rows(intCont).CloneNode(true)		
		set oRowInserted = NewObjsTable.rows(nNewRowPos).insertAdjacentElement("afterEnd",oNewRow)    
		nNewRowPos = nNewRowPos + 1		
	next
	set oNewRow = nothing
	set oRowInserted = nothing
	set NewObjsTable =  nothing
end sub

sub RowDrillDown(sParam)
	if trim(sParam) <> "" then
		if left(sParam,1) <> "T" and left(sParam,1) <> "A" then
			dim sPaso
			call UnloadMainMenu
			if trim(sTableParams) <> "" then	
				intIdaAlServer = intIdaAlServer + 1			
				sCurrentFrame = "frameSubObjs" & intIdaAlServer	
				sPaso= "ROWDD," & sParam  & "|" & intIdaAlServer & "," & sParametros & "_AWSep_" & sTableParams
				set oCurrFrame = document.createElement("IFRAME")				
				oCurrFrame.style.display = "none"	
				call oCurrFrame.SetAttribute("id",sCurrentFrame)
				call oCurrFrame.SetAttribute("name",sCurrentFrame)
				call document.body.insertAdjacentElement("beforeEnd",oCurrFrame)							
				sParamsPaso = sPaso				
				oCurrFrame.src = SendPage
				set oCurrFrame = nothing
			end if									
		end if
	else
		call UnloadMainMenu
	end if
end sub
