var move_timeer = null;
var AjaxObj;
var begin_x;
var mouse_down_bool = false;
//workfile
var viewArray                = new Array();
var goodViewArray;
var goodViewArrayNameDate    = new Array();
var WorkType                 = 2;
var WorkId                   = 0;
var DragBannerNameStateName  = 17;
var DragBannerNameStateDate  = 14;
var FileName                 = 17;
var FileSize                 = 10;
var FileType                 = 18;
var SaveCatalog              = 7;
var WorkUrl                  = 3;
var WorkCiteUrl              = 4;
var ResourceWrite            = 6;
var FileLoading              = 20;
var AverageRapidity          = 8;
var StartTime                = 14;
var TimeEd                   = 16;
var CompleteTime             = 15;
var RemnantTime              = 13;
var DownLoadEd               = 9;
var Cid                      = 21;
var WorkIngResource          = 11;
var WorkAllResource          = 12;
var FileState                = 5;
//bt_file
var BtAverageRapidity        = 8;
var BtInfoId                 = 17;
var BtFilePath               = 18;
var BtTitle                  = 19;
var BtHealthSize             = 20;
var BtFileUpload             = 21;
var BtUpSed                  = 22;
var BtDownLoadPlan           = 23;
var BtFileCount              = 24;
var BtTrackerCount           = 25;
var BtFileList               = 26;
//timeer
var ConentTime;
//variable
var g_TaskId     = null;
var view_type    = null;
var InfoNowCount = 0;
var InfoAllCount = 0;
var FileTypeCount;

var AjaxTxt;
var SetWorkArray = null;
var CountTtClick = false;


var re_content_cut;
var LOGIN_FOR_ID ;
var report_type;
var characteristic;
var have_preview_video;
var all_select;
var SetBtFileList;
var json_url;
var ifr_json ;
var AjaxImageSrc;
var	AjaxJsonV;
var	AjaxFileType;
var	AJF;
var bt_table_list_tbody;
var BT_NODES;
var	T_body;
var g_taskname ;
var g_taskDescription ;
var g_taskscore;


var _old_file_state = null;
var old_g_TaskInfo = null;
var p4p_time = null;
var commonly_after_cid = null;
var commonly_after_bool = false;
var bt_after_cid = null;
var bt_after_bool = false;
var g_Virus = false;


//初始引用函数
function set_content_info(formdel)
{
	if(formdel=="Virus")
	{
		$("left_info_box_img").src = "images/left_info_soft_bad.gif"	;
		g_Virus = true
	}
	else
	{
		g_Virus = false;
		formdel==undefined?formdel=false:1+1;
	}

	if($("file_info_box").style.display=="none"||$("file_info_box").style.display==""||LOGIN_FOR_ID==true)
		return;

	if(formdel == false)
		InfoNowCount = 0;
	InfoAllCount = 0;
	//取得当前ID
    g_TaskId = get_variable("Content_TaskId");
	//alert(g_TaskId);

	goodViewArray = new Array()
	//取得所有任务列表
	viewArray = window.frames['view'].g_TR;
	var viewArrayTemp="";
		//取得有效任务数及当前任务排名
	for(i=0;i<viewArray.length;i++)
    {
		if(viewArray[i].id!=0)
        {
            InfoAllCount+=1;
			//取得所有有效任务的obj;
			goodViewArray.push(viewArray[i]);
			viewArrayTemp = viewArrayTemp+viewArray[i].id+",";
        }
		if(viewArray[i].id == g_TaskId)
        {
            InfoNowCount = i -1;
        }
	}
	if(viewArrayTemp=="")
	return;
	//快捷键
	
	$("file_info_box").focus();
	//取得所有有效任务的名称及开始时间;
	goodViewArrayNameDate = thunder_server.GetTaskInfoSnap(viewArrayTemp).split("{\r\r*\r\r}");
	if(goodViewArrayNameDate==null)
	return;
	
	for(i=0;i<goodViewArrayNameDate.length;i++)
	{
		goodViewArrayNameDate[i] = goodViewArrayNameDate[i].split("{\r*\r}");
	}
	if(InfoAllCount==1)
	{
		InfoNowCount=0
	}
	set_ctt_all_info();
	listen($('drag_banner'),$('drag_obj'));	
}
function set_content_info_for_id()
{
	//设置只能查看一次
	XL_popUpWindow.fn_open("file_info_box");
	$("backDiv").onclick = function (){close_content()};
	try{document.body.removeChild($("leiyanscript"))}catch(e){};
	
	g_TaskInfo = null;	
	g_TaskInfo = get_task_info(get_variable("Content_TaskId"));
	if(g_TaskInfo==null)
	{
		alert("获取任务信息失败，请重试");
		on_content_close();
		return;
	}
	
	var cid = g_TaskInfo[Cid]
	var sct = document.createElement("script");
	sct.id  = "leiyanscript";
	sct.src = "http://leiyanstatic.xunlei.com/js/eyesfunc.js?channelid=3&replaceid=leiyancontent&leiyancachehref=http://my.xunlei.com/"+cid;
	document.body.appendChild(sct);
	
	LOGIN_FOR_ID=true;
	g_TaskId = get_variable("Content_TaskId");
	InfoAllCount = 1;
	InfoNowCount = 0;
	goodViewArray = new Array();
	var a = new Object;
	a.id =g_TaskId;
	goodViewArray.push(a);
	if(goodViewArray[InfoNowCount]==null)
	{
		on_content_close();
		return;	
	}
	/*g_TaskInfo = null;
	g_TaskInfo = get_task_info(get_variable("Content_TaskId"));
	if(g_TaskInfo==null)
	{
		alert("获取任务信息失败，请重试");
		on_content_close();
		return;
	}*/
	if(g_TaskInfo[WorkType] == 0)//普通任务
	{
	    bulid_commonly_work();
		content_tt_load($("tt_sed_tr"),$("tt_trd_tr"),$("tt_fst_tr_div"));
	}
	else
	{
	    bulid_bt_work();
		content_tt_load($("tt_bt_sed_tr"),$("tt_bt_trd_tr"),$("tt_bt_fst_tr_div"));
	}
	
	$("res_for_com").style.marginTop = "0px";
	if($("work_cite_url").value ==""||$("work_cite_url").value ==null||String($("work_cite_url").value).length<7)
	{
		$("go_work_cite_url_a").style.color = "#cccccc"
		$("go_work_cite_url_a").style.cursor = "default"
	}
	else
	{
		$("go_work_cite_url_a").style.color = "#314e74";
		$("go_work_cite_url_a").style.cursor = "pointer"
	}
	a = null;
	close_work_all()
}
function set_ctt_all_info(forCountId)
{
	if($("file_info_box").style.display=="none"||$("file_info_box").style.display=="")
	{
		return;
	}
	if(goodViewArray==null)
	{
		on_content_close();
		return;	
	}
	set_variable("Content_TaskId", goodViewArray[InfoNowCount].id);
	set_task_open_status(goodViewArray[InfoNowCount].id);
	g_TaskInfo = null;
	g_TaskInfo = get_task_info(get_variable("Content_TaskId"));
	
	//alert(get_variable("Content_TaskId"));

	if(g_TaskInfo==null)
	{
		alert("获取任务信息失败，请重试!");
		on_content_close();
		return;
	}
	if(g_TaskInfo[WorkType] == 0)//普通任务
	{
	    bulid_commonly_work();
		content_tt_load($("tt_sed_tr"),$("tt_trd_tr"),$("tt_fst_tr_div"));
	}
	else
	{
	    bulid_bt_work();
		content_tt_load($("tt_bt_sed_tr"),$("tt_bt_trd_tr"),$("tt_bt_fst_tr_div"));
	}
	
	$("res_for_com").style.marginTop = "0px";
	if(forCountId!=0)
	{
	set_drag_obj_left_for_count($('drag_banner'),$('drag_obj'),InfoNowCount,InfoAllCount);
	}
	if($("work_cite_url").value ==""||$("work_cite_url").value ==null||String($("work_cite_url").value).length<7)
	{
		$("go_work_cite_url_a").style.color = "#cccccc"
		$("go_work_cite_url_a").style.cursor = "default"
	}
	else
	{
		$("go_work_cite_url_a").style.color = "#314e74";
		$("go_work_cite_url_a").style.cursor = "pointer"
	}
	close_work_all();
}
function listen(drag_banner,drag_obj)
{
	drag_banner.onmousedown =function(){drag_banner_down(drag_banner,drag_obj)};
	document.onmousemove = function(){drag_banner_move(drag_banner,drag_obj)} ;
	document.onmouseup = function(){drag_banner_up()};
	drag_banner.onselectstart = function(){return false};
	banner_unit_width = drag_banner.style.pixelWidth/InfoAllCount;
}
function set_drag_banner_name_state()
{
   $("drag_banner_name_state_name").innerText = goodViewArrayNameDate[InfoNowCount][0]
   $("drag_banner_name_state_date").innerText = goodViewArrayNameDate[InfoNowCount][1]

}
function drag_banner_down(drag_banner,drag_obj)
{
	mouse_down_bool = true;
	$("drag_banner_name_state").style.display = "block"
	drag_banner_move(drag_banner,drag_obj)
}
function drag_banner_move(drag_banner,drag_obj)
{
	if(window.event.button == 1&&mouse_down_bool)
	{
		set_drag_obj_left(drag_banner,drag_obj)
		var page_count = Math.ceil(drag_obj.style.pixelLeft/banner_unit_width) ;
		if(page_count>InfoAllCount)
		{
			page_count = InfoAllCount;
		}
		if(page_count<=0)
		{
			page_count = 1;
		}
		if(page_count!=$('info_now_count').innerText)
		{
			InfoNowCount = page_count -1;
			$('info_now_count').innerText = page_count
		}
	 	set_drag_banner_name_state();
	}
}
function drag_banner_up()
{
    if(mouse_down_bool == true)
    {
		clear_time_out();
	    $("drag_banner_name_state").style.display = "none";
		set_ctt_all_info(0);
		mouse_down_bool = false;
    }
	set_drag_obj_left_for_count($('drag_banner'),$('drag_obj'),InfoNowCount,InfoAllCount)
}

