// 进入迷你模式时,完整模式的位置和大小
var WindowLeft=0;
var WindowTop=0;
var WindowWidth=0;
var WindowHeight=0;

// 进入迷你模式时,设置的迷你模式的位置和大小
var miniLeft = 0;
var miniTop = 0;
var miniWidth = 0;
var miniHeight = 0;

var strMessage, strAction;
var bFirstEnterChoiceAfertChangeMode = false;
var vipPopupTimerID = 0;

function limitCoreConnectionChange()
{
	var limitConnection = false;
	if (arguments.length > 0)
	{
		limitConnection = arguments[0];
	}
	else if (window.sizemode == 1 || !window.visible)
	{
		limitConnection = false;
	}
	else if ($("tabbox").getSelected() != 1)
	{
		limitConnection = false;
	}
	else
	{
		limitConnection = true;
	}

	if (limitConnection && !$("Choice").limitCoreConnection)
	{
			limitCoreConnection(true); // 立即限速
			$("Choice").limitCoreConnection = true;
	}
	else if (!limitConnection && $("Choice").limitCoreConnection)
	{
			limitCoreConnection(false); // 取消限速
			$("Choice").limitCoreConnection = false;
	}
}

function delayCreateChoice()
{
	if ($("Choice").contractId.length > 0)
	{
		return;
	}

	$("Choice").setContractId("@pplive.com/WebBrowser;1", false);
	$("Choice").showSWFBuffer = true;
	$("Choice").showNavigateStatus = true;
	var channelURL = "http://list.client.pplive.cn/v3/index/" + getCityCode() + ".html";
	var myid = 0;
	if (bFirstEnterChoiceAfertChangeMode)
	{
		bFirstEnterChoiceAfertChangeMode = false;

		//设置选集页面为当前播放页
		var ppp = Components.GetObject2("PPP");
		if (ppp && ppp.ChannelID && window.hasChannelPlaying())
		{
			//如果归属到合集，则显示合集对应的页面
			myid = ppp.HjID?ppp.HjID:ppp.ChannelID;
			channelURL += "#" + myid ;
		}
		else
		{	//节目未播放，则回到用户上次停留的页面
			var locationURL = getLocationURLBeforeChangeMode();
			if (locationURL && locationURL.length)
			{
				if (locationURL.indexOf("errorPage.htm?error=offline")==-1) //非离线模式页面
				{
					channelURL = locationURL;
				}
			}
		}
	}
	var bOfflineMode = false;

	var ppFrame = Components.GetObject2("@pplive.com/PPFrame;1");
	if (ppFrame)
	{
		bOfflineMode=ppFrame.bOfflineMode;
		if (bOfflineMode)
		{
			$("Choice").SetUrl(ShowAbsolutePath("data\\local\\errorPage.htm?error=offline"), "data\\local\\errorPage.htm?error=offline");
		}
	}
	if (!bOfflineMode)
	{
		try
		{
			if(myid)window.tellChoiceChannelDetail(myid);
			else $("Choice").SetUrl(channelURL, "data\\local\\errorPage.htm?<%errorcode%>");
		}
		catch (e)
		{
			$("Choice").SetUrl(channelURL, "data\\local\\errorPage.htm?<%errorcode%>");
		}
	}
	$("Choice").showContextMenu = true;
}
// 保持窗口中心位置不变,改变窗口大小
function keepCenterAndResizeWindow(cx, cy)
{
	var centerX = window.screenLeft+window.outerWidth/2;
	var centerY = window.screenTop+window.outerHeight/2;
	var availPos = ConstrainPosition(window.screen, centerX-cx/2, centerY-cy/2, cx, cy);
	window.moveSizeTo(availPos.left, availPos.top, cx, cy);
}
function construct()
{
	$("tabbox").items = new Array("Player", "Choice");
	$("tabbox").getSelected = function()
	{
		for (var key in this.items)
		{
			var obj = $("tab" + this.items[key]);
			if (obj && obj.selected)
			{
				return key;
			}
		}
	}
	$("tabbox").setSelected = function(name)
	{
		var oldSelected = null;
		var oldName = "";
		for (var key in this.items)
		{
			var obj = $("tab" + this.items[key]);
			if (obj && obj.selected)
			{
				oldName = this.items[key];
				oldSelected = obj;
				break;
			}
		}
		var newSelected = $("tab" + name);
		if (!newSelected || oldSelected == newSelected)
		{
			return false;
		}
		if (oldSelected && oldSelected.willUnselected)
		{
			oldSelected.willUnselected(name);
		}
		if (newSelected.willSelected)
		{
			newSelected.willSelected(oldName);
		}
		if (oldSelected)
		{
			oldSelected.selected = false;
			oldSelected.checked = false;
		}
		newSelected.selected = true;
		newSelected.checked = true;
		if (newSelected.didSelected)
		{
			newSelected.didSelected(oldName);
			try{oldSelected.label.fontStyle="bold";}catch(e){}
		}
		else
		{
			$(name + "Container").visible = true;
			$(name).visible = true;
		}
		if (oldSelected && oldSelected.didUnselected)
		{
			oldSelected.didUnselected(name);
		}
		else if (oldSelected)
		{
			$(oldName + "Container").visible = false;
			$(oldName).visible = false;
			try{oldSelected.label.fontStyle="normal";}catch(e){}
		}
		limitCoreConnectionChange();
		return true;
	}
	// 播放   标签栏被选中
	$("tabPlayer").bFindChannelTip=true;
	$("tabPlayer").didSelected = function(oldname)
	{
		// 首先 退出 视频小窗
		exitMiniPlayer();
		$("accelset").disabled = false;
		$("accelsetPlayer").disabled = false;
		window.activated = true;
		$("menu_switchTinyMode").disabled=false;
		$("menu2_05x").disabled=false;
		$("menu2_10x").disabled=false;
		$("menu2_20x").disabled=false;
		$("menu_FullOrUnfull2").disabled=false;
		if($("tabPlayer").bFindChannelTip && oldname=="Choice" && !window.balloons.IsVisible("education\\New2ClassicTip.xml"))
		{
			var nFindChannelTip = 0;
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
			{	
				var nFindChannelTip = registry.readDWORD("FindChannelTip");
				if(nFindChannelTip<3)registry.writeDWORD("FindChannelTip",nFindChannelTip+1);	
			}
			if(nFindChannelTip<3) window.ShowFindChannelTipBalloon(true);
			$("tabPlayer").bFindChannelTip=false;
		}

		$("Player").CreatePlayer();
		$("PlayerContainer").visible = true;
		$("Player").visible = true;
		window.setMinWidthAndHeight(800, 400, true);
		if ($("tabPlayer").previousWidth && $("tabPlayer").previousHeight && window.sizemode == 0)
		{
			var ppp = Components.GetObject2("PPP");
			if (ppp && (ppp.State == 2 || ppp.State == 0 || ppp.State == 3))
			{
				keepCenterAndResizeWindow($("tabPlayer").previousWidth, $("tabPlayer").previousHeight);
			}
		}
	}
	$("tabPlayer").didUnselected = function(newname)
	{
		$("accelset").disabled = true;
		$("menu_switchTinyMode").disabled=true;
		$("menu2_05x").disabled=true;
		$("menu2_10x").disabled=true;
		$("menu2_20x").disabled=true;
		$("menu_FullOrUnfull2").disabled=true;
		$("PlayerContainer").visible = false;
		$("Player").visible = false;
		// 可能要进入 视频小窗
		enterMiniPlayerIfNeed();
	}
	$("tabPlayer").willUnselected = function(oldname)
	{
		if (window.sizemode == 0)
		{
			var ppp = Components.GetObject2("PPP");
			if (ppp && (ppp.State == 2 || ppp.State == 0 || ppp.State == 3))
			{
				$("tabPlayer").previousLeft = window.screenLeft;
				$("tabPlayer").previousTop = window.screenTop;
				$("tabPlayer").previousWidth = window.outerWidth;
				$("tabPlayer").previousHeight = window.outerHeight;
			}
		}
	}
	// 选节目 标签栏被选中
	$("tabChoice").didSelected = function(oldname)
	{
		if ($("Choice").contractId.length <= 0)
		{
			var timerId = window.setTimeout("delayCreateChoice();", 1);
		}
		$("ChoiceContainer").visible = true;
		$("Choice").visible = true;
		$("tabChoice").label.fontStyle="bold";
		if (oldname == "Player" && $("tabChoice").previousWidth && $("tabChoice").previousHeight && window.sizemode == 0)
		{
			window.setMinWidthAndHeight(981, 456, false);
			keepCenterAndResizeWindow($("tabChoice").previousWidth, $("tabChoice").previousHeight);
		}
		else
		{
			window.setMinWidthAndHeight(981, 456, true);
		}
	}
	function otherTabWillUnselected(newname)
	{
		if (window.sizemode == 0 && newname == "Player")
		{
			$("tabChoice").previousLeft = window.screenLeft;
			$("tabChoice").previousTop = window.screenTop;
			$("tabChoice").previousWidth = window.outerWidth;
			$("tabChoice").previousHeight = window.outerHeight;
		}
	}
	$("tabChoice").willUnselected = otherTabWillUnselected;
}

