function handle_submit_comment() {
    // globals: comment_url
    
    function submit_comment_callback(data) { 
        //Set comment status
        green = "#95FF83"
        red = "#FF6358"
        color = data.success?green:red;
        $("#comment-status").show("slow");
        $("#comment-status").text(data.message);
        $("#comment-status-block").animate({backgroundColor: color}, 1000).animate({backgroundColor: "white"}, 1000);
        
        if(data.success) {
            //Blank the text box
            $("#id_comment")[0].value = "";
            //Blank the "no comments" message if it exists
            if($("#no_comments").length != 0) {
                $("#no_comments").hide("slow");
            }
            //Clone an existing comment to make a new comment <div>
            var new_comment_id = "new-comment-"+Math.round(Math.random()*10000);
            var new_comment = $("#new-comment").clone();
            new_comment.attr("id", new_comment_id);
            $("#comments-list").append(new_comment);
            //Set the relevant data on our new comment
            $("#"+new_comment_id).hide()
            data.comment = data.comment.replace(/\n/g, "</br>")
            $("#"+new_comment_id+" .comment-body").html(data.comment);
            $("#"+new_comment_id).show("slow")
        }
        $("#comment-status").animate({"opacity":1.0}, 3000).hide('slow');
    }
    form_data = get_form_data("#comment-form");
    $.post(comment_url, form_data, submit_comment_callback, 'json');
    return false;
}

function flag(url, comment_id) {
    function handle_flag_callback(data) {
        var msg = "This comment has been flagged as offensive and will be reviewed by the staff."
        $("#comment-"+comment_id+" .comment-body").append("<div class='offensive_status'>"+msg+"</div>");
        $("#comment-"+comment_id+" .comment-flag").hide();
    }
    
    $.post(url, handle_flag_callback);
}

jQuery(document).ready(
    function () {
        jQuery("#submit-comment").click(handle_submit_comment);
    }
);