var objAjax=new JAjax();
function treeModeClass(){//栏目操作的类
	this.menuid=null;//当前查找的栏目编号
    this.rootId=null;
	this.rootObj=null;//元素对象
	this.rootName=null;	
	var rootText=null;	
	this.tempObj=null;
	this.selectMenu=null;
	this.filesList=new Array();
	this.selectFiles=new Array();
	this.isPop=true;
	this.page=1;
	this.pageSize=20;
	this.nowElement=null;
	var selectMenu="";//当前选中的栏目
	//id,mName,mid,layer,isDown,uplistid,intro,indexNum,mDate,asTab
	this.createMenuList=function(idList,onclick){//左边创建栏目列表
	   this.selectMenu=null;
	   this.filesList=new Array();
	   this.selectFiles=new Array();
	   if (this.rootObj==null){	
			 menuLst.rootObj=$("leftMenu");
	   }
	   var i=1;
	   var upObj=null;
	   menuLst.display(idList);
	   var ctempObj=document.createElement("div");
	   ctempObj.id="treeNodeText"+idList[0][2];
	   ctempObj.menuid=idList[0][2];
	   ctempObj.idList=idList[0][5];
	   ctempObj.asTab=idList[0][9];
	   menuLst.readFiels(ctempObj);
	   if(idList[0][2]==this.rootId){
			i=1;
			this.rootName=idList[0][1];
			upObj=this.rootObj;
		}	
		if (rootText==null){
			var tempObj=document.createElement("div");
			obj=this.rootObj.appendChild(tempObj);
			obj.id="rootText";
			obj.menuid=this.rootId;
			obj.innerHTML="<span id='treeNodeType"+idList[0][2]+"' class='downNode_1'></span><span class='treeIco'></span><span>"+idList[0][1]+"</span>";
			obj.onclick=function(){
				menuLst.readMenu(this.menuid);
				var ctempObj=document.createElement("div");
				ctempObj.id="treeNodeText"+idList[0][2];
				ctempObj.menuid=idList[0][2];
				ctempObj.idList=idList[0][5];
				ctempObj.asTab=idList[0][9];
				menuLst.readFiels(ctempObj);
			}
			rootText=obj;
		}
		var downObj=null;
		if (i!=0){			
			downObj=document.getElementById("treeNodeDown"+idList[0][2]);
			if (downObj!=null){
				downObj.style.display="block";
			}
		}
       //id,mName,mid,layer,isDown,uplistid,intro,indexNum,mDate,asTab
		for (i;i<idList.length-1;i++){
			var textObj=document.getElementById("treeNodeText"+idList[i][2]);
			if (textObj==null){
				tempObj=document.createElement("div");
				var tObj=upObj.appendChild(tempObj);
				tObj.id="treeNode"+idList[i][2];
				tObj.className="treeNode"
				tempObj=document.createElement("div");
				textObj=tObj.appendChild(tempObj);
				textObj.id="treeNodeText"+idList[i][2];
				textObj.menuid=idList[i][2];
				textObj.idList=idList[i][5];
				textObj.asTab=idList[i][9];
				textObj.className="textNode";
				if (onclick==null){onclick=""}
				textObj.onclickText=onclick;				
				tempObj=document.createElement("div");
				downObj=tObj.appendChild(tempObj);
				downObj.id="treeNodeDown"+idList[i][2];
				downObj.style.display="none";
				textObj.onclick=function(){
					var downObj=document.getElementById("treeNodeDown"+this.menuid);
					var objType=document.getElementById("treeNodeType"+this.menuid);
					if(selectMenu){//选中的栏目
						selectMenu.className="textNode";	
					}
					selectMenu=this;
					this.className="textNode_1";
					if (downObj.style.display=="none"){
						downObj.style.display="block";
						if (this.onclickText==""){
							menuLst.readMenu(this.menuid);
							menuLst.readFiels($(this.id));
						}else{
							eval(this.onclickText)
						}
						if (objType!=null){
							objType.className="downNode_1";
						}
					}else{
						if (this.onclickText==""){
							menuLst.readMenu(this.menuid);
							menuLst.readFiels($(this.id));
						}else{
							eval(this.onclickText)
						}
						downObj.style.display="none";
						downObj.style.display="none";
						if (objType!=null){
							objType.className="downNode";
						}
					}					
				}
				textObj.onmouseover=function(){
					if(selectMenu!=this){
						this.className=this.className+"_1";
					}
				}
				textObj.onmouseout=function(){
					if(selectMenu!=this){
						var c=this.className.split("_");
						c=c[0];
						this.className=c;
					}
				}
			}
			var s=idList[i][5].split(",");
			var sp="";
			for (var x=0;x<s.length;x++){
				sp=sp+"<span style='width:20px;height:10px;'></span>"
			}
			if (idList[i][4]=="1"){
				textObj.innerHTML=sp+"<span id='treeNodeType"+idList[i][2]+"' class='downNode'></span><span class='treeIco'></span><span>"+idList[i][1]+"</span>";
			}else{
				textObj.innerHTML=sp+"<span  class='notDownNode'></span><span class='treeIco_1'></span><span>"+idList[i][1]+"</span>";
			}
		 }
	}
	
treeModeClass.prototype.readIsPop=function(obj){
		if(obj==null||obj==""){
			return false;
		}else{	
			var objResponse=new JHttpResponse();
			objResponse.write("menuid",obj);
			var out=objAjax.getText("post","mangerRun.aspx?type=readChild",objResponse,null);
			if(out=="noPop")
			{
				return false
			}
			if(out.indexOf(c1)==-1)
			{
				return false
			}
		}
		return true
}

treeModeClass.prototype.readFiels=function(textObj){//读出当前栏目下的分页信息
		menuLst.nowElement=textObj;
		if (this.asTab=="" ){
			return null;
		}
		var order="saveDate";
		var objResponse=new JHttpResponse();
		objResponse.write("menuid",textObj.menuid);
		objResponse.write("asTab",textObj.asTab);
		objResponse.write("page",this.page);
		objResponse.write("pageSize",this.pageSize);
		objResponse.write("order",order);
		objResponse.write("visionType","all");
		var out=objAjax.getText("post","../../system/myWeb/mywebServer.aspx?type=readFiles",objResponse,null);
		if (out=="noPop"){
			this.isPop=false;
			$("page").innerHTML="<span style='color:red'>此栏目您没有权限管理数据</span>";
			return;
		}
		if(out==null||out==""){
			this.isPop=false;
			$("page").innerHTML="<span style='color:red'>你当前还不是管理员,不能够进行操作</span>";
			return;
		}
		this.isPop=true;
		//第一级※  第二级⊙
		//id,title,saveDate,saveUser,cbs,IsTop,IsEssence,IsHidden,Examine,IsRemark
		//0   1         2        3     4   5     6       7           8     9 
		out= comminute(out,c1,c2)
		this.filesList=out;
		this.DisplayFiles(this.filesList);
		var pageDiv=document.getElementById("page");
		if (this.page>out[0][1]){
			this.page=out[0][1];
		}
		if (out[0][0]!="0"){
			pageDiv.innerText=" 一共有"+out[0][0]+"条, 分"+out[0][1]+"页,当前是第"+out[0][2]+"页";
			if (out[0][1]>1){
				var tempObj=document.createElement("span");
				var div=pageDiv.appendChild(tempObj);
				div.style.cssText="width:60px;text-align:center;cursor:hand; "
				div.innerText="上一页";
				div.title="上一页";
				if (this.page>1){
				   div.onclick=function(){
						menuLst.page=menuLst.page-1;
						menuLst.readFiels(menuLst.nowElement);
					}
				}
				tempObj=document.createElement("span");
				div=pageDiv.appendChild(tempObj);
				div.style.cssText="width:60px;text-align:center;cursor:hand;"
				div.title="下一页";
				div.innerText="下一页";
				if (this.page<out[0][1]){
				    div.onclick=function(){
						menuLst.page=menuLst.page+1;
						menuLst.readFiels(menuLst.nowElement);
					}
				}
			}
			tempObj=document.createElement("span");
			div=pageDiv.appendChild(tempObj);
			div.style.cssText="width:60px;text-align:center;cursor:hand"
			div.innerText="全选";
			div.title="全选"
			div.onclick=function(){
				menuLst.selsectAll();
			}
			tempObj=document.createElement("span");
			div=pageDiv.appendChild(tempObj);
			div.style.cssText="width:60px;text-align:center;cursor:hand"
			div.innerText="清除";
			div.title="清除";
			div.onclick=function(){
				menuLst.clearAll();
			}
			tempObj=document.createElement("span");
			div=pageDiv.appendChild(tempObj);
			div.style.cssText="width:100px;text-align:center"
			div.innerText=" 读取时间:"+out[0][4]+"ms"			
		}else{
			pageDiv.innerText=" 栏目下无数据"
		}
	  }	
	}
	
