var isSubmit = false; // 폼 서브밋 여부 체크 변수입니다. - smyeo

function setListType()
{
    var listFrm = document.list_form;
    var frm = document.board_hidden;
    frm.action = '/Front/Board/?url=lists';
    
    var sListType = null;
    
    /*for (var i=0; i < listFrm.list_type.length; i++) {
        if (listFrm.list_type[i].checked == true) {
            sListType = listFrm.list_type[i].value;
            break;
        }
    }*/
    if (document.getElementById('list_type_normal').checked == true) {
        sListType = document.getElementById('list_type_normal').value;
    }
    if (document.getElementById('list_type_gallery').checked == true) {
        sListType = document.getElementById('list_type_gallery').value;
    }
    
    if (sListType == null) {
        alert('리스트 타입이 정해지지 않았습니다.');
        return false;
    }
    frm.list_type.value = sListType;
    frm.submit();
}

//added by gckim 2005-05-11
function LockF5(){ 
    if (event.keyCode == 116) { 
        event.keyCode = 0; 
        return false; 
    }    
} 

//document.onkeydown = LockF5; 

function afile_display(id,flag) {
    
    if(flag==1) //첨부파일 보여줌
    {
        id.style.display="";
        id.style.position = "absolute";
        id.style.left = event.clientX;
        id.style.top = event.clientY+document.body.scrollTop; //세로축(Y)
    }
    else  //첨부파일 안보여줌
    {
        id.style.display="none";
    }
    
}

function ck_control() {
        var check_nums = document.list_form.elements.length;


        for (var i=0; i<check_nums; i++) {
        
            var checkbox_obj = eval("document.list_form.elements[" + i + "]");
            if(checkbox_obj.name=="ck_no[]") {
              if(document.list_form.all_ck.checked==true) {
                checkbox_obj.checked = 1
              }
              else {
                checkbox_obj.checked = 0
              }
            }
                
        }
}


function board_copy( form )
{
    if(checkBoxCheck(form)==true) {
        msg = "글 복사시 첨부파일 및 이미지는 원본글과 같이 사용하게 되므로 글삭제시 주의하시기 바랍니다. \r\r복사하시겠습니까?";
    
        if( !confirm( msg ) )
        {
             return false;
        }
        else
        {
            form.mode.value = 'copy_board_ck';
            return true;
        }
    }
    else {
        alert("복사할 글을 선택해주세요");
        return false;
    }
}


function board_move( form )
{
    if(checkBoxCheck(form)==true) {
        form.mode.value = 'move_board_ck';
        return true;
    }
    else {
        alert("이동할 글을 선택해주세요");
        return false;
    }

}

function checkBoxCheck(frm)
{
    var element   = frm.elements;
    var check_res = false;

    for(var i = 0;i < element.length;i++)
    {
        if(element[i].type == 'checkbox' && element[i].name == 'ck_no[]' && element[i].checked == true)
        {
            check_res = true;
            break;
        }
    }
    
    return check_res;
}

function setInputLayer(id, mode)
{
    var d = document.getElementById('d'+id);

    if (d.style.display == 'none') {
        d.style.display='inline';
        if (document.getElementById('re'+id)) {
            document.getElementById('re'+id).style.display = 'inline';
        }
    } else if (document.getElementById('frm'+id).mode.value == mode) {
        d.style.display='none';
        if (document.getElementById('re'+id)) {
            document.getElementById('re'+id).style.display = 'none';
        }
        return false;
    }
        
    document.getElementById('frm'+id).mode.value = mode;
    
    if (mode == 'update') {
        if (!document.getElementById('secret_flag'+id)) {
            document.getElementById('frm'+id).new_content.value = document.getElementById('content'+id).innerHTML;
        }
        if (document.getElementById('frm'+id).writer_name) {
            document.getElementById('frm'+id).writer_name.value = document.getElementById('name'+id).innerHTML;
        }
        document.getElementById('frm'+id).new_content.disabled = '';
        if (document.getElementById('frm'+id).writer_name) {
            document.getElementById('frm'+id).writer_name.disabled = '';
        }
        document.getElementById('submit'+id).innerHTML = '수정';
    } else if (mode == 'reply') {
        document.getElementById('frm'+id).new_content.value = '';
        document.getElementById('frm'+id).new_content.disabled = '';
        if (document.getElementById('frm'+id).writer_name) {
            document.getElementById('frm'+id).writer_name.disabled = '';
        }       
        document.getElementById('submit'+id).innerHTML = '등록';
    } else if (mode == 'del') {
        document.getElementById('frm'+id).new_content.value = document.getElementById('content'+id).innerHTML;
        if (document.getElementById('frm'+id).writer_name) {
            document.getElementById('frm'+id).writer_name.value = document.getElementById('name'+id).innerHTML;
        }
        document.getElementById('frm'+id).new_content.disabled = 'disabled';
        if (document.getElementById('frm'+id).writer_name) {
            document.getElementById('frm'+id).writer_name.disabled = 'disabled';
        }
        document.getElementById('submit'+id).innerHTML = '삭제';
    }
}

