
/*
 * 전체 신호제어기를 메모리에 저장해서 등록함(Bean 으로 등록하면 됨)
 */
var _mapSignal = new HashMap();

var _circleSize = 25;    //서클사이즈
var _circleStroke = 4;   //서클두께
var _imgW = 55;         //보행자이미지 가로
var _imgH = 55;         //보행자이미지 세로
var _lightBlinkImgSrc = 'images/lightBlink_55.gif';
var _pedeImgSrc = 'images/walking_55.png'; //보행자이미지
var _imgOffSetW = 27; //보행자 이미지 가로중심점               
var _imgOffsetH = 27; //보행자 이미지 세로중심점

var listDrawSignal = [];
var signalALineArr = [];
var signalBLineArr = [];
var signalBackCircleArr = [];
var signalInfoId = null;
var sigInfowindow = null;

var signalArr = [];
var signalInfo = {};
var signalIdx  = 0;
var sigDataArr = [];
var aRingPhaseValArr = [];
var bRingPhaseValArr = [];
var aRingPhaseArr = [];
var bRingPhaseArr = [];
var linkLineArr = [];
var linkPhaseLineArr = [];
var _ALineCenterArr = [];
var _BLineCenterArr = [];
var lineCenterCircleArr = [];

var _Flag = null;
var getPhaseTimeId = null;
var mapCircleMeta;
var _RingPhaseVal = 0;

var linkVtxArrData = null;
var linkVtxLineArr = [];
var siginfoPhaseDetailWin = null;

var _CvibObjArr = [];
var _CvibMapArr = [];
var _CvibCircleImgArr = [];
var _CvibInfoImgArr = [];
var _CvibTimeId = null;
var _CircleSize = [20, 20, 20, 25, 30];
var _CircleStroke = [14, 10, 6, 4, 3];
var _ImageSize = [335, 175, 90, 55, 33];

function mapZoomBound() {
	if(sigInfowindow != null) sigInfowindow.close();
	
	if(customOverlay != null)
	{
		customOverlay.setMap(null);
		customOverlay = null;
	}
	
	emptySignalArr(signalBackCircleArr);
	emptySignalArr(signalALineArr);
	emptySignalArr(signalBLineArr);
	emptySignalArr(lineCenterCircleArr);
	emptySignalArr(_CvibCircleImgArr);
	emptySignalArr(_CvibInfoImgArr);
	
	signalBackCircleArr = [];
	signalALineArr      = [];
	signalBLineArr      = [];
	lineCenterCircleArr = [];
	_CvibInfoImgArr     = [];
	_CvibCircleImgArr   = [];

	_Level = map.getLevel();
	if(_Level < 6)
	{
		
		_circleSize = _CircleSize[_Level];
		_circleStroke = _CircleStroke[_Level];
		const imageSize = _ImageSize[_Level];
		_imgW = imageSize;
		_imgH = imageSize;
		_lightBlinkImgSrc = 'images/lightBlink_' + imageSize + '.gif';
		_imgOffSetW = imageSize/2;
		_imgOffsetH = imageSize/2;
//		if(_Level == 0)
//		{
//			_circleSize = 20;    //원지름
//			_circleStroke = 14;   //원두께
//			_imgW = 335;
//			_imgH = 335;
//			_lightBlinkImgSrc = 'images/lightBlink_175.gif';
//			_pedeImgSrc = 'images/walking_175.png';
//			_imgOffSetW = 168;
//			_imgOffsetH = 168;
//		}
//		else if(_Level == 1)
//		{
//			_circleSize = 20;    //원지름
//			_circleStroke = 10;   //원두께
//			_imgW = 175;
//			_imgH = 175;
//			_lightBlinkImgSrc = 'images/lightBlink_175.gif';
//			_pedeImgSrc = 'images/walking_175.png';
//			_imgOffSetW = 86;
//			_imgOffsetH = 86;
//		}
//		else if(_Level == 2)
//		{
//			_circleSize = 20;
//			_circleStroke = 6;
//			_imgW = 90;
//			_imgH = 90;
//			_lightBlinkImgSrc = 'images/lightBlink_90.gif';
//			_pedeImgSrc = 'images/walking_90.png';
//			_imgOffSetW = 45;
//			_imgOffsetH = 45;
//		}
//		else if(_Level == 3)
//		{
//			_circleSize = 25;
//			_circleStroke = 4;
//			_imgW = 55;
//			_imgH = 55;
//			_lightBlinkImgSrc = 'images/lightBlink_55.gif';
//			_pedeImgSrc = 'images/walking_55.png';
//			_imgOffSetW = 27;
//			_imgOffsetH = 27;
//		}
//		else if(_Level == 4)
//		{
//			_circleSize = 30;
//			_circleStroke = 3;
//			_imgW = 33;
//			_imgH = 33;
//			_lightBlinkImgSrc = 'images/lightBlink_33.gif';
//			_pedeImgSrc = 'images/walking_33.png';
//			_imgOffSetW = 17;
//			_imgOffsetH = 17;
//		}
		
		if(typeof _Flag != 'undefined') getSignalInfo(_Flag);
		else
		{
			getSignalInfo();
			getCvibInfo();
		}
	}
	else 
	{
		if(signalArr != null)
		{
			signalArr.forEach(function(el) {
				el.mapCircle.setMap(null);
			});
			
			signalArr = 0;
			signalArr = [];
		}
		if(getPhaseTimeId != null) clearTimeout(getPhaseTimeId);
	}
	
	//돌발정보
	var ims  = $("#ims").attr("class");
	if(ims == "road_on") 
	{
		getIMS();
		imsFlag = false;
	}
	
	let circleArr;
	
	if (window.opener) {
		circleArr = window.opener.$('#iframeTreeList')[0].contentWindow.getIntGroupCircle();
	}
	else {
		circleArr = $('#iframeTreeList')[0].contentWindow.getIntGroupCircle();
	}
	if (circleArr && circleArr.length) {
		var radius = 30;
		if (_Level >= 6) {
			circleArr.forEach((obj)=>{
				obj.setMap(null);
			});
		}
		else {
			if (_Level === 3) {
				radius = 35;
			}
			else if (_Level === 4) {
				radius = 50;
			}
			else if (_Level === 5){
				radius = 80;
			}
			circleArr.forEach((obj)=>{
				obj.setOptions({radius: radius})
				obj.setMap(map);
			});
		}
		
	}
}

function mapMoveBound() {
	if(sigInfowindow != null) sigInfowindow.close();
	if(_Level < 6)
	{
		if(typeof _Flag != 'undefined')
		{
			getSignalInfo(_Flag);
			if(customOverlay != null) 
			{
				customOverlay.setMap(null);
				customOverlay = null;
			}
		}
		else
		{
			getSignalInfo();
			getCvibInfo();
		}
	}
	
}

function emptySignalArr(arr) {
	if(arr != null) 
	{
		arr.forEach(function(el) {
			el.setMap(null);
		});
		arr = 0;
	}
}

function getSignalInfo(flag) {
	const startTime = new Date();
	if(getPhaseTimeId != null) clearTimeout(getPhaseTimeId);
	
	_Flag = flag;
	
	var url = 'getSignalInfo.do';
	var param = 'regionCd='+_RegionCd+
	'&minX='+map.getBounds().getSouthWest().getLng()+
    '&minY='+map.getBounds().getSouthWest().getLat()+
    '&maxX='+map.getBounds().getNorthEast().getLng()+
    '&maxY='+map.getBounds().getNorthEast().getLat()+
    '&sidoFlag='+_Flag;
	//console.log(map.getCenter());
	//console.log(param);
	
	requestService(url, param, (data)=>{
		if ($("#iframeTreeList").contents().find("#intTree").children().length > 0) {
			$("#iframeTreeList").get(0).contentWindow.onlineCenterStatusCheckCallback(data.centerStatus);
		}
		getSignalInfoCallback(data.signalInfo);
		
		const endTime = new Date();
		const betweenTime = endTime.getTime() - startTime.getTime();
		let intervalTime = 1000 - betweenTime;
		if (betweenTime >= 1000) {
			intervalTime = 0;
		}
		
		if(_Level < 5)
		{
			if(_Flag == 'sigPop')
			{
				_circleSize = 20;     //원지름
				_circleStroke = 10;   //원두께
				_lightBlinkImgSrc = 'images/lightBlink_175.gif';
				_pedeImgSrc = 'images/walking_175.png'; //보행자이미지
				_imgW = 175;
				_imgH = 175;
				_imgOffSetW = 86;
				_imgOffsetH = 86;
				
				getPhaseTimeId = setTimeout('getSignalInfo("sigPop")',intervalTime);
			}
	//		else if(_Flag == 'SIDO' || _Flag == 'addSignal')
			else if(_Flag == 'addSignal')
			{
				if(getPhaseTimeId != null) clearTimeout(getPhaseTimeId);
			}
			else
			{
				getPhaseTimeId = setTimeout('getSignalInfo()',intervalTime);
			}
		}
	});
	
}

