'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 TabPostion
Dim ShowSidebar
Dim ShowFindbar
Dim SidebarWidth
Dim IsTabwidthStable
Dim TabItemMaxWidth
Dim FirstItemIndex
Dim ShowPluginBar
'Dim IsTabItemShowCloseBtn
Dim IsActiveTabBoldFont
Dim AutoAdjustActiveTabItem
Dim IsShowLinkBar
Dim IsShowFavBar
Dim bShowSearchBar
Dim IsTabBarShowNewBtn
Dim IsSidebarFloat
Dim MinSideBarWidth
Dim MaxSideBarWidth
Dim IsHighLightDown
Dim IsFullScreenMode

Dim ShowTabMovePicSrcId
Dim ShowTabMovePicTgtId
Dim ShowTabMovePicDirection
Dim ShouldHideTabMovePic

Dim TabItemShowCloseBtnMode
Dim bTooSmallToShowCloseBTN
Dim IsMouseEnterTab
Dim	MouseEnterTabNumber
Dim	FavLinkLabelColor
Dim ShowWebPagebar
Dim nMBrowserTop

Dim WindowTheme


Dim IsHideSomeBtnsFromRToolBar
Dim ThemeDraw

sub WindowLayOut()	
	Window.LockPaint()
	
	call RelayoutToolbar(toolbar)
	
	if IsFullScreenMode = 0 then
		WindowLayOutNormal()
	else
		WindowLayOutFullSCreen()	
	end if

	Window.UnLockPaint()
end sub	

Sub WindowLayOutFullSCreen()

	MenuDragContainer.visible = false
    MenuContainer.visible = false
	MenuBar.visible = false
    'MenuContainerLine.visible = false
    BtnPluginCont.visible = false
    LinkBar.visible = false
    FavBar.visible = false
    BottomLine.visible = false
    StatusBar.visible = false
    
    RebarBK.visible = true
    toolbar.visible = true
	browsertoolbar.visible = true
    AddressBar.visible = true
    SearchBar.visible = true
    TabRebar.visible = true
    MainArea.visible = true
    
    RebarBK.left = 0
    RebarBK.top = 0
	RebarBK.width = cxClient
	RebarBK.height = cyClient + 200'解决gdi+拉伸绘制问题	
  
	MaxWndToolBtns.visible = true
	MaxWndToolBtns.top = 0
	MaxWndToolBtns.left = cxClient - MaxWndToolBtns.width - 5
    'MaxWndToolBtns.width = 100
	'MaxWndToolBtns.Height = 23
		
    toolbar.left = 0
    toolbar.top = 0
    'toolbar.width = 161
    toolbar.height = 36

    browsertoolbar.left = toolbar.left + toolbar.width
    browsertoolbar.top = 0
    'browsertoolbar.width = 129
    browsertoolbar.height = toolbar.height
    
    AddressBar.left = browsertoolbar.left + browsertoolbar.width 
    AddressBar.top = 4
    AddressBar.width = cxClient - AddressBar.left - 195 - MaxWndToolBtns.width - 10
    
    SearchBar.left = cxClient - 195 - MaxWndToolBtns.width - 10
    SearchBar.top = 4
    SearchBar.width = 195
    
    TabRebar.left = 0
    TabRebar.top = toolbar.height
    TabRebar.width = cxClient
    TabRebar.height = 29
    
    MainArea.left = 0
    MainArea.top = toolbar.height + TabRebar.height
    MainArea.width = cxClient
    MainArea.height = cyClient - toolbar.height - TabRebar.height
    
	AdjustAddrBar()
	AdjustSearchBar()
	
	AdjustTabRebar()
    AdjustMainAreaFrame()
    AdjustSidebarAndMBrowser()
	ChangeFrameUI(1)
End Sub

sub ChangeThemeDrawPara(var)
	ThemeDraw = var
	if(ThemeDraw = 1)then
		ThemeTitleBar.IsThemeDraw = true
		btnSystemBtnMin.IsThemeDraw = true	
		btnSystemBtnMax.IsThemeDraw = true		
		btnSystemBtnRestore.IsThemeDraw = true
		btnSystemBtnClose.IsThemeDraw = true
		BKLeft.IsThemeDraw = true	
		BKRight.IsThemeDraw = true		
		BKBottom.IsThemeDraw = true
		CaptionLeftCorner.visible = false
		CaptionStretch.visible = false
		CaptionRightCorner.visible = false
		CaptionBar.visible = false
		BKLeftBorder.visible = false
		BKRightBorder.visible = false
	else
		ThemeTitleBar.IsThemeDraw = false
		btnSystemBtnMin.IsThemeDraw = false	
		btnSystemBtnMax.IsThemeDraw = false		
		btnSystemBtnRestore.IsThemeDraw = false
		btnSystemBtnClose.IsThemeDraw = false
		BKLeft.IsThemeDraw = false	
		BKRight.IsThemeDraw = false		
		BKBottom.IsThemeDraw = false	
		CaptionLeftCorner.visible = true
		CaptionStretch.visible = true
		CaptionRightCorner.visible = true
		CaptionBar.visible = true
		BKLeftBorder.visible = true
		BKRightBorder.visible = true
	end if