function checkform(id)
{
    if (isSubmit === false) {
        var frm = document.getElementById('frm'+id);
        
        if (document.getElementById('infomation_checkT')) {
            if (!document.getElementById('infomation_checkT').checked) {
                alert('개인정보취급방침에 동의하셔야 합니다.');
                return false;
            }
        }    
        if (!frm.new_content.value) {
            alert('내용을 입력하세요.');
            frm.new_content.focus();
            return false;
        }
    
        if (frm.writer_name && !frm.writer_name.value) {
            alert('작성자를 입력하세요.');
            frm.writer_name.focus();
            return false;   
        }
    
        if (!frm.passwd.value) {
            alert('비밀번호를 입력하세요.');
            frm.passwd.focus();
            return false;
        }
    
        if (document.getElementById('frm'+id).mode.value == 'del') {
            if (confirm('글을 삭제합니다. 취소하려면 취소를 클릭하세요.') === false) {
                return false;
            }
        }
        isSubmit = true;
        frm.submit();
    } else {
        alert('처리중입니다.');
    }
}

function viewImage(name, url, no, board_no) {
    window.open('/Front/Board/?url=PreviewImage&name='+encodeURI(name)+'&image='+url+'&no='+no+'&board_no='+board_no, 'view_image', 'width=0, height=0');
}

function imagePaging(val) {
    var maximg = maxImage();
    if (val == 'prev') {
        if (document.getElementById('nowPage').value != 0) {            
            document.getElementById('image'+document.getElementById('nowPage').value).style.display = 'none'; 
            prevpage = Number(document.getElementById('nowPage').value) - 1;
            document.getElementById('image'+prevpage).style.display = 'block';
            window.resizeTo(document.getElementById('image_'+prevpage).width + 60, document.getElementById('image_'+prevpage).height + 200);
            document.getElementById('nowPage').value = prevpage;
        } else {
            alert('이전 이미지가 없습니다.');
        }
    } else {        
        if (document.getElementById('nowPage').value != maxImage()) {
            document.getElementById('image'+document.getElementById('nowPage').value).style.display = 'none'; 
            nextpage = Number(document.getElementById('nowPage').value) + 1;
            document.getElementById('image'+nextpage).style.display = 'block';
            window.resizeTo(document.getElementById('image_'+nextpage).width + 60, document.getElementById('image_'+nextpage).height + 200);
            document.getElementById('nowPage').value = nextpage;
        } else {
            alert('다음 이미지가 없습니다.');
        }
    }
}

function maxImage() {
    for (var i=0;i<5;i++) {        
        if (document.getElementById('image'+i) == null) break;
    }    
    return i-1;
}

function setDelete(no) {
    document.getElementById('mode').value = 'del';
    document.getElementById('no').value = no;
    document.getElementById('content').value = document.getElementById('dContent'+no).innerHTML;
    document.getElementById('writer_name').value = document.getElementById('dWriter'+no).innerHTML;
    document.getElementById('password').focus();
}

function checkSubmit() {
    if (isSubmit === false) {
        var aForm = document.afternote_frm;
        if (!aForm.writer_name.value) {
            alert('작성자를 입력하세요.');
            aForm.writer_name.focus();
            return false;
        }
        if (!aForm.passwd.value) {
            alert('비밀번호를 입력하세요.');
            aForm.passwd.focus();
            return false;
        }
        if (!aForm.content.value) {
            alert('내용을 입력하세요.');
            aForm.content.focus();
            return false;
        }
        aForm.subject.value = aForm.subject.value.replace('MEMBER_NAME', aForm.writer_name.value);
        isSubmit = true;
        return true;
    } else {
        alert('처리중입니다.');
        return false;
    }
}