/* 좌표값 추출 테스트*/
function getSignalCoordinateFunc() {
	const updateData = [];
	requestService('getSignalCoordinate.do', null, (data)=>{
		data.forEach((obj)=>{
			const {
					A_RING_1_PHASE_VAL,
					A_RING_3_PHASE_VAL,
					A_RING_2_PHASE_VAL,
					A_RING_4_PHASE_VAL,
					A_RING_5_PHASE_VAL,
					A_RING_6_PHASE_VAL,
					A_RING_7_PHASE_VAL,
					A_RING_8_PHASE_VAL,
					A_RING_1_PHASE_CONF_CD,
					A_RING_2_PHASE_CONF_CD,
					A_RING_3_PHASE_CONF_CD,
					A_RING_4_PHASE_CONF_CD,
					A_RING_5_PHASE_CONF_CD,
					A_RING_6_PHASE_CONF_CD,
					A_RING_7_PHASE_CONF_CD,
					A_RING_8_PHASE_CONF_CD,
					A1_FLOW_NUM,
					A2_FLOW_NUM,
					A3_FLOW_NUM,
					A4_FLOW_NUM,
					A5_FLOW_NUM,
					A6_FLOW_NUM,
					A7_FLOW_NUM,
					A8_FLOW_NUM,
					A_RING_PHASE_VAL,
					B_RING_1_PHASE_VAL,
					B_RING_2_PHASE_VAL,
					B_RING_3_PHASE_VAL,
					B_RING_4_PHASE_VAL,
					B_RING_5_PHASE_VAL,
					B_RING_6_PHASE_VAL,
					B_RING_7_PHASE_VAL,
					B_RING_8_PHASE_VAL,
					B_RING_1_PHASE_CONF_CD,
					B_RING_2_PHASE_CONF_CD,
					B_RING_3_PHASE_CONF_CD,
					B_RING_4_PHASE_CONF_CD,
					B_RING_5_PHASE_CONF_CD,
					B_RING_6_PHASE_CONF_CD,
					B_RING_7_PHASE_CONF_CD,
					B_RING_8_PHASE_CONF_CD,
					B1_FLOW_NUM,
					B2_FLOW_NUM,
					B3_FLOW_NUM,
					B4_FLOW_NUM,
					B5_FLOW_NUM,
					B6_FLOW_NUM,
					B7_FLOW_NUM,
					B8_FLOW_NUM,
					B_RING_PHASE_VAL,
					COLLCT_DTIME,
					COMM_ON_OFF_FLAG,
					COMM_STATE,
					CONTRLR_MANUAL_FLAG,
					CONTRLR_OPER_MODE_CD,
					CONTRLR_TMDIFF_CONTRL_FLAG,
					GROUP_NO,
					INT_LAMPTYPE,
					INT_LCTYPE,
					INT_NM,
					INT_NO,
					INT_NO_SE,
					INT_SIG_CYCLE_CNT,
					INT_SIG_CYCLE_LEN,
					MAIN_INTNO,
					MAP_NO,
					MODEM_IP,
					NETWORK_TYPE,
					PPC_CONTRL_FLAG,
					REGION_CD,
					REGION_ID,
					REGION_NM,
					SIGLIGHT_BLINK_FLAG,
					SIGLIGHT_TURNOFF_FLAG,
					SIGUNGU_CD,
					SIMUL_FLAG,
					X_COORD,
					Y_COORD,
					INT_MAINPHASE
				} = obj;
					
	
			obj.aRingArr = [
				A_RING_1_PHASE_VAL,
				A_RING_2_PHASE_VAL,
				A_RING_3_PHASE_VAL,
				A_RING_4_PHASE_VAL,
				A_RING_5_PHASE_VAL,
				A_RING_6_PHASE_VAL,
				A_RING_7_PHASE_VAL,
				A_RING_8_PHASE_VAL
			];
			
			obj.aRingConfArr = [
				A_RING_1_PHASE_CONF_CD,
				A_RING_2_PHASE_CONF_CD,
				A_RING_3_PHASE_CONF_CD,
				A_RING_4_PHASE_CONF_CD,
				A_RING_5_PHASE_CONF_CD,
				A_RING_6_PHASE_CONF_CD,
				A_RING_7_PHASE_CONF_CD,
				A_RING_8_PHASE_CONF_CD
			];
			
			obj.bRingArr = [
				B_RING_1_PHASE_VAL,
				B_RING_2_PHASE_VAL,
				B_RING_3_PHASE_VAL,
				B_RING_4_PHASE_VAL,
				B_RING_5_PHASE_VAL,
				B_RING_6_PHASE_VAL,
				B_RING_7_PHASE_VAL,
				B_RING_8_PHASE_VAL
			];
			
			obj.bRingConfArr = [
				B_RING_1_PHASE_CONF_CD,
				B_RING_2_PHASE_CONF_CD,
				B_RING_3_PHASE_CONF_CD,
				B_RING_4_PHASE_CONF_CD,
				B_RING_5_PHASE_CONF_CD,
				B_RING_6_PHASE_CONF_CD,
				B_RING_7_PHASE_CONF_CD,
				B_RING_8_PHASE_CONF_CD
			];
			
			obj.aFlowNumArr = [
				A1_FLOW_NUM,
				A2_FLOW_NUM,
				A3_FLOW_NUM,
				A4_FLOW_NUM,
				A5_FLOW_NUM,
				A6_FLOW_NUM,
				A7_FLOW_NUM,
				A8_FLOW_NUM,
			];
			
			obj.bFlowNumArr = [
				B1_FLOW_NUM,
				B2_FLOW_NUM,
				B3_FLOW_NUM,
				B4_FLOW_NUM,
				B5_FLOW_NUM,
				B6_FLOW_NUM,
				B7_FLOW_NUM,
				B8_FLOW_NUM,
			];
			
			
			
			if (obj.aRingConfArr[0] >= 0 && obj.bRingConfArr[0] >= 0) {
				
				const phase1 = new SignalDraw(obj.aRingConfArr[0], obj.bRingConfArr[0], Y_COORD.toString(), X_COORD.toString(), REGION_CD, REGION_ID, 
								REGION_NM, INT_NO, INT_NM,INT_SIG_CYCLE_CNT,INT_SIG_CYCLE_LEN,
								COMM_ON_OFF_FLAG,GROUP_NO,MAP_NO, MAIN_INTNO, SIGUNGU_CD, 
								INT_LCTYPE, INT_LAMPTYPE, INT_MAINPHASE,
								NETWORK_TYPE, MODEM_IP);
			}
			const flowTypeArr = ['S','L','P'];
			for (let idx in obj.aRingArr) {
				if (obj.aRingArr[idx]) {
					
						const draw = new SignalDraw(obj.aRingConfArr[idx], obj.bRingConfArr[idx], Y_COORD.toString(), X_COORD.toString(), REGION_CD, REGION_ID, 
								REGION_NM, INT_NO, INT_NM,INT_SIG_CYCLE_CNT,INT_SIG_CYCLE_LEN,
								COMM_ON_OFF_FLAG,GROUP_NO,MAP_NO, MAIN_INTNO, SIGUNGU_CD, 
								INT_LCTYPE, INT_LAMPTYPE, INT_MAINPHASE,
								NETWORK_TYPE, MODEM_IP);
						
						if (draw.listCoordA && draw.listCoordA.length) {
							let aType = obj.aRingConfArr[idx].substr(0, 1);
							if (!flowTypeArr.includes(aType)) {
								aType = 'A';
							}
							const aData = {
								REGION_CD,
								INT_NO,
								MAP_NO,
								RING_NO : 0,
								PHASE_NO : idx,
								FLOW_NO : obj.aFlowNumArr[idx] ? obj.aFlowNumArr[idx] : null,
								FLOW_TP : aType,
								FLOW_S_LAT : draw.listCoordA[0].Lat,
								FLOW_S_LNG : draw.listCoordA[0].Lng,
								FLOW_M_LAT : draw.listCoordA[1].Lat,
								FLOW_M_LNG : draw.listCoordA[1].Lng,
								FLOW_E_LAT : draw.listCoordA[2].Lat,
								FLOW_E_LNG : draw.listCoordA[2].Lng,
								COLLCT_DTIME : COLLCT_DTIME,
							};
							updateData.push(aData);
						}
						if (draw.listCoordB && draw.listCoordB.length) {
							let bType = obj.bRingConfArr[idx].substr(0, 1);
							if (!flowTypeArr.includes(bType)) {
								aType = 'A';
							}
							const bData = {
								REGION_CD,
								INT_NO,
								MAP_NO,
								RING_NO : 1,
								PHASE_NO : idx,
								FLOW_NO : obj.bFlowNumArr[idx] ? obj.bFlowNumArr[idx] : null,
								FLOW_TP : bType,
								FLOW_S_LAT : draw.listCoordB[0].Lat,
								FLOW_S_LNG : draw.listCoordB[0].Lng,
								FLOW_M_LAT : draw.listCoordB[1].Lat,
								FLOW_M_LNG : draw.listCoordB[1].Lng,
								FLOW_E_LAT : draw.listCoordB[2].Lat,
								FLOW_E_LNG : draw.listCoordB[2].Lng,
								COLLCT_DTIME : COLLCT_DTIME,
							};
							updateData.push(bData);
							
						}
							
					}
				}

		});

		if (updateData.length > 0) {
			//console.log(updateData);
			$.ajax({
				url		: "/insertSignalFlowInfo.do"
			  , data 	: JSON.stringify(updateData)
			  , contentType: 'application/json; charset=utf-8'
			  , dataType: "JSON"
			  , method	: 'POST'
			  , success : function(res){
					alert(res.msg);
			  }
			  , error   : function(err) {
				  console.log(err);
			  }
			});
			
		}
		
	}, true);
	
}



