<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 
<%@ page session="false" %>
<!doctype html>
<html lang="ko" style="min-width:300px !important;overflow:hidden">
<head>
	<link rel="stylesheet" type="text/css" href="${contextRoot }/css/common.css" />
	<link rel="stylesheet" type="text/css" href="${contextRoot }/css/main.css" />
	<link rel="stylesheet" href="${contextRoot }/css/themes/default/style.css" />
</head>
<body class="sang" style="min-width:305px !important;overflow:hidden">
	<div class="leftMenu">
		<ul class="tabs">
			<li><a href="javascript:goIntMenu()" class="tab" id="tab1"><img src="images/tab01_on.png" alt="교차로메뉴" /></a></li>
			<li><a href="javascript:goGroupMenu()" class="tab" id="tab2"><img src="images/tab02_off.png" alt="신호그룹메뉴" /></a></li>
		</ul>
		<div class="search-box">
			<input type="text" id="searchText" placeholder="검색어를 입력해주세요" style="width: 210px;padding:5px;" onkeyup="searchTreeData(event)">
			<div class="search-button" onclick="searchTreeData()">검색</div>
		</div>
		<div id="onOffTree"></div>
		<div id="intTree"></div>
		<div id="groupTree"></div>
		<div class="treeLoading"><img src="/css/themes/classic/throbber.gif" /></div>
	</div>
<script src="${contextRoot }/js/common/common-all.js" type="text/javascript" ></script>
<script src="${contextRoot }/js/common/jstree.min.js" type="text/javascript" ></script>
  
<script type="text/javascript">
var treeJson = null;
var groupTreeJson = null;
var treeCtrl;
var onlineCenterStatusCheckId;
var offlineCenterStatusCheckId;
var onlineIntStatusCheckId;
var offlineIntStatusCheckId;
var _RegionCdArr      = [];
var _GroupNoArr       = [];
var intGroupLineArr   = [];
var intGroupCircleArr = [];
var _groupTreeListCallBackData;

