var BalloonTip;
var TrayIcon;
var EWA;
var vipPopupTimerID = 0;

//记录进入mini模式前的最小长宽
var minWidth=0;
var minHeight=0;
function ManualUpdate()
{
	var ppFrame=Components.GetObject2("PPFrame");
	if(ppFrame)
	{
		ppFrame.ManualUpdate();
	}
}
function OnActive(bActivated)
{
	if(!bActivated) return;
	var GallopStateInfo = Components.GetObject2("gallopStateInfo");
	if(GallopStateInfo)GallopStateInfo.ScrollNext();

	var Gallop = Components.GetObject2("gallopFrame");
	if(Gallop)Gallop.ScrollNext();
}
function windowOnShow()
{
	MY_DEBUG("windowOnShow");
	var ob = Components.GetObject2("AD");
	if(ob)ob.FrameShow(true);
	var ob2 = Components.GetObject2("@pplive.com/PopMsgManager;1");
	if(ob2)ob2.FrameShow(true);
	var ppFrame = Components.GetObject2("PPFrame");
	if(ppFrame)ppFrame.bActivedOnce=true;
	if(ppFrame)
	{
		ppFrame.ForceBreakBossState(true);
	}
	//window.ShowNumTip(0,0);
	if(window.firstShow)
	{
		window.firstShow=false;
		Show_Classic2NewTip();
	}

	//ShowFireWallForbiddenBalloon
	if (window.bShowFireWallForbiddenBalloon == true)
	{
		window.bForceShowFireWallForbiddenBalloon = true;
		window.ShowFirewallForbiddenBalloon(window.nFireWallForbiddenBalloonType);
	}
}
function PPSetFrameTitle()
{
		var PPFrame = Components.GetObject2("PPFrame");
		if(PPFrame)PPFrame.PPSetFrameTitle();
}

function 	showVipPopup()
{
	var vipweb = Components.GetObject2("POP_VIP");
	
	if(!vipweb)
	{
		vipweb=Components.CreateObject("@pplive.com/PPIconTray;1");
		vipweb.CreatePopWindow(5);
		Components.RegisterObject("POP_VIP", vipweb);
		vipweb.ForceTop = true;
	}
	
	if(vipweb)
	{
		var activeSkinId = getActiveSkinId();
		var skin = "other";
		if (activeSkinId == "0" || activeSkinId == "3")
		{
			skin = "blue";
		}
		if (activeSkinId == "1" || activeSkinId == "2" || activeSkinId == "4")
		{
			skin = "black";
		}
		var vipUrl = "http://live.v2.pplive.com/interface/client2/vipop_" + skin + ".html";
		vipweb.url = vipUrl;
	}
}

function windowOnChangeMode()
{
	//进入2X模式，放开内核限速
	limitCoreConnection(false);

/*
	var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
	if(chMgrFactory)
	{
		var fav = chMgrFactory.favLive;
		var recent = chMgrFactory.recent;
		if(fav) fav.LoadFavorites(2);
		if(recent) recent.LoadFavorites(1);
	}
*/	
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		var nstate = EWA.PlayState;
		if(nstate==IPlayerState.pppStop || nstate==IPlayerState.pppMediaEnd)
		{
			$("key_Stop").disabled =true;
			$("menu_Stop").disabled=true;
			$("menu_downfile").disabled=false;
			$("menu_addinfolder").disabled=false;
			$("menu_picMenu").disabled=true;
		}
		else if(nstate==IPlayerState.pppBuffering || nstate==IPlayerState.pppReady || nstate==IPlayerState.pppPlay || nstate==IPlayerState.pppPause)
		{
			$("key_Stop").disabled =false;
			$("menu_Stop").disabled=false;
			$("menu_downfile").disabled=false;
			$("menu_addinfolder").disabled=false; 
			$("menu_picMenu").disabled=false;
		}
	}
	
	PPSetFrameTitle();

	//通知ppframe模式切换
	var ppframe = Components.GetObject2("PPFrame");
	if (ppframe)
	{
		ppframe.runMode = 0;
	}

	//通知mframe模式切换
	var mframe = Components.GetObject2("mframe");
	if (mframe)
	{
		mframe.RunMode = 0;
	}
	//标题
	var globalWindow = Components.GetObject2("globalWindow");
	if(globalWindow)	
	{
		window.setTaskBarTitle(globalWindow.taskbarTitle);
		window.setWindowTitle(globalWindow.windowTitle);
	}

	//通知所有挂接该事件的JS脚本
	for (var keyname in window.vecOnModeChange)
	{
		try
		{
			uiMainWindow.vecOnModeChange[keyname](0);	
		}
		catch(e)
		{
		}
	}
	//通知chctrl对当前正在播放的频道进行加亮
	if (window.hasChannelPlaying())
	{
		var chctrl = Components.GetObject2("webchannel");
		if (chctrl)
		{
			var ppp = Components.GetObject2("PPP");
			if (ppp)
			{
				chctrl.playingChannel(ppp.CatalogID, ppp.ChannelID, ppp.HjID, ppp.RootCatalogId, ppp.PlayFromeWhere);
			}
		}
	}	
	var adModule = Components.GetObject2('AD');
	if(adModule)
	{
		try
		{
				//window.alert("changemode");
		    adModule.UIChangeMode(mframe.RunMode);
		}
		catch(e)
		{
		}
	}
	windowOnShow();
}

function Show_Classic2NewTip()
{
	if(window.tidyMode) return;
		var Classic2NewTipNum = 0;
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
		{	
			Classic2NewTipNum = registry.readDWORD("Classic2NewTip");
			if(Classic2NewTipNum<3)registry.writeDWORD("Classic2NewTip",Classic2NewTipNum+1);	
		}
		if(Classic2NewTipNum<3)
		{
			window.balloons.Create("education\\Classic2NewTip.xml",window.hwnd,185,0,-125,17);
			window.balloons.Show("education\\Classic2NewTip.xml",true);
		}
}
function windowOnSizemode()
{
	var maxRestoreBtn = document.getElementById('maxRestoreBtn');
	if (window.sizemode == IDOMWindow.SizeMode_Maximized)
	{
		var PPLState = Components.GetObject2("@pplive.com/PPLStat;1");
		if(PPLState)PPLState.PPTVStartTime(21);
		$("resizeGripper").visible = false;
		maxRestoreBtn.checked = true;
	}
	else
	{
		$("resizeGripper").visible = true;
		maxRestoreBtn.checked=false;
	}
	
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if(hoverInfo)
	{
		var isMinisize = (window.sizemode == IDOMWindow.SizeMode_Minimized);
		if(isMinisize)hoverInfo.hoverHide();
		else
		{
			hoverInfo.hoverShow();
			hoverInfo.SetHoverDefaultPos();
		}
	}

	//ShowFireWallForbiddenBalloon
	var balloon = window.balloons.Get("education\\firewallforbidden.xml");
	if (balloon) 
	{
		balloon.close();
		window.bShowFireWallForbiddenBalloon = true;
		window.bForceShowFireWallForbiddenBalloon = true;
		return;
	}
	if (window.bShowFireWallForbiddenBalloon == true)
	{
		window.ShowFirewallForbiddenBalloon(window.nFireWallForbiddenBalloonType);
	}
}

// 迷你模式是设置元素的位置
function windowOnSize()
{
	var tidyMode = window.tidyMode;

	if (tidyMode)
	{
		var mainWindow = document.getElementById('mainWindow');
		var tidyModeRegion = document.getElementById('tidyModeRegion');
		tidyModeRegion.sizeTo(mainWindow.width, mainWindow.height);

		var mainSubWindow = document.getElementById('mainSubWindow');
		mainSubWindow.moveSizeTo(3, 3, window.innerWidth-6, window.innerHeight-6);
	}

	return !tidyMode;
}

function mainSubWindowOnSize()
{
	var tidyMode = window.tidyMode;
	
	if (tidyMode)
	{
		$("mainSplitter").moveSizeTo(0, 0, this.width, this.height + 6);
		return false;
	}

	if (!$("mainSplitter").panePlace) // 频道列表 在左边
	{
		$("mainSplitter").moveSizeTo($("tabsContainer").width, 0, this.width - $("tabsContainer").width, this.height);
		if (window.tabs && window.tabs.panelVisible())
		{
			$("tabsContainer").moveSizeTo(0, $("passportContainer").height, $("tabsContainer").width, this.height - $("passportContainer").height);
		}
		else
		{
			$("tabsContainer").moveSizeTo(0, 0, $("tabsContainer").width, this.height);
		}
		return false;
	}
	else
	{
		$("mainSplitter").moveSizeTo(0, 0, this.width - $("tabsContainer").width, this.height);
		if (window.tabs && window.tabs.panelVisible())
		{
			$("tabsContainer").moveSizeTo(this.width - $("tabsContainer").width, $("passportContainer").height, 
				$("tabsContainer").width, this.height - $("passportContainer").height);
		}
		else
		{
			$("tabsContainer").moveSizeTo(this.width - $("tabsContainer").width, 0, $("tabsContainer").width, this.height);
		}
		return false;
	}
	return true;
}

var WindowLeft = 0;   //记录原始窗口Left
var WindowTop = 0;    //记录原始窗口Top
var WindowWidth = 0;  //记录原始窗口Width
var WindowHeight = 0; //记录原始窗口Height
var miniLeft = 0;     //记录进入TidyMode时Left
var miniTop =0;       //记录进入TidyMode时Top
var miniWidth = 0;    //记录进入TidyMode时Width
var miniHeight =0;    //记录进入TidyMode时Height

// 进入迷你模式
function enterTidyMode()
{
	if (window.tidyMode)
	{
		return false;
	}
	if(window.balloons)
	{
		window.balloons.Show("education\\Classic2NewTip.xml",false);
		window.ShowRegVip(false);
	}

	//记录进入mini模式之前的topmost
	window.IsTopMostEx = (window.GetTopMostEx()==0)?false:true;
	if(!window.IsTopMostEx)
	{
		window.SetTopMostEx(2);
		window.IsTopMostEx=false;
	}
	//打开窗口边框吸附
	window.setAdsorb=true;

	EwaUnFullScreen();
	if (window.sizemode != 0)
	{
		window.sizemode = 0;
	}
	var mframe = Components.GetObject2("mframe");
	if(mframe) mframe.PortalControl("notify","portal","mini","1","","");
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if(hoverInfo)hoverInfo.hoverHide();

	//禁止左右互换,在switchChannelDir()中处理？
	/*
	$("menu_switchDir2").disabled=true;
	$("menu_switchDir").disabled=true;
	$("key_switchDir").disabled=true;	
	*/

	//大窗口大小
	WindowLeft=window.screenLeft;
	WindowTop=window.screenTop;
	WindowWidth=window.innerWidth;
	WindowHeight=window.innerHeight;

    //设置精简窗口大小
	miniLeft=WindowLeft;
	miniTop=WindowTop+27;
	miniWidth=$("Player").width+6;
	miniHeight=$("Player").height+6-41;
	
	//如果视频正在播放，与视频1x大小比较
	var ppp = Components.GetObject2("PPP");
	if (ppp && (ppp.State == 2 || ppp.State == 0 || ppp.State == 3))
	{
		if (ppp.Oplayer)
		{
			//没取到视频大小，默认
			if (ppp.Oplayer.videoWidth==0 || ppp.Oplayer.videoHeight==0)
			{
				miniWidth=500;
				miniHeight=330;
			}
			else if (GetDisplayRate(ppp.Oplayer.videoWidth,ppp.Oplayer.videoHeight,miniWidth-6,miniHeight-6)>=100)
			{
				miniWidth=ppp.Oplayer.videoWidth+6;
				miniHeight=ppp.Oplayer.videoHeight+6;
			}
			else
			{
				miniWidth=$("Player").width+6;
				miniHeight=$("Player").height+6-41;
			}
		}
	}
	else
	{
		miniWidth=500;
		miniHeight=330;
	}

	//读取注册表中值
	var bPosChange = 0;
	var bSizeChange = 0;

	var registry = Components.CreateObject("@pplive.com/registry;1");
	if (registry && registry.open(registry.HKCU, "Software\\PPLive\\PPTV\\TidyMode",IRegistry.KEY_READ))
	{
		bPosChange = registry.read("bPosChange");
		bSizeChange = registry.read("bSizeChange");
	
		//有位置变化，且大小变化 读取 miniLeft miniTop miniWidth miniHeight
		if (bPosChange && bSizeChange)
		{
			miniLeft = registry.read("miniLeft");
			miniTop = registry.read("miniTop");
			miniWidth = registry.read("miniWidth");
			miniHeight = registry.read("miniHeight");

		}
		//仅有位置变化，读取miniLeft miniTop
		else if (bPosChange)
		{
			miniLeft = registry.read("miniLeft");
			miniTop = registry.read("miniTop");
		}
		//仅有大小变化，读取miniWidth miniHeight
		else if (bSizeChange)
		{
			miniWidth = registry.read("miniWidth");
			miniHeight = registry.read("miniHeight");
		}

		var availPos = ConstrainPosition(window.screen, miniLeft, miniTop, miniWidth, miniHeight);
		miniLeft = availPos.left;
		miniTop = availPos.top;
	}


	window.lock(7);
	window.tidyMode = true;

// 设置视频显示大小
	window.beforeTidydefaultSize = window.videoScan.defaultSize; 
	window.videoScan.zoom(5);
	var fullModeRegion = $("fullModeRegion");
	var tidyModeRegion = $("tidyModeRegion");
	var titleBar = $("titleBar");

	titleBar.visible = false;
	fullModeRegion.visible = false;
	tidyModeRegion.visible = true;

// 
	$("passportContainer").visible = false;  //  隐藏 "passport"
	$("tabsContainer").visible = false;  //  隐藏 "互动栏"
	var mainSplitter = $("mainSplitter");
	if(window.tabs)window.tabs.showPanel(false);
//	$("channelWnd").visible = false;
	
	window.tidyModeSplitterSinglePaneMode = mainSplitter.singlePaneMode;

	mainSplitter.singlePaneMode = 0;
	$("statusPanel").visible = false; // 隐藏走马灯

	//记录进入mini模式前的最小大小
	minWidth = window.minWidth;
	minHeight = window.minHeight;

	window.setMinWidthAndHeight(const_minWidth_Player_mini,const_minHeight_Player_mini,false);
	window.moveSizeTo(miniLeft,miniTop,miniWidth, miniHeight,0); //设置窗口大小
	window.unlock(7);
	try
	{
		$("Player").wrappedObject.ResizerCommand(4 , 1);
	}
	catch (e)
	{
	}
	
	if(mframe) mframe.TipControl.ShowTipText("迷你模式",0xcccccc,3);

	return true;
}

// 记录迷你模式位置
function recodeTidyModePosition()
{
	//当前窗口大小
	var curMiniLeft = window.screenLeft;
	var curMiniTop = window.screenTop;
	var curMiniWidth = $("Player").width+6;
	var curMiniHeight = $("Player").height+6;

    //读取注册表
	var registry = Components.CreateObject("@pplive.com/registry;1");
	if (registry && registry.create(registry.HKCU,"Software\\PPLive\\PPTV\\TidyMode"))
	{
		//读取当前切回次数
		var nUses = registry.readDWORD("nUses");  //0:第一次切回 1：第二次切回 2：第三次切回
		if (nUses <2)
		{
			registry.writeDWORD("nUses",nUses + 1);
		}

		if((curMiniLeft != miniLeft) || (curMiniTop != miniTop) ||(nUses == 1) )
		{
			//记录位置变化
			registry.writeDWORD("bPosChange",1);
			//记录位置 curMiniLeft curMiniTop
			registry.writeDWORD("miniLeft",curMiniLeft);
			registry.writeDWORD("miniTop",curMiniTop);
		}
		else
		{
			//删除记录位置变化
			if (nUses == 0)
			{
				registry.writeDWORD("bPosChange",0);
			}
		}
		
		if((curMiniWidth != miniWidth) || (curMiniHeight != miniHeight) ||(nUses == 1) )
		{
			//记录大小变化
			registry.writeDWORD("bSizeChange",1);
			//记录大小
			registry.writeDWORD("miniWidth",curMiniWidth);
			registry.writeDWORD("miniHeight",curMiniHeight);
		}
		else
		{
			//删除记录大小变化
			if (nUses == 0)
			{
				registry.writeDWORD("bSizeChange",0);
			}
		}
	}
}