function getSignalInfoCallback(data) {
	//신호표시 바깥원을 지운다..
	_mapSignal.clear();
	if(signalArr != null)
	{
		signalArr.forEach(function(el) {
			el.mapCircle.setMap(null);
		});
		
		signalArr  = 0;
		signalArr  = [];
		signalInfo = {};
		signalIdx  = 0;
	}
	
	//신호 페이즈정보 삭제..
	emptySignalArr(signalBackCircleArr);
	emptySignalArr(signalALineArr);
	emptySignalArr(signalBLineArr);
	
	signalArr = [];
	signalBackCircleArr = [];
	signalALineArr      = [];
	signalBLineArr      = [];
	
	aRingPhaseValArr = [];
	bRingPhaseValArr = [];
	aRingPhaseArr    = [];
	bRingPhaseArr    = [];
	sigDataArr       = [];
	
	_ALineCenterArr = 0;
	_BLineCenterArr = 0;
	_ALineCenterArr = [];
	_BLineCenterArr = [];
	
	var commState = 0;
	var simulFlag = 'N';
	var bottomStr = '';
	
	//if($(xml).find("list").length > 0 )

	if(data && data.length > 0 )
	{
		data.forEach((e)=> {
			var regionCd = e.region_cd;
			var regionId = e.region_id;
			var regionNm = e.region_nm;
			var intNo  = e.int_no;
			var intNm  = e.int_nm;
			var xCoord = e.x_coord;
			var yCoord = e.y_coord;
			var groupNo = e.group_no;
			var mainIntNo = e.main_intno;;
			var aRing0 = e.a_ring_1_phase_conf_cd;
			var aRing1 = e.a_ring_2_phase_conf_cd;
			var aRing2 = e.a_ring_3_phase_conf_cd;
			var aRing3 = e.a_ring_4_phase_conf_cd;
			var aRing4 = e.a_ring_5_phase_conf_cd;
			var aRing5 = e.a_ring_6_phase_conf_cd;
			var aRing6 = e.a_ring_7_phase_conf_cd;
			var aRing7 = e.a_ring_8_phase_conf_cd;
			var bRing0 = e.b_ring_1_phase_conf_cd;
			var bRing1 = e.b_ring_2_phase_conf_cd;
			var bRing2 = e.b_ring_3_phase_conf_cd;
			var bRing3 = e.b_ring_4_phase_conf_cd;
			var bRing4 = e.b_ring_5_phase_conf_cd;
			var bRing5 = e.b_ring_6_phase_conf_cd;
			var bRing6 = e.b_ring_7_phase_conf_cd;
			var bRing7 = e.b_ring_8_phase_conf_cd;
			var collctDtime = e.collct_dtime;
			var commOnOffFlag       = e.comm_on_off_flag;
			var contrlrOperModeCd   = e.contrlr_oper_mode_cd;
			var aRingPhaseVal       = e.a_ring_phase_val;
			var bRingPhaseVal       = e.b_ring_phase_val;
			var siglightTurnoffFlag = e.siglight_turnoff_flag;
			var siglightBlinkFlag   = e.siglight_blink_flag;
			var contrlrManualFlag   = e.contrlr_manual_flag;
			var contrlrTmdiffContrlFlag = e.contrlr_tmdiff_contrl_flag;
			var intSigCycleCnt      = e.int_sig_cycle_cnt;
			var intSigCycleLen      = e.int_sig_cycle_len;
			var mapNo               = e.map_no;
			var sigunguCd           = e.sigungu_cd;
			var intMainphase        = e.int_mainphase;
			var ppcContrlFlag       = e.ppc_contrl_flag;
			var intLcType           = e.int_lctype;
			var intLampType         = e.int_lamptype;
			var sigunguCd           = e.sigungu_cd;
			var simulFlag           = e.simul_FLAG;
			    commState           = e.comm_state;
			var networkType         = e.network_type;
			var modemIp             = e.modem_ip;

			//제어기 상태 색상변경..
			var strokeColor = '#0000FF';
			var fillColor;
			
			if(contrlrManualFlag == 1) fillColor = '#03fdee'; //수동
			else fillColor = '#ffffff';

			if(contrlrOperModeCd == 1 || contrlrOperModeCd == 2) //오프라인
			{
				if(contrlrOperModeCd == 2)
				{
					strokeColor = '#FF0000';
					fillColor = '#666666';
				}
				//시차제 인경우
				if(contrlrTmdiffContrlFlag == 1) strokeColor = '#FF00FF'; //핑크
			}
			else if(contrlrOperModeCd == 4 || contrlrOperModeCd == 5) //온라인
			{
				if(contrlrOperModeCd == 4)
				{
					strokeColor = '#FF0000'; //red
				}

				//시차제 인경우
				if(contrlrTmdiffContrlFlag == 1) strokeColor = '#FF00FF'; //핑크
			}
			
			var cdNo = regionCd+intNo;
			var signal = findSignal(cdNo);
			if(_mapSignal.containsKey(cdNo) == false)
			{
				signal = new Signal(yCoord, xCoord, strokeColor, fillColor, regionCd, regionId, regionNm, intNo, intNm, groupNo, 
						mapNo, mainIntNo, sigunguCd, intLcType, intLampType, intMainphase, commOnOffFlag, intSigCycleCnt, intSigCycleLen, networkType, modemIp);
				addSignal(cdNo,signal);
			}
			else
			{
				signal.mapCircle.setOptions({
					strokeColor: strokeColor,
					fillColor: fillColor
				});
			}

			//페이즈 구분을 해주자...
			signal.signalIdx = signalIdx++;
			signalInfo[signal.regionId+"."+signal.intNo] = signal;
			signalArr.push(signal);
			
			if(commState == 0 || (commState == 1 && simulFlag == 'Y'))
			{
				if(_Level < 5)
				{
					aRingPhaseValArr.push(aRingPhaseVal);
					bRingPhaseValArr.push(bRingPhaseVal);
					aRingPhaseArr.push(new ringPhaseData(aRing0,aRing1,aRing2,aRing3,aRing4,aRing5,aRing6,aRing7));
					bRingPhaseArr.push(new ringPhaseData(bRing0,bRing1,bRing2,bRing3,bRing4,bRing5,bRing6,bRing7));
					sigDataArr.push(new sigMetaData(regionCd,regionId,regionNm,intNo,intNm,intSigCycleCnt,intSigCycleLen,
							        commOnOffFlag,siglightTurnoffFlag,siglightBlinkFlag,contrlrManualFlag,groupNo,mapNo,mainIntNo,
							        sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp));
				}
				//하단교차로신호 정보
				if(_Flag != 'sigPop' || _Flag != 'addSignal')
				{
					bottomStr += '<tr>';
					bottomStr += '<td style="width:4%" id="regionNm_'+regionId+'_'+intNo+'">'+regionNm+'</td>';
					bottomStr += '<td style="width:5%" id="groupNo_'+regionId+'_'+intNo+'">'+groupNo+'</td>';
					bottomStr += '<td style="width:5%" id="intNo_'+regionId+'_'+intNo+'"><a href="javascript:goPanToInt(\''+intNm+'\','+xCoord+','+yCoord+')">'+intNo+'</a></td>';
					bottomStr += '<td style="width:12%" id="intNm_'+regionId+'_'+intNo+'"><a href="javascript:goPanToInt(\''+intNm+'\','+xCoord+','+yCoord+')">'+intNm+'</a></td>';
					bottomStr += '<td style="width:8%" id="collctDtime_'+regionId+'_'+intNo+'">'+collctDtime+'</td>';
					bottomStr += '<td style="width:5%" id="commOnOffFlag_'+regionId+'_'+intNo+'"><img src="/images/comm_'+commOnOffFlag+'.png" /></td>';
					bottomStr += '<td style="width:8%" id="contrlrOperModeCd_'+regionId+'_'+intNo+'">'+contrlrOperModeCdFnc(contrlrOperModeCd)+'</td>';
					bottomStr += '<td style="width:6%" id="contrlrTmdiffContrlFlag_'+regionId+'_'+intNo+'">'+tmdiffFlagFnc(contrlrTmdiffContrlFlag)+'</td>';
					bottomStr += '<td style="width:6%" id="aRingPhaseVal_'+regionId+'_'+intNo+'">'+(Number(aRingPhaseVal)+1)+'</td>';
					bottomStr += '<td style="width:6%" id="bRingPhaseVal_'+regionId+'_'+intNo+'">'+(Number(bRingPhaseVal)+1)+'</td>';
					bottomStr += '<td style="width:4%" id="siglightTurnoffFlag_'+regionId+'_'+intNo+'">'+onOffFlagFnc(siglightTurnoffFlag)+'</td>';
					bottomStr += '<td style="width:4%" id="siglightBlinkFlag_'+regionId+'_'+intNo+'">'+onOffFlagFnc(siglightBlinkFlag)+'</td>';
					bottomStr += '<td style="width:4%" id="contrlrManualFlag_'+regionId+'_'+intNo+'">'+onOffFlagFnc(contrlrManualFlag)+'</td>';
					bottomStr += '<td style="width:7%" id="intSigCycleCnt_'+regionId+'_'+intNo+'">'+intSigCycleCnt+'</td>';
					bottomStr += '<td style="width:5%" id="intSigCycleLen_'+regionId+'_'+intNo+'">'+intSigCycleLen+'</td>';
					bottomStr += '<td style="width:5%" id="mapNo_'+regionId+'_'+intNo+'">'+mapNo+'</td>';
					bottomStr += '<td style="width:6%" id="ppcContrlFlag_'+regionId+'_'+intNo+'">'+ppcFlagFnc(ppcContrlFlag)+'</td>';
					bottomStr += '</tr>';
				}
			}
			else
			{
				sigDataArr.push(new sigMetaData(regionCd,regionId,regionNm,intNo,intNm,intSigCycleCnt,intSigCycleLen,
						        '1',siglightTurnoffFlag,siglightBlinkFlag,contrlrManualFlag,groupNo,mapNo,mainIntNo,
						        sigunguCd,intLcType,intLampType,networkType,modemIp));
				if(_Flag != 'sigPop' || _Flag != 'addSignal')
				{
					bottomStr += '<tr>';
					bottomStr += '<td style="width:4%">'+regionNm+'</td>';
					bottomStr += '<td style="width:5%">'+groupNo+'</td>';
					bottomStr += '<td style="width:5%">'+intNo+'</td>';
					bottomStr += '<td style="width:12%">'+intNm+'</td>';
					bottomStr += '<td style="width:8%">-</td>';
					bottomStr += '<td style="width:5%">-</td>';
					bottomStr += '<td style="width:8%">-</td>';
					bottomStr += '<td style="width:6%">-</td>';
					bottomStr += '<td style="width:6%">-</td>';
					bottomStr += '<td style="width:6%">-</td>';
					bottomStr += '<td style="width:4%">-</td>';
					bottomStr += '<td style="width:4%">-</td>';
					bottomStr += '<td style="width:4%">-</td>';
					bottomStr += '<td style="width:7%">-</td>';
					bottomStr += '<td style="width:5%">-</td>';
					bottomStr += '<td style="width:5%">-</td>';
					bottomStr += '<td style="width:6%">-</td>';
					bottomStr += '</tr>';
				}
			}
		});
		
		if(_Flag != 'sigPop' || _Flag != 'addSignal')
		{
			setTimeout(function(){$('#iframeBottomList').contents().find('#bottomInfo').empty().html(bottomStr);},300);
		}
		
		if(_Level < 5) setRingPhase();
	}
	else {
		$('#iframeBottomList').contents().find('#bottomInfo').empty();
	}
}

/*function drawSignal(signal) {
	if(sigInfowindow != null) sigInfowindow.close();
}*/

