// GET STARTED IFRAME SUPPORT CODE jQuery(document).ready(function() { getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; }; // Get Devie Type var getDeviceType = () => { var ua = navigator.userAgent; if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) { return "Mobile"; } if ( /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test( ua ) ) { return "Mobile"; } return "Desktop"; }; getUrlParameter('referralCode') == '' || getUrlParameter('referralCode') == null || getUrlParameter('referralCode') == false ? $('#referral_code').val() : $('#referral_code').val(getUrlParameter('referralCode')); getUrlParameter('promoCode') == '' || getUrlParameter('promoCode') == null || getUrlParameter('promoCode') == false ? $('#promo_code').val() : $('#promo_code').val(getUrlParameter('promoCode')); if (getUrlParameter('pub') != '' && getUrlParameter('pub') != null && getUrlParameter('pub') != false) { sourceCode = getUrlParameter('pub'); } else if (getUrlParameter('sourceCode') != '' && getUrlParameter('sourceCode') != null && getUrlParameter('sourceCode') != false) { sourceCode = getUrlParameter('sourceCode'); } else { sourceCode = 'DGMEDUNKNFMT00015872'; } // Wait for page to load to make sure that nothing else enables submit button setTimeout(() => { $('#im-ready').prop("disabled", true); $('#im-ready').css({ 'opacity': '0.5' }); var hcuid = ''; var localData = JSON.parse(window.localStorage.getItem('hcUser')); if (localData != null) { if (localData['user'].hcuid != "undefined") { hcuid = localData['user'].hcuid; } if (localData['user'].gcid != "undefined") { gcid = localData['user'].gcid; } if (localData['user'].msclkid != "undefined") { msclkid = localData['user'].msclkid; } if (localData['user'].fbclid != "undefined") { fbclid = localData['user'].fbclid; } if (localData['user'].kuid != "null") { kuid = localData['user'].kuid; } } var gclid = getUrlParameter('gclid') == '' || getUrlParameter('gclid') == null || getUrlParameter('gclid') == false ? '' : getUrlParameter('gclid'); var msclkid = getUrlParameter('msclkid') == '' || getUrlParameter('msclkid') == null || getUrlParameter('msclkid') == false ? '' : getUrlParameter('msclkid'); var fbclid = getUrlParameter('fbclid') == '' || getUrlParameter('fbclid') == null || getUrlParameter('fbclid') == false ? '' : getUrlParameter('fbclid'); var kuid = getUrlParameter('kuid') == '' || getUrlParameter('kuid') == null || getUrlParameter('kuid') == false ? '' : getUrlParameter('kuid'); // var hcuid = getUrlParameter('hcuid') == '' || getUrlParameter('hcuid') == null || getUrlParameter('hcuid') == false ? '' : getUrlParameter('hcuid'); var googleClientId = ga.getAll()[0].get('clientId'); var deviceType = getDeviceType(); // var referralCode = getUrlParameter('referralCode') == '' || getUrlParameter('referralCode') == null || getUrlParameter('referralCode') == false ? $('#referral_code').val() : 'getUrlParameter('referralCode')'; var referralCode = ''; //if (getUrlParameter('referralCode') == '' || getUrlParameter('referralCode') == null || getUrlParameter('referralCode') == false || getUrlParameter('referralCode') == undefined) { if ($('#referral_code').val() == undefined || $('#referral_code').val() == null ) { referralCode = ''; } else { referralCode = $('#referral_code').val(); } // } else {referralCode = ''}; var campaignId = getUrlParameter('campaign') == '' || getUrlParameter('campaign') == null || getUrlParameter('campaign') == false ? '7017V000001gKScQAM' : getUrlParameter('campaign'); var zipcode = getUrlParameter('zip-code') == '' || getUrlParameter('zip-code') == null || getUrlParameter('zip-code') == false ? '' : getUrlParameter('zip-code'); var promocode = $('#promo_code').val(); $(document).on('change', '#referral_code', function() { referralCode = $(this).val(); }); if ((window.location.href.indexOf("perkopolis") > -1) || (window.location.href.indexOf("boca-kiosk-landing-page") > -1) || (window.location.href.indexOf("msgn-ny20") > -1) || (window.location.href.indexOf("chicago-theater") > -1) || (window.location.href.indexOf("eventos") > -1)) { console.log("perkopolis page is correct"); // update the iFrame SRC url // $('#get-started-iframe').attr('src', url); $("#get-started-form input").blur(function() { // Validate form on input updates ValidateForm(); //chose a location url here if ($('#promo_code').val() == undefined || $('#promo_code').val() == null || $('#promo_code').val() == '' ) { promocode = '20OFF'; } else { promocode = $('#promo_code').val(); } url = 'https://hc-customer.com/prod/#/choose-location' + '?campaignId=' + campaignId + '&sourceCode=' + sourceCode + '&promoCode=' + promocode + '&gclid=' + gclid + '&googleClientId=' + googleClientId + '&deviceType=' + deviceType + '&hcuid=' + hcuid + '&msclkid=' + msclkid + '&fbclid=' + fbclid + '&kuid=' + kuid + '&first-name=' + $('#first_name').val() + '&last-name=' + $('#last_name').val() + '&email=' + $('#email_address').val() + '&phone=' + $('#phone_number').val() + '&zip-code=' + $('#zippostal_code').val() + '&utm_campaign' + getUrlParameter('utm_campaign') + '&utm_source' + getUrlParameter('utm_source') + '&utm_medium' + getUrlParameter('utm_medium'); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); }); } else if (window.location.href.indexOf("kiosk") > -1) { console.log("Kiosk page is correct"); // update the iFrame SRC url // $('#get-started-iframe').attr('src', url); $("#get-started-form input").blur(function() { // Validate form on input updates // validateForm(); updateSubmitValid(); //chose a location url here if ($('#promo_code').val() == undefined || $('#promo_code').val() == null || $('#promo_code').val() == '') { promocode = 'KIOSK-10-OFF'; } else { promocode = $('#promo_code').val(); } url = 'https://hc-customer.com/prod/#/choose-location' + '?campaignId=' + campaignId + '&sourceCode=' + sourceCode + '&referralCode=' + referralCode + '&promoCode=' + promocode + '&gclid=' + gclid + '&googleClientId=' + googleClientId + '&deviceType=' + deviceType + '&hcuid=' + hcuid + '&msclkid=' + msclkid + '&fbclid=' + fbclid + '&kuid=' + kuid + '&first-name=' + $('#first_name').val() + '&last-name=' + $('#last_name').val() + '&email=' + $('#email_address').val() + '&phone=' + $('#phone_number').val() + '&zip-code=' + $('#zippostal_code').val() + '&utm_campaign' + getUrlParameter('utm_campaign') + '&utm_source' + getUrlParameter('utm_source') + '&utm_medium' + getUrlParameter('utm_medium'); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); }); } else if (window.location.href.indexOf("boca-kiosk") > -1) { console.log("Boca Kiosk page is correct"); // Watch for input change and update the iFrame Source URL // #get-started is the form ID $("#get-started-form input").blur(function() { // Validate form on input updates // validateForm(); updateSubmitValid(); //chose a location url here // referralCode = $('#referral_code').val(); var referralCode = ''; if ($('#referral_code').val() == undefined || $('#referral_code').val() == null ) { referralCode = ''; } else { referralCode = $('#referral_code').val(); } if ($('#promo_code').val() == undefined || $('#promo_code').val() == null || $('#promo_code').val() == '') { promocode = ''; } else { promocode = $('#promo_code').val(); } var gclid = getUrlParameter('gclid') == '' || getUrlParameter('gclid') == null || getUrlParameter('gclid') == false ? '' : getUrlParameter('gclid'); console.log("2 the gclid is: " + gclid); url = 'https://hc-customer.com/prod/#/choose-location' + '?campaignId=' + campaignId + '&sourceCode=' + sourceCode + '&referralCode=' + referralCode + '&promoCode=' + promocode + '&gclid=' + gclid + '&googleClientId=' + googleClientId + '&deviceType=' + deviceType + '&hcuid=' + hcuid + '&msclkid=' + msclkid + '&fbclid=' + fbclid + '&kuid=' + kuid + '&first-name=' + $('#first_name').val() + '&last-name=' + $('#last_name').val() + '&email=' + $('#email_address').val() + '&phone=' + $('#phone_number').val() + '&zip-code=' + $('#zippostal_code').val() + '&utm_campaign' + getUrlParameter('utm_campaign') + '&utm_source' + getUrlParameter('utm_source') + '&utm_medium' + getUrlParameter('utm_medium'); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); }); } else if (document.getElementById("get-started-form")) { // Watch for input change and update the iFrame Source URL // #get-started is the form ID $("#get-started-form input").blur(function() { // Validate form on input updates // validateForm(); updateSubmitValid(); //chose a location url here // referralCode = $('#referral_code').val(); var referralCode = ''; if ($('#referral_code').val() == undefined || $('#referral_code').val() == null ) { referralCode = ''; } else { referralCode = $('#referral_code').val(); } if ($('#promo_code').val() == undefined || $('#promo_code').val() == null || $('#promo_code').val() == '' ) { promocode = ''; } else { promocode = $('#promo_code').val(); } var gclid = getUrlParameter('gclid') == '' || getUrlParameter('gclid') == null || getUrlParameter('gclid') == false ? '' : getUrlParameter('gclid'); console.log("2 the gclid is: " + gclid); url = 'https://hc-customer.com/prod/#/choose-location' + '?campaignId=' + campaignId + '&sourceCode=' + sourceCode + '&referralCode=' + referralCode + '&promoCode=' + promocode + '&gclid=' + gclid + '&googleClientId=' + googleClientId + '&deviceType=' + deviceType + '&hcuid=' + hcuid + '&msclkid=' + msclkid + '&fbclid=' + fbclid + '&kuid=' + kuid + '&first-name=' + $('#first_name').val() + '&last-name=' + $('#last_name').val() + '&email=' + $('#email_address').val() + '&phone=' + $('#phone_number').val() + '&zip-code=' + $('#zippostal_code').val() + '&utm_campaign' + getUrlParameter('utm_campaign') + '&utm_source' + getUrlParameter('utm_source') + '&utm_medium' + getUrlParameter('utm_medium'); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); }); } else if (window.location.href.indexOf("find-a-center") > -1) { if ($('#promo_code').val() == undefined || $('#promo_code').val() == null || $('#promo_code').val() == '' ) { promocode = ''; } else { promocode = $('#promo_code').val(); } url = 'https://hc-customer.com/prod/#/customer' + '?campaignId=' + campaignId + '&sourceCode=' + sourceCode + '&referralCode=' + referralCode + '&promoCode=' + promocode + '&gclid=' + gclid + '&googleClientId=' + googleClientId + '&deviceType=' + deviceType + '&hcuid=' + hcuid + '&msclkid=' + msclkid + '&fbclid=' + fbclid + '&kuid=' + kuid + '&first-name=' + $('#first_name').val() + '&last-name=' + $('#last_name').val() + '&email=' + $('#email_address').val() + '&phone=' + $('#phone_number').val() + '&zip-code=' + zipcode + '&utm_campaign' + getUrlParameter('utm_campaign') + '&utm_source' + getUrlParameter('utm_source') + '&utm_medium' + getUrlParameter('utm_medium'); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); } else { if ($('#promo_code').val() == undefined || $('#promo_code').val() == null || $('#promo_code').val() == '' ) { promocode = ''; } else { promocode = $('#promo_code').val(); } url = 'https://hc-customer.com/prod/#/customer' + '?campaignId=' + campaignId + '&sourceCode=' + sourceCode + '&referralCode=' + referralCode + '&promoCode=' + promocode + '&gclid=' + gclid + '&googleClientId=' + googleClientId + '&deviceType=' + deviceType + '&hcuid=' + hcuid + '&msclkid=' + msclkid + '&fbclid=' + fbclid + '&kuid=' + kuid + '&first-name=' + $('#first_name').val() + '&last-name=' + $('#last_name').val() + '&email=' + $('#email_address').val() + '&phone=' + $('#phone_number').val() + '&zip-code=' + zipcode + '&utm_campaign' + getUrlParameter('utm_campaign') + '&utm_source' + getUrlParameter('utm_source') + '&utm_medium' + getUrlParameter('utm_medium'); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); } }, "2000"); // Watch for input change and update the iFrame Source URL // #get-started is the form ID $("#get-started-form input").blur(function() { // Validate form on input updates // validateForm(); updateSubmitValid(); }); }); // Watch for input change and update the iFrame Source URL // #get-started is the form ID $("#get-started-form input").blur(function() { // Validate form on input updates // validateForm(); updateSubmitValid(); }); function validateForm() { // declare form invalid variable and set to false var formInvalid = false; // $('#get-started-form input').not($('#promo_code')).each(function() { // if ($(this).val() == '' || $(this).val() == null) { // formInvalid = true; // } // }); // Check if all fields are filled out $('#get-started-form input').not('#promo_code').each(function() { if ($(this).val() == '' || $(this).val() == null) { formInvalid = true; } }); return !formInvalid; // If the form is valid, then Enable the Submit button // if (formInvalid == false ) { // $('#im-ready').css({'opacity': '1'}); // $('#im-ready').removeAttr('disabled'); // } } const emailInput = document.getElementById("email_address"); const phoneInput = document.getElementById("phone_number"); let emailIsValid = false; let phoneIsValid = false; function updateSubmitValid() { // let btn = document.getElementById("im-ready") // if (emailIsValid === true && phoneIsValid === true ) { // jQuery('#im-ready').css({'opacity': '1'}); // jQuery('#im-ready').removeAttr('disabled'); // } let btn = document.getElementById("im-ready") if (emailIsValid === true && phoneIsValid === true && validateForm() === true) { jQuery('#im-ready').css({'opacity': '1'}); jQuery('#im-ready').removeAttr('disabled'); } else { jQuery('#im-ready').css({'opacity': '0.5'}); jQuery('#im-ready').prop("disabled", true); } } function formatPhone(phone) { if (phone.startsWith("1")) { return phone; } else { return `1${phone}`; } } function validatePhone(phone, div, input) { fetch("https://api.experianaperture.io/phone/validate/v2", { "headers": { "accept": "application/json", "auth-token": "c49276ba-5bfc-4ccd-aae1-7aaa48c520df", "content-type": "application/json", "timeout-seconds": "15" }, "body": `{"number": "${formatPhone(phone)}"}`, "method": "POST"}) .then((response) => response.json()) .then((data) => { let confidence = null; let phoneType = null; let validTypes = ["Mobile", "Landline", "Mobile or landline", "VoIP", "Personal number", "Voicemail only", "Unknown"] if (data.result) { confidence = data.result.confidence; phoneType = data.result.phone_type; } else { confidence = "error" } if ((confidence === "Verified" || confidence === "Unknown") && validTypes.includes(phoneType)) { if (div && div.classList.contains("invalid-feedback")) { div.remove(); } phoneIsValid = true; updateSubmitValid(); } else { if (!div || !div.classList.contains("invalid-feedback")) { const newDiv = document.createElement("div"); newDiv.classList.add("invalid-feedback"); newDiv.innerHTML = "Please enter a valid phone number"; input.after(newDiv); } phoneIsValid = false; updateSubmitValid(); } }); } function validateEmail(email, div, input) { fetch("https://api.experianaperture.io/email/validate/v2", { "headers": { "accept": "application/json", "auth-token": "c49276ba-5bfc-4ccd-aae1-7aaa48c520df", "content-type": "application/json", "timeout-seconds": "15" }, "body": `{"email": "${email}"}`, "method": "POST"}) .then((response) => response.json()) .then((data) => { let confidence = null; if (data.result) { confidence = data.result.confidence } else { confidence = "error" } if (confidence === "verified" || confidence === "unknown") { if (div && div.classList.contains("invalid-feedback")) { div.remove(); } emailIsValid = true; updateSubmitValid(); } else { if (!div || !div.classList.contains("invalid-feedback")) { const newDiv = document.createElement("div"); newDiv.classList.add("invalid-feedback"); newDiv.innerHTML = "Please enter a valid email"; input.after(newDiv); } emailIsValid = false; updateSubmitValid(); } }); } function checkPhoneInput(event) { const input = event.target; const div = input.nextElementSibling; validatePhone(input.value, div, input) } function checkEmailInput(event) { const input = event.target; const div = input.nextElementSibling; validateEmail(input.value, div, input); } emailInput.addEventListener("blur", checkEmailInput); phoneInput.addEventListener("blur", checkPhoneInput); // Prevent entering a space in zipcode field $("#zippostal_code").keydown(function() { var e = window.event || e; var key = e.keyCode; //space pressed if (key == 32) { //space e.preventDefault(); } }); // Prevent pasting in a space in zipcode field $("#zippostal_code").bind("paste", function(e) { var data = event.clipboardData.getData("text/plain"); var isNullOrContainsWhitespace = (!data || data.length === 0 || /\s/g.test(data)); if(isNullOrContainsWhitespace) { event.preventDefault(); } }); window.addEventListener("message", (e) => { let data = e.data; if ("makeAppointment" == data.action) { var url = `https://hc-customer.com/prod/#/customer?campaign-id=7017V000001gKScQAM&zip-code=${data.zipCode}¢er-id=${data.idCenter}`; // console.log(url); // update the iFrame SRC url $('#get-started-iframe').attr('src', url); document.getElementById('nav-book-your-consult').click(); } else if ("call" == data.action) { // document.getElementById('top-bar-call-us').click(); window.location = "tel:800-424-7258"; window.dataLayer.push({'event':'ga.event','category':'contact','action':'call','label':'click to call','value':'','non-interactive':'false'}); } else if ("chat" == data.action) { document.getElementById('sp-chat-widget').click(); $('.modal-overlay').css({ 'display': 'none', 'opacity': '0', }); $('.modal-inner').css({ 'opacity': '0', 'transform': 'translate3d(0px, 0px, 0px) scale3d(1, 1, 1) rotateX(0deg) rotateY(0deg) rotateZ(0deg) skew(0deg, 0deg)', 'transform-style': 'preserve-3d' }); $('.link-block-5').css({ 'opacity': '0' }); } else if ("leadId" == data.action) { var sfLeadId = `${data.id}`; // console.log('lead id variable ' + sfLeadId); // window.dataLayer.push({'event':'datalayer.change','category':'user','action':'salesforceleadid','label':'salesforceleadid','value':sfLeadId,'non-interactive':'false'}); window.dataLayer.push({'user.salesforceleadid':sfLeadId}); $("#get-started-iframe").addClass("form-location-page-reached"); } else if ("searchZip" == data.action) { // Get the value of ${data.id} var searchedZipCode = `${data.zipCode}`; console.log('Searched zipcode: ' + searchedZipCode); // Initialize Google Analytics ga('create', 'UA-25883685-1', 'auto'); // Construct the Measurement Protocol URL var gaUrl = 'https://www.google-analytics.com/collect'; gaUrl += '?v=1'; gaUrl += '&t=pageview'; gaUrl += '&tid=G-29R484TY68'; gaUrl += '&cid=' + ga.getAll()[0].get('clientId'); gaUrl += '&dp=' + searchedZipCode; // Send the pageview hit to Google Analytics var img = new Image(); img.src = gaUrl; // Wait for GA to fully initialize before sending pageview setTimeout(function() { ga('send', 'pageview', '/find-a-center/' + searchedZipCode); }, 1000); } else if ("reportHeight" == data.action) { // Get the value of ${data.id} var iframeHeight = `${data.height}`; console.log('iframe height= ' + iframeHeight); function resizeIframe(event) { var iframe = document.getElementById('find-a-location'); iframe.style.height = iframeHeight + 'px'; } resizeIframe(); } }); window.addEventListener('message', e => { // console.log(e.data); if (e.data == "chat-pop-clicked") { FunctionA(); } }, false); function FunctionA() { document.getElementById('sp-chat-widget').click(); $('.modal-overlay').css({ 'display': 'none', 'opacity': '0', }); $('.modal-inner').css({ 'opacity': '0', 'transform': 'translate3d(0px, 0px, 0px) scale3d(1, 1, 1) rotateX(0deg) rotateY(0deg) rotateZ(0deg) skew(0deg, 0deg)', 'transform-style': 'preserve-3d' }); $('.link-block-5').css({ 'opacity': '0' }); document.getElementById('nav-book-your-consult').click(window.dataLayer.push({'event':'ga.event','category':'user','action':'hcuid','label':'INSERT_HCUID_VALUE','value':'','non-interactive':'false'})); } // END GET STARTED IFRAME SUPPORT CODE // CODE TO TO MAKE SOME OF THE OTHER BUTTONS / LINKS START CHAT AND CALLS jQuery(document).on('click', '#prime', function(e) { $("#sp-chat-widget").trigger('click'); }); jQuery(document).on('click', '#get-in-touch-chat-btn', function(e) { $("#sp-chat-widget").trigger('click'); // window.dataLayer.push({'event':'ga.event','category':'contact','action':'web chat','label':'click','value':'','non-interactive':'false'}); }); jQuery(document).on('click', '.live-chat', function(e) { $("#sp-chat-widget").trigger('click'); }); // Datalayer push when clicking phone number $('.call-us-link').click(function(e) { window.dataLayer.push({'event':'ga.event','category':'contact','action':'call','label':'click to call','value':'','non-interactive':'false'}); }); // Datalayer push when clicking chat $('.sp-round-button').click(function(e) { window.dataLayer.push({'event':'ga.event','category':'contact','action':'web chat','label':'click','value':'','non-interactive':'false'}); }); // Datalayer push when clicking any link that has the words "book your consult" $("a:contains('Book Your Consult')").click(function(e) { window.dataLayer.push({'event':'ga.event','category':'contact','action':'appointment','label':'lead form view','value':'','non-interactive':'false'}); }); // END CODE TO TO MAKE SOME OF THE OTHER BUTTONS / LINKS START CHAT AND CALLS