<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.docEngine.*" %>
<%@ include file="/sessionInfo.jsp"%>
<%@ include file="/docEngine/docEngineSession.jsp"%>

<html>
<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">
<style type=text/css>
	img{vertical-align:middle;} 

    t img { vertical-align:middle;}	
    

</style>

</head>

<body bgcolor="#F4FEFF" onselectstart="return false;" class="scrollbar"> 
<div style="width:1024px;">

<%
    //String sSearch = SzConvert.strWriteData(request.getParameter("search"));   
	String sSearch = SzConvert.toSpaceStr(request.getParameter("search"));
    //列出树
	WdyqType wdyqType = new WdyqType(moduleId);
	WdyqTypeInfo wdyqTypeInfo = null;
    String sCond = "FLGSID=" + szCOMPANY_SESSION;
    if (docEngineInfo.getModulePopedom().equals("0")) {
    	sCond += " AND FLDLID=" + szDLID_SESSION;
    } else {
    	sCond += " AND 1=1";
    }
    Iterator iter = wdyqType.getArrayList(sCond, "FLBH", 0, sSearch).iterator();
    int i = 0;
    int id = 0;
    String BH = "";
    String BT = "";
    //用来保部门的编号
    ArrayList<String> BHlist = new ArrayList<String>();
    int size = 0;	//BHlist.size();
    String BHStr = "";	
    String openUrl = strLevel_SESSION + "images/share/dirOpen1.gif";
    String closeUrl = strLevel_SESSION + "images/share/dirClose1.gif";
    
    String openUrl2 = strLevel_SESSION + "images/share/dirOpen2.gif";
    String closeUrl2 = strLevel_SESSION + "images/share/dirClose2.gif";
    int j = 0;
    int firstID = 0;
    String firstBH = "";
    boolean isClose = true;		//是否收缩形菜单
    while (iter != null && iter.hasNext()) {
    	wdyqTypeInfo = (WdyqTypeInfo)iter.next();
        id = wdyqTypeInfo.getFLID();
        BH = wdyqTypeInfo.getFLBH();
        BT = wdyqTypeInfo.getFLMC();
        if (firstBH.equals("")) {
        	firstID = id;
        	firstBH = BH;
        }
        i++;    
        int count = 0;
        size = BHlist.size();
        for(j = 0; j<size; j++){
        	BHStr = BHlist.get(j);
        	if (BH.length()>BHStr.length() && BH.startsWith(BHStr)) {
        		out.println("<input type=\"hidden\" name=\"div"+BHStr+"\" value=\""+BH+"\"/>");
        		count++;
        	}
        }
        //将部门编号存入BHlist
        BHlist.add(BH);        
%>
		<input type="hidden" name="bh" id="bh" value="<%=BH%>">
		<div id="ldiv<%=BH %>" <%out.println(isClose&&BH.length()>3?"style=\"display: none;\"":""); %>><% if (sSearch.equals("")) { %><%=SzLevelNumber.getLevelSpace(BH)%>
		     <img src="<%=isClose?closeUrl2:openUrl2%>"  border='0' style="cursor:hand;" id="imgOpen<%=BH %>" OnClick="javascript:ClickDepart('<%=openUrl2 %>','<%=closeUrl2 %>','<%=BH %>');">
		     <% } else { out.println("&nbsp;");} %>
		     <a href="list_index.jsp?XXFL=<%=id%>" target="WDMainFrame" id="href<%=BH %>" OnClick="javascript:ClickDir('<%=BH %>');" onfocus="javascript:blur();">
		     <img src="<%=closeUrl%>"  border='0' style="cursor:hand;" id="dirOpen<%=BH %>">
		     <%=BT %></a>
		<div id="<%=BH%>" <%out.println(isClose&&BH.length()>=3?"style=\"display: none;\"":""); %> align="left"> 
<%    
		out.println("</div id=\"" + BH + "\"></div>");
    }
%>
</div>
           

<input type="hidden" id="currentDir" value="">
<input type="hidden" id="firstID" value="<%=firstID%>">
<input type="hidden" id="firstBH" value="<%=firstBH%>">
<input type="hidden" id="search" value="<%=sSearch%>">
<script language="javascript">

	function ClickDepart(openUrl,closeUrl,BMBH) {
		var oDiv = document.getElementById(BMBH);
		if (oDiv.style.display == "none") {
			oDiv.style.display = "";
			document.getElementById("imgOpen" + BMBH).src = openUrl;
			showLowerDiv("div",BMBH,"");
		} else {
			oDiv.style.display = "none";
			document.getElementById("imgOpen" + BMBH).src = closeUrl;
			showLowerDiv("div",BMBH,"none");
		}
	}
	
	function showLowerDiv(divPrefix,divBH,display){
		var divGroup = document.getElementsByName(divPrefix+divBH);
		var size = divGroup.length;	//下级的个数
		var value = "";				//记录遍历当前的级divBH
		var divBHlen = divBH.length;
		var showStr = "";		//记录本级的display
		var lateShowStr = "";	//记录上一级的display
		var lateDiv = divBH;	//记录上一级的divBH
		var nonediv = "";		//记录隐藏的divBH
		var isNull = true;		//隐藏的divBH上否为""
		for(var i = 0;i < size;i++){
			value = divGroup[i].value;
			if(display=="none"){	//隐藏所有下级部门
				document.getElementById("ldiv"+value).style.display = "none";
			}else{	//遍历所有下级部门层
				lateDiv = value.substr(0,value.length-3);
				lateShowStr = document.getElementById(lateDiv).style.display;
				showStr = document.getElementById(value).style.display;
				if(lateShowStr=="none"){	//这个条件意思如：ldiv001001与001的显示一致
					continue;
				}else{
					//判断当前级是不是记录下来的隐藏级的子级，是的话不显示
					if(nonediv!=""&&nonediv==value.substr(0,nonediv.length)){
						continue;
					}else{
						nonediv = "";
						document.getElementById("ldiv"+value).style.display = "";
					}
					//判断当前级的div是不是隐藏的，是的话记录下来
					if(nonediv==""&&showStr=="none"){
						nonediv = value;
					}
				}
			}
		}
	}
	
	function ClickDir(BH) {
	    var openUrl = "<%=openUrl%>";
	    var closeUrl = "<%=closeUrl%>";		
		var currentDir = document.getElementById("currentDir").value;
		if (currentDir != "") {
			//关闭
			document.getElementById("dirOpen" + currentDir).src = closeUrl;
		}
		document.getElementById("dirOpen" + BH).src = openUrl;
		document.getElementById("currentDir").value = BH;

	}
	
	//初始化,默认第一层都是关闭的.
	function initial() {
	    var openUrl = "<%=openUrl2%>";
	    var closeUrl = "<%=closeUrl2%>";
		
		var array = document.getElementsByName("bh");
		//var(array);
		var vLen = array.length;
	    var bh = "";
		for (var i=0; i<vLen; i++) {
		  if (array[i] == null) {
		  	continue;
		  }
		  bh = array[i].value;
		  //>=3隐藏所有的层,==3隐藏第一层
		  if (bh.length >= 3) {
		  	//隐藏
		  	//alert(bh);
		  	ClickDepart(openUrl,closeUrl,bh);
		  }
		}
	}
/*
	//搜索的话默认选中第一个
	var search = document.getElementById("search").value;
	if (search != "") {
	  var firstBH = document.getElementById("firstBH").value;	 
	  var link = document.getElementById("href" + firstBH); 
	  link.click();
	}	
	initial();
	*/
</script>    
</body>