// 退出迷你模式
function exitTidyMode()
{
	if (!window.tidyMode)
	{
		return false;
	}
	if(!window.IsTopMostEx)
	{
		window.SetTopMostEx(0);
	}
	//关闭窗口边框吸附
	window.setAdsorb=false;

	EwaUnFullScreen();
	var mframe = Components.GetObject2("mframe");
	if(mframe) mframe.PortalControl("notify","portal","mini","0","","");
	//打开左右互换,在switchChannelDir()中处理？
	/*
	$("menu_switchDir2").disabled=false;
	$("menu_switchDir").disabled=false;
	$("key_switchDir").disabled=false;	
	*/
	
	window.lock(7);
	window.tidyMode = false;

	//记录迷你模式位置
	recodeTidyModePosition();

	var fullModeRegion = $("fullModeRegion");
	var tidyModeRegion = $("tidyModeRegion");
	var titleBar = $("titleBar");

	titleBar.visible = true;
	fullModeRegion.visible = true;
	tidyModeRegion.visible = false;

	$("mainSubWindow").moveTo(2, 27);

	var mainSplitter = $("mainSplitter");
	
	mainSplitter.singlePaneMode = window.tidyModeSplitterSinglePaneMode;
	if (mainSplitter.singlePaneMode == -1)
	{
		if(window.tabs)window.tabs.showPanel(true);
//		$("channelWnd").visible = true;                 // 显示频道列表
		$("passportContainer").visible = true;          // 显示 "passport"
	}

	$("tabsContainer").visible = true;  //  显示 "互动栏"
	$("statusPanel").visible = true;


	try
	{
		$("Player").wrappedObject.ResizerCommand(4 , 0);
	}
	catch (e)
	{
	}

// 还原视频大小
	window.videoScan.zoom(window.beforeTidydefaultSize);
	//还原窗口
	window.moveSizeTo(WindowLeft,WindowTop,WindowWidth, WindowHeight,0);

	window.unlock(7);

	//退出mini模式，设置回原来的最小大小
	window.setMinWidthAndHeight(minWidth, minHeight, true);

	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if(hoverInfo)hoverInfo.hoverShow();

	//退出mini模式的时候看看需不需要刷新节目列表
	//window.tryDelayRefresh();

	if(mframe) mframe.TipControl.ShowTipText("完整模式",0xcccccc,3);

	return true;
}

function windowOpenUrl()
{
	var url = window.showModalDialog("openurl.xml");
	if (url && url.length > 0)
	{
		pppPlayString(url,9);
	}
}

// 从注册表中加载(经典|扩展)模式
function windowInit()
{
	var leftright = 0; // 1 频道列表在左边
	try
	{
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if (registry.open(registry.HKCU, "Software\\PPLive\\Config\\Layout",IRegistry.KEY_READ))
		{
			leftright = registry.readDWORD("leftright");
		}
	}
	catch (e)
	{
		leftright = 0;
	}

	if (leftright != 0)
	{
		$("mainSplitter").panePlace = false;
	}
	//设置列表的最小宽度
	$("mainSplitter").setPaneMinSize(1,const_minWidth_list,0);
	//设置最小宽度的时候，保证整个窗体的最小宽度比各个子窗口的最小宽度和要大
	var minWidth=2+$("mainSplitter").getPaneMinSize(0)+4+$("mainSplitter").getPaneMinSize(1)+2 + 39/*互动扩展栏*/;
	window.setMinWidthAndHeight(minWidth, window.minHeight, false);

}

function cmdlineHandler(aCmdLine)
{
	if (aCmdLine.state == 0)
	{
		if (aCmdLine.findFlag("autorun") != -1)
		{
			return;
		}
		window.visible = true;
		try
		{Components.GetObject2("Loading").Destroy();}
		catch (e){}
	}
	else if (aCmdLine.state == 1)
	{
		window.activated = true;
		window.visible = true;
	}

	var url = aCmdLine.handleFlagWithParam("play");
	if (url.length > 0)
	{
		pppPlayString(url,11);
	}

	if (aCmdLine.length > 1)
	{
		url = aCmdLine.getArgument(1);
		if (url.length > 0 && url!="/forceil")
		{
			pppPlayString(url,11);
		}
	}
}

function checkUnFullscreen()
{
	if (EwaIsFullScreen())
	{
		EwaUnFullScreen();
	}
}

function centerWindow()
{// 窗口居中，并且根据显示器分辨率调整窗口的大小
	if (window.sizemode != 0)
	{
		window.sizemode = 0;
	}

	var screen = window.screen;
	var wndWidth = 780;
	var wndHeight = 540;
	if (screen.width == 1024 && screen.height == 768)
	{
		wndWidth = 780;
		wndHeight = 540;
	}
	else if (screen.width >= 1280 && screen.width < 1440 )
	{
		wndWidth = 898;
		wndHeight = 540;
	}
	else if (screen.width >= 1440)
	{
		wndWidth = 1088;
		wndHeight = 640;
	}

	if (window.tidyMode)
	{
		wndWidth = 500;
		wndHeight = 330;
	}
	else
	{
		if (!$("channelContainer").visible)
		{
			wndWidth = wndWidth - $("channelContainer").width;
		}
	}
	

	/* 主窗口+EPG窗口 居中 */
	var left = screen.left + (screen.width - wndWidth - 230)/2;
	var top = screen.top + (screen.height - wndHeight)/2;

	if (!$("mainSplitter").panePlace)
	{
		left += 230;
	}

	window.moveSizeTo(left, top, wndWidth, wndHeight);
}

function windowOnload()
{	
	AddSupport_Debug();
	var popMsgManager = Components.CreateObject("@pplive.com/PopMsgManager;1");
	window.firstShow=true;
	window.FFUnMuteId = 0;
	//更新置顶按钮状态
	window.$ = function(id)
	{
		return document.getElementById(id);
	};
	window.vecOnPlayInfo = {};
	window.OnPlayInfo=function()
	{
		for (var keyname in window.vecOnPlayInfo)
		{
			try
			{
				window.vecOnPlayInfo[keyname]();	
			}
			catch(e)
			{
			}
		}
	}
	window.MiniClose = function()
	{
		myClose();
	}

	window.DefaultSize = function()
	{
		checkUnFullscreen();
		centerWindow();
	}
	//是否有频道在播放
	window.hasChannelPlaying = function()
	{
		var ppp = Components.GetObject2("PPP");
		if (ppp)
		{
			var state = ppp.State;
			//处于初始化、媒体结束、节目停止三个状态时，则认为没有频道播放。
			if (state==-1 || state==4 || state==5)
				return false;

			return true;
		}
		return false;
	}
	window.RestartPPAP = function()
	{
		var ppp = Components.GetObject2("PPP");
		if (ppp)
		{
			ppp.ResetPPAP();
		}
		var admodule = Components.GetObject2("AD");
		if (admodule)
		{
			admodule.PPAPReload(0);
		}
	}
	//nclist会在地区码更改的时候通知外部
	window.vecOnCityCodeChange = {};
	window.OnCityCodeChange = function(cityCode)
	{
		var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
		if(hoverInfo)hoverInfo.OnCityCodeChange(cityCode);
		var ppframe = Components.GetObject2("PPFrame");
		if(ppframe)ppframe.cityCode=cityCode;
		for (var keyname in window.vecOnCityCodeChange)
		{
			try
			{
				window.vecOnCityCodeChange[keyname](cityCode);	
			}
			catch(e)
			{
			}
		}
	}
	
	//用户是否动过节目列表
	//每次刷新由PPFrame把window.ChannelListActivated设为false
	window.ChannelListActivated=true;
	window.activateChannelList = function()
	{
		window.ChannelListActivated=true;
	}
	window.SetTrack = function(nTrack)
	{	
		PPPSetTrack(nTrack);
	}
	window.ShowResizeTip = function(nSize)
	{
		var cxRate = window.videoScan.aspectRatioWidth;
		var cyRate = window.videoScan.aspectRatioHeight;

		// Half 0x0001 Normal 0x0002 Double 0x0003 Stretch 0x0004 Fit 0x0005
		var defaultSize = window.videoScan.defaultSize; 
		var MainFrame = Components.GetObject2("mframe");
		var currentSize = "";

		var bShowSize = true;
		if(nSize==0.0)
		{
			bShowSize=false;
		}
		else if(nSize==1.0)
		{
			currentSize="原始尺寸";
		}		
		else
		{
			currentSize=nSize + "倍尺寸";
		}

		var currentRate = "";
		if(defaultSize == 4)
		{
			currentRate  = "铺满窗口";
		}
		else if(cxRate == 0 && cyRate ==0)
		{
			currentRate  = "视频原始比例";
		}
		else if(cxRate == 4 && cyRate ==3)
		{
			currentRate  = "画面4:3";
		}
		else if(cxRate == 16 && cyRate ==9)
		{
			currentRate  = "画面16:9";
		}
		var showtext = "";
		if(bShowSize)
		{
			showtext = currentSize + "\r\n" + currentRate;
		}
		else
		{
			showtext = currentRate;
		}
		if(MainFrame)MainFrame.TipControl.ShowTipText(showtext,0xcccccc,3);
	}
	window.OnResizeCommand = function (idCmd,nState)
	{
		var isFullScreen = EwaIsFullScreen();
		var MainFrame = Components.GetObject2("mframe");
		if(idCmd==IResizeCommand.idResize050)
		{
			if (isFullScreen)
			{
				window.videoScan.zoom(1);
			}
			else
			{
				SetOriginalSizePlayPolicy(3, false); // 
			}
			window.ShowResizeTip(0.5);
		}
		else if(idCmd==IResizeCommand.idResize100)
		{
			if (isFullScreen)
			{
				window.videoScan.zoom(2);
			}
			else
			{
				SetOriginalSizePlayPolicy(3, false); // 
			}
			window.ShowResizeTip(1.0);
		}
		else if(idCmd==IResizeCommand.idResize150)
		{
			if (isFullScreen)
			{
				window.videoScan.zoom(7);
			}
			else
			{
				SetOriginalSizePlayPolicy(3, false); // 
			}
			window.ShowResizeTip(1.5);
		}
		else if(idCmd==IResizeCommand.idResize200)
		{
			if (isFullScreen)
			{
				window.videoScan.zoom(3);
			}
			else
			{
				SetOriginalSizePlayPolicy(3, false); // 
			}
			window.ShowResizeTip(2.0);
		}
	}
	window.vecOnPlayStateChange  = {};
	//模式切换通知到网页
	window.vecOnModeChange = {};
	//节目单延时下载
	//不显示节目列表的时候不刷新，只是记录下来
	//等下次显示节目列表的时候再刷新

	//刷新观看历史
	window.refreshLastWatch=function()
	{
		return;
	}
	//刷新最近观看
	window.refreshRecent=function()
	{
		return;
	}
	window.OnFolderChange=function(folderType)
	{
		try
		{
			if(folderType=="1")
			{
				window.refreshRecent();
			}
		}
		catch(e)
		{

		}
		return;
	}
	window.DelayRefresh = false;
	window.needDelayRefresh=function()
	{
		return false;
		/*
		if(window.DelayRefresh)return true;
		if(!window.channelIsVisible() || window.tidyMode || EwaIsFullScreen() || !window.visible)
		{
			window.DelayRefresh=true;
			return true;
		}
		return false;
		*/
	}
	window.tryDelayRefresh=function()
	{
		return;
		/*
		if(!window.DelayRefresh)return;
		if(window.channelIsVisible && !window.tidyMode && !EwaIsFullScreen())
		{
			window.DelayRefresh=false;
			var ppFrame=Components.GetObject2("PPFrame");
			if(ppFrame)ppFrame.P2PRefreshChannelList(0);
		}	
		*/
	}
	window.vipchanneltip = false;
	window.viplogin = false;
	window.CodecProblem = false;

	window.EwaOnFullScreen = function(newVal)
	{

		if(newVal)
		{
			window.ShowRegVip(false);
			//客户端启动时间统计
			var PplStat=Components.GetObject2("@pplive.com/PPLStat;1");
			if(PplStat)PplStat.PPTVStartTime(23);
		}
		else
		{
			var EWA = Components.GetObject2("EWA");
			if(EWA)
			{
				var nstate = EWA.PlayState;
				var topmost = window.GetTopMostEx();
				if(topmost==2)
				{
					if(nstate==IPlayerState.pppBuffering || nstate==IPlayerState.pppPlay || nstate==IPlayerState.pppReady)
					{
						window.topmost=true;
					}
					else
					{
						window.topmost=false;
					}
				}
			}
		}
		if(window.videoScan)window.videoScan.resetOnFullScreen(newVal);
		var mframe = Components.GetObject2("mframe");
		if(mframe) 
		{
			var currentRate = "";
			if(window.videoScan)
			{
				var cxRate = window.videoScan.aspectRatioWidth;
				var cyRate = window.videoScan.aspectRatioHeight;
				var defaultSize = window.videoScan.defaultSize; 
				if(defaultSize == 4)
				{
					currentRate  = "铺满窗口";
				}
				else if(cxRate == 0 && cyRate ==0)
				{
					currentRate  = "视频原始比例";
				}
				else if(cxRate == 4 && cyRate ==3)
				{
					currentRate  = "画面4:3";
				}
				else if(cxRate == 16 && cyRate ==9)
				{
					currentRate  = "画面16:9";
				}
			}
			if(newVal)
			{
				mframe.TipControl.ShowTipText("全屏模式\r\n" + currentRate,0xcccccc,3);
				mframe.PortalControl("notify","portal","full","1","","");
			}
			else
			{
				if(window.tidyMode)
					mframe.TipControl.ShowTipText("迷你模式\r\n" + currentRate ,0xcccccc,3);
				else
					mframe.TipControl.ShowTipText("完整模式\r\n" + currentRate,0xcccccc,3);
				mframe.PortalControl("notify","portal","full","0","","");
			}
		}
		
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if (registry && registry.create(registry.HKCU,"Software\\PPLive\\abmad"))
		{
			if(newVal)
			{
				registry.writeDWORD("fullscreenhwnd",window.hwnd);
			}
			registry.writeDWORD("fullscreen",newVal);			
		}
	}
	window.BossState = false;
	window.SetBossState = function(state)
	{	
		window.BossState  = (state==-1);
		var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
		if(window.BossState)
		{
			if(hoverInfo)hoverInfo.hoverHide();
		}
		else
		{
			if(hoverInfo)hoverInfo.hoverShow();
		}
	}
	window.tidyMode = false;
	window.enterTidyMode = enterTidyMode;
	window.exitTidyMode = exitTidyMode;
	window.showWindow = function (show)
	{
		if(window.sizemode == IDOMWindow.SizeMode_Minimized)
		{
			window.sizemode=IDOMWindow.SizeMode_Normal;
		}
		var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
		window.visible = show;
		if(show)
		{
			var TrayIcon = Components.GetObject2("SkinForm1");
			if(TrayIcon)TrayIcon.AddIcon();
			window.SetBossState(false);
			if(hoverInfo)hoverInfo.hoverShow();
		}
		else
		{
			if(hoverInfo)hoverInfo.hoverHide();
		}


	}
	window.showPreferences = function()
	{ 
		if (window.isShowPreferences) { return; }
		checkUnFullscreen();
		window.isShowPreferences = true;
		window.showModalDialog('Options.xml');
		window.isShowPreferences = false;
	};
	window.showAbout = function()
	{
		if (window.isShowAbout) { return; }
		checkUnFullscreen();
		window.isShowAbout = true;
		window.showModalDialog("about.xml","","notdisableparent=1");
		window.isShowAbout = false;
	};

	window.openUrlDialog = function()
	{
		checkUnFullscreen();
		return windowOpenUrl();
	}
	window.openFile = function()
	{
		checkUnFullscreen();
		return OpenFile();
	}
	window.directClose = function()
	{ 
		window.close();
	}
// 显示隐藏频道列表
	window.showChannel = function(aShow)
	{
//		if(aShow==$("channelWnd").visible) return;
		if(window.tabs && aShow==window.tabs.panelVisible) return;
		var ppplayercontrol = Components.GetObject2("PPPlayerControl");
		if(ppplayercontrol)
		{
			if(ppplayercontrol.$("chbtn"))ppplayercontrol.$("chbtn").visible = aShow;
			if(ppplayercontrol.$("ch2btn"))ppplayercontrol.$("ch2btn").visible = !aShow;				
		}
		var mainSplitter = $("mainSplitter");
		window.lock(7);
		mainSplitter.lock(7);

		var newScreenLeft = window.screenLeft;
		var newScreenTop = window.screenTop;
		var newOuterWidth = window.outerWidth;
		var newOuterHeight = window.outerHeight;

		var newMinWidth = 0;
		var newMinHeight = window.minHeight;

		var splitterMode = 0;
		if (aShow)
		{
			if (window.sizemode != IDOMWindow.SizeMode_Maximized)
			{
				newOuterWidth += $("channelContainer").width+4;
				if (!mainSplitter.panePlace)
				{
					newScreenLeft -= ($("channelContainer").width + 4);
				}
			}
			newMinWidth += 2+$("mainSplitter").getPaneMinSize(0)+4+$("mainSplitter").getPaneMinSize(1)+2 + 39/*互动扩展栏*/;
			splitterMode = -1;
		}
		else
		{
			window.ShowRegVip(false);
			if (window.sizemode != IDOMWindow.SizeMode_Maximized)
			{
				newOuterWidth -= ($("channelContainer").width + 4);
				if (!mainSplitter.panePlace)
				{
					newScreenLeft += $("channelContainer").width + 4;
				}
			}
			newMinWidth += 2+$("mainSplitter").getPaneMinSize(0)+2 + 39/*互动扩展栏*/;
			splitterMode = 0;
			$("passportContainer").visible = false;
			if(window.tabs)window.tabs.showPanel(false);
//			$("channelWnd").visible = false;
			$("statusPanel").visible = false; // 隐藏走马灯
		}

		
		mainSplitter.singlePaneMode = splitterMode;
		window.setMinWidthAndHeight(newMinWidth, newMinHeight, false);
		if (newOuterWidth >= window.screen.width)
		{
			if (window.sizemode != IDOMWindow.SizeMode_Maximized)
			{
				newScreenLeft = window.screen.availLeft;
			}
			else
			{
				newScreenLeft = window.screen.left - 3;
			}
		}
		window.moveSizeTo(newScreenLeft, newScreenTop, newOuterWidth, newOuterHeight);
		window.unlock(7);
		mainSplitter.unlock(7);

		if (aShow)
		{
			$("passportContainer").visible = true;
			if(window.tabs)window.tabs.showPanel(true);
//			$("channelWnd").visible = true;
			$("statusPanel").visible = true; // 显示走马灯

			//显示节目列表的时候看看需不需要刷新节目列表
			window.tryDelayRefresh();
		}
		try
		{
			$("Player").wrappedObject.NotifyChannelPane(aShow ? 0 : 1);
		}
		catch (e)
		{
		}
	}

	window.channelIsVisible = function()
	{
		return $("mainSplitter").singlePaneMode == -1;
	}
	window.channelIsLeft = function()
	{
		return !$("mainSplitter").panePlace;
	}
	window.setTaskBarTitle = function (aTitle)
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(globalWindow)globalWindow.taskbarTitle = aTitle;
		window.title = aTitle;
	}

	window.getTaskBarTitle = function()
	{
		return window.title;
	}
	window.setWindowTitle = function (aTitle)
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(globalWindow)globalWindow.windowTitle=aTitle;
		$("windowTitle").value = aTitle;
	}

	window.getWindowTitle = function()
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(globalWindow)
		{
			globalWindow.windowTitle=$("windowTitle").value;
		}
		return $("windowTitle").value;
	}	
	
	window.SetDisplayPos=function(aPos)	//0 right,!0 left
	{
		if ((aPos == 0 && !window.channelIsLeft())
			|| (aPos != 0 && window.channelIsLeft()))
		{
			return;
		}
		switchChannelDir();
//		if(window.tidyMode || $("channelWnd").visible == false || EwaIsFullScreen()) return;
//		$("mainSplitter").panePlace = !aPos;
	}
	window.GetDisplayPos=function()	//-1 invisible,0 right,1 left
	{
		if(window.tidyMode || !window.channelIsVisible() || EwaIsFullScreen()) return -1;
		else if($("mainSplitter").panePlace) return 0;
		else return 1;
	}
	window.InitTopMostEx=function()
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(!globalWindow) return;
		var aTopMost = globalWindow.TopMost;
		var PPFrame = Components.GetObject2("@pplive.com/PPFrame;1");
		if(PPFrame)PPFrame.ResizerCommand(5,aTopMost);
		if(aTopMost==0) //不置顶
		{
			window.topMost  = false;
		}
		else if(aTopMost==1) //置顶
		{
			window.topMost = true;
		}
		else if(aTopMost==2) //播放时置顶
		{
			var EWA = Components.GetObject2("EWA");
			if(EWA)
			{
				var nstate = EWA.PlayState;
				if(nstate==IPlayerState.pppBuffering || nstate==IPlayerState.pppPlay)
				{
					window.topMost  = true;
					return;
				}
			}
			window.topMost  = false;
		}
	}
	window.SetTopMostEx=function(aTopMost)
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(!globalWindow) return;
		globalWindow.TopMost = aTopMost;
		var PPFrame = Components.GetObject2("@pplive.com/PPFrame;1");
		if(PPFrame)PPFrame.ResizerCommand(5,aTopMost);
		var mframe = Components.GetObject2("mframe");
		
		if(aTopMost==0) //不置顶
		{
			window.topMost  = false;
			if(mframe && mframe.TipControl)
			{
				mframe.TipControl.ShowTipText("取消置顶",0xcccccc,3);
			}
		}
		else if(aTopMost==1) //置顶
		{
			window.IsTopMostEx = true;
			window.topMost = true;
			if(mframe && mframe.TipControl)
			{
				mframe.TipControl.ShowTipText("始终置顶",0xcccccc,3);
			}
		}
		else if(aTopMost==2) //播放时置顶
		{
			window.IsTopMostEx = true;
			if(mframe && mframe.TipControl)
			{
				mframe.TipControl.ShowTipText("播放时置顶",0xcccccc,3);
			}
			var EWA = Components.GetObject2("EWA");
			if(EWA)
			{
				var nstate = EWA.PlayState;
				if(nstate==IPlayerState.pppBuffering || nstate==IPlayerState.pppPlay)
				{
					window.topMost  = true;
					return;
				}
			}
			window.topMost  = false;
		}
	}
	window.GetTopMostEx=function()
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(!globalWindow) return -1;
		return globalWindow.TopMost;
	}
	window.InitTopMostEx();

	window.setTopMost=function(aTopMost)
	{
		/*
		if(aTopMost)
		{
			$("btnTopMost").checked = true;
		}
		else
		{
			 $("btnTopMost").checked = false;
		}
		*/
	}
	window.tabs = new Tabs($("tabsContainer"), $("channelContainer"));
	window.AddTab = function(aId,aResPath,aType,aUrl,aName)
	{
		
		if(window.tabs)window.tabs.add(aId, aResPath, aType, aUrl,aName);
	}

	window.balloons = new Balloons(window);

	var videoscan = Components.GetObject2("VideoScan");
	if(videoscan)window.videoScan = videoscan;

	var ppFrame=Components.GetObject2("PPFrame");
	if(ppFrame)
	{
		//创建播放器
		ppFrame.CreatePlayer();
		//加载互动扩展栏配置
		ppFrame.LoadTabs();
	}
	InitTimingService();
	windowInit();

