var pa = new Array();
var p;

	// 显示隐藏采集参数
	function modiDisp()
	{
		var ms = document.getElementById("modiSpan");
		var mt = document.getElementById("modiTable");
		if (mt.style.display=="none"){
			mt.style.display = "";
			ms.innerHTML = "隐藏采集参数";
		}else{
			mt.style.display = "none";
			ms.innerHTML = "显示采集参数";
		}
	}
	
	// 显示进度
	function dispState()
	{
		for(var i=0; i<pa.length; i++){
			var d=document.getElementById("st"+pa[i].id);
			if(d==null){
				continue;
			}
			if (!pa[i].doing){
				d.innerHTML="<font color='red'>未运行</font>";
			}else{
				var w = parseInt(pa[i].doneNum*200/pa[i].needDown);
				var str="需采集 "+ pa[i].needDown +" 条,已添加 "+ pa[i].newsNum +" 条,下载图片 "+ pa[i].imgNum +" 张";
				str+="<center style='font-size:12px;font-family:Arial;'><div style='width:200px; height:10px; border:1px #F7D4D4 solid;font-size:5px;' align='left'>";
				str+="<div style='width:"+ w +"px;height:10px;background:#4DADF4;'></div>";
				str+="</div>";
				str+=(pa[i].needDown==0 ? "100" : parseInt(pa[i].doneNum*100/pa[i].needDown)) + "%</center>";
				if (pa[i].endTime){
					var et=new Date(pa[i].endTime);
					var sd=new Date(et);
					sd.setMinutes(sd.getMinutes()+pa[i].interval);
					str+="上次完成时间 "+ getTimeString(et);
					if (pa[i].interval>0){
						str+=" 下次开始时间 "+ getTimeString(sd);
					}
				}
				if (pa[i].processing){
					str+=" <a href=\""+ pa[i].recentUrl +"\" target=\"_blank\">采集地址</a>";
				}
				if (pa[i].error.length>0){
					str+=" <a href=\"#\" title=\""+ pa[i].error.replace(/"/g,"&quot;").replace(/\[br]/g,"\r\n") +"\">错误</a>";
				}
				d.innerHTML=str;
			}
		}
	}
	
	function getTimeString(d)
	{
		var s="", n;
		n=d.getUTCHours();
		if (n<10){
			s+="0";
		}
		s+=n+":";
		n=d.getUTCMinutes();
		if (n<10){
			s+="0";
		}
		s+=n;
		return s;
	}
	
	function intervalWork()
	{
		var ids = "";
		var loop=false;	// 有循环采集的还需要循环
		for(var i=0;i<pa.length;i++){
			if(pa[i].doing){
				if (pa[i].interval>0 && pa[i].endTime){
					if (!loop){
						loop=true;
					}
					// 循环采集停止中暂时不取
					var now=new Date();
					var sd=new Date(pa[i].endTime);
					now.setUTCMinutes(now.getUTCMinutes()-timeOffset);
					sd.setUTCMinutes(sd.getUTCMinutes()+pa[i].interval);
//					myLabel.innerText=sd+"\r\n"+now+"\r\n"+pa[i].endTime;
					if (now<sd){
						continue;
					}
				}
				if (ids.length>0){
					ids+=",";
				}
				ids+=pa[i].id.toString();
			}
		}
		if (ids.length>0){
			iwms.ajSrc=null;
			$.post('admin_gathernews.aspx',{act:'ajax',cmd:'getState',ids:ids},function(r){
				pa=r;
				dispState();
			},'json');
		}else if (!loop){
			return;
		}else{
	//		alert('循环');
		}
		setTimeout("intervalWork()",3000);
	}