function addToList(n){var u=!1,f=n.find("input[type=text]").attr("id"),r;if($("#DonationList").find("input[type=text]").each(function(){$(this).attr("id")==f&&(u=!0)}),u==!1){$("#SearchForm").hide("slow");var t=n.children("div"),i=t.find("input").first(),e=t.find("a").first();e.on("click",function(){removeFromlist(t)});i.on("change",function(){$(this).val()!=""&&(parseFloat($(this).val())!=0?$(this).val(parseFloat($(this).val()).toFixed(2)):$(this).val(""));updateTotal()});i.on("keydown",function(n){onlyDecimal(n)});$("#DonationList").prepend(t);r=i.first().closest("form");r.removeData("validator");r.removeData("unobtrusiveValidation");$.validator.unobtrusive.parse(r);$("#DonationList").children("div").show("slow",function(){i.focus()});$("#ListContainer").show("slow");howMany++}n.hide("slow",function(){n.remove();$("#SearchResults").children("div").children("div").length<=1&&(howMany>1?ShowSearchForm():$("#SearchResults").hide("slow"))})}function SetupRiderDiv(n){var r=n.children("div"),t=r.find("input").first(),u=r.find("a").first(),i;u.on("click",function(){removeFromlist(r)});t.on("change",function(){$(this).val()!=""&&(parseFloat($(this).val())!=0?$(this).val(parseFloat($(this).val()).toFixed(2)):$(this).val(""));updateTotal()});t.on("keydown",function(n){onlyDecimal(n)});i=t.first().closest("form");i.removeData("validator");i.removeData("unobtrusiveValidation");$.validator.unobtrusive.parse(i);$("#DonationList").children("div").show("slow",function(){t.focus()});howMany++}function removeFromlist(n){n.hide("slow",function(){n.find("input").first().val("0");updateTotal();n.remove()});howMany=howMany-1;howMany==0&&$("#ListContainer").hide("slow",function(){ShowSearchForm()})}function ShowSearchForm(){$("#SearchResults").hide("slow",function(){$("#SearchForm").show("slow",function(){$("#SearchName").val("");$("#SearchName").focus();howMany==0&&$("#NonRider").show("slow");$("html, body").animate({scrollTop:parseInt($("#SearchName").offset().bottom)},1e3)})})}function updateTotal(){totalAmount=0;$("#DonationList").find("input[type=text]").each(function(){$(this).val()!=""&&(isNaN($(this).val())||(totalAmount+=parseFloat($(this).val())))});totalAmount=totalAmount.toFixed(2);$("#btnSubmit").val("Make a $0 donation".replace("0",totalAmount));$("#DAF").is(":checked")&&$("#btnSubmit").val($("#btnSubmit").val().replace("donation","Donor Advised Fund"));$("#btnSubmit").prop("disabled",totalAmount==0)}var totalAmount=0,howMany=0;$(function(){$("#SearchName").on("keyup",function(){$("#SearchName").val()!=""?$("#NonRider").hide("slow"):$("#NonRider").show("slow")});if(location.pathname.length>=6){var n=$("#DonationList").children("div"),t=n.find("input").first();SetupRiderDiv(n);t.trigger("change");$("#ListContainer").show(function(){t.focus()});$("#SearchForm").hide();$("#NonRider").hide()}$("#SearchButton").click(function(){var t="/Search/",n;return window.location.pathname.split("/")[1].toLowerCase()=="qa"&&(t="/qa"+t),$("#SearchName").val().length>=3?($("#SearchButton").prop("disabled",!0),$("#Spinner").show(),$("#SearchResults").hide("slow"),$("#SearchValidation").hide(),$("#NonRider").hide("slow"),n=$("#SearchName").val(),n=n.replace("&",""),n=n.replace(":",""),n=n.replace("#",""),n=n.replace("%",""),$("#SearchResults").load(encodeURI($.trim(t+n)),function(n,t,i){if($("#SearchButton").prop("disabled",!1),t=="success"){$("#SearchResults a.AddToList").one("click",function(){addToList($(this).parent())});$("#SearchResults").show("slow",function(){$("#Spinner").hide("slow");$("html, body").animate({scrollTop:parseInt($("#SearchResults").offset().top)},1e3)})}t=="error"&&alert("Error: "+i.status+": "+i.statusText)})):$("#SearchValidation").show(),!1});$("#DafInstructions").on("click",function(){return myApp.showPage("DONATE FROM A DONOR ADVISED FUND","/ems_client/html/DafInstructions.html"),!1});$("#DAF").on("click",function(){updateTotal()});$("#AddMore").on("click",function(){return ShowSearchForm(),!1})})