function OfferDataManipulation(n,t,i,r,u,f){n.length!=0&&SetOfferListJson(t,r,n,i,u,f)}function SetOfferListJson(n,t,i,r,u,f){var e={pageConfigId:t,countryId:0,offeritemTypeId:u,landingPageConfigId:f},o;$("#selectedGeoCountryId").val()!=undefined&&(e.countryId=$("#selectedGeoCountryId").val());o={IsAysnc:!1};AjaxGet(n,e,function(n){var u=n,f,t;window.offerListJson&&window.offerListJson==u||(window.offerListJson=u);n!=undefined&&(f=n.filter(function(n){return n.OfferFor==2}),f.length>0&&$(document).trigger("offersloaded"));SetOfferListJsonAjaxCallBack(i,r,i.val());$("#selectedGeoCountryId").val()!=undefined?$("#selectedGeoCountryId").val()!=""&&$("#selectedGeoCountryId").val()!="0"&&($("#PageType").val()=="Gift"||$("#PageType").val()=="Renewal")&&FillRecipentOfferDropdown(window.offerListJson,i):(t=n.filter(function(n){return n.OfferFor==1}),$(".DonorGiftOfferDd").each(function(){$("option:selected",this).data("stddiscountedrate")==undefined&&$("option:selected",this).text()!="--Select--"&&($("#PageType").val()=="Renewal"?FillDropdown(".DonorGiftOfferDd",t,"OfferId","OfferDesc"):FillDropdown(".DonorGiftOfferDd",t,"OfferWgtId","OfferDisplayText"))}),($("#PageType").val()=="Gift"||$("#PageType").val()=="Renewal")&&FillRecipentOfferDropdown(window.offerListJson,i));$("#PageType").val()!="Gift"&&UpdateOrderTotal(!1)},LoadOfferWgtListErrorCallback,o)}function SetOfferListJsonAjaxCallBack(n,t,i){if(n.val()!=""){var u=window.offerListJson.indexOfOfferWgtId(n.val()),r=window.offerListJson[u];r!=undefined&&r!=null&&(r.IsAutoRnw?DisplayDisclosureMsg(n,t):ResetAutoRenew(t),ShowHideDoNotCreateProfileRb(n,t),UpdateOrderTotalOfferWgt(n,t),SetQtyValByofferId(n,t),GenerateTieredPricing(t,i))}}function ResetAutoRenew(n){if($("#IsAutorenOverride_"+n).length){console.log("PB\\ViewScipts\\Render\\Offer.js: ResetAutoRenew but checkbox override was on so exiting");return}$("#DisclosureTextOfferAutoDiv_"+n).hide();$("#DisclosureTextOfferManualDiv_"+n).hide();$("#DisclosureTextPaymentAutoDiv").hide();$("#DisclosureTextPaymentManualDiv").hide();$("#DisclosureTextOfferAutoDiv_"+n).text("");$("#DisclosureTextPaymentAutoDiv").text("")}function DisplayDisclosureMsg(n,t){var i,s,f,e,o;if($("#PageType").val()!="Renewal"&&window.offerListJson!=undefined){var h=window.offerListJson.indexOfOfferWgtId(n.val()),r=window.offerListJson[h],u=r.AutomaticOrManual;($("#PageType").val()=="Gift"||$("#PageType").val()=="Upsell")&&(u=="1"?u="0":u=="0"&&(u="1"));$("#DisclosureTextOfferAutoDiv_"+t).hide();$("#DisclosureTextOfferManualDiv_"+t).hide();$("#DisclosureTextPaymentAutoDiv").hide();$("#DisclosureTextPaymentManualDiv").hide();$("#DisclosureTextOfferAutoDiv_"+t).text("");$("#DisclosureTextPaymentAutoDiv").text("");u=="1"?(s="0",f=r.DisclosureTxt,i=r.DispOn,i==null&&(i="O"),f!=null&&s=="0"&&(i=="O"?($("#DisclosureTextOfferAutoDiv_"+t).text(f),$("#DisclosureTextOfferAutoDiv_"+t).show(),$("#DisclosureTextOfferParentDiv_"+t).show()):i=="P"&&($("#DisclosureTextPaymentAutoDiv").text(f),$("#DisclosureTextPaymentAutoDiv").show(),$("#DisclosureTextPaymentParentDiv").show()))):u=="0"&&(e=r.IsDefaultChecked,o=r.OptTxt,i=r.DispOn,i=="O"?($("#OptInTxtOffer_"+t).text(o),e?$("#IsManualRenewOffer_"+t).attr("checked","checked"):$("#IsManualRenewOffer_"+t).removeAttr("checked","checked"),$("#DisclosureTextOfferManualDiv_"+t).show(),$("#DisclosureTextOfferParentDiv_"+t).show()):i=="P"&&($("#OptInTxtPayment").text(o),e?$("#IsManualRenewPayment").attr("checked","checked"):$("#IsManualRenewPayment").removeAttr("checked","checked"),$("#DisclosureTextPaymentManualDiv").show(),$("#DisclosureTextPaymentParentDiv").show()))}}function ShowHideDoNotCreateProfileRb(n){var i=window.offerListJson.indexOfOfferWgtId(n.val()),t=window.offerListJson[i],r=t.IsProfileReq,u=t.UpgradeOnly;$(".DoNotCreateRb").hide();$(".CreateNewRb").hide();u==1?($(".DoNotCreateRb").hide(),$(".CreateNewRb").show()):($(".CreateNewRb").show(),r?$(".DoNotCreateRb").hide():$(".DoNotCreateRb").show())}function UpdateOrderTotalOfferWgt(n){var r=window.offerListJson.indexOfOfferWgtId(n.val()),t=window.offerListJson[r],i;i=t.IsBundle?t.BundleStandardRate:t.StandardRate;$("#OrderTotal").html(i)}function SetQtyValByofferId(n,t){var f=window.offerListJson.indexOfOfferWgtId(n.val()),r=window.offerListJson[f],u,i;$("#Qty_"+t).spinner();u=r.IsAllowBulkOffer;i=r.BulkMaxQty;u?$("#QtyParentDiv_"+t).show():$("#QtyParentDiv_"+t).hide();$("#Qty_"+t).val("1");$("#Qty_"+t).attr("max",i);$("#Qty_"+t).spinner("option","max",i)}function GenerateTieredPricing(n,t){var r=window.offerListJson.indexOfOfferWgtId(t),i=window.offerListJson[r];$("#TieredPricingParentDiv_"+n).hide();$("#TieredPricingList_"+n).empty();i.TieredPricingList.length>0&&($.each(i.TieredPricingList,function(t,i){var r;r=i.CustomTxt!=null?"<li class='list-group-item'>"+i.CustomTxt+"<\/li>":i.DiscInpercent!=""&&i.DiscFix==null?"<li class='list-group-item'>"+i.QTYFrom+" - "+i.QTYTo+" "+i.DiscInpercent+"% off<\/li>":"<li class='list-group-item'>"+i.QTYFrom+" - "+i.QTYTo+" $"+i.DiscFix+" off<\/li>";$("#TieredPricingList_"+n).append(r)}),$("#TieredPricingParentDiv_"+n).show())}function LoadOfferWgtListErrorCallback(){}function FillRecipentOfferDropdown(n,t,i,r){var e,f,o;if(n!=undefined){e=n.filter(function(n){return n.OfferFor==2});f=[];$(".RecipientGiftOfferDd").each(function(){$(this).is(":enabled")&&$(this).is(":visible")&&f.push(this)});o=f.length;t!=undefined&&(f=t);var h=$("#IsIncludeDonor").val(),u=0,s=0;h==1&&$(".DonorGiftOfferDd").each(function(){$("option:selected",this).data("stddiscountedrate")!=undefined&&$("option:selected",this).data("stddiscountedrate")!=0&&(u=1,s=1)});$(f).each(function(){var t=$(this).val(),f,c,l,h;localStorage.getItem("clickedRecipient.edit.offerid")!=null&&(t=localStorage.getItem("clickedRecipient.edit.offerid"),localStorage.removeItem("clickedRecipient.edit.offerid"));f=!1;u=i||r?u+1:parseInt(s)+parseInt(o)+parseInt(formObjList.length);$("#actionRecipientId").val()!=""&&(c=$("#actionRecipientId").val(),l=formObjList.indexOfRecipientId(c),u=parseInt(s)+parseInt(o)+parseInt(l));h=$(this);$(this).html("<option value=''>--Select--<\/option>");$(this).next(".holder").html("--Select--");e.length>0&&($.each(e,function(i,r){var s=e[i],c=CalculateTieredPricingToTotal(n[0],u,s.StandardDiscountedRate),o,l;c=Math.round(c*100)/100;r.CustomOfferDesc==null||r.CustomOfferDesc==""?(o=r.OfferDisplayText,o=o.split("$"),l="",o.length>1&&o[1].indexOf(" ")>0&&(l=o[1].substring(o[1].indexOf(" "))),o=o[0]+"$"+parseFloat(c).toFixed(2)+l,r.OfferDesc!=""&&r.OfferDesc!=null&&r.OfferDisplayText!=r.OfferDesc&&(o=r.OfferDesc,o=o.replace(/<rate>/gi,"$"+parseFloat(c).toFixed(2)).replace(/<term>/gi,s.StandardTerm))):o=r.CustomOfferDesc.replace(/<rate>/gi,parseFloat(c).toFixed(2)).replace(/<term>/gi,s.StandardTerm);t==r.OfferId&&(f=!0);h.append($("<option data-mediatypeid="+s.MediaTypeId+" data-stdterm="+s.StandardTerm+" data-stdrate="+s.StandardRate+" data-stddiscountedrate="+parseFloat(c).toFixed(2)+"><\/option>").val(r.OfferId).text(o))}),f&&h.val(t))})}}function UpdateOrderTotal(n,t){var e,u,h,l,i,a;if(n){if(window.offerListJson==null){$("#disCodeDiv").show();$("#disCodeDiv>span").html("Please Select Offer");return}}else if(window.offerListJson==null){i=AddCrossSellToTotal(0);i=AddDonationToTotal(i);$("#OrderTotal").html(parseFloat(i).toFixed(2));return}var y=$("#hdnApplyDiscountUrl").val(),f=$("#DiscCode").val(),o=$("#hdnOfferWidgetDetailId").val(),s=$("input[class=offerRb]:checked"),p=window.offerListJson.indexOfOfferWgtId(s.val()),r=window.offerListJson[p];if(r!=undefined&&r!=null){if(e=$("#Qty_"+o).val(),u=1,isNaN(e)||e==""||(u=parseInt(e)),h=r.BundleStandardRate!=null?r.BundleStandardRate:r.StandardRate,l=r.IsTieredPerCopy,i=0,l=="1"?(a=CalculateTieredPricingToTotal(r,u,h),i=u*parseFloat(a)):(i=u*parseFloat(h),i=CalculateTieredPricingToTotal(r,u,i)),f!=""&&f!=undefined||n){var o=$("#hdnOfferWidgetDetailId").val(),s=$("input[class=offerRb]:checked"),v=s.closest(".SingleRbDiv-"+o).find(".DiscountGroupId").val(),w={discountCode:f,discountId:v,offerRate:i},c;if(n){if($("#disCodeDiv").hide(),$("#disCodeDiv>span").html(""),$("#AppliedMsgDiv_"+t).text(""),f==""){$("#disCodeDiv").show();$("#disCodeDiv>span").html("Please Enter Discount Code");return}if(v==undefined){$("#disCodeDiv").show();$("#disCodeDiv>span").html("Please Select Offer");return}c=$("#Widget-"+t);BlockUi(c)}AjaxGet(y,w,function(r){var f,u;n?(r.IsValid?(i=r.FinalAmount,f=$("#DiscCode").val(),$("#DiscCode").hide(),$("#DiscCodeSubmitBtn_"+t).hide(),$(".discounttxtlbl").hide(),u=$("<div>"),u.addClass("appliedCouponCode"),u.html(f),$("#AppliedMsgDiv_"+t).text($("#AppliedMsg_"+t).val()).css("color","green").show().prepend(u)):$("#AppliedMsgDiv_"+t).text(r.Message).css("color","red").show(),r.IsThirdPartyPaid&&($(".PmtTypeControl").rules("remove","required"),$(".IsThirdPartyPaid").val(1),$(".payment-widget").hide()),UnBlockUi(c)):r.IsValid&&(i=r.FinalAmount);i=AddCrossSellToTotal(i);i=AddDonationToTotal(i);$("#OrderTotal").html(parseFloat(i).toFixed(2))},ApplyDiscountCouponErrorCallback,null)}else i=AddCrossSellToTotal(i),i=AddDonationToTotal(i),$("#OrderTotal").html(parseFloat(i).toFixed(2));$("#fireTrigger").val()=="true"&&$(document).trigger("totalupdated")}}function CalculateTieredPricingToTotal(n,t,i){var r=!1;return n.TieredPricingList!=undefined&&n.TieredPricingList.length!=undefined&&n.TieredPricingList.length>0&&$.each(n.TieredPricingList,function(u,f){if(r)return i;f.QTYFrom<=t&&t<=f.QTYTo?f.DiscInpercent!=""&&(f.DiscFix==null||f.DiscFix==0)?(i=i-i*(f.DiscInpercent/100),r=!0):(i=i-f.DiscFix,r=!0):n.TieredPricingList.length==u+1&&(i=i)}),i}function AddDonationToTotal(n){if($("#DonationSettingWidgetRender_IsDonateAmount").val()!=undefined&&$("#DonationSettingWidgetRender_IsDonateAmount").is(":checked")&&$("#DonationSettingWidgetRender_DonatedAmount").val()!=""){var t=$("#DonationSettingWidgetRender_DonatedAmount").val();n+=parseFloat(t)}return n}function AddCrossSellToTotal(n){return $("input[class=crossSellCbx]").length>0&&$("input[class=crossSellCbx]:checked").each(function(){if(window.crossSellOfferListJson!=undefined){var t=this.id.split("_")[1],i=window.crossSellOfferListJson.indexOfOfferWgtId(t),r=window.crossSellOfferListJson[i];n+=parseFloat(r.StandardRate)}}),n}function UpdateGiftOrderTotal(){var n=0;$(".DonorGiftOfferDd").each(function(){$("option:selected",this).data("stddiscountedrate")!=undefined&&(n+=parseFloat($("option:selected",this).data("stddiscountedrate")))});$(".nopoprec").each(function(){$("option:selected",this).data("stddiscountedrate")!=undefined&&(n+=parseFloat($("option:selected",this).data("stddiscountedrate")))});typeof formObjList!="undefined"&&$(formObjList).each(function(){$("#isModify").val()=="True"?this.Offer.StandardDiscountedRate==undefined||isNaN(this.Offer.StandardDiscountedRate)||(n+=parseFloat(this.Offer.StandardDiscountedRate)):this.StdDiscountedRate==undefined||isNaN(this.StdDiscountedRate)?this.Offer.StandardDiscountedRate==undefined||isNaN(this.Offer.StandardDiscountedRate)||(n+=parseFloat(this.Offer.StandardDiscountedRate),this.StdDiscountedRate=this.Offer.StandardDiscountedRate):n+=parseFloat(this.StdDiscountedRate)});n=AddCrossSellToTotal(n);n=AddDonationToTotal(n);$("#OrderTotal").html(parseFloat(n).toFixed(2));$(document).trigger("totalupdated")}function EnableRowActions(n){$(n).is(":checked")?$(n).closest("tr").find("input").not(n).removeAttr("disabled"):$(n).closest("tr").find("input").not(n).attr("disabled","disabled");UpdateGiftOrderTotal()}function ResetGiftOrderTotal(){formObjList=[];UpdateGiftOrderTotal();BindGrid()}function toggleIsAutorenOverride(n){var t=n.id.split("_")[1];n.checked&&($("#DisclosureTextOfferAutoDiv_"+t).show(),$("#DisclosureTextOfferManualDiv_"+t).hide(),$("#DisclosureTextPaymentAutoDiv").show(),$("#DisclosureTextPaymentManualDiv").hide())}Array.prototype.indexOfOfferWgtId=function(n){for(var t=0;t<this.length;t++)if(this[t].OfferWgtId===parseInt(n))return t;return-1}