if(typeof fitbit=="undefined")var fitbit={};fitbit.namespace=function(){var a=arguments;var o=null;var i;var j;var d;for(i=0;i<a.length;i=i+1){d=a[i].split(".");o=fitbit;for(j=d[0]=="fitbit"?1:0;j<d.length;j=j+1){o[d[j]]=o[d[j]]||{};o=o[d[j]]}}return o};
(function(){if(typeof fitbit.i18n!="undefined")return;fitbit.namespace("fitbit.i18n");window["EN"]=function(englishValue){var tmpl=fitbit.i18n.byEnglish[englishValue]||"";for(var ii=1;ii<arguments.length;ii++)tmpl=tmpl.replace("{"+(ii-1)+"}",""+arguments[ii]);return tmpl};fitbit.i18n={resources:{},byEnglish:{},getResource:function(resourceKey,tplSubst){if(fitbit.i18n.resources[resourceKey]==undefined)return"";if(arguments.length>1){var resultResource=fitbit.i18n.resources[resourceKey];var i=0;for(var l=
arguments.length;i<l;i++)resultResource=resultResource.replace(new RegExp("\\{"+i+"\\}","g"),arguments[i+1]+"")}else resultResource=fitbit.i18n.resources[resourceKey];return resultResource},getPluralResource:function(resourceKey,n){var resourceArgs=[resourceKey];if(arguments.length>2)for(var i=2;i<arguments.length;++i)resourceArgs.push(arguments[i]);var msg=fitbit.i18n.getResource.apply(this,resourceArgs).replace(/\{\d+\}/g,"");if(msg.indexOf("{")==-1)return n==undefined?function(){return msg}:msg;
var mf=new MessageFormat(fitbit.i18n.locale);var message=mf.compile("{NUM_RESULTS, plural, "+msg+"}");if(n==undefined)return function(n){return message({NUM_RESULTS:n})};else return message({NUM_RESULTS:n})},setResource:function(resourceKey,resourceValue,englishValue){fitbit.i18n.resources[resourceKey.replace(/^\.+/,"")]=resourceValue;fitbit.i18n.byEnglish[englishValue]=resourceValue},switchLocale:function(lcl){$.post("/i18n/switch?locale\x3d"+lcl,function(){var arr=window.location.pathname.match("^/[a-z][a-z]($|/[^?]*$)");
if(arr==null)window.location.reload();else window.location.pathname=arr[2]})},locale:"en",decimalParams:{decimalSeparator:function(){switch(fitbit.i18n.locale){case "de_AT":case "de_CH":case "de_DE":case "es_ES":case "fr_FR":return",";default:return"\\."}},groupSeparator:function(){switch(fitbit.i18n.locale){case "de_AT":case "de_CH":case "de_DE":case "es_ES":return"\\.";case "fr_FR":return"\\s";default:return","}}},DecimalNumber:{decimalSeparator:".",groupSeparator:",",negativeSign:"-",parse:function(value){var valueStr=
String(value).trim();var numberPattern=new RegExp("^["+fitbit.i18n.DecimalNumber.negativeSign+"]?[\\d"+fitbit.i18n.DecimalNumber.groupSeparator+"]+["+fitbit.i18n.DecimalNumber.decimalSeparator+"]?[\\d]*$","");if(numberPattern.test(valueStr)){valueStr=valueStr.replace(fitbit.i18n.DecimalNumber.groupSeparator,"").replace(fitbit.i18n.DecimalNumber.decimalSeparator,".").replace(fitbit.i18n.DecimalNumber.negativeSign,"-");return parseFloat(valueStr)}return NaN},format:function(value){return YAHOO.util.Number.format(value,
{decimalSeparator:fitbit.i18n.DecimalNumber.decimalSeparator,thousandsSeparator:fitbit.i18n.DecimalNumber.groupSeparator,negativeFormat:fitbit.i18n.DecimalNumber.negativeSign+"#"})}},WEEKDAYS:null,MONTHS:null}})();
var CommerceAdminToolApi=function(){if(CommerceAdminToolApi.prototype._singletonInstance)return CommerceAdminToolApi.prototype._singletonInstance;CommerceAdminToolApi.prototype._singletonInstance=this;this.getStock=function(sku,currencyWrapper){var _this=this;var price="";var countryCode=this.getCommonEuLocale(this.getCountryCode());var locale=this.getLocale();var $defer=new $.Deferred;var response={};if(countryCode&&sku)this.requestToAPI(countryCode,locale).done(function(data){var product=_this.findProductBySKU(data,
sku);$.extend(response,product);if(product&&product.hasOwnProperty("priceWithSymbol")){response.price=_this.wrapCurrency(product.priceWithSymbol,currencyWrapper);$defer.resolve(response)}else $defer.reject()});return $defer};this.wrapCurrency=function(priceWithSymbol,currencyWrapper){if(!currencyWrapper)return priceWithSymbol;var currencySymbol=priceWithSymbol.replace(/[0-9., ]/g,"");return priceWithSymbol.replace(currencySymbol,$(currencyWrapper).text(currencySymbol).prop("outerHTML"))};this.getCountryCode=
function(fullLocale){var locale;var bodyClass=$("body").attr("class").match(/locale-\S+/);if(bodyClass)locale=bodyClass[0].replace("locale-","");else if(typeof fitbit!=="undefined")locale=fitbit.i18n.locale;if(typeof fullLocale==="undefined"||!fullLocale)locale=locale.split("_")[1].toLowerCase();return locale};this.getCommonEuLocale=function(locale){var locales=["eu"];return locales.indexOf(locale)===-1?locale:"pt"};this.getLocale=function(){var lclCookie=this.getCookie("lcl");return lclCookie&&lclCookie.length>=
5?lclCookie:this.getCountryCode(true)};this.getCookie=function(name){var value="; "+document.cookie;var parts=value.split("; "+name+"\x3d");if(parts.length==2)return parts.pop().split(";").shift()};this.formatCurrency=function(price,currencyWrapper){var countryCode=this.getCommonEuLocale(this.getCountryCode());var locale=this.getLocale();var currencyPosition="BEFORE_PRICE";var currencySeparator="";var decimalSeparator=".";var currencySymbol;switch(locale){case "en_DK":case "en_SE":case "sv_SE":case "en_NO":case "no_NO":currencyPosition=
"AFTER_PRICE";currencySeparator=" ";decimalSeparator="$1";break;case "fr_FR":case "de_DE":case "it_IT":case "es_ES":case "en_FI":case "en_BE":case "fr_BE":case "de_AT":case "de_CH":case "fr_CH":case "it_CH":case "en_NL":case "nl_NL":case "en_EU":case "fr_CA":case "en_IE":currencyPosition="AFTER_PRICE";currencySeparator=" ";decimalSeparator=",";break}switch(countryCode){case "us":case "ca":currencySymbol="$";break;case "nz":currencySymbol="NZ$";break;case "au":currencySymbol="A$";break;case "gb":currencySymbol=
"\u00a3";break;case "dk":currencySymbol="DKK";break;case "se":currencySymbol="SEK";break;case "no":currencySymbol="NOK";break;case "fr":case "de":case "it":case "es":case "fi":case "be":case "at":case "ch":case "nl":case "eu":case "pt":case "ie":currencySymbol="\u20ac";break}if(currencySymbol&&currencyWrapper)currencySymbol=$(currencyWrapper).text(currencySymbol).prop("outerHTML");var formattedPrice=price.toString().replace(/(\.|\,)/,decimalSeparator);if(currencyPosition==="BEFORE_PRICE")formattedPrice=
currencySymbol+currencySeparator+formattedPrice;else formattedPrice+=currencySeparator+currencySymbol;return formattedPrice};this.requestToAPI=function(countryCode,locale){if(typeof this._apiRequestCache==="undefined"){countryCode=countryCode?countryCode:this.getCommonEuLocale(this.getCountryCode());locale=locale?locale:this.getLocale();this._apiRequestCache=$.get("/cart/api/store",{id:countryCode,locale:locale})}return this._apiRequestCache};this.findProductBySKU=function(data,sku){if(data.hasOwnProperty("products"))if(data.products.hasOwnProperty(sku))return data.products[sku];
return false}};