// 命令行
	var cmdlinemgr = Components.GetObject("@pplive.com/command-line;1");
	window.cmdlineMgrCookie = cmdlinemgr.AddHandler(cmdlineHandler);

	window.ShowRegUser = function()
	{
		if (window.isShowRegUser) { return; }
		checkUnFullscreen();
		window.isShowRegUser = true;
		window.showModalDialog('RegUser.xml');
		window.isShowRegUser = false;		
	}

	//增强OnStateChange，由mframe调用通知
	window.OnStateChangeEx = function(bsMessage,bsAction,bswParam,bslParam)
	{
		var windowGlobal = Components.GetObject2("globalWindow");
		if (windowGlobal)
		{
			windowGlobal.strMessage = bsMessage;
			windowGlobal.strAction = bsAction;
		}
		if (bsMessage == "buffer" && bsAction=="mediaopen")
		{
			SetOriginalSizePlayPolicy();
		}
	}

	MY_DEBUG("AddSupport >>>");
	MY_DEBUG("AddSupport_education");
	AddSupport_education();
	MY_DEBUG("AddSupport_DownloadTask");
	AddSupport_DownloadTask();
	MY_DEBUG("AddSupport_Passport");
	AddSupport_Passport();
	MY_DEBUG("AddSupport_HotKey");
	AddSupport_HotKey();
	MY_DEBUG("AddSupport_Skin");
	AddSupport_Skin();
	MY_DEBUG("AddSupport_Offline");
	AddSupport_Offline();
	MY_DEBUG("AddSupport_SysTray");
	window.setTimeout("AddSupport_SysTray();", 1);
	MY_DEBUG("AddSupport_PushPOP");
	AddSupport_PushPOP();
	//MY_DEBUG("AddSupport_ChUpdatePOP");
	//AddSupport_ChUpdatePOP();
	MY_DEBUG("AddSupport_Hoverinfo");
	AddSupport_Hoverinfo();
	MY_DEBUG("AddSupport <<<");
	//显示菜单
	window.ShowPopMenu=function(name,x,y)
	{
		$(name).openPopupAtScreen(x, y);
	}

	EWA = Components.GetObject2("EWA");
	EWA.onPlayStateChanged=EwaOnPlayStateChanged;
	EWA.onFullScreen=window.EwaOnFullScreen;

	//播放支持
	window.play = function()
	{
		if(!EWA)EWA = Components.GetObject2("EWA");
		if(EWA)
		{
			EWA.Play();
		}
	}

	window.stop = function()
	{
		if(!EWA)EWA = Components.GetObject2("EWA");
		if(EWA)
		{
			EWA.Stop();
		}
	}

	window.pause = function()
	{
		if(!EWA)EWA = Components.GetObject2("EWA");
		if(EWA)
		{
			EWA.Pause();
		}
	}

	window.playprev = function()
	{
		var MainFrame = Components.GetObject2("mframe");
		if(MainFrame)MainFrame.PlayNewItem(-1);
	}

	window.playnext = function()
	{
		var MainFrame = Components.GetObject2("mframe");
		if(MainFrame)MainFrame.PlayNewItem(1);
	}
	
	//客户端启动时间统计
	var PplStat=Components.GetObject2("@pplive.com/PPLStat;1");
	if (PplStat)
	{
	    PplStat.PPLiveEndUpTime(2);
	}

	var MainFrame = Components.GetObject2("mframe");
	if(MainFrame)
	{
		MainFrame.DelayCreatePortal(3000);
	}

	//注册频道列表组建
	try{Components.RegisterObject("webchannel", $("channelWnd").wrappedObject);}catch(e){}
	try{Components.RegisterObject("gallopFrame", $("statusPanel").wrappedObject);}catch(e){}

	AddSupport_Favorite();
}

function windowOnUnload()
{
	//反注册频道列表组建
	try{Components.UnRegisterObject("webchannel");}catch(e){}
	//反注册状态栏走马灯组件
	try{Components.UnRegisterObject("gallopFrame");}catch(e){}


	//关闭vip气泡
	var pop_skin3 = Components.GetObject2("POP_VIP");
	if(pop_skin3)
	{
		pop_skin3.Show(0);
	}
	//关闭定时关机服务
	UninitTimingService();
	//关闭用户教育气泡
	if(window.balloons)window.balloons.Clear();
	// 卸载 命令行
	if (window.cmdlineMgrCookie)
	{
		var cmdlinemgr = Components.GetObject("@pplive.com/command-line;1");
		cmdlinemgr.RemoveHandler(window.cmdlineMgrCookie);
		window.cmdlineMgrCookie = 0;
	}
	//关闭浮层
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if (hoverInfo)
	{
		hoverInfo.close();
		Components.UnregisterObject("@pplive.com/hoverinfo;1");
	}
}

function checkDownload()
{
	var downloader = Components.GetObject("@pplive.com/chDownloadMgr;1");
	if(downloader)
	{	
		var hasTask = downloader.hasDownloadingTasks();
		if(hasTask)
		{
			var ret = downloader.showTipDlg(1,2,"  您还有下载任务在进行，确定要退出PPTV客户端吗？");
			if(!ret)
			{
				return false;	
			}
		}
	}
	return true;
}

function myClose()
{
	EwaUnFullScreen();
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	try
	{
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if (registry && registry.open(registry.HKCU, "Software\\PPLive\\Config\\Other"))
		{
			if (registry.queryType("CloseAction") != 4 || registry.readDWORD("CloseAction")) // 最小化到托盘
			{
				//去除最小化动画效果
				window.visible = false;
				if(hoverInfo)hoverInfo.hoverHide();
				EwaStop();	
				return;
			}
			// 关闭
			window.close();
			return;
		}
		//去除最小化动画效果
		window.visible = false;
		if(hoverInfo)hoverInfo.hoverHide();
		EwaStop();
		return;
	}
	catch (e)
	{
		window.close();
	}
	window.close();
}
// 返回 false 停止关闭
function windowOnClose() 
{
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if (window.tidyMode)
	{
		recodeTidyModePosition();
	}
	var closeMe = window.CheckDownloadTask();
	if(closeMe)window.ReleaseDownloadMgr();
	return closeMe;
}

//
function titleBarMouseDown(event)
{
	switch (event.button)
	{
	case IDOMEvent.eLeftButton:
		window.size("move");
		break;
	case IDOMEvent.eRightButton:
		$("mainMenu").openPopupAtScreen(-1, -1);
		break;
	}
}

function switchChannelDir()
{
//	if(window.tidyMode || $("channelWnd").visible == false || EwaIsFullScreen()) return;
	if(window.tidyMode || EwaIsFullScreen()) return;
	if (window.balloons)
	{
		window.balloons.Clear();
	}
	window.ShowRegVip(false);
	$("mainSplitter").panePlace = !$("mainSplitter").panePlace;
	var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
	if(hoverInfo)hoverInfo.SetHoverDefaultPos();

	$("mainSubWindow").relayout();

	var registry = Components.CreateObject("@pplive.com/registry;1");
	if (registry.open(registry.HKCU, "Software\\PPLive\\Config\\Layout",IRegistry.KEY_WRITE))
	{
		registry.writeDWORD("leftright", $("mainSplitter").panePlace ? 0 : 1);
	}

}

function openMiniSite()
{
	var bCreate = false;
	var ppframe = Components.GetObject2("@pplive.com/PPFrame;1");
	if (ppframe)
	{
		try
		{
			var minisite = Components.GetObject("@pplive.com/miniSizte;1");
			if (minisite)
			{
				if (minisite.visible)
				{
					minisite.showminiSite(true);
				}
				else
				{
					bCreate = true;
				}
			}
			else
			{
				bCreate = true;
			}
		}
		catch (e)
		{
			bCreate = true;
		}
		if (bCreate)
		{
			ppframe.DirectShowMiniSite();
			var minisite = Components.GetObject("@pplive.com/miniSizte;1");
			if (minisite)
			{
				minisite.showminiSite(true);
			}
		}
	}
}

function changeTopMost()
{
	var globalWindow = Components.GetObject2("globalWindow");
	if(!globalWindow) return;
	if(globalWindow.TopMost==0)
	{
		window.SetTopMostEx(2);
	}
	else
	{
		window.SetTopMostEx(0);
	}
	if (!window.topMost)
	{
		if (window.miniPlayer)
		{
			window.miniPlayer.topMost = true;
		}
	}
	var PPFrame = Components.GetObject2("@pplive.com/PPFrame;1");
	if(window.topMost)
	{
		PPLState(22);
	}
}


