'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 IsToolBarLargeOrSmall
Dim NextTabID
Dim ActiveTabID
Dim IsTabPostionOnTop 'tab是否在上
Dim ShowSidebar
Dim ShowFindbar
Dim ShowElementExtractbar
Dim ElementExtractSelectAll
Dim bShowSearchBar
Dim SidebarWidth
Dim IsTabwidthStable
Dim TabItemMaxWidth
Dim FirstItemIndex
Dim ShowPluginBar
Dim IsTabItemShowCloseBtn
Dim IsActiveTabBoldFont
Dim AutoAdjustActiveTabItem
Dim IsTabBarShowNewBtn
Dim IsShowLinkBar
Dim IsShowFavBar
Dim IsSidebarFloat
Dim MinSideBarWidth
Dim MaxSideBarWidth
Dim IsHighLightDown
Dim IsFullScreenMode

Dim RebarSepHeight 'rebar下方到tabbar的补偿

Dim ShowTabMovePicSrcId
Dim ShowTabMovePicTgtId
Dim ShowTabMovePicDirection
Dim ShouldHideTabMovePic

Dim IsTabItemShowCloseBtnOnMouseOver
Dim IsMouseEnterTab
Dim	MouseEnterTabNumber
Dim	FavLinkLabelColor
Dim ShowWebPagebar
Dim nMBrowserTop

Dim IsHideSomeBtnsFromRToolBar
Dim PluginBarWidth

