var ContractFX=window.ContractFX=window.ContractFX||{};ContractFX.Controls=ContractFX.Controls||{};ContractFX.Controls.ERFx=ContractFX.Controls.ERFx||{};ContractFX.Controls.ERFx.ShoppingCart=function(n,t,i){let r=this;this._containerID=n;this._lblShoppingCartItemCountID=t;this._lblShoppingCartTotalValueID=i;this.container=jQuery("#"+this._containerID);this._OnRemoveItem=null;this._OnRemoveItem2=null;r._OnRmoveListeners=[];r.AddRemoveListener=function(n){let t=r._OnRmoveListeners.indexOf(n);t<0&&r._OnRmoveListeners.push(n)};this._OnRemoveItemValidation=null;this._OnCartClear=null;r._OnCartClearListeners=[];r.AddCartClearListener=function(n){r._OnCartClearListeners.push(n)};this.Init=function(){var n;this.container=jQuery("#"+this._containerID);this.container.find(".shopping-cart-item").length<=0&&(this.container.find(".shopping-cart-empty-text").show(),this.container.find(".clear-cart-link").hide(),this.container.find(".btn-view-cart").hide());n=this;$(document).mouseup(function(t){var i=jQuery(n.container.find(".shopping-cart-ddl-popup")[0]),r=jQuery(n.container.find(".div-cart-container")[0]);i==null||i.is(t.target)||i.has(t.target).length!==0||r==null||r.is(t.target)||r.has(t.target).length!==0||i.hide()});jQuery(this.container.find(".div-cart-container")[0]).click(function(){n.OpenHideShoppingCartPopup()});this.AjaxRemoveItemFromCart=function(t){loading.Show();var i=function(t){loading.Show();$.ajax({type:"POST",url:"/Services/EventsService.asmx/RemoveShoppingCartItem",contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({ShoppingCartItemID:t}),async:!0,success:function(i){n.RemoveShoppingCartItem(t);i!=null&&i.d!=null&&n.UpdateGeneralShoppingCartData(i.d);n._OnRemoveItem!=null&&n._OnRemoveItem({itemID:t,data:i});n._OnRemoveItem2!=null&&n._OnRemoveItem2({itemID:t,data:i});r._OnRmoveListeners&&r._OnRmoveListeners.length>0&&r._OnRmoveListeners.forEach(function(n){n({itemID:t,data:i})})},error:function(){loading.Hide();k12PopupEFX.Alert('<div class="d-flex justify-content-center">Service not Responding<\/div>')}})};$.ajax({type:"POST",url:"/Services/EventsService.asmx/ValidateShoppingCartItemRemove",contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({ShoppingCartItemID:t}),async:!0,success:function(r){r!=null&&r.d!=null?r.d.isOk?r.d.Message!=""?(loading.Hide(),k12PopupEFX.Confirm('<div class="d-flex justify-content-center">'+r.d.Message+"<\/div>",function(){i(t)})):i(t):r.d.Message!=""?(loading.Hide(),k12PopupEFX.Alert('<div class="d-flex justify-content-center">'+r.d.Message+"<\/div>"),n._OnRemoveItemValidation!=null&&typeof n._OnRemoveItemValidation=="function"&&n._OnRemoveItemValidation()):(loading.Hide(),k12PopupEFX.Alert('<div class="d-flex justify-content-center">Service not Responding<\/div>')):(loading.Hide(),k12PopupEFX.Alert('<div class="d-flex justify-content-center">Service not Responding<\/div>'))},error:function(){loading.Hide();k12PopupEFX.Alert('<div class="d-flex justify-content-center">Service not Responding<\/div>')}})};n=this;this.container.find(".shopping-cart-remove-btn").click(function(){var t=jQuery(this),i=t.data("cartitem-id");n.AjaxRemoveItemFromCart(i)});this.container.find(".clear-cart-link").click(function(){var t=n.container.find(".shopping-cart-item");k12PopupEFX.Confirm('<div class="d-flex justify-content-center">Are you sure that you want to clear the cart?<\/div>',function(){$.ajax({type:"POST",url:"/Services/EventsService.asmx/ClearShoppingCart",contentType:"application/json; charset=utf-8",async:!0,success:function(i){n.UpdateGeneralShoppingCartData(i.d);for(var u=0;u<t.length;u++)n.RemoveShoppingCartItem($(t[u]).attr("data-cartitem-id"));n._OnCartClear!=null&&typeof n._OnCartClear=="function"&&n._OnCartClear();r._OnCartClearListeners&&r._OnCartClearListeners.length>0&&r._OnCartClearListeners.forEach(function(n){n()})},error:function(){loading.Hide();k12PopupEFX.Alert('<div class="d-flex justify-content-center">Service not Responding<\/div>')}})})})};this.OpenHideShoppingCartPopup=function(n){var t=jQuery(this.container.find(".shopping-cart-ddl-popup")[0]);n==null?t.is(":visible")?t.hide():t.show():n?t.show():t.hide()};this.UpdateGeneralShoppingCartData=function(n){var t=jQuery("#"+this._lblShoppingCartItemCountID),i=jQuery("#"+this._lblShoppingCartTotalValueID);t!=null&&t!=undefined&&t.text(n.ItemsInCart);i!=null&&i!=undefined&&i.text(n.TotalAmountStr)};this.RemoveShoppingCartItem=function(n){var t=jQuery("#"+this._containerID),i=jQuery(t.find('.shopping-cart-item[data-cartitem-id="'+n+'"]')[0]);i.remove();t.find(".shopping-cart-item").length<=0&&(t.find(".shopping-cart-empty-text").show(),t.find(".clear-cart-link").hide(),t.find(".btn-view-cart").hide());loading.Hide()};this.AddShoppingCartItem=function(n,t,i){var r=this;i==null&&(i=1);$.ajax({type:"POST",url:"/Services/EventsService.asmx/AddShoppingCartItem",contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({itemId:n,quantity:t,itemType:i}),async:!0,success:function(){},error:function(){k12PopupEFX.Alert('<div class="d-flex justify-content-center">Service not Responding<\/div>')}})}}