/**************************************************************
*
* 게시판 내용 조회  관련 Javascript 모음
*
**************************************************************/






// --------------------------- view.jsp ----------------------------

/**
 * 추천유형에 따라 추천 Ajax 호출
 */  
 
function confirmRecommendation(recommendType) {
    globalCommon.alertScriptConfirm("Do you recommend this article?", "yes", "javascript:recommendation('"+recommendType+"')", "javascript:nv.LBox.off()", "no");
}
 
function recommendation(recommendType){
    var viewForm = nv.$("viewForm");
    var recommendationForm = nv.$("recommendationForm");
    
    if(recommendType == 2) {
        for(i=0; i<recommendationForm.recommendPoint.length; i++) {
            if(recommendationForm.recommendPoint[i].checked) {
                viewForm.recommendPoint.value = recommendationForm.recommendPoint[i].value;
                break;
            }
        }
    }
    
    var param = "";
    param += "recommendPoint=" + nv.$("recommendPoint").value;
    param += "&messageId=" + nv.$("messageId").value;
    param += "&boardName=" + nv.$("boardName").value;
 
    new nv.Ajax("recommendation.do", param, callback_Recommendation, "GET", "JSON", recommendType);    
}

/**
 * 추천유형에 따라 추천 Ajax 호출
 */   
 
function confirmRecommendation2(recommendType, id) {
    globalCommon.alertScriptConfirm("Do you recommend this article?", "yes", "javascript:recommendation2('"+recommendType+"','"+id+"')", "javascript:nv.LBox.off()", "no");
} 

function recommendation2(recommendType, id){
	_id=id;
	var viewForm = nv.$("viewForm");
	var recommendationForm = nv.$("recommendationForm");
	
	if(recommendType == 2) {
		for(i=0; i<recommendationForm.recommendPoint.length; i++) {
			if(recommendationForm.recommendPoint[i].checked) {
				viewForm.recommendPoint.value = recommendationForm.recommendPoint[i].value;
				break;
			}
		}
	}
	
	var param = "";
	param += "recommendPoint=" + nv.$("recommendPoint").value;
	param += "&messageId=" + nv.$("messageId_"+id).value;
	param += "&boardName=" + nv.$("boardName").value;
	
	new nv.Ajax("recommendation.do", param, callback_Recommendation2, "GET", "JSON", recommendType);    
}



/**
 * 추천유형에 따라 추천 Ajax 호출 Callback 함수
 */
function callback_Recommendation(resultObj, recommendType){
     if(resultObj.result == "success") {
         nv.LBox.off();
         globalCommon.alertNotice("추천이 등록되었습니다.","");
         // 추천점수 반영
         if(nv.$("recommendCountDiv")) nv.$("recommendCountDiv").innerHTML = resultObj.recommentCount;
         if(nv.$("recommendPointDiv")) nv.$("recommendPointDiv").innerHTML = resultObj.recommendPoint;
     } else if(resultObj.result == "aleady"){
	     nv.LBox.off();         
         globalCommon.alertMsg("추천/반대는 한번만 참여할 수 있습니다.");
     } else if(resultObj.result == "deny"){
	     nv.LBox.off();         
         globalCommon.alertMsg("자신의 글은 추천할수 없습니다.");
     } else {
	     nv.LBox.off();         
         globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
     }
}

/**
 * 추천유형에 따라 추천 Ajax 호출 Callback 함수
 */
function callback_Recommendation2(resultObj, recommendType){
	if(resultObj.result == "success") {
	    nv.LBox.off();
         globalCommon.alertNotice("추천이 등록되었습니다.","");
		// 추천점수 반영
		if(nv.$("recommendCountDiv_"+_id)) nv.$("recommendCountDiv_"+_id).innerHTML = resultObj.recommentCount;
		if(nv.$("recommendPointDiv_"+_id)) nv.$("recommendPointDiv_"+_id).innerHTML = resultObj.recommendPoint;
	} else if(resultObj.result == "aleady"){
	    nv.LBox.off();
		globalCommon.alertMsg("추천/반대는 한번만 참여할 수 있습니다.");
     } else if(resultObj.result == "deny"){
	     nv.LBox.off();         
         globalCommon.alertMsg("자신의 글은 추천할수 없습니다.");		
	} else {
	    nv.LBox.off();
		globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
	}
}



/**
 * 반대 Ajax 호출
 */
 
function confirmObjection() {
    globalCommon.alertScriptConfirm("Do you non-recommend this article?", "yes", "javascript:objection()", "javascript:nv.LBox.off()", "no");
} 
 
function objection() {
    var viewForm = nv.$("viewForm");
    var recommendationForm = nv.$("recommendationForm");
    viewForm.recommendPoint.value = "-1";
    
    var param = "";
    param += "recommendPoint=" + nv.$("recommendPoint").value;
    param += "&messageId=" + nv.$("messageId").value;
    param += "&boardName=" + nv.$("boardName").value;
    param += "&searchText=" + nv.$("searchText").value;
    
    new nv.Ajax("recommendation.do", param, callback_Objection, "GET", "JSON");  
}


/**
 * 반대 Ajax 호출
 */

function confirmObjection2(id) {
    globalCommon.alertScriptConfirm("Do you non-recommend this article?", "yes", "javascript:objection2('"+id+"')", "javascript:nv.LBox.off()", "no");
} 

function objection2(id) {
	_id=id;
	var viewForm = nv.$("viewForm");
	var recommendationForm = nv.$("recommendationForm");
	viewForm.recommendPoint.value = "-1";
	
	var param = "";
	param += "recommendPoint=" + nv.$("recommendPoint").value;
	param += "&messageId=" + nv.$("messageId_"+id).value;
	param += "&boardName=" + nv.$("boardName").value;
	param += "&searchText=" + nv.$("searchText").value;
	
	new nv.Ajax("recommendation.do", param, callback_Objection2, "GET", "JSON");  
}



/**
 * 반대 Ajax 호출 Callback 함수
 */
function callback_Objection(resultObj) {
     if(resultObj.result == "success") {
        nv.LBox.off();
         globalCommon.alertNotice("This article has been non-recommended","");
         // 반대 수 적용
         if(nv.$("objectionCountDiv")) nv.$("objectionCountDiv").innerHTML = resultObj.objectionCount;
     } else if(resultObj.result == "aleady"){
         nv.LBox.off();
         globalCommon.alertMsg("추천/반대는 한번만 참여할 수 있습니다.");
     } else if(resultObj.result == "deny"){
	     nv.LBox.off();         
         globalCommon.alertMsg("자신의 글은 반대할수 없습니다.");         
     } else {
         nv.LBox.off();
         globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
     }

}

