function loadTools(){
	var tools=new toolsClass();
	tools.add("","恢复","re.undel();re.unMenu()","恢复被删除的文件或栏目")
	tools.add("","删除","re.clearFile();re.clearMenu()","彻底清除数据")
	tools.add("","按ID排序","re.setOrder('id')","")
	tools.add("","按名称","re.setOrder('title')","")
	tools.add("","按删除日期","re.setOrder('delDate')","")
	tools.add("","刷新","location.reload()","刷新当前页面")
	tools.add("","清空回收站","re.clearAll()","彻底删除所有被放入回收站的数据")
	tools.create(toolsDiv)
}

function setWH(){
	
	
}



function reclaimClass(){
	this.page=1;  
	this.mPage
	var selectObj=new Array();
	var selectMenu=new Array();
	this.tempObj=null;
	var pList=null;
	var idList=null;
	var order="id";
	var orderType="desc";
	
	this.setOrder=function(field){
		order=field;
		if (orderType==""){
			orderType="desc";
		}else{
			orderType="";
		}
		 this.loadDelMenu(this.mPage);
		 this.loadDelFile(this.page);
	}
	
	this.loadDelMenu=function(inPage){ //加载被删除的栏目
		  if (inPage==null){inPage=1}
		  	selectObj.clear();
			selectMenu.clear();
			
		   menuData.innerHTML="";
		  var mOrder=order;
		  if (mOrder=="title"){
			  mOrder="mName";
		  } 
		  if (mOrder=="delDate" ){
			   mOrder="id";
		  }
		  var objResponse=new JHttpResponse();
		  objResponse.write("page",inPage);
		  objResponse.write("pageSize","20");
		  objResponse.write("order",mOrder+" "+orderType);
		  var out=objAjax.getText("post","reclaim.aspx?type=readDelMenu",objResponse,null);
		   //alert(out);
		   // return  null;
		  
		  out= comminute(out,c1,c2);  //分割数据
		  var page=out[0];
		  this.mPage=page[2];
		  // "MID,mName,AsTab,UpListID"
		  
		  //显示内容
		  var wData=new tabList();
		  pList=raadArray(out,3)
		  idList=raadArray(out,0);
		  wData.obj=menuData;
		  wData.rowid="delMenuRow_";         //行的ID
		  wData.rowClass="";                 //行的样式
		  wData.mode=1;                      //数据显示的格式
		  wData.add(idList,"","50");    //添加一列数据
		  wData.add(raadArray(out,1),"","150");    //添加一列数据
		  wData.add(pList,"","240");    //添加一列数据
		  wData.add(raadArray(out,2),"","60");    //添加一列数据
		  wData.addid(raadArray(out,0));     //添加行标识
		  wData.create();		  
		  //内容显示完成
		  
		  //显示分页
		  var wPage=new outPage();
		  wPage.obj=menuPageDiv;
		  wPage.pageArray=page;
		  wPage.run="re.loadDelMenu";
		  wPage.create();
		  //分页显示完
		  
		  //alert(out);
		  if (idList.length==0){
			   return  null;
		  }
		  
		  var l=delMenuRow_.length;
		  if (l==null){
			   delMenuRow_.sel="0";
			  var str=delMenuRow__2.innerHTML;
			  delMenuRow__2.innerHTML=str.replace(/(\()([^\n]*)(\))/g,"<font color='#c0c0c0'>$1$2$3</font>")
			  
			  delMenuRow_.onmouseover=function(){
				  re.tempObj=this;
				  if (this.className==""){
					   this.className="selectRow";
				  }
				  
			  }
			  delMenuRow_.onmouseout=function(){
				  re.tempObj=null;
				  if (this.sel=="0"){
				  		this.className="";
				  }
			  }
			  delMenuRow_.onclick=function(){
				  if (this.sel=="0"){
					  this.sel="1";
					  this.className="selectRow";
				  }else{
					  this.sel="0";
					  this.className="";
				  }
				  setTimeout("re.addSelectMenu()",10);
			  }
			  return null;
			  
		  }
		  for (var i=0;i<l;i++){
			  delMenuRow_[i].sel="0";
			  var str=delMenuRow__2[i].innerHTML;
			  delMenuRow__2[i].innerHTML=str.replace(/(\()([^\n]*)(\))/g,"<font color='#c0c0c0'>$1$2$3</font>")
			  
			  delMenuRow_[i].onmouseover=function(){
				  re.tempObj=this;
				  if (this.className==""){
					   this.className="selectRow";
				  }
				  
			  }
			  delMenuRow_[i].onmouseout=function(){
				  re.tempObj=null;
				  if (this.sel=="0"){
				  		this.className="";
				  }
			  }
			  delMenuRow_[i].onclick=function(){
				  if (this.sel=="0"){
					  this.sel="1";
					  this.className="selectRow";
				  }else{
					  this.sel="0";
					  this.className="";
				  }
				  setTimeout("re.addSelectMenu()",10);
			  }
		  }
		
    }
	
	
	
	
	
	
	this.loadDelFile=function(inPage){ //加载删除的文件
		  if (inPage==null){inPage=1}
  		  	selectObj.clear();
			selectMenu.clear();
			
		  fileData.innerHTML="";
		  var objResponse=new JHttpResponse();
		  objResponse.write("page",inPage);
		  objResponse.write("order",order+" "+orderType);
		  objResponse.write("pageSize","20");
		  var out=objAjax.getText("post","reclaim.aspx?type=readDelFile",objResponse,null);
		  out= comminute(out,c1,c2);  //分割数据
		  var page=out[0];
		  this.page=page[2];
		  //title,tabid,tabName,delDate,id
		  
		  //显示内容
		  var wData=new tabList();
		  wData.obj=fileData;
		  wData.rowid="delFileRow_";         //行的ID
		  wData.rowClass="";                 //行的样式
		  wData.mode=1;                      //数据显示的格式
		  wData.add(raadArray(out,1),"","30");    //添加一列数据
		  wData.add(raadArray(out,0),"","250");    //添加一列数据
		  wData.add(raadArray(out,2),"","80");    //添加一列数据
		  wData.add(raadArray(out,3),"","120");    //添加一列数据
		  wData.addid(raadArray(out,4));     //添加行标识
		  wData.create();		  
		  //内容显示完成
		  
		  //显示分页
		  var wPage=new outPage();
		  wPage.obj=pageDiv;
		  wPage.pageArray=page;
		  wPage.run="re.loadDelFile";
		  wPage.create();
		  //分页显示完
		  
		  //alert(out);
		  //tabid,id,tabName,delDate,title
		  var delobj=document.getElementById("delFileRow_");
		  if (delobj==null){
			   return null;
		  }
		  var l=delFileRow_.length;
		  if (l==null){
			   delFileRow_.sel="0";
			  
			  delFileRow_.onmouseover=function(){
				  re.tempObj=this;
				  if (this.className==""){
					   this.className="selectRow";
				  }
				  
			  }
			  delFileRow_.onmouseout=function(){
				  re.tempObj=null;
				  if (this.sel=="0"){
				  		this.className="";
				  }
			  }
			  delFileRow_.onclick=function(){
				  if (this.sel=="0"){
					  this.sel="1";
					  this.className="selectRow";
				  }else{
					  this.sel="0";
					  this.className="";
				  }
				  setTimeout("re.addSelect()",10);
			  }
			 return null;  
		  }
		  for (var i=0;i<l;i++){
			  delFileRow_[i].sel="0";
			  
			  delFileRow_[i].onmouseover=function(){
				  re.tempObj=this;
				  if (this.className==""){
					   this.className="selectRow";
				  }
				  
			  }
			  delFileRow_[i].onmouseout=function(){
				  re.tempObj=null;
				  if (this.sel=="0"){
				  		this.className="";
				  }
			  }
			  delFileRow_[i].onclick=function(){
				  if (this.sel=="0"){
					  this.sel="1";
					  this.className="selectRow";
				  }else{
					  this.sel="0";
					  this.className="";
				  }
				  setTimeout("re.addSelect()",10);
			  }
		  }
		  
	}
	
	this.addSelect=function(){
		obj=this.tempObj;
		var l=selectObj.length;
		for (var i=0;i<l;i++){
			if (selectObj[i].tid==obj.tid){
				selectObj.removeAt(i)
				 return  null;
			}
		}
		selectObj[l]=obj;
	}
	
	this.addSelectMenu=function(){
		obj=this.tempObj;
		var l=selectMenu.length;
		for (var i=0;i<l;i++){
			if (selectMenu[i].tid==obj.tid){
				selectMenu.removeAt(i)
				 return  null;
			}
		}
		selectMenu[l]=obj;
	}
	
	
	this.clearAll=function(){
		 if (!window.confirm("你清空回收站,会导致:\n\n栏目和栏目下的子栏目\n\n所有被删除的文件\n\n 数据被彻底清除,并可能永远无法恢复,是否继续")){
			  return  null;
	    }
		 var out=objAjax.getText("post","reclaim.aspx?type=clearAll",null,null);
		 if (out=="1"){
		    alert("清空回收站成功");
		    this.loadDelMenu(this.mPage);
			this.loadDelFile(this.page); 
		 }else{
			alert(erStr(out));
		 }
		 
		  
	}
	
	
	this.clearMenu=function(){ //删除栏目
		if (selectMenu.length==0){
			 return  null;
		}
		 if (!window.confirm("你删除回收站中的栏目,会导致栏目和栏目下的子栏目\n\n 数据被彻底清除,并可能永远无法恢复,是否继续")){
			  return  null;
	    }
		var idList="";
		var l=selectMenu.length
		for (var i=0;i<l;i++){
			if (i<l-1){
				idList=idList+selectMenu[i].tid+","
			}else{
				idList=idList+selectMenu[i].tid+""
			}
		}
		//alert(idList);
		  var objResponse=new JHttpResponse();
		  objResponse.write("fileidList",idList);
		  var out=objAjax.getText("post","reclaim.aspx?type=clearMenu",objResponse,null);
		  if (out=="OK"){
			   alert("清除数据成功");
		  }else{
			   alert(out);
		  }
		  this.loadDelMenu(this.mPage);
		  this.loadDelFile(this.page);
	}
	
	
	
	this.unMenu=function(){  //恢复栏目
		
		if (selectMenu.length==0){
			 return  null;
		}
		var iList="";
		var l=selectMenu.length
		var notun=0;
		for (var i=0;i<l;i++){
			//alert(idList.length);
			var path=pList[findid(idList,selectMenu[i].tid)]
			if (path.search("路径已破损")==-1){
				if (i<l-1){
					iList=iList+selectMenu[i].tid+","
				}else{
					iList=iList+selectMenu[i].tid+""
				}
			}else{
				notun=1;
			}
		}
		if (iList==""){
			alert("你选择的栏目路径均已破损, 其上级栏目可能被删除,无法恢复")
		}else{
			  var objResponse=new JHttpResponse();
			  objResponse.write("fileidList",iList);
			  var out=objAjax.getText("post","reclaim.aspx?type=unMenu",objResponse,null);
			  if (out=="OK"){
				  if (notun==1){
				     alert("部分栏目恢复成功,有的栏目路径破损不能恢复");
				  }else{
					   alert("栏目恢复成功");
				  }
			  }else{
				   alert(out);
			  }
		}
        this.loadDelMenu(this.mPage);
		
	}
	
	
	
	this.clearFile=function(){ //删除数据
		if (selectObj.length==0){
			 return  null;
		}
		 if (!window.confirm("你删除回收站中的数据,会导致这些数据丢失,并可能永远无法恢复,是否继续")){
			  return  null;
	    }
		var idList="";
		var l=selectObj.length;
		for (var i=0;i<l;i++){
			if (i<l-1){
				idList=idList+selectObj[i].tid+","
			}else{
				idList=idList+selectObj[i].tid+""
			}
		}
		  var objResponse=new JHttpResponse();
		  objResponse.write("fileidList",idList);
		  var out=objAjax.getText("post","reclaim.aspx?type=clearFile",objResponse,null);
		  if (out=="OK"){
			   alert("清除数据成功");
		  }else{
			   alert(out);
		  }
		  this.loadDelFile(this.page);
     }
	
	
	this.undel=function(){  //恢复删除
		if (selectObj.length==0){
			 return  null;
		}
		
		var idList="";
		var l=selectObj.length;
		for (var i=0;i<l;i++){
			if (i<l-1){
				idList=idList+selectObj[i].tid+","
			}else{
				idList=idList+selectObj[i].tid+""
			}
		}
		  var objResponse=new JHttpResponse();
		  objResponse.write("fileidList",idList);
		  var out=objAjax.getText("post","reclaim.aspx?type=unDel",objResponse,null);
		  if (out=="OK"){
			  alert("数据恢复成功");
		  }else{
			 idList=out.split(",");
			  alert("有"+ (idList.length-1)+"条数据恢复失败\n 文件所在的栏目已删除");			  
		  }
		  
		this.loadDelFile(this.page);
		
	}
	
	
}

function findid(a,id){
	 //alert(a)
	for (var i=0;i<a.length;i++){
		if (a[i]==id){
			  return i;
		}
	}
}