<?xml version="1.0" encoding="utf-8"?>
<window screenLeft="0" screenTop="0" width="430" height="280" titleBar="false" resizeMargins="0,0,0,0" maxWidth="430" maxHeight="382" maximizable="false" onload="WindowOnLoad();" onclose="WindowOnClose();" >
	<script src="common.js" />
	<script language="JavaScript">
	<![CDATA[
	var uiMainWindow = Components.GetObject("@pplive.com/ui/mainwindow;1");
	var batwnd = Components.GetObject("@pplive.com/batdownloadwnd_3;1");
	function WindowOnLoad()
	{
		window.returnValue = 0;//初始化未0,不是用户点击确定

		if(!uiMainWindow)
			return;
		uiMainWindow.disabled = true;
		var list = $("list");
		if (list)
		{
			list.InsertHdItem("任务名称", 406, false);
			list.EnableCheckBox(true, true);//enable check box attribute, and set its init state to checked;
			Components.GetObject("@pplive.com/outputdebug;1").DebugString('onload get bat');
			if (batwnd)
			{
				var items = batwnd.GetExistingTaskCounts(true);
				for (var i=0; i<items; i++)
				{
					var item = batwnd.GetExistDownloadingTask(i);
					Components.GetObject("@pplive.com/outputdebug;1").DebugString('onload get item');
					if (item)
					{
						list.InsertItem(item.origName, item);
					}
				}
			}
		}
	}

	function WindowOnClose()
	{
		if (1 != window.returnValue)	//如果用户没有点击确定，那么=0
		{
			window.returnValue = 0;
		}
	}

	function SelectOpt(option)
	{
		var list = $("list");
		if (!list)
			return;

		if (0 == option)
		{
			list.SelectOpt(true);
		}
		else
		{
			list.SelectOpt(false);
		}
	}

	function SelectItemsChange(cnt)
	{
		var fileText = $("lblFileNum");
		if (fileText)
		{
			fileText.value = "共选择"+cnt+"个文件";
		}
	}

	function WindowOnClose()
	{
		if (uiMainWindow)
		{
			uiMainWindow.disabled = false;
		}

		window.close();
	}

	function WindowOnOK()
	{
		window.returnValue = 1;//refer to user click OK.
		var list = $("list");
		var downloadMgr = Components.GetObject("@pplive.com/chDownloadMgr;1");
		if (list && downloadMgr)
		{
			var items = list.GetItemCount();
			var selitems = list.GetSelectedItemCounts();
			var i=0;
			for (i=0; batwnd&&i<=items-selitems; i++)	//first set items user don't want to redownload unchecked.
			{
				var item = list.GetSelectedItem(i, false);
				if (item)
				{
					Components.GetObject("@pplive.com/outputdebug;1").DebugString('[DownloadTaskConfilct]set task unchecked for not download again,name='+item.origName);
					batwnd.SetItemCheck(item.channelId, false);
				}
			}

			for (i=0; batwnd&&i<selitems; i++)//second,remove items user want to redownload,caller will download them again
			{
				Components.GetObject("@pplive.com/outputdebug;1").DebugString('[DownloadTaskConfilct]RIIRIRIRIRIi'); 
				var item = list.GetSelectedItem(i, true);
				if (item)
				{
					Components.GetObject("@pplive.com/outputdebug;1").DebugString('[DownloadTaskConfilct]remove task first for redownload,name='+item.origName);
					downloadMgr.RemoveTask(item, false);
				}
			}
		}
		WindowOnClose();
	}
	]]>
	</script>
	<subwindow left="0" top="0" width="430" height="280">
		<!-- top left -->
		<subwindow left="0" top="0" width="190" height="32" backgroundImage="small_title_l.png" clippingColor="#FF00FF">
			<label left="30" top="0" width="190" height="32" value="提示" textAlignment="left vcenter" fontSize="12" fontStyle="bold" passThrough="true" foregroundColor="#FFFFFF"/>
		</subwindow>
		<!-- top -->
		<subwindow left="190" top="0" width="125" height="32" backgroundImage="small_title_m.png" clippingColor="#FF00FF" horizontalAlignment="stretch" backgroundImageStretchMode="stretch" backgroundColor="#000000"/>
		<!-- top right -->
		<subwindow left="315" top="0" width="115" height="32" backgroundImage="small_title_r.png" clippingColor="#FF00FF" >
			<button id="btnClose" left="83" top="4" width="24" height="24" image="close.png" hoverImage="close_hover.png" downImage="close_down.png" tooltip="关闭" onclick="WindowOnClose();"/>
		</subwindow>
		<!-- left frame border-->
		<subwindow left="0" top="32" width="2" height="248" backgroundImage="small_frame_l.png" horizontalAlignment="left" verticalAlignment="stretch" backgroundImageStretchMode="stretch" backgroundColor="#000000"/>
		<!-- right frame border-->
		<subwindow left="428" top="32" width="2" height="248" backgroundImage="small_frame_r.png" horizontalAlignment="right" verticalAlignment="stretch" backgroundImageStretchMode="stretch" backgroundColor="#000000"/>
		<!-- bottom frame border-->
		<subwindow left="2" top="278" width="426" height="2" backgroundImage="small_frame_bottom.png" horizontalAlignment="stretch" backgroundImageStretchMode="stretch" backgroundColor="#000000"/>
		<!-- below top -->
		<subwindow left="2" top="32" width="426" height="13" backgroundImage="below_title.png" clippingColor="#FF00FF" horizontalAlignment="stretch" verticalAlignment="top" backgroundImageStretchMode="stretch" backgroundColor="#000000"/>
		<!-- main subwindow-->
		<subwindow left="2" top="45" width="426" height="233" backgroundColor="#FFFFFF">
			<label left="23" top="0" width="350" height="20" value="以下任务在任务列表中已存在，是否重新下载" textAlignment="left vcenter" fontFace="tahoma"  fontSize="12" passThrough="true"/>
			<subwindow left="11" top="25" width="406" height="135" horizontalAlignment="stretch" verticalAlignment="stretch" backgroundColor="#7F9DB9" visible="true">
				<widget id="list" left="1" top="1" width="404" height="133" horizontalAlignment="stretch" verticalAlignment="stretch" contractId="@pplive.com/pplistctrl;1" visible="true" OnItemClick="SelectItemsChange(arguments[0]);"/>
			</subwindow>
			<label id="lblSelectAll" left="23" top="160" width="30" height="32" value="全选" cursor="hand" textAlignment="right vcenter" fontStyle="underLine" fontSize="12" foregroundColor="#7F9DB9" onclick="SelectOpt(0);"/>
			<label id="lblOppositeSel" left="63" top="160" width="30" height="32" value="反选" cursor="hand" textAlignment="right vcenter" fontStyle="underLine" fontSize="12" foregroundColor="#7F9DB9" onclick="SelectOpt(1);"/>
			<label id="lblFileNum" left="320" top="160" width="90" height="32" value="" passThrough="true" textAlignment="right vcenter" fontSize="12" foregroundColor="#000000"/>
			<label left="1" top="190" width="424" height="1" backgroundColor="#CCCCCC" passThrough="true"/>
			<button id="btnOK" left="340" top="200" width="70" height="26" label="确定" image="button.png" hoverImage="button_hover.png" downImage="button_down.png" disabledImage="button_disable.png" onclick="WindowOnOK();" />
		</subwindow>
	</subwindow>
</window>