
function userConfigClass(){
	this.tempObj=null;
	this.obj=null;
	this.delfield="";
	this.addfield="";
	
	this.loadConfig=function(){
		var out=objAjax.getText("post","saveUser.aspx?type=readConfig",null,null);
		out=comminute(out,c1,c2); 
		for (var i=0;i<out.length-1;i++){
			//[fieldName],[fieldAsName],[isFind],[isNull],[editMode],[isRow]
			//  0             1              2      3         4        5
			var nObj=this.addOption();
			var iObj=nObj.getElementsByTagName("input");
			for (var x=0;x<iObj.length;x++){
				 var id=iObj[x].id
				 //alert(id);
				 switch (id){
					 case "field":
					 	iObj[x].value=out[i][0];
						iObj[x].readOnly=true;
						break;
					 case "fieldName":
					 	iObj[x].value=out[i][1];
					 	break;
					 case "isNull":
					  //alert(out[i][3]);
					 	if (out[i][3]=="1"){
							iObj[x].checked=true;
						}else{
							iObj[x].checked=false;
						}
					 	break;
					 case "isFind":
					 	if (out[i][2]=="1"){
							iObj[x].checked=true;
						}else{
							iObj[x].checked=false;
						}
					 	break;
					 case "isRow":
					   
					 	if (out[i][5]=="1"){
							iObj[x].checked=true;
						}else{
							iObj[x].checked=false;
						}
					 	break;
					case "editMode":
					    
					
						break;
					 
				}
			}
			
			iObj=nObj.getElementsByTagName("select");
			for (var x=0;x<iObj.length;x++){
				if (iObj[x].id=="editMode")
				{ selectoption(iObj[x],out[i][4]);}
			}
			
		}

	}
	
	this.save=function(){
		var fieldlist=document.getElementsByName("field");
		var fieldAslist=document.getElementsByName("fieldName");
		for (var i=0;i<fieldlist.length-1;i++){
			if (fieldlist[i].readOnly!=true & fieldAslist[i].value!=""){
				if (fieldlist[i].value!=""){
					fieldlist[i].value="F_"+fieldlist[i].value;
				}
				this.addfield=this.addfield+fieldlist[i].value+c1;
				fieldlist[i].readOnly=true;
			}
		}
		var f=0;
		for (var i=0;i<fieldlist.length-1;i++){
			if (fieldlist[i].vale!="" & fieldAslist[i].value!=""){
				f=1;
				break;
			}
		}
		if (f==0){
			alert("系统需要最少一个扩展字段");
			return false;
		}
		var isNullstr="";
		var iNull=document.getElementsByName("isNull");
		for (var i=0;i<iNull.length-1;i++){
			if (iNull[i].checked==true){
				isNullstr=isNullstr+"1,"
			}else{
				isNullstr=isNullstr+"0,"
			}
		}
		
		var isFindstr="";
		var iFind=document.getElementsByName("isFind");
		for (var i=0;i<iFind.length-1;i++){
			if (iFind[i].checked==true){
				isFindstr=isFindstr+"1,"
			}else{
				isFindstr=isFindstr+"0,"
			}
		}
		
		var isRowstr="";
		var iRow=document.getElementsByName("isRow");
		for (var i=0;i<iRow.length-1;i++){
			
			if (iRow[i].checked==true){
				isRowstr=isRowstr+"1,"
			}else{
				isRowstr=isRowstr+"0,"
			}
		}
		
		//alert(this.delfield);
		//upButton.disabled=true;
		var objResponse=new JHttpResponse();
		objResponse.write("delfield",this.delfield);
		objResponse.write("addfield",this.addfield);
		objResponse.write("isNullstr",isNullstr);
		objResponse.write("isFindstr",isFindstr);
		objResponse.write("isRowstr",isRowstr);
		var out=objAjax.submit(form1,"post",true,objResponse);
		this.delfield="";
		this.addfield="";
		if (out=="OK"){
			alert("数据保存成功");
		}else{
			alert(erStr(out));
		}
	}
	
	this.cancel=function(){
		if (this.obj!=null){
			this.obj.className="listTitleOption";
			this.obj=null;
		}
		
	}
	
	this.loadOption=function(){
		var out=objAjax.getText("post","../sysSetup/optionSetupServer.aspx?type=readList",null,null);
	    out=comminute(out,c1,c2);
		var sObj=document.getElementById("editMode");
		for (var i=0;i<out.length-1;i++){
			var opt=document.createElement("option")
			opt.text=out[i][1];
			opt.value=parseInt(out[i][0])+20;
			sObj.options.add(opt);
		}
		
	}
	
	this.delOption=function(){
		if (this.obj!=null){
			
			var fl=this.obj.getElementsByTagName("input");
			for (var i=0;i<fl.length;i++){
				if (fl[i].id=="field"){
					if (fl[i].readOnly==true){
						this.delfield=this.delfield+fl[i].value+c1;
					}
				}
			}
			this.obj.removeNode(true);
			this.obj=null;
		}
	}
	
	this.addOption=function(){
		var objTemplate=document.getElementById("add");
		var objCopy=objTemplate.cloneNode(true); //复制行
		objCopy.style.display="block";
		objCopy.id="fieldRow";
		if (this.obj!=null){
			var newObj=this.obj.parentNode.insertBefore(objCopy,this.obj);//放置新行
		}else{
			var newObj=objTemplate.parentNode.insertBefore(objCopy,objTemplate);//放置新行
		}
		var obj=newObj.getElementsByTagName("input");
		for (var i=0;i<obj.length;i++){
			if (obj[i].id=="field"){
				obj[i].onchange=function(){
					if (this.value.search(/[^0-9^a-z]{1,}/gi)!=-1){
						this.value="";
						alert("字段名只能由英文和数字构成");
						this.focus();
					}
					var fieldlist=document.getElementsByName("field");
					var fieldAslist=document.getElementsByName("fieldName");
					for (var i=0;i<fieldlist.length;i++){
						if ((fieldlist[i].value=="F_"+this.value | fieldlist[i].value==this.value)&this.value!=""& fieldlist[i]!=this){
							this.value="";
							alert("字段名禁止重名");
							this.focus();
						}
						if (fieldlist[i]==this){
							if (fieldAslist[i].value==""){
								fieldAslist[i].value=this.value;
								fieldAslist[i].fname=this.value;
							}
						}
					}
				}
				
				
				
			}
			
			if (obj[i].id=="fieldName"){
				obj[i].onfocus=function(){
					if (this.fname==this.value){
						this.value="";
					}
				}
				
				obj[i].onblur=function(){
					var fieldlist=document.getElementsByName("field");
					var fieldAslist=document.getElementsByName("fieldName");
					for (var i=0;i<fieldlist.length;i++){
						if (fieldAslist[i]==this){
							if (fieldAslist[i].value=="" &fieldlist[i].value!=""){
								fieldAslist[i].value=fieldlist[i].value;
							}
						}
					}
					
				}
				
			}
			
			
		}
		newObj.onmouseover=function(){
			ufc.tempObj=this;
			this.className="listTitleOption_1";
		}
		newObj.onmouseout=function(){
			ufc.tempObj=null;
			if (ufc.obj!=this){
				this.className="listTitleOption";
			}

		}
		newObj.onclick=function(){
			//	alert(this.rowIndex);
			if (ufc.obj!=null &ufc.obj!=this){
				ufc.obj.className="listTitleOption";
			}
			ufc.obj=ufc.tempObj
			this.className="listTitleOption_1";
		}
		
		return newObj
		
	}
	
	this.up=function(){
		if (this.obj==null){
			return false;
		}
		var tr1=this.obj;
		var tr2=tr1.previousSibling;
		if (tr1.rowIndex>1){
			ExchangeTr(tr2,tr1)
		}
		//this.obj.rowIndex=this.obj.rowIndex-1;
		
	}
	
	this.down=function(){
		if (this.obj==null){
			return false;
		}
		var tr1=this.obj
		var tr2=tr1.nextSibling;
		//alert(tr2);
		if (tr2){
			ExchangeTr(tr1,tr2)
		}
	}
	
}


