var hiddenNodes=[];	//用于存储被隐藏的结点
	
	$(function(){
		init();
	
	})
	var zTreeObj;
	function init(){
		
		$.get("../../number/search/dept_list_ajax.jsp", function(data) {
				zTreeObj = $.fn.zTree.init($("#tree-obj"), setting, data); //.expandAll(true);
		        // 展开第一级节点
		        var nodes = zTreeObj.getNodesByParam("level", 0);
		        console.log(nodes);
		        for (var i = 0; i < nodes.length; i++) {
		        	zTreeObj.expandNode(nodes[i], true, false, false);
		        }
		        // 展开第二级节点
		        nodes = zTreeObj.getNodesByParam("level", 1);
		        for (var i = 0; i < nodes.length; i++) {
		        	zTreeObj.expandNode(nodes[i], true, false, false);
		        }
		        // 展开第三级节点
		        nodes = zTreeObj.getNodesByParam("level", 2);
		        for (var i = 0; i < nodes.length; i++) {
		        	zTreeObj.expandNode(nodes[i], true, false, false);
		        }
		
		
		    }
		);
		var setting = {		//ztree配置选项
				view:{selectedMulti:false,showLine:false},
		        data:{
		            key:{title:"name",name:"name"},
		            simpleData:{enable:true}
		        },
		        callback:{
		            onClick:function(event, treeId, treeNode){
		                $.post("../../number/search/right_user_list.jsp", {"dept_id":treeNode.id,"dept_user_name":treeNode.name},
		                    function(data) {
		                		window.setTimeout("getDeptInfo('"+treeNode.id+"')",100);
		                        $("#user_list").html(data);
		                    }
		                )
		            }
				}
		};
	};

	//过滤ztree显示数据
	function filter(){
		//显示上次搜索后背隐藏的结点
		zTreeObj.showNodes(hiddenNodes);
	
		//查找不符合条件的叶子节点
		function filterFunc(node){
			var _keywords=$("#keyword").val();
			_keywords = _keywords.substring(_keywords.indexOf("/")+1,_keywords.length);
			if(node.name==_keywords||node.jm_1==_keywords
				||node.jm_2==_keywords||node.jm_3==_keywords||node.jm_4==_keywords
				||node.jm_5==_keywords||node.jm_6==_keywords){
				$.post("../../number/search/right_user_list.jsp", {"opt":"logger","dept_id":node.id,"dept_user_name":node.name},
					function(data) {
						window.setTimeout("getDeptInfo('"+node.id+"','"+node.name+"')",100);
						$("#user_list").html(data);
					}
				)
			}
			if(node.isParent||node.name.indexOf(_keywords)!=-1||node.jm_1==_keywords
				||node.jm_2==_keywords||node.jm_3==_keywords||node.jm_4==_keywords
				||node.jm_5==_keywords||node.jm_6==_keywords) {

				return false;
			}


			return true;		
		};
	
		//获取不符合条件的叶子结点
		hiddenNodes=zTreeObj.getNodesByFilter(filterFunc);
		//隐藏不符合条件的叶子结点
		zTreeObj.hideNodes(hiddenNodes);
	};