/**
 * 반대 Ajax 호출 Callback 함수
 */
function callback_Objection2(resultObj) {
	if(resultObj.result == "success") {
	   nv.LBox.off();
         globalCommon.alertNotice("This article has been non-recommended","");
		// 반대 수 적용
		if(nv.$("objectionCountDiv_"+_id)) nv.$("objectionCountDiv_"+_id).innerHTML = resultObj.objectionCount;
	} else if(resultObj.result == "aleady"){
	    nv.LBox.off();
		globalCommon.alertMsg("추천/반대는 한번만 참여할 수 있습니다.");
     } else if(resultObj.result == "deny"){
	     nv.LBox.off();         
         globalCommon.alertMsg("자신의 글은 반대할수 없습니다.");		
	} else {
	     nv.LBox.off();
		globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
	}
}


  
/**
 * TOP(공지) 메세지 전환 Ajax 호출
 */   
function changeTopFlag(){
    var param = "";
    param += "messageId=" + nv.$("messageId").value; 
    param += "&boardName=" + nv.$("boardName").value; 
    param += "&messageNumber=" + nv.$("messageNumber").value; 
    new nv.Ajax("top.message.do", param, callback_changeTopFlag, "GET", "JSON");
}



/**
 * TOP(공지) 메세지 전환 Ajax 호출 Callback 함수
 */
function callback_changeTopFlag(resultObj) {
    if(resultObj.result == "success"){
        var txt = "공지설정";
        if(resultObj.isTopFlag == "true") {
            globalCommon.alertMsg("공지설정 되었습니다.");
            txt = "공지해제";
        } else {
            globalCommon.alertMsg("공지해제 되었습니다.");
        }
        
        if(nv.$("changeTopFlagDiv")) {
            var htmlTxt = "<a href=\"javascript:changeTopFlag();\" title=\"" + txt +"\">" + txt + "</a>";
            nv.$("changeTopFlagDiv").innerHTML = htmlTxt;
        }
    } else {
        globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
    }
}



/**
 * 메세지 스크랩 Ajax 호출
 */  
function scrap(){
    var param = "";
    param += "boardName=" + nv.$("boardName").value;
    param += "&messageId=" + nv.$("messageId").value;
    
    new nv.Ajax("../../mybbs/scrap/scrap.do", param, callback_Scrap, "POST", "JSON");
} 



/**
 * 메세지 스크랩 Ajax 호출 Callback 함수
 */
function callback_Scrap(resultObj) {
    if(resultObj.result == "success") {
        globalCommon.alertMsg("해당 게시물이 스크랩 되었습니다.");
    } else if(resultObj.result == "aleady") {
        globalCommon.alertMsg("이미 스크랩된 게시물입니다.");
    } else {
        globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
    }
}



/**
 * 메세지 등록 화면으로 이동
 */ 
function write(){
    nv.$("viewForm").action="write.form.do";
    nv.$("viewForm").submit();
}



/*
 * 메세지 답변 등록 화면으로 이동한다.
 */ 
function reply(){
    nv.$("viewForm").action ="write.form.do";
    nv.$("parentMessageId").value = nv.$("messageId").value;
    nv.$("viewForm").submit();
}

/*
 * 답변글에 대한 답글 등록 화면으로 이동한다.
 */ 
function replyMessage(replyMessageId){

    nv.$("viewForm").action ="write.form.do";    
    nv.$("parentMessageId").value =replyMessageId;
    nv.$("viewForm").submit();
}



/*
 * 메세지 수정 화면으로 이동한다.
 */ 
function update(authenticateFlag){
    if(authenticateFlag=='true'){
        nv.$("viewForm").action="update.form.do";
    }else{
       nv.$("viewForm").action="update.password.check.do";    
    }
    nv.$("viewForm").submit();
}

function update2(authenticateFlag, id){
    if(authenticateFlag=='true'){
    	nv.$("parentMessageId").value = nv.$("messageId").value;            
    	nv.$("messageId").value = nv.$("messageId_"+id).value;	
        nv.$("viewForm").action="update.form.do";
    }else{
       nv.$("viewForm").action="update.password.check.do";    
    }
    nv.$("viewForm").submit();
}


/*
 * 상담형 메세지 수정 화면으로 이동한다.
 */ 
function updateReply(replyMessageId){
    nv.$("messageId").value = replyMessageId;
    nv.$("viewForm").action="update.form.do";
    nv.$("viewForm").submit();
}



/*
 * 메세지 삭제 액션을 호출한다.
 */ 
function deleteMessage(authenticateFlag){
    var commentCount = nv.$("commentCountDiv_0").innerHTML;    
    if(commentCount > 0){
        gotoSupport();
    }else{
        if(authenticateFlag == "true") 
        {
            var viewForm = nv.$('viewForm');
            var validator = new nv.Validator(viewForm, globalCommon.alertMsg);
            
            var confirmMessage = 'Are you sure you wnat to delete this article?'  
            var confirmAction = 'delete.do';
            var confirmMethod = 'post';
            
            validator.setConfirmMessage(confirmMessage);
            validator.setConfirmAction(confirmAction, confirmMethod, 'delete', "javascript:nv.LBox.off()", 'cancel');
            validator.confirmValidate(globalCommon.alertConfirm);  
        }
    }
}

/*
 * 메세지 삭제 액션을 호출한다.
 */ 
function deleteMessage2(authenticateFlag, id){
    var commentCount = nv.$("commentCountDiv_"+(id+1)).innerHTML;
    if(commentCount > 0){
        gotoSupport();            
    }else{
    	if(authenticateFlag == "true") 
    	{
            nv.$("messageId").value = nv.$("messageId_"+id).value;
            var validator = new nv.Validator(viewForm, globalCommon.alertMsg);
    
            var confirmMessage = 'Are you sure you wnat to delete this article?'  
            var confirmAction = 'delete.do';
            var confirmMethod = 'post';
            
            validator.setConfirmMessage(confirmMessage);
            validator.setConfirmAction(confirmAction, confirmMethod, 'delete', "javascript:nv.LBox.off()", 'cancel');            
            validator.confirmValidate(globalCommon.alertConfirm);  	    	
    	}
    }
}



/*
 * 상담형 - 답변 메세지 삭제 액션을 호출한다.
 */ 
function deleteReplyMessage(replyMessageId){
    nv.$("viewForm").action="delete.do";
    nv.$("messageId").value = replyMessageId;
    nv.$("viewForm").submit();
}



/*
 * 메세지 목록화면으로 이동한다.
 */ 
