var openWindow='';

function alignCenter(win,width,height) {
        win.moveTo(screen.width/2-width/2,screen.height/2-height/2);
}	

function deleteComment(id, seq_category, seq_bbs) {		
        width = 735;
        height = 400;
        try { openWindow.close(); } catch(e) { }
        openWindow = window.open("/popup_guestbook.php?s=" + id + "&sc=" + seq_category + "&sb=" + seq_bbs + "&m=D", "comment", "width="+width+",height="+height+",location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
        openWindow.focus();
        alignCenter(openWindow,width,height);
}

function editComment(id) {		
        width = 735;
        height = 400;
        try { openWindow.close(); } catch(e) { }
        openWindow = window.open("/popup_guestbook.php?s=" + id + "&m=M", "comment", "width="+width+",height="+height+",location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
        openWindow.focus();
        alignCenter(openWindow,width,height);
}

function replyComment(id, seq_category, seq_bbs) {		
        width = 735;
        height = 400;
        try { openWindow.close(); } catch(e) { }
        openWindow = window.open("/popup_guestbook.php?s=" + id + "&m=R&sc=" + seq_category + "&sb=" + seq_bbs, "comment", "width="+width+",height="+height+",location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
        openWindow.focus();
        alignCenter(openWindow,width,height);
}

// regist guest book
function reg_guestbook(seq_category, seq_bbs) {
    var url = "/core/bbs/ajax_add_guestbook.php";
    var para = "nm="+encodeURIComponent($F('name'))+"&pw="+encodeURIComponent($F('password'))+"&hm="+encodeURIComponent($F('homepage'))+"&em="+encodeURIComponent($F('email'))+"&cm="+encodeURIComponent($F('comment'))+"&sc="+seq_category+"&sb="+seq_bbs+"&md=I&is="+$F('isSecret')+"&sp="+$F('seq_parent');
    var myAjax = new Ajax.Request(
        url,
        {
            method: 'post',
            asynchronous: false,
            parameters: para,
            onComplete: return_reg_guestbook
        });
}

function return_reg_guestbook(req) {
    var result = req.responseText;
    switch(result) {
        case '020' : alert('등록하는데 실패하였습니다. 잠시 후 다시 시도하여 주십시오'); $('name').focus(); break;
        case '010' : alert('값이 제대로 전달되지 못했습니다. 다시 입력해 주십시오.'); $('name').focus(); break;
        case '000' : alert('등록되었습니다.');
                     if(window.location.pathname=="/popup_guestbook.php") {
                        opener.location.reload();
                        self.close();
                     } else {
                        location.reload();
                     }
                     break;
        default : alert( '잘못된 접근입니다.\n\n' + result ); break;
    }
}

// regist guest book
function update_guestbook(seq_category, seq_bbs) {
    var url = "/core/bbs/ajax_add_guestbook.php";
    var para = "nm="+encodeURIComponent($F('name'))+"&pw="+encodeURIComponent($F('password'))+"&hm="+encodeURIComponent($F('homepage'))+"&em="+encodeURIComponent($F('email'))+"&cm="+encodeURIComponent($F('comment'))+"&md=M&is="+$F('isSecret')+"&s="+$F('seq_parent');
    var myAjax = new Ajax.Request(
        url,
        {
            method: 'post',
            asynchronous: false,
            parameters: para,
            onComplete: return_reg_guestbook
        });
}

// update bbs valid
function update_bbs_valid(seq_category, seq_bbs, is_valid) {
    var url = "/core/bbs/ajax_update_bbs_valid.php";
    var para = "sc="+seq_category+"&sb="+seq_bbs+"&iv="+is_valid;
    var myAjax = new Ajax.Request(
        url,
        {
            method: 'post',
            asynchronous: false,
            parameters: para,
            onComplete: return_update_bbs_valid
        });
}

function return_update_bbs_valid(req) {
    var result = req.responseText;
    switch(result) {
        case '020' : alert('전환하는데 실패하였습니다. 잠시 후 다시 시도하여 주십시오'); break;
        case '010' : alert('값이 제대로 전달되지 못했습니다. 다시 입력해 주십시오.'); break;
        case '000' : alert('전환되었습니다.'); self.refresh(); break;
        default : alert( '잘못된 접근입니다.\n\n' + result ); break;
    }
}

function edit_bbs(pseq,seq,menuid) {
	location.href = "/bbs_write.php?psq="+pseq+"&s="+seq+"&mnid="+menuid;
}