function skinMenuItemCommand(menuitem)
{
	if (menuitem.skinMenuItem)
	{
		ChangeSkin(menuitem.skinId);
	}
}

function checkMainMenu()
{
	//初始化菜单状态 声音 相关
	$("menu_leftTrack1").checked=false;
	$("menu_rightTrack1").checked=false;
	$("menu_stereo1").checked=false;
	
	var ppp = Components.GetObject2("PPP");
	if(ppp)
	{
		var nTrack = ppp.Track;
		if(nTrack ==0)
		{
			$("menu_stereo1").checked=true;			
		}
		else if(nTrack ==100)
		{
			$("menu_rightTrack1").checked=true;
		}
		else
		{
			$("menu_leftTrack1").checked=true;
		}					 
	}
	var mainWnd= Components.GetObject2("@pplive.com/ui/mainwindow;1");
	if (mainWnd)
	{
		var volumeMute = mainWnd.getElementById("menu_volumeMute2");
		if (volumeMute)
		{
			var EWA = Components.GetObject2("EWA");
			if (EWA)
			{
				if (EWA.Mute)
				{
					volumeMute.label = "取消静音";
				}
				else
				{
					volumeMute.label = "静音";
				}
			}
		}
	}
}

function checkPlayMenu()
{
	$("menu_soundLanguage").disabled = true;

	//初始化菜单状态 声音 相关
	$("menu_leftTrack").checked=false;
	$("menu_rightTrack").checked=false;
	$("menu_stereo").checked=false;
	$("menu_volumeMute").checked=false;

	if (EwaIsFullScreen())
	{
		$("menu_FullOrUnfull").label = "退出全屏";
	}
	else
	{
		$("menu_FullOrUnfull").label = "全屏";
	}
	var ppp = Components.GetObject2("PPP");
	if(ppp)
	{
		var fileType = ppp.PlayFileType;
		if(fileType==5)
		{
			$("menu_downfile").disabled = false;
		}
		else
		{
			$("menu_downfile").disabled = true;
		}
		if(ppp.OPlayer)
		{
			var audio = ppp.OPlayer.audio;
			if(audio)
			{
				var count = audio.languageCount;
				if(count>0)$("menu_soundLanguage").disabled = false;
			}
		}
		
		var nTrack = ppp.Track;
		if(nTrack ==0)
		{
			$("menu_stereo").checked=true;			
		}
		else if(nTrack ==100)
		{
			$("menu_rightTrack").checked=true;
		}
		else
		{
			$("menu_leftTrack").checked=true;
		}					 
	}
	var globalWindow = Components.GetObject2("globalWindow");
	if(globalWindow)
	{
		$("menu_cancelTop").checked=false;
		$("menu_alwaysTop").checked=false;
		$("menu_playTop").checked=false;
		if(globalWindow.TopMost==0)
		{
			$("menu_cancelTop").checked=true;
		}
		else if(globalWindow.TopMost==1)
		{
			$("menu_alwaysTop").checked=true;
		}
		else if(globalWindow.TopMost==2)
		{
			$("menu_playTop").checked=true;	
		}
	}
	var mainWnd= Components.GetObject2("@pplive.com/ui/mainwindow;1");
	if(mainWnd)
	{
		var volumeMute = mainWnd.getElementById("menu_volumeMute");
		if (volumeMute)
		{
			if (EWA.Mute)
			{
				volumeMute.label = "取消静音";
			}
			else
			{
				volumeMute.label = "静音";
			}
		}
	}
}

