VERSION 5.00
Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "SHDOCVW.dll"
Begin VB.Form frmMain 
   Caption         =   "phpGroupWare"
   ClientHeight    =   8280
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   11490
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   8280
   ScaleWidth      =   11490
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer tmrNotify 
      Enabled         =   0   'False
      Interval        =   60000
      Left            =   10620
      Top             =   7500
   End
   Begin VB.Timer tmrExit 
      Enabled         =   0   'False
      Interval        =   800
      Left            =   11040
      Top             =   7500
   End
   Begin SHDocVwCtl.WebBrowser wbMail 
      Height          =   2955
      Index           =   0
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   4395
      ExtentX         =   7752
      ExtentY         =   5212
      ViewMode        =   0
      Offline         =   0
      Silent          =   0
      RegisterAsBrowser=   0
      RegisterAsDropTarget=   1
      AutoArrange     =   0   'False
      NoClientEdge    =   0   'False
      AlignLeft       =   0   'False
      NoWebView       =   0   'False
      HideFileNames   =   0   'False
      SingleClick     =   0   'False
      SingleSelection =   0   'False
      NoFolders       =   0   'False
      Transparent     =   0   'False
      ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
      Location        =   ""
   End
   Begin VB.PictureBox pctStatusBar 
      Align           =   2  'Align Bottom
      Height          =   315
      Left            =   0
      ScaleHeight     =   255
      ScaleWidth      =   11430
      TabIndex        =   1
      Top             =   7965
      Width           =   11490
      Begin VB.CommandButton Command1 
         Enabled         =   0   'False
         Height          =   255
         Left            =   1260
         TabIndex        =   3
         Top             =   0
         Width           =   75
      End
      Begin VB.Shape shpProgress 
         BackColor       =   &H80000002&
         BorderColor     =   &H80000002&
         FillColor       =   &H80000002&
         FillStyle       =   0  'Solid
         Height          =   255
         Left            =   0
         Top             =   0
         Width           =   1275
      End
      Begin VB.Label lblStatus 
         AutoSize        =   -1  'True
         Caption         =   "lblStatus"
         Height          =   195
         Left            =   1380
         TabIndex        =   2
         Top             =   30
         Width           =   600
      End
   End
   Begin SHDocVwCtl.WebBrowser wbNotify 
      CausesValidation=   0   'False
      Height          =   1155
      Index           =   0
      Left            =   4920
      TabIndex        =   4
      Top             =   420
      Width           =   2055
      ExtentX         =   3625
      ExtentY         =   2037
      ViewMode        =   0
      Offline         =   0
      Silent          =   0
      RegisterAsBrowser=   0
      RegisterAsDropTarget=   1
      AutoArrange     =   0   'False
      NoClientEdge    =   0   'False
      AlignLeft       =   0   'False
      NoWebView       =   0   'False
      HideFileNames   =   0   'False
      SingleClick     =   0   'False
      SingleSelection =   0   'False
      NoFolders       =   0   'False
      Transparent     =   0   'False
      ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
      Location        =   ""
   End
   Begin VB.PictureBox pctOn 
      Height          =   675
      Left            =   3300
      Picture         =   "frmMain.frx":000C
      ScaleHeight     =   615
      ScaleWidth      =   615
      TabIndex        =   5
      Top             =   3900
      Visible         =   0   'False
      Width           =   675
   End
   Begin VB.Menu mnuFile 
      Caption         =   "&File"
      Begin VB.Menu mnuLogin 
         Caption         =   "&Login"
      End
      Begin VB.Menu mnuDash1 
         Caption         =   "-"
      End
      Begin VB.Menu mnuExit 
         Caption         =   "E&xit"
      End
   End
   Begin VB.Menu mnuTools 
      Caption         =   "&Tools"
      Begin VB.Menu mnuServersAccounts 
         Caption         =   "&Servers/Accounts"
      End
      Begin VB.Menu mnuDash3 
         Caption         =   "-"
      End
      Begin VB.Menu mnuInetOptions 
         Caption         =   "Internet &Options"
      End
   End
   Begin VB.Menu mnuServers 
      Caption         =   "&Servers"
      Begin VB.Menu mnuServer 
         Caption         =   "ServerItem"
         Index           =   0
      End
   End
   Begin VB.Menu mnuHelp 
      Caption         =   "&Help"
      Begin VB.Menu mnuphpGWSite 
         Caption         =   "phpGroupWare Web Site"
      End
      Begin VB.Menu mnuDash2 
         Caption         =   "-"
      End
      Begin VB.Menu mnuAbout 
         Caption         =   "&About"
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Implements ISubclass
Private m_emr As EMsgResponse

