function signalPhaseData(idx,aRingPhaseDeg,bRingPhaseDeg) {
	this.idx = idx;
	this.aRingPhaseDeg = aRingPhaseDeg;
	this.bRingPhaseDeg = bRingPhaseDeg;
}

function ringPhaseData(ring0,ring1,ring2,ring3,ring4,ring5,ring6,ring7) {
	this.ring0 = ring0;
	this.ring1 = ring1;
	this.ring2 = ring2;
	this.ring3 = ring3;
	this.ring4 = ring4;
	this.ring5 = ring5;
	this.ring6 = ring6;
	this.ring7 = ring7;
}

function sigMetaData(regionCd,regionId,regionNm,intNo,intNm,intSigCycleCnt,intSigCycleLen,commOnOffFlag,siglightTurnoffFlag,
		             siglightBlinkFlag,contrlrManualFlag,groupNo,mapNo,mainIntNo,sigunguCd,intLcType,intLampType,intMainphase,networkType,modemIp) {
	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.siglightTurnoffFlag = siglightTurnoffFlag;
	this.siglightBlinkFlag = siglightBlinkFlag;
	this.contrlrManualFlag = contrlrManualFlag;
	this.groupNo = groupNo;
	this.mapNo = mapNo;
	this.sigunguCd = sigunguCd;
	this.mainIntNo = mainIntNo;
	this.intLcType = intLcType;
	this.intLampType = intLampType;
	this.intMainphase = intMainphase;
	this.networkType = networkType;  
	this.modemIp = modemIp;
}

function ringLinkVtxData(ring0Vtx,ring1Vtx,ring2Vtx,ring3Vtx,ring4Vtx,ring5Vtx,ring6Vtx,ring7Vtx) {
	this.ring0Vtx = ring0Vtx;
	this.ring1Vtx = ring1Vtx;
	this.ring2Vtx = ring2Vtx;
	this.ring3Vtx = ring3Vtx;
	this.ring4Vtx = ring4Vtx;
	this.ring5Vtx = ring5Vtx;
	this.ring6Vtx = ring6Vtx;
	this.ring7Vtx = ring7Vtx;
}

function customArr(x,y,nm) {
	this.x = x;
	this.y = y;
	this.nm = nm;
}

function _LinkVtxArrObj(LINKID,VERTEXCNT,VERTEX) {
	this.LINKID = LINKID;
	this.VERTEXCNT = VERTEXCNT;
	this.VERTEX = VERTEX;
}

function maxLengthCheck(object){
    if (object.value.length > 3){
        object.value = object.value.slice(0, object.maxLength);
    }
}

//소수점이하 6자리맞춰 0으로 채우기
function leadingZeros(n, digits) {
	var zero = '';
    n = n.toString();
    if (digits > n.length) {
        for (var i = 0; digits - n.length > i; i++) {
            zero += '0';
        }
        return Number(n + zero);
    }
    else return Number(n);
    
}

function leadingZeros2(val, len) {
	var reAngle = val;
	var reLen = len;
	if(reAngle > 359) 
	{
		val = val - 360;
		reLen = val.length;
	}
	if(reLen == 2) reAngle = '0'+reAngle;
	if(reLen == 1) reAngle = '00'+reAngle;
	
	return reAngle;
}

function removeChar(event) {
    event = event || window.event;
    var keyID = (event.which) ? event.which : event.keyCode;
    if ( keyID == 8 || keyID == 46 || keyID == 37 || keyID == 39 )
        return;
    else
        event.target.value = event.target.value.replace(/[^0-9]/g, "");
}

var _UpadtePhaseLinkFlag = false;
var _PrePhaseNum = null;
var popMapPhaseArr = [];
var _SubLinkLineArr = [];
var _SelLinkColor = null;
var phaseValFlag = false;
var phaseBackMap = new HashMap();
var lastPhaseNum = null;
var _RegionCd = null;
var _RegionNm = null;
var _IntNo = null;
var _IntNm = null;
var _MapNo = 0;
var _XCoord = $('#XCoord').val();
var _YCoord = $('#YCoord').val();
var _MainIntNo = null;
var _GroupNo = null;
var _IntType     = null;
var _IntLcType  = null;
var _IntLampType = null;
var _SigunguCd = null;
var _IntMainphase = null;
var _NetworkType = null;
var _ModemIp = null;
var _PFlag = null;
var _Level = 3; 
var _LevelFlag = false;
var _PhaseNum = null;
var _RingSide = null;
var _ARingPhase;
var _BRingPhase;
var _CenterMarker = null;
var _LinkSide = null;
var _LinkId = null;
var _Leftturn;
var _DegIn;
var _DegOut;
var aRingPhaseData;
var bRingPhaseData;

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

