var objAjax=new JAjax();
function statistics(){
	var nowPage=1;
	var pageSize=13;
	var pageCount=0;
	var selArray=new Array();
}
statistics.prototype.selDate=function(thisObj){//选择时间,查看信息
	var d=openSelectDate("../../");
	if(d!="" & d!=null&typeof d!="undefined"){  
		if(thisObj.type=="button"){                  
			thisObj.previousSibling.value=d;
			this.nowPage=1;
			this.create();
		}
	}
}  
statistics.prototype.checkClick=function(thisObj){//选择时间,查看信息
	this.nowPage=1;
	this.create();
}
statistics.prototype.loadPage=function(){//系统加载时执行该程序
	var tools=new toolsClass();
	tools.add("","查看采用文章","editorDate.checkDate()","查看采用文章");
	tools.add("","生成Excel","editorDate.runExcel()","生成Excel");
	tools.create(toolsDiv);	
	var dt=new Date();		
	var nowDateSystem=dt.toLocaleString();
	var index=nowDateSystem.indexOf("月");
	var indexD=nowDateSystem.indexOf("日");
	$("selectTime").value=nowDateSystem.substring(0,4)+"-"+(nowDateSystem.substring(5,index)-1)+"-"+nowDateSystem.substring(index+1,indexD);         
	writeFettleLeft("提示:用鼠标选择行,然后进行相应的操作"); //状态栏提示
	this.nowPage=1;
	this.pageSize=13;//每页的大小
	this.create(); 
	//loadBodyclick();
}
statistics.prototype.checkDate=function(){//查看文章信息
	if(this.selArray){
		if(this.selArray.length>0){
			var signUser="";
			for(var i=0;i<this.selArray.length;i++){
				signUser+=this.selArray[i].id+c1;
			}
			if(signUser.indexOf(c1)>-1){
				signUser=signUser.substring(0,signUser.lastIndexOf(c1));
				var objnum=parent.win.objNum;
				par="wNum="+objnum+"&signUser="+signUser+"&nowTime="+$("selectTime").value;
				parent.win.pCreate("p-showArticle",par,"",true);
			}
		}else{
			alert("请选择要查看的用户");	
		}
	}else{
		alert("当前无任务数据\r\n请点击选择进行查找");	
	}
}

statistics.prototype.runExcel=function(){//生成Excel
	if(this.selArray){
		if($("selectTime").value!=""&&$("selectTime").value!=null){
			var isShow=1;//不显示
			if(selectTime.nextSibling.nextSibling.checked){
				isShow=0;	
			}
			var objResponse=new JHttpResponse();
			objResponse.write("selDate",$("selectTime").value);	
			objResponse.write("isShow",isShow);	
			var out=objAjax.getText("post","statistics.aspx?type=runExcel",objResponse,null);
			if(out.indexOf(".xls")>-1){
				$("runExcel").href=out;
				$("runExcel").click();
			}else{
				alert(out)
			}
		}else{
			alert("非法进入");	
		}
	}else{
		alert("当前无任务数据\r\n请点击选择进行查找");	
	}
}

