function GetActiveLayerState
	call Eview.Viewer.WaitForPageLoaded()

	dim layersOff
	dim layersOn
	dim layer

	for each layer in Eview.Viewer.Layers
		If layer.visible = "False" Then
			layersOff = layersOff + layer.name + ","
		Else
			If layer.visible = "True" Then
				layersOn = layersOn + layer.name + ","
			End If
		End If
	next

	GetActiveLayerState = "(" + layersOff + ")" + "&layersOn=(" + layersOn + ")"
end function

'-------------------------------------------------------------------'
' Helper function to compute colors                                 '
'-------------------------------------------------------------------'
function Color(r, g, b)
	Color = (b * 65536 + g * 256 + r)
end function

'-------------------------------------------------------------------'
' This demonstrates getting a control property                      '
'-------------------------------------------------------------------'
function ShowSourcePath
    MsgBox Eview.SourcePath
end function

'-------------------------------------------------------------------'
' This demonstrates iterating over the pages collection             '
'-------------------------------------------------------------------'
function ShowPages
    dim page

    for each page in Eview.Viewer.Pages
      Eview.Viewer.Page = page.Name
      call Eview.Viewer.WaitForPageLoaded()
      MsgBox Eview.Viewer.Page.Name
    next
end function

'-------------------------------------------------------------------'
' This demonstrates setting a control property and calling a method '
'-------------------------------------------------------------------'
function BGcolor
    Eview.Viewer.BackColor = Color(0, 102, 204)
    Eview.Viewer.ExecuteCommand("FITTOWINDOW")
end function

'-------------------------------------------------------------------'
' This demonstrates using the layers collection via an enumerator   '
'-------------------------------------------------------------------'
function ShowLayers
    dim layer

    ' Make sure the page is fully loaded first
    call Eview.Viewer.WaitForPageLoaded()

    ' Lets set the back color and fit to window again
    BGcolor

    ' Turn all the layers off
    for each layer in Eview.Viewer.Layers
      layer.Visible = false
    next

    ' Display each layer by itself
    for each layer in Eview.Viewer.Layers
      layer.Visible = true
      MsgBox layer.name
      layer.Visible = false
    next

    ' Turn all the layers back on
    for each layer in Eview.Viewer.Layers
      layer.Visible = true
    next
end function

'-------------------------------------------------------------------'
' This demonstrates using new named views collection via manual     '
' enumeration.                                                      '
'-------------------------------------------------------------------'
function ShowViews
    ' Make sure the page is fully loaded first
    call Eview.Viewer.WaitForPageLoaded()

    ' Loop iterate over the collection manually
    for i = 1 to Eview.Viewer.NamedViews.Count
      Eview.Viewer.View = Eview.Viewer.NamedViews.Item(i)
      MsgBox Eview.Viewer.View.Name
    next

    ' Fetch and set the initial view by name instead of index
    Eview.Viewer.View = Eview.Viewer.NamedViews.Item("INITIAL")
end function