'include "..\..\include\SkinAPI.vbs"

Dim cxClient
Dim cyClient
Dim SC_MINIMIZE 
Dim SC_MAXIMIZE
Dim SC_CLOSE 
Dim SC_RESTORE 
Dim SS_RESTORED
Dim SS_MINIMIZED
Dim SS_MAXIMIZED
Dim rand
Dim Tabs()
Dim TabCount
Dim NextTabID
Dim ActiveTabID
Dim IsTabbarOnTop '0为tab在下,1为tab在上
Dim ShowSidebar
Dim ShowFindbar
Dim bShowSearchBar
Dim SidebarWidth
Dim IsTabwidthStable
Dim TabItemMaxWidth
Dim FirstItemIndex
Dim ShowPluginBar
Dim ShowPluginHost
Dim IsTabItemShowCloseBtn
Dim IsActiveTabBoldFont
Dim AutoAdjustActiveTabItem
Dim IsWindowMaxmized
Dim IsTabBarShowNewBtn
Dim IsShowLinkBar
Dim IsShowFavBar
Dim IsHighLightDown
Dim IsSidebarFloat
Dim MinSideBarWidth
Dim MaxSideBarWidth
Dim IsFullScreenMode
Dim BrowserBarWidth
Dim ShowTabMovePicSrcId
Dim ShowTabMovePicTgtId
Dim ShowTabMovePicDirection
Dim ShouldHideTabMovePic
Dim IsTabItemShowCloseBtnOnMouseOver
Dim IsMouseEnterTab
Dim	MouseEnterTabNumber
Dim	FavLinkLabelColor
Dim ShowWebPagebar
Dim nMBrowserTop

Dim IsHideSomeBtnsFromRToolBar


sub WindowLayOut()	
	Window.LockPaint()
	
	call RelayoutToolbar(toolbar)
	
'	Dim SizeTop
'	SizeTop = 0
    if IsFullScreenMode = 0 then
		MaxWndToolBtns.visible = false
	    ' 标题栏
	    CaptionBar.width = cxClient
	    CaptionRightCorner.Left = cxClient - CaptionRightCorner.width
	    CaptionStretch.width = cxClient - CaptionLeftCorner.width - CaptionRightCorner.width + 2

	    CaptionBarBtns.left = cxClient - CaptionBarBtns.width
	    Caption.width = CaptionBarBtns.Left - Caption.left

	    '窗口在最大化和普通两个时刻, 左右上角的图片不一样.
	    If(IsWindowMaxmized = true) Then
		    CaptionLeftCorner.image="topleftcornerBlack.bmp"
		    CaptionRightCorner.image="toprightcornerBlack.bmp"
    '		btnCaptionClose.image="close1_wndmax.bmp"
    '		btnCaptionClose.hoverimage="close2_wndmax.bmp"
    '		btnCaptionClose.downimage="close3_wndmax.bmp"
	    Else
		    CaptionLeftCorner.image="topleftcorner.bmp"
		    CaptionRightCorner.image="toprightcorner.bmp"
    '		btnCaptionClose.image="close1.bmp"
    '		btnCaptionClose.hoverimage="close2.bmp"
    '		btnCaptionClose.downimage="close3.bmp"
	    End if

    	
		'StatusBar.height = 23

	    ' 边框
'	    BKLeft.height = cyClient - 30
	    BKRight.left = cxClient - BKRight.width
'	    BKRight.height = BKLeft.height
	    BKMiddle.Left = BKLeft.Width