Private gInTray As Boolean
Private gTrayId As Long
Private gTrayTip As String
Private gTrayHwnd As Long
Private gTrayIcon As StdPicture
Private gAddedToTray As Boolean

Private Const defInTray = False
Private Const defTrayTipOn = "phpGWShell" & vbNullChar
Private Const sInTray = "InTray"
Private Const sTrayIcon = "TrayIcon"
Private Const sTrayTip = "TrayTip"

Dim aByte() As Byte, bEnding As Boolean, bSendEmail As Boolean, strEmailTo As String
Dim iCurrSeconds As Integer, lCurrDelay As Long
Dim iNewEventServer As Integer, iCurrServer As Integer
Public lEventDelay As Long

Private Sub Form_Load()
On Error Resume Next
    
    If bAppLoading Then Exit Sub
    
    Randomize Timer
    
    bSendEmail = False
    lblStatus.Caption = ""
    shpProgress.Visible = False
    
    CheckExisting
    
    AttachMessage Me, Me.hwnd, WM_COPYDATA
    TagWindow Me.hwnd
    ParseCommand Command
    
    GetWindow Me
    
    InitServers True
    
    Me.Icon = frmAbout.Icon
    gInTray = defInTray                             ' Set global InTray default
    gAddedToTray = False                            ' Set default state
    gTrayId = 0                                     ' Set global TrayId default
    gTrayHwnd = Me.hwnd                                ' Set and keep HWND of user control
    SetInTray defInTray                               ' Init InTray Property
    SetTrayTip defTrayTipOn                             ' Init TrayTip Property
    SetTrayIcon pctOn.Picture                          ' Init TrayIcon property
    
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
    Cancel = 1
    mnuExit_Click
End Sub

Private Sub Form_Resize()
On Error Resume Next
    Dim i As Integer
    
    For i = 0 To UBound(arrServers)
        wbMail(i).Move 0, 0, Me.Width - 120, Me.Height - pctStatusBar.Height - 710
    Next i
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    Cancel = 1
    If GetInTray Then                      ' If TrayIcon is visible
        SetInTray False                   ' Cleanup and unplug it.
    End If
    
    mnuExit_Click
End Sub

Private Sub mnuAbout_Click()
On Error Resume Next
    frmAbout.Show vbModal
End Sub

Private Sub mnuExit_Click()
On Error Resume Next
    Dim i As Integer, bGotOne As Boolean
    Screen.MousePointer = vbHourglass
    
    bGotOne = False
    For i = 0 To UBound(arrServers)
        If arrServers(i).LoggedIn Then
            wbMail(i).Navigate2 arrServers(i).BaseURL & "logout.php"
            bGotOne = True
        End If
    Next i
    If bGotOne Then
        tmrExit.Enabled = True
    Else
        ExitApp
    End If
    bEnding = True
End Sub

Private Sub mnuInetOptions_Click()
On Error Resume Next
    ShellExecute 0, "", "inetcpl.cpl", "", "", 0
End Sub

Private Sub mnuLogin_Click()
On Error Resume Next
    AutoLogin iCurrServer
End Sub

Private Sub mnuphpGWSite_Click()
On Error Resume Next
    ShellExecute 0, "", "http://www.phpgroupware.org/", "", "", 0
End Sub

Private Sub mnuServer_Click(Index As Integer)
    ShowServer Index
End Sub

Private Sub mnuServersAccounts_Click()
On Error Resume Next
    frmServers.Show vbModal
End Sub

Private Sub tmrExit_Timer()
On Error Resume Next
    If iCurrSeconds > iSecondsToLogout Then
        tmrExit.Enabled = False
        Screen.MousePointer = vbNormal
        ExitApp
    End If
    iCurrSeconds = iCurrSeconds + 1
End Sub

Private Sub tmrNotify_Timer()
On Error Resume Next
    Dim i As Integer
    
    If lCurrDelay >= lEventDelay Then
        For i = 0 To UBound(arrServers)
            If arrServers(i).Events Then
                wbNotify(i).Navigate2 arrServers(i).BaseURL & "notify_simple.php?rnd=" & Rnd
            End If
        Next i
        lblStatus.Caption = "Checking for new events...."
        lCurrDelay = 0
    End If
    lCurrDelay = lCurrDelay + 1
