(function () { var take = function () { console.log("Locca Chatform Widget") window.AqurBaseURL = 'https://pr.aqur.com'; window.addEventListener("chatform_initialized", async () => { localStorage.removeItem("loccaLoadingDisabled"); createAqurBinding() }); function render(template, data) { return template.replace(/{{(.*?)}}/g, (match) => { return data[match.split(/{{|}}/).filter(Boolean)[0].trim()] }) } function activateChatformWidget() { if (!chatform_initialized) { console.log("Aqur is not ready") return } const w = document.querySelector('.chatform_widget'); w.classList.toggle("close"); if (w.classList.contains("close")) { document.body.classList.remove("chat_open"); } else { document.body.classList.add("chat_open"); } } var chatform_initialized = false const pid = "locca"; const target = "production"; const mode = "release"; const device = JSON.parse("false".toLowerCase()) ? "mobile" : "pc"; var launch = "click"; const client = "https://form.aqur.com/"; let REF = new URL(window.location); let userChatbot = REF.searchParams.get('usechatbot') if (userChatbot == "no") { console.log("no chatbot") return } REF.searchParams.append('pid', pid); REF.searchParams.append('mode', mode); REF.searchParams.append('target', target); REF.searchParams.append('hash', "3e413aa1-578f-4bb2-b95a-d6a3be8a0366"); REF.searchParams.append('browser', "undefined"); REF.searchParams.append('device', device); REF.searchParams.append('os', "undefined"); REF.searchParams.append('ua', "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"); REF.searchParams.append('ip', "216.73.217.85"); REF.searchParams.append('ref', REF.href); REF.searchParams.append('path', REF.pathname); //for UI REF.searchParams.append('CLIENT_ID', 'PR'); REF.searchParams.append('BASE_URL', 'https://pr.aqur.com'); REF.searchParams.append('HEADER_LABEL', ''); REF.searchParams.append('HEADER_BG_COLOR', '#fff'); REF.searchParams.append('HEADER_LABEL_COLOR', '#fff'); REF.searchParams.append('SHOW_TIMER', 'false'); REF.searchParams.append('ICON_PATH', 'https://res.cloudinary.com/dts6mbw86/image/upload/v1713319985/aqur/common/icon_azvikf.png'); const params = new URLSearchParams(REF.search.slice(1)); let search = REF.search.slice(1) //console.log(search) launch = params.get('launch'); let widget = render( '' + '', { device: device, client: client, search: (search) ? "&" + search : "", } ); const body = document.body; if (body) { var filterid = undefined; const chatbotProgressBar = "
" body.insertAdjacentHTML('beforeend', chatbotProgressBar); body.insertAdjacentHTML('beforeend', widget); const target = document.querySelector('.chatform_widget'); const observer = new MutationObserver((mutations) => { mutations.forEach(() => { if (!target.classList.contains("close")) { var contentWindow = target.contentWindow; if (contentWindow) { contentWindow.postMessage("chat_open", "*"); contentWindow.postMessage( { type: "filterIdChanged", data: filterid }, "*"); } } }); }); const config = { characterData: true, attributes: true, subtree: true }; observer.observe(target, config); } let creationComplete = function () { if (device == "pc") { var resize = () => { let zoom_level = window.devicePixelRatio || window.screen.availWidth / document.documentElement.clientWidth * 100; const targets = document.querySelectorAll('body,.chatform_widget'); if (zoom_level >= 3) { targets[0].classList.add("mobile") targets[0].classList.remove("pc") targets[1].classList.add("mobile") targets[1].classList.remove("pc") } else { targets[0].classList.add("pc") targets[0].classList.remove("mobile") targets[1].classList.add("pc") targets[1].classList.remove("mobile") } } resize() window.addEventListener("resize", () => { resize() }) } document.addEventListener('click', (event) => { if (event.target && event.target.closest('.chatformBtn') || event.target.classList.contains("chatformBtn") || event.target.closest('.cdhsbtn980') || event.target.classList.contains("cdhsbtn980") || event.target.closest('.cdhsbtn1870') || event.target.classList.contains("cdhsbtn1870") || event.target.id == "chatform_widget_cancelbtn" ) { activateChatformWidget() } }); document.dispatchEvent(new CustomEvent("chatform_widget_creation_complete")); }; setTimeout(creationComplete, 250); window.addEventListener("message", async (event) => { if(event.data.event == "redirect_thankPage"){ //console.log("redirect_chatform", event.data.event) const target = document.querySelector('.chatform_widget'); var param={ event: "chatform_clear" } target.contentWindow.postMessage(param, "*"); let redirect = function(){ window.location.href= event.data.url } setTimeout(redirect, 500); } if (event.data.event == "chatform_close") { activateChatformWidget(); } if (event.data.event == "chatform_evalScript") { window.eval(event.data.script) } if (event.data.event == "chatform_insertTag") { body.insertAdjacentHTML("beforeend", event.data.tag); event.data.scripts.forEach((item) => { eval(item.textContent) }) } if (event.data.event == "chatform_initialized") { console.log("Aqur Initialized") document.getElementById("chatbotProgressBar").style.width = "100%"; var opacity = function () { document.getElementById("chatbotProgressBar").style.opacity = "0"; }; setTimeout(opacity, 1000); chatform_initialized = true; if (launch == "auto") { activateChatformWidget(); } window.dispatchEvent(new CustomEvent("chatform_initialized")); } if (event.data.event == "chatform_sent") { //console.log("chatform_sent") var project = event.data.project; var arr = project.data; var chatform = { pid: project.pid, sid: project.sid, uuId: project.uuId, customId: "conversion", data: arr, // Store full form data array agreement2: event.data.agreement2, agreement3: event.data.agreement3 } // Store full chatform data in localStorage (DDP Version 1) localStorage.setItem('chatform-locca', JSON.stringify(chatform)); if (!window.aqur) window.aqur = {}; window.aqur.chatformData = arr; window.aqur.agreement2 = event.data.agreement2; window.aqur.agreement3 = event.data.agreement3; // bindandSubmit(arr) // Extract production parameters from current URL var currentUrl = new URL(window.location.href); var productionParams = new URLSearchParams(currentUrl.search); var redirectUrl = "https://locca.premium-water.net/landing/server/code/lp_07"; // Add production parameters if (productionParams.toString()) { redirectUrl += "?" + productionParams.toString(); } window.location.href = redirectUrl; } if (window.aqur) { window.aqur.bind(event) } }, false) } setTimeout(take, 0); }()) function createAqurBinding() { //console.log("AqurBindingCreated") //aqur bind start if (!window.aqur) window.aqur = {} window.aqur.debug = true; window.aqur.save = (key, value) => { window.aqur[key] = value; } window.aqur.reset = async () => { console.log("reset") } window.aqur.bind = (event) => { if (event.data.track) { var track = { pid: event.data.track.pid, sid: event.data.track.sid, uuId: event.data.track.uuId, customId: "conversion" } window.aqur.setTrack(track); window.aqur.save("Track", track); } } window.aqur.setTrack = (value) => { window.aqur.debug && console.log("debug setTrack"); localStorage.setItem('chatform', JSON.stringify(value)); } //Helper Method window.aqur.getCheckedOptionSA = (options) => { var rtn = options.find((v) => v.checked) return rtn } window.aqur.getCheckedOptionMA = (options) => { var checkedOptions = options.filter((v) => v.checked); var rtn = checkedOptions.map((v) => v.value); return rtn.join(", "); } } window.ChatFormWidgetHide = function () { console.log("ChatFormWidgetHide"); if (localStorage.getItem("chatform")) { // Trigger a general click (if needed) document.body.click(); const widget = document.querySelector('.chatform_widget'); if (!widget || !widget.contentWindow) { console.warn("Chat widget not available."); return; } const param = { event: "chatform_BeforeSubmit" }; widget.contentWindow.postMessage(param, "*"); widget.classList.toggle("close"); if (widget.classList.contains("close")) { document.body.classList.remove("chat_open"); } } }; window.ScrollFormtoSubmit = function () { const viewForm = document.querySelector('#order_billing_address_attributes_name1'); if (!viewForm) { console.warn("#order_billing_address_attributes_name1 not found on the page."); return; } const isAndroid = /Android/i.test(navigator.userAgent); if (isAndroid) { // Direct hash jump for Android window.location.hash = "#order_billing_address_attributes_name1"; const viewFormPosition = viewForm.getBoundingClientRect().top + window.pageYOffset - 100; window.scrollTo({ top: viewFormPosition, behavior: 'smooth' }); } else { // Smooth scroll for non-Android devices requestAnimationFrame(() => { viewForm.scrollIntoView({ behavior: 'smooth', block: 'start' }); }); } };