function setRingPhase() {
	if(sigInfowindow != null) sigInfowindow.close();
	
	var aRingDeg;
	var bRingDeg;
	
	for(var ii = 0; ii < signalArr.length; ii++)
	{
		var regionCd           = sigDataArr[ii].regionCd;
		var regionId           = sigDataArr[ii].regionId;
		var regionNm           = sigDataArr[ii].regionNm;
		var intNo              = sigDataArr[ii].intNo;
		var intNm              = sigDataArr[ii].intNm;
		var intSigCycleCnt     = sigDataArr[ii].intSigCycleCnt;
		var intSigCycleLen     = sigDataArr[ii].intSigCycleLen;
		var commOnOffFlag      = sigDataArr[ii].commOnOffFlag;
		var siglightTurnoffVal = sigDataArr[ii].siglightTurnoffFlag;
		var siglightBlinkVal   = sigDataArr[ii].siglightBlinkFlag;
		var groupNo            = sigDataArr[ii].groupNo;
		var mapNo              = sigDataArr[ii].mapNo;
		var mainIntNo          = sigDataArr[ii].mainIntNo;
		var sigunguCd          = sigDataArr[ii].sigunguCd;
		var intLcType          = sigDataArr[ii].intLcType;
		var intLampType        = sigDataArr[ii].intLampType;
		var intMainphase       = sigDataArr[ii].intMainphase;
		var networkType        = sigDataArr[ii].networkType;
		var modemIp            = sigDataArr[ii].modemIp;
		var aRingVal;
		var bRingVal;
		
		if(commOnOffFlag == 1) signalArr[ii].setPhase('commOff',null,regionCd,regionId,regionNm,intNo,intNm,intSigCycleCnt,intSigCycleLen,commOnOffFlag,groupNo,mapNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
		else if(siglightTurnoffVal == 1) signalArr[ii].setPhase('siglightTurnoff',null,regionCd,regionId,regionNm,intNo,intNm,intSigCycleCnt,intSigCycleLen,commOnOffFlag,groupNo,mapNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
		else if(siglightBlinkVal == 1) signalArr[ii].setPhase('siglightBlink',null,regionCd,regionId,regionNm,intNo,intNm,intSigCycleCnt,intSigCycleLen,commOnOffFlag,groupNo,mapNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
		else
		{
			if(_Flag == 'addSignal')
			{
				aRingVal = _RingPhaseVal;
				bRingVal = _RingPhaseVal;
			}
			else
			{
				aRingVal = aRingPhaseValArr[ii];
				bRingVal = bRingPhaseValArr[ii];
			}
			
			if(aRingVal == 0)      aRingDeg = aRingPhaseArr[ii].ring0;
			else if(aRingVal == 1) aRingDeg = aRingPhaseArr[ii].ring1;
			else if(aRingVal == 2) aRingDeg = aRingPhaseArr[ii].ring2;
			else if(aRingVal == 3) aRingDeg = aRingPhaseArr[ii].ring3;
			else if(aRingVal == 4) aRingDeg = aRingPhaseArr[ii].ring4;
			else if(aRingVal == 5) aRingDeg = aRingPhaseArr[ii].ring5;
			else if(aRingVal == 6) aRingDeg = aRingPhaseArr[ii].ring6;
			else if(aRingVal == 7) aRingDeg = aRingPhaseArr[ii].ring7;
			else aRingDeg = '';
			
			if(bRingVal == 0)      bRingDeg = bRingPhaseArr[ii].ring0;
			else if(bRingVal == 1) bRingDeg = bRingPhaseArr[ii].ring1;
			else if(bRingVal == 2) bRingDeg = bRingPhaseArr[ii].ring2;
			else if(bRingVal == 3) bRingDeg = bRingPhaseArr[ii].ring3;
			else if(bRingVal == 4) bRingDeg = bRingPhaseArr[ii].ring4;
			else if(bRingVal == 5) bRingDeg = bRingPhaseArr[ii].ring5;
			else if(bRingVal == 6) bRingDeg = bRingPhaseArr[ii].ring6;
			else if(bRingVal == 7) bRingDeg = bRingPhaseArr[ii].ring7;
			else bRingDeg = '';
			
			signalArr[ii].setPhase(aRingDeg, bRingDeg, regionCd, regionId, regionNm, intNo, intNm, intSigCycleCnt, intSigCycleLen, commOnOffFlag, groupNo, mapNo, mainIntNo, sigunguCd, intLcType, intLampType, intMainphase,networkType,modemIp);
			
		}
	}
	
}

function findSignal(Id) {
	return _mapSignal.get(Id);
};

function addSignal(Id, Obj) {
	_mapSignal.put(Id, Obj);
	return _mapSignal.size();
};


//#define RadToDeg(x) (57.29577951 * x)
//#define DegToRad(x) (0.017453293 * x)
Number.prototype.toRadians = function() { 
	return this * 0.017453293; 
	//return this * Math.PI / 180; 
};
Number.prototype.toDegrees = function() { 
	return this * 57.29577951; 
	//return this * 180 / Math.PI; 
};


/*
 * 좌표를 저장하는 Class
 * Lat(Y) = 37.564974, Lng(X) = 126.978517;
 * kakao.maps.LatLng(Lat, Lng)
 */
function SCoord(Lat, Lng) {
	this.Lat = parseFloat(Lat);
	this.Lng = parseFloat(Lng);
};

function SignalLinkDraw(ALink,BLink) {
	this.initialize(ALink,BLink);
}

SignalLinkDraw.prototype = {
	ALink : null,
	BLink : null,
	mapRingALink : null,
	mapRingBLink : null,
	
	initialize : function(ALink,BLink) {
		this.ALink = ALink;
		this.BLink = BLink;
		
		this.mapRingALink = null;
		this.mapRingBLink = null;
		
		var ALinkArr = ALink.substr(1).split('/');
		var BLinkArr = BLink.substr(1).split('/');
		var ALinkLatLng = [];
		var BLinkLatLng = [];
		var ALinkLatLngArr = [];
		var BLinkLatLngArr = [];
		if(ALinkArr.length > 0)
		{
			for(var ii = 0; ii < ALinkArr.length; ii++)
			{
				ALinkLatLng = ALinkArr[ii].split(',');
				var aLng;
				var aLat;
				
				for(var jj = 0; jj < 2; jj++)
				{
					if(jj == 0) aLng = ALinkLatLng[0];
					if(jj == 1) aLat = ALinkLatLng[1];
				}
				if(aLng != '' || typeof(aLng) != 'undefined' || aLng != null || aLat != '' || typeof(aLat) != 'undefined' || aLat != null)
				{
					ALinkLatLngArr.push(new kakao.maps.LatLng(aLat, aLng));
				}
			}
		}
		
		if(BLinkArr.length > 0)
		{
			for(var ii = 0; ii < BLinkArr.length; ii++)
			{
				BLinkLatLng = BLinkArr[ii].split(',');
				var bLng;
				var bLat;
				
				for(var jj = 0; jj < 2; jj++)
				{
					if(jj == 0) bLng = BLinkLatLng[0];
					if(jj == 1) bLat = BLinkLatLng[1];
				}
				
				if(bLng != '' || typeof(bLng) != 'undefined' || bLng != null || bLat != '' || typeof(bLat) != 'undefined' || bLat != null) 
				{
					BLinkLatLngArr.push(new kakao.maps.LatLng(bLat, bLng));
				}
			}
		}
		
		this.mapRingALink = new kakao.maps.Polyline({
	          path: ALinkLatLngArr,
	          strokeWeight: 2,
	          strokeColor: 'blue',
	          strokeOpacity: 1,
	          strokeStyle: 'solid',
	          endArrow: true,
	          zIndex: 5
	    });
		linkPhaseLineArr.push(this.mapRingALink);
		
		this.mapRingBLink = new kakao.maps.Polyline({
	          path: BLinkLatLngArr,
	          strokeWeight: 2,
	          strokeColor: 'blue',
	          strokeOpacity: 1,
	          strokeStyle: 'solid',
	          endArrow: true,
	          zIndex: 5
	    });
		linkPhaseLineArr.push(this.mapRingBLink);
	}
}

/*
 * 실제 신호 Phase를 그리는 Class
 */
function SignalDraw(ringA, ringB, lat, lng, regionCd, regionId, regionNm, intNo, intNm, intSigCycleCnt, 
		            intSigCycleLen, commOnOffFlag, groupNo, mapNo, mainIntNo, sigunguCd, intLcType, intLampType, 
		            intMainphase, networkType, modemIp) {
	this.initialize(ringA, ringB, lat, lng, regionCd, regionId, regionNm, intNo, intNm, intSigCycleCnt, 
			        intSigCycleLen, commOnOffFlag, groupNo, mapNo, mainIntNo, sigunguCd, intLcType, intLampType, 
			        intMainphase, networkType, modemIp);
};

SignalDraw.prototype = {
    ringA : null,
    ringB : null,
    Lat : 0,
	Lng : 0,
	regionCd : null,
	regionNm : null,
	intNo : null,
	intNm : null,
	intSigCycleCnt : 0,
	intSigCycleLen : 0,
	commOnOffFlag : null,
	groupNo : 0,

	posA : null,
	posB : null,
	
	typeA : 0,
	typeB : 0,
	mapCircle : null,
	mapRingA : null,
	mapRingB : null,
	
	listCoordA : null,
	listCoordB : null,
	showSigPop : null,
	
    initialize : function(ringA, ringB, lat, lng, regionCd, regionId, regionNm, intNo, intNm, 
    		              intSigCycleCnt, intSigCycleLen, commOnOffFlag, groupNo, mapNo, mainIntNo, 
    		              sigunguCd, intLcType, intLampType, intMainphase, networkType, modemIp) {
    	this.ringA = ringA;
    	this.ringB = ringB;
    	this.Lat = lat;
    	this.Lng = lng;
    	this.regionCd = regionCd;
    	this.regionId = regionId;
    	this.regionNm = regionNm;
    	this.intNo = intNo;
    	this.intNm = intNm;
    	this.intSigCycleCnt = intSigCycleCnt;
    	this.intSigCycleLen = intSigCycleLen;
    	this.commOnOffFlag = commOnOffFlag;
    	this.groupNo = groupNo;
    	this.mapNo = mapNo;
    	this.mainIntNo = mainIntNo;
    	this.sigunguCd = sigunguCd;
    	this.intLcType = intLcType;
    	this.intLampType = intLampType;
    	this.intMainphase = intMainphase;
    	this.networkType = networkType;
    	this.modemIp = modemIp;
    	
		this.posA = new SCoord(lat, lng);
    	this.posB = new SCoord(lat, lng);
    	
		this.mapRingA = null;
    	this.mapRingB = null;
    	
    	this.listCoordA = 0;
    	this.listCoordB = 0;
    	this.listCoordA = [];
		this.listCoordB = [];
		
		this.typeA = this.checkRingType(this.ringA);
		this.typeB = this.checkRingType(this.ringB);
		
		if (this.typeA == 0 && this.typeB == 0) {
			//페이즈정보가 없는경우...
			if(_Flag != 'addSignal') return this.createCircle();
		}
		
		var degAI = 0; var degAO = 0; var degBI = 0; var degBO = 0;
		
		// 진입, 진출 Degree 각도를 얻는다.
		if (this.typeA == 1 || this.typeA == 2 || this.typeA == 3) {
			degAI = Number(this.ringA.substring(1,4));
			degAO = Number(this.ringA.substring(4,7));
			
			if(this.typeA == 1 || this.typeA == 2)
			{
				if (degAI >= 360) degAI = degAI - 360;
				if (degAO >= 360) degAO = degAO - 360;
			}
			else if(this.typeA == 3)
			{
				if(degAO != 0)
				{
					return this.drawPedestrians();
				}
				else
				{
					degAI += 90;
					degAO = degAI + 180;
					
					if(degAI > 360) degAI = degAI - 360;
					if(degAO > 360) degAO = degAO - 360;
				}
			}
		}
		
		if (this.typeB == 1 || this.typeB == 2 || this.typeB == 3) {
			degBI = Number(this.ringB.substring(1,4));
			degBO = Number(this.ringB.substring(4,7));
			
			if(this.typeB == 1 || this.typeB == 2)
			{
				if (degBI >= 360) degBI = degBI - 360;
				if (degBO >= 360) degBO = degBO - 360;
			}
			else if(this.typeB == 3)
			{
				if(degBO != 0)
				{
					return this.drawPedestrians();
				}
				else
				{
					degBI += 90;
					degBO = degBI + 180;
					if(degBI > 360) degBI = degBI - 360;
					if(degBO > 360) degBO = degBO - 360;
				}
			}
		}
		
		//console.log("typeA: " + this.typeA + ", typeB: " + this.typeB);
		//console.log("1. AI: " + degAI + ", AO: " + degAO + ", BI: " + degBI + ", BO: " + degBO) ;

		if (((this.typeA == 1 || this.typeA == 2) && this.typeB == 0) || ((this.typeB == 1 || this.typeB == 2) && this.typeA == 0)) {
			// 보행자 신호이면 무조건 직선으로 표출되도록함(통신으로 수신한 각도를 사용하지 않음)
			// 보행자 신호인 경우 사거리 동시신호 보행자 신호인건가?
			if (this.typeA == 3) {
				degAI = 0;
				degAO = 180;
			}
			if (this.typeB == 3) {
				degBI = 0;
				degBO = 180;
			}
			return this.createMap(degAI, degAO, degBI, degBO);
		}

		//console.log("두개의 링 정보가 모두 유효한 경우임");

		var a;
		var gapAngle = 0;
		
		// ARing
		if (this.typeA == 1 || this.typeA == 2) 
		{
			if(this.typeA == 1)
			{
				//직진
				gapAngle = 270;
			}
			else
			{
				//좌회전
				gapAngle = 90;
			}

			a = degAI + gapAngle;
			if (a >= 360) a = a - 360;

			this.moveCenterPos(this.posA, a, false);
		}
		else if (this.typeA == 3) 
		{
			//console.log('deg : ' + degAI);
			var diff = Number(this.ringA.substring(1,4)); //288

			//보행자
			this.moveCenterPos(this.posA, diff, true);
		}
		else if (this.typeA == 4 || this.typeA == 5 || this.typeA == 6 || this.typeA == 7) 
		{
			return this.createErrMap(this.typeA);
		}

		// BRing
		if (this.typeB == 1 || this.typeB == 2)
		{
			if(this.typeB == 1)
			{
				//직진
				gapAngle = 270;
			}
			else 
			{
				//좌회전
				gapAngle = 90;
			}

			a = degBI + gapAngle;
			if (a >= 360) a = a - 360;

			this.moveCenterPos(this.posB, a, false);
		}
		else if (this.typeB == 3) 
		{
			var diff = Number(this.ringB.substring(1,4));
			/*if (diff > 180) {
				diff = diff - 180;
				//gapAngle = 90;
			} else {
				//gapAngle = 270;
			}*/
			
			//a = diff + gapAngle;
			//if (diff >= 360) a = a - 360;
			
			//보행자
			this.moveCenterPos(this.posB, diff, true);
		}
		
		return this.createMap(degAI, degAO, degBI, degBO);
    	
    },
    
	moveCenterPos : function(pos, deg, pedestriansA) {
		this.level = map.getLevel();
		var distance;
		if(this.level == 0) distance = 0.005;
		if(this.level == 1) distance = 0.005;
		if(this.level == 2) distance = 0.005;
		if(this.level == 3) distance = 0.007;
		if(this.level == 4) distance = 0.007;
		if (pedestriansA) {
			/*
			 * 보행자 신호인 경우 중심 좌표에서 진행방향으로 4미터 떨어진 곳을 중심으로 잡고
			 * (진입각-90)도 각으로 점선을 그려준다
			 */
			distance = 0.009;
		}

		var rad = deg.toRadians();
		var deltaLat = distance * Math.cos(rad);
		var deltaLng = distance * Math.sin(rad);
		
		deltaLat = (deltaLat * 360) / 40000;
		deltaLng = (deltaLng * 360) / 40000;
		pos.Lat = pos.Lat + deltaLat;
		pos.Lng = pos.Lng + deltaLng;
	},
    
	checkRingType : function(ring) {
    	if (ring == null)
    		return 0;	//유효하지 않은 유형
    	
    	var type = ring.substring(0,1);
		if (type == "S") return 1;	//직진
		if (type == "L") return 2;  //좌회전
		if (type == "P") return 3;	//보행자
		
		if (ring == "commOff") return 4;         //통신이상
		if (ring == "siglightTurnoff") return 5; //신호등소등여부
		if (ring == "siglightBlink") return 6;   //신호등점멸여부
		if (ring == "contrlrManual") return 7;   //제어기수동여부
		
		return 0;	//알수없음
    },

    draw : function(map) {
		if (this.mapRingA != null) this.mapRingA.setMap(map);
		if (this.mapRingB != null) this.mapRingB.setMap(map);
    },

    createMap : function(degAI, degAO, degBI, degBO) {
    	if(_Flag != 'sigPop')
    	{
    		if(_BackCircleFlag == true)
    		{
    			//this.createCircle();//백그라운드 서클생성
    		}
    	}
    	
		//console.log("*. AI: " + degAI + ", AO: " + degAO + ", BI: " + degBI + ", BO: " + degBO) ;
    	
    	var lineLengthA;            //A라인길이
    	var strokeWeightA;          //A라인두께
		var endArrawA = true;       //A라인화살표유무
		var strokeStyleA = 'solid'; //A라인 라인종류 
		var colorA = '#0000FF';     //A라인 색상
		
		var lineLengthB;            //B라인길이
		var strokeWeightB;          //B라인두께
		var endArrawB = true;       //B라인화살표유무
		var strokeStyleB = 'solid'; //B라인 라인종류
		var colorB = '#0000FF';     //B라인 색상
		
		var level = map.getLevel();
		
		if (this.typeA != 0) {
			if(this.typeA == 3) //보행자
			{
				if(level == 4)
				{
					lineLengthA = 0.02;
					strokeWeightA = 3;
				}
				else if(level == 3)
				{
					lineLengthA = 0.016;
					strokeWeightA = 4;
				}
				else if(level == 2)
				{
					lineLengthA = 0.012;
					strokeWeightA = 6;
				}
				else if(level == 1)
				{
					lineLengthA = 0.008;
					strokeWeightA = 8;
				}
				else if(level == 0)
				{
					lineLengthA = 0.008;
					strokeWeightA = 10;
				}
				endArrawA = false;
				strokeStyleA = 'shortdot';
				colorA = '#000000';
			}
			else
			{
				if(level == 4)
				{
					lineLengthA = 0.011;
					strokeWeightA = 2;
				}
				else if(level == 3)
				{
					lineLengthA = 0.011;
					strokeWeightA = 3;
				}
				else if(level == 2)
				{
					lineLengthA = 0.009;
					strokeWeightA = 5;
				}
				else if(level == 1)
				{
					lineLengthA = 0.009;
					strokeWeightA = 9;
				}
				else if(level == 0)
				{
					lineLengthA = 0.009;
					strokeWeightA = 12;
				}
				endArrawA = true;
				strokeStyleA = 'solid';
				colorA = '#0000FF';
			}
			
			this.listCoordA.push(new SCoord(lineLengthA * Math.cos(degAI.toRadians()), lineLengthA * Math.sin(degAI.toRadians())));
			this.listCoordA.push(new SCoord(this.posA.Lat, this.posA.Lng));
			this.listCoordA.push(new SCoord(lineLengthA * Math.cos(degAO.toRadians()), lineLengthA * Math.sin(degAO.toRadians())));
			_ALineCenterArr.push(new SCoord(this.posA.Lat, this.posA.Lng));
		}
		
		if (this.typeB != 0) {
			if(this.typeB == 3) //보행자
			{
				if(level == 4)
				{
					lineLengthB = 0.02;
					strokeWeightB = 3;
				}
				else if(level == 3)
				{
					lineLengthB = 0.016;
					strokeWeightB = 4;
				}
				else if(level == 2)
				{
					lineLengthB = 0.012;
					strokeWeightB = 6;
				}
				else if(level == 1)
				{
					lineLengthB = 0.008;
					strokeWeightB = 8;
				}
				else if(level == 0)
				{
					lineLengthB = 0.008;
					strokeWeightB = 10;
				}
				endArrawB = false;
				strokeStyleB = 'shortdot';
				colorB = '#000000';
			}
			else
			{
				if(level == 4)
				{
					lineLengthB = 0.011;
					strokeWeightB = 2;
				}
				else if(level == 3)
				{
					lineLengthB = 0.011;
					strokeWeightB = 3;
				}
				else if(level == 2)
				{
					lineLengthB = 0.009;
					strokeWeightB = 5;
				}
				else if(level == 1)
				{
					lineLengthB = 0.009;
					strokeWeightB = 9;
				}
				else if(level == 0)
				{
					lineLengthB = 0.009;
					strokeWeightB = 12;
				}
				endArrawB = true;
				strokeStyleB = 'solid';
				colorB = '#0000FF';
			}
			
			this.listCoordB.push(new SCoord(lineLengthB * Math.cos(degBI.toRadians()), (lineLengthB) * Math.sin(degBI.toRadians())));
			this.listCoordB.push(new SCoord(this.posB.Lat, this.posB.Lng));
			this.listCoordB.push(new SCoord(lineLengthB * Math.cos(degBO.toRadians()), (lineLengthB) * Math.sin(degBO.toRadians())));
			_BLineCenterArr.push(new SCoord(this.posB.Lat, this.posB.Lng));
		}
		
		for(var ii = 0; ii < 3; ii++) {
			if (ii == 1) continue;	//중심좌표는 보정이 필요없음.
			
	    	if (this.typeA != 0) {
		    	this.listCoordA[ii].Lat = (this.listCoordA[ii].Lat * 360) / 40000;	//delta lat
		    	this.listCoordA[ii].Lng = (this.listCoordA[ii].Lng * 360) / 40000;	//delta lng
		    	this.listCoordA[ii].Lat = this.posA.Lat + this.listCoordA[ii].Lat;
		    	this.listCoordA[ii].Lng = this.posA.Lng + this.listCoordA[ii].Lng;
	    	}
	    	if (this.typeB != 0) {
		    	this.listCoordB[ii].Lat = (this.listCoordB[ii].Lat * 360) / 40000;	//delta lat
		    	this.listCoordB[ii].Lng = (this.listCoordB[ii].Lng * 360) / 40000;	//delta lng
		    	this.listCoordB[ii].Lat = this.posB.Lat + this.listCoordB[ii].Lat;
		    	this.listCoordB[ii].Lng = this.posB.Lng + this.listCoordB[ii].Lng;
	    	}
		}
		
		if (this.typeA != 0) {
			this.mapRingA = new kakao.maps.Polyline({
		          path: [
		              new kakao.maps.LatLng(this.listCoordA[0].Lat, this.listCoordA[0].Lng),
		              new kakao.maps.LatLng(this.listCoordA[1].Lat, this.listCoordA[1].Lng),
		              new kakao.maps.LatLng(this.listCoordA[2].Lat, this.listCoordA[2].Lng)
		          ],
		          strokeWeight: strokeWeightA,
		          strokeColor: colorA,
		          strokeOpacity: 1,
		          strokeStyle: strokeStyleA,
		          endArrow: endArrawA,
		          zIndex: 10
		    });
			
			this.mapRingA.setMap(map);
			signalALineArr.push(this.mapRingA);
    	}
    	
    	if (this.typeB != 0) {
			this.mapRingB = new kakao.maps.Polyline({
	          path: [
	              new kakao.maps.LatLng(this.listCoordB[0].Lat, this.listCoordB[0].Lng),
	              new kakao.maps.LatLng(this.listCoordB[1].Lat, this.listCoordB[1].Lng),
	              new kakao.maps.LatLng(this.listCoordB[2].Lat, this.listCoordB[2].Lng)
	          ],
	          strokeWeight: strokeWeightB,
	          strokeColor: colorB,
	          strokeOpacity: 1,
	          strokeStyle: strokeStyleB,
	          endArrow: endArrawB,
	          zIndex: 10
			});
			
			this.mapRingB.setMap(map);
			signalBLineArr.push(this.mapRingB);
		}
    	
    },
    
    createErrMap : function(type) {
    	
    	var lat = this.Lat;
    	var lng = this.Lng;
    	var regionCd = this.regionCd;
    	var regionId = this.regionId;
    	var regionNm = this.regionNm;
    	var intNo = this.intNo;
    	var intNm = this.intNm;
    	var intSigCycleCnt = this.intSigCycleCnt;
    	var intSigCycleLen = this.intSigCycleLen;
    	var commOnOffFlag = this.commOnOffFlag;
    	var groupNo = this.groupNo;
    	var mapNo = this.mapNo;
		var circleTemp = null;
		var mainIntNo = this.mainIntNo; 
		var sigunguCd = this.sigunguCd; 
		var intLcType = this.intLcType; 
		var intLampType = this.intLampType;
		var intMainphase = this.intMainphase;
		var networkType = this.networkType;
		var modemIp = this.modemIp;
		
    	if(type == 6) circleTemp = this.siglightBlinkImg();
    	else 
    	{
    		var fillColor = '#FF0000';
    		var strokeColor = '#FF0000';
    		
    		if(type == 5) 
        	{
        		fillColor = '#000000';
        		strokeColor = '#000000';
        	} 
        	else if(type == 7)
        	{
        		fillColor = '#00ffff';
        		strokeColor = '#00ffff';
        	} 
        	
        	this.mapRingA = new kakao.maps.Circle({
    		    center : new kakao.maps.LatLng(lat, lng),
    		    radius: _CircleSize[_Level],
    		    strokeWeight: _CircleStroke[_Level],
    		    strokeColor: strokeColor,
    		    strokeOpacity: 1,
    		    strokeStyle: 'solid',
    		    fillColor: fillColor,
    		    fillOpacity: 1,
    		    zIndex: 20,
    		    map:map
    		});

        	circleTemp = this.mapRingA;
    	}
    	
		if(_Flag != 'sigPop')
		{
			this.showSigPop(circleTemp,lat,lng,regionCd,regionId,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
		}
		
		signalALineArr.push(circleTemp);
    },
    
    drawPedestrians : function() {
    	
    	var lat = this.Lat;
    	var lng = this.Lng;
    	var regionCd = this.regionCd;
    	var regionNm = this.regionNm;
    	var intNo = this.intNo;
    	var intNm = this.intNm;
    	var intSigCycleCnt = this.intSigCycleCnt;
    	var intSigCycleLen = this.intSigCycleLen;
    	var commOnOffFlag = this.commOnOffFlag;
    	var groupNo = this.groupNo;
    	var mapNo = this.mapNo;
    	var mainIntNo = this.mainIntNo; 
		var sigunguCd = this.sigunguCd; 
		var intLcType = this.intLcType; 
		var intLampType = this.intLampType;
		var intMainphase = this.intMainphase;
		var networkType = this.networkType;
		var modemIp = this.modemIp;
    	var position = new kakao.maps.LatLng(lat, lng);
    	var src = _pedeImgSrc;
    	var size = new kakao.maps.Size(_imgW,_imgH),
    	           options = {
    					offset : new kakao.maps.Point(_imgOffSetW,_imgOffsetH)
    				};
    	
    	var markerImage = new kakao.maps.MarkerImage(src, size, options);
    	this.mapRingA = new kakao.maps.Marker({
    		position : position,
    		image : markerImage,
    		zIndex : 1,
    		map:map
    	});
    	
    	var circleTemp = this.mapRingA;
    	
    	if(_Flag != 'sigPop')
		{
			this.showSigPop(circleTemp,lat,lng,regionCd,regionId,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
		}
		
    	signalALineArr.push(circleTemp);
    	
    },
    
    createCircle : function() {
    	var lat = this.Lat;
    	var lng = this.Lng;
    	var regionCd = this.regionCd;
    	var regionId = this.regionId;
    	var regionNm = this.regionNm;
    	var intNo = this.intNo;
    	var intNm = this.intNm;
    	var intSigCycleCnt = this.intSigCycleCnt;
    	var intSigCycleLen = this.intSigCycleLen;
    	var commOnOffFlag = this.commOnOffFlag;
    	var groupNo = this.groupNo;
    	var mapNo = this.mapNo;
    	var mainIntNo = this.mainIntNo; 
		var sigunguCd = this.sigunguCd; 
		var intLcType = this.intLcType; 
		var intLampType = this.intLampType;
		var intMainphase = this.intMainphase;
		var networkType = this.networkType;
		var modemIp = this.modemIp;
		
    	this.mapCircle = new kakao.maps.Circle({
		    center : new kakao.maps.LatLng(this.Lat, this.Lng),
		    radius: _CircleSize[map.getLevel()],
		    strokeWeight: _CircleStroke[map.getLevel()],
		    strokeColor: '#fff',
		    strokeOpacity: 0,
		    strokeStyle: 'solid',
		    fillColor: '#fff',
		    fillOpacity: 0.1,
		    zIndex: 20,
		    map:map
		});
    	
		var circleTemp = this.mapCircle;
		
		if(_Flag != 'sigPop')
		{
			this.showSigPop(circleTemp,lat,lng,regionCd,regionId,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
		}
		
		signalBackCircleArr.push(circleTemp);
    },
    
    showSigPop : function(obj,lat,lng,regionCd,regionId,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp) {
    	
    	kakao.maps.event.addListener(obj, 'mouseover', function() {
			if(_Flag == 'addSignal')
			{
				addSigPop(intNm,lng,lat);
			}
			else
			{
				if(_ToggleSiginfo)
					getSigPop(lat,lng,regionCd,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen);
				else {
					if (window.opener) {
						window.opener.customOverlayFnc(intNm,lng,lat);
					}
					else {
						customOverlayFnc(intNm,lng,lat);
					}
				}
			}
		});
		
		kakao.maps.event.addListener(obj, 'mouseout', function() {
			if(_Flag == 'addSignal')
			{
				if(customOverlay != null)
				{
					customOverlay.setMap(null);
					customOverlay = null;
				}
			}
			else
			{
				if(sigInfowindow != null) sigInfowindow.close();
				if(customOverlay != null) customOverlay.setMap(null);
			}
		});
		
		kakao.maps.event.addListener(obj, 'click', function() {
			if(_Flag == 'addSignal')
			{
				if(customOverlay != null)
				{
					customOverlay.setMap(null);
					customOverlay = null;
				}
				addSignalFnc(regionCd,regionNm,intNo,intNm,lng,lat,groupNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
			}
			else
			{
				var url = 'sigInfoPhaseDetail.do?regionCd='+regionCd+'&groupNo='+groupNo+'&intNo='+intNo+'&intNm='+intNm+'&yCoord='+lat+'&xCoord='+lng+'&regionNm='+encodeURI(regionNm)+'&intNm='+encodeURI(intNm);
				var options = 'scrollbars=no,toolbar=no,location=no,resizable=no,status=no,menubar=no,width=920px,height=845px,left=0,top=0';
				siginfoPhaseDetailWin = window.open(url,'childForm',options);
				$('#regionId').val(regionId);
				$('#intNo').val(intNo);
			}
		});
    },
    
    siglightBlinkImg : function() {
    	var lat = this.Lat;
    	var lng = this.Lng;
    	var icon = new kakao.maps.MarkerImage(
    			_lightBlinkImgSrc,
			    new kakao.maps.Size(_imgW,_imgH),
			    {
			        offset: new kakao.maps.Point(_imgOffSetW,_imgOffsetH),
			        alt: "점멸"
			    }
			);
		
		this.mapCircle = new kakao.maps.Marker({
					    position: new kakao.maps.LatLng(lat, lng),
					    image: icon,
					    zIndex: 10,
					    map:map
					});
		
		var circleTemp = this.mapCircle;
		
		return circleTemp;
    }
    
};

function addSignalFnc(regionCd,regionNm,intNo,intNm,lng,lat,groupNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp) {
	$('#centerList option[value="'+regionCd+'"]').prop('selected',true);
	getIntNo(regionCd,false);
	//시군구리스트 입력..
	getSigungu(regionCd);
	
	var val = regionCd+'|'+regionNm+'|'+intNo+'|'+intNm+'|'+lng+'|'+lat+'|'+
	          groupNo+'|'+mainIntNo+'|'+sigunguCd+'|'+intLcType+'|'+intLampType+'|'+
	          intMainphase+'|'+networkType+'|'+modemIp;
	selectInt(val);
}

/*
 * 신호제어기 정보
 */
function Signal(yCoord, xCoord, strokeColor, fillColor, regionCd, regionId, regionNm, intNo, intNm, groupNo, mapNo, mainIntNo, sigunguCd,
		intLcType, intLampType, intMainphase, commOnOffFlag, intSigCycleCnt, intSigCycleLen ,networkType, modemIp)
{
	this.initialize(yCoord, xCoord, strokeColor, fillColor, regionCd, regionId, regionNm, intNo, intNm, groupNo, mapNo, mainIntNo, sigunguCd,
			intLcType, intLampType, intMainphase, commOnOffFlag, intSigCycleCnt, intSigCycleLen ,networkType, modemIp);
};

Signal.prototype = {
	Lat  : 0,
	Lng  : 0,

	drawSignal     : null,	/* 현재 표출될 SignalDraw class */
	listDrawSignal : null, 	/* 표출현시 목록을 저장할 list array: 최초 한번만 좌표를 계산하도록 하기 위함, 성능에 따라 map 사용 가능 */
	
	mapCircle : null,

	initialize : function(Lat, Lng, strokeColor, fillColor, regionCd, regionId, regionNm, intNo, intNm, groupNo, mapNo, mainIntNo, sigunguCd,
			intLcType, intLampType, intMainphase, commOnOffFlag, intSigCycleCnt, intSigCycleLen, networkType, modemIp) {
		this.regionCd = regionCd;
		this.regionId = regionId;
		this.regionNm = regionNm;
		this.intNo    = intNo;
		this.intNm    = intNm;
		this.groupNo  = groupNo;
		this.Lat      = Lat;
		this.Lng      = Lng;
		this.listDrawSignal = [];
		this.signalIdx = 0;
		this.aRingDeg  = '';
		this.bRingDeg  = '';
		this.ring_a    = 0;
		this.ring_b    = 0;
		this.networkType = networkType;
		this.modemIp = modemIp;
		
		if(_Level < 5)
		{
			if (fillColor === '#ffffff') {
				fillColor = strokeColor;
			}
			
			this.mapCircle = new kakao.maps.Circle({
			    center : new kakao.maps.LatLng(this.Lat, this.Lng),
			    radius: _CircleSize[map.getLevel()],
			    strokeWeight: _CircleStroke[map.getLevel()],
			    strokeColor: strokeColor,
			    strokeOpacity: 1,
			    strokeStyle: 'solid',
			    fillColor: fillColor,
			    fillOpacity: 0.2,
			    zIndex: 10
			});
		}
		else if(_Level == 5 || _Level == 6)
		{
	    	var icon = new kakao.maps.MarkerImage (
	    			'images/TrafficLight25.png',
				    new kakao.maps.Size(25, 25),
				    {
	    				offset: new kakao.maps.Point(13, 15),
	    				alt: "신호현시"
				    }
	    	);
	    	
	    	this.mapCircle = new kakao.maps.Marker({
			    position: new kakao.maps.LatLng(Lat, Lng),
			    image: icon,
			    zIndex: 10
			});
		}

		this.mapCircle.setMap(map);
		
		kakao.maps.event.addListener(this.mapCircle, 'mouseover', function() {
			
			if(_Flag == 'addSignal')
			{
				addSigPop(intNm,Lng,Lat);
			}
			else
			{
				if(_ToggleSiginfo)
					getSigPop(Lat,Lng,regionCd,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen);
				else {
					if (window.opener) {
						window.opener.customOverlayFnc(intNm,Lng,Lat);
					}
					else {
						
						customOverlayFnc(intNm,Lng,Lat);
					}
				}
			}
		});
		
		kakao.maps.event.addListener(this.mapCircle, 'mouseout', function() {
			if(_Flag == 'addSignal')
			{
				if(customOverlay != null)
				{
					customOverlay.setMap(null);
					customOverlay = null;
				}
			}
			else
			{
				if(sigInfowindow != null) sigInfowindow.close();
				if(customOverlay != null) customOverlay.setMap(null);
			}
		});
		
		kakao.maps.event.addListener(this.mapCircle, 'click', function() {
			if(_Flag == 'addSignal')
			{
				if(customOverlay != null)
				{
					customOverlay.setMap(null);
					customOverlay = null;
				}
				
				addSignalFnc(regionCd,regionNm,intNo,intNm,Lng,Lat,groupNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp);
			}
			else
			{
				var url = 'sigInfoPhaseDetail.do?regionCd='+regionCd+'&groupNo='+groupNo+'&intNo='+intNo+'&intNm='+intNm+'&yCoord='+Lat+'&xCoord='+Lng+'&regionNm='+encodeURI(regionNm)+'&intNm='+encodeURI(intNm);
				var options = 'scrollbars=no,toolbar=no,location=no,resizable=no,status=no,menubar=no,width=920px,height=845px,left=0,top=0';
				siginfoPhaseDetailWin = window.open(url,'childForm',options);
				
			}
		});
		
	},

	/*
	 * 신호제어기 정보를 돌려줌
	 */
	getInfo : function() {
    	return this.Id + ', ' + this.Lat + '. ' + this.Lng + ", " + this.listDrawSignal.length + ", " + this.drawSignal;
	},

	/*
	 * 신호제어기 내의 Phase 가 존재하는 지를 검사
	 */
	find : function(ringA, ringB) {
		for(var ii = 0; ii < this.listDrawSignal.length; ii++) {
			if (this.listDrawSignal[ii].ringA == ringA && 
				this.listDrawSignal[ii].ringB == ringB) {
				return this.listDrawSignal[ii];
			}
		}
		return null;
	},

	setPhase : function(ARing, BRing, regionCd, regionId, regionNm, intNo, intNm, intSigCycleCnt, intSigCycleLen, 
			            commOnOffFlag, groupNo, mapNo, mainIntNo, sigunguCd, intLcType, intLampType, intMainphase, networkType, modemIp) {
		//신호라인 삭제
		if(this.drawSignal != null) this.empty(map);
		
		this.drawSignal = new SignalDraw(ARing, BRing, this.Lat, this.Lng, regionCd, regionId, regionNm, intNo, intNm, 
				                         intSigCycleCnt, intSigCycleLen, commOnOffFlag, groupNo, mapNo, mainIntNo, sigunguCd, 
				                         intLcType, intLampType, intMainphase, networkType, modemIp);
	},
	
	setLinkPhase : function(ALink, BLink) {
		
		if(this.listDrawSignalLink =! null)
		{
			if(this.listDrawSignalLink.length > 0)
			{
				if(this.listDrawSignalLink[0].mapRingALink != null) this.listDrawSignalLink[0].mapRingALink.setMap(null);
				if(this.listDrawSignalLink[0].mapRingBLink != null) this.listDrawSignalLink[0].mapRingBLink.setMap(null);
			}
		}
		
		this.drawSignalLink = new SignalLinkDraw(ALink, BLink);
		this.listDrawSignalLink = [];
		this.listDrawSignalLink.push(this.drawSignalLink);
	},
	
	draw : function(map) {
		if (this.mapCircle  != null) this.mapCircle.setMap(map);
		if (this.drawSignal != null) this.drawSignal.draw(map);
	},

	empty : function(map) {
		if(this.drawSignal.mapRingA != null) this.drawSignal.mapRingA.setMap(null);
		if(this.drawSignal.mapRingB != null) this.drawSignal.mapRingB.setMap(null);
		if(this.drawSignal.mapCircle != null) this.drawSignal.mapCircle.setMap(null);
	}
};


function getSigPop(lat,lng,regionCd,regionNm,intNo,intNm,groupNo,mapNo,commOnOffFlag,intSigCycleCnt,intSigCycleLen) {
	_RegionCd = regionCd;
	_IntNo = intNo;
	
	var str = "";
	str += "<div class='sigPop_box'>";
	str += "<table cellspacing='0' cellpadding='0' border='0' summary='신호 위치정보' class='pop_table'>";
	str += "<caption>신호 위치정보</caption>";
	str += "<colgroup>";
	str += "<col style='width:25%'>";
	str += "<col style='width:25%'>";
	str += "<col style='width:24%'>";
	str += "<col style='width:26%'>";
	str += "</colgroup>";
	str += "<thead>";
	str += "<tr>";
	str += "<th colspan='4'><img src='images/icon01.gif' alt='타이틀 블릿'/><strong>["+regionNm+"] "+intNm+"("+intNo+")</strong></th>";
	str += "</tr>";
	str += "</thead>";
	str += "<tbody>";
	str += "<tr>";
	str += "<td><span>그룹번호&nbsp;&nbsp; :</span></td>";
	str += "<td>"+groupNo+"</td>";
	str += "<td><span>통신여부&nbsp;&nbsp; :</span></td>";
	str += "<td>"+commOnOffFlagFnc(commOnOffFlag)+"</td>";
	str += "</tr>";
	str += "<tr>";
	str += "<td><span>주기카운트 :</span></td>"; 
	str += "<td>"+intSigCycleCnt+" 초</td>";
	str += "<td><span style='margin-left:0px'>주&nbsp;&nbsp;기&nbsp;&nbsp;&nbsp;&nbsp; :</span></td>";
	str += "<td>"+ intSigCycleLen +" 초</td>";
	str += "</tr>";
	str += "</tbody>";
	str += "<tfoot>";
	str += "</tfoot>";
	str += "</table>";
	str += '<table class="pop_table_phase">';
	str += '<tr>							';
	str += '	<td>현시</td>				';
	str += '	<td class="pa_1">1</td>		';
	str += '	<td class="pa_2">2</td>		';
	str += '	<td class="pa_3">3</td>		';
	str += '	<td class="pa_4">4</td>		';
	str += '	<td class="pa_5">5</td>		';
	str += '	<td class="pa_6">6</td>		';
	str += '</tr>							';
	str += '<tr>';
	str += '	<td>A링</td>';
	str += '	<td id="pAMap0"></td>';
	str += '	<td id="pAMap1"></td>';
	str += '	<td id="pAMap2"></td>';
	str += '	<td id="pAMap3"></td>';
	str += '	<td id="pAMap4"></td>';
	str += '	<td id="pAMap5"></td>';
	str += '</tr>';
	str += '<tr class="aProgress">';
	str += '	<td>주기</td>';
	str += '	<td id="aRing1Phase"></td>';
	str += '	<td id="aRing2Phase"></td>';
	str += '	<td id="aRing3Phase"></td>';
	str += '	<td id="aRing4Phase"></td>';
	str += '	<td id="aRing5Phase"></td>';
	str += '	<td id="aRing6Phase"></td>';
	str += '</tr>';
	str += '<tr>';
	str += '	<td>B링</td>';
	str += '	<td id="pBMap0"></td>';
	str += '	<td id="pBMap1"></td>';
	str += '	<td id="pBMap2"></td>';
	str += '	<td id="pBMap3"></td>';
	str += '	<td id="pBMap4"></td>';
	str += '	<td id="pBMap5"></td>';
	str += '</tr>';
	str += '<tr class="bProgress">';
	str += '	<td>주기</td>';
	str += '	<td id="bRing1Phase"></td>';
	str += '	<td id="bRing2Phase"></td>';
	str += '	<td id="bRing3Phase"></td>';
	str += '	<td id="bRing4Phase"></td>';
	str += '	<td id="bRing5Phase"></td>';
	str += '	<td id="bRing6Phase"></td>';
	str += '</tr>';
	str += '</table>';
	str += "<div class='arrow_sig'><img alt='' src='images/arrow_tooltip.png'></div>";
	str += "</div>";
	
	var tempMap = map;
	var level = tempMap.getLevel();
	var latOfLv = 0.0003;
	
	if(level == 1 || level == 2) latOfLv = 0.0002;
	if(level == 4) latOfLv = 0.00035;
	if(level == 5) latOfLv = 0.0006;
	if(level == 6) latOfLv = 0.0013;
	
	var lat2 = (Number(lat) + latOfLv);
	var position = new kakao.maps.LatLng(lat2,lng);
	
	sigInfowindow = new kakao.maps.InfoWindow({
	  	   position : position, 
	       content	: str,
	       removable: false,
	       yAnchor: 0.1,
	       zIndex	: 100
    });

	sigInfowindow.open(tempMap);

	//페이즈정보 
	getSigInfoPopDetail(regionCd,intNo,mapNo);
}

function getSigInfoPopDetail(regionCd,intNo,mapNo) {
	url = 'getSigInfoPhaseDetail.do';
	param = 'regionCd='+regionCd+'&intNo='+intNo+'&mapNo='+mapNo;
	requestService(url, param, sigPhasePopListCallback);
}

function sigPhasePopListCallback(data) {
	var regionCd = data[0].REGION_CD;
	var intNo = data[0].INT_NO;
	var phaseVal = Number(data[0].A_RING_PHASE_VAL) + 1;
	$('.pa_'+phaseVal).css('background-color','yellow');
	
	var aRing1Phase = data[0].A_RING_1_PHASE_CONF_CD;
	var aRing2Phase = data[0].A_RING_2_PHASE_CONF_CD;
	var aRing3Phase = data[0].A_RING_3_PHASE_CONF_CD;
	var aRing4Phase = data[0].A_RING_4_PHASE_CONF_CD;
	var aRing5Phase = data[0].A_RING_5_PHASE_CONF_CD;
	var aRing6Phase = data[0].A_RING_6_PHASE_CONF_CD;
	var bRing1Phase = data[0].B_RING_1_PHASE_CONF_CD;
	var bRing2Phase = data[0].B_RING_2_PHASE_CONF_CD;
	var bRing3Phase = data[0].B_RING_3_PHASE_CONF_CD;
	var bRing4Phase = data[0].B_RING_4_PHASE_CONF_CD;
	var bRing5Phase = data[0].B_RING_5_PHASE_CONF_CD;
	var bRing6Phase = data[0].B_RING_6_PHASE_CONF_CD;

	$('#aRing1Phase').text((typeof data[0].A_RING_1_PHASE_VAL == 'undefined' || data[0].A_RING_1_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_1_PHASE_VAL);
	$('#aRing2Phase').text((typeof data[0].A_RING_2_PHASE_VAL == 'undefined' || data[0].A_RING_2_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_2_PHASE_VAL);
	$('#aRing3Phase').text((typeof data[0].A_RING_3_PHASE_VAL == 'undefined' || data[0].A_RING_3_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_3_PHASE_VAL);
	$('#aRing4Phase').text((typeof data[0].A_RING_4_PHASE_VAL == 'undefined' || data[0].A_RING_4_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_4_PHASE_VAL);
	$('#aRing5Phase').text((typeof data[0].A_RING_5_PHASE_VAL == 'undefined' || data[0].A_RING_5_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_5_PHASE_VAL);
	$('#aRing6Phase').text((typeof data[0].A_RING_6_PHASE_VAL == 'undefined' || data[0].A_RING_6_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_6_PHASE_VAL);

	$('#bRing1Phase').text((typeof data[0].B_RING_1_PHASE_VAL == 'undefined' || data[0].B_RING_1_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_1_PHASE_VAL);
	$('#bRing2Phase').text((typeof data[0].B_RING_2_PHASE_VAL == 'undefined' || data[0].B_RING_2_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_2_PHASE_VAL);
	$('#bRing3Phase').text((typeof data[0].B_RING_3_PHASE_VAL == 'undefined' || data[0].B_RING_3_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_3_PHASE_VAL);
	$('#bRing4Phase').text((typeof data[0].B_RING_4_PHASE_VAL == 'undefined' || data[0].B_RING_4_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_4_PHASE_VAL);
	$('#bRing5Phase').text((typeof data[0].B_RING_5_PHASE_VAL == 'undefined' || data[0].B_RING_5_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_5_PHASE_VAL);
	$('#bRing6Phase').text((typeof data[0].B_RING_6_PHASE_VAL == 'undefined' || data[0].B_RING_6_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_6_PHASE_VAL);
	
	aRingPhaseData = new ringPhaseData(aRing1Phase,aRing2Phase,aRing3Phase,aRing4Phase,aRing5Phase,aRing6Phase);
	bRingPhaseData = new ringPhaseData(bRing1Phase,bRing2Phase,bRing3Phase,bRing4Phase,bRing5Phase,bRing6Phase);
	
	var aRingPhaseCnt = 0;
	if(aRing1Phase) aRingPhaseCnt = 1;
	if(aRing2Phase) aRingPhaseCnt = 2;
	if(aRing3Phase) aRingPhaseCnt = 3;
	if(aRing4Phase) aRingPhaseCnt = 4;
	if(aRing5Phase) aRingPhaseCnt = 5;
	if(aRing6Phase) aRingPhaseCnt = 6;
	
	for(var ii = 0; ii < aRingPhaseCnt; ii++)
	{
		listCoord = [];
		makePMap('pAMap'+ii);
		if(ii == 0) if(aRingPhaseData.ring0 != null) drawPhaseLine(aRingPhaseData.ring0,50);
		if(ii == 1) if(aRingPhaseData.ring1 != null) drawPhaseLine(aRingPhaseData.ring1,50);
		if(ii == 2) if(aRingPhaseData.ring2 != null) drawPhaseLine(aRingPhaseData.ring2,50);
		if(ii == 3) if(aRingPhaseData.ring3 != null) drawPhaseLine(aRingPhaseData.ring3,50);
		if(ii == 4) if(aRingPhaseData.ring4 != null) drawPhaseLine(aRingPhaseData.ring4,50);
		if(ii == 5) if(aRingPhaseData.ring5 != null) drawPhaseLine(aRingPhaseData.ring5,50);
	}
	
    var bRingPhaseCnt = 0;
	if(bRing1Phase) bRingPhaseCnt = 1;
	if(bRing2Phase) bRingPhaseCnt = 2;
	if(bRing3Phase) bRingPhaseCnt = 3;
	if(bRing4Phase) bRingPhaseCnt = 4;
	if(bRing5Phase) bRingPhaseCnt = 5;
	if(bRing6Phase) bRingPhaseCnt = 6;
	
	for(var jj = 0; jj < bRingPhaseCnt; jj++)
	{
		listCoord = [];
		makePMap('pBMap'+jj);
		if(jj == 0) if(bRingPhaseData.ring0 != null) drawPhaseLine(bRingPhaseData.ring0,50);
		if(jj == 1) if(bRingPhaseData.ring1 != null) drawPhaseLine(bRingPhaseData.ring1,50);
		if(jj == 2) if(bRingPhaseData.ring2 != null) drawPhaseLine(bRingPhaseData.ring2,50);
		if(jj == 3) if(bRingPhaseData.ring3 != null) drawPhaseLine(bRingPhaseData.ring3,50);
		if(jj == 4) if(bRingPhaseData.ring4 != null) drawPhaseLine(bRingPhaseData.ring4,50);
		if(jj == 5) if(bRingPhaseData.ring5 != null) drawPhaseLine(bRingPhaseData.ring5,50);
	}
	
	//kakao로고 삭제
	for(var mm = 0; mm < 6; mm++)
	{
		$('#pAMap'+mm+' div:nth-child(2)').css('z-index',0);
		$('#pBMap'+mm+' div:nth-child(2)').css('z-index',0);
	}
}

function addSigPop(intNm,lng,lat) {
	var level = map.getLevel();
	var content = '<div class ="sigCustom'+level+'"><span class="left"></span><span class="center">'+intNm+'</span><span class="right"></span></div>';
	// 커스텀 오버레이가 표시될 위치입니다 
	var position = new kakao.maps.LatLng(lat, lng);
	// 커스텀 오버레이를 생성합니다
	customOverlay = new kakao.maps.CustomOverlay({
	    position: position,
	    content: content,
	    zIndex: 30
	});
	// 커스텀 오버레이를 지도에 표시합니다
	customOverlay.setMap(map);
	$('.sigCustom'+level+'').parent().css('width','0px');
}

function makePMap(mapNum) {
	_YCoord = $('#YCoord').val();
	_XCoord = $('#XCoord').val();

	var pLat = parseFloat(_YCoord);
	var pLng = parseFloat(_XCoord);

	var pMapContainer = document.getElementById(mapNum) // 지도를 표시할 div 
	var mapOption = {
		center: new kakao.maps.LatLng(pLat, pLng),
		level: 1
	};

	pMap = new kakao.maps.Map(pMapContainer, mapOption); // 지도생성

	var mapBack = new kakao.maps.Circle({
		center : new kakao.maps.LatLng(pLat, pLng),
	    radius: 30,
	    strokeStyle: 'solid',
	    fillColor: '#fff',
	    fillOpacity: 1,
	    zIndex: 5
	});

	mapBack.setMap(pMap);
}

function commOnOffFlagFnc(val) {
	var str = '정상';
	if(val == 1) str = '이상';
	return str;
}

function onOffFlagFnc(val) {
	var str = 'OFF';
	if(val == 1) str = 'ON';
	return str;
}

function contrlrOperModeCdFnc(val) {
	var str = 'SCU모드';
	if(val == 1) str = '비감응 OFFLINE';
	else if(val == 2) str = '감응OFFLINE';
	else if(val == 4) str = '감응ONLINE';
	else if(val == 5) str = '비감응ONLINE';
	return str;
}

function tmdiffFlagFnc(val) {
	var str = '일반';
	if(val == 1) str = '시차제';
	return str;
}

function ppcFlagFnc(val) {
	var str = 'OFF';
	if(val == 1) str = 'ON';
	return str;
}


function getLinkVtx(sigunguCd) {
	$('.showLoading').show();
	var url = 'getLinkVtx.do';
	var param = 'sigunguCd='+sigunguCd;
	requestService(url, param, getLinkVtxCallback);
}

function getLinkVtxCallback(data) {
	emptySignalArr(linkLineArr);
	emptySignalArr(linkPhaseLineArr);
	emptySignalArr(_SubLinkLineArr);
	linkLineArr = [];
	linkPhaseLineArr = [];
	_SubLinkLineArr = [];
	
	var linkVtxMetaData = data;
	var linkVtxArr = [];
	for(var ii = 0; ii < linkVtxMetaData.length; ii++)
	{
		linkVtxArr.push(new _LinkVtxArrObj(linkVtxMetaData[ii].LINKID,linkVtxMetaData[ii].VERTEXCNT,linkVtxMetaData[ii].VERTEX));
	}
	linkVtxArrData = linkVtxArr
	drawLinkVtx();
	$('.showLoading').hide();
}

function drawLinkVtx() {

	var minX = map.getBounds().getSouthWest().getLng() - 0.01;
	var minY = map.getBounds().getSouthWest().getLat() - 0.01;
	var maxX = map.getBounds().getNorthEast().getLng() + 0.01;
	var maxY = map.getBounds().getNorthEast().getLat() + 0.01;

    var linkVtxArrTemp = linkVtxArrData;
	for(var ii = 0; ii < linkVtxArrTemp.length; ii++)
	{
		linkVtxLineArr = [];
		var vtxArr = linkVtxArrTemp[ii].VERTEX.split('/');
		vtxArr.splice(0,1);
		var coordIO = false;
		var xCoordArr = [];
		var yCoordArr = [];

		for(var jj = 0; jj < vtxArr.length; jj++)
		{
			var coords = vtxArr[jj].split(',');
			var xCoord = coords[0];
			var yCoord = coords[1];

			//console.log('xCoord : '+xCoord+' , yCoord : '+yCoord);

			if((minX <= xCoord && minY <= yCoord && maxX >= xCoord && maxY >= yCoord))
			{
				coordIO = true;
				xCoordArr.push(xCoord);
				yCoordArr.push(yCoord);
			}
		}

		if(coordIO == true)
		{
			for(kk = 0; kk < xCoordArr.length; kk++)
			{
				linkVtxLineArr.push(new kakao.maps.LatLng(yCoordArr[kk], xCoordArr[kk]));
			}
			
			var linkVtxLine = new kakao.maps.Polyline({
		        path: linkVtxLineArr,
		        strokeWeight: 3,
		        strokeColor: '#000000',
		        strokeOpacity: 0.3,
		        strokeStyle: 'solid',
		        endArrow: true,
		        zIndex: 100
			});
			linkVtxLine.setMap(map);
			linkLineArr.push(linkVtxLine);
			linkVtxLineEvent(linkVtxLine,linkVtxArrTemp[ii]);
		}
	}
}

function linkVtxLineEvent(linkVtxLine,lva) {
	kakao.maps.event.addListener(linkVtxLine, 'mouseover', function() {
		linkVtxLine.setOptions({
			strokeColor:'red',
			setOpacity:0.8,
			zIndex: 20
		});
	});
	
	kakao.maps.event.addListener(linkVtxLine, 'mouseout', function() {
		linkVtxLine.setOptions({
			strokeColor:'#000000',
			setOpacity:0.3,
			zIndex: 20
		});
	});
	
	kakao.maps.event.addListener(linkVtxLine, 'click', function() {
		if(lva.LINKID != null)
		{
			$('#linkId').val(lva.LINKID);
			
			emptySignalArr(linkPhaseLineArr);
			emptySignalArr(_SubLinkLineArr);
			linkPhaseLineArr = [];
			_SubLinkLineArr  = [];
			
			var linkVtx = new kakao.maps.Polyline({
				map:map,
		        path: linkVtxLine.getPath(),
		        strokeWeight: 3,
	            strokeColor: 'red',
	            strokeOpacity: 1,
	            strokeStyle: 'solid',
	            endArrow: true,
	            zIndex: 20
			});
			_SubLinkLineArr.push(linkVtx);
		}
	});
}