End Sub

Private Sub wbMail_DownloadComplete(Index As Integer)
On Error Resume Next
    shpProgress.Visible = False
End Sub

Private Sub wbMail_NavigateComplete2(Index As Integer, ByVal pDisp As Object, URL As Variant)
On Error Resume Next
    Dim i As Integer
    Screen.MousePointer = vbNormal
    If bEnding Then
        arrServers(Index).LoggedIn = False
        For i = 0 To UBound(arrServers)
            If arrServers(i).LoggedIn Then Exit Sub
        Next i
        ExitApp
    End If
    If arrServers(Index).AutoLogin Then
        If Right(URL, 15) = "login.php?cd=10" Or Right(URL, 14) = "login.php?cd=2" Then
            AutoLogin Index
            Exit Sub
        End If
    End If
    If InStr(URL, "login.php") = 0 And InStr(URL, "logout.php") = 0 Then
        arrServers(Index).LoggedIn = True
        If bSendEmail Then SendEmail Index
        tmrNotify.Enabled = True
    Else
        arrServers(Index).LoggedIn = False
    End If
End Sub

' Utility function to pack the data to post into an array of bytes
Private Sub PackBytes(ByteArray() As Byte, ByVal PostData As String)
On Error Resume Next
    Dim i As Long, iNewBytes As Long, iCursize As Long, ch As String
    iNewBytes = Len(PostData)
    If iNewBytes = 0 Then
        Exit Sub
    End If
    iCursize = UBound(ByteArray) - LBound(ByteArray)
    ReDim Preserve ByteArray(iNewBytes + iCursize)
    For i = 1 To iNewBytes
        ch = Mid(PostData, i, 1)
        If ch = Space(1) Then
            ch = "+"
        End If
        ByteArray(i + iCursize - 1) = Asc(ch)
    Next i
End Sub

Private Sub wbMail_ProgressChange(Index As Integer, ByVal Progress As Long, ByVal ProgressMax As Long)
On Error Resume Next
    Dim dMultiplier As Double
    If ProgressMax = 0 Then
        shpProgress.Visible = False
        Exit Sub
    End If
    dMultiplier = 1275 / ProgressMax
    shpProgress.Width = Progress * dMultiplier
    shpProgress.Visible = True
End Sub

Private Sub wbMail_StatusTextChange(Index As Integer, ByVal Text As String)
On Error Resume Next
    lblStatus.Caption = Text
End Sub

Private Sub wbMail_TitleChange(Index As Integer, ByVal Text As String)
On Error Resume Next
    Me.Caption = Text & " - phpGroupWare Shell"
End Sub

Private Sub Login(Index As Integer)
On Error Resume Next
    Screen.MousePointer = vbHourglass
    wbMail(Index).Navigate2 arrServers(Index).BaseURL & "login.php"
End Sub

Private Sub AutoLogin(Index As Integer)
On Error Resume Next
    Dim vPost As Variant, strPost As String
    ReDim aByte(0)
    
    If arrServers(Index).LoginID = "" Or arrServers(Index).Password = "" Then
        MsgBox "You can enter your LoginID and Password in the Servers Options to Automatically login."
        Login Index
        Exit Sub
    End If
    Screen.MousePointer = vbHourglass
    strPost = "login=" & arrServers(Index).LoginID & "&passwd=" & arrServers(Index).Password & "&submit=login"
    If arrServers(Index).DomainRequired Then
        strPost = strPost & "&logindomain=" & arrServers(Index).Domain
    End If
    PackBytes aByte, strPost
    
    vPost = aByte
    wbMail(Index).Navigate2 arrServers(Index).BaseURL & "login.php", , , vPost, "Content-Type: application/x-www-form-urlencoded" & vbCrLf
End Sub

Private Sub SendEmail(Index As Integer)
On Error Resume Next
    Screen.MousePointer = vbHourglass
    wbMail(Index).Navigate2 arrServers(Index).BaseURL & "email/compose.php?folder=INBOX&to=" & strEmailTo
    bSendEmail = False
End Sub