sub WindowLayOut()	
	Window.LockPaint()

	RelayoutToolbar(toolbar_s)
	RelayoutToolbar(toolbar)

    if IsFullScreenMode = 0 then
		MenuDragContainer.visible = true
		'MenuDragContainer.width = cxClient
		MenuContainer.visible = true		
		MenuBar.visible = true
		MaxWndToolBtns.visible = false
	    MenuContainer.width = cxClient
		'MenuBarBottomLine.width = cxClient
		TabRebar.width = cxClient
		RebarBK.left = 0
		RebarBK.width = cxClient
		RebarBK.height = cyClient		
		'searchbar
		AdjustSearchBar()

		'menubar
		MenuContainer.width = MenuDragContainer.width - MenuContainer.Left
		MenuContainer.height = MenuDragContainer.height
		If(MenuContainer.width < 346) Then
			btnMoreMenu.visible=true
			btnMoreMenu.Left = MenuContainer.width - btnMoreMenu.width
			btnMoreMenu.top = (MenuContainer.height - btnMoreMenu.height)/2
			MenuBar.width = MenuContainer.width - btnMoreMenu.width
		Else
			MenuBar.width = MenuContainer.width
			btnMoreMenu.visible = false
		End if

		' toolbar browsertoolbar pluginbar
		AjustToolBar
		AjustBrowerToolBar
		AdjustPluginBar()
		
	    'linkbar
	    If(IsShowLinkBar) Then
		    LinkBar.visible=true
				'LinkBarStretch.width = LinkBar.width
		    AdjustLinkBar()
	    Else
		    LinkBar.visible=false
	    End if 

	    'Favbar
	    If(IsShowFavBar) Then
		    FavBar.visible=true
		    'FavBarStretch.width = FavBar.width
		    AdjustFavBar()
	    Else
		    FavBar.visible=false
	    End if
		
		RelayeroutPlugins()
		
		RelayoutPluginBtn()

		'StatusBar
	    StatusBar.height = 24
	    StatusBar.left = 0
	    StatusBar.width = cxClient
	    StatusBar.top = cyClient - StatusBar.height

		StatusBarBK.left = 0
	    StatusBarBK.width = StatusBar.width
	    StatusBarBK.top = StatusBar.top

	    'Tab
	    if(IsTabPostionOnTop = 0) Then
		    TabRebarStretch.left = 0	
		    TabRebarStretch.width = cxClient
            TabRebar.top = StatusBar.top - TabRebar.height
		    TabBar.top = 0
		    btnSidebar.top = 2
		    btnNewAPage.top = 2
		    RToolbar.top = 0
		    RMovebar.top = 0		
		    btnMoveBack.top = 4
		    btnMoveFor.top = 4
			btnTextMode.top = 2
		    btnNewPage.top = 2
		    btnNewPageSelect.top = 2
		    btnBack.top = 2
		    btnBackSelect.top = 2
		    btnClose.top = 4
	
		    if(TabRebar.top > (Window.ReBarBottom + RebarSepHeight -1)) Then
			    MainArea.height = TabRebar.top - Window.ReBarBottom - RebarSepHeight - 1		
		    Else
			    MainArea.height = 0		
		    End if
			
            MainArea.top = Window.ReBarBottom + RebarSepHeight + 1
		    AllTabs.top = 0
    		
		    TabbarMakeupBk.top = 0
			RebarBottomLine.visible = true
			RebarBottomLine.top = Window.ReBarBottom
			RebarBottomLine.width = cxClient	
			RebarTopLine.visible = false			
	    Else
			RebarBottomLine.visible = false
			RebarTopLine.visible = false
			'RebarTopLine.top = 	Window.ReBarBottom + RebarSepHeight
			'RebarTopLine.width = cxClient
			TabRebar.top = Window.ReBarBottom + RebarSepHeight
		    TabRebarStretch.left = 0	
		    TabRebarStretch.width = cxClient
		    TabBar.top = 0
		    btnSidebar.top = 1
		    btnNewAPage.top = 1	
		    RToolbar.top = 0
		    RMovebar.top = 0		
		    btnMoveBack.top = 4
		    btnMoveFor.top = 4
			btnTextMode.top = 2
		    btnNewPage.top = 2
		    btnNewPageSelect.top = 2
		    btnBack.top = 2
		    btnBackSelect.top = 2
		    btnClose.top = 4
		    MainArea.top = TabRebar.top + TabRebar.height '+1
		    MainArea.height = StatusBar.top - (TabRebar.top + TabRebar.height)
			If(MainArea.height < 0) Then
				MainArea.height = 0
			End if
    		
		    AllTabs.top = 1
		    AllTabs.top = 1
    		
		    TabbarMakeupBk.top = 1
	    End If
	    
	    AjustBrowserHeight()

	    RToolbar.left = TabRebar.width  - RToolbar.width
	    RMovebar.left = RToolbar.left - RMovebar.width - 2
    	
	    TabBar.left = 0
	    if(RMovebar.visible = true) Then
		    TabBar.width =  RMovebar.left - TabBar.left
	    Else
		    TabBar.width =  RToolbar.left - TabBar.left	
	    End if
    	
	    btnSidebar.left = TabBar.left + 2
	    btnSidebar.width = 20	
	    AllTabs.Left = btnSidebar.Left + btnSidebar.width + 2
	    btnNewAPage.left = AllTabs.left + AllTabs.width + 2
	    btnNewAPage.width = 20
	    TabbarMakeupBk.left = 0
	    TabbarMakeupBK.width = cxClient
        SetTabBarNoMessage()
        
	    'MainArea
	    MainArea.width = cxClient
	    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(IsTabPostionOnTop = 0) Then
			If(StatusBar.top < TabRebar.top + TabRebar.height) Then
				StatusBar.visible = False
				StatusBarBK.visible = False
			Else
				StatusBar.visible = true
				StatusBarBK.visible = true
			End If
		Else 
			If(StatusBar.top < MainArea.top + MainArea.height) Then
				StatusBar.visible = False
				StatusBarBK.visible = False
			Else
				StatusBar.visible = true
				StatusBarBK.visible = true
			End If
		End if
	else
	    RebarBK.visible = true
	    'toolbar.visible = true
		AjustToolBar()
	    AddressBar.visible = true
	    SearchBar.visible = true
	    RebarTopLine.visible = true
	    TabRebar.visible = true
	    RebarBottomLine.visible = false
		MainArea.visible = true
		'browsertoolbar.visible = true
		AjustBrowerToolBar()
		
		MenuDragContainer.visible = true
	    MenuContainer.visible = false
		MenuBar.visible = false
	    BtnPluginCont.visible = False
		BtnPluginCont_s.visible = False
	    BtnPluginCont_s.visible = false
	    LinkBar.visible = false
	    FavBar.visible = false
		StatusBar.visible = false
		StatusBarBK.visible = false
		
		curTop = 0
		MaxWndToolBtns.visible = true
	    MaxWndToolBtns.top = 0
	    MaxWndToolBtns.left = cxClient - MaxWndToolBtns.width - 5
	    'MaxWndToolBtns.width = 100
	    MaxWndToolBtns.Height = 34
		
		RebarBK.top = curTop
		RebarBK.left = 0
		RebarBK.width = cxClient
		RebarBK.height = cyClient		
	
		If(IsToolBarLargeOrSmall = 0) Then
			toolbar.top = curTop
			toolbar.left = 0
			browsertoolbar.top = curTop
			browsertoolbar.left = toolbar.left + toolbar.width
			curTop = curTop + 48
		ElseIf(IsToolBarLargeOrSmall = 1) Then
			toolbar_s.top = curTop
			toolbar_s.left = 0
			browsertoolbar_s.top = curTop
			browsertoolbar_s.left = toolbar_s.left + toolbar_s.width
			curTop = curTop + 28
		End if
		
		'browsertoolbar.width = browsertoolbar.width
		'browsertoolbar.height = 48
		
		
		
		AddressBar.top = curTop
		AddressBar.left = 0
		AddressBar.width = cxClient - 226
		AddressBar.height = 26
		
		SearchBar.top = curTop
		SearchBar.left = cxClient - 226
		SearchBar.width = 226
		SearchBar.height = 26
		
		curTop = curTop + 26
		
		RebarTopLine.top = curTop
		RebarTopLine.left = 0
		RebarTopLine.width = cxClient
		RebarTopLine.height = 1		
		
		curTop = curTop + 1
		
		TabRebar.top = curTop
		TabRebar.left = 0
		TabRebar.width = cxClient
		TabRebar.height = 23
						