function buildSoundLanguageMenu(menupopup)
{
	if (menupopup && menupopup.hasChildNodes)
	{
		var menu = menupopup.firstChild;
		while (menu)
		{
			var nextmenu = menu.nextSibling;
			menupopup.removeChild(menu);
			menu = nextmenu;
		}			
	}
	
	var ppp = Components.GetObject2("PPP");
	if(ppp && ppp.OPlayer)
	{
		var audio = ppp.OPlayer.audio;
		if(audio)
		{
			var count = audio.languageCount;
			var select = audio.currentLanguageIndex;
			for(var i=0;i<count;i++)
			{
				var audioName = "音轨 "  + (i+1);
				var audioLanguageName = audio.languageName(i);
				if (audioLanguageName.length > 0)
				{
					var ss = audioLanguageName.split("/");
					if (ss.length > 1)
					{
						var l = ss[ss.length-1];
						var re = new RegExp("([^\(]+)\\((.+)\\)","ig");
						var arr = re.exec(l);
						if (arr)
						{
							audioName = RegExp.$1.replace(/(^\s*)|(\s*$)/g, "");;
						}
					}
				}
				if(select == i)
				{
					var menuItem = document.createElement("<menuitem type='radio' checked='true' oncommand='SwitchAudioLanguage(" + i + ");' label='"  + audioName + "'>");
					menupopup.appendChild(menuItem);
				}
				else
				{
					var menuItem = document.createElement("<menuitem type='radio' oncommand='SwitchAudioLanguage(" + i + ");' label='"  + audioName + "'>");
					menupopup.appendChild(menuItem);

				}
			}
		}
	}	
}
function SwitchAudioLanguage(nIndex)
{
	var ppp = Components.GetObject2("PPP");
	if(ppp && ppp.OPlayer)
	{
		var audio = ppp.OPlayer.audio;
		if(audio)
		{
			if(audio.currentLanguageIndex==nIndex)return;
			audio.currentLanguageIndex=nIndex;
		}
	}
}
function CheckViewMenu()
{
	var globalWindow = Components.GetObject2("globalWindow");
	if(globalWindow)
	{
		$("menu_cancelTop2").checked=false;
		$("menu_alwaysTop2").checked=false;
		$("menu_playTop2").checked=false;
		if(globalWindow.TopMost==0)
		{
			$("menu_cancelTop2").checked=true;
		}
		else if(globalWindow.TopMost==1)
		{
			$("menu_alwaysTop2").checked=true;
		}
		else if(globalWindow.TopMost==2)
		{
			$("menu_playTop2").checked=true;	
		}
	}

}
function buildSkinMenu(menupopup)
{
	if (menupopup && menupopup.hasChildNodes)
	{
		if (menupopup.firstChild.skinMenuItem)
		{
			var currentSkinId = getActiveSkinId();
			var skinMenu = menupopup.firstChild;
			while (skinMenu && skinMenu.skinMenuItem)
			{
				skinMenu.checked = (skinMenu.skinId == currentSkinId);
				skinMenu = skinMenu.nextSibling;
			}
			return;
		}
	}

	var skinMgr = Components.GetObject("@pplive.com/skinmgr;1");
	if (!skinMgr)
	{
		return;
	}

	var skinCount = skinMgr.count;
	var insertBefore = null;
	if (menupopup.hasChildNodes)
	{
		insertBefore = menupopup.firstChild;
	}

	var currentSkinId = getActiveSkinId();
	for (var i = 1; i <= skinCount ; i++)
	{
		var skinItem = skinMgr.Item(i);
		if (skinItem)
		{
			var menuItem = document.createElement("<menuitem type=\"radio\" oncommand=\"skinMenuItemCommand(this);\" label=\"" + skinItem.title + "\">");
			menuItem.skinMenuItem = true;
			menuItem.skinId = skinItem.id;
			if (skinItem.id == currentSkinId)
			{
				menuItem.checked = true;
			}
			if (insertBefore)
			{
				menupopup.insertBefore(menuItem, insertBefore);
			}
			else
			{
				menupopup.appendChild(menuItem);
			}
		}
	}
}
function AddSupport_education()
{
	window.ShowRegVip=function(show)
	{
		MY_DEBUG("ShowRegVip:" + show);
		if(show)
		{
			var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
			if(chMgrFactory && chMgrFactory.IsPatch())
			{
				var registry = Components.CreateObject("@pplive.com/registry;1");
				if(registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
				{
					var RegVipCount=registry.readDWORD("RegVip");
					if(!RegVipCount)
					{
						RegVipCount++;
						registry.writeDWORD("RegVip",RegVipCount);
						var show =  true;
						var registry2 = Components.CreateObject("@pplive.com/registry;1");
						if (registry2.open(registry.HKCU, "Software\\PPLive\\passport", IRegistry.KEY_READ))
						{
							if (registry2.readDWORD("autologin")!=0)
							{
								show=false;
							}
						}
						if(show)
						{
							if(window.channelIsLeft())
							{
								window.balloons.Create("education\\RegVip.xml",window.hwnd,169,0,$("beforeSign").offsetLeft + $("beforeSign").width - 10,$("beforeSign").offsetTop + $("beforeSign").height - 4);
								window.balloons.Show("education\\RegVip.xml",true);
							}
							else
							{
								window.balloons.Create("education\\RegVip.xml",window.hwnd,169,0,-20,$("beforeSign").offsetTop + $("beforeSign").height - 4);
								window.balloons.Show("education\\RegVip.xml",true);
							}
						}
					}
				}
			}
		}
		else
		{
			window.balloons.Show("education\\RegVip.xml",false);
		}
	}
	window.ShowRegVip(true);

	/*
	window.ShowDownloadBalloon=function(show)
	{
		MY_DEBUG("ShowDownloadBalloon:" + show);
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if(registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
		{
			var DownloadVideoCount=registry.readDWORD("DownloadVideo");
			if(!DownloadVideoCount)
			{
				DownloadVideoCount++;
				registry.writeDWORD("DownloadVideo",DownloadVideoCount);
				if(window.tabs)window.tabs.showballoonex(8,"education\\OldDownload.xml",show,23,93);
			}
		}
	}
	*/
	window.ShowAutoSeekBalloon=function(show,pos,duration)
	{
		return;
		if(show)
		{
			if(pos==0 || duration==0) return;
			var ppplayercontrol = Components.GetObject2("PPPlayerControl");
			if(!ppplayercontrol) return;
			var playslider = ppplayercontrol.$("playslider");
			if(!playslider || playslider.visible==false || playslider.width<=0 || playslider.height<=0) return;

			var offsetLeft = parseInt(playslider.offsetLeft + pos / duration *  playslider.width+1);
			var offsetTop =parseInt(playslider.offsetTop + playslider.height/2+1)-2;

			var AutoSeek = 0;
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
			{	
				AutoSeek = registry.readDWORD("AutoSeek");
				if(AutoSeek<3)registry.writeDWORD("AutoSeek",AutoSeek+1);	
			}
			if(AutoSeek<3)
			{
				window.balloons.Create("education\\AutoSeek.xml",ppplayercontrol.hwnd,65,75,offsetLeft,offsetTop);
				window.balloons.Show("education\\AutoSeek.xml",true);
			}
		}
		else
		{
			window.balloons.Show("education\\AutoSeek.xml",false);
		}
	}
	window.ShowChannelButtonBalloon=function(show)
	{
		MY_DEBUG("ShowChannelButtonBalloon:" + show);
	}
	window.ShowFirewallBalloon=function(show)
	{
		if(show)
		{
			var ppplayercontrol = Components.GetObject2("PPPlayerControl");
			if(!ppplayercontrol) return;
			var statespeedinfo = ppplayercontrol.$("statespeedinfo");
			if(!statespeedinfo || !statespeedinfo.visible) return;

			var offsetLeft = parseInt(statespeedinfo.offsetLeft + statespeedinfo.width/2 - ppplayercontrol.outerWidth);
			var offsetTop =parseInt(statespeedinfo.offsetTop + statespeedinfo.height/2);
			window.balloons.Create("education\\PPAPIsForbidden.xml",ppplayercontrol.hwnd,179,100,offsetLeft,offsetTop);
			window.balloons.Show("education\\PPAPIsForbidden.xml",true);
		}
		else
		{
			window.balloons.Show("education\\PPAPIsForbidden.xml",false);
		}
	}
	window.bShowFireWallForbiddenBalloon = false;
	window.nFireWallForbiddenBalloonType = 0;
	window.bForceShowFireWallForbiddenBalloon = false;
	window.ShowFirewallForbiddenBalloon = function(nType)
	{
		window.bShowFireWallForbiddenBalloon = true;
		window.nFireWallForbiddenBalloonType = nType;
		if (!window.bForceShowFireWallForbiddenBalloon && (window.sizemode == 1 || !window.visible))
		{
			window.bForceShowFireWallForbiddenBalloon = false;
			return;
		}
		var mainWnd=Components.GetObject("@pplive.com/ui/mainwindow;1");
		if(mainWnd)
		{	
			if (mainWnd.runMode == 1)  //3.0模式
			{
				var offsetLeft = mainWnd.outerWidth;
				var offsetTop = mainWnd.outerHeight;
				window.balloons.Create("education\\FirewallForbidden.xml",mainWnd.hwnd,270,156,-1,-1);
			}
			else if (mainWnd.runMode == 0) //旧2.7模式
			{
				var ppplayercontrol = Components.GetObject2("PPPlayerControl");
				var offsetLeft = -270;
				var offsetTop = 0;
				window.balloons.Create("education\\FirewallForbidden.xml",ppplayercontrol.hwnd,0,156,offsetLeft,offsetTop);
			}
			var balloon = window.balloons.Get("education\\firewallforbidden.xml");
			if (balloon)
			{
				balloon.ShowFirewallForbiddenBalloon(nType);
				window.balloons.Show("education\\FirewallForbidden.xml",true);
			}
			window.bShowFireWallForbiddenBalloon = false;
			window.nFireWallForbiddenBalloonType = 0;
			window.bForceShowFireWallForbiddenBalloon = false;
		}
	}
	window.CloseFirewallForbiddenBalloon = function()
	{
		var balloon = Components.GetObject("balloon.education\\firewallforbidden.xml");
		if (balloon)
		{
			balloon.close();
		}
	}
	window.ShowPause2BufferBalloon=function(show)
	{
		if(show)
		{
			var ppplayercontrol = Components.GetObject2("PPPlayerControl");
			if(!ppplayercontrol) return;
			var pausebtn = ppplayercontrol.$("pausebtn");
			if(!pausebtn) return;

			var offsetLeft = parseInt(pausebtn.offsetLeft + pausebtn.width/2+4);
			var offsetTop =parseInt(pausebtn.offsetTop + 3);

			window.balloons.Create("education\\Pause2Buffer.xml",ppplayercontrol.hwnd,28,93,offsetLeft,offsetTop);
			window.balloons.Show("education\\Pause2Buffer.xml",true);
		}
		else
		{
			window.balloons.Show("education\\Pause2Buffer.xml",false);
		}
	}
	window.ShowBDSwitchBalloon=function(show,dir)
	{
		MY_DEBUG("ShowBDSwitchBalloon:" + show);
		if(show)
		{
			var ppp = Components.GetObject2("PPP");
			if(ppp)
			{
				var switchto=ppp.BitrateSwitch(dir);
				MY_DEBUG("ShowBDSwitchBalloon dir:" + dir);
				MY_DEBUG("ShowBDSwitchBalloon switch:" + switchto);
				if(switchto!=0)
				{
					var ppplayercontrol = Components.GetObject2("PPPlayerControl");
					if(!ppplayercontrol) return;
					var shiftbtn = ppplayercontrol.$("shiftbtn");
					if(!shiftbtn || !shiftbtn.visible) return;

					var offsetLeft = parseInt(shiftbtn.offsetLeft + shiftbtn.width/2);
					var offsetTop =parseInt(shiftbtn.offsetTop + shiftbtn.height/2-5);
					if(dir>0)
					{
						//高清切到蓝光
						window.balloons.Show("education\\BDSwitch.xml",false);
						window.balloons.Create("education\\HDSwitch.xml",ppplayercontrol.hwnd,53,135,offsetLeft,offsetTop);
						window.balloons.Show("education\\HDSwitch.xml",true);
					}
					else
					{
						//蓝光切到高清
						window.balloons.Show("education\\HDSwitch.xml",false);
						window.balloons.Create("education\\BDSwitch.xml",ppplayercontrol.hwnd,53,135,offsetLeft,offsetTop);
						window.balloons.Show("education\\BDSwitch.xml",true);
					}
				}
			}
		}
		else
		{
			window.balloons.Show("education\\HDSwitch.xml",false);
			window.balloons.Show("education\\BDSwitch.xml",false);
		}
	}

}

//=========================AddSupport_SysTray begin add by lxb=================================
function AddSupport_SysTray()
{
	// 系统托盘
	var TrayIcon = Components.GetObject2("SkinForm1");
	if(!TrayIcon)
	{
		TrayIcon=Components.GetObject("@pplive.com/PPIconTray;1");
		if(TrayIcon)Components.RegisterObject("SkinForm1",TrayIcon);//气泡支持
	}
	if (TrayIcon)TrayIcon.AddIcon();

	var BalloonTip = Components.GetObject2("BalloonTip");
	if(!BalloonTip)
	{
		BalloonTip = Components.GetObject("@pplive.com/PPIconTray;1");
		if(BalloonTip)Components.RegisterObject("BalloonTip",BalloonTip);//气泡支持2
	}
}
//=========================AddSupport_SysTray end add by lxb=================================


//=========================AddSupport_Offline begin add by lxb=================================
function AddSupport_Offline()
{
	window.OnOffline = function(offline)
	{
		if(offline)
		{
			//进入离线模式

		}
		else
		{
			//退出离线模式
			
		}

		var TrayIcon = Components.GetObject("@pplive.com/PPIconTray;1");
		if(window.visible)
		{
			if(TrayIcon)TrayIcon.OnOffline(offline,true);
		}
		else
		{
			if(TrayIcon)TrayIcon.OnOffline(offline,false);
		}
	}
}
//=========================AddSupport_Offline end add by lxb=================================

//=========================AddSupport_Skin begin add by lxb=================================
function AddSupport_Skin()
{
	//vip气泡支持换肤
	window.onvipskinchanged = function(skin)
	{
		return;
	}
	window.vecOnSkinChange  = {};
	// 皮肤支持
	window.onskinchanged = function()
	{
		var activeSkin = getActiveSkin();
		if (!activeSkin)
		{
			return;
		}
		if(window.tabs)window.tabs.onchangeskin();
		$("Player").SetSkinPath(activeSkin.resourceFolder);
		var TrayIcon = Components.GetObject2("@pplive.com/PPIconTray;1");
		if(TrayIcon)TrayIcon.SetSkinPath(activeSkin.resourceFolder);
		var skinValue = "other";
		var skinId = activeSkin.id;
		if (skinId == "0" || skinId == "3") // 蓝色
		{
			skinValue = "blue";
			$("r_center").backgroundColor = "#336699";
			$("spltBar").backgroundColor = "#053A6C";
			$("passportContainer").backgroundColor = "#044D87";
		}
		else if (skinId == "1" || skinId == "2" || skinId == "4")
		{
			skinValue = "black";
			$("r_center").backgroundColor = "#121212";
			$("spltBar").backgroundColor = "#222222";
			$("passportContainer").backgroundColor = "none";
		}
		for (var keyname in window.vecOnSkinChange)
		{
			try
			{
				window.vecOnSkinChange[keyname](skinValue);	
			}
			catch(e)
			{
			}
		}
		window.onvipskinchanged(skinValue);
	}
	window.onskinchanged();
}
//=========================AddSupport_Skin end add by lxb=================================


//=========================AddSupport_DownloadTask begin add by lxb=================================
function AddSupport_DownloadTask()
{
	window.VasVip=function(xml,xmllogin,arg)
	{
		var passport = Components.GetObject2("@pplive.com/passport;1");
		var isVipUser = false;
		var isLoginUser = false;
		if(passport)
		{
			isVipUser = passport.IsVipUser;
			isLoginUser = (0==passport.state);
		}
		if(!isVipUser)
		{
			if(isLoginUser)
			{
				window.showModalDialog(xml,arg);
			}
			else
			{
				window.showModalDialog(xmllogin,arg);
			}
			if(passport)
			{
				isVipUser = passport.IsVipUser;
				isLoginUser = (0==passport.state);
			}
			if(!isVipUser) return false;
		}
		return true;
	}
	window.OnDragDownloadTask = function(filesize,taskid)
	{
		var downloadTask= Components.GetObject2("@pplive.com/newDownload;" + taskid);
		if(downloadTask)
		{
			downloadTask.OnGetDrag(filesize);
		}		
	}
	window.AddDwonloadTask=function(videoname,filepath,filename,taskid,defaultExt,isVip,nVtp)
	{
		
		var downloadTask= Components.GetObject2("@pplive.com/newDownload;" + taskid);
		if(!downloadTask)
		{
			downloadTask = window.open("NewDownloadTask.xml", "", "appwindow=1;hidden=1;");
		}
		if(!downloadTask) 
		{
			var downloader = Components.GetObject2("@pplive.com/chDownloadMgr;1");
			if(downloader)downloader.newDownloadCallBack(taskid,false,"");
			return;
		}

		if (downloadTask)
		{
			//max size if it is min.
			downloadTask.sizemode = 0;
		}

		if(isVip)
		{
			if(!window.VasVip("VIPDownload.xml","VIPDownloadLogin.xml",taskid))
			{
				downloadTask.close();
				var downloader = Components.GetObject2("@pplive.com/chDownloadMgr;1");
				if(downloader)downloader.newDownloadCallBack(taskid,false,"");
				return;
			}
		}
		else if(nVtp==2)
		{
			if(!window.VasVip("VIPDownloadHD.xml","VIPDownloadHDLogin.xml",taskid))
			{
				downloadTask.close();
				var downloader = Components.GetObject2("@pplive.com/chDownloadMgr;1");
				if(downloader)downloader.newDownloadCallBack(taskid,false,"");
				return;
			}
		}
		Components.RegisterObject("@pplive.com/newDownload;" + taskid,downloadTask);
		downloadTask.AddTask(videoname,filepath,filename,taskid,defaultExt);
		downloadTask.visible = true;
	}

	window.ShowDownloadTask=function(videoname,filepath,filename,filesize,taskid)
	{
		var downloadTask= Components.GetObject2("@pplive.com/newDownload;" + taskid);
		if(!downloadTask)
		{		
			downloadTask = window.open("NewDownloadTask.xml", "", "appwindow=1;");
			Components.RegisterObject("@pplive.com/newDownload;" + taskid,downloadTask);
		}
		if(!downloadTask)
		{
			return;
		}

		downloadTask.ShowTask(videoname,filepath,filename,filesize,taskid);
	}
	window.CheckDownloadTask = function()
	{
		var downloader = Components.GetObject2("@pplive.com/chDownloadMgr;1");
		if(downloader)
		{	
			var hasTask = downloader.hasDownloadingTasks();
			if(hasTask)
			{
				var ret = downloader.showTipDlg(1,2,"  您还有下载任务在进行，确定要退出PPTV客户端吗？");
				if(!ret)
				{
					return false;	
				}
			}
		}
		return true;
	}
	window.ReleaseDownloadMgr=function()
	{
		var downloadMgr = Components.GetObject2("@pplive.com/chDownloadMgr;1");
		if(downloadMgr)
		{
			downloadMgr.ReleaseDownloadMgr();
		}
	}
}
//=========================AddSupport_DownloadTask end add by lxb=================================

//=========================AddSupport_Passport begin add by lxb=================================
function autoLogin()
{
	if($("passport").userName.length != 0)
	{
		return;
	}
	var username = $("passport").DefaultUser;
	var password = $("passport").DefaultPwd;
	if (username.length > 0 && password.length > 0)
	{
		$("passport").Login(username, password);
		window.autologin=true;
	}
}

function AddSupport_Passport()
{
	//登录通知事件
	window.signin=0;
	window.autologin=false;
	if(!window.vecOnUserLogin)window.vecOnUserLogin  = {};
	if($("passport").userName.length==0)
	{
		//自动登录
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if (registry.open(registry.HKCU, "Software\\PPLive\\passport", IRegistry.KEY_READ))
		{
			if (registry.readDWORD("autologin"))
			{// 延迟自动登录
				var timerId = window.setTimeout("autoLogin();", 1000);
			}
		}
	}
	else
	{
		if($("passport").state==0)
		{
			var filepath = Components.GetObject("@pplive.com/filepath;1");
			if(filepath && filepath.PathFileExists($("passport").localFacePicture))
			{
				$("userFace").src=$("passport").localFacePicture;
			}
			$("userid").value = $("passport").userName;
			if($("passport").IsVipUser)
			{
				$("usernormal").visible = false;
				$("uservip").visible = true;
			}
			else
			{
				$("usernormal").visible = true;
				$("uservip").visible = false;
			}
			if (!window.loading)
			{
				$("channelContainer").relayout();
				$("mainSubWindow").relayout();
			}
			$("afterSign").visible = true;
			$("beforeSign").visible = false;
			window.ShowRegVip(false);
			var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
			if(hoverInfo)hoverInfo.onLogin(true);
		}
		else
		{
			//$("userFace").src="avatar_bg.png";
		}
		
	}
	//登录
	window.OnPassportLogin = function(vLogin)
	{
		if (vLogin)
		{
			$("userFace").src="";
			$("userid").value = $("passport").userName;

			//切换用户名
			var localChMgr = Components.GetObject("@pplive.com/PPChLocalManager;1");
			if(localChMgr)
			{
				localChMgr.SwitchUser($("passport").userName);
			}
			//切换用户 && 设置自动同步
			var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
			if(chMgrFactory)
			{
				var fav = chMgrFactory.favLive;
				var recent = chMgrFactory.recent;
				if(fav)
				{
					fav.CloseFavorites();
					fav.LoadFavorites(2);
				}
				if(recent)
				{
					recent.CloseFavorites();
					recent.LoadFavorites(1);
				}
			}
			//登录成功
			if ($("passport").IsVipUser)
			{
				//VIP用户登录
				var NoShowWelcome = 0;
				var registry = Components.CreateObject("@pplive.com/registry;1");
				if (registry.open(registry.HKCU, "Software\\PPLive\\vip", IRegistry.KEY_READ))
				{
					NoShowWelcome = registry.readDWORD("Welcome");
				}
				var pushpop = Components.GetObject2("@pplive.com/pushpop;1");
				var pushpop2 = Components.GetObject2("@pplive.com/pushpop2;1");
				if(NoShowWelcome==0 && (!pushpop || pushpop.visible==false) && (!pushpop2 || pushpop2.visible==false))
				{	//延时10秒显示VIP气泡
					if (vipPopupTimerID)
					{
						window.clearTimeout(vipPopupTimerID);
					}
					vipPopupTimerID = window.setTimeout("showVipPopup();", 10*1000);
				}
				$("usernormal").visible = false;
				$("uservip").visible = true;
			}
			else
			{	
				//非VIP用户登录
				$("usernormal").visible = true;
				$("uservip").visible = false;
			}

			$("channelContainer").relayout();
			$("afterSign").visible = true;
			$("beforeSign").visible = false;
			window.ShowRegVip(false);
			$("mainSubWindow").relayout();
			var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
			if(hoverInfo)hoverInfo.onLogin(true);
			for (var keyname in window.vecOnUserLogin)
			{
				try
				{
					window.vecOnUserLogin[keyname](true);			
				}
				catch(e)
				{
				}
			}
		}
		else
		{
			//登录失败
			if(window.autologin==true)
			{
				$("btnLogin").visible = false;
				$("btnReLogin").visible = true;
				$("lblLogin1").visible = true;				
			}
			if(window.autologin)
			{
				var globalWindow = Components.GetObject2("globalWindow");
				if(globalWindow.AutologinFail==false)
				{
					globalWindow.AutologinFail=true;
					if(window.visible && window.signin==0)window.showModalDialog("signin.xml");
				}
			}
		}
		window.autologin=false;
	}
	window.OnPassportLogout = function(reason)
	{
		var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
		if(hoverInfo)hoverInfo.onLogin(false);

			//切换用户 && 设置自动同步
		var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
		if(chMgrFactory)
		{
			var fav = chMgrFactory.favLive;
			var recent = chMgrFactory.recent;
			if(fav) fav.LoadFavorites(2);
			if(recent) recent.LoadFavorites(1);
		}

		$("beforeSign").visible = true;
		$("afterSign").visible = false;

		if ($('channelContainer').passportIsExpanded)
		{
			passportButtonClick(false);
		}
		else
		{
			$('channelContainer').relayout();
		}
		$("userid").value = "";

		//vip气泡消失
		var vippop = Components.GetObject2("POP_VIP");	
		if(vippop)vippop.show(0);

		for (var keyname in window.vecOnUserLogin)
		{
			try
			{
				window.vecOnUserLogin[keyname](false);			
			}
			catch(e)
			{
			}
		}
	}
	window.Logout=function()
	{
		$("passport").Logout();
		$("btnLogin").visible = true;
		$("btnReLogin").visible = false;
		$("lblLogin1").visible = false;
	}

	window.ReLoginClick=function()
	{
		$("btnLogin").visible = true;
		$("btnReLogin").visible = false;
		$("lblLogin1").visible = false;
		if(window.signin==0)window.showModalDialog('signin.xml');
	}
}

//=========================AddSupport_Passport end add by lxb=================================

//=========================AddSupport_Debug begin add by lxb=================================
function AddSupport_Debug()
{
	if (!window.debug)
	{
		window.debug = Components.GetObject("@pplive.com/outputdebug;1");
	}
}
function MY_DEBUG(strDebug)
{
	if (!window.debug)
	{
		window.debug = Components.GetObject("@pplive.com/outputdebug;1");
	}
	if(window.debug)window.debug.DebugString(strDebug);
}
//=========================AddSupport_Debug begin add by lxb=================================


//=========================AddSupport_HotKey begin add by lxb=================================
function AddSupport_HotKey()
{
	window.getHotKeyText = function(Itemname)
	{
		if(!$(Itemname)) return "";
		var keyText = "";
		if($(Itemname).nodename=="menuitem")
		{
			var key = $(Itemname).getAttribute("key");
			if(key)
			{
				keyText= $(key).readableText;
			}
		}
		else if($(Itemname).nodename=="key")
		{
			var key = Itemname;
			keyText= $(key).readableText;
		}
		return keyText;
	}
	window.getHotKey = function(Itemname)
	{
		if(!$(Itemname)) return 0;
		var cMod = 0;
		var cKey = 0;
		if($(Itemname).nodename=="menuitem")
		{
			var key = $(Itemname).getAttribute("key");
			if(key)
			{
				cMod = $(key).modifiersValue & 0xf ;
				cKey = $(key).keycodeValue;
			}
		}
		else if($(Itemname).nodename=="key")
		{
			var key = Itemname;
			cMod = $(key).modifiersValue & 0xf;
			cKey = $(key).keycodeValue;
		}

		var cShift = cMod & 0x1;
		var cAlt = (cMod & 0x2) >> 1;
		var cCtrl = (cMod & 0x4)>>2;
		var cMeta = (cMod & 0x8)>>3;
		var Modvalue = (cMeta << 3) | (cAlt<<2) | (cCtrl<<1) | cShift;
		var keyvalue = cKey;
		var hotkey = Modvalue << 16 | keyvalue;
		return hotkey;
	}
	window.setHotKey = function(Itemname,value,writeReg)
	{
		if (!$(Itemname))
		{
			return;
		}
		var Modvalue = value>>16;
		var keyValue= value & 0xffff;
		if(!arguments[2]) writeReg = false;
		var cShift = (Modvalue & 0x1)>>0;
		var cCtrl = (Modvalue & 0x2)>>1;
		var cAlt = (Modvalue & 0x4)>>2;
		var cMeta = (Modvalue & 0x8)>>3;
		var cMod = (cMeta << 3) | (cCtrl << 2) | (cAlt <<1) | cShift;
		var cKey = keyValue;
		
		if($(Itemname).nodename=="menuitem")
		{
			var key = $(Itemname).getAttribute("key");
			if(key)
			{
				$(key).modifiersValue =  cMod | (0xf <<4);
				$(key).keycodeValue= cKey;
				$(Itemname).refresh();
			}
		}
		else if($(Itemname).nodename=="key")
		{
			var key = Itemname;
			$(key).modifiersValue =  cMod | (0xf <<4);
			$(key).keycodeValue= cKey;
		}

		if(writeReg)
		{
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.create(registry.HKCU,"Software\\PPLive\\PPTV\\HotKey"))
			{
				if(Modvalue==0 && keyValue==0)
				{
					registry.writeDWORD(Itemname,0xffffffff);
				}
				else
				{
					registry.writeDWORD(Itemname,Modvalue<<16 | keyValue);
				}
			}
		}
	}
	function SetInitHotKey(Itemname,value)
	{
		if(value==0)
		{
			return;
		}
		else if(value == -1) 
		{
			value=0;
		}
		window.setHotKey(Itemname,value);
	}
	function InitHotKey()
	{
		// 检查配置
		var registry = Components.CreateObject("@pplive.com/registry;1");
		if (registry && registry.open(registry.HKCU, "Software\\PPLive\\PPTV\\HotKey"))
		{
			SetInitHotKey("key_screenshot",registry.readDWORD("key_screenshot"));
			SetInitHotKey("menu_openFile",registry.readDWORD("menu_openFile"));
			SetInitHotKey("key_vsmall",registry.readDWORD("key_vsmall"));
			SetInitHotKey("key_vlarge",registry.readDWORD("key_vlarge"));
			SetInitHotKey("key_upmove",registry.readDWORD("key_upmove"));
			SetInitHotKey("menu2_20x",registry.readDWORD("menu2_20x"));
			SetInitHotKey("menu_Stop",registry.readDWORD("menu_Stop"));
			SetInitHotKey("menu_volumeInc",registry.readDWORD("menu_volumeInc"));
			SetInitHotKey("menu_volumeDec",registry.readDWORD("menu_volumeDec"));
			SetInitHotKey("key_smaller",registry.readDWORD("key_smaller"));
			SetInitHotKey("key_FV",registry.readDWORD("key_FV"));
			SetInitHotKey("menu_volumeMute",registry.readDWORD("menu_volumeMute"));
			SetInitHotKey("menu_showPreferences",registry.readDWORD("menu_showPreferences"));
			SetInitHotKey("key_rightmove",registry.readDWORD("key_rightmove"));
			SetInitHotKey("key_resetscreen",registry.readDWORD("key_resetscreen"));
			SetInitHotKey("key_directCloseWindow",registry.readDWORD("key_directCloseWindow"));
			SetInitHotKey("key_FF",registry.readDWORD("key_FF"));
			SetInitHotKey("menu_PlayOrPause",registry.readDWORD("menu_PlayOrPause"));
			SetInitHotKey("menu_openUrl",registry.readDWORD("menu_openUrl"));
			SetInitHotKey("menu2_10x",registry.readDWORD("menu2_10x"));
			SetInitHotKey("menu2_05x",registry.readDWORD("menu2_05x"));
			SetInitHotKey("menu_switchTinyMode",registry.readDWORD("menu_switchTinyMode"));
			SetInitHotKey("key_middlemove",registry.readDWORD("key_middlemove"));
			SetInitHotKey("menu_switchDir",registry.readDWORD("menu_switchDir"));
			SetInitHotKey("key_leftmove",registry.readDWORD("key_leftmove"));
			SetInitHotKey("key_larger",registry.readDWORD("key_larger"));
			SetInitHotKey("key_hsmall",registry.readDWORD("key_hsmall"));
			SetInitHotKey("key_hlarge",registry.readDWORD("key_hlarge"));
			SetInitHotKey("menu_FullOrUnfull",registry.readDWORD("menu_FullOrUnfull"));
			SetInitHotKey("key_downmove",registry.readDWORD("key_downmove"));
			SetInitHotKey("menu_closeWindow",registry.readDWORD("menu_closeWindow"));
			SetInitHotKey("menu_playPrev",registry.readDWORD("menu_playPrev"));
			SetInitHotKey("menu_playNext",registry.readDWORD("menu_playNext"));
		}
	}
	InitHotKey();
}
//=========================AddSupport_HotKey end add by lxb=================================