'	    BKMiddle.height = BKLeft.height
	    BKMiddle.width = cxClient - BKLeft.width - BKRight.width
	    BKBottom.top = cyClient - 1
	    BKBottom.width = cxClient
		TabRebarSepLine.width = cxClient - 2
	'	TabRebarSepLine.left = BKLeft.left	

	    'BorderLeft.height = cyClient
	    'BorderRight.left = cxClient - BorderRight.width
	    'BorderRight.height = BorderLeft.height
	    'BorderBottom.top = cyClient - BorderBottom.height
	    'BorderBottom.width = cxClient

    	
    '	SizeTop = CaptionBar.height
	    'Rebar
	    'Rebar.top = SizeTop
	    'Rebar.left = 1
	    'Rebar.width =  cxClient - 2

	    'Rebar Element
    '	toolbarbk.left = Rebar.left - 1
    '	toolbarbk.width = Rebar.width
	    'toolbar.left = Rebar.left + 5

	    if(bShowSearchBar = 1) then
		    SearchBar.Visible = true
		    SearchBarDlg.Visible = true
		    'SearchBar.left = Rebar.width - SearchBar.width  - 3
		    SearchBorderIMG.width = SearchBar.width - HighLightButton.width - SearchBorderLeft.Left - SearchBorderLeft.width - 2
		    SearchBorderRight.left = SearchBar.width - HighLightButton.width - 2
		    SearchBarDlg.width = SearchBar.width - SearchButton.width - HighLightButton.width - SearchBorderLeft.Left - SearchBorderLeft.width - 2
		    SearchButton.left = SearchBar.width - SearchButton.width - HighLightButton.width - 2
		    HighLightButton.left = SearchBar.width - HighLightButton.width 
		    'AddressBar.left = toolbar.width 
		    'AddressBar.width = SearchBar.left - Addressbar.left - 9
		    AddrBorderIMG.width = AddressBar.width  - (AddrBorderLeft.left+AddrBorderLeft.Width)
		    AddrBorderRight.left = AddressBar.width - 1
		    AddrssCombo.width = AddressBar.width - GoButton.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - AddrBorderRight.width
		    GoButton.left = AddressBar.width - GoButton.width - 1
	    else
		    SearchBar.Visible = false
		    SearchBarDlg.Visible = false

		    'AddressBar.left = toolbar.width 
		    'AddressBar.width = Rebar.width - Addressbar.left - 9
		 '   AddrBorderIMG.width = AddressBar.width - 2
		 '   AddrBorderRight.left = AddressBar.width - 1
		 '   AddrssCombo.width = AddressBar.width - GoButton.width  - 2
		 '   GoButton.left = AddressBar.width - GoButton.width - 1
		    AddrBorderIMG.width = AddressBar.width  - (AddrBorderLeft.left+AddrBorderLeft.Width)
		    AddrBorderRight.left = AddressBar.width - 1
		    AddrssCombo.width = AddressBar.width - GoButton.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - AddrBorderRight.width
		    GoButton.left = AddressBar.width - GoButton.width - 1
	    end if


	    IF (ShowPluginBar = 1) Then
		    BtnPluginCont.visible = True
		    BtnPluginBar.width = BtnPluginCont.width-BtnPluginBar.left
	    ELSE
		    BtnPluginCont.Visible = False
	    END If

    	
	    IF (ShowPluginHost = 1) THEN
		    PluginHostCont.Visible = True
		    PluginHost.width = PluginHostCont.width - PluginHost.left
	    ELSE
		    PluginHostCont.Visible = False
	    END If
    	
		RelayeroutPlugins()

	    'linkbar
	    If(IsShowLinkBar) Then
		    LinkBar.visible=true
    '		LinkBar.Left = Rebar.Left
    '		LinkBar.width = Rebar.width
    '		LinkBar.top = SizeTop-2
		    AdjustLinkBar()
	    Else
		    LinkBar.visible=false
	    End If
    	
	    'searchbar
	    If(IsHighLightDown) Then
		    HighLightButton.image = "btnHighlightselect.png"
		    HighLightButton.hoverImage = "btnHighlightselect_over.png"	
		    HighLightButton.downImage = "btnHighlightselect_down.png"			
	    Else
		    HighLightButton.image = "btnHighlight.png"
		    HighLightButton.hoverImage = "btnHighlight_over.png"	
		    HighLightButton.downImage = "btnHighlight_down.png"		
	    End If	
	    'Favbar
	    If(IsShowFavBar) Then
		    FavBar.visible=true
		    AdjustFavBar()
	    Else
		    FavBar.visible=false
	    End if


	    'StatusBar
	    StatusBar.height = 23
	    StatusBar.left = 1
	    StatusBar.width = cxClient - 2
	    StatusBar.top = cyClient - StatusBar.height - 1
	    
	    StatusBarTopLine.top = StatusBar.top
	    StatusBarTopLine.width = StatusBar.width

		StatusBarLeft.left = 0
		StatusBarLeft.top = StatusBar.top
		StatusBarRight.left = StatusBar.width + StatusBar.left - StatusBarRight.width + 1
		StatusBarRight.top = StatusBar.top
		StatusBarBK.top = StatusBar.top
		StatusBarBK.left = StatusBarLeft.left + StatusBarLeft.width
		StatusBarBK.width = StatusBar.width - StatusBarLeft.width - StatusBarRight.width + 2
	
		'Tab
	    StatusBar.top = cyClient -  StatusBar.height -  1
	    if(IsTabbarOnTop = 0) Then
			TabRebarSepLine.left = 1
			TabRebarSepLine.width = cxClient - 2
            TabRebar.top = StatusBar.top - TabRebar.height  
			TabRebarSepLine.image = "Tab/tabBK0-1.png"	
			TabRebarSepLine.top = 0		
		    TabBar.top = 2
		    AllTabs.top = 1
		    btnSidebar.top = 2
		    btnNewAPage.top = 2
		    RToolbar.top = 3
		    'RMovebar.top = 3
		    btnMoveBack.top = 5
		    btnMoveFor.top = 5
			btnTextMode.top = 3
		    btnNewPage.top = 3
		    btnNewPageSelect.top = 3
		    btnBack.top = 3
		    btnBackSelect.top = 3
		    btnClose.top = 3
		    'TabbarMakeupBk.top = 1
		    'BtnPluginBarLine.visible = true
		    'BtnPluginBarLine.top = SizeTop + 1
		    'SizeTop = SizeTop + 1
		    'BtnPluginBarLine.width = cxClient
		    'BtnPluginBarLine.visible = false

		    if(TabRebar.top > (Window.ReBarBottom-1)) Then
			    MainArea.height = TabRebar.top - Window.ReBarBottom - 1		
		    Else
			    MainArea.height = 0		
		    End if
            MainArea.top = Window.ReBarBottom + 1
			
			TabRebarBKRight.visible = true
			TabRebarBKMiddle.visible = true
			TabRebarBKLeft.visible = true
			TabRebarBKRight.left = cxClient - TabRebarBKRight.width
			TabRebarBKMiddle.left = TabRebarBKLeft.width
			TabRebarBKMiddle.width = cxClient - BKLeft.width - BKRight.width	
		
	    Else
			TabRebarSepLine.left = 1
			TabRebarSepLine.width = cxClient - 2	
		    TabRebar.top =  Window.ReBarBottom + 1
			TabRebarSepLine.top = 0	
			TabRebarSepLine.image = "Tab/tabBK0.png"			
		    AllTabs.top = 2
		    TabBar.top = 2
		    btnSidebar.top = 2
		    btnNewAPage.top = 2	
		    RToolbar.top = 5
		    'RMovebar.top = 5
		    btnMoveBack.top = 5
		    btnMoveFor.top = 5
			btnTextMode.top = 3
		    btnNewPage.top = 3
		    btnNewPageSelect.top = 3
		    btnBack.top = 3
		    btnBackSelect.top =3
		    btnClose.top = 3
		    'TabbarMakeupBk.top = 0		
		    MainArea.top = TabRebar.top + TabRebar.height 
		    MainArea.height = StatusBar.top - MainArea.top
			TabRebarBKRight.visible = false
			TabRebarBKMiddle.visible = false
			TabRebarBKLeft.visible = false
    '		BtnPluginBarLine.image = "BtnPluginLine_tabtop.BMP"
	    End if

		MainAreaBKLeft.top = MainArea.top 
		MainAreaBKRight.top = MainArea.top		
		MainAreaBKLeft.height = MainArea.Height		
		MainAreaBKRight.height = MainArea.Height	
		MainAreaBKRight.left = cxClient - MainAreaBKRight.width
		
		BKLeft.height = MainArea.top
		BKRight.height  = BKLeft.height
		BKMiddle.height = BKLeft.height 
		
	    'MBrowser.height = MainArea.height
		AjustBrowserHeight()
	    TabRebar.width = cxClient
	    RToolbar.left = cxClient - 2  - RToolbar.width 
	    'RMovebar.left = RToolbar.left - RMovebar.width - 2

	    TabBar.left = 1
	    'if(RMovebar.visible = 1) Then
		 '   TabBar.width =  RMovebar.left - TabBar.left' - 20
	    'Else
		    TabBar.width =  RToolbar.left - TabBar.left' - 20	
	    'End if
    	
	    btnSidebar.left = TabBar.left -1
	    btnSidebar.width = 24
	    btnNewAPage.width = 24
	    AllTabs.Left = btnSidebar.Left + btnSidebar.width + 2
    	
	    btnNewAPage.left = AllTabs.left + AllTabs.width
	    'TabbarMakeupBk.left = btnNewAPage.left
	    'TabbarMakeupBk.width = 200
	    SetTabBarNoMessage()		
    	
	    'MainArea
	    MainArea.left = 1	
	    MainArea.width = cxClient - 2
	    if(ShowSidebar = 0) Then
		    SideRebar.visible = False
		    MBrowser.left = 0
		    'MBrowser.top = 0
		    MBrowser.width = MainArea.width
		    'MBrowser.height = MainArea.height
			AjustBrowserHeight()
	    Elseif(ShowSidebar = 1) Then
		    SideRebar.visible = True
		    SideRebar.left = 0
		    SideRebar.top = 0
		    SideRebar.width = SidebarWidth
		    SideRebar.height = MainArea.height	
		    if(IsSidebarFloat = 1) Then
			    MBrowser.left = 7
			    'MBrowser.top = 0
			    MBrowser.width = MainArea.width - 7
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    Else	
			    MBrowser.left = SidebarWidth
			    'MBrowser.top = 0
			    MBrowser.width = MainArea.width - SidebarWidth
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    End if
    		
	    Else
		    SideRebar.visible = True		
		    SideRebar.left = 0
		    SideRebar.top = 0		
		    SideRebar.width = 7
		    SideRebar.height = MainArea.height
		    if(IsSidebarFloat = 1) Then
			    MBrowser.left = 7
			    'MBrowser.top = 0
			    MBrowser.width = MainArea.width - 7
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    Else	
			    MBrowser.left = 7
			    'MBrowser.top = 0		
			    MBrowser.width = MainArea.width - 7
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    End if			
	    End IF    


	    if(IsTabbarOnTop = 0) Then
			If(StatusBar.top < TabRebar.top + TabRebar.height) Then
				StatusBar.visible = False
				StatusBarTopLine.visible = False
				StatusBarLeft.visible = False
				StatusBarBK.visible = False
				StatusBarRight.visible = False
			Else
				StatusBar.visible = true
				StatusBarTopLine.visible = true
				StatusBarLeft.visible = true
				StatusBarBK.visible = true
				StatusBarRight.visible = true
			End If
		Else 
			If(StatusBar.top < MainArea.top + MainArea.height) Then
				StatusBar.visible = False
				StatusBarTopLine.visible = False
				StatusBarLeft.visible = False
				StatusBarBK.visible = False
				StatusBarRight.visible = False
			Else
				StatusBar.visible = true
				StatusBarTopLine.visible = true
				StatusBarLeft.visible = true
				StatusBarBK.visible = true
				StatusBarRight.visible = true
			End If
		End if

    else
		MaxWndToolBtns.visible = true
	    MaxWndToolBtns.top = -1
	    MaxWndToolBtns.left = cxClient - 90
	    MaxWndToolBtns.width = 90
	    MaxWndToolBtns.Height = 34
		
	    CaptionLeftCorner.image="topleftcornerBlack.bmp"
		CaptionRightCorner.image="toprightcornerBlack.bmp"
		
		TabRebarSepLine.image = "Tab/tabBK0.png"		
	    TabRebarSepLine.left = 0
	    toolbar.visible = true
		browsertoolbar.visible = true
	    AddressBar.visible = true
	    SearchBar.visible = true
	    MainArea.visible = true
	    TabRebar.visible = true
	    BKWind.visible = true
	    BKLeft.visible = true
	    BKMiddle.visible = true
	    BKRight.visible = true
	    
	    BtnPluginCont.visible = false
	    LinkBar.visible = false
	    FavBar.visible = false
	    StatusBar.visible = false
		PluginHostCont.visible = false
		TabRebarBKRight.visible = false
		TabRebarBKMiddle.visible = false
		TabRebarBKLeft.visible = false
		
        BKWind.left = 0
        BKWind.top = 0
        
        BKLeft.left = 0
        BKLeft.top = 0
        
        BKMiddle.left = BKLeft.width
        BKMiddle.top = 0
        BKMiddle.width = cxClient - BKLeft.width - BKRight.width
        
        BKRight.top = 0
        BKRight.left = cxClient - BKRight.width
        
	    toolbar.top = 0
	    toolbar.left = 0
	    'toolbar.width = 153
	    'toolbar.Height = 34

	    browsertoolbar.top = 0
	    browsertoolbar.left = toolbar.left + toolbar.width
	    'browsertoolbar.width = BrowserBarWidth
	    'browsertoolbar.Height = 34
	    
	    AddressBar.top = 4
	    AddressBar.left = browsertoolbar.left + browsertoolbar.width
	    AddressBar.width = cxClient - (browsertoolbar.left + browsertoolbar.width) - 178 - (MaxWndToolBtns.width + 5)
	    'AddressBar.Height = 26
	    
	    SearchBar.top = 4
	    SearchBar.left = AddressBar.left + AddressBar.width
	    SearchBar.width = 178
	    'SearchBar.Height = 26
	    
	    TabRebar.top = toolbar.Height
	    TabRebar.left = 1
	    TabRebar.width = cxClient
	    TabRebar.Height = 32
	    
	    MainArea.top = toolbar.Height + TabRebar.Height
	    MainArea.left = 0
	    MainArea.width = cxClient
	    MainArea.Height = cyClient - MainArea.top 
		
    
	    SearchBorderIMG.width = SearchBar.width - HighLightButton.width - SearchBorderLeft.Left - SearchBorderLeft.width - 2
	    SearchBorderRight.left = SearchBar.width - HighLightButton.width - 2 
	    SearchBarDlg.width = SearchBar.width - SearchButton.width - HighLightButton.width - SearchBorderLeft.Left - SearchBorderLeft.width - 2
	    SearchButton.left = SearchBar.width - SearchButton.width - HighLightButton.width - 2
	    HighLightButton.left = SearchBar.width - HighLightButton.width 
	    AddrBorderIMG.width = AddressBar.width  - (AddrBorderLeft.left+AddrBorderLeft.Width)
	    AddrBorderRight.left = AddressBar.width - 1
	    AddrssCombo.width = AddressBar.width - GoButton.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - AddrBorderRight.width
	    GoButton.left = AddressBar.width - GoButton.width - 1
 
	    	
	    'searchbar
	    If(IsHighLightDown) Then
		    HighLightButton.image = "btnHighlightselect.png"
		    HighLightButton.hoverImage = "btnHighlightselect_over.png"	
		    HighLightButton.downImage = "btnHighlightselect_down.png"			
	    Else
		    HighLightButton.image = "btnHighlight.png"
		    HighLightButton.hoverImage = "btnHighlight_over.png"	
		    HighLightButton.downImage = "btnHighlight_down.png"		
	    End If	
	
	    'Tab
		TabRebarSepLine.width = cxClient - 2
        AllTabs.top = 2
        TabBar.top = 2
        btnSidebar.top = 0
        btnNewAPage.top = 0	
        RToolbar.top = 3
        'RMovebar.top = 3
        btnMoveBack.top = 5
        btnMoveFor.top = 5
		btnTextMode.top = 5
        btnNewPage.top = 5
        btnNewPageSelect.top = 5
        btnBack.top = 5
        btnBackSelect.top =5
        btnClose.top = 5
	    'MBrowser.height = MainArea.height
		AjustBrowserHeight()
	    RToolbar.left = cxClient - 2  - RToolbar.width 
	    'RMovebar.left = RToolbar.left - RMovebar.width - 2

	    TabBar.left = 1
	    'if(RMovebar.visible = 1) Then
		'    TabBar.width =  RMovebar.left - TabBar.left' - 20
	    'Else
		    TabBar.width =  RToolbar.left - TabBar.left' - 20	
	    'End if
    	
	    btnSidebar.left = TabBar.left -1
	    btnSidebar.width = 24
	    btnNewAPage.width = 24
	    AllTabs.Left = btnSidebar.Left + btnSidebar.width + 2
    	
	    btnNewAPage.left = AllTabs.left + AllTabs.width
	    'TabbarMakeupBk.left = btnNewAPage.left
	    'TabbarMakeupBk.width = 200	
	    SetTabBarNoMessage()	
    	
	    'MainArea
	    If(ShowSidebar = 0) Then
		    SideRebar.visible = False
		    MBrowser.left = 0
		    'MBrowser.top = 0
		    MBrowser.width = MainArea.width
		    'MBrowser.height = MainArea.height
			AjustBrowserHeight()
	    Elseif(ShowSidebar = 1) Then
		    SideRebar.visible = True
		    SideRebar.left = 0
		    SideRebar.top = 0
		    SideRebar.width = SidebarWidth
		    SideRebar.height = MainArea.height	
		    if(IsSidebarFloat = 1) Then
			    MBrowser.left = 8
			    'MBrowser.top = 0
			    MBrowser.width = MainArea.width - 8
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    Else	
			    MBrowser.left = SidebarWidth
			    'MBrowser.top = 0
			    MBrowser.width = MainArea.width - SidebarWidth
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    End if
    		
	    Else
		    SideRebar.visible = True		
		    SideRebar.left = 0
		    SideRebar.top = 0		
		    SideRebar.width = 8
		    SideRebar.height = MainArea.height
		    if(IsSidebarFloat = 1) Then
			    MBrowser.left = 8
			    'MBrowser.top = 0
			    MBrowser.width = MainArea.width - 8
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    Else	
			    MBrowser.left = 8
			    'MBrowser.top = 0		
			    MBrowser.width = MainArea.width - 8
			    'MBrowser.height = MainArea.height		
				AjustBrowserHeight()
		    End if			
	    End IF       
    end if




	Window.UnLockPaint()