function sigInfoUpdatePhaseDetailCallback(data)
{
	if(popMapPhaseArr != null) emptyPopMapPhaseArr();
	//현시 색상초기화(검정)..
	for(var pu = 1; pu < 9; pu++)
		$('.puA_'+pu).css('color','#fff');
	
	var regionCd = _RegionCd;
	var intNo = _IntNo;
	var mapNo = _MapNo;
	
	var aRing1Phase = null;
	var aRing2Phase = null;
	var aRing3Phase = null;
	var aRing4Phase = null;
	var aRing5Phase = null;
	var aRing6Phase = null;
	var aRing7Phase = null;
	var aRing8Phase = null;
	var bRing1Phase = null;
	var bRing2Phase = null;
	var bRing3Phase = null;
	var bRing4Phase = null;
	var bRing5Phase = null;
	var bRing6Phase = null;
	var bRing7Phase = null;
	var bRing8Phase = null;
	
	var aRing1PhaseVal = '-';
	var aRing2PhaseVal = '-';
	var aRing3PhaseVal = '-';
	var aRing4PhaseVal = '-';
	var aRing5PhaseVal = '-';
	var aRing6PhaseVal = '-';
	var aRing7PhaseVal = '-';
	var aRing8PhaseVal = '-';
	var bRing1PhaseVal = '-';
	var bRing2PhaseVal = '-';
	var bRing3PhaseVal = '-';
	var bRing4PhaseVal = '-';
	var bRing5PhaseVal = '-';
	var bRing6PhaseVal = '-';
	var bRing7PhaseVal = '-';
	var bRing8PhaseVal = '-';
	
	var aRing1PhaseStrtLinkCd = '-';
	var aRing1PhaseEndLinkCd  = '-';
	var aRing2PhaseStrtLinkCd = '-';
	var aRing2PhaseEndLinkCd  = '-';
	var aRing3PhaseStrtLinkCd = '-';
	var aRing3PhaseEndLinkCd  = '-';
	var aRing4PhaseStrtLinkCd = '-';
	var aRing4PhaseEndLinkCd  = '-';
	var aRing5PhaseStrtLinkCd = '-';
	var aRing5PhaseEndLinkCd  = '-';
	var aRing6PhaseStrtLinkCd = '-';
	var aRing6PhaseEndLinkCd  = '-';
	var aRing7PhaseStrtLinkCd = '-';
	var aRing7PhaseEndLinkCd  = '-';
	var aRing8PhaseStrtLinkCd = '-';
	var aRing8PhaseEndLinkCd  = '-';
	var bRing1PhaseStrtLinkCd = '-';
	var bRing1PhaseEndLinkCd  = '-';
	var bRing2PhaseStrtLinkCd = '-';
	var bRing2PhaseEndLinkCd  = '-';
	var bRing3PhaseStrtLinkCd = '-';
	var bRing3PhaseEndLinkCd  = '-';
	var bRing4PhaseStrtLinkCd = '-';
	var bRing4PhaseEndLinkCd  = '-';
	var bRing5PhaseStrtLinkCd = '-';
	var bRing5PhaseEndLinkCd  = '-';
	var bRing6PhaseStrtLinkCd = '-';
	var bRing6PhaseEndLinkCd  = '-';
	var bRing7PhaseStrtLinkCd = '-';
	var bRing7PhaseEndLinkCd  = '-';
	var bRing8PhaseStrtLinkCd = '-';
	var bRing8PhaseEndLinkCd  = '-';
	
	var p1Html = '';
	var p2Html = '';
	var link1Html = '';
	var link2Html = '';
	
	if(data.length > 0)
	{
		_RegionCd = data[0].REGION_CD;
		_IntNo = data[0].INT_NO;
		_MapNo = mapNo;
		
		aRing1Phase = data[0].A_RING_1_PHASE_CONF_CD;
		aRing2Phase = data[0].A_RING_2_PHASE_CONF_CD;
		aRing3Phase = data[0].A_RING_3_PHASE_CONF_CD;
		aRing4Phase = data[0].A_RING_4_PHASE_CONF_CD;
		aRing5Phase = data[0].A_RING_5_PHASE_CONF_CD;
		aRing6Phase = data[0].A_RING_6_PHASE_CONF_CD;
		aRing7Phase = data[0].A_RING_7_PHASE_CONF_CD;
		aRing8Phase = data[0].A_RING_8_PHASE_CONF_CD;
		bRing1Phase = data[0].B_RING_1_PHASE_CONF_CD;
		bRing2Phase = data[0].B_RING_2_PHASE_CONF_CD;
		bRing3Phase = data[0].B_RING_3_PHASE_CONF_CD;
		bRing4Phase = data[0].B_RING_4_PHASE_CONF_CD;
		bRing5Phase = data[0].B_RING_5_PHASE_CONF_CD;
		bRing6Phase = data[0].B_RING_6_PHASE_CONF_CD;
		bRing7Phase = data[0].B_RING_7_PHASE_CONF_CD;
		bRing8Phase = data[0].B_RING_8_PHASE_CONF_CD;
		
		//phase 색상(파랑) 구분하기.. 
		if(typeof aRing1Phase != 'undefined') $('.puA_1').css('color','blue');
		if(typeof aRing2Phase != 'undefined') $('.puA_2').css('color','blue');
		if(typeof aRing3Phase != 'undefined') $('.puA_3').css('color','blue');
		if(typeof aRing4Phase != 'undefined') $('.puA_4').css('color','blue');
		if(typeof aRing5Phase != 'undefined') $('.puA_5').css('color','blue');
		if(typeof aRing6Phase != 'undefined') $('.puA_6').css('color','blue');
		if(typeof aRing7Phase != 'undefined') $('.puA_7').css('color','blue');
		if(typeof aRing8Phase != 'undefined') $('.puA_8').css('color','blue');
		if(typeof bRing1Phase != 'undefined') $('.puA_1').css('color','blue');
		if(typeof bRing2Phase != 'undefined') $('.puA_2').css('color','blue');
		if(typeof bRing3Phase != 'undefined') $('.puA_3').css('color','blue');
		if(typeof bRing4Phase != 'undefined') $('.puA_4').css('color','blue');
		if(typeof bRing5Phase != 'undefined') $('.puA_5').css('color','blue');
		if(typeof bRing6Phase != 'undefined') $('.puA_6').css('color','blue');
		if(typeof bRing7Phase != 'undefined') $('.puA_7').css('color','blue');
		if(typeof bRing8Phase != 'undefined') $('.puA_8').css('color','blue');
		
		if(_UpadtePhaseLinkFlag == true)
		{
			aRing1PhaseStrtLinkCd = (typeof data[0].A_RING_1_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_1_PHASE_STRT_LINK_CD;
			aRing1PhaseEndLinkCd  = (typeof data[0].A_RING_1_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_1_PHASE_END_LINK_CD;
			aRing2PhaseStrtLinkCd = (typeof data[0].A_RING_2_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_2_PHASE_STRT_LINK_CD;
			aRing2PhaseEndLinkCd  = (typeof data[0].A_RING_2_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_2_PHASE_END_LINK_CD;
			aRing3PhaseStrtLinkCd = (typeof data[0].A_RING_3_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_3_PHASE_STRT_LINK_CD;
			aRing3PhaseEndLinkCd  = (typeof data[0].A_RING_3_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_3_PHASE_END_LINK_CD;
			aRing4PhaseStrtLinkCd = (typeof data[0].A_RING_4_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_4_PHASE_STRT_LINK_CD;
			aRing4PhaseEndLinkCd  = (typeof data[0].A_RING_4_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_4_PHASE_END_LINK_CD;
			aRing5PhaseStrtLinkCd = (typeof data[0].A_RING_5_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_5_PHASE_STRT_LINK_CD;
			aRing5PhaseEndLinkCd  = (typeof data[0].A_RING_5_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_5_PHASE_END_LINK_CD;
			aRing6PhaseStrtLinkCd = (typeof data[0].A_RING_6_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_6_PHASE_STRT_LINK_CD;
			aRing6PhaseEndLinkCd  = (typeof data[0].A_RING_6_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_6_PHASE_END_LINK_CD;
			aRing7PhaseStrtLinkCd = (typeof data[0].A_RING_7_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_7_PHASE_STRT_LINK_CD;
			aRing7PhaseEndLinkCd  = (typeof data[0].A_RING_7_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_7_PHASE_END_LINK_CD;
			aRing8PhaseStrtLinkCd = (typeof data[0].A_RING_8_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].A_RING_8_PHASE_STRT_LINK_CD;
			aRing8PhaseEndLinkCd  = (typeof data[0].A_RING_8_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].A_RING_8_PHASE_END_LINK_CD;
			bRing1PhaseStrtLinkCd = (typeof data[0].B_RING_1_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_1_PHASE_STRT_LINK_CD;
			bRing1PhaseEndLinkCd  = (typeof data[0].B_RING_1_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_1_PHASE_END_LINK_CD;
			bRing2PhaseStrtLinkCd = (typeof data[0].B_RING_2_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_2_PHASE_STRT_LINK_CD;
			bRing2PhaseEndLinkCd  = (typeof data[0].B_RING_2_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_2_PHASE_END_LINK_CD;
			bRing3PhaseStrtLinkCd = (typeof data[0].B_RING_3_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_3_PHASE_STRT_LINK_CD;
			bRing3PhaseEndLinkCd  = (typeof data[0].B_RING_3_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_3_PHASE_END_LINK_CD;
			bRing4PhaseStrtLinkCd = (typeof data[0].B_RING_4_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_4_PHASE_STRT_LINK_CD;
			bRing4PhaseEndLinkCd  = (typeof data[0].B_RING_4_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_4_PHASE_END_LINK_CD;
			bRing5PhaseStrtLinkCd = (typeof data[0].B_RING_5_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_5_PHASE_STRT_LINK_CD;
			bRing5PhaseEndLinkCd  = (typeof data[0].B_RING_5_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_5_PHASE_END_LINK_CD;
			bRing6PhaseStrtLinkCd = (typeof data[0].B_RING_6_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_6_PHASE_STRT_LINK_CD;
			bRing6PhaseEndLinkCd  = (typeof data[0].B_RING_6_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_6_PHASE_END_LINK_CD;
			bRing7PhaseStrtLinkCd = (typeof data[0].B_RING_7_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_7_PHASE_STRT_LINK_CD;
			bRing7PhaseEndLinkCd  = (typeof data[0].B_RING_7_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_7_PHASE_END_LINK_CD;
			bRing8PhaseStrtLinkCd = (typeof data[0].B_RING_8_PHASE_STRT_LINK_CD == 'undefined') ? '-' : data[0].B_RING_8_PHASE_STRT_LINK_CD;
			bRing8PhaseEndLinkCd  = (typeof data[0].B_RING_8_PHASE_END_LINK_CD  == 'undefined') ? '-' : data[0].B_RING_8_PHASE_END_LINK_CD;
		}
		
	}
	
	if(_UpadtePhaseLinkFlag == false)
	{
		p1Html += '<tr>';
		p1Html += '<td>A링</td>';
		p1Html += '<td id="pUAMap0" onclick="ringPhaseUpdate(\'A\',\''+aRing1Phase+'\',\''+bRing1Phase+'\',\'-\','+0+',\'-\',\'-\')" title="ARing 1현시 편집"></td>';
		p1Html += '<td id="pUAMap1" onclick="ringPhaseUpdate(\'A\',\''+aRing2Phase+'\',\''+bRing2Phase+'\',\'-\','+1+',\'-\',\'-\')" title="ARing 2현시 편집"></td>';
		p1Html += '<td id="pUAMap2" onclick="ringPhaseUpdate(\'A\',\''+aRing3Phase+'\',\''+bRing3Phase+'\',\'-\','+2+',\'-\',\'-\')" title="ARing 3현시 편집"></td>';
		p1Html += '<td id="pUAMap3" onclick="ringPhaseUpdate(\'A\',\''+aRing4Phase+'\',\''+bRing4Phase+'\',\'-\','+3+',\'-\',\'-\')" title="ARing 4현시 편집"></td>';
		p1Html += '<td id="pUAMap4" onclick="ringPhaseUpdate(\'A\',\''+aRing5Phase+'\',\''+bRing5Phase+'\',\'-\','+4+',\'-\',\'-\')" title="ARing 5현시 편집"></td>';
		p1Html += '<td id="pUAMap5" onclick="ringPhaseUpdate(\'A\',\''+aRing6Phase+'\',\''+bRing6Phase+'\',\'-\','+5+',\'-\',\'-\')" title="ARing 6현시 편집"></td>';
		p1Html += '<td id="pUAMap6" onclick="ringPhaseUpdate(\'A\',\''+aRing7Phase+'\',\''+bRing7Phase+'\',\'-\','+6+',\'-\',\'-\')" title="ARing 7현시 편집"></td>';
		p1Html += '<td id="pUAMap7" onclick="ringPhaseUpdate(\'A\',\''+aRing8Phase+'\',\''+bRing8Phase+'\',\'-\','+7+',\'-\',\'-\')" title="ARing 8현시 편집"></td>';
		p1Html += '</tr>';
		p2Html += '<tr>';
		p2Html += '<td>B링</td>';
		p2Html += '<td id="pUBMap0" onclick="ringPhaseUpdate(\'B\',\''+aRing1Phase+'\',\''+bRing1Phase+'\',\'-\','+0+',\'-\',\'-\')" title="BRing 1현시 편집"></td>';
		p2Html += '<td id="pUBMap1" onclick="ringPhaseUpdate(\'B\',\''+aRing2Phase+'\',\''+bRing2Phase+'\',\'-\','+1+',\'-\',\'-\')" title="BRing 2현시 편집"></td>';
		p2Html += '<td id="pUBMap2" onclick="ringPhaseUpdate(\'B\',\''+aRing3Phase+'\',\''+bRing3Phase+'\',\'-\','+2+',\'-\',\'-\')" title="BRing 3현시 편집"></td>';
		p2Html += '<td id="pUBMap3" onclick="ringPhaseUpdate(\'B\',\''+aRing4Phase+'\',\''+bRing4Phase+'\',\'-\','+3+',\'-\',\'-\')" title="BRing 4현시 편집"></td>';
		p2Html += '<td id="pUBMap4" onclick="ringPhaseUpdate(\'B\',\''+aRing5Phase+'\',\''+bRing5Phase+'\',\'-\','+4+',\'-\',\'-\')" title="BRing 5현시 편집"></td>';
		p2Html += '<td id="pUBMap5" onclick="ringPhaseUpdate(\'B\',\''+aRing6Phase+'\',\''+bRing6Phase+'\',\'-\','+5+',\'-\',\'-\')" title="BRing 6현시 편집"></td>';
		p2Html += '<td id="pUBMap6" onclick="ringPhaseUpdate(\'B\',\''+aRing7Phase+'\',\''+bRing7Phase+'\',\'-\','+6+',\'-\',\'-\')" title="BRing 7현시 편집"></td>';
		p2Html += '<td id="pUBMap7" onclick="ringPhaseUpdate(\'B\',\''+aRing8Phase+'\',\''+bRing8Phase+'\',\'-\','+7+',\'-\',\'-\')" title="BRing 8현시 편집"></td>';
		p2Html += '</tr>';
		
		$('#updatePhaseInfoList1').html(p1Html);
		$('#updatePhaseInfoList2').html(p2Html);
		
		aRingPhaseData = new ringPhaseData(aRing1Phase,aRing2Phase,aRing3Phase,aRing4Phase,aRing5Phase,aRing6Phase,aRing7Phase,aRing8Phase);
		bRingPhaseData = new ringPhaseData(bRing1Phase,bRing2Phase,bRing3Phase,bRing4Phase,bRing5Phase,bRing6Phase,bRing7Phase,bRing8Phase);
		
		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;
		if(aRing7Phase) aRingPhaseCnt = 7;
		if(aRing8Phase) aRingPhaseCnt = 8;
		
		var aHtml = '';
		var bHtml = '';
		
		for(var ii = 0; ii < aRingPhaseCnt; ii++)
		{
			listCoord = [];
			drawPhase('pUAMap'+ii);
			if(ii == 0) drawPhaseLine(aRingPhaseData.ring0);
			if(ii == 1) drawPhaseLine(aRingPhaseData.ring1);
			if(ii == 2) drawPhaseLine(aRingPhaseData.ring2);
			if(ii == 3) drawPhaseLine(aRingPhaseData.ring3);
			if(ii == 4) drawPhaseLine(aRingPhaseData.ring4);
			if(ii == 5) drawPhaseLine(aRingPhaseData.ring5);	
			if(ii == 6) drawPhaseLine(aRingPhaseData.ring6);
			if(ii == 7) drawPhaseLine(aRingPhaseData.ring7);
		}
		
	    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;
		if(bRing7Phase) bRingPhaseCnt = 7;
		if(bRing8Phase) bRingPhaseCnt = 8;
		
		for(var jj = 0; jj < bRingPhaseCnt; jj++)
		{
			listCoord = [];
			drawPhase('pUBMap'+jj);
			if(jj == 0) drawPhaseLine(bRingPhaseData.ring0);
			if(jj == 1) drawPhaseLine(bRingPhaseData.ring1);
			if(jj == 2) drawPhaseLine(bRingPhaseData.ring2);
			if(jj == 3) drawPhaseLine(bRingPhaseData.ring3);
			if(jj == 4) drawPhaseLine(bRingPhaseData.ring4);
			if(jj == 5) drawPhaseLine(bRingPhaseData.ring5);
			if(jj == 6) drawPhaseLine(bRingPhaseData.ring6);
			if(jj == 7) drawPhaseLine(bRingPhaseData.ring7);
		}
	}
	else
	{
		p1Html += '<tr class="aStrtLinkId">';
		p1Html += '<td rowspan=2>A링</td>';
		p1Html += '<td>시작</td>';
		p1Html += '<td class="linkColor_A1S" onclick="ringPhaseUpdate(\'A\',\''+aRing1Phase+'\',\''+bRing1Phase+'\',\'A1S\','+0+',\''+aRing1PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 1링크 편집">'+aRing1PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A2S" onclick="ringPhaseUpdate(\'A\',\''+aRing2Phase+'\',\''+bRing2Phase+'\',\'A2S\','+1+',\''+aRing2PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 2링크 편집">'+aRing2PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A3S" onclick="ringPhaseUpdate(\'A\',\''+aRing3Phase+'\',\''+bRing3Phase+'\',\'A3S\','+2+',\''+aRing3PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 3링크 편집">'+aRing3PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A4S" onclick="ringPhaseUpdate(\'A\',\''+aRing4Phase+'\',\''+bRing4Phase+'\',\'A4S\','+3+',\''+aRing4PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 4링크 편집">'+aRing4PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A5S" onclick="ringPhaseUpdate(\'A\',\''+aRing5Phase+'\',\''+bRing5Phase+'\',\'A5S\','+4+',\''+aRing5PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 5링크 편집">'+aRing5PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A6S" onclick="ringPhaseUpdate(\'A\',\''+aRing6Phase+'\',\''+bRing6Phase+'\',\'A6S\','+5+',\''+aRing6PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 6링크 편집">'+aRing6PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A7S" onclick="ringPhaseUpdate(\'A\',\''+aRing7Phase+'\',\''+bRing7Phase+'\',\'A7S\','+6+',\''+aRing7PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 7링크 편집">'+aRing7PhaseStrtLinkCd+'</td>';
		p1Html += '<td class="linkColor_A8S" onclick="ringPhaseUpdate(\'A\',\''+aRing8Phase+'\',\''+bRing8Phase+'\',\'A8S\','+7+',\''+aRing8PhaseStrtLinkCd+'\',\'STRT\')" title="ARing 8링크 편집">'+aRing8PhaseStrtLinkCd+'</td>';
		p1Html += '</tr>';
		p1Html += '<tr class="aEndLinkId">';
		p1Html += '<td>죵료</td>';
		p1Html += '<td class="linkColor_A1E" onclick="ringPhaseUpdate(\'A\',\''+aRing1Phase+'\',\''+bRing1Phase+'\',\'A1E\','+0+',\''+aRing1PhaseEndLinkCd+'\',\'END\')" title="ARing 1링크 편집">'+aRing1PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A2E" onclick="ringPhaseUpdate(\'A\',\''+aRing2Phase+'\',\''+bRing2Phase+'\',\'A2E\','+1+',\''+aRing2PhaseEndLinkCd+'\',\'END\')" title="ARing 2링크 편집">'+aRing2PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A3E" onclick="ringPhaseUpdate(\'A\',\''+aRing3Phase+'\',\''+bRing3Phase+'\',\'A3E\','+2+',\''+aRing3PhaseEndLinkCd+'\',\'END\')" title="ARing 3링크 편집">'+aRing3PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A4E" onclick="ringPhaseUpdate(\'A\',\''+aRing4Phase+'\',\''+bRing4Phase+'\',\'A4E\','+3+',\''+aRing4PhaseEndLinkCd+'\',\'END\')" title="ARing 4링크 편집">'+aRing4PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A5E" onclick="ringPhaseUpdate(\'A\',\''+aRing5Phase+'\',\''+bRing5Phase+'\',\'A5E\','+4+',\''+aRing5PhaseEndLinkCd+'\',\'END\')" title="ARing 5링크 편집">'+aRing5PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A6E" onclick="ringPhaseUpdate(\'A\',\''+aRing6Phase+'\',\''+bRing6Phase+'\',\'A6E\','+5+',\''+aRing6PhaseEndLinkCd+'\',\'END\')" title="ARing 6링크 편집">'+aRing6PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A7E" onclick="ringPhaseUpdate(\'A\',\''+aRing7Phase+'\',\''+bRing7Phase+'\',\'A7E\','+6+',\''+aRing7PhaseEndLinkCd+'\',\'END\')" title="ARing 7링크 편집">'+aRing7PhaseEndLinkCd+'</td>';
		p1Html += '<td class="linkColor_A8E" onclick="ringPhaseUpdate(\'A\',\''+aRing8Phase+'\',\''+bRing8Phase+'\',\'A8E\','+7+',\''+aRing8PhaseEndLinkCd+'\',\'END\')" title="ARing 8링크 편집">'+aRing8PhaseEndLinkCd+'</td>';
		p1Html += '</tr>';
		
		p2Html += '<tr class="bStrtLinkId">';
		p2Html += '<td rowspan="2">B링</td>';
		p2Html += '<td>시작</td>';
		p2Html += '<td class="linkColor_B1S" onclick="ringPhaseUpdate(\'B\',\''+aRing1Phase+'\',\''+bRing1Phase+'\',\'B1S\','+0+',\''+bRing1PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 1링크 편집">'+bRing1PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B2S" onclick="ringPhaseUpdate(\'B\',\''+aRing2Phase+'\',\''+bRing2Phase+'\',\'B2S\','+1+',\''+bRing2PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 2링크 편집">'+bRing2PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B3S" onclick="ringPhaseUpdate(\'B\',\''+aRing3Phase+'\',\''+bRing3Phase+'\',\'B3S\','+2+',\''+bRing3PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 3링크 편집">'+bRing3PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B4S" onclick="ringPhaseUpdate(\'B\',\''+aRing4Phase+'\',\''+bRing4Phase+'\',\'B4S\','+3+',\''+bRing4PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 4링크 편집">'+bRing4PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B5S" onclick="ringPhaseUpdate(\'B\',\''+aRing5Phase+'\',\''+bRing5Phase+'\',\'B5S\','+4+',\''+bRing5PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 5링크 편집">'+bRing5PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B6S" onclick="ringPhaseUpdate(\'B\',\''+aRing6Phase+'\',\''+bRing6Phase+'\',\'B6S\','+5+',\''+bRing6PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 6링크 편집">'+bRing6PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B7S" onclick="ringPhaseUpdate(\'B\',\''+aRing7Phase+'\',\''+bRing7Phase+'\',\'B7S\','+6+',\''+bRing7PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 7링크 편집">'+bRing7PhaseStrtLinkCd+'</td>';
		p2Html += '<td class="linkColor_B8S" onclick="ringPhaseUpdate(\'B\',\''+aRing8Phase+'\',\''+bRing8Phase+'\',\'B8S\','+7+',\''+bRing8PhaseStrtLinkCd+'\',\'STRT\')" title="BRing 8링크 편집">'+bRing8PhaseStrtLinkCd+'</td>';
		p2Html += '</tr>';
		p2Html += '<tr class="bEndLinkId">';
		p2Html += '<td>죵료</td>';
		p2Html += '<td class="linkColor_B1E" onclick="ringPhaseUpdate(\'B\',\''+aRing1Phase+'\',\''+bRing1Phase+'\',\'B1E\','+0+',\''+bRing1PhaseEndLinkCd+'\',\'END\')" title="BRing 1링크 편집">'+bRing1PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B2E" onclick="ringPhaseUpdate(\'B\',\''+aRing2Phase+'\',\''+bRing2Phase+'\',\'B2E\','+1+',\''+bRing2PhaseEndLinkCd+'\',\'END\')" title="BRing 2링크 편집">'+bRing2PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B3E" onclick="ringPhaseUpdate(\'B\',\''+aRing3Phase+'\',\''+bRing3Phase+'\',\'B3E\','+2+',\''+bRing3PhaseEndLinkCd+'\',\'END\')" title="BRing 3링크 편집">'+bRing3PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B4E" onclick="ringPhaseUpdate(\'B\',\''+aRing4Phase+'\',\''+bRing4Phase+'\',\'B4E\','+3+',\''+bRing4PhaseEndLinkCd+'\',\'END\')" title="BRing 4링크 편집">'+bRing4PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B5E" onclick="ringPhaseUpdate(\'B\',\''+aRing5Phase+'\',\''+bRing5Phase+'\',\'B5E\','+4+',\''+bRing5PhaseEndLinkCd+'\',\'END\')" title="BRing 5링크 편집">'+bRing5PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B6E" onclick="ringPhaseUpdate(\'B\',\''+aRing6Phase+'\',\''+bRing6Phase+'\',\'B6E\','+5+',\''+bRing6PhaseEndLinkCd+'\',\'END\')" title="BRing 6링크 편집">'+bRing6PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B7E" onclick="ringPhaseUpdate(\'B\',\''+aRing7Phase+'\',\''+bRing7Phase+'\',\'B7E\','+6+',\''+bRing7PhaseEndLinkCd+'\',\'END\')" title="BRing 7링크 편집">'+bRing7PhaseEndLinkCd+'</td>';
		p2Html += '<td class="linkColor_B8E" onclick="ringPhaseUpdate(\'B\',\''+aRing8Phase+'\',\''+bRing8Phase+'\',\'B8E\','+7+',\''+bRing8PhaseEndLinkCd+'\',\'END\')" title="BRing 8링크 편집">'+bRing8PhaseEndLinkCd+'</td>';
		p2Html += '</tr>';
		
		$('#updateLinkInfoList1').html(p1Html);
		$('#updateLinkInfoList2').html(p2Html);
	}
	
	//kakao로고 삭제
	for(var mm = 0; mm < 8; mm++)
	{
		$('#pUAMap'+mm+' div:nth-child(2)').css('z-index',0);
		$('#pUBMap'+mm+' div:nth-child(2)').css('z-index',0);
	}
	
}

function ringPhaseUpdate(ring,aRingPhase,bRingPhase,progress,phase,strtLinkCd,endLinkCd) 
{
	var aRing = aRingPhase;
	var bRing = bRingPhase;
	var leftFlag = '';
	var pedeFlag = '';
	
	if(typeof aRing == 'undefined' || aRing == 'undefined') aRing = '-'; 
	if(typeof bRing == 'undefined' || bRing == 'undefined') bRing = '-';
	
	if(ring == 'A') 
	{
		_Leftturn = aRingPhase.substring(0,1);
		_DegIn = aRingPhase.substring(1,4);
		_DegOut = aRingPhase.substring(4,7);
		_BRingPhase = bRing;
	}
	else
	{
		_Leftturn = bRingPhase.substring(0,1);
		_DegIn = bRingPhase.substring(1,4);
		_DegOut = bRingPhase.substring(4,7);
		_ARingPhase = aRing;
	}
	
	if(_Leftturn == 'L') leftFlag = 'checked="checked"';
	else if(_Leftturn == 'P') pedeFlag = 'checked="checked"';
	
	_RingPhaseVal = phase;
	
	emptySignalArr(linkPhaseLineArr);
	emptySignalArr(_SubLinkLineArr);
	
	linkPhaseLineArr = [];
	_SubLinkLineArr  = [];
	
	if(_UpadtePhaseLinkFlag == true)
	{
		selectLinkSide(strtLinkCd,endLinkCd);
	}
	
	_PhaseNum = phase + 1;
	_RingSide = ring;
	
	var uHtml = '';
	if(_UpadtePhaseLinkFlag == false)
	{
		uHtml += '<h3>['+ring+'링 '+_PhaseNum+'현시 ]</h3>';
		uHtml += '<ul>';
		uHtml += '<li><span class="phaseOption"><strong>현시옵션 : </strong></span><label for="leftturn">좌회전</label>&nbsp;<input type="checkbox" '+leftFlag+' id="leftturn" /></li>';
		uHtml += '<li><label for="pedeLine">보행자</label>&nbsp;<input type="checkbox" '+pedeFlag+' id="pedeLine" /></li>';
		uHtml += '<li class="updateDeg"> | <span><strong>각도조정 : </strong></span><label for="degIn">시작각 </label><input type="number" id="degIn" value="'+_DegIn+'" max=359 min="0" oninput="maxLengthCheck(this)"/></li>';
		uHtml += '<li><label for="degOut">종료각 </label><input type="number" id="degOut" value="'+_DegOut+'" max=359 min="0" oninput="maxLengthCheck(this)" /></li>';
		
		var phaseVal = 'pU' + ring + 'Map' + phase;
		
		//이전 현시 흔적 삭제..
		emptyLastPhase();
		
		//선택된 현시 색상(노랑) 변경
		var pVal = phaseBackMap.get(phaseVal);
		if(pVal != null)
		{
			phaseValFlag = true;
			pVal.setOptions({
				fillColor:'yellow'
			});
			lastPhaseNum = pVal;
		}
		else
		{
			phaseValFlag = false;
			$('#'+phaseVal).css('background-color','yellow');
			lastPhaseNum = phaseVal;
		}
	}
	else
	{
		var strtLink = strtLinkCd;
		var endLink = endLinkCd;
		
		if(typeof strtLink == 'undefined' || strtLink == 'undefined') strtLink = '-'; 
		if(typeof endLink == 'undefined' || endLink == 'undefined') endLink = '-';
		
		$('.linkColor_'+_SelLinkColor).css('background-color','').css('color','');
		var gubun = '시작';
		if(endLink == 'END') gubun = '종료';
		uHtml += '<h3>['+ring+'링 '+_PhaseNum+'현시  '+gubun+']</h3>';
		uHtml += '<ul>';
		uHtml += '<li><label for="linkId">링크ID : </label><input type="text" id="linkId" value="'+strtLink+'" /></li>';
		uHtml += '<div class="linkMessage"><strong>지도에서 변경될 링크를 선택하세요.</strong></div>';
		$('.linkColor_'+progress).css('background-color','yellow').css('color','red');
		_LinkSId = $('#linkId').val();
		_SelLinkColor = progress;
	}
	uHtml += '<li class="phaseSaveBt"><a href="javascript:savePhaseInfo()" class="btn" >저장</a></li>';
	uHtml += '</ul>';
	$('.updatePhaseDiv').empty().html(uHtml);
	
	resizePhaseInfo();
	
}

//이전현시 흔적 삭제..
function emptyLastPhase() {
	if(lastPhaseNum != null) 
	{
		if(phaseValFlag == true)
		{
			lastPhaseNum.setOptions({
				fillColor:'#ffffff',
				opacity:1
			});
		}
		else
		{
			$('#'+lastPhaseNum).css('background-color','#ffffff');
		}
	}
}

function selectLinkSide(linkId,side) {
	
	emptySignalArr(linkPhaseLineArr);
	emptySignalArr(_SubLinkLineArr);
	
	linkPhaseLineArr = [];
	_SubLinkLineArr  = [];
	
	_LinkSide = side;
	
	if(linkId != '-')
	{
		var url = 'getSelctLinkVtx.do';
		var param = 'linkId='+linkId;
		requestService(url, param, getSelctLinkVtxCallback);
	}
}

function getSelctLinkVtxCallback(data) {
	if(data.length > 0)
	{
		signalArr[0].setLinkPhase(data,'');
		linkPhaseLineArr[0].setOptions({
			strokeWeight: 3,
	        strokeColor: 'red',
	        strokeOpacity: 1,
	        strokeStyle: 'solid',
	        endArrow: true,
	        zIndex: 30
		});
		
		linkPhaseLineArr[0].setMap(map);
	}
	else
	{
		console.log('매칭되는 링크가 없습니다.');
	}
}

function getSigInfoPhaseDetail() {
	var url = 'getSigInfoPhaseDetail.do';
	var params;
	if(_PFlag == 'U')
	{
		var mapNo = $('#updateMapNo').val();
		params = 'regionCd='+_RegionCd+'&intNo='+_IntNo+'&mapNo='+mapNo;
		requestService(url, params, sigInfoUpdatePhaseDetailCallback);
	}
	else
	{
		params = 'regionCd='+_RegionCd+'&intNo='+_IntNo+'&mapNo='+_MapNo;
		requestService(url, params, sigPhaseDetailListCallback);
	}
}

function sigPhaseDetailListCallback(data) {
	if(popMapPhaseArr != null) emptyPopMapPhaseArr();
	
	var regionCd = data[0].REGION_CD;
	var intNo = data[0].INT_NO;
	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 aRing7Phase = data[0].A_RING_7_PHASE_CONF_CD;
	var aRing8Phase = data[0].A_RING_8_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;
	var bRing7Phase = data[0].B_RING_7_PHASE_CONF_CD;
	var bRing8Phase = data[0].B_RING_8_PHASE_CONF_CD;
	
	var aRing1PhaseVal = (typeof data[0].A_RING_1_PHASE_VAL == 'undefined' || data[0].A_RING_1_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_1_PHASE_VAL;
	var aRing2PhaseVal = (typeof data[0].A_RING_2_PHASE_VAL == 'undefined' || data[0].A_RING_2_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_2_PHASE_VAL;
	var aRing3PhaseVal = (typeof data[0].A_RING_3_PHASE_VAL == 'undefined' || data[0].A_RING_3_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_3_PHASE_VAL;
	var aRing4PhaseVal = (typeof data[0].A_RING_4_PHASE_VAL == 'undefined' || data[0].A_RING_4_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_4_PHASE_VAL;
	var aRing5PhaseVal = (typeof data[0].A_RING_5_PHASE_VAL == 'undefined' || data[0].A_RING_5_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_5_PHASE_VAL;
	var aRing6PhaseVal = (typeof data[0].A_RING_6_PHASE_VAL == 'undefined' || data[0].A_RING_6_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_6_PHASE_VAL;
	var aRing7PhaseVal = (typeof data[0].A_RING_7_PHASE_VAL == 'undefined' || data[0].A_RING_7_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_7_PHASE_VAL;
	var aRing8PhaseVal = (typeof data[0].A_RING_8_PHASE_VAL == 'undefined' || data[0].A_RING_8_PHASE_VAL == 9999) ? '정보없음' : data[0].A_RING_8_PHASE_VAL;
	
	var bRing1PhaseVal = (typeof data[0].B_RING_1_PHASE_VAL == 'undefined' || data[0].B_RING_1_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_1_PHASE_VAL;
	var bRing2PhaseVal = (typeof data[0].B_RING_2_PHASE_VAL == 'undefined' || data[0].B_RING_2_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_2_PHASE_VAL;
	var bRing3PhaseVal = (typeof data[0].B_RING_3_PHASE_VAL == 'undefined' || data[0].B_RING_3_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_3_PHASE_VAL;
	var bRing4PhaseVal = (typeof data[0].B_RING_4_PHASE_VAL == 'undefined' || data[0].B_RING_4_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_4_PHASE_VAL;
	var bRing5PhaseVal = (typeof data[0].B_RING_5_PHASE_VAL == 'undefined' || data[0].B_RING_5_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_5_PHASE_VAL;
	var bRing6PhaseVal = (typeof data[0].B_RING_6_PHASE_VAL == 'undefined' || data[0].B_RING_6_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_6_PHASE_VAL;
	var bRing7PhaseVal = (typeof data[0].B_RING_7_PHASE_VAL == 'undefined' || data[0].B_RING_7_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_7_PHASE_VAL;
	var bRing8PhaseVal = (typeof data[0].B_RING_8_PHASE_VAL == 'undefined' || data[0].B_RING_8_PHASE_VAL == 9999) ? '정보없음' : data[0].B_RING_8_PHASE_VAL;
	
	var p1Html = '';
	var p2Html = '';
	
	p1Html += '<tr>';
	p1Html += '<td>A링</td>';
	p1Html += '<td id="pAMap0"></td>';
	p1Html += '<td id="pAMap1"></td>';
	p1Html += '<td id="pAMap2"></td>';
	p1Html += '<td id="pAMap3"></td>';
	p1Html += '<td id="pAMap4"></td>';
	p1Html += '<td id="pAMap5"></td>';
	p1Html += '<td id="pAMap6"></td>';
	p1Html += '<td id="pAMap7"></td>';
	p1Html += '</tr>';
	p1Html += '<tr class="aProgress">';
	p1Html += '<td>주기</td>';
	p1Html += '<td>'+aRing1PhaseVal+'</td>';
	p1Html += '<td>'+aRing2PhaseVal+'</td>';
	p1Html += '<td>'+aRing3PhaseVal+'</td>';
	p1Html += '<td>'+aRing4PhaseVal+'</td>';
	p1Html += '<td>'+aRing5PhaseVal+'</td>';
	p1Html += '<td>'+aRing6PhaseVal+'</td>';
	p1Html += '<td>'+aRing7PhaseVal+'</td>';
	p1Html += '<td>'+aRing8PhaseVal+'</td>';
	p1Html += '</tr>';
	
	p2Html += '<tr>';
	p2Html += '<td>B링</td>';
	p2Html += '<td id="pBMap0"></td>';
	p2Html += '<td id="pBMap1"></td>';
	p2Html += '<td id="pBMap2"></td>';
	p2Html += '<td id="pBMap3"></td>';
	p2Html += '<td id="pBMap4"></td>';
	p2Html += '<td id="pBMap5"></td>';
	p2Html += '<td id="pBMap6"></td>';
	p2Html += '<td id="pBMap7"></td>';
	p2Html += '</tr>';
	p2Html += '<tr class="bProgress">';
	p2Html += '<td>주기</td>';
	p2Html += '<td>'+bRing1PhaseVal+'</td>';
	p2Html += '<td>'+bRing2PhaseVal+'</td>';
	p2Html += '<td>'+bRing3PhaseVal+'</td>';
	p2Html += '<td>'+bRing4PhaseVal+'</td>';
	p2Html += '<td>'+bRing5PhaseVal+'</td>';
	p2Html += '<td>'+bRing6PhaseVal+'</td>';
	p2Html += '<td>'+bRing7PhaseVal+'</td>';
	p2Html += '<td>'+bRing8PhaseVal+'</td>';
	p2Html += '</tr>';
	
	$('#phaseInfoList1').empty().html(p1Html);
	$('#phaseInfoList2').empty().html(p2Html);
	
	aRingPhaseData = new ringPhaseData(aRing1Phase,aRing2Phase,aRing3Phase,aRing4Phase,aRing5Phase,aRing6Phase,aRing7Phase,aRing8Phase);
	bRingPhaseData = new ringPhaseData(bRing1Phase,bRing2Phase,bRing3Phase,bRing4Phase,bRing5Phase,bRing6Phase,bRing7Phase,bRing8Phase);
	
	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;
	if(aRing7Phase) aRingPhaseCnt = 7;
	if(aRing8Phase) aRingPhaseCnt = 8;
	
	var aHtml = '';
	var bHtml = '';
	
	for(var ii = 0; ii < aRingPhaseCnt; ii++)
	{
		listCoord = [];
		drawPhase('pAMap'+ii);
		if(ii == 0) drawPhaseLine(aRingPhaseData.ring0);
		if(ii == 1) drawPhaseLine(aRingPhaseData.ring1);
		if(ii == 2) drawPhaseLine(aRingPhaseData.ring2);
		if(ii == 3) drawPhaseLine(aRingPhaseData.ring3);
		if(ii == 4) drawPhaseLine(aRingPhaseData.ring4);
		if(ii == 5) drawPhaseLine(aRingPhaseData.ring5);	
		if(ii == 6) drawPhaseLine(aRingPhaseData.ring6);
		if(ii == 7) drawPhaseLine(aRingPhaseData.ring7);
	}
	
    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;
	if(bRing7Phase) bRingPhaseCnt = 7;
	if(bRing8Phase) bRingPhaseCnt = 8;
	
	for(var jj = 0; jj < bRingPhaseCnt; jj++)
	{
		listCoord = [];
		drawPhase('pBMap'+jj);
		if(jj == 0) drawPhaseLine(bRingPhaseData.ring0);
		if(jj == 1) drawPhaseLine(bRingPhaseData.ring1);
		if(jj == 2) drawPhaseLine(bRingPhaseData.ring2);
		if(jj == 3) drawPhaseLine(bRingPhaseData.ring3);
		if(jj == 4) drawPhaseLine(bRingPhaseData.ring4);
		if(jj == 5) drawPhaseLine(bRingPhaseData.ring5);
		if(jj == 6) drawPhaseLine(bRingPhaseData.ring6);
		if(jj == 7) drawPhaseLine(bRingPhaseData.ring7);
	}
	
	//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 drawPhase(mapId)
{
	var pLat = parseFloat(_YCoord);
	var pLng = parseFloat(_XCoord);
	
	var pMapContainer = document.getElementById(mapId) // 지도를 표시할 div 
	var mapOption = {
		center: new kakao.maps.LatLng(pLat, pLng),
		level: 1
	};
	
	pMap = new kakao.maps.Map(pMapContainer, mapOption); // 지도생성
	pMap.setDraggable(false);
	pMap.setZoomable(false);
	
	var mapBack = new kakao.maps.Circle({
	    center : new kakao.maps.LatLng(pLat, pLng),
	    radius: 30,
	    strokeWeight: 1,
	    strokeOpacity: 1,
	    strokeStyle: 'solid',
	    fillColor: '#fff',
	    fillOpacity: 1,
	    zIndex: 5,
	    map:pMap
	});
	phaseBackMap.put(mapId,mapBack);
	
	var mapCircle = new kakao.maps.Circle({
	    center : new kakao.maps.LatLng(pLat, pLng),
	    radius: 8,
	    strokeWeight: 3,
	    strokeColor: '#FF0000',
	    strokeOpacity: 1,
	    strokeStyle: 'solid',
	    fillColor: '#fff',
	    fillOpacity: 1,
	    zIndex: 10,
	    map:pMap
	});
	popMapPhaseArr.push(mapCircle);
}

function drawPhaseLine(ringPhase,pedeSize) {
	var ringType;
	if(typeof ringPhase != 'undefined') ringType = checkPhaseRingType(ringPhase);
	else return;
	
	// 진입, 진출 Degree 각도를 얻는다.
	var degIn = Number(ringPhase.substring(1,4));
	var degOut = Number(ringPhase.substring(4,7));
	if(ringType == 1 || ringType == 2)
	{
		if (degIn  > 360) degIn = degIn - 360;
		if (degOut > 360) degOut = degOut - 360;
	}
	else if(ringType == 3)
	{
		if(degOut != 0)
		{
			return drawPhasePedestrians(pedeSize);
		}
		else
		{
			degIn += 90;
			degOut = degIn + 180;
			if(degIn  > 360) degIn  = degIn - 360;
			if(degOut > 360) degOut = degOut - 360;
		}
	}
	
	var turnLeftAngle = 135;
	var a;
	var gapAngle;
	var diff = degIn;
	
	if(ringType == 1) gapAngle = 270;
	else if(ringType == 2) gapAngle = 90;
	else if(ringType == 3) 
	{
		if (diff > 180) 
		{
			diff = diff - 180;
			gapAngle = 90;
		}
		else
		{
			gapAngle = 270;
		}
	}
	
	a = diff + gapAngle;
	if (a >= 360) a = a - 360;
	
	movePhaseCenterPos(a);
	createPhaseMap(ringType, degIn, degOut);
}

function checkPhaseRingType(ring)
{
	var type = ring.substring(0,1);
	if (type == "S") return 1;	//직진
	if (type == "L") return 2;  //좌회전
	if (type == "P") return 3;	//보행자	
}

function movePhaseCenterPos(deg)
{
	var pLat = parseFloat(_YCoord);
	var pLng = parseFloat(_XCoord);
	var rad = deg.toRadians();
	var deltaLat = 0.001 * Math.cos(rad);
	var deltaLng = 0.001 * Math.sin(rad);
	
	deltaLat = (deltaLat * 360) / 40000;
	deltaLng = (deltaLng * 360) / 40000;
	centerLat = parseFloat(pLat) + parseFloat(deltaLat);
	centerLng = parseFloat(pLng) + parseFloat(deltaLng);
}

function drawPhasePedestrians(pedeSize)
{
	var pLat = parseFloat(_YCoord);
	var position = new kakao.maps.LatLng(pLat, _XCoord);
	var src = 'images/walking60.png';
	var pWidth = 60;
	var pHeight = 60;
	var pOffsetX = 29;
	var pOffsetY = 29;
	if(typeof pedeSize != 'undefined') 
	{
		pWidth = pedeSize;
		pHeigth = pedeSize;
		pOffsetX = 24;
	}
	var size = new kakao.maps.Size(pWidth,pHeight),
	           options = {
					offset : new kakao.maps.Point(pOffsetX,pOffsetY),
					shape : 'poly'
				};
	
	var markerImage = new kakao.maps.MarkerImage(src, size, options);
	mapRing = new kakao.maps.Marker({
		position : position,
		image : markerImage
	});
	
	mapRing.setMap(pMap);
}

function createPhaseMap(ringType, degIn, degOut) {
	var color = '#0000FF';//blue
	var distance = 0.005;
	var strokeWeight = 3;
	var endArraw = true;
	var strokeStyle = 'solid';

	if (ringType != 0) {
		if (ringType == 3) {
			endArraw = false;
			distance = 0.0055;
			strokeWeight = 4;
			strokeStyle = 'shortdot';
			color = '#000000';//black
		}
		
		listCoord.push(new SCoord(distance * Math.cos(degIn.toRadians()), distance * Math.sin(degIn.toRadians())));
		listCoord.push(new SCoord(centerLat, centerLng));
		listCoord.push(new SCoord(distance * Math.cos(degOut.toRadians()), distance * Math.sin(degOut.toRadians())));
		
		for(var ii = 0; ii < 3; ii++) {
			if (ii == 1) continue;	//중심좌표는 보정이 필요없음.
			
	    	listCoord[ii].Lat = (listCoord[ii].Lat * 360) / 40000;	//delta lat
	    	listCoord[ii].Lng = (listCoord[ii].Lng * 360) / 40000;	//delta lng
	    	listCoord[ii].Lat = centerLat + listCoord[ii].Lat;
	    	listCoord[ii].Lng = centerLng + listCoord[ii].Lng;
		}
		
		mapRing = new kakao.maps.Polyline({
	          path: [
	              new kakao.maps.LatLng(listCoord[0].Lat, listCoord[0].Lng),
	              new kakao.maps.LatLng(listCoord[1].Lat, listCoord[1].Lng),
	              new kakao.maps.LatLng(listCoord[2].Lat, listCoord[2].Lng)
	          ],
	          strokeWeight: strokeWeight,
	          strokeColor: color,
	          strokeOpacity: 1,
	          strokeStyle: strokeStyle,
	          endArrow: endArraw,
	          zIndex: 10
	    });
		
		mapRing.setMap(pMap);
	}
	
}

function savePhaseInfo()
{
	if(_UpadtePhaseLinkFlag == false)
	{
		var leftturnVal = $('input:checkbox[id="leftturn"]').is(':checked');
		var pedeLineVal = $('input:checkbox[id="pedeLine"]').is(':checked');
		_DegIn = leadingZeros2($('#degIn').val(),$('#degIn').val().length);
		_DegOut = leadingZeros2($('#degOut').val(),$('#degOut').val().length);
		var mapNo = $('#updateMapNo').val();
		
		if(leftturnVal == true) _Leftturn = 'L';
		else
		{
			if(pedeLineVal == true) _Leftturn = 'P';
			else _Leftturn = 'S';
		}
		
		var phaseColumn = _RingSide+'_RING_'+_PhaseNum+'_PHASE_CONF_CD';
		var phaseCd = _Leftturn+_DegIn+_DegOut;
		
		if(phaseCd.length == 1) phaseCd = '';
		
		//현시 저장
		var url = 'savePhaseInfo.do';
		var param = 'regionCd='+_RegionCd+'&intNo='+_IntNo+'&mapNo='+mapNo+'&phaseColumn='+phaseColumn+'&phaseCd='+phaseCd;
		requestService(url, param, savePhaseInfoCallback);
	}
	else
	{
		_LinkId = $('#linkId').val();
		
		//링크아이디 저장
		var linkCd = _RingSide+'_RING_'+_PhaseNum+'_PHASE_'+_LinkSide+'_LINK_CD';
		var linkId = _LinkId;
		if(linkId == '-') linkId = '';
		
		signalArr[0].setLinkPhase(linkId,'');
		
		var url = 'updateLinkCd.do';
		var param = 'regionCd='+_RegionCd+
		            '&intNo='+_IntNo+
		            '&linkId='+linkId+
		            '&linkCd='+linkCd+
		            '&mapNo='+_MapNo;
		requestService(url, param, updateLinkCdCallback);
	}
}

function savePhaseInfoCallback(data) 
{
	getSigInfoPhaseDetail();
	resizePhaseInfo();
}

function updateLinkCdCallback(data) {
	setTimeout(function(){
		linkPhaseLineArr[0].setOptions({strokeColor:'red'});
		linkPhaseLineArr[0].setMap(map);
		resizePhaseInfo();
		getSigInfoPhaseDetail();
	},100);
	setTimeout(function(){$('.linkColor_'+_SelLinkColor).css('background-color','yellow').css('color','red');},300);
}

function phaseOnMap(val) {
	//이전 현시 흔적 삭제..
	phaseBackMap = new HashMap();
	emptyLastPhase();
	_MapNo = val;
	getSigInfoPhaseDetail();
}

function resizePhaseInfo() {
	
	var phaseCd = '';
	var degInVal = leadingZeros2(_DegIn,_DegIn.length);
	var degOutVal = leadingZeros2(_DegOut,_DegOut.length);
	
	phaseCd = _Leftturn+degInVal+degOutVal;
	
	emptySignalArr(signalALineArr);
	emptySignalArr(signalBLineArr);
	emptySignalArr(lineCenterCircleArr);
	
	signalALineArr      = [];
	signalBLineArr      = [];
	lineCenterCircleArr = [];
	
	_ALineCenterArr = [];
	_BLineCenterArr = [];
	
	_BackCircleFlag = false;
	
	if(_RingSide == 'A')
	{
		new SignalDraw(phaseCd, _BRingPhase, _YCoord, _XCoord, _RegionCd, '', '', '', '', '', '', '');
		if(_ALineCenterArr.length > 0)
		{
			if(_UpadtePhaseLinkFlag == false) drawLineCenter(_RingSide);
			signalALineArr[0].setOptions({strokeColor:'red',zIndex:20});
		}
	}
	else
	{
		new SignalDraw(_ARingPhase, phaseCd, _YCoord, _XCoord, _RegionCd, '', '', '', '', '', '', '');
		if(_BLineCenterArr.length > 0)
		{
			if(_UpadtePhaseLinkFlag == false) drawLineCenter(_RingSide);
			signalBLineArr[0].setOptions({strokeColor:'red',zIndex:20});
		}
	}
		
}

function drawLineCenter(ring) {
	var lat = null;
	var lng = null;
	
	if(ring == 'A')
	{
		lat = _ALineCenterArr[0].Lat;
		lng = _ALineCenterArr[0].Lng;
	} 
	else 
	{
		lat = _BLineCenterArr[0].Lat;
		lng = _BLineCenterArr[0].Lng;
	}
		
	var lineCenter = new kakao.maps.Circle({
	    center : new kakao.maps.LatLng(lat, lng),
	    radius: 1.5,
	    strokeWeight: 1,
	    strokeColor: '#000000',
	    strokeOpacity: 1,
	    strokeStyle: 'solid',
	    fillColor: 'yellow',
	    fillOpacity: 1,
	    zIndex: 30
	});
	lineCenter.setMap(map);
	lineCenterCircleArr.push(lineCenter);
}

function getIntNo(regionCd,levelFlag) {
	if(regionCd == '')
	{
		initUpdateSignal('region','','');
	}
	_LevelFlag = levelFlag;

	var regionNm = $('#centerList option:selected').text();
	$('#addRegionCd option:contains("'+regionNm+'")').prop('selected',true);
	
	var url = 'getIntNo.do';
	var params = 'regionCd='+regionCd;
	requestService(url, params, getIntNoCallback);
}

function getIntNoCallback(data) {
	if(data.length > 0)
	{
		var str = '';
		str += '<option value="">선택</option>';
		for(var ii = 0; ii < data.length; ii++)
		{
			var mainIntNo = data[ii].MAIN_INTNO;
			var groupNo   = data[ii].GROUP_NO;
			var xCoord    = String(data[ii].X_COORD);
			var yCoord    = String(data[ii].Y_COORD);
			if(typeof groupNo == 'undefined') groupNo = '';
			str += '<option value="'+data[ii].REGION_CD+'|'+data[ii].REGION_NM+'|'+data[ii].INT_NO+'|'+data[ii].INT_NM+'|'+xCoord+'|'+yCoord+'|'+groupNo+'|'+mainIntNo+'|'+data[ii].SIGUNGU_CD+'|'+data[ii].INT_LCTYPE+'|'+data[ii].INT_LAMPTYPE+'|'+data[ii].INT_MAINPHASE+'|'+data[ii].NETWORK_TYPE+'|'+data[ii].MODEM_IP+'">'+data[ii].INT_NO+'_'+data[ii].INT_NM+'</option>';
		}
		$('#intList').empty().html(str);
		
		if(_LevelFlag == true)
		{
			map.setCenter(new kakao.maps.LatLng(data[0].REGION_Y, data[0].REGION_X));
			if(map.getLevel() == 4) mapZoomBound();
			else map.setLevel(4);
		}
		else
		{
			intNoCallBack();
		}
	}
}

function intNoCallBack() {
	$('#intList option:contains("'+_IntNo+'_'+_IntNm+'")').prop('selected',true);
	var regionGuCd = _RegionCd + ',' + _SigunguCd;
	$('#addRegionCd option[value="'+regionGuCd+'"]').prop('selected',true);
}

function initUpdateSignal(flag) {
	if(flag == 'region') $('#intList').empty().html('<option>선택</option>');
	$('.table_cover').show();
	$('.table_type3').css('opacity',0.5);
	$('.addsig_bottom_btns').css('opacity',0.5);
	_RegionCd = '';
	_Level = 3;
	_XCoord = '127.0626736';
	_YCoord = '37.4972515';
	_circleSize = 25;
	_circleStroke = 4;
	
	initUpdateMap();
	
	return;
}

//엑셀다운로드 인트넘버...
function getDownloadIntNo(id,pageCnt) {
	var url = 'getIntNo.do';
	var params = 'regionCd='+id;
	requestService(url, params, getDownloadIntNoCallback);
}

function getDownloadIntNoCallback(data) {
	if(data.length > 0)
	{
		var str = '';
		str += '<option value="">선택</option>';
		for(var ii = 0; ii < data.length; ii++)
		{
			str += '<option value="'+data[ii].INT_NO+'">'+data[ii].INT_NO+'_'+data[ii].INT_NM+'</option>';
		}
		$('#strtIntNo').empty().html(str);
		$('#endIntNo').empty().html(str);
	}
}

$(document).on('keyup mouseup', '#degIn', function(e) {
	var leftturnVal = $('input:checkbox[id="leftturn"]').is(':checked');
	var pedeLineVal = $('input:checkbox[id="pedeLine"]').is(':checked');
	_DegIn = $('#degIn').val();
	_DegOut = $('#degOut').val();
	
	if(pedeLineVal == true)
	{
		_Leftturn = 'P';
	}
	else
	{
		if(leftturnVal == true) _Leftturn = 'L';
		else _Leftturn = 'S';
	}
	removeChar(e);
	resizePhaseInfo();
});
	
$(document).on('keyup mouseup', '#degOut', function(e) {
	var leftturnVal = $('input:checkbox[id="leftturn"]').is(':checked');
	var pedeLineVal = $('input:checkbox[id="pedeLine"]').is(':checked');
	_DegIn = $('#degIn').val();
	_DegOut = $('#degOut').val();
	
	if(pedeLineVal == true)
	{
		_Leftturn = 'P';
	}
	else
	{
		if(leftturnVal == true) _Leftturn = 'L';
		else _Leftturn = 'S';
	}
	removeChar(e);
	resizePhaseInfo();
});

$(document).on('click', '#leftturn',function() {
	_DegIn = $('#degIn').val();
	_DegOut = $('#degOut').val();
	
	if($("#pedeLine").is(":checked"))
	{
		_Leftturn = 'P';
    }
	else
	{
		if($("#leftturn").is(":checked"))
		{
			_Leftturn = 'L';
		} 
		else _Leftturn = 'S';
    }
	
	resizePhaseInfo();
});

$(document).on('click','#pedeLine',function() {
	_DegIn = $('#degIn').val();
	_DegOut = $('#degOut').val();
	
	if($("#pedeLine").is(":checked"))
	{
		_Leftturn = 'P';
    }
	else
	{
		if($("#leftturn").is(":checked")) _Leftturn = 'L';
		else _Leftturn = 'S';
    }
	
	resizePhaseInfo();
});

/*서울시 신호좌표데이터 각도데이터로 변경*/

function transAngle() {
	console.log('--------------------------------transAngle Start--------------------------------------');
	var url = 'transAngle.do';
	var param = '';
	requestService(url, param, transAngleCallback);
}

function transAngleCallback(data) {
	console.log('success!!');
}