function deconstruct()
{
}

function PPLState(i)
{
	var PPLState = Components.GetObject2('@pplive.com/PPLStat;1');
	if(PPLState)PPLState.PPTVStartTime(i);
}
function PPLTabState(name)
{
	var PPLState = Components.GetObject2('@pplive.com/PPLStat;1');
	if(PPLState)PPLState.PPTVClientTabClick(name);
}
function checkPictureMenu()
{

	$("menu_autoadjust").checked=false;
	$("menu_fitwindow").checked=false;
	$("menu_half").checked=false;
	$("menu_normal").checked=false;
	$("menu_double").checked=false;
	var ospp = GetOriginalSizePlayPolicy();
	switch (ospp)
	{
	case 1:
		$("menu_autoadjust").checked=true;
		break;
	case 2:
		$("menu_half").checked=true;
		break;
	case 3:
		$("menu_fitwindow").checked=true;
		break;
	case 4:
		$("menu_normal").checked=true;
		break;
	case 5:
		$("menu_double").checked=true;
		break;
	}
	if (window.videoScan.defaultSize==4)// 铺满窗口
	{
		$("menu_defaultrate").checked=false;
		$("menu_rate43").checked=false;
		$("menu_rate169").checked=false;
		$("menu_fill").checked=true;
		return;
	}
	$("menu_fill").checked=false;
	var varVideoScan = window.videoScan;
	if(varVideoScan)
	{
		$("menu_defaultrate").checked=false;
		$("menu_rate43").checked=false;
		$("menu_rate169").checked=false;
		if(varVideoScan.aspectRatioWidth == 0 && varVideoScan.aspectRatioHeight == 0)
		{
			$("menu_defaultrate").checked=true;
		}
		if(varVideoScan.aspectRatioWidth == 4 && varVideoScan.aspectRatioHeight == 3)
		{
			$("menu_rate43").checked=true;
		}
		if(varVideoScan.aspectRatioWidth == 16 && varVideoScan.aspectRatioHeight == 9)
		{
			$("menu_rate169").checked=true;
		}
	}
}
function commandVideoSizePolicy(policy)
{
	if (window.videoScan.defaultSize==4)
	{// 恢复默认比例
		window.videoScan.aspectRatioWidth=0;
		window.videoScan.aspectRatioHeight=0;
	}
	if(policy == 2 || policy == 4 || policy == 5)
	{
		SetOriginalSizePlayPolicy(policy);
		return;
	}
	SetOriginalSizePlayPolicy(policy);
	var osd="";
	var tjcode=0;
	switch(policy)
	{
	case 1: osd="自动调整视频尺寸"; tjcode=39; break;
	case 3: osd="适应窗口尺寸";     tjcode=41; break;
	}
	var mainFrame = Components.GetObject2('mframe');
	if(mainFrame)
		mainFrame.TipControl.ShowTipText(osd, 0xCCCCCC, 3);
	PPLState(tjcode);
}
function commandVideoAspect(ax,ay)
{
	window.videoScan.preventUpdate = true;
	if (window.videoScan.defaultSize==4) {
		SetOriginalSizePlayPolicy();
	}
	window.videoScan.aspectRatioWidth=ax;
	window.videoScan.aspectRatioHeight=ay;
	window.videoScan.preventUpdate = false;
	window.videoScan.update();
	window.ShowResizeTip(0.0);
}
function commandVideoFillWindow()
{
	if(window.videoScan.defaultSize==4) {
		window.videoScan.preventUpdate = true;
		var ax = window.videoScan.aspectRatioWidth;
		var ay = window.videoScan.aspectRatioHeight;
		SetOriginalSizePlayPolicy();
		window.videoScan.aspectRatioWidth=ax;
		window.videoScan.aspectRatioHeight=ay;
		window.videoScan.preventUpdate = false;
		window.videoScan.update();
	} else {
		AspectChange(-1,-1);
	}
}