end sub

sub ChangeFrameUI(fullscreen)

	if(ThemeDraw = 0)then	
		BKLeft.top = CaptionLeftCorner.height
		BKRight.top = CaptionRightCorner.height
		
		CaptionStretch.left = CaptionLeftCorner.Left + CaptionLeftCorner.width
	    CaptionStretch.width = cxClient - CaptionLeftCorner.width - CaptionRightCorner.width + 2
	    CaptionRightCorner.Left = cxClient - CaptionRightCorner.width	
		
	    CaptionBar.width = CaptionStretch.width - btnCaptionFeedback.width - btnSystemBtnMin.width - btnSystemBtnRestore.width - btnSystemBtnClose.width			
		Caption.width = CaptionBar.width - 30
		
		btnSystemBtnMin.left = cxClient - btnSystemBtnMin.width - btnSystemBtnRestore.width - btnSystemBtnClose.width - 5
		btnSystemBtnRestore.left = btnSystemBtnMin.left + btnSystemBtnMin.width
		btnSystemBtnMax.left = btnSystemBtnRestore.left	
		btnSystemBtnClose.left = btnSystemBtnRestore.left + btnSystemBtnRestore.width
		
		BKBottom.top = cyClient - BKBottom.height
		BKBottom.left = BKLeftBorder.width
		BKBottom.width = cxClient - BKLeftBorder.width - BKRightBorder.width
		BKLeft.height = cyClient - CaptionStretch.height - BKBottom.height
		BKRight.left = cxClient - BKRight.width
		BKRight.height = BKLeft.height
		
		BKLeftBorder.top = cyClient - BKLeftBorder.height
		BKRightBorder.left = cxClient - BKRightBorder.width
		BKRightBorder.top = cyClient - BKRightBorder.height	
	end if
	
	if(fullscreen = 0)then
		ThemeTitleBar.visible = true
		btnSystemBtnMin.visible = true
		'btnSystemBtnMax.visible = false
		'btnSystemBtnRestore.visible = false
		btnSystemBtnClose.visible = True
		btnCaptionFeedback.visible = true
		BKLeft.visible = true
		BKBottom.visible = true
		BKRight.visible = true	
		CaptionBK.width = cxClient
	elseif(fullscreen = 1)then
		ThemeTitleBar.visible = false
		btnSystemBtnMin.visible = false
		btnSystemBtnMax.visible = false
		btnSystemBtnRestore.visible = false
		btnSystemBtnClose.visible = False
		btnCaptionFeedback.visible = false
		BKLeft.visible = false
		BKBottom.visible = false
		BKRight.visible = false
	end If
	
	btnCaptionFeedback.left = btnSystemBtnMin.Left - btnCaptionFeedback.width -3
	btnCaptionFeedback.top = btnSystemBtnMin.top

	If(WindowTheme = CStr("2000") Or WindowTheme = CStr("Luna")) Then
		btnCaptionFeedback.image = "feedback_xp.png"
		btnCaptionFeedback.hoverImage = "feedback_xp_hover.png"
		btnCaptionFeedback.downImage = "feedback_xp_down.png"
		If(WindowTheme = CStr("Luna")) then
			btnCaptionFeedback.top = btnCaptionFeedback.top + 2
		End if
	ElseIf(WindowTheme = CStr("Aero")) then
		btnCaptionFeedback.image = "feedback_vista.png"
		btnCaptionFeedback.hoverImage = "feedback_vista_hover.png"
		btnCaptionFeedback.downImage = "feedback_vista_down.png"
	End if

end sub

Sub WindowLayOutNormal()
		window.minHeight = Window.ReBarBottom + StatusBar.height + TabRebar.height + 40'minmainarea
		ChangeFrameUI(0)
		MaxWndToolBtns.visible = false
		MenuBar.visible = true
		MenuDragContainer.visible = true
		MenuContainer.visible = true		
		MenuContainer.width = cxClient
		'MenuContainerLine.left = 0
		'MenuContainerLine.top = MenuContainer.top + MenuContainer.height		
		'MenuContainerLine.width = cxClient
		
		RebarBK.top = 20
		RebarBK.left = BKLeft.width
		RebarBK.width = cxClient - BKLeft.width - BKRight.width
		RebarBK.height = cyClient + 200'解决gdi+拉伸绘制问题	
		
		AdjustAddrBar()
		AdjustPluginBar()
		RelayeroutPlugins()

	    'linkbar
	    If(IsShowLinkBar) Then
		    LinkBar.visible=true
		    AdjustLinkBar()
	    Else
		    LinkBar.visible=false
	    End if
	    'Favbar
	    If(IsShowFavBar) Then
		    FavBar.visible=true
		    AdjustFavBar()
	    Else
		    FavBar.visible=false
	    End if

		AdjustStatusBar()
		AdjustTabRebar()
		AdjustMainAreaFrame()	
		AdjustSidebarAndMBrowser()

		if(IsTabPostionOnTop = 0) Then
			If(StatusBar.top < TabRebar.top + TabRebar.height) Then
				StatusBar.visible = False
				StatusBarLine.visible = False
				StatusBarBK.visible = False
			Else
				StatusBar.visible = true
				StatusBarLine.visible = true
				StatusBarBK.visible = true
			End If
		Else 
			If(StatusBar.top < MainArea.top + MainArea.height) Then
				StatusBar.visible = False
				StatusBarLine.visible = False
				StatusBarBK.visible = False
			Else
				StatusBar.visible = true
				StatusBarLine.visible = true
				StatusBarBK.visible = true
			End If
		End if
		AdjustSearchBar()