function list(){
    nv.$("viewForm").action="list.do";
    nv.$("viewForm").submit();
}


  
/*
 * 메세지 화면으로 이동한다.
 */ 
function viewMessage(messageId, messageNumber) {
    var viewForm = nv.$("viewForm");
    viewForm.action = "view.do";
    viewForm.messageId.value = messageId;
    viewForm.messageNumber.value = messageNumber;
    viewForm.method = "get";
    viewForm.submit();
}



/**
 * 투표형 게시판에서의 투표 처리 Ajax 호출
 */ 
function votePoll() {
    var viewForm = nv.$("viewForm");
    var voteForm = nv.$("voteForm");
    var validator = new nv.Validator(voteForm, globalCommon.alertMsg);
    
    validator.checkAtLeastOneChecked("itemSequence", "투표할 항목을 보기 중에서 선택해 주십시오.", false);
    
    if(validator.validate()) {
        var param = "";
        param += "messageId=" + nv.$("messageId").value;
        param += "&boardName=" + nv.$("boardName").value;
        param += "&searchText=" + nv.$("searchText").value;
        param += "&pollId=" + nv.$("pollId").value;
        param += "&voterKey=" + nv.$("voterKey").value;
        
        var itemSequences = document.getElementsByName("itemSequence");        
        for(i = 0; i < itemSequences.length; i++) {            
            if(itemSequences[i].checked == true) {
                param += "&itemSequence=" + itemSequences[i].value;
                break;
            }            
        }
        
        new nv.Ajax("vote.do", param, callback_VotePoll, "GET", "JSON");
    }  
}



/**
 * 투표형 게시판에서의 투표 처리 Ajax 호출 Callback 함수
 */
function callback_VotePoll(resultObj) {
    if(resultObj.result == "success") {
        globalCommon.alertMsg("투표 하였습니다.");
    } else if(resultObj.result == "aleady"){
        globalCommon.alertMsg("투표는 한번만 참여할 수 있습니다.");
    } else {
        globalCommon.alertMsg("잠시 후 다시 시도해 주십시오.");
    }
}



/**
 * 설문 투표 결과를 보여주는 Ajax 호출
 */ 
function viewResult(messageId){
    var param = "";
    param += "messageId=" + nv.$("messageId").value;
    param += "&boardName=" + nv.$("boardName").value;
    param += "&searchText=" + nv.$("searchText").value;
    
    new nv.Ajax("vote.result.do", param, callback_ViewResult, "GET", "TEXT");
}



/**
 * 설문 투표 결과를 보여주는 Ajax 호출 Callback 함수
 */
function callback_ViewResult(resultObj) {
    nv.LBox.on(resultObj);
}


/**
 * 코멘트 리스트 호출
 */
function viewCommentList() {
  if (nv.$("commentRootDiv").style.display == '') {
      nv.$("commentRootDiv").style.display = 'none';
  } else {
      if (nv.$("trackbackRootDiv")) nv.$("trackbackRootDiv").style.display = 'none';
      nv.$("commentRootDiv").style.display = '';
      getCommentList(1);   
  }  
  
}

/**
 * 코멘트 리스트 호출
 */
function viewCommentList2(id) {
	if (nv.$("commentListDiv_"+id).style.display == '') {
		nv.$("commentListDiv_"+id).style.display = 'none';
	} else {
		if (nv.$("trackbackRootDiv_"+id)) nv.$("trackbackRootDiv_"+id).style.display = 'none';
		nv.$("commentListDiv_"+id).style.display = '';
		getCommentList2(1, id);   
	}  
	
}

/**
 * 엮인글 리스트 호출 
 */
function viewTrackbackList() {
  if (nv.$("trackbackRootDiv").style.display == '') {
      nv.$("trackbackRootDiv").style.display = 'none';
  } else {
      if (nv.$("commentRootDiv")) nv.$("commentRootDiv").style.display = 'none';
      nv.$("trackbackRootDiv").style.display = '';
      getTrackbackList(1);   
  }    
}



