<%@ page contentType="text/html;charset=UTF-8" %>
<%@ 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=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<SCRIPT src="../../share/js/ftiens4_tree2.js"></SCRIPT>
</head>
<body>
<%
    String s = "";
		//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"));
	  int iFormID = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("FormID")));
	  int iInfoID = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("InfoID")));		
	  int iFlowID = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("FlowID")));
	  int iStepID = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("StepID")));
	  String RYBLYJ = SzConvert.toSpaceStr(request.getParameter("RYBLYJ"));
	  String BZRYID = SzConvert.toSpaceStr(request.getParameter("BZRYID"));
	  String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
    s = "";
      //+ "<input type='radio' name='DepartSelecting' value='' OnClick='ShowAllLogin2();'>显示全体员工"
      //+ "<input type='radio' name='DepartSelecting' value='0' OnClick='ClickDepart();'>显示没有部门的员工";    
%>
<%@ include file="/share/organize/user_js_include.jsp"%>
<table width="790" align="center" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formSelect" method="post">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
  <input type="hidden" name="win" value="win">
  <input type="hidden" name="objId" value="<%=objId%>">
  <input type="hidden" name="objName" value="<%=objName%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>">
  <input type="hidden" name="InfoID" value="<%=iInfoID%>">
  <input type="hidden" name="FlowID" value="<%=iFlowID%>">
  <input type="hidden" name="StepID" value="<%=iStepID%>">
  <input type="hidden" name="RYBLYJ" value="<%=RYBLYJ%>">
  <input type="hidden" name="BZRYID" value="<%=BZRYID%>">    
  <tr>
    <td colspan="3" align="center">
      <input type='radio' name='DepartSelecting' value='' OnClick='ShowAllLogin3();'>显示全体员工   
      <input type='radio' name='DepartSelecting' value='0' OnClick='ClickDepart();'>显示没有部门的员工 
      <input type="checkbox" name="login_checkall" value="1" OnClick="javascript:CheckAll(formSelect, login_checkall, 'LoginSelecting');" >人员全选&nbsp;
      <input type="button" name="btnOk" value="确定" OnClick="javascript:FunOk();">
      <input type="button" name="btnClose" value="关闭" OnCLick="javascript:window.close();">
    </td>
  </tr>
  <tr class="trClassTitle">
    <td>部门选择</td>
    <td>人员选择</td>
  </tr>
  <tr>
    <td width="26%" 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());
%> 
    <div id="divDepart"></div>
    </td>
    <!----------这里显示用户-------->
    <td width="74%" valign="top" align="left" id="tdUser">
      &nbsp;
    </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 ClickDepart() {
    //员工
    //var objId   = formSelect.objId.value;
    //var objName = formSelect.objName.value;

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

    //2009-04-15
    var j = 0;
    var oLogin;
    var oLoginName;
    var oTd;
    for (var i=0; i<userPostCount_JS; i++) {
        //oLogin = formSelect.LoginSelecting[i];
        //oLoginName = document.getElementById("LoginName" + i);
        oTd = document.getElementById("td" + i); 
        if (userPostArray_JS[i][0] == vBMID) {
        	//显示
        	//oLogin.style.display = "";
        	//oLoginName.style.display = "";
        	oTd.style.display = "";
        } else {
					//隐藏
					//oLogin.style.display = "none";
					//oLoginName.style.display = "none";
					oTd.style.display = "none";
        }
    }//for
  }

  //默认显示全部
  //将全体员工放进LoginSelecting
  //取得已经选中的员工ID，格式为0,1,2
  function ShowAllLogin2() {
    //var oWindow = window.dialogArguments;
    var oWindow = window.opener;
    var vId = formSelect.BZRYID.value;
    var oSelect = null;
    //if (objId != "") {
      //vId = eval("oWindow." + objId + ".value;");
    //}
    ShowAllLogin2_ini(vId);
  }

  function ShowAllLogin2_ini(vId) {
    tdUser.innerHTML = "";
    var vHTML = "<table width='100%' border='0'>";
    //var vHTML = "";
    var j = 0;
    vId = "," + vId + ",";
    var vCheck = "";
    for (var i=0; i<userPostCount_JS; i++) {
				if (vId.indexOf("," +userPostArray_JS[i][1] + ",") >=0) {
	   			//存在，选中
           vCheck = "checked";
        } else {
           vCheck = "";
        }
        j ++;
        if (i%3 == 0) {
        	//vHTML = vHTML + "<tr id='td" + i + "'>";
        	vHTML = vHTML + "<tr id='td" + i + "'>";
        }
        //vHTML = vHTML + "<td >";
        vHTML = vHTML + "<td id='td" + i + "'>";
        vHTML = vHTML + "<input type='checkbox' name='LoginSelecting' value='" + userPostArray_JS[i][1] + "' " + vCheck + " >";
        vHTML = vHTML + "<span id='LoginName" + i + "'>" + userPostArray_JS[i][2] + "</span>" + "&nbsp;";
        vHTML = vHTML + "</td>";
        
        if (i%3 == 2) {
        	vHTML = vHTML + "</tr>";
        }
    }
    vHTML = vHTML + "</table>"
    tdUser.innerHTML = vHTML;
  }
  
  function ShowAllLogin3() {
    var oLogin;
    var oLoginName;
    var oTd;    
    for (var i=0; i<userPostCount_JS; i++) {
        //oLogin = formSelect.LoginSelecting[i];
        //oLoginName = document.getElementById("LoginName" + i);
        oTd = document.getElementById("td" + i); 
        oTd.style.display = "";
    }
  }  
 
  
  //显示指定的一级部门下的部门
  function ShowAllDepart2(vBMBH_PARENT) {
    var oTd;
    
    for (var i=0; i<departCount_JS; i++) {
        oTd = document.getElementById("departtd" + i);
        if (vBMBH_PARENT == "" || departArray_JS[i][2] != null && departArray_JS[i][2].indexOf(vBMBH_PARENT) == 0) {            
            oTd.style.display = "";
        } else {
			oTd.style.display = "none";
        }
    }    
  }
  
  //显示所有部门，第一次的时候调用
  function ShowAllDepart3() {
    //var oWindow = window.dialogArguments;
    var oWindow = window.opener;
    ShowAllDepart3_ini();
  }
  function ShowAllDepart3_ini() {
    divDepart.innerHTML = "";
    var vHTML = "<table width='100%' border='0'>";
    //var vHTML = "";
    var j = 0;
    var vBMBH_P

    var vCheck = "";
    
    for (var i=0; i<departCount_JS; i++) {
        if (departArray_JS[i][2] != null) {
          vHTML = vHTML + "<tr id='departtd" + i + "'><td>";
        	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 + "</td></tr>";
        } 
    }    
    vHTML = vHTML + "</table>"
    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;
  }
</SCRIPT>
<script language="javascript">
  //用户
  var objId   = formSelect.objId.value;
  var objName = formSelect.objName.value;
    
  function FunOk() {
  	var count = NumberOfCheck(formSelect.LoginSelecting);
  	if (count == 0) {
  		alert("请至少选择一个人员");
  		return;
  	}
  	if (count == 1) {
  		//alert(ValueOfCheck(formSelect.LoginSelecting));
  		var vDLID = "," + "<%=szDLID_SESSION%>";
  		if (vDLID == ValueOfCheck(formSelect.LoginSelecting)) {
  			alert("不能只选择自己一个人");
  			return;
  		}
  	}
		if (confirm("确定改变办理的人员？")) {
		
			formSelect.action = "select_control.jsp";
			formSelect.submit();
		}
  }

  ShowAllDepart3();
  ShowAllLogin2();
  
</script>

