<%@ page contentType="text/html;charset=gbk" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Map" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.organize.*" %>
<%@ include file="/sessionInfo.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<SCRIPT src="../../share/js/ftiens4_tree2.js"></SCRIPT>
</head>
<body>
<%
    //只列出有部门的登陆帐号2008-01-03

    //type=all没有限制，same同一部门，tree树下的子部门
    String type = SzConvert.toSpaceStr(request.getParameter("type"));
    if (type.equals("")) {
        type = "all"; //默认是全部
    }
    String objId = SzConvert.toSpaceStr(request.getParameter("objId"));
    String objName = SzConvert.toSpaceStr(request.getParameter("objName"));
    String objDesc = SzConvert.toSpaceStr(request.getParameter("objDesc"));
    String objDescName = SzConvert.toSpaceStr(request.getParameter("objDescName"));
    String objPostId = SzConvert.toSpaceStr(request.getParameter("objPostId"));
    String objPostName = SzConvert.toSpaceStr(request.getParameter("objPostName"));    
%>
<%@ include file="/share/organize/user_js_include.jsp"%>
<!---------------------->

<table width="650" align="center" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formSelect" method="post">
  <input type="hidden" name="objId" value="<%=objId%>">
  <input type="hidden" name="objName" value="<%=objName%>">
  <input type="hidden" name="objDesc" value="<%=objDesc%>">
  <input type="hidden" name="objDescName" value="<%=objDescName%>">
  <input type="hidden" name="objPostId" value="<%=objPostId%>">
  <input type="hidden" name="objPostName" value="<%=objPostName%>">  
  <tr>
    <td colspan="3" align="center">
    
      <input type="button" name="btnOk" class="btnClass" value="确定" OnClick="javascript:FunOk();">
      <input type="button" name="btnClose" class="btnClass" value="关闭" OnCLick="javascript:window.close();">

    </td>
  </tr>
  <tr class="trClassTitle2">
    <td id="tdDepartTitle">部门选择</td>
    <td id="tdUserTitle">人员选择</td>
    <td id="tdPostTitle">职务选择</td>
  </tr>
  <tr>
    <td width="36%" height="350" valign="top"  id="tdDepart"><!----------这里显示部门-------->
<%
	//读取部门
	SzUserHelp szUserHelp = new SzUserHelp();
	//Map map = szUserHelp.getDepartStaticMap();
	Iterator iter = SzUserHelp.getDepartStaticList(szCOMPANY_SESSION).iterator();
	SzDepartInfo szDepartInfo = new SzDepartInfo();
	boolean flag = true;

	String sBMMC = "";
	String sBMBH = "";
	String sBMBH_SJ = "";
		
    int iBMID = 0;
    SzDepart szDepart = new SzDepart();
    out.println(szDepart.printFirstLevelDepart(szCOMPANY_SESSION));
%>
    <div id="divDepart"></div>
    </td>
    <!----------这里显示用户-------->
    <td width="44%" valign="top" align="left" id="tdUser">
      &nbsp;
    </td>
    <!----------这里显示职务-------->   
    <td width="20%" valign="top" align="left" id="tdPost">
<%
    Collection collPost = SzUserHelp.getPostStaticList();    
    Iterator iterPost = null;
    if (collPost != null) {
      iterPost = collPost.iterator(); 
    }
    SzPostInfo szPostInfo = null;
    while (iterPost != null && iterPost.hasNext()) {
    	szPostInfo = (SzPostInfo)iterPost.next();
    	out.println("<input type='radio' name='PostSelected' value='" + szPostInfo.getZWID() + "' >");
    	out.println(szPostInfo.getZWMC() + "<br>");
    }

%> 
    </td>      
  </tr>
  </form>