'		RebarBottomLine.top = 48 + 22 + 1 + 23
'		RebarBottomLine.left = 0
'		RebarBottomLine.width = cxClient
'		RebarBottomLine.height = 1
		
		curTop = curTop + 23
		MainArea.top = curTop
		MainArea.left = 0
		MainArea.width = cxClient
		MainArea.height = cyClient - (48 + 22 + 1 + 23 )					

        'adjust searchbar
		SearchBar.Visible = true
	    SearchBarDlg.Visible = true
	    SearchBorderIMG.width = SearchBar.width - HighLightButton.width - SearchButton.width  - SearchBorderLeft.Left - SearchBorderLeft.width - 2
	    SearchBorderRight.left = SearchBorderIMG.left + SearchBorderIMG.width  
	    SearchBarDlg.width = SearchBar.width - SearchButton.width - HighLightButton.width - SearchBorderLeft.Left - SearchBorderLeft.width -2
	    SearchButton.left = SearchBar.width - SearchButton.width - HighLightButton.width
	    HighLightButton.left = SearchBar.width - HighLightButton.width
	    AddrBorderIMG.width = AddressBar.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - GoButton.width - 2
	    AddrBorderRight.left = AddrBorderIMG.left + AddrBorderIMG.width
	    AddrssCombo.width = AddressBar.width - GoButton.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - AddrBorderRight.width - 2
	    GoButton.left = AddressBar.width - GoButton.width - 1
		If(IsHighLightDown) Then
		    HighLightButton.image = "Highlight_Down.png"
		    HighLightButton.hoverImage = "Highlight_Down.png"	
		    HighLightButton.downImage = "Highlight_Down.png"			
	    Else
		    HighLightButton.image = "Highlight_Normal.png"
		    HighLightButton.hoverImage = "Highlight_Hover.png"	
		    HighLightButton.downImage = "Highlight_Down.png"		
	    End If		    
	    '
	    'Tab
	    TabRebarStretch.left = 0	
	    TabRebarStretch.width = cxClient
	    TabBar.top = 0
	    btnSidebar.top = 1
	    btnNewAPage.top = 1	
	    RToolbar.top = 0
	    RMovebar.top = 0		
	    btnMoveBack.top = 4
	    btnMoveFor.top = 4
		btnTextMode.top = 2
	    btnNewPage.top = 2
	    btnNewPageSelect.top = 2
	    btnBack.top = 2
	    btnBackSelect.top = 2
	    btnClose.top = 4
	 		
	    AllTabs.top = 1
		
	    TabbarMakeupBk.top = 1

	   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

	    RToolbar.left = TabRebar.width  - RToolbar.width
	    RMovebar.left = RToolbar.left - RMovebar.width - 2
    	
	    btnSidebar.left = TabBar.left + 2
	    btnSidebar.width = 20	
	    AllTabs.Left = btnSidebar.Left + btnSidebar.width + 2
	    btnNewAPage.left = AllTabs.left + AllTabs.width + 2
	    btnNewAPage.width = 20
	    TabbarMakeupBk.left = 0
	    TabbarMakeupBK.width = cxClient	    
	    SetTabBarNoMessage()
	    
	end if
	AdjustToolBarImage()
	
	Window.UnLockPaint()
end sub	

Sub AjustToolBar()
	If(IsToolBarLargeOrSmall = 0) Then
		toolbar.visible = true
	
		toolbar_s.visible = false
	ElseIf(IsToolBarLargeOrSmall = 1) Then
		toolbar.visible = false
		toolbar_s.visible = true
	End If	
end sub	

Sub AjustBrowerToolBar()
	If(IsToolBarLargeOrSmall = 0) Then
		browsertoolbar.visible = true
		browsertoolbar_s.visible = false	
	ElseIf(IsToolBarLargeOrSmall = 1) Then
		browsertoolbar.visible = false
		browsertoolbar_s.visible = True
	End If	
end sub	

Sub AdjustPluginBar()
	IF (ShowPluginBar = 1) Then
		If(IsToolBarLargeOrSmall = 0) Then
			BtnPluginCont.visible = true
			BtnPluginCont_s.visible = false
		ElseIf(IsToolBarLargeOrSmall = 1) Then
			BtnPluginCont.visible = false
			BtnPluginCont_s.visible = true
		End If
	ELSE
		BtnPluginCont.visible = false
		BtnPluginCont_s.visible = false
	END If
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 AdjustToolBarImage()
	
end sub

Sub Window_OnShowStateChange(nCmdShow)

	ChangeTabsUI()	
End Sub



sub Window_WindowLayOut(cx, cy, wndState)
	cxClient = cx
	cyClient = cy
	WindowLayOut()	
end Sub

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

Sub Window_OnInit()
	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
	IsTabPostionOnTop = 1
	ShowSidebar = 0
	SidebarWidth = 214
	MinSideBarWidth = 192
	MaxSideBarWidth = 600	
	IsTabwidthStable = 0
	TabItemMaxWidth = 155
	FirstItemIndex = 0
	ShowPluginBar = 0
	avtiveSidebarID = "btnSidebarHistory"
	IsTabItemShowCloseBtn = 1
	AutoAdjustActiveTabItem = 1		
	bShowSearchBar = 0
	IsTabBarShowNewBtn = 1	
	IsShowLinkBar = false
	IsShowFavBar = false
	IsSidebarFloat = 1
	IsFullScreenMode = 0
	ShowTabMovePicSrcId = "InvalidTabItemId"
	ShowTabMovePicTgtId = "InvalidTabItemId"	
	ShowTabMovePicDirection = 0
	ShouldHideTabMovePic = 0	
	RebarSepHeight = 0
	
	IsToolBarLargeOrSmall = 4
	IsHideSomeBtnsFromRToolBar = 0


	Window.ExeCommand 70002, IsToolBarLargeOrSmall
	IsTabItemShowCloseBtnOnMouseOver = 0
	IsMouseEnterTab	= 0
	InsertMark.Visible = FALSE
	FavLinkLabelColor = "#000000"
	ShowWebPagebar = 0
	AjustToolBar()
	ShowElementExtractbar = 0
	ElementExtractSelectAll = 0
	AjustBrowerToolBar()
	PluginBarWidth = 0
End Sub

