function postComment() {
  $('#comment-status').empty();

  var dog = $.trim($('#comment-form input[name="dog"]').val());
  if (dog.length == 0 || dog.length > 20) {
    $('#comment-status').html("Empty name or name longer than 20");
    return false;
  }

  var ring = $.trim($('#comment-form input[name="ring"]').val());
  if (ring.length == 0 || ring.length > 50) {
    $('#comment-status').html("Empty email or email longer than 50");
    return false;
  }
  if (!/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(ring)) {
    $('#comment-status').html("Invalid email address");
    return false;
  }

  var shit = $.trim($('#comment-form textarea').val());
  if (shit.length == 0 || shit.length > 5000) {
    $('#comment-status').html("Empty content or content longer than 5000");
    return false;
  }

  // Post comment
  var button = $('#comment-form input[type="submit"]');
  button.attr('disabled', 'disabled');
  var origColor = button.css('color');
  button.css('color', '#AAAAAA');
  $('#comment-status').html('Posting your comment...');

  // GA tracking
  if (_gaq) {
    var type = $('#comment-form input[name="type"]').value;
    var object_id = $('#comment-form input[name="id"]').value;
    _gaq.push(['_trackPageview', '/post-comment/' + type + '/' + object_id]);
  }

  $.post('/poo/', $('#comment-form').serialize(),
      function(data) {
      if ($.trim($('#comment-list').html()) == '') {
        $('#comment-list').html('<div class="section-name">1 Comment</div>')
      }
      $('#comment-list').append(data);
      $('#comment-status').empty();
      $('#comment-form textarea').val('');
      button.removeAttr('disabled');
      button.css('color', origColor);
      $('#comment-preview').empty();
      });
  return false;
}

var markdownInput = null;
function previewMarkdown() {
  var input = $('#shit-input').val();
  if (input != markdownInput) {
    markdownInput = input;
    $('#comment-preview').html(converter.makeHtml(input));
  }
  setTimeout(previewMarkdown, 3000);
}

function initShowdown() {
  $('#shit-input').removeAttr('onfocus');
  $('#showdown-script').attr('src', '/static/js/showdown.js');
}