function showFullContents(iNo)
{
    document.getElementById('dContentFull'+iNo).style.display = 'inline';
    document.getElementById('dContent'+iNo).style.display = 'none';
    if (document.getElementById('dContentImage'+iNo)) {
        document.getElementById('dContentImage'+iNo).style.display = 'inline';
    }
    doCountUp(iNo);
}

function hideFullContents(iNo)
{
    document.getElementById('dContentFull'+iNo).style.display = 'none';
    document.getElementById('dContent'+iNo).style.display = 'inline';
    if (document.getElementById('dContentImage'+iNo)) {
        document.getElementById('dContentImage'+iNo).style.display = 'none';
    }    
}

/**
 * 상품후기 게시판 조회수 증가 Ajax
 */
function doCountUp(iNo) {
    var params = "&board_no="+document.afternote_frm.board_no.value+"&no="+iNo;
    sendRequest(doCountUpInsert, params,'POST', '/Front/Board/?url=setBulletinCount', false, false);
}

/**
 * 상품후기 게시판 조회수 증가 Ajax 수신
 * @param oj3
 * @return
 * doCountUp 함수와 꼭 같이 있어야함.
 * 함수 내용이 없어도 함수는 꼭 있어야함.
 */
function doCountUpInsert(oj3) {
    // 현재 조회수 증가와함께 게시판에 취할 action이 없어서 비워둠.
    // 앞으로 있을거라고 봄.
    //eval("var res = '" + oj3.responseText + "'");
    //alert(oj3.responseText);
}


/**
 * 답변 폼 보이기
 */
function showReplyForm(no) 
{
    var u4 = document.getElementById('u4');
    var btn = u4.getElementsByTagName('IMG');
    btn[0].onclick = 'doReplyAction('+no+')';

    document.getElementById('dForm'+no).innerHTML = document.getElementById('u4').innerHTML;
    document.getElementById('dButton'+no).innerHTML = '';
}

function setReply(no)
{
    document.getElementById('product_no').value = document.getElementById('dProductNo'+no).innerHTML;
    document.getElementById('product_name').value = document.getElementById('dProductName'+no).innerHTML;
    document.getElementById('content').focus();
}

function setModify(no, file_no) {
    document.getElementById('mode').value = 'update';
    document.getElementById('no').value = no;
    document.getElementById('content').value = document.getElementById('dContent'+no).innerHTML;
    document.getElementById('writer_name').value = document.getElementById('dWriter'+no).innerHTML;
    if (file_no != '') {
        document.getElementById('dFileDel').style.display = 'inline';
        document.getElementById('file_del').value = file_no;
    } else {
        document.getElementById('dFileDel').style.display = 'none';
    }
    document.getElementById('product_no').value = document.getElementById('dProductNo'+no).innerHTML;
    document.getElementById('content').focus();
}

/**
 * 수정 폼 보이기
 */
function showModifyForm(no) 
{
    var u31 = document.getElementById('u4');
    var textarea = u4.getElementsByTagName('TEXTAREA');
    textarea[0].value = document.getElementById('dContentFull'+no).innerHTML;
    
    var writer = u4.getElementsByTagName('INPUT');
    for (var i = 0; i < writer.length; i++) {
        if (writer[i].name == 'writer_name') {
            writer[i].value = document.getElementById('dWriter'+no).innerText;
        }        
    }
    
    if (document.getElementById('dPoint'+no)) {
        var point = document.getElementsByName('point');
        for (i = 0; i < point.length; i++) {
            if (point[i].value == document.getElementById('dPoint'+no).value) {
                point[i].checked = 'checked';
            } else {
                point[i].checked = '';
            }
        }
    }

    var btn = u4.getElementsByTagName('IMG');
    btn[0].onclick = 'doModifyAction('+no+')';
  
    document.getElementById('dModifyHide'+no).innerHTML = document.getElementById('dModify'+no).innerHTML;
    document.getElementById('dButtonHide'+no).innerHTML = document.getElementById('dButton'+no).innerHTML;
    
    document.getElementById('dModify'+no).innerHTML = document.getElementById('u4').innerHTML;
    document.getElementById('dButton'+no).innerHTML = '';

}

/**
 * 수정 폼 숨기기
 */
