$(document).on("ready",function(){function e(n){switch(olxConfig.selectedDonationType){case donationTypes.MONTHLY:$(".showForMonthly").show().css("visibility","visible");$(".hideForMonthly").hide();$("#monthlycontent sub").show();$("#oneoffcontent").hide();$(".btn-month-option-box").addClass("active");$(".btn-content.first").addClass("active");$(".btn-content.second").removeClass("active");$(".donation-container").removeClass("one-off-donation-theme");$(".donation-container").addClass("monthly-donation-theme");break;case donationTypes.ONEOFF:$(".hideForMonthly").show().css("visibility","visible");$(".showForMonthly").hide();$("#monthlycontent sub").hide();$("#oneoffcontent").fadeIn("1000");$(".btn-month-option-box").removeClass("active");$(".btn-content.first").removeClass("active");$(".btn-content.second").addClass("active");$(".donation-container").removeClass("monthly-donation-theme");$(".donation-container").addClass("one-off-donation-theme")}(window.location.href=window.location.href.substr(0,window.location.href.indexOf("#"))+"#"+olxConfig.selectedDonationType,n)||trackEvents("Donate form tab change",olxConfig.campaign,olxConfig.selectedDonationType)}function n(){var n=w(olxConfig.selectedDonationRadioOption);$(".btn-month-option-box").removeClass("error");$(".btn-month-option-box").removeClass("active");$(".amountError").addClass("hide");$selectedOption=$("#"+olxConfig.selectedDonationRadioOption);$selectedOption.prop("checked",!0);$selectedOption.prev(".btn-month-option-box").addClass("active");olxConfig.selectedAmount=n.amount;(n.amount!=""||n.amount!=0)&&(olxConfig.selectedAmount=n.amount,$("input[name=amountOther]").val(""),$("#bboxdonation_gift_rdGivingLevel4").prop("checked",!0),$("input#bboxdonation_gift_txtOtherAmountButtons").val(n.amount));p(olxConfig.selectedDonationType);b(n);$("#donation-monthly-options-bottom-content").css("visibility","visible")}function a(){e(!0);n();trackEvents("Donate form value loaded",olxConfig.campaign,olxConfig.selectedDonationType+" - "+olxConfig.selectedAmount)}function v(){var n=$("#mongo-form");n.length!==0&&($("#bboxdonation_divThanks").length>0&&r?(r=!1,i(),g(olxRecord)):(y(),$("html,body").animate({scrollTop:$(".form-area-outer").offset().top},"slow"),$(".open-popup-modal").magnificPopup("close")))}function s(){var n=$("#mongo-form"),t;n.length!==0&&(t=$("input, textarea",n),t.each(function(){var n=$(this).prev(),t;n.length>0&&(t=n.text(),$(this).attr("placeholder",t))}),$("select#bboxdonation_payment_cboCardType").find('option:contains("<Please Select>")').text("Card type"),$("option","#bboxdonation_giftattributes_ctl00_ddCodeTable").first().text("Reason for your donation"),o())}function h(){t||(i(),olxConfig.selectedDonationType=donationTypes.MONTHLY,olxConfig.campaign="UNHCR",e(),n(),bbox.showForm(olxConfig.monthlyGuid))}function c(){t||(i(),olxConfig.pageType==pageTypes.DONATE&&(olxConfig.campaign=$("select[name=donateTo] option:selected").val()),olxConfig.selectedDonationType=donationTypes.ONEOFF,e(),n(),bbox.showForm(olxConfig.oneoffGuid))}function y(){var i=$("#divError .BBFormServerErrorItem"),n="",t;return $.each(i,function(t,i){n=n+" - "+$(i).html()}),t=JSON.stringify({PaymentTerm:olxConfig.selectedDonationType,Amount:olxConfig.selectedAmount,Campaign:olxConfig.campaign,Title:$("#bboxdonation_billing_ddTitle").val(),FirstName:$("#bboxdonation_billing_txtFirstName").val(),LastName:$("#bboxdonation_billing_txtLastName").val(),Email:$("#bboxdonation_billing_txtEmail").val(),Phone:$("#bboxdonation_billing_txtPhone").val(),Country:$("#bboxdonation_billing_billingAddress_ddCountry").val(),Address:$("#bboxdonation_billing_billingAddress_txtAddress").val(),Suburb:$("#bboxdonation_billing_billingAddress_txtAUCity").val(),State:$("#bboxdonation_billing_billingAddress_ddAUState").val(),Postcode:$("#bboxdonation_billing_billingAddress_txtAUPostCode").val(),HearAboutUs:$("#bboxdonation_giftattributes_ctl00_ddCodeTable").val(),ReasonOfFailed:n,Subscribe:$("#subscribe:checked").val()?1:0,UniqueCode:olxConfig.uniqueCode}),$.ajax({url:"/umbraco/surface/donation/saveolxfaileddata/",data:t,type:"POST",contentType:"application/json; charset=utf-8",success:function(){},error:function(){}}),!0}function p(n){var t=0,i=0,r=0,f;n==donationTypes.MONTHLY?(t=donations.monthly.amount1,i=donations.monthly.amount2,r=donations.monthly.amount3):olxConfig.pageType==pageTypes.DONATE?(f=u(),f&&(t=f.oneoff.amount1,i=f.oneoff.amount2,r=f.oneoff.amount3)):(t=donations.oneoff.amount1,i=donations.oneoff.amount2,r=donations.oneoff.amount3);$("#radiooption1").val(t.amount);$("#radiooption2").val(i.amount);$("#radiooption3").val(r.amount);$("#amount1").text(t.amount);$("#amount2").text(i.amount);$("#amount3").text(r.amount)}function u(){var n="";return $("select[name=donateTo] option:selected").val()!=undefined&&$("select[name=donateTo] option:selected").val()!=""&&(n=$("select[name=donateTo] option:selected").data("script-id").replace(/\-/g,"")),donations.lists[n]}function w(n){var t;switch(n){case"radiooption1":olxConfig.selectedDonationType==donationTypes.MONTHLY?t=donations.monthly.amount1:olxConfig.selectedDonationType==donationTypes.ONEOFF&&(olxConfig.pageType==pageTypes.DONATE?(listItem=u(),t=listItem.oneoff.amount1):t=donations.oneoff.amount1);break;case"radiooption2":olxConfig.selectedDonationType==donationTypes.MONTHLY?t=donations.monthly.amount2:olxConfig.selectedDonationType==donationTypes.ONEOFF&&(olxConfig.pageType==pageTypes.DONATE?(listItem=u(),t=listItem.oneoff.amount2):t=donations.oneoff.amount2);break;case"radiooption3":olxConfig.selectedDonationType==donationTypes.MONTHLY?t=donations.monthly.amount3:olxConfig.selectedDonationType==donationTypes.ONEOFF&&(olxConfig.pageType==pageTypes.DONATE?(listItem=u(),t=listItem.oneoff.amount3):t=donations.oneoff.amount3)}return t}function i(){var n,i;t=!0;n=$(".form-wrapper");n?n.css("visibility","hidden"):f({level:0,message:"could not find donation form wrapper"},function(){},function(){});i=$(".loading-form");i?i.show():f({level:0,message:"could not find donation loading form"},function(){},function(){})}function o(){t=!1;$(".loading-form").hide();$(".form-wrapper").css("visibility","visible")}function b(n){$("#donation-monthly-options-bottom-content").fadeIn();var t="";$("select[name=donateTo] option:selected").val()!=undefined&&$("select[name=donateTo] option:selected").val()!=""&&(t=$("select[name=donateTo] option:selected").data("script-id").replace(/\-/g,""));$(".text-before-amount").html(l(n.prevalue));$(".text-after-amount").html(l(n.postvalue));$("#amount-from-olx").html(n.amount);n.icon?$("#donation-monthly-options-bottom-content img.icon-right").attr("src",n.icon).fadeIn():$("#donation-monthly-options-bottom-content img.icon-right").fadeOut()}function k(n){return/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(n)}function l(n){return $("<div/>").html(n).text()}function d(n,t,i){return $.ajax({url:"/umbraco/surface/donation/SaveDonationFormDataBeforeProcessing/",data:n,type:"POST",contentType:"application/json; charset=utf-8",success:t,error:i}),!0}function f(n,t,i){return $.ajax({url:"/umbraco/surface/donation/SaveLogEntry/",data:n,type:"POST",contentType:"application/json; charset=utf-8",success:t,error:i}),!0}function g(n){return $.ajax({url:"/umbraco/surface/donation/saveolxdata/",data:n,type:"POST",contentType:"application/json; charset=utf-8",success:function(){window.location.replace(olxConfig.thankYouUrl)},error:function(){f({level:0,message:"failed to save olx record for uniqueCode: "+n.uniqueCode+". - "+JSON.stringify(n)},function(){},function(){});$(".open-popup-modal").magnificPopup("open");o()}}),!0}var r,t;window.location.href=window.location.href.substr(0,window.location.href.indexOf("#"))+"#"+olxConfig.selectedDonationType;trackEvents("Donate form landing",olxConfig.campaign,olxConfig.selectedDonationType);navigator.userAgent.match(/Trident\/7\./)&&document.body.addEventListener("mousewheel",function(n){n.preventDefault();var t=n.wheelDelta,i=window.pageYOffset;window.scrollTo(0,i-t)});$(".sticky-flyout-sidebar").click(function(){$(".sticky-flyout-sidebar-detail").removeClass("hidden");$(this).addClass("hidden")});$(".sticky-flyout-sidebar-detail img.img-arrow-and-text, .sticky-flyout-sidebar-detail .open-header.mobile-only").click(function(){$(".sticky-flyout-sidebar").removeClass("hidden");$(this).parent().addClass("hidden")});a();r=!1;window.bboxOverrides={handleSubmitCallbackOverride:function(){v();s()}};window.bboxShowFormComplete=function(){s();o()};$(".custom-select").fancySelect().on("change.fs",function(){t||(i(),n(),olxConfig.currentFormId=$("select[name=donateTo] option:selected").data("script-id"),bbox.showForm(olxConfig.currentFormId),trackEvents("Donate form dropdown change",olxConfig.campaign,donationTypes.ONEOFF))});$(document).on("click","input#radiooption1, input#radiooption2, input#radiooption3",function(t){olxConfig.selectedDonationRadioOption=t.target.id;n()});t=!1;$("a#changeToMonthly").click(function(n){n.preventDefault();h()});$("a#changeToOneOff").click(function(n){n.preventDefault();c()});$("input#monthlyradio").click(function(){h()});$("input#oneoffradio").click(function(){c()});$("#monthlycontent input").on("change",function(){setTimeout(function(){trackEvents("Donate form value change",olxConfig.campaign,olxConfig.selectedDonationType+" - "+olxConfig.selectedAmount)},20)});$(document).on("click","input#radiooption3",function(){var t;olxConfig.selectedDonationType==donationTypes.MONTHLY?t=donations.monthly.amount3:olxConfig.selectedDonationType==donationTypes.ONEOFF&&(t=donations.oneoff.amount3);n(t)});$(document).on("focus click","input[name=amountOther]",function(){$("#donation-monthly-options-bottom-content").hide();$(".btn-month-option-box").removeClass("error");$(".amountError").addClass("hide")});$(document).on("focusout change","input[name=amountOther]",function(n){n.preventDefault();var t=$("input[name=amountOther]").val();olxConfig.selectedAmount=t;(isNaN(t)||t<10)&&($(".btn-month-option-box.active").addClass("error"),$(".amountError").removeClass("hide"));t!=""||t!=0?($("#bboxdonation_gift_rdGivingLevel4").prop("checked",!0),$("input#bboxdonation_gift_txtOtherAmountButtons").val(t)):olxConfig.selectedAmount=0});$(document).on("click","button.btn-lrg-donate.olx",function(){if(olxConfig.selectedAmount>=10)$("#bboxdonation_gift_rdGivingLevel4").prop("checked",!0),$("input#bboxdonation_gift_txtOtherAmountButtons").val(olxConfig.selectedAmount),$(".btn-month-option-box").removeClass("error"),$(".amountError").addClass("hide");else{$(".btn-month-option-box.active").addClass("error");$(".amountError").removeClass("hide");$("html,body").animate({scrollTop:$(".btn-month-option-box").offset().top-100},"slow");return}if($("input#bboxdonation_giftattributes_ctl01_txtAttrib").val(olxConfig.uniqueCode),!$("#readPrivacy:checked").val()){$(".error",".checkboxlisting.privacy .input-check").show();return}$(".checkboxlisting.privacy .input-check",".error").hide();$(".open-popup-modal").magnificPopup("open");$("html,body").animate({scrollTop:$(".loading").offset().top-100},"slow");olxRecord=JSON.stringify({PaymentTerm:olxConfig.selectedDonationType,Amount:olxConfig.selectedAmount,Campaign:olxConfig.campaign,Title:$("#bboxdonation_billing_ddTitle").val(),FirstName:$("#bboxdonation_billing_txtFirstName").val(),LastName:$("#bboxdonation_billing_txtLastName").val(),Email:$("#bboxdonation_billing_txtEmail").val(),Phone:$("#bboxdonation_billing_txtPhone").val(),Country:$("#bboxdonation_billing_billingAddress_ddCountry").val(),Address:$("#bboxdonation_billing_billingAddress_txtAddress").val(),Suburb:$("#bboxdonation_billing_billingAddress_txtAUCity").val(),State:$("#bboxdonation_billing_billingAddress_ddAUState").val(),Postcode:$("#bboxdonation_billing_billingAddress_txtAUPostCode").val(),HearAboutUs:$("#bboxdonation_giftattributes_ctl00_ddCodeTable").val(),Comment:$("#bboxdonation_comment_txtComments").val(),Subscribe:$("#subscribe:checked").val()?1:0,UniqueCode:olxConfig.uniqueCode});d(olxRecord,function(){r=!0;$("input#bboxdonation_btnSubmit").trigger("click")},function(){f({level:0,message:"failed to save pre processing record for uniqueCode: "+olxConfig.uniqueCode},function(){},function(){})})});$("#readPrivacy").change(function(){$(this).val()&&$(".error",".checkboxlisting.privacy .input-check").hide()});$(document).on("focusout","input",function(){$(this).val()!=""&&$(this).removeClass("input-validation-error").parent().children("span.icon-error").removeClass("icon-close-error")});$(document).on("focusout","input[name=paypalEmail]",function(){$(this).val()!=""&&k($(this).val())&&$(this).removeClass("input-validation-error").parent().children("span.icon-error").removeClass("icon-close-error")});$(document).on("click",".fancy-select",function(){$(this).children("select").val()!=""&&$(this).children("select").removeClass("input-validation-error").parent().parent().children("span.icon-error").removeClass("icon-close-error")});i()})