function checkMainMenu()
{
	//初始化菜单状态 声音 相关
	$("menu_leftTrack2").checked=false;
	$("menu_rightTrack2").checked=false;
	$("menu_stereo2").checked=false;
	
	var ppp = Components.GetObject2("PPP");
	if(ppp)
	{
		var nTrack = ppp.Track;
		if(nTrack ==0)
		{
			$("menu_stereo2").checked=true;			
		}
		else if(nTrack ==100)
		{
			$("menu_rightTrack2").checked=true;
		}
		else
		{
			$("menu_leftTrack2").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;
		var disableDownload = ppp.DisableDownload;
		if(fileType==5 && !disableDownload )
		{
			$("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)
		{
			var EWA = Components.GetObject2("EWA");
			if (EWA)
			{
				if (EWA.Mute)
				{
					volumeMute.label = "取消静音";
				}
				else
				{
					volumeMute.label = "静音";
				}
			}
		}
	}	
	if(!ppplayer)
	{
		var ppplayer = Components.GetObject2("PPPlayer");
	}
	if (ppplayer)
	{
		$("menu_film_info").disabled= ppplayer.bDisabledInfoBtn;
	}
}

function checkPlayControlMenu()
{
	if (!ppplayer)
	{
		var ppplayer = Components.GetObject2("PPPlayer");
	}
	if (ppplayer.bCanPrevious)
	{
		$("menu_playPrev").disabled = false;
	}
	else
	{
		$("menu_playPrev").disabled = true;
	}
	if (ppplayer.bCanNext)
	{
		$("menu_playNext").disabled = false;
	}
	else
	{
		$("menu_playNext").disabled = true;
	}
}
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 buildDefinitionMenu(menupopup)
{
	if (menupopup && menupopup.hasChildNodes)
	{
		var menu = menupopup.firstChild;
		while (menu)
		{
			var nextmenu = menu.nextSibling;
			menupopup.removeChild(menu);
			menu = nextmenu;
		}			
	}
	
	var ppplayer = Components.GetObject2("PPPlayer");
	if (ppplayer)
	{
		var linkid = ppplayer.linkid;
		var rt = ppplayer.rt;

		if ((rt & 0x0002) && linkid)   //蓝光频道关联普通高清频道
		{	
			var menuItem = document.createElement("<menuitem type='radio' checked='true' oncommand='OnSwitchVedio(2);' label='蓝光'>");
				menupopup.appendChild(menuItem);
			var menuItem = document.createElement("<menuitem type='radio' oncommand='OnSwitchVedio(1);' label='高清'>");
			menupopup.appendChild(menuItem);
		}
		else if ((rt & 0x004) && linkid)   //高清频道关联蓝光频道
		{
			var menuItem = document.createElement("<menuitem type='radio' checked='true' oncommand='OnSwitchVedio(1);' label='高清'>");
				menupopup.appendChild(menuItem);
			var menuItem = document.createElement("<menuitem type='radio' oncommand='OnSwitchVedio(2);' label='蓝光'>");
			menupopup.appendChild(menuItem);
		}
		else
		{	//根据 vtp 字段，来显示对应的频道类别
			var vtp = ppplayer.vtp;
			if (vtp == 0)
			{
				var menuItem = document.createElement("<menuitem type='radio' checked='true' oncommand='OnSwitchVedio(3);' label='标清'>");
				menupopup.appendChild(menuItem);
			}
			else if (vtp == 1)
			{
				var menuItem = document.createElement("<menuitem type='radio' checked='true' oncommand='OnSwitchVedio(1);' label='高清'>");
				menupopup.appendChild(menuItem);
			}
			else if (vtp == 2)
			{
				var menuItem = document.createElement("<menuitem type='radio' checked='true' oncommand='OnSwitchVedio(2);' label='蓝光'>");
				menupopup.appendChild(menuItem);
			}
		}
	}
}
function showVideoInfo()
{
	var mainWnd = Components.GetObject2("@pplive.com/ui/mainwindow;1");
	if (mainWnd)
	{
		mainWnd.infobtnfunc();
	}
}
function OnBright()
{
	if( EwaIsFullScreen() )
	{
		EwaFullOrUnfull();
	}
	window.showModalDialog('coloradjust.xml');

}
function OnSwitchVedio(n)
{
	if (!ppplayer)
	{
		var ppplayer = Components.GetObject2("PPPlayer");
	}
	
	if (ppplayer)
	{
		var rt = ppplayer.rt;
		var ppp = ppplayer.get_PPP();
		if (ppp)
		{
			if (n == 1)
			{
				if(rt & 0x0002)  //蓝光频道关联普通高清频道
				{
					ppp.BitrateSwitch(-1)=1;
					var registry = Components.CreateObject("@pplive.com/registry;1");
					if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
					{	
						var LowBitrateSwitch = registry.readDWORD("LowBitrateSwitch");
						registry.writeDWORD("LowBitrateSwitch",LowBitrateSwitch+1);
					}
					var ppplayercontrol = Components.GetObject2("PPPlayerControl");
					if (ppplayercontrol)
					{
						ppplayercontrol.OnDisabledShiftBtn(true);
					}
				}
			}
			else if (n == 2)
			{
				if(rt & 0x004)  //高清频道关联蓝光频道
				{
					ppp.BitrateSwitch(1)=1;
					var registry = Components.CreateObject("@pplive.com/registry;1");
					if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
					{	
						var HighBitrateSwitch = registry.readDWORD("HighBitrateSwitch");
						registry.writeDWORD("HighBitrateSwitch",HighBitrateSwitch+1);
					}
					var ppplayercontrol = Components.GetObject2("PPPlayerControl");
					if (ppplayercontrol)
					{
						ppplayercontrol.OnDisabledShiftBtn(true);
					}
				}
			}				
		}
	}
}
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 checkUnFullscreen()
{
	if (EwaIsFullScreen())
	{
		EwaUnFullScreen();
	}
}

function cmdlineHandler(aCmdLine)
{
	if (aCmdLine.state == 0)  // 启动 命令行
	{
		if (aCmdLine.findFlag("autorun") != -1)
		{
			$("tabbox").setSelected("Choice");
			return;
		}
		window.visible = true;
		try {Components.GetObject2("Loading").Destroy();} catch (e){}
	}
	else if (aCmdLine.state == 1) // 远程 命令行
	{
		window.activated = true;
		window.visible = true;
	}

	var selectedTab = "Choice";
	var url = aCmdLine.handleFlagWithParam("play");
	if (url.length > 0)
	{
		selectedTab = "Player";
		$("tabbox").setSelected("Player");
		pppPlayString(url,11);
	}

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

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

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

function windowOpenUrl()
{
	var url = window.showModalDialog("openurl.xml");
	if (url && url.length > 0)
	{
		pppPlayString(url,9);
	}
}
function windowOnActive(bActivated)
{
	if(!bActivated) return;
	var GallopStateInfo = Components.GetObject2("gallopStateInfo");
	if(GallopStateInfo)GallopStateInfo.ScrollNext();

	var Gallop = Components.GetObject2("gallopFrame");
	if(Gallop)Gallop.ScrollNext();
}
// 进入迷你模式
function enterTidyMode()
{
	if (window.tidyMode)
	{
		return false;
	}
	//记录进入mini模式之前的topmost
	window.IsTopMostEx = (window.GetTopMostEx()==0)?false:true;
	if(!window.IsTopMostEx)
	{
		window.SetTopMostEx(2);
		window.IsTopMostEx=false;
	}

	//没有选中播放TAB，禁止进入迷你模式。
	if ($("tabbox").getSelected() != 0)
	{
		return false;
	}
	
	try
	{
		window.ShowNew2ClassicTipBalloon(false);
		window.ShowFindChannelTipBalloon(false);
		window.CloseFirewallForbiddenBalloon();
		window.ShowFindDownloadMgrTipBalloon(false);
	}
	catch (e)
	{
	}


	//打开窗口边框吸附
	window.setAdsorb=true;

	EwaUnFullScreen();
	if (window.sizemode != 0)
	{
		window.sizemode = 0;
	}
	var mframe = Components.GetObject2("mframe");
	if(mframe) 
	{
		mframe.PortalControl("notify","portal","mini","1","","");
		mframe.StatusChange(0);
	}

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

    //设置精简窗口大小
	miniLeft=WindowLeft;
	miniTop=WindowTop+36;
	miniWidth=$("Player").width+6;
	miniHeight=$("Player").height+6-32;
	
	//如果视频正在播放，与视频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=700;
				miniHeight=426;
			}
			else if (GetDisplayRate(ppp.Oplayer.videoWidth,ppp.Oplayer.videoHeight,miniWidth-6,miniHeight-6)>=100)
			{
				miniWidth=ppp.Oplayer.videoWidth+4;
				miniHeight=ppp.Oplayer.videoHeight+4;
			}
			else
			{
				miniWidth=$("Player").width+6;
				miniHeight=$("Player").height+6-32;
			}
		}
	}
	else
	{
		miniWidth=700;
		miniHeight=426;
	}

	//读取注册表中值
	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;

	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+4;
	var curMiniHeight = $("Player").height+4;

	if(window.sizemode == IDOMWindow.SizeMode_Minimized)
	{
		return ;
	}

    //读取注册表
	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","","");
		mframe.StatusChange(0);
	}
	
	//调整主框架的最小大小
	if ($("tabbox").getSelected() == 0)
	{
		window.setMinWidthAndHeight(800, 400, false);
	}
	else
	{
		window.setMinWidthAndHeight(981, 456, false);
		if (window.innerWidth<981 || window.innerHeight<300)
		{	//如果小于最小大小，则调整到默认大小
			WindowLeft=window.screenLeft;
			WindowTop=window.screenTop;
			window.moveSizeTo(WindowLeft, WindowTop, 981, 635,0); //设置窗口大小
		}
	}

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

// 还原视频大小
	window.videoScan.zoom(window.beforeTidydefaultSize);
	//记录迷你模式位置
	recodeTidyModePosition();

    //还原窗口
	window.moveSizeTo(WindowLeft,WindowTop,WindowWidth, WindowHeight,0);

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

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

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

	window.unlock(7);

	try
	{
		$("Player").wrappedObject.ResizerCommand(4 , 0);
	}
	catch (e)
	{
	}
//	window.setMinWidthAndHeight(minWidth,minHeight,true);	

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

	return true;
}
function myClose()
{
	try
	{
		EwaUnFullScreen();
		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;
				EwaStop();
				return;
			}
			// 关闭
			window.close();
			return;
		}
		//去除最小化动画效果
		window.visible = false;
		EwaStop();
		return;
	}
	catch (e)
	{
		window.close();
	}
	window.close();
}
function windowOnClose() 
{
	if (window.tidyMode)
	{
		recodeTidyModePosition();
	}
	var closeMe = window.CheckDownloadTask();
	if(closeMe)window.ReleaseDownloadMgr();
	return closeMe;
}
function centerWindow()
{// 窗口居中，并且根据显示器分辨率调整窗口的大小
	if (window.sizemode != 0)
	{
		window.sizemode = 0;
	}
	var screen = window.screen;
	var wndWidth = 981;
	var wndHeight = 635;
	if (window.tidyMode)
	{
		wndWidth = 500;
		wndHeight = 330;
	}
	var left = screen.left + (screen.width - wndWidth)/2;
	var top = screen.top + (screen.height - wndHeight)/2;
	if (left < screen.availLeft)
	{
		left = screen.availLeft;
	}
	if (top < screen.availTop)
	{
		top = screen.availTop;
	}
	window.moveSizeTo(left, top, wndWidth, wndHeight);
}
function windowOnload()
{
	//初始化一些方法
	window.FFUnMuteId = 0;

	//第一次显示
	window.firstShow=true;
	//精简模式
	window.tidyMode = false;
	//进入精简模式
	window.enterTidyMode = enterTidyMode;
	//退出精简模式
	window.exitTidyMode = exitTidyMode;
	
	window.MiniClose = function()
	{
		myClose();
	}	

	window.DefaultSize = function()
	{
		checkUnFullscreen();
		centerWindow();
	}

	// 调整list的高度
	window.setSearchListPos = function(width, height)
	{
		$("searchlist").visible = true;
		$("searchlist").moveSizeTo($('mainframeright').left+$('combo_textboxsearch').left+5, $('mainframeright').top+$('combo_textboxsearch').top+$('combo_textboxsearch').height, $('combo_textboxsearch').width-10, height);
	}
	// 从list选中内容显示到edit
	window.setSearchEditInputChange = function(value)
	{
		// 先设置标记为false，再赋值value，顺序不能颠倒
		$("textboxsearch").isInputChange = false;
		$("textboxsearch").value = value;
		var aStart = $("textboxsearch").value.length;
		var aEnd = aStart;
		$("textboxsearch").setsel(aStart,aEnd);
	}
	// 跳转搜索结果,参考infobtnfunc
	window.skipSearchResult = function()
	{
		if ($("textboxsearch").value == "" || $("textboxsearch").value == "请输入关键字…")
			return ;
			
		if (bFirstEnterChoiceAfertChangeMode)
		{
			$("Choice").setContractId("@pplive.com/WebBrowser;1", false);
			$("Choice").showSWFBuffer = true;
			$("Choice").showNavigateStatus = true;
			bFirstEnterChoiceAfertChangeMode = false;
		}
		window.SetSelectedTabName("Choice");
			
		//http://list.client.pplive.cn/v3/index/地区码.html
		var channelURL = "http://list.client.pplive.cn/v3/index/" + getCityCode() + ".html" + "?kw=" + encodeURIComponent($("textboxsearch").value);

		var bOfflineMode = false;
		var ppFrame = Components.GetObject2("@pplive.com/PPFrame;1");
		if (ppFrame)
		{
			bOfflineMode=ppFrame.bOfflineMode;
			if (bOfflineMode)
			{
				$("Choice").SetUrl(ShowAbsolutePath("data\\local\\errorPage.htm?error=offline"), "data\\local\\errorPage.htm?error=offline");
			}
		}
		if (!bOfflineMode)
		{
			try
			{
				window.tellSearchKey($("textboxsearch").value);
			}
			catch (e)
			{
				$("Choice").SetUrl(channelURL, "data\\local\\errorPage.htm?<%errorcode%>");
			}
		}
	}


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

	//============================接口 AddSupport======================================
	//add by lxb
	AddSupport_Debug();
	AddSupport_DownloadTask();
	AddSupport_Passport();
	AddSupport_HotKey();
	AddSupport_Tab();
	AddSupport_Skin();
	AddSupport_Offline();
	AddSupport_Favorite();
	//AddSupport_ChUpdatePOP();
	AddSupport_SysTray();
	AddSupport_function();
	AddSupport_education();
	AddSupport_PushPOP();

	//客户端启动时间统计
	var PplStat=Components.GetObject2("@pplive.com/PPLStat;1");
	if (PplStat)
	{
	    PplStat.PPLiveEndUpTime(2);
	}
	// 有没有打开 视频小窗
	window.miniPlayerMode = false;

	//初始化自动关机服务
	InitTimingService();
}