function hideModifyForm(no)
{
    document.getElementById('dButton'+no).innerHTML = document.getElementById('dButtonHide'+no).innerHTML;
    document.getElementById('dButtonHide'+no).innerHTML = document.getElementById('dModify'+no).innerHTML;
    document.getElementById('dModify'+no).innerHTML = document.getElementById('dModifyHide'+no).innerHTML;
    document.getElementById('dModifyHide'+no).innerHTML = document.getElementById('dButtonHide'+no).innerHTML;
}

/**
 * 이미지미리보기
 */
function file_div_display(div_id,show_flag) {
    if(show_flag=="T") {
        document.getElementById(div_id).style.display="";
    }
    else {
        document.getElementById(div_id).style.display="none";
    }
}

/**
 * 첨부파일 삭제
 */
function del_and_reupload(oSelf, sTargetId, no){

    var myform = eval('document.afternote_frm'+no+'.'+sTargetId);
    if(oSelf.checked==true) myform.disabled = false;
        else myform.disabled = true;

}

/**
 * NEW 수정 폼 보이기
 */
function showModifyFormNew(no) 
{
    document.getElementById('u4btn'+no).onclick = 'doModifyActionN('+no+')';
    document.getElementById('u4btn1'+no).onclick = 'hideModifyForm('+no+')';
    
    document.getElementById('dButtonHide'+no).innerHTML = document.getElementById('dModify'+no).innerHTML;
    document.getElementById('dModify'+no).innerHTML = document.getElementById('dModifyHide'+no).innerHTML;
    document.getElementById('dModifyHide'+no).innerHTML = document.getElementById('dButtonHide'+no).innerHTML;
    document.getElementById('dButtonHide'+no).innerHTML = document.getElementById('dButton'+no).innerHTML;    
    document.getElementById('dButton'+no).innerHTML = '';
}

/**
 * NEW 글 수정
 */
function doModifyActionN(no)
{
    var dModify = document.getElementById('dModify'+no);
    
    var textarea = dModify.getElementsByTagName('TEXTAREA');
    if (!textarea[0].value) {
        alert('내용을 입력하세요');
        textarea[0].focus();
        return false;
    } 
    var input = dModify.getElementsByTagName('INPUT');
    for (var i = 0; i < input.length; i++) {
        if (input[i].name == 'writer_name') {
            if (!input[i].value) {
                alert('이름을 입력하세요');
                input[i].focus();
                return false;
            }
        } else if (input[i].name == 'passwd') {
            if (!input[i].value) {
                alert('비밀번호를 입력하세요');
                input[i].focus();
                return false;
            }
        }
    }
    document.getElementById('afternote_frm'+no).subject.value = document.getElementById('afternote_frm'+no).subject.value.replace('MEMBER_NAME', document.getElementById('afternote_frm'+no).writer_name.value);
    document.getElementById('afternote_frm'+no).submit();
}

/**
 * 답변
 */
function doReplyAction(no)
{
    if (isSubmit === false) {
        var dForm = document.getElementById('dForm'+no);
        var aForm = document.afternote_frm;
    
        var textarea = dForm.getElementsByTagName('TEXTAREA');
        if (!textarea[0].value) {
            alert('내용을 입력하세요');
            textarea[0].focus();
            return false;
        }
        aForm.new_content.value = textarea[0].value;
    
        var input = dForm.getElementsByTagName('INPUT');
        for (var i = 0; i < input.length; i++) {
            if (input[i].name == 'u4name') {
                if (!input[i].value) {
                    alert('이름을 입력하세요');
                    input[i].focus();
                    return false;
                }
                aForm.write_name.value = input[i].value;
            } else if (input[i].name == 'u4pw') {
                if (!input[i].value) {
                    alert('비밀번호를 입력하세요');
                    input[i].focus();
                    return false;
                }
                aForm.passwd.value = input[i].value;
            }
        }
        isSubmit = true;
        var sProductNo='';
        if (document.getElementById('ProductNo'+no)) {
            sProductNo=document.getElementById('ProductNo'+no).value;
        }
        aForm.product_no.value = sProductNo;
        aForm.mode.value = 'reply';
        aForm.no.value = no;
        aForm.submit();
    } else {
        alert('처리중입니다.');
    }
}

/**
 * 글 수정
 */
