<%@ page contentType="text/html;charset=GBK" %>
<%@ 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.guide.*" %>
<%@ include file="/sessionInfo.jsp"%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<style type=text/css>
	img{vertical-align:middle;} 

    t img { vertical-align:middle;}	
    
body{ 
SCROLLBAR-FACE-COLOR: white;
SCROLLBAR-HIGHLIGHT-COLOR: white; 
SCROLLBAR-SHADOW-COLOR: white;
SCROLLBAR-3DLIGHT-COLOR: white;
SCROLLBAR-ARROW-COLOR: #0C0C0C; 
SCROLLBAR-TRACK-COLOR: white; 
SCROLLBAR-DARKSHADOW-COLOR: white  
}
</style>
</head>


<body bgcolor="#F4FEFF">
<%
    //String sSearch = SzConvert.strWriteData(request.getParameter("search"));   
		String sSearch = SzConvert.toSpaceStr(request.getParameter("search"));
    //列出树
		Guide guide = new Guide();
    GuideInfo guideInfo = null;
    String sCond = "1=1";
    Iterator iter = guide.getArrayList(sCond, "ZNBH", 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/help/guide_bzk.gif";
    String closeUrl = strLevel_SESSION + "images/help/guide_bz.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 = "";
    while (iter != null && iter.hasNext()) {
        guideInfo = (GuideInfo)iter.next();
        id = guideInfo.getZNID();
        BH = guideInfo.getZNBH();
        BT = guideInfo.getZNBT();
        if (firstBH.equals("")) {
        	firstID = id;
        	firstBH = BH;
        }
        i++;    
        
        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+"\"/>");
        	}
        }
        //将部门编号存入BHlist
        BHlist.add(BH);        
%>
		<input type="hidden" name="bh" id="bh" value="<%=BH%>">
		<div id="ldiv<%=BH %>" ><% if (sSearch.equals("")) { %><%=SzLevelNumber.getLevelSpace(BH)%>
		     <img src="<%=openUrl2%>"  border='0' style="cursor:hand;" id="imgOpen<%=BH %>" OnClick="javascript:ClickDepart('<%=openUrl2 %>','<%=closeUrl2 %>','<%=BH %>');"><% } else { out.println("&nbsp;");} %>
		     <a href="guide_desktop.jsp?KEY=<%=id%>" target="szGuideMainFrame" 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%>" align="left"> 
<%    
		out.println("</div id=\"" + BH + "\"></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;
		  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); 
	  if (link !=null && link!= "") {	  
	  	link.click();
	  }
	}	
	initial();
</script>    
</body>