

function userPowerClass() //用于完成用户权限相关设置的类
{
	this.IPname=null; //一个地名指到的IP范围
	var areaList=new Array();
	this.selectText=null;
	this.menuid=null;   //栏目ID
	this.startid=null;   //初始化时的权限ID
	var type=null;
	this.form=null;
	this.upid=null;
	var sel=null;
	var topObj=null
	
	
	this.createDiv=function(obj,title, width){ //创建权限组外框
		 tempObj=document.createElement("div");
		 var div=obj.appendChild(tempObj);
		 div.className="PowerList";
		 if (width!=null){
			 div.style.width=width;
		 }
		
		 tempObj=document.createElement("fieldset");
		 var addObj=div.appendChild(tempObj);
 		 tempObj=document.createElement("legend");
		 var addText=addObj.appendChild(tempObj);
		 addText.innerText=title;
		 tempObj=document.createElement("div");
		 var addDiv=addObj.appendChild(tempObj);
		 addDiv.innerHTML="";
		 addDiv.className="PowerListOption";
		 return addDiv;
	}
	
	this.createBox=function(obj,data,name)  //创建复选框组
	{
		//[ID],[GroupName],[IsDefault],[IsGuest] 
		// 0        1           2        3  
		var html="";
		if (data!=null){
			for (var i=0;i<data.length-1;i++){
				//alert(data[i][0]);
				html=html+"<input type='checkbox' id='"+name+i+ "' name='"+name+"_G' value='"+data[i][0]+"'>"
				html=html+"<label for='"+name+i+"'>"+data[i][1]+"</label>&nbsp;&nbsp;";
			}
		}
		html=html+"<br>"
		 if (data!=null){
			html=html+"用户: <input type='text' size='35'   id='"+name+ "_U' name='"+name+"_U' ><input onclick=\"power.selectUser(this)\" type='button' value='选择'>"
		 }else{
			html=html+"用户: <input type='text' size='35'   id='"+name+ "' name='"+name+"' ><input onclick=\"power.selectUser(this)\"  type='button' value='选择'>"
		}
		html=html+""
		obj.innerHTML=html;
		
	}
	
	this.createArea=function(obj){ //创建地区
		var tempObj=document.createElement("div");
		var textDiv=obj.appendChild(tempObj);
		textDiv.innerHTML="地区:";
		
		tempObj=document.createElement("Input");
 	    this.selectText=textDiv.appendChild(tempObj);
		this.selectText.size="48";
		this.selectText.name="P_A_Area"
		this.selectText.id="P_A_Area"
		this.selectText.title="只能填写下面复选框可以选择的地名,名称总为2个字符\n地区限制权限和其它权限设置复合,取交集"
		
		tempObj=document.createElement("span");
 	    rSpan=textDiv.appendChild(tempObj);
		var HTML=" &nbsp;&nbsp;<input checked  type='radio' id='areaType1' name='P_A_AreaType' value='1'><label for='areaType1' >允许这些地区</label>"
		HTML=HTML+" <input type='radio' id='areaType2' name='P_A_AreaType' value='2' ><label for='areaType2' >限制这些地区</label> "
		HTML=HTML+"<font color='#c0c0c0'>此选项和其它权限设置复合</font>"
		rSpan.innerHTML=HTML;
		
		tempObj=document.createElement("span");
		var leftSpan=obj.appendChild(tempObj);
		leftSpan.className="leftAreaSpan"
		
		tempObj=document.createElement("div");
		var title=leftSpan.appendChild(tempObj);
		title.className="titleRow";
	
		var t=new outTitle();
		t.add("地名","","200");
		t.add("IP段数","","70");
		
		t.obj=title;
		t.create();	
		
		tempObj=document.createElement("div");
		var areaBody=leftSpan.appendChild(tempObj);
		areaBody.className="ipList";
		
		var out=objAjax.getText("post","../user/saveUser.aspx?type=readLeftIP",null,null);
			//addname, num, ID
			//alert(out);
	      out= comminute(out,c1,c2);  //分割数据
		  var wData=new tabList();
		  wData.obj=areaBody;
		  wData.rowid="sArea_";                    //行的ID, 列ID=行ID_行号如(  [abc_][_0])
		  wData.rowClass="tabListBodyRow";         //行的样式
		  wData.mode=1;                            //数据显示的格式
		  wData.isCheckbox=true;                  //加上复选框
		  wData.checkBoxID="cArea";                 //复选框名
		  wData.onmouseroverRun="";                 //鼠标移上
		  wData.onmouseroutRun="";                  //鼠标移走
		  wData.onclickRun="power.selectArea";      //鼠标单击
		  wData.ondblclickRun="";                   //鼠标双击
		  wData.add(raadArray(out,0,1),"listBodyOption","200");    //添加一列数据 
		  wData.add(raadArray(out,1,1),"listBodyOption","70");    //添加一列数据 

		  wData.addid(raadArray(out,2,1));                         //添加行标识, 标识 被添加 为TID属性和复框的VALUE属性
		  wData.create();
		 
		 var objs=document.getElementsByName("cArea");
		 for (var i=0;i<objs.length;i++){
			 objs[i].i=i;
			 objs[i].onclick=function(){
				  var tObjs=document.getElementsByName("sArea__0");
				  var v=power.selectText.value;
				  var i=parseInt(this.i)
				  //alert(tObjs.length);
				  if (this.checked==true){
					  v=v+ tObjs[i].innerText + ",";
				  }else{
					 v=v.replace(tObjs[i].title+",","")
				  }
				 power.selectText.value=v;
			 }
			 
		 }
		
		tempObj=document.createElement("span");
		var rightSpan=obj.appendChild(tempObj);
		
		tempObj=document.createElement("textarea");
		tempObj.className="ipListTextarea";
		tempObj.title="地区IP段详细(前100)";
		this.IPname=rightSpan.appendChild(tempObj);		 
		
		
	}
	
	this.selectArea=function(obj){
		var isFind=0;
		//alert(areaList.length);
		for (var i=0;i<areaList.length;i++){
			if (areaList[i][0]==obj.tid){
				var out=areaList[i][1];
				//alert("读取缓存");
				isFind=1;
				break;
			}
		}
		if (isFind==0){
			var objResponse=new JHttpResponse();
			objResponse.write("id",obj.tid);
			//alert("读取服务器");
			var out=objAjax.getText("post","../user/saveUser.aspx?type=testRead1",objResponse,null);
			out=out.replace(/※/g,"\n");
			out=out.replace(/⊙/g,"");
			i=areaList.length
			areaList[i]=new Array();
			areaList[i][0]=obj.tid;
			areaList[i][1]=out;
		}
			this.IPname.value=out;
			
	}
	
	this.createName=function(obj,pType){ //创建加载配置和配置的名字
		var tempObj=document.createElement("div");
		var div=obj.appendChild(tempObj);
		
		var tempObj=document.createElement("span");
		var lspan=div.appendChild(tempObj);
		lspan.innerHTML="<SPAN STYLE='width:5px'></SPAN>加载配置:";
		
		var tempObj=document.createElement("span");
		var rspan=div.appendChild(tempObj);
		rspan.innerHTML="<SPAN STYLE='width:15px'></SPAN>配置名称:";
		
		var tempObj=document.createElement("select");
		sel=lspan.appendChild(tempObj);
		if (pType==null){
			var out=objAjax.getText("get","mywebServer.aspx?type=loadPowerFileList",null,null);
		}else{
			var out=objAjax.getText("get","mywebServer.aspx?type=loadPowerMenuList",null,null);
		}
		out= comminute(out,c1,c2);
		if (type=="1"){
			var opt=document.createElement("option");
			opt.text="继承";
			opt.value="";
			sel.options.add(opt);
		}
		
		for (var i=0;i<out.length-1;i++){
			var opt=document.createElement("option");
			opt.text=out[i][0];
			opt.value=out[i][1];
			sel.options.add(opt);
		}
		sel.onchange=function(){
			power.loadPowerFile(this.value)
		}
		
		
		
		var tempObj=document.createElement("input");
		var text=rspan.appendChild(tempObj);
		text.name="MPName";
		text.id="MPName";
		
		var tempObj=document.createElement("input");
		tempObj.type="button";
		var save=rspan.appendChild(tempObj);
		save.value="保存";
		save.title="此保存只保存权限的设置,不能把此权限应用到栏目\需要把权限应用到栏目和栏目的子栏目,请点下方的确定";
		save.onclick=function(){
			power.save();
		}
		
		var tempObj=document.createElement("input");
		tempObj.type="button";
		var del=rspan.appendChild(tempObj);
		del.value="删除";
		del.onclick=function(){
			power.del();
		}
		
		if (type=="0"){
			var tempObj=document.createElement("span");
			var insp=rspan.appendChild(tempObj);
			insp.style.paddingLeft="15px"
			
			var tempObj=document.createElement("input");
			tempObj.type="button";
			var inherit=insp.appendChild(tempObj);
			inherit.value="获取";
			inherit.title="从上级栏目继承权限";
			
			inherit.onclick=function(){
				power.loadid();
			}
			
			var tempObj=document.createElement("input");
			tempObj.type="checkbox";
			var down=insp.appendChild(tempObj);
			down.value="1";
			down.id="setDownMenu";
			down.name="setDownMenu";
			var tempObj=document.createElement("span");
			var sp=insp.appendChild(tempObj);
			sp.innerHTML="<label for='setDownMenu' title='将本栏目的权限设置,应用到所有的子栏目中' >应用到子栏目</label>"
			
			var tempObj=document.createElement("input");
			tempObj.type="checkbox";
			var down=insp.appendChild(tempObj);
			down.value="1";
			down.id="IsDefault";
			down.name="IsDefault";
			var tempObj=document.createElement("span");
			var sp=insp.appendChild(tempObj);
			sp.innerHTML="<label for='IsDefault' title='将本权限方案设置为默认值'>设为默认</label>"
			
		}else{
			
			
		}
		
	}
	
	this.loadPowerFile=function(id,idType){
		if (type=="0"){
			this.loadPowerMenu(id,0)
			return;
		}
		if (id==null){
			return ;
		}
		if (id==""){
			this.form.MPName.value="";
			return ;
		}
		var objResponse=new JHttpResponse();
		objResponse.write("id",id);
		if (idType==1){
			var out=objAjax.getText("post","../myweb/mywebServer.aspx?type=loadMenuPowerID",objResponse,null);
		}else{
			var out=objAjax.getText("post","../myweb/mywebServer.aspx?type=loadPowerID",objResponse,null);
		}
		out=out.split(c1);
		// MPName,MPType,P_A_View_G,P_A_View_U,P_A_Add_G,P_A_Add_U,P_A_Edit_G,P_A_Edit_U,P_A_Area,P_A_AreaType,
		//  0      1          2         3          4          5       6          7            8        9
        //  P_A_manage,P_A_IsExamine,P_A_IsPower,P_A_Examine_1,P_A_Examine_2,P_A_Examine_3,P_A_Examine_4,P_C_IsExamine,P_C_View_G,
		//     10               11          12        13             14           15            16            17             18 
        //  P_C_View_U,P_C_Add_G,P_C_Add_U,P_C_manage 
		//   19            20         21       22
		if (out.length>20){
			var iList="MPName,MPType,P_A_View_G,P_A_View_U,P_A_Add_G,P_A_Add_U,P_A_Edit_G,P_A_Edit_U,P_A_Area,P_A_AreaType,";
                iList=iList+"P_A_manage,P_A_IsExamine,P_A_IsPower,P_A_Examine_1,P_A_Examine_2,P_A_Examine_3,P_A_Examine_4,P_C_IsExamine,P_C_View_G,";
		        iList=iList+"P_C_View_U,P_C_Add_G,P_C_Add_U,P_C_manage";
				iList=iList.split(",");
				if (idType!=1){
					document.getElementById(iList[0]).value=out[0];
				}
				document.getElementById(iList[3]).value=out[3];
				document.getElementById(iList[19]).value=out[19];
				document.getElementById(iList[8]).value=out[8];
				findCheckbox(iList[2],out[2]);
				findCheckbox(iList[18],out[18]);
				findCheckbox(iList[20],out[20]);
				findRadio(iList[9],out[9]);
		}else{
			alert(erStr(out.toString()));
		}
	}
	
	this.loadid=function(){
		if (pType=="modi"){
			this.loadPowerMenu(this.upid,1);
		}else{
			this.loadPowerMenu(this.menuid,1)	;
		}
		
	}
	
	this.loadPowerMenu=function(id,idType){ //依据ID加载一个栏目的权限配置, idtype=0  为权限 ID, =1为栏目ID
		if (id==null){
			return;
		}
		if (id==""){
			this.form.MPName.value="";
			return ;
		}
		
		var objResponse=new JHttpResponse();
		objResponse.write("id",id);
		if (idType==0){
			var out=objAjax.getText("post","../myweb/mywebServer.aspx?type=loadPowerID",objResponse,null);
		}else{
			var out=objAjax.getText("post","../myweb/mywebServer.aspx?type=loadMenuPowerID",objResponse,null);
		}
		
		out=out.split(c1);
		
		if (out.length>20){
			var iList="MPName,MPType,P_A_View_G,P_A_View_U,P_A_Add_G,P_A_Add_U,P_A_Edit_G,P_A_Edit_U,P_A_Area,P_A_AreaType,";
                iList=iList+"P_A_manage,P_A_IsExamine,P_A_IsPower,P_A_Examine_1,P_A_Examine_2,P_A_Examine_3,P_A_Examine_4,P_C_IsExamine,P_C_View_G,";
		        iList=iList+"P_C_View_U,P_C_Add_G,P_C_Add_U,P_C_manage";
				iList=iList.split(",");
				
				
				document.getElementById(iList[0]).value=out[0];
				document.getElementById(iList[3]).value=out[3];
				document.getElementById(iList[5]).value=out[5];
				document.getElementById(iList[7]).value=out[7];
				document.getElementById(iList[10]).value=out[10];
				document.getElementById(iList[19]).value=out[19];
				document.getElementById(iList[21]).value=out[21];
				document.getElementById(iList[8]).value=out[8];
				document.getElementById(iList[13]).value=out[13];
				document.getElementById(iList[14]).value=out[14];
				document.getElementById(iList[15]).value=out[15];
				document.getElementById(iList[16]).value=out[16];
				findCheckbox(iList[2],out[2]);
				findCheckbox(iList[4],out[4]);
				findCheckbox(iList[6],out[6]);
				findCheckbox(iList[11],out[11]);
				findCheckbox(iList[17],out[17]);
				findCheckbox(iList[18],out[18]);
				findCheckbox(iList[20],out[20]);
				findRadio(iList[9],out[9]);
				
				selectoptionText(sel,out[0])
				

				
		}else{
			out=out.toString();
			if (out!=""){
				alert(erStr(out));
			}
		}
		
	}
	
	this.createExamine=function(obj){
		var html="<div> <input type='checkbox' id='P_A_IsExamine' name='P_A_IsExamine' value='1'> <label for ='P_A_IsExamine'>非管理员发布主题需要审核</label>";
		html=html+"<span style='width:35px;'></span><input type='checkbox' id='P_C_IsExamine' name='P_C_IsExamine' value='1'> <label for ='P_C_IsExamine'>非管理员发布回复需要审核</label></div>";
		html=html+"<div>";
		html=html+"初审员: <input type='text' size='35'   id='P_A_Examine_1' name='P_A_Examine_1' ><input type='button' value='选择'  onclick=\"power.selectUser(this)\" >";
		html=html+"<span style='width:15px;'></span>复审员: <input type='text' size='35'   id='P_A_Examine_2' name='P_A_Examine_2' ><input type='button' value='选择'  onclick=\"power.selectUser(this)\" ><br>";
		html=html+"三审员: <input type='text' size='35'   id='P_A_Examine_3' name='P_A_Examine_3' ><input type='button' value='选择'  onclick=\"power.selectUser(this)\" >";
		html=html+"<span style='width:15px;'></span>终审员: <input type='text' size='35'   id='P_A_Examine_4' name='P_A_Examine_4' ><input type='button' value='选择'  onclick=\"power.selectUser(this)\" >";
		html=html+"</div>";
		obj.innerHTML=html;
	}
	
	
	this.createFile=function(obj){ //创建文件用权限选项界面 到OBJ中
		type="1";
		topObj=obj;
		this.createName(obj);  //创建保存设置
		
		var display=this.createDiv(obj,"可以查看主题的用户组和用户");
		 //add=this.createDiv(obj,"可以发布主题的用户组和用户");
		 // Examine=this.createDiv(obj,"发布数据不用审核的用户组和用户");
		 // edit=this.createDiv(obj,"可以编辑数据的用户组和用户");
		 var displayRe=this.createDiv(obj,"可以查看评论的用户组和用户");
		 var re=this.createDiv(obj,"可以发布评论的用户组和用户");
		 var IP=this.createDiv(obj,"地区限制","97%");
		 //manage=this.createDiv(obj,"可以管理的用户");
		 
		 var out=objAjax.getText("get","../user/saveUser.aspx?type=readGroup",null,null);
		 out= comminute(out,c1,c2); 
		 this.createBox(display,out,"P_A_View");
		 //this.createBox(add,out,"addGroup");
		 //this.createBox(Examine,out,"ExamineGroup");
		// this.createBox(edit,out,"editGroup");
		 this.createBox(displayRe,out,"P_C_View");
		 this.createBox(re,out,"P_C_Add");
		// this.createBox(manage,null,"ExamineReGroup");
		 this.createArea(IP);		
		 if (this.startid!=="" & this.startid!="-1" &this.startid!=null){
			 this.loadPowerFile(this.startid);
			 selectoption(sel,this.startid);
		 }else{
			  this.loadPowerFile(this.menuid,1);
		}
		
	}
	
	this.createMenu=function(obj){ //创建文件夹用权限选项界面 到OBJ中
		type="0";
		topObj=obj;
		this.createName(obj,"menu");  //创建保存设置
		
		 var display=this.createDiv(obj,"可以查看主题的用户组和用户");
		 var add=this.createDiv(obj,"可以发布主题的用户组和用户");
		 var edit=this.createDiv(obj,"可以编辑自己数据的用户组和用户");
		 var displayRe=this.createDiv(obj,"可以查看评论的用户组和用户");
		 var re=this.createDiv(obj,"可以发布评论的用户组和用户");
		 var manage=this.createDiv(obj,"管理员");
		 var Examine=this.createDiv(obj,"审核","97%");
		 var IP=this.createDiv(obj,"地区限制","97%");
		 
		 var out=objAjax.getText("get","../user/saveUser.aspx?type=readGroup",null,null);
		 out= comminute(out,c1,c2); 
		 this.createBox(display,out,"P_A_View");
		 this.createBox(add,out,"P_A_Add");
		 this.createBox(edit,out,"P_A_Edit");
		 this.createBox(displayRe,out,"P_C_View");
		 this.createBox(re,out,"P_C_Add");
		 this.createBox(manage,null,"P_A_manage");
		 this.createArea(IP);	
		 this.createExamine(Examine);
		 this.loadPowerMenu(this.menuid,1);
		
	}
	
	this.del=function(){
		//alert(sel.value);
		if (sel.value==""){
			
				alert("请选择一个配置");
				return ;
			
		}
		id=sel.value;
		var objResponse=new JHttpResponse();
		objResponse.write("id",id);
		//alert(id);
		var out=objAjax.getText("post","../myweb/mywebServer.aspx?type=delPowerID",objResponse,null);
		if (out=="OK"){
			selectDelvalue(sel,id);
			this.form.MPName.value="";
			 selectoption(sel,"");
		}else if (out=="0"){
			alert("当前权限配置是默认配置, 不能删除");
		}else{
			alert(erStr(out));
		}
	}
	
	this.selectUser=function(obj){  //选择用户
		var upObj=obj.previousSibling;
		var u= openSelectUser("admin");
		if (u!=null){
			var v=upObj.value;
			if (v==""){
				upObj.value=u;
			}else{
				upObj.value=v+","+u;
			}
		}
		
	}
	
	this.save=function(isInfo){
		//var objs = document.getElementsByName("P_C_Add_G");
//		for (var i=0;i<objs.length;i++){
//				alert(objs[i].outerHTML);
//		}
		if (this.form.MPName.value==""){
			if (type!="1"){
				alert("请输入权限配置的名字");
				return  null;
			}else{
				return -1;
			}
		}

		this.IPname.value="";
		var objResponse=new JHttpResponse();
		objResponse.write("MPType",type);
		this.form.action="../myweb/mywebServer.aspx?type=savePower";
		var out=objAjax.submit(this.form,"post",true,objResponse)
		//alert(out);
		if (!isNaN(out)){
			if (isInfo==null){
				alert("保存成功");
			}
			return out;
		}else{
			alert(erStr(out));
			return null;
		}
	}
	
}