end sub	
'

Sub AjustBrowserHeight()
	nMBrowserTop = 0
	
	if(ShowWebPagebar = 0)then
		WebPageBar.visible = false
	else
		WebPageBar.visible = true
		WebPageBar.top = nMBrowserTop 
		WebPageBar.left = MBrowser.left
		WebPageBar.width = MBrowser.width
		
		Set data = Window.CreateTTData	
		WebPageBarWidth = CInt(WebPageBar.width)
		data.SetDWord "dwWebPageBarWidth" , WebPageBarWidth
		window.ExeCommand 70250 , data
		WebPageBarHeight = data.GetDWord("dwWebPageBarHeight")
		WebPageBar.height = WebPageBarHeight
		nMBrowserTop = nMBrowserTop + WebPageBar.height
	end if
	MBrowser.top = nMBrowserTop
	MBrowser.height = MainArea.height - nMBrowserTop	
	
end sub	

Sub Window_OnShowStateChange(nCmdShow)

	ChangeTabsUI()	
	If nCmdShow = SS_RESTORED Then
		btnCaptionRestore.visible = false
		btnCaptionMax.visible = True
	elseIf nCmdShow = SS_MAXIMIZED Then
		btnCaptionRestore.visible = true
		btnCaptionMax.visible = False
	End If
End Sub



sub Window_WindowLayOut(cx, cy, wndState)
	cxClient = cx
	cyClient = cy
	If(wndState = SS_RESTORED) Then
		IsWindowMaxmized = false
	ElseIf (wndState = SS_MAXIMIZED) Then
		IsWindowMaxmized = true
	End if
	WindowLayOut()	
end Sub

sub Window_OnSwitchCurrentSkin(varParam)
	FavLinkLabelColor = varParam.GetStr("strFavLinkLabelColor")
	Window.ExeCommand 45002 , 0	
	AdjustFavBar()
	AdjustLinkBar()
end Sub

Sub Window_OnInit()
	TextMode = 0
	window.minWidth = 600
	window.minHeight = 200
	SC_MINIMIZE				= 61472
	SC_MAXIMIZE				= 61488
	SC_CLOSE				= 61536
	SC_RESTORE				= 61728
	SS_RESTORED				= 0
	SS_MINIMIZED			= 1
	SS_MAXIMIZED			= 2
	rand = 0
	IsTabbarOnTop = 1
	ShowSidebar = 0
	SidebarWidth = 214
	MinSideBarWidth = 192
	MaxSideBarWidth = 600
	
	IsTabwidthStable = 0
	TabItemMaxWidth = 155
	FirstItemIndex = 0
	IsSidebarFloat = 1
	bShowSearchBar = 1
	IsFullScreenMode = 0

	ShowPluginBar = 0
	ShowPluginHost = 0
	IsTabItemShowCloseBtn = 1
	IsActiveTabBoldFont = 0
	AutoAdjustActiveTabItem = 1	
	IsTabBarShowNewBtn = 1	

	bShowSearchBar = 0
	IsShowLinkBar = false
	IsShowFavBar = false
	IsHighLightDown = False
	
	ShowTabMovePicSrcId = "InvalidTabItemId"
	ShowTabMovePicTgtId = "InvalidTabItemId"	
	ShowTabMovePicDirection = 0
	ShouldHideTabMovePic = 0	
	
	BrowserBarWidth = browsertoolbar.width
	
	IsTabItemShowCloseBtnOnMouseOver = 0
	IsMouseEnterTab	= 0	
	InsertMark.Visible = FALSE
	FavLinkLabelColor = "#000000"
	ShowWebPagebar = 0
	IsHideSomeBtnsFromRToolBar = 0
End Sub

Sub Window_OnNotify(code ,var)

	call WindowNotify( code , var)
	
		if (code =  1) then
			FirstRebar.height = var
		Elseif(code = 2) Then    '增加了tab后调整宽度
			ChangeTabsUI()
		Elseif(code = 45000) Then
			btnCaptionMax_onClick()
		Elseif(code = 65000) Then
			TabCount = var
		Elseif(code = 65001) Then
			NextTabID = var
		Elseif(code = 65002) Then		
			ActiveTabID = var
		ElseIf(code = 65101) Then                       '关闭全部button
			For i = 0 To AllTabs.ChildCount-2
				NameTabContain = "TabContain" + CStr(i)
				AllTabs.ChildById(NameTabContain).Visible = 0
			Next			
			ChangeTabsUI()
		Elseif(code = 65102) Then ' change tab postion bottom
			IsTabbarOnTop = 1		
			ChangeTabsUI()
		Elseif(code = 30000) Then
			ShowSidebar = var
			WindowLayOut()
