var tmsCart=(function(){
var v_total=0;
var v_total_cp=0;
var v_items={};
var v_tpl='
';
var v_lu=0;
var v_hide_to=0;
var parseInfo=function(data){
v_total=data.cart.total;
v_total_frm=data.cart.total_frm;
v_total_cp=data.cart.total_cpoints;
v_total_cp_frm=data.cart.total_cpoints_frm;
v_items=data.cart.products;
};
var render=function(){
$('#headerCartTotal').html((v_total>0?v_total_frm:(v_total_cp>0?v_total_cp_frm:v_total_frm)));
$('#headerCart table').html('');
if(v_total || v_total_cp){
for(var i in v_items){
if(i<5){
var tr=v_tpl;
for(var key in v_items[i]){
tr=tr.split('{'+key+'}').join(v_items[i][key]);
}
$('#headerCart table').append(tr);
}
else if(i==5){
$('#headerCart table').append('| +'+(v_items.length-5)+' more item'+((v_items.length-5)>1?'s':'')+' |
');
}
}
jQuery('body').append('');
}
else{
tmsCart.hide();
}
};
var checkLastUpdate=function(){
$.ajax({
url: base_href+"checkout_ajax.php?action=getLastUpdate",
success: function(data){
if(!data.success){
return;
}
if(v_lu'+data.user.links[i]+'');
}
},
'json'
);
};
var checkLastUpdate=function(){
//console.log('tmsAccount.checkLastUpdate');
$.ajax({
url: base_href+"ajax.php?m=accountLastUpdate",
success: function(data){
if(!data.success){
return;
}
if(v_lu!=data.lu){
v_lu=data.lu;
refresh();
try{
if(typeof(tmsCheckout)=='object'){
tmsCheckout.refresh();
}
} catch(e){}
try{
if(typeof(tmsCheckout1)=='object'){
tmsCheckout1.refresh();
}
} catch(e){}
}
},
dataType: 'json',
complete: function(){
setTimeout(checkLastUpdate, 20000);
},
timeout: 10000
});
};
return {
init: function(){
$("#headerUserAccount .account").hoverIntent({sensitivity: 5, interval: 200, over: tmsAccount.show, timeout: 350, out: tmsAccount.hide});
checkLastUpdate();
},
show: function(){
if(!$("#headerAccount:visible").length){
if($("body.scroll").length){
$("#headerAccount").css({"left":$('#headerUserAccount .account').position().left-1+"px", "top":$('#headerUserAccount .account').position().top+32+"px"});
}
else{
$("#headerAccount").css({"left":$('#headerUserAccount .account').position().left+1+"px", "top":$('#headerUserAccount .account').position().top+54+"px"});
}
$("#headerAccount").show();
}
},
hide: function(){
if($("#headerAccount:visible").length){
$("#headerAccount").hide();
}
},
refresh: function(){
refresh();
}
};
}());
var tmsCompareBox=(function(){
var products;
if(window.localStorage && window.localStorage.getItem('compareProducts')){
products=JSON.parse(window.localStorage.getItem('compareProducts'));
if(products.ver!='2'){
products={l:0, ver:'2'};
window.localStorage.setItem('compareProducts', JSON.stringify(products));
}
}
else{
products={l:0, ver:'2'};
}
return {
init: function(){
if($('.productCompareLabel').length){
tmsCompareBox.mapCheckboxes();
var i=$('.productCompareLabel:first').attr('tms-compare-cid');
if(i in products){
for(var j in products[i]){
if(j!='l'){
tmsCompareBox.add(i, j, products[i][j].img, products[i][j].url);
}
}
}
tmsCompareBox.render(i);
}
},
render: function(cid){
if(cid in products && products[cid].l){
$('footer #rightCompareBox').show();
var params='';
for(var i in products[cid]){
if(i!=='l'){
params=params+'&prods[]='+i;
}
}
$('#rightCompareBoxGo').attr('href', base_href+'products/compare.html?ajaxPop=1'+params);
$('#rightCompareBoxGo').colorbox({
onComplete:function(){ tmsCart.mapSubmits(); },
maxWidth: '990px'
});
}
else{
$('footer #rightCompareBox').hide();
}
},
add: function(cid, pid, img, url){
var dragImage=false;
if(!(cid in products)){
products[cid]={l:0};
products.l++;
}
if(!(pid in products[cid])){
products[cid][pid]={'img': img, 'url': url};
products[cid].l++;
if(window.localStorage){
window.localStorage.setItem('compareProducts', JSON.stringify(products));
}
dragImage=true;
tmsCompareBox.render(cid);
}
$('.productComparePID'+pid+' input').prop('checked', true);
if(!$('footer #rightCompareBox #compareProduct'+pid).length){
if(dragImage){
//image flyover
var compareBox=$('footer #rightCompareBox');
var imgtodrag=$('.productComparePID'+pid).parents('.forCartImageItem').first().find(".image img").eq(0);
if(imgtodrag){
var imgclone = imgtodrag.clone()
.offset({
top: imgtodrag.offset().top,
left: imgtodrag.offset().left
})
.css({
'opacity': '0.5',
'position': 'absolute',
'height': '150px',
'width': '150px',
'z-index': '4000000002',
'display': 'block'
})
.appendTo($('body'))
.animate({
'top': compareBox.offset().top + 10,
'left': compareBox.offset().left + 10,
'width': 75,
'height': 75
}, 1000, 'easeInOutExpo');
imgclone.animate({
'width': 0,
'height': 0
}, function () {
$(this).detach()
});
}
setTimeout(function(){
$('footer #rightCompareBox').prepend('');
}, 1000);
}
else{
$('footer #rightCompareBox').prepend('');
}
}
},
remove: function(cid, pid){
if(cid in products){
if(pid in products[cid]){
delete products[cid][pid];
products[cid].l--;
if(window.localStorage){
window.localStorage.setItem('compareProducts', JSON.stringify(products));
}
tmsCompareBox.render(cid);
}
}
$('.productComparePID'+pid+' input').prop('checked', false);
if($('footer #rightCompareBox #compareProduct'+pid).length){
$('footer #rightCompareBox #compareProduct'+pid).remove();
}
},
mapCheckboxes: function(){
$('.productCompareLabel').mousedown(function(event){
event.preventDefault();
var cid=$(this).attr('tms-compare-cid');
var pid=$(this).attr('tms-compare-pid');
if((cid in products) && (pid in products[cid])){
tmsCompareBox.remove(cid, pid);
}
else{
if(cid in products && products[cid].l==4){
alert('You can only compare 4 products!');
}
else{
tmsCompareBox.add(cid, pid, $(this).attr('tms-compare-img'), $(this).attr('tms-compare-url'));
}
}
});
$('.productCompareLabel').click(function(event){
event.preventDefault();
});
$('.productCompareLabel input').click(function(event){
event.preventDefault();
});
}
};
}());
function setCookie(cookieName, cookieValue, nDays){
var today = new Date();
var expire = new Date();
if(nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString()+";path=/";
}
function getCookie(name){
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if(begin == -1){
begin = dc.indexOf(prefix);
if(begin != 0)
return null;
}
else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if(end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
var carouselIndexProds={'indexNewProducts':10, 'indexPopularProducts':10};
var carouselIndexPos={'indexNewProducts':0, 'indexPopularProducts':0};
function carouselIndexAddProds(carouselId){
$.get(
base_href+"ajax.php",
{'m': 'carouselIndexAddProds', 'cid': carouselId, 'pos': carouselIndexProds[carouselId]},
function(data){
if(!data.success){
return;
}
if(data.productsRes){
$("#"+data.carouselId+" .carousel ul").append(data.html);
$("#"+data.carouselId+" .carousel").trigger('endCarousel');
$("#"+data.carouselId+" .carousel").jCarouselLite({
btnNext: "#"+data.carouselId+" .carouselNext",
btnPrev: "#"+data.carouselId+" .carouselPrev",
circular: false,
visible: 5,
start: carouselIndexPos[data.carouselId],
scroll: 5,
afterEnd: function(prods){
carouselIndexPos[data.carouselId]=$(prods[0]).index();
if($(prods[0]).index()==carouselIndexProds[data.carouselId]-5){
carouselIndexAddProds(data.carouselId);
}
}
});
carouselIndexProds[data.carouselId]+=5;
tmsCart.mapSubmits();
}
else{
$("#"+data.carouselId+" .carousel").trigger('endCarousel');
$("#"+data.carouselId+" .carousel").jCarouselLite({
btnNext: "#"+data.carouselId+" .carouselNext",
btnPrev: "#"+data.carouselId+" .carouselPrev",
circular: false,
visible: 5,
start: carouselIndexPos[data.carouselId],
scroll: 5
});
}
},
'json'
);
}
function showCountrySelection(linkClicked){
if(!$('#countrySelectionContainer').length){
$.get(
base_href+"template_new/country_selection.html",
function(data){
$("body").append(data);
$("#countrySelectionContainer #countrySelectionMap area").click(function(event){
event.preventDefault();
$("#countrySelectionContainer .countries").hide();
$("#countrySelectionContainer ."+$(this).attr('href')).show();
});
$("#countrySelectionContainer .countries a").click(function(event){
event.preventDefault();
$("form[name=countrycf] input[name=country_currency]").val($(this).attr('country'));
$("form[name=countrycf]").submit();
});
$(document).mouseup(function(e){
if(!$("#countrySelectionContainer").is(e.target) && $("#countrySelectionContainer").has(e.target).length===0){
$("#countrySelectionContainer").hide();
$("#countrySelectionContainer .countries").hide();
}
});
if($(linkClicked).closest('header').length){
$("#countrySelectionContainer").css({"left":($(linkClicked).position().left+$(linkClicked).width()-475)+"px", "top":$(linkClicked).position().top+24+"px"});
}
else{
$("#countrySelectionContainer").css({"left":($(linkClicked).position().left)+"px", "top":$(linkClicked).position().top-257+"px"});
}
$('#countrySelectionContainer').show();
}
);
}
else{
if($('#countrySelectionContainer').is(':visible')){
$('#countrySelectionContainer').hide();
}
else{
if($(linkClicked).closest('header').length){
$("#countrySelectionContainer").css({"left":($(linkClicked).position().left+$(linkClicked).width()-475)+"px", "top":$(linkClicked).position().top+24+"px"});
}
else{
$("#countrySelectionContainer").css({"left":($(linkClicked).position().left)+"px", "top":$(linkClicked).position().top-257+"px"});
}
$('#countrySelectionContainer').show();
}
}
}
var scrollMenuHover=0;
$(document).ready(function(){
//check if compatible browser
if($('html').hasClass('no-canvas')){
$.colorbox({
html: '',
scrolling: false,
});
$('#cboxLoadingOverlay').remove();
$('#cboxLoadingGraphic').remove();
}
//lazy load images
$("img.lazy").lazyload({
skip_invisible: false,
effect: "fadeIn",
failure_limit: 10,
skip_invisible: false
});
var navPos=$('nav').position().top;
$(window).scroll(function(){
if($(document).scrollTop()>navPos){
if(!$("body.scroll").length){
tmsCart.hide();
tmsAccount.hide();
$('body').addClass('scroll');
if(scrollMenuHover==1){
$("nav").addClass("scrollShow");
$("nav").css({"left": $('#logoLine .logoLink').position().left-1+"px"});
$("nav > ul > li > div").css({"margin-left": -$('#logoLine').position().left+"px"});
}
}
}
else{
if($("body.scroll").length){
tmsCart.hide();
tmsAccount.hide();
$("#jquery-live-search").hide();
$('body').removeClass('scroll');
if(scrollMenuHover==1){
$("nav").removeClass("scrollShow");
$("nav > ul > li > div").css({"margin-left": $('#logoLine .logoLink').position().left+"px"});
}
}
}
});
//top menu
$("nav > ul > li").hoverIntent({
sensitivity: 5,
interval: 100,
over: function(){
$("div", this).show();
$("a", this).first().addClass('sel');
$("div", this).css({"margin-left":$('nav ul').position().left+ "px"});
scrollMenuHover=1;
},
timeout: 350,
out: function(){
$("div", this).hide();
$("a", this).first().removeClass('sel');
scrollMenuHover=0;
}
});
$("nav > ul > li > a").not('.nosubmenu').click(function(event){
event.preventDefault();
});
function showMenuScroll(){
scrollMenuHover=1;
$("nav").css({"left": $('#logoLine .logoLink').position().left-1+"px"});
$("nav").addClass("scrollShow");
}
function hideMenuScrollDo(){
if(scrollMenuHover==0){
$("nav").css({"left":"auto"});
$("nav").removeClass("scrollShow");
}
}
$("nav").mouseenter(function(){
showMenuScroll();
});
$("nav").mouseleave(function(){
scrollMenuHover=0;
setTimeout(function(){
hideMenuScrollDo()
}, 1000);
});
$("#logoLine .scrollMenu").mouseenter(function(){
showMenuScroll();
});
$("#logoLine .scrollMenu").click(function(event){
event.preventDefault();
showMenuScroll();
});
$("#logoLine .scrollMenu").mouseleave(function(){
scrollMenuHover=0;
setTimeout(function(){
hideMenuScrollDo()
}, 1000);
});
$("#topMenuNlSubscribeLink").click(function(event){
event.preventDefault();
$('#topMenuNlSubscribeForm input[name=email]').show();
$('#topMenuNlSubscribeForm input[name=submit]').show();
});
$("#topMenuNlSubscribeForm").submit(function(event){
event.preventDefault();
$.colorbox({
href: base_href+'subscribe.html?ajaxPop=1&subscribe=yes&email='+$('#topMenuNlSubscribeForm input[name=email]').val(),
width: '600px',
height: '200px',
iframe: true
});
});
$("#footerNlSubscribeForm").submit(function(event){
event.preventDefault();
$.colorbox({
href: base_href+'subscribe.html?ajaxPop=1&subscribe=yes&email='+$('#footerNlSubscribeForm input[name=email]').val(),
width: '600px',
height: '200px',
iframe: true
});
});
$("#indexNewsletterBoxForm").submit(function(event){
event.preventDefault();
$.colorbox({
href: base_href+'subscribe.html?ajaxPop=1&subscribe=yes&email='+$('#indexNewsletterBoxEmail').val(),
width: '600px',
height: '200px',
iframe: true
});
});
//rightSocial
$("#rightSocial").hoverIntent({
sensitivity: 5,
interval: 200,
over: function(){
$("#rightSocial .l").show(300);
},
timeout: 350,
out: function(){
$("#rightSocial .l").hide(300);
}
});
//livesearch
$('form[name=header_search_form] input[name=q]').liveSearch({
url: base_href+'livesearch.php?q=',
});
$('form[name=header_search_form]').submit(function(){
if($('form[name=header_search_form] input[name=q]').val().length<2){
alert('The search string is to short!');
return false;
}
});
//index carousels
$("#indexNewProducts .carousel").jCarouselLite({
btnNext: "#indexNewProducts .carouselNext",
btnPrev: "#indexNewProducts .carouselPrev",
circular: false,
visible: 5,
start: carouselIndexPos['indexNewProducts'],
scroll: 5,
afterEnd: function(prods){
carouselIndexPos['indexNewProducts']=$(prods[0]).index();
if($(prods[0]).index()==carouselIndexProds['indexNewProducts']-5){
carouselIndexAddProds('indexNewProducts');
}
}
});
$("#indexPopularProducts .carousel").jCarouselLite({
btnNext: "#indexPopularProducts .carouselNext",
btnPrev: "#indexPopularProducts .carouselPrev",
circular: false,
visible: 5,
start: carouselIndexPos['indexPopularProducts'],
scroll: 5,
afterEnd: function(prods){
carouselIndexPos['indexPopularProducts']=$(prods[0]).index();
if($(prods[0]).index()==carouselIndexProds['indexPopularProducts']-5){
carouselIndexAddProds('indexPopularProducts');
}
}
});
//account menu
tmsAccount.init();
//cart
tmsCart.init();
//vat selection
$("#topLinks .vat a").click(function(event){
event.preventDefault();
if(!$('#vatSelectionContainer').length){
$.get(
base_href+"template_new/vat_selection.html",
function(data){
$("body").append(data);
$("#vatSelectionContainer").css({"left":($('#topLinks .vat > span > span').position().left-8)+"px", "top":$('#topLinks .vat').position().top+26+"px"});
$("#vatSelectionContainer a").click(function(event){
event.preventDefault();
setCookie('display_vat', $(this).attr('vatdisplay'), 90);
window.location.reload(true);
});
$(document).mouseup(function(e){
if(!$("#vatSelectionContainer").is(e.target) && $("#vatSelectionContainer").has(e.target).length===0){
$("#vatSelectionContainer").hide();
}
});
}
);
}
if($('#vatSelectionContainer').is(':visible')){
$('#vatSelectionContainer').hide();
}
else{
$('#vatSelectionContainer').show();
}
});
//country selection
$("#topLinks .country a").click(function(event){
event.preventDefault();
showCountrySelection(this);
});
$('footer .ship_worldwide_container a').click(function(event){
event.preventDefault();
showCountrySelection(this);
});
if(/iPhone|iPod|iPad/.test(navigator.userAgent)){
}
//compare box
tmsCompareBox.init();
//colorbox ajax links
$('.colorboxAjaxLink').click(function(event){
event.preventDefault();
$.colorbox({
href: $(this).attr('href')+'?ajaxPop=1',
width: '990px',
height: '400px',
iframe: true
});
});
$('.colorboxPop').colorbox({
maxWidth: '990px'
});
$('#cookiesAcknowledgementClose').click(function(event){
event.preventDefault();
setCookie('cookies_acknowledged', 1, 30);
$('#cookiesAcknowledgement').remove();
$('#cookiesAcknowledgementBg').remove();
});
//ga promo views
var gaPromotions=[];
$('.gaPromoTrack').each(function(){
gaPromotions.push({
'name': $(this).attr('data-promoName'),
'creative': $(this).attr('data-promoCreative')
});
});
if(gaPromotions.length){
dataLayer.push({
'ecommerce': {
'promoView': {
'promotions': gaPromotions
}
}
});
}
//ga promo clicks
$('.gaPromoTrack').click(function(event){
event.preventDefault();
var promoObj=this;
if($(promoObj).attr('href') && $(promoObj).attr('href')!=undefined){
dataLayer.push({
'event': 'promotionClick',
'ecommerce': {
'promoClick': {
'promotions': [{
'name': $(this).attr('data-promoName'),
'creative': $(this).attr('data-promoCreative')
}]
}
},
'eventCallback': function(){
document.location = $(promoObj).attr('href');
}
});
}
});
});
$(window).load(function(){
$('#seal_thawte').show();
});
var tmsAddressSearchModule=(function(){
var _instance;
function init(f){
var form=f;
var zipInput=$('form[name='+form+'] input[name=zip]');
var addressList=[];
var addressListUS=[];
var getZip=function(){
if($(zipInput).length){
if(getCountry()=='GB' && /[A-Za-z]{1,2}[0-9Rr][0-9A-Za-z]? ?[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}/.test($(zipInput).val())){
return $(zipInput).val().toUpperCase();
}
else if(getCountry()=='US' && /(^\d{5}$)|(^\d{5}-\d{4}$)/.test($(zipInput).val())){
return $(zipInput).val().toUpperCase();
}
}
return '';
};
var getCountry=function(){
return $('form[name='+form+'] select[name=country]').val();
}
var searchAddresses=function(){
if(getCountry()!='US'){
$('.uk_before_postcode').show();
}
if(getCountry()!='GB' && getCountry()!='US'){
return;
}
if(getZip()){
if(getCountry()=='US'){
if(!addressListUS[getZip()]){
$.get(
base_href+'ajax.php',
{m: 'addressSearchStamps', zip: getZip()},
function(data){
if(data.success){
addressListUS[getZip()]=data.statecity;
renderStateCity(data.statecity);
}
},
'json'
);
}
else{
renderStateCity(addressListUS[getZip()]);
}
}
else{
if(!addressList[getZip()]){
$.get(
base_href+'ajax.php',
{m: 'addressSearchPC', zip: getZip()},
function(data){
if(data.success){
addressList[getZip()]=data.addressList;
renderAddresses();
}
},
'json'
);
}
else{
renderAddresses();
}
}
}
};
var renderStateCity=function(address){
$('form[name='+form+'] input[name=city]').val(address.city);
$('form[name='+form+'] select[name=county_select]').val(address.state);
$('.uk_before_postcode').show();
}
var renderAddresses=function(){
if(!addressList[getZip()].length){
htmlAddressList='We haven\'t found any address for the postcode you entered. Please fill the address manually.
';
}
else{
htmlAddressList='You can select your address from the following list (or close this popup and enter it manually):
';
}
htmlAddressList+='';
}
htmlAddressList+='';
}
htmlAddressList+='
';
$.colorbox({
html: htmlAddressList,
scrolling: false,
onComplete: function(){
$('#tmsAddressListContainer > ul > li > a').click(function(event){
event.preventDefault();
if($('ul', $(this).parent('li')).is(':visible')){
$('ul', $(this).parent('li')).hide();
}
else{
$('ul', $(this).parent('li')).show();
}
$.colorbox.resize();
});
$('#tmsAddressListContainer > ul > li > ul > li > a').click(function(event){
event.preventDefault();
selectAddress($(this).attr('rel'));
$.colorbox.close();
});
}
});
};
var selectAddress=function(selectId){
selectId=selectId.split(',');
var address=addressList[getZip()][selectId[0]];
var premise=address.premise[selectId[1]]
$('form[name='+form+'] input[name=city]').val(address.post_town);
$('form[name='+form+'] input[name=county_input]').val(address.county);
$('form[name='+form+'] input[name=company]').val(premise.organisation);
$('form[name='+form+'] input[name=address2]').val('');
$('form[name='+form+'] input[name=zip]').val(address.postcode);
if(/^[0-9]+$/.test(premise.premise)){
var addrValue=premise.premise+(address.dependent_street?', '+address.dependent_street:'')+(address.street?', '+address.street:'')+(address.double_dependent_locality?', '+address.double_dependent_locality:'')+(address.dependent_locality?', '+address.dependent_locality:'');
}
else if(!premise.premise){
var addrValue=address.dependent_street;
if(address.street)
addrValue+=(addrValue?', '+address.street:'');
if(address.double_dependent_locality)
addrValue+=(addrValue?', '+address.double_dependent_locality:'');
if(address.dependent_locality)
addrValue+=(addrValue?', '+address.dependent_locality:'');
}
else{
var addrValue=premise.premise;
$('form[name='+form+'] input[name=address2]').val(address.dependent_street+(address.street?(address.dependent_street?', ':'')+address.street:'')+(address.double_dependent_locality?', '+address.double_dependent_locality:'')+(address.dependent_locality?', '+address.dependent_locality:''));
}
$('form[name='+form+'] input[name=address1]').val(addrValue);
};
var revealSearchButton=function(){
console.log('revealSearchButton '+getZip());
if(getZip() && (getCountry()=='GB' || getCountry()=='US')){
if(getCountry()=='GB'){
$('#zipPostcoderLink').show();
$('#ship_zipPostcoderLink').show();
$('#bill_zipPostcoderLink').show();
}
if(!$('.uk_before_postcode:visible').length || getCountry()=='US'){
searchAddresses();
}
}
else{
$('#zipPostcoderLink').hide();
$('#ship_zipPostcoderLink').hide();
$('#bill_zipPostcoderLink').hide();
if(getCountry()=='GB' || getCountry()=='US'){
$('.uk_before_postcode').hide();
}
else{
$('.uk_before_postcode').show();
}
}
};
//init
$('#zipPostcoderLink').click(function(event){
event.preventDefault();
searchAddresses();
});
$('#ship_zipPostcoderLink').click(function(event){
event.preventDefault();
searchAddresses();
});
$('#bill_zipPostcoderLink').click(function(event){
event.preventDefault();
searchAddresses();
});
$(zipInput).on('input propertychange paste change', function(){
revealSearchButton();
});
$('form[name='+form+'] select[name=country]').change(revealSearchButton);
revealSearchButton();
return {};
};
return {
init: function(f){
/*if(!_instance){
_instance=init(f);
}
return _instance;*/
return init(f);
}
};
})();