Sub Window_OnNotify(code ,var)

	call WindowNotify_traditional( code ,var)	'plugin
	
		if (code =  1) then
			FirstRebar.height = var
		Elseif(code = 2) Then    '增加了tab后调整宽度
			ChangeTabsUI()
		Elseif(code = 45000) Then
			window.ShowWindow SC_MAXIMIZE
		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
			IsTabPostionOnTop = 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 = 70003) Then
			IsToolBarLargeOrSmall = var
			WindowLayOut()	
			if(IsToolBarLargeOrSmall = 0)then
				BtnPluginCont.ExternalAttribute("MinWidth") = CInt(PluginBarWidth)
			Elseif (IsToolBarLargeOrSmall = 1) Then
				BtnPluginCont_s.ExternalAttribute("MinWidth") = CInt(PluginBarWidth)
			end if				
		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()
			reportPluginbarStatus()
		Elseif(code = 30019)Then
			bShowSearchBar = var
			WindowLayOut()			
		'总是打开新窗口
		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 , IsTabPostionOnTop	
		Elseif(code = 30006) Then
			If(IsHideSomeBtnsFromRToolBar = 0) Then
				btnNewPage.visible = false
				btnNewPageSelect.visible = True
			End if
			Window.ExeCommand 117 , var	
			If(IsHideSomeBtnsFromRToolBar = 0) Then
				btnBack.visible = false
				btnBackSelect.visible = true
			End if
			Window.ExeCommand 119 , var
		Elseif(code = 30800)then
			if(IsToolBarLargeOrSmall = 0)then
				BtnPluginCont.ExternalAttribute("MinWidth") = CInt(PluginBarWidth)
			Elseif (IsToolBarLargeOrSmall = 1) Then
				BtnPluginCont_s.ExternalAttribute("MinWidth") = CInt(PluginBarWidth)
			end if		
		Elseif(code = 65103) Then ' change tab postion top
			IsTabPostionOnTop = 0
			SetTabRebarRes(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 = 30500 ) Then    'setpluginicon
			UpdateBtnPluginIcon(var)
			WindowLayOut()	
		Elseif(code = 30600 ) Then    'setplugintext
			UpdateBtnPluginText(var)
			WindowLayOut()	
		ElseIf(code = 30007) Then
			If(var = 1) Then
				btnNavBack.disabled = False
				btnNavBack.ico = "IDI_NAVBAR_GO_BACK_NORMAL.ico"
				btnNavBack_s.disabled = False
				btnNavBack_s.ico = "IDI_NAVBAR_GO_BACK_NORMAL.ico"
			Else
				btnNavBack.disabled = True
				btnNavBack.ico = "IDI_NAVBAR_GO_BACK_DISABLED.ico"
				btnNavBack_s.disabled = True
				btnNavBack_s.ico = "IDI_NAVBAR_GO_BACK_DISABLED.ico"
			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
				btnNavForward.ico = "IDI_NAVBAR_GO_FORWARD_NORMAL.ico"
				btnNavForward_s.disabled = False
				btnNavForward_s.ico = "IDI_NAVBAR_GO_FORWARD_NORMAL.ico"
			Else
				btnNavForward.disabled = True
				btnNavForward.ico = "IDI_NAVBAR_GO_FORWARD_DISABLED.ico"
				btnNavForward_s.disabled = True
				btnNavForward_s.ico = "IDI_NAVBAR_GO_FORWARD_DISABLED.ico"
			End if
		ElseIf(code = 30010) Then
			If(var = 1)Then
				btnNavList.disabled = False
				btnNavList_s.disabled = False
			Else
				btnNavList.disabled = True
				btnNavList_s.disabled = True
			End if
		ElseIf(code = 30011) Then
			If(var = 1)Then
				btnLastNav.disabled = False
				btnLastNavList.disabled = False
				btnLastNav.ico = "IDI_NAVIGATE_CLOSELIST_NORMAL.ico"	
				btnLastNav_s.disabled = False
				btnLastNavList_s.disabled = False
				btnLastNav_s.ico = "IDI_NAVIGATE_CLOSELIST_NORMAL.ico"	
			Else
				btnLastNav.disabled = True
				btnLastNavList.disabled = True
				btnLastNav.ico = "IDI_NAVIGATE_CLOSELIST_DISABLED.ico"
				btnLastNav_s.disabled = True
				btnLastNavList_s.disabled = True
				btnLastNav_s.ico = "IDI_NAVIGATE_CLOSELIST_DISABLED.ico"
			End If
			
		'--------------------------------------searchbar------------------------------------
		ElseIf(code = 30050) Then
			if(var = 0) then
				IsHighLightDown = false
				WindowLayOut()
			elseif(var = 1) then
				IsHighLightDown = true	
				WindowLayOut()			
			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

		'-------------------------------------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 = 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(IsTabPostionOnTop)
			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 = "BtnPluginCont" Or childId = "UserIconMenu"  Or childId = "UserIconMenu_s" Or childId = "UserIconBK"  Or childId = "UserIconBK_s"  Or childId = "UserIcon"  Or childId = "UserIcon_s"   Or  childId = "BtnPluginCont_s" Or childId = "btnNavBack" Or childId = "btnNavBack_s" or childId = "btnWeather" or childId = "HighLightButton" or childId = "SearchButton" or childId = "GoButton" or childId = "btnNavForward" or childId = "btnNavForward_s" or childId = "btnNavStop" or childId = "btnNavStop_s" or childId = "btnNavRefresh" or childId = "btnNavRefresh_s" or childId = "btnNavList" or childId = "btnNavList_s" or childId = "btnSeparator" or childId = "btnHomePage" or childId = "btnHomePage_s" or childId = "btnLastNav" or childId = "btnLastNav_s" or childId = "btnLastNavList" or childId = "btnLastNavList_s" or childId = "btnClearNavRecord" or childId = "btnClearNavRecord_s" or childId = "btnSeparator2" ) Then
		If(code = 1) then 
			window.ExeCommand 65004 , code
		Else
			If(childId = "btnNavBack" Or childId = "btnNavBack_s" ) Then
				Window.ExeCommand 103 , code	
			ElseIf(childId = "btnNavForward" Or childId = "btnNavForward_s") Then
				Window.ExeCommand 104 , code
			ElseIf(childId = "btnNavStop" or childId = "btnNavStop_s") Then
				Window.ExeCommand 101 , code
			ElseIf(childId = "btnNavRefresh" or childId = "btnNavRefresh_s") Then
				Window.ExeCommand 102 , code
			ElseIf(childId = "btnNavList" or childId = "btnNavList_s") Then
				Window.ExeCommand 109 , code
			ElseIf(childId = "btnLastNav" or childId = "btnLastNav_s") Then
				Window.ExeCommand 113 , code
			ElseIf(childId = "btnHomePage" or childId = "btnHomePage_s") Then
				Window.ExeCommand 105 , code
			ElseIf(childId = "btnLastNavList" or childId = "btnLastNavList_s") 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				
			ElseIf(childId = "btnWeather") Then
				if(code = 0) then
					x = btnWeather.ClientLeft + 2
					y = btnWeather.ClientTop + btnWeather.Height - 1
						a = x * 65536 + y	
					Window.ExeCommand 44012 , a
				end if
			End if
		end if
	ElseIf(childId = "AddressBar"or  childId = "btnSeparatorSearch"  or childId = "toolbar" or childId = "toolbar_s" 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 = "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 = "btnMoreMenu") Then
		If(code = 0) then
		   	x = btnMoreMenu.ClientLeft
			y = btnMoreMenu.ClientTop + btnMoreMenu.Height - 1
			a = x * 65536 + y

			Set data = Window.CreateTTData
			data.SetDWord "dwX", x
			data.SetDWord "dwY", y
			data.SetDWord "dwItemHideCount", MenuBar.ItemHideCount

			Window.ExeCommand 200 , data	
		End if

	ElseIf(childId = "MainMenu") Then
		Window.ExeCommand 106 , 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
			a = 100000
			Window.ExeCommand 117 , a				
		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
	'----------------------------------
	End if
	
	if code = 0 then
		ProcessBtnPluginClick(childId)
	end if

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 - 10
	if(btnNewAPage.visible) Then
		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - btnNewAPage.width - 10	
	Else
		TabCanUseWidth = TabBar.width - btnSidebar.width - btnSidebar.left - 10
	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
	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 = 16				
	Next	
End Sub

Sub ChangeUnStableTabUI()
	AdjustTabToolBar()
	GetTabCount()
	GetActiveTabID()
    childCount = TabCount	
	'TabCanUseWidth = TabRebar.width - RToolbar.width - btnSidebar.width - btnNewAPage.width - 8
	if(btnNewAPage.visible) Then
		TabCanUseWidth = TabRebar.width - RToolbar.width - btnSidebar.width - btnNewAPage.width - 8	
	Else
		TabCanUseWidth = TabRebar.width - RToolbar.width - btnSidebar.width - 8	
	End if	
	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
				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 = 16				
		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
					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 = 16					
			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 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_Bottom.bmp"
'		btnSidebar.downimage = "Tab/Fav_Down_Bottom.bmp"
'		btnSidebar.hoverimage = "Tab/Fav_Hover_Bottom.bmp"
'		btnNewAPage.image = "Tab/New_Normal_Bottom.bmp"
'		btnNewAPage.downimage = "Tab/New_Down_Bottom.bmp"
'		btnNewAPage.hoverimage = "Tab/New_Hover_Bottom.bmp"	
		
		RTBBk.image = "RTBBK_Bottom.bmp"
		RTBBk.top = 1

		btnMoveBack.image = "RTBMoveBack_Normal_Bottom.bmp"
		btnMoveBack.downimage = "RTBMoveBack_Down_Bottom.bmp"
		btnMoveBack.hoverimage = "RTBMoveBack_Hover_Bottom.bmp"

		btnMoveFor.image = "RTBMoveFor_Normal_Bottom.bmp"
		btnMoveFor.downimage = "RTBMoveFor_Down_Bottom.bmp"
		btnMoveFor.hoverimage = "RTBMoveFor_Hover_Bottom.bmp"
		
		btnNewPage.image = "RTBNewPage_Normal_Bottom.bmp"
		btnNewPage.downimage = "RTBNewPage_Down_Bottom.bmp"
		btnNewPage.hoverimage = "RTBNewPage_Hover_Bottom.bmp"

		btnNewPageSelect.image = "RTBNewPageSelect_Normal_Bottom.bmp"
		btnNewPageSelect.downimage = "RTBNewPageSelect_Down_Bottom.bmp"
		btnNewPageSelect.hoverimage = "RTBNewPageSelect_Hover_Bottom.bmp"

		btnBack.image = "RTBBack_Normal_Bottom.bmp"
		btnBack.downimage = "RTBBack_Down_Bottom.bmp"
		btnBack.hoverimage = "RTBBack_Hover_Bottom.bmp"		

		btnBackSelect.image = "RTBBackSelect_Normal_Bottom.bmp"
		btnBackSelect.downimage = "RTBBackSelect_Down_Bottom.bmp"
		btnBackSelect.hoverimage = "RTBBackSelect_Hover_Bottom.bmp"	

		btnClose.image = "RTBClose_Normal_Bottom.bmp"
		btnClose.downimage = "RTBClose_Down_Bottom.bmp"
		btnClose.hoverimage = "RTBClose_Hover_Bottom.bmp"

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

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

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

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

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

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

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

		TabbarMakeupBk.image = "Tab/TabbarMakeupBk.bmp"	
		
	End if
End Sub
Sub SetTabItemImg(TabItemID, bActive, bLeftofActive)
	TabItemID.tip = TabItemID.label
	TabItemID.height = 22
	
	IsUseTabTop = IsTabPostionOnTop
	if IsFullScreenMode = 1 then
	    IsUseTabTop = 1
	end if
	
	If(bActive) Then
		if(IsUseTabTop = 0) Then
			TabItemID.LeftImage = "Tab/Tab_ActiveLeftBorder_Bottom.bmp"
			TabItemID.MiddleImage = "Tab/Tab_ActiveMiddle_Bottom.bmp"
			TabItemID.RightImage = "Tab/Tab_ActiveRightBorder_Bottom.bmp"
			TabItemID.HoverLeftImage = "Tab/Tab_ActiveLeftBorder_Bottom.bmp"
			TabItemID.HoverMiddleImage = "Tab/Tab_ActiveMiddle_Bottom.bmp"
			TabItemID.HoverRightImage = "Tab/Tab_ActiveRightBorder_Bottom.bmp"	
			TabItemID.IconTopPadding = 2			
		Else
			TabItemID.LeftImage = "Tab/Tab_ActiveLeftBorder.bmp"
			TabItemID.MiddleImage = "Tab/Tab_ActiveMiddle.bmp"
			TabItemID.RightImage = "Tab/Tab_ActiveRightBorder.bmp"
			TabItemID.HoverLeftImage = "Tab/Tab_ActiveLeftBorder.bmp"
			TabItemID.HoverMiddleImage = "Tab/Tab_ActiveMiddle.bmp"
			TabItemID.HoverRightImage = "Tab/Tab_ActiveRightBorder.bmp"
			TabItemID.IconTopPadding = 4				
		End if
	Else
		if(IsUseTabTop = 0) Then
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder_Bottom.bmp"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle_Bottom.bmp"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder_Bottom.bmp"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder_Bottom.bmp"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle_Bottom.bmp"
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder_Bottom.bmp"						
				TabItemID.IconTopPadding = 2	
		Else	
				TabItemID.LeftImage = "Tab/Tab_InactiveLeftBorder.bmp"
				TabItemID.MiddleImage = "Tab/Tab_InactiveMiddle.bmp"
				TabItemID.RightImage = "Tab/Tab_InactiveRightBorder.bmp"
				TabItemID.HoverLeftImage = "Tab/Tab_InactiveLeftBorder.bmp"				
				TabItemID.HoverMiddleImage = "Tab/Tab_InactiveMiddle.bmp"
				TabItemID.HoverRightImage = "Tab/Tab_InactiveRightBorder.bmp"								
				TabItemID.IconTopPadding = 4	
		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)
	IsUseTabTop = IsTabPostionOnTop
	if IsFullScreenMode = 1 then
	    IsUseTabTop = 1
	end if
	
	if(bActive = 0) Then
		TabItemID.labelRightPadding = 5			
		TabCloseItemID.Visible = 0	
	Else
		if(IsTabItemShowCloseBtn > 0) Then	
			TabItemID.labelRightPadding = 20
			TabCloseItemID.top = 4
			TabCloseItemID.Visible = 1				
			TabCloseItemID.width=16
			TabCloseItemID.height=16
			
		Else
			TabItemID.labelRightPadding = 5			
			TabCloseItemID.Visible = 0					
		End if
	End if
