<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="/xml/formEngine2/sessionInfo2.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
    //获取提交的参数
    String name = SzConvert.toSpaceStr(request.getParameter("name"));
    String readonly = "";
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    BdOptions bdOptions = new BdOptions();
    String str[] = bdOptions.getInfo(name);
    
	if (sOPERATOR.equals("add")) {
	} else if (sOPERATOR.equals("update")) {
	}   	
%>
<body>

<!-----上面的工具栏------>
<form name="formUpdate" method="post">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
<%@ include file="/xml/formEngine2/title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <%=SzPageHelp.saveButton()%>
      <%=SzPageHelp.backButton()%>
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="650" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tdClassTitle">名称</td>
    <td colspan="3"><input type="text" name="name" value="<%=str[0]%>" size="10" <%if (sOPERATOR.equals("update")){%> readonly class="txtClass1R"<%}else {%>class="txtClass1"<%} %>><font color="red">*</font>(可用字母、数字、下划线的组合，10个字以内) </td>
  </tr>
  <tr>
    <td class="tdClassTitle">中文名称</td>
    <td colspan="3"><input type="text" name="desc" class="txtClass2" value="<%=str[1]%>"><font color="red">*</font></td>
  </tr> 
  <tr>
    <td class="tdClassTitle">选项信息</td>
    <td colspan="3">
      <input type="hidden" name="optionsValue" value="" class="txtClass1">
      <input type="hidden" name="optionsText" value="" class="txtClass1">
      选项value<input type="text" name="txtField" value="" class="txtClass1">
      选项text<input type="text" name="txtObject" value="" class="txtClass1">
      <input type="button" value="添加"  class="btnClassShort" OnClick="Add();">
      <input type="button" value="删除" class="btnClassShort" OnClick="DeleteItem();">      
    </td>  
  </tr>       
  <tr>
    <td valign="top" class="tdClassTitle"><br>选项value<br>
      <input type="button" value="上移" class="btnClassShort" OnClick="Up();"><br>
      <input type="button" value="下移" class="btnClassShort" OnClick="Down();"> <br>   
      (最多18个)
    </td>
    <td>
      <select name="fieldName" size="10" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(str[2], "," )); %>  
      </select>
    </td>
    <td valign="top"><br>选项text</td>
    <td>
      <select name="objectName" size="10" multiple style="width:180;">
      <% out.println(SzPageHelp.selectOption(str[3], "," )); %>
      </select>
    </td>  
  </tr>
</table>

</form>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript" src="../../../share/js/commonTool.js"></script>
<script language="javascript" src="../../../share/js/selectTool.js"></script>
<script language="javascript">
  function Add() {   
    var vField = formUpdate.txtField.value;
    var vObject = formUpdate.txtObject.value;
    
    if (!notSpace(formUpdate.txtField, "选项value")) {
      return false;
    }
    if (!notSpace(formUpdate.txtObject, "选项text")) {
      return false;
    }   
    var vLen = 0;
    vLen = formUpdate.fieldName.length;
    formUpdate.fieldName.options[vLen] = new Option(vField, vField); 
       
    vLen = formUpdate.objectName.length;
    formUpdate.objectName.options[vLen] = new Option(vObject, vObject);      
    formUpdate.txtField.value = "";
    formUpdate.txtObject.value = "";           
  }
  function DeleteItem() {  
    var vIndex = formUpdate.fieldName.selectedIndex;
    if (vIndex == -1) {
    	alert("请选择下面的其中一个选项");
    	return;
    }
    if (confirm("确定要删除选中的选项信息？")) {
    	formUpdate.fieldName.options[vIndex] = null;
    	formUpdate.objectName.options[vIndex] = null;    	
    } 
  }   
  function Down() {
    var vIndex = 0;
    var vLen   = 0;
    var vText  = "";
    var vValue = "";
    var oObject = null;
    oObject = formUpdate.fieldName;
    vIndex = oObject.selectedIndex;
    vLen   =  oObject.length;
    if (vIndex< vLen -1) {
		vText = oObject.options[vIndex + 1].text;
    	vValue = oObject.options[vIndex  + 1].value;  
    	
    	oObject.options[vIndex + 1].text 
    	=  oObject.options[vIndex].text;
    	oObject.options[vIndex + 1].value 
    	=  oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  vText;
    	oObject.options[vIndex].value 
    	=  vValue;  	
    	
    	//oObject.options[vIndex +1].selected = true;    
    	oObject = formUpdate.objectName;
		vText = oObject.options[vIndex + 1].text;
    	vValue = oObject.options[vIndex  + 1].value;  
    	
    	oObject.options[vIndex + 1].text 
    	=  oObject.options[vIndex].text;
    	oObject.options[vIndex + 1].value 
    	=  oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  vText;
    	oObject.options[vIndex].value 
    	=  vValue;    		 
    }  
  }
  
  function Up() {
    var vIndex = 0;
    var vLen   = 0;
    var vText  = "";
    var vValue = "";
    var oObject = null;
    oObject = formUpdate.fieldName;
    vIndex = oObject.selectedIndex;
    vLen   =  oObject.length;
      
    if (vIndex>0) {
		vText = oObject.options[vIndex].text;
    	vValue = oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  oObject.options[vIndex -1].text;
    	oObject.options[vIndex].value 
    	=  oObject.options[vIndex -1].value;  
    	
    	oObject.options[vIndex -1].text 
    	=  vText;
    	oObject.options[vIndex -1].value 
    	=  vValue;  	
    	
    	//oObject.options[vIndex -1].selected = true;
    	oObject = formUpdate.objectName;    	
		  vText = oObject.options[vIndex].text;
    	vValue = oObject.options[vIndex].value;  
    	
    	oObject.options[vIndex].text 
    	=  oObject.options[vIndex -1].text;
    	oObject.options[vIndex].value 
    	=  oObject.options[vIndex -1].value;  
    	
    	oObject.options[vIndex -1].text 
    	=  vText;
    	oObject.options[vIndex -1].value 
    	=  vValue;      	    	 
    }   
  }  
  function FormSave(formName, url) {
    if (!notSpace(formName.name, "名称")) {
      return false;
    }  
    if (!notSpace(formName.desc, "中文名称")) {
      return false;
    } 
    if (formUpdate.txtField.value != "" || formUpdate.txtObject.value != "") {
    	//提醒还有没添加的关联信息
    	if (confirm("还有没添加的选项信息,是否返回添加")) {
    		return false;
    	}
    }    
    if (formName.fieldName.length == 0) {
    	alert("选项信息的至少要有一个选项value和text");
    	return false;
    }       
    formName.optionsValue.value = ValueOfSelect(formName.fieldName,",");
    formName.optionsText.value = ValueOfSelect(formName.objectName,","); 
          
    formName.action = "control.jsp";
    formName.submit();
  }
 


</script>
</body>