//=========================AddSupport_PushPOP begin add by lxb=================================
function AddSupport_PushPOP()
{
	//push气泡窗口
	var pushpop = Components.GetObject2("@pplive.com/pushpop;1");
	if(!pushpop)
	{
		pushpop = window.open("push_pop.xml", "", "hidden=1;toolwindow=1;owner=1;");
		Components.RegisterObject("@pplive.com/pushpop;1", pushpop);
	}
	else
	{
		pushpop.bindSkinChange();
	}
	//push气泡窗口2
	var pushpop2 = Components.GetObject2("@pplive.com/pushpop2;1");
	if(!pushpop2)
	{
		pushpop2 = window.open("push_pop2.xml", "", "hidden=1;toolwindow=1;owner=1;");
		Components.RegisterObject("@pplive.com/pushpop2;1", pushpop2);
	}
	else
	{
		pushpop2.bindSkinChange();
	}
}
//=========================AddSupport_PushPOP begin add by lxb=================================

//=========================AddSupport_ChUpdatePOP begin add by lxb=================================
/*
function AddSupport_ChUpdatePOP()
{
	//节目量更新气泡
	window.ShowNumTip=function(num,show)
	{
		if(show!=0 && !window.firstShow)
		{
			return;
		}
		var channelNumTip;
		channelNumTip = Components.GetObject2("@pplive.com/channelnumtip;1");
		if(!channelNumTip && show!=0 && num>=100)
		{
			channelNumTip = window.open("ChannelNumTip.xml", "", "toolwindow=1;hidden=1");
			if(channelNumTip)Components.RegisterObject("@pplive.com/channelnumtip;1",channelNumTip);
		}
		var pushpop = Components.GetObject2("@pplive.com/pushpop;1");
		var pushpop2 = Components.GetObject2("@pplive.com/pushpop2;1");
		if(show!=0 && ((pushpop && pushpop.visible)||(pushpop2 && pushpop2.visible)))
			return false;
		
		if(channelNumTip && (( num>=100 && show!=0 ) || show==0))
		{
			channelNumTip.ShowNumTip(num,show);
			return true;
		}
		return false;
	}
	window.ShowNumTip(0,0);

}
*/
//=========================AddSupport_ChUpdatePOP end add by lxb=================================


//=========================AddSupport_Hoverinfo begin add by lxb=================================
function AddSupport_Hoverinfo()
{
	//悬停窗口
	var hoverInfo = window.open("hoverinfo.xml", "", "owner=1;hidden=1");
	if(!hoverInfo) return;
	Components.RegisterObject("@pplive.com/hoverinfo;1", hoverInfo);
	hoverInfo.onLogin = function(login){return;}
	hoverInfo.hoverHideBySystem=false;
	hoverInfo.hoverShow=function()
	{
		var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
		if(!hoverInfo) return;
		var isHoverVisible=hoverInfo.visible;
		var isUIVisible = window.visible;
		var isMinisize = (window.sizemode == IDOMWindow.SizeMode_Minimized);
		var isTidyMode = window.tidyMode;
		//UI显示，非miniszie状态，非迷你模式，hover恢复隐藏前的状态
		if(isUIVisible &&  !isMinisize && !isTidyMode && hoverInfo.hoverHideBySystem)
		{
			hoverInfo.visible = true;
			hoverInfo.hoverHideBySystem = false;
		}
		if(!isHoverVisible)hoverInfo.SetHoverDefaultPos();
	}
	hoverInfo.hoverHide=function()
	{
		var hoverInfo = Components.GetObject2("@pplive.com/hoverinfo;1");
		if(!hoverInfo) return;
		var hoverVisible = hoverInfo.visible;
		if(hoverVisible)
		{
			hoverInfo.hoverHideBySystem = true; 
		}
		hoverInfo.visible = false;
	}
}

//begin add by gjj.
//function for chctrl menu.
function OnChctrlMenu(wndType, menuType, xPos, yPos, expanded, playing, autocollapse, selnum, hjType, ChCnts)
{
	var menuPopup = null;

	window.MenuWndType = wndType;
	window.MenuType = menuType;
	window.MenuExpanded = expanded;
	window.MenuPlaying = playing;
	window.MenuAutocollapse = autocollapse;
	window.MenuSelnum = selnum;
	window.MenuHjType = hjType;
	window.MenuChCnts = ChCnts;

	MY_DEBUG("xml_menu::expand="+window.MenuExpanded);
	MY_DEBUG("xml_menu::playing="+window.MenuPlaying);
	MY_DEBUG("xml_menu::autocollapse="+window.MenuAutocollapse);
	MY_DEBUG("xml_menu::selnum="+window.MenuSelnum);
	MY_DEBUG("xml_menu::hjType="+window.MenuHjType);

	if (0 == wndType)//在线列表及搜索
	{
		switch (menuType)
		{
		case 0:
			menuPopup = document.getElementById("menu_live_channel");	//menu of catalog.
			break;
		case 1:
			menuPopup = document.getElementById("menu_live_channel");//menu of collection.
			break;
		case 2:
			menuPopup = document.getElementById("menu_live_catalog");	//menu of single channel.
			break;
		default:
			break;
		}
	}
	else if (1 == wndType)//收藏
	{
		switch (menuType)
		{
		case 0:
			menuPopup = document.getElementById("menu_fav_channel");
			break;
		default:
			break;
		}
	}
	else if (2 == wndType)//最近观看
	{
		switch (menuType)
		{
		case 0:
			menuPopup = document.getElementById("menu_lastwatch_channel");
			break;
		default:
			break;
		}
	}
	else if (3 == wndType)//搜藏和最近观看的搜索
	{
		switch (menuType)
		{
		case 1:	//收藏
			menuPopup = document.getElementById("menu_fav_search_channel");
			break;
		case 2:	//最近观看
			menuPopup = document.getElementById("menu_lastwatch_search_channel");
			break;
		default:
			break;
		}
	}

	if (menuPopup)
	{
		menuPopup.openPopupAtScreen(xPos, yPos);
	}
}

function DisableItem(item, bDisabled)
{
	if (item)
	{
		item.disabled = bDisabled;
	}
}

function buildChctrlSkinMenu(menupopup)
{
	var item_expand = null;
	var item_playing = null;
	var item_stop = null;
	var item_download = null;
	var item_copylink = null;
	var item_refresh = null;
	var item_addfav = null;
	var item_allcol = null;
	var item_autocol = null;
	var item_del_sel = null;
	var item_del_all = null;

	var menuId = menupopup.id;
	if ("menu_live_catalog" == menuId)
	{
		MY_DEBUG("xml_menu::Chctrl_live_Catalog_Menu_handler");
		item_expand = document.getElementById("menu_live_expand_catalog");
		item_autocol = document.getElementById("menu_live_auto_collapse_catalog");
		item_stop = document.getElementById("menu_live_stop_catalog");
		item_copylink = document.getElementById("menu_live_copy_cataloglink");
		item_addfav = document.getElementById("menu_live_addto_fav_catalog");
		if (!item_expand || !item_autocol || !item_stop || !item_copylink || !item_addfav)
			return;

		if (window.MenuSelnum)
		{
			if (window.MenuExpanded)
			{
				item_expand.label = "折叠";
			}
			else
				item_expand.label = "展开";
		}

		DisableItem(item_copylink, true);
		DisableItem(item_addfav, true);

		if (window.MenuPlaying)
		{
			DisableItem(item_stop, false);
		}
		else
			DisableItem(item_stop, true);

		item_autocol.checked = window.MenuAutocollapse;
	}
	else if ("menu_live_channel" == menuId)
	{
		MY_DEBUG("xml_menu::Chctrl_live_channel_Menu_handler");

		item_playing = document.getElementById("menu_live_play_channel");
		item_stop = document.getElementById("menu_live_stop_channel");
		item_download = document.getElementById("menu_live_download_channel");
		item_refresh = document.getElementById("menu_live_refresh_channel");
		item_copylink = document.getElementById("menu_live_copy_channellink");
		item_addfav = document.getElementById("menu_live_addto_fav_channel");
		item_autocol = document.getElementById("menu_live_auto_collapse_channel");

		if (!item_playing || !item_stop || !item_download || !item_refresh || !item_copylink || !item_addfav || !item_autocol)
		{
			MY_DEBUG("xml_menu::on item not exist");
			return;
		}

		if (window.MenuSelnum)
		{
			DisableItem(item_playing, false);
			DisableItem(item_stop, false);

			if (window.MenuHjType)
			{
				DisableItem(item_download, true);
			}
			else
				DisableItem(item_download, false);

			DisableItem(item_copylink, false);
			DisableItem(item_addfav, false);

			if (window.MenuPlaying)
			{
				DisableItem(item_stop, false);
			}
			else
			{
				DisableItem(item_stop, true);
			}
		}
		else
		{
			DisableItem(item_playing, true);
			DisableItem(item_stop, true);
			DisableItem(item_download, true);
			DisableItem(item_copylink, true);
			DisableItem(item_addfav, true);
		}

		item_autocol.checked = window.MenuAutocollapse;
	}
	else if ("menu_fav_channel" == menuId)
	{
		MY_DEBUG("xml_menu::Chctrl_fav_channel_Menu_handler");
		item_playing = document.getElementById("menu_fav_play");
		item_stop = document.getElementById("menu_fav_stop");
		item_download = document.getElementById("menu_fav_download");
		item_del_sel = document.getElementById("menu_fav_item_delete");
		item_copylink = document.getElementById("menu_fav_copy_link");
		item_del_all = document.getElementById("menu_fav_all_delete");
		
		if (!item_playing || !item_stop || !item_download || !item_del_sel || !item_copylink || !item_del_all)
		{
			MY_DEBUG("xml_menu::one item not exists.");
			return;
		}

		if (window.MenuSelnum)
		{
			DisableItem(item_playing, false);
			DisableItem(item_stop, false);

			if (window.MenuHjType)
			{
				DisableItem(item_download, true);
			}
			else
				DisableItem(item_download, false);

			DisableItem(item_copylink, false);
			DisableItem(item_del_sel, false);
		}
		else
		{
			DisableItem(item_playing, true);
			DisableItem(item_download, true);
			DisableItem(item_copylink, true);
			DisableItem(item_del_sel, true);
		}

		if (window.MenuPlaying)
		{
			DisableItem(item_stop, false);
		}
		else
		{
			DisableItem(item_stop, true);
		}

		if (window.MenuChCnts > 0)
			DisableItem(item_del_all, false);
		else
			DisableItem(item_del_all, true);
	}
	else if ("menu_fav_search_channel" == menuId)
	{
		MY_DEBUG("xml_menu::Chctrl_fav_search_channel_Menu_handler");
		item_playing = document.getElementById("menu_fav_search_play");
		item_stop = document.getElementById("menu_fav_search_stop");
		item_download = document.getElementById("menu_fav_search_download");
		item_copylink = document.getElementById("menu_fav_search_copy_link");
		
		if (!item_playing || !item_stop || !item_download || !item_copylink)
		{
			MY_DEBUG("xml_menu::one item not exists.");
			return;
		}

		if (window.MenuSelnum)
		{
			DisableItem(item_playing, false);
			DisableItem(item_stop, false);

			if (window.MenuHjType)
			{
				DisableItem(item_download, true);
			}
			else
				DisableItem(item_download, false);

			DisableItem(item_copylink, false);
		}
		else
		{
			DisableItem(item_playing, true);
			DisableItem(item_download, true);
			DisableItem(item_copylink, true);
		}

		if (window.MenuPlaying)
		{
			DisableItem(item_stop, false);
		}
		else
		{
			DisableItem(item_stop, true);
		}
	}
	else if ("menu_lastwatch_channel" == menuId)
	{
		MY_DEBUG("xml_menu::Chctrl_lastwatch_channel_Menu_handler");

		item_playing = document.getElementById("menu_last_play");
		item_stop = document.getElementById("menu_last_stop");
		item_download = document.getElementById("menu_last_download");
		item_del_sel = document.getElementById("menu_last_item_delete");
		item_copylink = document.getElementById("menu_last_copy_link");
		item_addfav = document.getElementById("menu_last_addto_fav");
		item_del_all = document.getElementById("menu_last_all_delete");

		if (!item_playing || !item_stop || !item_del_sel || !item_copylink || !item_addfav || !item_del_all)
		{
			MY_DEBUG("xml_menu::one item not exists.");
			return;
		}
		
		if (window.MenuSelnum)
		{
			DisableItem(item_playing, false);
			DisableItem(item_stop, false);
			DisableItem(item_copylink, false);
			DisableItem(item_del_sel, false);
			DisableItem(item_addfav, false);

			if (window.MenuHjType)
			{
				DisableItem(item_download, true);
			}
			else
				DisableItem(item_download, false);
		}
		else
		{
			DisableItem(item_playing, true);
			DisableItem(item_download, true);
			DisableItem(item_copylink, true);
			DisableItem(item_del_sel, true);
			DisableItem(item_addfav, true);
		}

		if (window.MenuPlaying)
		{
			DisableItem(item_stop, false);
		}
		else
		{
			DisableItem(item_stop, true);
		}

		if (window.MenuChCnts > 0)
			DisableItem(item_del_all, false);
		else
			DisableItem(item_del_all, true);
	}
	else if ("menu_lastwatch_search_channel" == menuId)
	{
		MY_DEBUG("xml_menu::Chctrl_lastwatch_search_channel_Menu_handler");

		item_playing = document.getElementById("menu_last_search_play");
		item_stop = document.getElementById("menu_last_search_stop");
		item_download = document.getElementById("menu_last_search_download");
		item_copylink = document.getElementById("menu_last_search_copy_link");
		item_addfav = document.getElementById("menu_last_search_addto_fav");

		if (!item_playing || !item_stop || !item_copylink || !item_addfav || !item_download)
		{
			MY_DEBUG("xml_menu::one item not exists.");
			return;
		}
		
		if (window.MenuSelnum)
		{
			DisableItem(item_playing, false);
			DisableItem(item_stop, false);
			DisableItem(item_copylink, false);
			DisableItem(item_addfav, false);

			if (window.MenuHjType)
			{
				DisableItem(item_download, true);
			}
			else
				DisableItem(item_download, false);
		}
		else
		{
			DisableItem(item_playing, true);
			DisableItem(item_download, true);
			DisableItem(item_copylink, true);
			DisableItem(item_addfav, true);
		}

		if (window.MenuPlaying)
		{
			DisableItem(item_stop, false);
		}
		else
		{
			DisableItem(item_stop, true);
		}
	}
	else
	{
		//no such menu.
	}
}