End Sub

Sub SetTabItemCloseInfo2(ChildNumber)
	IsUseTabTop = IsTabPostionOnTop
	if IsFullScreenMode = 1 then
	    IsUseTabTop = 1
	end if
	
	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 = 4
			AllTabs.ChildById(ContainerName).ChildById(TabCloseName).width=16
			AllTabs.ChildById(ContainerName).ChildById(TabCloseName).height=16
			
			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 AdjustTabToolBar()
	RToolbar.width = 85
	RTBBk.width = RToolbar.width
	RMovebar.left = RToolbar.left - RMovebar.width - 2
	if(IsTabwidthStable = 1) Then
		GetTabCount()
		TabCanUseWidth = cxClient  - TabBar.left - 85 - btnSidebar.width - btnSidebar.left - 26	
		TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth
		if(TabCanShowCount < TabCount) Then
			RMovebar.visible = true
			TabBar.width =  RMovebar.left - TabBar.left			
		Else
			FirstItemIndex = 0
			RMovebar.visible = false
			TabBar.width =  RToolbar.left - TabBar.left				
		End if			
	Else
		RMovebar.visible = false	
		TabBar.width =  RToolbar.left - TabBar.left	
	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 = 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
	Else
	    RToolbar.width = 85

		btnTextMode.visible = 1
		btnBack.left = 44
		btnBackSelect.left = 44
		btnClose.left = 63

	    RToolbar.left = TabRebar.width  - RToolbar.width


		RToolbar.width = 85
		RTBBk.width = RToolbar.width
		RMovebar.left = RToolbar.left - RMovebar.width - 2
		if(IsTabwidthStable = 1) Then
			GetTabCount()
			TabCanUseWidth = cxClient  - TabBar.left - 85 - btnSidebar.width - btnSidebar.left - 26	
			TabCanShowCount = TabCanUseWidth \ TabItemMaxWidth
			if(TabCanShowCount < TabCount) Then
				RMovebar.visible = true
				TabBar.width =  RMovebar.left - TabBar.left			
			Else
				FirstItemIndex = 0
				RMovebar.visible = false
				TabBar.width =  RToolbar.left - TabBar.left				
			End if			
		Else
			RMovebar.visible = false	
			TabBar.width =  RToolbar.left - TabBar.left	
		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 btnLastNavList_s_onClick()
	x = btnLastNavList_s.ClientLeft + 2
	y = btnLastNavList_s.ClientTop + btnLastNav_s.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 btnClearNavRecord_s_onClick()
	x = btnClearNavRecord_s.ClientLeft + 2
	y = btnClearNavRecord_s.ClientTop + btnClearNavRecord_s.Height - 1
	a = x * 65536 + y
	Window.ExeCommand 44008 , a