Private Sub ParseCommand(ByVal sCmd As String)
On Error Resume Next
    If (Me.Visible = False) Then
       Me.Visible = True
    End If
    
    RestoreAndActivate Me.hwnd
    sCmd = Trim$(sCmd)

    If Left(sCmd, 9) = "/mailurl:" Then
        strEmailTo = Replace(Right(sCmd, Len(sCmd) - 9), "?", "&", , 1)
        If UCase(Left(strEmailTo, 7)) = "MAILTO:" Then
            strEmailTo = Right(strEmailTo, Len(strEmailTo) - 7)
        End If
        bSendEmail = True
    End If
End Sub

Private Sub ExitApp()
On Error Resume Next
   SaveWindow Me
   DetachMessage Me, Me.hwnd, WM_COPYDATA
   SetInTray False
   EndApp
End Sub

Private Property Let ISubclass_MsgResponse(ByVal RHS As EMsgResponse)
On Error Resume Next
   ' Sometime....
End Property

Private Property Get ISubclass_MsgResponse() As EMsgResponse
On Error Resume Next
   ISubclass_MsgResponse = emrPostProcess
End Property

Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
    Dim tCDS As COPYDATASTRUCT
    Dim b() As Byte
    Dim sCommand As String
    
    Select Case iMsg
    Case WM_COPYDATA
        CopyMemory tCDS, ByVal lParam, Len(tCDS)
        If (tCDS.cbData > 0) Then
            ReDim b(0 To tCDS.cbData - 1) As Byte
            CopyMemory b(0), ByVal tCDS.lpData, tCDS.cbData
            sCommand = StrConv(b, vbUnicode)
            ParseCommand sCommand
            If Not arrServers(iDefaultServer).LoggedIn Then
                If vbNo = MsgBox("You do not appear to be logged in.  Log in now?", vbYesNo + vbQuestion) Then
                    Exit Function
                End If
                AutoLogin iDefaultServer
                Exit Function
            End If
            SendEmail iDefaultServer
        Else
            RestoreAndActivate Me.hwnd
        End If
    End Select
End Function

Private Sub wbNotify_DocumentComplete(Index As Integer, ByVal pDisp As Object, URL As Variant)
On Error GoTo Err_Handle
    
    Dim oTest As Object, arrCommands() As String, i As Integer, arrPair() As String

    lblStatus.Caption = ""
    Set oTest = wbNotify(Index).Document
    If oTest.body.innerHTML = "" Then
        SetInTray False
    Else
        arrCommands = Split(oTest.body.innerHTML, Chr(13))
        For i = 0 To UBound(arrCommands)
            If InStr(arrCommands(i), ":") > 0 Then
                arrPair = Split(arrCommands(i), ":")
                Select Case UCase(Trim(arrPair(0)))
                Case "ERROR"
                    MsgBox "Error during check: " & arrPair(1)
                Case "ACTION"
                    Select Case UCase(Trim(arrPair(1)))
                    Case "NEWMAIL"
                        NewMailPrompt Index, Val(arrPair(2))
                    End Select
                End Select
            End If
        Next i
    End If
Err_Handle:
    Screen.MousePointer = vbNormal
End Sub

