function donationController() {
  
  var $this = this;

  this.prepareDonationForm = function() {
    var hasError = false;

    $(document.donationForm).submit(function() {
      $(this.elements).each(function() {
        if ($(this).attr('required') == 'true' && this.value.length < 1) {
          hasError = true;
        }
      });

      if (hasError) {
        alert('Please fill out all fields before submitting the form.');
        return false;
      } else {
        $.post(base_url+'forms/processDonation/ajaxRequest', $(this.elements));
        return true;
      }
    });
  }

}

$(document).ready(function() {
  var donation = new donationController();

  donation.prepareDonationForm();

  $.ajaxSetup({
    async: false
  });
});