function set_drag_obj_left(drag_banner,drag_obj)
{
    var a = event.x - drag_banner.style.pixelLeft - drag_obj.style.pixelWidth - 2 - $("file_info_box").style.pixelLeft;
		if(a>0&&a<drag_banner.style.pixelWidth - drag_obj.style.pixelWidth - 2)
		{
			drag_obj.style.pixelLeft = a ;
		}
		else if(a<0)
		{
			drag_obj.style.pixelLeft = 0;
		}
		else if(a>drag_banner.style.pixelWidth - drag_obj.style.pixelWidth - 2 )
		{
			drag_obj.style.pixelLeft = drag_banner.style.pixelWidth - drag_obj.style.pixelWidth - 2;
		}

}
function set_drag_obj_left_for_count(drag_banner,drag_obj,InfoNowCount,InfoAllCount)
{
    var a = Math.ceil(drag_banner.style.pixelWidth/InfoAllCount);
    var b = a*(InfoNowCount+0.5)
        if(InfoNowCount == 0)
        {
            drag_obj.style.pixelLeft = 0;
        }
        else if(InfoNowCount==InfoAllCount-1)
        {
            drag_obj.style.pixelLeft = drag_banner.style.pixelWidth - drag_obj.style.pixelWidth ;
        }
		else if(InfoNowCount != 0&&b>0&&b<drag_banner.style.pixelWidth - drag_obj.style.pixelWidth)
		{
			drag_obj.style.pixelLeft = b ;
		}

}