End Sub

sub btnWebList_onClick()
	x = btnWebList.ClientLeft + 2
	y = btnWebList.ClientTop + btnWebList.Height - 1
	a = x * 65536 + y	
	Window.ExeCommand 44010 , a
End Sub

sub btnPaiPaiList_onClick()
	x = btnPaiPaiList.ClientLeft + 2
	y = btnPaiPaiList.ClientTop + btnPaiPaiList.Height - 1
	a = x * 65536 + y	
	Window.ExeCommand 44011 , 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 btnNavList_s_onClick()
	x = btnNavList_s.ClientLeft + 2
	y = btnNavList_s.ClientTop + btnNavList_s.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 btnOriginal_onClick()
'	a = 0
'	btnOriginal.image = "../../common/ElementExtractBar/ButtonDownBK.bmp"
'	btnText.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnImage.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnMedia.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnFlash.image = "../../common/ElementExtractBar/BarBK.bmp"	
'	Window.ExeCommand 44014 , a
'End Sub

'sub btnText_onClick()
'	a = 1
'	btnOriginal.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnText.image = "../../common/ElementExtractBar/ButtonDownBK.bmp"
'	btnImage.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnMedia.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnFlash.image = "../../common/ElementExtractBar/BarBK.bmp"		
'	Window.ExeCommand 44014 , a
'End Sub

