function createAuthCode(position) {
    var inst = '<span id="rdacspan' + position + '" class="left topspace10">'
             + '<span>验证码：</span>'
             + '<input id="rdauthCode" value="" style="height:15px;line-height:15px;" maxLength="4" size="4" type="text"/>'        
             + '<img id="rdvldtCode" height="22" width="90"><a id="rdchangecode">点这里换一张</a>'
             + '</span>';
    $("#rdaftauth"+position).before(inst);  
    refreshCode('rdvldtCode');
    $("#rdchangecode").attr("href","javascript:refreshCode('rdvldtCode');");
}

function removeAuthCode(position) {
    $("#rdacspan"+position).remove();
}

$("#commentAreaBottom").focus(function(){
    $("#postComment").hide();
    replyCancel(g_cid);
	if ($("#rdacspanBottom").length==0) {
        removeAuthCode("Center");
        removeAuthCode("Top");
	    createAuthCode("Bottom");
	}});

function postCommentShow() {
    $("#postComment").show();
    $("#postCommentTop").focus();
    $("#commentAreaTop").focus();
    replyCancel(g_cid);
    removeAuthCode("Center");
    removeAuthCode("Bottom");
    createAuthCode("Top");
}

function postCommentHide() {
    $("#postComment").hide();
    replyCancel(g_cid);
    removeAuthCode("Center");
    removeAuthCode("Bottom");
    removeAuthCode("Top");
}

function showPost() {
    if ($("#postComment").is(":hidden")) {
        postCommentShow();
    } else {
        postCommentHide();
    }
}

function replyComment(cid) {
    g_cid = cid;
    $(".reply_comment").show();
    $(".show_reply_class").remove();
    var replyHtml = '<div id="show_reply_' + cid + '" class="show_reply_class">'
                  + '<div class="publish_comments">'
                  + '    <div class="input_comments">'
                  + '        <div class="left">'
                  + '        <div id="emotionsCenter"></div>'
                  + '        <textarea id="commentAreaCenter" class="comments_textarea"/>'
                  + '        </div>'
                  + '        <span id="rdaftauthCenter" class="reply_comment topspace10">'
                  + '            <span class="anonymity"><input type="checkbox" id="anonyCenter"/> 匿名发表</span>'
                  + '            <input type="button" onclick="replyPost(' + cid + ')" value="回 复" class="commonbutton"/>'
                  + '            <input type="button" id="postCommentCenter" onclick="replyCancel(' + cid + ')" value="放 弃" class="commonbutton"/>'
                  + '        </span>'
                  + '    </div>'
                  + '    <div class="clear"/>'
                  + '</div>'
                  + '</div>';
    $("#comment_item_"+cid).after(replyHtml);
    $("#reply_button_"+cid).hide();
    $("#postComment").hide();
    EmotionContainer._initialize(theme_path,"emotionsCenter", "commentAreaCenter");
    removeAuthCode("Top");
    removeAuthCode("Bottom");
    createAuthCode("Center");
}

function replyCancel(cid) {
    $("#reply_button_"+cid).show();
    $("#show_reply_"+cid).remove();
}