End Sub

Sub AdjustAddrBar()
		AddrBorderIMG.width = AddressBar.width - 3
		AddrBorderRight.left = AddressBar.width - 1
		AddrssCombo.width = AddressBar.width - GoButton.width  - 12
		GoButton.left = AddressBar.width - GoButton.width
End Sub

Sub AdjustSearchBar()
	    if(bShowSearchBar = 1) then
		    SearchBorderIMG.width = SearchBar.width - HighLightButton.width  - SearchBorderLeft.Left - SearchBorderLeft.width - 2 '高亮关键字无上下边
		    SearchBorderRight.left = SearchBar.width - HighLightButton.width - 3
		    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

		    If(IsHighLightDown) Then
			    HighLightButton.image = "Highlight_Select_Normal.png"
			    HighLightButton.hoverImage = "Highlight_Select_Hover.png"	
			    HighLightButton.downImage = "Highlight_Select_Down.png"			
		    Else
			    HighLightButton.image = "Highlight_Normal.png"
			    HighLightButton.hoverImage = "Highlight_Hover.png"	
			    HighLightButton.downImage = "Highlight_Down.png"		
		    End If
		    SearchBar.Visible = true
		    SearchBarDlg.Visible = true
		else
		    SearchBar.Visible = false
		    SearchBarDlg.Visible = false
	    end if
End Sub

Sub AdjustPluginBar()
	    If (ShowPluginBar = 1) THEN
		    BtnPluginCont.visible = True
			BtnPluginBar.width = BtnPluginCont.width-BtnPluginBar.left
	    ELSE
		    BtnPluginCont.visible = False
	    END IF
End Sub

Sub AdjustStatusBar()

	    StatusBar.height = 24
	    StatusBar.top = cyClient -  StatusBar.height - BKBottom.height 
	    StatusBar.left = BKLeft.width
	    StatusBar.width = cxClient - BKLeft.width - BKRight.width
	    
		StatusBarLine.left = BKLeft.width
	    StatusBarLine.width = StatusBar.width
	    StatusBarLine.top = StatusBar.top	 
		
		StatusBarBK.left = 0
	    StatusBarBK.width = StatusBar.width
	    StatusBarBK.top = StatusBar.top
End Sub

Sub AdjustTabRebar()
	    if(TabPostion = 0) Then
	        if IsFullScreenMode = 0 then
                TabRebar.top = StatusBar.top - TabRebar.height - 1
				TabRebarSepLine.image = "Tab/TabRebarSepLine_Bottom.png"
				TabBar.top = 3
				btnSidebar.top = 2
				btnNewAPage.top = 2	
				RToolbar.top = 3
				RMovebar.top = 3		
				btnMoveBack.top = 4
				btnMoveFor.top = 4
				btnTextMode.top = 4
				btnNewPage.top = 4
				btnNewPageSelect.top = 4
				btnBack.top = 4
				btnBackSelect.top = 4
				btnClose.top = 6
			else 
				TabBar.top = 0
				btnSidebar.top = 0
				btnNewAPage.top = 0	
				RToolbar.top = 1
				RMovebar.top = 2		
				btnMoveBack.top = 6
				btnMoveFor.top = 6
				btnTextMode.top = 4
				btnNewPage.top = 4
				btnNewPageSelect.top = 4
				btnBack.top = 4
				btnBackSelect.top = 4
				btnClose.top = 6
				TabRebarSepLine.image = "Tab/TabRebarSepLine.png"
            end if
			
            TabRebarSepLine.top = 0
			TabRebarSepLine.left = 0
			TabRebarSepLine.width = cxClient + 2
			'TabRebarSepLine.image = "Tab/TabRebarSepLine_Bottom.png"	

			BottomLine.visible = true
			BottomLine.top = Window.ReBarBottom
			BottomLine.left = BKLeft.width
			BottomLine.width = cxClient	 - BKLeft.width - BKRight.width			
	    Else
	        if IsFullScreenMode = 0 then
                    TabRebar.top = Window.ReBarBottom + 1
                end if
	    
			TabRebarSepLine.left = 0
			TabRebarSepLine.top = 0	
			TabRebarSepLine.width = cxClient + 2
			TabRebarSepLine.image = "Tab/TabRebarSepLine.png"			
		    TabBar.top = 0
		    btnSidebar.top = 0
		    btnNewAPage.top = 0	
		    RToolbar.top = 1
		    RMovebar.top = 2		
		    btnMoveBack.top = 6
		    btnMoveFor.top = 6
			btnTextMode.top = 4
		    btnNewPage.top = 4
		    btnNewPageSelect.top = 4
		    btnBack.top = 4
		    btnBackSelect.top = 4
		    btnClose.top = 6
			
			BottomLine.visible = false
			
	    End if

		AllTabs.top = 0		
	    
	    if IsFullScreenMode = 0 then
			TabRebar.left = BKLeft.width
            TabRebar.width = cxClient - BKLeft.width - BKRight.width
        end if
        RToolbar.left = TabRebar.width - RToolbar.width
		
	    TabBar.left = 0
	    if(RMovebar.visible = 1) Then
		    TabBar.width =  RMovebar.left - TabBar.left
	    Else
		    TabBar.width =  RToolbar.left - TabBar.left	
	    End if
    	
	    btnSidebar.left = TabBar.left + 2
	    btnSidebar.width = 24	
	    AllTabs.Left = btnSidebar.Left + btnSidebar.width + 2
	    btnNewAPage.left = AllTabs.left + AllTabs.width + 2
	    btnNewAPage.width = 24
	    SetTabBarNoMessage()			