'sub btnImage_onClick()
'	a = 2
'	btnOriginal.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnText.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnImage.image = "../../common/ElementExtractBar/ButtonDownBK.bmp"
'	btnMedia.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnFlash.image = "../../common/ElementExtractBar/BarBK.bmp"		
'	Window.ExeCommand 44014 , a
'End Sub

'sub btnMedia_onClick()
'	a = 3
'	btnOriginal.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnText.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnImage.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnMedia.image = "../../common/ElementExtractBar/ButtonDownBK.bmp"
'	btnFlash.image = "../../common/ElementExtractBar/BarBK.bmp"		
'	Window.ExeCommand 44014 , a
'End Sub

'sub btnFlash_onClick()
'	a = 4
'	btnOriginal.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnText.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnImage.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnMedia.image = "../../common/ElementExtractBar/BarBK.bmp"
'	btnFlash.image = "../../common/ElementExtractBar/ButtonDownBK.bmp"		
'	Window.ExeCommand 44014 , a
'End Sub

'sub btnSelectAll_onClick()
'	a = 5
'	if(ElementExtractSelectAll = 0)then
'		ElementExtractSelectAll = 1
'		btnSelectAll.ico = "../../common/ElementExtractBar/SelectOn.ico"
'	else
'		ElementExtractSelectAll = 0
'		btnSelectAll.ico = "../../common/ElementExtractBar/SelectOff.ico"	
'	end if
'	Window.ExeCommand 44014 , a
'End Sub

'sub btnSave_onClick()
'	a = 6
'	Window.ExeCommand 44014 , a
'End Sub

'sub OnExtractElement(var)
'	If(var = 0)then
'		btnOriginal_onClick()
'	elseif(var = 1)then
'		btnText_onClick()
'	elseif(var = 2)then	
'		btnImage_onClick()
'	elseif(var = 3)then
'		btnMedia_onClick()
'	elseif(var = 4)then
'		btnFlash_onClick()
'	end if
'end sub

sub reportPluginbarStatus()
	window.ExeCommand 500, ShowPluginBar
end sub

Sub AdjustLinkBar()

	LinkBarCaption.color = FavLinkLabelColor
	Dim SpaceUsedToShow '能显示item的位置
	if(btnMoreLinkItems.visible) Then
		'有这么一种情况:morebtn可见,但是又不在LinkBar的最右边,这种情况要考虑 --rodman
		If( (btnMoreLinkItems.left+btnMoreLinkItems.width) < LinkBar.width) Then
			SpaceUsedToShow = LinkBar.width - btnMoreLinkItems.width -LinkItemCont.left 
		else
			SpaceUsedToShow = btnMoreLinkItems.left-LinkItemCont.Left
		End if
	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
		'有这么一种情况:morebtn可见,但是又不在FavBar的最右边,这种情况要考虑 --rodman
		If( (btnMoreFavItems.left+btnMoreFavItems.width) < FavBar.width) Then
			SpaceUsedToShow = FavBar.width - btnMoreFavItems.width -FavItemCont.left 
		else
			SpaceUsedToShow = btnMoreFavItems.left-FavItemCont.Left
		End if
	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 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 AdjustSearchBar()
    if(bShowSearchBar = 1) then
	    SearchBar.Visible = true
	    SearchBarDlg.Visible = true
	    SearchBorderIMG.width = SearchBar.width - HighLightButton.width - SearchButton.width  - SearchBorderLeft.Left - SearchBorderLeft.width - 2
	    SearchBorderRight.left = SearchBorderIMG.left + SearchBorderIMG.width  
	    SearchBarDlg.width = SearchBar.width - SearchButton.width - HighLightButton.width - SearchBorderLeft.Left - SearchBorderLeft.width -2
	    SearchButton.left = SearchBar.width - SearchButton.width - HighLightButton.width
	    HighLightButton.left = SearchBar.width - HighLightButton.width
	    AddrBorderIMG.width = AddressBar.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - GoButton.width - 2
	    AddrBorderRight.left = AddrBorderIMG.left + AddrBorderIMG.width
	    AddrssCombo.width = AddressBar.width - GoButton.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - AddrBorderRight.width - 2
	    GoButton.left = AddressBar.width - GoButton.width - 1
		If(IsHighLightDown) Then
		    HighLightButton.image = "Highlight_Down.png"
		    HighLightButton.hoverImage = "Highlight_Down.png"	
		    HighLightButton.downImage = "Highlight_Down.png"			
	    Else
		    HighLightButton.image = "Highlight_Normal.png"
		    HighLightButton.hoverImage = "Highlight_Hover.png"	
		    HighLightButton.downImage = "Highlight_Down.png"		
	    End If	
    else
	    SearchBar.Visible = false
	    SearchBarDlg.Visible = false
	    AddrBorderIMG.width = AddressBar.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - GoButton.width - 2
	    AddrBorderRight.left = AddrBorderIMG.left + AddrBorderIMG.width
	    AddrssCombo.width = AddressBar.width - GoButton.width  - (AddrBorderLeft.left+AddrBorderLeft.Width) - AddrBorderRight.width - 2
	    GoButton.left = AddressBar.width - GoButton.width - 1		
    end if		