function windowOnChangeMode()
{
	var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
	if(chMgrFactory)
	{
		var fav = chMgrFactory.favLive;
		var recent = chMgrFactory.recent;
		if(fav)try{ fav.LoadFavorites(2);}catch(e){}
		if(recent)try{ recent.LoadFavorites(1);}catch(e){}
	}
	
	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_addinfolder").disabled=false;
	      $("menu_picMenu").disabled=true;
	      $("menu_colorAdjust").disabled=true;
			try
			{
		  		$("menu_screenShot").disabled=true;
			}
			catch(e)
			{
			}
	  }
	  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;
			try
			{
				  $("menu_definition").disabled=false;
				if(newState==IPlayerState.pppBuffering)
				{
					$("menu_screenShot").disabled=true;
					$("menu_colorAdjust").disabled=true;
				}
				else
				{
					$("menu_screenShot").disabled=false;
					$("menu_colorAdjust").disabled=false;
				}
			}
			catch(e)
			{
			}
	  }	
	}
	
	var mframe = Components.GetObject2("mframe");
	if (mframe)
	{	//通知mframe当前显示模式
		try{ mframe.RunMode = 1;}catch(e){}
	}
	//设置标题
	var globalWindow = Components.GetObject2("globalWindow");
	if(globalWindow)	
	{
		try{ window.setTaskBarTitle(globalWindow.taskbarTitle);}catch(e){}
		try{ window.setWindowTitle(globalWindow.windowTitle);}catch(e){}
	}
	//通知所有挂接该事件的JS脚本
	for (var keyname in window.vecOnModeChange)
	{
		try
		{
			window.vecOnModeChange[keyname](1);	
		}
		catch(e)
		{
		}
	}

	bFirstEnterChoiceAfertChangeMode = true;

	if(window.hasChannelPlaying())
	{
		$("tabbox").setSelected("Player");
	}
	else
	{
		$("tabbox").setSelected("Choice");
	}

	var adModule = Components.GetObject('AD');
	if(adModule)
	{
		try
		{
				//window.alert("changemode");
		    adModule.UIChangeMode(mframe.RunMode);
		}
		catch(e)
		{
		}
	}
	windowOnShow();
}
function PPLState(i)
{
		var PPLState = Components.GetObject2('@pplive.com/PPLStat;1');
		if(PPLState)PPLState.PPTVStartTime(i);
}
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 AddSupport_education()
{
	window.ShowFindChannelTipBalloon=function(show)
	{
		if(show && !window.tidyMode)
		{
			window.balloons.Create("education\\FindChannelTip.xml",window.hwnd,161,85,240,14);
			window.balloons.Show("education\\FindChannelTip.xml",true);
		}
		else
		{
			window.balloons.Show("education\\FindChannelTip.xml",false);
		}
	}
	window.ShowNew2ClassicTipBalloon=function(show)
	{
		if(show && !window.tidyMode)
		{
			if (window.balloons.IsVisible("education\\FindChannelTip.xml"))
			return false;
			var New2ClassicTip = 0;
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
			{	
				New2ClassicTip = registry.readDWORD("New2ClassicTip");
				if(New2ClassicTip<1)registry.writeDWORD("New2ClassicTip",New2ClassicTip+1);	
			}
			if(New2ClassicTip<1)
			{
				window.balloons.Create("education\\New2ClassicTip.xml",window.hwnd,155,0,-177,28);
				window.balloons.Show("education\\New2ClassicTip.xml",true);
				return true;
			}
			return false;
		}
		else
		{
				window.balloons.Show("education\\New2ClassicTip.xml",false);
				return true;
		}
	}
	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);
		}
	}
	window.ShowFindDownloadMgrTipBalloon = function(show)
	{
		if (show && !window.tidyMode)
		{
			var nFindDownloadMgrTip = 0;
			var registry = Components.CreateObject("@pplive.com/registry;1");
			if (registry && registry.create(registry.HKCU, "Software\\PPLive\\PPTV\\UserEdu"))
			{	
				nFindDownloadMgrTip = registry.readDWORD("FindDownloadMgrTip");
			}
			if (nFindDownloadMgrTip == 1)
			{
				retrun;
			}
			else if (nFindDownloadMgrTip == 0)
			{
				window.balloons.Create("education\\FindDownloadMgrTip.xml",window.hwnd,0,0,44,30);
				window.balloons.Show("education\\FindDownloadMgrTip.xml",true);
			}
		}
		else
		{
			window.balloons.Show("education\\FindDownloadMgrTip.xml",false);
		}
	}
}