Private Sub NewMailPrompt(Index As Integer, Optional NumMsg As Long = 0)
On Error Resume Next
    
    If arrServers(Index).LastNumMsg <> NumMsg Then
        SetInTray True
        SetTrayTip "New email on server """ & arrServers(Index).FriendlyName & """"
        iNewEventServer = Index
        If arrServers(Index).EventSound Then
            Call PlaySound("MailBeep", 0, SND_ASYNC Or SND_NOWAIT)
        End If
        If arrServers(Index).EventPrompt Then
            If vbYes = MsgBox("You have new email on server """ & arrServers(Index).FriendlyName & """.  Would you like to read it now?", vbQuestion + vbYesNo) Then
                Screen.MousePointer = vbHourglass
                wbMail(Index).Navigate2 arrServers(Index).BaseURL & "email/"
            End If
        End If
    End If
    arrServers(Index).LastNumMsg = NumMsg
End Sub

Public Sub SetTrayIcon(Icon As StdPicture)
On Error GoTo Error_Handle

    Dim Tray As NOTIFYICONDATA                          ' Notify Icon Data structure
    Dim rc As Long                                      ' API return code
    If Not (Icon Is Nothing) Then                       ' If icon is valid...
        If (Icon.Type = vbPicTypeIcon) Then             ' Use ONLY if it is an icon
            If gAddedToTray Then                        ' Modify tray only if it is in use.
                Tray.uID = gTrayId                      ' Unique ID for each HWND and callback message.
                Tray.hwnd = gTrayHwnd                   ' HWND receiving messages.
                Tray.hIcon = Icon.Handle                ' Tray icon.
                Tray.uFlags = NIF_ICON                  ' Set flags for valid data items
                Tray.cbSize = Len(Tray)                 ' Size of struct.
                
                rc = Shell_NotifyIcon(NIM_MODIFY, Tray) ' Send data to Sys Tray.
            End If
    
            Set gTrayIcon = Icon                        ' Save Icon to global
            Set Me.Picture = Icon                          ' Show user change in control as well(gratuitous)
        End If
    End If

Exit_Proc:
    Exit Sub

Error_Handle:
    MsgBox Err.Description & " in SetTrayIcon"
    GoTo Exit_Proc

End Sub

Public Function GetTrayIcon() As StdPicture
On Error GoTo Error_Handle

    Set GetTrayIcon = gTrayIcon                        ' Return Icon value

Exit_Proc:
    Exit Function

Error_Handle:
    MsgBox Err.Description & " in GetTrayIcon"
    GoTo Exit_Proc

End Function

Public Sub SetTrayTip(Tip As String)
On Error GoTo Error_Handle

    Dim Tray As NOTIFYICONDATA                      ' Notify Icon Data structure
    Dim rc As Long                                  ' API Return code
    If gAddedToTray Then                            ' if TrayIcon is in taskbar
        Tray.uID = gTrayId                          ' Unique ID for each HWND and callback message.
        Tray.hwnd = gTrayHwnd                       ' HWND receiving messages.
        Tray.szTip = Tip & vbNullChar               ' Tray tool tip
        Tray.uFlags = NIF_TIP                       ' Set flags for valid data items
        Tray.cbSize = Len(Tray)                     ' Size of struct.
        
        rc = Shell_NotifyIcon(NIM_MODIFY, Tray)     ' Send data to Sys Tray.
    End If
    
    gTrayTip = Tip                                  ' Save Tip

Exit_Proc:
    Exit Sub

Error_Handle:
    MsgBox Err.Description & " in SetTrayTip"
    GoTo Exit_Proc

End Sub

Public Function GetTrayTip() As String
On Error GoTo Error_Handle

    GetTrayTip = gTrayTip                              ' Return Global Tip...

Exit_Proc:
    Exit Function

Error_Handle:
    MsgBox Err.Description & " in GetTrayTip"
    GoTo Exit_Proc

End Function

Public Sub SetInTray(Show As Boolean)
On Error GoTo Error_Handle

    Dim ClassAddr As Long                           ' Address pointer to Control Instance
    If (Show <> gInTray) Then                       ' Modify ONLY if state is changing!
        If Show Then                                ' If adding Icon to system tray...
            PrevWndProc = SetWindowLong(gTrayHwnd, GWL_WNDPROC, AddressOf WindowProc)
            SetWindowLong gTrayHwnd, GWL_USERDATA, ObjPtr(Me) 'ClassAddr
            
            AddIcon gTrayHwnd, gTrayId, GetTrayTip, GetTrayIcon ' Add TrayIcon to System Tray...
            gAddedToTray = True                 ' Save state of control used in teardown procedure
        Else                                        ' If removing Icon from system tray
            If gAddedToTray Then                    ' If Added to system tray then remove...
                DeleteIcon gTrayHwnd, gTrayId       ' Remove icon from system tray
                
                ' Un SubClass controls window proc.
                SetWindowLong gTrayHwnd, GWL_WNDPROC, PrevWndProc
                gAddedToTray = False                ' Maintain the state for teardown purposes
            End If
        End If
        
        gInTray = Show                              ' Update global variable
    End If

Exit_Proc:
    Exit Sub

Error_Handle:
    MsgBox Err.Description & " in SetInTray"
    GoTo Exit_Proc

End Sub

Public Function GetInTray() As Boolean
On Error GoTo Error_Handle

    GetInTray = gInTray                                ' Return global property

Exit_Proc:
    Exit Function

Error_Handle:
    MsgBox Err.Description & " in GetInTray"
    GoTo Exit_Proc

End Function

Private Sub AddIcon(hwnd As Long, Id As Long, Tip As String, Icon As StdPicture)
On Error GoTo Error_Handle

    Dim Tray As NOTIFYICONDATA                      ' Notify Icon Data structure
    Dim tFlags As Long                              ' Tray action flag
    Dim rc As Long                                  ' API return code
    Tray.uID = Id                                   ' Unique ID for each HWND and callback message.
    Tray.hwnd = hwnd                                ' HWND receiving messages.
    
    If Not (Icon Is Nothing) Then                   ' Validate Icon picture
        Tray.hIcon = Icon.Handle                    ' Tray icon.
        Tray.uFlags = Tray.uFlags Or NIF_ICON       ' Set ICON flag to validate data item
        Set gTrayIcon = Icon                        ' Save icon
    End If
    
    If (Tip <> "") Then                             ' Validate Tip text
        Tray.szTip = Tip & vbNullChar               ' Tray tool tip
        Tray.uFlags = Tray.uFlags Or NIF_TIP        ' Set TIP flag to validate data item
        gTrayTip = Tip                              ' Save tool tip
    End If
    
    Tray.uCallbackMessage = TRAY_CALLBACK           ' Set user defined message
    Tray.uFlags = Tray.uFlags Or NIF_MESSAGE        ' Set flags for valid data item
    Tray.cbSize = Len(Tray)                         ' Size of struct.
    
    rc = Shell_NotifyIcon(NIM_ADD, Tray)            ' Send data to Sys Tray.

Exit_Proc:
    Exit Sub

Error_Handle:
    MsgBox Err.Description & " in AddIcon"
    GoTo Exit_Proc

End Sub

Private Sub DeleteIcon(hwnd As Long, Id As Long)
On Error GoTo Error_Handle

    Dim Tray As NOTIFYICONDATA                      ' Notify Icon Data structure
    Dim rc As Long                                  ' API return code
    Tray.uID = Id                                   ' Unique ID for each HWND and callback message.
    Tray.hwnd = hwnd                                ' HWNDreceiving messages.
    Tray.uFlags = 0&                                ' Set flags for valid data items
    Tray.cbSize = Len(Tray)                         ' Size of struct.
    
    rc = Shell_NotifyIcon(NIM_DELETE, Tray)         ' Send delete message.

Exit_Proc:
    Exit Sub

Error_Handle:
    MsgBox Err.Description & " in DeleteIcon"
    GoTo Exit_Proc

End Sub

Public Sub RightClick()
On Error Resume Next
    
End Sub

Public Sub DoubleClick()
On Error Resume Next
    SetForegroundWindow Me.hwnd                     ' Set current window as ForegroundWindow
    PostMessage Me.hwnd, WM_USER, 0&, 0&            ' Update form...
    SetInTray False
    SetTrayTip "phpGWShell"
    ShowServer iNewEventServer
End Sub

Public Sub ShowServer(Index As Integer)
On Error Resume Next
    Dim i As Integer
    
    iCurrServer = Index
    wbMail(Index).Visible = True
    wbMail(Index).ZOrder 0
    wbNotify(Index).Visible = True
    wbNotify(Index).ZOrder 99
    For i = 0 To mnuServer.UBound
        If i = Index Then
            mnuServer(i).Checked = True
        Else
            mnuServer(i).Checked = False
        End If
    Next i
End Sub

Public Sub InitServers(DoLogin As Boolean)
On Error Resume Next
    Dim i As Integer
    
    If UBound(arrServers) > wbMail.UBound Then
        For i = wbMail.UBound + 1 To UBound(arrServers)
            Load wbMail(i)
            Load wbNotify(i)
            Load mnuServer(i)
        Next i
    End If
    If UBound(arrServers) < wbMail.UBound Then
        For i = wbMail.UBound To UBound(arrServers) + 1 Step -1
            Unload wbMail(i)
            Unload wbNotify(i)
            Unload mnuServer(i)
        Next i
    End If
    For i = 0 To UBound(arrServers)
        If arrServers(i).BaseURL = "" Then
            Load frmOptions
            frmOptions.LoadServer CLng(i)
            frmOptions.Show vbModal
            SaveServers
        End If
        
        mnuServer(i).Caption = arrServers(i).FriendlyName
        wbMail(i).Visible = True
        wbNotify(i).Visible = True
        wbNotify(i).ZOrder 99
        Debug.Print DoLogin & " " & arrServers(i).LoggedIn
        If DoLogin And Not arrServers(i).LoggedIn Then
            If arrServers(i).AutoLogin Then
                AutoLogin i
            Else
                Login i
            End If
        End If
    Next i
    
    ShowServer iDefaultServer
End Sub