function doModifyAction(no)
{
    var dModify = document.getElementById('dModify'+no);
    var aForm = document.afternote_frm;
    
    var textarea = dModify.getElementsByTagName('TEXTAREA');
    aForm.new_content.value = textarea[0].value;
    
    var input = dModify.getElementsByTagName('INPUT');
    for (var i = 0; i < input.length; i++) {
        if (input[i].name == 'u4name') {
            aForm.write_name.value = input[i].value;
        } else if (input[i].name == 'u4pw') {
            aForm.passwd.value = input[i].value;
        }
    }

    if (document.getElementById('dPoint'+no)) {
        var point = document.getElementsByName('point');
        for (i = 0; i < point.length; i++) {
            if (point[i].value == document.getElementById('dPoint'+no).value) {
                point[i].checked = 'checked';
            } else {
                point[i].checked = '';
            }
        }
    }
    
    aForm.product_no.value = document.getElementById('ProductNo'+no).value;
    aForm.mode.value = 'reply';
    aForm.no.value = no;
    aForm.submit();
}

/**
 * 삭제 폼 보이기 (비회원)
 */
function showDeleteForm(no) 
{
    var aForm = document.afternote_frm;
    
    aForm.mode.value = 'del';
    aForm.no.value = no;
    document.getElementById('dForm'+no).innerHTML = document.getElementById('u5').innerHTML;
}

/**
 * 직접 삭제 (회원)
 */
function doDeleteDirectly(no)
{
    if (confirm('정말 삭제하시겠습니까?')) {
        var aForm = document.afternote_frm;
        
        aForm.mode.value = 'del';
        aForm.no.value = no;
        aForm.submit();
    }
}

/**
 * 글 삭제
 */
function doDeleteAction(o)
{
    var aForm = document.afternote_frm;
    var childNode = o.parentNode.childNodes;
    for (var i = 0; i < childNode.length; i++) {
        if (childNode[i].name == 'u5pw') {
            aForm.passwd.value = childNode[i].value;
        }
    }
    
    aForm.submit();
}

/**
 *  코멘트 레이어 보이기/닫기
 */
function viewCommentLayer(id)
{
    var d = document.getElementById('re'+id);

    if (d.style.display == 'none') {
        d.style.display='inline';
        return true
    } else {
        d.style.display='none';
        return false;
    }
}

/**
 *  코멘트 폼 검사
 */
function checkCommentForm(id)
{
    if (isSubmit === false) {
        var frm = document.getElementById('frm'+id);
        frm.target="_self";
    
        if (!frm.comment.value) {
            alert('내용을 입력하세요.');
            frm.comment.focus();
            return false;
        }
    
        if (frm.comment_name && !frm.comment_name.value) {
            alert('작성자를 입력하세요.');
            frm.comment_name.focus();
            return false;   
        }
    
        if (!frm.comment_passwd.value) {
            alert('비밀번호를 입력하세요.');
            frm.comment_passwd.focus();
            return false;
        }

        frm.comment_name.value = get_string_trim(frm.comment_name.value);
        frm.comment_passwd.value = get_string_trim(frm.comment_passwd.value);
        frm.comment.value = get_string_trim(frm.comment.value);

        isSubmit = true;
        json_init(frm,"add");
        return false;
    } else {
        alert('처리중입니다.');
    }
}


function json_init(form,mode) {
    if(mode=="add") {
        var sIsSecret = 'F';

        if (form.is_secret) {
            for (var i=0; i<form.is_secret.length; i++) {
                if (form.is_secret[i].checked === true) {
                    sIsSecret = form.is_secret[i].value;
                }
            }
        }
    
        parma_str = "&mode=comment_add&board_no="+form.board_no.value+"&comment_name="+form.comment_name.value+"&comment_passwd="+form.comment_passwd.value+"&comment="+form.comment.value+"&no="+form.no.value+"&is_secret="+sIsSecret;
        sendRequest(json_comment_insert, parma_str,'POST', '/front/php/b/board_write_a_new.php', true, true);
    }
}

