let lb_paginationbusy=!1;$.fn.setCursorPosition=function(pos){this.each((index,elem)=>{if(elem.setSelectionRange){elem.setSelectionRange(pos,pos)}else if(elem.createTextRange){const range=elem.createTextRange();range.collapse(!0);range.moveEnd('character',pos);range.moveStart('character',pos);range.select()}});return this};$.fn.replaceWithCallback=function(replace,callback){const ret=$.fn.replaceWith.call(this,replace);if(typeof callback==='function'){callback.call(ret)}
return ret};const customjs=(function($){let popupclosecallback;function liftcurtain(){$(document).off('keydown');$('#curtain, #popup').remove();popupclosecallback}
function dropcurtain(ps_id){liftcurtain();$(document).on('keydown',(event)=>{if(event.key==='Escape'){liftcurtain()}});$(document).on('click','.s-popupClose, .s-popupCloseBtn, .s-popupCurtain, .j-popupClose, .closeSlidein',()=>{liftcurtain();$('body').removeClass('noScroll')});$(document.body).prepend(`<div id="curtain" class="s-popupCurtain"></div><div id="popup" class="s-site-popup loading ${ps_id}"></div>`)}
function loadpopup(ps_id,ps_url,po_data,po_callback,po_closecallback){po_callback=typeof po_callback!=='undefined'?po_callback:null;po_closecallback=typeof po_closecallback!=='undefined'?po_closecallback:null;if(!po_closecallback===null){popupclosecallback=po_closecallback}
dropcurtain(ps_id);$.get(ps_url,po_data,(ps_response)=>{$('#popup').html(ps_response).removeClass('loading');po_callback;const li_scrolltop=$(document).scrollTop();$('.s-popup').css('top',`${li_scrolltop}px`);$('.j-typeaheadinput').trigger('focus')})}
function setcookie(ps_name,ps_value,pi_time){const d=new Date();d.setTime(d.getTime()+(pi_time));const expires=`expires=${d.toUTCString()}`;document.cookie=`${ps_name}=${ps_value}; ${expires}; path=/`}
function deletecookie(ps_name){document.cookie=`${ps_name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`}
function getcookie(ps_name){const name=`${ps_name}=`;const ca=document.cookie.split(';');for(let i=0;i<ca.length;i++){let c=ca[i];while(c.charAt(0)==' '){c=c.substring(1)}
if(c.indexOf(name)!=-1)return c.substring(name.length,c.length);}
return''}
function showcreditblockedpopup(ps_cookiename){const ls_cookie=getcookie(ps_cookiename);const lb_response=!0;if(ls_cookie===''){setcookie(ps_cookiename,1,60*60*24*30*1000);$.getJSON('/process-login',{a:'iscreditblocked'},(lo_data)=>{if(lo_data.blocked){loadpopup('genericpopup','/message-popup',{m:lo_data.message})}})}}
function processcart(po_request){$.getJSON('/process-cart',po_request,(lo_data)=>{if(typeof lo_data.datalayer!=='undefined'){dataLayer.push(lo_data.datalayer)}})}
function showformerror(ps_error,po_field){$(po_field).next('.s-inError').html(ps_error).show()}
function clearformerror(po_field){$(po_field).next('.s-inError').html('').hide()}
function updatepostcode(pi_postcode){const lo_request={};lo_request.a='updatepostcode';lo_request.p=pi_postcode;$.getJSON('/your-details',lo_request,(po_response)=>{if(!po_response.status){return!1}})}
return{redirectpage(e){e.preventDefault();const _self=this;setTimeout(()=>{if($(_self).hasClass('j-disabled')){return}
window.location.href=$(_self).attr('href')},1000)},showcharactersleft(e){const li_length=$(e.data.input).val().length;const li_left=e.data.limit-li_length;$(e.data.helptext).html(`${li_left} characters left`)},countcharactersleft(e){if(typeof e.data==='undefined'){e.data={};e.data.limit=$(this).data('limit');e.data.helptext=$(this).siblings('.j-helptext')}
const li_length=$(this).val().length;const li_left=e.data.limit-li_length;const ls_value=$(this).val();switch(e.key){case 'Backspace':case 'Delete':case 'Tab':case 'Enter':case 'LeftArrow':case 'UpArrow':case 'RightArrow':case 'DownArrow':break;default:if(li_left<0&&(e.key!=='Backpace'||e.key!=='Delete')){e.preventDefault();e.stopPropagation();$(this).val(ls_value.substring(0,e.data.limit));return!1}}
$(e.data.helptext).html(`${li_left} characters left`)},updateinterface(e){let ls_value=$(this).val();ls_value=ls_value||'[No Value]';$(e.data.dom).html(ls_value)},submitlogin(e){e.preventDefault();$('.j-loginformbtn').html('Signing In..');const lo_email=$(this).find('input[name=__email]');const lo_password=$(this).find('input[name=__password]');const lo_redirect=$(this).find('input[name=__redirect]');const lo_result=$(this).find('div.j-loginresponse');const lo_request={};lo_request.a='login';lo_request.e=$(lo_email).val();lo_request.p=$(lo_password).val();lo_request.r=$(lo_redirect).val();lo_request.t=$(this).data('type');$(lo_result).addClass('j-hidden');$.post('/process-login',lo_request,(lo_response)=>{$('.j-loginformbtn').html('Sign In');if(lo_response.success){$('.j-loginform .s-success').removeClass('j-hidden');if(lo_response.redirect){document.location.href=lo_response.redirect}else{document.location.href='/my-account/details'}}else{$(lo_result).removeClass('j-hidden');$(lo_result).html(lo_response.error)}})},login(e){e.preventDefault();const lo_email=$(this).find('input[name=email]');const lo_password=$(this).find('input[name=password]');const lo_request={};lo_request.email=$(lo_email).val();lo_request.password=$(lo_password).val();$.post('?a=login',lo_request,(lo_response)=>{if(lo_response.success){if(lo_response.redirect){document.location.href=lo_response.redirect}else{location.reload()}}else{if(lo_response.emailerror){$('.s-input-error').removeClass('is-hidden').html(lo_response.emailerror)}
if(lo_response.error){$('.s-error').removeClass('is-hidden').html(lo_response.emailerror)}}})},resetpasswordform(e){e.preventDefault();loadpopup('resetpasswordform','/reset-password-popup')},resetpassword(e){e.preventDefault();if($(this).hasClass('j-submitted')){return}
$(this).addClass('j-submitted');const _self=this;const lo_email=$(this).find('input[name=__email]');const lo_result=$(this).find('div.j-resetpasswordresponse');const lo_request={};lo_request.a='resetpassword';lo_request.e=$(lo_email).val();$.getJSON('/process-login',lo_request,(lo_response)=>{if(!lo_response.success){$(_self).removeClass('j-submitted')}
$(lo_result).html(lo_response.content);if(lo_response.success){$('.j-resetpasswordform').children().not('.j-resetpasswordresponse').remove()}})},shareproduct(e){e.preventDefault();const lo_sendername=$(this).find('input[name=__sendername]');const lo_senderemail=$(this).find('input[name=__senderemail]');const lo_contactname=$(this).find('input[name=__contactname]');const lo_contactemail=$(this).find('input[name=__contactemail]');const lo_message=$(this).find('textarea[name=__message]');const lo_article=$(this).find('input[name=__articleid]');const lo_request={};lo_request.a='send';lo_request.__sendername=$(lo_sendername).val();lo_request.__senderemail=$(lo_senderemail).val();lo_request.__contactname=$(lo_contactname).val();lo_request.__contactemail=$(lo_contactemail).val();lo_request.__message=$(lo_message).val();lo_request.__articleid=$(lo_article).val();const lo_result=$(this).find('div.j-sharebyemailresponse');const lo_inputs=$(this).find('.s-defInput');const lo_button=$(this).find('.s-redBtn');$.post('/share-with-friend-popup',lo_request,(lo_response)=>{$('.s-inError').removeClass('j-show');if(!lo_response.success){$.each(lo_response.errors,(ls_name,ls_error)=>{$(`[data-for="${ls_name}"]`).html(ls_error).addClass('j-show')})}else{lo_result.show();lo_inputs.hide();lo_button.hide()}})},initcategory(po_result){if(!po_result.hasfilters){$('.filterGroup').removeClass('j-active');$('.filterResetAll').addClass('disabled')}else{$('.filterResetAll').removeClass('disabled')}
$('.pcItems').replaceWithCallback(po_result.itemhtml,()=>{deviceimages()});if(lb_paginationbusy){lb_paginationbusy=!1}
customjs.addproductimpressions(po_result.impressions)},checkaddressoptions(e){ls_tagtype=this.nodeName.toLowerCase();if(ls_tagtype=='a'){e.preventDefault()}
if(ls_tagtype=='input'&&!$(this).is(':checked')){$('.addressoption').hide();return}
ls_addressoption=$(this).data('addressoption');la_addressoptions=ls_addressoption.split(' ');$.each(la_addressoptions,(i,ls_addressoption)=>{console.log(ls_addressoption)});if(ls_optionvalue=='j-addresssearch'){lo_option.find('input').trigger('focus')}},addaddress(e){e.preventDefault()},validateemail(e){const _self=this;const lo_request={};lo_request.a='validateemail';lo_request.e=$(this).val();$.getJSON('/egiftcards',lo_request,(po_response)=>{if(!po_response.success){showformerror(po_response.message,_self)}else{clearformerror(_self)}})},iscreditblocked(){showcreditblockedpopup('homecreditblocked')},updatepostcode(e){const li_postcode=$(this).val();if(li_postcode.length===0){return!1}
updatepostcode(li_postcode)},addproductimpressions(pa_impressions){la_impressions=pa_impressions.impressions;if(typeof psdatalayer.ecommerce.impressions==='undefined'){psdatalayer.ecommerce.impressions=[]}
psdatalayer.ecommerce.impressions=la_impressions;for(li_ind in la_impressions){lo_impression=la_impressions[li_ind];if(typeof psdatalayer.facebook!=='undefined'){psdatalayer.facebook.content_ids.push(lo_impression.id)}}
dataLayer.push(psdatalayer)},}}(jQuery));let lo_ajaxtimeout;let li_activeresult=0;const typeahead=function(po_config){const self=this;this.container=po_config.container;this.result=po_config.result;this.keycode=po_config.keycode;this.searchterm=po_config.searchterm;this.url=po_config.url;this.callback=po_config.callback;let li_totalitems=0;const lb_active=(li_activeresult>=0);this.hidetypeahead=function(){this.container.html('');this.container.hide()};this.search=function(){if(this.searchterm===''){this.hidetypeahead();return}
this.container.show();switch(this.keycode){case 'Enter':li_totalitems=this.container.find('ul > li').length;if(li_totalitems==1){$(this.result).eq(0).trigger('click')}
return!1;case 'Escape':this.hidetypeahead();$('.searchForm').find('input').val('');li_activeresult=-1;return!1;case 'DownArrow':li_totalitems=this.container.find('ul > li').length;++li_activeresult;if(li_activeresult<0){li_activeresult=0}else if(li_activeresult>li_totalitems){li_activeresult=li_totalitems}
$(this.result).removeClass('j-active');if($(this.result).eq(li_activeresult).length>0){$(this.result).eq(li_activeresult).addClass('j-active')}else{$(this.result).first().addClass('j-active');li_activeresult=0}
return!1;case 'UpArrow':li_totalitems=this.container.find('ul > li').length;--li_activeresult;if(li_activeresult<0){li_activeresult=0}else if(li_activeresult>li_totalitems){li_activeresult=li_totalitems}
$($(this.result)).removeClass('j-active');if(li_activeresult>=0){$(this.result).eq(li_activeresult).addClass('j-active')}
return!1;default:if(lo_ajaxtimeout){console.log(self.result);clearTimeout(lo_ajaxtimeout)}
lo_ajaxtimeout=setTimeout(()=>{self.container.load(`${self.url}?q=${encodeURIComponent(self.searchterm)}`,()=>{$(window).resize()});$(document).off('click',self.result);$(document).on('click',self.result,(e)=>{const fn=self.callback;if(typeof fn==='function'){fn(e)}
self.hidetypeahead()});$(document).off('mouseup').on('mouseup',(e)=>{if(!self.container.is(e.target)&&self.container.has(e.target).length===0&&!$('#popup').is(e.target)&&$('#popup').has(e.target).length===0&&!$('#curtain').is(e.target)){self.hidetypeahead()}})},200);return!1}};return this};$(()=>{$(document).on('submit','.j-loginform',customjs.submitlogin);$(document).on('submit','.login-form',customjs.login);$(document).on('click','.j-forgetpassword',customjs.resetpasswordform);$(document).on('submit','.j-resetpasswordform',customjs.resetpassword);if(typeof peppercategory!=='undefined'){peppercategory.postupdate=customjs.initcategory;$(document).on('click','.pcSort li',function(){peppercategory.update('sort',$(this).attr('value'))});$(document).on('click','.filterResetAll',()=>{peppercategory.update('reset')});$(document).on('click',`.${peppercategory.config.paginationclass} .viewAll`,function(){if($(this).parents('li').hasClass('disabled')){return!1}
const lm_page=$(this).data('altpage');if(lm_page=='undefined'){return}
switch(lm_page){default:if(!isNaN(lm_page)){lb_paginationbusy=!0;peppercategory.update('paginate',lm_page)}
break}
return!1})}})