jQuery(document).ready(function(){var amountInCart=0;if(Cookies.get('amountInCart')!==undefined){amountInCart=Cookies.get('amountInCart');if($('.jsShoppingCartAmountUnique').length){$('.jsShoppingCartAmountUnique').text(amountInCart)}}
$('.jsSubCategory').on('click',function(){if($(this).hasClass('active')){$(this).removeClass('active');$('.jsSubCategories[data-uid="'+$(this).attr('data-uid')+'"]').slideUp()}else{$(this).addClass('active');$('.jsSubCategories[data-uid="'+$(this).attr('data-uid')+'"]').slideDown()}})
$('.jsShowLoader').on('click',function(){if($('.loader').length){$('.loader').removeClass('invisible')}})
$('.jsItemCategory').on('change',function(){loadItemsThroughAjax('default')})
$('.jsItemSorting').on('change',function(){loadItemsThroughAjax('sort')})
$('.jsLoadMoreItems').on('click',function(){loadItemsThroughAjax('new')})
$('.jsItemSearchValue').on('keydown',function(e){if(e.which==13){loadItemsThroughAjax($('.jsItemSearchValue').val())}})
$('.jsItemSearchSubmit').on('click',function(){loadItemsThroughAjax($('.jsItemSearchValue').val())})
$('.jsFilterReset').on('click',function(){$('.jsItemCategory').prop('checked',!1);$('.jsItemSearchValue').val('');loadItemsThroughAjax('reset')})
var itemInFocus=$('.jsItemInFocus');if(itemInFocus.length){var itemUid=itemInFocus.attr('data-uid');var item=$('.jsListItem[data-uid="'+itemUid+'"]');if(item.length){$('html,body').animate({scrollTop:item.offset().top-80},'slow')}}
$('.jsAreaHead').on('click',function(){if($(this).hasClass('open')){$(this).removeClass('open').next('.jsAreaBody').slideUp()}else{$(this).addClass('open').next('.jsAreaBody').slideDown()}})
$('.jsItemAmount').on('input',function(){if(!$.isNumeric($(this).val())){$('.jsItemAmount').val('')}else{var itemAmount=$(this).val();if($(this).attr('data-index')!==undefined){itemAmount=$('.jsItemAmount[data-index="'+$(this).attr('data-index')+'"]').val();if($('.jsUpdateCart').length){var index=$(this).attr('data-index');$('.jsUpdateCart.index'+index).removeClass('d-none')}
if($('.jsStartCheckout').length){$('.jsStartCheckout').addClass('d-none')}}
var min=parseInt($('.jsItemAmount').attr('data-min'));var amount=parseInt($(this).val());if(amount<min){amount=min}
itemAmount.val(amount)}});$('.jsItemLess').on('click',function(){var index=$(this).attr('data-index');var itemAmountSelector=$('.jsItemAmount[data-index="'+index+'"]');var itemAmount=itemAmountSelector.val();if($('.jsUpdateCart').length){$('.jsUpdateCart.index'+index).removeClass('d-none')}
if($('.jsStartCheckout').length){$('.jsStartCheckout').addClass('d-none')}
var min=parseInt(itemAmountSelector.attr('data-min'));var amount=itemAmount-1;if(amount>=min){itemAmountSelector.val(amount);if($('.jsVoucherTotal').length){var total=$('.jsVoucherValueOption.active').attr('data-value')*(amount);$('.jsVoucherTotal').text(total);$('.jsValuePreview').text(total)}}})
$('.jsItemPlus').on('click',function(){var index=$(this).attr('data-index');var itemAmountSelector=$('.jsItemAmount[data-index="'+index+'"]');var itemAmount=parseInt(itemAmountSelector.val());if($('.jsUpdateCart').length){$('.jsUpdateCart.index'+index).removeClass('d-none')}
if($('.jsStartCheckout').length){$('.jsStartCheckout').addClass('d-none')}
var amount=itemAmount+1;itemAmountSelector.val(amount);if($('.jsVoucherTotal').length){var total=$('.jsVoucherValueOption.active').attr('data-value')*(amount);$('.jsVoucherTotal').text(total);$('.jsValuePreview').text(total)}})
$('.jsLinkTrigger').on('change',function(){if($(this).prop('checked')){$('.jsLoginLink')[0].click()}})
$('.jsUpdateCartSubmit').on('click',function(){if($('.loader').length){$('.loader').removeClass('invisible')}
var newAmounts={};$('.jsItemAmount').each(function(){newAmounts[$(this).attr('data-index')]=$(this).val()})
$('.jsNewCartAmounts').val(JSON.stringify(newAmounts));$('.jsUpdateCart').submit()})
$('.jsItemVariant').on('change',function(){var selectedVariantUid=$(this).val();if($('.jsVariantPrice[data-uid="'+selectedVariantUid+'"]').length){let variantprice=$('.jsVariantPrice[data-uid="'+selectedVariantUid+'"]').attr('data-price');let variantpriceFormatted=$('.jsVariantPrice[data-uid="'+selectedVariantUid+'"]').text();$('.jsItemPrice').attr('data-price',variantprice).text(variantpriceFormatted)}else{let variantprice=$('.jsOgItemPrice').attr('data-price');let variantpriceFormatted=$('.jsOgItemPrice').text();$('.jsItemPrice').attr('data-price',variantprice).text(variantpriceFormatted)}})
$('.jsShowRequestForm').on('click',function(){if(!$('.jsRequestForm').hasClass('open')){$('.jsRequestForm').addClass('open').next('.jsAreaBody').slideDown();$('html,body').animate({scrollTop:$('.jsRequestForm').offset().top-80},'slow')}})
$('.jsThumbSujet').on('click',function(){if(!$(this).hasClass('active')){$('.jsThumbSujet').removeClass('active');$(this).addClass('active');$('.jsMainSujet').addClass('d-none');$('.jsMainSujet[data-uid="'+$(this).attr('data-uid')+'"]').removeClass('d-none')}})
$('.jsVoucherValueOption').on('click',function(){$('.jsVoucherValueOption').removeClass('active');$(this).addClass('active');var total=$('.jsVoucherValueOption.active').attr('data-value')*$('.jsItemAmount').val();$('.jsVoucherTotal').text(total);$('.jsValuePreview').text(total);$('.jsValuePreviewDescription').text($(this).attr('data-text'))})
$('.jsVoucherInput').on('input',function(){$('.jsPreviewField[data-uid="'+$(this).attr('data-uid')+'"]').text($(this).val())})
$('.jsAddToCartWebxShop').on('click',function(){var uid=$(this).attr('data-uid');var amount=$('.jsItemAmount').val();var variantSelected=!1;if($('.jsItemVariant').length){variantSelected=!1;if($('.jsItemVariant').val()!=null){variantSelected=!0}}else{variantSelected=!0}
if(uid!==undefined&&variantSelected){var variant='';var itemprice='';var total=0;var text='';var requestdata={};if(uid==0){variant=$('.jsThumbSujet.active').attr('data-uid');itemprice=$('.jsVoucherValueOption.active').attr('data-value');total=parseFloat(itemprice)*parseInt(amount);$('.jsVoucherInput').each(function(){text=text+$(this).attr('data-uid')+':'+$(this).val()+'|'})}else{variant=$('.jsItemVariant').val();itemprice=$('.jsItemPrice').attr('data-price');total=parseFloat(itemprice)*parseInt(amount)}
requestdata.uid=uid;requestdata.amount=amount;requestdata.total=total;requestdata.variant=variant;requestdata.itemprice=itemprice;requestdata.text=text;addToCartThroughAjax(requestdata)}else{generateSwal($('.jsNoVariantSelected').attr('data-title'),$('.jsNoVariantSelected').attr('data-text'))}})
$('.jsCloseCartPopUp').on('click',function(){$('.jsCartPopUp').addClass('d-none')})
if($('.jsCorrectAmountInCart').length){var value=$('.jsCorrectAmountInCart').attr('data-amount');if(value!=amountInCart){Cookies.set('amountInCart',value,{expires:7,path:'/'})
if($('.jsShoppingCartAmountUnique').length){$('.jsShoppingCartAmountUnique').text(value)}}}
if($('.jsCartTotalPosition').length&&$('.jsAmountToPay').length){calculateCartTotal()}
$('.jsPaymentMethod').on('change',function(){$('.jsPaymentOption').addClass('d-none');if($('.jsPaymentOption[data-uid="'+$(this).val()+'"]').length){$('.jsPaymentOption[data-uid="'+$(this).val()+'"]').removeClass('d-none')}
calculateCartTotal()})
$('.jsDeliveryType').on('change',function(){$('.jsDeliveryOption').addClass('d-none');let selectedCountry=$('.jsInvoiceCountrySelect').val();let deliveryFree=!1;if($('.jsCountryDeliveryFree[data-uid="'+selectedCountry+'"]').length){if($('.jsAmountToPay').attr('data-value')>=$('.jsCountryDeliveryFree[data-uid="'+selectedCountry+'"]').attr('data-total')){deliveryFree=!0}}
if(!deliveryFree){if($('.jsDeliveryOption[data-uid="'+$(this).val()+'"]').length){$('.jsDeliveryOption[data-uid="'+$(this).val()+'"]').removeClass('d-none')}}
calculateCartTotal()})
$('.jsUsertype').on('change',function(){if($(this).val()=='guest'){$('.jsUserPasswordSection').addClass('d-none');$('input[name="userdata[password]"]').prop('required',!1);$('input[name="userdata[username]"]').prop('required',!1)}else{$('.jsUserPasswordSection').removeClass('d-none');$('input[name="userdata[password]"]').prop('required',!0);$('input[name="userdata[username]"]').prop('required',!1)}})
$('.jsInvoiceCountrySelect').on('change',function(){$('.loader').removeClass('invisible');var url=$('#calculatePricesAsync').attr('data-url');var currency=$('#calculatePricesAsync').attr('data-currency');var value=$(this).val();if(value!=13&&value!=54){$('.jsPaymentMethodOption[data-uid="2"]').removeClass('d-flex').addClass('d-none');$('.jsPaymentMethod[id="2"]').prop('checked',!1);$('.jsPaymentMethodOption:not(".d-none"):first').find('.jsPaymentMethod').prop('checked',!0)}else{$('.jsPaymentMethodOption[data-uid="2"]').removeClass('d-none').addClass('d-flex')}
let payload={deliveryCountry:value,calculatePricesAsync:1};jQuery.ajax({type:"POST",url:url,async:!0,cache:!1,dataType:'html',data:payload,success:function(content){$('.jsDeliveryFeeHint').text('');var prices=JSON.parse(content);$('.jsCalculatedPriceContainer').children().remove();$.each(prices,function(k,v){$.each(v,function(key,value){var replace=value.toString().replace(',','.');var float=parseFloat(replace).toFixed(2);if(float>0){if(key!=='subtotal'){$('.jsCalculatedPriceContainer').append('<div><label class="fixedWidthLabel">'+key+'</label><span>'+currency+' '+value+'</span></div>')}else{$('.jsCalculatedPriceContainer').append(' <div class="jsCartTotalPosition" data-value="'+float+'"/>')}}else{if(key=='deliveryHint'){$('.jsDeliveryFeeHint').text(value)}}})})
calculateCartTotal();$('.loader').addClass('invisible')},error:function(error){$('.loader').addClass('invisible')}})});$('.jsVoucherCodeRedeem').on('input',function(){if($(this).val().length>2){var url=$('#verifyDicscountCodeAsync').attr('data-url');var cartTotal=$('.jsAmountToPay').attr('data-value');var code=$(this).val();if(url){$(this).data({code:code,cartTotal:cartTotal});jQuery.ajax({type:"POST",url:url,async:!1,cache:!1,dataType:'html',data:$(this).data(),success:function(content){var response=JSON.parse(content);if(response.valid){var voucherValue=0;var currency=$('#calculatePricesAsync').attr('data-currency');var cartTotal=$('.jsAmountToPay').attr('data-value');var amount=response.amount;var unit='';if(response.unit==1){if(amount>100){amount=100}
unit='%';voucherValue=(cartTotal/100)*amount}else{unit='€';if(amount>cartTotal){voucherValue=cartTotal}else{voucherValue=amount}
if(voucherValue<=0){voucherValue=0}}
$('.jsVoucherValueRedeem').attr('data-value',voucherValue).text('-'+currency+' '+parseFloat(voucherValue).toFixed(2).toLocaleString().replace('.',','));$('.jsDiscountVerificationResult').text(response.label+' '+amount+unit);calculateCartTotal()}else{$('.jsDiscountVerificationResult').text(response.label);$('.jsVoucherValueRedeem').attr('data-value',0).text('');calculateCartTotal()}},error:function(error){}})}}else{$('.jsDiscountVerificationResult').text('');$('.jsVoucherValueRedeem').attr('data-value',0).text('');calculateCartTotal()}})
$('.jsDeliverySameAsInvoice').on('change',function(){if($(this).prop('checked')){var contact='';$('.jsContactData').each(function(){if($(this).val().length>0){contact=contact+$(this).val()+' '}})
if($('input[name="userdata[deliveryContact]"]').length){$('input[name="userdata[deliveryContact]"]').val(contact)}
$('.jsInvoiceAddress').each(function(){$('.jsDeliveryAddress[data-type="'+$(this).attr('data-type')+'"]').val($(this).val())})}})
$('input[name="userdata[email]"]').on('input',function(){if($('input[name="userdata[username]"]').length){$('input[name="userdata[username]"]').val($(this).val())}})
$('.jsShowSwal').on('click',function(){generateSwal($(this).attr('data-title'),$(this).attr('data-text'))})
$('.jsDeliveryAddressSelect').on('change',function(){var addressoption=$('.jsDeliveryAddressOption[data-uid="'+$(this).val()+'"]');if(addressoption.length){$('input[name="userdata[deliveryContact]"]').val(addressoption.attr('data-contact'));$('input[name="userdata[deliveryAddress]"]').val(addressoption.attr('data-address'));$('input[name="userdata[deliveryZip]"]').val(addressoption.attr('data-zip'));$('input[name="userdata[deliveryCity]"]').val(addressoption.attr('data-place'))}})
$('.jsPasswordCheck').on('input',function(){$('.jsPasswordCheck').val($(this).val());var passwordStrength=checkPasswordStrength($(this).val());let text=$('.jsPasswordStrength').attr(passwordStrength);$('.jsPasswordStrength').removeClass('data-save').removeClass('data-error').removeClass('data-warning').removeClass('d-none').text(text).addClass(passwordStrength)})
$('.jsChangePasswordState').on('click',function(){$('.jsPasswordState').removeClass('d-none');$(this).parent().addClass('d-none')})
$('.jsValidateForm').on('click',function(e){e.preventDefault();$(this).prop('disabled',!0);var form=$(this).closest('form');var valid=!0;if(form[0].checkValidity()){if($('.jsUsertype:checked').val()=='user'){if($('.jsPasswordStrength').hasClass('data-error')){valid=!1;generateSwal($('.jsShowSwal').attr('data-title'),$('.jsShowSwal').attr('data-text'))}
var url=$('.jsUsernameUniquenessUrl').attr('data-url');var username=$('.jsUsernameInputField').val();$(this).data({username:username});if(url){jQuery.ajax({async:!1,type:"POST",url:url,data:$(this).data(),success:function(content){if(content==1){valid=!1;generateSwal($('.jsCustomValidityUsernameTitle').text(),$('.jsCustomValidityUsernameText').text())}},error:function(error){console.log(error)}})}}}else{valid=!1;form[0].reportValidity();$(this).prop('disabled',!1)}
if(valid){form.submit()}else{$(this).prop('disabled',!1)}})
if($('.jsThumbSliderAutoHeight').length){setThumbSlidesToSameHeight()}})
$(window).resize(function(){if($('.jsThumbSliderAutoHeight').length){setThumbSlidesToSameHeight()}});function checkPasswordStrength(password){var levels=[/^.{8,}/,/^.*[A-Z]/,/^.*[a-z]/,/^.*[0-9]/,/^.*[^A-Za-z0-9]/];var rating=0;$.each(levels,function(index,value){if(value.test(password)){rating++}})
if(rating==5){return'data-save'}
if(rating<5&&rating>=3){return'data-warning'}
if(rating<=2){return'data-error'}}
function calculateCartTotal(){var currency=$('#calculatePricesAsync').attr('data-currency');let selectedCountry=$('.jsInvoiceCountrySelect').val();if($('.jsCountryDeliveryFree[data-uid="'+selectedCountry+'"]').length){$('.jsDeliveryOption').addClass('d-none')}
var cartTotal=0;$('.jsCartTotalPosition').each(function(){if(!($(this).hasClass('d-none'))){let itemprice=parseFloat($(this).attr('data-value'));cartTotal=cartTotal+itemprice}})
if($('.jsVoucherValueRedeem').length){if($('.jsVoucherValueRedeem').attr('data-value')>0){cartTotal=cartTotal-parseFloat($('.jsVoucherValueRedeem').attr('data-value'));$('.jsVoucherRedeem').removeClass('d-none').addClass('d-flex')}else{$('.jsVoucherRedeem').removeClass('d-flex').addClass('d-none')}
if(cartTotal<=0){cartTotal=0}}
$('.jsAmountToPay').text(currency+' '+parseFloat(cartTotal).toFixed(2).toLocaleString().replace('.',',')).attr('data-value',cartTotal)}
function loadItemsThroughAjax(action){$('.loader').removeClass('invisible');var categories='';var subcategories='';$('.jsItemCategory:checked').each(function(){if($(this).attr('name')=='shopCategory'){categories=categories+$(this).val()+','}
if($(this).attr('name')=='shopSubCategory'){subcategories=subcategories+$(this).val()+','}})
$(this).data({category:categories,subcategory:subcategories,sorting:$('.jsItemSorting').val(),action:action,offset:$('.jsListItem').length});var url=$('#ajaxRoute').attr('data-url');var resultbox=$('.jsItemContainer');jQuery.ajax({async:!0,type:"POST",url:url,data:$(this).data(),success:function(content){if(content!=''){var expectedResultCount=$('.jsLoadLimit').attr('data-limit');var regex=/jsListItem/g;var count=content.match(regex).length;$('.loader').addClass('invisible');if(count<expectedResultCount){$('.jsLoadMoreItems').addClass('d-none')}else{$('.jsLoadMoreItems').removeClass('d-none')}
if(action!='new'){$('.jsListItem').remove()}
resultbox.append(content)}else{$('.loader').addClass('invisible');$('.jsLoadMoreItems').addClass('d-none')}},error:function(error){console.log(error)}})}
function addToCartThroughAjax(data){$('.loader').removeClass('invisible');$('.jsAvailabilityMessage').removeClass('ok').removeClass('error').removeClass('warning').addClass('d-none');$(this).data(data);var url=$('#addToCartUrl').attr('data-url');if(url){jQuery.ajax({async:!0,type:"POST",url:url,data:$(this).data(),success:function(content){$('.loader').addClass('invisible');response=JSON.parse(content);$.each(response,function(key,value){if(key=='amountInCart'){Cookies.set('amountInCart',value,{expires:7,path:'/'})
if($('.jsShoppingCartAmountUnique').length){$('.jsShoppingCartAmountUnique').text(value)}}else{$('.jsAvailabilityMessage').removeClass('d-none').addClass(key).text(value)}
if(key=='ok'){if($('.jsMainSliderSlide').length){$('.jsCartPopUpItemImg').attr('src',$('.jsMainSliderSlide.swiper-slide-active .slider_image').prop('href'))}else{$('.jsCartPopUpItemImg').attr('src',$('.jsItemImage').prop('src'))}
$('.jsCartPopUpItemVariant').text($('.jsItemAmount').val()+'x  '+$('.jsItemVariant option:selected').text());$('.jsCartPopUpItemPrice').text($('.jsItemPrice').text());$('.jsCartPopUp').removeClass('d-none')}})},error:function(error){console.log(error)}})}else{console.log('path not found')}}
function generateSwal(title,text){swal({title:title,text:text,icon:"info",closeOnClickOutside:!0,confirmButtonClass:"btn btn-primary",closeOnEsc:!0,buttons:{confirm:{text:"OK",value:!0,visible:!0,className:'',closeModal:!0}}})}
function setThumbSlidesToSameHeight(){$('.jsThumbSliderAutoHeight').each(function(){var height=0;$(this).find('.jsThumbSlideAutoHeight').each(function(){let slideHeight=$(this).outerHeight();if(slideHeight>height){height=slideHeight}})
$(this).find('.jsThumbSlideAutoHeight').css('height',height)})}