function del_comment(id)
{
	if (confirm('您确定要删除这条评论吗？'))
	{
		$.post('/delete/comment/' + id + '/');
		$('#comment_a'+id).remove();
		$('#comment_b'+id).remove();
	}
}

function report(id)
{
    $.post('/report/comment/' + id + '/');
    $('#comment_r'+id).html('感谢帮助！');
}

function commitComment(){
    if (document.commentForm.comment.value.length > 1000){
        $('#comment_error').show();
    }
    else
        document.commentForm.submit();
}

g_comment_id = 0;
function show_comment_form(anchor, comment_id, user)
{
	g_comment_id = comment_id;
    $(anchor).after($('#reply_comment_form'));
    $('#reply_comment_form').show();
    $('#comment_area').val('@' + user + ': ');
    $('#comment_area').focus();
}

function cancel_comment() {
    $('#comment_area').val('');
    $('#reply_comment_form').hide();
}

function post_comment() {
    var text = $('#comment_area').val();
    var nickname = $('#nickname').html();
    var user_id = $('#user').html();

    if(text.length > 1000) {
        $('#comment_area').after('<span class="errorlist">评论长度不能超过1000字。</span>');
    } else {
        $.post('/reply_comment/'+g_comment_id+'/', 
            {'comment':text, 'bear':'bear', 'nick_name':nickname},
            function(data) {
                if(data=="ok") {
                    cancel_comment();
                } else {
                    $('#comment_area').after(data);
                }
            });
    }
}