statistics.prototype.create=function(){//读取数据进行绑定
	var cTable=$("bodyDiv");//存放信息
	var divPages=$("divPages");//存放分页信息
	var selectTime=$("selectTime");//获取当前选择的时间
	if(selectTime.value==""&&selectTime.value==null){
		return;	
	}
	var isShow=1;//不显示
	if(selectTime.nextSibling.nextSibling.checked){
		isShow=0;	
	}
	var objResponse=new JHttpResponse();
	objResponse.write("nowPage",this.nowPage);	
    objResponse.write("pageSize",this.pageSize);
	objResponse.write("selTime",selectTime.value);
	objResponse.write("isShow",isShow);	
	var out=objAjax.getText("post","statistics.aspx?type=readDate",objResponse,null);
	if(out.indexOf(c3)>-1){
		this.selArray=new Array();
		out=out.split(c3);
		this.pageCount=out[1];//总页数
		this.saveDateArray=out[0].split(c2);
		if(cTable.childNodes.length>0){
			cTable.firstChild.removeNode(true);
		}
		divPages.innerHTML="";		
		var t=new createOurTitle();
		t.add("序号","text-align:center;","50");
		t.add("用户名","text-align:leftlpadding-left:5px;","300");
		t.add("发布数","text-align:center","95");
		t.add("采用数","text-align:center","95");
		t.add("采用率","text-align:center","95");
		t.table=cTable;
		t.create();
		var tr=null;
		for(var i=0;i<this.saveDateArray.length;i++){
			tr=cTable.insertRow();
			var tSplit=this.saveDateArray[i].split(c1);
			tr.setAttribute("id",tSplit[0]);
			for(var j=0;j<tSplit.length;j++){
				var createTD=tr.insertCell();
				if(j==0){
					createTD.style.cssText="text-align:center;height:23px;width:50px;";
					createTD.appendChild(document.createTextNode(i+1+(parseInt(this.nowPage)-1)*parseInt(this.pageSize)));
					createTD=tr.insertCell();
					createTD.style.cssText="text-align:left;padding-left:10px;height:23px;width:330px;";
					createTD.appendChild(document.createTextNode(tSplit[j]));
				}else if(j==tSplit.length-1){
					createTD.style.cssText="text-align:center;height:23px;width:95px;";
					createTD.appendChild(document.createTextNode(tSplit[j]));
					createTD=tr.insertCell();
					createTD.style.cssText="text-align:center;color:#FF0000;;height:23px;width:95px;";
					var persent=parseFloat(0).toFixed(3);
					if(parseInt(tSplit[1])>0){
						persent=parseFloat(tSplit[2]/tSplit[1]*100).toFixed(3);	
					}
					createTD.appendChild(document.createTextNode(persent+"%"));
				}else{
					createTD.style.cssText="text-align:center;height:23px;width:95px;";
					createTD.appendChild(document.createTextNode(tSplit[j]));
				}				
			}
			tr.onmouseover=function(){
			   for(var i=0;i<this.childNodes.length;i++){
					this.childNodes[i].className="listTitleOption_1Other";	
			   }
			}
			tr.onmouseout=function(){
			   var isBool=false;
			   for(var i=0;i<editorDate.selArray.length;i++){
					if(editorDate.selArray[i]==this){
						isBool=true;	
						break;
					}
			   }			  
			   if(isBool==false){
					for(var i=0;i<this.childNodes.length;i++){
						this.childNodes[i].className="listBodyOptionOther";	
					}
				}
			}
			tr.onclick=function(){
				var isBool=false;
				if(parseInt(this.childNodes[3].innerText)==0){
					return;	
				}
				if(editorDate.selArray==null||editorDate.selArray==""){
					editorDate.selArray=new Array();
					editorDate.selArray.push(this);
					return ;
				}
				for(var i=0;i<editorDate.selArray.length;i++){
					if(editorDate.selArray[i]==this){
							editorDate.selArray.splice(i,1);
							isBool=true;
							break;
					}
				}
				if(isBool==false){
					editorDate.selArray.push(this);
				}
			}
			tr.ondblclick=function(){
			try{
			       if(parseInt(this.childNodes[3].innerText)>0){
			            var objnum=parent.win.objNum;
				        par="wNum="+objnum+"&signUser="+this.childNodes[1].innerText+"&nowTime="+$("selectTime").value;
				        parent.win.pCreate("p-showArticle",par,"",true);
			       }
			   }
			   catch(e){}
			}
		}
		//分页写入开始
		var pages=parseInt(this.pageCount/this.pageSize);
		if(this.pageCount%this.pageSize>0){
			pages=pages+1;	
		}
		divPages.appendChild(document.createTextNode("一共有"+this.pageCount+"条,分"+pages+"页,第"+this.nowPage+"页"));
		
		var cPage=document.createElement("span");
		cPage.setAttribute("title","首  页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="首  页";	
		if(pages>1&&this.nowPage>1){
		   cPage.onclick=function(){
			   editorDate.nowPage=1;
			   editorDate.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage);
		
		cPage=document.createElement("span");
		cPage.setAttribute("title","下一页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="下一页";
		if(pages>1&&this.nowPage<pages){
		   cPage.onclick=function(){
			   editorDate.nowPage=parseInt(editorDate.nowPage)+1;
			   editorDate.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage);
		
		cPage=document.createElement("span");
		cPage.setAttribute("title","上一页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="上一页";
		if(pages>1&&this.nowPage>1){
		   cPage.onclick=function(){
			   editorDate.nowPage=parseInt(editorDate.nowPage)-1;
			   editorDate.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage)
		
		cPage=document.createElement("span");
		cPage.setAttribute("title","尾  页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="尾  页";
		if(pages>1&&this.nowPage<pages){
		   cPage.onclick=function(){
			   editorDate.nowPage=pages;
			   editorDate.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage)
		var runTime=document.createElement("span");
		runTime.style.cssText="color:#FF0000;padding-left:25px;"
		runTime.innerHTML="页面运行总时间"+out[2]+"毫秒";
		divPages.appendChild(runTime);
		
	}else{
		if(cTable.childNodes.length>0){
			cTable.firstChild.removeNode(true);
		}
		divPages.innerHTML="<p style='color:#FF0000;'>从"+$("selectTime").value+"到现在没有相应的信息</p>";		
	}
}