//=========================AddSupport_function begin add by lxb=================================

function AddSupport_function()
{
	window.OpenPPGame = OpenPPGame;
	window.showDownloadMgrWnd = showDownloadMgrWnd;

	var popMsgManager = Components.CreateObject("@pplive.com/PopMsgManager;1");

	window.ShowRegUser = function()
	{
		if (window.isShowRegUser) { return; }
		checkUnFullscreen();
		window.showModalDialog('RegUser.xml');	
	}
	//显示菜单
	window.ShowPopMenu=function(name,x,y)
	{
		$(name).openPopupAtScreen(x, y);
	}
	//显示详情页
	window.ShowVideoDetailInfo=function(url)
	{
		var bOfflineMode = false;
		var ppFrame = Components.GetObject2("@pplive.com/PPFrame;1");
		if (ppFrame)
		{
			bOfflineMode=ppFrame.bOfflineMode;
		}
		if(!bOfflineMode)
		{
			$("Choice").SetUrl(url, "data\\local\\errorPage.htm?<%errorcode%>");
		}
		window.SetSelectedTabName("Choice");
	}
	
	//common.js中会分发播放状态
	window.vecOnPlayStateChange  = {};

	//模式切换通知到网页
	window.vecOnModeChange = {};

	//CPlayerControl infobtn
	window.infobtnfunc = function()
	{
		if (window.tidyMode)
		{
			exitTidyMode();
		}
		checkUnFullscreen();
		// 搜索框置空
		$("textboxsearch").foregroundColor = "#656565";
		$("textboxsearch").value = "请输入关键字…";
		$("textboxsearch").lastInput = "";

		window.SetSelectedTabName("Choice");

		//http://list.client.pplive.cn/v3/index/地区码.html
		var channelURL = "http://list.client.pplive.cn/v3/index/" + getCityCode() + ".html";
		var myid = 0;
		//设置选集页面为当前播放页
		var ppp = Components.GetObject2("PPP");
		if (ppp && ppp.ChannelID)
		{
			//如果归属到合集，则显示合集对应的页面
			myid = ppp.HjID?ppp.HjID:ppp.ChannelID;
			channelURL += "#" + myid ;
		}

		var bOfflineMode = false;

		var ppFrame = Components.GetObject2("@pplive.com/PPFrame;1");
		if (ppFrame)
		{
			bOfflineMode=ppFrame.bOfflineMode;
			if (bOfflineMode)
			{
				$("Choice").SetUrl(ShowAbsolutePath("data\\local\\errorPage.htm?error=offline"), "data\\local\\errorPage.htm?error=offline");
			}
		}
		if (!bOfflineMode)
		{
				try
				{
					if(myid)window.tellChoiceChannelDetail(myid);
					else $("Choice").SetUrl(channelURL, "data\\local\\errorPage.htm?<%errorcode%>");
				}
				catch (e)
				{
					$("Choice").SetUrl(channelURL, "data\\local\\errorPage.htm?<%errorcode%>");
				}
		}
	}
	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();
	//PPFrame中会调用
	window.setTopMost=function(aTopMost)
	{
	}
	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;
	}
	window.getWindowTitle = function()
	{
		var globalWindow = Components.GetObject2("globalWindow");
		if(globalWindow) return globalWindow.windowTitle;
		return "";
	}	

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

			return true;
		}

		return false;
	}
	window.directClose = function()
	{ 
		window.close();
	}

	window.openFile = function()
	{
		checkUnFullscreen();
		return OpenFile();
	}
	//打开网址
	window.openUrlDialog = function()
	{
		checkUnFullscreen();
		return windowOpenUrl();
	}

	window.$ = function(id)
	{
		return document.getElementById(id);
	};
	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.showWindow = function (show)	
	{
		if(window.sizemode == IDOMWindow.SizeMode_Minimized)
		{
			window.sizemode=IDOMWindow.SizeMode_Normal;
		}
		window.visible = show;
		if(show)
		{
			var TrayIcon = Components.GetObject2("SkinForm1");
			if(TrayIcon)
			{
				TrayIcon.AddIcon();
			}
			window.SetBossState(false);
		}
	}
	//老板键 PPFrame中使用
	window.BossState = false;
	window.SetBossState = function(state)
	{	
		window.BossState  = state;
		if (window.BossState)  // 老板键被按下
		{
			var mframe = Components.GetObject2("mframe");
			if(mframe) 
			{
				mframe.StatusChange(0);
			}
		}
		else
		{
		}
	}
	//播放支持
	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);
	}

	//PPP中用到，防止多个框弹出来
	window.vipchanneltip = false;
	window.viplogin = false;
	window.CodecProblem = false;
	window.CheckVipPlay = function(channelid)
	{
		var islogin = $("passport").state==0?true:false;
		if(!islogin)
		{
			window.viplogin=true;
			window.showModalDialog("VIPLogin.xml",channelid);
			window.viplogin=false;
		}
		islogin = $("passport").state==0?true:false;
		if(!islogin) return false;
		var isvip = $("passport").IsVipUser;
		if(!isvip)
		{
			window.vipchanneltip=true;
			window.showModalDialog("VIPChannelTip.xml",channelid);
			window.vipchanneltip=false;
			return false;
		}
		return true;
	}
	//PPFrame中右键菜单调用
	window.SetTrack = function(nTrack)
	{	
		PPPSetTrack(nTrack);
	}
	//nclist会在地区码更改的时候通知外部
	window.vecOnCityCodeChange = {};
	window.OnCityCodeChange = function(cityCode)
	{
		var ppframe = Components.GetObject2("@pplive.com/PPFrame;1");
		if(ppframe)ppframe.cityCode=cityCode;
		for (var keyname in window.vecOnCityCodeChange)
		{
			try
			{
				window.vecOnCityCodeChange[keyname](cityCode);	
			}
			catch(e)
			{
			}
		}
	}

	//PPFrame守护PPAP进程，当崩溃时调用
	//PPAP异常崩溃处理
	window.RestartPPAP = function()
	{
		var ppp = Components.GetObject2("PPP");
		if (ppp)
		{
			ppp.ResetPPAP();
		}
		var admodule = Components.GetObject2("AD");
		if (admodule)
		{
			admodule.PPAPReload(0);
		}
	}

	window.EwaOnFullScreen = function(newVal)
	{
		if(newVal)
		{ //客户端启动时间统计
			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);			
		}
	}
	var EWA = Components.GetObject2("EWA");
	if(EWA)
	{
		EWA.onPlayStateChanged=EwaOnPlayStateChanged;
		EWA.onFullScreen=window.EwaOnFullScreen;
	}
	//ppframe在CreatePlayer之后调用
	window.OnCreatePlayer=function()
	{
		var EWA = Components.GetObject2("EWA");
		if(EWA)
		{
			EWA.onPlayStateChanged=EwaOnPlayStateChanged;
			EWA.onFullScreen=window.EwaOnFullScreen;
		}

		var MainFrame = Components.GetObject2("MFRAME");
		if(MainFrame)
		{
			MainFrame.DelayCreatePortal(0);
		}
	}
	//在线升级,菜单调用
	window.ManualUpdate=function()
	{
		var ppFrame=Components.GetObject2("@pplive.com/PPFrame;1");
		if(ppFrame)
		{
			ppFrame.ManualUpdate();
		}
	}
	//显示ResizeTip
	window.ShowResizeTip = function(nSize)
	{
		var MainFrame = Components.GetObject2("MFRAME");
		if(!MainFrame) return;

		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 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);
	}
	//1x , 1.5x , 2x 命令
	window.OnResizeCommand = function (idCmd,nState)
	{
		var isFullScreen = EwaIsFullScreen();
		var MainFrame = Components.GetObject2("MFRAME");
		if(!MainFrame) return;
		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);
		}
	}	

	//增强OnStateChange，由mframe调用通知
	window.OnStateChangeEx = function(bsMessage,bsAction,bswParam,bslParam)
	{
		var windowGlobal = Components.GetObject2("globalWindow");
		if (windowGlobal)
		{
			windowGlobal.strMessage = bsMessage;
			windowGlobal.strAction = bsAction;
		}
		if (bsMessage=="stop")
		{
			if (bsAction=="mediaend" && bswParam=="1")
			{	//媒体结束消息里面，不立即退出
				return;
			}
			if ($("tabbox").getSelected() == 0)
			{
				$("tabPlayer").previousWidth = window.outerWidth;
				$("tabPlayer").previousHeight = window.outerHeight;
			}
			exitMiniPlayer();
		}
		else if (bsMessage == "buffer" && bsAction=="mediaopen")
		{
			SetOriginalSizePlayPolicy();
		}
	}
}