'		Elseif(code = 70000) Then
'			ShowFindbar = var
'			WindowLayOut()
'		Elseif(code = 70001) Then
'			btnFindResult.Label = var
'			WindowLayOut()

		Elseif(code = 70200) Then
			WebPageBarVisible = CInt(var.GetDWord("dwWebPageBarVisible"))
			ShowWebPagebar = WebPageBarVisible			
			WindowLayOut()
		Elseif(code = 70210) Then
			WebPageBarVisible = CInt(var.GetDWord("dwWebPageBarVisible"))
			ShowWebPagebar = WebPageBarVisible			
			WindowLayOut()	
		
		Elseif(code = 30009) Then
			ShowSidebar = 1
			WindowLayOut()
		Elseif(code = 30001)Then
			ShowPluginBar = var
			WindowLayOut()
		Elseif(code = 30019)Then
			bShowSearchBar = var
			WindowLayOut()

		Elseif(code = 30020)Then
			If(var = 0) Then
				HideMenuBar()
			Else
				ShowMenuBar()
			End if

		Elseif(code = 30002) Then
			Caption.value = var
		'总是打开新窗口
		Elseif(code = 30003) Then
			If(IsHideSomeBtnsFromRToolBar = 0) Then
			if(var = 0) Then
				btnNewPage.visible = true
				btnNewPageSelect.visible = false
			Else
				btnNewPage.visible = false
				btnNewPageSelect.visible = true
			End if
			End If
		'总是在后台打开新窗口
		Elseif(code = 30004) Then
			if(var = 0) Then
				btnBack.visible = true
				btnBackSelect.visible = false
			Else
				btnBack.visible = false
				btnBackSelect.visible = true
			End if
		Elseif(code = 30005) Then
			Window.ExeCommand 1000 , IsTabbarOnTop	
		Elseif(code = 30006) Then
			If(IsHideSomeBtnsFromRToolBar = 0) Then
			btnNewPage.visible = false
			btnNewPageSelect.visible = true
			End If
			Window.ExeCommand 117 , var				
			btnBack.visible = false
			btnBackSelect.visible = true
			Window.ExeCommand 119 , var
		Elseif(code = 65103) Then ' change tab postion top
			IsTabbarOnTop = 0					
			ChangeTabsUI()
		Elseif(code = 65104) Then			
			if(IsTabwidthStable <> var) Then
				IsTabwidthStable = var
				AdjustTabToolBar()
				ChangeTabsUI()				
			End if
		Elseif(code = 65105) Then
			if(TabItemMaxWidth <> var) Then
				TabItemMaxWidth = var
				ChangeTabsUI()
			End if
		Elseif(code = 65106) Then
			if(IsTabItemShowCloseBtn <> var) Then
				IsTabItemShowCloseBtn = var
				ChangeTabsUI()
			End if		
		Elseif(code = 65107) Then
			if(IsActiveTabBoldFont <> var) Then
				IsActiveTabBoldFont = var
				ChangeTabsUI()
			End if
		Elseif(code = 65108) Then
			if(IsTabBarShowNewBtn <> var) Then
				IsTabBarShowNewBtn = var
				btnNewAPage.visible = IsTabBarShowNewBtn
				ChangeTabsUI()
			End if
		Elseif(code = 65109) Then
			IsTabItemShowCloseBtnOnMouseOver = var				
		Elseif(code >= 53000 and code <= 54999) Then    '关闭button	
			NameTabContain = "TabContain" + CStr(code - 53000)
			AllTabs.ChildById(NameTabContain).Visible = 0
			ChangeTabsUI()
		Elseif(code >= 55000 and code <= 56999) Then    'SetDefIcon
			NameTabContain = "TabContain" + CStr(code - 55000)
			TabName = "TabItem"+CStr(code - 55000)
			AllTabs.ChildById(NameTabContain).ChildById(TabName).Ico = var
			WindowLayOut()				
		Elseif(code >= 57000 and code <= 58999) Then	'SetText
			NameTabContain = "TabContain" + CStr(code - 57000)
			TabName = "TabItem"+CStr(code - 57000)
			AllTabs.ChildById(NameTabContain).ChildById(TabName).Label = var
			AllTabs.ChildById(NameTabContain).ChildById(TabName).Tip = var
			WindowLayOut()		
		Elseif(code >= 59000 and code <= 60999) Then    'SetIcon
			NameTabContain = "TabContain" + CStr(code - 59000)
			TabName = "TabItem"+CStr(code - 59000)
			AllTabs.ChildById(NameTabContain).ChildById(TabName).IcoAbsolutePath = var
			WindowLayOut()			
		Elseif(code >= 61000 and code <= 62999) Then    'ActiveButton
			NameTabContain = "TabContain" + CStr(code - 61000)
			TabName = "TabItem"+CStr(code - 61000)				
			ChangeTabsUI()
		Elseif(code >= 63000 and code <= 64999) Then    'ActiveButton
			NameTabContain = "TabContain" + CStr(code - 63000)
			AllTabs.ChildById(NameTabContain).Visible = 1
			ChangeTabsUI()		
		ElseIf(code = 30007) Then
			If(var = 1) Then
				btnNavBack.disabled = False
			Else
				btnNavBack.disabled = True
			End if
		elseif(code = 30053) then
			OnDropTest(var)
		elseif(code = 30055) then
			OnGetItemRect(var)
		elseif(code = 30131) then
			SetInsertMark(var)
		ElseIf(code = 30008) Then
			If(var = 1)Then
				btnNavForward.disabled = False
			Else
				btnNavForward.disabled = True
			End if
		ElseIf(code = 30010) Then
			If(var = 1)Then
				btnNavList.disabled = False
			Else
				btnNavList.disabled = True
			End if
		ElseIf(code = 30011) Then
			If(var = 1)Then
				btnLastNav.disabled = False
				btnLastNavList.disabled = False
			Else
				btnLastNav.disabled = True
				btnLastNavList.disabled = True
			End If

		'-------------------------------------linkbar----------------------------------------
		ElseIf(code = 30024) Then
			AdjustLinkBar()
		ElseIf(code = 30025) Then
			if LinkBar.visible = true then
				itemIndex = var.GetDWord("dwLinkBarItemIndex")
				ItemName = "LinkItem"+CStr(itemIndex)
				var.SetDWord "dwLinkBarItemLeft", LinkItemCont.ChildById(ItemName).Clientleft
				var.SetDWord "dwLinkBarItemRight", LinkItemCont.ChildById(ItemName).Clientleft + LinkItemCont.ChildById(ItemName).Width
				var.SetDWord "dwLinkBarItemTop", LinkItemCont.ChildById(ItemName).ClientTop
				var.SetDWord "dwLinkBarItemBottom", LinkItemCont.ChildById(ItemName).ClientTop + LinkItemCont.ChildById(ItemName).Height
			end if
		ElseIf(code = 30026) Then
			childCount = LinkItemCont.ChildCount
			Dim i
			For i = 0 To childCount-1	
				ItemName = "LinkItem"+CStr(i)
				If( LinkItemCont.ChildById(ItemName).visible = false) Then	
					Exit for
				End if
			Next	
			var.SetDWord "dwLinkBarItemsShowedCount", i
		ElseIf(code = 30027) Then
			IsShowLinkBar = True
			WindowLayOut()
		ElseIf(code = 30028) Then
			IsShowLinkBar = False
			WindowLayOut()
		ElseIf(code = 30029) Then
			Window.LockPaint()
		ElseIf(code = 30030) Then
			Window.UnLockPaint()
		'--------------------------------------Plugins-------------------------------
		Elseif(code = 30031) Then
			ShowPlugin "PluginHostCont_" & CStr(var), true
		Elseif(code = 30032) Then
			ShowPlugin "PluginHostCont_" & CStr(var), false
		'--------------------------------------searchbar------------------------------------
		ElseIf(code = 30050) Then
			if(var = 0) then
				IsHighLightDown = false
				WindowLayOut()
			elseif(var = 1) then
				IsHighLightDown = true	
				WindowLayOut()			
			end if
		'---------------------------------------------------------------------------------------

		'-------------------------------------favbar----------------------------------------
		ElseIf(code = 40024) Then
			AdjustFavBar()
		ElseIf(code = 40025) Then
			if FavBar.visible = true then
				itemIndex = var.GetDWord("dwFavBarItemIndex")
				ItemName = "FavItem"+CStr(itemIndex)
				var.SetDWord "dwFavBarItemLeft", FavItemCont.ChildById(ItemName).Clientleft
				var.SetDWord "dwFavBarItemRight", FavItemCont.ChildById(ItemName).Clientleft + FavItemCont.ChildById(ItemName).Width
				var.SetDWord "dwFavBarItemTop", FavItemCont.ChildById(ItemName).ClientTop
				var.SetDWord "dwFavBarItemBottom", FavItemCont.ChildById(ItemName).ClientTop + FavItemCont.ChildById(ItemName).Height
			end if
		ElseIf(code = 40026) Then
			FavChildCount = FavItemCont.ChildCount
			For i = 0 To FavChildCount-1	
				ItemName = "FavItem"+CStr(i)
				If( FavItemCont.ChildById(ItemName).visible = false) Then	
					Exit for
				End if
			Next	
			var.SetDWord "dwFavBarItemsShowedCount", i
		ElseIf(code = 40027) Then
			IsShowFavBar = True
			WindowLayOut()
		ElseIf(code = 40028) Then
			IsShowFavBar = False
			WindowLayOut()
		'---------------------------------------------------------------------------------------

		'如果不是精简版,就隐藏工具栏上的屏幕截屏按钮
		ElseIf(code = 40029) Then
			btnCaptureScreen.visible=false
			browsertoolbar.ExternalAttribute("Width") = 167
			BrowserBarWidth = 167
			WindowLayOut()
		ElseIf(code = 30012) Then
			IsSidebarFloat = var
			WindowLayOut()
		ElseIf(code = 30013) Then	
			ShowSidebar = 0
			Window.ExeCommand 44003 , code			
			WindowLayOut()	
		ElseIf(code = 30014) Then	
			SidebarWidth = SidebarWidth + var
			if(SidebarWidth < MinSideBarWidth) Then
				SidebarWidth = MinSideBarWidth
			ElseIf(SidebarWidth > MaxSideBarWidth) Then
				SidebarWidth = MaxSideBarWidth			
			End if
			WindowLayOut()	
		ElseIf(code = 30016) Then	
			SidebarWidth = var
			WindowLayOut()			
		ElseIf(code = 30017) Then
		    IsFullScreenMode = var
			
		'---------------------------------------------------------------------------------------
		elseif(code = 50006) then
		    ProcessMouseDragMove var	
		elseif(code = 50007) then
		    PorcessMouseDragDrop var					
		ElseIf(code = 50070) Then
		    IsHideSomeBtnsFromRToolBar = var
			AdjustTabToolBar()
		end If
End Sub

Sub ProcessMouseDragMove(varParam)
	ShouldHideTabMovePic = 0
	
	ShowTabMovePicSrcId = varParam.GetStr("strTabbarDragSrcId")
	ShowTabMovePicTgtId = varParam.GetStr("strTabbarDragTgtId")
	ShowTabMovePicDirection = varParam.GetDWord("dwTabbarDragDirection")
	
	srcIndex = CInt(Right(ShowTabMovePicSrcId, Len(ShowTabMovePicSrcId)-7))
	TgtIndex = CInt(Right(ShowTabMovePicTgtId, Len(ShowTabMovePicTgtId)-7))	
	ShowTabMovePicSrcId = "TabContain" & CStr(srcIndex)
	ShowTabMovePicTgtId = "TabContain" & CStr(TgtIndex)
	
	ChangeTabsUI()	
	
End Sub

Sub PorcessMouseDragDrop(varParam)
	ShouldHideTabMovePic = 1
	
	SrcId = varParam.GetStr("strTabbarDragSrcId")
	TgtId = varParam.GetStr("strTabbarDragTgtId")
	xDirection = varParam.GetDWord("dwTabbarDragDirection")
	
	srcIndex = CInt(Right(SrcId, Len(SrcId)-7))
	TgtIndex = CInt(Right(TgtId, Len(TgtId)-7))

	Set data = Window.CreateTTData
	data.SetDWord "dwTabbarDragSrcId_Number", (srcIndex)
	data.SetDWord "dwTabbarDragTgtId_Number", (TgtIndex)
	data.SetDWord "dwTabbarDragDirection", (xDirection)
	
	window.ExeCommand 65005 , data

	ShowTabMovePicSrcId = "InvalidTabItemId"
	ShowTabMovePicTgtId = "InvalidTabItemId"
	ShowTabMovePicDirection	 = 0

	ChangeTabsUI()	


	
End Sub