// --------------------------- _view_comment.jsp ----------------------------

    /**
     * 코멘트 목록 조회 Ajax 호출
     * @param {string} commentPage 코멘트 페이지
     */
    function getCommentList(commentPage) {
        // DIV 영역을 비운다.
        nv.Dom.removeChildNodes(nv.$("commentListDiv"));
        nv.Dom.removeChildNodes(nv.$("commentPagingDiv"));
        
        var param = "";
        param += "messageId=" + nv.$("commentForm").messageId.value;
        param += "&boardName=" + nv.$("commentForm").boardName.value;
        param += "&curViewPage=" + commentPage;
        new nv.Ajax("comment.list.do", param, callback_CommentList, "GET", "JSON", commentPage); 
    }
    
    /**
     * 코멘트 목록 조회 Ajax 호출2
     * @param {string} commentPage 코멘트 페이지
     */
    var _id;
    function getCommentList2(commentPage, id) {
    	// DIV 영역을 비운다.

    	nv.Dom.removeChildNodes(nv.$("commentListDiv_"+id));
    	nv.Dom.removeChildNodes(nv.$("commentPagingDiv_"+id));
    	_id=id;

    	var param = "";
    	param += "messageId=" + nv.$("commentForm_"+id).messageId.value;
    	param += "&boardName=" + nv.$("commentForm_"+id).boardName.value;
    	param += "&curViewPage=" + commentPage;
    	new nv.Ajax("comment.list.do", param, callback_CommentList2, "GET", "JSON", commentPage); 
    }
    
    /**
     * 코멘트 목록 콜백
     * @param {object} resultObj Ajax 결과 JSON 객체
     * @param {string} commentPage 코멘트 페이지
     */
    function callback_CommentList(resultObj, commentPage) {
    	
        if(resultObj.result == "success") {
            // 페이지에 결과가 없을경우 이전 페이지 조회
            if(commentPage > 1 && resultObj.data.length < 1) {
                getCommentList(commentPage-1);
                return;
            }
            
            // 등록된 코멘트 div 생성
            for(var i=0; i<resultObj.data.length; i++) {
                var commentObj = resultObj.data[i];
                // 코멘트를 감싸는 엘리먼트
                var commentBoxElement = nv.$("commentListDiv");

                // 코멘트 레벨에 따라 감싸는 div를 겹겹이 쌓는다.
                for(var j=1; j<commentObj.commentLevel; j++) {
                    var tempElement = document.createElement("div");
                    tempElement.className = "comment_view";
                    commentBoxElement.appendChild(tempElement);
                    commentBoxElement = tempElement;
                }
                
                // div 생성
                var commentElement = document.createElement("div");
                commentElement.setAttribute("id", "commentDiv_" + commentObj.commentId);
                
                // 코멘트 레벨에 따른 class명 부여
                if(commentObj.commentLevel > 1) { 
                    commentElement.className = "re_comment_view";
                } else {
                    commentElement.className = "comment_view";
                    
                    // 구분선 표시
                    if(i != 0) {
                        var lineElement = document.createElement("div");
                        lineElement.className = "re_comment_line";
                        commentBoxElement.appendChild(lineElement);
                    }
                }
                
                commentBoxElement.appendChild(commentElement);
                
                // 댓글 div 영역 HTML 텍스트
                var htmlTxt = "";
                htmlTxt += "<div class=\"head\">";
                htmlTxt += "    <div class=\"emoticon\"><img src=\""  + imageServer + "/images/bbs/emoticon/" + commentObj.emoticonId + ".gif\"></div>";
                htmlTxt += "    <div class=\"info\">";
                htmlTxt += "        <div class=\"writer\">" + commentObj.registerNickname + "</div>";
                htmlTxt += "        <div class=\"date\">(" + commentObj.registerDate.detailDate + ")</div>";
                // 삭제버튼
                if(commentObj.registerId == nv.$("commentForm").userKey.value || nv.$("commentForm").availableManageFlag.value == "true") {
                    if(commentObj.registerId == nv.$("anonymousId").value && nv.$("commentForm").availableManageFlag.value == "false") {  // 익명 댓글일 경우
                        htmlTxt += "<div class=\"btn_x\"><a onclick=\"openAnonymousComment('" + commentObj.commentId + "', this);\" style=\"cursor: pointer;\"><img src=\""  + imageServer + "/images/bbs/btn_x.gif\" id=\"deletePasswordCommentBtnImg\"></a></div>";
                    } else {
                        htmlTxt += "<div class=\"btn_x\"><a href=\"javascript:confirmDeleteComment('" + commentObj.commentId + "');\"><img src=\""  + imageServer + "/images/bbs/btn_x.gif\"></a></div>";
                    }
                }
                // 댓댓글 버튼
                if(nv.$("commentForm").availableCommentFlag.value == "true") {
                    htmlTxt += "        <div class=\"btn_x\"><a href=\"javascript:openChildCommentForm('" + commentObj.commentId + "');\"><img src=\""  + imageServer + "/images/bbs/btn_re.gif\"></a></div>";
                }
                htmlTxt += "    </div>";
                htmlTxt += "</div>";
                htmlTxt += "<div class=\"clear\"></div>";
                htmlTxt += "<div class=\"read\">" + commentObj.contents + "</div>";
                
                commentElement.innerHTML = htmlTxt;
            }  // ~for(i)
            
            // 변경된 페이지를 기억
            nv.$("commentForm").curViewPage.value = commentPage;
            
            // 페이징을 재생성
            //drawPaging2();
            
            // 코멘트 수 갱신
            if(nv.$("commentCountDiv")) {
                 nv.$("commentCountDiv").innerHTML =nv.$("commentForm").commentCount.value;
            }
        } else {
            globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
        }
    }
    
    /**
     * 코멘트 목록 콜백2
     * @param {object} resultObj Ajax 결과 JSON 객체
     * @param {string} commentPage 코멘트 페이지
     */
    function callback_CommentList2(resultObj, commentPage) {
    	if(resultObj.result == "success") {
    		// 페이지에 결과가 없을경우 이전 페이지 조회
    		if(commentPage > 1 && resultObj.data.length < 1) {
    			getCommentList2(commentPage-1, _id);
    			return;
    		}
    		var commentBoxElement = nv.$("commentListDiv_"+_id);
    		// 등록된 코멘트 div 생성
    		var htmlTxt = "";
    		for(var i=0; i<resultObj.data.length; i++) {
    			var commentObj = resultObj.data[i];
                
                // 댓글 div 영역 HTML 텍스트
    			if(i > 0){
    			     htmlTxt += "<div class=\"mgt10 clearfix mgl12\">";
    			}else{
    			     htmlTxt += "<div class=\"mgt8 clearfix mgl12\">";
    			}
    			htmlTxt += "<div class=\"floatl\"><a href=\"#.\"><img src=\""  + commentObj.registePicture + "\" alt=\"\" class=\"borderw\" width=\"29px\" height=\"29px\"/></a></div>";
    			htmlTxt += "<div class=\"floatr box_co01\">";
                htmlTxt += "    <div class=\"clearfix\">";
                htmlTxt += "		<div class=\"floatl\"><a href=\"#.\" class=\"pink\">" + commentObj.registerNickname + "</a> <span class=\"bul_grgap basic9 gray5c\">" + commentObj.tranRegisterDate + "</span></div>";
                // 삭제버튼
    			if(commentObj.registerId == nv.$("commentForm_"+_id).userKey.value || nv.$("commentForm_"+_id).availableManageFlag.value == "true") {
                    htmlTxt += "		<a href=\"javascript:confirmDeleteComment2('" + commentObj.commentId + "','"+_id+"');\" class=\"dp_b closex floatr\"><img src=\""  + imageServer + "/img/common/mygallery/btn_x4.gif\" alt=\"delete\" /></a>";
    			}
    			
                htmlTxt += "        </div>";
                htmlTxt += "        <p class=\"basic10 graya9 ln_h_12\">"+commentObj.contents +"</p>";
                htmlTxt += "    </div>";	
    			htmlTxt += "</div>";
    		}  // ~for(i)
    		
    		htmlTxt += "<div class=\"mgt10 clearfix mgl12\">";
            htmlTxt += "    <div class=\"floatl\"><a href=\"#.\"><img src=\"/common/myprofile/profile/image.do?userId="+nv.$("commentForm_"+_id).userKey.value+"&mode=small\" width=\"29px\" height=\"29px\" alt=\"\" class=\"borderw\" /></a></div>";
            htmlTxt += "    <div class=\"floatr\">";
            htmlTxt += "        <textarea name=\"contents\" class=\"borderw textarea5 mgr1\" style=\"width:584px; height:31px; #margin-top:-2px;\" onFocus=\"this.value=''\"></textarea>";
            if(nv.$("authenticateUserFlag_"+_id).value == "true"){
                htmlTxt += "<a href=\"javascript:writeComment2('"+_id+"');\"><img src=\""+imageServer+"/img/community/learn/btn_comment.gif\" alt=\"댓글 달기\" class=\"vert\" /></a>";
            }else{
    		    htmlTxt += "<a href=\"javascript:goLoginPage('"+ nv.$("loginUrl").value +"');\"><img src=\""+imageServer+"/img/community/learn/btn_comment.gif\" alt=\"댓글 달기\" class=\"vert\" /></a>";
    		}
            htmlTxt += "    </div>";
            htmlTxt += "</div>";
    		
    		commentBoxElement.innerHTML = htmlTxt;

    		// 변경된 페이지를 기억
    		nv.$("commentForm_"+_id).curViewPage.value = commentPage;

    		// 페이징을 재생성
    		//drawPaging2();
    		
    		// 코멘트 수 갱신
    		if(nv.$("commentCountDiv_"+_id)) {
    			nv.$("commentCountDiv_"+_id).innerHTML = nv.$("commentForm_"+_id).commentCount.value;
    		}
    	} else {
    		globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
    	}
    }
   
    /**
     * 페이징 링크를 표시
     */ 
    function drawPaging() {
    	// 페이지당 표시 건수
    	var pageCount = nv.$("commentForm").commentListLines.value;
    	// 페이징
    	var commentPagingElement = document.createElement("div");
    	commentPagingElement.setAttribute("align", "center");
    	// 페이징 div를 비운다.
    	nv.Dom.removeChildNodes(nv.$("commentPagingDiv"));
    	// 페이징 div에 재생성한 페이징 엘리먼트를 추가한다.
    	nv.$("commentPagingDiv").appendChild(commentPagingElement);
    	// 페이지 계산. 소수점은 올림처리한다.
    	var totalPage = Math.ceil(nv.$("commentForm").commentCount.value / pageCount);
    	// 이전/다음 페이지이동 계산
    	var pageSetNum = Math.ceil(nv.$("commentForm").curViewPage.value / pageCount);
    	var endPage = pageSetNum * 10;
    	var startPage = endPage - 9; 
    	
    	// 페이징 링크 텍스트 생성
    	var pageTxt = "";
    	// 이전 페이징 이미지 버튼
    	if(endPage > 10) {
    		pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList(1);\" title=\"첫 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_pre.gif\"></a></span>";
    		pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList(" + (endPage-10) + ")\" title=\"이전 10 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_pre_1.gif\"></a></span>";
    	}
    	
    	if(endPage > totalPage) endPage = totalPage;
    	for(var i=startPage; i<=endPage; i++) {
    		if(i != startPage) pageTxt += " | "
    			if(i == nv.$("commentForm").curViewPage.value) {
    				pageTxt += "<span class=\"view\">" + i + "</span>";
    			} else {
    				pageTxt += "<span><a href=\"javascript:getCommentList('" + i + "');\" title=\"" + i + " 페이지로 이동\">" + i + "</a></span>";
    			}
    	}
    	// 다음 페이징 이미지 버튼
    	if(totalPage > endPage) {
    		pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList(" + (startPage+10) + ");\" title=\"다음 10 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_next_1.gif\"></a></span>";
    		pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList(" + (totalPage) + ");\" title=\"마지막 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_next.gif\"></a></span>";
    	}
    	
    	commentPagingElement.innerHTML = pageTxt;
    }    
    
    /**
     * 페이징 링크를 표시
     */ 
    function drawPaging2() {
        // 페이지당 표시 건수
        var pageCount = nv.$("commentForm_"+_id).commentListLines.value;
        // 페이징

        var commentPagingElement = document.createElement("div");
        commentPagingElement.setAttribute("align", "center");
        // 페이징 div를 비운다.
        nv.Dom.removeChildNodes(nv.$("commentPagingDiv_"+_id));
        // 페이징 div에 재생성한 페이징 엘리먼트를 추가한다.

        nv.$("commentPagingDiv_"+_id).appendChild(commentPagingElement);
        // 페이지 계산. 소수점은 올림처리한다.
        var totalPage = Math.ceil(nv.$("commentForm_"+_id).commentCount.value / pageCount);
        // 이전/다음 페이지이동 계산
        var pageSetNum = Math.ceil(nv.$("commentForm_"+_id).curViewPage.value / pageCount);
        var endPage = pageSetNum * 10;
        var startPage = endPage - 9; 

        // 페이징 링크 텍스트 생성
        var pageTxt = "";
        // 이전 페이징 이미지 버튼
        if(endPage > 10) {
            pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList2(1,'" + _id + "');\" title=\"첫 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_pre.gif\"></a></span>";
            pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList2(" + (endPage-10) + ",'" + _id + "')\" title=\"이전 10 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_pre_1.gif\"></a></span>";
        }
        
        if(endPage > totalPage) endPage = totalPage;
        for(var i=startPage; i<=endPage; i++) {
            if(i != startPage) pageTxt += " | "
            if(i == nv.$("commentForm_"+_id).curViewPage.value) {
                pageTxt += "<span class=\"view\">" + i + "</span>";
            } else {
                pageTxt += "<span><a href=\"javascript:getCommentList2('" + i + "','" + _id + "');\" title=\"" + i + " 페이지로 이동\">" + i + "</a></span>";
            }
        }
        // 다음 페이징 이미지 버튼
        if(totalPage > endPage) {
            pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList2(" + (startPage+10) + ",'" + _id + "');\" title=\"다음 10 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_next_1.gif\"></a></span>";
            pageTxt += "<span class=\"paging_btn\"><a href=\"javascript:getCommentList2(" + (totalPage) + ",'" + _id + "');\" title=\"마지막 페이지\"><img src=\""  + imageServer + "/images/bbs/btn_next.gif\"></a></span>";
        }

        commentPagingElement.innerHTML = pageTxt;
    }
    

    
    /**
     * 코멘트 등록 Ajax 호출
     */
    function writeComment() {

        // 내용 입력 체크
        var validator = new nv.Validator(nv.$("commentForm"), globalCommon.alertNotice);
        validator.checkRequired("contents", "댓글 내용을 입력해 주세요.", true);
        validator.checkMaxLengthByte("contents", 3000, 3, "댓글은 3000바이트까지 등록 가능합니다.");
        // 비로그인 등록시
        if(nv.$("availableCommentFlag").value == "true" && nv.$("authenticateUserFlag").value == "false") {
            validator.checkRequired("registerNickname", "닉네임을 입력해 주세요.", true);
            validator.checkRequired("anonymousPassword", "비밀번호를 입력해 주세요.", true);
        }
        if(!validator.validate()) return;
    
        var param = "";
        param += "messageId=" + nv.$("commentForm").messageId.value;
        param += "&boardName=" + nv.$("commentForm").boardName.value;
        param += "&emoticonId=" + nv.$("commentForm").emoticonId.value;
        param += "&contents=" + nv.$("commentForm").contents.value;
        
        // 비로그인 등록시
        if(nv.$("availableCommentFlag").value == "true" && nv.$("authenticateUserFlag").value == "false") {
            param += "&registerNickname=" + nv.$("commentForm").registerNickname.value;
            param += "&anonymousPassword=" + nv.$("commentForm").anonymousPassword.value;
        }
        new nv.Ajax("comment.write.do", param, callback_WriteComment, "POST", "JSON");
    }
    
    /**
     * 코멘트 등록 Ajax 호출
     */
    function writeComment2(id) {
    	_id=id;
    	// 내용 입력 체크
    	var validator = new nv.Validator(nv.$("commentForm_"+id), globalCommon.alertNotice);
    	validator.checkRequired("contents", "댓글 내용을 입력해 주세요.", true);
    	validator.checkMaxLengthByte("contents", 3000, 3, "댓글은 3000바이트까지 등록 가능합니다.");

    	if(!validator.validate()) return;
    	
    	var param = "";
    	param += "messageId=" + nv.$("commentForm_"+id).messageId.value;
    	param += "&boardName=" + nv.$("commentForm_"+id).boardName.value;
    	param += "&emoticonId=" + nv.$("commentForm_"+id).emoticonId.value;
    	param += "&contents=" + nv.$("commentForm_"+id).contents.value;

    	new nv.Ajax("comment.write.do", param, callback_WriteComment2, "POST", "JSON");
    }
    
    /**
     * 코멘트 등록 콜백
     * @param {object} resultObj 결과 JSON 객체
     */
    function callback_WriteComment(resultObj) {
        if(resultObj.result == "success") {
            // 입력란 초기화
            nv.$("commentForm").contents.value = "";
            // 비로그인 등록시
            if(nv.$("availableCommentFlag").value == "true" && nv.$("authenticateUserFlag").value == "false") {
                nv.$("commentForm").registerNickname.value = "";
                nv.$("commentForm").anonymousPassword.value = "";
            }
            
            // 코멘트 수 증가
            nv.$("commentForm").commentCount.value = parseInt(nv.$("commentForm").commentCount.value) + 1;
            // 페이징 재생성  
            drawPaging();
            // 1페이지로 이동
            getCommentList(1);
        } else {
            globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
        }
    }
    
    /**
     * 코멘트 등록 콜백
     * @param {object} resultObj 결과 JSON 객체
     */
    function callback_WriteComment2(resultObj) {

    	if(resultObj.result == "success") {
    		// 입력란 초기화
    		nv.$("commentForm_"+_id).contents.value = "";
    		// 비로그인 등록시
    		if(nv.$("availableCommentFlag_"+_id).value == "true" && nv.$("authenticateUserFlag_"+_id).value == "false") {
    			nv.$("commentForm_"+_id).registerNickname.value = "";
    			nv.$("commentForm_"+_id).anonymousPassword.value = "";
    		}
    		
    		// 코멘트 수 증가
    		nv.$("commentForm_"+_id).commentCount.value = parseInt(nv.$("commentForm_"+_id).commentCount.value) + 1;
    		// 페이징 재생성
    		//drawPaging2();
    		// 1페이지로 이동
    		getCommentList2(1, _id);
    	} else {
    		globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
    	}
    }
    
    /**
     * 댓댓글 등록폼 표시
     * @param {string} commentId 댓글 ID
     */ 
    function openChildCommentForm(commentId) {
        // 열려있는 댓댓글 폼을 없앤다.
        nv.Dom.removeNode(nv.$("childCommentFormDiv"));
        
        var childCommentFormDiv = document.createElement("div"); 
        childCommentFormDiv.setAttribute("id", "childCommentFormDiv");
        childCommentFormDiv.className = "re_comment_wirite";
        nv.$("commentDiv_" + commentId).appendChild(childCommentFormDiv);
        
        // 댓댓글 등록폼 HTML 텍스트
        var htmlTxt = "";
        htmlTxt += "<div>";
        htmlTxt += "<table border=\"0\" class=\"w100\">";
        htmlTxt += "    <tr>";
        htmlTxt += "        <td class=\"comment_write_l\"><div class=\"re_comment_ti\">답글</div></td>";
        htmlTxt += "        <td class=\"comment_write_l\">";
        htmlTxt += "            <img src=\""  + imageServer + "/images/bbs/emoticon/" + nv.$("commentForm").childEmoticonId.value + ".gif\" id=\"childEmoticonImg\">";
        htmlTxt += "            <img src=\""  + imageServer + "/images/bbs/i_re_down.gif\" id=\"childEmoticonOpenImg\" onclick=\"openEmoticonDiv(this, true);\" style=\"cursor: pointer;\">";
        htmlTxt += "        </td>";
        htmlTxt += "        <td class=\"comment_write_r\"><textarea name=\"childContents\" id=\"childContents\"></textarea></td>";
        htmlTxt += "        <td class=\"comment_write_btn\"><a href=\"javascript:writeChildComment('" + commentId + "');\"><img src=\""  + imageServer + "/images/bbs/btn_s_register.gif\"></a></td>";
        htmlTxt += "    </tr>";
        htmlTxt += "</table>";
        htmlTxt += "</div>";
        
        // 비로그인 등록시
        if(nv.$("availableCommentFlag").value == "true" && nv.$("authenticateUserFlag").value == "false") {
            htmlTxt += "<div class=\"nonmember\" align=\"right\">";
            htmlTxt += "<table cellpadding=\"0\" cellspacing=\"0\">";
            htmlTxt += "    <tr>";
            htmlTxt += "        <td><div class=\"nonmember_td1\">닉네임</div></td>";
            htmlTxt += "        <td class=\"nonmember_td2\"><input type=\"text\" class=\"write_input\" name=\"childRegisterNickname\" id=\"childRegisterNickname\" maxlength=\"20\" /></td>";
            htmlTxt += "        <td><div class=\"nonmember_td1\">비밀번호</div></td>";
            htmlTxt += "        <td class=\"nonmember_td2\"><input type=\"password\" class=\"write_input\" name=\"childAnonymousPassword\" id=\"childAnonymousPassword\" maxlength=\"20\" /></td>";
            htmlTxt += "    </tr>";
            htmlTxt += "</table>";
            htmlTxt += "</div>";
        }
        
        childCommentFormDiv.innerHTML = htmlTxt;
        
        nv.$("childContents").focus();
    }

    /**
     * 댓댓글 등록 Ajax 호출
     * @param {string} parentCommentId 부모 댓글 ID
     */
    function writeChildComment(parentCommentId) {
        // 내용 입력 체크
        var validator = new nv.Validator(nv.$("commentForm"), globalCommon.alertMsg);
        validator.checkRequired("childContents", "댓글 내용을 입력해 주세요.", true);
        validator.checkMaxLengthByte("childContents", 3000, 3, "댓글은 3000바이트까지 등록 가능합니다.");
        // 비로그인 등록시
        if(nv.$("availableCommentFlag").value == "true" && nv.$("authenticateUserFlag").value == "false") {
            validator.checkRequired("childRegisterNickname", "닉네임을 입력해 주세요.", true);
            validator.checkRequired("childAnonymousPassword", "비밀번호를 입력해 주세요.", true);
        }
        if(!validator.validate()) return;
        
        var param = "";
        param += "messageId=" + nv.$("commentForm").messageId.value;
        param += "&boardName=" + nv.$("commentForm").boardName.value;
        param += "&emoticonId=" + nv.$("commentForm").childEmoticonId.value;
        param += "&parentCommentId=" + parentCommentId;
        param += "&contents=" + nv.$("commentForm").childContents.value;
        // 비로그인 등록시
        if(nv.$("availableCommentFlag").value == "true" && nv.$("authenticateUserFlag").value == "false") {
            param += "&registerNickname=" + nv.$("commentForm").childRegisterNickname.value;
            param += "&anonymousPassword=" + nv.$("commentForm").childAnonymousPassword.value;
        }
        
        new nv.Ajax("comment.write.do", param, callback_WriteChildComment, "POST", "JSON");    
    }
    
    /**
     * 댓댓글 등록 콜백
     * @param {object} resultObj 결과 JSON 객체
     */
    function callback_WriteChildComment(resultObj) {
        if(resultObj.result == "success") {
            // 코멘트 수 증가
            nv.$("commentForm").commentCount.value = parseInt(nv.$("commentForm").commentCount.value) + 1;
            // 페이징 재생성  
            drawPaging();
            // 현재 페이지를 리로딩
            getCommentList(nv.$("commentForm").curViewPage.value);
        } else {
            globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
        }
    }    
    
    function openAnonymousComment(commentId, element) {
        
        nv.$("commentForm").commentId.value = commentId;
        
        // 버튼 엘리먼트의 좌표 획득
        var elementXY = nv.UI.getXY(element);
        
        // 위치 변경
        var commentPasswordDeleteDiv = nv.$("commentPasswordDeleteDiv");
        commentPasswordDeleteDiv.style.left = (elementXY.x) + "px"; 
        commentPasswordDeleteDiv.style.top = (elementXY.y) + "px";
        
        commentPasswordDeleteDiv.style.display = "inline";
    }
    
    function hideDeleteAnonymousCommentDiv() {
        var commentPasswordDeleteDiv = nv.$("commentPasswordDeleteDiv");
        nv.$("commentAnonymousPassword").value = "";
        commentPasswordDeleteDiv.style.display = "none"; 
    }
    
    function deleteAnonymousComment() {
        
        var validator = new nv.Validator(nv.$("commentForm"), globalCommon.alertMsg);
        validator.checkRequired("commentAnonymousPassword", "비밀번호를 입력해 주세요.", true);
        if(!validator.validate()) return;

        var param = "";
        param += "commentId=" + nv.$("commentForm").commentId.value;
        param += "&messageId=" + nv.$("commentForm").messageId.value;
        param += "&boardName=" + nv.$("commentForm").boardName.value;
        param += "&anonymousPassword=" + nv.$("commentAnonymousPassword").value;
        new nv.Ajax("comment.delete.do", param, callback_DeleteComment, "POST", "JSON");
        
        hideDeleteAnonymousCommentDiv();        
    }
    
    /**
     * 댓글 삭제 Ajax 호출
     * @param {string} commentId 댓글 ID
     */

    function confirmDeleteComment(commentId) {
        globalCommon.alertScriptConfirm("Are you sure you want to delete this comment?", "delete", "javascript:deleteComment('"+commentId+"')", "javascript:nv.LBox.off()", "cancel");
    }
     
    function deleteComment(commentId) {
        var param = "";
        param += "commentId=" + commentId;
        param += "&messageId=" + nv.$("commentForm").messageId.value;
        param += "&boardName=" + nv.$("commentForm").boardName.value;
        new nv.Ajax("comment.delete.do", param, callback_DeleteComment, "POST", "JSON");
    }
    /**
     * 댓글 삭제 Ajax 호출
     * @param {string} commentId 댓글 ID
     */

    function confirmDeleteComment2(commentId, id) {
        globalCommon.alertScriptConfirm("Are you sure you want to delete this comment?", "delete", "javascript:deleteComment2('"+commentId+"','"+id+"')", "javascript:nv.LBox.off()", "cancel");
    }
     
    function deleteComment2(commentId, id) {
    	_id=id;
    	var param = "";
    	param += "commentId=" + commentId;
    	param += "&messageId=" + nv.$("commentForm_"+id).messageId.value;
    	param += "&boardName=" + nv.$("commentForm_"+id).boardName.value;
    	new nv.Ajax("comment.delete.do", param, callback_DeleteComment2, "POST", "JSON");
    }
    
    /**
     * 댓글 삭제 콜백
     * @param {object} resultObj 결과 JSON 객체
     */
    function callback_DeleteComment(resultObj) {
        if(resultObj.result == "success") {
	        nv.LBox.off();  
            // 코멘트 수 감소
            nv.$("commentForm").commentCount.value = parseInt(nv.$("commentForm").commentCount.value) - 1;
            // 페이징 재생성
            drawPaging();
            // 현재 페이지를 리로딩
            getCommentList(nv.$("commentForm").curViewPage.value);
            globalCommon.alertNotice("It has been delete.");
        } else if(resultObj.result == "password") {
	        nv.LBox.off();             
            globalCommon.alertMsg("잘못된 비밀번호 입니다.");
        } else {
	        nv.LBox.off();            
            globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
        }
    }
    
    /**
     * 댓글 삭제 콜백
     * @param {object} resultObj 결과 JSON 객체
     */
    function callback_DeleteComment2(resultObj) {
    	if(resultObj.result == "success") {
	        nv.LBox.off();      	    
    		// 코멘트 수 감소
    		nv.$("commentForm_"+_id).commentCount.value = parseInt(nv.$("commentForm_"+_id).commentCount.value) - 1;
    		// 페이징 재생성
    		//drawPaging2();
    		// 현재 페이지를 리로딩
    		getCommentList2(nv.$("commentForm_"+_id).curViewPage.value, _id);
            globalCommon.alertNotice("It has been delete.");    		
    	} else if(resultObj.result == "password") {
	        nv.LBox.off();      	    
    		globalCommon.alertMsg("잘못된 비밀번호 입니다.");
    	} else {
	        nv.LBox.off();      	    
    		globalCommon.alertMsg("잠시 후 다시 시도해 주세요.");
    	}
    }
    
    /**
     * 이모티콘 선택 div 표시
     * @param {object} element 엘리먼트 객체
     * @param {boolean} childFlag 자식 댓글 여부
     */
    function openEmoticonDiv(element, childFlag) {
        // 버튼 엘리먼트의 좌표 획득
        var elementXY = nv.UI.getXY(element);
        
        // 위치 변경
        var emoticonSelectDiv = nv.$("emoticonSelectDiv");
        emoticonSelectDiv.style.left = (elementXY.x + 15) + "px"; 
        emoticonSelectDiv.style.top = elementXY.y + "px";
        
        // 감추거나 보인다.
        if(emoticonSelectDiv.style.display == "none") {
            emoticonSelectDiv.style.display = "inline";
        } else {
            emoticonSelectDiv.style.display = "none"; 
        }
        
        if(childFlag) nv.$("commentForm").emoticonChildFlag.value = "Y";
        else nv.$("commentForm").emoticonChildFlag.value = "N";
    }
    
    /**
     * 이모티콘 선택
     * @param {string} emoticonNum 이모티콘 번호
     */
    function selectEmoticon(emoticonNum) {
        if(nv.$("commentForm").emoticonChildFlag.value == "Y") {
            nv.$("commentForm").childEmoticonId.value = emoticonNum;
            nv.$("childEmoticonImg").src = ""  + imageServer + "/images/bbs/emoticon/" + emoticonNum + ".gif";
        } else {
            nv.$("commentForm").emoticonId.value = emoticonNum;
            nv.$("emoticonImg").src = ""  + imageServer + "/images/bbs/emoticon/" + emoticonNum + ".gif";        
        }
        nv.$("emoticonSelectDiv").style.display = "none";
    }
    