treeModeClass.prototype.clearAll=function(){ //取消全部选择
		var fl=this.selectFiles;
		var i=fl.length;
		if (i==0){
			return false;
		}
		for (var x=0;x<i;x++){
			var obj=document.getElementById(fl[x].id)
			if (obj!=null){
				obj.className=obj.oldclass;
			}
		}
		menuLst.clearDelFile();
	}
	
treeModeClass.prototype.selsectAll=function(){  //选择当前页的全部
		var div=document.getElementById("wFiles");
		objList=div.getElementsByTagName("DIV");
		for (var i in objList){
			if (objList[i].id !=null){
				if (objList[i].id.search("webFile_")!=-1){
					if (!this.isDelFile(objList[i])){
						this.addDelFile(objList[i]);
						objList[i].oldclass=objList[i].className;
						objList[i].className=objList[i].className+"_1";
					}
				}
			}
		}
	}
	
treeModeClass.prototype.DisplayFiles=function(out){//读取文章信息
		var files=out;
		if (files==null){return null; }
		if (files.length==0){return null;}
		var div=document.getElementById("wFiles");
		if (div==null){
			var tempObj=document.createElement("div");
			div=document.getElementById("fileList").appendChild(tempObj);
			div.id="wFiles";
			div.style.cssText="clear:both";
		}else{
			div.innerHTML="";
		}
		this.mode=3;
		var signObj=null;
		for (i=1;i<files.length-1;i++){	
			switch (this.mode){
					case 3: //小图标
						var tempObj=document.createElement("div");
						var newObj=div.appendChild(tempObj);
						newObj.className="M4F";
						if(i==1){
						    newObj.style.cssText="border-top:solid 1px #EFEFEF;";
						}
						
						tempObj=document.createElement("div");
						signObj=newObj.appendChild(tempObj);
						signObj.className="signdiv";
						
						tempObj=document.createElement("div");
						var idObj=newObj.appendChild(tempObj);
						idObj.innerHTML="&nbsp;&nbsp;<img src='../../system/myWeb/img/f3.gif'>&nbsp;";
						idObj.className="fileTabRow";
						
						tempObj=document.createElement("div");
						var nameObj=newObj.appendChild(tempObj);
						nameObj.innerText=files[i][1];
						nameObj.className="fileTabTitleRow";
												
						tempObj=document.createElement("div"); //简介
						var introObj=newObj.appendChild(tempObj);
						introObj.innerText=files[i][4];
						introObj.className="fileTabRow_R2";
						
						tempObj=document.createElement("div"); //创建人
						var createObj=newObj.appendChild(tempObj);
						createObj.innerText=files[i][3];
						createObj.className="fileTabRow_R1";
						
						tempObj=document.createElement("div");  //创建日期
						var dateObj=newObj.appendChild(tempObj);
						dateObj.innerText=files[i][2];
						dateObj.className="fileTabRow_R";
						break;
					
			}
			newObj.icoType="F";
			newObj.id="webFile_"+files[i][0];
			newObj.fileid=files[i][0];
			newObj.title=files[i][1];
			if (signObj!=null){
				//id,title,saveDate,saveUser,cbs,IsTop,IsEssence,IsHidden,Examine,IsRemark
				//0   1         2        3     4   5     6       7           8     9 
				if (files[i][5]=="1"){
					signObj.innerHTML=signObj.innerHTML+"<img title='置顶' src='../../system/myWeb/img/top.gif'>";
				}
				if (files[i][6]=="1"){
					signObj.innerHTML=signObj.innerHTML+"<img  title='精华' src='../../system/myWeb/img/Essence.gif'>";
				}
				if (files[i][7]=="1"){
					signObj.innerHTML=signObj.innerHTML+"<img  title='隐藏' src='../../system/myWeb/img/Hidden.gif'>";
				}
				if (files[i][8]!="1"){
					signObj.innerHTML=signObj.innerHTML+"<img  title='未终审' src='../../system/myWeb/img/Examine.gif'>";
				}
			}					
			if (this.isDelFile(newObj)){
				newObj.oldclass=newObj.className;
				newObj.className=newObj.className+"_1";
			}			
			newObj.onmouseover=function(){
				if (!menuLst.isDelFile(this)){
					this.oldclass=this.className;
					this.className=this.className+"_1";
				}
				menuLst.tempObj=this;
			}			
			newObj.onmouseout=function(){
				if (!menuLst.isDelFile(this)){
					this.className=this.oldclass;
				}
				menuLst.tempObj=null;
			}				
			newObj.ondblclick=function(){  //双击图标, 打开文件
				menuLst.modiData(this.fileid);
			}			
			newObj.onmousedown=function(){  //单击选定文件
				menuLst.tempObj=this;
				var button=event.button 
 				if (button==1){
					setTimeout("menuLst.selectFileObj()",10)
				}
			}
		}
	}
	
