CHARITABLE=window.CHARITABLE||{},function(exports,$){var t=function(t){this.errors=[],this.pending_processes=[],this.form=t,this.pause_processing=!1,this.submit_processing=!1,this.total=0,this.prevent_scroll_to_top=!1;var e=this,o=$("body"),r=function(){return e.form.find(".charitable-terms-text").addClass("active"),!1},i=function(){$(this).closest("li").trigger("click").find("input[name=donation_amount]").prop("checked",!0).trigger("change"),e.form.off("focus","input.custom-donation-input",i),$(this).focus(),e.form.on("focus","input.custom-donation-input",i)},n=function(){o.trigger("charitable:form:amount:changed",e),o.trigger("charitable:form:total:changed",e)},a=function(){var t=e.unformat_amount($(this).val());$.trim(t)>0&&$(this).val(e.format_amount(t)),n()},s=function(){var t=$(this).closest("li");t.hasClass("selected")||(t.parents(".charitable-donation-form").find(".donation-amount.selected").removeClass("selected"),t.addClass("selected").find("[name=donation_amount]").prop("checked",!0),t.hasClass("custom-donation-amount")&&t.find("input.custom-donation-input").focus(),n())},c=function(){e.hide_inactive_payment_methods(),e.show_active_payment_methods($(this).val())},d=function(){$(this).parent().addClass("charitable-hidden")},u=function(t){var e=t.data.helper;return!e.submit_processing&&(e.submit_processing=!0,e.show_processing(),!1===e.validate()?(e.cancel_processing(),!1):!1===e.pause_processing&&(1!==e.form.data("use-ajax")||(_(e,(function(){o.trigger("charitable:form:process",e)})),!1)))},_=function(t,e){t.waiting()?setTimeout(_,500,t,e):t.get_errors().length>0?t.cancel_processing():e()},l=function(t,e){var r=e.get_data();e.form;return r.action="make_donation",r.form_action=r.charitable_action,delete r.charitable_action,$.ajax({type:"POST",data:r,dataType:"json",url:CHARITABLE_VARS.ajaxurl,timeout:0,xhrFields:{withCredentials:!0},success:function(t){o.trigger("charitable:form:processed",[t,e]),t.success?_(e,(function(){window.location.href=t.redirect_to})):(e.cancel_processing(t.errors),t.donation_id&&e.set_donation_id(t.donation_id))}}).fail((function(t,o,r){window.console&&window.console.log&&console.log(t),e.cancel_processing([CHARITABLE_VARS.error_unknown])})),!1};e.form.on("click",".donation-amount",s),e.form.on("focus","input.custom-donation-input",i),e.form.on("click",".charitable-terms-link",r),e.form.on("blur",".custom-donation-input",a),e.form.find(".donation-amount input:checked").each((function(){$(this).closest("li").addClass("selected")})),e.get_all_payment_methods().length&&(e.hide_inactive_payment_methods(),e.form.on("change","#charitable-gateway-selector input[name=gateway]",c)),e.form.on("click",".change-donation",d),e.form.on("submit",{helper:e},u),!1===CHARITABLE.forms_initialized&&(o.on("charitable:form:process",l),o.trigger("charitable:form:initialize",e),CHARITABLE.forms_initialized=!0),o.trigger("charitable:form:loaded",e)};t.prototype.get_input=function(t){return this.form.find("[name="+t+"]")},t.prototype.get_email=function(){return this.form.find("[name=email]").val()},t.prototype.is_recurring_donation=function(){var t=this.form.find("[name=recurring_donation]:checked, [name=recurring_donation][type=hidden]");return t.length&&"once"!==t.val()},t.prototype.get_suggested_amount=function(){return accounting.unformat(this.form.find("[name=donation_amount]:checked, input[type=hidden][name=donation_amount]").val(),CHARITABLE_VARS.currency_format_decimal_sep)},t.prototype.get_custom_amount=function(){var t=this.form.find(".charitable-donation-options.active input.custom-donation-input,.charitable-donation-options.active input.custom-donation-amount");return 0===t.length&&(t=this.form.find("input.custom-donation-input")),accounting.unformat(t.val(),CHARITABLE_VARS.currency_format_decimal_sep)},t.prototype.get_subtotal=function(){return this.get_suggested_amount()||this.get_custom_amount()},t.prototype.get_amount=function(){return this.total=this.get_subtotal(),this.form.trigger("charitable:form:get_amount",this),this.total},t.prototype.add_amount=function(t){this.total+=t},t.prototype.remove_amount=function(t){this.total-=t},t.prototype.get_description=function(){return this.form.find("[name=description]").val()||""},t.prototype.get_cc_number=function(){return this.form.find("#charitable_field_cc_number input").val()||""},t.prototype.get_cc_cvc=function(){return this.form.find("#charitable_field_cc_cvc input").val()||""},t.prototype.get_cc_expiry_month=function(){return this.form.find("#charitable_field_cc_expiration select.month").val()||""},t.prototype.get_cc_expiry_year=function(){return this.form.find("#charitable_field_cc_expiration select.year").val()||""},t.prototype.clear_cc_fields=function(){this.form.find("#charitable_field_cc_number input, #charitable_field_cc_name input, #charitable_field_cc_cvc input, #charitable_field_cc_expiration select").removeAttr("name")},t.prototype.get_payment_method=function(){return this.form.find("[type=hidden][name=gateway], [name=gateway]:checked").val()||""},t.prototype.get_all_payment_methods=function(){return this.form.find("#charitable-gateway-selector input[name=gateway]")},t.prototype.hide_inactive_payment_methods=function(){var t=this.get_payment_method(),e=this.form.find(".charitable-gateway-fields[data-gateway!="+t+"]");e.hide(),e.find("input[required],select[required],textarea[required]").attr("data-required",1).attr("required",!1)},t.prototype.show_active_payment_methods=function(t){t=t||this.get_payment_method();var e=this.form.find(".charitable-gateway-fields[data-gateway="+t+"]");e.show(),e.find("[data-required]").attr("required",!0)},t.prototype.format_amount=function(t,e){return void 0===e&&(e=""),accounting.formatMoney(t,{symbol:e,decimal:CHARITABLE_VARS.currency_format_decimal_sep,thousand:CHARITABLE_VARS.currency_format_thousand_sep,precision:CHARITABLE_VARS.currency_format_num_decimals,format:CHARITABLE_VARS.currency_format}).trim()},t.prototype.unformat_amount=function(t){return Math.abs(parseFloat(accounting.unformat(t,CHARITABLE_VARS.currency_format_decimal_sep)))},t.prototype.add_error=function(t){this.errors.push(t)},t.prototype.get_errors=function(){return this.errors},t.prototype.get_error_message=function(){return this.errors.join(" ")},t.prototype.print_errors=function(t){var e=t||this.errors,o=e.length,r="",i=void 0===CHARITABLE_VARS.error_notice_donation_display?"top":CHARITABLE_VARS.error_notice_donation_display;0!==o&&(this.form.find(".charitable-form-errors").length&&this.form.find(".charitable-form-errors").remove(),r+='