var buttons = jQuery('.box.donate'); var input = jQuery('.custom-donate input'); var activeValue = 25; var formValid = false;
var validation = { bank: false, agreement: false, email: false };
var setActive = function (amount) { amount = Math.round(amount); if (amount < 1) { amount = 1; } jQuery('.box.donate').removeClass('active'); jQuery('.box.donate[data-amount=' + amount + ']').addClass('active'); jQuery('.boxes form input[name=amount]').val(amount * 100); }; function getInputValue(name) { return jQuery('form input[name="' + name + '"]').val(); } function getCheckboxValue(name) { return jQuery('form input[name="' + name + '"]:checked').val(); } var getSig = function () { var str = ""; // str += "agreement=" + getInputValue("agreement") + "&"; str += "amount=" + getInputValue("amount") + "&"; str += "client_ip=" + getInputValue("client_ip") + "&"; str += "desc=" + getInputValue("desc") + "&"; str += "email=" + encodeURIComponent(getInputValue("email")) + "&"; str += "first_name=" + getInputValue("first_name") + "&"; str += "js=" + getInputValue("js") + "&"; str += "last_name=" + getInputValue("last_name") + "&"; str += "pay_type=" + getCheckboxValue("pay_type") + "&"; str += "pos_auth_key=" + getInputValue("pos_auth_key") + "&"; str += "pos_id=" + getInputValue("pos_id") + "&"; str += "session_id=" + getInputValue("session_id") + "&"; str += "ts=" + getInputValue("ts") + "&"; str += "2ad612506f94381d927e0dec249cf2dd"; return sha256(str); }; buttons.each(function (index, button) { jQuery(button).click(function () { activeValue = jQuery(button).data('amount'); setActive(activeValue); jQuery(input).val(activeValue); // Ustawienie wartości w polu input }); }); jQuery(input).change(function () { var inp = jQuery(this); activeValue = inp.val(); setActive(activeValue); }); var validateForm = function () { var isValid = validation.agreement && validation.bank && validation.email; if (isValid) { jQuery('.form-error').hide(); jQuery('.przekaz').show(); } else { jQuery('.form-error').show(); jQuery('.przekaz').hide(); } }; jQuery('form[name="payU-form"] table td a').each(function (idx, a) { jQuery(a).click(function () { validation.bank = true; validateForm(); }); }); jQuery('form[name="payU-form"] input[type="radio"]').each(function (idx, radio) { jQuery(radio).change(function () { validation.bank = true; validateForm(); }); }); jQuery('form[name="payU-form"]').submit(function (e) { var self = this; var sig = getSig(); this.agreement.disabled = true; jQuery(self).find('input[name="sig"]').val(sig); return true; }); jQuery('form[name="payU-form"] input[name="agreement"]').change(function () { validation.agreement = jQuery(this).is(':checked'); validateForm(); }); jQuery('form[name="payU-form"] input[name="email"]').change(function () { var val = jQuery(this).val(); validation.email = val.length > 0;
validateForm(); });
setActive(activeValue);