End Sub

Sub AdjustMainAreaFrame()
    if IsFullScreenMode = 0 then
         if(TabPostion = 0) Then
	        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		
	 Else
	        MainArea.top = TabRebar.top + TabRebar.height 
	        MainArea.height = StatusBar.top - (TabRebar.top + TabRebar.height)		
	 End if
		 MainArea.left = BKLeft.width
         MainArea.width = cxClient - BKLeft.width - BKRight.width	
    End if
End Sub

Sub AdjustSidebarAndMBrowser()
	if(ShowSidebar = 0) Then
		SideRebar.visible = False
		MBrowser.left = 0
		'MBrowser.top = 0
		'MBrowser.height = MainArea.height
		AjustBrowserSize(MainArea.width)
	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		
		Else	
			MBrowser.left = SidebarWidth	
		End if 
		'MBrowser.top = 0
		'MBrowser.height = MainArea.height 
		AjustBrowserSize(MainArea.width - MBrowser.left)
		
	Else
		SideRebar.visible = True		
		SideRebar.left = 0
		SideRebar.top = 0		
		SideRebar.width = 7
		SideRebar.height = MainArea.height

		MBrowser.left = SideRebar.width
		'MBrowser.top = 0		
		'MBrowser.height = MainArea.height		
		AjustBrowserSize(MainArea.width - SideRebar.width)

	End IF
End Sub

Sub AjustBrowserSize(width)
	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.SetSize width, MainArea.height - nMBrowserTop
end sub	

	

'Sub Window_OnShowStateChange(nCmdShow)
'	ChangeTabsUI()	
'End Sub

sub Window_WindowLayOut(cx, cy, wndState)

	if(cy < window.minHeight)then
		cyClient = window.minHeight	
	else 
		cyClient = cy	
	end if
	
	if(cx < window.minWidth)then
		cxClient = window.minWidth	
	else 
		cxClient = cx	
	end if
	
	WindowLayOut()	
end Sub