Sub Window_OnChildCommand( childId, code )
	If(childId = "Window") Then
			window.ExeCommand 65004 , code
	End If
	
	call ProcessLogin( childId, code )
	
	If(code = 7) Then
		SetTabItemCloseInfo3(childId)
	End If
	
	If((childId = "btnNavBack" or childId = "HighLightButton" or childId = "btnNavForward" or childId = "btnNavList" or childId = "btnNavStop" or childId = "btnNavRefresh" or childId = "btnHomePage" or childId = "btnFavorite"	or childId = "btnLastNav" or childId = "btnLastNavList" or childId = "btnCaptureScreen" or childId = "btnClearNavRecord")) Then
	If(code = 1) then 
			window.ExeCommand 65004 , code
		Else
			If(childId = "btnNavBack") Then
				Window.ExeCommand 103 , code	
			ElseIf(childId = "btnNavForward") Then
				Window.ExeCommand 104 , code
			ElseIf(childId = "btnNavStop") Then
				Window.ExeCommand 101 , code
			ElseIf(childId = "btnNavRefresh") Then
				Window.ExeCommand 102 , code
			ElseIf(childId = "btnNavList") Then
				Window.ExeCommand 109 , code
			ElseIf(childId = "btnLastNav") Then
				Window.ExeCommand 113 , code
			ElseIf(childId = "btnHomePage") Then
				Window.ExeCommand 105 , code
			ElseIf(childId = "btnLastNavList") Then
				Window.ExeCommand 115 , code
			ElseIf(childId = "btnQQ") Then
				Window.ExeCommand 150 , code				
			ElseIf(childId = "btnWebList") Then
				Window.ExeCommand 151 , code			
			ElseIf(childId = "btnCapScreen") Then
				Window.ExeCommand 155 , code			
			ElseIf(childId = "GoButton") Then
				Window.ExeCommand 107 , code
			ElseIf(childId = "SearchButton") Then
				Window.ExeCommand 108 , code
			ElseIf(childId = "HighLightButton") Then
				Window.ExeCommand 122 , code				
			ElseIf(childId = "btnFavorite") Then
				Window.ExeCommand 120 , code		
			ElseIf(childId = "btnCaptureScreen") Then
				Window.ExeCommand 121 , code		
			End if
		end if
	ElseIf(childId = "toolbar" or childId = "AddressBar" or childID = "SearchBar" or childID = "LinkBar" or childID = "FavBar") Then
		If(code = 1) then 
			window.ExeCommand 65004 , code
		ElseIf(code = 0) Then
			Window.ExeCommand 65010 , code		
		End if
	ElseIf(childId = "MainMenu") Then
		If(code = 0) then
		   	x = MainMenu.ClientLeft
			y = MainMenu.ClientTop + MainMenu.Height - 1
			a = x * 65536 + y
			Window.ExeCommand 44004 , a	
		End if
	ElseIf(childId = "GoButton") Then
		Window.ExeCommand 107 , code
	ElseIf(childId = "SearchButton") Then
		Window.ExeCommand 108 , code
	ElseIf(childId = "HighLightButton") Then
		Window.ExeCommand 122 , code	
	ElseIf(childId = "btnTextMode") Then 'nioland
		if(code = 0)then
			Set data = Window.CreateTTData
			data.SetDWord "dwRectLeft", (btnTextMode.ClientLeft)
			data.SetDWord "dwRectTop", (btnTextMode.ClientTop)
			data.SetDWord "dwRectWidth", (btnTextMode.width)
			data.SetDWord "dwRectHight", (btnTextMode.height)
	
			Window.ExeCommand 125 , data	
			AdjustTabToolBar()	
		end if
	ElseIf(childId = "btnClose") Then
		Window.ExeCommand 112 , code
	ElseIf(childId = "btnMoveFor") Then
		if((code = 0) AND (IsTabwidthStable > 0)) Then
			if((FirstItemIndex + 1) < TabCount) Then
				AutoAdjustActiveTabItem = 0
				FirstItemIndex = FirstItemIndex + 1			
				ChangeTabsUI()
				AutoAdjustActiveTabItem = 1		
			End if
		End if
	ElseIf(childId = "btnMoveBack") Then
		if((code = 0) AND (IsTabwidthStable > 0)) Then
			if(FirstItemIndex > 0) Then
				AutoAdjustActiveTabItem = 0
				FirstItemIndex = FirstItemIndex - 1		
				ChangeTabsUI()
				AutoAdjustActiveTabItem = 1
			End if				
		End if			
	'总是打开新窗口
	ElseIf(childId = "btnNewPage") Then
		if(code = 0) Then
			If(IsHideSomeBtnsFromRToolBar = 0) Then
			btnNewPage.visible = false
			btnNewPageSelect.visible = true
			End If
			Window.ExeCommand 117 , code				
		End if	
	ElseIf(childId = "btnNewPageSelect") Then
		if(code = 0) Then
			If(IsHideSomeBtnsFromRToolBar = 0) Then
			btnNewPage.visible = true
			btnNewPageSelect.visible = false
			End If
			Window.ExeCommand 116 , code							
		End if
	'总是后台打开新窗口
	ElseIf(childId = "btnBack") Then
		if(code = 0) Then
			btnBack.visible = false
			btnBackSelect.visible = true
			Window.ExeCommand 119 , code
		End if	
	ElseIf(childId = "btnBackSelect") Then
		if(code = 0) Then
			btnBack.visible = true
			btnBackSelect.visible = false
			Window.ExeCommand 118 , code
		End if
	ElseIf(childId = "btnSidebar") Then
		Window.ExeCommand 300 , code
	ElseIf(childId = "btnNewAPage") Then
		Window.ExeCommand 50001 , code
	ElseIf(childId = "TabBar") Then
		If(code = 0) Then
			Window.ExeCommand 65010 , code
		Else
			Window.ExeCommand 65003 , code		
		End if
	ElseIf( (Len(childId) > 7) and (Left(childId, 7) = "TabItem") ) Then
		ChildNumber = CInt(Right(childId, Len(childId)-7))
		nChildId = ChildNumber + 51000
		if(code = 7) Then
			SetTabItemCloseInfo2 ChildNumber	
		End if		
		Window.ExeCommand nChildId , code
	ElseIf( (Len(childId) > 8) and (Left(childId, 8) = "TabClose") ) Then
		nChildId = CInt(Right(childId, Len(childId)-8)) + 53000
		Window.ExeCommand nChildId , code

	'----------LinkBar---------------
	ElseIf( (Len(childId) > 8) and (Left(childId, 8) = "LinkItem") ) Then
		nChildId = CInt(Right(childId, Len(childId)-8)) + 55000  '在55000到56000之间
		Window.ExeCommand nChildId , code
	ElseIf(childId = "btnMoreLinkItems") Then
		If(code = 0) Then
			Set data = Window.CreateTTData
			data.SetDWord "dwBtnMoreLinkItemsLeft", (btnMoreLinkItems.ClientLeft)
			data.SetDWord "dwBtnMoreLinkItemsRight", (btnMoreLinkItems.ClientLeft+btnMoreLinkItems.width)
			data.SetDWord "dwBtnMoreLinkItemsTop", (btnMoreLinkItems.ClientTop)
			data.SetDWord "dwBtnMoreLinkItemsBottom", (btnMoreLinkItems.ClientTop+btnMoreLinkItems.height)
			Window.ExeCommand 56001 , data
		End If
	'---------------------------------


	'---------FavBar---------------------
	ElseIf( (Len(childId) > 7) and (Left(childId, 7) = "FavItem") ) Then
		nChildId = CInt(Right(childId, Len(childId)-7)) + 57000  '在57000到58000之间
		Window.ExeCommand nChildId , code
	ElseIf(childId = "btnMoreFavItems") Then
		If(code = 0) Then
			Set data = Window.CreateTTData
			data.SetDWord "dwBtnMoreFavItemsLeft", (btnMoreFavItems.ClientLeft)
			data.SetDWord "dwBtnMoreFavItemsRight", (btnMoreFavItems.ClientLeft+btnMoreFavItems.width)
			data.SetDWord "dwBtnMoreFavItemsTop", (btnMoreFavItems.ClientTop)
			data.SetDWord "dwBtnMoreFavItemsBottom", (btnMoreFavItems.ClientTop+btnMoreFavItems.height)
			Window.ExeCommand 58001 , data
		End If
	'----------------------------------



	ElseIf(childId = "btnMenuSwitcher") Then
		If(code = 0) Then
			If(MenuContainer.visible) Then
				HideMenuBar()
			Else
				ShowMenuBar()
			End if
		End If

	End if
End Sub


Sub ShowMenuBar()
	MenuContainer.visible = true
	MenuBar.visible = True
	Window.ExeCommand 233 , 1
	WindowLayOut()	
End Sub

Sub HideMenuBar()
	MenuContainer.visible = false
	MenuBar.visible = False
	Window.ExeCommand 233 , 0
	WindowLayOut()	
End Sub



Sub btnCaptionMin_onClick()
	window.ShowWindow SC_MINIMIZE
End Sub

Sub btnCaptionMax_onClick()
	btnCaptionMax.visible = false
	btnCaptionRestore.visible = true
	window.ShowWindow SC_MAXIMIZE
End Sub

Sub btnCaptionRestore_onClick()
	btnCaptionMax.visible = true
	btnCaptionRestore.visible = false
	window.ShowWindow SC_RESTORE
End Sub

Sub btnCaptionClose_onClick()
	window.ShowWindow SC_CLOSE
End Sub

Sub btnToolBtnMin_onClick()
	window.ShowWindow SC_MINIMIZE
End Sub

Sub btnToolBtnClose_onClick()
	window.ShowWindow SC_CLOSE
End Sub

Sub btnToolBtnRestore_onClick()
	Window.ExeCommand 301 , 0
End Sub

Sub ChangeTabsUI()
	Window.LockPaint()
	if(IsTabwidthStable = 0) Then
		ChangeUnStableTabUI()
	Else
		ChangeStableTabUI()		
	End if

	ShowTabMoveInfo()	
	
	Window.UnLockPaint()
	WindowLayOut()
End Sub