function OnExpand()	//expand item.
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		if (window.MenuExpanded)
			chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 1);
		else
			chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 0);
	}
}

function OnPlayItem()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 2);
	}
}

function OnStopItem()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 3);
	}
}

function OnDownloadItem()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 4);
	}
}

function OnCopyPlayLink()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 5);
	}
}

function OnRefreshChannel()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 6);
	}
}

function OnAddToFav()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 7);
	}
}

function OnAllCollapse()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 8);
	}
}

function OnAutoCollapse()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 9);
	}
}

function OnDeleteSel()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 10);
	}
}

function OnDeleteAll()
{
	var chlist = Components.GetObject2("webchannel");
	if (chlist)
	{
		chlist.OnMenuCommandHandler(window.MenuWndType, window.MenuType, 11);
	}
}

//downloadwnd version2.7 menu.
function OnDownlaodWndMenu(wndType, menuType, xPos, yPos, vbAllRemoved)
{
	var menuPopup = null;

	if (1 == wndType)
	{
		switch (menuType)
		{
		case 0:
			menuPopup = document.getElementById("menu_downloading_single");
			break;
		case 1:
			menuPopup = document.getElementById("menu_downloading_multi");
			break;
		case 2:
			menuPopup = document.getElementById("menu_downloading_all");
			break;
		default:
			break;
		}
	}
	else if (2 == wndType)
	{
		switch (menuType)
		{
		case 0:
			menuPopup = document.getElementById("menu_finish_single");
			break;
		case 1:
			menuPopup = document.getElementById("menu_finish_multi");
			break;
		case 2:
			menuPopup = document.getElementById("menu_finish_all");
			break;
		default:
			break;
		}

		window.MenubAllRemoved = vbAllRemoved;
	}


	window.MenuwndType = wndType;
	window.MenumenuType = menuType;
	if (menuPopup)
	{
		menuPopup.openPopupAtScreen(xPos, yPos);
	}
}

function buildDownloadSkinMenu(menupopup)
{
	var menuId = menupopup.id;
	if ("menu_downloading_single" == menuId)	//正在下载单个任务菜单
	{
		MY_DEBUG("xml_menu::Downloading_Single_Select_handler");
		DownloadingSingleSelectMenuPreShow();
	}
	else if ("menu_downloading_multi" == menuId)//正在下载多个任务菜单
	{
		MY_DEBUG("xml_menu::Downloading_Multi_Select_handler");
		DownloadingMultiSelectMenuPreShow();
	}
	else if ("menu_downloading_all" == menuId)//正在下载全部任务菜单
	{
		MY_DEBUG("xml_menu::Downloading_All_Select_handler");
		DownloadingAllSelectMenuPreShow();
	}
	else if ("menu_finish_single" == menuId)//已完成单个任务菜单
	{
		FinishSingleSelectPreShow();
	}
	else if ("menu_finish_multi" == menuId)//已完成多个任务菜单
	{
		FinishMultiSelectPreShow($("Download").bAllRemoved);
	}
	else if ("menu_finish_all" ==  menuId)//已完成全部任务菜单
	{
		FinishAllSelectPreShow(window.MenubAllRemoved);
	}
	else
	{
		//no such menu.
	}
}

function DownloadingSingleSelectMenuPreShow()
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	var task = downloadHost.CurrentSelectedTask(window.MenuwndType);//1:正在下载窗口

	if (task)
	{
		var lCurStep = task.curState;
		var beginDownloadItem = document.getElementById("menu_begin_download");
		var pauseDownloadItem = document.getElementById("menu_pause_download");
		if (!beginDownloadItem || !pauseDownloadItem)
		{
			return;
		}
		
		beginDownloadItem.disabled = false;
		pauseDownloadItem.disabled = false;
		if (4==lCurStep || 5==lCurStep || 6==lCurStep || 10==lCurStep)
			beginDownloadItem.disabled = true;
		else if (7==lCurStep || 8==lCurStep)
			pauseDownloadItem.disabled = true;
	}

	var beginAllItem = document.getElementById("menu_begin_all_inSingle_download");
	var pauseAllItem = document.getElementById("menu_pause_al_inSingle_download");
	if (!beginAllItem || !pauseAllItem)
	{
		return;
	}

	var iDownloading = downloadHost.GetAllDownloadingInfo(0);//得到正在下载的数目
	var iPause = downloadHost.GetAllDownloadingInfo(1);//暂停的数目
	var iWait = downloadHost.GetAllDownloadingInfo(2);//等待的数目
	var iFail = downloadHost.GetAllDownloadingInfo(3);//失败的数目
	downloadHost.EndGetAllDownloadingInfo();//取消AllDownloadingInfo的缓存,在获取到所有你需要的DownloadingInfo之后该接口函数必须被调用

	MY_DEBUG('xml_menu::downloading '+iDownloading);
	MY_DEBUG('xml_menu::pause '+iPause);
	MY_DEBUG('xml_menu::wait '+iWait);
	MY_DEBUG('xml_menu::fail '+iFail);
	if (iDownloading+iWait <= 0)
		pauseAllItem.disabled = true;
	else
		pauseAllItem.disabled = false;

	if (iPause+iFail <= 0)
		beginAllItem.disabled = true;
	else
		beginAllItem.disabled = false;
}

function DownloadingMultiSelectMenuPreShow()
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	var beginMultiItem = document.getElementById("menu_begin_multi_download");
	var pauseMultiItem = document.getElementById("menu_pause_multi_download");
	if (!beginMultiItem || !pauseMultiItem)
	{
		return;
	}

	var iMultiDownloading = downloadHost.GetMultiSelectDownloadingInfo(0);//得到正在下载的数目
	var iMultiPause = downloadHost.GetMultiSelectDownloadingInfo(1);//暂停的数目
	var iMultiWait = downloadHost.GetMultiSelectDownloadingInfo(2);//等待的数目
	var iMultiFail = downloadHost.GetMultiSelectDownloadingInfo(3);//失败的数目
	downloadHost.EndGetMultiSelectDownloadingInfo();//取消MultiDownloadingInfo的缓存,在获取到所有你需要的DownloadingInfo之后该接口函数必须被调用
	
	MY_DEBUG('xml_menu::multidownloading '+iMultiDownloading);
	MY_DEBUG('xml_menu::multipause '+iMultiPause);
	MY_DEBUG('xml_menu::multiwait '+iMultiWait);
	MY_DEBUG('xml_menu::multifail '+iMultiFail);

	if (iMultiDownloading+iMultiWait <= 0)
		pauseMultiItem.disabled = true;
	else
		pauseMultiItem.disabled = false;

	if (iMultiPause+iMultiFail <= 0)
		beginMultiItem.disabled = true;
	else
		beginMultiItem.disabled = false;
}

function DownloadingAllSelectMenuPreShow()
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	var beginAllItem = document.getElementById("menu_begin_all_download");
	var pauseAllItem = document.getElementById("menu_pause_all_download");
	var deleteAllTask = document.getElementById("menu_delete_all_task_download");
	var deleteAllTaskFile = document.getElementById("menu_delete_all_task_file_download");
	if (!beginAllItem || !pauseAllItem || !deleteAllTask || !deleteAllTaskFile)
	{
		return;
	}

	var iAllDownloading = downloadHost.GetAllDownloadingInfo(0);//得到正在下载的数目
	var iAllPause = downloadHost.GetAllDownloadingInfo(1);//暂停的数目
	var iAllWait = downloadHost.GetAllDownloadingInfo(2);//等待的数目
	var iAllFail = downloadHost.GetAllDownloadingInfo(3);//失败的数目
	downloadHost.EndGetAllDownloadingInfo();//取消AllDownloadingInfo的缓存,在获取到所有你需要的DownloadingInfo之后该接口函数必须被调用
	
	MY_DEBUG('xml_menu::downloading '+iAllDownloading);
	MY_DEBUG('xml_menu::pause '+iAllPause);
	MY_DEBUG('xml_menu::wait '+iAllWait);
	MY_DEBUG('xml_menu::fail '+iAllFail);

	if (iAllDownloading+iAllWait <= 0)
		pauseAllItem.disabled = true;
	else
		pauseAllItem.disabled = false;

	if (iAllPause+iAllFail <= 0)
		beginAllItem.disabled = true;
	else
		beginAllItem.disabled = false;

	if (iAllDownloading+iAllPause+iAllWait+iAllFail <= 0)
	{
		deleteAllTask.disabled = true;
		deleteAllTaskFile.disabled = true;
	}
	else
	{
		deleteAllTask.disabled = false;
		deleteAllTask.disabled = false;
	}
}

function FinishSingleSelectPreShow()
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	var openFileItem = document.getElementById("menu_open_file_finish");
	var deleteTaskFileItem = document.getElementById("menu_delete_task_file_finish");
	var moveFileToItem = document.getElementById("menu_move_file_finish");
	if (!openFileItem || !deleteTaskFileItem || !moveFileToItem)
	{
		return;
	}

	var task = downloadHost.CurrentSelectedTask(window.MenuwndType);//2:已完成窗口
	if (task)
	{
		var filePath = task.savePath;
		if (filePath)
		{
			var bPathValidate = downloadHost.CheckFileValidate(filePath);
			if (!bPathValidate)
			{
				openFileItem.disabled = true;
				deleteTaskFileItem.disabled = true;
				moveFileToItem.disabled = true;
			}
			else
			{
				openFileItem.disabled = false;
				deleteTaskFileItem.disabled = false;
				moveFileToItem.disabled = false;
			}
		}
		else
		{
				openFileItem.disabled = true;
				deleteTaskFileItem.disabled = true;
				moveFileToItem.disabled = true;
		}
	}
}

function FinishMultiSelectPreShow(bAllRemoved)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	var deleteMultiTaskFile = document.getElementById("menu_delete_multi_task_file_finish");
	if (!deleteMultiTaskFile)
	{
		return;
	}

	if (bAllRemoved)
		deleteMultiTaskFile.disabled = true;
	else
		deleteMultiTaskFile.disabled = false;
}

function FinishAllSelectPreShow(bAllRemoved)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	var items = downloadHost.GetTaskCounts(window.MenuwndType);

	var deleteAllTaskFile = document.getElementById("menu_delete_all_task_file_finish");
	var deleteAllTask = document.getElementById("menu_delete_all_task_finish");
	if (!deleteAllTaskFile || !deleteAllTask)
	{
		return;
	}

	if (bAllRemoved)
		deleteAllTaskFile.disabled = true;
	else
		deleteAllTaskFile.disabled = false;

	if (items > 0)
		deleteAllTask.disabled = false;
	else
		deleteAllTask.disabled = true;
}

function DownloadingSingleSelectCmd(id)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	downloadHost.OnCommandHandler(window.MenuwndType, id);
}

function DownloadingMultiSelectPreCmd(id)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	downloadHost.OnCommandHandler(window.MenuwndType, 20+id);
}

function DownloadingAllSelectCmd(id)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	downloadHost.OnCommandHandler(window.MenuwndType, 40+id);
}

function FinishSingleSelectCmd(id)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	downloadHost.OnCommandHandler(window.MenuwndType, id);
}

function FinishMultiSelectCmd(id)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	downloadHost.OnCommandHandler(window.MenuwndType, 20+id);
}

function FinishAllSelectCmd(id)
{
	var downloadHost = Components.GetObject("@pplive.com/chdownloadwnd_3;1");
	if (!downloadHost)
	{
		return;
	}

	downloadHost.OnCommandHandler(window.MenuwndType, 40+id);
}

//=========================AddSupport_Favorite begin add by lxb=================================
function AddSupport_Favorite()
{
	//收藏夹同步事件（通知WEB)
	window.vecFavoriteEvent = {}
	window.onFavoriteEvent = function(statusCode, errCode)
	{
		for (var keyname in window.vecFavoriteEvent)
		{
			try
			{
				window.vecFavoriteEvent[keyname](statusCode, errCode);	
			}
			catch(e)
			{
			}
		}
	}
}
//=========================AddSupport_Favorite end add by lxb=================================
//end add by gjj.
//end add by gjj.
//=========================AddSupport_Hoverinfo begin add by lxb=================================