//打开时屏蔽selet
function on_content_close()
{
	LOGIN_FOR_ID = false;
	all_select = null;
	all_select = top.document.frames["view"].document.getElementsByTagName("SELECT");
	for(i=0;i<all_select.length;i++)
	{
		all_select[i].style.clip="rect(auto auto auto auto)";
		all_select[i].style.position="static"
	}
	clear_time_out();
    $("file_info_box").style.display = "none";
	$("variable_menu").style.display = "none";
	if($("set2_div")!=null)
	{
	document.body.removeChild($("set2_div"));
	}
	//$("p4pcon").src="";
	clear_content_all_set();
	all_select = null;
	fresh_tasklist(0);
	g_dragBool = false;
}
function clear_time_out()
{
	if(ConentTime)
	{
		clearTimeout(ConentTime);
		ConentTime = null;
	}
}
//"查看网址"，查看引用页相关fun
function show_work_url()
{
	if(document.getElementById('work_url_parent').style.display=='none')
	{
		document.getElementById('work_url_parent').style.display='block';
		document.getElementById('work_cite_url_parent').style.display='none'
	}
	else
	{
		document.getElementById('work_url_parent').style.display='none';
	}
}
function show_work_cite_url()
{
	if(document.getElementById('work_cite_url_parent').style.display=='none')
	{
		document.getElementById('work_url_parent').style.display='none';
		document.getElementById('work_cite_url_parent').style.display='block'
	}
	else
	{
		document.getElementById('work_cite_url_parent').style.display='none'
	}
}
function close_work_all()
{
    document.getElementById('work_url_parent').style.display='none';
    document.getElementById('work_cite_url_parent').style.display='none'    
}
function set_boardData()
{
	window.clipboardData.setData('Text',$('work_url').value)
}
function go_work_cite_url()
{
	if($("work_cite_url").value!="")
	window.open($("work_cite_url").value)
}
function content_on_front()
{
    if(InfoNowCount==0)
    {
        alert("已经是第一条");
		return;
    }
    else
    {
		clear_time_out();
        InfoNowCount=InfoNowCount-1;
        $("info_now_count").innerText = InfoNowCount;
        set_drag_banner_name_state();
        set_drag_obj_left_for_count($('drag_banner'),$('drag_obj'),InfoNowCount,InfoAllCount);
		set_ctt_all_info();
    }
}
function content_on_next()
{
    if(InfoNowCount>=InfoAllCount-1)
    {
        alert("已经是最后一条")
		return
    }
    else
    {
		clear_time_out();
        InfoNowCount=InfoNowCount+1;
        $("info_now_count").innerText = InfoNowCount+1;
        set_drag_obj_left_for_count($('drag_banner'),$('drag_obj'),InfoNowCount,InfoAllCount);
		set_ctt_all_info();
    }
}
function content_open()
{	
	fn_open_file("for_content_open_file");
	fn_content_state('content_open');
	var content_id = get_variable("Content_TaskId");
	open_task_file(content_id);
	content_id = null;
}
function content_open_folder()
{
	fn_content_state("content_open_folder");
	var content_id = get_variable("Content_TaskId");
	open_task_folder(content_id);
	content_id = null;
}
function content_start()
{
	fn_content_state("content_start");
	var content_id = get_variable("Content_TaskId");
	start_task(content_id);
	set_ctt_all_info()
	content_id = null;
	
}
function content_pause()
{
	fn_content_state("content_pause");
	stop_task(get_variable("Content_TaskId"));
}
function content_delete()
{
	fn_content_state("content_delete");
	var content_id = get_variable("Content_TaskId");
	delete_task(content_id);
	window.frames["view"].outer_rebuild_list(REBUILD_ALL);
	top.update_recycle_ui();
	if(InfoAllCount==0||InfoAllCount==1)
	{
		on_content_close();
		content_id = null;
		return
	}
	var deleteid;
	InfoNowCount-1<=0?deleteid = InfoNowCount:deleteid=InfoNowCount-1
	set_content_info(true);
	content_id = null;
}
function content_speak()
{
	fn_content_state("content_speak");
	var task_id = get_variable("Content_TaskId");
	if(g_TaskInfo==null)
	{
		on_content_close();
		task_id = null;
		return;
	}
	if(g_TaskInfo[WorkType] == 0)
		var cid = g_TaskInfo[Cid];
	else
		var cid = g_TaskInfo[BtInfoId];
	var rc_info = get_resource_info(task_id);
	if(rc_info == null || rc_info.length < 3)
	{
		content_comment(task_id);
	}
	else
	{
		//window.open("http://content.gougou.com/content?cid="+cid);
		OpenGougouPage("http://wstatic.xunlei.com/content/" + cid + ".html");	// 2007/10/20
	}
	task_id = null;
	cid = null;
	rc_info = null;
}
function content_comment(_id)
{
	fn_content_state("content_comment");
	if(window.confirm("该资源还没有发布，你要马上发布吗？"))   
	{
		if(goodViewArray[InfoNowCount]==null)
		{
			on_content_close();
			return;
		}
		on_publish(_id);	
	} 
}
function bulid_commonly_work()
{
    get_commonly_work();
	ctt_fst_onfocus();
	bulid_commonly_work_for_time();
	set_res_bewrite_to_left_img(g_TaskInfo[Cid])
}
function bulid_commonly_work_for_time()
{
	ctt_info_cmly_show();
	if(ConentTime!=undefined)
	{
		g_TaskInfo = null;
		g_TaskInfo = get_task_info(get_variable("Content_TaskId"));
		if(g_TaskInfo==null)
			return;
	}
	if(old_g_TaskInfo == g_TaskInfo)
		return;
	else
	{
		old_g_TaskInfo = null;
		old_g_TaskInfo = g_TaskInfo;
	}
	var file_state = g_TaskInfo[FileState];
	teans_data()
	for(i=0;i<2;i++)
	{
		if(SetWorkArray[i][1]!= $(SetWorkArray[i][0]).innerText)
			$(SetWorkArray[i][0]).innerText = SetWorkArray[i][1];
	}
	for(i=2;i<8;i++)
	{
		if(g_TaskInfo[SetWorkArray[i][1]]!= $(SetWorkArray[i][0]).innerText)
			$(SetWorkArray[i][0]).innerText = g_TaskInfo[SetWorkArray[i][1]]
	}
	for(i=8;i<SetWorkArray.length;i++)
    {
        if(g_TaskInfo[SetWorkArray[i][1]]!= $(SetWorkArray[i][0]).innerText)
             $(SetWorkArray[i][0]).innerText = g_TaskInfo[SetWorkArray[i][1]]
    }
	mly_bt_set_buttion(file_state);
	if(file_state==11)
		$("file_name").className="file_name_click"
	else
		$("file_name").className="file_name_noclick"
	if($("li_3").className=="selected")
	{
		$("content_mask1").style.display="none";
		$("content_mask2").style.display="none";
		clear_time_out()	
	}
	else
	{
		if(file_state<=2)
		{
			if($("content_mask1").style.display!="block")
				$("content_mask1").style.display="block"
			if($("content_mask2").style.display!="none")
				$("content_mask2").style.display="none"
			ConentTime = setTimeout("bulid_commonly_work_for_time()",1000)	
		}
		else if(file_state==10||file_state==12)
		{
			$("content_mask1").style.display="none";
			$("content_mask2").style.display="block";
			clear_time_out()
		}
		else
		{
			$("content_mask1").style.display="none"
			$("content_mask2").style.display="none"
			clear_time_out()
		}
	}
	file_state = null;
}
function get_commonly_work()
{
	SetWorkArray = null;
	SetWorkArray = [["info_all_count",InfoAllCount],["info_now_count",InfoNowCount+1],["file_name",FileName],["file_name2",FileName],["file_size",FileSize],["file_type",FileType],["save_catalog",SaveCatalog],["work_url",WorkUrl],["work_cite_url",WorkCiteUrl],["file_loading",FileLoading],["average_rapidity",AverageRapidity],["start_time",StartTime],["time_ed",TimeEd],["complete_time",CompleteTime],["remnant_time",RemnantTime],["down_load_ed",DownLoadEd],["work_ing_resource",WorkIngResource],["work_all_resource",WorkAllResource]]
}
function bulid_bt_work()
{
	get_bt_work();
	bulid_bt_work_for_time();
	set_res_bt_to_left_img(g_TaskInfo[BtInfoId]);
	for(i=0;i<g_TaskInfo[BtFileCount]*3;i+=3)
	{
		var bt_td3_id = g_TaskInfo[BtTrackerCount+i+3];
		if(bt_td3_id == 2)
		{
			ctt_secd_onfocus();
			return
		}
		else
		{
			ctt_fst_onfocus()
		}
		bt_td3_id = null;
	}
}
function bulid_bt_work_for_time()
{
	try
	{
		g_TaskInfo = null;
		g_TaskInfo = get_task_info(get_variable("Content_TaskId"));
	}
	catch(e){}
	if(g_TaskInfo==null)
	{
		on_content_close();
		return;
	}
	if(old_g_TaskInfo == g_TaskInfo)
		return;
	else
	{
		old_g_TaskInfo = null;
		old_g_TaskInfo = g_TaskInfo;
	}
	bt_teans_data();
	
	for(i=0;i<2;i++)
	{
		if(SetWorkArray[i][1]!= $(SetWorkArray[i][0]).innerText)
			$(SetWorkArray[i][0]).innerText = SetWorkArray[i][1];
	}
	for(i=2;i<8;i++)
	{
		if(g_TaskInfo[SetWorkArray[i][1]]!= $(SetWorkArray[i][0]).innerText)
			$(SetWorkArray[i][0]).innerText = g_TaskInfo[SetWorkArray[i][1]]
	}
	for(i=8;i<SetWorkArray.length;i++)
	{
		if(g_TaskInfo[SetWorkArray[i][1]]!= $(SetWorkArray[i][0]).innerText)
			$(SetWorkArray[i][0]).innerText = g_TaskInfo[SetWorkArray[i][1]]
	}
	bt_table_list_tbody = document.getElementById("bt_table_list").firstChild;
	BT_NODES = document.getElementById("bt_table_list").firstChild;
	document.getElementById("bt_table_list").removeChild(BT_NODES);
	T_body = document.createElement("tbody");

	var T_body_fst_tr = document.createElement("tr");
	var T_body_fst_td1 = document.createElement("td");
	var T_body_fst_td2 = document.createElement("td");
	var T_body_fst_td3 = document.createElement("td");
	T_body_fst_td1.innerText = "文件名";
	T_body_fst_td2.innerText = "完成进度";
	T_body_fst_td3.innerText = "操作";
	T_body_fst_td1.className = "table_lise_tr";
	T_body_fst_td2.width = "80px";
	T_body_fst_tr.appendChild(T_body_fst_td1);
	T_body_fst_tr.appendChild(T_body_fst_td2);
	T_body_fst_tr.appendChild(T_body_fst_td3);
	T_body.appendChild(T_body_fst_tr);
	
	document.getElementById("bt_table_list").appendChild(T_body);
	for(i=0;i<g_TaskInfo[BtFileCount]*3;i+=3)
	{
		var bt_tr = document.createElement("tr");
		var bt_td1 = document.createElement("td");
		bt_td1.className = "table_lise_tr";
		var bt_td2 = document.createElement("td");
		var bt_td3 = document.createElement("td");

		
		bt_td1.innerText = g_TaskInfo[BtTrackerCount+i+1];
		bt_td2.innerText = float_to_fixed(100*g_TaskInfo[BtTrackerCount+i+2],1)+"%";
		var bt_td3_id = parseInt(g_TaskInfo[BtTrackerCount+i+3]);
		var bt_td3_id_load = g_TaskInfo[BtTrackerCount+i+2]
		var _id = get_variable("Content_TaskId");
		if(bt_td3_id == 2&&bt_td3_id_load==1)
		{
			bt_td3.innerHTML = "<a href=javascript:open_bt_task_file('"+_id+"','"+i/3+"')>打开</a>"
		}
		else
		{
			bt_td3.innerHTML = "<a  style='color:#eee'>打开</a>"
		}
		bt_tr.appendChild(bt_td1);
		bt_tr.appendChild(bt_td2);
		bt_tr.appendChild(bt_td3);
		document.getElementById("bt_table_list").firstChild.appendChild(bt_tr);
		bt_td3_id = null;
		_id = null;
		bt_tr = null;
		bt_td1 = null ;
		bt_td2 = null;
		bt_td3 = null;
	}
	T_body_fst_tr = null;
	T_body_fst_td1 = null;
	T_body_fst_td2 = null;
	T_body_fst_td3 = null;

	var file_state = g_TaskInfo[FileState];
	if(file_state==11)
		$("file_name").className="file_name_click"
	else
		$("file_name").className="file_name_noclick"
	mly_bt_set_buttion(file_state);
	if($("li_3").className=="selected")
	{
		$("content_mask1").style.display="none";
		$("content_mask2").style.display="none";
		clear_time_out()	
	}
	else
	{
		if(file_state<=2||file_state==7)
		{
			if($("content_mask1").style.display!="block")
			$("content_mask1").style.display="block";
			if($("content_mask2").style.display!="none")
			$("content_mask2").style.display="none";
			clear_time_out();
			ConentTime = setTimeout("bulid_bt_work_for_time()",1000)	
		}
		else if(file_state==10||file_state==12)
		{
			$("content_mask1").style.display="none";
			$("content_mask2").style.display="block";
			clear_time_out()
		}
		else
		{
			$("content_mask1").style.display="none";
			$("content_mask2").style.display="none";
			clear_time_out()
		}
	}
	file_state = null;
}
function get_bt_work()
{
	SetWorkArray = null;
    SetWorkArray = [["info_all_count",InfoAllCount],["info_now_count",InfoNowCount+1],["file_name",BtTitle],["file_name2",BtTitle],["file_size",FileSize],["file_type",FileType],["save_catalog",SaveCatalog],["work_url",WorkUrl],["work_cite_url",WorkCiteUrl],["bt_down_load_plan",BtDownLoadPlan],["bt_average_rapidity",AverageRapidity],["bt_health_size",BtHealthSize],["bt_remnant_time",RemnantTime],["bt_up_sed",BtUpSed],["bt_down_load_ed",DownLoadEd],["bt_start_time",StartTime],["bt_time_ed",TimeEd],["bt_complete_time",CompleteTime]]}