/*
 * DIV 내부에 존재하는 이미지 들의 사이즈를 조정한다.
 *
 * divName : 이미지가 존재하는 div명(텍스트로 전달)
 * maxWidth : 허용할 최대 가로크기(옵션) (-1시 무시)
 * maxHeight : 허용할 최대 세로 크기(옵션) (-1시 무시)
 * hideFlag : 이미지 리사이징 동안 본문정보를 보일것인지 여부(옵션) true입력시 감췄다가 보임
 *
 * resize_images('dealerdetsright', 550);
 * resize_images('dealerdetsright', 550, 400);
 */
function resize_images(divName, maxWidth, maxHeight) {

    var isCheckWidth = (maxWidth!=undefined && maxWidth>0);
    var isCheckHeight = (maxHeight!=undefined && maxHeight>0);


    var imgList = document.getElementsByTagName('img');

    if(imgList) {

        if(!imgList.length) {
            var imgObj = imgList;
            var imgWidth = imgObj.width;
            var imgHeight = imgObj.height;

            if(isCheckWidth) {
                if(imgWidth > maxWidth) {
                    var widthRatio = maxWidth/imgWidth;
                    imgObj.width = imgWidth * widthRatio;
                    imgObj.height = imgHeight * widthRatio;
                }
            }

            imgWidth = imgObj.width;
            imgHeight = imgObj.height;

            if(isCheckHeight) {
                if(imgHeight > maxHeight) {
                    var heightRatio = maxHeight/imgHeight;
                    imgObj.height = imgHeight * heightRatio;
                    imgObj.width = imgWidth * heightRatio;
                }
            }
        } else {
            for(var i=0; i<imgList.length; i++) {
                var imgObj = imgList[i];
                var imgWidth = imgObj.width;
                var imgHeight = imgObj.height;

                if(isCheckWidth) {
                    if(imgWidth > maxWidth) {
                        var widthRatio = maxWidth/imgWidth;
                        imgObj.width = imgWidth * widthRatio;
                        imgObj.height = imgHeight * widthRatio;
                    }
                }

                imgWidth = imgObj.width;
                imgHeight = imgObj.height;

                if(isCheckHeight) {
                    if(imgHeight > maxHeight) {
                        var heightRatio = maxHeight/imgHeight;
                        imgObj.height = imgHeight * heightRatio;
                        imgObj.width = imgWidth * heightRatio;
                    }
                }
            }
        }
    }
}

