define(function(require, exports, module) {
	require('ztree');
	var global = require("../../js/global");
	var jGlobal = require("./faultDiagGlobal");
	var selectDevice = require("./selectDevice");

	var zNodes = [];
	var setting = {
		view: {
			showLine: false,
			showIcon: false,
			selectedMulti: false,
			dblClickExpand: false,
			autoCancelSelected: false,
			addDiyDom: addDiyDom
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeClick: beforeClick,
			onClick: onClick
		}
	};

	function addDiyDom(treeId, treeNode) {
		var spaceWidth = 20;
		var switchObj = $("#" + treeNode.tId + "_switch");
		var icoObj = $("#" + treeNode.tId + "_ico");
		switchObj.remove();
		icoObj.before(switchObj);
		var spaceStr = "<span style='display: inline-block;width:" + (spaceWidth * treeNode.level) + "px'></span>";
		switchObj.before(spaceStr);
	}

	function beforeClick(treeId, treeNode) {
		if(treeNode.isParent) {
			var zTree = $.fn.zTree.getZTreeObj("diagItemTree");
			zTree.expandNode(treeNode);
			return false;
		}

		return true;
	}

	function onClick(event, treeId, treeNode, clickFlag) {
		if(treeNode.isParent !== true) {
			jGlobal.faultDiag.collectType = treeNode.getParentNode().name;
			jGlobal.faultDiag.typeName = treeNode.name;
			jGlobal.faultDiag.curSelectNode = treeNode;

			// 这个id在选择故障类型的时候生成,以后不管是收集，还是诊断，都用这个项。
			jGlobal.faultDiag.diagnoseId = global.jsUtil.makeGuid();
			console.log('in onClick, id:', jGlobal.faultDiag.diagnoseId);

			// Log文件夹的名称也在这个时候生成好
			jGlobal.faultDiag.logId = global.jsUtil.getCurTimeStr();
			console.log('in onClick, log id:', jGlobal.faultDiag.logId);

			//搜索框与文档树的联动匹配
			//console.log("treeNode节点数据："+JSON.stringify(treeNode));			
			var nodeName = treeNode["name"];
			//console.log("nodeName数据"+nodeName);
			$("#selectItem").val(nodeName);
			var diagItem = $("#diagItemTree li a");
			diagItem.removeClass("curSelectedNode");
			//console.log("diagItem节点数据："+diagItem[1]["title"]);
			for(var i = 0; i < diagItem.length; i++) {
				var diagItemTitle = diagItem[i]["title"];
				//判断选择框和文档树的匹配，进行打钩图标的联动
				if(diagItemTitle == nodeName && $(diagItem[i]).attr("class") == "level1") {
					$(diagItem[i]).addClass("curSelectedNode");
				}
			}

			if(treeNode.manualDiag != undefined && treeNode.manualDiag == true) { //人工诊断
				$("#startCollect").hide();
				$("#startDiag").hide();
				jGlobal.faultDiag.isLoadFromDiag = true;
				//	            if (treeNode.mapHtml != undefined && treeNode.mapHtml != "") {
				//	                $("#manualDiagStep").load(treeNode.mapHtml);
				//	            } else {
				//	                $("#manualDiagStep").html("");
				//	            }

				if(treeNode.mapHtml != undefined && treeNode.mapHtml != "") {
					$("#detailFault").load("../../db/" + treeNode.mapHtml);
				} else {
					$("#detailFault").html("");
				}
			} else {
				if(treeNode.supportOldDiag == true || treeNode.supportNewDiag == true) {
					// 先诊断后收集
					jGlobal.faultDiag.isLoadFromDiag = true;
					$("#startCollect").hide();
					$("#startDiag").show();
				} else {
					// 仅收集
					jGlobal.faultDiag.isLoadFromDiag = false;
					$("#startDiag").hide();
					$("#startCollect").show();
				}

				if(treeNode.mapHtml != undefined && treeNode.mapHtml != "") {
					$("#detailFault").load("../../db/" + treeNode.mapHtml);
				} else {
					$("#detailFault").html("");
				}
			}
		}
	}

	function readFaultTypeFromJsonFile(rulePath, deviceType) {
		var jsonFilePath = global.nwPath.resolve(global.jsUtil.getRootPath(), rulePath);		
		var jsonFilestream = global.fs.readFileSync(jsonFilePath, 'utf-8');
		var checkItems = JSON.parse(jsonFilestream).checkItems;

		var zNodes = [];
		var tmp_parent_zNodes = {};
		var tmp_child_zNodes = {};
		
		//查找全面诊断项
		var overallDiag = null;
		for(var i = 0; i < checkItems.length; i++) {
			for(var j = 0; j < checkItems[i].subTypes.length; j++) {
				var isOverallDiag = (checkItems[i].subTypes)[j].overallDiag;
				if (isOverallDiag != undefined && isOverallDiag) {
					var diagRule = (checkItems[i].subTypes)[j].diagRule;
					overallDiag = diagRule;
				}
			}
		}

		//console.log("...数据...00000000000000000000000000："+JSON.stringify(checkItems));
		for(var i = 0; i < checkItems.length; i++) {
			if(checkItems[i].collectType != "自定义收集") {
				var flag = false;
				
				for(var j = 0; j < checkItems[i].subTypes.length; j++) {
					var typeName = (checkItems[i].subTypes)[j].typeName;
					var t = (checkItems[i].subTypes)[j].t;
					var mapHtml = (checkItems[i].subTypes)[j].mapHtml;
					var supportOldDiag = (checkItems[i].subTypes)[j].supportOldDiag;
					var supportNewDiag = (checkItems[i].subTypes)[j].supportNewDiag;
					var diagRule = (checkItems[i].subTypes)[j].diagRule;
					
					if (supportOldDiag || supportNewDiag) {
						if (!flag) {
							flag = true;
							
							//添加父节点(添加过一次就不再添加)
							tmp_parent_zNodes = {};
							tmp_parent_zNodes.id = '1' + '-' + i;
							tmp_parent_zNodes.pId = '1';
							tmp_parent_zNodes.name = checkItems[i].collectType;
							tmp_parent_zNodes.t = "";
							tmp_parent_zNodes.isParent = true;
							tmp_parent_zNodes.open = true;
							zNodes.push(tmp_parent_zNodes);
						}
						
						//添加子节点
						tmp_child_zNodes = {};
						tmp_child_zNodes.id = '1' + '-' + i + '-' + j;
						tmp_child_zNodes.pId = '1' + '-' + i;
						tmp_child_zNodes.name = typeName;
						tmp_child_zNodes.t = t;
						tmp_child_zNodes.mapHtml = mapHtml;
						tmp_child_zNodes.supportOldDiag = supportOldDiag;
						tmp_child_zNodes.supportNewDiag = supportNewDiag;
						tmp_child_zNodes.diagRule = diagRule;
						tmp_child_zNodes.overallDiag = overallDiag;
						if((checkItems[i].subTypes)[j].manualDiag != undefined) {
							tmp_child_zNodes.manualDiag = (checkItems[i].subTypes)[j].manualDiag;
						}
						if((checkItems[i].subTypes)[j].manualPreCondHtml != undefined) {
							tmp_child_zNodes.manualPreCondHtml = (checkItems[i].subTypes)[j].manualPreCondHtml;
						}
						zNodes.push(tmp_child_zNodes);
					}
				}
			}
		}
		
		//console.log("44444444444444444443333333数据：",JSON.stringify(zNodes));
		return zNodes;
	}

	function startCollectFromDev(curAction) {
		//* 判断状态
		if(jGlobal.faultDiag.curStatus != 'connected') {
			if(jGlobal.faultDiag.curStatus == 'collect' || jGlobal.faultDiag.curStatus == 'diagnosis') { //* 原则上不会跑到这里
				alert(undefined, '正在收集设备(' + jGlobal.faultDiag.collectDevName[0] + ')的信息，请稍候。');
			} else {
				alert(undefined, '与设备(' + jGlobal.faultDiag.collectDevName[0] + ')连接断开，请重新连接。');
			}
			return;
		}

		// 设置状态为notReady,在循环收集时要用到
		jGlobal.faultDiag.collectStatus = 'notReady';

		//* 判断输入内容
		//	    var zTree = $.fn.zTree.getZTreeObj("diagItemTree");
		//	    var nodeList = zTree.getNodesByParamFuzzy("name", jGlobal.faultDiag.typeName);

		//	    var zTree = $.fn.zTree.getZTreeObj("diagItemTree");
		//	    var nodeListTmp = zTree.getNodesByParamFuzzy("name", jGlobal.faultDiag.typeName);		
		//		var nodeList = [];
		//		for (var i in nodeListTmp) {
		//			if (!nodeListTmp[i].isParent) { //* 修订父节点和子节点同名的情况，这里假定子项不冲突
		//				nodeList.push(nodeListTmp[i]);
		//				break;
		//			}
		//		}
		if($("#definedCollect").hasClass("curSelectItem")) {

			if(!checkPrecondition()) {
				return;
			}
			getPrecondition();
			jGlobal.faultDiag.diagnoseId = global.jsUtil.makeGuid();
			console.log('in onClick, id:', jGlobal.faultDiag.diagnoseId);

			// Log文件夹的名称也在这个时候生成好
			jGlobal.faultDiag.logId = global.jsUtil.getCurTimeStr();
			console.log('in onClick, log id:', jGlobal.faultDiag.logId);
		} else if(jGlobal.faultDiag.curSelectNode.manualDiag != undefined && jGlobal.faultDiag.curSelectNode.manualDiag == true) { //人工诊断
			if(jGlobal.faultDiag.curSelectNode.manualPreCondHtml != undefined && jGlobal.faultDiag.curSelectNode.manualPreCondHtml != "") {
				if(!checkPrecondition()) {
					return;
				}
				getPrecondition();
			} else {
				jGlobal.faultDiag.preconditionParams = {};
				jGlobal.faultDiag.preconditionParams.collectType = jGlobal.faultDiag.collectType;
				jGlobal.faultDiag.preconditionParams.typeName = jGlobal.faultDiag.typeName;
			}
		} else { //非人工诊断
			if(jGlobal.faultDiag.curSelectNode.mapHtml != undefined && jGlobal.faultDiag.curSelectNode.mapHtml != "") {
				if(!checkPrecondition()) {
					return;
				}
				getPrecondition();
			} else {
				jGlobal.faultDiag.preconditionParams = {};
				jGlobal.faultDiag.preconditionParams.collectType = jGlobal.faultDiag.collectType;
				jGlobal.faultDiag.preconditionParams.typeName = jGlobal.faultDiag.typeName;
			}
		}
		//        console.log('precondition:', JSON.stringify(jGlobal.faultDiag.preconditionParams));

		//生成收集结和诊断log的目录
		console.log('in setCollectInfo, id:', jGlobal.faultDiag.diagnoseId, ' log ID:', jGlobal.faultDiag.logId);
		global.tftpOperateInstance.setCollectInfo(
			jGlobal.faultDiag.collectDevName[0],
			jGlobal.faultDiag.preconditionParams,
			jGlobal.faultDiag.diagnoseId,
			jGlobal.faultDiag.logId
		);

		// 这里来写一下数据库, 记录
		//global.operDbIns.replace({
		//    diagnoseId: jGlobal.faultDiag.diagnoseId,
		//    logId: jGlobal.faultDiag.logId, 
		//    deviceName: jGlobal.faultDiag.collectDevName[0], 
		//    deviceType: 
		//}, function (error) {
		//});
		// 初始，先记录数据库
		// XXX 先不考虑时序问题
		jGlobal.startSaveOperInfo();

		if(curAction == "Collect") {
			var connectStatus = global.devicesIns.getDeviceStatus(jGlobal.faultDiag.collectDevName[0]);
			if(connectStatus == "connected") {
				$("#checkDevEnvModal").modal('show');
				global.tftpOperateInstance.getCpuUsingRate(jGlobal.faultDiag.collectDevName[0], getCpuUsingRateCallback);
			} else {
				alert(undefined, "设备断开，请重新连接设备！");
			}
		} else if(curAction == "Diag") {
			initDiagnosis();
		}
	}

	function getCpuUsingRateCallback(result) {
		$("#checkDevEnvModal").modal('hide');
		if(result < jGlobal.faultDiag.cpuUsedLimit) {
			initCollect(false);
		} else {
			alert(undefined, "当前设备cpu使用率高，是否继续收集诊断？", function() {
				initCollect(true);
			}, true, function() {});
		}
	}
	exports.getCpuUsingRateCallback = getCpuUsingRateCallback;

	function initCollect(cpuHighFlag) {
		jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'collect');

		//	    showDetailIns.clearData();
		jGlobal.faultDiag.tmpCollectPercent = 0;
		jGlobal.faultDiag.startTime_collect = global.moment();
		jGlobal.faultDiag.diagSavePath = global.tftpOperateInstance.getCurrentDir(jGlobal.faultDiag.collectDevName[0]);

		if(cpuHighFlag !== undefined) {
			jGlobal.faultDiag.preconditionParams.cpuHighFlag = cpuHighFlag;
		} else {
			jGlobal.faultDiag.preconditionParams.cpuHighFlag = false;
		}
		setTimeout(function() {
			$(".selectDeviceContent").load("./faultDiagMenu/html/collectEnd.html", function() {
				if($("#definedCollect").hasClass("curSelectItem")) {
					$(".curStep .curStepText .curStepDiv").eq(1).text("配置收集参数");
					$(".curStep .curStepText .curStepDiv").eq(2).text("收集中");
					$(".curStep .curStepText .curStepDiv").eq(3).text("收集完成");
				}
				global.tftpOperateInstance.collectInfo(jGlobal.faultDiag.collectDevName[0], jGlobal.faultDiag.preconditionParams, undefined);
			});
		}, 300);
	}
	exports.initCollect = initCollect;

	function initDiagnosis(cpuHighFlag) {
		jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'diagnosis');

		//	    showDetailIns.clearData();
		jGlobal.faultDiag.tmpDiagPercent = 0;
		jGlobal.faultDiag.diagCount = 0;
		jGlobal.faultDiag.totalWarnCount = 0;
		jGlobal.faultDiag.successCount = 0;
		jGlobal.faultDiag.manualCount = 0;
		jGlobal.faultDiag.portNameArray = [];
		jGlobal.faultDiag.flag = false;
		jGlobal.faultDiag.autoRepairCmds = [];
		jGlobal.faultDiag.backRepairCmds = [];
		jGlobal.faultDiag.manualConfirmAdvice = [];
		jGlobal.faultDiag.diagnoseResult = [];
		jGlobal.faultDiag.startTime_diag = global.moment();
		jGlobal.faultDiag.diagSavePath = global.tftpOperateInstance.getCurrentDir(jGlobal.faultDiag.collectDevName[0]);
		global.devicesIns.clearCmdCacheByName(jGlobal.faultDiag.collectDevName[0]);

		//	    var zTree = $.fn.zTree.getZTreeObj("diagItemTree");
		//	    var nodeList = zTree.getNodesByParamFuzzy("name", jGlobal.faultDiag.typeName);		
		//		var node = null;
		//		for (var i in nodeList) {
		//			if (!nodeList[i].isParent) { //* 修订父节点和子节点同名的情况，这里假定子项不冲突
		//				node = nodeList[i];
		//				break;
		//			}
		//		}

		if(jGlobal.faultDiag.curSelectNode.supportNewDiag == true) {
			global.diagDirectorIns = new global.diagDirector.DiagDirector();

			global.diagDirectorIns.setBasedInfo({
				devMgr: global.devicesIns,
				deviceName: jGlobal.faultDiag.collectDevName[0]
			});

			//	    	showDetailIns.showCheckResult(diagDirectorIns);
			$(".selectDeviceContent").load("./faultDiagMenu/html/diagEnd.html", function() {
				//	    		console.error('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee');
				//	    		var scriptErr = global.diagDirectorIns.doDiag(jGlobal.faultDiag.curSelectNode.diagRule, jGlobal.faultDiag.preconditionParams.paramForDiag, jGlobal.faultDiag.diagSavePath);
				//	    		console.error(scriptErr);
				//		    	if (scriptErr == false) {
				//		    		if (jGlobal.faultDiag.curStatus != 'closing' && jGlobal.faultDiag.curStatus != 'init') {
				//		    			jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'connected');
				//		            }
				//		    		alert(undefined, "当前故障诊断脚本还未添加！");
				//		    	}
			});
		}
	}

	function init() {
		initPageStatistic();
		removeGlobalEvent();
		initVariable();
		initTree();
		initEvent();
		initDom();
		initGlobalEvent();
		initSelect();
		initGuide();

		function initGuide() {
			var tip = $('#device-group-tip');
			if(global.guide) {
				tip.css({
					display: 'block',
					top: '72px',
					left: '150px'
				});
				setTimeout(function() {
					tip.css('display', 'none');
				}, 5000);

				$('#diagItemTree').click(function() {
					$('#red-point').css({
						display: 'block',
						top: '545px',
						left: '740px'
					});
				});
			}
		}

		function initPageStatistic() {
			statRecordEle("faultDiag#selectDiagContent");
		}

		function removeGlobalEvent() {
			global.devicesIns.removeAllListeners("deviceConnected");
			global.devicesIns.removeAllListeners("deviceError");
			global.devicesIns.removeAllListeners("deviceDisconnected");
		}

		function initVariable() {
			//当前页面变量初始化
			zNodes = [];
			setting = {
				view: {
					showLine: false,
					showIcon: false,
					selectedMulti: false,
					dblClickExpand: false,
					autoCancelSelected: false,
					addDiyDom: addDiyDom
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeClick: beforeClick,
					onClick: onClick
				}
			};
		}

		function initTree() {
			var productType = global.tftpOperateInstance.checkProductType(jGlobal.faultDiag.collectDevName[0]); //判断产品类型			
			zNodes = readFaultTypeFromJsonFile(jGlobal.faultDiag.rulePath, productType.deviceType);
			//$.fn.zTree.init($("#diagItemList"), setting, zNodes);
			$.fn.zTree.init($("#diagItemTree"), setting, zNodes);

		}

		function initEvent() {

			$("#reConnect").click(function() {
				var connectStatus = global.devicesIns.getDeviceStatus(jGlobal.faultDiag.collectDevName[0]);
				console.log(connectStatus);
				if(connectStatus == "notConnected") {
					var row = {};
					row.deviceName = jGlobal.faultDiag.collectDevName[0];
					selectDevice.collectClick(row);
				} else {
					alert(undefined, "设备已连上，无需重新连接！");
				}
			});

			global.devicesIns.on("deviceConnected", function(devName) {
				$('#connectDevModal').modal('hide');

				if(jGlobal.faultDiag.curStatus != 'connecting') {
					return;
				}
				jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'connected');
			});

			global.devicesIns.on("deviceError", function(res) {
				$('#connectDevModal').modal('hide');

				if(jGlobal.faultDiag.curStatus == 'closing' || jGlobal.faultDiag.curStatus == 'init') {
					return;
				}

				jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'closing');
				global.tftpOperateInstance.changeDirName(jGlobal.faultDiag.collectDevName[0]);

				alert(undefined, '连接设备(' + res.deviceName + ')失败！错误信息: ' + res.errInfo);
				return;
			});

			global.devicesIns.on("deviceDisconnected", function(devName) {
				$('#connectDevModal').modal('hide');

				if(jGlobal.faultDiag.curStatus == 'closing' || jGlobal.faultDiag.curStatus == 'init') {
					jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'init');
					return;
				}

				var msg = '';
				if(jGlobal.faultDiag.curStatus == 'connecting') {
					msg = '无法与设备(' + devName + ')建立连接！';
				} else if(jGlobal.faultDiag.curStatus == 'collect') { //* 原则上不会跑到
					msg = '收集失败，与设备(' + devName + ')断开连接';
				} else if(jGlobal.faultDiag.curStatus == 'diagnosis') { //* 原则上不会跑到
					msg = '诊断失败，与设备(' + devName + ')断开连接';
				} else if(jGlobal.faultDiag.curStatus == 'repair') { //* 原则上不会跑到
					msg = '修复失败，与设备(' + devName + ')断开连接';
				} else if(jGlobal.faultDiag.curStatus == 'backRepair') { //* 原则上不会跑到
					msg = '回退失败，与设备(' + devName + ')断开连接';
				} else {
					msg = '与设备(' + devName + ')连接断开！';
				}

				jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'init');
				alert(undefined, msg);
			});

			$("#startCollect").click(function() {
				if($("#definedCollect").hasClass("curSelectItem")) {

					jGlobal.faultDiag.collectType = "自定义收集";
					jGlobal.faultDiag.typeName = "自定义收集";
					startCollectFromDev("Collect");
					return;
				}
				if(jGlobal.faultDiag.collectType == undefined || jGlobal.faultDiag.typeName == undefined) {
					alert(undefined, "请选择故障类型!");
					return;
				}
				startCollectFromDev("Collect");
			});

			$("#startDiag").click(function() {
				if(jGlobal.faultDiag.collectType == undefined || jGlobal.faultDiag.typeName == undefined) {
					alert(undefined, "请选择故障类型!");
					return;
				}

				startCollectFromDev("Diag");
			});
		}

		function initDom() {
			$('#checkDevEnvModal').modal({
				backdrop: 'static',
				show: false
			});
		}

		function initGlobalEvent() {
			global.exitPageCallback.exitFun = function() {
				removeGlobalEvent();
				// 离开该页面，断开设备
				if(jGlobal.faultDiag.curStatus != 'init') {
					global.devicesIns.once("deviceDisconnected", function(devName) {
						jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'init');
					});
					jGlobal.faultDiag.curStatus = jGlobal.changeDevStatus(jGlobal.faultDiag.curStatus, 'closing');
					global.devicesIns.closeDeviceLink(jGlobal.faultDiag.collectDevName[0]);
				}

				return true;
			}
		}

		function initSelect() {
			//对输入框进行事件注册 
			var $diagItemList = $("#diagItemList");
			var productType = global.tftpOperateInstance.checkProductType(jGlobal.faultDiag.collectDevName[0]); //判断产品类型			
			zNodes = readFaultTypeFromJsonFile(jGlobal.faultDiag.rulePath, productType.deviceType);
			$("#selectItem").focus(function() {
				$("#selectItem").val("");
			});
			$("#selectItem").keyup(function(event) {
				//字母数字，退格，空格 
				if(event.keyCode > 40 || event.keyCode == 8 || event.keyCode == 32) {
					//首先删除下拉列表中的信息
					var searchNodes = [{
						"id": "1-0",
						"pId": "1-1",
						"name": "",
						"t": "",
						"isParent": true,
						"open": true
					}];
					var $selectItem = $("#selectItem").val();
					$diagItemList.empty().hide();
					$diagItemList.show();
					var j = 0;
					for(var i = 0; i < zNodes.length; i++) {
						//console.log("zNodes[i][name]数据:"+zNodes[i]["name"]);
						var zNodesIndex = zNodes[i]["name"].toLowerCase();
						if(($selectItem.trim()).length > 0 && !zNodes[i]["isParent"] && zNodesIndex.indexOf($selectItem.trim().toLowerCase()) != -1) {
							zNodes[i]["pId"] = "1-0";
							zNodes[i]["id"] = "1-0-" + j;
							searchNodes.push(zNodes[i]);
						}
					}
					if(searchNodes.length == 1) {
						searchNodes.push({
							"id": "1-0-0",
							"pId": "1-0",
							"name": "无搜索结果",
							"t": "",
							"mapHtml": "",
							"supportOldDiag": false,
							"supportNewDiag": true,
							"diagRule": ""
						});
					}
					//console.log("selectItem数据:"+$selectItem);
					//console.log("zNodes数据："+JSON.stringify(zNodes));
					//console.log("searchNodes数据"+JSON.stringify(searchNodes));
					$.fn.zTree.init($("#diagItemList"), setting, searchNodes);
				}
			});
			$("#selectItem").blur(function() {
				setTimeout(function() {
					$("#diagItemList").empty().hide();
				}, 300);
			});
		}
	}
	exports.init = init;
});