// SIG // Begin signature block
// SIG // MIIVVgYJKoZIhvcNAQcCoIIVRzCCFUMCAQExCzAJBgUr
// SIG // DgMCGgUAMGcGCisGAQQBgjcCAQSgWTBXMDIGCisGAQQB
// SIG // gjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIBAAIB
// SIG // AAIBAAIBAAIBADAhMAkGBSsOAwIaBQAEFONyD60p02S1
// SIG // PTHVw7yWk31yIN2FoIIRWzCCA3owggJioAMCAQICEDgl
// SIG // 1/r4Ya+e9JDnJrXWWtUwDQYJKoZIhvcNAQEFBQAwUzEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMSswKQYDVQQDEyJWZXJpU2lnbiBUaW1lIFN0YW1w
// SIG // aW5nIFNlcnZpY2VzIENBMB4XDTA3MDYxNTAwMDAwMFoX
// SIG // DTEyMDYxNDIzNTk1OVowXDELMAkGA1UEBhMCVVMxFzAV
// SIG // BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQDEytW
// SIG // ZXJpU2lnbiBUaW1lIFN0YW1waW5nIFNlcnZpY2VzIFNp
// SIG // Z25lciAtIEcyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
// SIG // iQKBgQDEtfJSFbyIhmApFkpbL0uRa4eR8zVUWDXq0TZe
// SIG // Yk1SUTRxwntmHYnI3SrEagr2N9mYdJH2kq6wtXaW8alK
// SIG // Y0VHLmsLkk5LK4zuWEqL1AfkGiz4gqpY2c1C8y3Add6N
// SIG // q8eOHZpsTAiVHt7b72fhcsJJwp5gPOHivhajY3hpFHut
// SIG // LQIDAQABo4HEMIHBMDQGCCsGAQUFBwEBBCgwJjAkBggr
// SIG // BgEFBQcwAYYYaHR0cDovL29jc3AudmVyaXNpZ24uY29t
// SIG // MAwGA1UdEwEB/wQCMAAwMwYDVR0fBCwwKjAooCagJIYi
// SIG // aHR0cDovL2NybC52ZXJpc2lnbi5jb20vdHNzLWNhLmNy
// SIG // bDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDCDAOBgNVHQ8B
// SIG // Af8EBAMCBsAwHgYDVR0RBBcwFaQTMBExDzANBgNVBAMT
// SIG // BlRTQTEtMjANBgkqhkiG9w0BAQUFAAOCAQEAUMVLyCSA
// SIG // 3+QNJMLeGrGhAqGmgi0MgxWBNwqCDiywWhdhtdgF/ojb
// SIG // 8ZGRs1YaQKbrkr44ObB1NnQ6mE/kN7qZicqVQh2wuceg
// SIG // jVfg+tVkBEI1TgHRM6IXyE2qJ8fy4YZMAjhNg3jG/FPg
// SIG // 6+AGh92klp5eDJjipb6/goXDYOHfrSjYx6VLZNrHG1u9
// SIG // rDkI1TgioTOLL4qa67wHIT9EQQkHtWUcJLxI00SA66HP
// SIG // yQK0FM9UxxajgFz5eT5dcn2IF54sQ6LKU859PfYqOrhP
// SIG // lAClbQqDXfleU/QYs1cPcMP79a2VoA4X3sQWgGDJDytu
// SIG // hgTx6/R4J9EFxe40W165STLyMzCCA8QwggMtoAMCAQIC
// SIG // EEe/GZXfjVJGQ/fbbUgNMaQwDQYJKoZIhvcNAQEFBQAw
// SIG // gYsxCzAJBgNVBAYTAlpBMRUwEwYDVQQIEwxXZXN0ZXJu
// SIG // IENhcGUxFDASBgNVBAcTC0R1cmJhbnZpbGxlMQ8wDQYD
// SIG // VQQKEwZUaGF3dGUxHTAbBgNVBAsTFFRoYXd0ZSBDZXJ0
// SIG // aWZpY2F0aW9uMR8wHQYDVQQDExZUaGF3dGUgVGltZXN0
// SIG // YW1waW5nIENBMB4XDTAzMTIwNDAwMDAwMFoXDTEzMTIw
// SIG // MzIzNTk1OVowUzELMAkGA1UEBhMCVVMxFzAVBgNVBAoT
// SIG // DlZlcmlTaWduLCBJbmMuMSswKQYDVQQDEyJWZXJpU2ln
// SIG // biBUaW1lIFN0YW1waW5nIFNlcnZpY2VzIENBMIIBIjAN
// SIG // BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqcqypMzN
// SIG // IK8KfYmsh3XwtE7x38EPv2dhvaNkHNq7+cozq4QwiVh+
// SIG // jNtr3TaeD7/R7Hjyd6Z+bzy/k68Numj0bJTKvVItq0g9
// SIG // 9bbVXV8bAp/6L2sepPejmqYayALhf0xS4w5g7EAcfrkN
// SIG // 3j/HtN+HvV96ajEuA5mBE6hHIM4xcw1XLc14NDOVEpkS
// SIG // ud5oL6rm48KKjCrDiyGHZr2DWFdvdb88qiaHXcoQFTyf
// SIG // hOpUwQpuxP7FSt25BxGXInzbPifRHnjsnzHJ8eYiGdvE
// SIG // s0dDmhpfoB6Q5F717nzxfatiAY/1TQve0CJWqJXNroh2
// SIG // ru66DfPkTdmg+2igrhQ7s4fBuwIDAQABo4HbMIHYMDQG
// SIG // CCsGAQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDov
// SIG // L29jc3AudmVyaXNpZ24uY29tMBIGA1UdEwEB/wQIMAYB
// SIG // Af8CAQAwQQYDVR0fBDowODA2oDSgMoYwaHR0cDovL2Ny
// SIG // bC52ZXJpc2lnbi5jb20vVGhhd3RlVGltZXN0YW1waW5n
// SIG // Q0EuY3JsMBMGA1UdJQQMMAoGCCsGAQUFBwMIMA4GA1Ud
// SIG // DwEB/wQEAwIBBjAkBgNVHREEHTAbpBkwFzEVMBMGA1UE
// SIG // AxMMVFNBMjA0OC0xLTUzMA0GCSqGSIb3DQEBBQUAA4GB
// SIG // AEpr+epYwkQcMYl5mSuWv4KsAdYcTM2wilhu3wgpo17I
// SIG // ypMT5wRSDe9HJy8AOLDkyZNOmtQiYhX3PzchT3AxgPGL
// SIG // OIez6OiXAP7PVZZOJNKpJ056rrdhQfMqzufJ2V7duyuF
// SIG // PrWdtdnhV/++tMV+9c8MnvCX/ivTO1IbGzgn9z9KMIIE
// SIG // /DCCBGWgAwIBAgIQZVIm4bIuGOFZDymFrCLnXDANBgkq
// SIG // hkiG9w0BAQUFADBfMQswCQYDVQQGEwJVUzEXMBUGA1UE
// SIG // ChMOVmVyaVNpZ24sIEluYy4xNzA1BgNVBAsTLkNsYXNz
// SIG // IDMgUHVibGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBB
// SIG // dXRob3JpdHkwHhcNMDkwNTIxMDAwMDAwWhcNMTkwNTIw
// SIG // MjM1OTU5WjCBtjELMAkGA1UEBhMCVVMxFzAVBgNVBAoT
// SIG // DlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2ln
// SIG // biBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJtcyBv
// SIG // ZiB1c2UgYXQgaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
// SIG // L3JwYSAoYykwOTEwMC4GA1UEAxMnVmVyaVNpZ24gQ2xh
// SIG // c3MgMyBDb2RlIFNpZ25pbmcgMjAwOS0yIENBMIIBIjAN
// SIG // BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvmcdtGCq
// SIG // EElvVhd8Zslehg3V8ayncYOOi4n4iASJFQa6LYQhleTR
// SIG // nFBM+9IivdrysjU7Ho/DCfv8Ey5av4l8PTslHvbzWHuc
// SIG // 9AG1xgq4gM6+J3RhZydNauXsgWFYeaPgFxASFSew4U00
// SIG // fytHIES53mYkZorNT7ofxTjIVJDhcvYZZnVquUlozzh5
// SIG // DaowqNssYEie16oUAamD1ziRMDkTlgM6fEBUtq3gLxuD
// SIG // 3KgRUj4Cs9cr/SG2p1yjDwupphBQDjQuTafOyV4l1Iy8
// SIG // 8258KbwBXfwxh1rVjIVnWIgZoL818OoroyHnkPaD5ajt
// SIG // YHhee2CD/VcLXUENY1Rg1kMh7wIDAQABo4IB2zCCAdcw
// SIG // EgYDVR0TAQH/BAgwBgEB/wIBADBwBgNVHSAEaTBnMGUG
// SIG // C2CGSAGG+EUBBxcDMFYwKAYIKwYBBQUHAgEWHGh0dHBz
// SIG // Oi8vd3d3LnZlcmlzaWduLmNvbS9jcHMwKgYIKwYBBQUH
// SIG // AgIwHhocaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3Jw
// SIG // YTAOBgNVHQ8BAf8EBAMCAQYwbQYIKwYBBQUHAQwEYTBf
// SIG // oV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAHBgUrDgMC
// SIG // GgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDov
// SIG // L2xvZ28udmVyaXNpZ24uY29tL3ZzbG9nby5naWYwHQYD
// SIG // VR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMDMDQGCCsG
// SIG // AQUFBwEBBCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29j
// SIG // c3AudmVyaXNpZ24uY29tMDEGA1UdHwQqMCgwJqAkoCKG
// SIG // IGh0dHA6Ly9jcmwudmVyaXNpZ24uY29tL3BjYTMuY3Js
// SIG // MCkGA1UdEQQiMCCkHjAcMRowGAYDVQQDExFDbGFzczND
// SIG // QTIwNDgtMS01NTAdBgNVHQ4EFgQUl9BrqCZwyKE/lB8I
// SIG // LcQ1m6ShHvIwDQYJKoZIhvcNAQEFBQADgYEAiwPA3ZTY
// SIG // QaJhabAVqHjHMMaQPH5C9yS25INzFwR/BBCcoeL6gS/r
// SIG // wMpE53LgULZVECCDbpaS5JpRarQ3MdylLeuMAMcdT+dN
// SIG // MrqF+E6++mdVZfBqvnrKZDgaEBB4RXYx84Z6Aw9gwrNd
// SIG // nfaLZnaCG1nhg+W9SaU4VuXeQXcOWA8wggURMIID+aAD
// SIG // AgECAhBtUn9NfWwaK6fvgdUMiddlMA0GCSqGSIb3DQEB
// SIG // BQUAMIG2MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVy
// SIG // aVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRy
// SIG // dXN0IE5ldHdvcmsxOzA5BgNVBAsTMlRlcm1zIG9mIHVz
// SIG // ZSBhdCBodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBh
// SIG // IChjKTA5MTAwLgYDVQQDEydWZXJpU2lnbiBDbGFzcyAz
// SIG // IENvZGUgU2lnbmluZyAyMDA5LTIgQ0EwHhcNMDkxMTE5
// SIG // MDAwMDAwWhcNMTIxMTE4MjM1OTU5WjCBzjELMAkGA1UE
// SIG // BhMCQ04xETAPBgNVBAgTCFNoYW5naGFpMREwDwYDVQQH
// SIG // EwhTaGFuZ2hhaTEbMBkGA1UEChQSUFBMaXZlIENvcnBv
// SIG // cmF0aW9uMT4wPAYDVQQLEzVEaWdpdGFsIElEIENsYXNz
// SIG // IDMgLSBNaWNyb3NvZnQgU29mdHdhcmUgVmFsaWRhdGlv
// SIG // biB2MjEfMB0GA1UECxQWUHJvZHVjdCBQbGFubmluZyBE
// SIG // ZXB0LjEbMBkGA1UEAxQSUFBMaXZlIENvcnBvcmF0aW9u
// SIG // MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDY7Kff
// SIG // TNpvjGy6zGck0u1/S+B50zuxRF0HrIlPfcpSGmsQyfzm
// SIG // b2eigTz0KuN+palZSdpx0amg9gD+ANFSNo9uqfk1PLeP
// SIG // V7187RIh4taAGUnYROqkPr9kVAsU/SepgjYLVAU46+Bu
// SIG // FtDmCaenpb6rqE+0Y6AV50Rc3iBA0rHvawIDAQABo4IB
// SIG // gzCCAX8wCQYDVR0TBAIwADAOBgNVHQ8BAf8EBAMCB4Aw
// SIG // RAYDVR0fBD0wOzA5oDegNYYzaHR0cDovL2NzYzMtMjAw
// SIG // OS0yLWNybC52ZXJpc2lnbi5jb20vQ1NDMy0yMDA5LTIu
// SIG // Y3JsMEQGA1UdIAQ9MDswOQYLYIZIAYb4RQEHFwMwKjAo
// SIG // BggrBgEFBQcCARYcaHR0cHM6Ly93d3cudmVyaXNpZ24u
// SIG // Y29tL3JwYTATBgNVHSUEDDAKBggrBgEFBQcDAzB1Bggr
// SIG // BgEFBQcBAQRpMGcwJAYIKwYBBQUHMAGGGGh0dHA6Ly9v
// SIG // Y3NwLnZlcmlzaWduLmNvbTA/BggrBgEFBQcwAoYzaHR0
// SIG // cDovL2NzYzMtMjAwOS0yLWFpYS52ZXJpc2lnbi5jb20v
// SIG // Q1NDMy0yMDA5LTIuY2VyMB8GA1UdIwQYMBaAFJfQa6gm
// SIG // cMihP5QfCC3ENZukoR7yMBEGCWCGSAGG+EIBAQQEAwIE
// SIG // EDAWBgorBgEEAYI3AgEbBAgwBgEBAAEB/zANBgkqhkiG
// SIG // 9w0BAQUFAAOCAQEAEHyS6zHfeAr7VXV0+4exGGIaodyt
// SIG // snOwewImElZdtDXV0P9r4B6gp1Ej1ZT8Ddco099Xc7NE
// SIG // e7gyfzCQh27Uq6DSVQP0P9zBI2VgwWaOLweplMHFqKrD
// SIG // q0DXzRAsXiYCu15ugktqWBRVhsOCrNFPcYAiEHhMeRJY
// SIG // 1p5pA+TyXSs2X5AyL1zfpaqrDfJKmhspWabkMbjyLWG9
// SIG // jkQv7K4rviPg//9QfzZoYG3cJBMDqLC3KsSFXs6GNzXo
// SIG // 7EDYhzgJFjpalJUV0n7TL+aPFgRY6/lG3UYPZtsRtGBI
// SIG // W2frpPZy0ww0vcTMzXYL+2TGyka40qCWF3XUw14+znhe
// SIG // yMNA5TGCA2cwggNjAgEBMIHLMIG2MQswCQYDVQQGEwJV
// SIG // UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNV
// SIG // BAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsxOzA5BgNV
// SIG // BAsTMlRlcm1zIG9mIHVzZSBhdCBodHRwczovL3d3dy52
// SIG // ZXJpc2lnbi5jb20vcnBhIChjKTA5MTAwLgYDVQQDEydW
// SIG // ZXJpU2lnbiBDbGFzcyAzIENvZGUgU2lnbmluZyAyMDA5
// SIG // LTIgQ0ECEG1Sf019bBorp++B1QyJ12UwCQYFKw4DAhoF
// SIG // AKBwMBAGCisGAQQBgjcCAQwxAjAAMBkGCSqGSIb3DQEJ
// SIG // AzEMBgorBgEEAYI3AgEEMBwGCisGAQQBgjcCAQsxDjAM
// SIG // BgorBgEEAYI3AgEVMCMGCSqGSIb3DQEJBDEWBBQ5bRgM
// SIG // baZcNscLIW1ddDqJp0uQADANBgkqhkiG9w0BAQEFAASB
// SIG // gE8+REOvT20YKWuOimOag3aq6Pv7xMFXBP4M0bcrRW0D
// SIG // OF9rGBJzJE23TSXnD3NHLEZVS6ZOpbSNq01XYWgPOg6d
// SIG // 6qJWdB+Mc1xyU25fp6neCwyiUC7C8XoKfWGmbIkINKFv
// SIG // 1NltmSdORLrgvDys38N8y4SILVUH5MlhC0V/+Nl1oYIB
// SIG // fzCCAXsGCSqGSIb3DQEJBjGCAWwwggFoAgEBMGcwUzEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMSswKQYDVQQDEyJWZXJpU2lnbiBUaW1lIFN0YW1w
// SIG // aW5nIFNlcnZpY2VzIENBAhA4Jdf6+GGvnvSQ5ya11lrV
// SIG // MAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZI
// SIG // hvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xMTA3MjMwOTEw
// SIG // MDNaMCMGCSqGSIb3DQEJBDEWBBRR4gAEi9osY3Gb9uF8
// SIG // XNu4k/WY6zANBgkqhkiG9w0BAQEFAASBgJ8DIp80jvv2
// SIG // 671jUvsFNu8DZhvcQ7tj+qZZUssRqiAU9vwc3KbAjyFC
// SIG // 25YB0dqZeQxQCEa7qboKlpEtONCN/MQ8rk43Ym3UCF+3
// SIG // 0aQCbpaaF6gEqZFlts09/eqcyPn2iOttD2Q4Gh+qGkvZ
// SIG // ZaLYxHdfH8LzcAQBOGJK2Sqxm7vb
// SIG // End signature block