function json_comment_insert(oj) {

    eval("var res = " + oj.responseText);
    
    try {
        comment_tpl = document.getElementById('div_comment_tpl').value;

        comment_tpl = comment_tpl.replace(/\[ajax_comment_no\]/g,res.Static[0].comment_no);
        comment_tpl = comment_tpl.replace(/\[ajax_comment_cnt\]/g,res.Static[1].comment_cnt);
        comment_tpl = comment_tpl.replace(/\[ajax_comment_name\]/g,res.Static[2].comment_name);
//        comment_tpl = comment_tpl.replace("[ajax_comment]",document.getElementById('comment').value);
        comment_tpl = comment_tpl.replace(/\[ajax_comment\]/g,res.Static[7].comment_bt_comment);
        
        comment_tpl = comment_tpl.replace(/\[ajax_comment_member_id\]/g,res.Static[3].comment_member_id);
        comment_tpl = comment_tpl.replace(/\[ajax_comment_write_date\]/g,res.Static[4].comment_write_date);
        comment_tpl = comment_tpl.replace(/\[ajax_comment_group_icon\]/g,res.Static[5].comment_group_icon);
        comment_tpl = comment_tpl.replace(/\[ajax_comment_bt_idx\]/g,res.Static[6].comment_bt_idx);

        ret_comment_tpl = comment_tpl;
        ret_comment_tpl = document.getElementById('comment_list'+res.Static[6].comment_bt_idx).innerHTML+ret_comment_tpl;
        document.getElementById('comment_list'+res.Static[6].comment_bt_idx).innerHTML = ret_comment_tpl;
        document.getElementById('frm'+res.Static[6].comment_bt_idx).comment.value='';
    } catch(e) {}
    alert('등록되었습니다.');
    isSubmit = false;
}

function get_string_trim( string )
{
    return string.replace(/(^\s*)|(\s*$)/g, "");
}
// comment modify/secret comment view
var commentControlTarget = '';
function getCommentPasswordForm(iCommentIdx)
{
    if (commentControlTarget != '') {
        alert('처리중입니다.');
    } else {
        commentControlTarget = iCommentIdx;
        sParams = "&url=commentPasswordForm&comment_no="+iCommentIdx;
        sendRequest(setCommentPasswordForm, sParams,'POST', '/Front/Board/', true, true);
    }
}

function setCommentPasswordForm(obj)
{
    document.getElementById('comment_control_area_'+commentControlTarget).style.display = '';
    document.getElementById('comment_control_area_'+commentControlTarget).innerHTML = obj.responseText;
    commentControlTarget = '';
}

var secretCommentReadTarget = '';
var secretCommentModifyTarget = '';
function chkCommentPassword(oForm, iCommentIdx, isModifyMode)
{
    if (secretCommentReadTarget != '') {
        alert('처리중입니다.');
    } else {
        var iCommentNo = oForm.comment_no.value;
        var sPassword = oForm.comment_passwd.value;
        secretCommentReadTarget = iCommentIdx;
        if (isModifyMode == 'T') {
            secretCommentModifyTarget = iCommentIdx;
        } else {
            isModifyMode = 'F';
        }

        try {
            // SSL
            var ssl_callback_fn = function(output){
                var sParams = "&url=commentPasswordCheck&isModifyMode="+isModifyMode+"&"+AuthSSL.key+"="+output;
                sendRequest(setSecretCommentContents, sParams, 'POST', '/Front/Board/', true, true);
            };
            if (AuthSSL_encode(oForm, ["comment_no", "comment_passwd"], ssl_callback_fn) == true) {
                return false;
            }
        } catch (e) {}

        // HTTP
        var sParams = "&url=commentPasswordCheck&comment_no="+iCommentNo+"&"+"comment_passwd="+sPassword+"&isModifyMode="+isModifyMode;
        sendRequest(setSecretCommentContents, sParams,'POST', '/Front/Board/', true, true);
    }

    return false;
}

function setSecretCommentContents(obj)
{
    var sChkCode = obj.responseText;
    sChkCode = sChkCode.replace(/[\r\n\s]/, '');
    var aErrorCode = {
            'ERROR_8001' : '해당 댓글의 읽기 권한이 없습니다.',
            'ERROR_8002' : '잘못된 비밀번호입니다.',
            'ERROR_9001' : '잘못된 댓글정보입니다. 관리자에게 문의하여 주세요.'
    };
    
    if (sChkCode == '') {
        alert('알 수 없는 오류입니다. 관리자에게 문의하여 주세요.');
        secretCommentReadTarget = '';
        return false;
    }

    if (aErrorCode[sChkCode]) {
        alert(aErrorCode[sChkCode]);
        secretCommentReadTarget = '';
        return false;
    } else {
        if (document.getElementById('secret_comment_'+secretCommentReadTarget)) {
            document.getElementById('secret_comment_'+secretCommentReadTarget).innerHTML = obj.responseText;
        }
        if (secretCommentModifyTarget == secretCommentReadTarget) {
            getCommentModifyForm(secretCommentModifyTarget);
        } else {
            document.getElementById('comment_control_area_'+secretCommentReadTarget).style.display = 'none';
        }

        secretCommentReadTarget = '';
        secretCommentModifyTarget = '';
        return true;
    }
}

