function TermsRequired_ClientValidate(n,t){t.IsValid=jQuery(".termsrequired input:checkbox").is(":checked")}function ChangeDebtorStore(n){$.ajax({dataType:"json",async:!1,url:"/api/account/changebranch/"+n}).success(function(n){typeof n!="undefined"&&n.success==!0?location.reload(!0):alert("Error changing the store")}).error(function(){alert("Error changing the store")})}function OpenChangeDebtorStoreDialog(n){var t=0,i=$.Deferred();return $(".dialog-change-store").dialog({modal:!0,autoOpen:!0,position:{my:"center",at:"top+175",of:window},dialogClass:"noTitleStuff",open:function(){},buttons:{OK:function(){n!=null&&n.length>0&&(t=n[0].BranchID);i.resolve(t);$(this).dialog("close")}}}),i.promise()}function IsChangeStoreRequired(n){$.ajax({dataType:"json",async:!1,url:"/api/account/changebranchrequired/"+n}).success(function(n){typeof n!="undefined"&&n.success==!0&&n.changeBranchRequired.ChangeBranchRequired==!0&&$.when(OpenChangeDebtorStoreDialog(n.changeBranchRequired.AvailableBranches)).then(function(n){var t=parseInt(n);t>0&&ChangeDebtorStore(t)})})}var app=angular.module("LiquorApp",["ng","ngRoute","ngCookies"]);app.HeaderBasketLoaded=!1;app.LoginCtrlLoaded=!1;app.controller("LoginCtrl",["$scope","$compile",function(n){var t=$("#IsForgotPasswordMode");n.IsForgotPasswordMode=t!=null&&$("#IsForgotPasswordMode").val()=="true";n.$watch(function(){return $("#IsForgotPasswordMode")!=null&&$("#IsForgotPasswordMode").val()=="true"},function(t){n.SetBreadCrumb(t);n.SetTitles(t)});n.SetTitles=function(t){t?(n.pageTitle="Lost Password",n.pageSubTitle="We will email you instructions to reset and create a new password."):(n.pageTitle="Sign in or Register",n.pageSubTitle="Sign in to your account to place orders, access your order history, and other personalised features.")};n.SetBreadCrumb=function(n){var t=$(".breadCrumbs").find(".content").find("span.breadCrumbs");t.length>0&&(n?t.last().after("<span class='lp'> > <\/span><span  class='lp breadCrumbs'>Lost Password<\/span>"):$(".lp").remove())}}]);app.controller("ViewModeCtrl",["$scope","$cookieStore","$window",function(n,t,i){function r(n,t){var i=new Date;i.setTime(i.getTime()+864e5);document.cookie=n+"="+t+";path=/; expires="+i.toGMTString()}n.IsMobileView=function(){var i=t.get("viewdesktop");n.IsMobile=i!=null?i===!1:!1};n.SetMobileView=function(t){r("viewdesktop",!t);n.IsMobile=t;i.location.reload()};n.IsMobileView()}]);app.controller("ACIntegrationDashboardCtrl",["$scope","$http",function(n,t){function i(){t.get(n.url+"/Get").success(function(t){n.Processors=t}).error(function(){alert("An error occurred. Please, refresh this page.");n.Processors=[]})}n.url="/api/ACIntegrationDashboard";n.Modes=[{id:0,name:"Changed values"},{id:1,name:"All values"}];i();n.refresh=function(){i()};n.saveChanges=function(){var r=n.Processors,i=t.post(n.url+"/Post?FSIntent=true",r,{timeout:3e4});i.success(function(t){alert("Settings were saved successfully");n.Processors=t});i.error(function(){alert("Error occurred. Please, refresh this page")})}}]);app.controller("ACIntegrationBranchMapCtrl",["$scope","$http",function(n,t){function i(){t.get(n.url+"/Get/0").success(function(t){var i,u,f;if(typeof t=="object")if(Array.isArray(t.KnownRegions)?(t.KnownRegions.splice(0,0,{RegionID:0,RegionName:""}),n.Regions=t.KnownRegions):n.Regions=[],Array.isArray(t.KnownBranches)){if(i=t.KnownBranches,n.Branches=i,u=n.currentBranch,n.currentBranch=i[0],typeof u!="undefined")for(f in i)if(i[f].BranchId==u.BranchId){n.currentBranch=i[f];break}}else n.Branches=[];else n.Branches=[],n.Regions=[],n.currentBranch=undefined,n.currentRegionId=undefined;n.currentRegionId=typeof n.currentBranch=="object"?n.currentBranch.RegionId:undefined;r()}).error(function(){n.Branches=[];n.currentBranch=undefined})}function r(){var i=!1;n.hasChanges=!1;typeof n.currentBranch=="undefined"&&(n.currentBranch=n.Branches[0],i=!0);!0&&(typeof n.currentBranch!="undefined"?t.get(n.url+"/Get/"+n.currentBranch.BranchId.toString()).success(function(t){var i=[],u,f,r;Array.isArray(n.Branches)&&(i=n.Branches.slice());for(r in i)if(i[r].BranchId==n.currentBranch.BranchId){i.splice(r,1);break}if(n.SelectedBranches=t,u=[],Array.isArray(n.SelectedBranches)&&Array.isArray(i)){f={};for(r in n.SelectedBranches)f[n.SelectedBranches[r].BranchId]=!0;for(r in i)typeof f[i[r].BranchId]=="undefined"&&u.push(i[r])}n.FreeBranches=u;n.addBranch=Array.isArray(n.FreeBranches)?n.FreeBranches[0]:undefined}):(n.SelectedBranches=[],n.FreeBranches=[]),n.addBranch=Array.isArray(n.FreeBranches)?n.FreeBranches[0]:undefined)}n.url="/api/ACIntegrationBranchMap";n.Branches=[];n.Regions=[];n.FreeBranches=[];n.hasChanges=!1;i();n.refresh=function(n){n.preventDefault();i()};n.saveChanges=function(i){var r,u,f;i.preventDefault();r=n.currentBranch;typeof r!="undefined"&&typeof r.BranchId!="undefined"&&(u={},u.LinkedBranches=n.SelectedBranches,u.RegionID=n.currentRegionId,f=t.post(n.url+"/Post/"+r.BranchId.toString()+"?FSIntent=true",u,{timeout:3e4}),f.success(function(){n.hasChanges=!1;alert("Settings saved successfully")}),f.error(function(){alert("There is an error occurred. Please, refresh this page")}))};n.branchChanged=function(){n.currentRegionId=n.currentBranch.RegionId;r()};n.linkBranch=function(t){if(t.preventDefault(),typeof n.addBranch!="undefined"){n.SelectedBranches.push(n.addBranch);for(var i in n.FreeBranches)if(n.FreeBranches[i]==n.addBranch){n.FreeBranches.splice(i,1);n.addBranch=n.FreeBranches.length>i?n.FreeBranches[i]:n.FreeBranches.length>0?n.FreeBranches[n.FreeBranches.length-1]:undefined;break}}};n.moveUp=function(t,i){if(i.preventDefault(),typeof t!="undefined")for(var r in n.SelectedBranches)if(n.SelectedBranches[r]==t&&r>0){n.hasChanges=!0;n.SelectedBranches.splice(r,1);n.SelectedBranches.splice(r-1,0,t);break}};n.moveDown=function(t,i){if(i.preventDefault(),typeof t!="undefined")for(var r in n.SelectedBranches)if(n.SelectedBranches[r]==t&&r<n.SelectedBranches.length-1){n.hasChanges=!0;n.SelectedBranches.splice(r,1);n.SelectedBranches.splice(r+1,0,t);break}};n.releaseBranch=function(t,i){var r;if(i.preventDefault(),typeof t!="undefined"){for(r in n.SelectedBranches)if(n.hasChanges=!0,n.SelectedBranches[r]==t){n.SelectedBranches.splice(r,1);break}for(r in n.FreeBranches)if(n.hasChanges=!0,n.FreeBranches[r].Caption>=t.Caption){n.FreeBranches.splice(r,0,t);return}n.FreeBranches.push(t);n.addBranch=t}};n.clearAll=function(t){while(n.SelectedBranches.length>0)n.releaseBranch(n.SelectedBranches[0],t)}}]);app.controller("ACIntegrationProductHierarchyCtrl",["$scope","$http",function(n,t){function i(){t.get(n.url+"/Get").success(function(t){typeof t!="undefined"&&(n.Categories=t.Categories,n.Rows=t.Rows)}).error(function(){alert("There is an error occurred. Please, refresh this page");n.Rows=[]})}n.url="/api/ACIntegrationProductHierarchy";n.Categories=[];n.Rows=[];i();n.refresh=function(){i()};n.saveChanges=function(){var r=n.Rows,i;Array.isArray(r)&&(i=t.post(n.url+"/Post?FSIntent=true",r,{timeout:3e4}),i.success(function(){alert("Settings saved successfully")}),i.error(function(){alert("There is an error occurred. Please, refresh this page")}))}}]);app.controller("SplashCtrl",["$scope","$http","$cookies","$window",function(n,t,i,r){var h,f,u,e,o,s;n.getMonths=function(){for(var t=moment.months(),i=[],r,n=0;n<t.length;n++)r=n<10?"0"+(n+1).toString():(n+1).toString(),i[n]={month:t[n],id:r};return i};h=(new Date).getFullYear();n.Regions=[];f={RegionID:0,RegionName:"Region",Id:0};u={BranchId:0,Caption:"Branch",Name:"Branch",Id:0};n.SelectedItems={SelectedRegion:f,SelectedStore:u,SelectedDateOfBirth:0};n.ShowControls={ShowRegions:!1,ShowBranch:!1,ShowEnterRegions:!1};n.$watch("SelectedItems.SelectedDateOfBirth",function(){var t=n.SelectedItems.SelectedDateOfBirth===1;t&&!n.CheckAge()});n.over18=function(t){var i=n.SelectedItems;i.SelectedDate=1;i.SelectedMonth=1;t?(i.SelectedYear=1900,n.isOver18=1):(i.SelectedYear=moment().year(),n.isOver18=2)};n.jcfRefreshAll=function(){typeof n.timeout!="undefined"&&(clearTimeout(n.timeout),n.timeout=undefined);n.timeout=setTimeout(function(){r.jcf.refreshAll()},500)};n.$watchCollection("SelectedItems",function(){n.DOB();var t=n.SelectedItems.SelectedDateOfBirth===1;(!t||n.CheckAge())&&(n.ShowControls.ShowRegions=t,n.ShowControls.ShowBranch=t&&n.SelectedItems.SelectedRegion.RegionID>0,n.ShowControls.ShowEnterRegions=t&&n.SelectedItems.SelectedRegion.RegionID>0&&n.SelectedItems.SelectedStore.BranchId>0,n.jcfRefreshAll())});n.DobValue=null;n.DOB=function(){if(_.isNumber(n.SelectedItems.SelectedYear)&&n.SelectedItems.SelectedDate&&n.SelectedItems.SelectedMonth){n.SelectedItems.SelectedDateOfBirth=1;var t=moment(n.SelectedItems.SelectedYear+"-"+n.SelectedItems.SelectedMonth+"-"+n.SelectedItems.SelectedDate,"YYYY-MM-DD");return n.DobValue=t.format("YYYYMMDD"),t}return n.SelectedItems.SelectedDateOfBirth=0,moment(null)};n.CheckAge=function(t){var i=n.DOB(),r,u;return i.isValid()?(r=moment().startOf("day").add(-18,"years"),u=i>r,u)?(e.dialog("open"),typeof t!="undefined"&&t.preventDefault(),!1):!0:!1};e=$("#dialog-Under18Warning").dialog({modal:!0,autoOpen:!1,width:600,position:{my:"top",at:"top+175"},dialogClass:"noTitleStuff",open:function(){setTimeout("$('#dialog-Under18Warning').dialog('close')",5e3)},close:function(){window.location="http://www.scholastic.com/ispy/games/index.htm"},buttons:{Ok:function(){$(this).dialog("close")}}});o=$("#dialog-notLocalStore").dialog({modal:!0,autoOpen:!1,width:600,position:{my:"top",at:"top+175"},dialogClass:"noTitleStuff",open:function(){setTimeout("$('#dialog-notLocalStore').dialog('close')",5e3)},close:function(){$(this).dialog("close")},buttons:{Ok:function(){$(this).dialog("close")}}});n.ChangeRegion=function(){n.SelectedItems.SelectedRegion.Stores=_.filter(n.KnownBranches,{RegionId:n.SelectedItems.SelectedRegion.RegionID});n.SelectedItems.SelectedRegion.Stores.unshift(u);n.SelectedItems.SelectedStore=u};n.SetDOBFromCookie=function(){var t=i.VisitorIsAdult,r=i.sessiondob;t!=null&&r!=null&&(n.SelectedItems.SelectedYear=1900,n.SelectedItems.SelectedMonth=01,n.SelectedItems.SelectedDate=01,n.SelectedItems.SelectedDateOfBirth=1)};n.SetDOB=function(){n.SetDOBFromCookie()};n.EnterShop=function(){if(n.CheckAge()){$("#DOB").attr("value",n.DOB().format("YYYYMMDD"));var i=n.SelectedItems.SelectedStore.BranchId,r="/api/Account/islocalstore/"+i;t.get(r).success(function(n){var t=n.success,i=n.IsLocalStore;t&&i?$("#frmEnterShop").submit():o.dialog("open")}).error(function(){alert("Check local store failed.")})}};s=function(){t.get("/api/ACIntegrationBranchMap/GetAvailableBranchesForUser").success(function(t){var r,e;_.isObject(t)&&_.isArray(t.KnownRegions)&&_.isArray(t.KnownBranches)&&(n.KnownRegions=t.KnownRegions,n.KnownBranches=t.KnownBranches,n.Regions=n.KnownRegions,n.Regions.unshift(f),n.SetDOB(),i.selectedStore!=null?(r=_.find(n.KnownBranches,{Id:parseInt(i.selectedStore)||0}),r!=null&&(e=_.find(n.KnownRegions,{RegionID:r.RegionId}),n.SelectedItems.SelectedRegion=e,e.Stores=_.filter(n.KnownBranches,{RegionId:r.RegionId}),e.Stores.unshift(u),n.SelectedItems.SelectedStore=r,n.jcfRefreshAll())):(n.SelectedItems.SelectedRegion=n.Regions[0],n.ChangeRegion(),n.jcfRefreshAll()))}).error(function(){n.Regions=[]})};s();n.jcfRefreshAll()}]);app.factory("CartService",["$http",function(n){var t={Qty:0,Sum:0},i=function(){return n.get("/api/cart/headerproducts").success(function(n){t=n.success?n.data:emptyData}).error(function(){t=emptyData})},r=function(t,i){var r={ProductId:t,Qty:i};return n.post("/api/cart/addproduct?FSIntent=true",r)},u=function(n){var i=Array.isArray(n),t,r;if(i)for(t=0;t<n.length;t++)if(r=n[t],_.parseInt(r.qty)!=r.qty){i=!1;break}return i},f=function(n){headerBasket=n};return{getheaderBasket:i,setheaderBasket:f,addToCart:r,isValidQty:u}}]);app.controller("AddToBasketCtrl",["$scope","CartService",function(n,t){n.Qty=1;n.AddToCart=function(i){var r=[{qty:n.Qty}];if(!t.isValidQty(r)){alert("The quantity of a product must be an integer number");return}t.addToCart(i,n.Qty).then(function(n){var t=n.data;t.success?(t.data.response==="Success"&&(location.href="basket.aspx"),t.data.response==="RedirectToUrl"&&(location.href=t.data.description),t.data.response==="OutOfStock"&&alert(t.data.description),t.data.response==="Error"&&alert(t.data.description)):alert(t.message)})}}]);app.controller("headerBasketCtlr",["$scope","$compile","CartService",function(n,t,i){var r=function(){i.getheaderBasket().then(function(t){n.headerData=t.data.data})};n.$watch(function(){return i.CurrentBasketHeader},function(){n.headerData=i.CurrentBasketHeader});app.HeaderBasketLoaded||(Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(){var i=angular.element(document.getElementById("headerBasket"));i.replaceWith(t(i)(n));n.$apply()}),app.HeaderBasketLoaded=!0);r()}]);app.controller("OrderCtrl",["$scope","$http",function(n,t){n.HeaderTitle="What to Collect";n.url="/api/order";n.ShowTax=!1;n.getOrders=function(i){t.get(n.url+"/orderitems/"+i).success(function(t){t.success?(n.products=t.data,n.ShowTax=t.ShowTax):alert(t.message)}).error(function(){n.products=[]})}}]);app.controller("BasketCtrl",["$scope","$http","$cookies","CartService",function(n,t,i,r){n.headerData={Qty:0,Sum:0};n.url="/api/cart";n.lastShoppingUrl="";n.checkoutUrl="";n.products=[];n.warnings=[];n.subtotalval=0;n.ShowTax=!1;n.HeaderTitle="What's in Your Cart";n.subtotal=function(){return _.reduce(n.products,function(n,t){return n+parseFloat(t.price*t.qty)},0)};n.isEmpty=function(){return n.products.length==0};n.isValidQty=function(){var i=Array.isArray(n.products)&&!n.isEmpty(),t;if(i)for(t in n.products)if(!_.isNumber(t.qty)||_.parseInt(t.qty)!=t.qty){i=!1;break}return i};n.tooLow=function(){return n.subtotal()<n.minOrderAmount};n.tooHigh=function(){return n.maxOrderAmount>0&&n.subtotal()>n.maxOrderAmount};n.enableCheckout=function(){return!n.isEmpty()&&!n.tooLow()&&!n.tooHigh()};n.updateProduct=function(n){var t=[{qty:n.qty}];if(!r.isValidQty(t)){alert("The quantity of a product must be an integer number");return}r.addToCart(n.id,n.qty).then(function(n){var t=n.data;t.success?(t.data.response==="Success",t.data.response==="RedirectToUrl",t.data.response==="OutOfStock"&&alert(t.data.description),t.data.response==="Error"&&alert(t.data.description)):alert(t.message)})};n.deleteProduct=function(i){confirm("Are you sure you want to remove this item from your cart?")&&t.delete(n.url+"/products/"+i.basketitemid).success(function(t){t.success?(n.products=t.data,n.warnings=t.warnings,n.refreshHeader(),n.subtotalval=n.subtotal()):alert(t.message)}).error(function(){n.products=[];n.refreshHeader()})};n.clear=function(){confirm("Are you sure you want to clear your cart?")&&t.delete(n.url+"/products").success(function(t){t.success?(n.products=[],n.warnings=[]):alert(t.message);n.refreshHeader()}).error(function(){n.products=[];n.refreshHeader()})};n.update=function(i){if(!r.isValidQty(n.products)){alert("The quantity of a product must be an integer number");return}var u=_.map(n.products,function(n){return{basketitemid:n.basketitemid,qty:n.qty}});t.post(n.url+"/products?FSIntent=true",u).success(function(t){if(t.success){if(n.products=t.data,n.warnings=t.warnings,n.refreshHeader(),i&&(!t.warnings||t.warnings.length==0)&&t.checkoutUrl){window.location=t.checkoutUrl;return}n.subtotalval=n.subtotal()}else alert(t.message)}).error(function(){n.products=[]})};n.refreshHeader=function(){r.getheaderBasket().then(function(t){n.headerData=t.data.data;r.CurrentBasketHeader=n.headerData})};var u=function(){t.get(n.url+"/products").success(function(t){t.success?(n.products=t.data,n.warnings=t.warnings,n.ShowTax=t.ShowTax,n.subtotalval=n.subtotal()):alert(t.message)}).error(function(){n.products=[]})};u()}]);app.controller("AccountCtlr",["$scope","$http",function(n,t){n.url="/api/Account";var i=function(){t.get(n.url+"/GetCurrentUserInfo",{cache:!0}).success(function(t){typeof t!="undefined"&&(n.UserInfo=t)}).error(function(){n.UserInfo={IsLoggedIn:!1,UserBranch:"Choose Store"}})};i();n.changeStore=function(n,t){$(".dialog-change-store").dialog({modal:!0,autoOpen:!0,width:t,position:{my:"center",at:"top+175",of:window},dialogClass:"noTitleStuff",buttons:{"CHANGE MY STORE":function(){location.href="/Splash.aspx"},"KEEP MY STORE":function(){$(this).dialog("close")}}})}}]);app.controller("SearchCtlr",["$scope","$element","$http",function(n,t,i){n.SearchInput=null;n.url="/api/Search";n.StartSearch=function(t){var u,r;if(t.preventDefault(),u=n.SearchInput.replace(/\s{1,}/g,"+"),u.length<3){alert("Search keyword must be at least 3 characters in length excluding spaces and wildcards.");return}r="/Search.aspx?k="+u;location.href.indexOf("mobile")>=0&&(r="/mobile"+r);i.post(n.url+"/SaveSearchHistory?FSIntent=true",'"'+u+'"').success(function(){location.href=r}).error(function(){location.href=r})};n.EnterSearch=function(i){var r=$(t);if(r!=null)if(i.which||i.keyCode){if(i.which===13||i.keyCode===13)return n.StartSearch(i),!1}else return!0}}]);jQuery(document).ready(function(n){var t=n(".searchPhrase");t!=null&&t.autocomplete({source:function(t,i){n.ajax({url:"/Search.aspx/Suggest",data:"{ 'term': '"+t.term+"' }",dataType:"json",type:"POST",contentType:"application/json; charset=utf-8",dataFilter:function(n){return n},success:function(t){i(n.map(t.d,function(n){return{value:n}}))}})},minLength:2})})