function set_res_bewrite_to_left_img(cid)
{
	commonly_after_cid = cid;
	set_res_bewrite_to_left_img_after()
	setTimeout("set_res_null()",6000)
}
function set_res_null()
{
	if($("ajax_file_name").innerText == "正在载入资源名称..."||$("res_for_com").innerText == "正在载入资源描述...")
	{
		$("ajax_file_name").innerText = "无资源名称";
		$("res_for_com").innerText = "无资源描述"	
	}
}
function set_res_bewrite_to_left_img_after()
{
	var cid = commonly_after_cid;
	$("ajax_file_name").innerText = "正在载入资源名称...";
	$("res_for_com").innerText = "正在载入资源描述...";
	FileTypeCount = "all";
	AjaxFileType = g_TaskInfo[FileType].toUpperCase();
	AJF = AjaxFileType;
	
	if(AJF == "MP3"||AJF == "WMA"||AJF == "WAV"||AJF == "AA"||AJF == "AAC"||AJF == "A52"||AJF == "AC3"||AJF == "AIF"||AJF == "AIFC"||AJF == "AIFF"||AJF == "AU"||AJF == "SND"||AJF == "CDA"||AJF == "CUE"||AJF == "DTS"||AJF == "FLA"||AJF == "FLAC"||AJF == "MID"||AJF == "MIDI"||AJF == "RMI"||AJF == "FAR"||AJF == "IT"||AJF == "MOD"||AJF == "MTM"||AJF == "S3M"||AJF == "STM"||AJF == "UMX"||AJF == "XM"||AJF == "APE"||AJF == "MAC"||AJF == "MP1"||AJF == "MP2"||AJF == "MP3"||AJF == "PRO"||AJF == "MPA"||AJF == "MA4"||AJF == "MP+"||AJF == "MPC"||AJF == "RA"||AJF == "OGG"||AJF == "TTA"||AJF == "M3U"||AJF == "M3U8"||AJF == "TTBL"||AJF == "TTPL")
	{
		AjaxImageSrc = "images/left_info_music.gif";
	}
	else if(AJF == "MPEG"||AJF == "MPG"||AJF == "MPGA"||AJF == "ASF"||AJF == "AVI"||AJF == "RM"||AJF == "RMVB"||AJF == "WMP"||AJF == "WMV"||AJF == "3GP"||AJF == "WM"||AJF == "MKV"||AJF == "OGM"||AJF == "MP4"||AJF == "M4V"||AJF == "M4P"||AJF == "M4B"||AJF == "TP"||AJF == "TS"||AJF == "TPR"||AJF == "PVA"||AJF == "PSS"||AJF == "VOB"||AJF == "MPE"||AJF == "RAM"||AJF == "RPM"||AJF == "REALPIX"||AJF == "RT"||AJF == "SMI"||AJF == "SMIL"||AJF == "AIF"||AJF == "AIFF"||AJF == "AIFC"||AJF == "AMR"||AJF == "3GPP"||AJF == "3G2"||AJF == "QT"||AJF == "MOV"||AJF == "FLV"||AJF == "SWF"||AJF == "M1V"||AJF == "M2V"||AJF == "PMP"||AJF == "SMK"||AJF == "BIK"||AJF == "RAT"||AJF == "DVD"||AJF == "VG2"||AJF == "IVF"||AJF == "VP6"||AJF == "D2V"||AJF == "MOD"||AJF == "M2P"||AJF == "VID"||AJF == "PMP2"||AJF == "ASX"||AJF == "PLS"||AJF == "WVX"||AJF == "WAX"||AJF == "WMX"||AJF == "MPCPL")
	{
		AjaxImageSrc = "images/left_info_movie.gif" ;
		FileTypeCount = "movie";
	}
	else if(AJF == "EXE"||AJF == "ISO"||AJF == "RAR"||AJF == "ZIP"||AJF == "JAR"||AJF == "MSI")
	{
		AjaxImageSrc = "images/left_info_soft_good.gif"
	}
	else
	{
		AjaxImageSrc = "images/left_info_unknow.gif"
	}
	if(g_Virus==false)
		$("left_info_box_img").src = AjaxImageSrc;
	//重要：分辨是否是本地
	if(window.location.href.indexOf("my.xunlei.com")==-1)
	{
		$("ajax_file_name").innerText = "无资源名称";
		$("res_for_com").innerHTML = "无资源描述";	
		return
	}
	$("left_info_box_img").style.cursor="pointer";
	$("left_info_box_img").onclick=function(){window.open(getViewMovieSrc(cid))};
	json_url = getResourceUrlFromCID(g_TaskInfo[Cid]);
	ifr_json = document.createElement("iframe");
	ifr_json.style.display = "none"
	document.body.appendChild(ifr_json);
	ifr_json.id = "ifr_json_id2";
	ifr_json.src = json_url;
	ifr_json.attachEvent('onload',function()
	{try
		{
		if(window.frames['ifr_json_id2'].jsonObj!=null)
		{
			AjaxTxt =  window.frames['ifr_json_id2'].jsonObj.description;
			AjaxObj =  window.frames['ifr_json_id2'].jsonObj;
			AjaxJsonV = Number(AjaxObj.virus_num);
			$("ajax_file_name").innerText = AjaxObj.name;
			report_type = AjaxObj.report_type;
			characteristic = AjaxObj.characteristic?AjaxObj.characteristic:0;
			have_preview_video = AjaxObj.have_preview_video?AjaxObj.have_preview_video:0;
			g_taskname = window.frames['ifr_json_id2'].jsonObj.name.substring(0,24).replace(/<br \/>/g,'').replace(/<p>/g,'');
			g_taskDescription = window.frames['ifr_json_id2'].jsonObj.description.substring(0,32).replace(/<br \/>/g,'').replace(/<p>/g,'');
			g_taskscore = window.frames['ifr_json_id2'].jsonObj.mark;
		}
		else
		{
			AjaxJsonV = 0;
			AjaxTxt="无资源描述";
			$("ajax_file_name").innerText = "无资源名称";
			var g_taskscore = -1;
			characteristic = 0;
			have_preview_video = 0;
		}
		if(characteristic==2||have_preview_video==2)
		{
			if(FileTypeCount == "movie"&&g_TaskInfo[Cid] != 000000000000000000000000000000)
			{
				AjaxImageSrc = getPicPath(g_TaskInfo[Cid],2);
			}
		}
		else
		{
			if(AjaxJsonV>0)
			{
				AjaxImageSrc = "images/left_info_soft_bad.gif";
			}
		}
		if(g_Virus==false)
		{
			$("left_info_box_img").src = AjaxImageSrc;
			$("left_info_box_img").onerror = function(){this.src = "images/left_info_movie.gif"
		}
		set_resourse_for_com();
		}

		top.document.body.removeChild(ifr_json);
		thunder_server.ReadWriteResourceInfo(cid,g_taskscore+"{\r*\r}"+g_taskname+"{\r*\r}"+g_taskDescription+"{\r*\r}");
		top.close_iframe();
		}
		catch(e){}
	});
	on_p4p_load();	
}
function set_res_bt_to_left_img(cid)
{
	bt_after_cid = cid;
	set_res_bt_to_left_img_after()
	setTimeout("set_res_null()",6000)
}
function set_res_bt_to_left_img_after()
{
	var cid = bt_after_cid;
	$("ajax_file_name").innerText = "正在载入资源名称...";
	$("res_for_com").innerText = "正在载入资源描述...";
	var ifr_json = document.createElement("iframe");
	ifr_json.style.display = "none";
	ifr_json.id = "ifr_json_id";
	if(g_Virus==false)
	{
		AjaxImageSrc = "images/left_info_bt.gif";
		$("left_info_box_img").src = AjaxImageSrc;
	}
	//重要：分辨是否是本地
	if(window.location.href.indexOf("my.xunlei.com")==-1)
	{
		$("ajax_file_name").innerText = "无资源名称";
		$("res_for_com").innerHTML = "无资源描述";	
		return
	}
	json_url =  getResourceUrlFromCID(cid);
	document.body.appendChild(ifr_json);	
	ifr_json.src = json_url;
	$("left_info_box_img").onclick=function(){return false}
	ifr_json.attachEvent('onload',function()
	{
		if(window.frames['ifr_json_id'].jsonObj!=null)
		{
		AjaxTxt =  window.frames['ifr_json_id'].jsonObj.description
		AjaxObj =  window.frames['ifr_json_id'].jsonObj;
		AjaxJsonV = Number(AjaxObj.virus_num);
		$("ajax_file_name").innerText = AjaxObj.name;
		report_type = AjaxObj.report_type;
		characteristic = AjaxObj.characteristic?AjaxObj.characteristic:0;
		have_preview_video = AjaxObj.have_preview_video?AjaxObj.have_preview_video:0;
		var g_taskname = window.frames['ifr_json_id'].jsonObj.name.substring(0,24).replace(/<br \/>/g,'').replace(/<p>/g,'');
		var g_taskDescription = window.frames['ifr_json_id'].jsonObj.description.substring(0,32).replace(/<br \/>/g,'').replace(/<p>/g,'');
		var g_taskscore = window.frames['ifr_json_id'].jsonObj.mark;
		}
		else
		{
		AjaxTxt="无资源描述";
		var g_taskscore = -1;
		characteristic = 0;
		have_preview_video = 0;
		}
		if(characteristic==2||have_preview_video==2)
		{
			//AjaxImageSrc = getPicPath(g_TaskInfo[BtInfoId])+"/02_b.jpg";
			AjaxImageSrc = getPicPath(g_TaskInfo[BtInfoId],1);
			$("left_info_box_img").style.cursor="pointer";
			$("left_info_box_img").onclick=function(){window.open(getViewMovieSrc(cid))}				
		}
		else
		{
			if(AjaxJsonV>0)
			{
				AjaxImageSrc = "images/left_info_soft_bad.gif";
			}
			else
			{
			}
		}
		if(g_Virus==false)
			$("left_info_box_img").src = AjaxImageSrc;
		set_resourse_for_com();
		var info = g_taskscore+"{\r*\r}"+g_taskname+"{\r*\r}"+g_taskDescription+"{\r*\r}";
		thunder_server.ReadWriteResourceInfo(cid,info);
		try{top.document.body.removeChild(ifr_json);}catch(e){}
		top.close_iframe();
		}
	)
	$("left_info_box_img").onerror = function(){$("left_info_box_img").src = "images/left_info_bt.gif"}
	on_p4p_load();
}
function set_resourse_for_com()
{
    if(AjaxTxt==""||AjaxTxt==null)
    $("res_for_com").innerHTML = "无资源描述";	
    else
	$("res_for_com").innerHTML = AjaxTxt;
}
function set_resourse_for_clict()
{
    if(AjaxTxt!="")
	$("res_for_com").innerHTML = AjaxTxt;
    else
    $("res_for_com").innerHTML = "没有相关资源描述";

}
function getResourceUrlFromCID(sCID){
	var iParentDir = parseInt(sCID.substr(0, 2), 16);
	var iChildDir = parseInt(sCID.substr(2, 2), 16);
	var iServerIndex = Math.floor(iParentDir/16);
	var sUrl = "http://t"+iServerIndex+".rstatic.xunlei.com/resource_data/"+iParentDir+"/"+iChildDir+"/"+sCID+".htm"; 
	return sUrl
} 
function getPicPath(cid,_cnt)
{
	var Str = getViewMovieSrcFaz(cid);
	//Aj_format = Aj_format.toLowerCase();
	//if(Aj_format=='rm')
	//Aj_format='rmvb';
	//var StrPath = Str+'/s0'+_cnt+'.'+Aj_format+'.jpg';
	var StrPath = Str+'/s0'+_cnt+'.jpg';
	return StrPath
}
function getViewMovieSrcFaz(cid)
{
	var lg=cid.length;  
	var returnStr="http://vidview"+cid.substring(0,1)+".xunlei.com/"+cid.substring(0,2)+"/"+cid.substring(lg-2,lg)+"/"+cid;
	return returnStr;
}
function content_move_time_down()
{
    if(move_timeer!=null)
    {clearInterval(move_timeer);}
    move_timeer = setInterval("content_move_time_down_time()",30)
}
function content_move_time_down_time()
{
	var res_info_cnt = $("res_for_com").style.marginTop;
	var res_info_cnt = -parseInt(res_info_cnt.substring(0,res_info_cnt.length-2));
	if(res_info_cnt>=$("res_for_com").offsetHeight - 108)
	{
		clearInterval(move_timeer);
	}
	else
	{
		$("res_for_com").style.marginTop= Number($("res_for_com").style.marginTop.substring(0,$("res_for_com").style.marginTop.length-2))-1+"px"
	}
	res_info_cnt = null;
}
function content_move_time_up()
{
    if(move_timeer!=null)
    {clearInterval(move_timeer);}
    move_timeer = setInterval("content_move_time_up_time()",30)
}
function content_move_time_up_time()
{
	var res_info_cnt = $("res_for_com").style.marginTop;
	var res_info_cnt = -parseInt(res_info_cnt.substring(0,res_info_cnt.length-2));
	if(res_info_cnt<=0)
	{
		clearInterval(move_timeer);
	}
	else
	{
    $("res_for_com").style.marginTop= Number($("res_for_com").style.marginTop.substring(0,$("res_for_com").style.marginTop.length-2))+1+"px"
	}
	res_info_cnt = null;
}
function content_out()
{if(move_timeer!=null)
   {clearInterval(move_timeer);}
}
function teans_data()
{
	 g_TaskInfo[AverageRapidity] = number_to_description(g_TaskInfo[AverageRapidity], 1, false) + "B/s";
	 g_TaskInfo[FileSize] = number_to_description(g_TaskInfo[FileSize],2,true) + "B";
	 g_TaskInfo[FileLoading] = float_to_fixed(100*g_TaskInfo[FileLoading],2)+"%";
	 g_TaskInfo[TimeEd] = format_number_to_time(g_TaskInfo[TimeEd]);
	 g_TaskInfo[RemnantTime] = format_number_to_time(g_TaskInfo[RemnantTime]);
	 g_TaskInfo[DownLoadEd] = number_to_description(g_TaskInfo[DownLoadEd],2,true) + "B";
}
function bt_teans_data()
 {
	 g_TaskInfo[BtDownLoadPlan] = float_to_fixed(100*g_TaskInfo[BtDownLoadPlan],2)+"%";
	 g_TaskInfo[BtFileUpload] = number_to_description(g_TaskInfo[BtFileUpload],2,true) + "B";
	 g_TaskInfo[FileSize] = number_to_description(g_TaskInfo[FileSize],2,true) + "B";
	 g_TaskInfo[FileType] ="BT任务";
	 g_TaskInfo[BtHealthSize] = g_TaskInfo[BtHealthSize]+"%";
	 g_TaskInfo[BtUpSed] = number_to_description(parseInt(g_TaskInfo[BtUpSed]),1,false) + "B/s";
	 g_TaskInfo[AverageRapidity] = number_to_description(parseInt(g_TaskInfo[AverageRapidity]),1,false) + "B/s";
	 g_TaskInfo[TimeEd] = format_number_to_time(g_TaskInfo[TimeEd]);
	 if(g_TaskInfo[FileState]==7||g_TaskInfo[FileState]==11)
	 g_TaskInfo[RemnantTime]="-/-"
	 else
	 g_TaskInfo[RemnantTime] = format_number_to_time(g_TaskInfo[RemnantTime]);
	 g_TaskInfo[DownLoadEd] = number_to_description(g_TaskInfo[DownLoadEd],2,true) + "B";
}
function format_number_to_time(_time)
{
	if(_time=="0")
	{
		return "-/-"
	}
	else
	{
		var h,m,s;
		var MinMilli = 60;
		var HrMilli = MinMilli * 60;
		var min = _time%HrMilli;
		h = (_time - min)/HrMilli;
		if(h <10) h="0"+h;
		
		_time = min;
		m = (_time - _time%MinMilli)/60;
		if(m<10)  m ="0" +m;
		
		s = _time%60;
		if(s<10) s ="0"+s;
			return  h+ ":" + m+ ":" + s ;
	}
}
function format_time(_time)
{
	if(_time < 1000)
		return "";
	var now = new Date(_time*1000);
	var year = now.getYear();
	var mon = now.getMonth()+1;
	if(mon <=9) 
		mon = "0"+ mon;
	var day =now.getDate();
	if(day <=9) 
		day = "0" + day;
	var hour=now.getHours();
	if(hour<=9) 
		hour="0"+hour;
	var mi = now.getMinutes();
	if(mi <= 9) 
		mi="0"+mi;
	var sec=now.getSeconds();
	if(sec <= 9) 
		sec="0"+sec;
	return  (year+ "-" +mon + "-" + day + " "+ hour+":"+mi+":"+sec);
}
function content_name_show()
{
	if($("file_name2").offsetHeight>30)
	{
		$("file_name2").style.visibility = "collapse"
	}	
}
function content_name_show()
{
	$("file_name2").style.display = "block"
	
}
function content_name_close()
{
	$("file_name2").style.display = "none"
	
}
function on_publish(_id)
{
	var login_staatus = get_login_status();
	if(login_staatus != LoginStatus_LoginOkay)
	{
		alert("您还没有登陆雷区，请先登录才能使用该功能！");
		return;
	}
	var task = get_task_info(_id);
	if (task == null)
	{
		alert("获取任务信息失败！");
		return;
	}
	if(task[FileState]==11||task[FileState]==7)
	{
		var cid = task[18];
		var reg = /0{40}/g;	
		if (reg.test(cid) == true)
		{
			alert("该资源数据异常，无法发布！");
			return;
		}
		update_resource_info(_id);
		alert(_id)
		set_variable("PublishTaskId", _id);
		set_browser_window_data("http://my.xunlei.com/publish_container.htm", "资源发布");
		//setTimeout("show_browser_window()", 3000);
	}
	else
	{
		alert("任务还未完成，请下载完成后再发布！");
		return;
	}
}
function content_download_again()
{
	download_again(get_variable("Content_TaskId"));
	set_ctt_all_info()
}
function mly_bt_set_buttion(file_state)
{
	if(_old_file_state==file_state&&ConentTime!=null)
	{
	}
	else
	{
		if($("content_button_td").firstChild)
		{
			$("content_back").appendChild($("content_button_td").firstChild)
		}
		else{}
		if($("li_3").className=="selected")
		{
			$("content_button_td").appendChild($("content_huanyuan_complete"));
			$("content_button_td_bottom").style.display = "none";
		}
		else{
			if(file_state==7||file_state==11)
			{
				$("content_button_td").appendChild($("content_complete"));	
				if(	thunder_server.GetTaskFileStatus(get_variable("Content_TaskId"))==0)
				{
					$("content_back").appendChild($("content_button_td").firstChild);
					$("content_button_td_bottom").style.display = "block"
				}
				else{$("content_button_td_bottom").style.display = "none"}
			}	
			else
			{
				$("content_button_td").appendChild($("content_no_complete"));
				$("content_button_td_bottom").style.display = "none";
			}
		}
		_old_file_state = file_state;
	}
}
function content_rev_delete()
{
	var _id = g_TaskInfo[WorkId]
	var delfile = 0;
	var ret = query_delete_task()
	if (ret == 2)
	delfile = 1;
	else if(ret == 0)
	return;
	thunder_server.DeleteTask(_id,delfile);	
	window.frames["view"].outer_rebuild_list(REBUILD_ALL);
	top.update_recycle_ui();
	if(InfoAllCount==0||InfoAllCount==1)
	{
		on_content_close();
		return
	}
	var deleteid;
	InfoNowCount-1<=0?deleteid = InfoNowCount:deleteid=InfoNowCount-1
	set_content_info();
	
}
function content_rev()
{
	var _id = g_TaskInfo[WorkId];
	thunder_server.RevertTask(_id);
	window.frames["view"].outer_rebuild_list(REBUILD_ALL);
	top.update_recycle_ui();
	if(InfoAllCount==1)
	{
		on_content_close();
		return
	}
	var deleteid;
	InfoNowCount-1<=0?deleteid = InfoNowCount:deleteid=InfoNowCount-1
	set_variable("Content_TaskId",goodViewArray[deleteid].id);
	set_content_info();
	
}
function content_tt_click(s_obj,t_obj,f_obj_div)
{
	if(f_obj_div.innerText=='+')
	{
		s_obj.style.display = 'block';
		t_obj.style.display = 'block';
		f_obj_div.innerText='-';
		$("res_for_com_box").style.height = "145px"
		CountTtClick = true;
	}
	else
	{
		s_obj.style.display = 'none';
		t_obj.style.display = 'none';
		f_obj_div.innerText='+';
		CountTtClick = false;
		$("res_for_com_box").style.height = "189px"
	}	
}
function content_tt_load(s_obj,t_obj,f_obj_div)
{
	if(CountTtClick == true)
	{
		s_obj.style.display = 'block';
		t_obj.style.display = 'block';
		f_obj_div.innerText='-'
		$("res_for_com_box").style.height = "145px"
	}
	else
	{
		s_obj.style.display  = 'none';
		t_obj.style.display  = 'none';
		f_obj_div.innerText='+';
		$("res_for_com_box").style.height = "189px"
	}
	
}
function ctt_fst_onfocus()
{
	if(g_TaskInfo==null)
		{
			on_content_close();
			return;
		}
	if(g_TaskInfo[WorkType] == 0)
	{
		$("lft_info_title_empty").className = "lft_info_title_empty";
	}
	else
	{
		$("content_file_list").style.display  = "block";
		$("content_des_txt").className = "fst_focus";

		$("content_des_txt").runtimeStyle.borderBottomColor = $("content_des_txt").style.backgroundColor;
		
		$("content_file_list").className  = "secd_unfocus";
		$("content_file_list").runtimeStyle.borderBottomColor='';

		$("lft_info_bt_inf").style.display = "block";
		$("lft_info_cmy_inf").style.display = "none";
		$("lft_info_com").style.display = "block";
		$("lft_inf_bt_list").style.display = "none";
		$("lft_info_title_empty").className = "lft_info_title_empty_the2show";	
	}
}
function ctt_secd_onfocus()
{
	$("content_file_list").style.display  = "block";

	$("content_des_txt").className = "fst_unfocus"	
	$("content_des_txt").runtimeStyle.borderBottomColor = '';

	$("content_file_list").className  = "secd_focus";
	$("content_file_list").runtimeStyle.borderBottomColor	= $("content_file_list").style.backgroundColor;

	$("lft_info_bt_inf").style.display = "none";
	$("lft_info_cmy_inf").style.display = "none";
	$("lft_info_com").style.display = "none";
    $("lft_inf_bt_list").style.display = "block";
	$("lft_info_title_empty").className = "lft_info_title_empty_the2show";	

}
function ctt_info_cmly_show()
{

	$("lft_info_cmy_inf").style.display = "block";
	$("lft_info_com").style.display = "block";
	$("content_des_txt").className = "fst_focus"
	$("content_file_list").style.display = "none";
	$("lft_info_bt_inf").style.display = "none";
    $("lft_inf_bt_list").style.display = "none";
}
function file_name_onclick(obj)
{
	if(obj.className=="file_name_click")
	{
		content_open();
	}
}
//右边IFRAME
function on_p4p_load()
{
	clearTimeout(p4p_time);
	p4p_time = setTimeout("fill_task_data()",3000);
}
function fill_task_data()
{
	var g_LastCid = null;
	var cid;
	if(g_TaskInfo[WorkType] == 0)
		cid =g_TaskInfo[Cid] ;
	else
		cid =g_TaskInfo[BtInfoId] ;
	setMyCookie("file_cid",cid);
	try
	{
		var jumpkey = thunder_server.GetJumpKey();
	}
	catch(e){};
	setMyCookie("login_key",jumpkey);
	//$("p4pcon").src = "http://recommend.xunlei.com/client_webxl.html"
}
function getViewMovieSrc(cid)
{
	var src = "http://content.gougou.com/content?cid="+cid+"&pvfrom=5";
	return src
}
