function optionClass(){
	var downOptionList=new Array();
	var serverOption=new Array();  //从服务器下载回来的选项设置 
	
	this.tempObj=null;
	this.selectObj=null;       //当前选择到的选项
	this.selectOption=null;   //当前选择到的项目
	this.sindex="";
	this.dataType=1;
	
	this.newItem=function(){
		form1.mainText.onchange=function(){
			if (this.vlaue!=""){
				op.addItem(this.value,this.value);
			}
			this.value="";
		}
		
		form1.downValue.value="";
		form1.downValue.onchange=function(){
			op.addOplist(op.selectObj,this.value);
		}
		
	
		
		document.body.onmouseup=function(){
			var button=event.button 
			if (button!=1){
			   rmenu.clear();
			   rmenu.add("新增项目","op.createOption()");
			   rmenu.add("删除当前项目","op.removeOption()");
			   rmenu.add("保存设置","op.save()");
			   rmenu.add("删除当前选项","op.delOption()");
			   rmenu.add("刷新页面","location.reload()");
			   rmenu.create();
			}else{
				rmenu.clear();
			}
		}
				
	}
	
	this.createOption=function(){//创建新的大项
		this.sindex="";
		cItem.innerHTML="";
		form1.select.checked=true;
		form1.optionName.value="";
		form1.downValue.readOnly=false;
		
	}
	
	this.addItem=function(objText,objValue){
		var tempObj=document.createElement("div");
		var div=cItem.appendChild(tempObj);
		div.id="MainDiv";
		
		tempObj=document.createElement("input");
		tempObj.id="nMainText";
		var text=div.appendChild(tempObj);
		text.value=objText;
		text.style.cssText="width:130px";
		
		tempObj=document.createElement("input");
		tempObj.id="nMainValue";
		tempObj.style.cssText="width:65px";
		tempObj.value=objValue;
		var val=div.appendChild(tempObj);
		
		form1.downValue.value="";
		
		div.onmouseover=function(){
			op.tempObj=this;
		}
		
		div.onmouseout=function(){
			op.tempObj=null;
		}
		
		div.onclick=function(){
			op.selectObj=op.tempObj;
			form1.downValue.value=op.readOplist(this);
		}
		return  div;
	}
	
	
	
	
	this.readOplist=function(obj){
		var l=downOptionList.length;
		for (var i=0;i<l;i++){
			if (downOptionList[i][0]==obj){
				return downOptionList[i][1];
			}
		}
		return "";
	}
	
	this.addOplist=function(obj,value){
		if (obj==null){
			return ;
		}
		var l=downOptionList.length;
		for (var i=0;i<l;i++){
			if (downOptionList[i][0]==obj){
				downOptionList[i][1]=value;
				return ;
			}
		}
		downOptionList[l]=new Array();
		downOptionList[l][0]=obj;
		downOptionList[l][1]=value;
		return ;
	}
	
	this.delOption=function(){
		if (this.selectObj==null){
			return ;
		}
		this.selectObj.removeNode(true);
	}
	
	this.selecttype=function(obj){
		if (obj.id!="select"){
			form1.downValue.readOnly=true;
		}else{
			form1.downValue.readOnly=false;
		}
	}
	
	this.save=function(){
		var v=new validate();
		v.form=document.getElementById("form1");
		if (!v.start()){  //验证必填项
		   return ;
		}
		try{
			var l=MainDiv.length;
			if (l==0 | l==null){
				return ;
			}
		}catch(e) {
			alert("请填写选项")
			 return 
		}
		var sName=form1.optionName.value;
		var sType="0";
		if (form1.radio.checked){sType="1"}
		if (form1.checkbox.checked){sType="2"}
		var mainTextStr="";
		var mainValueStr="";
		var downTextStr="";
		for (var i=0;i<l;i++){
			downTextStr=downTextStr+this.readOplist(MainDiv[i])+c1;
			mainTextStr=mainTextStr+form1.nMainText[i].value+c1;
			mainValueStr=mainValueStr+form1.nMainValue[i].value+c1;
		}
		
		
		//alert(downTextStr+"|"+mainTextStr+"|"+mainValueStr)
		
		var objResponse=new JHttpResponse();
		objResponse.write("sName",sName);
		objResponse.write("sType",sType);
		objResponse.write("sindex",this.sindex);
		objResponse.write("downTextStr",downTextStr);
		objResponse.write("mainTextStr",mainTextStr);
		objResponse.write("mainValueStr",mainValueStr);
		objResponse.write("dataType",this.dataType);
		objResponse.write("menuID",$("menuID").value);
		objResponse.write("menuName",$("menuName").value);
		objResponse.write("menuTable",$("menuTab").value);
		
		var out=objAjax.getText("post","optionSetupServer.aspx?type=save",objResponse,null);
		if (out=="OK"){
			alert("保存成功")
			this.readList();
			serverOption.clear();
	    }else{
	   	    alert(out)
		}
		
	}
	
	
	this.readList=function(){  //加载大项
		var out=objAjax.getText("post","optionSetupServer.aspx?type=readList",null,null);
		out=comminute(out,c1,c2);
		optionsObj=document.getElementById("options")
		optionsObj.innerHTML="";
		for (var i=0;i<out.length-1;i++){
			var tempObj=document.createElement("div");
			var div=optionsObj.appendChild(tempObj);
			div.innerText=out[i][1];
			div.sindex=out[i][0];
			div.className="createOption_1";
			div.id="";
			
			div.onmouseover=function(){
				this.className="createOption";
				op.tempObj=this;
			}
			
			div.onmouseout=function(){
				if (op.selectOption!==this){
					this.className="createOption_1";
				}
				op.tempObj=null;
			}
			
			div.onmouseup=function(){
				if (op.selectOption!=op.tempObj & op.selectOption!=null){
					op.selectOption.className="createOption_1";
				}
				op.selectOption=op.tempObj;
				op.loadOption();
				
				
			}
			
			
			
		}
   	   // alert(out)
	}
	
	this.removeOption=function(){
		var obj=this.selectOption;
		if (obj==null){return}
	    if (window.confirm("你正在准备删除一个已设置好的选项\n\n此操作将导致所有引用这个选项的程序失败\n\n是否继续?")){
			var objResponse=new JHttpResponse();
			objResponse.write("sindex",obj.sindex);
			var out=objAjax.getText("post","optionSetupServer.aspx?type=remove",objResponse,null);
			if (out=="OK"){
				this.readList();
			}else{
				alert(out);
			}
		 }
	}
	
    this.loadOption=function(){ //加载选项
		//serverOption
		var sindex=this.selectOption.sindex;
		var opArray=this.findOption(sindex);
		if (opArray==null){
			var objResponse=new JHttpResponse();
			objResponse.write("sindex",sindex);
			var out=objAjax.getText("post","optionSetupServer.aspx?type=readItem",objResponse,null);
			opArray=comminute(out,c1,c2);
			serverOption[serverOption.length]=opArray;
		}
		
//		sindex,sName,mainItemText,mainItemValue,downItem,itemType,menuid,tabName,menuName,dataType
//        0     1      2           3               4        5         6        7  8         9
		if (opArray[0][9]=="2"){
			$("menuSetup").click();
			$("menuName").value=opArray[0][8];
			$("menuID").value=opArray[0][6];
			$("menuTab").value=opArray[0][7];
		}else{
			$("mySetup").click();
		}
		cItem.innerHTML="";
		for (var i=0;i<opArray.length-1;i++){
			 var option=opArray[i];
			 var div=this.addItem(option[2],option[3]);
			 this.addOplist(div,option[4]);
		}
		this.sindex=option[0];
		form1.optionName.value=option[1];
		if (option[5]!="0"){
			if (option[5]=="1"){
				form1.radio.click();
				//form1.radio.checked=true;
			}else{
				form1.checkbox.click();
				//form1.checkbox.checked=true;
			}
		}else{
			form1.select.click();
			//form1.select.checked=true;
		}
		
		
	}
	
	this.findOption=function(sindex){
		if (serverOption.length==0){
			return null
		}
		// sindex,sName,mainItemText,mainItemValue,downItem,itemType
		//  0       1      2             3            4        5
		for (var i=0;i<serverOption.length;i++){
			var opArray=serverOption[i];
			
			if (opArray[0][0]==sindex){
				//alert(opArray[0][0]+"|"+sindex);
				return opArray;
			}
		}
		return null;
	}
	
	this.selectMenu=function(){
		var arr=openSelectMenu();
		if (arr==null){
			return;
		}
		arr=arr.split(c1);
		$("menuName").value=arr[0];
		$("menuID").value=arr[1];
		$("menuTab").value=arr[2];
	}
	
}