//=========================AddSupport_function begin add by lxb=================================


//=========================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_Favorite begin add by lxb=================================
function AddSupport_Favorite()
{
	//收藏夹同步事件（通知WEB)
	window.onFavoriteEvent= function(statusCode, errCode){return;}
	window.vecFavoriteEvent = {};
	window.OnSyncEvent=function(statusCode, errCode)
	{
		try{window.onFavoriteEvent(statusCode, errCode);}catch(e){}
		for (var keyname in window.vecFavoriteEvent)
		{
			try
			{
				window.vecFavoriteEvent[keyname](statusCode, errCode);	
			}
			catch(e)
			{
			}
		}
	}
	var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
	try{chMgrFactory.Sync(-1);}catch(e){}	//检查一下
}
//=========================AddSupport_Favorite end add by lxb=================================

//=========================AddSupport_Offline begin add by lxb=================================
function AddSupport_Offline()
{
	window.OnOffline = function(offline)
	{
		if(offline)
		{
			//进入离线模式
			$("Choice").SetUrl(ShowAbsolutePath("data\\local\\errorPage.htm?error=offline"), "data\\local\\errorPage.htm?error=offline");
		}
		else
		{
			//退出离线模式
			$("Choice").SetUrl("http://list.client.pplive.cn/v3/index/" + getCityCode() + ".html", "data\\local\\errorPage.htm?<%errorcode%>");
		}
		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;
		}
		$("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";
		}
		else if (skinId == "1" || skinId == "2" || skinId == "4")
		{
			skinValue = "black";
		}
		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_Tab begin add by lxb=================================
function AddSupport_Tab()
{
	// 播放视频时，修改窗口的大小来适应视频的大小
	// 参数分别为：视频的宽度和高度
	// 具体策略请看文档
	window.selectPlayerTabOnPlay=function(cx, cy)
	{
		if ($("tabbox").getSelected() == 0 || EwaIsFullScreen())
		{
			return;
		}

		var windowWidth = window.outerWidth;
		var windowHeight = window.outerHeight;
		{// 使用节目库的大小
			$("tabPlayer").previousLeft = window.screenLeft;
			$("tabPlayer").previousTop = window.screenTop;
			$("tabPlayer").previousWidth = windowWidth;
			$("tabPlayer").previousHeight = windowHeight;
		}
		$("tabbox").setSelected("Player");
	}
	window.SetSelectedTabName = function(name)
	{
		$("tabbox").setSelected(name);
	}
	window.GetSelectedTabName = function()
	{
		return $("tabbox").getSelected();
	}
}
//=========================AddSupport_Tab begin 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_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"));
			SetInitHotKey("menu_directCloseWindow",registry.readDWORD("key_directCloseWindow"));
		}
	}
	InitHotKey();
}
//=========================AddSupport_HotKey end 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_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_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)
	{
		window.autologin = true;
		$("passport").Login(username, password);
	}
}

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 vipUrl = "http://live.v2.pplive.com/interface/client2/vipop_" + "black" + ".html";
		vipweb.url = vipUrl;
	}
}