sub Window_OnSwitchCurrentSkin(var)
	FavLinkLabelColor = var.GetStr("strTabbarDragSrcId")
	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
	TabPostion = 1
	ShowSidebar = 0
	SidebarWidth = 214
	MinSideBarWidth = 192
	MaxSideBarWidth = 600	
	IsTabwidthStable = 0
	TabItemMaxWidth = 155
	FirstItemIndex = 0
	ShowPluginBar = 0
	'IsTabItemShowCloseBtn = 1
	AutoAdjustActiveTabItem = 1		
	bShowSearchBar = 0
	IsTabBarShowNewBtn = 1	
	IsSidebarFloat = 1
	IsFullScreenMode = 0
	ShowTabMovePicSrcId = "InvalidTabItemId"
	ShowTabMovePicTgtId = "InvalidTabItemId"	
	ShowTabMovePicDirection = 0		
	ShouldHideTabMovePic = 0
	
	TabItemShowCloseBtnMode = 1
	bTooSmallToShowCloseBTN = false
	IsMouseEnterTab	= 0
	InsertMark.Visible = FALSE
	FavLinkLabelColor = "#000000"
	ShowWebPagebar = 0

	IsHideSomeBtnsFromRToolBar = 0
	ThemeDraw = 1
	CaptionLeftCorner.visible = false
	CaptionStretch.visible = false
	CaptionRightCorner.visible = false
	BKLeftBorder.visible = false
	BKRightBorder.visible = false
	CaptionBar.visible = false
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
			window.ShowWindow SC_MAXIMIZE
		'Elseif(code = 45003) Then
		'	ChangeThemeDrawPara(var)
		Elseif(code = 45004) Then
			WindowTheme = CStr(var.GetStr("strSkinThemeName"))	
			if(WindowTheme = CStr("2000"))then
				ChangeThemeDrawPara(1)
			elseif(WindowTheme = CStr("Aero"))then
				ChangeThemeDrawPara(1)
			elseif(WindowTheme = CStr("Luna"))then
				ChangeThemeDrawPara(1)
			else
				ChangeThemeDrawPara(0)
			end if				
		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-1
				NameTabContain = "TabContain" + CStr(i)
				AllTabs.ChildById(NameTabContain).Visible = 0
			Next			
			ChangeTabsUI()
		Elseif(code = 65102) Then ' change tab postion bottom
			TabPostion = 1
			SetTabRebarRes(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 = 70300) 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 = 30002) Then
			Caption.value = var
			RefreshFrame()
		'总是打开新窗口
		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 , TabPostion	
		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
			TabPostion = 0
			SetTabRebarRes(0)					
			ChangeTabsUI()
		Elseif(code = 65104) Then			
			if(IsTabwidthStable <> var) Then
				IsTabwidthStable = var
				ChangeTabsUI()				
			End if
		Elseif(code = 65105) Then
			if(TabItemMaxWidth <> var) Then
				TabItemMaxWidth = var
				ChangeTabsUI()
			End if
		Elseif(code = 65111) Then
			if( CInt(var) < TabItemShowCloseBtnMode or CInt(var) > TabItemShowCloseBtnMode) Then
				TabItemShowCloseBtnMode = CInt(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 >= 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
			On Error Resume Next  
			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
			On Error GoTo 0	
		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
			On Error Resume Next  
			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
			On Error GoTo 0	
		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 = 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	
			SetTabRebarRes(TabPostion)		
			ChangeTabsUI()
		'---------------------------------------------------------------------------------------
		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 = "GoButton" or  childId = "btnNavForward" or childId = "btnNavStop" or childId = "btnNavRefresh" or childId = "btnNavList" or childId = "btnSeparator" or childId = "btnHomePage" or childId = "btnLastNav" or childId = "btnLastNavList") 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 = "btnClearNavRecord") Then
			'	Window.ExeCommand 115 , 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				
			End if
		end if
	ElseIf(childId = "AddressBar" or  childId = "Rebar" or childId = "toolbar" or childId = "SearchBar" or childID = "LinkBar" or childID = "FavBar" or childID = "MenuContainer") Then
		If(code = 1) then 
			window.ExeCommand 65004 , code
		ElseIf(code = 0) Then
			Window.ExeCommand 65010 , code		
		End if

	ElseIf(childId = "MainMenu") Then
		Window.ExeCommand 106 , code
	ElseIf(childId = "HighLightButton") Then
		Window.ExeCommand 122 , code
	ElseIf(childId = "SearchButton") Then
		Window.ExeCommand 108 , code
	ElseIf(childId = "btnClose") Then
		Window.ExeCommand 112 , 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 = "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
		On Error Resume Next  
		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
		On Error GoTo 0	
	'---------------------------------


	'---------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
		On Error Resume Next  
		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
		On Error GoTo 0	
	'----------------------------------

	End if
End Sub

