bgneal@89: $(document).ready(function() {
bgneal@89:    var postText = $('#id_body');
bgneal@89:    var postButton = $('#forums-reply-post');
bgneal@89:    postButton.click(function () {
bgneal@89:       var text = $.trim(postText.val());
bgneal@89:       if (text.length == 0) {
bgneal@126:          alert('Please enter some text.');
bgneal@89:          return false;
bgneal@89:       }
bgneal@89:       $(this).attr('disabled', 'disabled').val('Posting reply...');
bgneal@89:       $.ajax({
bgneal@89:          url: '/forums/quick-reply/', 
bgneal@89:          type: 'POST',
bgneal@89:          data: {
bgneal@89:          body : postText.val(),
bgneal@89:          topic_id : $('#id_topic_id').val()
bgneal@89:          },
bgneal@89:          dataType: 'html',
bgneal@89:          success: function (data, textStatus) {
bgneal@89:             postText.val('');
bgneal@89:             $('#forum-topic tr:last').after(data);
bgneal@89:             var lastTr = $('#forum-topic tr:last');
bgneal@89:             lastTr.hide();
bgneal@89:             lastTr.fadeIn(3000);
bgneal@89:             postButton.removeAttr('disabled').val('Submit Reply');
bgneal@89:          },
bgneal@89:          error: function (xhr, textStatus, ex) {
bgneal@108:             alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + 
bgneal@108:                xhr.responseText);
bgneal@89:             postButton.removeAttr('disabled').val('Submit Reply');
bgneal@89:          }
bgneal@89:          });
bgneal@89:       return false;
bgneal@89:    });
bgneal@98:    $('a.post-flag').click(function () {
bgneal@98:       var id = this.id;
bgneal@107:       if (id.match(/fp-(\d+)/)) {
bgneal@98:          id = RegExp.$1;
bgneal@98:          if (confirm('Only flag a post if you feel it is spam, abuse, violates site rules, ' +
bgneal@98:                  'or is not appropriate. ' +
bgneal@98:                  'A moderator will be notified and will review the post. ' +
bgneal@98:                  'Are you sure you want to flag this post?')) {
bgneal@99:              $.ajax({
bgneal@99:                url: '/forums/flag-post/',
bgneal@99:                type: 'POST',
bgneal@99:                data: {id: id}, 
bgneal@99:                dataType: 'text',
bgneal@99:                success: function (response, textStatus) {
bgneal@99:                   alert(response);
bgneal@99:                },
bgneal@99:                error: function (xhr, textStatus, ex) {
bgneal@99:                   alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
bgneal@99:                }
bgneal@99:              });
bgneal@98:          }
bgneal@98:      }
bgneal@98:      return false;
bgneal@98:    });
bgneal@107:    $('a.post-delete').click(function () {
bgneal@107:       var id = this.id;
bgneal@107:       if (id.match(/dp-(\d+)/)) {
bgneal@107:          id = RegExp.$1;
bgneal@107:          if (confirm('Are you sure you want to delete this post?')) {
bgneal@107:              $.ajax({
bgneal@107:                url: '/forums/delete-post/',
bgneal@107:                type: 'POST',
bgneal@107:                data: {id: id}, 
bgneal@107:                dataType: 'text',
bgneal@107:                success: function (response, textStatus) {
bgneal@107:                   alert(response);
bgneal@107:                   $('#post-' + id).fadeOut(3000);
bgneal@107:                },
bgneal@107:                error: function (xhr, textStatus, ex) {
bgneal@107:                   alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
bgneal@107:                }
bgneal@107:              });
bgneal@107:          }
bgneal@107:      }
bgneal@107:      return false;
bgneal@107:    });
bgneal@109:    $('#forum-mod-del-topic').click(function () {
bgneal@109:          return confirm('Are you sure you want to delete this topic?\n' +
bgneal@109:             'WARNING: all posts will be lost.');
bgneal@109:    });
bgneal@89: });