function AddSupport_Passport()
{
	window.signin=0;
	window.autologin = false;
	//登录通知事件
	window.vecOnUserLogin  = {};
	window.vecOnGetUserPicture = {};
	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);
			}
		}
	}
	window.OnGetUserPicture = function()
	{
		//用户登录成功通知
		for (var keyname in window.vecOnGetUserPicture)
		{
			try
			{
				window.vecOnGetUserPicture[keyname]();			
			}
			catch(e)
			{
			}
		}
	}
	//登录
	window.OnPassportLogin = function(vLogin)
	{
		if (vLogin)
		{
			//$("title_user").value=$("passport").userName;
			//$("title_after_login").visible=true;
			//$("title_before_login").visible=false;
			window.autologin=false;
			//切换用户名
			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.LoadFavorites(2);
				if(recent) recent.LoadFavorites(1);
				try{chMgrFactory.Sync(0);}catch(e){}		//登录时的同步
			}
			//登录成功
			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);
				}
			}
			else
			{	
				//非VIP用户登录
			}
			//用户登录成功通知
			for (var keyname in window.vecOnUserLogin)
			{
				try
				{
					window.vecOnUserLogin[keyname](true);			
				}
				catch(e)
				{
				}
			}
		}
		else
		{
			//登录失败
			if(window.autologin)
			{
				var globalWindow = Components.GetObject2("globalWindow");
				if(globalWindow.AutologinFail==false)
				{
					globalWindow.AutologinFail=true;
					if(window.visible && window.signin==0)window.showModalDialog("signin2.xml");
				}
				window.autologin=false;
			}
		}
	}
	window.OnPassportLogout = function(reason)
	{
		//$("title_before_login").visible=true;
		//$("title_after_login").visible=false;
		var chMgrFactory = Components.GetObject2("@pplive.com/ChannelManagerFactory;1");
		try{chMgrFactory.Sync(2);}catch(e){}	//退出时的同步

		//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)
			{
			}
		}
	}
}
//=========================AddSupport_Passport end add by lxb=================================


function windowOnunload()
{
	// 卸载 命令行
	if (window.cmdlineMgrCookie)
	{
		var cmdlinemgr = Components.GetObject("@pplive.com/command-line;1");
		cmdlinemgr.RemoveHandler(window.cmdlineMgrCookie);
		window.cmdlineMgrCookie = 0;
	}

	//关闭推荐气泡

	var pop_skin3 = Components.GetObject2("POP_VIP");
	if(pop_skin3)
	{
		pop_skin3.Show(0);
	}

	//关闭定时关机服务
	UninitTimingService();
	//关闭用户教育气泡
	if (window.balloons)window.balloons.Clear();
	if (window.miniPlayer)
	{
		exitMiniPlayer();
		window.miniPlayer.visible=false;
		if (!window.miniPlayer.closed)
		{
			window.miniPlayer.directClose();
		}
		window.miniPlayer = null;
	}
	
	// 关闭下载窗口
	var downloadMgrWnd = Components.GetObject2("DownloadMgrWnd");
	if (downloadMgrWnd)
	{
		downloadMgrWnd.close();
		Components.UnregisterObject("DownloadMgrWnd");
	}
}

function windowOnShow()
{
	var ob = Components.GetObject2("AD");
	if(ob)ob.FrameShow(true);
	var ob2 = Components.CreateObject("@pplive.com/PopMsgManager;1");
	if(ob2)ob2.FrameShow(true);
	var ppFrame = Components.GetObject2("@pplive.com/PPFrame;1");
	if(ppFrame)
	{
		ppFrame.bActivedOnce=true;
		ppFrame.ForceBreakBossState(true);
	}
	if(window.firstShow) 
	{
		window.firstShow=false;
		//教育气泡控制
		window.balloons = new Balloons(window);
		//视频窗体大小控制
		var videoscan = Components.GetObject2("VideoScan");
		if(videoscan)window.videoScan = videoscan;
		//延时3秒初始化一些参数
		window.setTimeout("delayInitWindowParam()", 3000);
	}
	//更新量提示气泡
	//window.ShowNumTip(0,0);
	if (window.miniPlayerMode && window.miniPlayer)
	{
		window.miniPlayer.visible = true;
	}

	//ShowFireWallForbiddenBalloon
	if (window.bShowFireWallForbiddenBalloon == true)
	{
		window.bForceShowFireWallForbiddenBalloon = true;
		window.ShowFirewallForbiddenBalloon(window.nFireWallForbiddenBalloonType);
	}
}

function delayInitWindowParam()
{
	window.ShowNew2ClassicTipBalloon(true);
}