</table>
</body>
<SCRIPT language="javascript" src="../../share/js/commonTool.js"></script>
<SCRIPT language="javascript">
  //根据部门ID，获取部门名称
  function GetDepartName(vBMID) {
    var vBMMC = "";
    for (var i=0; i<departCount_JS; i++) {
      if (departArray_JS[i][0] == vBMID) {
        vBMMC = departArray_JS[i][1];
        break;;
      }
    }
    return vBMMC;
  }
  
  function GetPostName(vZWID) {
    var vZWMC = "";
    for (var i=0; i<postCount_JS; i++) {
      if (postArray_JS[i][0] == vZWID) {
        vZWMC = postArray_JS[i][1];
        break;
      }
    }
    return vZWMC;
  }  
  //选择部门，显示用户
  function ClickDepart() {
    var objId   = formSelect.objId.value;
    var objName = formSelect.objName.value;
    var objDesc = formSelect.objDesc.value;
    var objDescName = formSelect.objDescName.value;
    //如果没有用户，就不用管这个了
    if (objId == "" && objName == "") {
        return;
    }

    //获取选择的部门
    var vBMID = "0";
    //vBMID = ValueOfRadio(formSelect.DepartSelecting);
    vBMID = ValueOfRadio2("DepartSelecting");

    tdUser.innerHTML = "";
    var vHTML = "<table width='100%' border='0'>";
    var j = 0;
    //========显示部门的全体人员========
      //如果选择了部门，或者选择了没有部门的
    for (var i=0; i<userPostCount_JS; i++) {
        //如果是同一个部门的，就放进去
        //因为员工是按照部门排序的，所以这里可以加一个变量，如果已经加完同一部门的，就跳出循环。
        if (userPostArray_JS[i][0] == vBMID) {

          if (j % 2 == 0) {
            vHTML = vHTML + "<tr><td>";
            vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td>";
          } else {
            vHTML = vHTML + "<td>";
            vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td></tr>";
          }
          j ++;

        } // if == ends
    }//for

    vHTML = vHTML + "</table>"
    tdUser.innerHTML = vHTML;
  }

  //默认显示全部
  //将全体员工放进LoginSelecting
  function ShowAllLogin2() {
    tdUser.innerHTML = "";
    var vHTML = "<table width='100%' border='0'>";
    var j = 0;
    for (var i=0; i<userPostCount_JS; i++) {
        if (j % 2 == 0) {
            vHTML = vHTML + "<tr><td>";
            vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td>";
        } else {
            vHTML = vHTML + "<td>";
            vHTML = vHTML + "<input type='radio' name='LoginSelecting' value='" + i + "'>" + userPostArray_JS[i][2] + "&nbsp;";
            vHTML = vHTML + "</td></tr>";
        }
        j ++;
    }
    vHTML = vHTML + "</table>"
    tdUser.innerHTML = vHTML;
  }
  
  function ShowAllDepart2(vBMBH_PARENT) {
    divDepart.innerHTML = "";
    var vHTML = "";
    var j = 0;
    var vBMBH_P
    for (var i=0; i<departCount_JS; i++) {
        if (vBMBH_PARENT == "" || departArray_JS[i][2] != null && departArray_JS[i][2].indexOf(vBMBH_PARENT) == 0) {
        	vHTML = vHTML + "<input type='radio' name='DepartSelecting' value='" + departArray_JS[i][0] + "'  OnClick='ClickDepart();'>";
        	vHTML = vHTML + getLevelSpace(departArray_JS[i][2], <%=SzLevelNumber.I_NUMBER_LEN%>) +  departArray_JS[i][1];
        	vHTML = vHTML + "<BR>";
        } 
    }
    
    divDepart.innerHTML = vHTML;
  }  
  
  //选择部门
  function SelectFirstDepart() {
	//alert(formSelect.firstDepartNumber.value);
	//只显示一级下的部门
	var vBMBH_PARENT = formSelect.firstDepartNumber.value;
	ShowAllDepart2(vBMBH_PARENT);
  }  
  
  function getLevelSpace(number, vNumberLen) {
    var vLen = number.length;
    var vCount = vLen / vNumberLen;
    
    var vReturn = "";
    for(var i=1; i<vCount; i++) {
		vReturn += "&nbsp;&nbsp;";
    }
    return vReturn;
  }    
  
  var objId   = formSelect.objId.value;
  var objName = formSelect.objName.value;
  var objDescName = formSelect.objDescName.value; 
  //如果没有用户，就不用管这个了
  if (objName != "") {
    ShowAllLogin2();
    ShowAllDepart2("");    
  } else if (objDescName != "") {
    ShowAllDepart2("");    
  }