Sub ChangeTabsUI()
	Window.LockPaint()

	AdjustTabToolBar()	
	
	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()
	GetTabCount()
	GetActiveTabID()
    childCount = TabCount
	
	'TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - 5	
	TabCanUseWidth = TabBar.width - btnSidebar.width - btnNewAPage.width - 10
	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
	TabWantUseWidth = (TabItemMaxWidth) * (childCount - FirstItemIndex)
	if(childCount = 0) Then
		AllTabs.width = 0
	ElseIf(TabCanUseWidth > TabWantUseWidth) Then	
		AllTabs.width = TabWantUseWidth
	Else
		AllTabs.width = TabCanUseWidth'(TabItemMaxWidth - 1) * (TabCanShowCount) + 1	
	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
			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()
	GetTabCount()
	GetActiveTabID()
    childCount = TabCount	
	'TabCanUseWidth = TabBar.width - btnSidebar.width -  btnSidebar.left - 5	
	TabCanUseWidth = TabRebar.width  - btnSidebar.width - btnNewAPage.width - 8	- RToolbar.width
	'TabWantUseWidth = (TabItemMaxWidth) * childCount + 1
	TabWantUseWidth = (TabItemMaxWidth) * childCount
	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
				SetTabItemFont AllTabs.ChildById(ContainerName).ChildById(TabName), 1
				SetTabItemCloseInfo AllTabs.ChildById(ContainerName).ChildById(TabName), AllTabs.ChildById(ContainerName).ChildById(TabCloseName), 1				
				bLeftofActive = 0
			Else
				'If(AllTabs.ChildById(ContainerName)=0) then
				'else
				'	MsgBox ContainerName
				'End if
				'MsgBox ContainerName
				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
	Else
		AllTabs.width = TabCanUseWidth


		if(childCount > 0) Then
			tabWidth = (AllTabs.width) \ childCount
			tabWidthMod = (AllTabs.width) Mod childCount
			bLeftofActive = 1
			
			if( tabWidth < 50 )then
				bTooSmallToShowCloseBTN = true
			else
				bTooSmallToShowCloseBTN = false		
			end if
			
			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
					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				
				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
				'if(AllTabs.ChildById(ContainerName).width < 36) Then
				'	AllTabs.ChildById(ContainerName).ChildById(TabName).labelRightPadding = 5	
				'	AllTabs.ChildById(ContainerName).ChildById(TabCloseName).Visible = 0
				'End if					
			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 Window_OnShowStateChange(nCmdShow)

	ChangeTabsUI()	
	ChangeFrameParam(nCmdShow)	
	if IsFullScreenMode = 0 then
		If nCmdShow = SS_RESTORED Then
			btnSystemBtnRestore.visible = false
			btnSystemBtnMax.visible = True
		elseIf nCmdShow = nCmdShow Then
			btnSystemBtnRestore.visible = true
			btnSystemBtnMax.visible = False
		End If
	end if
End Sub

sub ChangeFrameParam(nCmdShow)
	if(nCmdShow = SS_MAXIMIZED)then
		BKLeft.width = 0
		BKRight.width = 0
		BKBottom.height = 0
		BKLeftBorder.width = 0
		BKLeftBorder.height = 0	
		BKRightBorder.width = 0
		BKRightBorder.height= 0
		'StatusBar.height = 24 
		BKBottom.visible = false
		if(ThemeDraw = 1)then
			CaptionBK.image="CaptionOpaque.bmp"
		end if
	elseif(nCmdShow = SS_RESTORED)then
		BKLeft.width = 4
		BKRight.width = 4
		BKBottom.height = 4
		BKLeftBorder.width = 4
		BKLeftBorder.height = 4	
		BKRightBorder.width = 4
		BKRightBorder.height= 4	
		'StatusBar.height = 24 + BKBottom.height
		BKBottom.visible = true
		if(ThemeDraw = 1)then
			CaptionBK.image="CaptionTransparent.bmp"	
		end if	
	end if
	WindowLayOut()
end sub

Sub btnSystemBtnMin_onClick()
	window.ShowWindow SC_MINIMIZE
End Sub

Sub btnSystemBtnMax_onClick()
	btnSystemBtnMax.visible = false
	btnSystemBtnRestore.visible = true
	ChangeFrameParam(SC_MAXIMIZE)
	window.ShowWindow SC_MAXIMIZE
End Sub

Sub btnSystemBtnRestore_onClick()
	btnSystemBtnMax.visible = true
	btnSystemBtnRestore.visible = false
	ChangeFrameParam(SC_RESTORE)
	window.ShowWindow SC_RESTORE
End Sub