function windowOnSizemode()
{
	if (window.sizemode == IDOMWindow.SizeMode_Maximized)
	{
		PPLState(21);
		$("resizeGripper").visible = false;
		$("maxRestoreBtn").checked = true;
	}
	else
	{
		$("resizeGripper").visible = true;
		$("maxRestoreBtn").checked=false;

		if (window.miniPlayer && window.miniPlayerMode)
		{
			if (window.sizemode == 1 && !window.topMost) // 最小化
			{
				window.miniPlayer.topMost = true;
			}
		}
	}

	//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(2, 2, window.innerWidth-4, window.innerHeight-4);
	}
	return !tidyMode;
}

function OpenPPGame()
{
	var ppframe = Components.GetObject("@pplive.com/PPFrame;1");
	if(ppframe)
  {
		 var ntabId = 4;
		 ppframe.PPTVClickTabId(ntabId);
	}
}

// 每次从播放TAB切换到其他TAB都会调用这个方法
function enterMiniPlayerIfNeed()
{
	//已经进入mini态，或者节目未播放，禁止进入
	if (window.miniPlayerMode || !window.hasChannelPlaying() || EwaIsFullScreen())
	{
		return false;
	}

	//节目处于异常状态，不允许进入
	var windowGlobal = Components.GetObject2("globalWindow");
	if (windowGlobal && windowGlobal.strMessage=="stop" && windowGlobal.strAction=="error")
	{
		return false;
	}

	//节目处于播放状态，并且是纯音频节目，则不再切换到小窗体
	var ppp = Components.GetObject2("PPP");
	if (ppp && ppp.State==2)
	{
		if (ppp.Oplayer.videoWidth==0 && ppp.Oplayer.videoHeight==0)
		{
			return false;
		}
	}

	//用户设置禁止弹出小窗体
	var showMiniPlayer = 1;
	var registry = Components.CreateObject("@pplive.com/registry;1");
	if (registry && registry.open(registry.HKCU, "Software\\PPLive\\config\\other",IRegistry.KEY_READ))
	{
		if (registry.queryType("showMiniPlayer") == 4)
		{
			showMiniPlayer = registry.readDWORD("showMiniPlayer");
		}
		if (!showMiniPlayer)
		{
			return false;
		}
	}
	
	PPLState(28);

	$("accelsetPlayer").disabled = true;
	if (!window.miniPlayer)
	{
		window.miniPlayer = window.open("miniplayer.xml", "", "owner=1;hidden=1;toolwindow=1");
	}
	window.miniPlayerMode = true;
	window.miniPlayer.topMost = true;
	window.miniPlayer.openMiniPlayer();

	var mframe = Components.GetObject2("mframe");
	if (mframe)
	{
		mframe.MiniPlayerMode = true;
	}

	var ad = Components.GetObject2("AD");
	if (ad)
	{
		ad.VideoModeChange(true);
	}
	return true;
}

function exitMiniPlayer(switchToPlayerTab)
{
	if (!window.miniPlayer)
	{
		return;
	}
	if (!window.miniPlayerMode)
	{
		return;
	}
	window.miniPlayerMode = false;
	if (!window.miniPlayer.closed)
	{
		window.miniPlayer.closeMiniPlayer();
	}

	$("Player").rob();
	if (arguments.length > 0 && switchToPlayerTab)
	{
		if (window.sizemode==1)
		{
			window.sizemode=0;
		}
		$('tabbox').setSelected('Player');
	}
	else
	{
		$("accelsetPlayer").disabled = true;
	}
	var mframe = Components.GetObject2("mframe");
	if (mframe)
	{
		mframe.MiniPlayerMode = false;
	}

	var ad = Components.GetObject2("AD");
	if (ad)
	{
		ad.VideoModeChange(false);
	}
}

function beforeChangeMode()
{	//在切换模式之前，记录选集页面地址到注册表，再切换回来的时候，再访问该地址
	var webbrowser = $("Choice").IWebBrowser2;
	if (webbrowser)
	{
		var locationURL = webbrowser.LocationURL;
		if (locationURL && locationURL.length)
		{
			var windowGlobal = Components.GetObject2("globalWindow");
			if (windowGlobal)
			{
				windowGlobal.locationURL = locationURL;
			}
		}
	}
}

function getLocationURLBeforeChangeMode()
{
	var windowGlobal = Components.GetObject2("globalWindow");
	if (windowGlobal && windowGlobal.locationURL)
	{
		return windowGlobal.locationURL;
	}

	return "";
}

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 showUserFeedbackWnd()
{
	//创建意见反馈窗口
	if(!window.userFeedbackWnd || window.userFeedbackWnd.closed)
	{
		window.userFeedbackWnd = null ;
		window.userFeedbackWnd = window.open("UserFeedback.xml", "", "modal=0;center=1;") ;
	}
	else
	{
		window.userFeedbackWnd.activated = true;
	}
}

//end add by gjj.

// SIG // Begin signature block
// SIG // MIIVVgYJKoZIhvcNAQcCoIIVRzCCFUMCAQExCzAJBgUr
// SIG // DgMCGgUAMGcGCisGAQQBgjcCAQSgWTBXMDIGCisGAQQB
// SIG // gjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIBAAIB
// SIG // AAIBAAIBAAIBADAhMAkGBSsOAwIaBQAEFFCR7sxRaWyo
// SIG // Txr+zqC5P5G7PKNuoIIRWzCCA3owggJioAMCAQICEDgl
// 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 // BgorBgEEAYI3AgEVMCMGCSqGSIb3DQEJBDEWBBSsG3/n
// SIG // Qq1LtdDEjgJjIs20w1CNfDANBgkqhkiG9w0BAQEFAASB
// SIG // gFnBKo4lNO1eXCls+ggtaQ9QFVkpG3hmSlFoAnz5u0Lo
// SIG // IGUsS6CT2vpaOsRGUwDcbZOZPfT+WR5Q9OMwhAzsRwnK
// SIG // V/PPd9n4MtbMQE+1LDC3RiCRtHGhVz3Ix6OLzfbpoDe1
// SIG // iOup2Q2J35TB/URp+RHiXKKu0t1o83nHbfKHJDfioYIB
// SIG // fzCCAXsGCSqGSIb3DQEJBjGCAWwwggFoAgEBMGcwUzEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMSswKQYDVQQDEyJWZXJpU2lnbiBUaW1lIFN0YW1w
// SIG // aW5nIFNlcnZpY2VzIENBAhA4Jdf6+GGvnvSQ5ya11lrV
// SIG // MAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZI
// SIG // hvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xMTA5MTMwOTAx
// SIG // NTVaMCMGCSqGSIb3DQEJBDEWBBTooppc4wZE/YV3kfbW
// SIG // c+N2FqFVHDANBgkqhkiG9w0BAQEFAASBgCnoD/y3JBwG
// SIG // q5Bipao0/hiAJ/tvoEqtq3NF5PtN8ELvtj/Ygp9PJJrw
// SIG // 2hXWkK/XDgI/7F1bPe1sOdJ2jhZn7wAdNZ3rPMAoGUDr
// SIG // Ycf+v65IRTCIZ1D4IGEKc2SK6QiQQiAjzPGZE7Bj8NL+
// SIG // oiKoK9Evi5m7eO/yd/CyiWNvfyFR
// SIG // End signature block
