<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery.ztree.core-3.4.js"></script>
	<script type="text/javascript" src="${ctx_js_plugins}/zTree/js/jquery.ztree.excheck-3.4.js"></script>
	<link rel="stylesheet" href="${ctx_js_plugins}/zTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${ctx_js_plugins}/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript">
		var jQuery_1_4_4= $.noConflict(true);
	</script>
	<SCRIPT type="text/javascript">

		var inputObj;
		var initParams1="";
		var initParams2="";
		var initParams3="";
		var initParams4=false;
		function createSetting(){
			var setting = {
				view: {
					dblClickExpand: false,
					expandSpeed: "slow",
					selectedMulti: false
				},
				data: {
					simpleData: {
						enable : true,
						idKey : "id",
						pIdKey : "pId" ,
						DIY:"isAccessTopMenu"
					}
				},async: {
					enable: true,
					url:"${ctx}/sysGlType/geWfTypeTree.do",
					autoParam:["id", "name=n","level=lv"],
					otherParam:{"assignTreeId":initParams1,"treeLevel":initParams2}
				},
				callback: {
					onClick: onDblClick
				}
			};
			return setting;
		}

		function createSettingCheck(){
			var setting = {
				check: {
					enable: true,
					chkboxType: {"Y":"", "N":""}
				},
				view: {
					dblClickExpand: false,
					expandSpeed: "slow"
				},
				data: {
					simpleData: {
						enable : true,
						idKey : "id",
						pIdKey : "pId" ,
						DIY:"isAccessTopMenu"
					}
				},async: {
					enable: true,
					url:"${ctx}/sysGlType/geWfTypeTree.do",
					autoParam:["id", "name=n","level=lv"],
					otherParam:{"assignTreeId":initParams1,"treeLevel":initParams2}
				},
				callback: {
					beforeClick: beforeClick,
					onCheck: onCheck
				}

			};
			return setting;
		}

		function beforeClick(treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeDept");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}

		function onCheck(e, treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeDept"),
					nodes = zTree.getCheckedNodes(true),
					name = "",
					id="";

			//nodes.sort(function compare(a,b){return a.id-b.id;});
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].level<=0||nodes[i].level<=initParams3)
					continue;
				name += nodes[i].name + ",";
				id += nodes[i].id + ",";
			}

			if (id.length > 0 ) id = id.substring(0, id.length-1);
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				var fun=inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+id+"')");
			}catch(e){}
		}


		function onDblClick(e, treeId, treeNode) {
			var zTree = jQuery_1_4_4.fn.zTree.getZTreeObj("treeDept"),
					nodes = zTree.getSelectedNodes(),
					name = "",
					id="";
			if(nodes==""){
				try{
					var fun=inputObj+"OnDbClick";
					eval(fun+"('','')");
				}catch(e){}
				hideMenu();
				return ;
			}
			//nodes.sort(function compare(a,b){return a.id-b.id;});
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].level<=0||nodes[i].level<=initParams3)
					return;
				if(nodes[i].pId=="TOP_FLOW_TYPE"){
					continue;
				}
				name += nodes[i].name + ",";
				id += nodes[i].id + ",";
			}

			if (id.length > 0 ) {
				id = id.substring(0, id.length-1);
			}else{
				return;
			}
			if (name.length > 0 ) name = name.substring(0, name.length-1);
			try{
				var fun=inputObj+"OnDbClick";
				eval(fun+"('"+name +"','"+id+"')");
			}catch(e){}
			hideMenu();
		}

		function showMenu(inputName,params1,params2,params3) {
			//alert(params2);
			initParams1=params1;
			initParams2=params2;
			initParams3=params3;
			jQuery_1_4_4.fn.zTree.init(jQuery_1_4_4("#treeDept"), createSetting());
			inputObj=inputName;
			var cityObj = jQuery_1_4_4("#"+inputName);
			var cityOffset = cityObj.offset();
			jQuery_1_4_4("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			jQuery_1_4_4("body").bind("mousedown", onBodyDown);

		}

		function showMenu1(inputName,params1,params2,params3) {
			//alert(params2);
			initParams1=params1;
			initParams2=params2;
			initParams3=params3;
			jQuery_1_4_4.fn.zTree.init(jQuery_1_4_4("#treeDept"), createSettingCheck());
			inputObj=inputName;
			var cityObj = jQuery_1_4_4("#"+inputName);
			var cityOffset = cityObj.offset();
			jQuery_1_4_4("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			jQuery_1_4_4("body").bind("mousedown", onBodyDown);

		}

		function hideMenu() {
			jQuery_1_4_4("#menuContent").fadeOut("fast");
			jQuery_1_4_4("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || jQuery_1_4_4(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}

		jQuery_1_4_4(document).ready(function(){
			//
		});
	</SCRIPT>
</head>
<BODY>
<div  id="menuContent" class="menuContent" style="z-index:1;display:none; position: absolute;">
	<ul id="treeDept" class="ztree" style="margin-top:0; width:270px;"></ul>

</div>
</BODY>
</HTML>