<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ include file="sessionInfo2.jsp"%>
<html>
<body>
<%
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    String sTitle = "";
    if (sType.equals("radio")) {
    	sTitle = "表单引擎单项选择设置窗体";
    } else if (sType.equals("check")) {
    	sTitle = "表单引擎多项选择设置窗体";
    } else if (sType.equals("select")) {
    	sTitle = "表单引擎下拉列表设置窗体";
    }
%>
<head>
<title><%=sTitle %></title>
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>


<form name="formUpdate" method="post" action="formSave.jsp">
  <input type="hidden" name="type" value="<%=sType%>">
<table width="245" border="0" align="center">
  <tr>
    <td colspan="2">
	  <b><%=sTitle %></b>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      选项value:<input type="text" name="txtValue" value="" class="txtClass1" style="width:130;">
     <input type="button" value="同下"  class="btnClassShort" OnClick="copyValue(formUpdate.txtValue, formUpdate.txtText);">
    </td>
  </tr>
  <tr>
    <td colspan="2">
      选项text&nbsp;:<input type="text" name="txtText" value=""  class="txtClass1"  style="width:130;">
     <input type="button" value="同上"  class="btnClassShort" OnClick="copyValue(formUpdate.txtText, formUpdate.txtValue);">
    </td>
  </tr> 
  <tr>
    <td width="180">
      <select name="selectOption" size="15" multiple style="width:180;" OnChange="Select();"></select>
    </td>
    <td align="left">
      <input type="button" value="添加"  class="btnClassShort" OnClick="Add();"><br>
      <input type="button" value="删除" class="btnClassShort" OnClick="Delete();"><br>     
      <input type="button" value="上移" class="btnClassShort" OnClick="Up();"><br>
      <input type="button" value="下移" class="btnClassShort" OnClick="Down();">      
    </td>  
  </tr>
  <tr>
    <td colspan="2" align="center">
      <input type="button" value="确定" class="btnClass" OnClick="Save();">
      <input type="button" value="关闭" class="btnClass" OnClick="window.close();">
    </td>  
  </tr>    
</table>

</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  function Add() {
    var vText = formUpdate.txtText.value;
    var vValue = formUpdate.txtValue.value;
    AddOption(vText, vValue);
    formUpdate.txtText.value = "";
    formUpdate.txtValue.value = "";     
  }
  
  function AddOption(vText, vValue) {
    var vLen = formUpdate.selectOption.length;
    formUpdate.selectOption.options[vLen] = new Option(vText,vValue);   
  }
  
  function Delete() {
    var vIndex = formUpdate.selectOption.selectedIndex;
    if (vIndex >=0 ) {
    	formUpdate.selectOption.options[vIndex] = null;
    	formUpdate.txtText.value = "";
    	formUpdate.txtValue.value = "";     	
    }
  }
  
  function Select() {
    var vIndex = formUpdate.selectOption.selectedIndex;
    if (vIndex >=0 ) {
		formUpdate.txtText.value = formUpdate.selectOption.options[vIndex].text;
    	formUpdate.txtValue.value = formUpdate.selectOption.options[vIndex].value;
    }  
  }
  
  function Down() {
    var vIndex = formUpdate.selectOption.selectedIndex;
    var vLen = formUpdate.selectOption.length;
    if (vIndex< vLen -1) {
		var vText = formUpdate.selectOption.options[vIndex + 1].text;
    	var vValue = formUpdate.selectOption.options[vIndex  + 1].value;  
    	
    	formUpdate.selectOption.options[vIndex + 1].text 
    	=  formUpdate.selectOption.options[vIndex].text;
    	formUpdate.selectOption.options[vIndex + 1].value 
    	=  formUpdate.selectOption.options[vIndex].value;  
    	
    	formUpdate.selectOption.options[vIndex].text 
    	=  vText;
    	formUpdate.selectOption.options[vIndex].value 
    	=  vValue;  	
    	
    	formUpdate.selectOption.options[vIndex +1].selected = true;    	 
    }  
  }
  
  function Up() {
    var vIndex = formUpdate.selectOption.selectedIndex;
    if (vIndex>0) {
		var vText = formUpdate.selectOption.options[vIndex].text;
    	var vValue = formUpdate.selectOption.options[vIndex].value;  
    	
    	formUpdate.selectOption.options[vIndex].text 
    	=  formUpdate.selectOption.options[vIndex -1].text;
    	formUpdate.selectOption.options[vIndex].value 
    	=  formUpdate.selectOption.options[vIndex -1].value;  
    	
    	formUpdate.selectOption.options[vIndex -1].text 
    	=  vText;
    	formUpdate.selectOption.options[vIndex -1].value 
    	=  vValue;  	
    	
    	formUpdate.selectOption.options[vIndex -1].selected = true;    	 
    }   
  }
  
  function Save() {
    var oWindow = window.dialogArguments;
    if (oWindow == null) {
      return;
    }
    var vLen = formUpdate.selectOption.length; 
	var vText = "";
    var vValue = "";   
    var vHtml = "";
    var type = formUpdate.type.value;
    var id = "0";
    if (type == "radio") {
      id = oWindow.getNewObjectCount("31");
    } else if (type == "check") {
      id = oWindow.getNewObjectCount("32");
    } else if (type == "select") {
      id = oWindow.getNewObjectCount("133");
    }
      
    if (type == "select") {
	  vHtml += "<select name='" + id + "' id='" + id + "' class='txtClass1'>";
    }
    for (var i=0; i<vLen; i++) {
	  vText = formUpdate.selectOption.options[i].text;
      vValue = formUpdate.selectOption.options[i].value; 
      if (type == "radio") {
        vHtml += "<input type='radio' ";
        vHtml += " name='" + id + "' id='" + id + "' value='" + vValue + "' text='" + vText + "'>" + vText; 
      } else if (type == "check") {
        vHtml += "<input type='checkbox' ";
        vHtml += " name='" + id + "' id='" + id + "' value='" + vValue + "' text='" + vText + "'>" + vText; 
      } else if (type == "select") {
		vHtml += "<option value='" + vValue + "'>";
		vHtml += vText;
		vHtml += "</option>";
      }      
    }
    
    if (type == "select") {
	  vHtml += "</select>";
    }  
        
    oWindow.SetHtml(vHtml);
    window.close();
  }
  
  //2008-09-07新增加，修改的时候直接把选项带过去。	
  var oWindow = window.dialogArguments;
  if (oWindow != null) {
    //获取已经选中的html
    var oCell   = oWindow.getCellObject();
    var vObject = null;
    var vText   = "";
    var vValue  = "";
    if (oCell != null) {
      var iLenObject = oCell.childNodes.length;
      for (var m = 0; m<iLenObject; m++ ) {
        vObject = oCell.childNodes[m];
        if (vObject != null && vObject.id != null && vObject.id.indexOf("XX") != -1) {
		  if (vObject.type == "radio" || vObject.type == "checkbox" || vObject.type == "select") {
			//加到option中			
			vText  = vObject.text;
			vValue = vObject.value;
			AddOption(vText, vValue);
		  }
        } 
      }//for m      
    }
  }
</script>
</body>
</html>