treeModeClass.prototype.modiData=function(id){
		if (id==null){
			if (this.selectFiles.length!=0){
				var fl=this.selectFiles;
				l=fl.length-1;
				id=fl[l].fileid;
			}
		}
		if (id==null){
			alert("请先选择一篇文章")
			return ;
		}
		createDiv.addElementContent(document.body,60,800,500,"./createDate.htm?pType=modi&menuid="+this.menuid+"&asTab="+this.asTab+"&id="+id+"&t="+create_id());
 }
 
treeModeClass.prototype.readMenu=function(menuid){//读取栏目信息
	 var objResponse=new JHttpResponse();
     objResponse.write("menuid",menuid);
     objResponse.write("order","indexNum");
	 var out=objAjax.getText("post","../../system/myWeb/mywebServer.aspx?type=read",objResponse,null);
	 //第一级※  第二级⊙
	  out=comminute(out,c1,c2);
	  menuLst.rootId=menuid;
	  menuLst.rootObj=$("treeNodeDown"+menuid);
	  menuLst.createMenuList(out);	
	}

treeModeClass.prototype.display=function(menuList){ //读取栏目
		//显示栏目列表 mode 显示的模式 0 略图 1 大图标, 2小图标, 3列表 
		this.mode=1;
		var mList=menuList;
		var div=document.getElementById("fileList");
		var i=0;
		if (this.menuid==0){
			if (mList.length==1){
				div.innerHTML="<div>网站中没有发现任何栏目</div>";
				return false;
			}
			this.menuName="根栏目";
			this.menuid=0;
			this.layer=0;
			this.upListid="";
			this.asTab="";
			this.isDown="1";
		}else{
			i=1;
			this.asTab=mList[0][9]
			this.menuName=mList[0][1];
			this.menuid=mList[0][2];
			this.layer=mList[0][3];
			this.upListid=mList[0][5];
			this.isDown=mList[0][4];
			if (mList.length==2){
				div.innerHTML="<div>..</div>";
				return false;
			}
		}
		div.innerHTML="";
		//id,mName,mid,layer,isDown,uplistid,intro,indexNum,mDate,asTab
		for (i=i;i<mList.length-1;i++){
			switch (this.mode){
					case 1: //小图标
						var tempObj=document.createElement("div");
						tempObj.id="webMenu_"+i;
						var newObj=div.appendChild(tempObj);
						newObj.className="ZM2F";
						newObj.menuid=mList[i][2];
						newObj.title=mList[i][1];
						
						tempObj=document.createElement("div");
						var imgObj=newObj.appendChild(tempObj);
						if (mList[i][4]=="1"){
							imgObj.innerHTML="<img src='../../system/myWeb/img/m2.gif'>";
						}else{
							imgObj.innerHTML="<img src='../../system/myWeb/img/m2_0.gif'>";
						}
						imgObj.className="m2img";
						
						tempObj=document.createElement("div");
						var textObj=newObj.appendChild(tempObj);
						textObj.innerHTML=mList[i][1];
						textObj.className="m2Text";
				        break;
			}
			newObj.asTab=mList[i][9];
			newObj.upList=mList[i][5];
			newObj.icoType="M";
		
			newObj.onmouseover=function(){
				if (menuLst.selectMenu!=this){					
					this.oldclass=this.className;
					this.className=this.className+"_1";
				}	
				this.selectMenu=this;
			}
			
			newObj.onmouseout=function(){
				if (menuLst.selectMenu!=this){
					this.className=this.oldclass;
				}	
				this.selectMenu=null;
			}
			
			newObj.ondblclick=function(){  //双击图标, 读下级栏目
				if(menuLst.selectMenu){
					menuLst.selectMenu.className="textNode";
				}
				menuLst.selectMenu=$("treeNodeText"+this.menuid);
				$("treeNodeText"+this.menuid).className="textNode_1"
				menuLst.readMenu(this.menuid);
			}
			
			newObj.onmousedown=function(){  //点击鼠标 选定栏目				
				menuLst.selectMenuObj(this);
			}
		}
	}
	
