$(function() {
  var $body = $('body');

  $body.on('submit', '.form', function(event) {
    event.preventDefault();
    var $form = $(this);
    var id = $form.attr('id');

    $form.addClass('loading');

    $.ajax({
      type: $form.attr('method'),
      url: $form.attr('action'),
      data: $form.serialize(),
      success: function(data) {
        django_recaptcha_callbacks = [];
        var $new = $(data).find('#' + id);
        $new.find('.reveal').each(function() {
          $(this).removeClass('reveal reveal_animation');
        });
        $new.removeClass('reveal reveal_animation');
        $form.replaceWith($new);
        djangoRecaptchaOnLoadCallback();
      }
    });
  });
});