function popupLearnCopyTheUrl() {
    var htmlStr = " <!-- str :: Copy the url layer --> ";
    htmlStr += " <div id=\"copyurl\" class=\"rbox_pk\" style=\"display:none; position:absolute; top:77px; left:4px;_left:-10px; width:730px; z-index:1000;\"> ";
    htmlStr += " 	<div class=\"corner lt\"></div> ";
    htmlStr += " 	<div class=\"corner rt\"></div> ";
    htmlStr += " 		<a href=\"#\" onclick=\"closePop('copyurl');\"><img src=\"/img/common/mygallery/btn_x.gif\" alt=\"close\" class=\"close_x\" /></a> ";
    htmlStr += " 		<img src=\"/img/community/learn/tit_copytourl.gif\" alt=\"Copy the url / Click on the Copy button to copy the URL and paste it where you want to. If the “Copy” button doesn’t work, please click and drag over the URL, then right-click and choose “Copy”.\" /> ";
    htmlStr += " 		<input type=\"text\" id=\"copyTheUrlTextArea\" name=\"copyTheUrlTextArea\" size=\"\" title=\"\" class=\"graya9 input21 bdr_wrap mgt18\" style=\"width:880px;\" value=" + document.URL + "/> ";
    htmlStr += " 		<div class=\"textcenter mgt10\"><a href=\"#\"><img src=\"/img/community/learn/btn_copy.gif\" alt=\"복사\" /></a></div> ";
    htmlStr += " 	<div class=\"corner lb\"></div> ";
    htmlStr += " 	<div class=\"corner rb\"></div> ";
    htmlStr += " </div> ";
    htmlStr += " <!-- end :: Copy the url layer --> ";
    
    var urlLayer = nv.$('urlLayer');
    var urlShowDiv = nv.$("urlShowDiv");
    if(urlShowDiv) {
        urlLayer.removeChild(urlShowDiv);
    }    
        
    urlShowDiv = document.createElement('div');
    urlShowDiv.id = 'urlShowDiv';
    urlShowDiv.className = 'urlShowDiv';
    urlShowDiv.style.display = 'block';
    urlShowDiv.innerHTML = htmlStr;
    urlLayer.appendChild(urlShowDiv);
}