treeModeClass.prototype.isDelFile=function(obj){ //检测是否已保存在删除列表中
		var fl=this.selectFiles;
		var i=fl.length;
		if (i==0){
			return false;
		}
		for (var x=0;x<i;x++){
			if (fl[x].id==obj.id){
				return true;
			}
		}
		return false;
	}
	
treeModeClass.prototype.selectFileObj=function(){
		var obj=menuLst.tempObj;
		if (!this.isDelFile(obj)){
				this.addDelFile(obj);
			}else{
			menuLst.moveDelFile(obj);
			this.className=obj.oldclass;
		}
	}
	
treeModeClass.prototype.moveDelFile=function(obj){//移除一个要删除的文件
		var fl=this.selectFiles;
		var i=fl.length;
		for (var x=0;x<i;x++){
			if (fl[x].id==obj.id){
				this.selectFiles.splice(x,1);
				break;	
			}
		}
	}
	
treeModeClass.prototype.addDelFile=function(obj){ //增加一个要删除的文件
		if (this.isDelFile(obj)){
			return;
		}
		this.selectFiles.push(obj);		
	}
	
treeModeClass.prototype.selectMenuObj=function(obj){//检查当前的栏目是否被选中	
		if (menuLst.selectMenu==obj){
			return false;
		}		
		if (this.selectMenu!=null){
			this.selectMenu.className=this.selectMenu.oldclass;
		}
		this.selectMenu=obj;
	}
	
