let focused=null;const selectedValues={left:[],right:[]};let lastEye=null;function setOptionVariant(t,e){e=e||t.find(".vc-product-options-first-eye .vc-product-variants-select").val();const o=$('.vc-product-options-first-eye .vc-product-variants-select option[value="'+e+'"]').first().text()||$(".vc-product-options-first-eye .vc-product-variants-select option:selected").text();"null"==e&&$(".vc-product-variants-list").removeClass("active"),t.find(".vc-product-variants-item").each((function(){$(this).data("value")==e?$(this).hasClass("active")?$(this).closest(".vc-product-variants-list").addBack().removeClass("active"):$(this).closest(".vc-product-variants-list").addBack().addClass("active"):$(this).removeClass("active")})),t.find(".vc-product-variants-select").find('option[value="'+e+'"]').prop("selected",!0).end().each((function(){$(this).closest(".vc-product-options-items").is(":visible")&&onSkuPropValueChanged($(this).attr("id"))})),t.find(".vc-product-options-second-eye .vc-product-options-color .form-control-static").text("null"==e?"---":o)}function buildSkuPropValueKey(t){const e=[];return skuStockInfo.skuPropValueEffectiveStockUnitsMap.keyBuilder.requiredSkuPropIds.forEach((function(o){e.push(t[o])})),e.join(";")}function getFirstSkuEffectiveUnits(t){for(const e in t)if(t.hasOwnProperty(e))return t[e];return 0}function getEffectiveStockUnits(t){if(0===skuStockInfo.skuPropValuesCount)return getFirstSkuEffectiveUnits(skuStockInfo.skuPropValueEffectiveStockUnitsMap.map);const e=skuStockInfo.skuPropValueEffectiveStockUnitsMap.map;return e[t]?e[t]:0}function getWhEffectiveStockUnits(t,e){let o=skuStockInfo.storeInfo.whSkuPropValueEffectiveUnitsMaps[e]||null;return null===o?0:(o=o.map,0===skuStockInfo.skuPropValuesCount?getFirstSkuEffectiveUnits(o):null!==o&&o[t]?o[t]:0)}function onSelectedAllParams(){const t=buildSkuPropValueKey(selectedValues[lastEye]),e=getEffectiveStockUnits(t),o=$("#aval-productParam-"+lastEye).closest(".vc-product-options-availability");toggleBusyIndicator("show",o),void 0!==skuStockInfo.skuDataIds[t]&&"undefined"!=typeof opticStoresCount&&opticStoresCount>0&&($.get(baseUrl("/product/on-optic-store/"),{sid:skuStockInfo.skuDataIds[t],pid:productId},(function(t){document.querySelector(".vc-js-detail-info-optic-store").innerHTML=t.html})),$.post(baseUrl("/product/log-availability-info/"),{productId:productId,onStock:e,deliveryDays:skuStockInfo.supplyDeliveryDays,skuId:skuStockInfo.skuDataIds[t]})),window.setTimeout(hideToggleBusyIndicator,300)}function recordSelectedValues(t){const e=t.split("-"),o=e[0],n=e[1];lastEye=n,selectedValues[lastEye]={};let s=!0;var a=getSelectedValues(o,n);a=getSelectedValues(o,n);selectedValues[lastEye]=a;for(const t in a)a.hasOwnProperty(t)&&(s=s&&"null"!=a[t]);s&&onSelectedAllParams()}function initSkuParams(){$("#quantity-right, #quantity-left").change((function(){l=$(this).attr("id").split("-");updateDeliveryMsg("productParam",l[1])})),$("select[id^=productParam-], select[id^=giftParam-]").change((function(){onSkuPropValueChanged($(this).attr("id")),clearErrorTT()}))}function _triggerStockInfoOnLoad(){const t=$("select[id^=productParam-right]").get(0);let e=$(t).attr("id");if(null===t)return;onSkuPropValueChanged(e);const o=$("select[id^=productParam-left]").get(0);null!=o&&(e=$(o).attr("id"),onSkuPropValueChanged(e))}function clearErrorTT(){null!==focused&&($(".vc-detail-add-to-cart").prev(".alert-danger").remove(),$(".vc-product-variants").removeClass("has-feedback has-error"),$(focused).parent(".form-group").removeClass("has-feedback has-error"))}function setQuantityValues(t,e){e=Math.min(QUANTITY_LIMIT,e);const o=$("#quantity-"+t).get(0),n=$("#quantity-"+t).val();if(void 0===o.options)return;if(o.options.length==e+1)return;let s,a;if(o.options.length>e+1)for(var i=o.options.length-1;i>=0;i--)o.options[i].value>e&&(o.options[i]=null);else{x=e-o.options.length+1,s=o.options.length-1;for(i=o.options.length;i<=e;i++){a=new Option(i,i);try{o.add(a,o.options[o.options.length])}catch(t){o.add(a)}}}o.selectedIndex=Math.min(o.options.length-1,n)}function getQuantityForEye(t){const e=$("#quantity-"+t).val();return null!=e?parseInt(e):0}function getQuantity(){const t={total:0,right:0,left:0,useRight:!0,useLeft:!0};return $(".vc-product-options-second-eye").hasClass("hidden")&&0==$("#vc-product-form").hasClass("subscription-edit-item-form")?(t.useLeft=!1,0!==getQuantityForEye("left")&&$("#quantity-left").val(0).change()):(t.useRight=t.useLeft=!1,$("select[id^=productParam-]").each((function(){const e=$(this);"null"===e.val()||e.attr("id").match(/-8$/)||(e.attr("id").indexOf("right")>0?t.useRight=!0:t.useLeft=!0)})),!t.useRight&&t.useLeft&&0!==getQuantityForEye("right")&&$("#quantity-right").val(0).change()),t.right=getQuantityForEye("right"),t.left=getQuantityForEye("left"),t.total=t.right+t.left,t.useRight=t.useRight&&t.right>0,t.useLeft=t.useLeft&&t.left>0,t.useRight||t.useLeft||(t.right>0?t.useRight=!0:t.left>0?t.useLeft=!0:t.useRight=!0),t}function showMissingTT(t){clearErrorTT();let e=SELECT_ALL_PARAMS;$(t).hasClass("vc-js-sunglasses-size-select")&&(e=SELECT_SIZE_PARAM),$(t).hasClass("vc-product-variants-select")&&(t=$(".vc-product-variants-list")),$(t).parent(".form-group").addClass("has-feedback has-error"),$(".vc-detail-add-to-cart").before('<div class="alert alert-danger">'+e+"</div>")}function groupInputsByName(t){return t.reduce((function(t,e){return(t[e.name]=t[e.name]||[]).push(e),t}),{})}function getValidationResult(t){const e={errorType:null,paramObj:null},o=getQuantity();if(0===o.total)return e.errorType="QUANTITY",e;let n=!1;$("select[id^=productParam-]").each((function(){const t=$(this),s=t.attr("id").indexOf("right")>0;"null"===t.val()&&!1===n&&(s?o.useRight:o.useLeft)&&(n=!0,e.errorType="PRODUCT_PARAMS",e.paramObj=this)})),t||$("select[id^=reading-glasses-right-sphere]").each((function(){"null"===$(this).val()&&!1===n&&(n=!0,e.errorType="PRODUCT_PARAMS",e.paramObj=this)}));const s=groupInputsByName(Array.from(document.querySelectorAll("input[type=radio][name^=productParam-]")));return Object.keys(s).forEach((function(t){if(!s[t].some((function(t){return!!t.checked})))return e.errorType="PRODUCT_PARAMS",e.paramObj=$(s[t][0]),e})),e}function validateParams(t,e){const o=getValidationResult($(t.target).hasClass("vc-js-skip-validate-sphere"));return"QUANTITY"===o.errorType?(alert(SELECT_QUANTITY),!1):"PRODUCT_PARAMS"===o.errorType?(focusMissingParam(o.paramObj),!1):void e()}function focusMissingParam(t){$(t).focus(),showMissingTT(t),focused=t}function onSkuPropValueChanged(t){recordSelectedValues(t);const e=t.split("-");$("select[id^=productParam-"+e[1]+"]").each((function(e,o){const n=$(o).attr("id");n!=t&&onSkuSinglePropValueChanged(n)})),updateDeliveryMsg("productParam",e[1])}function onSkuSinglePropValueChanged(t){const e=t.split("-"),o=e[0],n=e[1],s=e[3],a="left"===n?"right":"left";if(skuStockInfo.stockLiveConnect){let o=selectedValues[n][s],i=getValidParams(n,selectedValues,o,s);if(8==s){const t=getValidParams(a,selectedValues,o,s);i=intersect_safe(i.sort(),t.sort())}if(updateSelectbox(i,t,n,s,o),8==s){const t=e.slice();t[1]=a;const n=t.join("-"),r=$("#"+n);r.closest(".vc-product-options-items").is(":visible")&&(void 0!==o&&"null"!==o||(o=selectedValues[a][s]||r.val()),updateSelectbox(i,n,a,s,o))}}updateDeliveryMsg(o,n)}function getValidParams(t,e,o,n){const s=skuStockInfo.availableSkuPropValueCombinations.filter((function(o,s,a){for(const s in e[t])if(n!=s&&"null"!=e[t][s]&&o[s]!=e[t][s])return!1;return!0})),a={};for(let t=0;t<s.length;++t){const e=s[t];for(const t in e){void 0===a[t]&&(a[t]=[e[t]]);let o=!1;for(const n in a[t])a[t][n]==e[t]&&(o=!0);o||a[t].push(e[t])}}const i=a[n];switch(parseInt(n)){case 1:return i.sort((function(t,e){return parseFloat(t)-parseFloat(e)}));case 6:var r=["High","Medium","Low"];return i.sort((function(t,e){return r.indexOf(t)-r.indexOf(e)}));default:return i}}function updateSelectbox(t,e,o,n,s){const a=$("select#"+e);let i=a.get(0);for(var r=i.options.length-1;r>=0;r--)"null"!=i.options[r].value&&(i.options[r]=null);i=a.get(0);let c=0;if(r=0,t){if(-1!=t.indexOf("180")){r++;const t=new Option("0°",180);try{i.add(t,i.options[i.options.length])}catch(e){i.add(t)}}}else t=[];t.sort((function(t,e){return t-e}));for(let e=0;e<t.length;e++){const o=t[e],a=n+";"+o,l=skuStockInfo.frmParams[a];r++;const u=new Option(l,o);try{i.add(u,i.options[i.options.length])}catch(t){i.add(u)}s==o&&(c=r)}if(8==n){$(".vc-product-variants-item").hide();for(r=0;r<t.length;++r)$('.vc-product-variants-item[data-value="'+t[r]+'"]').show()}const l=a.siblings(".vc-js-custom-select");if(void 0!==l&&l.length>0){const t=l.find(".vc-select-options-part");l.find(".vc-select-options-item").each((function(t,e){e.remove()}));const e=document.createElement("span");e.classList.add("vc-select-options-item"),e.setAttribute("role","option");const o=e.cloneNode(!0);o.dataset.value="null",o.innerHTML="---",t[0].prepend(o.cloneNode(!0)),t[1].append(o);const n=e.cloneNode(!0);n.dataset.value="0",n.innerHTML="&plusmn;0.00",[].reverse.call(a.children()).each((function(o,s){const a=parseFloat(s.value,10);if(Number.isNaN(a)||a>0)return;const i=e.cloneNode(!0);i.dataset.value=a,i.textContent=a.toFixed(2),0===a?t[0].prepend(n.cloneNode(!0)):t[0].prepend(i)})),a.children().each((function(o,s){const a=parseFloat(s.value,10);if(Number.isNaN(a)||a<0)return;const i=e.cloneNode(!0);i.dataset.value=a,i.innerHTML="+"+a.toFixed(2),0===a?t[1].append(n.cloneNode(!0)):t[1].append(i)}))}i.selectedIndex=c}function intersect_safe(t,e){let o=0,n=0;const s=[];for(;o<t.length&&n<e.length;)t[o]<e[n]?o++:(t[o]>e[n]||(s.push(t[o]),o++),n++);return s}function getSelectedValues(t,e){const o={},n=skuStockInfo.skuPropValueEffectiveStockUnitsMap.keyBuilder.requiredSkuPropIds;for(let s=0;s<n.length;s++){const a=n[s],i="#"+t+"-"+e+"-"+skuStockInfo.defaultGoodId+"-"+a;o[a]=$(i).val()}return o}function isProductGlasses(){return 20===skuStockInfo.propTypeId||36===skuStockInfo.propTypeId||41===skuStockInfo.propTypeId||42===skuStockInfo.propTypeId}function updateDeliveryMsg(t,e){if(isProductGlasses())return;let o=$("#quantity-"+e).val(),n=0;0===o&&(o=1);let s,a=null;const i=getSelectedValues(t,e);for(const t in i)if(i.hasOwnProperty(t)&&"null"==i[t])return void setQuantityValues(e,QUANTITY_LIMIT);const r=buildSkuPropValueKey(i);if(0===skuStockInfo.skuPropValuesCount&&null!==skuStockInfo.storeInfo.defaultWhId&&!1===skuStockInfo.storeInfo.stores[skuStockInfo.storeInfo.defaultWhId].split_orders&&(s=getWhEffectiveStockUnits(r,skuStockInfo.storeInfo.defaultWhId),n=Math.abs(Math.min(0,s-o)),0===n&&(a=skuStockInfo.storeInfo.deliveryOnStockArray[skuStockInfo.storeInfo.defaultWhId])),a)return void setAvail(t,e,a);const c=getEffectiveStockUnits(r);let l;skuStockInfo.allowBuyOnlyOnStockSkus||!0===skuStockInfo.skusUnavailableForSupplyOrder[r]?(l=c,o>c&&(o=c,$("#quantity-"+e).val(c)),freeProduct&&(l=1),setQuantityValues(e,Math.min(l,QUANTITY_LIMIT))):setQuantityValues(e,QUANTITY_LIMIT),skuStockInfo.storeInfo.defaultWhId&&!1===skuStockInfo.storeInfo.stores[skuStockInfo.storeInfo.defaultWhId].split_orders&&getWhEffectiveStockUnits(r,skuStockInfo.storeInfo.defaultWhId)>=o?a=skuStockInfo.storeInfo.deliveryOnStockArray[skuStockInfo.storeInfo.defaultWhId]:(n=Math.abs(Math.min(0,c-o)),a=getFormattedStockMsg(skuStockInfo,n,c,!1));for(const t in skuStockInfo.storeInfo.stores){if(!skuStockInfo.storeInfo.stores.hasOwnProperty(t))continue;const e=getWhEffectiveStockUnits(r,t);if(e>=o&&e>0&&skuStockInfo.storeInfo.deliveryOnStockArray[t]&&skuStockInfo.storeInfo.stores[t].has_pick_up){a+=availability_options_seperator+skuStockInfo.storeInfo.deliveryOnStockArray[t];break}}setAvail(t,e,a)}function setAvail(t,e,o){$("#aval-"+t+"-"+e).html(o)}function getFormattedStockMsg(t,e,o,n){if(n)return t.defaultDeliveryMsg;if(0===e)return t.deliveryOnStock;if(o<=0)return t.deliveryNotOnStock;let s=t.deliveryPartlyOnStock;return s=s.replace("{effectiveStockUnits}",o),s=s.replace("{missing}",e),s}function handleQuantityChange(t){const e=parseInt($(this).val()),o=$("select[id^=productParam-"+t.data+"-]");0===e?(o.not("[id$=-8]").val("null"),o.attr("disabled",!0),o.parent(".form-group").hasClass("has-error")&&clearErrorTT()):o.attr("disabled",!1)}"undefined"==typeof QUANTITY_LIMIT&&(QUANTITY_LIMIT=10),window.addEventListener("load",(function(){const t=document.querySelector(".vc-detail-image-additional.glider");t&&new Glider(t,{slidesToShow:3,slidesToScroll:1,duration:3,draggable:!0,scrollLock:!1,dots:".vc-detail-image-additional-dots",skipTrack:!1,responsive:[{breakpoint:440,settings:{slidesToShow:4}},{breakpoint:768,settings:{slidesToShow:2}}]});var e=document.getElementById("vc-js-video-container");e&&setupVideo(e)})),$((function(){$("body").on("click",".vc-js-add-to-cart-btn:not(.dropdown-toggle)",(function(t){return validateParams(t,(function(){addToCartEvent()}))}));let t=null;$("#vc-product-form.ajax").on("submit",(function(e){if(void 0!==e.originalEvent.submitter&&$(e.originalEvent.submitter).hasClass("vc-js-skip-ajax"))return!0;toggleBusyIndicator("show");const o=$(this).serializeArray();return o.push({name:"ajax",value:!0}),$.ajax({type:"POST",url:$(this).attr("action"),data:o,dataType:"json",encode:!0}).done((function(e){e.success?($html=$(e.html),$("body").append($html),t=$html.filter(".modal"),t.on("show.bs.modal",(function(t){})).on("hidden.bs.modal",(function(t){return $(this).remove(),$(".modal-backdrop").remove(),!0})).modal(),$("#vc-nav-cart").replaceWith(e.cart),void 0!==e.trackEvent&&null!==e.trackEvent&&trackEvent(e.trackEvent.category,e.trackEvent.action,e.trackEvent.label,e.trackEvent.value)):e.redirectUrl&&(window.location=e.redirectUrl),toggleBusyIndicator("hide")})).fail((function(t){toggleBusyIndicator("hide"),window.location.reload()})),!1})),$(document).on("click",".vc-js-add-box",(function(t){toggleBusyIndicator("show",$(".vc-cart-substep-item"));const e=$(this).data("scitemid"),o=$(this).data("quantity");$(this).data("label-success");$.ajax({type:"POST",url:baseUrl("/shopping-cart/update-quantity"),data:{scItemId:e,quantity:o},dataType:"json",encode:!0}).done((function(t){t.reload?window.location=$(".vc-btn--icon-goto-next").attr("href"):($(".vc-js-quantity-"+e).html(o),$(".vc-js-add-box").fadeOut(500),$("#scMATop").html(t.scMonetaryInfo.finalMAFrm)),toggleBusyIndicator("hide")})).fail((function(t){toggleBusyIndicator("hide")})),t.preventDefault()})),$(document).on("click",".vc-recommended-product.ajax",(function(e){toggleBusyIndicator("show",$(this)),t&&(t.remove(),$(".modal-backdrop").remove()),$("#vc-cart-substep").remove(),$.ajax({type:"GET",url:$(this).attr("href"),dataType:"json",encode:!0}).done((function(e){e.success?($html=$(e.html),$("body").append($html),t=$html.filter(".modal"),t.on("show.bs.modal",(function(t){})).on("hidden.bs.modal",(function(t){$(this).remove(),$(".modal-backdrop").remove()})).modal(),$("#vc-nav-cart").replaceWith(e.cart),void 0!==e.trackEvent&&null!==e.trackEvent&&trackEvent(e.trackEvent.category,e.trackEvent.action,e.trackEvent.label,e.trackEvent.value)):e.redirectUrl&&(window.location=e.redirectUrl),toggleBusyIndicator("hide")})).fail((function(t){toggleBusyIndicator("hide"),window.location.reload()})),e.preventDefault()}));const e=$("#paramsModal");$("a.vc-js-help-box").click((function(t){t.preventDefault();const o=$(this).attr("href");o.length>1?e.find('a[href="'+o+'"]').tab("show"):e.find("a").first().tab("show"),e.modal(),trackEvent("Product detail","Help-box click",productId)})),$("a[class^=showStockInfo]").click((function(){return!1})),$("a[class^=showStockInfo]").hover((function(){const t=$(this).attr("href");$(".vc-bubble-stockinfo .vc-matrjoska").load(t),$(".vc-bubble-stockinfo").show()}),(function(){$(".vc-bubble-stockinfo").hide()})),triggerStockInfoOnLoad&&_triggerStockInfoOnLoad(),initSkuParams();let o=location.hash;if(o){o=decodeURIComponent(o.substring(1));const t=o.split("&");o=t[t.length-1].replace();const e=skuStockInfo.defaultGoodId,s=o.split(";");for(const t in s)if(s[t].includes(":")){data=s[t].split(":");const o=data[0];var n=data[1];id="productParam-right-"+e+"-"+o,$("select[id="+id+"] option").filter((function(){return $(this).text()==n})).prop("selected",!0),onSkuPropValueChanged(id)}}const s=$(".vc-product-options");s.find(".vc-product-options-second-eye .vc-product-variants-select").hide().after('<p class="form-control-static"></p>').end().each((function(){setOptionVariant($(this))})).on("click",".vc-product-variants-item",(function(){let t=$(this).data("value");$(this).hasClass("active")&&(t="null"),setOptionVariant(s,t)})).find(".vc-product-options-first-eye .vc-product-variants-select").on("change",(function(){setOptionVariant(s)})),$("#quantity-right").change("right",handleQuantityChange).change(),$("#quantity-left").change("left",handleQuantityChange).change()}));const glassesDetail=document.getElementsByClassName("vc-js-product-detail-glasses");if(glassesDetail.length){var slideIndex=1;showSlides(slideIndex)}function currentSlide(t){showSlides(slideIndex=t)}function showSlides(t){let e,o=1;const n=document.getElementsByClassName("vc-detail-image-older-link"),s=document.getElementsByClassName("vc-detail-image-thumbnail");for(t>n.length&&(slideIndex=1),t<1&&(slideIndex=n.length),e=0;e<s.length;e++)s[e].setAttribute("onClick","currentSlide("+o+++")");for(e=0;e<n.length;e++)n[e].classList.remove("vc-is-active");for(e=0;e<s.length;e++)s[e].className=s[e].className.replace(" vc-is-active","");n[slideIndex-1].classList.add("vc-is-active"),s[slideIndex-1].className+=" vc-is-active"}function setupVideo(t){var e=t.querySelector("a"),o=t.querySelector(".vc-js-video-play"),n=e.dataset.src;t.addEventListener("click",(function(){var s=createIframe(n);e.remove(),o.remove(),t.appendChild(s)})),e.removeAttribute("href"),t.classList.add("embed-responsive","embed-responsive-16by9")}function createIframe(t){var e=document.createElement("iframe");return e.setAttribute("allowfullscreen",""),e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"),e.setAttribute("src",generateURL(t)),e.classList.add("embed-responsive-item"),e}function generateURL(t){return"https://www.youtube.com/embed/"+t+"?rel=0&showinfo=0&autoplay=1"}$("#vcColorsLink").on("click",(function(t){$('a[href="#colors"]').tab("show")})),$(".vc-js-glasses-color-variants-data").qtip({content:{text:function(){return $(this).data("tooltip")}},position:{my:"top center",at:"bottom center",adjust:{x:0,y:10},viewport:$(window)},style:{classes:"vc-glasses-color-variants-bubble",tip:{corner:!0}}});const colorVariantsContainer=document.querySelector(".vc-js-glasses-color-variants-list");if(null!==colorVariantsContainer){const t=window.matchMedia("(min-width: 768px)");t.matches&&document.addEventListener("DOMContentLoaded",(function(){const t=colorVariantsContainer.querySelector(".vc-js-glasses-color-variants-more"),e=colorVariantsContainer.firstElementChild;e&&e.classList.add("vc-is-selected"),null!==t&&t.addEventListener("click",(function(){event.preventDefault(),colorVariantsContainer.classList.add("vc-show-all"),t.style.display="none"}))})),t.matches||new Glider(colorVariantsContainer,{slidesToShow:3.5,slidesToScroll:1,duration:3,draggable:!0,scrollLock:!1,skipTrack:!1,responsive:[{breakpoint:440,settings:{slidesToShow:5.5}}]})}