var onlineCenterStatusData;
var offlineCenterStatusData;
var onlineIntStatusData;
var offlineIntStatusData;
var _searchText = "";
var _Tab = "int";
	setTreeList();
	getIntTreeList();
	function searchTreeData(el) {
		if (el && el.code !== "Enter") {
			return;
		}
		
		const $searchText = $('#searchText');
		_searchText = $searchText.val();
		if (_Tab === 'int') {
			clearIntInterval();
			const oldTree = $('#intTree').jstree(true);
			if (oldTree) {
				oldTree.destroy();
			}
			setTreeList();
			getIntTreeList();
			$('#intTree').jstree("refresh");
		}
		else {
			
		}
		//$('#intTree').jstree(true).search(_searchText);
	}
	function clearIntInterval() {
		if(onlineCenterStatusCheckId != null) clearTimeout(onlineCenterStatusCheckId);
		if(onlineIntStatusCheckId != null) clearTimeout(onlineIntStatusCheckId);
		onlineCenterStatusCheckId = null;
		onlineIntStatusCheckId = null;
	}
	
	function goIntMenu() {
		$('#tab1 img').attr('src','images/tab01_on.png');
		$('#tab2 img').attr('src','images/tab02_off.png');
		
		$('.treeLoading').hide();
		$('#groupTree').hide();
		$('#intTree').show();
		$('.search-box').show();
		emptyintGroupLineArr();
		emptyintGroupCircleArr();
	}

	function goGroupMenu() {
		$('#tab2 img').attr('src','images/tab02_on.png');
		$('#tab1 img').attr('src','images/tab01_off.png');
		
		$('#intTree').hide();
		$('#groupTree').show();
		$('.search-box').hide();
		if(groupTreeJson == null)
		{
			$('.treeLoading').show();
			goGroupTreeList();
		}
	}

	function setTreeList()
	{
		/**
		 ** ****************************************************
		 ** 레이어 리스트 Tree 생성
		 ** ****************************************************
		 */
		
		treeCtrl = treeCtrl || (function(){
		 	var Node = function( nodeName, data, id, icon ){
		        return {
		        	id : id,
		        	icon : icon,
		            text: nodeName,
		            state: { 'opened' : false, 'selected' : false },
		            data: data,         // @type: ol.Layer
		            children: []
		        };
		    };
		 
		    var _root = new Node('ROOT','item');
		 
		    var findChild = function( parent, nodeName ){
		        for( var i=0; i < parent.children.length; i++ ){
		            var child = parent.children[i];
		            if( child.text == nodeName ){
		                return child;
		            }
		        }
		 
		        return null;
		    };
		 
		    // find parent which save item
		    var getParent = function( parent, group, data, id, icon, opt_make){
		        opt_make = ( typeof opt_make === 'undefined' ) ? true : false;
		        
		        for( var i=0; i < group.length; i++ ){
		            var child = findChild( parent, group[i] );
		            // 없으면 Node 생성
		            if( !child )
		            {
		                if( !opt_make ) return null;
		                child = new Node( group[i], data );
		                parent.children.push( child );
		            }
		            parent = child;
		        }
		        
		        return parent;
		    }
		 
		    // group에 layer 아이템 저장
		    var _set = function( key, item){
		    	key.forEach(function(el) {
		    		var group = el.split('-');
			        var parent = getParent( _root, group, item.data, item.id, item.icon);
			        var child = new Node(item.name, item.data, item.id, item.icon);
			        parent.children.push(child);
			        return child;
		    	});
		    };
		 
		    // item인 node들만 반환 (=layer)
		    var _get = function( key ){
		        var group = key.split('-');
		        var parent = getParent( _root, group );
		        return parent.children.filter(function( node ){
		            return node.type == 'item'
		        });
		    };
		 
		    var _clear = function(){
		        _root.children = [];
		    };
		 
		    var _setState = function( key, state ){
		        var group = key.split('-');
		        var node = getParent( _root, group, false );
		        if( !node ) return false;
		        
		        node['state'] = state;
		        return true;
		    };
		 
		    var _toTreeJson = function(){
		        return _root.children;
		    };
		 
		    return {
		        'root'      : _root,
		        'set'       : _set,
		        'get'       : _get,
		        'setState'  : _setState,
		        'toTreeJson': _toTreeJson,
		        'clear'     : _clear,
		    };
		 
		})(treeCtrl);
	}
	
	function getIntTreeList()
	{
		$('.treeLoading').show();
		var url = 'getIntTreeList.do';
		requestService(url, '', getIntTreeListCallback);
	}
	const regionMap = new Map();
	
	function getIntTreeListCallback(data)
	{
		regionMap.clear();
		treeCtrl.clear();
		if (data && data.length) {
			let searchX = null;
			let searchY = null;
			let searchText = null;
			
			//검색어 있는 경우 
			if (_searchText) {
				if (_searchText.indexOf(',') > -1) {
					const coordArr = _searchText.split(',');
					if (coordArr.length === 2) {
						searchX = coordArr[0].trim();
						searchY = coordArr[1].trim();
					}
				}
				else {
					searchText = _searchText
				}
			}
			
			for (let obj of data) {
				const { 
					INT_NM, INT_NO, INT_NO_SE, INT_X_COORD, INT_Y_COORD,
					NETWORK_TYPE, REGION_CD, REGION_NM, SIGUNGU_CD, NODE_ID,
					SIGUNGU_NM, SIGUNGU_X, SIGUNGU_Y, X_COORD, Y_COORD,
				} = obj
				
				//지역 코드별로 데이터 분류
				if (!regionMap.get(REGION_CD)) {
					regionMap.set(REGION_CD, []);
				}
				
				//검색어 있을 시 있는 것만 표출
				if (searchText !== null) {
					console.log(obj);
					if ( NODE_ID == searchText || 
						REGION_CD.includes(searchText) ||
						REGION_NM.includes(searchText) ||
						INT_NO.toString().includes(searchText) ||
						(INT_NM !== null && INT_NM !== undefined && INT_NM.includes(searchText))
					) {
						regionMap.get(REGION_CD).push(obj);
					}
				}
				else if (searchY !== null && searchX !== null) {
					if (INT_X_COORD == searchX && INT_Y_COORD  == searchY) {
						regionMap.get(REGION_CD).push(obj);
					}
				}//검색어 없을 시 다 표출
				else {
					regionMap.get(REGION_CD).push(obj);
				}
			}
		}
		
		if (regionMap.size > 0) {
			regionMap.forEach((arr, key)=>{
				let lastObj = [];
				for (let obj of arr) {
					if (obj.SIGUNGU_NM === '기타') {
						lastObj.push(obj);
					}
					else {
						setTreeInfo(obj);
					}
				}
				if (lastObj.length > 0) {
					for (let obj of lastObj) {
						setTreeInfo(obj);
					}
				}
			});
		}
		
		treeJson = treeCtrl.toTreeJson();
		
		// jsTree 생성
		$('#intTree').jstree({
		    'core' : {
		    	'data' : treeJson,
		    	"themes" : { "stripes" : true },
		    },
		    "plugins" : [ "wholerow"],
		}).on('loaded.jstree', function(e, data) {
			//onlineCenterStatusCheck();
			onlineIntStatusCheck();
			parent.document.getElementById('iframeBottomList').contentWindow.showOnlineList();
	  	});
		
		
		
		$('#intTree').bind('open_node.jstree', function(event, data) {
			
			if(data.node.text.indexOf('name="0_int"') != -1)
			{	if (data.node.text.indexOf('class="regionComm') != -1) {
					_RegionCdArr.push(data.node.data.regionCd);
				}
				drawCenterStatus(0,onlineCenterStatusData);
				onlineIntStatusCheck();
			}
		});
		
		$('#intTree').bind('close_node.jstree', function(event, data) {
			if(data.node.text == '유선')
			{
				if(onlineCenterStatusCheckId != null) clearTimeout(onlineCenterStatusCheckId);
				if(onlineIntStatusCheckId != null) clearTimeout(onlineIntStatusCheckId);
			}
			else if (data.node.text.indexOf('class="regionComm') != -1) {
				const idx = _RegionCdArr.findIndex(regionCd => regionCd === data.node.data.regionCd);
				if (idx > -1) {
					_RegionCdArr.splice(idx, 1);
				}
			}
			
		});
		
		// jsTree 클릭 이벤트 : 레이어 setVisible
		$('#intTree').bind('select_node.jstree', function(event, data) {
			var parentNd = data.node.parent;
			var children = data.node.children;
			
			parent._RegionCd = data.node.data.regionCd;
			if(parentNd == '#') //시도 선택 
			{
				var xCoord = data.node.data.xCoord;
				var yCoord = data.node.data.yCoord;
				
				parent.map.setCenter(new parent.kakao.maps.LatLng(yCoord, xCoord));
				parent.map.setLevel(3);
				parent.getSignalInfo('SIDO');
			}
			else if(parentNd != '#' && children.length > 0) //구 선택
			{
				var guX = data.node.data.sigunguX;
				var guY = data.node.data.sigunguY;
				
				if(guX != null && guY != null)
				{
					parent.map.panTo(new parent.kakao.maps.LatLng(guY, guX));
					setTimeout(function() {parent.mapZoomBound()},100*3);
				}
			}
			else
			{
				var intNm     = data.node.data.intNm;
				var intXCoord = data.node.data.intXCoord;
				var intYCoord = data.node.data.intYCoord;
				
				parent.$('#regionCd').val(data.node.data.regionCd);
				parent.$('#intNo').val(data.node.data.intNo);
				parent.$('#intNm').val(intNm);
				parent.$('#treeXCoord').val(intXCoord);
				parent.$('#treeYCoord').val(intYCoord);
				
				parent.map.panTo(new parent.kakao.maps.LatLng(intYCoord, intXCoord));
				if(parent._Level > 4) parent.map.setLevel(4);
				setTimeout(
					function() {
						parent.getSignalInfo();
						parent.customOverlayFnc(intNm,intXCoord,intYCoord);
					},100 * 2
				);
				if(parent._Level == 1)
				{
					//무선, 유무선인경우 신호등 표시..
					parent.getCvibInfo();
				}
					
			}
			
			if(data.node.data.line == 'offline') parent.document.getElementById('iframeBottomList').contentWindow.showOfflineList();
			else if(data.node.data.line == 'online') parent.document.getElementById('iframeBottomList').contentWindow.showOnlineList();
			
			_Flag = '';
		});
		
		$('.treeLoading').hide();
		
		getGroupTreeList();
		
	}
	
	function setTreeInfo(data) {
		const { 
			INT_NM, INT_NO, INT_NO_SE, INT_X_COORD, INT_Y_COORD,
			NETWORK_TYPE, REGION_CD, REGION_NM, SIGUNGU_CD,
			SIGUNGU_NM, SIGUNGU_X, SIGUNGU_Y, X_COORD, Y_COORD, NODE_ID
		} = data
		let nameCntOn = '<img class="regionComm_'+NETWORK_TYPE+'_'+REGION_CD+'" src="" alt="'+REGION_CD+'" style="padding:0 0 2px 0" />';
		
		nameCntOn += '&nbsp;<strong class="centerNm_'+REGION_CD+'">' + REGION_NM + '</strong>' +
		  			 '&nbsp;( 전체 : <span class="intTotal_'+NETWORK_TYPE+'_'+REGION_CD+'" name="'+NETWORK_TYPE+'_int" style="color:#0000FF"></span>'+
		  			  ' / 이상 : <span class="intErrCnt_'+NETWORK_TYPE+'_'+REGION_CD+'" style="color:#FF0000"></span> )';
		if (REGION_NM !== SIGUNGU_NM) {
			nameCntOn = nameCntOn + '-' + SIGUNGU_NM +
			'&nbsp;( 전체 : <span class="guIntTotal_'+ NETWORK_TYPE + '_'+REGION_CD+'_'+SIGUNGU_CD+'" name="'+NETWORK_TYPE+'_int" style="color:#0000FF"></span> / 이상 : '+
			'<span class="guIntErrCnt_'+NETWORK_TYPE+'_'+REGION_CD+'_'+SIGUNGU_CD+'" style="color:#FF0000"></span> )';
		}
		
		
		treeCtrl.set([nameCntOn],{
			name : INT_NO + '_' + INT_NM,
			id   : REGION_CD+'_'+NETWORK_TYPE+'_'+INT_NO,
			data : {
				'line' : 'online',
				'regionCd' : REGION_CD , 
				'intNo' : INT_NO , 
				'intNm' : INT_NM, 
				'xCoord' : X_COORD , 
				'yCoord' : Y_COORD , 
				'intXCoord' : INT_X_COORD, 
				'intYCoord' : INT_Y_COORD,
				'sigunguX' : SIGUNGU_X, 
				'sigunguY' : SIGUNGU_Y , 
				'sigunguCd' : SIGUNGU_CD , 
				'networkType' : NETWORK_TYPE
			}
		});
	}
	
	//그룹트리 리스트..
	function getGroupTreeList(param) {
		treeCtrl.clear();
		//지역그룹리스트 가저오기...
		var url = 'getGroupTreeList.do';
		var param = param;
		//requestService(url, param, getGroupTreeListCallback);
		requestService(url, param, goGroupTreeList);
	}
	
	function getGroupTreeListCallback(data) {
		_groupTreeListCallBackData = data;
	}
	
	function goGroupTreeList(data) {
		if (data && data.length > 0) {
			for (let obj of data) {
				const { regionCd, regionNm, sigunguCd, sigunguNm, sigunguX, sigunguY, xCoord, yCoord, groupNm, groupList } = obj;
				if (groupList && groupList.length > 0) {
					const groupXCoord = [];
					const groupYCoord = [];
					groupList.forEach((intInfo)=>{
						groupXCoord.push(intInfo.intXCoord);
						groupYCoord.push(intInfo.intYCoord);
					});
					
					let groupStateNm = `<img class="regionComm_0_\${regionCd}" src="" alt="" style="padding:0 0 2px 0" />&nbsp;
	                   					<strong class="centerNm_\${regionCd}">\${regionNm}</strong>&nbsp;
                   						( 전체 : <span class="intTotal_0_\${regionCd}" name="0_int" style="color:#0000FF"></span>
                   						 / 이상 : <span class="intErrCnt_0_\${regionCd}" style="color:#FF0000"></span> )`;
					let groupTitle;
					if(regionNm == sigunguNm) {
						groupTitle = groupStateNm + '-' + groupNm;
					}
					else {
						groupTitle = groupStateNm + '-' + 
				      	sigunguNm + '&nbsp;( 전체 : <span class="guIntTotal_0_'+regionCd+'_'+ sigunguCd + '" style="color:#0000FF"></span> / ' + 
				      	'이상 : <span class="guIntErrCnt_0_'+regionCd+'_'+ sigunguCd + '" name="0_int" style="color:#FF0000"></span> )' + '-' + groupNm;
					}
					
					
					for (let group of groupList) {
						const intNm = regionCd + group.intNo + '_' + group.intNm;
						treeCtrl.set([groupTitle],{
							name : intNm,
							id : regionCd + '_0_' + group.intNo,
							data : {
								'regionCd' : regionCd , 'intNo' : group.intNo , 'intNm' : intNm,
								'xCoord' : xCoord , 'yCoord' : yCoord , 'intXCoord' : group.intXCoord , 'intYCoord' : group.intYCoord , 'sigunguX' : sigunguX ,
								'sigunguY' : sigunguY , 'groupXCoord' : groupXCoord , 'groupYCoord' : groupYCoord , 'sigunguCd' : sigunguCd
							}
						});
					}
				}
				
				
			}
		}
		else {
			alert('데이터정렬이 안되었습니다.\n잠시후 다시 선택하십시오.');
			return;
		}
		
		groupTreeJson = treeCtrl.toTreeJson();
		
		// 법정경계 펼치고, 선택하기
		//treeCtrl.setState( '의왕시', { 'opened' : true, 'selected' : true } );
		
		// jsTree 생성
		$('#groupTree').jstree({
		    'core' : { 
		    	'data' : groupTreeJson,
		    	"themes" : { "stripes" : true },
		    },
		    "plugins" : [ "wholerow", "changed", "types", "themes", "ui" ]
		})
		//.on('loaded.jstree', function(e, data) {
		//	onlineCenterStatusCheck();
	  	//});
		
		
		$('#groupTree').bind('open_node.jstree', function(event, data) {
			_RegionCdArr = [];
			_GroupNoArr  = [];
			//else if(data.node.text == '무선')
			//{
			//	offlineCenterStatusCheck();
			//}
			if(data.node.text.indexOf('name="0_int"') != -1)
			{
				_RegionCdArr.push(data.node.data.regionCd);
				drawCenterStatus(0,onlineCenterStatusData);
				onlineIntStatusCheck();
			}
			else if(data.node.text.indexOf('그룹번호') != -1)
			{
				_RegionCdArr.push(data.node.data.regionCd);
				drawCenterStatus(0,onlineCenterStatusData);
				onlineIntStatusCheck();
			}
			//else {
			//	onlineCenterStatusCheck();
			//}
		});
		
		$('#groupTree').bind('close_node.jstree', function(event, data){
			if(data.node.text.indexOf('name="0_int"') != -1)
			{
				if(onlineIntStatusCheckId != null) clearTimeout(onlineIntStatusCheckId);
			}
			else if(data.node.text.indexOf('그룹번호') != -1)
			{
				
			}
			else {
				if(onlineCenterStatusCheckId != null) clearTimeout(onlineCenterStatusCheckId);
				if(onlineIntStatusCheckId != null) clearTimeout(onlineIntStatusCheckId);
			}
			_RegionCdArr = [];
		});
		
		// jsTree 클릭 이벤트 : 레이어 setVisible
		$('#groupTree').bind('select_node.jstree', function(event, data){
			parent._RegionCd = data.node.data.regionCd;
			var parentNd = data.node.parent;
			var childrenId = data.node.id;
			var nodeNm  = data.node.text;
			
			var _groupXCoord;
			var _groupYCoord;
			
			if(parentNd == '#') //시도 선택 
			{
				var xCoord = data.node.data.xCoord;
				var yCoord = data.node.data.yCoord;
				parent.$('#XCoord').val(xCoord);
				parent.$('#YCoord').val(yCoord);
				
				parent.map.setCenter(new parent.kakao.maps.LatLng(yCoord, xCoord));
				parent.map.setLevel(3);
				parent.getSignalInfo('SIDO');
				emptyintGroupLineArr();
				emptyintGroupCircleArr();
				_Flag = '';
			}
			else if(parentNd != '#' && data.node.children.length > 0 && nodeNm.substr(0,1) !== '그') //구 선택
			{
				var guX = data.node.data.sigunguX;
				var guY = data.node.data.sigunguY;
				
				if(guX != null && guY != null)
				{
					parent.map.panTo(new parent.kakao.maps.LatLng(guY, guX));
					setTimeout(function() {parent.mapZoomBound()},100*3);
				}
			}
			else if(nodeNm.substr(0,1) == '그') //그룹 선택
			{
				var groupNo = data.node.data.groupNo;
				var groupXCoord = data.node.data.groupXCoord;
				var groupYCoord = data.node.data.groupYCoord;
				var minX;
				var minY;
				var maxX;
				var maxY;
				
				if(groupXCoord != null || groupYCoord != null)
				{
					//_groupXCoord = groupXCoord.split('|');
					//_groupYCoord = groupYCoord.split('|');
					_groupXCoord = groupXCoord;
					_groupYCoord = groupYCoord;
					
					minX = _groupXCoord[0];
					minY = _groupYCoord[0];
					maxX = _groupXCoord[0];
					maxY = _groupYCoord[0];
					
					for(var ii = 0; ii < _groupXCoord.length; ii++)
					{
						if(_groupXCoord[ii] < minX) minX = _groupXCoord[ii];
						if(_groupYCoord[ii] < minY) minY = _groupYCoord[ii];
						if(_groupXCoord[ii] > maxX) maxX = _groupXCoord[ii];
						if(_groupYCoord[ii] > maxY) maxY = _groupYCoord[ii];
					}
				}
				else
				{
					alert('TB_INT테이블의 좌표가 없습니다.');
					return;
				}
				
				var points = [
				              new parent.kakao.maps.LatLng(minY, minX),
				              new parent.kakao.maps.LatLng(maxY, maxX)
				          ];
				
				var bounds = new parent.kakao.maps.LatLngBounds();
				
				for(var jj = 0; jj < points.length; jj++)
				{
					bounds.extend(points[jj]);
				}
				
				parent.map.setBounds(bounds);
				parent.getSignalInfo(groupNo);
				
				//그룹라인그리기
				drawIntGroupLine(_groupXCoord,_groupYCoord);
				
			}
			else if(childrenId.substr(0,1) != 'j') //교차로 선택
			{
				var intNm = data.node.data.intNm;
				var intXCoord  = data.node.data.intXCoord;
				var intYCoord  = data.node.data.intYCoord;
				
				parent.$('#regionCd').val(data.node.data.regionCd);
				parent.$('#intNo').val(data.node.data.intNo);
				parent.$('#intNm').val(intNm);
				parent.$('#treeXCoord').val(intXCoord);
				parent.$('#treeYCoord').val(intYCoord);
				
				setTimeout(
					function() {
						parent.getSignalInfo();
						parent.customOverlayFnc(intNm,intXCoord,intYCoord);
					},100 * 2
				);
				parent.map.panTo(new parent.kakao.maps.LatLng(intYCoord, intXCoord));
				
				emptyintGroupCircleArr();
			}
			
		});
	
		$('.treeLoading').hide();
	}
	
	//유선 센터상테 체크..
	function onlineCenterStatusCheck() {
		
		if(onlineCenterStatusCheckId != null) clearTimeout(onlineCenterStatusCheckId);
		onlineCenterStatusCheckId = setTimeout('onlineCenterStatusCheck()', 5 * 1000);
		
		var url = 'getOnlineCenterStatus.do';
		requestService(url, '', onlineCenterStatusCheckCallback);
	}

	function onlineCenterStatusCheckCallback(data) {
		onlineCenterStatusData = data;
		drawCenterStatus(0,data);
	}
	
	//무선 센터상테 체크..
	function offlineCenterStatusCheck() {
		
		if(offlineCenterStatusCheckId != null) clearTimeout(offlineCenterStatusCheckId);
		offlineCenterStatusCheckId = setTimeout('offlineCenterStatusCheck()', 5 * 1000);
		
		var url = 'getOfflineCenterStatus.do';
		requestService(url, '', offlineCenterStatusCheckCallback);
	}

	function offlineCenterStatusCheckCallback(data) {
		offlineCenterStatusData = data;
		drawCenterStatus(1,data);
	}
	
	function drawCenterStatus(network,data) {
		var regionCd;
		var totCnt;
		var errCnt;
		var commState;
		var commImg = '';
		
		for(var ii = 0; ii < data.length; ii++)
		{
			regionCd   = data[ii].REGION_CD;
			totCnt     = data[ii].TOT;
			errCnt     = data[ii].ERR_CNT;
			commState  = data[ii].COMM_STATE;
			simulFlag  = data[ii].SIMUL_FLAG;
			if(commState == 1)
			{
				commImg = 'images/commOff.png';
				$('.intErrCnt_'+network+'_'+regionCd).text(totCnt);
				//$('.intErrCnt_'+network+'_'+regionCd).text(errCnt);
			}
			else
			{
				commImg = 'images/commOn.png';
				$('.intErrCnt_'+network+'_'+regionCd).text(errCnt);
			}
			
			if (simulFlag === 'Y') {
				commImg = 'images/comm_2.png';
			}
			if(network == 0) $('.regionComm_'+network+'_'+regionCd).attr('src',commImg);
			
			$('.intTotal_'+network+'_'+regionCd).text(totCnt);
		}
	}
	
	//유선 제어기 상태 체크..
	function onlineIntStatusCheck() {
		if(_RegionCdArr.length > 0)
		{
			if(onlineIntStatusCheckId != null) clearTimeout(onlineIntStatusCheckId);
			onlineIntStatusCheckId = setTimeout('onlineIntStatusCheck()',5 * 1000);
			
			var url = 'getOnlineIntStatus.do';
			var param = 'regionCd='+_RegionCdArr;
			requestService(url, param, onlineIntStatusCheckCallback);
		}
	}
	
	function onlineIntStatusCheckCallback(data) {
		onlineIntStatusData = data;
		drawIntStatus(0,data);
	}
	
	//무선 제어기 상태 체크..
	function offlineIntStatusCheck() {
		if(_RegionCdArr.length > 0)
		{
			if(offlineIntStatusCheckId != null) clearTimeout(offlineIntStatusCheckId);
			offlineIntStatusCheckId = setTimeout('offlineIntStatusCheck()',5 * 1000);
			
			var url = 'getOfflineIntStatus.do';
			var param = 'regionCd='+_RegionCdArr;
			requestService(url, param, offlineIntStatusCheckCallback);
		}
	}

	function offlineIntStatusCheckCallback(data) {
		offlineIntStatusData = data;
		drawIntStatus(1,data);
	}
	
	function drawIntStatus(network,data) {
		var commState;
		const onlineCenterMap = new Map();
		if(network == 0)
		{
			for(var i = 0; i < onlineCenterStatusData.length; i++) 
			{
				const {REGION_CD, COMM_STATE} = onlineCenterStatusData[i];
				onlineCenterMap.set(REGION_CD, COMM_STATE);
				//if(onlineCenterStatusData[i].REGION_CD == data[0].REGION_CD)
				//{
				//	commState = onlineCenterStatusData[i].COMM_STATE;
				//	break;
				//}
			}
		}
		else
		{
			commState = 0;
		}
		
		var regionCd;
		var siguguCd;
		var intNoArr;
		var commOnOffFlagArr;
		var commOnOffImg;
		for(var ii = 0; ii < data.length; ii++) {
			regionCd      = data[ii].REGION_CD;
			sigunguCd     = data[ii].SIGUNGU_CD;
			intNoArr      = data[ii].INT_NO.split('|');
			commOnOffFlagArr = data[ii].COMM_ON_OFF_FLAG.split('|');
			
			$('.guIntTotal_' + network +'_'+regionCd+'_'+ sigunguCd).text(intNoArr.length);
			
			//sigunguCd = 41190 부천시 , 41430 의왕시, 41410 군포시
			
			//commState = 1;
			if (onlineCenterMap.size > 0) {
				commState = onlineCenterMap.get(regionCd);
			}
			//시군구 코드가 없으면 상태정보이미지가 없데이트가 안된다...
			if(commState == 0) 
			{
				var guIntErrCnt = 0;
				for(var jj = 0; jj < intNoArr.length; jj++)
				{
					if(commOnOffFlagArr[jj] == 1)
					{
						guIntErrCnt++;
						commOnOffImg = 'background-image:url("images/intStatusOff.png");background-position:center center';
					}
					else
					{
						commOnOffImg = 'background-image:url("images/intStatusOn.png");background-position:center center';
					}
					$('#' + regionCd + '_' + network + '_' + intNoArr[jj] + ' .jstree-anchor .jstree-icon').attr('style',commOnOffImg);
				}
				$('.guIntErrCnt_' + network + '_' + regionCd +'_' + sigunguCd).text(guIntErrCnt);
			}
			else
			{
				for(var j = 0; j < intNoArr.length; j++)
				{
					commOnOffImg = 'background-image:url("images/intStatusOff.png");background-position:center center';
					$('#' + regionCd + '_' + network + '_' + intNoArr[j] + ' .jstree-anchor .jstree-icon').attr('style',commOnOffImg);
				}
				$('.guIntErrCnt_' + network + '_' + regionCd + '_' + sigunguCd).text(intNoArr.length);
			}

		}
	}
	
	//그룹제어기 상태체크..
	
	function emptyintGroupLineArr() {
		if(intGroupLineArr != null) {
			for(var ii = 0; ii < intGroupLineArr.length; ii++)
			{
				intGroupLineArr[ii].setMap(null);
			}
			intGroupLineArr = [];
		}
	}

	function emptyintGroupCircleArr() {
		if(intGroupCircleArr != null) {
			for(var ii = 0; ii < intGroupCircleArr.length; ii++)
			{
				intGroupCircleArr[ii].setMap(null);
			}
			intGroupCircleArr = [];
		}
	}

	function drawIntGroupLine(groupXCoord,groupYCoord)
	{
		emptyintGroupLineArr();
		emptyintGroupCircleArr();
		var groupLatLngArr = [];
		var groupCircleRadius = 10;
		level = parent.map.getLevel();
		
		//if(level == 0 || level == 1) groupCircleRadius = 10;
		//else if(level == 2) groupCircleRadius = 20;
		//else if(level == 3) groupCircleRadius = 25;
		//else if(level == 4) groupCircleRadius = 30;
		//else if(level == 5) groupCircleRadius = 80;
		//else if(level == 6) groupCircleRadius = 120;
		if(level < 3) groupCircleRadius = 30;
		else if(level === 3) groupCircleRadius = 35;
		else if(level === 4) groupCircleRadius = 50;
		else if(level === 5) groupCircleRadius = 80;
		
		for(var ii = 0; ii < groupXCoord.length; ii++)
		{
			groupLatLngArr.push(new parent.kakao.maps.LatLng(groupYCoord[ii], groupXCoord[ii]));
			
			var intGroupCircle = new parent.kakao.maps.Circle({
			    center : new parent.kakao.maps.LatLng(groupYCoord[ii], groupXCoord[ii]),
			    radius: groupCircleRadius,
			    strokeWeight: 2,
			    strokeColor: '#000000',
			    strokeOpacity: 1,
			    strokeStyle: 'solid',
			    fillColor: 'yellow',
			    fillOpacity:0.5,
			    zIndex: 10
			});
			if (level < 6) {
				intGroupCircle.setMap(parent.map);
			}
			intGroupCircleArr.push(intGroupCircle);
		}
		var intGroupLine = new parent.kakao.maps.Polyline({
	        path: groupLatLngArr,
	        strokeWeight: 30,
	        strokeColor: '#FF0000',
	        strokeOpacity: 0.3,
	        strokeStyle: 'solid',
	        endArrow: false,
	        zIndex: 10
		});
		
		//intGroupLine.setMap(parent.map);
		//intGroupLineArr.push(intGroupLine);
	}
	
	function getIntGroupCircle() {
		return intGroupCircleArr;
	}

</script>
</body>
</html>