Sub btnSystemBtnClose_onClick()
	window.ShowWindow SC_CLOSE
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 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 SetTabRebarRes(bOnTop)
    if IsFullScreenMode = 1 then
        bOnTop = 1
    end if
    
	if(bOnTop = 0) Then
		'TabRebarStretch.image = "Tab/tabrebar_stretch_bottom.png"
		
		btnSidebar.image = "Tab/Fav_Normal.png"
		btnSidebar.downimage = "Tab/Fav_Down.png"
		btnSidebar.hoverimage = "Tab/Fav_Hover.png"
		btnNewAPage.image = "Tab/New_Normal.png"
		btnNewAPage.downimage = "Tab/New_Down.png"
		btnNewAPage.hoverimage = "Tab/New_Hover.png"	
		
		RTBBk.image = "tab/RTBBK_Bottom.png"
		RTBBk.top = 1

		btnMoveBack.image = "RTBMoveBack_Normal.png"
		btnMoveBack.downimage = "RTBMoveBack_Down.png"
		btnMoveBack.hoverimage = "RTBMoveBack_Hover.png"

		btnMoveFor.image = "RTBMoveFor_Normal.png"
		btnMoveFor.downimage = "RTBMoveFor_Down.png"
		btnMoveFor.hoverimage = "RTBMoveFor_Hover.png"
		
		btnNewPage.image = "RTBNewPage_Normal.png"
		btnNewPage.downimage = "RTBNewPage_Down.png"
		btnNewPage.hoverimage = "RTBNewPage_Hover.png"

		btnNewPageSelect.image = "RTBNewPageSelect_Normal.png"
		btnNewPageSelect.downimage = "RTBNewPageSelect_Down.png"
		btnNewPageSelect.hoverimage = "RTBNewPageSelect_Hover.png"

		btnBack.image = "RTBBack_Normal.png"
		btnBack.downimage = "RTBBack_Down.png"
		btnBack.hoverimage = "RTBBack_Hover.png"		

		btnBackSelect.image = "RTBBackSelect_Normal.png"
		btnBackSelect.downimage = "RTBBackSelect_Down.png"
		btnBackSelect.hoverimage = "RTBBackSelect_Hover.png"	

		btnClose.image = "RTBClose_Normal.png"
		btnClose.downimage = "RTBClose_Down.png"
		btnClose.hoverimage = "RTBClose_Hover.png"

		'TabbarMakeupBk.image = "Tab/TabbarMakeupBk_Bottom.bmp"			
		
	Else 
		'TabRebarStretch.image = "Tab/tabrebar_stretch_top.png"
		
		btnSidebar.image = "Tab/Fav_Normal.png"
		btnSidebar.downimage = "Tab/Fav_Down.png"
		btnSidebar.hoverimage = "Tab/Fav_Hover.png"
		btnNewAPage.image = "Tab/New_Normal.png"
		btnNewAPage.downimage = "Tab/New_Down.png"
		btnNewAPage.hoverimage = "Tab/New_Hover.png"		
		
		RTBBk.image = "tab/RTBBK.png"
		RTBBk.top = 1

		btnMoveBack.image = "RTBMoveBack_Normal.png"
		btnMoveBack.downimage = "RTBMoveBack_Down.png"
		btnMoveBack.hoverimage = "RTBMoveBack_Hover.png"

		btnMoveFor.image = "RTBMoveFor_Normal.png"
		btnMoveFor.downimage = "RTBMoveFor_Down.png"
		btnMoveFor.hoverimage = "RTBMoveFor_Hover.png"
		
		btnNewPage.image = "RTBNewPage_Normal.png"
		btnNewPage.downimage = "RTBNewPage_Down.png"
		btnNewPage.hoverimage = "RTBNewPage_Hover.png"

		btnNewPageSelect.image = "RTBNewPageSelect_Normal.png"
		btnNewPageSelect.downimage = "RTBNewPageSelect_Down.png"
		btnNewPageSelect.hoverimage = "RTBNewPageSelect_Hover.png"

		btnBack.image = "RTBBack_Normal.png"
		btnBack.downimage = "RTBBack_Down.png"
		btnBack.hoverimage = "RTBBack_Hover.png"		

		btnBackSelect.image = "RTBBackSelect_Normal.png"
		btnBackSelect.downimage = "RTBBackSelect_Down.png"
		btnBackSelect.hoverimage = "RTBBackSelect_Hover.png"	

		btnClose.image = "RTBClose_Normal.png"
		btnClose.downimage = "RTBClose_Down.png"
		btnClose.hoverimage = "RTBClose_Hover.png"

		'TabbarMakeupBk.image = "Tab/TabbarMakeupBk.bmp"	
		
	End if
End Sub

Sub SetTabItemImg(TabItemID, bActive, bLeftofActive)
    IsTabOnTop = TabPostion
    
    if IsFullScreenMode = 1 then
        IsTabOnTop = 1
    end if

	TabItemID.height = 26
	TabItemID.tip = TabItemID.label
	TabItemID.IconTopPadding = 5
	If(bActive) Then
		if(IsTabOnTop = 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"				
		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"				
		End if
	Else
		if(IsTabOnTop = 0) 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_Bottom.png"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle_Bottom.png"
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder_Bottom.png"						
		Else	
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder.png"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle.png"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder.png"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder.png"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle.png"
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder.png"								
		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)
	TabCloseItemID.top = 7
	
	if( 0 = TabItemShowCloseBtnMode )Then
		TabItemID.labelRightPadding = 5
		TabCloseItemID.Visible = false		
 	elseif( 1 = TabItemShowCloseBtnMode  ) Then
		if(bActive)then
			TabItemID.labelRightPadding = 20
			TabCloseItemID.Visible = true	
		else
			TabItemID.labelRightPadding = 5
			TabCloseItemID.Visible = false					
		end if
	elseif( 2 = TabItemShowCloseBtnMode)then
		if(bActive)then
			TabItemID.labelRightPadding = 20
			TabCloseItemID.Visible = true	
		else
			TabItemID.labelRightPadding = 5
			TabCloseItemID.Visible = false					
		end if
	elseif( 3 = TabItemShowCloseBtnMode )then		
		TabItemID.labelRightPadding = 20
		TabCloseItemID.Visible = 1				
		TabCloseItemID.image = "Tab/TabClose_Normal.png"
		TabCloseItemID.hoverImage = "Tab/TabClose_Hover.png"
		TabCloseItemID.downimage = "Tab/TabClose_Down.png"	
	End if
	
	if( TabCloseItemID.Visible and bTooSmallToShowCloseBTN )then
		if( 0 = bActive ) Then
			TabItemID.labelRightPadding = 5	
			TabCloseItemID.Visible = false
		End if	
	end if	