function getCommentModifyForm(iCommentIdx)
{
    if (commentControlTarget != '') {
        alert('처리중입니다.');
    } else {
        commentControlTarget = iCommentIdx;
        sParams = "&url=commentModifyForm&comment_no="+iCommentIdx;
        sendRequest(setCommentModifyForm, sParams,'POST', '/Front/Board/', true, true);
    }
}

function setCommentModifyForm(obj)
{
    var sChkCode = obj.responseText;
    sChkCode = sChkCode.replace(/[\r\n\s]/, '');
    var aErrorCode = {
            'ERROR_8001' : '해당 댓글의 수정 권한이 없습니다.',
            'ERROR_9001' : '잘못된 댓글정보입니다. 관리자에게 문의하여 주세요.'
    };
    
    if (sChkCode == '') {
        alert('알 수 없는 오류입니다. 관리자에게 문의하여 주세요.');
        commentControlTarget = '';
        return false;
    }
    
    if (aErrorCode[sChkCode]) {
        alert(aErrorCode[sChkCode]);
        commentControlTarget = '';
        return false;
    } else {
        document.getElementById('comment_control_area_'+commentControlTarget).style.display = '';
        document.getElementById('comment_control_area_'+commentControlTarget).innerHTML = obj.responseText;
        commentControlTarget = '';
        return true;
    }
}

function setCommentModifyDao(oForm)
{
    if (isSubmit != false) {
        alert('처리중입니다.');
    } else {
        isSubmit = true;

        var iCommentNo = oForm.comment_no.value;
        var sPassword = oForm.comment_passwd.value;
        var sName = oForm.comment_name.value;
        var sContents = oForm.comment.value;

        var sIsSecret = 'F';

        if (oForm.is_secret) {
            for (var i=0; i<oForm.is_secret.length; i++) {
                if (oForm.is_secret[i].checked === true) {
                    sIsSecret = oForm.is_secret[i].value;
                }
            }
        }

        try {
            // SSL
            var ssl_callback_fn = function(output){
                var sParams = "&url=Commentmodify&is_secret="+sIsSecret+"&"+AuthSSL.key+"="+output;
                sendRequest(getCommentModifyResult, sParams, 'POST', '/Front/Board/', true, true);
            };
            if (AuthSSL_encode(oForm, ["comment_no", "comment_passwd", "comment_name", "comment"], ssl_callback_fn) == true) {
                return false;
            }
        } catch (e) {}

        // HTTP
        var sParams = "&url=Commentmodify&comment_no="+iCommentNo+"&comment_passwd="+sPassword+"&comment_name="+sName+"&comment="+sContents+"&is_secret="+sIsSecret;
        sendRequest(getCommentModifyResult, sParams,'POST', '/Front/Board/', true, true);
    }

    return false;
}

function getCommentModifyResult(obj)
{
    var sChkCode = obj.responseText;
    sChkCode = sChkCode.replace(/[\r\n\s]/, '');
    var aErrorCode = {
            'ERROR_0000' : '댓글이 수정되었습니다.',
            'ERROR_8001' : '해당 댓글의 수정 권한이 없습니다.',
            'ERROR_9001' : '잘못된 댓글정보입니다. 관리자에게 문의하여 주세요.',
            'ERROR_9003' : '지정된 댓글이 존재하지 않습니다.',
            'ERROR_9999' : '알 수 없는 오류입니다. 관리자에게 문의하여 주세요.'
    };

    if (aErrorCode[sChkCode]) {
        alert(aErrorCode[sChkCode]);
        isSubmit = false;
        if (sChkCode == 'ERROR_0000') {
            // 수정 성공시 reload
            location.reload();
        }
        return false;
    } else {
        alert(aErrorCode['ERROR_9999']);
        isSubmit = false;
        return false;
    }
    return false;
}
