var link_to_php_folder = 'https://www.animalslebanon.org/php/'; var currentSlideID = 0; var key = ''; function showNetCommerce() { if ( $("[name='iam']").attr('value') == 'monthly_giving_latest' ) { opt = 'scrollbars=yes, status=no, width=757, height=700, screenX=40 ,screenY=120,left=40,top=120'; window.open('https://www.animalslebanon.org/php/payment_monthly.php?key=' + key,'NetCommerce Payment Processor', opt); } else { opt = 'scrollbars=yes, status=no, width=770, height=700, screenX=40 ,screenY=120,left=40,top=120'; window.open('https://www.animalslebanon.org/php/payment.php?key=' + key,'NetCommerce Payment Processor', opt); } } //sending the AJAX form data function sendIt2(caller) { var url = link_to_php_folder + "forms.php"; if (!$('#marker').length) { //introduce marker if missing $('#' + caller).append('
'); } $.ajax({ type: "POST", url: url, data: $("#" + caller).serialize(), success: function(data) { var marker = $('#marker'); var arr = data.split('*'); if (arr[0] != 'ok') { var target = $("[name='" + arr[0] +"']"); if (arr[1] == currentSlideID) { //same state target.focus(); marker.css({top: (target.position().top +1) + 'px', left: (target.position().left + target.width() + 15) + 'px'}); marker.show(); } else { marker.hide(); nextStep(nextSlideID); } } else { marker.hide(); key = data.substring(3); finishIt(); } } }); } function finishIt() { nextStep(nextSlideID); } function nextStep(which) { currentSlideID = which; switch(which) { case 2: $('#buttons').hide(); $('#info').show(); $('#bubls').css({ 'background-position':'0px -29px'}); $('#st2').css({ color:'#000'}); if ( $("[name='iam']").attr('value') == 'monthly_giving_latest' ) { nextSlideID = 6; } else if ($("[name='monthly']").is(':checked') || $("[name='iam']").attr('value') == 'monthly_giving') { nextSlideID = 3; $("[name='iam']").attr('value', 'monthly_giving'); $("[name='special']").attr('value', 'Monthly'); } else { nextSlideID = 4; } $("[name='step']").attr('value', '2'); break; case 3: $('#info').hide(); $('#ccard').show(); $('#bubls').css({ 'background-position':'0px -58px'}); $('#st3').css({ color:'#000'}); nextSlideID = 4; break; case 4: $('#info').hide(); $('#ccard').hide(); $('#donatio').hide(); $('#netcommerce').show(); $('#bubls').css({ 'background-position':'0px -58px'}); $('#st3').css({ color:'#000'}); break; case 5: $('#ccard').hide(); $('#thank-you').show(); $('#bubls').css({ 'background-position':'0px -87px'}); $('#st4').css({ color:'#000'}); break; case 6: $('#info').hide(); $('#donatio').show(); $('#bubls').css({ 'background-position':'0px -58px'}); $('#st3').css({ color:'#000'}); $("[name='step']").attr('value', '3'); nextSlideID = 4; break; } } function validateAmount() { var d = new Date(); var n = d.getDay(); //account will be deducted tomorrow unless tomorrow is Sunday //so unless it's Saturday. On Saturday, account will be deducted on Monday. if (n == 6) { d.setDate(d.getDate() + 1); //skip the next day } d.setDate(d.getDate() + 1); dadate = days[d.getDay()] + ', ' + months[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear(); $("#next_date").html(dadate); //chcking the misc amount txt = $("[name='other']").val(); txt = txt.replace('$ ', ''); amount = parseInt(txt); if (amount > 0) { $("[name='amount']").attr('value', amount); } amount = parseInt( $("[name='amount']").attr('value') ) if ( amount > 0) { $("#monthly_amount").html('$ ' + amount); nextSlideID = 2; currentSlideID = 1; sendIt2('donation_form'); } } function fillMonthYear(obj) { buf = ''; var d = new Date(); var m = d.getMonth(); var y = d.getFullYear(); icount = 0; while (icount < 37) { buf += ''; m++; if (m > 11) { y++; m = 0; } icount++; } $("[name='" + obj + "']").html(buf); } //clicking the others field turns off buttons and resets the amount $("[name='other']").on("mousedown", function(event) { $('#buttons a').removeClass('rouge_bg'); $("[name='amount']").attr('value', 0); }); //filtering the field value, placing the $ sign $("[name='other']").on("input", function () { amount = $("[name='other']").val(); amount = amount.replace('$', ''); amount = '$ ' + amount.replace(' ', ''); $("[name='other']").val(amount); }); //cancel return keys on the field $("[name='other']").on("keypress", function (e) { if(!String.fromCharCode(e.which).match(/[0-9]/)) { e.preventDefault(); // not a valid character so cancel it } }); //clicking the buttons $(".aca_button").on("click", function(event) { switch(event.target.id){ case 'ab1': wi = 1; valu = 25; break; case 'ab2': wi = 2; valu = 50; break; case 'ab3': wi = 3; valu = 100; break; case 'ab4': wi = 4; valu = 250; break; } $('#buttons a').removeClass('rouge_bg'); $('#buttons a:nth-child('+ wi + ')').addClass('rouge_bg'); $("[name='amount']").attr('value', valu); $("[name='other']").val(''); }); //next step click $("#next_button").on("click", function(event) { switch(currentSlideID) { case 0: validateAmount(); break; case 1: case 2: case 3: case 6: sendIt2('donation_form'); break; case 4: showNetCommerce(); break; } }); fillMonths('dob_month'); fillYearsDOB('dob_year'); fillMonths('exp_month'); fillYearsCC('exp_year'); fillCountry('country'); fillMonthYear('last_month_contribution');