function comment_message(message){
  $("#comment-error").html(message).show().fadeOut(10000);
  return false;
}

$(function(){
  $("#comment-form").submit(function(){
    if($("#comment-author").val().length == 0){
      return comment_message('You forgot to enter your comment!!');
    }
    if($("#comment-email").val().indexOf('@') == -1){
      return comment_message('Invalid email address.');
    }
    if($("#comment-comment").val().length < 10){
      return comment_message('Your comment is too short!');
    }
    $.post("/action/post-comment.php", $(this).serialize(), function(d){
      if(d.success){
        $("#comments").append(d.payload);
        $("#comment-form input[type='text'], #comment-form textarea").val('');
        $("#no-comments").remove();
      }
      comment_message(d.message);
    }, "json");
    return false;
  });
});