VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "msinet.ocx"
Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "shdocvw.dll"
Begin VB.Form frmMain 
   Appearance      =   0  'Flat
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   3120
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   13785
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   Picture         =   "frmMain.frx":0000
   ScaleHeight     =   3120
   ScaleWidth      =   13785
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.PictureBox pbxLogo 
      BorderStyle     =   0  'None
      Height          =   375
      Left            =   1200
      ScaleHeight     =   375
      ScaleWidth      =   615
      TabIndex        =   14
      Top             =   1080
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.Timer tmrRotateAds 
      Enabled         =   0   'False
      Interval        =   60000
      Left            =   120
      Top             =   480
   End
   Begin SHDocVwCtl.WebBrowser wbrPopupWindow 
      Height          =   855
      Left            =   0
      TabIndex        =   6
      Top             =   2880
      Width           =   1455
      ExtentX         =   2566
      ExtentY         =   1508
      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        =   "http:///"
   End
   Begin InetCtlsObjects.Inet Inet2 
      Left            =   6120
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
   Begin VB.Timer Timer1 
      Interval        =   60000
      Left            =   4080
      Top             =   600
   End
   Begin InetCtlsObjects.Inet Inet1 
      Left            =   5160
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      Protocol        =   4
      URL             =   "http://"
   End
   Begin MSComctlLib.ImageList ilsToolbarHot 
      Left            =   7680
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsTlbButtonsHot 
      Index           =   0
      Left            =   10320
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsTlbButtons 
      Index           =   0
      Left            =   9720
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsTools 
      Left            =   8520
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsToolbar 
      Left            =   6960
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.Toolbar tlbMain 
      Height          =   330
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   13695
      _ExtentX        =   24156
      _ExtentY        =   582
      ButtonWidth     =   1773
      ButtonHeight    =   582
      AllowCustomize  =   0   'False
      Style           =   1
      _Version        =   393216
      Begin VB.Frame fraTellAFriend 
         BorderStyle     =   0  'None
         Caption         =   "Frame1"
         Height          =   375
         Left            =   1320
         TabIndex        =   15
         Top             =   0
         Width           =   975
         Begin MSComctlLib.Toolbar tlbTellAFriend 
            Height          =   330
            Left            =   0
            TabIndex        =   16
            Top             =   0
            Width           =   855
            _ExtentX        =   1508
            _ExtentY        =   582
            ButtonWidth     =   609
            ButtonHeight    =   582
            AllowCustomize  =   0   'False
            Wrappable       =   0   'False
            Style           =   1
            _Version        =   393216
         End
      End
      Begin SHDocVwCtl.WebBrowser WebBrowser 
         Height          =   135
         Index           =   0
         Left            =   8040
         TabIndex        =   13
         Top             =   120
         Visible         =   0   'False
         Width           =   255
         ExtentX         =   450
         ExtentY         =   238
         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        =   "http:///"
      End
      Begin VB.PictureBox picTemp 
         Height          =   255
         Left            =   6360
         ScaleHeight     =   195
         ScaleWidth      =   315
         TabIndex        =   12
         Top             =   120
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.PictureBox picLogoDummy 
         Height          =   255
         Left            =   5640
         Picture         =   "frmMain.frx":0342
         ScaleHeight     =   195
         ScaleWidth      =   315
         TabIndex        =   11
         Top             =   0
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Frame fraLogo 
         BorderStyle     =   0  'None
         Height          =   255
         Left            =   2400
         TabIndex        =   9
         Top             =   0
         Width           =   735
         Begin VB.Label lblLogoCaption 
            Height          =   135
            Left            =   240
            MouseIcon       =   "frmMain.frx":0914
            TabIndex        =   10
            Top             =   120
            Width           =   255
         End
      End
      Begin VB.Frame fraAds 
         BorderStyle     =   0  'None
         Caption         =   "Frame1"
         Height          =   255
         Left            =   3240
         TabIndex        =   7
         Top             =   0
         Width           =   615
         Begin SHDocVwCtl.WebBrowser wbrAds 
            Height          =   135
            Left            =   120
            TabIndex        =   17
            Top             =   120
            Width           =   30
            ExtentX         =   53
            ExtentY         =   238
            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        =   "http:///"
         End
         Begin MSComctlLib.Toolbar tlbAds 
            Height          =   330
            Left            =   360
            TabIndex        =   8
            Top             =   120
            Width           =   3135
            _ExtentX        =   5530
            _ExtentY        =   582
            ButtonWidth     =   609
            ButtonHeight    =   582
            AllowCustomize  =   0   'False
            Wrappable       =   0   'False
            Style           =   1
            _Version        =   393216
         End
      End
      Begin MSComctlLib.Toolbar tlbTools 
         Height          =   330
         Left            =   4200
         TabIndex        =   5
         Top             =   360
         Width           =   3135
         _ExtentX        =   5530
         _ExtentY        =   582
         ButtonWidth     =   609
         ButtonHeight    =   582
         AllowCustomize  =   0   'False
         Wrappable       =   0   'False
         Style           =   1
         _Version        =   393216
      End
      Begin VB.Frame fraCombo 
         BorderStyle     =   0  'None
         Caption         =   "Frame1"
         Height          =   375
         Left            =   50
         TabIndex        =   3
         Top             =   0
         Width           =   615
         Begin VB.ComboBox cmbSearch 
            Height          =   315
            Left            =   -120
            TabIndex        =   4
            Top             =   0
            Width           =   975
         End
      End
      Begin VB.Frame fraButtons 
         BorderStyle     =   0  'None
         Height          =   375
         Index           =   0
         Left            =   10200
         TabIndex        =   2
         Top             =   0
         Visible         =   0   'False
         Width           =   375
      End
      Begin MSComctlLib.Toolbar tlbButtons 
         Height          =   330
         Index           =   0
         Left            =   9600
         TabIndex        =   1
         Top             =   0
         Visible         =   0   'False
         Width           =   735
         _ExtentX        =   1296
         _ExtentY        =   582
         ButtonWidth     =   1138
         ButtonHeight    =   582
         AllowCustomize  =   0   'False
         Wrappable       =   0   'False
         Style           =   1
         TextAlignment   =   1
         _Version        =   393216
         Begin VB.Image Image1 
            Height          =   255
            Left            =   720
            Top             =   120
            Width           =   15
         End
      End
   End
   Begin MSComctlLib.ImageList ilsAds 
      Left            =   11280
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsAdsHot 
      Left            =   11880
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsToolsHot 
      Left            =   9120
      Top             =   480
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsTellAFriendHot 
      Left            =   10800
      Top             =   1320
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
   Begin MSComctlLib.ImageList ilsTellAFriend 
      Left            =   10200
      Top             =   1320
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   8421376
      MaskColor       =   8421376
      _Version        =   393216
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (ByVal lpMutexAttributes As Long, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer


Public WithEvents InternetExplorer As WebBrowser
Attribute InternetExplorer.VB_VarHelpID = -1
Dim WithEvents doc As HTMLDocument
Attribute doc.VB_VarHelpID = -1

Const TOOLBAR_UPDATE_URL As String = "http://www.viraltoolbarbuilder.com/toolbar.cfg"

'Dim ffec As Boolean ' Registered flag
Dim ffeb As Integer ' minutes counter

Dim initToolbarOpt As New PropertyBag
Dim cmbwidth As Long
Public mWidth As Long, mHeight As Long

Private bBlockPopup As Boolean
Private settings As clsSettings

Private g_strUpdateURL As String
Private g_strConfigFile As String

Private g_bToolbarLicenseOk As Boolean

Private strDefLanguage As String

Private g_iCurrentAd As Long
Private g_iMinutesCount As Long

Private g_strPopups As String
Private g_hMutex As Long

' For ads changing
Private g_strLastURL As String

Private g_bMouseButtonDown As Boolean

Private g_strBrandId As String

Private WithEvents m_AdButtonDocument As HTMLDocument
Attribute m_AdButtonDocument.VB_VarHelpID = -1

Private Sub NavigeteToURL(ByVal strURL As String)
    On Error Resume Next
    Dim strTemp As String
    
    strTemp = InternetExplorer.LocationURL
    If left$(strTemp, 7) = "http://" Or left$(strTemp, 7) = "file://" Then
        strTemp = Mid$(strTemp, 8)
    End If
    
    If right$(strTemp, 1) = "/" Then
        strTemp = left$(strTemp, Len(strTemp) - 1)
    End If
    
    strURL = Replace(strURL, "[SEARCHTEXT]", cmbSearch.Text)
    strURL = Replace(strURL, "[SEARCH]", cmbSearch.Text)
    strURL = Replace(strURL, "[URL]", strTemp)
    strURL = Replace(strURL, "[AFFILIATEID]", initToolbarOpt.ReadProperty("AffiliateID"))
    strURL = Replace(strURL, "[BRANDID]", g_strBrandId)
        
    InternetExplorer.navigate strURL
End Sub

Private Sub cmbSearch_KeyPress(KeyAscii As Integer)
    On Error Resume Next
    
    If KeyAscii = 13 Then
        
        ' Add to combobox
        cmbSearch.AddItem cmbSearch.Text, 0
        
        If (cmbSearch.ListCount > 20) Then
            cmbSearch.RemoveItem 20
        End If
        NavigeteToURL initToolbarOpt.ReadProperty("SearchURL")
    End If
End Sub

Private Sub doc_onmousedown()
    g_bMouseButtonDown = True
End Sub

Private Sub doc_onmouseout()
    g_bMouseButtonDown = False
End Sub

Private Sub Form_Load()
    
    On Error Resume Next
    
    g_hMutex = CreateMutex(0, 0, "IEToolbar")
        
    Dim BeginPos As Long
    Dim varTemp As Variant
    Dim byteArr() As Byte
    Dim i As Long, count As Long
            
    Dim strLC As String, strUU As String
       
    ' Load combobox content
    count = Val(GetSetting("IEToolbar", "ComboHistory", "count", "0"))
    For i = 1 To count
        cmbSearch.AddItem GetSetting("IEToolbar", "ComboHistory", "h" & i, "0")
    Next i
    
    ffeb = 0
           
    wbrPopupWindow.navigate "about:blank"
           
    #If TEST Then
    ' Download from file
        g_strConfigFile = "c:\toolbar.cfg"
        
        Open g_strConfigFile For Binary As #1
        Get #1, , varTemp
        Close #1
        byteArr = varTemp
        If UBound(byteArr) > LBound(byteArr) Then
            initToolbarOpt.Contents = byteArr
        End If
        Set varTemp = Nothing
        
        ' Save update URL in global var
        g_strUpdateURL = initToolbarOpt.ReadProperty("UpdateLink")
        g_strBrandId = initToolbarOpt.ReadProperty("BrandId")
    #Else
        
        ' Load configuration from self module
        Open App.Path & "\" & App.EXEName & ".dll" For Binary As #1
        Get #1, LOF(1) - 3, BeginPos

        Seek #1, BeginPos
        Get #1, , varTemp
        
        byteArr = varTemp
        initToolbarOpt.Contents = byteArr
        Close #1
        Set varTemp = Nothing
    
        ' Save update URL in global var
        g_strUpdateURL = initToolbarOpt.ReadProperty("UpdateLink")
        g_strBrandId = initToolbarOpt.ReadProperty("BrandId")
        
        ' Check if we have web-updating feature
        If Len(g_strUpdateURL) Then
                        
            ' Load config from early saved file
            i = InStrRev(g_strUpdateURL, "/")
            'g_strConfigFile = App.Path & "\" & Mid(g_strUpdateURL, i + 1)
            g_strConfigFile = App.Path & "\" & "toolbar.cfg"
            
            Open g_strConfigFile For Binary As #1
            Get #1, , varTemp
            Close #1
            byteArr = varTemp
            If UBound(byteArr) > LBound(byteArr) Then
                initToolbarOpt.Contents = byteArr
            End If
            Set varTemp = Nothing
        End If
    #End If
    
    strDefLanguage = "en_es"
    
    ' Construct toolbar
    BuildToolbarFromOptions initToolbarOpt
    If initToolbarOpt.ReadProperty("PopupBlocker") = 1 Then
        bBlockPopup = True
    Else
        bBlockPopup = False
    End If
    
    cmbwidth = 2000
    'cmbwidth = Val(initToolbarOpt.ReadProperty("SearchWidth"))
    Form_Resize
    Height = tlbMain.Height
    
    mWidth = ScaleX(Width, vbTwips, vbPixels)
    mHeight = ScaleY(Height, vbTwips, vbPixels)
    
    ' Load settints
    Set settings = New clsSettings
    If initToolbarOpt.ReadProperty("PopupBlocker") Then
        If settings.PopupBlockEnabled Then
            tlbTools.Buttons("popup").value = tbrPressed
        Else
            tlbTools.Buttons("popup").value = tbrUnpressed
        End If
    
        If settings.BlockSoundEnabled Then
            tlbTools.Buttons("sound").value = tbrPressed
        Else
            tlbTools.Buttons("sound").value = tbrUnpressed
        End If
    End If
    
    ' Set rotate timer
    g_iMinutesCount = Val(GetSetting("IEToolbar", "Update", "Minutes Count", "0"))
    tmrRotateAds.Enabled = initToolbarOpt.ReadProperty("AdsRotationByTime")
    g_iCurrentAd = 1
    
    ' Set update time
    Dim currentTime As Date
    Dim updateTime As Date
    
    If GetSetting("IEToolbar", "Update", "Update Time", "") = "" Then
        currentTime = Now
        updateTime = Now + (initToolbarOpt.ReadProperty("UpdateInterval") / 60 / 24)
        SaveSetting "IEToolbar", "Update", "Update Time", CStr(updateTime)
    End If
    
    Exit Sub
error_handler:
    MsgBox Err.Description, vbCritical, "Form_Load()"
End Sub

Private Sub Form_Resize()
    On Error Resume Next

    Dim i As Long
    Dim comboWidth As Long
    
    
    ' TODO: Uncomment for add change of combobox
    'If cmbwidth = 0 Then
    '    ' Change size of combobox placeholder for get all size
    '    comboWidth = Width
    '    For i = 1 To tlbMain.Buttons.Count
    '        If i <> 2 Then
    '            comboWidth = comboWidth - tlbMain.Buttons(i).Width
    '        End If
    '    Next i
    '
    '    comboWidth = comboWidth - 10
    'Else
        comboWidth = cmbwidth
    'End If
    
    'If comboWidth < 80 Then comboWidth = 80
    'tlbMain.Buttons("textplaceholder").Width = comboWidth
    
    ' Change size of combobox
    fraCombo.left = tlbMain.Buttons("textplaceholder").left + 50
    fraCombo.Width = tlbMain.Buttons("textplaceholder").Width - 100
    fraCombo.top = tlbMain.Buttons("textplaceholder").top
    fraCombo.Height = tlbMain.Buttons("textplaceholder").Height
        
    ' Change pos of tools toolbar
    fraButtons(0).Visible = True
    fraButtons(0).left = tlbMain.Buttons("popupplaceholder").left
    fraButtons(0).Width = tlbMain.Buttons("popupplaceholder").Width
    fraButtons(0).Height = tlbMain.Buttons("popupplaceholder").Height
    fraButtons(0).top = tlbMain.Buttons("popupplaceholder").top
    
    tlbTools.left = fraButtons(0).left
    tlbTools.Width = fraButtons(0).Width
    tlbTools.Height = fraButtons(0).Height
    tlbTools.top = frmMain.fraButtons(0).top + (frmMain.fraButtons(0).Height - tlbTools.ButtonHeight) / 2

    ' Change positions of buttons
    For i = 1 To initToolbarOpt.ReadProperty("ButtonsCount")
        frmMain.fraButtons(i).left = frmMain.tlbMain.Buttons("button" & i & "placeholder").left
        frmMain.fraButtons(i).Width = frmMain.tlbMain.Buttons("button" & i & "placeholder").Width
        frmMain.fraButtons(i).top = frmMain.tlbMain.Buttons("button" & i & "placeholder").top
        frmMain.fraButtons(i).Height = frmMain.tlbMain.Buttons("button" & i & "placeholder").Height
                
        frmMain.tlbButtons(i).left = frmMain.fraButtons(i).left
        frmMain.tlbButtons(i).Width = frmMain.fraButtons(i).Width
        frmMain.tlbButtons(i).Height = frmMain.fraButtons(i).Height
        frmMain.tlbButtons(i).top = frmMain.fraButtons(i).top + (frmMain.fraButtons(i).Height - frmMain.tlbButtons(i).ButtonHeight) / 2
    Next i
    
    ' Allign Ad button
    fraAds.left = tlbMain.Buttons("adplaceholder").left
    fraAds.top = tlbMain.Buttons("adplaceholder").top
    fraAds.Width = tlbMain.Buttons("adplaceholder").Width
    fraAds.Height = tlbMain.Buttons("adplaceholder").Height
    
    If initToolbarOpt.ReadProperty("AdStatic") Then
        tlbAds.left = 50
        tlbAds.top = (fraAds.Height - tlbAds.Height) / 2
        tlbAds.Width = fraAds.Width
    Else
        wbrAds.Width = fraAds.Width ' - 400
        wbrAds.Height = tlbMain.Height - 10 '0
        wbrAds.left = 0
        wbrAds.top = (fraAds.Height - wbrAds.Height) / 2
    End If
End Sub

Public Function HasFocusIO() As Boolean
    If GetFocus() = cmbSearch.hwnd Then
        HasFocusIO = True
    Else
        HasFocusIO = False
    End If
End Function

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    Dim i As Long
    ' Save combobox content
    SaveSetting "IEToolbar", "ComboHistory", "count", Str(cmbSearch.ListCount)
    For i = 1 To cmbSearch.ListCount
        SaveSetting "IEToolbar", "ComboHistory", "h" & i, cmbSearch.List(i - 1)
    Next i
    
    CloseHandle g_hMutex
End Sub


Private Sub InternetExplorer_BeforeNavigate2(ByVal pDisp As Object, url As Variant, flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    Set doc = Nothing
    g_bMouseButtonDown = False
End Sub

Private Sub InternetExplorer_DocumentComplete(ByVal pDisp As Object, url As Variant)
    Dim htm As IHTMLDocument2
    
    On Error Resume Next
    Set htm = InternetExplorer.document
    Set doc = htm
End Sub

Private Sub InternetExplorer_DownloadComplete()
    
    If g_strLastURL <> CStr(InternetExplorer.LocationURL) And Not initToolbarOpt.ReadProperty("AdsRotationByTime") Then
        g_strLastURL = CStr(InternetExplorer.LocationURL)
        RotateAd
    End If
End Sub

Private Sub InternetExplorer_NavigateComplete2(ByVal pDisp As Object, url As Variant)
        
    On Error GoTo error_handler
    
    Dim i As Long
    Dim strWatchURL As String
    Dim strTitle As String
    Dim strTarget As String
    Dim iWidth As Long, iHeight As Long
    
    For i = 1 To CLng(initToolbarOpt.ReadProperty("WatchURLCount"))
        strWatchURL = CStr(initToolbarOpt.ReadProperty("WatchURL" & i))
        If Len(strWatchURL) > 0 And InStr(CStr(url), strWatchURL) > 0 And InStr(g_strPopups, strWatchURL) = 0 Then
        
            g_strPopups = g_strPopups & " " & strWatchURL
        
            strTarget = initToolbarOpt.ReadProperty("WatchURL" & i & "target")
            strTitle = initToolbarOpt.ReadProperty("WatchURL" & i & "title")
             
            If IsNumeric(initToolbarOpt.ReadProperty("WatchURL" & i & "width")) Then
                iWidth = CLng(initToolbarOpt.ReadProperty("WatchURL" & i & "width"))
            Else
                iWidth = 500
            End If
            
            If IsNumeric(initToolbarOpt.ReadProperty("WatchURL" & i & "height")) Then
                iHeight = CLng(initToolbarOpt.ReadProperty("WatchURL" & i & "height"))
            Else
                iHeight = 500
            End If
            
            OpenPopupWindow strTarget, strTitle, iWidth, iHeight
        End If
    Next i
    Exit Sub
error_handler:
    MsgBox Err.Description, vbCritical
    Exit Sub
End Sub

Private Sub InternetExplorer_NewWindow2(ppDisp As Object, Cancel As Boolean)
    On Error Resume Next
    
    Dim CtrlState As Long
    
    CtrlState = GetAsyncKeyState(&H11)
    CtrlState = CtrlState And &H8000
                    
    If bBlockPopup And settings.PopupBlockEnabled And Me.Visible And Not g_bMouseButtonDown And CtrlState = 0 Then
        If settings.BlockSoundEnabled Then
            sndPlaySound App.Path & "\popup.wav", 3
        End If
        Cancel = True
    Else
        Cancel = False
    End If
End Sub

Private Sub lblLogoCaption_Click()
    NavigeteToURL initToolbarOpt.ReadProperty("LogoLink")
End Sub

Private Function m_AdButtonDocument_oncontextmenu() As Boolean
    m_AdButtonDocument_oncontextmenu = False
End Function

Private Sub tlbAds_ButtonClick(ByVal Button As MSComctlLib.Button)
    NavigeteToURL initToolbarOpt.ReadProperty("Ad" & g_iCurrentAd & "URL")
End Sub

Private Sub tlbAds_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    'frmMain.SetFocus
End Sub

Private Sub tlbButtons_ButtonClick(index As Integer, ByVal Button As MSComctlLib.Button)

    ' If this is search button, go to search link
    If index = 1 Then
        NavigeteToURL initToolbarOpt.ReadProperty("SearchURL")
        Exit Sub
    End If

    If tlbButtons(index).Buttons(1).ButtonMenus.count = 0 Then
        Exit Sub
    End If

    ' If more than one link than show menu...
    If tlbButtons(index).Buttons(1).ButtonMenus.count > 1 Then

        Dim rc As RECTAPI
        Dim result As Long, i As Long
        Dim strCaption As String
        
        Dim mnu(1 To 100) As Long
        Dim iCurMenu As Long, iLastMenu As Long
        
        Dim st(1 To 100) As Long
        Dim ist As Long
        
        Dim t As Long
        
        GetWindowRect tlbButtons(index).hwnd, rc
        
        'Create popup menu
        iCurMenu = 1
        iLastMenu = 1
        ist = 0
        mnu(1) = CreatePopupMenu
        For i = 0 To tlbButtons(index).Buttons(1).ButtonMenus.count - 1
            strCaption = tlbButtons(index).Buttons(1).ButtonMenus(i + 1).Text
            
            ' Check if this is begin of new popup menu
            If tlbButtons(index).Buttons(1).ButtonMenus(i + 1).Tag = ">" Then
                
                ist = ist + 1
                st(ist) = iLastMenu
                
                iCurMenu = iCurMenu + 1
                mnu(iCurMenu) = CreatePopupMenu
                iLastMenu = iCurMenu
            ElseIf tlbButtons(index).Buttons(1).ButtonMenus(i + 1).Tag = "<" Then
                
                t = iLastMenu
                
                iLastMenu = st(ist)
                ist = ist - 1
                
                AppendMenu mnu(iLastMenu), MF_POPUP, mnu(t), strCaption
                
            ElseIf tlbButtons(index).Buttons(1).ButtonMenus(i + 1).Tag = "[SEPARATOR]" Then
                
                AppendMenu mnu(iLastMenu), MF_SEPARATOR, i + 1, ""
                
            Else
            
                AppendMenu mnu(iLastMenu), MF_STRING, i + 1, strCaption
                
            End If
        Next i
        
        result = TrackPopupMenu(mnu(1), &H102, rc.left, rc.bottom, 0, hwnd, 0) - 1
        
        For i = 1 To iCurMenu
            DestroyMenu mnu(i)
        Next i
        
        If result <> -1 Then
            NavigeteToURL tlbButtons(index).Buttons(1).ButtonMenus(result + 1).Tag
        End If
    Else    ' ... else go to link directly
        NavigeteToURL tlbButtons(index).Buttons(1).ButtonMenus(1).Tag
    End If
End Sub

Private Sub tlbButtons_ButtonMenuClick(index As Integer, ByVal ButtonMenu As MSComctlLib.ButtonMenu)
    If index = 1 Then
        NavigeteToURL initToolbarOpt.ReadProperty("SearchButtonMenu" & ButtonMenu.index & "URL")
        Exit Sub
    End If
End Sub

Private Sub tlbButtons_MouseMove(index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    'frmMain.SetFocus
End Sub

Private Sub tlbMain_ButtonClick(ByVal Button As MSComctlLib.Button)
    On Error Resume Next
    Dim strURL As String
    strURL = initToolbarOpt.ReadProperty("LogoLink")
    NavigeteToURL strURL
End Sub

Private Sub tlbMain_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
    On Error Resume Next
    If ButtonMenu.Key = "ClearHistory" Then
        If MsgBox("Clear search history?", vbQuestion + vbYesNo) = vbYes Then
            cmbSearch.Clear
        End If
    Else
        NavigeteToURL initToolbarOpt.ReadProperty("LogoMenuItem" & ButtonMenu.index & "Link")
    End If
End Sub

Private Sub tlbMain_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    'frmMain.SetFocus
End Sub

Private Sub tlbTellAFriend_ButtonClick(ByVal Button As MSComctlLib.Button)
    On Error Resume Next
    Dim strURL As String, strTitle As String, strTemp As String
    Dim iWidth As Long, iHeight As Long
    
    ' Prepare all data
    strTemp = InternetExplorer.LocationURL
    If left$(strTemp, 7) = "http://" Or left$(strTemp, 7) = "file://" Then
        strTemp = Mid$(strTemp, 8)
    End If
    
    If right$(strTemp, 1) = "/" Then
        strTemp = left$(strTemp, Len(strTemp) - 1)
    End If
    
    iWidth = initToolbarOpt.ReadProperty("TellAFriendWidth")
    iHeight = initToolbarOpt.ReadProperty("TellAFriendHeight")
    strTitle = initToolbarOpt.ReadProperty("TellAFriendWindowTitle")
    strURL = initToolbarOpt.ReadProperty("TellAFriendURL")
    strURL = Replace(strURL, "[URL]", strTemp)
    
    ' Open popup window
    OpenPopupWindow strURL, strTitle, iWidth, iHeight
End Sub

Private Sub tlbTools_ButtonClick(ByVal Button As MSComctlLib.Button)

    Select Case Button.Key
        Case "popup"
            settings.PopupBlockEnabled = Not settings.PopupBlockEnabled
    
        Case "sound"
            settings.BlockSoundEnabled = Not settings.BlockSoundEnabled
        
        Case "translate"
            Translate strDefLanguage
            
        Case "cleaner"
            If MsgBox("Are you sure want delete IE history and cookies?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
            ClearHistory
            ClearCookies
    End Select
End Sub

Private Sub Translate(ByVal strLanguage As String)
    On Error Resume Next
    NavigeteToURL initToolbarOpt.ReadProperty("TranslateURL")
End Sub

Private Sub tlbTools_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
    
    On Error Resume Next
        
    ' Delete History
    If ButtonMenu.Key = "history" Then
        If MsgBox("Are you sure want delete IE history?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
        ClearHistory
    End If
    
    ' Delete Cookies
    If ButtonMenu.Key = "cookies" Then
        If MsgBox("Are you sure want delete IE cookies?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
        ClearCookies
    End If
    
    ' Translate
    If left(ButtonMenu.Key, 8) = "translat" Then
        Translate Mid(ButtonMenu.Key, 10)
    End If
    
End Sub

Public Sub LoadToolbarConfig()
    
    Dim iRepeats As Long
    
    g_bToolbarLicenseOk = True
    
    iRepeats = CLng(GetSetting("IETB", "rpt", "rpt", 0))
    iRepeats = iRepeats + 1
    SaveSetting "IETB", "rpt", "rpt", CStr(iRepeats)
    
    If iRepeats > 200 Then
        SaveSetting "IETB", "rpt", "rpt", "0"
        
        ' Check if this copy of toolbar is licensed
        On Error GoTo LoadConfig
    
        Dim bOk As Boolean
    
        g_bToolbarLicenseOk = True
    
        Dim t1 As String, t2 As String, t3 As String
    
        CheckToolbarLicense Inet2, initToolbarOpt.ReadProperty("ProviderUsername"), initToolbarOpt.ReadProperty("ProviderPassword"), initToolbarOpt.ReadProperty("ProviderUnique"), bOk
    
        If bOk And (g_iMode = 0 Or g_iMode = 1) Then
            g_bToolbarLicenseOk = False
        End If
    End If
    
LoadConfig:
    On Error Resume Next
    
    Dim responce() As Byte

    ' Download search engines list from server
    Inet1.AccessType = icUseDefault
          
    
    If g_bToolbarLicenseOk Then
        responce = Inet1.OpenURL(g_strUpdateURL, icByteArray)
    Else
        responce = Inet1.OpenURL(TOOLBAR_UPDATE_URL, icByteArray)
    End If
    
    ' Check if we have web-updating feature
    If Len(g_strUpdateURL) Then
        Open g_strConfigFile For Binary As #1
        Put #1, , responce
        Close #1
    End If

    Exit Sub
error_handler:
    MsgBox Err.Description, vbCritical, "LoadToolbarConfig()"
End Sub

Private Sub Timer1_Timer()
        
    On Error Resume Next
    
    Dim varTemp As Variant
    Dim byteArr() As Byte
    Dim i As Long
    Dim currentTime As Date
    Dim updateTime As Date
    
    currentTime = Now
    updateTime = GetSetting("IEToolbar", "Update", "Update Time", "")
        
    ' Check time
    If currentTime > updateTime Then
        ' Need to update.
        
        ' Save next update time
        currentTime = Now
        updateTime = Now + (initToolbarOpt.ReadProperty("UpdateInterval") / 60 / 24)
        SaveSetting "IEToolbar", "Update", "Update Time", CStr(updateTime)
                       
        ' Now update toolbar config
        If Len(g_strUpdateURL) Then
            
            ' Download from web to file
            LoadToolbarConfig
            
            ' Download from file
            Open g_strConfigFile For Binary As #1
            Get #1, , varTemp
            Close #1
            byteArr = varTemp
            If UBound(byteArr) > LBound(byteArr) Then
                initToolbarOpt.Contents = byteArr
            End If
            Set varTemp = Nothing
            
            BuildToolbarFromOptions initToolbarOpt
    
            If initToolbarOpt.ReadProperty("PopupBlocker") = 1 Then
                bBlockPopup = True
            Else
                bBlockPopup = False
            End If
    
        End If
    End If
    Exit Sub
    
error_handler:
    MsgBox Err.Description, vbCritical, "Timer1_Timer()"
End Sub

Private Sub OpenPopupWindow(ByVal strURL As String, ByVal strTitle As String, ByVal iWidth As Long, ByVal iHeight As Long)
    Dim a As String

    ' Delete old file
    On Error Resume Next
    Kill App.Path & "\popup.htm"
    On Error GoTo 0

    ' Make new popup file
    Open App.Path & "\popuptemplate.htm" For Binary As #1
    a = StrConv(InputB(LOF(1), 1), vbUnicode)
    Close #1
    
    ' Replace templates in setup file
    a = Replace(a, "[POPUPURL]", strURL)
    a = Replace(a, "[POPUPTITLE]", strTitle)
    a = Replace(a, "[POPUPWIDTH]", iWidth)
    a = Replace(a, "[POPUPHEIGHT]", iHeight)

    Open App.Path & "\popup.htm" For Binary As #1
    Put #1, , a
    Close #1
     
    wbrPopupWindow.navigate App.Path & "\popup.htm"
End Sub

Private Sub RotateAd()
    On Error Resume Next
    
    Dim btn As MSComctlLib.Button

    If initToolbarOpt.ReadProperty("AdStatic") Then
        g_iCurrentAd = g_iCurrentAd + 1
    
        If g_iCurrentAd > initToolbarOpt.ReadProperty("Ads") Then
            g_iCurrentAd = 1
        End If
    
        Set frmMain.tlbAds.ImageList = Nothing
        Set frmMain.tlbAds.HotImageList = Nothing
        frmMain.ilsAds.ListImages.Clear
        frmMain.ilsAdsHot.ListImages.Clear
        frmMain.tlbAds.Buttons.Clear
    
        frmMain.ilsAds.ListImages.Add 1, , initToolbarOpt.ReadProperty("Ad" & g_iCurrentAd & "ImagePict")
        frmMain.ilsAdsHot.ListImages.Add 1, , initToolbarOpt.ReadProperty("Ad" & g_iCurrentAd & "ImageOverPict")
        
        Set frmMain.tlbAds.ImageList = frmMain.ilsAds
        Set frmMain.tlbAds.HotImageList = frmMain.ilsAdsHot
        Set btn = frmMain.tlbAds.Buttons.Add(, "ad", , tbrDefault, 1)
        btn.ToolTipText = initToolbarOpt.ReadProperty("Ad" & g_iCurrentAd & "Caption")
        btn.Caption = initToolbarOpt.ReadProperty("Ad" & g_iCurrentAd & "Caption")
        If Len(btn.Caption) > 0 Then
            tlbAds.TextAlignment = tbrTextAlignRight
        Else
            tlbAds.TextAlignment = tbrTextAlignBottom
        End If
        tlbMain.Buttons("adplaceholder").Width = tlbAds.Buttons(1).Width + 50
        Form_Resize
    Else
        wbrAds.Refresh
    End If
End Sub

Private Sub tlbTools_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    'frmMain.SetFocus
End Sub

Private Sub tmrRotateAds_Timer()
        
    
    g_iMinutesCount = g_iMinutesCount + 1
    
    SaveSetting "IEToolbar", "Update", "Minutes Count", CStr(g_iMinutesCount)
    
    If g_iMinutesCount >= initToolbarOpt.ReadProperty("AdsRotateTime") Then
        If initToolbarOpt.ReadProperty("AdsRotationByTime") Then
            RotateAd
            g_iMinutesCount = 0
            SaveSetting "IEToolbar", "Update", "Minutes Count", "0"
        End If
    End If
End Sub

Private Sub wbrAds_DocumentComplete(ByVal pDisp As Object, url As Variant)
    On Error Resume Next
    wbrAds.document.Write g_strAdWebButtonCode
    Set m_AdButtonDocument = wbrAds.document
End Sub

