(function(n,t){if(typeof exports=="object"&&exports)t(exports);else{var i={};t(i);typeof define=="function"&&define.amd?define(i):n.Mustache=i}})(this,function(n){function a(n,t){return l.call(n,t)}function y(n){return!a(v,n)}function u(n){return typeof n=="function"}function o(n){return n.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function b(n){return String(n).replace(/[&<>"'\/]/g,function(n){return w[n]})}function s(n){if(!e(n)||n.length!==2)throw new Error("Invalid tags: "+n);return[new RegExp(o(n[0])+"\\s*"),new RegExp("\\s*"+o(n[1]))]}function nt(t,i){function st(){if(ft&&!b)while(w.length)delete p[w.pop()];else w=[];ft=!1;b=!1}var a,f,e,nt,et,v,rt,ot;i=i||n.tags;t=t||"";typeof i=="string"&&(i=i.split(h));for(var l=s(i),u=new r(t),ut=[],p=[],w=[],ft=!1,b=!1;!u.eos();){if(a=u.pos,e=u.scanUntil(l[0]),e)for(rt=0,ot=e.length;rt<ot;++rt)nt=e.charAt(rt),y(nt)?w.push(p.length):b=!0,p.push(["text",nt,a,a+1]),a+=1,nt==="\n"&&st();if(!u.scan(l[0]))break;if(ft=!0,f=u.scan(g)||"name",u.scan(k),f==="="?(e=u.scanUntil(c),u.scan(c),u.scanUntil(l[1])):f==="{"?(e=u.scanUntil(new RegExp("\\s*"+o("}"+i[1]))),u.scan(d),u.scanUntil(l[1]),f="&"):e=u.scanUntil(l[1]),!u.scan(l[1]))throw new Error("Unclosed tag at "+u.pos);if(et=[f,e,a,u.pos],p.push(et),f==="#"||f==="^")ut.push(et);else if(f==="/"){if(v=ut.pop(),!v)throw new Error('Unopened section "'+e+'" at '+a);if(v[1]!==e)throw new Error('Unclosed section "'+v[1]+'" at '+a);}else f==="name"||f==="{"||f==="&"?b=!0:f==="="&&(l=s(i=e.split(h)))}if(v=ut.pop(),v)throw new Error('Unclosed section "'+v[1]+'" at '+u.pos);return it(tt(p))}function tt(n){for(var u=[],t,i,r=0,f=n.length;r<f;++r)t=n[r],t&&(t[0]==="text"&&i&&i[0]==="text"?(i[1]+=t[1],i[3]=t[3]):(u.push(t),i=t));return u}function it(n){for(var u=[],r=u,i=[],t,e,f=0,o=n.length;f<o;++f){t=n[f];switch(t[0]){case"#":case"^":r.push(t);i.push(t);r=t[4]=[];break;case"/":e=i.pop();e[5]=t[2];r=i.length>0?i[i.length-1][4]:u;break;default:r.push(t)}}return u}function r(n){this.string=n;this.tail=n;this.pos=0}function t(n,t){this.view=n==null?{}:n;this.cache={".":this.view};this.parent=t}function i(){this.cache={}}var l=RegExp.prototype.test,v=/\S/,p=Object.prototype.toString,e=Array.isArray||function(n){return p.call(n)==="[object Array]"},w={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"},k=/\s*/,h=/\s+/,c=/\s*=/,d=/\s*\}/,g=/#|\^|\/|>|\{|&|=|!/,f;r.prototype.eos=function(){return this.tail===""};r.prototype.scan=function(n){var i=this.tail.match(n),t;return i&&i.index===0?(t=i[0],this.tail=this.tail.substring(t.length),this.pos+=t.length,t):""};r.prototype.scanUntil=function(n){var i=this.tail.search(n),t;switch(i){case-1:t=this.tail;this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,i);this.tail=this.tail.substring(i)}return this.pos+=t.length,t};t.prototype.push=function(n){return new t(n,this)};t.prototype.lookup=function(n){var t,i,r,f;if(n in this.cache)t=this.cache[n];else{for(i=this;i;){if(n.indexOf(".")>0)for(t=i.view,r=n.split("."),f=0;t!=null&&f<r.length;)t=t[r[f++]];else t=i.view[n];if(t!=null)break;i=i.parent}this.cache[n]=t}return u(t)&&(t=t.call(this.view)),t};i.prototype.clearCache=function(){this.cache={}};i.prototype.parse=function(n,t){var r=this.cache,i=r[n];return i==null&&(i=r[n]=nt(n,t)),i};i.prototype.render=function(n,i,r){var u=this.parse(n),f=i instanceof t?i:new t(i);return this.renderTokens(u,f,r,n)};i.prototype.renderTokens=function(t,i,r,f){function y(n){return v.render(n,i,r)}for(var c,a,h="",v=this,s,o,l=0,p=t.length;l<p;++l){s=t[l];switch(s[0]){case"#":if(o=i.lookup(s[1]),!o)continue;if(e(o))for(c=0,a=o.length;c<a;++c)h+=this.renderTokens(s[4],i.push(o[c]),r,f);else if(typeof o=="object"||typeof o=="string")h+=this.renderTokens(s[4],i.push(o),r,f);else if(u(o)){if(typeof f!="string")throw new Error("Cannot use higher-order sections without the original template");o=o.call(i.view,f.slice(s[3],s[5]),y);o!=null&&(h+=o)}else h+=this.renderTokens(s[4],i,r,f);break;case"^":o=i.lookup(s[1]);(!o||e(o)&&o.length===0)&&(h+=this.renderTokens(s[4],i,r,f));break;case">":if(!r)continue;o=u(r)?r(s[1]):r[s[1]];o!=null&&(h+=this.renderTokens(this.parse(o),i,r,o));break;case"&":o=i.lookup(s[1]);o!=null&&(h+=o);break;case"name":o=i.lookup(s[1]);o!=null&&(h+=n.escape(o));break;case"text":h+=s[1]}}return h};n.name="mustache.js";n.version="0.8.1";n.tags=["{{","}}"];f=new i;n.clearCache=function(){return f.clearCache()};n.parse=function(n,t){return f.parse(n,t)};n.render=function(n,t,i){return f.render(n,t,i)};n.to_html=function(t,i,r,f){var e=n.render(t,i,r);if(u(f))f(e);else return e};n.escape=b;n.Scanner=r;n.Context=t;n.Writer=i});BRW.ViewModels.GiveAways=function(n){function i(n,t){$(n).next().is(".giveAwayRow")||$(n).after(t)}function r(n,i,r){var g="giveAwayRow "+t.options.style,s=0,p=2,w=3,b=!1,e,k,o,f,u,v,c,l,a;switch(t.options.style){case"articleList":s=$(t.options.selectors.articleListOffset.attributesContainer).data(t.options.selectors.articleListOffset.attributesDataAttribute);break;case"basket":s=2;break;case"shoppingList":s=2;w=2;break;case"orderConfirmation":b=!0;s=1;p=0}for(e={},e.giveAways=[],k=n.GiveAways.length,o=0;o<n.GiveAways.length;o++){if(f=n.GiveAways[o],u={},u.internalNumber=f.ArticleInternalNumber,u.toolshopNumber=f.ArticleToolshopNumber,u.name=f.Name,u.dimension=f.Dimension,u.link=f.ProductLink,u.freePriceText=t.options.translations.freePrice,u.unit=f.Unit,v=f.UseBasketItemQuantity?f.QuantityForBasketItem:f.Quantity,r){var nt=t.options.selectors.basketItemQuatitySelector,d=nt.replace("{0}",n.ArticleInternalNumber),y=$(d).val(),h=parseInt(y);isNaN(h)&&(y=$(d).text(),h=parseInt(y));h&&f.UseBasketItemQuantity&&(v=f.QuantityForBasketItem*h)}for(u.quantity=v,e.titleColspan=s,e.priceColspan=1,e.quantityColspan=1,e.stockColspan=w,e.unitColspan=p,e.extraTd=b,u.cssClass=g+" giveAwayContainer",o===0&&(u.cssClass+=" first",u.title=t.options.translations.title),o===k-1&&(u.cssClass+=" last"),u.stocks=[],c=0;c<f.Stocks.length;c++)l=f.Stocks[c],a={},a.image=l.StockIcon,a.text=r?l.BasketStockText:l.StockText,u.stocks.push(a);e.giveAways.push(u)}return Mustache.render(i,e)}var t=this;t.options=n;t.LoadGiveAways=function(){var n=$(t.options.selectors.articlesToSearch).map(function(){return $(this).data(t.options.selectors.articlesInternalNumberDataAttribute)}).get();$.ajax({url:t.options.urls.getGiveAwaysUrl,type:"POST",contentType:"application/json; charset=utf-8",data:JSON.stringify(n),success:function(n){var u,s,h,f;if(!!n&&n.length>0)for(u=!1,t.options.mode==="basket"&&(u=!0),s=document.getElementById(t.options.template).innerHTML,h=r,f=0;f<n.length;f++){var c=n[f],e=h(c,s,u),v=t.options.selectors.itemToReplaceFormat,o=v.replace("{0}",c.ArticleInternalNumber);if(u){var y=$(o).data("uid"),l="[child-dta-uid="+y+"]",a=$(l);a&&a.length>0?i(l,e):i(o,e)}else i(o,e)}}})}}