</SCRIPT>
<script language="javascript">
    var objId   = formSelect.objId.value;
    var objName = formSelect.objName.value;
    var objDesc = formSelect.objDesc.value;
    var objDescName = formSelect.objDescName.value;
    //职务
    var objPostId = formSelect.objPostId.value;
    var objPostName = formSelect.objPostName.value;
    
  function FunOk() {
    var oWindow = window.dialogArguments;

    
    var vId = "";
    var vName = "";
    var vDesc = "";
    var vDescName = "";
    var vPostId = "";
    var vPostName = "";    
    //确定，获取
    var j = 0;
    //这里是单个的选择，
    //这里是数组的index
    var vIndex = -1;
    //如果没有用户，就不用管这个了

    if (objId == "" && objName == "") {
        vIndex = 0;
        vId = "";
        vName = "";
        //vDesc = ValueOfRadio(formSelect.DepartSelecting);
        vDesc = ValueOfRadio2("DepartSelecting");
        vDescName = GetDepartName(vDesc);
    } else {
        //vIndex = ValueOfRadio(formSelect.LoginSelecting);
        vIndex = ValueOfRadio2("LoginSelecting");
        if (vIndex == "") {
          vIndex = "-1";
        }
        //根据数据的index获取部门ID，部门名称，登陆ID，员工姓名
        if (vIndex >=0) {
          vId = userPostArray_JS[vIndex][1];
          //vName = userPostArray_JS[vIndex][2];
	  	  vName = userPostArray_JS[vIndex][4];	//新增加一个登陆姓名
          vDesc = userPostArray_JS[vIndex][0];
          vDescName = userPostArray_JS[vIndex][3];
        }
    }
    if (vIndex >= 0) {
      if (objId != "") {
          eval("oWindow.document." + objId + ".value='" + vId + "';");
      }
      if (objName != "") {
          eval("oWindow.document." + objName + ".value='" + vName + "';");
      }
      if (objDesc != "") {
          eval("oWindow.document." + objDesc + ".value='" + vDesc + "';");
      }
      if (objDescName != "") {
          eval("oWindow.document." + objDescName + ".value='" + vDescName + "';");
      }    
    } else {
      if (objId != "") {
          eval("oWindow.document." + objId + ".value='';");
      }
      if (objName != "") {
          eval("oWindow.document." + objName + ".value='';");
      }
      if (objDesc != "") {
          eval("oWindow.document." + objDesc + ".value='';");
      }
      if (objDescName != "") {
          eval("oWindow.document." + objDescName + ".value='';");
      }     
    }
        
    var oSelect = document.getElementsByName("PostSelected");
    if (oSelect != null) {
      vIndex = ValueOfRadio2("PostSelected");
      j = 0;
      vLen = oSelect.length;
      for (i=0; i<vLen; i++) {
        //是否选中？
        if (oSelect[i].checked == true) {          
          //这个是职务ID
          vIndex = oSelect[i].value;
          vPostId = vIndex;
          vPostName =  GetPostName(vIndex);
          //增加部门
          j++;
          break;
        }
      } //for i=0;

    } //if();
    if (objPostId != "") {
    	eval("oWindow.document." + objPostId + ".value ='" + vPostId + "';");
    }
    if (objPostName != "") {
    	eval("oWindow.document." + objPostName + ".value ='" + vPostName + "';");
	} 


    window.close();

  }

  //window.resizeTo(1800, 450);
  if (objId == "" && objName == "") {
	tdUser.style.display = "none";
	tdUserTitle.style.display = "none";	
  }
  if ( objDesc == "" && objDescName == "" && objId == "" && objName == "") {
    tdDepart.style.display = "none";
    tdDepartTitle.style.display = "none";
  }
  if (objPostId == "" && objPostName == "") {
	tdPost.style.display = "none";
	tdPostTitle.style.display = "none";
  } 
</script>