treeModeClass.prototype.del=function(menuid){//移除栏目
		delObj=document.getElementById("treeNode"+menuid);
		delObj.removeNode(true);
	}
	
treeModeClass.prototype.clearDelFile=function(){
		this.selectFiles.clear();
	}
	
treeModeClass.prototype.onloadproto=function(){
		window.location.href=window.location.href;	
	}
	
treeModeClass.prototype.setFile=function(){//添加文章内容信息
	    createDiv.addElementContent(document.body,60,800,500,"./createDate.htm?pType&menuid="+this.menuid+"&asTab="+this.asTab+"&t="+create_id());
	}
	
treeModeClass.prototype.delMenu=function(){//删除栏目
		if (!this.isPop){
			alert("您不具有此权限");
			return;
		}
		if (this.selectMenu!=null){
			  if (this.selectMenu.menuid<1000){
				  alert("你选中的栏目是系统栏目,不能删除") 
			  }else{
				  if (window.confirm("你的删除操作将删除栏目及栏目下的子栏目和数据,是否继续")){
					  var mid=this.selectMenu.menuid;
					  var upList=this.selectMenu.upList;
					  upList=upList.split(",");
					  var u=""
					  for (var i=0;i<=upList.length-2;i++){
						  if (i<upList.length-2){
							u=u+upList[i]+","
						  }else{
							u=u+upList[i]
						  }
					  }
					  var objResponse=new JHttpResponse();
					  objResponse.write("menuid",mid);
					  objResponse.write("upList",u);
					 var out=objAjax.getText("post","../../system/myWeb/mywebServer.aspx?type=delMenu",objResponse,null);
					 if (out=="OK"){
						 this.selectMenu.removeNode(true);
						 this.selectMenu=null;
						 menuLst.del(mid);
					 }else{
						  alert(out)
					 }
				   }
			}
		}else{
			alert("请选择要删除的栏目");
		}
	}
	