Sub ShowTabMoveInfo()
	'if( (ShowTabMovePicSrcId = "InvalidTabItemId") OR (ShowTabMovePicTgtId = "InvalidTabItemId") OR (ShowTabMovePicSrcId = ShowTabMovePicTgtId) OR (ShouldHideTabMovePic = 1)) Then
	if( (ShowTabMovePicSrcId = "InvalidTabItemId") OR (ShowTabMovePicTgtId = "InvalidTabItemId") OR (ShouldHideTabMovePic = 1)) Then
		TabbarMovePos.Visible = FALSE	
	Else
		if(ShowTabMovePicDirection) Then
			TabbarMovePos.Left = AllTabs.Left + AllTabs.ChildById(ShowTabMovePicTgtId).Left + AllTabs.ChildById(ShowTabMovePicTgtId).width - 2
		Else
			TabbarMovePos.Left = AllTabs.Left + AllTabs.ChildById(ShowTabMovePicTgtId).Left - 2		
		End if
		TabbarMovePos.Visible = TRUE
		'LowLeft = AllTabs.Left + AllTabs.ChildById(ShowTabMovePicSrcId).Left - 3
		'HighLeft = AllTabs.Left + AllTabs.ChildById(ShowTabMovePicSrcId).Left + AllTabs.ChildById(ShowTabMovePicSrcId).width + 1		
		'if( (TabbarMovePos.Left > LowLeft) AND (TabbarMovePos.Left < HighLeft) )Then
		'	TabbarMovePos.Visible = FALSE
		'Else
		'	TabbarMovePos.Visible = TRUE			
		'End if
	End if
End Sub

Sub ChangeStableTabUI()
	AdjustTabToolBar()
	GetTabCount()
	GetActiveTabID()
    childCount = TabCount
	
	'TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - 5	
	if(btnNewAPage.visible) Then
		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - btnNewAPage.width - 5	
	else
		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - 5		
	End if
	
	TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth

	if(AutoAdjustActiveTabItem = 1) Then
			For i = 0 To childCount-1
				GetTabID(i)	
				if(NextTabID = ActiveTabID) Then
					if(i < FirstItemIndex) Then
						FirstItemIndex = i
					ElseIf((i - FirstItemIndex) > TabCanShowCount) Then
						FirstItemIndex = i - TabCanShowCount
					End if
				End if
			Next
	End if	
	
	TabWantUseWidth = (TabItemMaxWidth) * (childCount - FirstItemIndex) + 1	
	if(childCount = 0) Then
		AllTabs.width = 0
	ElseIf(TabCanUseWidth > TabWantUseWidth) Then	
		AllTabs.width = TabWantUseWidth
	Else
		AllTabs.width = TabCanUseWidth
	End If
	
		
	bLeftofActive = 1
	For i = 0 To childCount-1	
		GetTabID(i)			
		ContainerName = "TabContain" + CStr(NextTabID)
		TabName = "TabItem"+CStr(NextTabID)
		TabCloseName = "TabClose" + CStr(NextTabID)
				
		if(i < FirstItemIndex) Then
			AllTabs.ChildById(ContainerName).Visible = 0		
			AllTabs.ChildById(ContainerName).Left = 0
		ElseIf((i - FirstItemIndex) > TabCanShowCount) Then
			AllTabs.ChildById(ContainerName).Visible = 0		
			AllTabs.ChildById(ContainerName).Left = TabItemMaxWidth * (i - FirstItemIndex)		
		Else
			AllTabs.ChildById(ContainerName).Visible = 1
			AllTabs.ChildById(ContainerName).Left = TabItemMaxWidth * (i - FirstItemIndex)			
		End if
		AllTabs.ChildById(ContainerName).width = TabItemMaxWidth
			
		AllTabs.ChildById(ContainerName).ChildById(TabName).Visible = AllTabs.ChildById(ContainerName).Visible		
		if(NextTabID = ActiveTabID) Then
			AllTabs.ChildById(ContainerName).Height = AllTabs.Height
			AllTabs.ChildById(ContainerName).ChildById(TabName).Height = AllTabs.ChildById(ContainerName).Height
			SetTabItemImg AllTabs.ChildById(ContainerName).ChildById(TabName), 1, bLeftofActive
			TabWindBG.width = AllTabs.ChildById(ContainerName).width 	
			TabWindBG.left = AllTabs.ChildById(ContainerName).left + AllTabs.ChildById(ContainerName).width - TabWindBG.width			
			SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 1
			SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 1
			bLeftofActive = 0		
		Else
			AllTabs.ChildById(ContainerName).Height = AllTabs.Height - 1
			AllTabs.ChildById(ContainerName).ChildById(TabName).Height = AllTabs.ChildById(ContainerName).Height
			SetTabItemImg AllTabs.ChildById(ContainerName).ChildById(TabName), 0, bLeftofActive			
			SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 0
			SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 0				
			
		End if
		AllTabs.ChildById(ContainerName).ChildById(TabName).Left = 0
		AllTabs.ChildById(ContainerName).ChildById(TabName).width = AllTabs.ChildById(ContainerName).width		
		AllTabs.ChildById(ContainerName).ChildById(TabCloseName).left = AllTabs.ChildById(ContainerName).width - 20
		AllTabs.ChildById(ContainerName).ChildById(TabCloseName).width = 13				
	Next	
End Sub

Sub ChangeUnStableTabUI()
	AdjustTabToolBar()
	GetTabCount()
	GetActiveTabID()
    	childCount = TabCount	
	if(btnNewAPage.visible) Then
		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - btnNewAPage.width - 5		
	else
		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - 5		
	End if	
	
	TabWantUseWidth = (TabItemMaxWidth) * childCount + 1
	if(TabWantUseWidth <= TabCanUseWidth) Then
		if(childCount = 0) Then
			AllTabs.width = 0
		Else	
			AllTabs.width = TabWantUseWidth
		End If
		
		
		bLeftofActive = 1
		For i = 0 To childCount-1
			GetTabID(i)			
			ContainerName = "TabContain" + CStr(NextTabID)
			TabName = "TabItem"+CStr(NextTabID)
			TabCloseName = "TabClose" + CStr(NextTabID)
			if(i = 0) Then
				AllTabs.ChildById(ContainerName).Left = 0
			Else
				AllTabs.ChildById(ContainerName).Left = TabItemMaxWidth * i			
			End if
			AllTabs.ChildById(ContainerName).width = TabItemMaxWidth
			AllTabs.ChildById(ContainerName).Visible = 1			
			if(NextTabID = ActiveTabID) Then			
				AllTabs.ChildById(ContainerName).Height = AllTabs.Height
				AllTabs.ChildById(ContainerName).ChildById(TabName).Height = AllTabs.ChildById(ContainerName).Height
				SetTabItemImg AllTabs.ChildById(ContainerName).ChildById(TabName), 1, bLeftofActive
				TabWindBG.width = AllTabs.ChildById(ContainerName).width 	
				TabWindBG.left = AllTabs.ChildById(ContainerName).left + AllTabs.ChildById(ContainerName).width - TabWindBG.width				
				SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 1
				SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 1				
				bLeftofActive = 0
			Else
				AllTabs.ChildById(ContainerName).Height = AllTabs.Height 
				AllTabs.ChildById(ContainerName).ChildById(TabName).Height = AllTabs.ChildById(ContainerName).Height				
				SetTabItemImg AllTabs.ChildById(ContainerName).ChildById(TabName), 0, bLeftofActive								
				SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 0
				SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 0		
			End if
			AllTabs.ChildById(ContainerName).ChildById(TabName).Left = 0
			AllTabs.ChildById(ContainerName).ChildById(TabName).width = AllTabs.ChildById(ContainerName).width		
			AllTabs.ChildById(ContainerName).ChildById(TabCloseName).left = AllTabs.ChildById(ContainerName).width - 20
			AllTabs.ChildById(ContainerName).ChildById(TabCloseName).width = 13				
		Next
	Else
		AllTabs.width = TabCanUseWidth
		
		
		if(childCount > 0) Then
			tabWidth = (AllTabs.width) \ childCount
			tabWidthMod = (AllTabs.width) Mod childCount
			bLeftofActive = 1
			For i = 0 To childCount-1
				GetTabID(i)		
				ContainerName = "TabContain" + CStr(NextTabID)
				TabName = "TabItem"+CStr(NextTabID)
				TabCloseName = "TabClose" + CStr(NextTabID)
				
				if(i < tabWidthMod) Then
					AllTabs.ChildById(ContainerName).Left = (tabWidth + 1) * i
					AllTabs.ChildById(ContainerName).width = tabWidth + 1 					
				Else
					AllTabs.ChildById(ContainerName).Left = (tabWidth ) * i + tabWidthMod	
					AllTabs.ChildById(ContainerName).width = tabWidth 
				End if

				AllTabs.ChildById(ContainerName).Visible = 1
				AllTabs.ChildById(ContainerName).ChildById(TabName).Visible = 1						
				if(NextTabID = ActiveTabID) Then
					AllTabs.ChildById(ContainerName).Height = AllTabs.Height
					AllTabs.ChildById(ContainerName).ChildById(TabName).Height = AllTabs.ChildById(ContainerName).Height
					SetTabItemImg AllTabs.ChildById(ContainerName).ChildById(TabName), 1, bLeftofActive
					TabWindBG.width = AllTabs.ChildById(ContainerName).width 	
					TabWindBG.left = AllTabs.ChildById(ContainerName).left + AllTabs.ChildById(ContainerName).width - TabWindBG.width					
					SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 1
					SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 1				
					bLeftofActive = 0
				Else
					AllTabs.ChildById(ContainerName).Height = AllTabs.Height 
					AllTabs.ChildById(ContainerName).ChildById(TabName).Height = AllTabs.ChildById(ContainerName).Height
					SetTabItemImg AllTabs.ChildById(ContainerName).ChildById(TabName), 0, bLeftofActive
					SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 0
					SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 0				
					AllTabs.ChildById(ContainerName).ChildById(TabName).labelRightPadding = 0
					AllTabs.ChildById(ContainerName).ChildById(TabCloseName).Visible = 0					
				End if			
				AllTabs.ChildById(ContainerName).ChildById(TabName).Left = 0
				AllTabs.ChildById(ContainerName).ChildById(TabName).width = AllTabs.ChildById(ContainerName).width				
				if(AllTabs.ChildById(ContainerName).width > 20) Then
					AllTabs.ChildById(ContainerName).ChildById(TabCloseName).left = AllTabs.ChildById(ContainerName).width - 20				
				Else
					AllTabs.ChildById(ContainerName).ChildById(TabCloseName).left = 0
				End if
				AllTabs.ChildById(ContainerName).ChildById(TabCloseName).width = 13					
			Next		
		End if
				
	End If
