var $document = $(document); function getGA4ClientId() { try { const cookies = document.cookie.split(';'); let gaCookie = null; for (let i = 0; i < cookies.length; i++) { let cookie = cookies[i].trim(); if (cookie.startsWith('_ga=')) { gaCookie = cookie; break; } } if (gaCookie) { // Extract the value after '_ga=' const gaValue = gaCookie.substring(4); // Split the value and take the last two parts which form the Client ID const parts = gaValue.split('.'); if (parts.length >= 4) { return parts[2] + '.' + parts[3]; } } } catch (ex) { console.log('Error extracting GA4 Client ID:', ex); } return null; // Return null if _ga cookie or Client ID is not found } $(function () { try { var date = new Date(); date.setTime(date.getTime() + (30 * 60 * 1000)); const clientId = getGA4ClientId(); $.cookie("ga_client_id", clientId, { expires: date, samesite: "None", secure: true }); } catch (ex) { console.log(ex); } //Handle gclid param -> if exist save in cookie session HandleGclidParam(); $(".ShowAllWords").click(function () { $(".Dictionary .WordsList").height("auto"); $(this).hide(); }); if ($(".Dictionary .WordsList .WordColumn .WordRow").length > 6) { $(".ShowAllWords").show(); } else $(".ShowAllWords").hide(); $document.on("click", "[data-encoded-href]", function (event) { event.preventDefault(); event.stopPropagation(); var href = b64DecodeUnicode($(this).data("encoded-href")); window.location = href; }); $document.on("click", "[data-href]", function (event) { var href = $(this).data("href"); window.location = href; }); $document.mouseup(function (e) { var container = $(".InfoTooltip"); if ($(container).is(':visible')) { if (!container.is(e.target) // if the target of the click isn't the container... && container.has(e.target).length === 0) // ... nor a descendant of the container { container.hide(); } } }); if ($(".BackToTopLink").length > 0) { $(window).scroll(function () { if ($(window).scrollTop() > 500) { $(".BackToTopLink").fadeIn(); } else { $(".BackToTopLink").fadeOut(); } }); initSmoothScroll(); } SetMilonPopup(); $(window).resize(function () { ShowHideTower(); }); $(".ToMobile").click(function (e) { e.preventDefault(); SetMobileCookie("1", ""); location.reload(); }); var $checkbox = $("[data-id='personal-privacy']"); $checkbox.on("change", function () { var $this = $(this); var $myForm = $this.closest("form"); var $submitBtn = $myForm.find("[type='submit']"); var personalPrivacyErrorText = $myForm.find('.personalPrivacyErrorText'); if ($this.is(":checked")) { $submitBtn.prop("disabled", false); personalPrivacyErrorText.html(""); } else { $submitBtn.prop("disabled", true); personalPrivacyErrorText.html("נא לסמן תיבה זו כדי להמשיך"); } }); $("[data-rule='mailingListForm']").submit(function (e) { var $myForm = $(this); if ($myForm[0].checkValidity()) { e.preventDefault(); var $this = $myForm.find("[data-rule='btnMailingList']"); $myForm.find('[data-rule="registrationLoader"]').show(); var email = $myForm.find("[data-rule='email']").val(); var ext1 = $this.data().ext1; var ext2 = $this.data().ext2; var ext3 = $this.data().ext3; var ext4 = $this.data().ext4; var fullName = ''; var parent = $this.closest(".mailingList"); var mailingListText = parent.find('.mailingListText'); var chkPersonalPrivacy = $myForm.find("[data-id='personal-privacy']"); if (chkPersonalPrivacy.length == 0 || !chkPersonalPrivacy.is(":checked")) { var personalPrivacyErrorText = parent.find('.personalPrivacyErrorText'); personalPrivacyErrorText.html("נא לסמן תיבה זו כדי להמשיך"); $('[data-rule="registrationLoader"]').hide(); return false; } var data = {}; data.fullname = fullName; data.email = email; data.ext1 = ext1; data.ext2 = ext2; data.ext3 = ext3; data.ext4 = ext4; grecaptcha.ready(function () { // do request for recaptcha token // response is promise with passed token grecaptcha.execute(reCaptchaSiteKey, { action: 'homepage' }).then(function (token) { console.log('captcha had been executed!'); // add token to form var hdnToken = $("[name='g-recaptcha-response']"); if (hdnToken.length == 0) { $('#mailingListForm').prepend(''); } else { hdnToken.val(token); } data.token = token; $.ajax({ url: wisebuyUrl + '/api/activetrail/registration', type: 'POST', data: JSON.stringify(data), contentType: "application/json", success: function (data) { if (data == "Success") { mailingListText.html("הרשמתך בוצעה בהצלחה!"); fixStyle(); gaTrack.sendEvent('register', 'success', 'success'); } else if (data == "Email") { mailingListText.html("חובה להזין כתובת מייל תקינה."); gaTrack.sendEvent('register', 'falied', 'invalid'); } else { mailingListText.html("אירעה שגיאה בעת הרשמתך."); fixStyle(); gaTrack.sendEvent('register', 'failed', 'error'); } }, error: function (x, y, z) { mailingListText.html("אירעה שגיאה בעת הרשמתך."); fixStyle(); gaTrack.sendEvent('register', 'failed', 'error'); }, complete: function () { parent.find(".titleMailing").hide(); parent.find(".mailingListInput").hide(); parent.find(".ApprovalDiv").hide(); } }); }); }); //string fullName, string email, string ext1, string ext2, string ext3, string ext4 } else { gaTrack.sendEvent('register', 'falied', 'invalid'); } ShowHideTower(); }); function fixStyle() { $('[data-rule="mailingListForm"]').css('text-align', 'center'); $('.mailingList').css('padding-bottom', '15px'); $('[data-rule="registrationLoader"]').hide(); } }); $(function () { $('.TowerBannerRight').each(function (i, obj) { const observer = new MutationObserver(function (mutationsList) { // You can filter mutations here if needed ShowHideTower(); }); observer.observe(obj, { childList: true, // detect added/removed child elements subtree: true, // watch inside descendants too characterData: true, // detect text content changes attributes: true // detect attribute changes }); }); }); function ShowHideTower() { if (($(window).width() < ($(".TowerBannerRight > div > div > iframe").width() * 2) + $(".WiseBuy").width())) { $(".TowerBannerRight").hide(); } else { $(".TowerBannerRight").show(); } if ($(window).width() < ($(".TowerBanner > div > div > iframe").width() * 2) + $(".WiseBuy").width()) { $(".TowerBanner").hide(); } else { $(".TowerBanner").show(); } } function SetMilonPopup() { $(".MilonLink").click(function () { var milonId = $(this).data("id"); //$("#milon_" + milonId).show(); var _top, _left; _top = $(this).offset().top - 28; _left = $(this).offset().left - 260; var helpTitle = $(this).text(); var helpBody = $("#milon_" + milonId).html();//.text(); ShowToolTip(".InfoTooltip", helpTitle, helpBody, _top, _left); return false; }); } function ShowToolTip(TooltipSelector, title, Body, Top, Left) { var ToolTipDiv = $(TooltipSelector); var ToolTipTitle = $(ToolTipDiv).find(".TooltipTitle").text(title); var ToolTipBody = $(ToolTipDiv).find(".TooltipTxt").html(Body); ToolTipDiv.toggle(); ToolTipDiv.offset({ top: Top, left: Left }); } function CloseTooltip(fld) { $(fld).parent().parent().hide(); } function GetQueryParam(variable) { variable = variable.toLowerCase(); var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair[0].toLowerCase() == variable) { return pair[1]; } } return ''; } function checkSearchStr() { var $keyword = $("#keyword"); var keywordText = $keyword.data("keyword") != undefined ? $keyword.data("keyword").trim().toLowerCase() : ""; if (keywordText == null || keywordText == '' || keywordText == 'חיפוש מוצר, מדריך או סקירה') { alert("אנא הכנס ערך לחיפוש"); $keyword.val(""); $keyword.focus(); return false; } if (AutoComplete.isValidCharactersIndexOfAutoComplete(keywordText)) { $(".submitSearch").attr('disabled', 'disabled'); var url = '/search.aspx?keyword=' + escape(keywordText); AutoComplete.SetCookieAndRedirect(keywordText, url); } return false; } function initSmoothScroll() { try { smoothScroll.init({ speed: 1000, easing: 'easeInOutCubic', offset: 0, updateURL: true, callbackBefore: function (toggle, anchor) { }, callbackAfter: function (toggle, anchor) { } }); } catch (e) { } } function SetMobileCookie(value, url) { $.cookie('mobileWB', value, { path: '/', expires: 2, domain: 'wisebuy.co.il', samesite: "None", secure: true }); if (url != "") { window.location.href = url; } } function HandleGclidParam() { var gclidValue = GetQueryParam('gclid'); if (gclidValue != '' && !jQuery.cookie('gclidParam')) { $.cookie('gclidParam', 'true', { samesite: "None", secure: true }); } } function writeClientLog(errorTxt) { console.log(errorTxt); } try { if (document.characterSet.toLowerCase() != "utf-8") { writeClientLog('Charset : ' + document.characterSet); if (IsReloadPage()) { location.href = location.href; } } } catch (ex) { console.log(ex + " Charset Function Failed"); } function IsReloadPage() { var reloadCnt = []; var storageName = "reloadCnt"; if (sessionStorage.getItem(storageName) != null) { reloadCnt = JSON.parse(sessionStorage.getItem(storageName)); } var modelId = GetQueryParam("productid"); if (modelId > 0) { var modelExist = false; for (var i = 0; i < reloadCnt.length; i++) { if (modelId == reloadCnt[i].modelId) { modelExist = true; reloadCnt[i].counter++; if (reloadCnt[i].lastUpdate + 60000 < new Date().getTime()) { reloadCnt[i].counter = 1; reloadCnt[i].lastUpdate = new Date().getTime(); sessionStorage.setItem(storageName, JSON.stringify(reloadCnt)); return true; } else if (reloadCnt[i].counter == 2) { writeClientLog('Second Time Charset Error - Charset : ' + document.characterSet); } sessionStorage.setItem(storageName, JSON.stringify(reloadCnt)); } } if (!modelExist) { reloadCnt.push({ lastUpdate: new Date().getTime(), modelId: GetQueryParam("productid"), counter: 1 }); sessionStorage.setItem(storageName, JSON.stringify(reloadCnt)); return true; } } return false; } function b64DecodeUnicode(str) { // Going backwards: from bytestream, to percent-encoding, to original string. return decodeURIComponent(atob(str).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); } if (!isIframe) { const SCRIPT_LOAD_DELAY = 3000; // delay in milliseconds runWhenIdle(() => { try { const s = document.createElement("script"); s.src = "https://img.zapgroup.co.il/policy/blocker-new/loader.js?v=" + Date.now(); s.type = "text/javascript"; s.async = true; s.onerror = () => console.error("Failed to load privacy script"); (document.body || document.head).appendChild(s); } catch (err) { console.error("Error while injecting privacy script:", err); } }, SCRIPT_LOAD_DELAY); } function runWhenIdle(callback, timeout = 0) { if ('requestIdleCallback' in window) { requestIdleCallback(callback); } else { setTimeout(callback, timeout); } }