/****************************************************************************************************
* 돌발인포윈도우
* @param Icon
* @param points
* @param title
* @param temp : ims(돌발) trouble(전면통제)
****************************************************************************************************/
function getImsPop(Icon, points, title, temp) {
	
	//돌발타입
	var typeCd   = "";
	var str	     = "";
	var getTitle = "";
	var topTitle = nvl(points[4], "");
	var title	 = nvl(points[4], "");			
	var title2	 = nvl(points[5], "");
	var imsImagePath = nvl(points[8], "");
	var incidentId = nvl(points[2], "");
   	 
	$("#imsTopNm").html("");
	$("#getTitle").html("");
	$("#getStart").html("");
	$("#getEnd").html("");
	
	typeCd = nvl(points[3], "");
	
	if(typeCd == '1') {
		
		str	+= '[사고]';
		
	}else if(typeCd == '2') {
		
		str	+= '[공사]';
		
	}else if(typeCd== '3') {
		
		str	+= '[행사]';
		
	}else if(typeCd == '4') {
		
		str	+= '[기상]';
		
	}else if(typeCd == '5') {
		
		str	+= '[통제]';
	}
	
	if(topTitle != "" && (topTitle.indexOf("::") > 0)) {
		topTitle = topTitle.split("::");
		var topTileChk = nvl(topTitle[3], "");
		if(topTileChk != ""){
			topTitle = str + topTitle[3].replace(/::/g,'&nbsp;');
		}
	}
	
	if(title != "") {
		
		title = title.replace(/::/g,'&nbsp;');
	}
	
	if(title2 != "") {
		
		title2 = points[5].replace(/::/g,'&nbsp;');
	}
	
	if(title != title) {
		
		getTitle = title + title2;
		
	}else {
		
		getTitle = title;
	}
	
	if(topTitle.length > 24) {
		
		fnSubString(topTitle, 0, 24);
	}
	
	/*console.log("====================================================================");
	console.log("points : " + points);
	console.log("points[2] : " + points[2]);
	console.log("points[0] : " + points[0] + ":::" + "points[1] >>" + points[1]);
	console.log("====================================================================");*/
	
	var imsTopNm = "<img src=\""+ CONTEXTROOT +"/images/icon01.gif\" alt=\"타이틀 블릿\"/>" + nvl(topTitle, points[4]);
	
	var str  = "<div class=\"pop_box\">";
		str += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" summary=\"팝업 상황박스입니다.\" class=\"pop_table\">";
		str += "<caption>현황페이지</caption>";
		str += "<colgroup>";
		str += "<col style=\"width:15%;\">";
		str += "<col style=\"width:*\">";
		str += "</colgroup>";
		str += "<thead>";
		str += "<tr>";
		str += "<th colspan=\"2\" id=\"imsTopNm\">"+ imsTopNm +"</th>";
		str += "</tr>";
		str += "</thead>";
		str += "<tbody>";
		str += "<tr>";
		str += "<td><span>제목:</span></td>";
		str += "<td id=\"getTitle\">"+ getTitle +"</td>";
		str += "</tr>";

		var getImsImage = "http://ims.utic.go.kr/incident/getImageBlob.do?INCIDENT_ID=" + incidentId;
		if(imsImagePath == 'Y'){
			str += "<td><span>사진:</span></td>";
			str += "<td id=\"getImsImage\">";
			str += "<img src=\""+getImsImage+"\" class=\"pop_ims_image\"></td>";
			str += "</td>";
			str += "</tr>";	
		}

		str += "<tr>";
		str += "<td><span>시작:</span></td>";
		str += "<td id=\"getStart\">"+ points[6] +"</td>";
		str += "</tr>";
			
		str += "</tbody>";
		str += "<tfoot>";
		str += "<tr>";
		str += "<td><span>종료:</span></td>";
		str += "<td id=\"getEnd\">"+ points[7] +"</td>";
		str += "</tr>";
		
		str += "</tfoot>";
		str += "</table>";
		str += "<div class=\"arrow_ims\"><img alt=\"\" src=\"" + CONTEXTROOT + "/images/arrow_tooltip.png\"></div>";
		str += "</div>";
	
   	 var position = new kakao.maps.LatLng(points[0],points[1]);
 
   	 
   	 
   	 //돌발
   	 if(temp == "ims") {
   		 
   		 infowindow = new kakao.maps.InfoWindow({
         	   position : position, 
              content: str,
              removable : false,
              zIndex	: 100
          });
          
        infowindow.open(map, Icon);
        
        //돌발링크 구분
        //linkLineEvent(points[9]);
   	 }
   	 
   	 //전면통제
   	 if(temp == "trouble") {
   		 
   		troubleInfoWindow = new kakao.maps.InfoWindow({
   			
						      	   position : position, 
						           content: str,
						           removable : false,
						           zIndex	: 100
					   		});
	       
   		troubleInfoWindow.open(map, Icon);
   	 }
   	 
   	 imsPopOpen = points[0]+'-'+points[1];
}
/****************************************************************************************************
* OBEID 인포윈도우
* @param Icon
* @param points
* @param title
****************************************************************************************************/
function getObePop(Icon, points, title){
	
	var textDate  = points[3].substr(0, 4) + "년 " + points[3].substr(4, 2) + "월 " + points[3].substr(6, 2) + "일 ";
	    textDate += points[3].substr(8, 2) + "시 " + points[3].substr(10, 2) + "분 " + points[3].substr(12, 2) + "초 ";
	
	var str  = "<div class=\"pop_box\" style=\"width:300px;\">";
		str += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" summary=\"OBE 위치정보\" class=\"pop_table\" style=' width:300px;'>";
		str += "<caption>OBE 위치정보</caption>";
		str += "<colgroup>";
		str += "<col style=\"width:18%;\">";
		str += "<col style=\"width:*\">";
		str += "</colgroup>";
		str += "<thead>";
		str += "<tr>";
		str += "<th colspan=\"2\"><img src=\""+ CONTEXTROOT +"/images/icon01.gif\" alt=\"타이틀 블릿\"/>OBE 위치정보</th>";
		str += "</tr>";
		str += "</thead>";
		str += "<tbody>";
		str += "<tr>";
		str += "<td><span>시각:</span></td>";
		str += "<td id=\"getTitle\">"+ textDate +"</td>";
		str += "</tr>";
		str += "<tr>";
		str += "<td><span>ID:</span></td>";
		str += "<td id=\"getStart\">"+ points[2] +"</td>";
		str += "</tr>";
		str += "</tbody>";
		str += "</table>";
		str += "<div class=\"arrow_ims\" style=\"margin-left:-50px;\"><img alt=\"\" src=\"" + CONTEXTROOT + "/images/arrow_tooltip.png\"></div>";
		str += "</div>";
		
	 var position = new kakao.maps.LatLng(points[0],points[1]);
	 
     obeInfowindow = new kakao.maps.InfoWindow({
      	   position : position, 
           content	: str,
           removable: false,
           zIndex	: 100
       });
       
     obeInfowindow.open(map, Icon);
	
}

/**
 * target 문자열이 null이면 대체문자열로 치환
 * @param target
 * @param replace
 * @returns {String}
 */
function nvl(target, replace) {
	
	// return할 값
    var str = "";
    
    try {
    	
    	// target문자열 앞뒤 공백제거
    	var strr = $.trim(target);
    	
    	// null이면 대체문자열로 retun
    	if(!strr || strr == null || strr == "" || strr == "null" || strr == "undefined" || strr == undefined || strr == "") {
    		
    		str = replace;
    	}
    	
    	// 아닌 경우 원래문자열 return
    	else {
    		
    		str = target;
    	}
    }
    
    catch(err) {
    	
    	str = replace;
    }
    
    return str;
}