var VM=VM||{};VM.Widgets={wordCount:0,noinject:!1,injects:[],container:null,init:function(){this.initProperties();this.detailsInjects();this.categoryInjects()},initProperties:function(){this.container===null&&(this.container=document.getElementById("details-body"),this.container&&(this.noinject=this.container.classList.contains("noinject"),this.wordCount=parseInt(this.container.getAttribute("data-words"),10)))},detailsInjects:function(){if(this.container){var n=document.querySelectorAll("#details-body > p");document.querySelectorAll("aside .widget-inject").forEach(function(t){VM.Widgets.inject(t,n)})}},categoryInjects:function(){if(!this.container&&(this.container=document.getElementById("category-items"),this.container)){var n=this.container.children;document.querySelectorAll("section .widget-inject").forEach(function(t){VM.Widgets.inject(t,n)})}},inject:function(n,t,i){var u,e,o,h;if(!t||t.length===0||n.classList.contains("widget-injected")||(u=VM.Widgets,e=parseInt(n.getAttribute("data-min")||0,10),e>0&&u.wordCount>0&&e>u.wordCount)||u.noinject&&!n.classList.contains("widget-inject-override"))return!0;var s=parseInt(n.getAttribute("data-per"),10)/100,c=Math.max(Math.round(s*t.length)-1,0),r=n.cloneNode(!0),f=document.createElement("div");return f.classList.add("widget","injected"),f.setAttribute("data-id",n.getAttribute("data-id")),r.classList.add("widget-injected"),n.replaceWith(f),r.data_placeholder=f,s===1?(o=document.getElementById("widget-inject-100"),o?o.appendChild(r):u.container.appendChild(r)):(h=t[c],h.insertAdjacentElement("afterend",r)),u.injects.push(r),f.data_injected=r,typeof i=="function"?i(r):void 0}};VM.Slots={init:function(){googletag&&(this.loadSlots(),googletag.cmd.push(function(){googletag.pubads().addEventListener("slotRenderEnded",function(n){var i=document.getElementById(n.slot.getSlotElementId()),t;i&&(t=i.parentNode,n.isEmpty||(t.classList.contains("slot-alert")?document.body.classList.add("has-slot-alert"):t.classList.contains("slot-alert-inline")?t.classList.add("slot-alert-show"):t.classList.contains("slot-footer")?VM.Slots.processFooter(t):t.classList.contains("slot-pixel")&&t.classList.add("slot-pixel-show")),t.classList.contains("slot-widget")&&VM.Slots.processWidget(t,n.isEmpty,n.size))})}))},processWidget:function(n,t,i){var r=n.parentNode;t?r.classList.contains("widget-inject")&&r.classList.remove("widget-injected"):i[0]===0&&r.classList.contains("widget-inject")&&r.classList.add("widget-dfp-fluid")},processFooter:function(n){n.classList.add("slot-footer-show");var t=document.createElement("div");t.classList.add("slot-close");t.setAttribute("aria-label","close");t.innerHTML="&times;";n.appendChild(t);t.addEventListener("click",function(){n.parentNode.removeChild(n)})},loadSlots:function(){if(!document.body.classList.contains("noads")&&googletag&&typeof adUtility=="undefined"){var n=this,t=document.body.classList.contains("has-hb");document.querySelectorAll(".gam").forEach(function(i){if(!i.classList.contains("widget-inject")||i.classList.contains("widget-injected")){var r=null;r=i.hasAttribute("data-dim")?i.getAttribute("data-dim"):window.innerWidth>767?window.innerWidth>991?i.getAttribute("data-dim-d"):i.getAttribute("data-dim-t"):i.getAttribute("data-dim-m");r?(i.setAttribute("data-size",r),i.innerHTML=i.classList.contains("widget")?'<div class="slot slot-widget"><span id="'+n.getSlotId(i)+'"><\/span><\/div>':'<span id="'+n.getSlotId(i)+'"><\/span>',t&&i.getAttribute("data-lazy")==="true"?i.classList.add("lazyad"):n.buildSlotFromElement(i,function(n){VM.slots.push(n)})):i.removeAttribute("style")}});t?googletag.cmd.push(function(){googletag.enableServices();n.requestBids(VM.slots)}):googletag.cmd.push(function(){googletag.enableServices();googletag.pubads().refresh(VM.slots,{changeCorrelator:!1})})}},buildSlotFromElement:function(n,t){var i={path:n.getAttribute("data-path"),slotid:this.getSlotId(n),mapping:n.getAttribute("data-mapping"),size:n.getAttribute("data-size").replace(/'/g,'"'),targeting:n.getAttribute("data-targeting")||"[]"};try{i.size=JSON.parse(i.size)}catch(r){console.error("Error parsing props.size",i.size,r);return}try{i.targeting=JSON.parse(i.targeting)}catch(r){console.error("Error parsing props.targeting",i.targeting,r);return}googletag.cmd.push(function(){var r,u;if(n.hasAttribute("data-oop"))if(r=googletag.defineOutOfPageSlot(i.path,googletag.enums.OutOfPageFormat[n.getAttribute("data-oop")]),r)r.addService(googletag.pubads());else return;else r=googletag.defineSlot(i.path,i.size,i.slotid).addService(googletag.pubads()),i.mapping&&i.mapping!=="null"&&r.defineSizeMapping(window[i.mapping]);if(i.targeting&&i.targeting.length>0)for(u=0;u<i.targeting.length;u++)r.setTargeting(i.targeting[u].Key,i.targeting[u].Values);t(r)})},getSlotId:function(n){return(n.classList.contains("widget")?"slot_w_":"slot_")+n.getAttribute("data-id")},requestedSlotKeys:[],requestBids:function(n){pbjs.que.push(function(){pbjs.rp.requestBids({callback:VM.Slots.callAdserver,gptSlotObjects:n})});setTimeout(function(){VM.Slots.callAdserver(n)},3500)},callAdserver:function(n){for(var i=n.map(function(n){return n.getSlotElementId()}).join("_"),t=0;t<VM.Slots.requestedSlotKeys.length;t++)if(VM.Slots.requestedSlotKeys[t]===i)return;VM.Slots.requestedSlotKeys.push(i);googletag.pubads().refresh(n)}};VM.Me={init:function(){var n=new XMLHttpRequest;n.addEventListener("load",function(){this.status===200?VM.Me.load(JSON.parse(this.responseText)):VM.Me.load({id:0})});n.open("POST","/account/me");n.send()},load:function(n){this.user=n;this.setTargeting();this.setAnalytics();this.setLoggedIn();this.updateAntiforgery();this.removeBodyClasses()},user:null,getUser:function(n){var t=0,i=window.setInterval(function(){return VM.Me.user?(window.clearInterval(i),n(VM.Me.user)):(t++,t===20?(window.clearInterval(i),n({id:0})):void 0)},150)},setTargeting:function(){var n=this;typeof adUtility=="undefined"&&googletag.cmd.push(function(){if(window.URLSearchParams!==undefined){var t=new URLSearchParams(window.location.search);t.forEach(function(n,t){var i=t.split("_");i.length===2&&i[0]==="utm"&&googletag.pubads().setTargeting(i[1],n)})}googletag.pubads().setTargeting("LoggedIn",n.toBoolString(n.user.id!==0)).setTargeting("User",n.user.id.toString()).setTargeting("Member",n.toBoolString(n.user.member)).setTargeting("Subscriber",n.toBoolString(n.user.subscriber))})},setAnalytics:function(){window.ga&&(this.user.id!==0&&(ga("base.set","userId",this.user.id.toString()),ga("site.set","userId",this.user.id.toString()),this.user.ev_login&&(ga("base.send","event",{eventCategory:"NTG account",eventAction:"login",eventLabel:"success",nonInteraction:!1}),ga("site.send","event",{eventCategory:"NTG account",eventAction:"login",eventLabel:"success",nonInteraction:!1})),this.user.ev_verified&&(ga("base.send","event",{eventCategory:"NTG account",eventAction:"registration",eventLabel:"success",nonInteraction:!1}),ga("site.send","event",{eventCategory:"NTG account",eventAction:"registration",eventLabel:"success",nonInteraction:!1}))),ga("base.set","dimension20",this.toBoolString(this.user.member)),ga("site.set","dimension20",this.toBoolString(this.user.member)),ga("base.set","dimension21",this.toBoolString(this.user.subscriber)),ga("site.set","dimension21",this.toBoolString(this.user.subscriber)))},setLoggedIn:function(){if(this.user.id!==0){var t=document.getElementById("welcome"),n=document.querySelector("header .avatar");t&&(t.parentNode.setAttribute("aria-controls","hd-account"),t.setAttribute("data-user",this.user.id),t.innerHTML=(t.getAttribute("data-default")||"").replace("{0}",this.user.username)+' <span class="caret" aria-hidden="true"><\/span>');n&&(n.setAttribute("data-initials",this.user.initials),this.user.photo&&this.user.photo.length>0?(n.innerHTML='<img alt="" class="avatar-img" src="'+this.user.photo+'">',n.className="avatar-sm avatar"):(n.innerHTML=this.user.initials,n.className="theme-bg avatar-sm avatar"))}},removeBodyClasses:function(){this.user.cms&&(document.body.classList.remove("staged"),document.body.classList.remove("noads"))},updateAntiforgery:function(n){var f=document.createElement("div"),t,e,r,u;if(f.innerHTML=n||this.user.af,t=f.firstChild,t)for(e=t.getAttribute("name"),r=document.querySelectorAll('form[method="post"]'),i=0;i<r.length;++i)u=r[i].querySelector('input[name="'+e+'"]'),u?u.value=t.value:r[i].appendChild(t.cloneNode())},toBoolString:function(n){return n?"True":"False"}};VM.Widgets.init();VM.Slots.init();VM.Me.init()