function board_submit(f)
{
    if (f.txtSubject.value == "")
    {
        alert("제목을 입력해 주십시오.");
        f.txtSubject.focus();
        return false;
    }
    
    return true;
}

function boardcomment_submit(f)
{
    if (f.txtComment.value == "")
    {
        alert("내용을 입력해 주십시오.");
        f.txtComment.focus();
        return false;
    }
    
    return true;
}

function board_search_submit()
{
    var f=document.all.frmBBS;
    if (f.searchKeyword.value == "")
    {
        alert("검색어를 입력해 주십시오.");
        f.searchKeyword.focus();
        return;
    }
    document.all.frmBBS.page.value = 1;
    document.all.frmBBS.submit();
}

function boardSearchForNickname(nickname)
{
    var f=document.all.frmBBS;

    f.searchKeyword.value = decodeURI(escape(nickname));
    f.optArticle.checked = false;
    f.optSubject.checked = false;
    f.optComment.checked = false;
    f.optNickName.checked = true;
    
    f.page.value = 1;
    f.submit();
}

function goSort(stype)
{
    if(stype==document.all.frmBBS.sortType.value)
    {
        if(document.all.frmBBS.sequence.value=="desc")
        {
            document.all.frmBBS.sequence.value="asc";
        }
        else
        {
            document.all.frmBBS.sequence.value="desc";
        }
    }
    else
    {
        document.all.frmBBS.sequence.value = "desc";
    }
    
    if(document.all.frmBBS.sequence.value=="")
    {
        document.all.frmBBS.sequence.value = "desc";
    }
    
    document.all.frmBBS.sortType.value = stype;
    document.all.frmBBS.submit();
}

function goPage(page)
{
    document.all.frmBBS.action.value = "list";
    document.all.frmBBS.page.value = page;
    document.all.frmBBS.submit();
}

function goRead(number)
{
    document.all.frmBBS.no.value = number;
    document.all.frmBBS.action.value = "read";
    document.all.frmBBS.submit();    
}

function goList()
{
    document.all.frmBBS.action.value = "list";
    document.all.frmBBS.submit();
}

function goWrite()
{
    document.all.frmBBS.action.value = "new";
    document.all.parentno.value = 0;
    document.all.frmBBS.submit();
}

function goReply()
{
    document.all.frmBBS.action.value = "new";
    document.all.frmBBS.submit();
}

function go_Page(allpage)
{
    var page = document.all.pageInputTop.value;
    if(!ChkSignlessIntegral(page))
    {
        alert('이동할 페이지가 0보다 작을수 없습니다.');
        document.all.pageInputTop.value = 1;
        document.all.pageInputTop.focus();
        return;
    }
    if(page>allpage)
    {
        alert('이동할 페이지가 최대 페이지보다 클 수 없습니다.');
        document.all.pageInputTop.value = 1;
        document.all.pageInputTop.focus();
        return;
    }
    document.all.frmBBS.page.value = page;
    document.all.frmBBS.submit();
}

function enter(allpage)
{
    if(event.keyCode == 13)
    { 
        go_Page(allpage);
    }
}

function board_delete()
{  
    if(confirm("글 내용을 삭제 하겠습니까?"))  
        {
            document.all.frmBBS.action.value = "delete";
            document.all.frmBBS.submit();
        }
}

function board_edit()
{  
    document.all.frmBBS.action.value = "edit";
    document.all.frmBBS.submit();

}

function vote()
{  
    document.all.frmBBS.action.value = "vote";
    document.all.frmBBS.submit();

}

function comment_delete(commentnumber)
{  
    if(confirm("글 내용을 삭제 하겠습니까?"))  
        {
            document.all.frmBBS.action.value = "commentdelete";
            document.all.frmBBS.commentno.value = commentnumber;
            document.all.frmBBS.submit();
        }
}

function comment_edit(commentnumber)
{  
    commenttextid = eval("document.all.Article"+commentnumber);
    showid = eval("document.all.showArticle"+commentnumber);
    YAHOO.example.container.commentEdit.show();
    $("commenttext").innerHTML="<textarea name='Commenttxt' rows='10' cols='45'>"+commenttextid.value+"</textarea>";
    document.all.comment_Edit.Comment_No.value=commentnumber;
    
}

function init() {
    
    // Define various event handlers for Dialog
    var handleSubmit = function() {        
        this.submit();
    };
    var handleCancel = function() {
        this.cancel();
    };
    
    var handleSuccess = function(o) {
        var messages = o.responseText;        
        if (messages!=null)
        {
            var resultshow = messages;
            commenttextid.value=document.all.comment_Edit.Commenttxt.value;
            showid.innerHTML = resultshow;
        }
        else
        {
           alert("알수없는 에러가 발생 하였습니다.");
           return;
        }
    };
    var handleFailure = function(o) {
        alert("Submission failed: " + o.status);
    };

    // Instantiate the Dialog
    YAHOO.example.container.commentEdit = new YAHOO.widget.Dialog("commentEdit", 
                            { width : "33em",
                              fixedcenter : true,
                              visible : false, 
                              constraintoviewport : true,
                              buttons : [ { text:"확인", handler:handleSubmit, isDefault:true },
                                      { text:"취소", handler:handleCancel } ]
                            });

    // Validate the entries in the form to require that both first and last name are entered

    // Wire up the success and failure handlers
    YAHOO.example.container.commentEdit.callback = { success: handleSuccess,
                             failure: handleFailure };
    
    // Render the Dialog
   YAHOO.example.container.commentEdit.render();

   // YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.commentEdit.show, YAHOO.example.container.commentEdit, true);
    //YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.commentEdit.hide, YAHOO.example.container.commentEdit, true);
}
function messageWrite(userNO)
{
    window.open ("/kr/message/instantMessage.php?action=new&receiveUserNo="+userNO+"&opentype=bbs", "newwindow", "height=500, width=650, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no")
}

function BlackArticle(articleno,commentno,userno)
{
    document.frmBBS.action.value = "blackarticle";
    document.frmBBS.no.value = articleno;
    document.frmBBS.commentno.value = commentno;
    document.frmBBS.userno.value = userno;
    document.frmBBS.submit();
}

function quote(commentno,nickname)
{
    commenttextid = eval("document.all.Article"+commentno);
    var quotetext = commenttextid.value;
    var quotearray = quotetext.split("[/quotation]");
    if(quotearray.length>0)
    {
        quotetext = quotearray[quotearray.length-1];
    }
    
    document.frmBBSComment.txtComment.value="[quotation] "+decodeURI(escape(nickname))+" 님께서 올린글: "+quotetext+"[/quotation]"+"\r\n";
}