End Sub

Sub ShowPlugin(var, bshow)

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

end sub

Sub RelayoutPluginBtn()

	btnLeft = 10
	if (IsToolBarLargeOrSmall = 0) Then
		for i = 2000 to 2100
			if Window.ObjIsGot("PluginButton_" & CStr(i)) = false then 
				Exit for
			end if
			
			BtnName = "PluginButton_" & CStr(i)
			Window.ChildById("BtnPluginCont").ChildById(BtnName).AutoSpace()
			Window.ChildById("BtnPluginCont").ChildById(BtnName).left = btnLeft
			btnLeft = btnLeft + Window.ChildById("BtnPluginCont").ChildById(BtnName).width
	
			if Window.ObjIsGot("PluginButtonList_" & CStr(i)) then 
				BtnName = "PluginButtonList_" & CStr(i)
				Window.ChildById("BtnPluginCont").ChildById(BtnName).left = btnLeft
				btnLeft = btnLeft + Window.ChildById("BtnPluginCont").ChildById(BtnName).width
			end If
		Next
	Elseif (IsToolBarLargeOrSmall = 1) Then
		for i = 2000 to 2100
			if Window.ObjIsGot("PluginButton_s_" & CStr(i)) = false then 
				Exit for
			end if
			
			BtnName = "PluginButton_s_" & CStr(i)
			Window.ChildById("BtnPluginCont_s").ChildById(BtnName).AutoSpace()
			Window.ChildById("BtnPluginCont_s").ChildById(BtnName).left = btnLeft
			btnLeft = btnLeft + Window.ChildById("BtnPluginCont_s").ChildById(BtnName).width
	
			if Window.ObjIsGot("PluginButtonList_s_" & CStr(i)) then 
				BtnName = "PluginButtonList_s_" & CStr(i)
				Window.ChildById("BtnPluginCont_s").ChildById(BtnName).left = btnLeft
				btnLeft = btnLeft + Window.ChildById("BtnPluginCont_s").ChildById(BtnName).width
			end If
		Next
	end if
	PluginBarWidth = btnLeft
end Sub

Sub ProcessBtnPluginClick(childId)

	Dim bButton
	Dim bButtonList
	Dim Obj

	bButton = false
	bButtonList = false

	if (IsToolBarLargeOrSmall = 0) Then
		if InStr(1, CStr(childId), CStr("PluginButtonList_"), 1) = 1 then
			bButtonList = true
		end if
		if InStr(1, CStr(childId), CStr("PluginButton_"), 1) = 1 then 
			bButton = true
		end If
	Elseif (IsToolBarLargeOrSmall = 1) Then
		if InStr(1, CStr(childId), CStr("PluginButtonList_s_"), 1) = 1 then
			bButtonList = true
		end if
		if InStr(1, CStr(childId), CStr("PluginButton_s_"), 1) = 1 then 
			bButton = true
		end If
	End if
	

	if bButtonList <> true and bButton <> true then
		exit Sub
	end if

	if (IsToolBarLargeOrSmall = 0) Then
		Set Obj = Window.ChildById("BtnPluginCont").ChildById(childId)
	Elseif (IsToolBarLargeOrSmall = 1) Then
		Set Obj = Window.ChildById("BtnPluginCont_s").ChildById(childId)
	End if

	id = Right(childId, 4)

	Set data = Window.CreateTTData
	data.SetDWord "dwPluginBtnID", (CInt(id))
	data.SetDWord "dwPluginBtnLeft", (Obj.Clientleft)
	data.SetDWord "dwPluginBtnTop", (Obj.Clienttop)
	data.SetDWord "dwPluginBtnWidth", (Obj.width)
	data.SetDWord "dwPluginBtnHight", (Obj.height)
	data.SetBool "bPluginBtnType", (bButton)

	Window.ExeCommand 155 , data

end Sub

Sub UpdateBtnPluginIcon(var)
	
	path = Right(var, Len(var) - 4)

	if (IsToolBarLargeOrSmall = 0) Then
		id = "PluginButton_" & Left(var, 4)
		Window.ChildById("BtnPluginCont").ChildById(id).Ico = path
	Elseif (IsToolBarLargeOrSmall = 1) Then
		id = "PluginButton_s_" & Left(var, 4)
		Window.ChildById("BtnPluginCont_s").ChildById(id).Ico = path
	End if

end Sub

Sub UpdateBtnPluginText(var)
	
	Text = Right(var, Len(var) - 4)

	if (IsToolBarLargeOrSmall = 0) Then
		id = "PluginButton_" & Left(var, 4)
		Window.ChildById("BtnPluginCont").ChildById(id).Label = Text
	Elseif (IsToolBarLargeOrSmall = 1) Then
		id = "PluginButton_s_" & Left(var, 4)
		Window.ChildById("BtnPluginCont_s").ChildById(id).Label = Text
	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)
	
	if obj.Visible = true then
		var.SetDWord "dwRectLeft", obj.left
		var.SetDWord "dwRectTop", obj.top
		var.SetDWord "dwRectWidth", obj.width
		var.SetDWord "dwRectHight", obj.height
	end if

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