End Sub

Sub GetTabCount()
	window.ExeCommand 65000 , 0
End Sub

Sub GetTabID(index)
	window.ExeCommand 65001 , index	
End Sub

Sub GetActiveTabID()
	window.ExeCommand 65002 , 0	
End Sub

sub SetTabToolbarImage()
    IsOnTop = IsTabbarOnTop
    If IsFullScreenMode = 1 then
        IsOnTop = 1
    end if
    
	if(IsOnTop = 1) then 
	'tab在上面
		if(IsTabwidthStable = 1) Then
			GetTabCount()
			TabCanUseWidth = cxClient - 2  - TabBar.left - 99 - btnSidebar.width - btnSidebar.left - 26	
			TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth
			'if(TabCanShowCount < TabCount) Then
			'	RTBBk.image = "tab/RTBBK.png"
			'Else
			'	RTBBk.image = "tab/RTBBK_Nomove.png"
			'End if			
		'Else
			'RTBBk.image = "tab/RTBBK_Nomove.png"
		End if
	else
	'tab在下面
		if(IsTabwidthStable = 1) Then
			GetTabCount()
			TabCanUseWidth = cxClient - 2  - TabBar.left - 99 - btnSidebar.width - btnSidebar.left - 26	
			TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth
			'if(TabCanShowCount < TabCount) Then
			'	RTBBk.image = "tab/RTBBK_Bottom.png"
			'Else
			'	RTBBk.image = "tab/RTBBK_Bottom_Nomove.png"
			'End if			
		'Else
			'RTBBk.image = "tab/RTBBK_Bottom_Nomove.png"
		End if
	end if

end sub



Sub SetTabItemImg(TabItemID, bActive, bLeftofActive)
    IsOnTop = IsTabbarOnTop
    If IsFullScreenMode = 1 then
        IsOnTop = 1
    end if
    
	TabItemID.tip = TabItemID.label
	If(bActive) Then
		TabItemID.top = 0
		if(IsOnTop = 0) Then
			TabItemID.LeftImage = "Tab/Tab_ActiveLeftBorder_Bottom.png"
			TabItemID.MiddleImage = "Tab/Tab_ActiveMiddle_Bottom.png"
			TabItemID.RightImage = "Tab/Tab_ActiveRightBorder_Bottom.png"
			TabItemID.HoverLeftImage = "Tab/Tab_ActiveLeftBorder_Bottom.png"
			TabItemID.HoverMiddleImage = "Tab/Tab_ActiveMiddle_Bottom.png"
			TabItemID.HoverRightImage = "Tab/Tab_ActiveRightBorder_Bottom.png"			
			TabItemID.IconTopPadding = 4
			TabItemID.LabelTopPadding = 0
		Else
			TabItemID.LeftImage = "Tab/Tab_ActiveLeftBorder.png"
			TabItemID.MiddleImage = "Tab/Tab_ActiveMiddle.png"
			TabItemID.RightImage = "Tab/Tab_ActiveRightBorder.png"
			TabItemID.HoverLeftImage = "Tab/Tab_ActiveLeftBorder.png"
			TabItemID.HoverMiddleImage = "Tab/Tab_ActiveMiddle.png"
			TabItemID.HoverRightImage = "Tab/Tab_ActiveRightBorder.png"			
			TabItemID.IconTopPadding = 6
			TabItemID.LabelTopPadding = 4
		End If
	Else
		if(IsOnTop = 0) Then
			TabItemID.top = -1
			if(bLeftofActive = 1) Then
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder_Bottom.png"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle_Bottom.png"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder_Bottom.png"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder_Hover_bottom.png"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle_Hover_bottom.png"	
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder_Hover_bottom.png"				
				TabItemID.IconTopPadding = 2
				TabItemID.LabelTopPadding = -1
			Else
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder_Bottom.png"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle_Bottom.png"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder_Bottom.png"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder_Hover_bottom.png"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle_Hover_bottom.png"	
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder_Hover_bottom.png"					
				TabItemID.IconTopPadding = 2
				TabItemID.LabelTopPadding = -1
			End if		
		Else
			TabItemID.top = 0
			if(bLeftofActive = 1) Then		
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder.png"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle.png"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder.png"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder_Hover.png"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle_Hover.png"
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder_Hover.png"				
				TabItemID.IconTopPadding = 7
				TabItemID.LabelTopPadding = 5
			Else
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder.png"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle.png"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder.png"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder_Hover.png"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle_Hover.png"
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder_Hover.png"				
				TabItemID.IconTopPadding = 7
				TabItemID.LabelTopPadding = 5
			End if				
		End if
	End if

End Sub

Sub SetTabItemFont(TabItemID, bActive)
	if(bActive = 0) Then
		TabItemID.LabelFontWeight = 400
	Else
		fontWeight = 400
		If(IsActiveTabBoldFont <> 0) Then
			fontWeight = 700
		End if
		TabItemID.LabelFontWeight = fontWeight
	End if
End Sub

Sub SetTabItemCloseInfo(TabItemID, TabCloseItemID, bActive)
	if(bActive = 0) Then
		TabItemID.labelRightPadding = 5			
		TabCloseItemID.Visible = 0	
	Else
		if(IsTabItemShowCloseBtn > 0) Then	
			TabItemID.labelRightPadding = 20
			TabCloseItemID.Visible = 1		
			TabCloseItemID.top = 7
		Else
			TabItemID.labelRightPadding = 5			
			TabCloseItemID.Visible = 0					
		End if
	End if
End Sub

Sub SetTabItemCloseInfo2(ChildNumber)
	if( (IsTabItemShowCloseBtnOnMouseOver > 0) and (IsTabItemShowCloseBtn > 0)) Then	
		GetActiveTabID()
		if(ChildNumber <> ActiveTabID) Then
			ContainerName = "TabContain" + CStr(ChildNumber)
			TabName = "TabItem"+CStr(ChildNumber)
			TabCloseName = "TabClose" + CStr(ChildNumber)
			AllTabs.ChildById(ContainerName).ChildById(TabName).labelRightPadding = 20
			AllTabs.ChildById(ContainerName).ChildById(TabCloseName).Visible = 1		
			AllTabs.ChildById(ContainerName).ChildById(TabCloseName).top = 7

			IsMouseEnterTab = 1
			MouseEnterTabNumber = ChildNumber
		End if
	End if
End Sub

Sub SetTabItemCloseInfo3(childId)
	if( (IsTabItemShowCloseBtnOnMouseOver > 0) and (IsTabItemShowCloseBtn > 0) and (IsMouseEnterTab > 0) ) Then			
		GetActiveTabID()
		if(MouseEnterTabNumber <> ActiveTabID) Then
			MouseEnterTabItemID = "TabItem" + CStr(MouseEnterTabNumber)
			TmpTabID = childId
			If( (Len(childId) > 8) and (Left(childId, 8) = "TabClose") ) Then
				TmpTabID = "TabItem" + Right(childId, Len(childId)-8)
			End If			
			If(MouseEnterTabItemID <> TmpTabID) Then
				ContainerName = "TabContain" + CStr(MouseEnterTabNumber)
				TabName = "TabItem"+CStr(MouseEnterTabNumber)
				TabCloseName = "TabClose" + CStr(MouseEnterTabNumber)	
				
				IsMouseEnterTab = 0
				AllTabs.ChildById(ContainerName).ChildById(TabName).labelRightPadding = 5			
				AllTabs.ChildById(ContainerName).ChildById(TabCloseName).Visible = 0							
			End if
		End if	
	End if	
End Sub

Sub HideSomeBtnsFromRToolBar()
	If(IsHideSomeBtnsFromRToolBar) Then
		RToolbar.width = RToolbar.width - btnNewPage.width*2
		RToolbar.left = cxClient - RToolbar.width - 1

		If(Window.ObjIsGot("RTBBk")) then
			RTBBk.width = RTBBk.width - 38	
			RTBBk.left = RToolbar.width - RTBBk.width			
		End If
		
		btnTextMode.visible = 0
		btnNewPage.visible = 0
		btnNewPageSelect.visible = 0
		btnBack.left = btnBack.Left - btnNewPage.width*2
		btnBackSelect.left = btnBackSelect.Left - btnNewPage.width*2
		btnClose.left = btnClose.left - btnNewPage.width*2
		TabBar.width =  RToolbar.left - TabBar.left' - 20	
	Else
		btnTextMode.visible = 1
	End if
End Sub





Sub AdjustTabToolBar()

	if(IsTabwidthStable = 1) Then
		GetTabCount()
		TabCanUseWidth = cxClient - 2  - TabBar.left - 87 - btnSidebar.width - btnSidebar.left - 26	
		TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth
		if(TabCanShowCount < TabCount) Then
			RToolbar.width = 120
			RToolbar.left = cxClient - RToolbar.width - 2
			btnTextMode.left = 42			
			btnNewPage.left = 61
			btnNewPageSelect.left = 61
			btnBack.left = 80
			btnBackSelect.left = 80
			btnClose.left = 99
			btnMoveBack.visible = 1
			btnMoveFor.visible = 1	
			TabBar.width =  RToolbar.left - TabBar.left' - 20	
		Else
			FirstItemIndex = 0
			btnMoveBack.visible = 0
			btnMoveFor.visible = 0
			RToolbar.width = 87
			RToolbar.left = cxClient - RToolbar.width - 2	
			btnTextMode.left = 6			
			btnNewPage.left = 25
			btnNewPageSelect.left = 25
			btnBack.left = 44
			btnBackSelect.left = 44
			btnClose.left = 63				
			TabBar.width =  RToolbar.left - TabBar.left' - 20			
		End if			
	Else
		btnTextMode.left = 6			
		btnNewPage.left = 25
		btnNewPageSelect.left = 25
		btnBack.left = 44
		btnBackSelect.left = 44
		btnClose.left = 63	
		RToolbar.width = 87
		RToolbar.left = cxClient - RToolbar.width - 2	
		'RTBBk.width = 66
		'RTBBk.left = cxClient - RTBBk.width			
		btnMoveBack.visible = 0
		btnMoveFor.visible = 0		
		TabBar.width =  RToolbar.left - TabBar.left' - 20			
	End If
	HideSomeBtnsFromRToolBar()