treeModeClass.prototype.delFilters=function(){
         if (this.selectFiles.length!=0){  //删除文章开始
			 var fileList="";
			 var fl=this.selectFiles;
			 var l=fl.length;
			 for (var i=0;i<l;i++){
				 fileList=fileList+fl[i].fileid+",";
			 }
			 fileList=fileList.substr(0,fileList.length-1);
		     var objResponse=new JHttpResponse();
			 objResponse.write("menuid",this.menuid);
			 objResponse.write("fileidList",fileList);
			 objResponse.write("table",this.asTab);
			 var out=objAjax.getText("post","../../system/myWeb/mywebServer.aspx?type=delFiles",objResponse,null);
			 if (out=="OK"){
				 l=fl.length;
				  for (i=0;i<l;i++){
					  if (fl[i].id!=null){
						  var obj=document.getElementById(fl[i].id);
						  if (obj!=null){
							 obj.removeNode(true);
						  }
					  }
				  }
				  this.clearDelFile();
			}else{
				  alert(out)
			}
		}
		else{
			alert("请选择要删除的数据");
		}
	}
	
treeModeClass.prototype.createMenu=function(){//创建栏目
		createDiv.addElementContent(document.body,60,800,500,"./createMenu.htm?type=&menuid="+this.menuid+"&asTab="+this.asTab+"&t="+create_id());
	}
	
treeModeClass.prototype.editorMenu=function(){//编辑栏目
	if (this.selectMenu==null){
		  alert("请选择要编辑的栏目");
	  	  return;
	}
	createDiv.addElementContent(document.body,60,800,500,"./createMenu.htm?type=modi&menuid="+this.selectMenu.menuid+"&asTab="+this.selectMenu.asTab+"&t="+create_id());
	}
	
treeModeClass.prototype.setChildWeb=function(){//编辑站点
	createDiv.addElementContent(document.body,60,800,500,"./childManger.htm?menuid="+menuid+"&t="+create_id());
}

treeModeClass.prototype.setModel=function(){//设置模板
	createDiv.addElementContent(document.body,60,900,607,"./childModel.htm?menuid="+menuid+"&t="+create_id());
}