var FUNNEL_ID = document.head.querySelector("meta[name=funnel_id]").content; var FUNNEL_PAGE_ID = document.head.querySelector( "meta[name=funnel_page_id]" ).content; var BASE_URL = "https://api.myflxfnls.com"; var path = new URL(document.location); var params = path.searchParams; var ai = params.get("ai"), pi = params.get("pi"), ti = params.get("ti"), fid = params.get("fid"), product_id = params.get("id"), ffid = params.get("ffid"); ftphonenumber = function (inputtxt) { var phoneno = /^[+]*[(]{0,1}[0-9]{1,3}[)]{0,1}[-\s\./0-9]*$/g; if (inputtxt.match(phoneno)) { return true; } else { return false; } }; getCookie = function (cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(";"); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == " ") { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; }; delete_cookie = function (name) { document.cookie = name + "=; Path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT"; }; delete_cookies = function (clist) { clist.forEach(function (key) { document.cookie = key + "=; Path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT"; }); }; setCookie = function (clist) { clist.forEach(function (item, index) { document.cookie = item.key + "=" + item.value + "; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT"; }); }; // getTimerDate = function (t, offset) { // now = new Date(); // local_time = now.getTime(); // local_offset = now.getTimezoneOffset() * 60000; // utc = local_time + local_offset; // return new Date(utc + 3600000 * offset); // }; getTimerDate = function (t, offset) { var d = t ? new Date(t) : new Date(); var localTime = d.getTime(); var localOffset = d.getTimezoneOffset() * 60000; var utc = localTime + localOffset; var timer_res = utc + 3600000 * offset; return new Date(timer_res); }; generateUniqueId = function (event) { return `_${Date.now().toString(36)}${Math.floor( Number.MAX_SAFE_INTEGER * Math.random() ).toString(36)}`; }; var utmkeys = [ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "utm_id", ]; getUTMtracking = function (params, data, utmId) { var utm_s = params.get("utm_source"); if (utm_s != null) { utmkeys.forEach(function (number) { var t = params.get(number); if (t != null) data[number] = t; }); var utm_count = getCookie("utm_count_" + utmId); var utm_ad = getCookie("utm_append_" + utmId); data["touch_point"] = utm_count; data["utm_flow"] = utm_ad; } return data; }; setUTMtracking = function (params, utmId) { var utm = params.get("utm_source"); if (utm != null) { var utmObj = {}; utmkeys.forEach(function (number) { var t = params.get(number); if (t != null) utmObj[number] = t; }); var lutm = getCookie("lus_" + utmId); console.log(utm); var utm_count = 0; var utm_append = ""; if (lutm !== "" && lutm != utm) { utmObj["lus"] = lutm; var utm_count_in = getCookie("utm_count_" + utmId); utm_count = parseInt(getCookie("utm_count_" + utmId)) + 1; console.log(JSON.parse(getCookie("utm_append_" + utmId))); var newUTM = JSON.parse(getCookie("utm_append_" + utmId)); console.log(newUTM); newUTM.push(utm); console.log(utm); console.log(newUTM); utm_append = newUTM; } else if (lutm !== "" && lutm == utm) { utm_count = parseInt(getCookie("utm_count_" + utmId)); utm_append = JSON.parse(getCookie("utm_append_" + utmId)); } else { utm_count = 1; utm_append = [utm]; console.log(utm_append); } setCookie([ { key: "utag_main_" + utmId, value: JSON.stringify(utmObj), }, { key: "ft_params_" + utmId, value: params.toString(), }, { key: "lus_" + utmId, value: utmObj.utm_source, }, { key: "lus_utm_id_" + utmId, value: utmObj.utm_id, }, //UTM Count { key: "utm_count_" + utmId, value: utm_count, }, //UTM append { key: "utm_append_" + utmId, value: JSON.stringify(utm_append), }, ]); } //return res; }; $(document).ready(function () { callHTTP = function ( url, data, callback, // How can I use this callback?, type ) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { // if (xhr.readyState == 4) { callback(this); // Another callback here // } }; xhr.open(type ? type : "POST", url); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); // xhr.setRequestHeader("authorizationToken", path.host); xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(data); }; mailValidation = function (val) { var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; var mode = false; if (!expr.test(val)) mode = true; if (val.includes("+")) mode = false; return mode; }; validatePhone = function (phone) { if (typeof phone == "undefined") return true; var regex = /^\+(?:[0-9] ?){6,14}[0-9]$/; if (regex.test(phone)) { return true; } else { return false; } }; formvalidation = function (formId, $formData) { var fail = false; var errList = {}; formErrMsgShowUp(formId, {}); function inputValidation(obj, name, value, errList) { if (name == "email") { value.trim().replace(/ /g, ""); if (mailValidation(value)) { obj.addClass("gjs-ip-brdrclr"); fail = true; errList.email = ["Please enter a valid email address"]; } if (obj.prop("required")) $formData["erq_mode"] = 1; } else if (name == "phone") { var mode = obj.attr("data-tel-mode"); if (mode == "true") { $formData[name] = obj.attr("data-tel-no") ? obj.attr("data-tel-no") : value; var dialcode = obj.attr("data-tel-countrycode"); if (!verifier(dialcode)) $formData["ft_countrycode"] = dialcode; } else if (mode == "false") { // var device = getUA(); // if (device == "UCBrowser") { // var po_res = ftphonenumber(value); // if (!po_res) { // obj.addClass("gjs-ip-brdrclr"); // fail = true; // errList.phone = [ // "Please enter a valid phone number", // ]; // } else $formData[name] = value; // } else { obj.addClass("gjs-ip-brdrclr"); fail = true; errList.phone = [ obj.attr("data-tel-err") ? obj.attr("data-tel-err") : "Please enter a valid phone number", ]; // } } else $formData[name] = value; // if (!phonenumber(value)) { // obj.addClass("gjs-ip-brdrclr"); // fail = true; // errList.phone = ["Please enter a valid phone number"]; // } } } $("#" + formId) .find("select, textarea, input") .each(function () { var name = $(this).attr("name"); var type = $(this).attr("type"); var value = $(this).val().trim(); if (name == "pricing_id") { var price = $( "input[name=pricing_id]:checked", "#" + formId ).val(); if (verifier(price)) { errList.pricing_id = [ "Please select at least one pricing option", ]; fail = true; } } $(this).removeClass("gjs-ip-brdrclr"); if ($(this).prop("required")) { // If input require if (!value) { let dataRequired = $(this).attr("data-required"); //For autoResponder code if (dataRequired == "false") { } else { fail = true; $(this).addClass("gjs-ip-brdrclr"); errList["empty"] = [ "Please fill in all the required fields", ]; } } else inputValidation($(this), name, value, errList); } else if (value) { inputValidation($(this), name, value, errList); } }); //submit if fail never got set to true if (fail) formErrMsgShowUp(formId, errList); var res = { fail: !fail, formData: $formData }; return res; }; // function ftButton(sId, hId) { // (document.getElementById(sId).style.display = "inline-block"), // (document.getElementById(hId).style.display = "none"); // } //commonGetInputs verifier = function (value) { return ( value === undefined || value === null || (typeof value === "object" && Object.keys(value).length === 0) || (typeof value === "string" && value.trim().length === 0) ); }; getAssignedData = function ($dataObject) { if (!verifier($('input[name="product_id"]').val())) $dataObject["product_id"] = $('input[name="product_id"]').val(); if (!verifier($('input[name="ffid"]').val())) $dataObject["ffid"] = $('input[name="ffid"]').val(); if (!verifier($('input[name="fid"]').val())) $dataObject["fid"] = $('input[name="fid"]').val(); return $dataObject; }; btnLoader = function (obj, pObj) { var temp = obj.find(".fa-spin"); if (temp.length != 0) return false; if (pObj) pObj.addClass("gjs-btneffect"); else obj.addClass("gjs-btneffect"); obj.append(``); return true; }; removebtnLoader = function (obj, pObj) { setTimeout(function () { if (pObj) pObj.removeClass("gjs-btneffect"); else obj.removeClass("gjs-btneffect"); obj.find(".fa-spin").remove(); }, 1200); }; getAllFormsData = function ($dataObject) { $("body") .find("form") .each(function (index) { $fData = $(this).serializeArray(); $fData.map(function (val) { $dataObject[val.name] = val.value; }); }); return $dataObject; }; formSucssMsgShowUp = function (formId, curObj, msg) { setTimeout(function () { curObj.removeClass("skeleton-loader"); //curObj.removeClass("gjs-btneffect"); // curObj.find(".fa-spin").fadeOut("slow", function () { // $(this).remove(); // }); curObj.find(".fa-spin").remove(); }, 500); var fObj = $("#" + formId); if (fObj) { fObj[0].reset(); if (!verifier(msg)) { fObj.find(".ft-formsuc-block").remove(); fObj.find(".ft-formerr-block").remove(); var html = `
${msg}
`; fObj.prepend(html); } } }; actionUrlCheck = function (url) { try { let domain = new URL(url); domain = domain.hostname.replace("www.", ""); return domain; } catch (err) { return false; } }; getUA = function () { let device = "Unknown"; const ua = { "Generic Linux": /Linux/i, Android: /Android/i, BlackBerry: /BlackBerry/i, Bluebird: /EF500/i, "Chrome OS": /CrOS/i, Datalogic: /DL-AXIS/i, Honeywell: /CT50/i, iPad: /iPad/i, iPhone: /iPhone/i, iPod: /iPod/i, macOS: /Macintosh/i, Windows: /IEMobile|Windows/i, Zebra: /TC70|TC55/i, UCBrowser: /UCBrowser/i, }; Object.keys(ua).map( (v) => navigator.userAgent.match(ua[v]) && (device = v) ); return device; }; formErrMsgShowUp = function (formId, fErr, curObj) { document.querySelector("#" + formId).scrollIntoView({ behavior: "smooth", }); if (curObj) { setTimeout(function () { curObj.removeClass("skeleton-loader"); }, 0); } var tArray = []; Object.keys(fErr).forEach(function (key, value) { var res = { type: key, msg: fErr[key][0], }; tArray.push(res); }); var fObj = $("#" + formId); if (fObj) { fObj.find(".ft-formsuc-block").remove(); fObj.find(".ft-formerr-block").remove(); //fObj.find(".gjs-ip-brdrclr").removeClass("gjs-ip-brdrclr"); if (tArray.length != 0) { var liInner = ``; tArray.forEach(function (item, index) { fObj.find(`input[name=${item.type}]`).addClass( "gjs-ip-brdrclr" ); liInner += `
  • ${item.msg}
  • `; }); var html = `
    `; fObj.prepend(html); } } }; $(document).on( "click", "img[data-action='url'],.ft-icon[data-action='url']", function () { ($url = $(this).attr("data-url")), ($target = $(this).attr("data-target") ? $(this).attr("data-target") : "_self"), window.open($url, $target); } ), ($climg = $("img[data-action='calls'],.ft-icon[data-action='calls']")), $climg.each(function () { $url = $(this).attr("href"); $(this).wrap(``); }), $(document).on( "click", "img[data-action='popup'],.ft-icon[data-action='popup']", function () { var pop_id = $(this).attr("data-popup"); $("#" + pop_id).addClass("show"); } ), $(document).on("click", ".ff-modal-pop-close", function (event) { event.stopPropagation(); var id = $(this).attr("data-popid"); $("#" + id) .find(".ff-modal-div") .addClass("fmc-ani-down") .delay(300) .queue(function () { $(this).removeClass("fmc-ani-down").dequeue(); }); setTimeout(function () { var pObj = $("#" + id); if (pObj.length !== 0) { pObj.removeClass("show"); addCookieToPopup(pObj); } }, 250); }), $(document).on("click", "div[data-popupbgclose='yes']", function () { $(this).removeClass("show"); addCookieToPopup($(this)); }), $(document).on( "click", "div[data-popupbgclose='no']", function (event) { // alert(); // $(this).find('.ff-modal-div').addClass("fmc-scale").delay(1000).removeClass("fmc-scale"); $(this) .find(".ff-modal-div") .addClass("fmc-scale") .delay(100) .queue(function () { $(this).removeClass("fmc-scale").dequeue(); }); } ), $(document).on("click", ".ff-modal-content", function (event) { event.stopPropagation(); }), $(document).on("click", "a[href*='#open-popup']", function () { ($id = $(this).attr("data-popup")), $("#" + $id).addClass("show"); return false; }), $(document).on("click", ".formsuc-close", function () { $(this).parent().fadeOut(); }), // ******************************************* // popup start close // ******************************************** // *********** // Nav start // *********** $(document).on("click", ".ft-navbar-toggler", function () { $sticky = $(".ft-stickytop").first(); if ($sticky.length != 0) $sticky.addClass("ft-stickytop-box"); $(this).next().toggleClass("show"); }), // $(".ft-dropdown").hover( // function () { // var color = $(this).css("background-color"); // $(this).prev().css("background-color", color); // }, // function () { // $(this).prev().removeAttr("style"); // } // ), // *********** // Nav close // *********** $(document).on( "click", "a[href*='#scroll-'],img[data-imagelink*='#scroll-'],.ft-icon[data-imagelink*='#scroll-']", function () { $id = $(this).attr("data-ftscrollid"); if (typeof $id !== "undefined") { var top = $("#" + $id).offset().top; $([document.documentElement]) .stop() .animate( { scrollTop: top, }, { done: function () { var itop = $("#" + $id).offset().top; if (top !== itop) { $([document.documentElement]) .stop() .animate( { scrollTop: itop, }, 100 ); } }, duration: 500, } ); } return false; } ), $(document).on("click", "a[href*='#product']", function () { var curObj = $(this); $product_id = $(this).attr("data-ft-productData"); // ($checkout_url = $(this).attr("data-checkout-url")); //if (!verifier($checkout_url)) window.location.href = $checkout_url; // else { if ($(curObj).hasClass("skeleton-loader")) return false; curObj.addClass("skeleton-loader"); $newObject = { product_id: $product_id ? $product_id : "", type: "product", }; var data = JSON.stringify($newObject); callHTTP(BASE_URL + "/checkout", data, function (res) { if (res.readyState === 4) { curObj.removeClass("skeleton-loader"); var response = JSON.parse(res.responseText); window.location.href = response.body.checkout_page_url; } }); //} return !1; }), $(document).on("click", "a[href*='#funnel']", function () { var curObj = $(this); if ($(curObj).hasClass("skeleton-loader")) return false; curObj.addClass("skeleton-loader"); // var btnApp = $(this).find(".ffbtntxt"); // if (!btnLoader(btnApp, curObj)) return false; //Multi Acation prevent ($product_id = $(this).attr("data-ft-productData")), ($type = $(this).attr("href") == "#funnel" ? "funnel" : "product"), ($funnel_id = $(this).attr("data-ft-funnelData")), ($funnel_product_id = $(this).attr("data-funnel_product_id")); $newObject = { product_id: $product_id ? $product_id : "", funnel_id: $funnel_id ? $funnel_id : "", funnel_product_id: $funnel_product_id ? $funnel_product_id : "", type: $type, }; var data = JSON.stringify($newObject); callHTTP(BASE_URL + "/checkout", data, function (res) { if (res.readyState === 4) { curObj.removeClass("skeleton-loader"); var response = JSON.parse(res.responseText); window.location.href = response.body.checkout_page_url; } }); // var xhr = new XMLHttpRequest(); // xhr.addEventListener("readystatechange", function () { // if (this.readyState === 4) { // // removebtnLoader(btnApp, curObj); //remove loader after res // curObj.removeClass("skeleton-loader"); // console.log(this.responseText); // console.log(typeof this.responseText); // var response = JSON.parse(this.responseText); // // console.log(this.getResponseHeader('Set-Cookie')); // // window.location.href = response.checkout_page_url + "?id=" + response.product_id; // window.location.href = response.body.checkout_page_url; // // curObj.removeClass("gjs-btneffect"); // // curObj.find(".fa-spin").remove(); // } // }); // xhr.open("POST", "https://dev.myflxfnls.com/checkout"); // xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); // xhr.setRequestHeader("authorizationToken", path.host); // xhr.setRequestHeader("Content-Type", "application/json"); // xhr.send(data); return !1; }), //No thanks button $(document).on("click", "a[href*='#no-thanks']", function () { var curObj = $(this); $dataObject = { product_id: $(this).attr("data-ft-productdata"), fid: $(this).attr("data-funnel_product_id"), ffid: $(this).attr("data-ft-funneldata"), }; var data = JSON.stringify($dataObject); if (curObj.hasClass("gjs-btneffect")) return false; curObj.addClass("gjs-btneffect"); callHTTP(BASE_URL + "/no-thanks", data, function (res) { if (res.readyState === 4) { var response = JSON.parse(res.responseText); var url = response.body.sales_url; if (!verifier(url)) window.location.href = url; curObj.removeClass("gjs-btneffect"); } }); return !1; }), $(document).on("click", "a[href*='#submit']", async function () { var formId = $(this).attr("data-formid"); var clset_id = $(this).closest("form").attr("id"); if (formId !== clset_id) formId = clset_id; $dataObject = {}; if (!verifier(formId)) { $formData = $("#" + formId).serializeArray(); $formData.map(function (val) { var key = val.name; $dataObject[key] = val.value; }); $dataObject["form_id"] = formId; } else $dataObject = getAllFormsData($dataObject); if (ai != null && pi != null) ($dataObject["ai"] = ai), ($dataObject["pi"] = pi); //Form Default Valiation var formEle = $("#" + formId); if (!formEle[0].checkValidity()) { var errList = { empty: ["Please fill in all the required fields"], }; formErrMsgShowUp(formId, errList); formEle[0].reportValidity(); return false; } //Form Manual Valiation var res = formvalidation(formId, $dataObject); if (res.fail == false) return false; else $dataObject = res.formData; var curObj = $(this); if ($(curObj).hasClass("skeleton-loader")) return false; curObj.addClass("skeleton-loader"); // var btnApp = $(this).find(".ffbtntxt"); // if (!btnLoader(btnApp, curObj)) return false; //Multi Acation prevent var goNext = $(this).attr("data-nextGo") ? $(this).attr("data-nextGo") : ""; //after var gotarget = $(this).attr("data-target") ? $(this).attr("data-target") : "_self"; //after var smsg = curObj.attr("data-smsg") ? curObj.attr("data-smsg") : ""; // if (formId !== "" && typeof formId !== "undefined") { // $formData = $("#" + formId).serializeArray(); // $formData.map(function (val) { // var key = val.name; // $dataObject[key] = val.value; // }); // $dataObject["form_id"] = formId; // } else $dataObject = getAllFormsData($dataObject); $dataObject["funnel_id"] = $("meta[name=funnel_id]").attr( "content" ); $dataObject["funnel_page_id"] = $("meta[name=funnel_page_id]").attr( "content" ); $dataObject["rule_id"] = "0"; var device = getUA(); $dataObject["device"] = device; // if ($order["coupon"].status) { // $dataObject["coupon_code"] = $order["coupon"].coupon_code; // } $dataObject = getUTMtracking( params, $dataObject, $dataObject["funnel_page_id"] ); //console.log($dataObject); //console.log("test"); // return false; // if (t.status) { // $dataObject["utag_main"] = t["utm"]; // Object.keys(t["utm"]).forEach(function (key, value) { // $dataObject[key] = t["utm"][key]; // }); // } var data = JSON.stringify($dataObject); $(".ft-form-error").remove(); //AutoResponder form code if ($("#" + formId).hasClass("ft-autoresponder")) { var type = $(this).attr("data-autoresponder"); if (typeof type !== "undefined") { var phone = validatePhone($dataObject["phone"]); if (!phone) { curObj .parent() .prepend( `Please add country code before the phone number` ); curObj.removeClass("gjs-btneffect"); curObj.find(".fa-spin").remove(); return false; } } // function ajaxMaskUI(settings) { // function maskPageOn(color) { // color can be ie. 'rgba(176,176,176,0.7)' or 'transparent' // var div = $('#maskPageDiv'); // if (div.length === 0) { // $(document.body).append(''); // create it // div = $('#maskPageDiv'); // } // if (div.length !== 0) { // div[0].style.zIndex = 2147483647; // div[0].style.backgroundColor=color; // div[0].style.display = 'inline'; // } // } // function maskPageOff() { // var div = $('#maskPageDiv'); // if (div.length !== 0) { // div[0].style.display = 'none'; // div[0].style.zIndex = 'auto'; // } // } // function hourglassOn() { // if ($('style:contains("html.hourGlass")').length < 1) $('