End Sub


sub btnFavorite_onClick()
	x = btnFavorite.ClientLeft + 5
	y = btnFavorite.ClientTop + btnFavorite.Height - 1
	a = x * 65536 + y
	Window.ExeCommand 44005 , a
End Sub

sub btnLastNavList_onClick()
	x = btnLastNavList.ClientLeft + 2
	y = btnLastNavList.ClientTop + btnLastNav.Height - 1
	a = x * 65536 + y
	Window.ExeCommand 44006 , a
End Sub

sub btnClearNavRecord_onClick()
	x = btnClearNavRecord.ClientLeft + 2
	y = btnClearNavRecord.ClientTop + btnClearNavRecord.Height - 1
	a = x * 65536 + y
	Window.ExeCommand 44008 , a
End Sub

sub btnNavList_onClick()
	x = btnNavList.ClientLeft + 2
	y = btnNavList.ClientTop + btnNavList.Height - 1
	a = x * 65536 + y
	Window.ExeCommand 44007 , a
End Sub

'sub btnFindClose_onClick()
'	a = 1	
'	Window.ExeCommand 44013 , a
'End Sub

'sub btnFindPre_onClick()
'	a = 3	
'	Window.ExeCommand 44013 , a
'End Sub

'sub btnFindNext_onClick()
'	a = 4
'	Window.ExeCommand 44013 , a
'End Sub

'sub btnFindResult_onClick()
'	a = 5
'	Window.ExeCommand 44013 , a
'End Sub

Sub AdjustLinkBar()

	btnMoreLinkItems.Left=LinkBar.width-btnMoreLinkItems.width

	LinkBarCaption.color = FavLinkLabelColor
	Dim SpaceUsedToShow '能显示item的位置
	if(btnMoreLinkItems.visible) Then
		SpaceUsedToShow = btnMoreLinkItems.left-LinkItemCont.left
	else
		SpaceUsedToShow = LinkBar.width-LinkItemCont.left 
	End if


	childCount = LinkItemCont.ChildCount
	For i = 0 To childCount-1	
		If(i = 0) Then
			LinkItemCont.Child(i).Left = 0			
		else
			LinkItemCont.Child(i).Left = LinkItemCont.Child(i-1).Left + LinkItemCont.Child(i-1).width
		End If

		If( (LinkItemCont.Child(i).Left + LinkItemCont.Child(i).width) > SpaceUsedToShow ) Then
			LinkItemCont.Child(i).visible = False
		Else
			LinkItemCont.Child(i).visible = true
		End If
		
		'LinkItemCont.Child(i).LabelColor="#28374b"
		'LinkItemCont.Child(i).LabelColorHover="#28374b"
		LinkItemCont.Child(i).LabelColor = FavLinkLabelColor
		LinkItemCont.Child(i).LabelColorHover = FavLinkLabelColor		
	Next	


	'调整显示morelink按钮
	If(childCount>0) then
		LastItemRight = LinkItemCont.Child(childCount-1).Left + LinkItemCont.Child(childCount-1).width '最右边一个item的右边界

		if(LastItemRight > SpaceUsedToShow) Then '如果item显示不下,那么就显示出morelink的按钮来,并缩短LinkItemCont的宽度
			btnMoreLinkItems.visible=True
			LinkItemCont.width=btnMoreLinkItems.left-LinkItemCont.left
		Else
			btnMoreLinkItems.visible=False
			LinkItemCont.width=SpaceUsedToShow
		End if
	Else
		btnMoreLinkItems.visible=False
		LinkItemCont.width=0
	End if
End Sub


Sub AdjustFavBar()

	btnMoreFavItems.Left=FavBar.width-btnMoreFavItems.width

	FavBarCaption.color = FavLinkLabelColor
	Dim SpaceUsedToShow '能显示item的位置
	if(btnMoreFavItems.visible) Then
		SpaceUsedToShow = btnMoreFavItems.left-FavItemCont.left
	else
		SpaceUsedToShow = FavBar.width-FavItemCont.left 
	End if



	childCount = FavItemCont.ChildCount
	For i = 0 To childCount-1	
		If(i = 0) Then
			FavItemCont.Child(i).Left = 0			
		else
			FavItemCont.Child(i).Left = FavItemCont.Child(i-1).Left + FavItemCont.Child(i-1).width
		End If

		If( (FavItemCont.Child(i).Left + FavItemCont.Child(i).width) > SpaceUsedToShow ) Then
			FavItemCont.Child(i).visible = False
		Else
			FavItemCont.Child(i).visible = true
		End If
		
		'FavItemCont.Child(i).LabelColor="#28374b"
		'FavItemCont.Child(i).LabelColorHover="#28374b"
		FavItemCont.Child(i).LabelColor=FavLinkLabelColor
		FavItemCont.Child(i).LabelColorHover=FavLinkLabelColor
	Next	


	'调整显示moreFav按钮
	If(childCount>0) then
		LastItemRight = FavItemCont.Child(childCount-1).Left + FavItemCont.Child(childCount-1).width '最右边一个item的右边界

		if(LastItemRight > SpaceUsedToShow) Then '如果item在FavItemCont里面容不下,那么就显示出moreFav的按钮来,并缩短FavItemCont的宽度
			btnMoreFavItems.visible=True
			FavItemCont.width=btnMoreFavItems.left-FavItemCont.left
		Else
			btnMoreFavItems.visible=false
			FavItemCont.width=SpaceUsedToShow
		End if
	Else
		btnMoreFavItems.visible=False
		FavItemCont.width=0
	End if
End Sub


Sub RelayeroutPlugins()
	
	for i = 2001 to 2100
		
		if Window.ObjIsGot("PluginHostCont_" & CStr(i)) = false then 
			Exit for
		end if
		
		RelayeroutPlugin("PluginHostCont_" & CStr(i))

	Next

End Sub

Sub RelayeroutPlugin(var)
	
	if Window.ObjIsGot(var) then
		count = Window.ChildById(var).ChildCount
		if count >= 1 then
		Window.ChildById(var).Child(0).width = Window.ChildById(var).width - 10
		end if
	end if

end sub

Sub ShowPlugin(var, bshow)

	if Window.ObjIsGot(var) then
		Window.ChildById(var).Visible = bshow
	end if

end sub

Sub OnDropTest(var)

	x = var.GetDWord("dwPosX")
	y = var.GetDWord("dwPosY")

	set obj = Window.ChildByPos(x, y)

	

	var.SetStr "strElementName", Window.GetChildId(Window.ChildByPos(x, y))

end Sub

Sub OnGetItemRect(var)

	name = var.GetStr("strElementName")
	
	set obj = Window.ChildById(name)

	var.SetDWord "dwRectLeft", obj.left
	var.SetDWord "dwRectTop", obj.top
	var.SetDWord "dwRectWidth", obj.width
	var.SetDWord "dwRectHight", obj.height

end Sub
Sub SetInsertMark(var)

	name = var.GetStr("strElementName")
	pos = var.GetDWord("dwPos")
	if name = "LinkBar" then
		LinkbarSetInsertMark(pos)
	elseif name = "FavBar" then
		FavbarSetInsertMark(pos)
	else 
		InsertMark.Visible = FALSE
	end if

end Sub

sub LinkbarSetInsertMark(pos)
		InsertMark.Visible = TRUE
		index = CInt(pos)

		childCount = LinkItemCont.ChildCount
		Dim max
		For max = 0 To childCount-1	
			ItemName = "LinkItem"+CStr(max)
			If( LinkItemCont.ChildById(ItemName).visible = false) Then	
				Exit for
			End if
		Next	

		if index >= max then
			set obj = LinkItemCont.Child(index - 1)
			InsertMark.left = Obj.Clientleft + Obj.width - 3
		else
			set obj = LinkItemCont.Child(index)
			InsertMark.left = Obj.Clientleft - 3
		end if
		InsertMark.top = Linkbar.top + 4
end sub

sub FavbarSetInsertMark(pos)
		InsertMark.Visible = TRUE
		index = CInt(pos)

		childCount = FavItemCont.ChildCount
		Dim max
		For max = 0 To childCount-1	
			ItemName = "FavItem"+CStr(max)
			If( FavItemCont.ChildById(ItemName).visible = false) Then	
				Exit for
			End if
		Next	

		if index >= max then
			set obj = FavItemCont.Child(index - 1)
			InsertMark.left = Obj.Clientleft + Obj.width - 3
		else
			set obj = FavItemCont.Child(index)
			InsertMark.left = Obj.Clientleft - 3
		end if
		InsertMark.top = Favbar.top + 4
end sub

Sub SetTabBarNoMessage()
		TabBarNoMessage.width = btnNewAPage.left + btnNewAPage.width	
end Sub



Sub menuFile_OnPopupMenu()
	PopupMenu menuFile, 51	
End Sub

Sub menuEdit_OnPopupMenu()
	PopupMenu menuEdit, 52
End Sub

Sub menuView_OnPopupMenu()
	PopupMenu menuView, 53
End Sub

Sub menuTool_OnPopupMenu()
	PopupMenu menuTool, 54
End Sub

Sub menuAcount_OnPopupMenu()
	PopupMenu menuAcount, 59
End Sub

Sub menuService_OnPopupMenu()
	PopupMenu menuService, 55
End Sub

Sub menuHelp_OnPopupMenu()
	PopupMenu menuHelp, 56
End Sub

Sub menuFav_OnPopupMenu()
	PopupMenu menuFav, 57
End Sub

Sub PopupMenu(menu, v)
	x = menu.ClientLeft
	y = menu.ClientTop + menu.Height+1

	a = x * 65536 + y

	window.ExeCommand v, a
End Sub

Sub menuFile_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuEdit_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuView_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuTool_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuAcount_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuService_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuHelp_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

Sub menuFav_OnCancelMenu
	window.ExeCommand 50, 0
End Sub

sub btnCaptionFeedback_onClick()
	window.ExeCommand 1999, 0
End sub