End Sub

Sub SetTabItemCloseInfo2(ChildNumber)
	IsUseTabTop = IsTabPostionOnTop
	if IsFullScreenMode = 1 then
	    IsUseTabTop = 1
	end if
	
	if( ( 2 = TabItemShowCloseBtnMode )) Then	
		'GetActiveTabID()
		'if(ChildNumber <> ActiveTabID) Then
			ContainerName = "TabContain" + CStr(ChildNumber)
			TabName = "TabItem"+CStr(ChildNumber)
			TabCloseName = "TabClose" + CStr(ChildNumber)
			
			if(bTooSmallToShowCloseBTN and ( ChildNumber <> ActiveTabID) )then
				AllTabs.ChildById(ContainerName).ChildById(TabCloseName).Visible = 0		
				AllTabs.ChildById(ContainerName).ChildById(TabName).labelRightPadding = 5		
			else
				AllTabs.ChildById(ContainerName).ChildById(TabCloseName).Visible = 1
				AllTabs.ChildById(ContainerName).ChildById(TabName).labelRightPadding = 20	
			end if	
		
			IsMouseEnterTab = 1
			MouseEnterTabNumber = ChildNumber
		'End if
	End if
End Sub

Sub SetTabItemCloseInfo3(childId)
	if( ( 2 = TabItemShowCloseBtnMode ) 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) and (ActiveTabID <> MouseEnterTabNumber) ) 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 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 reportPluginbarStatus()
	window.ExeCommand 500, ShowPluginBar
end sub

Sub AdjustLinkBar()

	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="#000000"
		'LinkItemCont.Child(i).LabelColorHover="#000000"
		LinkItemCont.Child(i).LabelColor = FavLinkLabelColor
		LinkItemCont.Child(i).LabelColorHover = FavLinkLabelColor		
	Next	

	btnMoreLinkItems.Left=LinkBar.width-btnMoreLinkItems.width

	'调整显示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()

	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="#000000"
		'FavItemCont.Child(i).LabelColorHover="#000000"
		FavItemCont.Child(i).LabelColor=FavLinkLabelColor
		FavItemCont.Child(i).LabelColorHover=FavLinkLabelColor
	Next	

	btnMoreFavItems.Left=FavBar.width-btnMoreFavItems.width

	'调整显示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 AdjustTabToolBar()

    IsTabOnTop = TabPostion
    
    if IsFullScreenMode = 1 then
        IsTabOnTop = 1
    end if

	RToolbar.width = 85
	RToolbar.left = TabRebar.width - RToolbar.width
	RTBBk.width = 85	
	if(IsTabOnTop = 1) Then
		RTBBk.image = "tab/RTBBK.png"
	Else
		RTBBk.image = "tab/RTBBK_Bottom.png"
	End if	
	
	RMovebar.left = RToolbar.left - RMovebar.width - 2
	
	if(IsTabwidthStable = 1) Then
		GetTabCount()
		TabCanUseWidth = cxClient - 2  - RToolbar.width - btnSidebar.width - btnNewAPage.width	
		TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth
		if(TabCanShowCount < TabCount) Then
			RMovebar.visible = 1
			TabBar.width =  RMovebar.left '- TabBar.left '- RMovebar.width			
		Else
			FirstItemIndex = 0
			RMovebar.visible = 0
			TabBar.width =  RToolbar.left '- TabBar.left '- 20					
		End if			
	Else
		RMovebar.visible = 0	
		TabBar.width =  RToolbar.left '- TabBar.left '- 20			
	End if

	HideSomeBtnsFromRToolBar()

End Sub

Sub HideSomeBtnsFromRToolBar()
	If(IsHideSomeBtnsFromRToolBar) Then
		RMovebar.Left = RMovebar.Left + btnNewPage.width*2

	    TabBar.width =  RMovebar.left - TabBar.Left
   		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - btnNewAPage.width - 10	


		RToolbar.width = RToolbar.width - btnNewPage.width*2
		RToolbar.left = TabRebar.width - RToolbar.width

		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
	Else
		btnTextMode.visible = 1
		btnBack.left = 44
		btnBackSelect.left = 44
		btnClose.left = 63

	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 btnCaptionFeedback_onClick()
	Window.ExeCommand 1999, 0
End Sub


Sub RefreshFrame()

	RefreshElement(ThemeTitleBar)
	RefreshElement(btnSystemBtnMin)
	RefreshElement(btnSystemBtnMax)
	RefreshElement(btnSystemBtnRestore)
	RefreshElement(btnSystemBtnClose)

	RefreshElement(BKLeft)
	RefreshElement(BKRight)
	RefreshElement(BKBottom)

end Sub

sub RefreshElement(obj)

	if obj.visible then
		obj.visible = false
		obj.visible = true
	end if

end sub