var link_to_php_folder = '//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); window.location.href = 'https://www.animalslebanon.org/php/payment_monthly.php?key=' + key; } else { opt = 'scrollbars=yes, status=no, width=770, height=700, screenX=40 ,screenY=120,left=40,top=120'; window.location.href = 'https://www.animalslebanon.org/php/payment.php?key=' + key; //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 = 6; $("[name='steps']").attr('value', '3'); $("[name='iam']").attr('value', 'monthly_giving_latest'); $("[name='special']").attr('value', 'Monthly New'); } else { nextSlideID = 4; } $("[name='step']").attr('value', '2'); break; case 4: $('#info').hide(); $('#donatio').hide(); $('#netcommerce').show(); $('#bubls').css({ 'background-position':'0px -58px'}); $('#st3').css({ color:'#000'}); break; case 5: $('#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 if ($("[name='currency']").val() == 840){ txt = $("[name='other']").val(); txt = txt.replace('$ ', ''); amount = parseInt(txt); if (amount > 0) { $("[name='amount']").attr('value', amount); } } else { txt = $("[name='other2']").val(); txt = txt.replace('LBP ', ''); 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 < 61) { 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 others field turns off buttons and resets the amount $("[name='other2']").on("mousedown", function(event) { $('#buttons a').removeClass('rouge_bg'); $("[name='amount']").attr('value', 0); }); //filtering the field value, placing the $ sign $("[name='other2']").on("input", function () { amount = $("[name='other2']").val(); amount = amount.replace('LBP', ''); amount = 'LBP ' + amount.replace(' ', ''); $("[name='other2']").val(amount); }); //cancel return keys on the field $("[name='other2']").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': valu = 25; break; case 'ab2': valu = 50; break; case 'ab3': valu = 100; break; case 'ab4': valu = 250; break; case 'bb1': valu = 50000; break; case 'bb2': valu = 100000; break; case 'bb3': valu = 250000; break; case 'bb4': valu = 500000; break; } $('#buttons a').removeClass('rouge_bg'); //$('#buttons a:nth-child('+ wi + ')').addClass('rouge_bg'); $(event.target).addClass('rouge_bg'); $("[name='amount']").attr('value', valu); $("[name='other']").val(''); $("[name='other2']").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; } }); $("#switchlbp").on("click", function(event) { $("[name='currency']").attr('value', '422'); $('#usdmode').hide(); $('#lbpmode').show(); }); $("#switchusd").on("click", function(event) { $("[name='currency']").attr('value', '840'); $('#usdmode').show(); $('#lbpmode').hide(); }); fillMonths('dob_month'); fillYearsDOB('dob_year'); fillMonths('exp_month'); fillYearsCC('exp_year'); fillCountry('country'); fillMonthYear('last_month_contribution');