(function(){bwb.bus=new Vue})(),function(){bwb.pixels={activateRemarketingTag:function(n,t){if(bwb.store.state.allowAllCookies){var i=document.createElement("img");i.onload=function(){return};i.src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1038151260/?value=0&guid=ON&script=0&data.ecomm_prodid="+n+"&data.ecomm_pagetype="+t+"&random="+(new Date).getTime()}}}}(),function(){bwb.cart={serviceUrl:"/cart/cartservices.aspx",checkoutUrl:"/bag/checkout",getCartCount:function(n){if(n){bwb.store.setCartCount(n);return}$.ajax({url:"/Cart/GetCartCount",type:"POST",cache:!1}).done(function(n){bwb.store.setCartCount(n)})},getCartData:function(n,t){n||bwb.store.setCartLoaded(!1);var i=this;$.ajax({url:this.serviceUrl,type:"GET",data:{op:"GetCart"},cache:!1}).done(function(n){if(!n||!n.CartItems){console.log(n);return}var r=0;n.CartSubTotal=0;$.each(n.CartItems,function(t){r+=n.CartItems[t].Quantity;n.CartItems[t].CartPrice=bwb.serverShare.pricing.getForeignPrice(n.CartItems[t].Price,bwb.store.state.cartCurrency);n.CartSubTotal+=parseFloat(n.CartItems[t].CartPrice*n.CartItems[t].Quantity);var i=n.CartItems[t].ProductUrl.replace(".aspx","").split("-");bwb.pixels.activateRemarketingTag(i[i.length-1],"loadCart")});i.getCartCount(r);n.CartSubTotal=n.CartSubTotal.toFixed(2);n.CartPromoTotal=bwb.serverShare.pricing.getForeignPrice(n.PromoTotal,bwb.store.state.cartCurrency);bwb.store.setCartData(n);bwb.store.setCartLoaded(!0);t&&t(n)})},clearCart:function(n){$.post(this.serviceUrl,{op:"ClearCart"},function(t){n&&n(t)},"json")},removePromo:function(n,t){$.post(this.serviceUrl,{op:"RemovePromoCode",code:n},function(n){t&&t(n)},"json")},applyPromo:function(n,t){$.post(this.serviceUrl,{op:"ApplyPromoCode",code:n},function(n){t&&t(n)},"json")},updateQuantity:function(n,t,i){$.post(this.serviceUrl,{op:"UpdateCartItemQuantity",lineId:n,quantity:t},function(n){i&&i(n)},"json")},removeItem:function(n,t){$.post(this.serviceUrl,{op:"RemoveItem",lineId:n},function(n){t&&t(n)},"json")},checkInventoryShortage:function(n,t){$.post(this.serviceUrl,{op:"CheckInventoryShortage",removeInventoryShortage:n},function(n){t&&t(n)},"json")},findReplacement:function(n,t){$.post(this.serviceUrl,{op:"FindReplacement",lineId:n},function(n){t&&t(n)},"json")}}}(),function(){bwb.product={getDetailUrl:function(n,t){return"/product/detail/"+bwb.helpers.dashify(n)+"-"+t},defaultImageCheck:function(n){return bwb.store.state.useOpenLibraryImages?n.naturalHeight==1?(n.src="/images/products/imageless-placeholder.png",!0):!1:undefined},logMissingImage:function(n){bwb.store.state.useOpenLibraryImages&&$.post("/imagelog/"+n)},findProductImageUrl:function(n){if(window.location.href.indexOf("localhost")==-1){var i=n.substring(3,6),t="https://images.bwbcovers.com/"+i+"/"+n+".jpg";$.ajax({url:t,cache:!1}).done(function(){$("#hitimg-"+n).attr("src",t);var i="https://titleimages.betterworldbooks.com/api/Find/Lookup?isbn="+n;$.post(i)})}},buildProductImageUrl:function(n){var t=n;return(n=n.toLowerCase().trim(),n=="")?undefined:_.startsWith(n,"http")?t.replace(/HTTP/i,"http"):(_.startsWith(t,"/")||(t="/"+t),"https://images.bwbcovers.com"+t)},subConditions:[{id:1,name:"New"},{id:2,name:"Refurbished"},{id:3,name:"Refurbished (Used)"},{id:4,name:"Like New"},{id:5,name:"Very Good"},{id:6,name:"Good"},{id:7,name:"Acceptable"},{id:8,name:"Collectible: Like New"},{id:9,name:"Collectible: Very Good"},{id:10,name:"Collectible: Good"},{id:11,name:"Collectible: Acceptable"}],getConditionString:function(n){var i=n>1&&n<8?"Used ":"",t;return isNaN(n)?"":(t=this.subConditions.filter(function(t){return t.id===parseInt(n)}),t[0]==undefined?i+"":i+t[0].name)},getRatingStars:function(n,t){var r,i;for(t||(t=""),r="",i=1;i<=5;i++)r+=n>=i?'<span class="glyphicon glyphicon-star '+t+'"><\/span>':'<span class="glyphicon glyphicon-star-empty '+t+'"><\/span>';return r}}}(),function(){bwb.pricing={inStock:function(n,t){return bwb.store.state.combineInventory?this.isBwbInStock(n,1)==!0||this.isBwbInStock(n,2)==!0:this.isBwbInStock(n,t)==!0},isBwbInStock:function(n,t){return n.Websites?(t=t?t.toString():"",n.Websites.indexOf(t)===-1)?!1:n.BWBInStkArr?n.BWBInStkArr.indexOf(t)>-1:!1:n.BwbInStock},preferUK:function(n){var t=[{zone:3,websiteId:2},{zone:4,websiteId:2},{zone:5,websiteId:2},{zone:6,websiteId:2},{zone:8,websiteId:2},{zone:11,websiteId:2},{zone:12,websiteId:2},{zone:14,websiteId:2}],i;return bwb.helpers.deepFreeze(t),i=_.findIndex(t,function(t){return t.zone===n}),i!==-1},inventoryPreference:function(n){for(var r=!0,i,t=0;t<n.siteCopies.length;t++)if(n.siteCopies[t].ConditionId!=1){r=!1;break}for(i=!0,t=0;t<n.remoteCopies.length;t++)if(n.remoteCopies[t].ConditionId!=1){i=!1;break}r&&n.remoteCopies.length>0&&!i&&(n.siteCopies=n.remoteCopies.slice(),n.remoteCopies=[])},scrubCopies:function(n){var t=$.grep(n,function(n){return n.ConditionId>1}),u=$.grep(n,function(n){return n.ConditionId==1}),i=_.minBy(t,"UnitPrice"),r=_.minBy(u,"UnitPrice");return r&&i&&r.UnitPrice<i.UnitPrice?t:n},populatePricing:function(n,t,i,r,u){var h=[],c,f,y,v;for(t=this.scrubCopies(t),c=t.length,f=0;f<c;f++){var e=t[f].ConditionId,p=t[f].ConditionSort,o=t[f].UnitPrice,s=t[f].MarketPlaceId,w=t[f].ProductId,b=n.EAN,l=t[f].WebsiteId,a="en-US";t[f].LocationId===20&&l===2&&(a="en-UK2");t[f].LocationId===20&&l===1&&(a="en-UK1");y=n.ListPrice;(o>0&&e>(u?0:1)&&s===1||t.length===1&&o>0&&e===1&&s===1&&bwb.helpers.showNewItems()||i>1&&r===0&&o>0&&e===1&&s===1&&bwb.helpers.showNewItems())&&(v={ProductId:w,EAN:b,Condition:e,ConditionSort:p,MarketPlaceId:s,UnitPrice:o,WebSiteId:l,SourceLocale:a,ListPrice:y},c===1&&e===1?u===!0&&h.push(v):h.push(v))}return _.sortBy(h,function(n){return u===!0?n.Condition:n.ConditionSort})},getPriceObject:function(n,t,i){var v=this,h=0,r=[],c=n.AvailableCopies,s,f,e,y,o,u,l,g,a,w,nt,b;if(v.inStock(n,i.siteId)){for(s=[],f=[],e=0;e<c.length;e++)c[e].WebsiteId==i.siteId?s.push(c[e]):f.push(c[e]);if(y=i.searchStore.queryParameters.disjunctiveFacetsRefinements["AvailableCopies.IsNew"],o=!1,y!==undefined&&(o=y[0]=="true"),bwb.helpers.showNewItems()||(o=!1,t=!1),i.combineInventory&&(s.length==0||!o&&!t&&f.length>0&&this.preferUK(i.zoneId))&&(s=f.slice(),f=[]),u={siteCopies:s,remoteCopies:f},o||t||!i.combineInventory||v.inventoryPreference(u),u.siteCopies.length>0){var tt=u.siteCopies.filter(function(n){return n.MarketPlaceId===1&&n.ConditionId===1}).length,k=u.siteCopies.filter(function(n){return n.MarketPlaceId===1&&n.ConditionId>=2}).length,p=o||t||!k,d=u.siteCopies;p===!0&&u.remoteCopies.length>0&&(d=u.siteCopies.concat(u.remoteCopies.filter(function(n){return n.ConditionId===1})));r=v.populatePricing(n,d,tt,k,p);r.length>1?(l={"en-US":1,"en-UK1":2,"en-UK2":3},this.preferUK(i.zoneId)&&(l={"en-US":3,"en-UK1":1,"en-UK2":2}),r=r.sort(function(n,t){return l[n.SourceLocale]-l[t.SourceLocale]}),g=r[0].SourceLocale,a=0,p===!0?a=_.minBy(r,"Condition").Condition:(r=r.filter(function(n){return n.SourceLocale===g}),a=_.minBy(r,"ConditionSort").ConditionSort),w=r.filter(function(n){return n.Condition===a}),w.length>0?(nt=_.minBy(w,"UnitPrice"),h=nt):h=null):r.length===1&&(b=r[0],h=b.MarketPlaceId===1?b:null)}}return h},applyZoneAddIns:function(n,t,i,r,u){var f,e,o,b,c,s;if(isNaN(t)||t==undefined)return 0;if(u||(u="en-US"),i=parseInt(i),(isNaN(r)||r===undefined)&&(r=0),t>0){switch(u){case"en-US":f=bwb.store.state.usShippingRates;e=1;break;case"en-UK1":f=bwb.store.state.ukWebsite1ShippingRates;e=1;break;case"en-UK2":f=bwb.store.state.ukWebsite2ShippingRates;e=2;break;default:f=bwb.store.state.usShippingRates;e=1}var l=_.findIndex(f,function(n){return n.zone===i}),a=0,v=0,y=r===0?1:r,p=0,w=0,k=this.getSiteExchangeRate(e),h=t;return l!==-1&&(o=f[l],a=o.AddIn,v=o.WeightAddIn,p=o.NewAddIn,w=o.NewWeightAddIn),n==1?(b=t+p+y*w,h=Math.round(b*100)/100):(c=1,e=="2"&&bwb.store.state.siteId=="1"&&(c=k),s=t+a+y*v,s=Math.round(s*100)/100,h=(s*c).toFixed(2)),bwb.serverShare.pricing.getForeignPrice(h,bwb.store.state.cartCurrency)}return t},getSiteExchangeRate:function(n){var r=1,i=bwb.store.state.siteExchangeRates,t;if(i)for(t=0;t<i.length;t++)if(i[t].SellingSiteId==bwb.store.state.siteId&&i[t].InventorySiteId==n){r=i[t].Rate;break}return r},percentageSaved:function(n,t){return n&&t&&n>t?Math.floor(((1-t/n)*100).toFixed(2)):0}}}(),function(){bwb.localize={siteSettings:{SiteId:1,CountryCode:"US",CurrencySymbol:"$",CurrencyAbbrev:"USD",CartName:"Cart",BargainName:"Bin",GiftCertName:"Certificate",Shipping:"FREE",CurrencyRate:1},allSiteSettings:{1:{SiteId:1,CountryCode:"US",CurrencySymbol:"$",CurrencyAbbrev:"USD",CartName:"Cart",BargainName:"Bin",GiftCertName:"Certificate",Shipping:"FREE"},2:{SiteId:2,CountryCode:"UK",CurrencySymbol:"£",CurrencyAbbrev:"GBP",CartName:"Basket",BargainName:"Bookshelf",GiftCertName:"Voucher",Shipping:"Included"}},setSite:function(n){n==1||n==2?this.siteSettings=this.allSiteSettings[n]:console.log("Localize.SetSite called with invalid site",n)},forSite:function(n){return n==1||n==2?this.allSiteSettings[n]:this.allSiteSettings[0]},relocalize:function(n){this.siteSettings.CurrencySymbol=n.CurrencySymbol;this.siteSettings.CurrencyAbbrev=n.Currency;this.siteSettings.CurrencyRate=n.Rate}}}(),function(){bwb.search={productGTMPushTimer:0,primaryIndex:"",previousUrl:"",baseSearchUrl:function(){return window.location.origin+"/search/results"},setUrlQueryParameters:function(n){var f,i,e,o,u;if(bwb.ignoreparams)return!1;var r=window.location.href,s=r.indexOf("/search/results")!=-1,t=encodeURIComponent(n.query);for(f in n.disjunctiveFacets)if(i=n.disjunctiveFacets[f],n.disjunctiveFacetsRefinements[i])for(e in n.disjunctiveFacetsRefinements[i])o=n.disjunctiveFacetsRefinements[i][e],t+="&"+encodeURIComponent(i)+"="+encodeURIComponent(o);n.hierarchicalFacetsRefinements.Categories&&(u=encodeURIComponent(n.hierarchicalFacetsRefinements.Categories.join(",")),u.length&&(t+="&"+encodeURIComponent("Categories")+"="+u));(n.page>1||n.hitsPerPage>12)&&(t+="&p="+n.page,t+="&hpp="+n.hitsPerPage);n.index!=this.primaryIndex&&(t+="&idx="+n.index);t=t.length>0?this.baseSearchUrl()+"?q="+t:window.location.href.split("?")[0];t!=window.location.href&&(s?history.replaceState({url:this.previousUrl},n.query+" | Better World Books",t):(this.previousUrl=r,history.pushState({url:r},n.query+" | Better World Books",t)))},setRefinementsFromUrl:function(n){var i,r,f,e,t,u;if(bwb.ignoreparams)return!1;if((n||(n=bwb.store.state.searchStore),i=this.parseQueryString(),r=$.grep(i,function(n){return n.key.indexOf("utm_")!=-1}),!(r.length>0)||i.length!=r.length)&&(f=$.grep(i,function(n){return bwb.store.state.ignoreParams.indexOf(n.key.toLowerCase())!=-1}),!(f.length>0))){for(e in i)t=i[e],t.key!="q"&&t.key!="p"&&t.key.toLowerCase()!="hpp"&&t.key.indexOf("utm_")==-1&&t.key!="idx"&&t.key!="is_v"&&t.key!="Websites"&&t.key!="dsNav"&&(t.key.indexOf("[")!=-1&&(t.key=t.key.split("[")[1].split("]")[0]),t.key!="Categories"?(n.addFacet(t.key,VueInstantSearch.FACET_OR),n.addFacetRefinement(t.key,t.value)):(u=t,setTimeout(function(){n.addFacetRefinement(u.key,u.value)},0)));var o=this.getPage(),s=this.getHitsPerPage(),h=this.getIndex();setTimeout(function(){n.algoliaHelper.setIndex(h);n.resultsPerPage=s;n.page=o},0);window.location.href.indexOf("/search/results")==-1&&bwb.store.setSearchVisible(i.length>0)}},getQuery:function(){var t=this.parseQueryString(),i="",r,n;for(r in t)if(n=t[r],n.key=="q"){i=n.value;break}return i},getPage:function(){var t=this.parseQueryString(),i=1,r,n;for(r in t)if(n=t[r],n.key=="p"){i=n.value;break}return i},getIndex:function(){var t=this.parseQueryString(),i=this.primaryIndex,r,n;for(r in t)if(n=t[r],n.key=="idx"){i=n.value;break}return i},getHitsPerPage:function(){var t=this.parseQueryString(),i=12,r,n;for(r in t)if(n=t[r],n.key.toLowerCase()=="hpp"){n.value%12==0&&(i=n.value);break}return i},parseQueryString:function(){for(var i=window.location.search.substring(1).split("&"),r=[],t,n=0;n<i.length;n++)t=i[n].split("="),t.length==2&&r.push({key:decodeURIComponent(t[0]),value:decodeURIComponent(t[1])});return r},pushToGoogleTagManager:function(n){bwb.search.productGTMPushTimer>0&&clearTimeout(bwb.search.productGTMPushTimer);bwb.search.productGTMPushTimer=setTimeout(function(){$(n).each(function(n,t){switch(n){case 0:dataLayer.push({prodID:t.EAN})}if(n>0)return!1})},3e3)}};$(window).bind("popstate",function(n){try{window.location.href!=n.target.location.href&&(window.location.href=n.target.location.href)}catch(t){console.error(t)}})}(),function(){bwb.account={ordersUrl:"/services/orders.aspx",accountUrl:"/services/account.aspx",GetOrders:function(n,t){var i=this;$.ajax({url:this.ordersUrl,data:{op:"History",Page:n},dataType:"json",cache:!1}).done(function(n){t&&t(n)})},GetOrderDetails:function(n,t){$.ajax({url:this.ordersUrl,data:{op:"Details",OrderID:n},dataType:"json",cache:!1}).done(function(n){t&&t(n)})},GetOrderStatus:function(n,t,i){$.ajax({url:"/order/check",data:{orderNumber:n,postalCode:t},type:"GET",dataType:"json",contentType:"application/json; charset=utf-8",cache:!1}).done(function(n){i&&i(n)})},GetAccountPageInfo:function(n){$.ajax({url:this.accountUrl,data:{op:"GetAccountPageInfo"},dataType:"json",cache:!1}).done(function(t){n&&n(t)})},GetStoredCards:function(n){$.ajax({url:"/my/cards",type:"POST"}).done(function(t){n&&n(t)})},RemoveStoredCard:function(n,t){$.ajax({url:"/my/removecard",type:"POST",data:{cardId:n}}).done(function(n){t&&t(n)})},UpdateAccountInfo:function(n,t){$.ajax({type:"POST",url:this.accountUrl+"?op=UpdateAccountInfo",data:{name:n.name,email:n.email},dataType:"json"}).done(function(n){t&&t(n)})},GetAddresses:function(n,t){$.ajax({url:this.accountUrl,data:{op:"GetAddresses",loadAll:n},dataType:"json",cache:!1}).done(function(n){t&&t(n)})},GetCountries:function(n){$.ajax({url:this.accountUrl,data:{op:"GetCountries"},dataType:"json",cache:!1}).done(function(t){n&&n(t)})},UpdateAddress:function(n,t){$.ajax({type:"POST",url:this.accountUrl+"?op=UpdateAddress",data:n,dataType:"json"}).done(function(n){t&&t(n)})},CreateAddress:function(n,t,i){n.makeDefaultShippingAddress=!!t;$.ajax({type:"POST",url:this.accountUrl+"?op=CreateAddress",data:n,dataType:"json"}).done(function(n){i&&i(n)})},DeleteAddress:function(n,t){$.ajax({type:"POST",url:this.accountUrl,data:{op:"DeleteAddress",addressId:n},dataType:"json"}).done(function(n){t&&t(n)})},SetDefaultShippingAddress:function(n,t){$.ajax({type:"POST",url:this.accountUrl,data:{op:"SetDefaultShippingAddress",addressId:n},dataType:"json"}).done(function(n){t&&t(n)})},UpdatePassword:function(n,t){$.ajax({type:"POST",url:this.accountUrl+"?op=UpdatePassword",data:{oldpassword:n.currentPassword,newpassword:n.newPassword,confirmpassword:n.confirmPassword},dataType:"json"}).done(function(n){t&&t(n)})},GetEmailPreferences:function(n){$.ajax({url:this.accountUrl,data:{op:"GetEmailPreferences"},dataType:"json",cache:!1}).done(function(t){n&&n(t)})},UpdateSubscriptions:function(n,t){for(var r=[],i=0;i<n.length;i++)n[i].Subscribed==!0&&r.push(n[i].ListId);$.ajax({type:"POST",url:this.accountUrl+"?op=UpdateEmailPreferences",data:{emailSubs:r},dataType:"json"}).done(function(n){t&&t(n)})},GetWishlistItems:function(n,t){$.ajax({type:"POST",url:"/My/GetWishlistItems",dataType:"json",data:{wishlistUserId:n}}).done(function(n){t&&t(n)})},GetWishlistSettings:function(n,t){$.ajax({type:"POST",url:"/My/GetWishlistSettings",data:{wishlistUserId:n},dataType:"json"}).done(function(n){t&&t(n)})},SaveWishlistSettings:function(n,t){$.ajax({type:"POST",data:{settings:n},url:"/My/SaveWishlistSettings",dataType:"json"}).done(function(n){t&&t(n)})}}}(),function(){bwb.serverShare.pricing={priceAdjustByCents:function(n,t){t>1&&(t=t/100);return Math.ceil(n*2)/2-t},getCurrentCurrencyExchangeRateByCurrencyCode:function(n,t){return exchangeRates=t==="USD"?bwb.store.state.usdExchangeRates:t==="GBP"?bwb.store.state.gbpExchangeRates:bwb.store.state.usdExchangeRates,_.find(exchangeRates,function(t){return t.Currency===n})||_.find(exchangeRates,function(n){return n.CountryCode==="us"})||{CountryCode:"us",Currency:"USD",CurrencySymbol:"$",Rate:1,SourceCurrency:"USD"}},getCurrentCurrencyExchangeRate:function(n,t){exchangeRates=t==="USD"?bwb.store.state.usdExchangeRates:t==="GBP"?bwb.store.state.gbpExchangeRates:bwb.store.state.usdExchangeRates;var i=bwb.store.state.useLocalCurrency?n:"us";return _.find(exchangeRates,function(n){return n.CountryCode===i})||_.find(exchangeRates,function(n){return n.CountryCode==="us"})||{CountryCode:"us",Currency:"USD",CurrencySymbol:"$",Rate:1,SourceCurrency:"USD"}},getSourceCurrencyFromWebsiteId:function(n){switch(n){case 1:return"USD";case 2:return"GBP";default:return"USD"}},getForeignPrice:function(n,t){var i=this.getCurrentCurrencyExchangeRateByCurrencyCode(t,"USD").Rate,r=n*i;return r.toFixed(2)}}}()