function mainBot() {
  var main_url = "https://www.smatbot.com";
  var url = "https://www.smatbot.com";
  var xhr = new XMLHttpRequest();
  xhr.addEventListener("readystatechange", function () {
    if (this.readyState === 4 && this.status === 200) {
      var head = document.getElementsByTagName("head")[0];
      function appendScriptLinks(url, type) {
        var head = document.getElementsByTagName("head")[0];
        if (type == 'script') {
          var link = document.createElement("script");
          link.src = url;
          head.appendChild(link);
        } else if (type == "style") {
          var style = document.createElement("style");
          style.type = "text/css";
          style.innerHTML = url;
          head.appendChild(style);
        } else {
          var link = document.createElement("link");
          link.type = "text/css";
          link.rel = "stylesheet";
          link.href = url;
          head.appendChild(link);
        }
      }
      if (chatbot_id != 5771) {
        appendScriptLinks("https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js", "script");
        appendScriptLinks("https://cdn.jsdelivr.net/npm/pikaday/pikaday.min.js", "script");
      }
      appendScriptLinks("https://cdn.jsdelivr.net/npm/pikaday/css/pikaday.min.css", "css");
      appendScriptLinks("https://plugin.smatbot.com/smatbot.css.gz", "css");
      appendScriptLinks("https://fonts.googleapis.com/icon?family=Material+Icons", "css");
      var visitedUrls = [];
      var src;
      var src_date;
      var alreadyEmailChecked;
      var user_location;
      var userResponseText;
      var agreed;
      var lead_revisited;
      var lead_revisit_notification;
      var needPrivacy;
      var prev_email_text;
      var is_adwords_enabled;
      var radio_options;
      var is_radio_hidden;
      var activeTimeouts = [];
      var isReloaded;
      var partner_client_details = false;
      var brand_name_added;
      var phone_validation_regex = {
        973: {
          prefix:
            "^(31|322|33|340|341|343|344|345|353|355|36|377|383|384|388|33|663|666|669)",
          length: [8],
        },
        965: {
          prefix: "^(5|6|9)",
          length: [8],
        },
        968: {
          prefix: "^(9)",
          length: [8],
        },
        974: {
          prefix: "^(33|55|66|77)",
          length: [8],
        },
        966: {
          prefix: "^(5)",
          length: [9],
        },
        971: {
          prefix: "^(50|55|52|56|54|58)",
          length: [9],
        },
        44: {
          prefix: "^(71|72|73|74|75|7624|77|78|79)",
          length: [10],
        },
        852: {
          prefix: "^(51|52|53|54|55|56|59|6|90|91|92|93|94|95|96|97|98)",
          length: [8],
        },
        86: {
          prefix: "^(13|15|18)",
          length: [11],
        },
        91: {
          prefix: "^(9|8|7|6)",
          length: [10],
        },
        27: {
          prefix:
            "^(60|710|711|712|713|714|715|716|717|718|719|72|73|74|741|76|78|79|811|812|813|814|815|82|83|84)",
          length: [9],
        },
      };
      try {
        var urlArray = window.location.href.split("?");
        if (urlArray && urlArray.length > 1) {
          var queries = urlArray[1].split("&");
          for (var i = 0; i < queries.length; i++) {
            if (queries[i].includes("utm_source=")) {
              src = queries[i].replace("utm_source=", "");
              src_date = new Date();
            }
          }
          if (src && src.length > 0) {
          } else {
            if (document && document.referrer && document.referrer.length > 0) {
              src = document.referrer;
              src_date = new Date();
            } else {
            }
          }
        } else {
          if (document && document.referrer && document.referrer.length > 0) {
            src = document.referrer;
            src_date = new Date();
          } else {
          }
        }
      } catch (e) { }
      var urls;
      var white_urls;
      var lat, lng, place_id;
      var body;
      var consentDiv;
      var multiLangDiv;
      var lang_json;
      var main_lang_code;
      var totalData;
      var cb_session;
      var live_chat_cb_session;
      var device_print;
      var mainDiv;
      var pushState = history.pushState;
      var is_online;
      var enable_live_online;
      var inTheMiddle;
      var shouldDisableTakeAction;
      var firstCustomSingleChoiceId;
      var firstCustomSingleChoiceSequence;
      var firstCustomSingleChoiceOptions;
      var language_code;
      var translations;
      var otp_validation;
      var old_otp_validation;
      var otp_verified;
      var device_blocked;
      var reload_div;
      var font_name = "bot-google-font";
      history.pushState = function () {
        pushState.apply(history, arguments);
        var urlDer;
        visitedUrls.push(window.location.href);
        if (white_urls && white_urls.length > 0) {
          for (var i = 0; i < white_urls.length; i++) {
            var url_without_starting = window.location.href;
            if (url_without_starting.includes("https://")) {
              url_without_starting = url_without_starting.replace("https://", "");
            }
            if (url_without_starting.includes("http://")) {
              url_without_starting = url_without_starting.replace("http://", "");
            }
            if (url_without_starting.includes("www.")) {
              url_without_starting = url_without_starting.replace("www.", "");
            }
            var current_url = white_urls[i];
            if (current_url.includes("https://")) {
              current_url = current_url.replace("https://", "");
            }
            if (current_url.includes("http://")) {
              current_url = current_url.replace("http://", "");
            }
            if (current_url.includes("www.")) {
              current_url = current_url.replace("www.", "");
            }
            if (url_without_starting.includes(current_url.trim())) {
              urlDer = !0;
            }
          }
          if (urlDer) {
            try {
              if (pulseDiv) {
                pulseDiv.style.display = "block";
              }
            } catch (e) {
            } finally {
            }
            if (document.getElementById("closed")) {
              document.getElementById("closed").style.display = "block";
            }
            if (
              document.getElementById("pulse") &&
              document.getElementById("pulse") != null
            ) {
              document.getElementById("pulse").style.display = "block";
            }
            if (
              !document.getElementById("opened") &&
              !document.getElementById("closed")
            ) {
              if (enable_live_online && is_online) {
              } else {
                if (
                  proceed_to_start_bot &&
                  !device_blocked
                ) {
                  if (!already_total_fn_loaded) {
                    totalFn();
                    already_total_fn_loaded = true;
                  }
                } else {
                  setTimeout(function () {
                    if (document.getElementById("pulse_smatbot_unique")) {
                      document.getElementById("pulse_smatbot_unique").innerHTML =
                        "";
                    }
                  }, 500);
                }
              }
            }
          } else {
            if (document.getElementById("opened")) {
              document.getElementById("opened").style.display = "none";
            }
            if (document.getElementById("closed")) {
              document.getElementById("closed").style.display = "block";
            }
            if (
              document.getElementById("pulse") &&
              document.getElementById("pulse") != null
            ) {
              document.getElementById("pulse").style.display = "block";
            }
            already_total_fn_loaded = false;
          }
        }
        if (urls && urls.length > 0) {
          for (var i = 0; i < urls.length; i++) {
            var url_without_starting = window.location.href;
            if (url_without_starting.includes("https://")) {
              url_without_starting = url_without_starting.replace("https://", "");
            }
            if (url_without_starting.includes("http://")) {
              url_without_starting = url_without_starting.replace("http://", "");
            }
            if (url_without_starting.includes("www.")) {
              url_without_starting = url_without_starting.replace("www.", "");
            }
            var current_url = urls[i];
            if (current_url.includes("https://")) {
              current_url = current_url.replace("https://", "");
            }
            if (current_url.includes("http://")) {
              current_url = current_url.replace("http://", "");
            }
            if (current_url.includes("www.")) {
              current_url = current_url.replace("www.", "");
            }
            if (url_without_starting.includes(current_url.trim())) {
              urlDer = !0;
            }
          }
          if (urlDer) {
            try {
              if (pulseDiv) {
                pulseDiv.style.display = "none";
              }
            } catch (e) {
            } finally {
            }
            if (document.getElementById("opened")) {
              document.getElementById("opened").style.display = "none";
            }
            if (document.getElementById("closed")) {
              document.getElementById("closed").style.display = "none";
            }
            if (
              document.getElementById("pulse") &&
              document.getElementById("pulse") != null
            ) {
              document.getElementById("pulse").style.display = "none";
            }
            already_total_fn_loaded = false;
          } else {
            if (document.getElementById("closed")) {
              document.getElementById("closed").style.display = "block";
            }
            if (
              document.getElementById("pulse") &&
              document.getElementById("pulse") != null
            ) {
              document.getElementById("pulse").style.display = "block";
            }
            if (
              !document.getElementById("opened") &&
              !document.getElementById("closed")
            ) {
              if (enable_live_online && is_online) {
              } else {
                if (
                  proceed_to_start_bot &&
                  !device_blocked
                ) {
                  if (!already_total_fn_loaded) {
                    totalFn();
                    already_total_fn_loaded = true;
                  }
                } else {
                  setTimeout(function () {
                    if (document.getElementById("pulse_smatbot_unique")) {
                      document.getElementById("pulse_smatbot_unique").innerHTML =
                        "";
                    }
                  }, 500);
                }
              }
            }
          }
        }
        if (is_first_question_url_flow && !atleastOneAnswered) {
          if (body && body.style.display == "block") {
            if (reload_div) {
              reload_div.click();
            }
          } else {
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                mainDiv.click();
              }
            };
            xhttp.open(
              "POST",
              main_url + "/kya_backend/pagehub/chatbot_utils?action=refresh_chat",
              !0
            );
            xhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            xhttp.send(
              "action=refresh_chat&cb_session=" +
              cb_session +
              "&chatbot_id=" +
              chatbot_id +
              "&device_print=" +
              device_print
            );
          }
        }
      };
      var user_country_code;
      var ip_address;
      var live_chat_ip_address;
      var live_chat_location;
      var user_dial_code;
      var user_location_enc;
      var chat_with_us_cliked;
      var main_fore;
      var call_fore;
      var user_location_array = [];
      var randomcountries = [
        {
          name: "Israel",
          dial_code: "+972",
          code: "IL",
        },
        {
          name: "Afghanistan",
          dial_code: "+93",
          code: "AF",
        },
        {
          name: "Albania",
          dial_code: "+355",
          code: "AL",
        },
        {
          name: "Algeria",
          dial_code: "+213",
          code: "DZ",
        },
        {
          name: "AmericanSamoa",
          dial_code: "+1 684",
          code: "AS",
        },
        {
          name: "Andorra",
          dial_code: "+376",
          code: "AD",
        },
        {
          name: "Angola",
          dial_code: "+244",
          code: "AO",
        },
        {
          name: "Anguilla",
          dial_code: "+1 264",
          code: "AI",
        },
        {
          name: "Antigua and Barbuda",
          dial_code: "+1268",
          code: "AG",
        },
        {
          name: "Argentina",
          dial_code: "+54",
          code: "AR",
        },
        {
          name: "Armenia",
          dial_code: "+374",
          code: "AM",
        },
        {
          name: "Aruba",
          dial_code: "+297",
          code: "AW",
        },
        {
          name: "Australia",
          dial_code: "+61",
          code: "AU",
        },
        {
          name: "Austria",
          dial_code: "+43",
          code: "AT",
        },
        {
          name: "Azerbaijan",
          dial_code: "+994",
          code: "AZ",
        },
        {
          name: "Bahamas",
          dial_code: "+1 242",
          code: "BS",
        },
        {
          name: "Bahrain",
          dial_code: "+973",
          code: "BH",
        },
        {
          name: "Bangladesh",
          dial_code: "+880",
          code: "BD",
        },
        {
          name: "Barbados",
          dial_code: "+1 246",
          code: "BB",
        },
        {
          name: "Belarus",
          dial_code: "+375",
          code: "BY",
        },
        {
          name: "Belgium",
          dial_code: "+32",
          code: "BE",
        },
        {
          name: "Belize",
          dial_code: "+501",
          code: "BZ",
        },
        {
          name: "Benin",
          dial_code: "+229",
          code: "BJ",
        },
        {
          name: "Bermuda",
          dial_code: "+1 441",
          code: "BM",
        },
        {
          name: "Bhutan",
          dial_code: "+975",
          code: "BT",
        },
        {
          name: "Bosnia and Herzegovina",
          dial_code: "+387",
          code: "BA",
        },
        {
          name: "Botswana",
          dial_code: "+267",
          code: "BW",
        },
        {
          name: "Brazil",
          dial_code: "+55",
          code: "BR",
        },
        {
          name: "British Indian Ocean Territory",
          dial_code: "+246",
          code: "IO",
        },
        {
          name: "Bulgaria",
          dial_code: "+359",
          code: "BG",
        },
        {
          name: "Burkina Faso",
          dial_code: "+226",
          code: "BF",
        },
        {
          name: "Burundi",
          dial_code: "+257",
          code: "BI",
        },
        {
          name: "Cambodia",
          dial_code: "+855",
          code: "KH",
        },
        {
          name: "Cameroon",
          dial_code: "+237",
          code: "CM",
        },
        {
          name: "Canada",
          dial_code: "+1",
          code: "CA",
        },
        {
          name: "Cape Verde",
          dial_code: "+238",
          code: "CV",
        },
        {
          name: "Cayman Islands",
          dial_code: "+ 345",
          code: "KY",
        },
        {
          name: "Central African Republic",
          dial_code: "+236",
          code: "CF",
        },
        {
          name: "Chad",
          dial_code: "+235",
          code: "TD",
        },
        {
          name: "Chile",
          dial_code: "+56",
          code: "CL",
        },
        {
          name: "China",
          dial_code: "+86",
          code: "CN",
        },
        {
          name: "Christmas Island",
          dial_code: "+61",
          code: "CX",
        },
        {
          name: "Colombia",
          dial_code: "+57",
          code: "CO",
        },
        {
          name: "Comoros",
          dial_code: "+269",
          code: "KM",
        },
        {
          name: "Congo",
          dial_code: "+242",
          code: "CG",
        },
        {
          name: "Cook Islands",
          dial_code: "+682",
          code: "CK",
        },
        {
          name: "Costa Rica",
          dial_code: "+506",
          code: "CR",
        },
        {
          name: "Croatia",
          dial_code: "+385",
          code: "HR",
        },
        {
          name: "Cuba",
          dial_code: "+53",
          code: "CU",
        },
        {
          name: "Cyprus",
          dial_code: "+537",
          code: "CY",
        },
        {
          name: "Czech Republic",
          dial_code: "+420",
          code: "CZ",
        },
        {
          name: "Denmark",
          dial_code: "+45",
          code: "DK",
        },
        {
          name: "Djibouti",
          dial_code: "+253",
          code: "DJ",
        },
        {
          name: "Dominica",
          dial_code: "+1 767",
          code: "DM",
        },
        {
          name: "Dominican Republic",
          dial_code: "+1 849",
          code: "DO",
        },
        {
          name: "Ecuador",
          dial_code: "+593",
          code: "EC",
        },
        {
          name: "Egypt",
          dial_code: "+20",
          code: "EG",
        },
        {
          name: "El Salvador",
          dial_code: "+503",
          code: "SV",
        },
        {
          name: "Equatorial Guinea",
          dial_code: "+240",
          code: "GQ",
        },
        {
          name: "Eritrea",
          dial_code: "+291",
          code: "ER",
        },
        {
          name: "Estonia",
          dial_code: "+372",
          code: "EE",
        },
        {
          name: "Ethiopia",
          dial_code: "+251",
          code: "ET",
        },
        {
          name: "Faroe Islands",
          dial_code: "+298",
          code: "FO",
        },
        {
          name: "Fiji",
          dial_code: "+679",
          code: "FJ",
        },
        {
          name: "Finland",
          dial_code: "+358",
          code: "FI",
        },
        {
          name: "France",
          dial_code: "+33",
          code: "FR",
        },
        {
          name: "French Guiana",
          dial_code: "+594",
          code: "GF",
        },
        {
          name: "French Polynesia",
          dial_code: "+689",
          code: "PF",
        },
        {
          name: "Gabon",
          dial_code: "+241",
          code: "GA",
        },
        {
          name: "Gambia",
          dial_code: "+220",
          code: "GM",
        },
        {
          name: "Georgia",
          dial_code: "+995",
          code: "GE",
        },
        {
          name: "Germany",
          dial_code: "+49",
          code: "DE",
        },
        {
          name: "Ghana",
          dial_code: "+233",
          code: "GH",
        },
        {
          name: "Gibraltar",
          dial_code: "+350",
          code: "GI",
        },
        {
          name: "Greece",
          dial_code: "+30",
          code: "GR",
        },
        {
          name: "Greenland",
          dial_code: "+299",
          code: "GL",
        },
        {
          name: "Grenada",
          dial_code: "+1 473",
          code: "GD",
        },
        {
          name: "Guadeloupe",
          dial_code: "+590",
          code: "GP",
        },
        {
          name: "Guam",
          dial_code: "+1 671",
          code: "GU",
        },
        {
          name: "Guatemala",
          dial_code: "+502",
          code: "GT",
        },
        {
          name: "Guinea",
          dial_code: "+224",
          code: "GN",
        },
        {
          name: "Guinea-Bissau",
          dial_code: "+245",
          code: "GW",
        },
        {
          name: "Guyana",
          dial_code: "+595",
          code: "GY",
        },
        {
          name: "Haiti",
          dial_code: "+509",
          code: "HT",
        },
        {
          name: "Honduras",
          dial_code: "+504",
          code: "HN",
        },
        {
          name: "Hungary",
          dial_code: "+36",
          code: "HU",
        },
        {
          name: "Iceland",
          dial_code: "+354",
          code: "IS",
        },
        {
          name: "India",
          dial_code: "+91",
          code: "IN",
        },
        {
          name: "Indonesia",
          dial_code: "+62",
          code: "ID",
        },
        {
          name: "Iraq",
          dial_code: "+964",
          code: "IQ",
        },
        {
          name: "Ireland",
          dial_code: "+353",
          code: "IE",
        },
        {
          name: "Israel",
          dial_code: "+972",
          code: "IL",
        },
        {
          name: "Italy",
          dial_code: "+33",
          code: "IT",
        },
        {
          name: "Jamaica",
          dial_code: "+1 876",
          code: "JM",
        },
        {
          name: "Japan",
          dial_code: "+81",
          code: "JP",
        },
        {
          name: "Jordan",
          dial_code: "+962",
          code: "JO",
        },
        {
          name: "Kazakhstan",
          dial_code: "+7 7",
          code: "KZ",
        },
        {
          name: "Kenya",
          dial_code: "+254",
          code: "KE",
        },
        {
          name: "Kiribati",
          dial_code: "+686",
          code: "KI",
        },
        {
          name: "Kuwait",
          dial_code: "+965",
          code: "KW",
        },
        {
          name: "Kyrgyzstan",
          dial_code: "+996",
          code: "KG",
        },
        {
          name: "Latvia",
          dial_code: "+371",
          code: "LV",
        },
        {
          name: "Lebanon",
          dial_code: "+961",
          code: "LB",
        },
        {
          name: "Lesotho",
          dial_code: "+266",
          code: "LS",
        },
        {
          name: "Liberia",
          dial_code: "+231",
          code: "LR",
        },
        {
          name: "Liechtenstein",
          dial_code: "+423",
          code: "LI",
        },
        {
          name: "Lithuania",
          dial_code: "+370",
          code: "LT",
        },
        {
          name: "Luxembourg",
          dial_code: "+352",
          code: "LU",
        },
        {
          name: "Madagascar",
          dial_code: "+261",
          code: "MG",
        },
        {
          name: "Malawi",
          dial_code: "+265",
          code: "MW",
        },
        {
          name: "Malaysia",
          dial_code: "+60",
          code: "MY",
        },
        {
          name: "Maldives",
          dial_code: "+960",
          code: "MV",
        },
        {
          name: "Mali",
          dial_code: "+223",
          code: "ML",
        },
        {
          name: "Malta",
          dial_code: "+356",
          code: "MT",
        },
        {
          name: "Marshall Islands",
          dial_code: "+692",
          code: "MH",
        },
        {
          name: "Martinique",
          dial_code: "+596",
          code: "MQ",
        },
        {
          name: "Mauritania",
          dial_code: "+222",
          code: "MR",
        },
        {
          name: "Mauritius",
          dial_code: "+230",
          code: "MU",
        },
        {
          name: "Mayotte",
          dial_code: "+262",
          code: "YT",
        },
        {
          name: "Mexico",
          dial_code: "+52",
          code: "MX",
        },
        {
          name: "Monaco",
          dial_code: "+377",
          code: "MC",
        },
        {
          name: "Mongolia",
          dial_code: "+976",
          code: "MN",
        },
        {
          name: "Montenegro",
          dial_code: "+382",
          code: "ME",
        },
        {
          name: "Montserrat",
          dial_code: "+1664",
          code: "MS",
        },
        {
          name: "Morocco",
          dial_code: "+212",
          code: "MA",
        },
        {
          name: "Myanmar",
          dial_code: "+95",
          code: "MM",
        },
        {
          name: "Namibia",
          dial_code: "+264",
          code: "NA",
        },
        {
          name: "Nauru",
          dial_code: "+674",
          code: "NR",
        },
        {
          name: "Nepal",
          dial_code: "+977",
          code: "NP",
        },
        {
          name: "Netherlands",
          dial_code: "+31",
          code: "NL",
        },
        {
          name: "Netherlands Antilles",
          dial_code: "+599",
          code: "AN",
        },
        {
          name: "New Caledonia",
          dial_code: "+687",
          code: "NC",
        },
        {
          name: "New Zealand",
          dial_code: "+64",
          code: "NZ",
        },
        {
          name: "Nicaragua",
          dial_code: "+505",
          code: "NI",
        },
        {
          name: "Niger",
          dial_code: "+227",
          code: "NE",
        },
        {
          name: "Nigeria",
          dial_code: "+234",
          code: "NG",
        },
        {
          name: "Niue",
          dial_code: "+683",
          code: "NU",
        },
        {
          name: "Norfolk Island",
          dial_code: "+672",
          code: "NF",
        },
        {
          name: "Northern Mariana Islands",
          dial_code: "+1 670",
          code: "MP",
        },
        {
          name: "Norway",
          dial_code: "+47",
          code: "NO",
        },
        {
          name: "Oman",
          dial_code: "+968",
          code: "OM",
        },
        {
          name: "Pakistan",
          dial_code: "+92",
          code: "PK",
        },
        {
          name: "Palau",
          dial_code: "+680",
          code: "PW",
        },
        {
          name: "Panama",
          dial_code: "+507",
          code: "PA",
        },
        {
          name: "Papua New Guinea",
          dial_code: "+675",
          code: "PG",
        },
        {
          name: "Paraguay",
          dial_code: "+595",
          code: "PY",
        },
        {
          name: "Peru",
          dial_code: "+51",
          code: "PE",
        },
        {
          name: "Philippines",
          dial_code: "+63",
          code: "PH",
        },
        {
          name: "Poland",
          dial_code: "+48",
          code: "PL",
        },
        {
          name: "Portugal",
          dial_code: "+351",
          code: "PT",
        },
        {
          name: "Puerto Rico",
          dial_code: "+1 933",
          code: "PR",
        },
        {
          name: "Qatar",
          dial_code: "+974",
          code: "QA",
        },
        {
          name: "Romania",
          dial_code: "+40",
          code: "RO",
        },
        {
          name: "Rwanda",
          dial_code: "+250",
          code: "RW",
        },
        {
          name: "Samoa",
          dial_code: "+685",
          code: "WS",
        },
        {
          name: "San Marino",
          dial_code: "+378",
          code: "SM",
        },
        {
          name: "Saudi Arabia",
          dial_code: "+966",
          code: "SA",
        },
        {
          name: "Senegal",
          dial_code: "+221",
          code: "SN",
        },
        {
          name: "Serbia",
          dial_code: "+381",
          code: "RS",
        },
        {
          name: "Seychelles",
          dial_code: "+248",
          code: "SC",
        },
        {
          name: "Sierra Leone",
          dial_code: "+232",
          code: "SL",
        },
        {
          name: "Singapore",
          dial_code: "+65",
          code: "SG",
        },
        {
          name: "Slovakia",
          dial_code: "+421",
          code: "SK",
        },
        {
          name: "Slovenia",
          dial_code: "+386",
          code: "SI",
        },
        {
          name: "Solomon Islands",
          dial_code: "+677",
          code: "SB",
        },
        {
          name: "South Africa",
          dial_code: "+27",
          code: "ZA",
        },
        {
          name: "South Georgia and the South Sandwich Islands",
          dial_code: "+500",
          code: "GS",
        },
        {
          name: "Spain",
          dial_code: "+34",
          code: "ES",
        },
        {
          name: "Sri Lanka",
          dial_code: "+94",
          code: "LK",
        },
        {
          name: "Sudan",
          dial_code: "+249",
          code: "SD",
        },
        {
          name: "Suriname",
          dial_code: "+597",
          code: "SR",
        },
        {
          name: "Swaziland",
          dial_code: "+268",
          code: "SZ",
        },
        {
          name: "Sweden",
          dial_code: "+46",
          code: "SE",
        },
        {
          name: "Switzerland",
          dial_code: "+41",
          code: "CH",
        },
        {
          name: "Tajikistan",
          dial_code: "+992",
          code: "TJ",
        },
        {
          name: "Thailand",
          dial_code: "+66",
          code: "TH",
        },
        {
          name: "Togo",
          dial_code: "+228",
          code: "TG",
        },
        {
          name: "Tokelau",
          dial_code: "+690",
          code: "TK",
        },
        {
          name: "Tonga",
          dial_code: "+676",
          code: "TO",
        },
        {
          name: "Trinidad and Tobago",
          dial_code: "+1 868",
          code: "TT",
        },
        {
          name: "Tunisia",
          dial_code: "+216",
          code: "TN",
        },
        {
          name: "Turkey",
          dial_code: "+90",
          code: "TR",
        },
        {
          name: "Turkmenistan",
          dial_code: "+993",
          code: "TM",
        },
        {
          name: "Turks and Caicos Islands",
          dial_code: "+1 649",
          code: "TC",
        },
        {
          name: "Tuvalu",
          dial_code: "+688",
          code: "TV",
        },
        {
          name: "Uganda",
          dial_code: "+256",
          code: "UG",
        },
        {
          name: "Ukraine",
          dial_code: "+380",
          code: "UA",
        },
        {
          name: "United Arab Emirates",
          dial_code: "+971",
          code: "AE",
        },
        {
          name: "United Kingdom",
          dial_code: "+44",
          code: "GB",
        },
        {
          name: "United States",
          dial_code: "+1",
          code: "US",
        },
        {
          name: "Uruguay",
          dial_code: "+598",
          code: "UY",
        },
        {
          name: "Uzbekistan",
          dial_code: "+998",
          code: "UZ",
        },
        {
          name: "Vanuatu",
          dial_code: "+678",
          code: "VU",
        },
        {
          name: "Wallis and Futuna",
          dial_code: "+681",
          code: "WF",
        },
        {
          name: "Yemen",
          dial_code: "+967",
          code: "YE",
        },
        {
          name: "Zambia",
          dial_code: "+260",
          code: "ZM",
        },
        {
          name: "Zimbabwe",
          dial_code: "+263",
          code: "ZW",
        },
        {
          name: "land Islands",
          dial_code: "",
          code: "AX",
        },
        {
          name: "Antarctica",
          dial_code: null,
          code: "AQ",
        },
        {
          name: "Bolivia, Plurinational State of",
          dial_code: "+591",
          code: "BO",
        },
        {
          name: "Brunei Darussalam",
          dial_code: "+673",
          code: "BN",
        },
        {
          name: "Cocos (Keeling) Islands",
          dial_code: "+61",
          code: "CC",
        },
        {
          name: "Congo, The Democratic Republic of the",
          dial_code: "+243",
          code: "CD",
        },
        {
          name: "Cote d'Ivoire",
          dial_code: "+225",
          code: "CI",
        },
        {
          name: "Falkland Islands (Malvinas)",
          dial_code: "+500",
          code: "FK",
        },
        {
          name: "Guernsey",
          dial_code: "+44",
          code: "GG",
        },
        {
          name: "Holy See (Vatican City State)",
          dial_code: "+379",
          code: "VA",
        },
        {
          name: "Hong Kong",
          dial_code: "+852",
          code: "HK",
        },
        {
          name: "Iran, Islamic Republic of",
          dial_code: "+98",
          code: "IR",
        },
        {
          name: "Isle of Man",
          dial_code: "+44",
          code: "IM",
        },
        {
          name: "Jersey",
          dial_code: "+44",
          code: "JE",
        },
        {
          name: "Korea, Democratic People's Republic of",
          dial_code: "+850",
          code: "KP",
        },
        {
          name: "Korea, Republic of",
          dial_code: "+82",
          code: "KR",
        },
        {
          name: "Lao People's Democratic Republic",
          dial_code: "+856",
          code: "LA",
        },
        {
          name: "Libyan Arab Jamahiriya",
          dial_code: "+218",
          code: "LY",
        },
        {
          name: "Macao",
          dial_code: "+853",
          code: "MO",
        },
        {
          name: "Macedonia, The Former Yugoslav Republic of",
          dial_code: "+389",
          code: "MK",
        },
        {
          name: "Micronesia, Federated States of",
          dial_code: "+691",
          code: "FM",
        },
        {
          name: "Moldova, Republic of",
          dial_code: "+373",
          code: "MD",
        },
        {
          name: "Mozambique",
          dial_code: "+258",
          code: "MZ",
        },
        {
          name: "Palestinian Territory, Occupied",
          dial_code: "+970",
          code: "PS",
        },
        {
          name: "Pitcairn",
          dial_code: "+872",
          code: "PN",
        },
        {
          name: "R\u00e9union",
          dial_code: "+262",
          code: "RE",
        },
        {
          name: "Russia",
          dial_code: "+7",
          code: "RU",
        },
        {
          name: "Saint Barth\u00e9lemy",
          dial_code: "+590",
          code: "BL",
        },
        {
          name: "Saint Helena, Ascension and Tristan Da Cunha",
          dial_code: "+290",
          code: "SH",
        },
        {
          name: "Saint Kitts and Nevis",
          dial_code: "+1 869",
          code: "KN",
        },
        {
          name: "Saint Lucia",
          dial_code: "+1 758",
          code: "LC",
        },
        {
          name: "Saint Martin",
          dial_code: "+590",
          code: "MF",
        },
        {
          name: "Saint Pierre and Miquelon",
          dial_code: "+508",
          code: "PM",
        },
        {
          name: "Saint Vincent and the Grenadines",
          dial_code: "+1 784",
          code: "VC",
        },
        {
          name: "Sao Tome and Principe",
          dial_code: "+233",
          code: "ST",
        },
        {
          name: "Somalia",
          dial_code: "+252",
          code: "SO",
        },
        {
          name: "Svalbard and Jan Mayen",
          dial_code: "+47",
          code: "SJ",
        },
        {
          name: "Syrian Arab Republic",
          dial_code: "+963",
          code: "SY",
        },
        {
          name: "Taiwan, Province of China",
          dial_code: "+886",
          code: "TW",
        },
        {
          name: "Tanzania, United Republic of",
          dial_code: "+255",
          code: "TZ",
        },
        {
          name: "Timor-Leste",
          dial_code: "+670",
          code: "TL",
        },
        {
          name: "Venezuela, Bolivarian Republic of",
          dial_code: "+58",
          code: "VE",
        },
        {
          name: "Viet Nam",
          dial_code: "+84",
          code: "VN",
        },
        {
          name: "Virgin Islands, British",
          dial_code: "+1 284",
          code: "VG",
        },
        {
          name: "Virgin Islands, U.S.",
          dial_code: "+1 340",
          code: "VI",
        },
      ];
      var countries = randomcountries.map((item) => {
        return item.name + " " + item.dial_code;
      });

      function ipLookUp() {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
          if (this.readyState == 4 && this.status == 200) {
            user_country_code = JSON.parse(this.responseText).response.country_code;
            ip_address = JSON.parse(this.responseText).response.IPv4;
            live_chat_ip_address = JSON.parse(this.responseText).response
              .IPv4_livechat;
            live_chat_location = JSON.parse(this.responseText).response
              .location_livechat;
            if (banned_ips && banned_ips.length > 0) {
              for (var i = 0; i < banned_ips.length; i++) {
                if (banned_ips[i].banned_ip == ip_address) {
                  ip_is_banned = true;
                  banned_reason = banned_ips[i].reason;
                }
              }
            }
            if (
              JSON.parse(this.responseText).response.location &&
              JSON.parse(this.responseText).response.location.length > 0
            ) {
              user_location_enc = JSON.parse(this.responseText).response.location;
            }
            countries = [];
            for (var i = 0; i < randomcountries.length; i++) {
              if (chatbot_id == "19819" || chatbot_id == "18664" || chatbot_id == "20097") {
                if (countries.indexOf(randomcountries[i].dial_code) === -1) {
                  countries.push(randomcountries[i].dial_code);
                }
              } else {
                countries.push(
                  randomcountries[i].name + " " + randomcountries[i].dial_code
                );
              }
            }
            countries.sort();
            for (var i = 0; i < randomcountries.length; i++) {
              if (chatbot_id == "19819" || chatbot_id == "18664" || chatbot_id == "20097") {
                if (randomcountries[i].code == user_country_code) {
                  user_dial_code = randomcountries[i].dial_code;
                }
              } else {
                if (randomcountries[i].code == user_country_code) {
                  user_dial_code =
                    randomcountries[i].name + " " + randomcountries[i].dial_code;
                }
              }
            }
          }
        };
        xhttp.open("GET", main_url + "/kya_backend/api/geoIp", !0);
        xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.send();
      }
      ipLookUp();
      if (chatbot_id) {
      } else {
        if (document.getElementById("pulse_smatbot_unique")) {
          document.getElementById("pulse_smatbot_unique").innerHTML = "";
        }
      }
      var is_safari;
      var is_firefox;
      var ua = navigator.userAgent.toLowerCase();
      if (ua.indexOf("safari") != -1) {
        if (ua.indexOf("chrome") > -1) {
        } else {
          is_safari = !0;
        }
      }
      if (ua.indexOf("firefox") != -1) {
        if (ua.indexOf("chrome") > -1) {
        } else {
          is_firefox = !0;
        }
      }
      var is_speech_on;
      var is_sound_on;
      var voices;
      setInterval(function () {
        if (voices && voices.length > 0) {
        } else {
          voices = speechSynthesis.getVoices();
        }
      }, 100);

      function closeAudio() {
        var audio = document.getElementById("audioPlayback");
        if (audio) {
          audio.duration = "";
          document.getElementById("audioSource").src = "";
        }
      }

      let audio_going_on = false, speechQueue = [];

      function processQueue() {
        console.log("Queue Length: ", speechQueue.length); // Log current queue length
        if (speechQueue.length > 0 && !audio_going_on) {
          const { message, id } = speechQueue.shift(); // Get the first item from the queue
          audio_going_on = true; // Set flag when starting speech synthesis
          console.log("Processing speech for ID:", id);
          saySpeech(message, id);
        } else {
          console.log("Either queue is empty or audio is already ongoing.");
        }
      }

      let sdk, speechConfig, audioConfig, synthesizer, player, audioElement;

      function removeOrReplaceUrls(text, urlReplacement = "a link", bracketsReplacement = "") {
        const urlPattern = /(\b(https?|ftp|file):\/\/[\w+&@#\/%=~_|!:,.;?-]+[\w+&@#\/%=~_|])/ig;
        return text.replace(urlPattern, urlReplacement);
      }

      let azure_language_voices = [{
        lang: "ar",
        lang_code: "ar-AE",
        female_name: "ar-AE-FatimaNeural",
        male_name: "ar-AE-HamdanNeural",
      }, {
        lang: "da",
        lang_code: "da-DK",
        female_name: "da-DK-ChristelNeural",
        male_name: "da-DK-JeppeNeural",
      }, {
        lang: "nl",
        lang_code: "nl-NL",
        female_name: "nl-NL-FennaNeural",
        male_name: "nl-NL-MaartenNeural",
      }, {
        lang: "fr",
        lang_code: "fr-FR",
        female_name: "fr-FR-DeniseNeural",
        male_name: "fr-FR-HenriNeural",
      }, {
        lang: "de",
        lang_code: "de-DE",
        female_name: "de-DE-KatjaNeural",
        male_name: "de-DE-ConradNeural",
      }, {
        lang: "hi",
        lang_code: "hi-IN",
        female_name: "hi-IN-SwaraNeural",
        male_name: "hi-IN-MadhurNeural",
      }, {
        lang: "it",
        lang_code: "it-IT",
        female_name: "it-IT-ElsaNeural",
        male_name: "it-IT-DiegoNeural",
      }, {
        lang: "ja-Hani",
        lang_code: "ja-JP",
        female_name: "ja-JP-NanamiNeural",
        male_name: "ja-JP-KeitaNeural",
      }, {
        lang: "ko",
        lang_code: "ko-KR",
        female_name: "ko-KR-SunHiNeural",
        male_name: "ko-KR-InJoonNeural",
      }, {
        lang: "no",
        lang_code: "nb-NO",
        female_name: "nb-NO-PernilleNeural",
        male_name: "nb-NO-FinnNeural",
      }, {
        lang: "no",
        lang_code: "nb-NO",
        female_name: "nb-NO-PernilleNeural",
        male_name: "nb-NO-FinnNeural",
      }, {
        lang: "pl",
        lang_code: "pl-PL",
        female_name: "pl-PL-AgnieszkaNeural",
        male_name: "pl-PL-MarekNeural",
      }, {
        lang: "pt",
        lang_code: "pt-PT",
        female_name: "pt-PT-RaquelNeural",
        male_name: "pt-PT-DuarteNeural",
      }, {
        lang: "pt-BR",
        lang_code: "pt-BR",
        female_name: "pt-BR-FranciscaNeural",
        male_name: "pt-BR-AntonioNeural",
      }, {
        lang: "ro",
        lang_code: "ro-RO",
        female_name: "ro-RO-AlinaNeural",
        male_name: "ro-RO-EmilNeural",
      }, {
        lang: "es",
        lang_code: "es-ES",
        female_name: "es-ES-ElviraNeural",
        male_name: "es-ES-AlvaroNeural",
      }, {
        lang: "sv",
        lang_code: "sv-SE",
        female_name: "sv-SE-SofieNeural",
        male_name: "sv-SE-MattiasNeural",
      }, {
        lang: "tr",
        lang_code: "tr-TR",
        female_name: "tr-TR-EmelNeural",
        male_name: "tr-TR-AhmetNeural",
      }, {
        lang: "te",
        lang_code: "te-IN",
        female_name: "te-IN-ShrutiNeural",
        male_name: "te-IN-MohanNeural",
      }, {
        lang: "ta",
        lang_code: "ta-IN",
        female_name: "ta-IN-PallaviNeural",
        male_name: "ta-IN-ValluvarNeural",
      }, {
        lang: "ml",
        lang_code: "ml-IN",
        female_name: "ml-IN-SobhanaNeural",
        male_name: "ml-IN-MidhunNeural",
      }, {
        lang: "bn",
        lang_code: "bn-IN",
        female_name: "bn-IN-TanishaaNeural",
        male_name: "bn-IN-BashkarNeural",
      }, {
        lang: "bn",
        lang_code: "bn-IN",
        female_name: "bn-IN-TanishaaNeural",
        male_name: "bn-IN-BashkarNeural",
      }, {
        lang: "gu",
        lang_code: "gu-IN",
        female_name: "gu-IN-DhwaniNeural",
        male_name: "gu-IN-NiranjanNeural",
      }, {
        lang: "kn",
        lang_code: "kn-IN",
        female_name: "kn-IN-SapnaNeural",
        male_name: "kn-IN-GaganNeural",
      }, {
        lang: "kn",
        lang_code: "kn-IN",
        female_name: "kn-IN-SapnaNeural",
        male_name: "kn-IN-GaganNeural",
      }, {
        lang: "mr",
        lang_code: "mr-IN",
        female_name: "mr-IN-AarohiNeural",
        male_name: "mr-IN-ManoharNeural",
      }, {
        lang: "or",
        lang_code: "or-IN",
        female_name: "or-IN-SubhasiniNeural",
        male_name: "or-IN-SukantNeural",
      }, {
        lang: "ur",
        lang_code: "ur-PK",
        female_name: "ur-PK-UzmaNeural",
        male_name: "ur-PK-AsadNeural",
      }]

      function saySpeech(message, id) {
        message = removeOrReplaceUrls(message);
        if (main_lang_code == 'en' || (main_lang_code == 'default' && language_code == 'en')) {
          const bracketsPattern = /\[.*?\]/g;
          const bracketsOtherPattern = /\(.*?\)/g;
          const specialCharsPattern = /[^\w\s,.!?;:'"-]/g;
          message = message.replace(specialCharsPattern, '').replace(bracketsPattern, '').replace(bracketsOtherPattern, '');
        }
        let str = message.replace(/\d+/g, match => match.split("").join(" "));
        let voice_name, speech_language;
        const subscriptionKey = "df2d60048d204bf6a00b7b85e2d92405";
        const serviceRegion = "eastus";
        sdk = window.SpeechSDK;

        if (!sdk) {
          console.error("Speech SDK not found!");
          return;
        }

        speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);

        if (main_lang_code == 'default') {
          main_lang_code = language_code;
        }
        if (main_lang_code && main_lang_code != 'en') {
          for (let lang_index = 0; lang_index < azure_language_voices.length; lang_index++) {
            let single_language = azure_language_voices[lang_index];
            if (single_language.lang == main_lang_code) {
              speechConfig.speechSynthesisLanguage = single_language.lang_code;
              speech_language = single_language.lang_code;
              if (is_female_voice) {
                speechConfig.speechSynthesisVoiceName = single_language.female_name;
                voice_name = single_language.female_name;
              } else {
                speechConfig.speechSynthesisVoiceName = single_language.male_name;
                voice_name = single_language.male_name;
              }
              break;
            }
          }
        } else {
          if (is_female_voice) {
            voice_name = "en-US-AvaMultilingualNeural";
            speech_language = "en-US";
          }
          else {
            voice_name = "en-US-AndrewMultilingualNeural"
            speech_language = "en-US";
          }
        }
        player = new sdk.SpeakerAudioDestination();
        audioConfig = sdk.AudioConfig.fromSpeakerOutput(player);
        synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);


        let ssml = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="` + speech_language + `">
                      <voice name="`+ voice_name + `">
                        <prosody rate="+10%">`+ str + `</prosody>
                      </voice>
                    </speak>`;


        synthesizer.speakSsmlAsync(
          ssml,
          result => {

            if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {

              const mp3Supported = 'MediaSource' in window && MediaSource.isTypeSupported('audio/mpeg');

              const audio = document.createElement('audio');
              const canPlayWav = audio.canPlayType('audio/wav') !== "";
              const canPlayOgg = audio.canPlayType('audio/ogg') !== "";

              if (!mp3Supported && is_firefox) {

                let audioType = '';
                let mimeType = '';

                if (canPlayOgg) {
                  audioType = 'audio/ogg';
                  mimeType = 'audio/ogg; codecs="opus"';
                } else if (canPlayWav) {
                  audioType = 'audio/wav';
                  mimeType = 'audio/wav';
                } else {
                  console.error("No compatible audio format found.");
                  audio_going_on = false;
                  processQueue();
                  return;
                }

                const audioBlob = new Blob([result.audioData], { type: mimeType });
                const audioUrl = URL.createObjectURL(audioBlob);
                audioElement = new Audio(audioUrl);

                audioElement.play().then(() => {
                  console.log(`Playing audio as ${audioType}.`);
                }).catch(error => {
                  console.error("Error playing audio:", error);
                });

                audioElement.onended = () => {
                  URL.revokeObjectURL(audioUrl);
                  audio_going_on = false;
                  processQueue();
                };
              } else {

                console.log("MP3 supported. Speech synthesis completed.");
                setTimeout(() => {
                  audio_going_on = false;
                  processQueue();
                }, ((result.privAudioDuration / 10000)));
              }
            }

          },
          error => {
            console.error("Speech synthesis failed: ", error);
            audio_going_on = false;
            processQueue();
          }
        );
      }

      function say(m, id) {
        if (is_sound_on) {
          speechQueue.push({ message: m, id }); // Add new message to the queue
          console.log("Added to queue:", m);
          processQueue();
        }
      }
      var alredyTherePhoneProper;
      var alredyTherePhone;
      var alredyThereEmail;
      var all_languages = [
        {
          id: "1",
          language: "Bosnian",
          google_code: "bs",
          iso_code: "bs",
          script_form: "bäznēən",
        },
        {
          id: "2",
          language: "Brazilian",
          google_code: "pt",
          iso_code: "pt-BR",
          script_form: "Brazilian Portuguese",
        },
        {
          id: "3",
          language: "Portuguese",
          google_code: "pt",
          iso_code: "pt",
          script_form: "Português",
        },
        {
          id: "4",
          language: "Bulgarian",
          google_code: "bg",
          iso_code: "bg",
          script_form: "Български",
        },
        {
          id: "5",
          language: "Catalan",
          google_code: "ca",
          iso_code: "ca",
          script_form: "Català",
        },
        {
          id: "6",
          language: "Croatian",
          google_code: "hr",
          iso_code: "hr",
          script_form: "Hrvatski",
        },
        {
          id: "7",
          language: "Czech",
          google_code: "cs",
          iso_code: "cs",
          script_form: "Česky",
        },
        {
          id: "8",
          language: "Danish",
          google_code: "da",
          iso_code: "da",
          script_form: "Dansk",
        },
        {
          id: "9",
          language: "Dutch",
          google_code: "nl",
          iso_code: "nl",
          script_form: "Nederlands",
        },
        {
          id: "10",
          language: "English",
          google_code: "en",
          iso_code: "en",
          script_form: "English",
        },
        {
          id: "11",
          language: "Estonian",
          google_code: "et",
          iso_code: "et",
          script_form: "Eesti",
        },
        {
          id: "12",
          language: "Finnish",
          google_code: "fi",
          iso_code: "fi",
          script_form: "Suomi",
        },
        {
          id: "13",
          language: "French",
          google_code: "fr",
          iso_code: "fr",
          script_form: "Français",
        },
        {
          id: "14",
          language: "German",
          google_code: "de",
          iso_code: "de",
          script_form: "Deutsch",
        },
        {
          id: "15",
          language: "Greek",
          google_code: "el",
          iso_code: "el",
          script_form: "Ελληνικά",
        },
        {
          id: "16",
          language: "Hebrew",
          google_code: "iw",
          iso_code: "he",
          script_form: "עברית",
        },
        {
          id: "17",
          language: "Hungarian",
          google_code: "hu",
          iso_code: "hu",
          script_form: "Magyar",
        },
        {
          id: "18",
          language: "Indonesian",
          google_code: "id",
          iso_code: "id",
          script_form: "Bahasa Indonesia",
        },
        {
          id: "19",
          language: "Italian",
          google_code: "it",
          iso_code: "it",
          script_form: "Italiano",
        },
        {
          id: "20",
          language: "Japanese",
          google_code: "ja",
          iso_code: "ja-Hani",
          script_form: "日本語",
        },
        {
          id: "21",
          language: "Korean",
          google_code: "ko",
          iso_code: "ko",
          script_form: "\t한국어",
        },
        {
          id: "22",
          language: "Latvian",
          google_code: "lv",
          iso_code: "lv",
          script_form: "Latviešu",
        },
        {
          id: "23",
          language: "Lithuanian",
          google_code: "lt",
          iso_code: "lt",
          script_form: "Lietuvių",
        },
        {
          id: "24",
          language: "Mongolian",
          google_code: "mn",
          iso_code: "mn",
          script_form: "Монгол",
        },
        {
          id: "25",
          language: "Norwegian",
          google_code: "no",
          iso_code: "no",
          script_form: "Norsk ",
        },
        {
          id: "26",
          language: "Polish",
          google_code: "pl",
          iso_code: "pl",
          script_form: "Polski",
        },
        {
          id: "27",
          language: "Romanian",
          google_code: "ro",
          iso_code: "ro",
          script_form: "Română",
        },
        {
          id: "28",
          language: "Russian",
          google_code: "ru",
          iso_code: "ru",
          script_form: "Русский",
        },
        {
          id: "29",
          language: "Serbian",
          google_code: "sr",
          iso_code: "sr",
          script_form: "Српски",
        },
        {
          id: "30",
          language: "Simplified Chinese",
          google_code: "zh-CN",
          iso_code: "zh-Hans",
          script_form: "閩東語",
        },
        {
          id: "31",
          language: "Slovene",
          google_code: "sl",
          iso_code: "sl",
          script_form: "Slovenščina",
        },
        {
          id: "32",
          language: "Spanish",
          google_code: "es",
          iso_code: "es",
          script_form: "Español",
        },
        {
          id: "33",
          language: "Swedish",
          google_code: "sv",
          iso_code: "sv",
          script_form: "Svenska",
        },
        {
          id: "34",
          language: "Traditional Chinese",
          google_code: "zh-TW",
          iso_code: "zh-Hant",
          script_form: "中文",
        },
        {
          id: "35",
          language: "Turkish",
          google_code: "tr",
          iso_code: "tr",
          script_form: "Türkçe",
        },
        {
          id: "36",
          language: "Vietnamese",
          google_code: "vi",
          iso_code: "vi",
          script_form: "Việtnam",
        },
        {
          id: "37",
          language: "Hindi",
          google_code: "hi",
          iso_code: "hi",
          script_form: "हिन्दी",
        },
        {
          id: "38",
          language: "Bengali",
          google_code: "bn",
          iso_code: "bn",
          script_form: "বাংলা",
        },
        {
          id: "33",
          language: "Telugu",
          google_code: "te",
          iso_code: "te",
          script_form: "తెలుగు",
        },
        {
          id: "40",
          language: "Marathi",
          google_code: "mr",
          iso_code: "mr",
          script_form: "मराठी",
        },
        {
          id: "41",
          language: "Tamil",
          google_code: "ta",
          iso_code: "ta",
          script_form: "தமிழ்",
        },
        {
          id: "42",
          language: "Urdu",
          google_code: "ur",
          iso_code: "ur",
          script_form: "اردو",
        },
        {
          id: "43",
          language: "Kannada",
          google_code: "kn",
          iso_code: "kn",
          script_form: "ಕನ್ನಡ",
        },
        {
          id: "44",
          language: "Gujarati",
          google_code: "gu",
          iso_code: "gu",
          script_form: "ગુજરાતી",
        },
        {
          id: "45",
          language: "Malayalam",
          google_code: "ml",
          iso_code: "ml",
          script_form: "മലയാളം",
        },
        {
          id: "46",
          language: "Punjabi",
          google_code: "pa",
          iso_code: "pa",
          script_form: "पंजाबी ",
        },
        {
          id: "47",
          language: "Arabic",
          google_code: "ar",
          iso_code: "ar",
          script_form: "العربية",
        },
        {
          id: "48",
          language: "Thai",
          google_code: "th",
          iso_code: "th",
          script_form: "ไทย ",
        },
        {
          id: "49",
          language: "Ukrainian",
          google_code: "uk",
          iso_code: "uk",
          script_form: "Українська",
        },
        {
          id: "50",
          language: "Basque",
          google_code: "eu",
          iso_code: "eu",
          script_form: "Euskara",
        },
        {
          id: "51",
          language: "Irish",
          google_code: "ga",
          iso_code: "ga",
          script_form: "Gaeilge",
        },
        {
          id: "52",
          language: "Maltese",
          google_code: "mt",
          iso_code: "mt",
          script_form: "bil-Malti",
        },
        {
          id: "53",
          language: "Oriya",
          google_code: "or",
          iso_code: "or",
          script_form: "ଓଡିଆ",
        },
        {
          id: "54",
          language: "Nepali",
          google_code: "ne",
          iso_code: "ne",
          script_form: "नेपाली",
        },
      ];
      var skip_otp_validation;

      function difference(arr1, arr2) {
        return arr1.filter(function (i) {
          return arr2.indexOf(i) < 0;
        });
      }
      var shouldShowFullFeedback;
      var shouldShowMenu;
      var menu_options_array;
      var menu_option_question_id;
      var menu_option_sequence;
      var email_timestamp;
      var atleastOneAnswered;
      var is_first_question_url_flow;
      var is_user_answered_session;
      var nothingWentOnFor;
      var encourageMessageIteration = 0;
      var shouldStartEncourageTimer;
      var isTableOpened;
      var ua = navigator.userAgent.toLowerCase();
      var check = function (r) {
        return r.test(ua);
      };
      var DOC = document;
      var isStrict = DOC.compatMode == "CSS1Compat";
      var isOpera = check(/opr/);
      var isChrome = check(/chrome/);
      var isWebKit = check(/webkit/);
      var isSafari = !isChrome && check(/safari/);
      var isIE = !isOpera && check(/msie/);
      var isIE7 = isIE && check(/msie 7/);
      var isIE8 = isIE && check(/msie 8/);
      var isIE6 = isIE && !isIE7 && !isIE8;
      var isGecko = !isWebKit && check(/gecko/);
      var isGecko2 = isGecko && check(/rv:1\.8/);
      var isGecko3 = isGecko && check(/rv:1\.9/);
      var isWindows = check(/windows|win32/);
      var isMac = check(/macintosh|mac os x/);
      var isLinux = check(/linux/);
      var jsType = "",
        browserType = "",
        browserVersion = "",
        osName = "";
      var ua = navigator.userAgent.toLowerCase();
      var check = function (r) {
        return r.test(ua);
      };
      if (isWindows) {
        osName = "Windows";
        if (check(/windows nt/)) {
          var start = ua.indexOf("windows nt");
          var end = ua.indexOf(";", start);
          osName = ua.substring(start, end);
        }
      } else {
        osName = isMac ? "Mac" : isLinux ? "Linux" : "Other";
      }
      if (isIE) {
        browserType = "IE";
        jsType = "IE";
        var versionStart = ua.indexOf("msie") + 5;
        var versionEnd = ua.indexOf(";", versionStart);
        browserVersion = ua.substring(versionStart, versionEnd);
        jsType = isIE6 ? "IE6" : isIE7 ? "IE7" : isIE8 ? "IE8" : "IE";
      } else if (isGecko) {
        var isFF = check(/firefox/);
        browserType = isFF ? "Firefox" : "Others";
        jsType = isGecko2 ? "Gecko2" : isGecko3 ? "Gecko3" : "Gecko";
        if (isFF) {
          var versionStart = ua.indexOf("firefox") + 8;
          var versionEnd = ua.indexOf(" ", versionStart);
          if (versionEnd == -1) {
            versionEnd = ua.length;
          }
          browserVersion = ua.substring(versionStart, versionEnd);
        }
      } else if (isChrome) {
        browserType = "Chrome";
        jsType = isWebKit ? "Web Kit" : "Other";
        var versionStart = ua.indexOf("chrome") + 7;
        var versionEnd = ua.indexOf(" ", versionStart);
        browserVersion = ua.substring(versionStart, versionEnd);
      } else {
        browserType = isOpera ? "Opera" : isSafari ? "Safari" : "";
      }
      var locationSearchClicked;
      var firstTimeClicked;
      var transition_time = 100;
      var appointment_timezone;
      var enable_timezone_selection;
      var order_question_id;
      var order_question_options;
      var selected_orders = [];
      var order_status_string = "items_added";
      var order_items_question;
      var order_items = [];
      var editing_number = 0;
      var add_more_clicked;
      var available_timezones;
      if (chatbot_id == 7131) {
        available_timezones = [
          {
            value: "-12:00",
            name: "International Date Line West",
          },
          {
            value: "+13:00",
            name: "Samoa",
          },
          {
            value: "-11:00",
            name: "Coordinated Universal Time-11",
          },
          {
            value: "-10:00",
            name: "Aleutian Islands",
          },
          {
            value: "-10:00",
            name: "Hawaii",
          },
          {
            value: "-09:30",
            name: "Marquesas Islands",
          },
          {
            value: "-09:00",
            name: "Alaska",
          },
          {
            value: "-09:00",
            name: "Coordinated Universal Time-09",
          },
          {
            value: "-07:00",
            name: "Yukon",
          },
          {
            value: "-08:00",
            name: "Baja California",
          },
          {
            value: "-08:00",
            name: "Coordinated Universal Time-08",
          },
          {
            value: "-08:00",
            name: "Pacific Time (US & Canada",
          },
          {
            value: "-07:00",
            name: "Arizona",
          },
          {
            value: "-07:00",
            name: "Chihuahua, La Paz, Mazatlan",
          },
          {
            value: "-07:00",
            name: "Mountain Time (US & Canada",
          },
          {
            value: "-05:00",
            name: "Chetumal",
          },
          {
            value: "-06:00",
            name: "Central Time (US & Canada",
          },
          {
            value: "-06:00",
            name: "Central America",
          },
          {
            value: "-06:00",
            name: "Easter Island",
          },
          {
            value: "-06:00",
            name: "Guadalajara, Mexico City, Monterrey",
          },
          {
            value: "-06:00",
            name: "Saskatchewan",
          },
          {
            value: "-05:00",
            name: "Bogota, Lima, Quito, Rio Branco",
          },
          {
            value: "-05:00",
            name: "Eastern Time (US & Canada",
          },
          {
            value: "-05:00",
            name: "Haiti",
          },
          {
            value: "-05:00",
            name: "Havana",
          },
          {
            value: "-05:00",
            name: "Indiana (East",
          },
          {
            value: "-05:00",
            name: "Turks and Caicos",
          },
          {
            value: "-04:00",
            name: "Caracas",
          },
          {
            value: "-03:00",
            name: "Punta Arenas",
          },
          {
            value: "-04:00",
            name: "Asuncion",
          },
          {
            value: "-04:00",
            name: "Atlantic Time (Canada",
          },
          {
            value: "-04:00",
            name: "Cuiaba",
          },
          {
            value: "-04:00",
            name: "Georgetown, La Paz, Manaus, San Juan",
          },
          {
            value: "-04:00",
            name: "Santiago",
          },
          {
            value: "-03:30",
            name: "Newfoundland",
          },
          {
            value: "-03:00",
            name: "Araguaina",
          },
          {
            value: "-03:00",
            name: "Brasilia",
          },
          {
            value: "-03:00",
            name: "Cayenne, Fortaleza",
          },
          {
            value: "-03:00",
            name: "City of Buenos Aires",
          },
          {
            value: "-03:00",
            name: "Greenland",
          },
          {
            value: "-03:00",
            name: "Montevideo",
          },
          {
            value: "-03:00",
            name: "Saint Pierre and Miquelon",
          },
          {
            value: "-03:00",
            name: "Salvador",
          },
          {
            value: "-02:00",
            name: "Coordinated Universal Time-02",
          },
          {
            value: "-02:00",
            name: "Mid-Atlantic - Old",
          },
          {
            value: "-01:00",
            name: "Azores",
          },
          {
            value: "-01:00",
            name: "Cabo Verde Is.",
          },
          {
            value: "+00:00",
            name: "Coordinated Universal Time",
          },
          {
            value: "+00:00",
            name: "Dublin, Edinburgh, Lisbon, London",
          },
          {
            value: "+00:00",
            name: "Monrovia, Reykjavik",
          },
          {
            value: "+01:00",
            name: "Casablanca",
          },
          {
            value: "+01:00",
            name: "Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna",
          },
          {
            value: "+01:00",
            name: "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
          },
          {
            value: "+01:00",
            name: "Brussels, Copenhagen, Madrid, Paris",
          },
          {
            value: "+01:00",
            name: "Sarajevo, Skopje, Warsaw, Zagreb",
          },
          {
            value: "+01:00",
            name: "West Central Africa",
          },
          {
            value: "+02:00",
            name: "Tripoli",
          },
          {
            value: "+02:00",
            name: "Windhoek",
          },
          {
            value: "+02:00",
            name: "Amman",
          },
          {
            value: "+02:00",
            name: "Athens, Bucharest",
          },
          {
            value: "+02:00",
            name: "Beirut",
          },
          {
            value: "+02:00",
            name: "Cairo",
          },
          {
            value: "+02:00",
            name: "Chisinau",
          },
          {
            value: "+02:00",
            name: "Damascus",
          },
          {
            value: "+02:00",
            name: "Gaza, Hebron",
          },
          {
            value: "+02:00",
            name: "Harare, Pretoria",
          },
          {
            value: "+02:00",
            name: "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
          },
          {
            value: "+02:00",
            name: "Jerusalem",
          },
          {
            value: "+02:00",
            name: "Juba",
          },
          {
            value: "+02:00",
            name: "Kaliningrad",
          },
          {
            value: "+02:00",
            name: "Khartoum",
          },
          {
            value: "+03:00",
            name: "Istanbul",
          },
          {
            value: "+03:00",
            name: "Minsk",
          },
          {
            value: "+03:00",
            name: "Baghdad",
          },
          {
            value: "+03:00",
            name: "Kuwait, Riyadh",
          },
          {
            value: "+03:00",
            name: "Moscow, St. Petersburg",
          },
          {
            value: "+03:00",
            name: "Nairobi",
          },
          {
            value: "+04:00",
            name: "Astrakhan, Ulyanovsk",
          },
          {
            value: "+04:00",
            name: "Izhevsk, Samara",
          },
          {
            value: "+04:00",
            name: "Saratov",
          },
          {
            value: "+04:00",
            name: "Volgograd",
          },
          {
            value: "+03:30",
            name: "Tehran",
          },
          {
            value: "+04:00",
            name: "Abu Dhabi, Muscat",
          },
          {
            value: "+04:00",
            name: "Baku",
          },
          {
            value: "+04:00",
            name: "Port Louis",
          },
          {
            value: "+04:00",
            name: "Tbilisi",
          },
          {
            value: "+04:00",
            name: "Yerevan",
          },
          {
            value: "+04:30",
            name: "Kabul",
          },
          {
            value: "+05:00",
            name: "Ashgabat, Toshkent",
          },
          {
            value: "+05:00",
            name: "Ekaterinburg",
          },
          {
            value: "+05:00",
            name: "Islamabad, Karachi",
          },
          {
            value: "+05:00",
            name: "Qyzylorda",
          },
          {
            value: "+05:30",
            name: "Chennai, Kolkata, Mumbai, New Delhi",
          },
          {
            value: "+05:30",
            name: "Sri Jayawardenepura",
          },
          {
            value: "+05:45",
            name: "Kathmandu",
          },
          {
            value: "+06:00",
            name: "Astana",
          },
          {
            value: "+06:00",
            name: "Dhaka",
          },
          {
            value: "+06:00",
            name: "Omsk",
          },
          {
            value: "+07:00",
            name: "Barnaul, Gorno-Altaysk",
          },
          {
            value: "+07:00",
            name: "Novosibirsk",
          },
          {
            value: "+07:00",
            name: "Tomsk",
          },
          {
            value: "+06:30",
            name: "Yangon (Rangoon",
          },
          {
            value: "+07:00",
            name: "Bangkok, Hanoi, Jakarta",
          },
          {
            value: "+07:00",
            name: "Hovd",
          },
          {
            value: "+07:00",
            name: "Krasnoyarsk",
          },
          {
            value: "+08:00",
            name: "Beijing, Chongqing, Hong Kong, Urumqi",
          },
          {
            value: "+08:00",
            name: "Irkutsk",
          },
          {
            value: "+08:00",
            name: "Kuala Lumpur, Singapore",
          },
          {
            value: "+08:00",
            name: "Perth",
          },
          {
            value: "+08:00",
            name: "Taipei",
          },
          {
            value: "+08:00",
            name: "Ulaanbaatar",
          },
          {
            value: "+09:00",
            name: "Chita",
          },
          {
            value: "+09:00",
            name: "Pyongyang",
          },
          {
            value: "+08:45",
            name: "Eucla",
          },
          {
            value: "+09:00",
            name: "Osaka, Sapporo, Tokyo",
          },
          {
            value: "+09:00",
            name: "Seoul",
          },
          {
            value: "+09:00",
            name: "Yakutsk",
          },
          {
            value: "+09:30",
            name: "Adelaide",
          },
          {
            value: "+09:30",
            name: "Darwin",
          },
          {
            value: "+10:00",
            name: "Brisbane",
          },
          {
            value: "+10:00",
            name: "Canberra, Melbourne, Sydney",
          },
          {
            value: "+10:00",
            name: "Guam, Port Moresby",
          },
          {
            value: "+10:00",
            name: "Hobart",
          },
          {
            value: "+10:00",
            name: "Vladivostok",
          },
          {
            value: "+11:00",
            name: "Bougainville Island",
          },
          {
            value: "+11:00",
            name: "Magadan",
          },
          {
            value: "+11:00",
            name: "Sakhalin",
          },
          {
            value: "+10:30",
            name: "Lord Howe Island",
          },
          {
            value: "+11:00",
            name: "Chokurdakh",
          },
          {
            value: "+11:00",
            name: "Norfolk Island",
          },
          {
            value: "+11:00",
            name: "Solomon Is., New Caledonia",
          },
          {
            value: "+12:00",
            name: "Anadyr, Petropavlovsk-Kamchatsky",
          },
          {
            value: "+12:00",
            name: "Auckland, Wellington",
          },
          {
            value: "+12:00",
            name: "Coordinated Universal Time+12",
          },
          {
            value: "+12:00",
            name: "Fiji",
          },
          {
            value: "+12:00",
            name: "Petropavlovsk-Kamchatsky - Old",
          },
          {
            value: "+12:45",
            name: "Chatham Islands",
          },
          {
            value: "+13:00",
            name: "Coordinated Universal Time+13",
          },
          {
            value: "+13:00",
            name: "Nuku'alofa",
          },
          {
            value: "+14:00",
            name: "Kiritimati Island",
          },
        ];
      } else {
        available_timezones = [
          { value: '-12:00', name: '(GMT -12:00) Baker Island Time (Pacific/Baker)' },
          { value: '-11:00', name: '(GMT -11:00) Niue Time (Pacific/Niue)' },
          {
            value: '-11:00',
            name: '(GMT -11:00) Samoa Standard Time (Pacific/Pago_Pago)',
          },
          {
            value: '-10:00',
            name: '(GMT -10:00) Hawaii-Aleutian Standard Time (Pacific/Honolulu)',
          },
          {
            value: '-10:00',
            name: '(GMT -10:00) Cook Islands Standard Time (Pacific/Rarotonga)',
          },
          { value: '-10:00', name: '(GMT -10:00) Tahiti Time (Pacific/Tahiti)' },
          { value: '', name: '(GMT -09:-30) Marquesas Time (Pacific/Marquesas)' },
          {
            value: '-09:00',
            name: '(GMT -09:00) Hawaii-Aleutian Daylight Time (America/Adak)',
          },
          { value: '-09:00', name: '(GMT -09:00) Gambier Time (Pacific/Gambier)' },
          {
            value: '-08:00',
            name: '(GMT -08:00) Alaska Daylight Time (America/Anchorage)',
          },
          {
            value: '-08:00',
            name: '(GMT -08:00) Alaska Daylight Time (America/Juneau)',
          },
          {
            value: '-08:00',
            name: '(GMT -08:00) Alaska Daylight Time (America/Metlakatla)',
          },
          { value: '-08:00', name: '(GMT -08:00) Alaska Daylight Time (America/Nome)' },
          {
            value: '-08:00',
            name: '(GMT -08:00) Alaska Daylight Time (America/Sitka)',
          },
          {
            value: '-08:00',
            name: '(GMT -08:00) Alaska Daylight Time (America/Yakutat)',
          },
          { value: '-08:00', name: '(GMT -08:00) Pitcairn Time (Pacific/Pitcairn)' },
          {
            value: '-07:00',
            name: '(GMT -07:00) Pacific Standard Time (America/Dawson)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Mountain Standard Time (America/Dawson_Creek)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Mountain Standard Time (America/Fort_Nelson)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Mexican Pacific Standard Time (America/Hermosillo)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Pacific Daylight Time (America/Los_Angeles)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Mexican Pacific Standard Time (America/Mazatlan)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Mountain Standard Time (America/Phoenix)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Pacific Daylight Time (America/Tijuana)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Pacific Daylight Time (America/Vancouver)',
          },
          {
            value: '-07:00',
            name: '(GMT -07:00) Pacific Standard Time (America/Whitehorse)',
          },
          { value: '-07:00', name: '(GMT -07:00) Mountain Standard Time (MST)' },
          { value: '-07:00', name: '(GMT -07:00) Pacific Daylight Time (PST)' },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Bahia_Banderas)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Belize)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Mountain Daylight Time (America/Boise)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Mountain Daylight Time (America/Cambridge_Bay)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Chihuahua)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Mountain Daylight Time (America/Ciudad_Juarez)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Costa_Rica)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Mountain Daylight Time (America/Denver)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Mountain Daylight Time (America/Edmonton)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/El_Salvador)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Guatemala)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Mountain Daylight Time (America/Inuvik)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Managua)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Merida)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Mexico_City)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Monterrey)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Regina)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Swift_Current)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Central Standard Time (America/Tegucigalpa)',
          },
          {
            value: '-06:00',
            name: '(GMT -06:00) Easter Island Standard Time (Pacific/Easter)',
          },
          { value: '-06:00', name: '(GMT -06:00) Galapagos Time (Pacific/Galapagos)' },
          {
            value: '-05:00',
            name: '(GMT -05:00) Colombia Standard Time (America/Bogota)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Eastern Standard Time (America/Cancun)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Chicago)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Acre Standard Time (America/Eirunepe)',
          },
          { value: '-05:00', name: '(GMT -05:00) Ecuador Time (America/Guayaquil)' },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Indiana/Knox)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Indiana/Tell_City)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Eastern Standard Time (America/Jamaica)',
          },
          { value: '-05:00', name: '(GMT -05:00) Peru Standard Time (America/Lima)' },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Matamoros)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Menominee)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/North_Dakota/Beulah)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/North_Dakota/Center)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/North_Dakota/New_Salem)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Ojinaga)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Eastern Standard Time (America/Panama)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Rankin_Inlet)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Resolute)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Acre Standard Time (America/Rio_Branco)',
          },
          {
            value: '-05:00',
            name: '(GMT -05:00) Central Daylight Time (America/Winnipeg)',
          },
          { value: '-05:00', name: '(GMT -05:00) Central Daylight Time (CST6CDT)' },
          {
            value: '-04:00',
            name: '(GMT -04:00) Paraguay Standard Time (America/Asuncion)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Atlantic Standard Time (America/Barbados)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Amazon Standard Time (America/Boa_Vista)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Amazon Standard Time (America/Campo_Grande)',
          },
          { value: '-04:00', name: '(GMT -04:00) Venezuela Time (America/Caracas)' },
          {
            value: '-04:00',
            name: '(GMT -04:00) Amazon Standard Time (America/Cuiaba)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Detroit)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Grand_Turk)',
          },
          { value: '-04:00', name: '(GMT -04:00) Guyana Time (America/Guyana)' },
          { value: '-04:00', name: '(GMT -04:00) Cuba Daylight Time (America/Havana)' },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Indiana/Indianapolis)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Indiana/Marengo)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Indiana/Petersburg)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Indiana/Vevay)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Indiana/Vincennes)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Indiana/Winamac)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Iqaluit)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Kentucky/Louisville)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Kentucky/Monticello)',
          },
          { value: '-04:00', name: '(GMT -04:00) Bolivia Time (America/La_Paz)' },
          {
            value: '-04:00',
            name: '(GMT -04:00) Amazon Standard Time (America/Manaus)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Atlantic Standard Time (America/Martinique)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/New_York)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Port-au-Prince)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Amazon Standard Time (America/Porto_Velho)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Atlantic Standard Time (America/Puerto_Rico)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Chile Standard Time (America/Santiago)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Atlantic Standard Time (America/Santo_Domingo)',
          },
          {
            value: '-04:00',
            name: '(GMT -04:00) Eastern Daylight Time (America/Toronto)',
          },
          { value: '-04:00', name: '(GMT -04:00) Atlantic Standard Time (PRT)' },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Araguaina)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Buenos_Aires)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Catamarca)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Cordoba)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Jujuy)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/La_Rioja)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Mendoza)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Rio_Gallegos)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Salta)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/San_Juan)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Western Argentina Standard Time (America/Argentina/San_Luis)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Tucuman)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Argentina Standard Time (America/Argentina/Ushuaia)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Bahia)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Belem)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) French Guiana Time (America/Cayenne)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Fortaleza)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (America/Glace_Bay)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (America/Goose_Bay)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (America/Halifax)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Maceio)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (America/Moncton)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Uruguay Standard Time (America/Montevideo)',
          },
          { value: '-03:00', name: '(GMT -03:00) Suriname Time (America/Paramaribo)' },
          {
            value: '-03:00',
            name: '(GMT -03:00) Punta Arenas Standard Time (America/Punta_Arenas)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Recife)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Santarem)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Brasilia Standard Time (America/Sao_Paulo)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (America/Thule)',
          },
          { value: '-03:00', name: '(GMT -03:00) Chile Time (Antarctica/Palmer)' },
          { value: '-03:00', name: '(GMT -03:00) Rothera Time (Antarctica/Rothera)' },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (Atlantic/Bermuda)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Falkland Islands Standard Time (Atlantic/Stanley)',
          },
          {
            value: '-03:00',
            name: '(GMT -03:00) Atlantic Daylight Time (SystemV/AST4ADT)',
          },
          {
            value: '',
            name: '(GMT -02:-30) Newfoundland Daylight Time (America/St_Johns)',
          },
          {
            value: '-02:00',
            name: '(GMT -02:00) St. Pierre &amp; Miquelon Daylight Time (America/Miquelon)',
          },
          {
            value: '-02:00',
            name: '(GMT -02:00) Fernando de Noronha Standard Time (America/Noronha)',
          },
          {
            value: '-02:00',
            name: '(GMT -02:00) South Georgia Time (Atlantic/South_Georgia)',
          },
          {
            value: '-01:00',
            name: '(GMT -01:00) Western Greenland Summer Time (America/Nuuk)',
          },
          {
            value: '-01:00',
            name: '(GMT -01:00) East Greenland Summer Time (America/Scoresbysund)',
          },
          {
            value: '-01:00',
            name: '(GMT -01:00) Cape Verde Standard Time (Atlantic/Cape_Verde)',
          },
          {
            value: '+00:00',
            name: '(GMT +00:00) Greenwich Mean Time (Africa/Abidjan)',
          },
          { value: '+00:00', name: '(GMT +00:00) Greenwich Mean Time (Africa/Bissau)' },
          {
            value: '+00:00',
            name: '(GMT +00:00) Greenwich Mean Time (Africa/Monrovia)',
          },
          {
            value: '+00:00',
            name: '(GMT +00:00) West Africa Standard Time (Africa/Sao_Tome)',
          },
          {
            value: '+00:00',
            name: '(GMT +00:00) Greenwich Mean Time (America/Danmarkshavn)',
          },
          {
            value: '+00:00',
            name: '(GMT +00:00) Azores Summer Time (Atlantic/Azores)',
          },
          { value: '+00:00', name: '(GMT +00:00) Greenwich Mean Time (GMT)' },
          {
            value: '+01:00',
            name: '(GMT +01:00) Central European Standard Time (Africa/Algiers)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) Western European Summer Time (Africa/Casablanca)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) Western European Summer Time (Africa/El_Aaiun)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) West Africa Standard Time (Africa/Lagos)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) West Africa Standard Time (Africa/Ndjamena)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) Central European Standard Time (Africa/Tunis)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) Western European Summer Time (Atlantic/Canary)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) Western European Summer Time (Atlantic/Faroe)',
          },
          {
            value: '+01:00',
            name: '(GMT +01:00) Western European Summer Time (Atlantic/Madeira)',
          },
          { value: '+01:00', name: '(GMT +01:00) Irish Standard Time (Europe/Dublin)' },
          {
            value: '+01:00',
            name: '(GMT +01:00) Western European Summer Time (Europe/Lisbon)',
          },
          { value: '+01:00', name: '(GMT +01:00) British Summer Time (Europe/London)' },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Africa/Ceuta)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) South Africa Standard Time (Africa/Johannesburg)',
          },
          { value: '+02:00', name: '(GMT +02:00) East Africa Time (Africa/Juba)' },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central Africa Time (Africa/Khartoum)',
          },
          { value: '+02:00', name: '(GMT +02:00) Central Africa Time (Africa/Maputo)' },
          {
            value: '+02:00',
            name: '(GMT +02:00) Eastern European Standard Time (Africa/Tripoli)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Western African Time (Africa/Windhoek)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Antarctica/Troll)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Andorra)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Belgrade)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Berlin)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Brussels)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Budapest)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Gibraltar)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Eastern European Standard Time (Europe/Kaliningrad)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Madrid)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Malta)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Paris)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Prague)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Rome)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Tirane)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Vienna)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Warsaw)',
          },
          {
            value: '+02:00',
            name: '(GMT +02:00) Central European Summer Time (Europe/Zurich)',
          },
          { value: '+02:00', name: '(GMT +02:00) Middle Europe Summer Time (MET)' },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Africa/Cairo)',
          },
          { value: '+03:00', name: '(GMT +03:00) East Africa Time (Africa/Nairobi)' },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Standard Time (Asia/Amman)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Arabian Standard Time (Asia/Baghdad)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Asia/Beirut)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Standard Time (Asia/Damascus)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Asia/Famagusta)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Asia/Gaza)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Asia/Hebron)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Israel Daylight Time (Asia/Jerusalem)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Asia/Nicosia)',
          },
          { value: '+03:00', name: '(GMT +03:00) Arabian Standard Time (Asia/Qatar)' },
          { value: '+03:00', name: '(GMT +03:00) Arabian Standard Time (Asia/Riyadh)' },
          { value: '+03:00', name: '(GMT +03:00) Eastern European Summer Time (EET)' },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Athens)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Bucharest)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Chisinau)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Helsinki)',
          },
          { value: '+03:00', name: '(GMT +03:00) Turkey Time (Europe/Istanbul)' },
          { value: '+03:00', name: '(GMT +03:00) Moscow Standard Time (Europe/Kirov)' },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Kyiv)',
          },
          { value: '+03:00', name: '(GMT +03:00) Moscow Standard Time (Europe/Minsk)' },
          {
            value: '+03:00',
            name: '(GMT +03:00) Moscow Standard Time (Europe/Moscow)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Riga)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Moscow Standard Time (Europe/Simferopol)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Sofia)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Tallinn)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Eastern European Summer Time (Europe/Vilnius)',
          },
          {
            value: '+03:00',
            name: '(GMT +03:00) Moscow Standard Time (Europe/Volgograd)',
          },
          { value: '+03:00', name: '(GMT +03:00) East Africa Time (EAT)' },
          { value: '+03:30', name: '(GMT +03:30) Iran Standard Time (Asia/Tehran)' },
          {
            value: '+04:00',
            name: '(GMT +04:00) Azerbaijan Standard Time (Asia/Baku)',
          },
          { value: '+04:00', name: '(GMT +04:00) Gulf Standard Time (Asia/Dubai)' },
          {
            value: '+04:00',
            name: '(GMT +04:00) Georgia Standard Time (Asia/Tbilisi)',
          },
          {
            value: '+04:00',
            name: '(GMT +04:00) Armenia Standard Time (Asia/Yerevan)',
          },
          {
            value: '+04:00',
            name: '(GMT +04:00) Astrakhan Standard Time (Europe/Astrakhan)',
          },
          {
            value: '+04:00',
            name: '(GMT +04:00) Samara Standard Time (Europe/Samara)',
          },
          {
            value: '+04:00',
            name: '(GMT +04:00) Saratov Standard Time (Europe/Saratov)',
          },
          {
            value: '+04:00',
            name: '(GMT +04:00) Ulyanovsk Standard Time (Europe/Ulyanovsk)',
          },
          {
            value: '+04:00',
            name: '(GMT +04:00) Mauritius Standard Time (Indian/Mauritius)',
          },
          { value: '+04:30', name: '(GMT +04:30) Afghanistan Time (Asia/Kabul)' },
          { value: '+05:00', name: '(GMT +05:00) Mawson Time (Antarctica/Mawson)' },
          { value: '+05:00', name: '(GMT +05:00) East Kazakhstan Time (Asia/Almaty)' },
          { value: '+05:00', name: '(GMT +05:00) West Kazakhstan Time (Asia/Aqtau)' },
          { value: '+05:00', name: '(GMT +05:00) West Kazakhstan Time (Asia/Aqtobe)' },
          {
            value: '+05:00',
            name: '(GMT +05:00) Turkmenistan Standard Time (Asia/Ashgabat)',
          },
          { value: '+05:00', name: '(GMT +05:00) West Kazakhstan Time (Asia/Atyrau)' },
          { value: '+05:00', name: '(GMT +05:00) Tajikistan Time (Asia/Dushanbe)' },
          {
            value: '+05:00',
            name: '(GMT +05:00) Pakistan Standard Time (Asia/Karachi)',
          },
          { value: '+05:00', name: '(GMT +05:00) West Kazakhstan Time (Asia/Oral)' },
          {
            value: '+05:00',
            name: '(GMT +05:00) Kostanay Standard Time (Asia/Qostanay)',
          },
          {
            value: '+05:00',
            name: '(GMT +05:00) East Kazakhstan Time (Asia/Qyzylorda)',
          },
          {
            value: '+05:00',
            name: '(GMT +05:00) Uzbekistan Standard Time (Asia/Samarkand)',
          },
          {
            value: '+05:00',
            name: '(GMT +05:00) Uzbekistan Standard Time (Asia/Tashkent)',
          },
          {
            value: '+05:00',
            name: '(GMT +05:00) Yekaterinburg Standard Time (Asia/Yekaterinburg)',
          },
          { value: '+05:00', name: '(GMT +05:00) Maldives Time (Indian/Maldives)' },
          { value: '+05:30', name: '(GMT +05:30) India Standard Time (Asia/Colombo)' },
          { value: '+05:30', name: '(GMT +05:30) India Standard Time (Asia/Kolkata)' },
          { value: '+05:45', name: '(GMT +05:45) Nepal Time (Asia/Kathmandu)' },
          { value: '+06:00', name: '(GMT +06:00) Kyrgyzstan Time (Asia/Bishkek)' },
          {
            value: '+06:00',
            name: '(GMT +06:00) Bangladesh Standard Time (Asia/Dhaka)',
          },
          { value: '+06:00', name: '(GMT +06:00) Omsk Standard Time (Asia/Omsk)' },
          { value: '+06:00', name: '(GMT +06:00) Bhutan Time (Asia/Thimphu)' },
          {
            value: '+06:00',
            name: '(GMT +06:00) Xinjiang Standard Time (Asia/Urumqi)',
          },
          { value: '+06:00', name: '(GMT +06:00) Indian Ocean Time (Indian/Chagos)' },
          { value: '+06:30', name: '(GMT +06:30) Myanmar Time (Asia/Yangon)' },
          { value: '+07:00', name: '(GMT +07:00) Davis Time (Antarctica/Davis)' },
          { value: '+07:00', name: '(GMT +07:00) Indochina Time (Asia/Bangkok)' },
          {
            value: '+07:00',
            name: '(GMT +07:00) Barnaul Standard Time (Asia/Barnaul)',
          },
          { value: '+07:00', name: '(GMT +07:00) Indochina Time (Asia/Ho_Chi_Minh)' },
          { value: '+07:00', name: '(GMT +07:00) Hovd Standard Time (Asia/Hovd)' },
          {
            value: '+07:00',
            name: '(GMT +07:00) Western Indonesia Time (Asia/Jakarta)',
          },
          {
            value: '+07:00',
            name: '(GMT +07:00) Krasnoyarsk Standard Time (Asia/Krasnoyarsk)',
          },
          {
            value: '+07:00',
            name: '(GMT +07:00) Krasnoyarsk Standard Time (Asia/Novokuznetsk)',
          },
          {
            value: '+07:00',
            name: '(GMT +07:00) Novosibirsk Standard Time (Asia/Novosibirsk)',
          },
          {
            value: '+07:00',
            name: '(GMT +07:00) Western Indonesia Time (Asia/Pontianak)',
          },
          { value: '+07:00', name: '(GMT +07:00) Tomsk Standard Time (Asia/Tomsk)' },
          { value: '+08:00', name: '(GMT +08:00) Casey Time (Antarctica/Casey)' },
          {
            value: '+08:00',
            name: '(GMT +08:00) Choibalsan Standard Time (Asia/Choibalsan)',
          },
          {
            value: '+08:00',
            name: '(GMT +08:00) Hong Kong Standard Time (Asia/Hong_Kong)',
          },
          {
            value: '+08:00',
            name: '(GMT +08:00) Irkutsk Standard Time (Asia/Irkutsk)',
          },
          { value: '+08:00', name: '(GMT +08:00) Malaysia Time (Asia/Kuching)' },
          { value: '+08:00', name: '(GMT +08:00) China Standard Time (Asia/Macau)' },
          {
            value: '+08:00',
            name: '(GMT +08:00) Central Indonesia Time (Asia/Makassar)',
          },
          {
            value: '+08:00',
            name: '(GMT +08:00) Philippine Standard Time (Asia/Manila)',
          },
          { value: '+08:00', name: '(GMT +08:00) China Standard Time (Asia/Shanghai)' },
          {
            value: '+08:00',
            name: '(GMT +08:00) Singapore Standard Time (Asia/Singapore)',
          },
          { value: '+08:00', name: '(GMT +08:00) Taipei Standard Time (Asia/Taipei)' },
          {
            value: '+08:00',
            name: '(GMT +08:00) Ulaanbaatar Standard Time (Asia/Ulaanbaatar)',
          },
          {
            value: '+08:00',
            name: '(GMT +08:00) Australian Western Standard Time (Australia/Perth)',
          },
          {
            value: '+08:45',
            name: '(GMT +08:45) Australian Central Western Standard Time (Australia/Eucla)',
          },
          { value: '+09:00', name: '(GMT +09:00) Yakutsk Standard Time (Asia/Chita)' },
          { value: '+09:00', name: '(GMT +09:00) East Timor Time (Asia/Dili)' },
          {
            value: '+09:00',
            name: '(GMT +09:00) Eastern Indonesia Time (Asia/Jayapura)',
          },
          {
            value: '+09:00',
            name: '(GMT +09:00) Yakutsk Standard Time (Asia/Khandyga)',
          },
          { value: '+09:00', name: '(GMT +09:00) Pyongyang Time (Asia/Pyongyang)' },
          { value: '+09:00', name: '(GMT +09:00) Korean Standard Time (Asia/Seoul)' },
          { value: '+09:00', name: '(GMT +09:00) Japan Standard Time (Asia/Tokyo)' },
          {
            value: '+09:00',
            name: '(GMT +09:00) Yakutsk Standard Time (Asia/Yakutsk)',
          },
          { value: '+09:00', name: '(GMT +09:00) Palau Time (Pacific/Palau)' },
          {
            value: '+09:30',
            name: '(GMT +09:30) Australian Central Standard Time (Australia/Adelaide)',
          },
          {
            value: '+09:30',
            name: '(GMT +09:30) Australian Central Standard Time (Australia/Broken_Hill)',
          },
          {
            value: '+09:30',
            name: '(GMT +09:30) Australian Central Standard Time (Australia/Darwin)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Macquarie Island Time (Antarctica/Macquarie)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Vladivostok Standard Time (Asia/Ust-Nera)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Vladivostok Standard Time (Asia/Vladivostok)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Australian Eastern Standard Time (Australia/Brisbane)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Australian Eastern Standard Time (Australia/Hobart)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Australian Eastern Standard Time (Australia/Lindeman)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Australian Eastern Standard Time (Australia/Melbourne)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Australian Eastern Standard Time (Australia/Sydney)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Chamorro Standard Time (Pacific/Guam)',
          },
          {
            value: '+10:00',
            name: '(GMT +10:00) Papua New Guinea Time (Pacific/Port_Moresby)',
          },
          {
            value: '+10:30',
            name: '(GMT +10:30) Lord Howe Standard Time (Australia/Lord_Howe)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) Magadan Standard Time (Asia/Magadan)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) Sakhalin Standard Time (Asia/Sakhalin)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) Srednekolymsk Time (Asia/Srednekolymsk)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) Bougainville Standard Time (Pacific/Bougainville)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) Vanuatu Standard Time (Pacific/Efate)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) Solomon Islands Time (Pacific/Guadalcanal)',
          },
          { value: '+11:00', name: '(GMT +11:00) Kosrae Time (Pacific/Kosrae)' },
          {
            value: '+11:00',
            name: '(GMT +11:00) Norfolk Island Time (Pacific/Norfolk)',
          },
          {
            value: '+11:00',
            name: '(GMT +11:00) New Caledonia Standard Time (Pacific/Noumea)',
          },
          { value: '+12:00', name: '(GMT +12:00) Anadyr Standard Time (Asia/Anadyr)' },
          {
            value: '+12:00',
            name: '(GMT +12:00) Petropavlovsk-Kamchatski Standard Time (Asia/Kamchatka)',
          },
          {
            value: '+12:00',
            name: '(GMT +12:00) New Zealand Standard Time (Pacific/Auckland)',
          },
          { value: '+12:00', name: '(GMT +12:00) Fiji Standard Time (Pacific/Fiji)' },
          {
            value: '+12:00',
            name: '(GMT +12:00) Marshall Islands Time (Pacific/Kwajalein)',
          },
          { value: '+12:00', name: '(GMT +12:00) Nauru Time (Pacific/Nauru)' },
          {
            value: '+12:00',
            name: '(GMT +12:00) Gilbert Islands Time (Pacific/Tarawa)',
          },
          { value: '+12:00', name: '(GMT +12:00) New Zealand Standard Time (NST)' },
          {
            value: '+12:45',
            name: '(GMT +12:45) Chatham Standard Time (Pacific/Chatham)',
          },
          { value: '+13:00', name: '(GMT +13:00) Apia Standard Time (Pacific/Apia)' },
          { value: '+13:00', name: '(GMT +13:00) Tokelau Time (Pacific/Fakaofo)' },
          {
            value: '+13:00',
            name: '(GMT +13:00) Kanton Standard Time (Pacific/Kanton)',
          },
          {
            value: '+13:00',
            name: '(GMT +13:00) Tonga Standard Time (Pacific/Tongatapu)',
          },
          {
            value: '+14:00',
            name: '(GMT +14:00) Line Islands Time (Pacific/Kiritimati)',
          },
        ];
      }
      var multi_lingual_switch;
      var start_again_switch;
      var real_time_search_items;
      var date_output_format;
      var sock;
      var alreadySockLoaded;
      var liveSessionSet;
      var agent_name;
      var agent_id;
      var agent_message_timer = 0;
      var start_live_chat_timer = false;
      var proceed_to_start_bot = false;
      var first_busy_message =
        "I am trying to reach my agent.....In the meantime go grab some coffee ☕";
      var second_busy_message =
        "Looks like my agent is busy helping other prospects like you, let me try again.....";
      var third_busy_message =
        "Sorry for making you wait this long. It is taking more time than usual, our agent will be here anytime soon....🙂";
      var live_chat_session_feedback;
      var liveChatFeedbackDiv;
      var banned_ips;
      var ip_is_banned;
      var banned_reason;
      var live_chat_feedback_submitted;
      var liveChatFeedbackInput;
      var liveChatInputSubmit;
      var live_chat_feedback_rated;
      var seen_cleared;
      var real_time_search_type;
      var video_call_token;
      var video_call_object;
      var screen_sharing_object;
      var video_call_room;
      var screen_share_from_agent;
      var question_skipped;
      var number_skipped;
      var websited_skipped;
      var contacts_skipped;
      var location_skipped;
      var voice_input;
      if (isChrome || true) {
        try {
          var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
          var recognition = new SpeechRecognition();
          recognition.continuous = false;
          recognition.lang = "en-US";
          recognition.interimResults = false;
          recognition.maxAlternatives = 1;
        } catch (e) {
        } finally {
        }
      }
      var typingMessageSent;
      var strictEmailValidation;
      var adminMessaged;
      var live_chat_feedback_opened;
      if (chatbot_id != 10561) {
        window.botWidget = {};
        window.botWidget.user = {};
        window.botWidget.init = function (obj) {
          var keys = Object.keys(obj);
          for (var i = 0; i < keys.length; i++) {
            window.botWidget.user[keys[i]] = obj[keys[i]];
          }
        };
        window.botWidget.init({
          bot_id: chatbot_id,
          url: window.location.href,
        });
        window.botWidget.setUserEmail = function (str) {
          window.botWidget.user.email = str;
        };
        window.botWidget.setUserPhone = function (str) {
          window.botWidget.user.phone = str;
        };
        window.botWidget.setUserFirstName = function (str) {
          window.botWidget.user.first_name = str;
        };
        window.botWidget.setUserLastName = function (str) {
          window.botWidget.user.last_name = str;
        };
        window.botWidget.setAction = function (str) {
          window.botWidget.user.action = str;
        };
        window.botWidget.setNotes = function (str) {
          window.botWidget.user.notes = str;
        };
        window.botWidget.setLanguage = function (str) {
          window.botWidget.user.language = str;
        };
        window.botWidget.setPartnerCode = function (str) {
          window.botWidget.user.partner_code = str;
        };
        window.botWidget.setOtpGenerateType = function (str) {
          window.botWidget.user.otp_generate_type = str;
        };
        window.botWidget.setPartnerType = function (str) {
          window.botWidget.user.partner_type = str;
        };
        window.botWidget.getAction = function (str) {
          return window.botWidget.user.action;
        };
        window.botWidget.getUserEmail = function (str) {
          return window.botWidget.user.email;
        };
        window.botWidget.getUserPhone = function (str) {
          return window.botWidget.user.phone;
        };
        window.botWidget.getUserFirstName = function (str) {
          return window.botWidget.user.first_name;
        };
        window.botWidget.getUserLastName = function (str) {
          return window.botWidget.user.last_name;
        };
        window.botWidget.getNotes = function (str) {
          return window.botWidget.user.notes;
        };
        window.botWidget.getLanguage = function (str) {
          return window.botWidget.user.language;
        };
        window.botWidget.getPartnerCode = function (str) {
          return window.botWidget.user.partner_code;
        };
        window.botWidget.getOtpGenerateType = function (str) {
          return window.botWidget.user.otp_generate_type;
        };
        window.botWidget.getPartnerType = function (str) {
          return window.botWidget.user.partner_type;
        };
        window.botWidget.minimise = function () {
          if (body && body.style.display == "block") {
            mainDiv.click();
          }
        };
        window.botWidget.maximize = function () {
          if (body && (body.style.display == "none" || body.innerHTML == "")) {
            mainDiv.click();
          }
        };
        window.botWidget.removeWidget = function () {
          let opened = document.getElementById("opened")
          let plus = document.getElementById("pulse")
          if (opened && plus) {
            opened.remove()
            plus.remove();
          }
        };
      }
      function checkSaveMAxUserLogin() {
        try {
          if (
            window.localStorage.getItem("allDetailOnLoin") &&
            window.localStorage.getItem("allDetailOnLoin").length > 0 &&
            (chatbot_id == 18664 || chatbot_id == 20097)
          ) {
            var user_json = JSON.parse(
              window.localStorage.getItem("allDetailOnLoin")
            );
            if (user_json && user_json.emailId && user_json.emailId.length > 0) {
              window.botWidget.setUserEmail(user_json.emailId);
            }
            if (
              user_json &&
              user_json.mobileNumber &&
              user_json.mobileNumber.toString().length > 0
            ) {
              window.botWidget.setUserPhone(user_json.mobileNumber);
            }
            if (
              user_json &&
              user_json.name &&
              user_json.name.toString().length > 0
            ) {
              window.botWidget.setUserFirstName(user_json.name);
            }
            if (
              user_json &&
              user_json.userId &&
              user_json.userId.toString().length > 0
            ) {
              window.botWidget.setNotes(user_json.userId);
            }
          }
        } catch (error) { }
      }

      function checkRateGainDetails() {
        try {
          const currentrateGainUrl = window.location.href;
          if (currentrateGainUrl && (currentrateGainUrl.includes("unolive-qa.rategain.com") || currentrateGainUrl.includes("unolive.rategain.com")) && window.localStorage.getItem("UserDetails") && window.localStorage.getItem("UserDetails").length > 0 &&
              window.localStorage.getItem("SelectedProperty").length > 0 && chatbot_id == 23895) {
              const userDetails = JSON.parse(window.localStorage.getItem("UserDetails"));
              const selectedPropertyId = window.localStorage.getItem("SelectedProperty");
              const propertyList = JSON.parse(window.localStorage.getItem("propertyList"));

              const matchedProperty = propertyList.find(property => property.propertyID == selectedPropertyId);
  
              if (userDetails && matchedProperty) {
                  if (userDetails.FirstName && userDetails.FirstName.length > 0) {
                      window.botWidget.setUserFirstName(userDetails.FirstName);
                  }
                  if (userDetails.LastName && userDetails.LastName.length > 0) {
                      window.botWidget.setUserLastName(userDetails.LastName);
                  }
                  if (userDetails.EmailID && userDetails.EmailID.length > 0) {
                      window.botWidget.setUserEmail(userDetails.EmailID);
                  }
                  if (matchedProperty.name && matchedProperty.name.length > 0) {
                      window.botWidget.setNotes(matchedProperty.name);
                  }
              } 
            } else if (currentrateGainUrl && (currentrateGainUrl.includes("rzhospicert.rategain.com") || currentrateGainUrl.includes("rz.rategain.com"))) {
              const propertyNameElement = document.querySelector(".propName");
              const userDetailsElement = document.querySelector(".uDetails");

              if (propertyNameElement && userDetailsElement) {
                  const propertyName = propertyNameElement.textContent.trim();
                  const userDetails = userDetailsElement.querySelectorAll("div");

                  if (userDetails.length >= 2) {
                      const firstName = userDetails[0].textContent.trim();
                      const emailId = userDetails[1].textContent.trim();

                      // Set values in bot widget
                      if (firstName && firstName.length > 0) {
                          window.botWidget.setUserFirstName(firstName);
                      }
                      if (emailId && emailId.length > 0) {
                          window.botWidget.setUserEmail(emailId);
                      }
                      if (propertyName && propertyName.length > 0) {
                          window.botWidget.setNotes(propertyName);
                      }
                  }
              }
            } else {
              if (
                  window.localStorage.getItem("UserDetails") && window.localStorage.getItem("UserDetails").length > 0 && window.localStorage.getItem("SelectedProperty").length > 0  && chatbot_id == 23895 ) {
                  var user_DetailsRateGain = JSON.parse(
                    window.localStorage.getItem("UserDetails")
                  );
                  var selectedProperty_RateGain = JSON.parse(
                    window.localStorage.getItem("SelectedProperty")
                  );
                  if (user_DetailsRateGain && user_DetailsRateGain.email && user_DetailsRateGain.email.length > 0) {
                    window.botWidget.setUserEmail(user_DetailsRateGain.email);
                  }
                  if (
                    user_DetailsRateGain &&
                    user_DetailsRateGain.phone &&
                    user_DetailsRateGain.phone.toString().length > 0
                  ) {
                    window.botWidget.setUserPhone(user_DetailsRateGain.phone);
                  }
                  if (
                    user_DetailsRateGain &&
                    user_DetailsRateGain.firstName &&
                    user_DetailsRateGain.firstName.toString().length > 0
                  ) {
                    window.botWidget.setUserFirstName(user_DetailsRateGain.firstName);
                  }
                  if (
                    user_DetailsRateGain &&
                    user_DetailsRateGain.lastName &&
                    user_DetailsRateGain.lastName.toString().length > 0
                  ) {
                    window.botWidget.setUserLastName(user_DetailsRateGain.lastName);
                  }
                  if (
                    selectedProperty_RateGain &&
                    selectedProperty_RateGain.name &&
                    selectedProperty_RateGain.name.toString().length > 0
                  ) {
                    window.botWidget.setNotes(selectedProperty_RateGain.name);
                  }
              }
            }
            
        } catch(e) { }
      }

      var euro_country_codes = [
        "BE",
        "EL",
        "LT",
        "PT",
        "BG",
        "ES",
        "LU",
        "RO",
        "CZ",
        "FR",
        "HU",
        "SI",
        "DK",
        "HR",
        "MT",
        "SK",
        "DE",
        "IT",
        "NL",
        "FI",
        "EE",
        "CY",
        "AT",
        "SE",
        "IE",
        "LV",
        "PL",
        "IS",
        "LI",
        "NO",
        "CH",
        "UK",
        "ME",
        "MK",
        "AL",
        "RS",
        "TR",
        "RU",
      ];
      var timePicker;

      function convertFontSizes(str, buffer) {
        var font_size = str.substring(str.Length - 2);
        font_size = parseInt(font_size);
        var return_font_size = font_size - parseInt(buffer);
        return return_font_size + "px";
      }

      function adjustUI(shouldShowMenu, entry_id, header, body, footer, input, microphone, enter, company_title_description, setPlaceHolders, id) {
        const adjustBodyHeight = (headerContainsDescription, heightWithDescription, heightWithoutDescription) => {
          body.style.height = headerContainsDescription ? heightWithDescription : heightWithoutDescription;
        };

        if (!shouldShowMenu) {
          footer.style.display = "none";
          adjustBodyHeight(header.contains(company_title_description), "calc(100% - 168px)", "calc(100% - 93px)");
          footer.classList.add("close");
        } else {
          if (entry_id) {
            input.style.pointerEvents = "auto";
            microphone.style.pointerEvents = "auto";
            microphone.style.opacity = 1;
            enter.style.pointerEvents = "auto";
            setPlaceHolders();
            adjustBodyHeight(header.contains(company_title_description), "calc(100% - 218px)", "calc(100% - 143px)");
          } else {
            input.style.pointerEvents = "none";
            microphone.style.pointerEvents = "none";
            microphone.style.opacity = 0;
            enter.style.pointerEvents = "none";
            input.blur();
            input.placeholder = "Choose from Menu";
            input.type = "text";
            adjustBodyHeight(header.contains(company_title_description), "calc(100% - 218px)", "calc(100% - 143px)");
          }
        }
        if (id && id == 1) {
          if (picker) {
            try {
              picker.destroy();
            } catch (e) {
            } finally {
            }
          }
        }
      }

      function translateContent(translations, elem, text, main_lang_code, language_code, type = 1) {
        if (type == 2) {
          elem.placeholder = text;
        } else {
          elem.innerHTML = text;
        }
        let temp_text = text;
        if (translations && translations.length > 0) {
          for (var i = 0; i < translations.length; i++) {
            if (main_lang_code == "default" && language_code != "en") {
              if (translations[i].keyword === text && language_code == translations[i].iso_code) {
                temp_text = translations[i].translation;
                break;
              }
            } else if (main_lang_code != "default" && main_lang_code != "en") {
              if (translations[i].keyword === text && main_lang_code == translations[i].iso_code) {
                temp_text = translations[i].translation;
                break;
              }
            }
          }
          if (type == 2) {
            elem.placeholder = temp_text;
          } else {
            elem.innerHTML = temp_text;
          }
          if (main_lang_code && language_code) {
            var rtlLanguages = ["he", "ur", "ar"];
            if (main_lang_code && rtlLanguages.includes(main_lang_code)) {
              elem.classList.add("rtl");
            } else if (main_lang_code === "default" && rtlLanguages.includes(language_code)) {
              elem.classList.add("rtl");
            }
          }
        }
      }

      function generateTranslatedContent(translations, text, main_lang_code, language_code, input) {
        let temp_text = text;
        if (translations && translations.length > 0) {
          for (var i = 0; i < translations.length; i++) {
            if (main_lang_code == "default" && language_code != "en") {
              if (translations[i].keyword === text && language_code == translations[i].iso_code) {
                temp_text = translations[i].translation;
                break;
              }
            } else if (main_lang_code != "default" && main_lang_code != "en") {
              if (translations[i].keyword === text && main_lang_code == translations[i].iso_code) {
                temp_text = translations[i].translation;
                break;
              }
            }
          }
          if (main_lang_code && language_code && input) {
            var rtlLanguages = ["he", "ur", "ar"];
            if (main_lang_code && rtlLanguages.includes(main_lang_code)) {
              input.classList.add("rtl");
            } else if (main_lang_code === "default" && rtlLanguages.includes(language_code)) {
              input.classList.add("rtl");
            }
          }
        }
        return temp_text;
      }

      var main_image_shadow;
      var already_total_fn_loaded;
      var answer_color;
      var eccentric_param_object = {};
      var start_again_clicked;
      var is_disabled;
      var department_settings;
      var store_session;
      var store_session_called;
      var checkboxDropdown;
      var form_value;
      var contact_key = 0;
      var roinet_old_session;
      var out_of_office_jump;

      const GAHelper = {
        detectGAVersion() {
            if (typeof gtag === 'function') {
                return 'GA4';
            } else if (typeof ga === 'function') {
                return 'UA';
            }
            return null;
        },
        sendEvent(eventData) {
            const version = this.detectGAVersion();
            
            if (!version) {
                console.log('No Google Analytics installation detected');
                return false;
            }
    
            const {
                action,
                category = 'Chatbot',
                userInfo = {},
                additionalParams = {}
            } = eventData;
    
            try {
                if (version === 'GA4') {
                    // GA4 event tracking
                    const eventParams = {
                        event_category: category,
                        chat_action: action,
                        ...userInfo,
                        ...additionalParams
                    };
                    gtag('event', 'chatbot_interaction', eventParams);
                } else {
                    // Universal Analytics event tracking
                    ga('send', {
                        hitType: 'event',
                        eventCategory: category,
                        eventAction: action,
                        eventLabel: JSON.stringify(userInfo),
                        eventValue: additionalParams.value
                    });
                }
                return true;
            } catch (error) {
                console.log('Error sending analytics:', error);
                return false;
            }
        }
      };

      function trackChatbotInteraction(eventData) {
        return GAHelper.sendEvent(eventData);
      }

      function trackUserSubmission(userInfo) {
        return trackChatbotInteraction({
            action: 'user_info_submitted',
            userInfo: {
                user_type: userInfo.type || 'unknown',
                user_location: userInfo.location || 'unknown',
                user_country_code: userInfo.country_code || 'unknown',
                user_device_print: userInfo.device_print || 'unknown',
                user_ipv4: userInfo.ipv4 || 'unknown',                 
                submission_success: true
            }
        });
      }

      const FBPixelHelper = {
        isPixelInitialized() {
          return typeof fbq === 'function';
        },
        sendEvent(eventData) {
          if (!this.isPixelInitialized()) {
            console.log('Facebook Pixel not initialized');
            return false;
          }
      
          const { eventName, params = {} } = eventData;
      
          try {
            fbq('track', eventName, params);
            return true;
          } catch (error) {
            console.log('Error sending Facebook Pixel event:', error);
            return false;
          }
        }
      };

      function trackUserSubmissionFacebook(userInfo) {
        return FBPixelHelper.sendEvent({
          eventName: 'ChatbotSubmit',
          params: {
            user_type: userInfo.type || 'unknown',
            user_location: userInfo.location || 'unknown',
            user_country_code: userInfo.country_code || 'unknown',
            user_device_print: userInfo.device_print || 'unknown',
            user_ipv4: userInfo.ipv4 || 'unknown',  
            success: true,
            timestamp: new Date().toISOString()
          }
        });
      }
        

      function totalFn() {
        setTimeout(function () {
          if (document.getElementById("pulse_smatbot_unique")) {
            document.getElementById("pulse_smatbot_unique").innerHTML = "";
          }
        }, 500);
        var pulseDiv = document.createElement("DIV");
        pulseDiv.id = "pulse";
        if (chatbot_id == 10561 || chatbot_id == 14964 || chatbot_id == 23895) {
          pulseDiv.style.cssText = pulseDiv.style.cssText + "width:60px !important";
          pulseDiv.style.cssText = pulseDiv.style.cssText + "height:60px !important";
        }
        mainDiv = document.createElement("DIV");
        pulseDiv.appendChild(mainDiv);
        mainDiv.id = "closed";
        if (typeof chatbot_id != "undefined" && (chatbot_id == 3333 || chatbot_id == 23895)) {
        } else {
          mainDiv.classList.add("pulse-btn");
        }
        consentDiv = document.createElement("DIV");
        consentDiv.classList.add("consent-div");
        var consent_label = document.createElement("LABEL");
        consent_label.classList.add("consent-label");
        consentDiv.appendChild(consent_label);
        var consent_btn = document.createElement("BUTTON");
        consent_btn.classList.add("confirm-btn-smatest");
        consent_btn.classList.add("consent-btn");
        translateContent(translations, consent_btn, "I agree", main_lang_code, language_code);
        consent_btn.addEventListener("click", function (k) {
          agreed = !0;
          if (
            document.getElementsByClassName("upload-button-sb") &&
            document.getElementsByClassName("upload-button-sb").length > 0
          ) {
            document
              .getElementsByClassName("upload-button-sb")[0]
              .classList.remove("no-pointer-events");
          }
          body.removeChild(consentDiv);
        });
        consentDiv.appendChild(consent_btn);
        multiLangDiv = document.createElement("DIV");
        multiLangDiv.classList.add("multi-lang-div");
        var multi_lang_div = document.createElement("div");
        multi_lang_div.style.width = '100%'
        multi_lang_div.style.display = 'flex'
        multi_lang_div.style.justifyContent = 'center'
        multi_lang_div.style.flexWrap = 'wrap'

        var multi_lang_label = document.createElement("LABEL");
        multi_lang_label.classList.add("consent-label");
        multi_lang_label.style.textAlign = 'center'
        if (totalData[0].multilingual_statement && totalData[0].multilingual_statement.length > 0) {
          multi_lang_label.innerHTML = totalData[0].multilingual_statement;
        } else {
          multi_lang_label.innerHTML = "Please choose a language of your preference";
        }
        multiLangDiv.appendChild(multi_lang_label);
        var launcher_position;
        var img = document.createElement("Img");
        img.id = "main_icon_smatest";
        img.alt = "Primary logo of " + totalData[0].name;
        var imgLogo = document.createElement("Img");
        imgLogo.id = "logo-smatest";
        imgLogo.alt = "Secondary logo of " + totalData[0].name
        imgLogo.classList.add("logo-smatest");
        mainDiv.style.display = "none";
        mainDiv.classList.add("other-pointer");
        var launcher_div = document.createElement("DIV");
        var launcher_header = document.createElement("DIV");
        launcher_header.classList.add("launcher-header-div");
        var launcher_header_label = document.createElement("LABEL");
        launcher_header_label.classList.add("launcher-header-label");
        launcher_header.appendChild(launcher_header_label);
        var launcher_label_main_div = document.createElement("DIV");
        launcher_label_main_div.classList.add("launcher-label-main-div");
        var launcher_text = document.createElement("LABEL");
        launcher_div.appendChild(launcher_header);
        launcher_label_main_div.appendChild(launcher_text);
        launcher_div.appendChild(launcher_label_main_div);
        launcher_text.classList.add("launcher-label-main");
        launcher_text.style.cssText = launcher_text.style.cssText + "margin:0px !important";
        launcher_text.style.cssText = launcher_text.style.cssText + "padding:0px !important";
        var launcher_close_icon = document.createElement("IMG");
        launcher_close_icon.src =
          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/launcher_close_icon.png";
        launcher_close_icon.classList.add("launcher-close-icon");
        launcher_close_icon.addEventListener("click", function (k) {
          launcher_div.parentElement.removeChild(launcher_div);
          launcher_close_icon.parentElement.removeChild(launcher_close_icon);
          this.parentElement.removeChild(this);
          this.parentElement.style.height = "80px";
        });
        // pulseDiv.appendChild(launcher_close_icon);
        launcher_div.appendChild(launcher_close_icon);
        var audio_loading_div = document.createElement("DIV");
        var avatar_icon;
        var anotherDiv = document.createElement("DIV");
        anotherDiv.id = "opened";
        if (
          /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
            navigator.userAgent
          )
        ) {
          var x = window.innerWidth - 10;
        }
        var header = document.createElement("DIV");
        if (chatbot_id == 20609) {
          header.classList.add("header-div-isp");
        } else {
          header.classList.add("header-div");
        }
        var icon_header_div = document.createElement("DIV");
        icon_header_div.classList.add("icon-header-div");
        body = document.createElement("DIV");
        body.classList.add("body-div");
        if (header.contains(company_title_description)) {
          body.style.height = "calc(100% - 168px)";
        } else {
          body.style.height = "calc(100% - 93px)";
        }
        anotherDiv.appendChild(header);
        var footer = document.createElement("DIV");
        footer.style.borderRadius ='8px';
        footer.style.margin ='auto 5%';
        footer.style.width ='90%';
        footer.classList.add("footer-div");
        footer.classList.add("close");
        // var input = document.createElement("TEXTAREA");
        var input = document.createElement("INPUT");
        input.style.cssText = input.style.cssText + "padding: 0 5px !important";
        input.style.cssText = input.style.cssText + "position: relative !important";
        
        translateContent(translations, input, "Type an answer", main_lang_code, language_code, 2);
        input.classList.add("answer-text");
        input.addEventListener(
          "click",
          function (k) {
            input.focus();
            if (totalWidth) {
              if (
                /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                  navigator.userAgent
                )
              ) {
                anotherDiv.style.cssText =
                  anotherDiv.style.cssText +
                  "max-width:" +
                  totalWidth +
                  "px !important";
              }
            }
            if (header.contains(company_title_description)) {
              header.removeChild(company_title_description);
              header.style.textAlign = "center";
              imgLogo.style.marginLeft = "0px";
              imgLogo.style.height = "36px";
              imgLogo.style.width = "36px";
              imgLogo.style.top = "0";
              company_name_dec.style.display = "inline-flex";
              header.style.height = "60px";
              company_name_dec.style.float = "left";
              imgLogo.style.marginLeft = "0px";
              imgLogo.style.height = "36px";
              imgLogo.style.width = "36px";
              if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                document.getElementById('rating-live-chat-feedback_div_sb').style.top = '60px'
              }
              if (header.classList.contains("header-ease-in")) {
                header.classList.remove("header-ease-in");
              }
              var selected_orders_div = document.getElementById("selected-orders");
              if (footer.style.display == "none") {
                body.style.height = "calc(100% - 93px)";
              } else if (footer.contains(selected_orders_div)) {
                body.style.height = "calc(100% - 174px)";
              } else {
                if (footer.style.height == "230px") {
                  body.style.height = "calc(100% - 323px)";
                } else if (footer.style.height == "315px") {
                  body.style.height = "calc(100% - 408px)";
                } else {
                  var x = footer.offsetHeight + 93+13;
                  body.style.height = "calc(100% - " + x + "px)";
                }
              }
            }
          },
          !1
        );
        var enterSVG = `
          <svg xmlns="http://www.w3.org/2000/svg" width="17.753" height="17.753" viewBox="0 0 17.753 17.753">
            <path d="M10.771.043,1.628,2.33a2.149,2.149,0,0,0,.029,4.176L4.5,7.175a.209.209,0,0,0,.2-.056L8,3.816a.524.524,0,1,1,.74.739l-3.306,3.3a.209.209,0,0,0-.056.2L6.049,10.9a2.149,2.149,0,0,0,4.176.029L12.511,1.78A1.433,1.433,0,0,0,10.771.043Z" transform="translate(8.876) rotate(45)"/>
          </svg>
          `;
          var enter = document.createElement("i");
         enter.classList.add("enter-icon");
         enter.innerHTML = enterSVG; 
        var microphone = document.createElement("IMG");
        microphone.src =
          // "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/bot_input_mic.svg";
          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/microphone-widget-new.svg"
        microphone.classList.add("microphone-icon");
        microphone.alt = "Mirophone";
        var live_file_input = document.createElement("INPUT");
        live_file_input.type = "file";
        if (
          /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
            navigator.userAgent
          )
        ) {
        } else {
          live_file_input.accept = "*";
        }
        live_file_input.id = "live-file-input";
        live_file_input.style.display = "none";
        var attach_label = document.createElement("LABEL");
        var attach_file = document.createElement("IMG");
        attach_file.src =
          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/paperclip_widget_new.svg";
        attach_file.classList.add("attach-file-icon");
        attach_label.appendChild(attach_file);
        attach_label.htmlFor = "live-file-input";
        attach_label.classList.add("m-t-0");
        attach_label.style.marginRight = "10px";
        attach_label.classList.add("pull-right-i");
        var menu = document.createElement("IMG");
        menu.classList.add("menu-icon-sb");
        menu.src =
         "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/headder_menu_icon_new_sb.svg"
        var opened_menu = document.createElement("IMG");
        opened_menu.classList.add("menu-icon-sb");
        opened_menu.src =
          "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/close_modal.png";
        opened_menu.classList.add("opacity-0");
        var menu_options_div = document.createElement("DIV");
        menu_options_div.classList.add("menu-options-div");
        menu_options_div.classList.add("close");
        menu.addEventListener("click", function (k) {
          if (menu_options_div.classList.contains("close")) {
            menu_options_div.classList.remove("close");
            menu.classList.add("opacity-0");
            opened_menu.classList.remove("opacity-0");
          } else {
            menu_options_div.classList.add("close");
            opened_menu.classList.add("opacity-0");
            menu.classList.remove("opacity-0");
          }
          nothingWentOnFor = 0;
          encourageMessageIteration = 0;
        });
        opened_menu.addEventListener("click", function (k) {
          if (menu_options_div.classList.contains("close")) {
            menu_options_div.classList.remove("close");
            menu.classList.add("opacity-0");
            opened_menu.classList.remove("opacity-0");
          } else {
            menu_options_div.classList.add("close");
            opened_menu.classList.add("opacity-0");
            menu.classList.remove("opacity-0");
          }
          nothingWentOnFor = 0;
          encourageMessageIteration = 0;
        });
        document.addEventListener('click', function(event) {
          if (!menu_options_div.contains(event.target) && !menu.contains(event.target) && !opened_menu.contains(event.target)) {
              if (!menu_options_div.classList.contains('close')) {
                  menu_options_div.classList.add('close');
                  opened_menu.classList.add("opacity-0");
                  menu.classList.remove("opacity-0");
              }
          }
        });
        footer.appendChild(input);
        footer.appendChild(enter);
        anotherDiv.appendChild(body);
        var smat_footer = document.createElement("DIV");
        var smt_label = document.createElement("SPAN");
        var smat;
        if (typeof chatbot_id != "undefined" && (chatbot_id == 3333 || chatbot_id == 23895)) { 
          smat = document.createTextNode("Powered by ");
        } else {
          if(totalData[0].custom_brand_name && totalData[0].custom_brand_name.toLowerCase() == "cloudway.ai") {
            smat = document.createTextNode("Powered by");
          } else {
            smat = document.createTextNode("we run on");
          }
          
        }
        smt_label.appendChild(smat);
        smt_label.style.float = "revert";
        smt_label.style.color = "#576E93";
        smt_label.style.fontSize = "12px";
        smt_label.style.fontWeight = "500";
        smt_label.style.cssText = smt_label.style.cssText + "display:inline-block !important";
        var smat_label = document.createElement("SPAN");
        smat_label.style.float = "right";
        smat_label.style.cssText = smat_label.style.cssText + "display:inline-block !important";
        var smat_a = document.createElement("A");
        // smat_a.title = "Powered by SmatBot";
        smat_a.style.float = "left";
        smat_a.style.marginLeft = "3px";
        smat_a.classList.add("smat-branding-a");
        smat_a.target = "_blank";
        smat_a.style.cssText = smat_a.style.cssText + "display:block !important";
        if (
          chatbot_id == 527 ||
          chatbot_id == 746 ||
          chatbot_id == 3182
        ) {
          smat_a.href = "https://www.firstmeridian.com/";
          var img_brand = document.createElement("IMG");
          smat_a.appendChild(img_brand);
          img_brand.src =
            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/digibot-logo.png";
          img_brand.style.height = "12px";
          img_brand.alt = "Digibot";
          img_brand.style.verticalAlign = "middle";
          img_brand.style.marginLeft = "5px";
        } else {
          if (
            /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
              navigator.userAgent
            )
          ) {
            var medium = "mobile";
          } else {
            var medium = "desktop";
          }
          if (
            totalData[0].stop_redirection &&
            totalData[0].stop_redirection == "0"
          ) {
            if(chatbot_id && (chatbot_id == 5486 || chatbot_id == 17113 || chatbot_id == 17030)) {} else {
              smat_a.href = main_url + "/";
              smat_a.addEventListener("click", function (k) {
                if (smat_a && smat_a.href.includes("smatbot.com")) {
                  smat_a.href = main_url + "/";
                  smat_a.href =
                    smat_a.href +
                    "?utm_source=" +
                    window.location.href +
                    "&utm_medium=" +
                    medium;
                }
              });  
            }
          }
          smat_a.innerHTML = 'SmatBot'
            // '<img alt="SmatBot" src="https://s3.ap-south-1.amazonaws.com/custpostimages/sb_images/SB_logo_horizontal_text.png" style="height: 20px !important;display:block !important;">';
        }
        smat_label.appendChild(smat_a);
        smat_footer.appendChild(smt_label);
        smat_footer.appendChild(smat_label);
        smat_footer.classList.add("smat-footer");
        smat_footer.style.cssText =
          smat_footer.style.cssText + "display:flex !important;";
        if (chatbot_id == 18664 || chatbot_id == 20097) {
          smat_footer.style.cssText =
            smat_footer.style.cssText + "position:relative !important;";
          smat_footer.style.cssText =
            smat_footer.style.cssText + "bottom:0 !important;";
          smat_footer.style.cssText =
            smat_footer.style.cssText + "right:0 !important;";
        }
        if (chatbot_id == 23568) {
          smat_footer.style.cssText = smat_footer.style.cssText + "pointer-events: none;";
          smat_footer.style.cssText = smat_footer.style.cssText + "cursor: none;";
        }
        anotherDiv.appendChild(footer);
        var close = document.createElement("I");
        close.classList.add("close-icon");
        close.title = "Close Bot";
        reload_div = document.createElement("DIV");
        reload_div.classList.add("header-menu-item");
        var reload = document.createElement("I");
        reload.classList.add("reload-icon");
        reload.id = "reload";
        reload.title = "Refresh Chat";
        reload_div.appendChild(reload);
        var reload_text = document.createElement("span");
        reload_text.innerHTML = "Restart Chat";
        reload_text.classList.add("header-menu-item-text");
        reload_div.appendChild(reload_text);
        var close_bot = document.createElement("I");
        close_bot.id = "minimise";
        close_bot.title = "Minimise Bot";
        close_bot.classList.add("close-bot-icon");
        var header_menu = document.createElement("I");
        header_menu.classList.add("header-menu-icon");
        header_menu.id = "Menu";
        header_menu.title = "Menu";

        var reload_menu = document.createElement("I");
        reload_menu.classList.add("refresh-menu-icon");
        reload_menu.id = "reload_icon";
        reload_menu.title = "Refresh Chat";

        var header_menu_div = document.createElement("DIV");
        header_menu_div.classList.add("header-menu-div");
        header_menu_div.classList.add("closed-header-menu");
        var company_title_description = document.createElement("DIV");
        company_title_description.classList.add("company-title-description-div");
        var company_title_label = document.createElement("LABEL");
        company_title_label.innerHTML = "Hi 🙂 Welcome to SmatBot";
        company_title_label.classList.add("company-title-label");
        var company_description_label = document.createElement("LABEL");
        company_description_label.innerHTML = "";
        company_description_label.classList.add("company-description-label");
        company_title_description.appendChild(company_title_label);
        company_title_description.appendChild(company_description_label);
        var video_call_icon_div = document.createElement("DIV");
        video_call_icon_div.classList.add("header-menu-item");
        var video_call = document.createElement("I");
        video_call.classList.add("video-call-icon");
        video_call.id = "video_call";
        video_call.title = "Start Video Call";
        video_call_icon_div.appendChild(video_call);
        var video_call_text = document.createElement("span");
        video_call_text.innerHTML = "Start Video Call";
        video_call_text.classList.add("header-menu-item-text");
        video_call_icon_div.appendChild(video_call_text);
        var ask_live_chat_feedback_div = document.createElement("DIV");
        ask_live_chat_feedback_div.classList.add("header-menu-item");
        var ask_live_chat_feedback = document.createElement("I");
        ask_live_chat_feedback.classList.add("live-chat-feedback-icon");
        ask_live_chat_feedback.id = "ask-live-chat-feedback";
        ask_live_chat_feedback.title = "Submit Feedback";
        ask_live_chat_feedback_div.appendChild(ask_live_chat_feedback);
        var ask_live_chat_feedback_text = document.createElement("span");
        ask_live_chat_feedback_text.innerHTML = generateTranslatedContent(translations, "Rate Conversation", main_lang_code, language_code, input);
        ask_live_chat_feedback_text.classList.add("header-menu-item-text");
        ask_live_chat_feedback_div.appendChild(ask_live_chat_feedback_text);
        var sound_icon_div = document.createElement("DIV");
        sound_icon_div.classList.add("header-menu-item");
        var sound_icon = document.createElement("I");
        sound_icon.classList.add("sound-icon");
        sound_icon.title = "Sound";
        sound_icon_div.appendChild(sound_icon);
        var sound_text = document.createElement("span");
        sound_text.innerHTML = "Mute Notifications";
        sound_text.classList.add("header-menu-item-text");
        sound_icon_div.appendChild(sound_text);
        var more_icon = document.createElement("I");
        more_icon.classList.add("more-icon");
        more_icon.title = "More";
        var bot_mic = document.createElement("I");
        bot_mic.title = "Trigger Human chat";
        var noBot;
        var trigger_time;
        var trigger_time_mobile;
        var font;
        var mailSequence;
        var currentMailSequence;
        var currentQuestionIsLead;
        var alreadyClicked;
        var mailSent;
        var closure_enable;
        var random_key;
        var current_logical_jump;
        var zapier_webhook;
        var selectedCode;
        var entry_question;
        var entry_id;
        var showInput;
        var sheet_id;
        var df_options;
        var question_and_answers = [];
        var alreadyShowedActions;
        var themes_array;
        var take_action_id;
        var take_action_sequence;
        var custom_action_id;
        var custom_action_sequence;
        var doneThatTAF;
        var scheduleClicked;
        var delay_time = 250;
        var other_delay_time = 260;
        var totalWidth;
        var company_email_validation;
        var email_otp_validated;
        var webpage_closing_alert;
        var alreadyWebpageClosed;
        var notification_sound_enabled;
        var bot_type;
        var button_radius;
        var button_text_alignment;
        var button_border;
        var question_bubble_type;
        if (totalData && totalData.length > 0) {
          if (
            totalData[0].custom_brand_enabled &&
            totalData[0].custom_brand_enabled == "1"
          ) {
            if (
              totalData[0].custom_brand_name &&
              totalData[0].custom_brand_name.length > 0
            ) {
              partner_client_details = true;
              brand_name_added = totalData[0].custom_brand_name;
              console.log("fygyuhio",brand_name_added)
              if (
                totalData[0].custom_brand_url &&
                totalData[0].custom_brand_url.length > 0
              ) {
                if (totalData[0].custom_brand_name == "KP AI Solutions") {
                  smat_a.href = totalData[0].custom_brand_url;
                  smat_a.innerHTML =
                    '<img src="https://kpaisolutions.com/images/logo1.png" style="height: 20px;">';
                } else {
                  smat_a.innerHTML = totalData[0].custom_brand_name;

                  if (totalData[0].custom_brand_url.startsWith('http')) {
                    smat_a.href = totalData[0].custom_brand_url
                  }else{
                    smat_a.href =  `https://${totalData[0].custom_brand_url}` 
                  }
                  // smat_a.href = totalData[0].custom_brand_url;
                }
              }
            }
          }
          bot_type = totalData[0].bot_type;
          voice_input = totalData[0].voice_input;
          if (voice_input == "1") {
            footer.appendChild(microphone);
            appendScriptLinks("https://aka.ms/csspeech/jsbrowserpackageraw", "script");
            appendScriptLinks("https://cdn.jsdelivr.net/npm/microsoft-cognitiveservices-speech-sdk@latest/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle.js", "script");
          }
          if (
            totalData[0].view_setup_object &&
            totalData[0].view_setup_object.length > 0
          ) {
            var json = JSON.parse(totalData[0].view_setup_object);
            if (json.button_radius && json.button_radius.toString().length > 0) {
              button_radius = json.button_radius + "px";
            } else {
              button_radius = "6px";
            }
            if (
              json.button_text_alignment &&
              json.button_text_alignment.toString().length > 0
            ) {
              if (json.button_text_alignment == "1") {
                button_text_alignment = "left";
              } else if (json.button_text_alignment == "2") {
                button_text_alignment = "center";
              } else if (json.button_text_alignment == "3") {
                button_text_alignment = "right";
              } else {
                button_text_alignment = "left";
              }
            } else {
              button_text_alignment = "left";
            }
            if (json.button_border && json.button_border.length > 0) {
              button_border = json.button_border;
            }
            if (
              json.question_bubble_type &&
              json.question_bubble_type.toString().length > 0
            ) {
              question_bubble_type = json.question_bubble_type;
            } else {
              question_bubble_type = "3";
            }
            if (
              json.bot_description &&
              json.bot_description.toString().length > 0
            ) {
              company_description_label.innerHTML = json.bot_description;
            }
            if (json.main_opacity && json.main_opacity.toString().length > 0) {
              var opacity = parseInt(json.main_opacity) / 100;
              main_image_shadow = "inset 0 0 0 2000px rgba(0,0,0," + opacity + ")";
            }
          } else {
            button_radius = "6px";
            button_text_alignment = "left";
            question_bubble_type = "3";
            main_image_shadow = "inset 0 0 0 2000px rgba(0,0,0,0)";
          }
          if (totalData[0].consent_enabled && totalData[0].consent_enabled == "0") {
            agreed = !0;
          } else if (
            totalData[0].consent_enabled &&
            totalData[0].consent_enabled == "1"
          ) {
            agreed = !1;
          }
          if (
            totalData[0].consent_enabled_for_euro &&
            totalData[0].consent_enabled_for_euro == "0"
          ) {
            if (euro_country_codes.indexOf(user_country_code) > -1) {
              agreed = false;
            }
          } else {
            if (euro_country_codes.indexOf(user_country_code) > -1) {
              agreed = false;
            } else {
              if (
                totalData[0].consent_enabled &&
                totalData[0].consent_enabled == "0"
              ) {
                agreed = true;
              } else if (
                totalData[0].consent_enabled &&
                totalData[0].consent_enabled == "1"
              ) {
                agreed = !1;
              }
            }
          }
          if (
            totalData[0].multi_lingual_switch &&
            totalData[0].multi_lingual_switch == "1"
          ) {
            multi_lingual_switch = !0;
          }
          if (totalData[0].store_session && totalData[0].store_session == "1") {
            store_session = true;
          }
          if (totalData[0].revisit_switch && totalData[0].revisit_switch == "1") {
            start_again_switch = !0;
          } else {
            start_again_switch = !1;
          }
          if (totalData[0].email_otp_vali && totalData[0].email_otp_vali == "1") {
            email_otp_validated = !0;
          }
          if (
            totalData[0].lead_unfilled_alert &&
            totalData[0].lead_unfilled_alert == "1"
          ) {
            webpage_closing_alert = !0;
          }
          if (
            totalData[0].notification_sound_enabled &&
            totalData[0].notification_sound_enabled == "1"
          ) {
            notification_sound_enabled = !0;
          }
          if(partner_client_details){
            consent_label.innerHTML =  `By clicking below, you consent to allow  ${brand_name_added || ''} to store and process the information collected through this chat to assist you further.`;
          }else{
            consent_label.innerHTML = totalData[0].consent_text;
          }          
          if (
            (totalData[0].phone_validation &&
              totalData[0].phone_validation == "1") ||
            (totalData[0].whatsapp_otp_val && totalData[0].whatsapp_otp_val == "1")
          ) {
            otp_validation = !0;
            old_otp_validation = !0;
          }
          if (
            totalData[0].skip_otp_validation &&
            totalData[0].skip_otp_validation == "1"
          ) {
            skip_otp_validation = !0;
          }
          try {
            lang_json = JSON.parse(totalData[0].properties);
            if (lang_json.multi_lingual && lang_json.multi_lingual == 1) {
              var keys = Object.keys(lang_json.languages);
              var default_text;
              for (var k = 0; k < all_languages.length; k++) {
                if (all_languages[k].iso_code == totalData[0].language_code) {
                  default_text = all_languages[k].script_form;
                }
              }
              var def_lang_btn = document.createElement("BUTTON");
              def_lang_btn.classList.add("confirm-btn-smatest");
              def_lang_btn.classList.add("consent-btn");
              def_lang_btn.classList.add("m-l-5");
              def_lang_btn.classList.add("m-r-5");
              setTimeout(function () {
                if (font && font.length > 0) {
                  def_lang_btn.classList.add(font);
                }
              }, 500);
              def_lang_btn.id = totalData[0].language_code;
              def_lang_btn.innerHTML = default_text;
              def_lang_btn.addEventListener("click", function (k) {
                main_lang_code = this.id;
                if (body.contains(multiLangDiv)) {
                  body.removeChild(multiLangDiv);
                  multiLangDiv.classList.remove("scale-1");
                }
                var langXhttp = new XMLHttpRequest();
                langXhttp.onreadystatechange = function () {
                  if (this.readyState == 4 && this.status == 200) {
                    translations = JSON.parse(this.responseText).translations;
                    if(partner_client_details){
                      let message = `By clicking below, you consent to allow ${brand_name_added || ''} to store and process the information collected through this chat to assist you further.`;
                      translateContent(translations, consent_label, message, main_lang_code, language_code);
                    }else{
                      translateContent(translations, consent_label, "By clicking below, you consent to allow SmatBot to store and process the information collecting through this chat to assist you further.", main_lang_code, language_code);
                    }
                    translateContent(translations, consent_btn, "I agree", main_lang_code, language_code);
                  }
                };
                langXhttp.open(
                  "GET",
                  main_url +
                  "/kya_backend/pagehub/translation?language_code=" +
                  main_lang_code,
                  !0
                );
                langXhttp.setRequestHeader(
                  "Content-type",
                  "application/x-www-form-urlencoded"
                );
                langXhttp.send();
                mainApiCall();
              });
              
              multi_lang_div.appendChild(def_lang_btn);
              multiLangDiv.appendChild(multi_lang_div);

              if (keys && keys.length) {
              } else {
                var keys_arr = [];
                var keys_of_keys = Object.keys(keys);
                for (var i = 0; i < keys_of_keys.length; i++) {
                  keys_arr.push(keys[keys_of_keys]);
                }
                keys = keys_arr;
              }
              for (var i = 0; i < keys.length; i++) {
                var x;
                for (var k = 0; k < all_languages.length; k++) {
                  if (all_languages[k].iso_code == lang_json.languages[keys[i]]) {
                    x = all_languages[k].script_form;
                  }
                }
                var lang_btn = document.createElement("BUTTON");
                lang_btn.classList.add("confirm-btn-smatest");
                lang_btn.classList.add("consent-btn");
                lang_btn.classList.add("m-l-5");
                lang_btn.classList.add("m-r-5");
                setTimeout(function () {
                  if (font && font.length > 0) {
                    lang_btn.classList.add(font);
                  }
                }, 500);
                lang_btn.innerHTML = x;
                lang_btn.id = lang_json.languages[keys[i]];
                lang_btn.addEventListener("click", function (k) {
                  main_lang_code = this.id;
                  if (body.contains(multiLangDiv)) {
                    body.removeChild(multiLangDiv);
                  }
                  var langXhttp = new XMLHttpRequest();
                  langXhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      translations = JSON.parse(this.responseText).translations;
                      if(partner_client_details){ 
                        let message = `By clicking below, you consent to allow ${brand_name_added || ''} to store and process the information collected through this chat to assist you further.`;
                        translateContent(translations, consent_label, message, main_lang_code, language_code);
                      }else{
                        translateContent(translations, consent_label, "By clicking below, you consent to allow SmatBot to store and process the information collecting through this chat to assist you further.", main_lang_code, language_code);
                      }
                      translateContent(translations, consent_btn, "I agree", main_lang_code, language_code);
                    }
                  };
                  langXhttp.open(
                    "GET",
                    main_url +
                    "/kya_backend/pagehub/translation?language_code=" +
                    main_lang_code,
                    !0
                  );
                  langXhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  langXhttp.send();
                  mainApiCall();
                });
                multi_lang_div.appendChild(lang_btn);
              multiLangDiv.appendChild(multi_lang_div);
              }
            } else {
              main_lang_code = language_code;
            }
          } catch (e) {
          } finally {
          }
          if (
            totalData[0].adwords_integration &&
            totalData[0].adwords_integration == "1"
          ) {
            is_adwords_enabled = !0;
          }
          if (
            totalData[0].text_to_speech_status &&
            totalData[0].text_to_speech_status == "1"
          ) {
            is_sound_on = !0;
            is_speech_on = !0;
            appendScriptLinks("https://aka.ms/csspeech/jsbrowserpackageraw", "script");
          }
          if (
            totalData[0].text_to_speech_voice &&
            totalData[0].text_to_speech_voice == "1"
          ) {
            is_female_voice = !0;
          } else {
            is_female_voice = !1;
          }
          if (totalData[0].language_code && totalData[0].language_code.length > 0) {
            language_code = totalData[0].language_code;
          } else {
            language_code = "ar";
          }
          if (language_code && language_code != "en") {
            var langXhttp = new XMLHttpRequest();
            langXhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                translations = JSON.parse(this.responseText).translations;
                if(partner_client_details){
                  let message = `By clicking below, you consent to allow ${brand_name_added || ''} to store and process the information collected through this chat to assist you further.`;
                  translateContent(translations, consent_label, message, main_lang_code, language_code);
                }else{
                  translateContent(translations, consent_label, "By clicking below, you consent to allow SmatBot to store and process the information collecting through this chat to assist you further.", main_lang_code, language_code);
                }          
                translateContent(translations, consent_btn, "I agree", main_lang_code, language_code);
              }
            };
            langXhttp.open(
              "GET",
              main_url +
              "/kya_backend/pagehub/translation?language_code=" +
              language_code,
              !0
            );
            langXhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            langXhttp.send();
          }
          if (
            totalData[0].lead_revisit_notification &&
            totalData[0].lead_revisit_notification == "1"
          ) {
            lead_revisit_notification = 1;
          } else {
            lead_revisit_notification = 0;
          }
          if (totalData[0].delay_switch == "1") {
            delay_time = 700;
            other_delay_time = 710;
            if (chatbot_id == 22583) {
              delay_time = 2000;
              other_delay_time = 2010;
            }
          }
          if (totalData[0].remove_branding && totalData[0].remove_branding == "1") {
          } else {
            anotherDiv.appendChild(smat_footer);
          }
          avatar_icon = totalData[0].avatar_url;
          is_disabled = totalData[0].is_disabled;
          sheet_id = totalData[0].spreadsheet_id;
          if (button_radius && button_radius.length > 0) {
          } else {
            button_radius = "6px";
          }
          appendScriptLinks(".refresh-btn { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".continue-btn { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".upload-button-sb { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".cancel-button-sb { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".contact-btn-smatest { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".confirm-btn-smatest-other { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".confirm-checkbox-btn-smatest { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".contact-list-btn { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".options-smatest { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".options-smatest-checkbox { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".confirm-btn-smatest { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".radio-slide-label { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".contact-div-smatest { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".dialogs-div-smatest { border-radius :" + button_radius + " !important; }", "style");
          appendScriptLinks(".dialogs-div-vertical-smatest { border-radius :" + button_radius + " !important; }", "style");

          if (button_text_alignment && button_text_alignment.length > 0) {
          } else {
            button_text_alignment = "left";
          }

          appendScriptLinks(".refresh-btn { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".continue-btn { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".upload-button-sb { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".cancel-button-sb { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".contact-btn-smatest { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".confirm-btn-smatest-other { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".confirm-checkbox-btn-smatest { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".contact-list-btn { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".options-smatest { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".options-smatest-checkbox { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".confirm-btn-smatest { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".radio-slide-label { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".contact-div-smatest { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".dialogs-div-smatest { text-align :" + button_text_alignment + " !important; }", "style");
          appendScriptLinks(".dialogs-div-vertical-smatest { text-align :" + button_text_alignment + " !important; }", "style");

          if (question_bubble_type && question_bubble_type.toString().length > 0) {
          } else {
            question_bubble_type = "3";
          }
          var bubble_radius;
          var bubble_answer_radius;
          var skip_radius;
          switch (question_bubble_type) {
            case "1":
              bubble_radius = "10px";
              bubble_answer_radius = "4px";
              skip_radius = "0 0 4px 4px";
              break;
            case "2":
              bubble_radius = "20px";
              bubble_answer_radius = "20px";
              skip_radius = "0 0 20px 20px";
              break;
            case "3":
              bubble_radius = "12px 12px 12px 0";
              bubble_answer_radius = "12px 12px 0px 12px";
              skip_radius = "0 0 12px 0px";
              break;
            default:
          }

          appendScriptLinks(".options-div-smatest { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".main-options-div-smatest { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".question-img-smatest { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".question-text { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".skip-question-div { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".spinner1-smatest { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".spinner2-smatest { border-radius :" + bubble_radius + " !important; }", "style");
          appendScriptLinks(".answer-label { border-radius :" + bubble_radius + " !important; }", "style");

          if (
            totalData[0].font_size &&
            totalData[0].font_size != null &&
            totalData[0].font_size.length > 0
          ) {
            appendScriptLinks(".consent-label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".feedback-icon { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".timezone-dropdown { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".file-name-sb { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".please-rate-us-text { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".menu-option-label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".autocomplete-items { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".new-autocomplete-items { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".consent-btn { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".smat-main-btn { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".smat-main-lb-btn { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".consent-btn { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".confirm-btn-smatest { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".slot-label { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".confirm-btn-smatest-slides { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".confirm-btn-smatest-other { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".contact-list-btn { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".contact-div-smatest a { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".options-smatest span { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".contact-btn-smatest { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".contact-desc-smatest { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".options-smatest-checkbox span { font-size :" + convertFontSizes(totalData[0].font_size, 2) + "; }", "style");
            appendScriptLinks(".consent { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".options-div-smatest label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".options-div-smatest label { margin :" + '0px !important' + "; }", "style");
            appendScriptLinks(".question-text-error { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".question-text { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".pac-controls label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".answer-label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".pac-container-thopest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".rating-div { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".rating-p { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".slider-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".simple-label-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".simple-label-smatest-other { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".options-smatest-checkbox span { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".check-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".slides-div-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".avatar-scrollbar label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".right-div-smat { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".contact-title-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".contact-title-dynamic-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".contact-desc-dynamic-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".dialogs-div-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".help-label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".other-help-label { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".answer-text { font-size :" + totalData[0].font_size + "; }", "style");
            appendScriptLinks(".smat-dropdown-botest { font-size :" + totalData[0].font_size + " !important; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest label { font-size :" + totalData[0].font_size + "; }", "style");

            if (
              totalData[0].font_size == "11px" ||
              totalData[0].font_size == "12px" ||
              totalData[0].font_size == "13px" ||
              totalData[0].font_size == "14px" ||
              totalData[0].font_size == "15px"
            ) {
              appendScriptLinks(".company-name-smatest { font-size : 16px; }", "style");
            } else {
              appendScriptLinks(".company-name-smatest { font-size :" + totalData[0].font_size + "; }", "style");
            }
          }
          if (totalData[0].theme && totalData[0].theme.length > 0) {
            themes_array = totalData[0].theme.split("..");
          }
          if (themes_array && themes_array[0] && themes_array[0].length > 0) {
            header.style.background = themes_array[0];
            var pulse_theme;
            if (
              themes_array[0].includes("rgb") ||
              themes_array[0].includes("rgba")
            ) {
              pulse_theme = themes_array[0];
            } else {
              var header_theme_array = themes_array[0].split(",");
              if (header_theme_array && header_theme_array.length > 1) {
                pulse_theme = header_theme_array[1].trim().split(" ")[0];
              } else {
                pulse_theme = themes_array[0];
              }
            }
            appendScriptLinks(".pulse-btn { box-shadow: 0 0 0 0 " + pulse_theme + "; }", "style");
            if (pulse_theme && pulse_theme.includes("rgba")) {
              var qsn_color = pulse_theme
                .replace("rgba(", "")
                .replace(")", "")
                .split(",");
              var o = Math.round(
                (parseInt(qsn_color[0]) * 299 +
                  parseInt(qsn_color[1]) * 587 +
                  parseInt(qsn_color[2]) * 114) /
                1000
              );
              var fore = o > 125 ? "black" : "white";
              main_fore = fore;
              appendScriptLinks(".company-name-smatest { color: " + fore + "; }", "style");
              appendScriptLinks(".company-title-label { color: " + fore + "; }", "style");
              appendScriptLinks(".company-description-label { color: " + fore + "; }", "style");
              appendScriptLinks(".company_dec_smatest { color: " + fore + "; }", "style");
            } else if (pulse_theme && pulse_theme.includes("rgb")) {
              var qsn_color = pulse_theme
                .replace("rgb(", "")
                .replace(")", "")
                .split(",");
              var o = Math.round(
                (parseInt(qsn_color[0]) * 299 +
                  parseInt(qsn_color[1]) * 587 +
                  parseInt(qsn_color[2]) * 114) /
                1000
              );
              var fore = o > 125 ? "black" : "white";
              main_fore = fore;
              appendScriptLinks(".company-name-smatest { color: " + fore + "; }", "style");
              appendScriptLinks(".company-title-label { color: " + fore + "; }", "style");
              appendScriptLinks(".company-description-label { color: " + fore + "; }", "style");
              appendScriptLinks(".company_dec_smatest { color: " + fore + "; }", "style");

            } else if (pulse_theme) {
              var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
                pulse_theme
              );
              if (result && result.length > 1) {
                var main_color =
                  "rgb(" +
                  parseInt(result[1], 16) +
                  "," +
                  parseInt(result[2], 16) +
                  "," +
                  parseInt(result[3], 16) +
                  ")";
                var qsn_color = main_color
                  .replace("rgb(", "")
                  .replace(")", "")
                  .split(",");
                var o = Math.round(
                  (parseInt(qsn_color[0]) * 299 +
                    parseInt(qsn_color[1]) * 587 +
                    parseInt(qsn_color[2]) * 114) /
                  1000
                );
                var fore = o > 125 ? "black" : "white";
                main_fore = fore;
                appendScriptLinks(".company-name-smatest { color: " + fore + "; }", "style");
                appendScriptLinks(".company-title-label { color: " + fore + "; }", "style");
                appendScriptLinks(".company-description-label { color: " + fore + "; }", "style");
              appendScriptLinks(".company_dec_smatest { color: " + fore + "; }", "style");

              }
            }
            if (main_fore == "black") {
              bot_mic.classList.add("bot-mic-icon");
              close_bot.classList.add("close-bot-icon-black");
              header_menu.classList.add("header-menu-icon-black");
              reload_menu.classList.add("refresh-menu-icon-black");
            } else if (main_fore == "white") {
              bot_mic.classList.add("bot-mic-white-icon");
              close_bot.classList.add("close-bot-icon");
              header_menu.classList.add("header-menu-icon");
            }
          } else {
            appendScriptLinks(".pulse-btn { box-shadow: 0 0 0 0 #1094d1; }", "style");
            header.style.background = "linear-gradient(45deg, #ff00cc, #333339)";
            bot_mic.classList.add("bot-mic-icon");
          }
          if (themes_array && themes_array[1] && themes_array[1].length > 0) {
            body.style.background = themes_array[1];
            if (themes_array[1] == "transparent") {
              anotherDiv.style.background = "transparent";
            }
            if (
              themes_array[1] &&
              themes_array[1].length > 0 &&
              themes_array[1].includes("url")
            ) {
              body.style.boxShadow = main_image_shadow;
            }
          } else {
            anotherDiv.style.background = "rgb(222,228,232)";
          }
          if (themes_array && themes_array[3] && themes_array[3].length > 0) {
            appendScriptLinks(".options-div-smatest { background: " + themes_array[3] + "; }", "style");
            appendScriptLinks(".question-text { background: " + themes_array[3] + "; }", "style");
            appendScriptLinks(".spinner1-smatest { background: " + themes_array[3] + "; }", "style");
            if (themes_array[3].includes("rgba")) {
              var qsn_color = themes_array[3]
                .replace("rgba(", "")
                .replace(")", "")
                .split(",");
              var o = Math.round(
                (parseInt(qsn_color[0]) * 299 +
                  parseInt(qsn_color[1]) * 587 +
                  parseInt(qsn_color[2]) * 114) /
                1000
              );
              var fore = o > 125 ? "black" : "white";
              call_fore = fore;
              if (fore == "black") {
                appendScriptLinks(".rating-with-stars:not(:checked)>label { color: rgba(0,0,0,0.3);}", "style");
                appendScriptLinks(".rating-with-stars:not(:checked)>label:hover, .rating-with-stars:not(:checked)>label:hover~label { color: rgba(255,255,255);}", "style");
              } else {
                appendScriptLinks(".rating-with-stars:not(:checked)>label { color: rgba(255,255,255,0.3);}", "style");
                appendScriptLinks(".rating-with-stars:not(:checked)>label:hover, .rating-with-stars:not(:checked)>label:hover~label { color: rgba(255,255,255);}", "style");
              }
              appendScriptLinks(".options-div-smatest label { color: " + fore + " !important;}", "style");
              appendScriptLinks(".question-text-error{ color: " + fore + " !important;}", "style");
              appendScriptLinks(".question-text{ color: " + fore + " !important;}", "style");
              appendScriptLinks(".options-div-smatest span{ color: " + fore + " !important;}", "style");
              appendScriptLinks(".options{ color: " + fore + " !important;}", "style");
              if (fore == "black") {
                appendScriptLinks(".spinner1-smatest>div { background-color: #5a5a5a;}", "style");
              } else {
                appendScriptLinks(".spinner1-smatest>div { background-color: " + fore + ";}", "style");
              }
            } else {
              var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
                themes_array[3]
              );
              if (result && result.length > 1) {
                var main_color =
                  "rgb(" +
                  parseInt(result[1], 16) +
                  "," +
                  parseInt(result[2], 16) +
                  "," +
                  parseInt(result[3], 16) +
                  ")";
                var qsn_color = main_color
                  .replace("rgb(", "")
                  .replace(")", "")
                  .split(",");
                var o = Math.round(
                  (parseInt(qsn_color[0]) * 299 +
                    parseInt(qsn_color[1]) * 587 +
                    parseInt(qsn_color[2]) * 114) /
                  1000
                );
                var fore = o > 125 ? "black" : "white";
                call_fore = fore;
                if (fore == "black") {
                  appendScriptLinks(".rating-with-stars:not(:checked)>label { color: rgba(0,0,0,0.3);}", "style");
                  appendScriptLinks(".rating-with-stars:not(:checked)>label:hover, .rating-with-stars:not(:checked)>label:hover~label { color: rgba(0,0,0);}", "style");
                } else {
                  appendScriptLinks(".rating-with-stars:not(:checked)>label { color: rgba(255,255,255,0.3);}", "style");
                  appendScriptLinks(".rating-with-stars:not(:checked)>label:hover, .rating-with-stars:not(:checked)>label:hover~label { color: rgba(255,255,255);}", "style");
                }
                appendScriptLinks(".options-div-smatest label { color: " + fore + " !important;}", "style");
                appendScriptLinks(".question-text-error { color: " + fore + " !important;}", "style");
                appendScriptLinks(".question-text { color: " + fore + ";}", "style");
                appendScriptLinks(".options-div-smatest span { color: " + fore + ";}", "style");
                if (fore == "black") {
                  appendScriptLinks(".spinner1-smatest>div { background-color: #5a5a5a;}", "style");
                } else {
                  appendScriptLinks(".spinner1-smatest>div { background-color: " + fore + ";}", "style");
                }
              }
            }
          } else {
            appendScriptLinks(".options-div-smatest { background: rgb(255,255,255); }", "style");
            appendScriptLinks(".options-div-smatest label { color: #455a64;}", "style");
            appendScriptLinks(".question-text-error { color: #455a64;}", "style");
            appendScriptLinks(".rating-with-stars:not(:checked)>label { color: rgba(0,0,0,0.3);}", "style");
            appendScriptLinks(".rating-with-stars:not(:checked)>label:hover, .rating-with-stars:not(:checked)>label:hover~label { color: rgba(0,0,0);}", "style");
            appendScriptLinks(".question-text { color: #455a64;}", "style");
            appendScriptLinks(".options-div-smatest span { color: #455a64 !important;}", "style");
            appendScriptLinks(".spinner1-smatest>div { background-color: #656262;}", "style");
            appendScriptLinks(".spinner1-smatest { background: white;}", "style");
            appendScriptLinks(".question-text { background: white; }", "style");
          }
          if (themes_array && themes_array[4] && themes_array[4].length > 0) {
            if (button_border && button_border.length > 0) {
            } else {
              button_border = themes_array[4];
            }
            if (themes_array[4].includes("rgba")) {
              var ans_color = themes_array[4]
                .replace("rgba(", "")
                .replace(")", "")
                .split(",");
              var o = Math.round(
                (parseInt(ans_color[0]) * 299 +
                  parseInt(ans_color[1]) * 587 +
                  parseInt(ans_color[2]) * 114) /
                1000
              );
              var fore = o > 125 ? "black" : "white";
              answer_color = fore;
              appendScriptLinks(".answer-label { color: " + fore + ";}", "style");
              appendScriptLinks(".is-selected .pika-button { color: " + fore + ";}", "style");
              appendScriptLinks(".answer-label label { color: " + fore + ";}", "style");
              appendScriptLinks(".answer-opp-color-text { color: " + fore + ";}", "style");
              appendScriptLinks(".dialogs-div-smatest label { color: " + fore + " !important;;}", "style");
              appendScriptLinks(".dialogs-div-vertical-smatest label { color: " + fore + " !important;}", "style");
              appendScriptLinks(".pika-title select { color: " + fore + " !important;}", "style");
              appendScriptLinks(".radio-slide-label span { color: " + fore + ";}", "style");
              appendScriptLinks(".contact-div-smatest>a>span { color: " + fore + " !important;}", "style");
              appendScriptLinks(".contact-div-smatest>a>p { color: " + fore + " !important;}", "style");
              appendScriptLinks(".spinner2-smatest { color: " + fore + ";}", "style");
              appendScriptLinks(".pika-button:hover, .pika-row.pick-whole-week:hover .pika-button { color: " + fore + " !important;}", "style");
              appendScriptLinks(".contact-btn-smatest>a{color:" + fore + " !important}", "style");
              appendScriptLinks(".contact-btn-smatest{color:" + fore + " !important}", "style");
              appendScriptLinks(".upload-button-sb { color: " + fore + " !important;}", "style");
              appendScriptLinks(".upload-button-sb>span { color: " + fore + " !important;}", "style");
              appendScriptLinks(".confirm-btn-smatest { color: " + fore + " !important;}", "style");
              if (fore == "white") {
                appendScriptLinks(".contact-icon-smatest { filter: invert(1);}", "style");
                appendScriptLinks(".is-rtl .pika-next, .pika-prev { filter: invert(1);}", "style");
                appendScriptLinks(".is-rtl .pika-prev, .pika-next { filter: invert(1);}", "style");
              }
            } else {
              var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
                themes_array[4]
              );
              if (result && result.length > 1) {
                var main_color =
                  "rgb(" +
                  parseInt(result[1], 16) +
                  "," +
                  parseInt(result[2], 16) +
                  "," +
                  parseInt(result[3], 16) +
                  ")";
                var ans_color = main_color
                  .replace("rgb(", "")
                  .replace(")", "")
                  .split(",");
                var o = Math.round(
                  (parseInt(ans_color[0]) * 299 +
                    parseInt(ans_color[1]) * 587 +
                    parseInt(ans_color[2]) * 114) /
                  1000
                );
                var fore = o > 125 ? "black" : "white";
                answer_color = fore;
                appendScriptLinks(".answer-label { color: " + fore + ";}", "style");
                appendScriptLinks(".answer-label label { color: " + fore + ";}", "style");
                appendScriptLinks(".answer-opp-color-text { color: " + fore + ";}", "style");
                appendScriptLinks(".dialogs-div-smatest label { color: " + fore + ";}", "style");
                appendScriptLinks(".dialogs-div-vertical-smatest label { color: " + fore + ";}", "style");
                appendScriptLinks(".radio-slide-label span { color: " + fore + ";}", "style");
                appendScriptLinks(".pika-title select { color: " + fore + " !important;}", "style");
                appendScriptLinks(".contact-div-smatest>a>span { color: " + fore + " !important;}", "style");
                appendScriptLinks(".contact-div-smatest>a>p { color: " + fore + " !important;}", "style");
                appendScriptLinks(".spinner2-smatest { color: " + fore + ";}", "style");
                appendScriptLinks(".pika-button:hover, .pika-row.pick-whole-week:hover .pika-button { color: " + fore + " !important;}", "style");
                appendScriptLinks(".contact-btn-smatest>a{color:" + fore + " !important}", "style");
                appendScriptLinks(".contact-btn-smatest{color:" + fore + " !important}", "style");
                appendScriptLinks(".upload-button-sb { color: " + fore + "!important;}", "style");
                appendScriptLinks(".upload-button-sb>span { color: " + fore + "!important;}", "style");
                appendScriptLinks(".dialogs-div-smatest:hover label{ color: " + fore + "!important;}", "style");
                appendScriptLinks(".dialogs-div-vertical-smatest:hover label { color: " + fore + "!important;}", "style");
                appendScriptLinks(".is-selected .pika-button { color: " + fore + "!important;}", "style");
                appendScriptLinks(".confirm-btn-smatest { color: " + fore + " !important;}", "style");
                if (fore == "white") {
                  appendScriptLinks(".contact-icon-smatest { filter: invert(1);}", "style");
                  appendScriptLinks(".is-rtl .pika-next, .pika-prev { filter: invert(1);}", "style");
                  appendScriptLinks(".is-rtl .pika-prev, .pika-next { filter: invert(1);}", "style");
                }
              }
            }
            appendScriptLinks(".confirm-btn-smatest { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".confirm-checkbox-btn-smatest { border: 1px solid " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".answer-label { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".dialogs-div-smatest { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".rating-logo-div { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".progress-block { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest { border-color: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".dialogs-div-smatest { border-color: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest:hover { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".dialogs-div-smatest:hover { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".dialogs-div-smatest:hover label { color: " + fore + " !important; }", "style");
            appendScriptLinks(".slot-label { border: 1px solid " + themes_array[4] + "; }", "style");
            appendScriptLinks("#slot-scroll::-webkit-scrollbar-thumb { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".pika-title { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".slider-smatest { background: linear-gradient(to right, " + themes_array[4] + " 0%, " + themes_array[4] + " 0%, #e1e1e1 0%, #e1e1e1 100%;}", "style");
            appendScriptLinks(".slider-smatest::-webkit-slider-thumb { border: 1px solid " + themes_array[4] + "}", "style");
            appendScriptLinks(".radio-slide-label { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".contact-div-smatest { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".spinner2-smatest { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".options-smatest-checkbox { border: 1px solid " + themes_array[4] + "; }", "style");
            appendScriptLinks(".is-selected .pika-button, .has-event .pika-button { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".pika-button:hover, .pika-row.pick-whole-week:hover .pika-button { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".radio-slide-label { border: 2px solid " + themes_array[4] + "; }", "style");
            appendScriptLinks(".radio-slide-label { padding: 6px 12px !important;}", "style");
            appendScriptLinks(".upload-button-sb { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".skip-text { color: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".slides-options-smatest { color: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".confirm-btn-smatest-other { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".contact-list-btn { background: " + themes_array[4] + " !important; }", "style");
            appendScriptLinks(".text-blue { color: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".contact-btn-smatest { background: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".other-help-label { color: " + themes_array[4] + "; }", "style");
            appendScriptLinks(".confirm-btn-smatest { background: " + themes_array[4] + " !important; }", "style");

            function isLightColor(color) {
              let r, g, b;
              if (color.startsWith("rgb")) {
                  [r, g, b] = color.match(/\d+/g).map(Number);
              } else if (color.startsWith("#")) {
                  if (color.length === 4) {
                      r = parseInt(color[1] + color[1], 16);
                      g = parseInt(color[2] + color[2], 16);
                      b = parseInt(color[3] + color[3], 16);
                  } else {
                      r = parseInt(color.slice(1, 3), 16);
                      g = parseInt(color.slice(3, 5), 16);
                      b = parseInt(color.slice(5, 7), 16);
                  }
              }
              let brightness = 0.299 * r + 0.587 * g + 0.114 * b;
              return brightness > 128;
          }

            function extractFirstColor(gradientString) {
              let colorMatch = gradientString.match(/(rgb\(\d+,\s*\d+,\s*\d+\)|#[0-9a-fA-F]{3,6})/);
              return colorMatch ? colorMatch[0] : null;
            }
          
          if (themes_array[0].includes("linear-gradient")) {
              let chosenColor = extractFirstColor(themes_array[0]);
              if (chosenColor) {
                  appendScriptLinks(".enter-icon  { background: " + chosenColor + "; }", "style");
                  if (isLightColor(chosenColor)) {
                    appendScriptLinks(".enter-icon { fill: black; }", "style");
                  } else {
                      appendScriptLinks(".enter-icon { fill: white; }", "style");
                  }
              }
          } else {
              appendScriptLinks(".enter-icon  { background: " + themes_array[0] + "; }", "style");
              if (isLightColor(themes_array[0])) {
                appendScriptLinks(".enter-icon { fill: black; }", "style");
              } else {
                  appendScriptLinks(".enter-icon { fill: white; }", "style");
              }
          }
            
          } else {
            if (button_border && button_border.length > 0) {
            } else {
              button_border = "#1094d1";
            }
            answer_color = "white";
            appendScriptLinks(".answer-label { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".answer-label label { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".answer-opp-color-text { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".dialogs-div-smatest label { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".dialogs-div-smatest:hover label{ color: white !important; }", "style");
            appendScriptLinks(".pika-title { background: #1094d1; }", "style");
            appendScriptLinks(".radio-slide-label span { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".contact-div-smatest { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".spinner2-smatest { color: rgb(255,255,255);}", "style");
            appendScriptLinks(".pika-button:hover, .pika-row.pick-whole-week:hover .pika-button { color: rgb(255,255,255) !important;}", "style");
            appendScriptLinks(".upload-button-sb { color: rgb(255,255,255) !important;}", "style");
            appendScriptLinks(".upload-button-sb>span { color: rgb(255,255,255) !important;}", "style");
            appendScriptLinks(".contact-btn-smatest>a{color:rgb(255,255,255) !important}", "style");
            appendScriptLinks(".contact-btn-smatest{color:rgb(255,255,255) !important}", "style");
            appendScriptLinks(".confirm-btn-smatest { background: #1094d1 !important; }", "style");
            appendScriptLinks(".confirm-checkbox-btn-smatest { border: 1px solid #1094d1 !important; }", "style");
            appendScriptLinks(".answer-label { background: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-smatest { background: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest { background: #1094d1; }", "style");
            appendScriptLinks(".rating-logo-div { background: #1094d1; }", "style");
            appendScriptLinks(".progress-block { background: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest { border-color: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-smatest { border-color: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest:hover { background: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-smatest:hover { background: #1094d1; }", "style");
            appendScriptLinks(".dialogs-div-smatest label { color: white !important; }", "style");
            appendScriptLinks(".dialogs-div-vertical-smatest label { color: white !important; }", "style");
            appendScriptLinks(".slot-label { border: 1px solid #1094d1; }", "style");
            appendScriptLinks("#slot-scroll::-webkit-scrollbar-thumb { background: #1094d1; }", "style");
            appendScriptLinks(".pika-title { background: #1094d1; }", "style");
            appendScriptLinks(".slider-smatest { background: linear-gradient(to right, #1094d1 0%, #1094d1 0%, #e1e1e1 0%, #e1e1e1 100%;}", "style");
            appendScriptLinks(".slider-smatest::-webkit-slider-thumb { border: 1px solid #1094d1}", "style");
            appendScriptLinks(".radio-slide-label { background: #1094d1; }", "style");
            appendScriptLinks(".contact-div-smatest { background: #1094d1; }", "style");
            appendScriptLinks(".spinner2-smatest { background: #1094d1; }", "style");
            appendScriptLinks(".is-today .pika-button { color: #1094d1; }", "style");
            appendScriptLinks(".pika-button:hover, .pika-row.pick-whole-week:hover .pika-button { background: #1094d1 !important; }", "style");
            appendScriptLinks(".radio-slide-label { border: 2px solid #1094d1;}", "style");
            appendScriptLinks(".radio-slide-label { padding: 6px 12px !important;}", "style");
            appendScriptLinks(".upload-button-sb { background: #1094d1; }", "style");
            appendScriptLinks(".skip-text { color: #1094d1 !important; }", "style");
            appendScriptLinks(".slides-options-smatest { color: #1094d1 !important; }", "style");
            appendScriptLinks(".confirm-btn-smatest-other { background: #1094d1 !important; }", "style");
            appendScriptLinks(".contact-list-btn { background: #1094d1 !important; }", "style");
            appendScriptLinks(".text-blue { color: #1094d1; }", "style");
            appendScriptLinks(".contact-btn-smatest { background: #1094d1; }", "style");
            appendScriptLinks(".other-help-label { color: #1094d1 !important; }", "style");
            appendScriptLinks(".confirm-btn-smatest { background: #1094d1 !important; }", "style");
          }
          if (themes_array && themes_array[5] && themes_array[5].length > 0) {
            if (themes_array[5].includes("rgba")) {
              var ans_color = themes_array[5]
                .replace("rgba(", "")
                .replace(")", "")
                .split(",");
              var o = Math.round(
                (parseInt(ans_color[0]) * 299 +
                  parseInt(ans_color[1]) * 587 +
                  parseInt(ans_color[2]) * 114) /
                1000
              );
              var fore = o > 125 ? "black" : "white";
              appendScriptLinks(".options-smatest span { color:" + fore + " !important;}", "style");
              appendScriptLinks(".options-smatest-checkbox span { color:" + fore + " !important;}", "style");
            } else {
              var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
                themes_array[5]
              );
              if (result && result.length > 1) {
                var main_color =
                  "rgb(" +
                  parseInt(result[1], 16) +
                  "," +
                  parseInt(result[2], 16) +
                  "," +
                  parseInt(result[3], 16) +
                  ")";
                var ans_color = main_color
                  .replace("rgb(", "")
                  .replace(")", "")
                  .split(",");
                var o = Math.round(
                  (parseInt(ans_color[0]) * 299 +
                    parseInt(ans_color[1]) * 587 +
                    parseInt(ans_color[2]) * 114) /
                  1000
                );
                var fore = o > 125 ? "black" : "white";
                appendScriptLinks(".options-smatest span { color:" + fore + " !important;}", "style");
                appendScriptLinks(".options-smatest-checkbox span { color:" + fore + " !important;}", "style");
              }
            }
            appendScriptLinks(".options-smatest { background: " + themes_array[5] + " !important;}", "style");
            appendScriptLinks(".options-smatest-checkbox { background: " + themes_array[5] + " !important;}", "style");
            appendScriptLinks(".radio-box-botest { --active: " + themes_array[5] + " !important;}", "style");
            appendScriptLinks(".radio-box-botest { --border-hover: " + themes_array[5] + " !important;}", "style");
          } else if (
            themes_array &&
            themes_array[4] &&
            themes_array[4].length > 0
          ) {
            if (themes_array[4].includes("rgba")) {
              var ans_color = themes_array[4]
                .replace("rgba(", "")
                .replace(")", "")
                .split(",");
              var o = Math.round(
                (parseInt(ans_color[0]) * 299 +
                  parseInt(ans_color[1]) * 587 +
                  parseInt(ans_color[2]) * 114) /
                1000
              );
              var fore = o > 125 ? "black" : "white";
            } else {
              var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(
                themes_array[4]
              );
              if (result && result.length > 1) {
                var main_color =
                  "rgb(" +
                  parseInt(result[1], 16) +
                  "," +
                  parseInt(result[2], 16) +
                  "," +
                  parseInt(result[3], 16) +
                  ")";
                var ans_color = main_color
                  .replace("rgb(", "")
                  .replace(")", "")
                  .split(",");
                var o = Math.round(
                  (parseInt(ans_color[0]) * 299 +
                    parseInt(ans_color[1]) * 587 +
                    parseInt(ans_color[2]) * 114) /
                  1000
                );
                var fore = o > 125 ? "black" : "white";
              }
            }
            appendScriptLinks(".options-smatest span { color: " + themes_array[4] + " !important;}", "style");
            appendScriptLinks(".options-smatest { border: 1px solid " + themes_array[4] + " !important;}", "style");
            appendScriptLinks(".options-smatest-checkbox span { color: " + themes_array[4] + " !important;}", "style");
            appendScriptLinks(".options-smatest-checkbox { border: 1px solid " + themes_array[4] + " !important;}", "style");
            appendScriptLinks(".radio-box-botest { --active: " + themes_array[4] + " !important;}", "style");
            appendScriptLinks(".radio-box-botest { --border-hover: " + themes_array[4] + " !important;}", "style");
          } else {
            appendScriptLinks(".options-smatest span { color: #1094d1 !important;}", "style");
            appendScriptLinks(".options-smatest { border: 1px solid #1094d1 !important;}", "style");
            appendScriptLinks(".options-smatest-checkbox span { color: #1094d1 !important;}", "style");
            appendScriptLinks(".options-smatest-checkbox { border: 1px solid #1094d1 !important;}", "style");
            appendScriptLinks(".radio-box-botest { --active: #1094d1 !important;}", "style");
            appendScriptLinks(".radio-box-botest { --border-hover: #1094d1 !important;}", "style");
          }
          if (chatbot_id == 20609) {
            appendScriptLinks(".options-smatest:hover { background: rgb(192,214,57) !important;}", "style");
          }
          appendScriptLinks(".options-smatest { border : 1px solid " + button_border + " !important; }", "style");
          appendScriptLinks(".options-smatest-checkbox { border : 1px solid " + button_border + " !important; }", "style");
          appendScriptLinks(".radio-slide-label { border : 1px solid " + button_border + " !important; }", "style");
          appendScriptLinks(".dialogs-div-smatest { border : 1px solid " + button_border + " !important; }", "style");
          appendScriptLinks(".dialogs-div-vertical-smatest { border : 1px solid " + button_border + " !important; }", "style");

          const updateLauncherGreeting = (text) => {
              const currentHour = new Date().getHours();
              if (/good morning/i.test(text)) {
                if (currentHour >= 12 && currentHour <= 16) {
                  return text.replace(/good morning/i, "Good Afternoon");
                } else if ((currentHour >= 17 && currentHour <= 23) || (currentHour >= 0 && currentHour <= 4)) {
                  return text.replace(/good morning/i, "Good Evening");
                }
              }
              return text;
            };

          if (is_disabled == 0) {
            img.src = avatar_icon;
            var text;
            if (
              browserType == "Chrome" ||
              browserType == "Firefox" ||
              browserType == "Safari"
            ) {
              if (chatbot_id == 23568) {
                launcher_text.innerHTML =updateLauncherGreeting(totalData[0].launcher_text);
                let launcher_texts_arr = [totalData[0].launcher_text, 'Hi There, Good morning!', 'Is there anything that I can help you with?', 'Ask Me for Help!'];

                launcher_texts_arr = launcher_texts_arr.map(updateLauncherGreeting);

                let current_index = 0;
                setInterval(() => {
                  current_index = (current_index + 1) % launcher_texts_arr.length;
                  launcher_text.innerHTML = launcher_texts_arr[current_index];
                }, 60000);
              } else {
                launcher_text.innerHTML = updateLauncherGreeting(totalData[0].launcher_text);
              }
            } else {
              launcher_text.innerHTML =
              updateLauncherGreeting(totalData[0].launcher_text) +
                " (For better experience please use Chrome or Firefox or Safari)";
            }
            if (text && text.length > 0) {
              launcher_text.classList.add("launcher-label-smatest");
            } else {
              launcher_text.classList.add("p-r-0");
              setTimeout(function () {
                if (document.getElementsByClassName("smat-lb-div")[0]) {
                  document.getElementsByClassName("smat-lb-div")[0].style.padding =
                    "0px";
                } else if (document.getElementsByClassName("smat-div")[0]) {
                  document.getElementsByClassName("smat-div")[0].style.padding =
                    "0px";
                } else if (document.getElementsByClassName("smat-rm-div")[0]) {
                  document.getElementsByClassName("smat-rm-div")[0].style.padding =
                    "0px";
                }
              }, 500);
            }
            if (font && font.length > 0) {
              launcher_text.classList.add(font);
            }
            mainDiv.style.display = "block";
            mainDiv.appendChild(img);
            setTimeout(function () {
              if (document.getElementsByClassName("smat-lb-div")[0]) {
                document.getElementsByClassName("smat-lb-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-div")[0]) {
                document.getElementsByClassName("smat-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-rm-div")[0]) {
                document.getElementsByClassName("smat-rm-div")[0].style.padding =
                  "0px";
              }
            }, 500);
            if (
              totalData[0].launcher_text &&
              totalData[0].launcher_text.length > 0
            ) {
              pulseDiv.appendChild(launcher_div);
              var x = launcher_div.clientHeight + 95;
              pulseDiv.style.height = x + "px";
            } else {
              launcher_close_icon.style.opacity = "0";
            }
            if (chatbot_id == 13479) {
              setTimeout(function () {
                var array = [
                  "Hello!",
                  "안녕하십니까",
                  "Hallo",
                  "Bonjour",
                  "こんにちは",
                ];
                var tranition_num = 0;
                setInterval(function () {
                  tranition_num = tranition_num + 1;
                  if (tranition_num > 4) {
                    tranition_num = 0;
                  }
                  launcher_text.innerHTML = array[tranition_num];
                }, 2000);
              }, 500);
            }
            var label = document.createElement("LABEL");
            launcher_position = totalData[0].launcher_position;
            trigger_time = totalData[0].trigger_time;
            trigger_time_mobile = totalData[0].trigger_time_mobile;
            if (
              totalData[0].send_email_after != null &&
              totalData[0].send_email_after &&
              totalData[0].send_email_after.length > 0
            ) {
              mailSequence = totalData[0].send_email_after.split(",");
            } else {
              mailSequence = [];
            }
            var company_name_dec = document.createElement("div");
            company_name_dec.style.display = 'inline-flex';
            company_name_dec.style.flexDirection = 'column';
            company_name_dec.style.justifyContent = 'center';
            company_name_dec.style.alignItems = 'flex-start';
            company_name_dec.style.maxWidth = '54%';
            company_name_dec.style.float = 'left';
            company_name_dec.style.marginLeft = '10px';
            company_name_dec.style.height = '100%';
            // company_name_dec.style.gap = '2px';
            company_name_dec.style.overflow = 'hidden';

            var company_dec = document.createElement("LABEL");
            company_dec.classList.add('company_dec_smatest')
            company_dec.style.fontSize = '11px'
            company_dec.style.cssText = company_dec.style.cssText + "margin:0 !important";
            company_dec.style.cssText = company_dec.style.cssText + "padding:0 !important";
            var json = JSON.parse(totalData[0].view_setup_object);
            
            var company_name = document.createElement("LABEL");
            company_name.style.fontSize = '14px'
            company_name.style.fontWeight = '600'
            if (totalData[0].name && totalData[0].name.length > 0) {
              company_name.innerHTML = totalData[0].name;
              company_title_label.innerHTML = totalData[0].name;
              launcher_header_label.innerHTML =
                encodeURIComponent(totalData[0].name) + " says";
            }
            company_name.classList.add("company-name-smatest");
            company_name.style.cssText = company_name.style.cssText + "margin:0 !important";
            company_name.style.cssText = company_name.style.cssText + "padding:0 !important";
            header.appendChild(imgLogo);
            if (
              totalData[0].company_logo_url &&
              totalData[0].company_logo_url.length > 0
            ) {
              imgLogo.src = totalData[0].company_logo_url;
            } else {
              imgLogo.src = avatar_icon;
            }
            company_name_dec.appendChild(company_name);
            if (
              json && 
              json.bot_description &&
              json.bot_description.toString().length > 0
            ) {
              company_dec.innerHTML = json.bot_description;
              company_name_dec.appendChild(company_dec);
            }
            header.appendChild(company_name_dec);

            if (
              totalData[0].font_object &&
              totalData[0].font_object != null &&
              totalData[0].font_object.length > 0
            ) {
              var font_object = JSON.parse(totalData[0].font_object);
              appendScriptLinks(font_object.url, "css");
              if (font_object.category && font_object.category.length > 0) {
                appendScriptLinks(".bot-google-font { font-family: " + font_object.name + ", " + font_object.category + " !important; }", "style");
              } else {
                appendScriptLinks(".bot-google-font { font-family: " + font_object.name + " !important; }", "style");
              }
              if (font_object.category && font_object.category.length > 0) {
                appendScriptLinks(".bot-google-font div { font-family: " + font_object.name + ", " + font_object.category + " !important; }", "style");
              } else {
                appendScriptLinks(".bot-google-font div { font-family: " + font_object.name + " !important; }", "style");
              }
              appendScriptLinks(font_object.url, "css");
              if (font_object.category && font_object.category.length > 0) {
                appendScriptLinks(".pika-button { font-family: " + font_object.name + ", " + font_object.category + "; }", "style");
              } else {
                appendScriptLinks(".pika-button { font-family: " + font_object.name + "; }", "style");
              }
              appendScriptLinks(font_object.url, "css");
              if (font_object.category && font_object.category.length > 0) {
                appendScriptLinks(".pika-table abbr { font-family: " + font_object.name + ", " + font_object.category + "; }", "style");
              } else {
                appendScriptLinks(".pika-table abbr { font-family: " + font_object.name + "; }", "style");
              }
              font = "bot-google-font";
            } else {
              if (totalData[0].font && totalData[0].font != null) {
                if (totalData[0].font == 1) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Open+Sans", "css");
                  font = "open-sans";
                } else if (totalData[0].font == 2) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Josefin+Sans", "css");
                  font = "josefin";
                } else if (totalData[0].font == 3) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Arvo", "css");
                  font = "arvo";
                } else if (totalData[0].font == 4) {
                  font = "Lato";
                } else if (totalData[0].font == 5) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Vollkorn", "css");
                  font = "vollkorn";
                } else if (totalData[0].font == 6) {
                  font = "Lato";
                } else if (totalData[0].font == 7) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Comfortaa:300,400,700", "css");
                  font = "comfortaa";
                } else if (totalData[0].font == 8) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Satisfy", "css");
                  font = "satisfy";
                } else if (totalData[0].font == 9) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Shadows+Into+Light", "css");
                  font = "shadows-into-light";
                } else if (totalData[0].font == 10) {
                  font = "times-new-roman";
                } else if (totalData[0].font == 11) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Caveat", "css");
                  font = "caveat";
                } else if (totalData[0].font == 12) {
                  appendScriptLinks("https://fonts.googleapis.com/css?family=Pompiere", "css");
                  font = "pompiere";
                } else if (totalData[0].font == 13) {
                  font = "arial";
                } else if (totalData[0].font == 14) {
                  font = "calibri";
                } else if (totalData[0].font == "arial") {
                  font = "arial";
                } else if (totalData[0].font == "calibri") {
                  appendScriptLinks('.bot-google-font { font-family: Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif;}', "style");
                  font = "bot-google-font";
                } else {
                  var font_url = totalData[0].font;
                  var font_style = "normal";
                  var font_weight = 400;
                  var newStyle = document.createElement("style");
                  newStyle.appendChild(
                    document.createTextNode(
                      "                 @font-face {                     font-family: '" +
                      font_name +
                      "';                     src: " +
                      font_url +
                      ";                 }               "
                    )
                  );
                  document.head.appendChild(newStyle);
                  appendScriptLinks('.bot-google-font { font-family: "' + font_name + '"; }', "style");
                  font = "bot-google-font";
                  appendScriptLinks('.bot-google-font div { font-family: "' + font_name + '"; }', "style");
                }
              } else {
                font = "lato";
              }
            }
            try {
              if (window.parent) {
                window.parent.postMessage("disappear", "*");
              }
            } catch (e) {
            } finally {
            }
            if (font && font.length > 0) {
              footer.classList.add(font);
              body.classList.add(font);
              smat_footer.classList.add(font);
              smat_label.classList.add(font);
              input.classList.add(font);
              launcher_text.classList.add(font);
              company_name.classList.add(font);
              consent_btn.classList.add(font);
              img.classList.add(font);
              header_menu_div.classList.add(font);
              company_title_description.classList.add(font);
              launcher_header_label.classList.add(font);
              company_title_label.classList.add(font);
              company_description_label.classList.add(font);
              company_dec.classList.add(font);
            }
            if (launcher_position == "RB") {
              mainDiv.classList.add("smat-div");
              img.classList.add("smat-main-btn");
              pulseDiv.classList.add("pulse-div");
              if (font && font.length > 0) {
                img.classList.add(font);
              }
              launcher_div.classList.add("launcher-label-div");
              anotherDiv.classList.add("opened-div");
            } else if (launcher_position == "RM") {
              mainDiv.classList.add("smat-rm-div");
              img.classList.add("smat-main-btn");
              pulseDiv.classList.add("pulse-rm-div");
              if (font && font.length > 0) {
                img.classList.add(font);
              }
              launcher_div.classList.add("launcher-label-rm-div");
              anotherDiv.classList.add("opened-rm-div");
            } else if (launcher_position == "LB") {
              mainDiv.classList.add("smat-lb-div");
              img.classList.add("smat-main-lb-btn");
              pulseDiv.classList.add("pulse-lb-div");
              if (font && font.length > 0) {
                img.classList.add(font);
              }
              launcher_div.classList.add("launcher-label-lb-div");
              anotherDiv.classList.add("opened-lb-div");
              consentDiv.style.left = "30px";
            }
            if (chatbot_id == 10561 || chatbot_id == 14964) {
              pulseDiv.style.cssText =
                pulseDiv.style.cssText + "width:60px !important";
              pulseDiv.style.cssText =
                pulseDiv.style.cssText + "height:60px !important";
            }
            if (launcher_position == "RB") {
              audio_loading_div.classList.add("opened-div");
            } else if (launcher_position == "LB") {
              audio_loading_div.classList.add("opened-lb-div");
            } else if (launcher_position == "RM") {
              audio_loading_div.classList.add("opened-rm-div");
            }
            audio_loading_div.classList.add("audio-loading-div");
            try {
              if (
                body.parentElement &&
                body.parentElement.parentElement &&
                body.parentElement.parentElement.parentElement
              ) {
                var main_body = body.parentElement.parentElement.parentElement;
                if (main_body.clientWidth == 361 || main_body.clientWidth == 150) {
                  if (window.parent) {
                    window.parent.postMessage("disappear", "*");
                  }
                }
              }
            } catch (e) {
            } finally {
            }
            if (
              /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                navigator.userAgent
              )
            ) {
              header.appendChild(close_bot);
              header.appendChild(header_menu);
              header.appendChild(reload_menu);
              header.appendChild(header_menu_div);
             
              if (company_description_label.innerHTML != "") {
                header.appendChild(company_title_description);
                header.style.textAlign = "center";
                imgLogo.style.cssText =
                  imgLogo.style.cssText + "margin-left:calc(50% - 25px) !important";
                imgLogo.style.height = "44px";
                imgLogo.style.width = "44px";
                imgLogo.style.top = "9px";
                company_name_dec.style.display = "none";
                header.style.height = "135px";
                if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                  document.getElementById('rating-live-chat-feedback_div_sb').style.top = '135px'
                }
                if (header.classList.contains("header-ease-in")) {
                } else {
                  header.classList.add("header-ease-in");
                }
                body.style.height = "calc(100% - 226px)";
              } else {
                header.style.textAlign = "center";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                imgLogo.style.top = "0";
                company_name_dec.style.display = "inline-flex";
                header.style.height = "60px";
                company_name_dec.style.float = "left";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                  document.getElementById('rating-live-chat-feedback_div_sb').style.top = '60px'
                }
                if (header.classList.contains("header-ease-in")) {
                  header.classList.remove("header-ease-in");
                }
                var selected_orders_div =
                  document.getElementById("selected-orders");
                if (footer.style.display == "none") {
                  body.style.height = "calc(100% - 93px)";
                } else if (footer.contains(selected_orders_div)) {
                  body.style.height = "calc(100% - 174px)";
                } else {
                  if (footer.style.height == "230px") {
                    body.style.height = "calc(100% - 323px)";
                  } else if (footer.style.height == "315px") {
                    body.style.height = "calc(100% - 408px)";
                  } else {
                    var x = footer.offsetHeight + 93 + 13;
                    body.style.height = "calc(100% - " + x + "px)";
                  }
                }
              }

              if (is_speech_on) {
                header_menu_div.appendChild(sound_icon_div);
                var audio_element = document.createElement("AUDIO");
                audio_element.onended = closeAudio();
                audio_element.id = "audioPlayback";
                audio_element.style.display = "none";
                var audio_source = document.createElement("SOURCE");
                audio_source.type = "audio/mp3";
                audio_source.id = "audioSource";
                audio_element.appendChild(audio_source);
                anotherDiv.appendChild(audio_element);
                var aws_loaded;
                setInterval(function () {
                  if (!aws_loaded) {
                    if (AWS && AWS.VERSION) {
                      aws_loaded = true;
                      // say("hi", 1);
                    }
                  }
                }, 100);
              }
              header_menu_div.appendChild(reload_div);
              if (trigger_time_mobile && trigger_time_mobile != "-1") {
                if (trigger_time_mobile.toString() == "0") {
                  trigger_time_mobile = trigger_time_mobile + 1;
                }
                setInterval(function () {
                  var device_print_loaded;
                  if (device_print && !device_print_loaded) {
                    device_print_loaded = !0;
                    setTimeout(function () {
                      if (
                        body.style.display != "block" &&
                        !noBot &&
                        !alreadyClicked &&
                        mainDiv.style.display == "block"
                      ) {
                        if (
                          window.localStorage.getItem("alreadyOpened") == "true"
                        ) {
                        } else {
                          mainDiv.click();
                          var audio = new Audio(
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/notification.mp3"
                          );
                          var playPromise = audio.play();
                          window.localStorage.setItem("alreadyOpened", !0);
                        }
                      }
                    }, parseInt(trigger_time_mobile) * 1000);
                  }
                }, 10);
              }

              setTimeout(() => {
                updateMenuIcons()
              }, 1000);

            } else {
              header.appendChild(close_bot);
              header.appendChild(header_menu);
              header.appendChild(reload_menu);
              header.appendChild(header_menu_div);

              if (company_description_label.innerHTML != "") {
                header.appendChild(company_title_description);
                header.style.textAlign = "center";
                imgLogo.style.cssText =
                  imgLogo.style.cssText + "margin-left:calc(50% - 25px) !important";
                imgLogo.style.height = "44px";
                imgLogo.style.width = "44px";
                imgLogo.style.top = "9px";
                company_name_dec.style.display = "none";
                header.style.height = "135px";
                if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                  document.getElementById('rating-live-chat-feedback_div_sb').style.top = '135px'
                }
                if (header.classList.contains("header-ease-in")) {
                } else {
                  header.classList.add("header-ease-in");
                }
                body.style.height = "calc(100% - 226px)";
              } else {
                header.style.textAlign = "center";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                imgLogo.style.top = "0";
                company_name_dec.style.display = "inline-flex";
                header.style.height = "60px";
                company_name_dec.style.float = "left";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                  document.getElementById('rating-live-chat-feedback_div_sb').style.top = '60px'
                }
                if (header.classList.contains("header-ease-in")) {
                  header.classList.remove("header-ease-in");
                }
                var selected_orders_div =
                  document.getElementById("selected-orders");
                if (footer.style.display == "none") {
                  body.style.height = "calc(100% - 93px)";
                } else if (footer.contains(selected_orders_div)) {
                  body.style.height = "calc(100% - 174px)";
                } else {
                  if (footer.style.height == "230px") {
                    body.style.height = "calc(100% - 323px)";
                  } else if (footer.style.height == "315px") {
                    body.style.height = "calc(100% - 408px)";
                  } else {
                    var x = footer.offsetHeight + 93 +13;
                    body.style.height = "calc(100% - " + x + "px)";
                  }
                }
              }
              if (is_speech_on) {
                header_menu_div.appendChild(sound_icon_div);
                var audio_element = document.createElement("AUDIO");
                audio_element.id = "audioPlayback";
                audio_element.onended = closeAudio();
                audio_element.style.display = "none";
                var audio_source = document.createElement("SOURCE");
                audio_source.type = "audio/mp3";
                audio_source.id = "audioSource";
                audio_element.appendChild(audio_source);
                anotherDiv.appendChild(audio_element);
                var aws_loaded;
                setInterval(function () {
                  if (!aws_loaded) {
                    try {
                      if (AWS && AWS.VERSION) {
                        aws_loaded = true;
                        // say("hi", 1);
                      }
                    } catch (e) {
                    } finally {
                    }
                  }
                }, 100);
              }

              header_menu_div.appendChild(reload_div);
              if (trigger_time && trigger_time != "-1") {
                if (trigger_time.toString() == "0") {
                  trigger_time = trigger_time + 1;
                }
                var device_print_loaded;
                setInterval(function () {
                  if (device_print && !device_print_loaded) {
                    device_print_loaded = !0;
                    setTimeout(function () {
                      if (
                        body.style.display != "block" &&
                        !noBot &&
                        !alreadyClicked &&
                        mainDiv.style.display == "block"
                      ) {
                        if (
                          window.localStorage.getItem("alreadyOpened") == "true"
                        ) {
                        } else {
                          var audio = new Audio(
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/notification.mp3"
                          );
                          var playPromise = audio.play();
                          if (playPromise !== undefined) {
                            playPromise.then(function () { }).catch(function () { });
                          }
                          mainDiv.click();
                          window.localStorage.setItem("alreadyOpened", !0);
                        }
                      }
                    }, parseInt(trigger_time) * 1000);
                  }
                }, 10);
              }

              setTimeout(() => {
                updateMenuIcons()
              }, 1000);
            }
            if (
              totalData[0].enable_live_online &&
              totalData[0].enable_live_online == "0"
            ) {
            }
          } else {
            if (document.getElementById("opened")) {
              document.getElementById("opened").style.display = "none";
            }
            if (document.getElementById("closed")) {
              document.getElementById("closed").style.display = "none";
            }
            if (
              document.getElementById("pulse") &&
              document.getElementById("pulse") != null
            ) {
              document.getElementById("pulse").style.display = "none";
            }
          }
        } else {
          noBot = !0;
        }
        try {
          new Fingerprint2().get(function (result, components) {
            device_print = result;
          });
        } catch (e) {
        } finally {
        }
        var random = !1;
        document.body.addEventListener("mouseleave", function () {
          if (!random) {
            closure();
            random = !0;
          }
        });
        var alreadyBlurred;
        window.onblur = function () {
          if (
            body.style.display != "block" &&
            !noBot &&
            !alreadyBlurred &&
            mainDiv.style.display == "block" &&
            closure_enable == "1"
          ) {
            alreadyBlurred = !0;
            mainDiv.click();
          }
        };
        var close_called;
        window.onbeforeunload = function () {
          if (
            body.style.display == "block" &&
            !noBot &&
            webpage_closing_alert &&
            !alreadyWebpageClosed &&
            atleastOneAnswered &&
            !mailSent &&
            bot_type == "lead"
          ) {
            alreadyWebpageClosed = !0;
            return "Sure?";
          }
          try {
            close_called = true;
            var d = new Date();
            var date = d.getDate();
            if (date < 10) {
              date = "0" + date;
            }
            var month = d.getMonth() + 1;
            if (month < 10) {
              month = "0" + month;
            }
            var hours = d.getHours();
            if (hours < 10) {
              hours = "0" + hours;
            }
            var mins = d.getMinutes();
            if (mins < 10) {
              mins = "0" + mins;
            }
            var seconds = d.getSeconds();
            if (seconds < 10) {
              seconds = "0" + seconds;
            }
            d =
              date +
              "/" +
              month +
              "/" +
              d.getFullYear() +
              ", " +
              hours +
              ":" +
              mins +
              ":" +
              seconds;
            sock.emit("closesession", {
              session_id: live_chat_cb_session,
              device_print: device_print,
              bot_id: chatbot_id,
              time: d,
              channel: "website",
              agent_id: agent_id,
            });
          } catch (e) {
          } finally {
          }
        };
        window.addEventListener("pagehide", function () {
          if (!close_called) {
            try {
              close_called = true;
              var d = new Date();
              var date = d.getDate();
              if (date < 10) {
                date = "0" + date;
              }
              var month = d.getMonth() + 1;
              if (month < 10) {
                month = "0" + month;
              }
              var hours = d.getHours();
              if (hours < 10) {
                hours = "0" + hours;
              }
              var mins = d.getMinutes();
              if (mins < 10) {
                mins = "0" + mins;
              }
              var seconds = d.getSeconds();
              if (seconds < 10) {
                seconds = "0" + seconds;
              }
              d =
                date +
                "/" +
                month +
                "/" +
                d.getFullYear() +
                ", " +
                hours +
                ":" +
                mins +
                ":" +
                seconds;
              sock.emit("closesession", {
                session_id: live_chat_cb_session,
                device_print: device_print,
                bot_id: chatbot_id,
                time: d,
                channel: "website",
                agent_id: agent_id,
              });
            } catch (e) {
            } finally {
            }
          }
        });
        setInterval(function () {
          anotherDiv.onmousemove = function () {
            if (!seen_cleared && sock) {
              var d = new Date();
              var date = d.getDate();
              if (date < 10) {
                date = "0" + date;
              }
              var month = d.getMonth() + 1;
              if (month < 10) {
                month = "0" + month;
              }
              var hours = d.getHours();
              if (hours < 10) {
                hours = "0" + hours;
              }
              var mins = d.getMinutes();
              if (mins < 10) {
                mins = "0" + mins;
              }
              var seconds = d.getSeconds();
              if (seconds < 10) {
                seconds = "0" + seconds;
              }
              d =
                date +
                "/" +
                month +
                "/" +
                d.getFullYear() +
                ", " +
                hours +
                ":" +
                mins +
                ":" +
                seconds;
              sock.emit("userseenmessage", {
                session_id: live_chat_cb_session,
                device_print: device_print,
                bot_id: chatbot_id,
                time: d,
                channel: "website",
                agent_id: agent_id,
              });
            }
            seen_cleared = true;
          };
          anotherDiv.onfocus = function () {
            if (!seen_cleared && sock) {
              var d = new Date();
              var date = d.getDate();
              if (date < 10) {
                date = "0" + date;
              }
              var month = d.getMonth() + 1;
              if (month < 10) {
                month = "0" + month;
              }
              var hours = d.getHours();
              if (hours < 10) {
                hours = "0" + hours;
              }
              var mins = d.getMinutes();
              if (mins < 10) {
                mins = "0" + mins;
              }
              var seconds = d.getSeconds();
              if (seconds < 10) {
                seconds = "0" + seconds;
              }
              d =
                date +
                "/" +
                month +
                "/" +
                d.getFullYear() +
                ", " +
                hours +
                ":" +
                mins +
                ":" +
                seconds;
              sock.emit("userseenmessage", {
                session_id: live_chat_cb_session,
                device_print: device_print,
                bot_id: chatbot_id,
                time: d,
                channel: "website",
                agent_id: agent_id,
              });
            }
            seen_cleared = true;
          };
        }, 1000);

        function closure() {
          if (closure_enable == "1") {
            if (
              body.style.display != "block" &&
              !noBot &&
              !alreadyClicked &&
              mainDiv.style.display == "block"
            ) {
              mainDiv.click();
            }
          }
        }
        var current_question_type;
        var question_id;
        var session_feedback;
        if (
          /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
            navigator.userAgent
          )
        ) {
          // anotherDiv.style.display = "none";
          anotherDiv.style.visibility = "hidden";
        } else {
          anotherDiv.style.display = "block";
          anotherDiv.style.visibility = "visible";
        }
        // anotherDiv.style.bottom = "-100%";
        anotherDiv.style.visibility = "hidden";

        if (launcher_position == "LB") {
          anotherDiv.style.transform = "translateX(-40%) translateY(40%) scale(0)";
        }else{
          anotherDiv.style.transform = "translateX(40%) translateY(40%) scale(0)";
        }

        setTimeout(function () {
          if (is_disabled == 0) {
            document.body.appendChild(pulseDiv);
            setTimeout(function () { }, transition_time);
            document.body.appendChild(anotherDiv);
            setTimeout(function () {
              var x = launcher_div.clientHeight + 95;
              pulseDiv.style.height = x + "px";
            }, 100);
          }
        }, 500);
        more_icon.addEventListener("click", function (k) {
          if (
            /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
              navigator.userAgent
            )
          ) {
            k.stopPropagation();
          }
          if (header.contains(icon_header_div)) {
            if (launcher_position == "RM") {
            }
            header.removeChild(icon_header_div);
          } else {
            if (launcher_position == "RM") {
            }
            header.appendChild(icon_header_div);
          }
        });
        close_bot.addEventListener("click", function (k) {
          mainDiv.click();
          var audio = document.getElementById("audioPlayback");
          if (audio) {
            audio.pause();
            audio.currentTime = 0;
          }
        });
        header_menu.addEventListener("click", function (k) {
          k.stopPropagation();
          window.onclick = function (event) {
            if (event.target != header_menu_div && event.target != header_menu) {
              if (header_menu_div.classList.contains("closed-header-menu")) {
              } else {
                header_menu_div.classList.add("closed-header-menu");
              }
            }
          };
          if (header_menu_div.classList.contains("closed-header-menu")) {
            header_menu_div.classList.remove("closed-header-menu");
          } else {
            header_menu_div.classList.add("closed-header-menu");
          }
        });
        launcher_div.addEventListener("click", function (k) {
          mainDiv.click();
        });
        mainDiv.addEventListener(
          "click",
          function (k) {
            if (device_print) {
            } else {
              device_print = ip_address;
            }
            if (voice_input == "1") {
              if (document.body.contains(audio_loading_div)) {
              } else {
                var audio_loading_image = document.createElement("IMG");
                audio_loading_image.classList.add("audio-loading-image");
                audio_loading_image.src =
                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/other_mic_loading.gif";
                audio_loading_div.appendChild(audio_loading_image);
                document.body.appendChild(audio_loading_div);
              }
            }
            if (enter.src && enter.src.length > 0) {
            } else {
              enter.src =
                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/bot_input_send.svg";
            }
            if (microphone.src && microphone.src.length > 0) {
            } else {
              microphone.src =
                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/microphone-widget-new.svg"
            }
            if (attach_file.src && attach_file.src.length > 0) {
            } else {
              attach_file.src =
                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/paperclip_widget_new.svg";
            }
            if (menu.src && menu.src.length > 0) {
            } else {
              menu.src =
                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/menu.svg";
            }
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            if (chatbot_id != 13479) {
              if (chatbot_id == 23568) {

              } else {
                launcher_div.style.display = "none";
                pulseDiv.style.cssText =
                  pulseDiv.style.cssText + "width:60px !important";
                pulseDiv.style.cssText =
                  pulseDiv.style.cssText + "height:60px !important";
              }
            }
            if (launcher_close_icon && launcher_close_icon.parentElement) {
              launcher_close_icon.parentElement.removeChild(launcher_close_icon);
            }
            if (window.Tawk_API) {
              if (!chat_with_us_cliked) {
                window.Tawk_API.hideWidget();
              }
            }
            try {
              var zd_status = zE("webWidget:get", "display");
              if (zd_status != "hidden") {
                zE("webWidget", "hide");
              }
            } catch (e) {
            } finally {
            }
            if (window.LC_API) {
              try {
                window.LC_API.hide_chat_window();
              } catch (e) {
              } finally {
              }
            }
            if (body && body.style.display == "block") {
              try {
                if (
                  body.parentElement &&
                  body.parentElement.parentElement &&
                  body.parentElement.parentElement.parentElement
                ) {
                  var main_body = body.parentElement.parentElement.parentElement;
                  if (
                    main_body.clientWidth == 361 ||
                    main_body.clientWidth == 150
                  ) {
                    if (window.parent) {
                      window.parent.postMessage("disappear", "*");
                    }
                  }
                }
              } catch (e) {
              } finally {
              }
              var label = document.getElementsByClassName(
                "launcher-label-smatest"
              )[0];
              if (label) {
                label.parentElement.style.display = "none";
              }
              if (document.getElementsByClassName("smat-lb-div")[0]) {
                document.getElementsByClassName("smat-lb-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-other-div")[0]) {
                document.getElementsByClassName("smat-other-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-rm-div")[0]) {
                document.getElementsByClassName("smat-rm-div")[0].style.padding =
                  "0px";
              }
              if (mainDiv.className.includes("smat-other-div")) {
                mainDiv.classList.remove("smat-other-div");
                mainDiv.classList.add("smat-div");
              }
              if (mainDiv.className.includes("smat-lb-other-div")) {
                mainDiv.classList.remove("smat-lb-other-div");
                mainDiv.classList.add("smat-lb-div");
              }
              if (mainDiv.className.includes("smat-rm-other-div")) {
                mainDiv.classList.remove("smat-rm-other-div");
                mainDiv.classList.add("smat-rm-div");
              }
              if (pulseDiv.className.includes("pulse-rm-other-div")) {
                pulseDiv.classList.remove("pulse-rm-other-div");
                pulseDiv.classList.add("pulse-rm-div");
              }
              body.style.display = "none";
              mainDiv.style.display = "block";
              var img = document.getElementById("main_icon_smatest");
              if (img.className.includes("height-25")) {
                img.classList.remove("height-25");
              }
              if (img.className.includes("width-25")) {
                img.classList.remove("width-25");
              }
              img.src = avatar_icon;
              img.currentSrc = avatar_icon;
              if (mainDiv.className.includes("padding-15")) {
                mainDiv.classList.remove("padding-15");
              }
              if (
                /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                  navigator.userAgent
                )
              ) {
                // anotherDiv.style.display = "none";
                anotherDiv.style.visibility = "hidden";
              } else {
                anotherDiv.style.display = "block";
                anotherDiv.style.visibility = "visible";
              }
              // anotherDiv.style.bottom = "-100%";
              anotherDiv.style.visibility = "hidden";
              if (launcher_position == "LB") {
                anotherDiv.style.transform = "translateX(-40%) translateY(40%) scale(0)";
              }else{
                anotherDiv.style.transform = "translateX(40%) translateY(40%) scale(0)";
              }
              // mainDiv.style.background = 'transparent';
              if (mainDiv.classList.contains("bg-green-gradient")) {
                mainDiv.classList.remove("bg-green-gradient");
              }
            } else {
              try {
                if (
                  body.parentElement &&
                  body.parentElement.parentElement &&
                  body.parentElement.parentElement.parentElement
                ) {
                  var main_body = body.parentElement.parentElement.parentElement;
                  if (
                    main_body.clientWidth == 361 ||
                    main_body.clientWidth == 150
                  ) {
                    if (window.parent) {
                      window.parent.postMessage("appear", "*");
                    }
                  }
                }
              } catch (e) {
              } finally {
              }
              if (mainDiv.className.includes("pulse-btn")) {
                mainDiv.classList.remove("pulse-btn");
              }
              if (document.getElementsByClassName("smat-lb-div")[0]) {
                document.getElementsByClassName("smat-lb-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-div")[0]) {
                document.getElementsByClassName("smat-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-rm-div")[0]) {
                document.getElementsByClassName("smat-rm-div")[0].style.padding =
                  "0px";
              }
              var img = document.getElementById("main_icon_smatest");
              if (main_fore == "white") {
                img.src =
                  "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/close_modal_white.png";
                img.currentSrc =
                  "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/close_modal_white.png";
              } else {
                img.src =
                  "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/close_modal.png";
                img.currentSrc =
                  "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/close_modal.png";
              }
              img.classList.add("height-25");
              img.classList.add("width-25");
              if (mainDiv.className.includes("smat-div")) {
                mainDiv.classList.remove("smat-div");
                mainDiv.classList.add("smat-other-div");
              }
              if (mainDiv.className.includes("smat-lb-div")) {
                mainDiv.classList.remove("smat-lb-div");
                mainDiv.classList.add("smat-lb-other-div");
              }
              if (mainDiv.className.includes("smat-rm-div")) {
                mainDiv.classList.remove("smat-rm-div");
                mainDiv.classList.add("smat-rm-other-div");
              }
              if (pulseDiv.className.includes("pulse-rm-div")) {
                pulseDiv.classList.remove("pulse-rm-div");
                pulseDiv.classList.add("pulse-rm-other-div");
              }
              mainDiv.classList.add("padding-15");
              if (themes_array && themes_array[0] && themes_array[0].length > 0) {
                // mainDiv.style.background = themes_array[0]
              } else {
                mainDiv.classList.add("bg-green-gradient");
              }
              var label = document.getElementsByClassName(
                "launcher-label-smatest"
              )[0];
              if (label) {
                label.parentElement.style.display = "none";
              }
              if (!firstTimeClicked) {
                adjustUI(shouldShowMenu, entry_id, header, body, footer, input, microphone, enter, company_title_description, setPlaceHolders)
                if (!shouldShowMenu) {
                  footer.style.display = "none";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 168px)";
                  } else {
                    body.style.height = "calc(100% - 93px)";
                  }
                  footer.classList.add("close");
                } else {
                  if (entry_id) {
                    footer.style.display = "block";
                    input.style.pointerEvents = "auto";
                    microphone.style.pointerEvents = "auto";
                    microphone.style.opacity = 1;
                    enter.style.pointerEvents = "auto";
                    setPlaceHolders();
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                  } else {
                    footer.style.display = "block";
                    input.blur();
                    input.style.pointerEvents = "none";
                    microphone.style.pointerEvents = "none";
                    microphone.style.opacity = 0;
                    enter.style.pointerEvents = "none";
                    input.placeholder = "Choose from Menu";
                    input.type = "text";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                  }
                }
                if (picker) {
                  try {
                    picker.destroy();
                  } catch (e) {
                  } finally {
                  }
                }
                mainClick(1);
              } else {
                anotherDiv.style.display = "block";
                anotherDiv.style.bottom = "15px";
                anotherDiv.style.visibility = "visible";
                anotherDiv.style.transform = " translateX(0) translateY(0) scale(1)";
                body.style.display = "block";
              }
            }
          },
          !1
        );
        reload_menu.addEventListener("click", function (k) {
          k.stopPropagation();
          const modalBg = document.createElement("div");
          modalBg.className = "relaod_model-div-bg";
          // modalBg.id = "opened";
          modalBg.style.zIndex = '999999999999999'
          
          const modalContent = document.createElement("div");
          modalContent.className = "relaod_model-inside_div";

          const heading = document.createElement("h2");
          heading.innerHTML = generateTranslatedContent(translations, "Reset Chat", main_lang_code, language_code, input); 
          heading.style.fontSize = "16px";
          heading.style.margin = "0";
          heading.style.color = "#000";
          heading.style.fontWeight = "600";
          heading.style.textAlign = "center";

          modalContent.appendChild(heading);

          const message = document.createElement("p");
          let text1 = generateTranslatedContent(translations, "Confirm reset?", main_lang_code, language_code, input); 
          let text2 = generateTranslatedContent(translations, "This will create a new session", main_lang_code, language_code, input); 
          message.innerHTML = text1 + '<br/>' + text2
          message.style.color = "#555";
          message.style.fontSize = "14px";
          message.style.margin = "0";
          message.style.textAlign ='center'
          message.style.lineHeight ='24px'

          modalContent.appendChild(message);

          const Btn_div = document.createElement("div");
          Btn_div.style.display = "flex"

          const cancelButton = document.createElement("button");
          cancelButton.innerHTML = generateTranslatedContent(translations, "Cancel", main_lang_code, language_code, input); 
          cancelButton.style.marginRight = "10px";
          cancelButton.style.padding = "10px 20px";
          cancelButton.style.border = "none";
          cancelButton.style.borderRadius = "5px";
          cancelButton.style.cssText = cancelButton.style.cssText + "background-color:#fff !important";
          cancelButton.style.cssText = cancelButton.style.cssText + "color:#000 !important";
          cancelButton.style.cursor = "pointer";
          cancelButton.style.fontSize = "14px";
          cancelButton.style.fontWeight = "600";
          cancelButton.style.minWidth = "fit-content";
          cancelButton.style.width = "fit-content";

          cancelButton.addEventListener("click", function () {
              modalBg.remove();
          });
          Btn_div.appendChild(cancelButton);
          const resetButton = document.createElement("button");
          resetButton.innerHTML = generateTranslatedContent(translations, "Reset", main_lang_code, language_code, input); 
          resetButton.style.padding = "10px 20px";
          resetButton.style.border = "none";
          resetButton.style.borderRadius = "9px";
          resetButton.style.cssText = resetButton.style.cssText + "background-color:black !important";
          resetButton.style.cssText = resetButton.style.cssText + "color:white !important";
          resetButton.style.cursor = "pointer";
          resetButton.style.fontSize = "14px";
          resetButton.style.minWidth = "fit-content";
          resetButton.style.width = "fit-content";
          resetButton.addEventListener("click", function () {
              if (reload_div) {
                reload_div.click()
              };
              modalBg.remove();
          });
          if (font && font.length > 0) {
            heading.classList.add(font);
            message.classList.add(font);
            cancelButton.classList.add(font);
            resetButton.classList.add(font);
          }
          Btn_div.appendChild(resetButton);
          modalContent.appendChild(Btn_div);
          modalBg.appendChild(modalContent);
          const opened = document.getElementById("opened")
          if (opened) {
            opened.appendChild(modalBg);
          }
        });

        var prev_placeholder;
        var prev_input_type;
        var prev_should_show;
        var prev_style;
        var prev_id;
        var continue_chat = document.createElement("DIV");
        continue_chat.classList.add("continue-chat-div");
        var refresh_btn = document.createElement("BUTTON");
        var continue_btn = document.createElement("BUTTON");
        refresh_btn.classList.add("refresh-btn");
        continue_btn.classList.add("continue-btn");
        continue_chat.appendChild(refresh_btn);
        continue_chat.appendChild(continue_btn);

        function getParagraphs(htmlString) {
          var first_div_index;
          if (htmlString) {
            first_div_index = htmlString.indexOf("<div");
          }
          var str;
          if (first_div_index > -1) {
            str = htmlString.substring(0, first_div_index);
            str = str.split("<br/>").join("");
          }
          var div = document.createElement("div");
          div.innerHTML = htmlString;
          var array = [];
          if (str && str.length > 0) {
            var test_div = document.createElement("DIV");
            test_div.innerHTML = str;
            if (
              test_div &&
              test_div.outerText &&
              test_div.outerText.trim().length > 0
            ) {
              array.push(test_div);
            }
          }
          for (var i = 0; i < div.children.length; i++) {
            var k = document.createElement("DIV");
            k.innerHTML = div.children[i].innerHTML;
            if (
              (k.innerText && k.innerText.length > 0) ||
              k.innerHTML.includes("<iframe")
            ) {
              array.push(div.children[i]);
            }
          }
          return array;
        }

        function getCustomParagraphs(htmlString) {
          htmlString = htmlString.split("<br/>").join("")
          var first_div_index = htmlString.indexOf("<div");
          var str;
          if (first_div_index > -1) {
            str = htmlString.substring(0, first_div_index);
            str = str.split("<br/>").join("");
          }
          var div = document.createElement("div");
          div.innerHTML = htmlString;
          var array = [];
          if (str && str.length > 0) {
            var test_div = document.createElement("DIV");
            test_div.innerHTML = str;
            if (
              test_div &&
              test_div.outerText &&
              test_div.outerText.trim().length > 0
            ) {
              array.push(test_div);
            }
          }
          for (var i = 0; i < div.children.length; i++) {
            var k = document.createElement("DIV");
            k.innerHTML = div.children[i].innerHTML;
            if (
              (k.innerText && k.innerText.length > 0) ||
              k.innerHTML.includes("<iframe")
            ) {
              array.push(div.children[i]);
            }
          }
          return array;
        }

        function updateMenuIcons() {
          const headerMenuItems = document.querySelectorAll('.header-menu-item');    
          if (headerMenuItems.length == 1) {
              if (header_menu) {
                header_menu.style.display = 'none'
              }
              if (reload_menu) {
                reload_menu.style.display = 'block'
              }
          } else if (headerMenuItems.length >= 2) {
              if (reload_menu) {
                reload_menu.style.display = 'none'
              }
              if (header_menu) {
                header_menu.style.display = 'block'
              }
          }
        }

        function createAppMenu(option_div, text, bg_shadow, container) {
          var app_menu_div = document.createElement('DIV');
          app_menu_div.classList.add('menu_div');
          app_menu_div.setAttribute('id', 'open-menu-sb');
          
          var menu_inner = document.createElement('DIV');
          menu_inner.innerHTML = generateTranslatedContent(translations, text, main_lang_code, language_code, input);
          menu_inner.style.fontWeight = '600'
          
          var menu_icon = document.createElement("IMG");
          menu_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/menu-list-new.svg';
          menu_icon.alt = 'menuIcon';
          menu_icon.style.width = '15px';
          menu_icon.style.height = '15px';
          
          app_menu_div.appendChild(menu_icon);
          app_menu_div.appendChild(menu_inner);
          
          option_div.appendChild(app_menu_div);

            body.scrollTop = body.scrollHeight;
          
          var intervalId = setInterval(function() {
            if (bg_shadow && container) {
                app_menu_div.addEventListener('click', function () {
                    bg_shadow.style.visibility = 'visible';
                    container.style.opacity = '1';
                    container.style.transform = 'translateY(0)';  
                });
                clearInterval(intervalId); 
            }
          }, 100);
        }

        function handleImageModal(question_array, main_image_options_div) {
            if (
              question_array[0].image_url &&
              question_array[0].image_url.length > 0 &&
              question_array[0].image_url != "null" &&
              (question_array[0].image_url.includes("s3.ap-south-1.amazonaws.com") ||
                question_array[0].image_url.includes("media.tenor.com") ||
                question_array[0].image_url.includes("giphy.com"))
            ) {
              var imgDiv = document.createElement("DIV");
              imgDiv.classList.add("image-div-smatest");
          
              var questionImg = document.createElement("IMG");
              questionImg.src = question_array[0].image_url;
              questionImg.classList.add("question-img-smatest");
          
              imgDiv.appendChild(questionImg);
              main_image_options_div.appendChild(imgDiv);
          
              var modal_div = document.createElement("DIV");
              if (font && font.length > 0) {
                modal_div.classList.add(font);
              }
              modal_div.classList.add("modal-smatest");
              modal_div.id = "myImageModal";
          
              var modal_content_div = document.createElement("DIV");
              modal_content_div.classList.add("modal-content-smatest");
          
              var modal_close_span = document.createElement("SPAN");
              modal_close_span.classList.add("close-modal");
              modal_close_span.innerHTML = "&times";
              modal_content_div.appendChild(modal_close_span);
          
              modal_div.appendChild(modal_content_div);
              modal_div.style.display = "block";
          
              window.onclick = function (event) {
                if (event.target == modal_div) {
                  if (modal_content_div.contains(imgDiv)) {
                    modal_content_div.removeChild(imgDiv);
                  }
                  questionImg.style.width = "100%";
                  main_image_options_div.appendChild(imgDiv);
                  if (document.body.contains(modal_div)) {
                    document.body.removeChild(modal_div);
                  }
                  imgDiv.children[0].classList.remove("fit-content-i");
                }
              };
          
              modal_close_span.addEventListener("click", function (k) {
                if (modal_content_div.contains(imgDiv)) {
                  modal_content_div.removeChild(imgDiv);
                }
                questionImg.style.width = "100%";
                main_image_options_div.appendChild(imgDiv);
                if (document.body.contains(modal_div)) {
                  document.body.removeChild(modal_div);
                }
                imgDiv.children[0].classList.remove("fit-content-i");
              });
          
              imgDiv.addEventListener("click", function (k) {
                if (!document.body.contains(modal_div)) {
                  modal_content_div.appendChild(imgDiv);
                  questionImg.style.width = "auto";
                  imgDiv.children[0].classList.add("fit-content-i");
                  document.body.appendChild(modal_div);
                }
              });
            }
        }
        
        nothingWentOnFor = 0;
        setInterval(function () {
          if (
            anotherDiv &&
            anotherDiv.style.display == "block" &&
            shouldStartEncourageTimer &&
            !isTableOpened
          ) {
            nothingWentOnFor = nothingWentOnFor + 1;
            if (nothingWentOnFor == 100000) {
              nothingWentOnFor = 0;
              encourageMessageIteration = encourageMessageIteration + 1;
              if (
                encourageMessageIteration == 1 ||
                encourageMessageIteration == 2 ||
                encourageMessageIteration == 3
              ) {
                var encourageDiv = document.createElement("DIV");
                encourageDiv.classList.add("question-div-smatest");
                setTimeout(function () {
                  encourageDiv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  encourageDiv.classList.add(font);
                }
                var encourage_icon = document.createElement("IMG");
                encourage_icon.alt = "Logo of " + totalData[0].name;
                encourage_icon.src = avatar_icon;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(encourage_icon);
                iconDiv.classList.add("question-icon-div");
                encourage_icon.classList.add("question-icon-smatest");
                var encourage_text = document.createElement("LABEL");
                encourage_text.innerHTML = generateTranslatedContent(translations, "Hi, I did not receive a response. Is there anything I can help you with?", main_lang_code, language_code, input);
                say(encourage_text.innerText);
                encourage_text.classList.add("question-text-error");
                encourage_text.classList.add("options-div-smatest");
                if (font && font.length > 0) {
                  encourage_text.classList.add(font);
                }
                encourageDiv.appendChild(iconDiv);
                encourageDiv.appendChild(encourage_text);
                body.appendChild(encourageDiv);
                playBotUserSound(1);
                body.scrollTop = body.scrollHeight;
              } else if (encourageMessageIteration == 4) {
                var encourageDiv = document.createElement("DIV");
                encourageDiv.classList.add("question-div-smatest");
                setTimeout(function () {
                  encourageDiv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  encourageDiv.classList.add(font);
                }
                var encourage_icon = document.createElement("IMG");
                encourage_icon.alt = "Logo of " + totalData[0].name;
                encourage_icon.src = avatar_icon;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(encourage_icon);
                iconDiv.classList.add("question-icon-div");
                encourage_icon.classList.add("question-icon-smatest");
                var encourage_text = document.createElement("LABEL");
                encourage_text.innerHTML = "Come on Boy!";
                say(encourage_text.innerText);
                encourage_text.classList.add("question-text-error");
                encourage_text.classList.add("options-div-smatest");
                if (font && font.length > 0) {
                  encourage_text.classList.add(font);
                }
                encourageDiv.appendChild(iconDiv);
                encourageDiv.appendChild(encourage_text);
                body.appendChild(encourageDiv);
                playBotUserSound(1);
                body.scrollTop = body.scrollHeight;
              }
            }
          }
        }, 1000);
        setInterval(function () {
          var d = new Date();
            var date = d.getDate();
            if (date < 10) {
              date = "0" + date;
            }
            var month = d.getMonth() + 1;
            if (month < 10) {
              month = "0" + month;
            }
            var hours = d.getHours();
            if (hours < 10) {
              hours = "0" + hours;
            }
            var mins = d.getMinutes();
            if (mins < 10) {
              mins = "0" + mins;
            }
            var seconds = d.getSeconds();
            if (seconds < 10) {
              seconds = "0" + seconds;
            }
            d = date + "/" +  month +  "/" + d.getFullYear() +  ", " + hours + ":" + mins + ":" + seconds;
          if (start_live_chat_timer) {
            agent_message_timer = agent_message_timer + 1;
            if (
              agent_message_timer == 30 &&
              first_busy_message &&
              first_busy_message.length > 0
            ) {
              var livechatEncourageDiv = document.createElement("DIV");
              livechatEncourageDiv.classList.add("question-div-smatest");
              setTimeout(function () {
                livechatEncourageDiv.classList.add("top-0");
              }, transition_time);
              if (font && font.length > 0) {
                livechatEncourageDiv.classList.add(font);
              }
              var live_chat_encourage_icon = document.createElement("IMG");
              live_chat_encourage_icon.alt = "Logo of " + totalData[0].name;
              live_chat_encourage_icon.src = avatar_icon;
              var iconDiv = document.createElement("DIV");
              iconDiv.appendChild(live_chat_encourage_icon);
              iconDiv.classList.add("question-icon-div");
              live_chat_encourage_icon.classList.add("question-icon-smatest");
              var live_chat_encourage_text = document.createElement("LABEL");
              live_chat_encourage_text.innerHTML = first_busy_message;
              say(live_chat_encourage_text.innerText);
              live_chat_encourage_text.classList.add("question-text-error");
              live_chat_encourage_text.classList.add("options-div-smatest");
              if (font && font.length > 0) {
                live_chat_encourage_text.classList.add(font);
              }
              livechatEncourageDiv.appendChild(iconDiv);
              livechatEncourageDiv.appendChild(live_chat_encourage_text);
              if (alreadySockLoaded) {
                body.appendChild(livechatEncourageDiv);
              }
              playBotUserSound(1);
              body.scrollTop = body.scrollHeight;
              sock.emit("usersentmessage", {
                time: d,
                message: first_busy_message,
                session_id: live_chat_cb_session,
                device_print: device_print,
                type: "user",
                bot_id: chatbot_id,
                name: "user",
                channel: "website",
                agent_id: agent_id,
              });
            } else if (
              agent_message_timer == 60 &&
              second_busy_message &&
              second_busy_message.length > 0
            ) {
              var livechatEncourageDiv = document.createElement("DIV");
              livechatEncourageDiv.classList.add("question-div-smatest");
              setTimeout(function () {
                livechatEncourageDiv.classList.add("top-0");
              }, transition_time);
              if (font && font.length > 0) {
                livechatEncourageDiv.classList.add(font);
              }
              var live_chat_encourage_icon = document.createElement("IMG");
              live_chat_encourage_icon.alt = "Logo of " + totalData[0].name;
              live_chat_encourage_icon.src = avatar_icon;
              var iconDiv = document.createElement("DIV");
              iconDiv.appendChild(live_chat_encourage_icon);
              iconDiv.classList.add("question-icon-div");
              live_chat_encourage_icon.classList.add("question-icon-smatest");
              var live_chat_encourage_text = document.createElement("LABEL");
              live_chat_encourage_text.innerHTML = second_busy_message;
              say(live_chat_encourage_text.innerText);
              live_chat_encourage_text.classList.add("question-text-error");
              live_chat_encourage_text.classList.add("options-div-smatest");
              if (font && font.length > 0) {
                live_chat_encourage_text.classList.add(font);
              }
              livechatEncourageDiv.appendChild(iconDiv);
              livechatEncourageDiv.appendChild(live_chat_encourage_text);
              if (alreadySockLoaded) {
                body.appendChild(livechatEncourageDiv);
              }
              playBotUserSound(1);
              body.scrollTop = body.scrollHeight;
              sock.emit("usersentmessage", {
                time: d,
                message: second_busy_message,
                session_id: live_chat_cb_session,
                device_print: device_print,
                type: "user",
                bot_id: chatbot_id,
                name: "user",
                channel: "website",
                agent_id: agent_id,
              });
            } else if (
              agent_message_timer == 120 &&
              third_busy_message &&
              third_busy_message.length > 0
            ) {
              var livechatEncourageDiv = document.createElement("DIV");
              livechatEncourageDiv.classList.add("question-div-smatest");
              setTimeout(function () {
                livechatEncourageDiv.classList.add("top-0");
              }, transition_time);
              if (font && font.length > 0) {
                livechatEncourageDiv.classList.add(font);
              }
              var live_chat_encourage_icon = document.createElement("IMG");
              live_chat_encourage_icon.alt = "Logo of " + totalData[0].name;
              live_chat_encourage_icon.src = avatar_icon;
              var iconDiv = document.createElement("DIV");
              iconDiv.appendChild(live_chat_encourage_icon);
              iconDiv.classList.add("question-icon-div");
              live_chat_encourage_icon.classList.add("question-icon-smatest");
              var live_chat_encourage_text = document.createElement("LABEL");
              var link;
              if (
                /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                  navigator.userAgent
                )
              ) {
              } else {
              }
              live_chat_encourage_text.innerHTML = third_busy_message;
              say(live_chat_encourage_text.innerText);
              live_chat_encourage_text.classList.add("question-text-error");
              live_chat_encourage_text.classList.add("options-div-smatest");
              if (font && font.length > 0) {
                live_chat_encourage_text.classList.add(font);
              }
              livechatEncourageDiv.appendChild(iconDiv);
              livechatEncourageDiv.appendChild(live_chat_encourage_text);
              if (alreadySockLoaded) {
                body.appendChild(livechatEncourageDiv);
              }
              playBotUserSound(1);
              body.scrollTop = body.scrollHeight;
              sock.emit("usersentmessage", {
                time: d,
                message: third_busy_message,
                session_id: live_chat_cb_session,
                device_print: device_print,
                type: "user",
                bot_id: chatbot_id,
                name: "user",
                channel: "website",
                agent_id: agent_id,
              });
            }
          }
        }, 1000);

        function clickSchedule(text, arr) {
          if (arr && arr.length > 0) {
            take_action_id = arr[0];
            take_action_sequence = arr[1];
            custom_action_id = arr[0];
            custom_action_sequence = arr[1];
          }
          var spinningDiv = document.createElement("DIV");
          spinningDiv.classList.add("question-div-smatest");
          spinningDiv.classList.add("top-0");
          if (font && font.length > 0) {
            spinningDiv.classList.add(font);
          }
          var spinnerDiv = document.createElement("DIV");
          spinnerDiv.classList.add("spinner1-smatest");
          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
          var iconDiv = document.createElement("DIV");
          iconDiv.appendChild(ques_icon);
          iconDiv.classList.add("question-icon-div");
          ques_icon.src = avatar_icon;
          ques_icon.classList.add("question-icon-smatest");
          var inner1 = document.createElement("DIV");
          inner1.classList.add("bounce1");
          var inner2 = document.createElement("DIV");
          inner2.classList.add("bounce2");
          var inner3 = document.createElement("DIV");
          inner3.classList.add("bounce3");
          spinnerDiv.appendChild(inner1);
          spinnerDiv.appendChild(inner2);
          spinnerDiv.appendChild(inner3);
          spinningDiv.appendChild(iconDiv);
          spinningDiv.appendChild(spinnerDiv);
          body.appendChild(spinningDiv);
          body.scrollTop = body.scrollHeight;
          setTimeout(function () {
            body.removeChild(spinningDiv);
            var questionDIv = document.createElement("DIV");
            questionDIv.classList.add("question-div-smatest");
            setTimeout(function () {
              questionDIv.classList.add("top-0");
            }, transition_time);
            if (font && font.length > 0) {
              questionDIv.classList.add(font);
            }
            var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
            var iconDiv = document.createElement("DIV");
            iconDiv.appendChild(ques_icon1);
            iconDiv.classList.add("question-icon-div");
            ques_icon1.src = avatar_icon;
            ques_icon1.classList.add("question-icon-smatest");
            questionDIv.appendChild(iconDiv);
            var option_div = document.createElement("DIV");
            var option_question = document.createElement("LABEL");
            option_question.innerHTML = text;
            say(option_question.innerText);
            if (font && font.length > 0) {
              option_question.classList.add(font);
            }
            if (
              (main_lang_code &&
                (main_lang_code == "he" ||
                  main_lang_code == "ur" ||
                  main_lang_code == "ar")) ||
              (main_lang_code == "default" &&
                (language_code == "ar" ||
                  language_code == "he" ||
                  language_code == "ur"))
            ) {
              option_question.classList.add("rtl");
            }
            option_div.appendChild(option_question);
            option_div.classList.add("options-div-smatest");
            questionDIv.appendChild(option_div);
            body.appendChild(questionDIv);
            body.scrollTop = body.scrollHeight;
            prev_input_type = input.type;
            prev_style = input.style.cssText;
            prev_id = input.id;
            input.type = "date";
            input.placeholder = "Enter date in dd/mm/yyyy format";
            input.id = "";
            if (shouldShowMenu) {
              if (voice_input == "1") {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 115px) !important";
              } else {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 80px) !important";
              }
            } else {
              if (voice_input == "1") {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 75px) !important";
              } else {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 45px) !important";
              }
            }
            input.style.cssText = input.style.cssText + "min-height:24px !important";
            input.style.cssText = input.style.cssText + "height:24px !important";
            input.style.cssText = input.style.cssText + "border:none !important";
            // input.style.cssText = input.style.cssText + "max-height:72px !important";
            footer.id = "";
            input.autocomplete = "off";
            try {
              google.maps.event.clearInstanceListeners(input);
            } catch (e) {
            } finally {
            }
            if (footer.style.display == "block") {
              prev_should_show = !0;
            } else {
              prev_should_show = !1;
            }
            footer.style.display = "block";
            if (header.contains(company_title_description)) {
              body.style.height = "calc(100% - 226px)";
            } else {
              body.style.height = "calc(100% - 150px)";
            }
            footer.classList.remove("close");
            if (shouldShowMenu) {
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
            }
            input.focus();
            var date = new Date();
            var day = date.getDate();
            day = ("0" + day).slice(-2);
            var month = date.getMonth() + 1;
            month = parseInt(month) + 1;
            month = ("0" + month).slice(-2);
            var year = date.getFullYear();
            var minValue = year + "-" + month + "-" + day;
            input.min = minValue;
            prev_placeholder = input.placeholder;
            input.placeholder = "visit";
          }, delay_time);
        }

        function clickFaq() {
          var spinningDiv = document.createElement("DIV");
          spinningDiv.classList.add("question-div-smatest");
          spinningDiv.classList.add("top-0");
          if (font && font.length > 0) {
            spinningDiv.classList.add(font);
          }
          var spinnerDiv = document.createElement("DIV");
          spinnerDiv.classList.add("spinner1-smatest");
          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
          var iconDiv = document.createElement("DIV");
          iconDiv.appendChild(ques_icon);
          iconDiv.classList.add("question-icon-div");
          ques_icon.src = avatar_icon;
          ques_icon.classList.add("question-icon-smatest");
          var inner1 = document.createElement("DIV");
          inner1.classList.add("bounce1");
          var inner2 = document.createElement("DIV");
          inner2.classList.add("bounce2");
          var inner3 = document.createElement("DIV");
          inner3.classList.add("bounce3");
          spinnerDiv.appendChild(inner1);
          spinnerDiv.appendChild(inner2);
          spinnerDiv.appendChild(inner3);
          spinningDiv.appendChild(iconDiv);
          spinningDiv.appendChild(spinnerDiv);
          body.appendChild(spinningDiv);
          body.scrollTop = body.scrollHeight;
          setTimeout(function () {
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                body.removeChild(spinningDiv);
                question_array = JSON.parse(this.response).next_question;
                var questionDIv = document.createElement("DIV");
                questionDIv.id =
                  question_array[0].id + ".." + question_array[0].sequence;
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.classList.add("white-space-normal");
                if (
                  question_array[0].question_text &&
                  question_array[0].question_text.includes("{{") &&
                  question_array[0].question_text.includes("}}")
                ) {
                  parseDataReferring(question_array, 0);
                }
                option_question.innerHTML = question_array[0].question_text;
                say(option_question.innerText);
                option_div.appendChild(option_question);
                handleImageModal(question_array, main_image_options_div);
                option_div.classList.add("dialogs-div-more-vertical-smatest");
                var slides_div = document.createElement("DIV");
                slides_div.classList.add("avatar-vertical-scrollbar");
                slides_div.classList.add("slides-random");
                slides_div.id = "avatar-scroll";
                var optionsArray = question_array[0].default_options.split(";;");
                if (optionsArray && optionsArray.length > 0) {
                  for (var j = 0; j < optionsArray.length; j++) {
                    var selectedKey;
                    var contact = document.createElement("DIV");
                    contact.classList.add("dialogs-div-vertical-smatest");
                    if (font && font.length > 0) {
                      contact.classList.add(font);
                    }
                    var label = document.createElement("LABEL");
                    var text = document.createTextNode(optionsArray[j]);
                    label.appendChild(text);
                    contact.appendChild(label);
                    slides_div.appendChild(contact);
                    contact.addEventListener("click", function (e) {
                      var value = this.children[0].innerHTML;
                      var arr =
                        this.parentElement.parentElement.previousSibling.id.split(
                          ".."
                        );
                      if (!shouldDisableTakeAction) {
                        if (
                          footer &&
                          (input.style.pointerEvents == "none" ||
                            footer.style.display == "none")
                        ) {
                          takingRadioValue(
                            value,
                            this.parentElement,
                            2,
                            arr[0],
                            arr[1],
                            "c_s_c"
                          );
                        } else {
                          if (input && input.placeholder == "Type your query") {
                            takingRadioValue(
                              value,
                              this.parentElement,
                              2,
                              arr[0],
                              arr[1],
                              "c_s_c"
                            );
                          }
                        }
                      }
                    });
                  }
                }
                option_div.appendChild(slides_div);
                questionDIv.appendChild(iconDiv);
                questionDIv.appendChild(option_div);
                body.appendChild(questionDIv);
                setTimeout(function () {
                  body.appendChild(main_image_options_div);
                }, delay_time);
                body.scrollTop = body.scrollHeight;
              }
            };
            xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=faq_answer", !0);
            xhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            xhttp.send(
              "action=faq_answer&cb_session=" +
              cb_session +
              "&chatbot_id=" +
              chatbot_id +
              "&answer_text=FAQs&is_help=1"
            );
            body.scrollTop = body.scrollHeight;
          }, delay_time);
        }
        var all_emojis = [
          {
            name: "Grinning Face",
            value: "&#128512;",
            title: "GRINNING FACE",
          },
          {
            name: "Grinning Face with smiling face",
            value: "&#128513;",
            title: "GRINNING FACE WITH SMILING FACE",
          },
          {
            name: "Face with tears of joy",
            value: "&#128514;",
            title: "FACE WITH TEARS OF JOY",
          },
        ];
        var picker;
        var i = 0;

        function moveProgress(str) {
          if (i == 0) {
            i = 1;
            var elem = document.getElementById(str);
            var width = 1;
            var id = setInterval(frame, 20);

            function frame() {
              if (width >= 100) {
                clearInterval(id);
                i = 0;
              } else {
                width++;
                elem.style.width = width + "%";
              }
            }
          }
        }

        function addQuestionFeedback(option_div, question_array) {
          var question_feedback_wrapper = document.createElement("DIV");
          question_feedback_wrapper.classList.add("pull-left");
          question_feedback_wrapper.classList.add("text-center");
          question_feedback_wrapper.classList.add("full-width");
          var question_feedback_div = document.createElement("DIV");
          question_feedback_div.classList.add("question-feedback-div");
          question_feedback_div.classList.add("inline-block");
          question_feedback_wrapper.appendChild(question_feedback_div);
          var thumbs_up_div = document.createElement("SPAN");
          thumbs_up_div.classList.add("thumbs-up-parent");
          var thumbs_up = document.createElement("IMG");
          thumbs_up.src =
            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/feedback_thumbs_up.png";
          thumbs_up.classList.add("feedback-icon");
          thumbs_up.id = question_array[0].id;
          thumbs_up.title = "Helpful";
          thumbs_up_div.appendChild(thumbs_up);
          thumbs_up.addEventListener("click", function (k) {
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            this.classList.add("no-pointer-events");
            this.parentElement.parentElement.classList.add("no-pointer-events");
            var icons = this.parentElement.parentElement.children;
            for (var i = 0; i < icons.length; i++) {
              if (icons[i].children[0].title != "Helpful") {
                icons[i].parentElement.removeChild(icons[i]);
              }
            }
            this.parentElement.parentElement.classList.add("opacity-1");
            var submitFeedbackXhttp = new XMLHttpRequest();
            submitFeedbackXhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                var appreciation_div = document.createElement("DIV");
                appreciation_div.classList.add("appreciation-div");
                var progress_parent_div = document.createElement("DIV");
                progress_parent_div.id = "myProgress";
                var progress_child_div = document.createElement("DIV");
                progress_child_div.id = "myBar";
                progress_parent_div.appendChild(progress_child_div);
                appreciation_div.appendChild(progress_parent_div);
                var appreciation_label = document.createElement("LABEL");
                appreciation_label.innerHTML =
                  generateTranslatedContent(translations, "Thanks for submitting your feedback.", main_lang_code, language_code, input);
                appreciation_div.appendChild(appreciation_label);
                var progressLoaded;
                body.appendChild(appreciation_div);
                setInterval(function () {
                  if (!progressLoaded) {
                    if (document.getElementById("myBar")) {
                      progressLoaded = !0;
                      moveProgress("myBar");
                    }
                  }
                });
                setTimeout(function () {
                  body.removeChild(appreciation_div);
                }, 2000);
              }
            };
            submitFeedbackXhttp.open(
              "POST",
              main_url + "/kya_backend/pagehub/feedback",
              !0
            );
            submitFeedbackXhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            submitFeedbackXhttp.send(
              "chatbot_id=" +
              chatbot_id +
              "&action=question_feedback&feedback=1&cb_session=" +
              cb_session +
              "&question_id=" +
              this.id
            );
          });
          var thumbs_down_div = document.createElement("SPAN");
          thumbs_down_div.classList.add("thumbs-down-parent");
          var thumbs_down = document.createElement("IMG");
          thumbs_down.src =
            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/feedback_thumbs_down.png";
          thumbs_down.classList.add("feedback-icon");
          thumbs_down.id = question_array[0].id;
          thumbs_down.title = "Not Helpful";
          thumbs_down_div.appendChild(thumbs_down);
          thumbs_down.addEventListener("click", function (k) {
            agreed = !1;
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            var k = this;
            negativeFeedbackDiv = document.createElement("DIV");
            negativeFeedbackDiv.classList.add("negative-feedback-div");
            negativeFeedbackDiv.classList.add("full-width");
            negativeFeedbackDiv.classList.add("p-b-8");
            if (negativeFeedbackDiv.classList.contains("closed")) {
              negativeFeedbackDiv.classList.remove("closed");
            } else {
              negativeFeedbackDiv.classList.add("closed");
              negativeFeedbackDiv.classList.remove("closed");
            }
            var full_feedback_header = document.createElement("DIV");
            full_feedback_header.classList.add("negative-feedback-header");
            var full_feedback_label = document.createElement("LABEL");
            full_feedback_label.classList.add("negative-feedback-label");
            full_feedback_label.classList.add("text-center");
            full_feedback_label.innerHTML = "We are sorry 😔 ";
            fullFeedbackDiv.appendChild(full_feedback_label);
            if (font && font.length > 0) {
              fullFeedbackDiv.classList.add(font);
            }
            var feedback_footer_div = document.createElement("DIV");
            feedback_footer_div.classList.add("inline-block");
            feedback_footer_div.classList.add("w-90");
            feedback_footer_div.classList.add("m-l-5p");
            var feedback_input = document.createElement("TEXTAREA");
            feedback_input.placeholder =
              "I would really appreciate it if you could give me some more details.";
            feedback_input.classList.add("feedback-input");
            if (font && font.length > 0) {
              feedback_input.classList.add(font);
            }
            var feedback_enter = document.createElement("IMG");
            feedback_enter.src =
              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/bot_input_send.svg";
            feedback_enter.classList.add("feedback-enter-icon");
            feedback_footer_div.appendChild(feedback_input);
            feedback_footer_div.appendChild(feedback_enter);
            var question_id = this.id;
            feedback_input.addEventListener("keydown", function (e) {
              if (
                e.keyCode === 13 &&
                feedback_enter.style.pointerEvents != "none"
              ) {
                if (
                  feedback_input &&
                  feedback_input.value &&
                  feedback_input.value.length > 0
                ) {
                  var json = {};
                  json.message = feedback_input.value;
                  agreed = !0;
                  var submitFeedbackXhttp = new XMLHttpRequest();
                  submitFeedbackXhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      feedback_enter.style.pointerEvents = "auto";
                      negativeFeedbackDiv.classList.add("closed");
                      var appreciation_div = document.createElement("DIV");
                      appreciation_div.classList.add("appreciation-div");
                      var progress_parent_div = document.createElement("DIV");
                      progress_parent_div.id = "myProgress";
                      var progress_child_div = document.createElement("DIV");
                      progress_child_div.id = "myBar";
                      progress_parent_div.appendChild(progress_child_div);
                      appreciation_div.appendChild(progress_parent_div);
                      var appreciation_label = document.createElement("LABEL");
                      appreciation_label.innerHTML =
                        generateTranslatedContent(translations, "Thanks for submitting your feedback.", main_lang_code, language_code, input);
                      appreciation_div.appendChild(appreciation_label);
                      var progressLoaded;
                      body.appendChild(appreciation_div);
                      setInterval(function () {
                        if (!progressLoaded) {
                          if (document.getElementById("myBar")) {
                            progressLoaded = !0;
                            moveProgress("myBar");
                          }
                        }
                      });
                      setTimeout(function () {
                        body.removeChild(appreciation_div);
                      }, 2000);
                    }
                  };
                  submitFeedbackXhttp.open(
                    "POST",
                    main_url + "/kya_backend/pagehub/feedback",
                    !0
                  );
                  submitFeedbackXhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  submitFeedbackXhttp.send(
                    "chatbot_id=" +
                    chatbot_id +
                    "&action=question_feedback_message&feedback_message=" +
                    JSON.stringify(json) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id
                  );
                }
              }
            });
            feedback_enter.addEventListener("click", function (e) {
              if (
                feedback_input &&
                feedback_input.value &&
                feedback_input.value.length > 0
              ) {
                var json = {};
                json.message = feedback_input.value;
                agreed = !0;
                var submitFeedbackXhttp = new XMLHttpRequest();
                submitFeedbackXhttp.onreadystatechange = function () {
                  if (this.readyState == 4 && this.status == 200) {
                    feedback_enter.style.pointerEvents = "none";
                    negativeFeedbackDiv.classList.add("closed");
                    var appreciation_div = document.createElement("DIV");
                    appreciation_div.classList.add("appreciation-div");
                    var progress_parent_div = document.createElement("DIV");
                    progress_parent_div.id = "myProgress";
                    var progress_child_div = document.createElement("DIV");
                    progress_child_div.id = "myBar";
                    progress_parent_div.appendChild(progress_child_div);
                    appreciation_div.appendChild(progress_parent_div);
                    var appreciation_label = document.createElement("LABEL");
                    appreciation_label.innerHTML =
                      generateTranslatedContent(translations, "Thanks for submitting your feedback.", main_lang_code, language_code, input);
                    appreciation_div.appendChild(appreciation_label);
                    var progressLoaded;
                    body.appendChild(appreciation_div);
                    setInterval(function () {
                      if (!progressLoaded) {
                        if (document.getElementById("myBar")) {
                          progressLoaded = !0;
                          moveProgress("myBar");
                        }
                      }
                    });
                    setTimeout(function () {
                      body.removeChild(appreciation_div);
                    }, 2000);
                  }
                };
                submitFeedbackXhttp.open(
                  "POST",
                  main_url + "/kya_backend/pagehub/feedback",
                  !0
                );
                submitFeedbackXhttp.setRequestHeader(
                  "Content-type",
                  "application/x-www-form-urlencoded"
                );
                submitFeedbackXhttp.send(
                  "chatbot_id=" +
                  chatbot_id +
                  "&action=question_feedback_message&feedback_message=" +
                  JSON.stringify(json) +
                  "&cb_session=" +
                  cb_session +
                  "&question_id=" +
                  question_id
                );
              }
            });
            var close_feedback_icon = document.createElement("IMG");
            full_feedback_header.appendChild(full_feedback_label);
            full_feedback_header.appendChild(close_feedback_icon);
            close_feedback_icon.src =
              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/close_feedback.png";
            // close_feedback_icon.classList.add('fa');
            // close_feedback_icon.classList.add('fa-times');
            close_feedback_icon.classList.add("feedback-icon");
            close_feedback_icon.style.right = "10px";
            close_feedback_icon.style.top = "10px";
            close_feedback_icon.style.position = "absolute";
            close_feedback_icon.style.cursor = "pointer";
            close_feedback_icon.addEventListener("click", function (k) {
              agreed = !0;
              if (body.contains(negativeFeedbackDiv)) {
                negativeFeedbackDiv.classList.add("closed");
                var json = {};
                json.message = "Cancelled";
                var submitFeedbackXhttp = new XMLHttpRequest();
                submitFeedbackXhttp.onreadystatechange = function () {
                  if (this.readyState == 4 && this.status == 200) {
                    feedback_enter.style.pointerEvents = "auto";
                    negativeFeedbackDiv.classList.add("closed");
                    k.classList.add("no-pointer-events");
                    k.parentElement.parentElement.classList.add(
                      "no-pointer-events"
                    );
                    var icons = k.parentElement.parentElement.children;
                    for (var i = 0; i < icons.length; i++) {
                      if (icons[i].children[0].title != "Helpful") {
                        icons[i].parentElement.removeChild(icons[i]);
                      }
                    }
                    k.parentElement.parentElement.classList.add("opacity-1");
                  }
                };
                submitFeedbackXhttp.open(
                  "POST",
                  main_url + "/kya_backend/pagehub/feedback",
                  !0
                );
                submitFeedbackXhttp.setRequestHeader(
                  "Content-type",
                  "application/x-www-form-urlencoded"
                );
                submitFeedbackXhttp.send(
                  "chatbot_id=" +
                  chatbot_id +
                  "&action=question_feedback_message&feedback_message=" +
                  JSON.stringify(json) +
                  "&cb_session=" +
                  cb_session +
                  "&question_id=" +
                  question_id
                );
              }
            });
            negativeFeedbackDiv.appendChild(full_feedback_header);
            negativeFeedbackDiv.appendChild(feedback_footer_div);
            negativeFeedbackDiv.appendChild(close_feedback_icon);
            body.appendChild(negativeFeedbackDiv);
            this.classList.add("no-pointer-events");
            this.parentElement.parentElement.classList.add("no-pointer-events");
            var icons = this.parentElement.parentElement.children;
            for (var i = 0; i < icons.length; i++) {
              if (icons[i].children[0].title != "Not Helpful") {
                icons[i].parentElement.removeChild(icons[i]);
              }
            }
            this.parentElement.parentElement.classList.add("opacity-1");
            var submitFeedbackXhttp = new XMLHttpRequest();
            submitFeedbackXhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
              }
            };
            submitFeedbackXhttp.open(
              "POST",
              main_url + "/kya_backend/pagehub/feedback",
              !0
            );
            submitFeedbackXhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            submitFeedbackXhttp.send(
              "chatbot_id=" +
              chatbot_id +
              "&action=question_feedback&feedback=-1&cb_session=" +
              cb_session +
              "&question_id=" +
              this.id
            );
          });
          question_feedback_div.appendChild(thumbs_up_div);
          question_feedback_div.appendChild(thumbs_down_div);
          addFullFeedback();
          if (
            question_array[0].question_feedback &&
            question_array[0].question_feedback != null
          ) {
            if (question_array[0].question_feedback == "1") {
              question_feedback_div.removeChild(thumbs_down_div);
              question_feedback_div.parentElement.classList.add(
                "no-pointer-events"
              );
            } else if (question_array[0].question_feedback == "-1") {
              question_feedback_div.removeChild(thumbs_up_div);
              question_feedback_div.parentElement.classList.add(
                "no-pointer-events"
              );
            }
          }
          option_div.appendChild(question_feedback_wrapper);
          shouldShowFullFeedback = !0;
        }

        function sendAlertCall() {
          mailSent = !0;
          var d = new Date();
          var new_date = new Date(d.getTime() + d.getTimezoneOffset() * 60000);
          var final_date = d;
          var hours = final_date.getHours();
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
              var questionArray = [];
              prev_questions_array = JSON.parse(this.response).qna_prev;
              if (prev_questions_array && prev_questions_array.length > 0) {
                for (var i = 0; i < prev_questions_array.length; i++) {
                  if (
                    prev_questions_array[i].type == "contact" ||
                    prev_questions_array[i].type == "slides" ||
                    prev_questions_array[i].type == "statement" ||
                    prev_questions_array[i].type == "url_auto_redirect" ||
                    prev_questions_array[i].type == "show_file" ||
                    prev_questions_array[i].type == "show_contacts" ||
                    prev_questions_array[i].type == "show_location" ||
                    prev_questions_array[i].type == "custom_answer"
                  ) {
                    prev_questions_array.splice(i, 1);
                    i--;
                  }
                }
                if (zapier_webhook && zapier_webhook.length > 0) {
                  var output = {};
                  output.timestamp = new Date();
                  for (var i = 0; i < prev_questions_array.length; i++) {
                    var str = prev_questions_array[i].question_text;
                    output[str] = prev_questions_array[i].answer_text;
                  }
                  var xhttpNew = new XMLHttpRequest();
                  xhttpNew.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                    }
                  };
                  xhttpNew.open("POST", zapier_webhook, !0);
                  xhttpNew.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  xhttpNew.send("output=" + JSON.stringify(output));
                }
                for (var i = 0; i < prev_questions_array.length; i++) {
                  questionArray.push({
                    question: prev_questions_array[i].question_text,
                    answer: prev_questions_array[i].answer_text,
                  });
                }
              }
            }
          };
          xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat", !0);
          xhttp.setRequestHeader(
            "Content-type",
            "application/x-www-form-urlencoded"
          );

          let userInfo = {}
          userInfo.type = 'Chatbot';
          userInfo.location = '';
          userInfo.ipv4 = '';   
          userInfo.country_code = '';
          userInfo.device_print = '';

          if (device_print && device_print.length > 0) {
              userInfo.device_print = device_print; 
          }
          if (ip_address && ip_address.length > 0) {
            userInfo.ipv4 = ip_address;   
          }

          if (user_country_code && user_country_code.length > 0) {
              userInfo.country_code = user_country_code;
          }

          if (user_location_enc && user_location_enc.length > 0) {
            userInfo.location = user_location_enc;
          } else {
            if (user_location_array && user_location_array.length > 0) {
              userInfo.location = user_location_array.join();
            }
          }

          if (totalData[0].custom_settings && totalData[0].custom_settings.length > 0 ){

            var parsedjson = JSON.parse(totalData[0].custom_settings)

            if (parsedjson.facebook_pixel == '1') {
              trackUserSubmissionFacebook(userInfo); // FBPixel
            }

            if (parsedjson.google_analytic == '1') {
              trackUserSubmission(userInfo) // (gtag)
            }

          }


          if (
            main_lang_code &&
            main_lang_code.length > 0 &&
            main_lang_code != language_code
          ) {
          } else {
            main_lang_code = "default";
          }
          var bot_widget_obj;
          var is_sendable;
          try {
            checkSaveMAxUserLogin();
            checkRateGainDetails();
          } catch (error) { }
          if (window.botWidget && window.botWidget.user) {
            var keys = Object.keys(window.botWidget.user);
            for (var t = 0; t < keys.length; t++) {
              if (
                window.botWidget.user[keys[t]] &&
                window.botWidget.user[keys[t]].length > 0
              ) {
                is_sendable = true;
              }
            }
            if (is_sendable) {
              bot_widget_obj = window.botWidget.user;
            } else {
              bot_widget_obj = "";
            }
            if (window.botWidget.user.bot_id) {
              delete window.botWidget.user.bot_id;
            }
            if (window.botWidget.user.url) {
              delete window.botWidget.user.url;
            }
          }
          xhttp.send(
            "action=init_chat&device_print=" +
            device_print +
            "&chatbot_id=" +
            chatbot_id +
            "&language_code=" +
            main_lang_code +
            "&bot_widget_obj=" +
            JSON.stringify(bot_widget_obj)
          );
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
            }
          };
          xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=send_alert", !0);
          xhttp.setRequestHeader(
            "Content-type",
            "application/x-www-form-urlencoded"
          );
          var date = new Date();
          try {
            if (typeof gtag_report_conversion != "undefined") {
              if (is_adwords_enabled) {
                gtag_report_conversion();
              }
            }
          } catch (e) {
          } finally {
          }
          var user_location_string;
          if (user_location_enc && user_location_enc.length > 0) {
            user_location_string = user_location_enc;
          } else {
            if (user_location_array && user_location_array.length > 0) {
              user_location_string = user_location_array.join();
            }
          }
          if (src && src.length > 0) {
          } else {
            src = encodeURIComponent(window.location.href);
          }
          var bot_widget_obj;
          var is_sendable;
          try {
            checkSaveMAxUserLogin();
            checkRateGainDetails();
          } catch (error) { }
          if (window.botWidget && window.botWidget.user) {
            var keys = Object.keys(window.botWidget.user);
            for (var t = 0; t < keys.length; t++) {
              if (
                window.botWidget.user[keys[t]] &&
                window.botWidget.user[keys[t]].length > 0
              ) {
                is_sendable = true;
              }
            }
            if (is_sendable) {
              bot_widget_obj = window.botWidget.user;
            } else {
              bot_widget_obj = "";
            }
            if (window.botWidget.user.bot_id) {
              delete window.botWidget.user.bot_id;
            }
            if (window.botWidget.user.url) {
              delete window.botWidget.user.url;
            }
          }
          if (src && src.length > 0) {
            xhttp.send(
              "action=send_alert&cb_session=" +
              cb_session +
              "&chatbot_id=" +
              chatbot_id +
              "&url=" +
              encodeURIComponent(window.location.href) +
              "&sheet_id=" +
              sheet_id +
              "&client_ip_address=" +
              ip_address +
              "&name=" +
              encodeURIComponent(totalData[0].name) +
              "&user_location=" +
              user_location_string +
              "&source=" +
              src +
              "&last_question_answered=0" +
              "&timestamp=" +
              date +
              "&hours=" +
              hours +
              "&bot_widget_obj=" +
              JSON.stringify(bot_widget_obj)
            );
          } else {
            xhttp.send(
              "action=send_alert&cb_session=" +
              cb_session +
              "&chatbot_id=" +
              chatbot_id +
              "&url=" +
              encodeURIComponent(window.location.href) +
              "&sheet_id=" +
              sheet_id +
              "&client_ip_address=" +
              ip_address +
              "&name=" +
              encodeURIComponent(totalData[0].name) +
              "&user_location=" +
              user_location_string +
              "&last_question_answered=0" +
              "&timestamp=" +
              date +
              "&hours=" +
              hours +
              "&bot_widget_obj=" +
              JSON.stringify(bot_widget_obj)
            );
          }
        }

        function convertStandardTime(time) {
          var hours = Number(time.match(/^(\d+)/)[1]);
          var minutes = Number(time.match(/:(\d+)/)[1]);
          var AMPM = time.match(/\s(.*)$/)[1];
          if (AMPM == "PM" && hours < 12) hours = hours + 12;
          if (AMPM == "AM" && hours == 12) hours = hours - 12;
          var sHours = hours.toString();
          var sMinutes = minutes.toString();
          if (hours < 10) sHours = "0" + sHours;
          if (minutes < 10) sMinutes = "0" + sMinutes;
          return sHours + ":" + sMinutes;
        }

        function showDatePicker(def, id, question_id) {
          if (def == 'Yes;;Yes') {
            def =
              '{"date_range":[["a","b"]],"period":[0,0],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == 'Yes;;No') {
            def =
              '{"date_range":[["a","b"]],"period":[0,"b"],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == 'No;;Yes') {
            def =
              '{"date_range":[["a","b"]],"period":["a",0],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == 'No;;No') {
            def =
              '{"date_range":[["a","b"]],"period":["a","b"],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == '') {
            def =
              '{"date_range":[["a","b"]],"period":["a","b"],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          }
          var json = JSON.parse(def);
          var blocked_week_days = [];
          var total_week_days = [1, 2, 3, 4, 5, 6, 7];
          if (json.weekdays && json.weekdays.length > 0) {
            json.weekdays = json.weekdays.sort();
          }
          var blocked_week_days = difference(total_week_days, json.weekdays);
          var blocked_week_days = difference(total_week_days, json.weekdays);
          var date_range = json.date_range[0];
          var min_date = date_range[0];
          var max_date = date_range[1];
          var current_date = new Date();
          var show_def_date;
          if (date_range[0] == 'a') {
            min_date = !1;
          } else {
            show_def_date = true;
            var date = new Date(min_date);
            min_date = new Date(
              date.getFullYear(),
              date.getMonth(),
              date.getDate()
            );
          }
          if (date_range[1] == 'b') {
            max_date = !1;
          } else {
            var date = new Date(max_date);
            max_date = new Date(
              date.getFullYear(),
              date.getMonth(),
              date.getDate()
            );
          }
          var period = json.period;
          var past_days = period[0];
          var future_days = period[1];
          if (past_days != 'a' && past_days != null) {
            var past_date = new Date();
            past_date.setDate(past_date.getDate() - parseInt(past_days));
            min_date = new Date(
              past_date.getFullYear(),
              past_date.getMonth(),
              past_date.getDate()
            );
          }
          if (future_days != 'b' && future_days != null) {
            var future_date = new Date();
            future_date.setDate(future_date.getDate() + parseInt(future_days));
            max_date = new Date(
              future_date.getFullYear(),
              future_date.getMonth(),
              future_date.getDate()
            );
          }
          var next_days;
          if (json.next_days && json.next_days.toString().length > 0) {
            next_days = json.next_days;
          }
          if (next_days && next_days.toString().length > 0) {
            var result = new Date(min_date);
            result.setDate(result.getDate() + next_days);
            min_date = new Date(
              result.getFullYear(),
              result.getMonth(),
              result.getDate()
            );
          }
          var from_timing = json.from_timing;
          var to_timing = json.to_timing;
          var timezone = json.timezone;
          var atleast_one_date_avaialable;
          var military_time;
          if (json.military_time && json.military_time == '1') {
            military_time = !0;
          } else {
            military_time = !1;
          }
          var no_slots_message;
          if (json.no_slots_message && json.no_slots_message.length > 0) {
            no_slots_message = json.no_slots_message;
          } else {
            no_slots_message = 'No Slots are available for the selected day';
          }
          var already_booked_message;
          if (
            json.already_booked_message &&
            json.already_booked_message.length > 0
          ) {
            already_booked_message = json.already_booked_message;
          } else {
            already_booked_message = 'Selected slot is not available';
          }
          var interval = json.interval;
          var bookings_per_slot;
          if (
            json.bookings_per_slot &&
            json.bookings_per_slot.toString().length > 0
          ) {
            bookings_per_slot = json.bookings_per_slot;
          } else {
            bookings_per_slot = 1;
          }
          var date_selected;
          var actualDate;
          var storingDate;
          var default_date;
          if (show_def_date) {
            default_date = min_date;
          } else {
            default_date = new Date();
          }

          const Dateinterval = setInterval(() => {
            const element = document.getElementById(
              'smatbot_date_picker_container'
            );
            if (element) {
              setTimeout(function () {
                picker = new Pikaday({
                  field: document.getElementById('smatest_datepicker'),
                  firstDay: 1,
                  minDate: min_date,
                  maxDate: max_date,
                  defaultDate: default_date,
                  bound: !1,
                  yearRange: 100,
                  // container: document.getElementById("smatest_date_container"),
                  container: document.getElementById(
                    'smatbot_date_picker_container'
                  ),
                  theme: 'triangle-theme triangle-theme-new-styles_sb',
                  onSelect: function () {
                    date_selected = true;
                    var date = new Date(this.toString()).getDate();
                    var month = new Date(this.toString()).getMonth();
                    var year = new Date(this.toString()).getFullYear();
                    var all_months = [
                      'Jan',
                      'Feb',
                      'Mar',
                      'Apr',
                      'May',
                      'Jun',
                      'Jul',
                      'Aug',
                      'Sep',
                      'Oct',
                      'Nov',
                      'Dec',
                    ];
                    var month_name = all_months[month];
                    month = parseInt(month) + 1;
                    if (date > 0 && date < 10) {
                      date = '0' + date;
                    }
                    if (month > 0 && month < 10) {
                      month = '0' + month;
                    }
                    actualDate = year + '-' + month + '-' + date;
                    storingDate = date + ' ' + month_name + ' ' + year;

                    if (header.contains(company_title_description)) {
                      body.style.height = 'calc(100% - 226px)';
                    } else {
                      body.style.height = 'calc(100% - 150px)';
                    }
                    input.style.display = 'block';
                    enter.style.display = 'flex';
                    footer.style.borderTop = '0';
                    footer.style.padding = '6px 15px';
                    footer.style.height = '49px';

                    let actualformatDate = convertDateFormat(
                      new Date(actualDate),
                      date_output_format
                    );

                    document.getElementById('smatest_datepicker').value =
                      actualformatDate;
                    input.setAttribute('value', actualformatDate);

                    const selectedButtons = document.querySelectorAll(
                      '.is-selected .pika-button'
                    );
                    if (selectedButtons.length > 0) {
                      selectedButtons.forEach((button) => {
                        button.style.cssText += `background-color: ${themes_array[4]} !important;`;
                      });
                    }
                  },
                  onDraw: function () {
                    const monthYearSelector =
                      document.querySelector('.pika-select');
                    if (monthYearSelector) {
                      const monthDropdown =
                        document.querySelector('.pika-select-month');
                      const yearDropdown =
                        document.querySelector('.pika-select-year');
                      if (
                        (monthDropdown && monthDropdown.value) ||
                        (yearDropdown && yearDropdown.value)
                      ) {
                        document.getElementById('smatest_datepicker').value =
                          '';
                        input.setAttribute('value', '');
                      }
                    }
                  },
                  disableDayFn: function (theDate) {
                    var date = new Date(theDate);
                    var k;
                    for (var i = 0; i < blocked_week_days.length; i++) {
                      if (blocked_week_days[i] == 7) {
                        blocked_week_days[i] = 0;
                      }
                      if (date.getDay() == blocked_week_days[i]) {
                        k = !0;
                      }
                    }
                    if (k) {
                      return !0;
                    } else {
                      atleast_one_date_avaialable = !0;
                    }
                  },
                });
                if (header.contains(company_title_description)) {
                  body.style.height = 'calc(100% - 226px)';
                } else {
                  body.style.height = 'calc(100% - 150px)';
                }
                footer.style.borderTop = '0';
                footer.style.padding = '0';
                input.style.pointerEvents = 'none';
                microphone.style.pointerEvents = 'none';
                microphone.style.opacity = 0;
                input.blur();
                var pik_lander =
                  document.getElementsByClassName('pika-lendar')[0];
                if (font && font.length > 0) {
                  pik_lander.classList.add(font);
                }
                if (body) {
                  body.scrollTop = body.scrollHeight;
                }

                const intervalId = setInterval(() => {
                  const selectedButtons = document.querySelectorAll(
                    '.is-selected .pika-button'
                  );
                  if (selectedButtons.length > 0) {
                    selectedButtons.forEach((button) => {
                      button.style.cssText += `background-color: ${themes_array[4]} !important;`;
                    });
                    clearInterval(intervalId);
                  }
                }, 500);
              }, 300);
              clearInterval(Dateinterval);
            }
          }, 100);
        }

        function showAppointmentBooking(def, id, question_id) {
          if (def == 'Yes;;Yes') {
            def =
              '{"date_range":[["a","b"]],"period":[0,0],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == 'Yes;;No') {
            def =
              '{"date_range":[["a","b"]],"period":[0,"b"],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == 'No;;Yes') {
            def =
              '{"date_range":[["a","b"]],"period":["a",0],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == 'No;;No') {
            def =
              '{"date_range":[["a","b"]],"period":["a","b"],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          } else if (def == '') {
            def =
              '{"date_range":[["a","b"]],"period":["a","b"],"weekdays":[1,2,3,4,5,6,7],"blocked_days":[],"from_timing":"09:00 AM","to_timing":"05:00 PM"}';
          }
          var json = JSON.parse(def);
          var blocked_week_days = [];
          var total_week_days = [1, 2, 3, 4, 5, 6, 7];
          if (json.weekdays && json.weekdays.length > 0) {
            json.weekdays = json.weekdays.sort();
          }
          var blocked_week_days = difference(total_week_days, json.weekdays);
          var blocked_week_days = difference(total_week_days, json.weekdays);
          var date_range = json.date_range[0];
          var min_date = date_range[0];
          var max_date = date_range[1];
          var current_date = new Date();
          var show_def_date;
          if (date_range[0] == 'a') {
            min_date = !1;
          } else {
            show_def_date = true;
            var date = new Date(min_date);
            min_date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
          }
          if (date_range[1] == 'b') {
            max_date = !1;
          } else {
            var date = new Date(max_date);
            max_date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
          }
          var period = json.period;
          var past_days = period[0];
          var future_days = period[1];
          if (past_days != 'a' && past_days != null) {
            var past_date = new Date();
            past_date.setDate(past_date.getDate() - parseInt(past_days));
            min_date = new Date(
              past_date.getFullYear(),
              past_date.getMonth(),
              past_date.getDate()
            );
          }
          if (future_days != 'b' && future_days != null) {
            var future_date = new Date();
            future_date.setDate(future_date.getDate() + parseInt(future_days));
            max_date = new Date(
              future_date.getFullYear(),
              future_date.getMonth(),
              future_date.getDate()
            );
          }
          var next_days;
          if (json.next_days && json.next_days.toString().length > 0) {
            next_days = json.next_days;
          }
          if (next_days && next_days.toString().length > 0) {
            var result = new Date(min_date);
            result.setDate(result.getDate() + next_days);
            min_date = new Date(
              result.getFullYear(),
              result.getMonth(),
              result.getDate()
            );
          }
          var from_timing = json.from_timing;
          var to_timing = json.to_timing;
          var timezone = json.timezone;
          var atleast_one_date_avaialable;
          var military_time;
          if (json.military_time && json.military_time == '1') {
            military_time = !0;
          } else {
            military_time = !1;
          }
          var no_slots_message;
          if (json.no_slots_message && json.no_slots_message.length > 0) {
            no_slots_message = json.no_slots_message;
          } else {
            no_slots_message = 'No Slots are available for the selected day';
          }
          var already_booked_message;
          if (json.already_booked_message && json.already_booked_message.length > 0) {
            already_booked_message = json.already_booked_message;
          } else {
            already_booked_message = 'Selected slot is not available';
          }
          var interval = json.interval;
          var bookings_per_slot;
          if (json.bookings_per_slot && json.bookings_per_slot.toString().length > 0) {
            bookings_per_slot = json.bookings_per_slot;
          } else {
            bookings_per_slot = 1;
          }
          var date_selected;
          var actualDate;
          var storingDate;
          var default_date;
          if (show_def_date) {
            default_date = min_date;
          } else {
            default_date = new Date();
          }
        
          var main_opened_div = document.getElementById('opened');
        
          if (
            main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
          ) {
            main_opened_div.removeChild(
              document.getElementById('bg-shadow-overlay')
            );
          }
    
          var openMenuSb = document.getElementById('open-menu-sb');
          var optionsDiv = document.getElementsByClassName('options-div-smatest');
    
          if (openMenuSb && optionsDiv.length > 0) {
            if (
              optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
            ) {
              optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
            }
          }
        
          var appoint_new_div = document.createElement('DIV');
          appoint_new_div.setAttribute('id', 'bg-shadow-overlay');
        
          var bg_overlay = document.createElement('DIV');
          bg_overlay.setAttribute('id', 'appointment-container');
    
          if (json.openMenu && json.openMenu.length > 0) {
            if (json.openMenu == 'open') {
              appoint_new_div.style.visibility = 'visible';
              bg_overlay.style.opacity = '1';
              bg_overlay.style.transform = 'translateY(0)';
            }else{
              appoint_new_div.style.visibility = 'hidden';
            }
          }else{
            appoint_new_div.style.visibility = 'hidden';
          }


    
          var inner_div_scrool = document.createElement('DIV');
          inner_div_scrool.setAttribute('class', 'inner_div_scrool-app');
          inner_div_scrool.setAttribute('id', 'inner_div_scrool-app');
    
          main_opened_div.appendChild(appoint_new_div);
          appoint_new_div.appendChild(bg_overlay);
          bg_overlay.appendChild(inner_div_scrool)
          createBrandWrapper(bg_overlay, 'SmatBot', main_url, font);
          
          var booking_type = '1'
    
          if (json.interface && json.interface.length > 0) {
            if (json.interface == 'modern') {
              booking_type = "2"
            }else{
              booking_type = "1"
            }
          }
        
          setTimeout(function () {
            input.blur()
            if (booking_type == '1') {
    
              try {
                if (picker) {
                  picker.destroy();   
                }
              } catch (e) {
              } finally {
              }
              
              picker = new Pikaday({
                field: document.getElementById('smatest_datepicker'),
                firstDay: 1,
                minDate: min_date,
                maxDate: max_date,
                defaultDate: default_date,
                bound: !1,
                yearRange: 100,
                container: document.getElementById('inner_div_scrool-app'),
                theme: 'dark-theme',
                onSelect: function () {
                  date_selected = true;
                  var date = new Date(this.toString()).getDate();
                  var month = new Date(this.toString()).getMonth();
                  var year = new Date(this.toString()).getFullYear();
                  var all_months = [
                    'Jan',
                    'Feb',
                    'Mar',
                    'Apr',
                    'May',
                    'Jun',
                    'Jul',
                    'Aug',
                    'Sep',
                    'Oct',
                    'Nov',
                    'Dec',
                  ];
                  var month_name = all_months[month];
                  month = parseInt(month) + 1;
                  if (date > 0 && date < 10) {
                    date = '0' + date;
                  }
                  if (month > 0 && month < 10) {
                    month = '0' + month;
                  }
                  actualDate = year + '-' + month + '-' + date;
                  storingDate = date + ' ' + month_name + ' ' + year;
                
                    const selectedButtons = document.querySelectorAll('.is-selected .pika-button');
                    if (selectedButtons.length > 0) {
                        selectedButtons.forEach(button => {
                            button.style.cssText += `background-color: ${themes_array[4]} !important;`;
                        });
                    }
               

                  callSlotes()
                },
                disableDayFn: function (theDate) {
                  var date = new Date(theDate);
                  var k;
                  for (var i = 0; i < blocked_week_days.length; i++) {
                    if (blocked_week_days[i] == 7) {
                      blocked_week_days[i] = 0;
                    }
                    if (date.getDay() == blocked_week_days[i]) {
                      k = !0;
                    }
                  }
                  if (k) {
                    return !0;
                  } else {
                    atleast_one_date_avaialable = !0;
                  }
                },
              });
              
            } else{
    
              // Setup elements and styling
              var datepicker = document.createElement('DIV')
              datepicker.style.display = 'flex';
              datepicker.style.alignItems = 'center';
              datepicker.style.justifyContent = 'center';
              datepicker.style.gap = '12px';
              datepicker.style.width = '80%';
              datepicker.style.marginTop = '8px';
    
              var scrollContainer = document.createElement('DIV')
              scrollContainer.style.display = 'flex';
              scrollContainer.style.alignItems = 'center';
              scrollContainer.style.justifyContent = 'center';
              scrollContainer.style.marginTop = '8px';
              scrollContainer.style.marginBottom = '12px';
              scrollContainer.style.gap = '8px';
    
              if (font && font.length > 0) {
                  datepicker.classList.add(font);
              }
    
              inner_div_scrool.appendChild(datepicker);
              inner_div_scrool.appendChild(scrollContainer);
    
              const prevMonthBtn = document.createElement('IMG'); 
              prevMonthBtn.id = 'prevMonth';
              prevMonthBtn.alt = 'prevMonth';
              prevMonthBtn.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg';
              prevMonthBtn.style.width = '12px';
              prevMonthBtn.style.height = '12px';
              prevMonthBtn.style.cursor = 'pointer';
              datepicker.appendChild(prevMonthBtn);
    
              const monthYearDisplay = document.createElement('div');
              monthYearDisplay.style.fontSize = '13px'
              monthYearDisplay.style.color = '#1D2D35'
              monthYearDisplay.style.fontWeight = '600'
              monthYearDisplay.style.flex = '1'
              monthYearDisplay.style.textAlign = 'center'
              datepicker.appendChild(monthYearDisplay);
    
              const nextMonthBtn = document.createElement('IMG');
              nextMonthBtn.id = 'nextMonth';
              nextMonthBtn.alt = 'nextMonth';
              nextMonthBtn.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg';
              nextMonthBtn.style.width = '12px';
              nextMonthBtn.style.height = '12px';
              nextMonthBtn.style.transform = 'rotate(180deg)';
              nextMonthBtn.style.cursor = 'pointer';
              datepicker.appendChild(nextMonthBtn);
    
              const prevScrollBtn = document.createElement('IMG');
              prevScrollBtn.id = 'prevScroll';
              prevScrollBtn.alt = 'prevScroll';
              prevScrollBtn.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg';
              prevScrollBtn.style.width = '12px';
              prevScrollBtn.style.height = '12px';
              prevScrollBtn.style.background = '#ECF4FF';
              prevScrollBtn.style.borderRadius = '50%';
              prevScrollBtn.style.padding = '8px';
              prevScrollBtn.style.cursor = 'pointer';
              prevScrollBtn.style.opacity = '0.5';
              prevScrollBtn.style.pointerEvents = 'none'; // Disabled initially
              scrollContainer.appendChild(prevScrollBtn);
    
              const datesContainer = document.createElement('div');
              datesContainer.id = 'datesContainer_scroolBar_sb';
              datesContainer.style.overflowX = 'auto';
              datesContainer.style.display = 'flex';
              datesContainer.style.gap = '10px';
              scrollContainer.appendChild(datesContainer);
    
              const dates = document.createElement('div');
              dates.style.display = 'flex';
              dates.style.gap = '6px';
              dates.style.width = '100%';
              if (font && font.length > 0) {
                  dates.classList.add(font);
              }
              datesContainer.appendChild(dates);
    
              const nextScrollBtn = document.createElement('IMG');
              nextScrollBtn.id = 'nextScroll';
              nextScrollBtn.alt = 'nextScroll';
              nextScrollBtn.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg';
              nextScrollBtn.style.width = '12px';
              nextScrollBtn.style.height = '12px';
              nextScrollBtn.style.transform = 'rotate(180deg)';
              nextScrollBtn.style.background = '#ECF4FF';
              nextScrollBtn.style.borderRadius = '50%';
              nextScrollBtn.style.padding = '8px';
              nextScrollBtn.style.cursor = 'pointer';
              scrollContainer.appendChild(nextScrollBtn);
    
              let currentMonth = new Date().getMonth();
              let currentYear = new Date().getFullYear();
    
              const minDate = min_date; 
              const maxDate = max_date; 
              const blockDays = blocked_week_days.map(day => day == 7 ? 0 : day); 
    
              function renderDates() {
                  dates.innerHTML = '';
                  monthYearDisplay.textContent = `${new Date(currentYear, currentMonth).toLocaleString('default', { month: 'long' })} ${currentYear}`;
    
                  const startDate = new Date(currentYear, currentMonth, 1);
                  const endDate = new Date(currentYear, currentMonth + 1, 0);
                  const today = new Date().getDate();
    
                  for (let i = startDate.getDate(); i <= endDate.getDate(); i++) {
                      const currentDate = new Date(currentYear, currentMonth, i);
    
                      if (currentDate < minDate || currentDate > maxDate) {
                          continue;
                      }
    
                      const dateElement = document.createElement('div');
                      dateElement.classList.add('date_list_sb');
                      // dateElement.dataset.date = currentDate.toISOString().split('T')[0];
                      const isoDate = currentDate.toLocaleDateString('en-CA'); // 'en-CA' for YYYY-MM-DD format
                      dateElement.dataset.date = isoDate;
                      
                      const monthElement = document.createElement('div');
                      monthElement.style.fontSize = '12px';
                      monthElement.style.color = '#1D2D35';
                      monthElement.style.fontWeight = '500';
                      monthElement.textContent = currentDate.toLocaleString('default', { month: 'short' }); // Use currentDate
    
                      const dayElement = document.createElement('div');
                      dayElement.style.fontWeight = '600';
                      dayElement.style.color = '#1D2D35';
                      dayElement.style.fontSize = '14px';
                      dayElement.textContent = i;
    
                      // console.log(`Date Element: ${dateElement.dataset.date}, Displayed Day: ${i}, currentDate: ${currentDate.toISOString()}`);
    
                      dateElement.appendChild(monthElement);
                      dateElement.appendChild(dayElement);
    
                      if (blockDays.includes(currentDate.getDay())) {
                          dateElement.style.background = '#d3d3d3';
                          dayElement.style.color = '#fff';
                          monthElement.style.color = '#fff';
                          dateElement.style.pointerEvents = 'none';
                      } else {
                          dateElement.addEventListener('click', function () {
                            date_selected = true;
                              document.querySelectorAll('.date_list_sb').forEach(date => date.classList.remove('confirm-btn-smatest'));
                              this.classList.add('confirm-btn-smatest');
    
                              var dateString = this.getAttribute('data-date');
                              var date = new Date(dateString);
                              var selectedDate = date.getDate();
                              var month = date.getMonth();
                              var year = date.getFullYear();
    
                              var all_months = [
                                  'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                                  'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
                              ];
                              var month_name = all_months[month];
                              month = parseInt(month) + 1;
    
                              if (selectedDate > 0 && selectedDate < 10) {
                                  selectedDate = '0' + selectedDate;
                              }
                              if (month > 0 && month < 10) {
                                  month = '0' + month;
                              }
    
                              actualDate = year + '-' + month + '-' + selectedDate;
                               storingDate = selectedDate + ' ' + month_name + ' ' + year;
                              
                              // console.log('Selected Date:', actualDate);
                              // console.log('Formatted Date:', storingDate);
                              callSlotes()
                            });
                      }
    
                      // if (i === today && currentMonth === new Date().getMonth() && currentYear === new Date().getFullYear()) {
                      //     dateElement.classList.add('selected_date_sb');
                      // }
                      
                      dates.appendChild(dateElement);
                  }
    
                  handleScrollButtons();
              }
              
              nextMonthBtn.addEventListener('click', () => {
                  if (currentMonth === 11) {
                    currentMonth = 0;
                      currentYear++;
                    } else {
                      currentMonth++;
                    }
                    
                  handleMonthButtons();
                  renderDates();
              });
    
              prevMonthBtn.addEventListener('click', () => {
                  if (currentMonth === 0) {
                      currentMonth = 11;
                      currentYear--;
                  } else {
                      currentMonth--;
                  }
                  
                  handleMonthButtons();
                  renderDates();
              });
    
              function handleMonthButtons() {
                if (minDate) {
                  if (currentYear === minDate.getFullYear() && currentMonth === minDate.getMonth()) {
                      prevMonthBtn.style.pointerEvents = 'none';
                      prevMonthBtn.style.opacity = '0.5';
                  } else {
                      prevMonthBtn.style.pointerEvents = 'auto';
                      prevMonthBtn.style.opacity = '1';
                  }
                }
    
                  if (currentYear === maxDate.getFullYear() && currentMonth === maxDate.getMonth()) {
                      nextMonthBtn.style.pointerEvents = 'none';
                      nextMonthBtn.style.opacity = '0.5';
                  } else {
                      nextMonthBtn.style.pointerEvents = 'auto';
                      nextMonthBtn.style.opacity = '1';
                  }
              }
    
              function handleScrollButtons() {
                  prevScrollBtn.style.pointerEvents = datesContainer.scrollLeft > 0 ? 'auto' : 'none';
                  prevScrollBtn.style.opacity = datesContainer.scrollLeft > 0 ? '1' : '0.5';
    
                  nextScrollBtn.style.pointerEvents = datesContainer.scrollWidth > datesContainer.scrollLeft + datesContainer.clientWidth ? 'auto' : 'none';
                  nextScrollBtn.style.opacity = datesContainer.scrollWidth > datesContainer.scrollLeft + datesContainer.clientWidth ? '1' : '0.5';
              }
    
              datesContainer.addEventListener('scroll', handleScrollButtons);
    
              prevScrollBtn.addEventListener('click', () => {
                  datesContainer.scrollBy({ left: -250, behavior: 'smooth' });
              });
    
              nextScrollBtn.addEventListener('click', () => {
                  datesContainer.scrollBy({ left: 250, behavior: 'smooth' });
              });
    
              renderDates(); 
              handleMonthButtons();
         
            }
            function callSlotes() {
              if (id && id == 1) {
                var picker = this;
                if (inner_div_scrool.contains(document.getElementById('slot-scroll'))) {
                  inner_div_scrool.removeChild(document.getElementById('slot-scroll'));
                }
                if (bg_overlay) {
                  var submitButtons = bg_overlay.querySelectorAll('#appointment-submit_btn');
                  submitButtons?.forEach(function(submitButton) {
                    if (bg_overlay.contains(submitButton)) {
                      bg_overlay.removeChild(submitButton);
                    }
                  });
                }
                if (
                  inner_div_scrool.contains(document.getElementById('slot_details_div'))
                ) {
                  inner_div_scrool.removeChild(
                    document.getElementById('slot_details_div')
                  );
                }
                var slots_div = document.createElement('DIV');
                slots_div.classList.add('slot-scrollbar-new');
                slots_div.id = 'slot-scroll';
    
                // input.style.display = 'none';
                enter.style.display = 'none';
                footer.style.borderTop = '0';
                footer.style.padding = '0';
    
                var slot_details_div = document.createElement('DIV');
                slot_details_div.setAttribute('id', 'slot_details_div');
    
                inner_div_scrool.appendChild(slot_details_div);
                inner_div_scrool.appendChild(slots_div);
                var img = document.createElement('IMG');
                img.style.margin = 'auto';
                img.id = 'calendar-loading';
                img.src =
                  // "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/animate_calendar.gif";
                  'https://cdn.pixabay.com/animation/2023/05/12/07/29/07-29-43-548_256.gif';
                img.classList.add('calendar-loading');
                var loader_div = document.createElement('DIV');
                loader_div.style.margin = 'auto';
                loader_div.style.display = 'flex';
                loader_div.style.alignItems = 'center';
                loader_div.style.justifyContent = 'center';
    
                loader_div.innerHTML = `<div class="loader-sb">
                                        <span class="hour"></span>
                                        <span class="min"></span>
                                        <span class="circel"></span>
                                      </div>`;
    
                slots_div.appendChild(loader_div);
                // slots_div.appendChild(img);
                var converted_start_time = convertStandardTime(from_timing);
                var converted_end_time = convertStandardTime(to_timing);
                if (document.getElementById('timezone_select')) {
                  timezone = document.getElementById('timezone_select').value;
                }
                var start_time = actualDate + 'T00:00:00' + timezone;
                var end_time = actualDate + 'T23:59:59' + timezone;
                var current_time;
                var date = new Date().getDate();
                var month = new Date().getMonth();
                var year = new Date().getFullYear();
                month = parseInt(month) + 1;
                if (date > 0 && date < 10) {
                  date = '0' + date;
                }
                if (month > 0 && month < 10) {
                  month = '0' + month;
                }
                var currentDate = year + '-' + month + '-' + date;
                var hours = new Date().getHours();
                var minutes = new Date().getMinutes();
                if (hours > 0 && hours < 10) {
                  hours = '0' + hours;
                }
                if (minutes > 0 && minutes < 10) {
                  minutes = '0' + minutes;
                }
                var current_time =
                  currentDate + 'T' + hours + ':' + minutes + ':00' + timezone;
                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                  if (this.readyState == 4 && this.status == 200) {
                    if (
                      slots_div.contains(document.getElementById('calendar-loading'))
                    ) {
                      slots_div.removeChild(
                        document.getElementById('calendar-loading')
                      );
                    }

                    if (bg_overlay) {
                      var submitButtons = bg_overlay.querySelectorAll('#appointment-submit_btn');
                      submitButtons?.forEach(function(submitButton) {
                        if (bg_overlay.contains(submitButton)) {
                          bg_overlay.removeChild(submitButton);
                        }
                      });
                    }

                    slots_div.innerHTML = '';
    
                    var slot_details = document.createElement('DIV');
                    slot_details.setAttribute('id', 'slot_details_headding');
                    if (font && font.length > 0) {
                      slot_details.classList.add(font);
                    }
                    var selectted_time;
                    slot_details.innerText = storingDate + ' ' + '|' + ' ' + timezone;
    
                    var inner_slots_div = document.createElement('DIV');
                    inner_slots_div.classList.add('pull-left');
                    inner_slots_div.classList.add('full-width');
                    inner_slots_div.classList.add('text-center');
                    inner_slots_div.id = 'inner-slots-div';
                    slots_div.appendChild(inner_slots_div);
    
                    var submit_btn = document.createElement('BUTTON');
                    submit_btn.classList.add('confirm-btn-smatest');
                    submit_btn.innerHTML = generateTranslatedContent(translations, "Looks good. Schedule it!", main_lang_code, language_code, input);
                    if (font && font.length > 0) {
                      submit_btn.classList.add(font);
                    }
                    submit_btn.setAttribute('id', 'appointment-submit_btn');
    
                    var submit_icon = document.createElement('IMG');
                    submit_icon.src =
                      'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                    submit_icon.alt = 'SubmitIcon';
                    submit_icon.style.width = '18px';
                    submit_icon.style.height = '18px';
    
                    submit_btn.appendChild(submit_icon);
    
                    var response = JSON.parse(this.responseText);
                    if (response.data && response.data.length > 0) {
                      slot_details_div.appendChild(slot_details);
                      bg_overlay.appendChild(submit_btn);
    
                      for (var i = 0; i < response.data.length; i++) {
                        var label = document.createElement('label');
                        label.classList.add('slot-label');
                        label.style.cssText = label.style.cssText + "border-radius: 27px !important";
                        label.style.color = '#313131';
                        label.style.border = '1px solid #E1E7FE';
                        label.style.opacity = '1';
                        label.style.fontWeight = '600';
                        label.style.fontSize = '10px';
                        label.style.cssText = label.style.cssText + "text-align: center !important";
    
                        label.id = convertStandardTime(response.data[i]);
                        if (military_time) {
                          label.innerHTML = convertStandardTime(response.data[i]);
                        } else {
                          label.innerHTML = response.data[i];
                        }
                        if (font && font.length > 0) {
                          label.classList.add(font);
                        }
    
                        //  click event start
    
                        label.addEventListener('click', function (k) {
                          var labels = document.querySelectorAll('.slot-label');
                          labels.forEach(function (lbl) {
                            // lbl.classList.remove('selected-time');
                            lbl.classList.remove('confirm-btn-smatest');
                          });
    
                          // this.classList.add('selected-time');
                          this.classList.add('confirm-btn-smatest');
                          slot_details.innerText =
                            storingDate +
                            '  , ' +
                            this.innerText +
                            ' | ' +
                            ' ' +
                            timezone;
                          selectted_time = this;
                        });
    
                        inner_slots_div.appendChild(label);
                      }
    
                      submit_btn.addEventListener('click', function (k) {
                        if (selectted_time && selectted_time.id.length > 0) {
                          slots_div.removeChild(inner_slots_div);
                          var img = document.createElement('IMG');
                          img.id = 'calendar-loading';
                          img.src =
                            'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/animate_calendar.gif';
                          // 'https://cdn.pixabay.com/animation/2023/05/12/07/29/07-29-43-548_256.gif';
                          img.classList.add('calendar-loading');
                          slots_div.appendChild(img);
                          var this_label = selectted_time;
                          var xhttp = new XMLHttpRequest();
                          xhttp.onreadystatechange = function () {
                            if (this.readyState == 4 && this.status == 200) {
                              var response = JSON.parse(this.responseText);
                              if (response.status) {
                                if (
                                  inner_div_scrool.contains(
                                    document.getElementById('slot-scroll')
                                  )
                                ) {
                                  inner_div_scrool.removeChild(
                                    document.getElementById('slot-scroll')
                                  );
                                }
                                input.setAttribute('type', 'text');
                                var k;
                                for (var i = 0; i < available_timezones.length; i++) {
                                  if (available_timezones[i].value == timezone) {
                                    k = available_timezones[i].name.split(',')[0];
                                  }
                                }
                                let booked_text = 'Booked successfully on ';
                                booked_text = generateTranslatedContent(translations, "Booked successfully on ", main_lang_code, language_code, input);
                                input.setAttribute(
                                  'value',
                                  booked_text +
                                    storingDate +
                                    ', ' +
                                    this_label.innerHTML +
                                    '(' +
                                    k +
                                    ')'
                                );
                                input.value = actualDate + ' ' + this_label.id;
                                enter.style.pointerEvents = 'auto';
                                try {
                                  picker.destroy();
                                } catch (e) {
                                } finally {
                                }
                                if (header.contains(company_title_description)) {
                                  body.style.height = 'calc(100% - 168px)';
                                } else {
                                  body.style.height = 'calc(100% - 93px)';
                                }
                                if (
                                  main_opened_div.contains(
                                    document.getElementById('bg-shadow-overlay')
                                  )
                                ) {
                                  main_opened_div.removeChild(
                                    document.getElementById('bg-shadow-overlay')
                                  );
                                }
                                var openMenuSb =
                                  document.getElementById('open-menu-sb');
                                var optionsDiv = document.getElementsByClassName(
                                  'options-div-smatest'
                                );
    
                                if (openMenuSb && optionsDiv.length > 0) {
                                  if (
                                    optionsDiv[optionsDiv.length - 1].contains(
                                      openMenuSb
                                    )
                                  ) {
                                    optionsDiv[optionsDiv.length - 1].removeChild(
                                      openMenuSb
                                    );
                                  }
                                }
                                input.style.display = 'block';
                                enter.style.display = 'flex';
                                footer.style.borderTop = '0';
                                footer.style.padding = '6px 15px';
                                footer.style.height = '49px';

                                input.style.pointerEvents = "none";
                                microphone.style.pointerEvents = "none";
                                microphone.style.opacity = 0;
                                enter.style.pointerEvents = "none";

                                document.getElementById('smatest_datepicker').value =
                                  actualDate;
                                enter.click();
                                input.id = '';
                              } else {
                                slots_div.appendChild(inner_slots_div);
                                if (
                                  slots_div.contains(
                                    document.getElementById('calendar-loading')
                                  )
                                ) {
                                  slots_div.removeChild(
                                    document.getElementById('calendar-loading')
                                  );
                                }
                                // var errorDiv = document.createElement('DIV');
                                // errorDiv.classList.add('question-div-smatest');
                                // setTimeout(function () {
                                //   errorDiv.classList.add('top-0');
                                // }, transition_time);
                                // if (font && font.length > 0) {
                                //   errorDiv.classList.add(font);
                                // }
                                // var error_icon = document.createElement('IMG');
                                // error_icon.alt = 'Logo of ' + totalData[0].name;
                                // error_icon.src = avatar_icon;
                                // var iconDiv = document.createElement('DIV');
                                // iconDiv.appendChild(error_icon);
                                // iconDiv.classList.add('question-icon-div');
                                // error_icon.classList.add('question-icon-smatest');
                                // var error_text = document.createElement('LABEL');
                                // error_text.innerHTML = already_booked_message;
                                // say(error_text.innerText);
                                // error_text.classList.add('question-text-error');
                                // error_text.classList.add('options-div-smatest');
                                // if (font && font.length > 0) {
                                //   error_text.classList.add(font);
                                // }
                                // errorDiv.appendChild(iconDiv);
                                // errorDiv.appendChild(error_text);
                                // body.appendChild(errorDiv);
                                // playBotUserSound(1);
                                // body.scrollTop = body.scrollHeight;

                                if (!document.querySelector('.toast-file-message')) {
                                  const toast = document.createElement('div');
                                  toast.classList.add('toast-file-message');
                                  toast.style.top = '5px'
                                  toast.style.padding = '12px 10px'
                                  toast.style.background = 'black'
                                  toast.style.color = '#fff'
                                  if (font && font.length > 0) {
                                    toast.classList.add(font);
                                  }
                                
                                  toast.innerHTML = already_booked_message ;
                                  if (document.getElementById("inner_div_scrool-app")) {
                                    document.getElementById("inner_div_scrool-app").appendChild(toast);
                                  }
                                
                                  setTimeout(() => {
                                    toast.remove();
                                  }, 5000);
                                }

                              }
                            }else{
                              // submit_btn.disabled = true;
                            }
                          };
                          xhttp.open(
                            'POST',
                            main_url + '/kya_backend/pagehub/createAppointment',
                            !0
                          );
                          xhttp.setRequestHeader(
                            'Content-type',
                            'application/x-www-form-urlencoded'
                          );
                          if (document.getElementById('timezone_select')) {
                            timezone = document.getElementById('timezone_select').value;
                          }
                          xhttp.send(
                            'chatbot_id=' +
                              chatbot_id +
                              '&cb_session=' +
                              cb_session +
                              '&question_id=' +
                              question_id +
                              '&time=' +
                              encodeURIComponent(actualDate) +
                              'T' +
                              encodeURIComponent(this_label.id) +
                              ':00' +
                              encodeURIComponent(timezone)
                          );
                        } else {
                          console.log('select time slot first');
                        }
                      });
                    } else {
                      var label = document.createElement('LABEL');
                      label.innerHTML = no_slots_message;
                      if (font && font.length > 0) {
                        label.classList.add(font);
                      }
                      label.classList.add('no-slots-label');
                      slots_div.appendChild(label);
                    }
                  }
                };
                if (currentDate == actualDate) {
                  xhttp.open(
                    'GET',
                    main_url +
                      '/kya_backend/pagehub/getSlots?chatbot_id=' +
                      chatbot_id +
                      '&question_id=' +
                      question_id +
                      '&cb_session=' +
                      cb_session +
                      '&bookings_per_slot=' +
                      bookings_per_slot +
                      '&starttime=' +
                      encodeURIComponent(start_time) +
                      '&endtime=' +
                      encodeURIComponent(end_time) +
                      '&interval=' +
                      interval +
                      '&current_time=' +
                      encodeURIComponent(current_time),
                    !0
                  );
                } else {
                  xhttp.open(
                    'GET',
                    main_url +
                      '/kya_backend/pagehub/getSlots?chatbot_id=' +
                      chatbot_id +
                      '&question_id=' +
                      question_id +
                      '&cb_session=' +
                      cb_session +
                      '&bookings_per_slot=' +
                      bookings_per_slot +
                      '&starttime=' +
                      encodeURIComponent(start_time) +
                      '&endtime=' +
                      encodeURIComponent(end_time) +
                      '&interval=' +
                      interval,
                    !0
                  );
                }
                xhttp.setRequestHeader(
                  'Content-type',
                  'application/x-www-form-urlencoded'
                );
                xhttp.send();
              } else {
                this.destroy();
                if (header.contains(company_title_description)) {
                  body.style.height = 'calc(100% - 168px)';
                } else {
                  body.style.height = 'calc(100% - 93px)';
                }
                appoint_new_div.style.display = 'none';
                input.style.display = 'block';
                enter.style.display = 'flex';
                footer.style.borderTop = '0';
                footer.style.padding = '6px 15px';
                footer.style.height = '49px';
                document.getElementById('smatest_datepicker').value = actualDate;
                input.setAttribute('value', actualDate);
                enter.click();
                input.id = '';
                input.style.pointerEvents = "none";
                microphone.style.pointerEvents = "none";
                microphone.style.opacity = 0;
                enter.style.pointerEvents = "none";
              }
            }
    
            
            // if (header.contains(company_title_description)) {
            //   body.style.height = "calc(100% - 398px)";
            // } else {
            //   body.style.height = "calc(100% - 323px)";
            // }
            // input.style.display = 'none';
            enter.style.display = 'none';
            
            input.style.pointerEvents = "none";
            microphone.style.pointerEvents = "none";
            microphone.style.opacity = 0;
            enter.style.pointerEvents = "none";

            footer.style.borderTop = '0';
            footer.style.padding = '0';
            // footer.style.height = "230px";
            var pik_lander = document.getElementsByClassName('pika-lendar')[0];
            if (font && font.length > 0) {
              if (pik_lander) {
                pik_lander.classList.add(font);
              }
            }
            var timezone_loaded;
        
            function checkForTimezone() {
              if (!timezone_loaded) {
                if (document.getElementById('timezone_select')) {
                  timezone_loaded = true;
                  var timezone_dropdown = document.getElementById('timezone_select');
                  timezone_dropdown.addEventListener('change', function () {
                    if (date_selected) {
                      var timezone_val = this.value;
                      if (
                        inner_div_scrool.contains(document.getElementById('slot-scroll'))
                      ) {
                        inner_div_scrool.removeChild(
                          document.getElementById('slot-scroll')
                        );
                      }
                      if (
                        bg_overlay.contains(
                          document.getElementById('appointment-submit_btn')
                        )
                      ) {
                        bg_overlay.removeChild(
                          document.getElementById('appointment-submit_btn')
                        );
                      }
                      var slots_div = document.createElement('DIV');
                      slots_div.classList.add('slot-scrollbar-new');
                      slots_div.id = 'slot-scroll';
                      // if (header.contains(company_title_description)) {
                      //   body.style.height = "calc(100% - 483px)";
                      // } else {
                      //   body.style.height = "calc(100% - 408px)";
                      // }
                      // input.style.display = 'none';
                      enter.style.display = 'none';
                      footer.style.borderTop = '0';
                      footer.style.padding = '0';
                      // footer.style.height = "315px";
                      // footer.style.maxHeight = "315px";
                      // if (document.getElementsByClassName("pika-single")[0]) {
                      //   document.getElementsByClassName(
                      //     "pika-single"
                      //   )[0].style.bottom = "115px";
                      // }
            
                      var slot_details_div = document.createElement('DIV');
                      slot_details_div.setAttribute('id', 'slot_details_div');
            
                      inner_div_scrool.appendChild(slot_details_div);
                      inner_div_scrool.appendChild(slots_div);
            
                      var img = document.createElement('IMG');
                      img.id = 'calendar-loading';
                      img.src =
                        // "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/animate_calendar.gif";
                        'https://cdn.pixabay.com/animation/2023/05/12/07/29/07-29-43-548_256.gif';
                      img.classList.add('calendar-loading');
    
                      var loader_div = document.createElement('DIV');
                      loader_div.style.margin = 'auto';
                      loader_div.style.display = 'flex';
                      loader_div.style.alignItems = 'center';
                      loader_div.style.justifyContent = 'center';
        
                      loader_div.innerHTML = `<div class="loader-sb">
                                              <span class="hour"></span>
                                              <span class="min"></span>
                                              <span class="circel"></span>
                                            </div>`
        
                      slots_div.appendChild(loader_div);
    
                      // slots_div.appendChild(img);
                      var converted_start_time = convertStandardTime(from_timing);
                      var converted_end_time = convertStandardTime(to_timing);
                      var start_time = actualDate + 'T00:00:00' + timezone_val;
                      var end_time = actualDate + 'T23:59:59' + timezone_val;
                      var current_time;
                      var date = new Date().getDate();
                      var month = new Date().getMonth();
                      var year = new Date().getFullYear();
                      month = parseInt(month) + 1;
                      if (date > 0 && date < 10) {
                        date = '0' + date;
                      }
                      if (month > 0 && month < 10) {
                        month = '0' + month;
                      }
                      var currentDate = year + '-' + month + '-' + date;
                      var hours = new Date().getHours();
                      var minutes = new Date().getMinutes();
                      if (hours > 0 && hours < 10) {
                        hours = '0' + hours;
                      }
                      if (minutes > 0 && minutes < 10) {
                        minutes = '0' + minutes;
                      }
                      var current_time =
                        currentDate + 'T' + hours + ':' + minutes + ':00' + timezone_val;
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        if (this.readyState == 4 && this.status == 200) {
                          if (
                            slots_div.contains(document.getElementById('calendar-loading'))
                          ) {
                            slots_div.removeChild(
                              document.getElementById('calendar-loading')
                            );
                          }
                          if (
                            bg_overlay.contains(
                              document.getElementById('appointment-submit_btn')
                            )
                          ) {
                            bg_overlay.removeChild(
                              document.getElementById('appointment-submit_btn')
                            );
                          }
                          if (
                            inner_div_scrool.contains(
                              document.getElementById('slot_details_div')
                            )
                          ) {
                            inner_div_scrool.removeChild(
                              document.getElementById('slot_details_div')
                            );
                          }
                          slots_div.innerHTML = '';
                          var inner_slots_div = document.createElement('DIV');
                          inner_slots_div.classList.add('pull-left');
                          inner_slots_div.classList.add('full-width');
                          inner_slots_div.classList.add('text-center');
                          inner_slots_div.id = 'inner-slots-div';
                          slots_div.appendChild(inner_slots_div);
            
                          var slot_details = document.createElement('DIV');
                          slot_details.setAttribute('id', 'slot_details_headding');
                          if (font && font.length > 0) {
                            slot_details.classList.add(font);
                          }
                          var selectted_time;
                          slot_details.innerText = storingDate + ' ' + '|' + ' ' + timezone_val;
            
                          var inner_slots_div = document.createElement('DIV');
                          inner_slots_div.classList.add('pull-left');
                          inner_slots_div.classList.add('full-width');
                          inner_slots_div.classList.add('text-center');
                          inner_slots_div.id = 'inner-slots-div';
                          slots_div.appendChild(inner_slots_div);
            
                          var submit_btn = document.createElement('BUTTON');
                          submit_btn.classList.add('confirm-btn-smatest');
    
                          submit_btn.innerHTML = generateTranslatedContent(translations, "Looks good. Schedule it!", main_lang_code, language_code, input);
                          if (font && font.length > 0) {
                            submit_btn.classList.add(font);
                          }
                          submit_btn.setAttribute('id', 'appointment-submit_btn');
    
                          var submit_icon = document.createElement('IMG');
                          submit_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                          submit_icon.alt = 'SubmitIcon';
                          submit_icon.style.width = "18px";
                          submit_icon.style.height = "18px";
        
                          submit_btn.appendChild(submit_icon);
            
                          var response = JSON.parse(this.responseText);
                          if (response.data && response.data.length > 0) {
                            slot_details_div.appendChild(slot_details);
                            bg_overlay.appendChild(submit_btn);
            
                            for (var i = 0; i < response.data.length; i++) {
                              var label = document.createElement('label');
                              label.classList.add('slot-label');
                              label.style.cssText = label.style.cssText + "border-radius: 27px !important";
                              label.style.color = '#313131';
                              label.style.border = '1px solid #E1E7FE';
                              label.style.opacity = '1';
                              label.style.fontWeight = '600';
                              label.style.fontSize = '10px';
                              label.style.cssText = label.style.cssText + "text-align: center !important";
            
                              label.id = convertStandardTime(response.data[i]);
                              if (military_time) {
                                label.innerHTML = convertStandardTime(response.data[i]);
                              } else {
                                label.innerHTML = response.data[i];
                              }
                              if (font && font.length > 0) {
                                label.classList.add(font);
                              }
            
                              //  click event start
            
                              label.addEventListener('click', function (k) {
                                var labels = document.querySelectorAll('.slot-label');
                                labels.forEach(function (lbl) {
                                  // lbl.classList.remove('selected-time');
                                  lbl.classList.remove('confirm-btn-smatest');
                                });
            
                                // this.classList.add('selected-time');
                                this.classList.add('confirm-btn-smatest');
                                
                                slot_details.innerText =
                                  storingDate +
                                  '  , ' +
                                  this.innerText +
                                  ' | ' +
                                  ' ' +
                                  timezone_val;
                                selectted_time = this;
                              });
            
                              inner_slots_div.appendChild(label);
                            }
            
                            submit_btn.addEventListener('click', function (k) {
                              if (selectted_time && selectted_time.id.length > 0) {
                                slots_div.removeChild(inner_slots_div);
                                var img = document.createElement('IMG');
                                img.id = 'calendar-loading';
                                img.src =
                                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/animate_calendar.gif";
                                img.classList.add('calendar-loading');
                                slots_div.appendChild(img);
                                var this_label = selectted_time;
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var response = JSON.parse(this.responseText);
                                    if (response.status) {
                                      if (
                                        inner_div_scrool.contains(
                                          document.getElementById('slot-scroll')
                                        )
                                      ) {
                                        inner_div_scrool.removeChild(
                                          document.getElementById('slot-scroll')
                                        );
                                      }
                                      input.setAttribute('type', 'text');
                                      var k;
                                      for (var i = 0; i < available_timezones.length; i++) {
                                        if (available_timezones[i].value == timezone) {
                                          k = available_timezones[i].name.split(',')[0];
                                        }
                                      }
                                      let booked_text = 'Booked successfully on ';
                                      booked_text = generateTranslatedContent(translations, "Booked successfully on ", main_lang_code, language_code, input);
                                      input.setAttribute(
                                        'value',
                                        booked_text +
                                          storingDate +
                                          ' at ' +
                                          this_label.innerHTML +
                                          '(' +
                                          k +
                                          ')'
                                      );
                                      input.value = actualDate + ' ' + this_label.id;
                                      enter.style.pointerEvents = 'auto';
                                      try {
                                        picker.destroy();
                                      } catch (e) {
                                      } finally {
                                      }
                                      if (header.contains(company_title_description)) {
                                        body.style.height = 'calc(100% - 168px)';
                                      } else {
                                        body.style.height = 'calc(100% - 93px)';
                                      }
                                      if (
                                        main_opened_div.contains(
                                          document.getElementById('bg-shadow-overlay')
                                        )
                                      ) {
                                        main_opened_div.removeChild(
                                          document.getElementById('bg-shadow-overlay')
                                        );
                                      }
                                      var openMenuSb = document.getElementById(
                                        'open-menu-sb'
                                      );
                                      var optionsDiv = document.getElementsByClassName(
                                        'options-div-smatest'
                                      );
            
                                      if (openMenuSb && optionsDiv.length > 0) {
                                        if (
                                          optionsDiv[optionsDiv.length - 1].contains(
                                            openMenuSb
                                          )
                                        ) {
                                          optionsDiv[optionsDiv.length - 1].removeChild(
                                            openMenuSb
                                          );
                                        }
                                      }
                                      input.style.display = 'block';
                                      enter.style.display = 'flex';
                                      footer.style.borderTop = '0';
                                      footer.style.padding = '6px 15px';
                                      footer.style.height = '49px';
                                      input.style.pointerEvents = "none";
                                      microphone.style.pointerEvents = "none";
                                      microphone.style.opacity = 0;
                                      enter.style.pointerEvents = "none";
                                      document.getElementById('smatest_datepicker').value =
                                        actualDate;
                                      enter.click();
                                      input.id = '';
                                    } else {
                                      slots_div.appendChild(inner_slots_div);
                                      if (
                                        slots_div.contains(
                                          document.getElementById('calendar-loading')
                                        )
                                      ) {
                                        slots_div.removeChild(
                                          document.getElementById('calendar-loading')
                                        );
                                      }
                                      // var errorDiv = document.createElement('DIV');
                                      // errorDiv.classList.add('question-div-smatest');
                                      // setTimeout(function () {
                                      //   errorDiv.classList.add('top-0');
                                      // }, transition_time);
                                      // if (font && font.length > 0) {
                                      //   errorDiv.classList.add(font);
                                      // }
                                      // var error_icon = document.createElement('IMG');
                                      // error_icon.alt = 'Logo of ' + totalData[0].name;
                                      // error_icon.src = avatar_icon;
                                      // var iconDiv = document.createElement('DIV');
                                      // iconDiv.appendChild(error_icon);
                                      // iconDiv.classList.add('question-icon-div');
                                      // error_icon.classList.add('question-icon-smatest');
                                      // var error_text = document.createElement('LABEL');
                                      // error_text.innerHTML = already_booked_message;
                                      // say(error_text.innerText);
                                      // error_text.classList.add('question-text-error');
                                      // error_text.classList.add('options-div-smatest');
                                      // if (font && font.length > 0) {
                                      //   error_text.classList.add(font);
                                      // }
                                      // errorDiv.appendChild(iconDiv);
                                      // errorDiv.appendChild(error_text);
                                      // body.appendChild(errorDiv);
                                      // playBotUserSound(1);
                                      // body.scrollTop = body.scrollHeight;

                                      if (!document.querySelector('.toast-file-message')) {
                                        const toast = document.createElement('div');
                                        toast.classList.add('toast-file-message');
                                        toast.style.top = '5px'
                                        toast.style.padding = '12px 10px'
                                        toast.style.background = 'black'
                                        toast.style.color = '#fff'
                                        if (font && font.length > 0) {
                                          toast.classList.add(font);
                                        }
                                      
                                        toast.innerHTML = already_booked_message;
                                        if (document.getElementById("inner_div_scrool-app")) {
                                          document.getElementById("inner_div_scrool-app").appendChild(toast);
                                        }
                                      
                                        setTimeout(() => {
                                          toast.remove();
                                        }, 5000);
                                      }

                                    }
                                  }else{
                                    // submit_btn.disabled = true;
                                  }
                                };
                                xhttp.open(
                                  'POST',
                                  main_url + '/kya_backend/pagehub/createAppointment',
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  'Content-type',
                                  'application/x-www-form-urlencoded'
                                );
                                if (document.getElementById('timezone_select')) {
                                  timezone =
                                    document.getElementById('timezone_select').value;
                                }
                                xhttp.send(
                                  'chatbot_id=' +
                                    chatbot_id +
                                    '&cb_session=' +
                                    cb_session +
                                    '&question_id=' +
                                    question_id +
                                    '&time=' +
                                    encodeURIComponent(actualDate) +
                                    'T' +
                                    encodeURIComponent(this_label.id) +
                                    ':00' +
                                    encodeURIComponent(timezone)
                                );
                              } else {
                                console.log('select time slot first');
                              }
                            });
                          } else {
                            var label = document.createElement('LABEL');
                            label.innerHTML = no_slots_message;
                            if (font && font.length > 0) {
                              label.classList.add(font);
                            }
                            label.classList.add('no-slots-label');
                            slots_div.appendChild(label);
                          }
                        }
                      };
                      if (currentDate == actualDate) {
                        xhttp.open(
                          'GET',
                          main_url +
                            '/kya_backend/pagehub/getSlots?chatbot_id=' +
                            chatbot_id +
                            '&question_id=' +
                            question_id +
                            '&cb_session=' +
                            cb_session +
                            '&bookings_per_slot=' +
                            bookings_per_slot +
                            '&starttime=' +
                            encodeURIComponent(start_time) +
                            '&endtime=' +
                            encodeURIComponent(end_time) +
                            '&interval=' +
                            interval +
                            '&current_time=' +
                            encodeURIComponent(current_time),
                          !0
                        );
                      } else {
                        xhttp.open(
                          'GET',
                          main_url +
                            '/kya_backend/pagehub/getSlots?chatbot_id=' +
                            chatbot_id +
                            '&question_id=' +
                            question_id +
                            '&cb_session=' +
                            cb_session +
                            '&bookings_per_slot=' +
                            bookings_per_slot +
                            '&starttime=' +
                            encodeURIComponent(start_time) +
                            '&endtime=' +
                            encodeURIComponent(end_time) +
                            '&interval=' +
                            interval,
                          !0
                        );
                      }
                      xhttp.setRequestHeader(
                        'Content-type',
                        'application/x-www-form-urlencoded'
                      );
                      xhttp.send();
                    }
                  });
                }
              } else {
                stopInterval();
              }
            }
            
        
            function stopInterval() {
              clearInterval(timer);
            }
            var timer = setInterval(checkForTimezone, 100);
          }, 10);
        }

        function parseDataReferring(question_array, id) {
          nothingWentOnFor = 0;
          encourageMessageIteration = 0;
          if (
            question_array[id].question_text.includes("{{time_based_greeting}}")
          ) {
            var d = new Date();
            var new_date = new Date(d.getTime() + d.getTimezoneOffset() * 60000);
            var final_date = d;
            var greeting;
            var hours = final_date.getHours();
            if (hours >= 5 && hours <= 11) {
              greeting = generateTranslatedContent(translations, "Good Morning", main_lang_code, language_code, input);
            } else if (hours >= 12 && hours <= 16) {
              greeting = generateTranslatedContent(translations, "Good Afternoon", main_lang_code, language_code, input);
            } else if ((hours >= 17 && hours <= 23) || (hours >= 0 && hours <= 4)) {
              greeting = generateTranslatedContent(translations, "Good Evening", main_lang_code, language_code, input);
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{time_based_greeting}}", greeting);
          }
          if (question_array[id].question_text.includes("{{first_name}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.first_name &&
              window.botWidget.user.first_name.length > 0
            ) {
              str = window.botWidget.user.first_name;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{first_name}}", str);
          }
          if (question_array[id].question_text.includes("{{last_name}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.last_name &&
              window.botWidget.user.last_name.length > 0
            ) {
              str = window.botWidget.user.last_name;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{last_name}}", str);
          }
          if (question_array[id].question_text.includes("{{email}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.email &&
              window.botWidget.user.email.length > 0
            ) {
              str = window.botWidget.user.email;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{email}}", str);
          }
          if (question_array[id].question_text.includes("{{mobile}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.phone &&
              window.botWidget.user.phone.length > 0
            ) {
              str = window.botWidget.user.phone;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{mobile}}", str);
          }
          if (question_array[id].question_text.includes("{{notes}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.notes &&
              window.botWidget.user.notes.length > 0
            ) {
              str = window.botWidget.user.notes;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{notes}}", str);
          }
          if (question_array[id].question_text.includes("{{language}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.language &&
              window.botWidget.user.language.length > 0
            ) {
              str = window.botWidget.user.language;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{language}}", str);
          }
          if (question_array[id].question_text.includes("{{partner_code}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.partner_code &&
              window.botWidget.user.partner_code.length > 0
            ) {
              str = window.botWidget.user.partner_code;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{partner_code}}", str);
          }
          if (question_array[id].question_text.includes("{{otp_generate_type}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.otp_generate_type &&
              window.botWidget.user.otp_generate_type.length > 0
            ) {
              str = window.botWidget.user.otp_generate_type;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{otp_generate_type}}", str);
          }
          if (question_array[id].question_text.includes("{{partner_type}}")) {
            var str;
            if (
              window.botWidget &&
              window.botWidget.user &&
              window.botWidget.user.partner_type &&
              window.botWidget.user.partner_type.length > 0
            ) {
              str = window.botWidget.user.language;
            } else {
              str = "";
            }
            question_array[id].question_text = question_array[
              id
            ].question_text.replace("{{partner_type}}", str);
          }
          var index1 = question_array[id].question_text.indexOf("{{");
          var index2 = question_array[id].question_text.indexOf("}}");
          var data_type;
          if (index2 > 0 && index1 > 0) {
            var data_refer = question_array[id].question_text.substring(
              index1,
              index2 + 2
            );
            var data_arr = data_refer.split("_");
            var data_id = data_arr[data_arr.length - 1];
            data_type = data_refer.replace(data_id, "");
            data_type = data_type.replace("}}", "");
            data_type = data_type.replace("{{", "");
            data_id = data_id.replace("}}", "");
          }
          var key;
          if (question_and_answers && question_and_answers.length > 0) {
            for (var i = question_and_answers.length - 1; i >= 0; i--) {
              if (question_and_answers[i].id == data_id) {
                key = !0;
                if (data_type == "dynamic_question") {
                  question_array[id].question_text = question_array[
                    id
                  ].question_text.replace(
                    data_refer,
                    question_and_answers[i].question_text
                  );
                } else {
                  if (question_and_answers[i].answer == "skipped") {
                    question_array[id].question_text = question_array[
                      id
                    ].question_text.replace(data_refer, "");
                  } else {
                    question_array[id].question_text = question_array[
                      id
                    ].question_text.replace(
                      data_refer,
                      question_and_answers[i].answer
                    );
                  }
                }
              }
            }
            if (!key) {
              if (data_refer) {
                question_array[id].question_text = question_array[
                  id
                ].question_text.replace(data_refer, "");
              }
            } else {
            }
            if (
              question_array[id].question_text &&
              question_array[id].question_text.includes("{{") &&
              question_array[id].question_text.includes("}}")
            ) {
              parseDataReferring(question_array, id);
            }
          }
        }

        function callFileUpload(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;
    
            function addQuestionArrays() {
              if (j < question_arr.length) {
                var major_drag_and_upload_div;
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);

                  var optionsText = question_array[0].default_options;
                  try {
                    optionsText = JSON.parse(optionsText);
                    if (optionsText.button_text && optionsText.button_text.length > 0) {
                      optionsText = optionsText.button_text;
                    } else {
                      optionsText = "Upload";
                    }
                  } catch (error) {
                    optionsText = "Upload";
                  }
    
                  //code start
    
                  var isMultiUpload ;
                  var defaultoptions = question_array[0].default_options;
                  try {
                    var options = JSON.parse(defaultoptions);
                    if (options && options.type && options.type == 'multiple') {
                        isMultiUpload = true;
                    }else{
                       isMultiUpload = false;
                    }
                  } catch (error) {
                     isMultiUpload = false;
                  }
    
    
                  var main_opened_div = document.getElementById('opened');
        
                  if (
                    main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                  ) {
                    main_opened_div.removeChild(
                      document.getElementById('bg-shadow-overlay')
                    );
                  }
            
                  var openMenuSb = document.getElementById('open-menu-sb');
                  var optionsDiv = document.getElementsByClassName('options-div-smatest');
            
                  if (openMenuSb && optionsDiv.length > 0) {
                    if (
                      optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                    ) {
                      optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                    }
                  }
    
                  var opened_div = document.getElementById('opened');
    
                  if (opened_div.contains(document.getElementById('bg-shadow-overlay'))) {
                      opened_div.removeChild(document.getElementById('bg-shadow-overlay'));
                  }
    
                  var close_icon_div = document.createElement('DIV');
                  close_icon_div.setAttribute('class', 'close-icon-div');
    
                  var close_icon_img = document.createElement('IMG');
                  close_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small.svg'
                  close_icon_img.alt ='closeicon'
                  close_icon_img.style.width ='10px';
                  close_icon_img.style.height ='10px';
    
                  var bg_shadow_fileUplaod = document.createElement('DIV');
                  bg_shadow_fileUplaod.setAttribute('id', 'bg-shadow-overlay');
    
                  var fileUpload_container = document.createElement('DIV');
                  fileUpload_container.setAttribute('id', 'fileUpload_container');
                  fileUpload_container.style.minHeight = '35%';

                  try {
                    var json = JSON.parse(defaultoptions);
                  } catch (error) {
                    
                  }

                  if (json && json.openMenu && json.openMenu.length > 0) {
                    if (json.openMenu == 'open') {
                      bg_shadow_fileUplaod.style.visibility = 'visible';
                      fileUpload_container.style.opacity = '1';
                      fileUpload_container.style.transform = 'translateY(0)';
                    }else{
                      bg_shadow_fileUplaod.style.visibility = 'hidden';
                      fileUpload_container.style.opacity = '0.5';
                      fileUpload_container.style.transform = 'translateY(100%)';
                    }
                  }else{
                    bg_shadow_fileUplaod.style.visibility = 'hidden';
                    fileUpload_container.style.opacity = '0.5';
                    fileUpload_container.style.transform = 'translateY(100%)';
                  }

                  createAppMenu(option_div, 'Upload', bg_shadow_fileUplaod, fileUpload_container)

                  fileUpload_container.appendChild(close_icon_div);
                  createBrandWrapper(fileUpload_container, 'SmatBot', main_url, font);
                  close_icon_div.appendChild(close_icon_img);
                  setTimeout(() => {
                    opened_div.appendChild(bg_shadow_fileUplaod);
                    bg_shadow_fileUplaod.appendChild(fileUpload_container);
                  }, 1000);
        
                  close_icon_div.addEventListener("click", function () {
                      if (opened_div.contains(bg_shadow_fileUplaod)) {
                          bg_shadow_fileUplaod.style.visibility = 'hidden';
                          fileUpload_container.style.opacity = '0.5';
                          fileUpload_container.style.transform = 'translateY(100%)';
                      }
                  });
    
                  var drag_and_upload_div_sb = document.createElement("DIV");
                  drag_and_upload_div_sb.classList.add('drag_and_upload_div_sb')
                  
                  var drag_and_upload_headder_sb = document.createElement("h5");
                  drag_and_upload_headder_sb.style.textAlign = 'center';
                  drag_and_upload_headder_sb.style.margin = '0';
                  drag_and_upload_headder_sb.style.padding = '0';
                  drag_and_upload_headder_sb.style.color = '#1D2D35';
                  drag_and_upload_headder_sb.style.fontSize = '13px';
                  drag_and_upload_headder_sb.style.fontWeight = '600';
                  drag_and_upload_headder_sb.style.padding = '0';

                  let text = 'Upload Media'
                  try {
                    if (json.button_text && json.button_text.length > 0) {
                      text = json.button_text;
                    } else {
                      text = 'Upload Media'
                    }
                  } catch (error) {
                    text = 'Upload Media'
                  }

                  drag_and_upload_headder_sb.innerHTML = generateTranslatedContent(translations, text, main_lang_code, language_code, input) 
                  
                  var file_upload_icons_div_sb = document.createElement("DIV");
                  file_upload_icons_div_sb.classList.add('file-upload-icons_container_sb')
                  
                  // Array of upload items
                  var uploadItems = [
                      { type: 'Image', iconSrc: 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/filuplad_image_icon_new.svg', acceptedTypes: 'image/*' },
                      { type: 'Video', iconSrc: 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/clapperboard-play.svg', acceptedTypes: 'video/*' },
                      { type: 'File', iconSrc: 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg', acceptedTypes: 'application/pdf' }
                  ];
                  
                  // Create upload items
                  uploadItems.forEach(item => {
                      var file_upload_div = document.createElement("DIV");
                      file_upload_div.classList.add('file-upload-item-list');
                  
                      var file_upload_image_div = document.createElement("DIV");
                      file_upload_image_div.classList.add('file-upload-item-image_div');
                  
                      var file_upload_div_icon = document.createElement("IMG");
                      file_upload_div_icon.src = item.iconSrc;
                      file_upload_div_icon.alt = 'file icon';
                  
                      var file_upload_div_text = document.createElement("h5");
                      file_upload_div_text.innerHTML = generateTranslatedContent(translations, item.type, main_lang_code, language_code, input);
                  
                      file_upload_image_div.appendChild(file_upload_div_icon);
                      file_upload_div.appendChild(file_upload_image_div);
                      file_upload_div.appendChild(file_upload_div_text);
                      file_upload_icons_div_sb.appendChild(file_upload_div);
                  
                      if (font && font.length > 0) {
                          drag_and_upload_headder_sb.classList.add(font);
                          file_upload_div_text.classList.add(font);
                      }
                  
                      // Event listener for file upload
                      file_upload_div.addEventListener('click', function() {
                          var input = document.createElement('input');
                          input.type = 'file';
                          input.accept = item.acceptedTypes;
                          input.click();
                          input.addEventListener('change', function(event) {
    
                            const maxSizeMB = 5; 
                            const maxSizeBytes = maxSizeMB * 1024 * 1024;
    
                            var files = event.target.files;
                            if (files.length > 0) {
                              for (var i = 0; i < files.length; i++) {
                                if (files[i].size > maxSizeBytes) {
                                    displayLargeFileMessage(files[i]);
                                    return; // Exit if any file is too large
                                }
                            }
                              handleFileUpload(files, item.acceptedTypes);     
                            }
    
                          });
                      });
    
                  });
    
                  // Drag and drop event listeners
                  opened_div.addEventListener('dragover', function(event) {
                    event.preventDefault();
                    fileUpload_container.classList.add('drag-over');
                  });
    
                  opened_div.addEventListener('dragleave', function() {
                    fileUpload_container.classList.remove('drag-over');
                  });
    
                  opened_div.addEventListener('drop', function(event) {
                    event.preventDefault();
                    fileUpload_container.classList.remove('drag-over');
                    var files = event.dataTransfer.files;
                    const maxSizeMB = 5; 
                    const maxSizeBytes = maxSizeMB * 1024 * 1024;
                    if (files.length > 0) {
                        var file = files[0];
                        if (file.size > maxSizeBytes) {
                          displayLargeFileMessage(file);
                          return;
                        }
                        if (file.type.startsWith('image/')) {
                            handleFileUpload(files, 'image/*');
                        } else if (file.type.startsWith('video/')) {
                            handleFileUpload(files, 'video/*');
                        } else if (file.type === 'application/pdf') {
                            handleFileUpload(files, 'application/pdf');
                        } else {
                            console.log('Unsupported file type');
                        }
                    }
                  });
    
                  function displayLargeFileMessage(file,type='error') {
     
                      const toast = document.createElement('div');
                      toast.classList.add('toast-file-message', type);
                      if (font && font.length > 0) {
                        toast.classList.add(font);
                      }
    
    
                      toast.innerHTML =  `File "${file.name}" is greater than 5MB and cannot be uploaded.`;
    
                      if (document.getElementById('bg-shadow-overlay')) {
                          document.getElementById('bg-shadow-overlay').appendChild(toast);
                      } else {
                          document.body.appendChild(toast); 
                      }
                  
                  
                      setTimeout(() => {
                          toast.remove();
                      }, 5000);
                  }
    
                  var uploadedFilesArray = [];
    
                  function handleFileUpload(files, acceptedTypes) {
                    const maxSizeMB = 5;
                    const maxSizeBytes = maxSizeMB * 1024 * 1024;
                    var hasLargeFile = false;
                
                    var fileListDiv = document.querySelector('.file-list-sb');
                    if (!fileListDiv) {
                        fileListDiv = document.createElement('div');
                        if (isMultiUpload) {
                            fileListDiv.style.justifyContent = 'flex-start';
                            fileListDiv.style.marginBottom = '20px';
                            fileListDiv.style.justifyItems = 'start';
                            fileListDiv.style.width = '100%';
                        } else {
                            fileListDiv.style.alignItems = 'center';
                        }
                        fileListDiv.classList.add('file-list-sb');
                        drag_and_upload_div_sb.style.display = 'none';
                        fileUpload_container.appendChild(fileListDiv);
                    }
    
                    if (!isMultiUpload) {
                        var file = files[0];
                        if (file.size <= maxSizeBytes) {
                            fileListDiv.innerHTML = '';
                            displaySingleFile(file);
                        } else {
                            displayLargeFileMessage(file);
                            hasLargeFile = true;
                        }
                    } else {
                        for (var i = 0; i < files.length; i++) {
                            if (files[i].size <= maxSizeBytes) {
                                displayMultipleFiles(files[i]);
                                uploadedFilesArray.push(files[i]);
                            } else {
                                displayLargeFileMessage(files[i]);
                                hasLargeFile = true;
                            }
                        }
                        displayMultipleFilesControls();
                    }
                
                    function displaySingleFile(file) {
                        var fileItem = document.createElement('div');
                        fileItem.classList.add('file-item-sb');
                
                        var fileIcon = document.createElement('img');
                        if (file?.type?.includes('image')) {
                            fileIcon.src = URL.createObjectURL(file);
                        } else if (file?.type?.includes('video')) {
                            fileIcon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/clapperboard-play.svg';
                        } else {
                            fileIcon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg';
                        }
                
                        fileIcon.alt = file.name;
                        fileIcon.classList.add('file-icon-sb');
                
                        var fileDetails = document.createElement('div');
                        fileDetails.classList.add('file-details-sb');
                
                        var fileName = document.createElement('p');
                        fileName.textContent = file.name;
                
                        var fileSize = document.createElement('p');
                        if (file.size < 1024 * 1024) {
                            fileSize.textContent = (file.size / 1024).toFixed(2) + ' KB';
                        } else {
                            fileSize.textContent = (file.size / 1024 / 1024).toFixed(2) + ' MB';
                        }
                
                        var uploadAgainLink = document.createElement('a');
                        uploadAgainLink.classList.add('upload-again-sb');
                        uploadAgainLink.classList.add('upload-new-file-button-sb');
                        uploadAgainLink.textContent =  generateTranslatedContent(translations, "Upload Again", main_lang_code, language_code, input);
                        uploadAgainLink.addEventListener('click', function (event) {
                            event.preventDefault();
                            uploadAgain(acceptedTypes);
                        });
                
                        fileDetails.appendChild(fileName);
                        fileDetails.appendChild(fileSize);
                        fileDetails.appendChild(uploadAgainLink);
                
                        fileItem.appendChild(fileIcon);
                        fileItem.appendChild(fileDetails);
                
                        var sendButton = document.createElement('button');
                        sendButton.classList.add('file-upload-send-button-sb');
                        sendButton.classList.add('confirm-btn-smatest');
                        sendButton.innerHTML = generateTranslatedContent(translations, "Send", main_lang_code, language_code, input);
                        sendButton.disabled = hasLargeFile; 
    
                        var submit_icon = document.createElement('IMG');
                        submit_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                        submit_icon.alt = 'SubmitIcon';
                        submit_icon.style.width = "18px";
                        submit_icon.style.height = "18px";
                        submit_icon.style.margin = "0";
      
                        sendButton.appendChild(submit_icon);
    
                        var progress_Bar = document.createElement('DIV');
                        progress_Bar.classList.add('progress-bar-loading-sb');
                        progress_Bar.setAttribute('id', 'progress-bar-loading-sb');
                        progress_Bar.style.display ='none'
                        progress_Bar.style.margin ='20px'
    
                
                        if (font && font.length > 0) {
                            sendButton.classList.add(font);
                            fileItem.classList.add(font);
                        }
                
                        sendButton.addEventListener('click', function () {
                            convertFilesToBase64([file]);
                        });
                
                        fileListDiv.appendChild(fileItem);
                        fileListDiv.appendChild(sendButton);
                        fileListDiv.appendChild(progress_Bar);
    
                    }
                
                    function displayMultipleFiles(file) {
                        var fileItem = document.createElement('div');
                        fileItem.classList.add('file-item-sb');
                        fileItem.style.flexDirection = 'row';
                        fileItem.style.width = '85%';
                        fileItem.style.justifyContent = 'flex-start';
                        fileItem.style.margin = 'auto';
                
                        var fileDiv = document.createElement('DIV');
                        fileDiv.classList.add('file-image-div-sb');
                
                        var fileIcon = document.createElement('img');
                        fileIcon.style.height = '20px';
                        fileIcon.style.margin = '0px';
                        fileIcon.style.objectFit = 'contain';
                
                        if (file?.type?.includes('image')) {
                            fileIcon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/filuplad_image_icon_new.svg';
                        } else if (file?.type?.includes('video')) {
                            fileIcon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/clapperboard-play.svg';
                        } else {
                            fileIcon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg';
                        }
                
                        fileIcon.alt = file.name;
                        fileIcon.classList.add('file-icon-sb');
                
                        var fileDetails = document.createElement('div');
                        fileDetails.classList.add('file-details-sb');
                        fileDetails.style.flexDirection = 'row';
                        fileDetails.style.width = '100%';
                        fileDetails.style.justifyContent = 'flex-start';
                
                        var fileInfo = document.createElement('div');
                        fileInfo.style.flexDirection = 'column';
                
                        var fileName = document.createElement('p');
                        fileName.textContent = file.name;
                        fileName.style.fontSize = '12px';
                        fileName.style.fontWeight = '600';
                
                        var fileSize = document.createElement('p');
                        fileSize.style.fontSize = '12px';
                        fileSize.style.fontWeight = '600';
                        if (file.size < 1024 * 1024) {
                            fileSize.textContent = (file.size / 1024).toFixed(2) + ' KB';
                        } else {
                            fileSize.textContent = (file.size / 1024 / 1024).toFixed(2) + ' MB';
                        }
                
                        var deleteFileLink = document.createElement('IMG');
                        deleteFileLink.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/trash.svg';
                        deleteFileLink.alt = 'delete icon';
                        deleteFileLink.style.margin = '0';
                        deleteFileLink.style.marginLeft = 'auto';
                        deleteFileLink.style.cursor = 'pointer';
                        deleteFileLink.style.width = '12px';
                        deleteFileLink.style.height = '12px';
                
                        deleteFileLink.classList.add('delete-file');
                        deleteFileLink.addEventListener('click', function (event) {
                            event.preventDefault();
                            fileItem.remove();
                            uploadedFilesArray = uploadedFilesArray.filter(f => f.name !== file.name);
                        });
                
                        if (font && font.length > 0) {
                            fileItem.classList.add(font);
                        }
    
         
                
                        fileInfo.appendChild(fileName);
                        fileInfo.appendChild(fileSize);
                        fileDetails.appendChild(fileInfo);
                        fileDetails.appendChild(deleteFileLink);
                
                        fileDiv.appendChild(fileIcon);
                        fileItem.appendChild(fileDiv);
                        fileItem.appendChild(fileDetails);
                
                        fileListDiv.appendChild(fileItem);
    
                    }
                
                    function displayMultipleFilesControls() {
                        var controlsDiv = document.querySelector('.controls-div-sb');
                        if (!controlsDiv) {
                            controlsDiv = document.createElement('div');
                            controlsDiv.classList.add('controls-div-sb');
                            fileUpload_container.appendChild(controlsDiv);
                        }
                
                        controlsDiv.innerHTML = '';
                
                        var uploadNewFileButton = document.createElement('a');
                        uploadNewFileButton.classList.add('upload-new-file-button-sb');
                        uploadNewFileButton.textContent =  generateTranslatedContent(translations, "Upload New File", main_lang_code, language_code, input); 
                        uploadNewFileButton.addEventListener('click', function (event) {
                            event.preventDefault();
                            uploadAgain(acceptedTypes);
                        });
                
                        var sendButton = document.createElement('button');
                        sendButton.classList.add('file-upload-send-button-sb');
                        sendButton.classList.add('confirm-btn-smatest');
                        sendButton.innerHTML = generateTranslatedContent(translations, "Send", main_lang_code, language_code, input); 
                        sendButton.disabled = hasLargeFile; 
    
                        var submit_icon = document.createElement('IMG');
                        submit_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                        submit_icon.alt = 'SubmitIcon';
                        submit_icon.style.width = "18px";
                        submit_icon.style.height = "18px";
                        submit_icon.style.margin = "0";
      
                        sendButton.appendChild(submit_icon);
                
                        if (font && font.length > 0) {
                            uploadNewFileButton.classList.add(font);
                            sendButton.classList.add(font);
                        }
                
                        sendButton.addEventListener('click', function () {
                            convertFilesToBase64(uploadedFilesArray);
                        });
    
                        var progress_Bar = document.createElement('DIV');
                        progress_Bar.classList.add('progress-bar-loading-sb');
                        progress_Bar.setAttribute('id', 'progress-bar-loading-sb');
                        progress_Bar.style.display ='none'
                        progress_Bar.style.margin ='20px'
                
                        controlsDiv.appendChild(uploadNewFileButton);
                        controlsDiv.appendChild(sendButton);
                        controlsDiv.appendChild(progress_Bar);
    
                    }
                
                    function uploadAgain(acceptedTypes) {
                        var input = document.createElement('input');
                        input.type = 'file';
                        input.accept = acceptedTypes;
                        input.click();
                        input.addEventListener('change', function (event) {
                            var files = event.target.files;
                            if (files.length > 0) {
                                var file = files[0];
                                if (file.size <= maxSizeBytes) {
                                    handleFileUpload(files, acceptedTypes);
                                } else {
                                    displayLargeFileMessage(file);
                                    hasLargeFile = true;
                                }
                            }
                        });
                    }
                
                    function convertFilesToBase64(files) {
                      var base64Files = [];
                      var responses = []; 
                      var loadingElement = document.getElementById('progress-bar-loading-sb'); 
                      var submit_button = document.querySelector('.file-upload-send-button-sb')
                      var upload_again_button = document.querySelector('.upload-new-file-button-sb')
    
                      const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
                  
                      function uploadFile(file) {
                          return new Promise((resolve, reject) => {
                              var reader = new FileReader();
                              reader.readAsDataURL(file);
                              reader.onload = function () {
                                  base64Files.push({ file_name: file.name, data: reader.result });
                                  resolve();
                              };
                              reader.onerror = function (error) {
                                  base64Files.push({ file_name: file.name, data: '' });
                                  resolve();
                              };
                          });
                      }
                  
                      async function uploadFilesSequentially() {
                          if (loadingElement) loadingElement.style.display = 'block'; 
                          if (submit_button) submit_button.style.display ='none'
                          if (upload_again_button) upload_again_button.style.display ='none'
                            
                          for (const file of files) {
                              await uploadFile(file);
                              await delay(1000); // Wait for 1 second
                          }
                  
                          // Process API calls after all files are read
                          for (const { file_name, data } of base64Files) {
                              try {
                                  let response = await fetch(main_url + '/kya_backend/pagehub/uploadFilecb', {
                                      method: 'POST',
                                      headers: {
                                          'Content-type': 'application/x-www-form-urlencoded'
                                      },
                                      body: new URLSearchParams({
                                          'data': data,
                                          'file_name': file_name,
                                          'bot_id': chatbot_id
                                      })
                                  });
                  
                                  let responseData = await response.json();
                                  responses.push(responseData); // Store response data
                              } catch (error) {
                                  console.error('Error uploading file:', error);
                              }
                              await delay(1000); // Wait for 1 second between API calls
                          }
                  
                          if (loadingElement) loadingElement.style.display = 'none'; 
                          if (submit_button) submit_button.style.display = 'block'
                          if (upload_again_button) upload_again_button.style.display ='block'
                  
    
                          let urls = responses.map(obj => obj.url).join(',');
    
                          if (urls && urls?.length > 0) {
                            takingRadioValue( urls, bg_shadow_fileUplaod, 3 );
    
                            var openMenuSb = document.getElementById('open-menu-sb');
                            var optionsDiv = document.getElementsByClassName('options-div-smatest');
                      
                            if (openMenuSb && optionsDiv.length > 0) {
                              if (
                                optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                              ) {
                                optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                              }
                            }
    
                          }
    
                      }
                  
                      uploadFilesSequentially();
                  }
                  
                  }
              
                  drag_and_upload_div_sb.appendChild(drag_and_upload_headder_sb);
                  drag_and_upload_div_sb.appendChild(file_upload_icons_div_sb);
                  
    
                  //NEW code End
                  if (
                    question_array[0].is_skip &&
                    question_array[0].is_skip == "1"
                  ) {
                    option_div.style.position = "relative";
                    var skippable_div = document.createElement("DIV");
                    skippable_div.id = "skip-question-div";
                    skippable_div.classList.add("skip-question-div");
                    translateContent(translations, skippable_div, "Skip", main_lang_code, language_code);
                    if (font && font.length > 0) {
                      skippable_div.classList.add(font);
                    }
                    option_div.style.paddingBottom = "5px";
                    skippable_div.addEventListener("click", function (k) {
                      takingRadioValue("skipped", skippable_div, 5);
                      option_div.style.paddingBottom = "9px";
                      option_div.style.cssText =
                        option_div.style.cssText + "background:darkgray !important";
                        var main_opened_div = document.getElementById('opened');
        
                        if (
                          main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                        ) {
                          main_opened_div.removeChild(
                            document.getElementById('bg-shadow-overlay')
                          );
                        }
                  
                        var openMenuSb = document.getElementById('open-menu-sb');
                        var optionsDiv = document.getElementsByClassName('options-div-smatest');
                  
                        if (openMenuSb && optionsDiv.length > 0) {
                          if (
                            optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                          ) {
                            optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                          }
                        }
                    });
                    option_div.appendChild(skippable_div);
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                  body.scrollTop = body.scrollHeight;
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      // body.appendChild(major_drag_and_upload_div); 
                      // fileUpload_container.appendChild(major_drag_and_upload_div);
                      fileUpload_container.appendChild(drag_and_upload_div_sb);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 100);
                  }
                  body.appendChild(questionDIv);
                  body.scrollTop = body.scrollHeight;
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(major_drag_and_upload_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 100);
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
        }

        function callSlides(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes('{{') &&
            question_array[0].question_text.includes('}}')
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var k = 0;
    
            function addQuestionArrays() {
              if (k < question_arr.length) {
                var questionDIv = document.createElement('DIV');
                questionDIv.classList.add('question-div-smatest');
                setTimeout(function () {
                  questionDIv.classList.add('top-0');
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement('IMG');
                ques_icon1.alt = 'Logo of ' + totalData[0].name;
                var iconDiv = document.createElement('DIV');
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add('question-icon-div');
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add('question-icon-smatest');
                var option_div = document.createElement('DIV');
                var main_options_div = document.createElement('DIV');
                main_options_div.classList.add('swipper');
                main_options_div.classList.add('some-animation');
                var main_image_options_div = document.createElement('DIV');
                main_image_options_div.classList.add(
                  'main-options-div-smatest-image'
                );
                main_image_options_div.classList.add('some-animation');
                option_div.classList.add('options-div-smatest');
                var option_question = document.createElement('LABEL');
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == 'he' ||
                      main_lang_code == 'ur' ||
                      main_lang_code == 'ar')) ||
                  (main_lang_code == 'default' &&
                    (language_code == 'ar' ||
                      language_code == 'he' ||
                      language_code == 'ur'))
                ) {
                  option_question.classList.add('rtl');
                }
                option_question.innerHTML = question_arr[k].trim();
                if (k == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (k != question_arr.length - 1) {
                  option_div.classList.add('m-l-40');
                }
                if (k == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  option_question.classList.add('slides-label');
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == 'he' ||
                        main_lang_code == 'ur' ||
                        main_lang_code == 'ar')) ||
                    (main_lang_code == 'default' &&
                      (language_code == 'ar' ||
                        language_code == 'he' ||
                        language_code == 'ur'))
                  ) {
                    option_question.classList.add('rtl');
                  }
                  option_div.appendChild(option_question);
                  option_div.classList.add('options-div-smatest');
                  // main_options_div.classList.add('slides-div-more-smatest');
                  main_options_div.style.height = '270px';
                  main_options_div.style.width = '100%';
                  main_options_div.style.position = 'relative';
                  main_options_div.style.float = 'left';
                  main_options_div.style.overflowY = 'hidden';
                  main_options_div.style.top = '4px';
    
                  var slides_div = document.createElement('DIV');
                  slides_div.classList.add('swiper-container_sb');
                  slides_div.style.overflow = 'hidden';
                  slides_div.style.position = 'relative';
                  slides_div.style.width = '100%';
                  slides_div.style.height = '100%';
                  slides_div.style.perspective = '1000px';
    
                  var wrapper_div = document.createElement('DIV');
                  wrapper_div.classList.add('swiper-wrapper_sb');
                  wrapper_div.style.display = 'flex';
                  wrapper_div.style.transition = 'transform 0.5s ease';
                  wrapper_div.style.transformStyle = 'preserve-3d';
                  wrapper_div.style.height = '100%';
    
                  var prevButton = document.createElement('BUTTON');
                  prevButton.classList.add('swiper-button_sb', 'prev');
                  prevButton.innerText = '❮';
                  prevButton.style.position = 'absolute';
                  prevButton.style.top = '50%';
                  prevButton.style.left = '12%';
                  prevButton.style.transform = 'translateY(-50%)';
                  prevButton.style.background = '#fff';
                  prevButton.style.color = '#000';
                  prevButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px'
                  prevButton.style.border = 'none';
                  prevButton.style.padding = '10px';
                  prevButton.style.cursor = 'pointer';
                  prevButton.style.zIndex = '2';
                  prevButton.style.borderRadius = '50%';
                  prevButton.style.width = '34px';
                  prevButton.style.height = '34px';
                  prevButton.style.display = 'flex';
                  prevButton.style.alignItems = 'center';
                  prevButton.style.justifyContent = 'center';
    
                  var nextButton = document.createElement('BUTTON');
                  nextButton.classList.add('swiper-button_sb', 'next');
                  nextButton.innerText = '❯';
                  nextButton.style.position = 'absolute';
                  nextButton.style.top = '50%';
                  nextButton.style.right = '12%';
                  nextButton.style.transform = 'translateY(-50%)';
                  nextButton.style.background = ' #fff';
                  nextButton.style.color = '#000';
                  nextButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px'
                  nextButton.style.border = 'none';
                  nextButton.style.padding = '10px';
                  nextButton.style.cursor = 'pointer';
                  nextButton.style.zIndex = '2';
                  nextButton.style.borderRadius = '50%';
                  nextButton.style.width = '34px';
                  nextButton.style.height = '34px';
                  nextButton.style.display = 'flex';
                  nextButton.style.alignItems = 'center';
                  nextButton.style.justifyContent = 'center';
    
                  slides_div.appendChild(prevButton);
                  slides_div.appendChild(nextButton);
                  var question_ID = question_array[0]?.id
    
                  if (question_array[0].default_options) {
                    var contact_list =
                      question_array[0].default_options.split(';;');
                    var wo_key;
                    for (var j = 0; j < contact_list.length; j++) {
                      var slides_item = contact_list[j].split('..');
    
                      var slide = document.createElement('DIV');
                      slide.classList.add('swiper-slide_sb');
                      slide.style.position = 'relative';
                      slide.style.flex = '0 0 auto';
                      slide.style.width = '200px';
                      slide.style.height = '240px';
                      slide.style.margin = '10px 10px';
                      slide.style.transition =
                        'transform 0.5s ease, opacity 0.5s ease';
                      slide.style.backfaceVisibility = 'hidden';
                      slide.style.background = 'none';
                      slide.style.padding = '0';
                      slide.style.boxShadow = '0';
                      // slide.classList.add('slides-div-smatest');
                      slides_div.appendChild(wrapper_div);
                      if (font && font.length > 0) {
                        slide.classList.add(font);
                      }
                      
                      if (slides_item[5] == 'image') {
                        if (slides_item[0] == 'null') {
                        } else {
                          var contact_img_a = document.createElement('A');
                          contact_img_a.title = 'Slides image redirection';
                         
                          contact_img_a.href = slides_item[1];
                          contact_img_a.target = '_blank';
                          contact_img_a.style.width = '100%';
                          contact_img_a.style.height = '100%';
                          contact_img_a.style.float = 'left';
                          contact_img_a.style.borderRadius = '10px';
    
                          var contact_image = document.createElement('IMG');
                          contact_image.src = slides_item[0];
                          contact_image.style.width = '100%';
                          contact_image.style.height = '100%';
                          contact_image.style.objectFit = 'cover';
                          contact_image.style.borderRadius = '10px';
    
                          var overley = document.createElement('DIV');
                          overley.style.width = '100%';
                          overley.style.position = 'absolute';
                          overley.style.left = '0';
                          overley.style.bottom = '0';
                          overley.style.height = '45%';
                          overley.style.borderRadius = '10px';
                          overley.style.display = 'block';
                          overley.style.transition = 'all 0.5s ease 0s';
                          overley.style.background =
                            'linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.69) 100%) transparent';
    
                          var slidesOverlay = document.createElement('DIV');
                          slidesOverlay.style.position = 'absolute';
                          slidesOverlay.style.display = 'flex';
                          slidesOverlay.style.flexDirection = 'column';
                          slidesOverlay.style.margin = 'auto';
                          slidesOverlay.style.textAlign = 'center';
                          // slidesOverlay.style.padding = '0px 20px';
                          slidesOverlay.style.bottom = '0px';
                          slidesOverlay.style.width = '100%';
    
                          var contact_title = document.createElement('A');
                          contact_title.innerHTML = slides_item[2];
                          contact_title.href = slides_item[1];
                          contact_title.target = '_blank';
                          contact_title.style.color = '#fff';
                          contact_title.style.marginBottom = '0.5rem';
                          contact_title.style.textAlign = 'left';
                          contact_title.style.marginLeft = '1rem';
                          contact_title.style.marginRight = '1rem';
                          contact_title.style.textDecoration = 'none';
                          contact_title.style.maxWidth = '100%';
                          contact_title.style.overflow = 'hidden';
                          contact_title.style.whiteSpace = 'nowrap';
                          contact_title.style.textOverflow = 'ellipsis';
                          contact_title.style.display = 'inline-block';
                          contact_title.style.lineHeight = '16px';
                          contact_title.style.fontWeight = '500';
                          contact_title.style.fontSize = '14px';
    
                          var contact_desc = document.createElement('A');
                          contact_desc.title = slides_item[6];
                          contact_desc.innerHTML = slides_item[6];
                          contact_desc.target = '_blank';
                          contact_desc.style.color = '#fff';
                          contact_desc.style.marginBottom = '0.5rem';
                          contact_desc.style.textAlign = 'left';
                          contact_desc.style.marginLeft = '1rem';
                          contact_desc.style.marginRight = '1rem';
                          contact_desc.style.textDecoration = 'none';
                          contact_desc.style.maxWidth = '100%';
                          contact_desc.style.overflow = 'hidden';
                          contact_desc.style.whiteSpace = 'nowrap';
                          contact_desc.style.textOverflow = 'ellipsis';
                          contact_desc.style.display = 'inline-block';
                          contact_desc.style.lineHeight = '16px';
                          contact_desc.style.fontWeight = '500';
                          contact_desc.style.fontSize = '12px';
    
                          if (font && font.length > 0) {
                            contact_title.classList.add(font);
                            contact_desc.classList.add(font);
                          }
    
                          if (slides_item[3] && slides_item[3].length > 0) {
                            var btnDiv = document.createElement('DIV');
                            btnDiv.classList.add('btn-div-smatest');
                            var contact_button = document.createElement('button');
                            contact_button.style.padding = '0';
                            contact_button.style.border = '0';
                            contact_button.style.background = 'transparent';
                            contact_button.style.float = 'left';
                            contact_button.style.width = '100%';
                            contact_button.style.display = 'inline-block';
                            var contact_btn_a = document.createElement('A');
                            contact_btn_a.title = 'Slides button redirection';
                            var button_text = document.createTextNode(slides_item[3]);
                            contact_btn_a.appendChild(button_text);
                            contact_btn_a.classList.add('btn-a');
                            contact_btn_a.href = slides_item[4];
                            contact_btn_a.target = '_blank';
                            contact_button.appendChild(contact_btn_a);
                            contact_btn_a.classList.add('contact-btn-smatest');
                            contact_btn_a.style.float = 'left';
                            contact_btn_a.style.fontSize = '12px';
                            contact_btn_a.style.padding = '8px 15px';
                            contact_btn_a.style.marginLeft = '15px';
                            contact_btn_a.style.marginTop = '5px';
                            contact_btn_a.style.cssText =
                              contact_btn_a.style.cssText + 'width:calc(100% - 30px)';
                            contact_btn_a.style.boxSizing = 'border-box';
                            
                            if (font && font.length > 0) {
                              contact_button.classList.add(font);
                            }
                            
                            btnDiv.appendChild(contact_button);
                            
                          }
    
                          contact_img_a.appendChild(contact_image);
                          slide.appendChild(contact_img_a);
                          if(question_ID == '2393737'){
                          }else{
                            slide.appendChild(overley);
                            slide.appendChild(slidesOverlay);
                            slidesOverlay.appendChild(contact_title);
                            slidesOverlay.appendChild(contact_desc);
                            slidesOverlay.appendChild(contact_button);
                          }
    
                        }
                      } else if (slides_item[5] == 'video') {
                        var video_frame = document.createElement('IFRAME');
                        var embed_str;
                        if (
                          slides_item[0] &&
                          slides_item[0].includes('youtube') &&
                          slides_item[0].includes('watch?v=')
                        ) {
                          embed_str = slides_item[0].split('watch?v=')[1];
                        } else if (
                          slides_item[0].includes('youtube') ||
                          slides_item[0].includes('youtu.be')
                        ) {
                          var arr = slides_item[0].split('/');
                          embed_str = arr[arr.length - 1];
                        }
                        video_frame.src =
                          'https://www.youtube.com/embed/' + embed_str;
                        video_frame.frameborder = 0;
                        video_frame.classList.add('contact-image-smatest');
                        video_frame.style.borderRadius = '10px';
                        slide.appendChild(video_frame);
                      } else {
    
                        var contact_img_a = document.createElement('A');
                        contact_img_a.title = 'Slides image redirection';
                       
                        contact_img_a.href = slides_item[1];
                        contact_img_a.target = '_blank';
                        contact_img_a.style.width = '100%';
                        contact_img_a.style.height = '100%';
                        contact_img_a.style.float = 'left';
                        contact_img_a.style.borderRadius = '10px';
    
                        var contact_image = document.createElement('IMG');
                        contact_image.src = slides_item[0];
                        contact_image.style.width = '100%';
                        contact_image.style.height = '100%';
                        contact_image.style.objectFit = 'cover';
                        contact_image.style.borderRadius = '10px';
    
                        contact_img_a.appendChild(contact_image);
                        slide.appendChild(contact_img_a);
    
                      }
                      
                      wrapper_div.appendChild(slide);
                    }
                  }
                  
                  var activeIndex = 0;
                  var autoScrollInterval;
                  var autoSlideEnabled = false;
                  var autoSlideTimeTnterval = 1000;
    
                  function updateSlides() {
                    var containerWidth = slides_div?.offsetWidth;
                    let slideWidthWithMargin = 200 + 20
                    if(contact_list?.length > 15){
                       slideWidthWithMargin = 200 + 21.5
                    }else{
                       slideWidthWithMargin = 200 + 20
                    }
                    const offset =
                      -activeIndex * slideWidthWithMargin +
                      containerWidth / 2 -
                      slideWidthWithMargin / 2;
                    
                    wrapper_div.style.transform = `translateX(${offset}px)`;
                    Array.from(wrapper_div.children).forEach((slide, index) => {
                      slide.classList.remove('active', 'left', 'right');
                      if (index == activeIndex) {
                        slide.classList.add('active');
                        slide.style.transform = 'translateZ(0px) scale(1.1)';
                        slide.style.zIndex = '1';
                      } else if (index < activeIndex) {
                        slide.classList.add('left');
                        slide.style.transform = 'translateZ(-100px) rotateY(50deg)';
                      } else {
                        slide.classList.add('right');
                        slide.style.transform =
                          'translateZ(-100px) rotateY(-50deg)';
                      }
                    });
    
                    prevButton.disabled = activeIndex == 0;
                    nextButton.disabled = activeIndex == contact_list?.length - 1;
                    if (prevButton.disabled) {
                      prevButton.style.opacity = '0.3';
                      prevButton.style.cursor = 'not-allowed';
                    } else {
                      prevButton.style.opacity = '1';
                      prevButton.style.cursor = 'pointer';
                    }
    
                    if (nextButton.disabled) {
                      nextButton.style.opacity = '0.3';
                      nextButton.style.cursor = 'not-allowed';
                    } else {
                      nextButton.style.opacity = '1';
                      nextButton.style.cursor = 'pointer';
                    }
                  }
                  function startAutoScroll() {
                    if (autoSlideEnabled) {
                      autoScrollInterval = setInterval(() => {
                        activeIndex = (activeIndex + 1) % contact_list?.length;
                        updateSlides();
                      }, autoSlideTimeTnterval); 
                    }
                  }
    
                  function stopAutoScroll() {
                    clearInterval(autoScrollInterval);
                  }
    
                  prevButton.addEventListener('click', () => {
                    stopAutoScroll();
                    if (activeIndex > 0) {
                      activeIndex--;
                    }
                    updateSlides();
                  });
    
                  nextButton.addEventListener('click', () => {
                    stopAutoScroll();
                    if (activeIndex < contact_list.length - 1) {
                      activeIndex++;
                    }
                    updateSlides();
                  });
    
    
                  if (
                    question_array[0].auto_slide && 
                    question_array[0].auto_slide.length > 0 && 
                    parseInt(question_array[0].auto_slide) > 0
                    ) {
                    autoSlideEnabled = true;
                    autoSlideTimeTnterval = parseInt(question_array[0].auto_slide) * 1000 + 1000;
                  }
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    main_options_div.appendChild(slides_div);
                 
                  }
                  if (
                    question_array[0].is_feedback &&
                    question_array[0].is_feedback == '1'
                  ) {
                    option_div.style.marginBottom = '15px';
                    addQuestionFeedback(option_div, question_array);
                  }
                }

                setTimeout(() => {
                  updateSlides();
                  startAutoScroll();
                }, 1000);
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement('DIV');
                var spinnerDiv = document.createElement('DIV');
                spinnerDiv.classList.add('spinner1-smatest');
                var ques_icon = document.createElement('IMG');
                ques_icon.alt = 'Logo of ' + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add('question-icon-smatest');
                var inner1 = document.createElement('DIV');
                inner1.classList.add('bounce1');
                var inner2 = document.createElement('DIV');
                inner2.classList.add('bounce2');
                var inner3 = document.createElement('DIV');
                inner3.classList.add('bounce3');
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add('m-l-40');
                otherSpinningDIv.classList.add('m-t-5');
                otherSpinningDIv.classList.add('pull-left');
                otherSpinningDIv.appendChild(spinnerDiv);
                if (k != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (k == 0) {
                  if (k == question_arr.length - 1) {
                    setTimeout(function () {
                      takingRadioValue('something', option_div, 1);
                    }, delay_time);
                  }
                  k++;
                  if (k == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    if (k == question_arr.length - 1) {
                      setTimeout(function () {
                        takingRadioValue('something', option_div, 1);
                      }, delay_time);
                    }
                    k++;
                    if (k == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add('m-t-5');
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callImagesSlider(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes('{{') &&
            question_array[0].question_text.includes('}}')
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;
        
            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement('DIV');
                questionDIv.classList.add('question-div-smatest');
                setTimeout(function () {
                  questionDIv.classList.add('top-0');
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement('IMG');
                ques_icon1.alt = 'Logo of ' + totalData[0].name;
                var iconDiv = document.createElement('DIV');
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add('question-icon-div');
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add('question-icon-smatest');
                var option_div = document.createElement('DIV');
                var main_options_div = document.createElement('DIV');
                main_options_div.classList.add('swipper');
                main_options_div.classList.add('some-animation');
                option_div.classList.add('options-div-smatest');
                var option_question = document.createElement('LABEL');
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == 'he' ||
                      main_lang_code == 'ur' ||
                      main_lang_code == 'ar')) ||
                  (main_lang_code == 'default' &&
                    (language_code == 'ar' ||
                      language_code == 'he' ||
                      language_code == 'ur'))
                ) {
                  option_question.classList.add('rtl');
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add('m-l-40');
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  option_div.classList.add('m-b-10');
                  iconDiv.classList.add('m-b-10');
                  option_div.classList.add('options-div-smatest');
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    main_options_div.style.height = '270px';
                  }
                  main_options_div.style.width = '100%';
                  main_options_div.style.position = 'relative';
                  main_options_div.style.float = 'left';
                  main_options_div.style.overflowY = 'hidden';
                  main_options_div.style.top = '4px';
        
                  var slides_div = document.createElement('DIV');
                  slides_div.classList.add('swiper-container_sb');
                  slides_div.style.overflow = 'hidden';
                  slides_div.style.position = 'relative';
                  slides_div.style.width = '100%';
                  slides_div.style.height = '100%';
                  slides_div.style.perspective = '1000px';
        
                  var wrapper_div = document.createElement('DIV');
                  wrapper_div.classList.add('swiper-wrapper_sb');
                  wrapper_div.style.display = 'flex';
                  wrapper_div.style.transition = 'transform 0.5s ease';
                  wrapper_div.style.transformStyle = 'preserve-3d';
                  wrapper_div.style.height = '100%';
        
                  var prevButton = document.createElement('BUTTON');
                  prevButton.classList.add('swiper-button_sb', 'prev');
                  prevButton.innerText = '❮';
                  prevButton.style.position = 'absolute';
                  prevButton.style.top = '50%';
                  prevButton.style.left = '12%';
                  prevButton.style.transform = 'translateY(-50%)';
                  prevButton.style.background = '#fff';
                  prevButton.style.color = '#000';
                  prevButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                  prevButton.style.border = 'none';
                  prevButton.style.padding = '10px';
                  prevButton.style.cursor = 'pointer';
                  prevButton.style.zIndex = '2';
                  prevButton.style.borderRadius = '50%';
                  prevButton.style.width = '34px';
                  prevButton.style.height = '34px';
                  prevButton.style.display = 'flex';
                  prevButton.style.alignItems = 'center';
                  prevButton.style.justifyContent = 'center';
        
                  var nextButton = document.createElement('BUTTON');
                  nextButton.classList.add('swiper-button_sb', 'next');
                  nextButton.innerText = '❯';
                  nextButton.style.position = 'absolute';
                  nextButton.style.top = '50%';
                  nextButton.style.right = '12%';
                  nextButton.style.transform = 'translateY(-50%)';
                  nextButton.style.background = ' #fff';
                  nextButton.style.color = '#000';
                  nextButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                  nextButton.style.border = 'none';
                  nextButton.style.padding = '10px';
                  nextButton.style.cursor = 'pointer';
                  nextButton.style.zIndex = '2';
                  nextButton.style.borderRadius = '50%';
                  nextButton.style.width = '34px';
                  nextButton.style.height = '34px';
                  nextButton.style.display = 'flex';
                  nextButton.style.alignItems = 'center';
                  nextButton.style.justifyContent = 'center';
        
                  slides_div.appendChild(prevButton);
                  slides_div.appendChild(nextButton);
        
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var contact_list = question_array[0].default_options.split(';;');
                    var wo_key;
                    for (var k = 0; k < contact_list.length; k++) {
                      var slide = document.createElement('DIV');
                      slide.classList.add('swiper-slide_sb');
                      slide.style.flex = '0 0 auto';
                      slide.style.width = '200px';
                      slide.style.height = '240px';
                      slide.style.margin = '10px 10px';
                      slide.style.transition = 'transform 0.5s ease, opacity 0.5s ease';
                      slide.style.backfaceVisibility = 'hidden';
        
                      var contact_img_a = document.createElement('A');
                      // contact_img_a.title = 'Images slider';
                      contact_img_a.href = contact_list[k];
                      contact_img_a.target = '_blank';
                      contact_img_a.style.width = '100%';
                      contact_img_a.style.height = '100%';
                      contact_img_a.style.float = 'left';
                      contact_img_a.style.borderRadius = '10px';
        
                      var contact_image = document.createElement('IMG');
                      contact_image.src = contact_list[k];
                      contact_image.style.width = '100%';
                      contact_image.style.height = '100%';
                      contact_image.style.objectFit = 'cover';
                      contact_image.style.borderRadius = '10px';
        
                      contact_img_a.appendChild(contact_image);
                      slide.appendChild(contact_img_a);
                      wrapper_div.appendChild(slide);
                    }
                    slides_div.appendChild(wrapper_div);
        
                  }
        
                  var activeIndex = 0;
                  var autoScrollInterval;
                  var autoSlideEnabled = false;
                  var autoSlideTimeTnterval = 1000;
        
                  function updateSlides() {
                    var containerWidth = slides_div?.offsetWidth;
                    const slideWidthWithMargin = 200 + 20;
                    const offset = -activeIndex * slideWidthWithMargin + containerWidth / 2 - slideWidthWithMargin / 2;
                    wrapper_div.style.transform = `translateX(${offset}px)`;
                    Array.from(wrapper_div.children).forEach((slide, index) => {
                      slide.classList.remove('active', 'left', 'right');
                      if (index == activeIndex) {
                        slide.classList.add('active');
                        slide.style.transform = 'translateZ(0px) scale(1.1)';
                        slide.style.zIndex = '1';
                      } else if (index < activeIndex) {
                        slide.classList.add('left');
                        slide.style.transform = 'translateZ(-100px) rotateY(50deg)';
                      } else {
                        slide.classList.add('right');
                        slide.style.transform = 'translateZ(-100px) rotateY(-50deg)';
                      }
                    });
        
                    prevButton.disabled = activeIndex == 0;
                    nextButton.disabled = activeIndex == contact_list?.length - 1;
                    if (prevButton.disabled) {
                      prevButton.style.opacity = '0.3';
                      prevButton.style.cursor = 'not-allowed';
                    } else {
                      prevButton.style.opacity = '1';
                      prevButton.style.cursor = 'pointer';
                    }
        
                    if (nextButton.disabled) {
                      nextButton.style.opacity = '0.3';
                      nextButton.style.cursor = 'not-allowed';
                    } else {
                      nextButton.style.opacity = '1';
                      nextButton.style.cursor = 'pointer';
                    }
                  }
        
                  function startAutoScroll() {
                    if (autoSlideEnabled) {
                      autoScrollInterval = setInterval(() => {
                        activeIndex = (activeIndex + 1) % contact_list?.length;
                        updateSlides();
                      }, autoSlideTimeTnterval);
                    }
                  }
        
                  function stopAutoScroll() {
                    clearInterval(autoScrollInterval);
                  }
        
                  prevButton.addEventListener('click', () => {
                    stopAutoScroll();
                    if (activeIndex > 0) {
                      activeIndex--;
                    }
                    updateSlides();
                  });
        
                  nextButton.addEventListener('click', () => {
                    stopAutoScroll();
                    if (activeIndex < contact_list.length - 1) {
                      activeIndex++;
                    }
                    updateSlides();
                  });
                
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    main_options_div.appendChild(slides_div);
                    if (
                      question_array[0].auto_slide &&
                      question_array[0].auto_slide.length > 0 &&
                      parseInt(question_array[0].auto_slide) > 0
                    ) {
                      autoSlideEnabled = true;
                      autoSlideTimeTnterval =
                        parseInt(question_array[0].auto_slide) * 1000;
                    }
                  }
                  if (
                    question_array[0].is_feedback &&
                    question_array[0].is_feedback == '1'
                  ) {
                    option_div.style.marginBottom = '15px';
                    addQuestionFeedback(option_div, question_array);
                  }
                }
                setTimeout(() => {
                  updateSlides();
                  startAutoScroll();
                }, 1000);
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement('DIV');
                var spinnerDiv = document.createElement('DIV');
                spinnerDiv.classList.add('spinner1-smatest');
                var ques_icon = document.createElement('IMG');
                ques_icon.alt = 'Logo of ' + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add('question-icon-smatest');
                var inner1 = document.createElement('DIV');
                inner1.classList.add('bounce1');
                var inner2 = document.createElement('DIV');
                inner2.classList.add('bounce2');
                var inner3 = document.createElement('DIV');
                inner3.classList.add('bounce3');
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add('m-l-40');
                otherSpinningDIv.classList.add('m-t-5');
                otherSpinningDIv.classList.add('pull-left');
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  if (j == question_arr.length - 1) {
                    option_div.classList.remove('m-b-10');
                    iconDiv.classList.remove('m-b-10');
                    setTimeout(function () {
                      takingRadioValue('something', option_div, 1);
                    }, delay_time);
                  }
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    if (j == question_arr.length - 1) {
                      option_div.classList.remove('m-b-10');
                      iconDiv.classList.remove('m-b-10');
                      setTimeout(function () {
                        takingRadioValue('something', option_div, 1);
                      }, delay_time);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add('m-t-5');
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callRadioSlides(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes('{{') &&
            question_array[0].question_text.includes('}}')
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var k = 0;
            var speakable_str = '';
        
            function addQuestionArrays() {
              if (k < question_arr.length) {
                var questionDIv = document.createElement('DIV');
                questionDIv.classList.add('question-div-smatest');
                setTimeout(function () {
                  questionDIv.classList.add('top-0');
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement('IMG');
                ques_icon1.alt = 'Logo of ' + totalData[0].name;
                var iconDiv = document.createElement('DIV');
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add('question-icon-div');
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add('question-icon-smatest');
                var option_div = document.createElement('DIV');
                var main_options_div = document.createElement('DIV');
                main_options_div.classList.add('swipper');
                main_options_div.classList.add('some-animation');
                var main_image_options_div = document.createElement('DIV');
                main_image_options_div.classList.add('main-options-div-smatest-image');
                main_image_options_div.classList.add('some-animation');
                option_div.classList.add('options-div-smatest');
                var option_question = document.createElement('LABEL');
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == 'he' ||
                      main_lang_code == 'ur' ||
                      main_lang_code == 'ar')) ||
                  (main_lang_code == 'default' &&
                    (language_code == 'ar' ||
                      language_code == 'he' ||
                      language_code == 'ur'))
                ) {
                  option_question.classList.add('rtl');
                }
                option_question.innerHTML = question_arr[k].trim();
                speakable_str = speakable_str + ' ' + option_question.innerText;
                option_div.appendChild(option_question);
                if (k != question_arr.length - 1) {
                  option_div.classList.add('m-l-40');
                }
                if (k == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  option_question.classList.add('slides-label');
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == 'he' ||
                        main_lang_code == 'ur' ||
                        main_lang_code == 'ar')) ||
                    (main_lang_code == 'default' &&
                      (language_code == 'ar' ||
                        language_code == 'he' ||
                        language_code == 'ur'))
                  ) {
                    option_question.classList.add('rtl');
                  }
                  option_div.appendChild(option_question);
                  option_div.classList.add('options-div-smatest');
                  // main_options_div.classList.add('slides-div-more-smatest');
                  var slides_div = document.createElement('DIV');
                  // main_options_div.style.height = '240px';
                  slides_div.classList.add('avatar-scrollbar');
                  slides_div.classList.add('slides-random');
                  slides_div.classList.add(
                    'radio-slider-auto-rotate' + question_array[0].id
                  );
                  slides_div.id = 'avatar-scroll';
        
                  main_options_div.style.height = '270px';
                  main_options_div.style.width = '100%';
                  main_options_div.style.position = 'relative';
                  main_options_div.style.float = 'left';
                  main_options_div.style.overflowY = 'hidden';
                  main_options_div.style.top = '4px';
        
                  var slides_div = document.createElement('DIV');
                  slides_div.classList.add('swiper-container_sb');
                  slides_div.style.overflow = 'hidden';
                  slides_div.style.position = 'relative';
                  slides_div.style.width = '100%';
                  slides_div.style.height = '100%';
                  slides_div.style.perspective = '1000px';
        
                  var wrapper_div = document.createElement('DIV');
                  wrapper_div.classList.add('swiper-wrapper_sb');
                  wrapper_div.style.display = 'flex';
                  wrapper_div.style.transition = 'transform 0.5s ease';
                  wrapper_div.style.transformStyle = 'preserve-3d';
                  wrapper_div.style.height = '100%';
        
                  var prevButton = document.createElement('BUTTON');
                  prevButton.classList.add('swiper-button_sb', 'prev');
                  prevButton.innerText = '❮';
                  prevButton.style.position = 'absolute';
                  prevButton.style.top = '50%';
                  prevButton.style.left = '12%';
                  prevButton.style.transform = 'translateY(-50%)';
                  prevButton.style.background = '#fff';
                  prevButton.style.color = '#000';
                  prevButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                  prevButton.style.border = 'none';
                  prevButton.style.padding = '10px';
                  prevButton.style.cursor = 'pointer';
                  prevButton.style.zIndex = '2';
                  prevButton.style.borderRadius = '50%';
                  prevButton.style.width = '34px';
                  prevButton.style.height = '34px';
                  prevButton.style.display = 'flex';
                  prevButton.style.alignItems = 'center';
                  prevButton.style.justifyContent = 'center';
        
                  var nextButton = document.createElement('BUTTON');
                  nextButton.classList.add('swiper-button_sb', 'next');
                  nextButton.innerText = '❯';
                  nextButton.style.position = 'absolute';
                  nextButton.style.top = '50%';
                  nextButton.style.right = '12%';
                  nextButton.style.transform = 'translateY(-50%)';
                  nextButton.style.background = ' #fff';
                  nextButton.style.color = '#000';
                  nextButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                  nextButton.style.border = 'none';
                  nextButton.style.padding = '10px';
                  nextButton.style.cursor = 'pointer';
                  nextButton.style.zIndex = '2';
                  nextButton.style.borderRadius = '50%';
                  nextButton.style.width = '34px';
                  nextButton.style.height = '34px';
                  nextButton.style.display = 'flex';
                  nextButton.style.alignItems = 'center';
                  nextButton.style.justifyContent = 'center';
        
                  slides_div.appendChild(prevButton);
                  slides_div.appendChild(nextButton);
        
                  if (question_array[0].default_options) {
                    var contact_list = question_array[0].default_options.split(';;');
                    var wo_key;
                    for (var j = 0; j < contact_list.length; j++) {
                      var slides_item = contact_list[j].split('..');
                      if (slides_item.length > 2) {
                        if (
                          chatbot_id == '18664' ||
                          chatbot_id == '19819' ||
                          chatbot_id == "20097" 
                        ) {
                          var slide = document.createElement('DIV');
                          slide.classList.add('swiper-slide_sb');
                          slide.style.flex = '0 0 auto';
                          slide.style.width = '200px';
                          slide.style.height = '240px';
                          slide.style.margin = '10px 10px';
                          slide.style.transition = 'transform 0.5s ease, opacity 0.5s ease';
                          slide.style.backfaceVisibility = 'hidden';
                          slide.style.background = 'none';
                          slide.style.padding = '0';
                          slide.style.boxShadow = '0';
                  
                          slide.classList.add('slides-div-smatest');
                  
                          if (font && font.length > 0) {
                            slide.classList.add(font);
                          }
                  
                          var contact_div_inside = document.createElement('DIV');
                          contact_div_inside.style.width = '100%';
                          contact_div_inside.style.height = '100%';
                          contact_div_inside.style.float = 'left';
                          contact_div_inside.style.borderRadius = '10px';
                          contact_div_inside.style.position = 'relative';
                  
                          var contact_image = document.createElement('IMG');
                          contact_image.src = slides_item[1];
                          contact_image.style.width = '100%';
                          contact_image.style.height = '100%';
                          contact_image.style.objectFit = 'cover';
                          contact_image.style.borderRadius = '10px';
                  
                          var overley = document.createElement('DIV');
                          overley.style.width = '100%';
                          overley.style.position = 'absolute';
                          overley.style.left = '0';
                          overley.style.bottom = '0';
                          overley.style.height = '45%';
                          overley.style.borderRadius = '10px';
                          overley.style.display = 'block';
                          overley.style.transition = 'all 0.5s ease 0s';
                          overley.style.background =
                            'linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.69) 100%) transparent';
                  
                          var radio_div = document.createElement('DIV');
                          radio_div.style.display = 'flex';
                          radio_div.style.alignItems = 'center';
                          radio_div.style.flexDirection = 'column';
                          radio_div.style.width = '100%';
                          radio_div.style.bottom = '1rem';
                          radio_div.style.gap = '0.3rem';
                          radio_div.style.position = 'absolute';
                  
                          overley.appendChild(radio_div);
                          contact_div_inside.appendChild(contact_image);
                          contact_div_inside.appendChild(overley);
                  
                          slide.appendChild(contact_div_inside);
                          wrapper_div.appendChild(slide);
                          slides_div.appendChild(wrapper_div);
                          if (font && font.length > 0) {
                            radio_div.classList.add(font);
                          }
                          var radio_text = document.createElement('label');
                          var span = document.createElement('span');
                          var option = document.createTextNode(slides_item[0]);
                          span.appendChild(option);
                          speakable_str = speakable_str + ' ' + span.innerText;
                          if (j != contact_list.length - 1) {
                            speakable_str = speakable_str + ' or ';
                          }
                          var check = document.createElement('DIV');
                          check.classList.add('check-smatest');
                          var radio = document.createElement('input');
                          radio.type = 'radio';
                          radio.name = 'radio_option';
                          radio.value = slides_item[0];
                          radio.classList.add('radio-botest');
                          radio_text.classList.add('radio-slide-label');
                          radio_text.style.margin = '0px';
                          radio_text.style.fontSize = '12px';
                          radio_text.style.cssText =
                            radio_text.style.cssText + 'padding:8px 15px !important';
                          radio_text.style.cssText =
                            radio_text.style.cssText + 'width:calc(100% - 20px)';
                          radio_text.appendChild(radio);
                          radio_text.appendChild(check);
                          radio_text.appendChild(span);
                          radio.addEventListener('click', function (k) {
                            if (agreed) {
                              takingRadioValue(this.value, main_options_div);
                            } else {
                              k.preventDefault();
                            }
                          });
                          radio_div.appendChild(radio_text);
                        } else {
                          var slide = document.createElement('DIV');
                          slide.classList.add('swiper-slide_sb');
                          slide.style.flex = '0 0 auto';
                          slide.style.width = '200px';
                          slide.style.height = '240px';
                          slide.style.margin = '10px 10px';
                          slide.style.transition = 'transform 0.5s ease, opacity 0.5s ease';
                          slide.style.backfaceVisibility = 'hidden';
                          slide.style.background = 'none';
                          slide.style.padding = '0';
                          slide.style.boxShadow = '0';
                  
                          slide.classList.add('slides-div-smatest');
                  
                          if (font && font.length > 0) {
                            slide.classList.add(font);
                          }
                  
                          var contact_div_inside = document.createElement('DIV');
                          contact_div_inside.style.width = '100%';
                          contact_div_inside.style.height = '100%';
                          contact_div_inside.style.float = 'left';
                          contact_div_inside.style.borderRadius = '10px';
                          contact_div_inside.style.position = 'relative';
                  
                          var contact_image = document.createElement('IMG');
                          contact_image.src = slides_item[1];
                          contact_image.style.width = '100%';
                          contact_image.style.height = '100%';
                          contact_image.style.objectFit = 'cover';
                          contact_image.style.borderRadius = '10px';
                  
                          var overley = document.createElement('DIV');
                          overley.style.width = '100%';
                          overley.style.position = 'absolute';
                          overley.style.left = '0';
                          overley.style.bottom = '0';
                          overley.style.height = '45%';
                          overley.style.borderRadius = '10px';
                          overley.style.display = 'block';
                          overley.style.transition = 'all 0.5s ease 0s';
                          overley.style.background =
                            'linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.69) 100%) transparent';
                  
                          var radio_div = document.createElement('DIV');
                          radio_div.style.display = 'flex';
                          radio_div.style.alignItems = 'center';
                          radio_div.style.flexDirection = 'column';
                          radio_div.style.width = '100%';
                          radio_div.style.bottom = '1rem';
                          radio_div.style.gap = '0.3rem';
                          radio_div.style.position = 'absolute';
                  
                          overley.appendChild(radio_div);
                          contact_div_inside.appendChild(contact_image);
                          contact_div_inside.appendChild(overley);
                  
                          slide.appendChild(contact_div_inside);
                          wrapper_div.appendChild(slide);
                          slides_div.appendChild(wrapper_div);
                          if (font && font.length > 0) {
                            radio_div.classList.add(font);
                          }
                          var radio_text = document.createElement('label');
                          var span = document.createElement('span');
                          var option = document.createTextNode(slides_item[0]);
                          span.appendChild(option);
                          speakable_str = speakable_str + ' ' + span.innerText;
                          if (j != contact_list.length - 1) {
                            speakable_str = speakable_str + ' or ';
                          }
                          var check = document.createElement('DIV');
                          check.classList.add('check-smatest');
                          var radio = document.createElement('input');
                          radio.type = 'radio';
                          radio.name = 'radio_option';
                          radio.value = slides_item[0];
                          radio.classList.add('radio-botest');
                          radio_text.classList.add('radio-slide-label');
                          radio_text.style.margin = '0px';
                          radio_text.style.fontSize = '12px';
                          radio_text.style.cssText =
                            radio_text.style.cssText + 'padding:8px 15px !important';
                          radio_text.style.cssText =
                            radio_text.style.cssText + 'width:calc(100% - 20px)';
                          radio_text.appendChild(radio);
                          radio_text.appendChild(check);
                          radio_text.appendChild(span);
                          radio.addEventListener('click', function (k) {
                            if (agreed) {
                              takingRadioValue(this.value, main_options_div);
                            } else {
                              k.preventDefault();
                            }
                          });
                          radio_div.appendChild(radio_text);
                        }
                      } else {
                        var slide = document.createElement('DIV');
                        slide.classList.add('swiper-slide_sb');
                        slide.style.flex = '0 0 auto';
                        slide.style.width = '200px';
                        slide.style.height = '240px';
                        slide.style.margin = '10px 10px';
                        slide.style.transition = 'transform 0.5s ease, opacity 0.5s ease';
                        slide.style.backfaceVisibility = 'hidden';
                        slide.style.background = 'none';
                        slide.style.padding = '0';
                        slide.style.boxShadow = '0';
                  
                        slide.classList.add('slides-div-smatest');
                  
                        if (font && font.length > 0) {
                          slide.classList.add(font);
                        }
                  
                        var contact_div_inside = document.createElement('DIV');
                        contact_div_inside.style.width = '100%';
                        contact_div_inside.style.height = '100%';
                        contact_div_inside.style.float = 'left';
                        contact_div_inside.style.borderRadius = '10px';
                        contact_div_inside.style.position = 'relative';
                  
                        var contact_image = document.createElement('IMG');
                        contact_image.src = slides_item[1];
                        contact_image.style.width = '100%';
                        contact_image.style.height = '100%';
                        contact_image.style.objectFit = 'cover';
                        contact_image.style.borderRadius = '10px';
                  
                        var overley = document.createElement('DIV');
                        overley.style.width = '100%';
                        overley.style.position = 'absolute';
                        overley.style.left = '0';
                        overley.style.bottom = '0';
                        overley.style.height = '45%';
                        overley.style.borderRadius = '10px';
                        overley.style.display = 'block';
                        overley.style.transition = 'all 0.5s ease 0s';
                        overley.style.background =
                          'linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.69) 100%) transparent';
                  
                        var radio_div = document.createElement('DIV');
                        radio_div.style.display = 'flex';
                        radio_div.style.alignItems = 'center';
                        radio_div.style.flexDirection = 'column';
                        radio_div.style.width = '100%';
                        radio_div.style.bottom = '1rem';
                        radio_div.style.gap = '0.3rem';
                        radio_div.style.position = 'absolute';
                  
                        overley.appendChild(radio_div);
                        contact_div_inside.appendChild(contact_image);
                        contact_div_inside.appendChild(overley);
                  
                        slide.appendChild(contact_div_inside);
                        wrapper_div.appendChild(slide);
                        slides_div.appendChild(wrapper_div);
                        if (font && font.length > 0) {
                          radio_div.classList.add(font);
                        }
                        var radio_text = document.createElement('label');
                        var span = document.createElement('span');
                        var option = document.createTextNode(slides_item[0]);
                        span.appendChild(option);
                        speakable_str = speakable_str + ' ' + span.innerText;
                        if (j != contact_list.length - 1) {
                          speakable_str = speakable_str + ' or ';
                        }
                        var check = document.createElement('DIV');
                        check.classList.add('check-smatest');
                        var radio = document.createElement('input');
                        radio.type = 'radio';
                        radio.name = 'radio_option';
                        radio.value = slides_item[0];
                        radio.classList.add('radio-botest');
                        radio_text.classList.add('radio-slide-label');
                        radio_text.style.margin = '0px';
                        radio_text.style.fontSize = '12px';
                        radio_text.style.cssText =
                          radio_text.style.cssText + 'padding:8px 15px !important';
                        radio_text.style.cssText =
                          radio_text.style.cssText + 'width:calc(100% - 20px)';
                        radio_text.appendChild(radio);
                        radio_text.appendChild(check);
                        radio_text.appendChild(span);
                        radio.addEventListener('click', function (k) {
                          if (agreed) {
                            takingRadioValue(this.value, main_options_div);
                          } else {
                            k.preventDefault();
                          }
                        });
                        radio_div.appendChild(radio_text);
                      }
                    }
                  }
                  
        
                  let activeIndex = 0;
                  let autoScrollInterval;
                  let autoSlideEnabled = false;
                  let autoSlideTimeTnterval = 1000;
        
                  function updateSlides() {
                    var containerWidth = slides_div?.offsetWidth;
                    const slideWidthWithMargin = 200 + 20;
                    const offset =
                      -activeIndex * slideWidthWithMargin +
                      containerWidth / 2 -
                      slideWidthWithMargin / 2;
                    wrapper_div.style.transform = `translateX(${offset}px)`;
                    Array.from(wrapper_div.children).forEach((slide, index) => {
                      slide.classList.remove('active', 'left', 'right');
                      if (index == activeIndex) {
                        slide.classList.add('active');
                        slide.style.transform = 'translateZ(0px) scale(1.1)';
                        slide.style.zIndex = '1';
                      } else if (index < activeIndex) {
                        slide.classList.add('left');
                        slide.style.transform = 'translateZ(-100px) rotateY(50deg)';
                      } else {
                        slide.classList.add('right');
                        slide.style.transform = 'translateZ(-100px) rotateY(-50deg)';
                      }
                    });
        
                    prevButton.disabled = activeIndex == 0;
                    nextButton.disabled = activeIndex == contact_list?.length - 1;
                    if (prevButton.disabled) {
                      prevButton.style.opacity = '0.3';
                      prevButton.style.cursor = 'not-allowed';
                    } else {
                      prevButton.style.opacity = '1';
                      prevButton.style.cursor = 'pointer';
                    }
        
                    if (nextButton.disabled) {
                      nextButton.style.opacity = '0.3';
                      nextButton.style.cursor = 'not-allowed';
                    } else {
                      nextButton.style.opacity = '1';
                      nextButton.style.cursor = 'pointer';
                    }
                  }
                  function startAutoScroll() {
                    if (autoSlideEnabled) {
                      autoScrollInterval = setInterval(() => {
                        activeIndex = (activeIndex + 1) % contact_list?.length;
                        updateSlides();
                      }, autoSlideTimeTnterval);
                    }
                  }
        
                  function stopAutoScroll() {
                    clearInterval(autoScrollInterval);
                  }
        
                  prevButton.addEventListener('click', () => {
                    stopAutoScroll();
                    if (activeIndex > 0) {
                      activeIndex--;
                    }
                    updateSlides();
                  });
        
                  nextButton.addEventListener('click', () => {
                    stopAutoScroll();
                    if (activeIndex < contact_list.length - 1) {
                      activeIndex++;
                    }
                    updateSlides();
                  });
                  if (
                    question_array[0].auto_slide &&
                    question_array[0].auto_slide.length > 0 &&
                    parseInt(question_array[0].auto_slide) > 0
                  ) {
                    autoSlideEnabled = true;
                    autoSlideTimeTnterval =
                      parseInt(question_array[0].auto_slide) * 1000 + 1000;
                  }
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    main_options_div.appendChild(slides_div);
                  }
                }
                setTimeout(() => {
                  updateSlides();
                  startAutoScroll();
                }, 1000)
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement('DIV');
                var spinnerDiv = document.createElement('DIV');
                spinnerDiv.classList.add('spinner1-smatest');
                var ques_icon = document.createElement('IMG');
                ques_icon.alt = 'Logo of ' + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add('question-icon-smatest');
                var inner1 = document.createElement('DIV');
                inner1.classList.add('bounce1');
                var inner2 = document.createElement('DIV');
                inner2.classList.add('bounce2');
                var inner3 = document.createElement('DIV');
                inner3.classList.add('bounce3');
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add('m-l-40');
                otherSpinningDIv.classList.add('m-t-5');
                otherSpinningDIv.classList.add('pull-left');
                otherSpinningDIv.appendChild(spinnerDiv);
                if (k != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (k == 0) {
                  k++;
                  if (k == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    k++;
                    if (k == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add('m-t-5');
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callCustomSingleChoice(question_array) {
          if (!firstCustomSingleChoiceId) {
            firstCustomSingleChoiceId = question_array[0].id;
            firstCustomSingleChoiceSequence = question_array[0].sequence;
            firstCustomSingleChoiceOptions = question_array[0].default_options;
          }
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var k = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (k < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.accessKey = "custom-single-choice-question-div-" + k;
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                questionDIv.id =
                  question_array[0].id + ".." + question_array[0].sequence;
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest");
                main_options_div.classList.add("some-animation");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[k].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_question.classList.add("white-space-normal");
                option_div.appendChild(option_question);
                if (k != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (k == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  option_question.classList.add("slides-label");
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == "he" ||
                        main_lang_code == "ur" ||
                        main_lang_code == "ar")) ||
                    (main_lang_code == "default" &&
                      (language_code == "ar" ||
                        language_code == "he" ||
                        language_code == "ur"))
                  ) {
                    option_question.classList.add("rtl");
                  }
                  option_div.appendChild(option_question);
                  if (question_array[0].error_text && question_array[0].error_text == 'dropdown') {
                    var select = document.createElement("SELECT");
                    select.id = "csc-type-dropdown";
                    select.classList.add("options-dropdown");
                    var optionsArray =
                      question_array[0].default_options.split(";;");
                    var option = document.createElement("OPTION");
                    option.value = "";
                    option.innerHTML = generateTranslatedContent(translations, "Select an option", main_lang_code, language_code, input);
                    select.appendChild(option);
                    for (var i = 0; i < optionsArray.length; i++) {
                      var option = document.createElement("OPTION");
                      option.value = optionsArray[i];
                      option.innerHTML = optionsArray[i];
                      select.appendChild(option);
                      if (font && font.length > 0) {
                        option.classList.add(font);
                      }
                    }
                    var confirm_button = document.createElement("BUTTON");
                    confirm_button.classList.add("confirm-btn-smatest");
                    if (font && font.length > 0) {
                      confirm_button.classList.add(font);
                    }
                    translateContent(translations, confirm_button, "Confirm", main_lang_code, language_code);
                    confirm_button.style.pointerEvents = "none";
                    confirm_button.style.opacity = "0.6";
                    select.addEventListener("change", function (k) {
                      if (this.value && this.value.length > 0) {
                        confirm_button.style.pointerEvents = "auto";
                        confirm_button.style.opacity = "1";
                      } else {
                        confirm_button.style.pointerEvents = "none";
                        confirm_button.style.opacity = "0.6";
                      }
                    });
                    confirm_button.addEventListener("click", function (k) {
                      if (document.getElementById("csc-type-dropdown")) {
                        var drp = document.getElementById("csc-type-dropdown");
                        if (drp.value && drp.value.length > 0) {
                          if (agreed) {
                            var arr =
                              this.parentElement.previousSibling.id.split(
                                ".."
                              );
                            if (!shouldDisableTakeAction) {
                              if (
                                footer &&
                                (input.style.pointerEvents == "none" ||
                                  footer.style.display == "none")
                              ) {
                                takingRadioValue(
                                  drp.value,
                                  this.parentElement,
                                  2,
                                  arr[0],
                                  arr[1],
                                  "c_s_c"
                                );
                              } else {
                                if (input && input.placeholder == "Type your query") {
                                  takingRadioValue(
                                    drp.value,
                                    this.parentElement,
                                    2,
                                    arr[0],
                                    arr[1],
                                    "c_s_c"
                                  );
                                } else {
                                  if (
                                    current_question_type != "statement" &&
                                    current_question_type != "url_auto_redirect" &&
                                    current_question_type != "contact" &&
                                    current_question_type != "slides" &&
                                    current_question_type != "audio" &&
                                    current_question_type != "custom_answer" &&
                                    current_question_type != "custom_actions" &&
                                    current_question_type != "show_file" &&
                                    current_question_type != "show_location" &&
                                    current_question_type != "show_contacts"
                                  ) {
                                    // if (body && body.lastChild) {
                                    //   body.removeChild(body.lastChild);
                                    // }
                                  }
                                  takingRadioValue(
                                    drp.value,
                                    this.parentElement,
                                    2,
                                    arr[0],
                                    arr[1],
                                    "c_s_c"
                                  );
                                }
                              }
                            }
                          } else {
                            k.preventDefault();
                          }
                        }
                      }
                    });
                    main_options_div.appendChild(select);
                    main_options_div.appendChild(confirm_button);
                    if (font && font.length > 0) {
                      select.classList.add(font);
                    }
                  } else {
                    if (
                      question_array[0].error_text &&
                      question_array[0].error_text.length > 0 &&
                      question_array[0].error_text == "horizontal"
                    ) {
                      option_div.classList.add("dialogs-div-more-smatest");
                    } else {
                      option_div.classList.add("dialogs-div-more-vertical-smatest");
                    }
                    var slides_div = document.createElement("DIV");
                    if (
                      question_array[0].error_text &&
                      question_array[0].error_text.length > 0 &&
                      question_array[0].error_text == "horizontal"
                    ) {
                      slides_div.classList.add("avatar-scrollbar");
                    } else {
                      slides_div.classList.add("avatar-vertical-scrollbar");
                    }
                    slides_div.style.cssText =
                      slides_div.style.cssText + "max-height: fit-content !important";
                    slides_div.classList.add("slides-random");
                    slides_div.id = "avatar-scroll";
                    var optionsArray = question_array[0].default_options.split(";;");
                    if (optionsArray && optionsArray.length > 0) {
                      for (var j = 0; j < optionsArray.length; j++) {
                        var selectedKey;
                        var contact = document.createElement("DIV");
                        if (
                          question_array[0].error_text &&
                          question_array[0].error_text.length > 0 &&
                          question_array[0].error_text == "horizontal"
                        ) {
                          contact.classList.add("dialogs-div-smatest");
                        } else {
                          contact.classList.add("dialogs-div-vertical-smatest");
                        }
                        if (font && font.length > 0) {
                          contact.classList.add(font);
                        }
                        var label = document.createElement("LABEL");
                        var text = document.createTextNode(optionsArray[j]);
                        label.appendChild(text);
                        speakable_str = speakable_str + " " + label.innerText;
                        if (j != optionsArray.length - 1) {
                          speakable_str = speakable_str + " or ";
                        }
                        contact.appendChild(label);
                        slides_div.appendChild(contact);
                        contact.addEventListener("click", function (e) {
                          var value = this.children[0].innerHTML;
                          var arr =
                            this.parentElement.parentElement.previousSibling.id.split(
                              ".."
                            );
                          if (!shouldDisableTakeAction) {
                            if (
                              footer &&
                              (input.style.pointerEvents == "none" ||
                                footer.style.display == "none")
                            ) {
                              takingRadioValue(
                                value,
                                this.parentElement,
                                2,
                                arr[0],
                                arr[1],
                                "c_s_c"
                              );
                            } else {
                              if (input && input.placeholder == "Type your query") {
                                takingRadioValue(
                                  value,
                                  this.parentElement,
                                  2,
                                  arr[0],
                                  arr[1],
                                  "c_s_c"
                                );
                              } else {
                                if (
                                  current_question_type != "statement" &&
                                  current_question_type != "url_auto_redirect" &&
                                  current_question_type != "contact" &&
                                  current_question_type != "slides" &&
                                  current_question_type != "audio" &&
                                  current_question_type != "custom_answer" &&
                                  current_question_type != "custom_actions" &&
                                  current_question_type != "show_file" &&
                                  current_question_type != "show_location" &&
                                  current_question_type != "show_contacts"
                                ) {
                                  if (body && body.lastChild) {
                                    body.removeChild(body.lastChild);
                                  }
                                }
                                takingRadioValue(
                                  value,
                                  this.parentElement,
                                  2,
                                  arr[0],
                                  arr[1],
                                  "c_s_c"
                                );
                              }
                            }
                          }
                        });
                      }
                      main_options_div.appendChild(slides_div);
                    }
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (k != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (k == 0) {
                  k++;
                  if (k == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    k++;
                    if (k == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            var children = Array.from(body.children);
            var scrollDiv;
            for (var i = children.length - 1; i > 0; i--) {
              if (children[i].accessKey == "custom-single-choice-question-div-0") {
                scrollDiv = children[i];
                break;
              }
            }
            if (scrollDiv) {
              body.scrollTop = scrollDiv.offsetTop - 75;
            }
          }, 0);
        }

        function callContact(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var k = 0;
            var n = 0;

            function addQuestionArrays() {
              if (n < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest");
                main_options_div.classList.add("some-animation");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[n].trim();
                if (n == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (n != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (n == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  option_div.classList.add("m-b-10");
                  iconDiv.classList.add("m-b-10");
                  handleImageModal(question_array, main_image_options_div);
                  option_div.classList.add("options-div-smatest");
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var contact_list =
                      question_array[0].default_options.split(";;");
                    for (var j = 0; j < contact_list.length; j++) {
                      var contact = document.createElement("DIV");
                      var contact_item1 = contact_list[j].split("..");
                      if (
                        contact_item1[0] != "faqs" &&
                        contact_item1[0] != "schedule"
                      ) {
                        contact.classList.add("contact-div-smatest");
                        if (font && font.length > 0) {
                          contact.classList.add(font);
                        }
                        var contact_icon = document.createElement("IMG");
                        var contact_item = document.createElement("A");
                        contact_item.title = "Contact redirection";
                        if (chatbot_id != 10561 && chatbot_id != 14372) {
                          contact_item.style.height = "20px";
                          contact_item.style.lineHeight = "20px";
                        }
                        contact_item.classList.add("text-black");
                        if (font && font.length > 0) {
                          contact_item.classList.add(font);
                        }
                        if (contact_item1[0] == "facebook") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/fb_navigator.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "twitter") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/twitter_navigator.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "instagram") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/insta_navigator.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "linkedin") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/linkedin_navigator.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "messenger") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/messenger_navigator.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "zendesk") {
                          contact_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/zendesk_navigator.png";
                          contact_item.addEventListener("click", function () {
                            try {
                              mainDiv.click();
                              zE("webWidget", "show");
                              zE("webWidget", "toggle");
                            } catch (e) {
                            } finally {
                            }
                          });
                        } else if (contact_item1[0] == "tawkto") {
                          contact_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/tawkto_navigator.png";
                          contact_item.addEventListener("click", function () {
                            chat_with_us_cliked = true;
                            try {
                              if (
                                window.Tawk_API &&
                                window.Tawk_API.isChatHidden()
                              ) {
                                window.Tawk_API.showWidget();
                                Tawk_API.maximize();
                              } else if (window.Tawk_API) {
                                Tawk_API.maximize();
                              }
                            } catch (e) {
                            } finally {
                            }
                            mainDiv.click();
                          });
                        } else if (contact_item1[0] == "refresh") {
                          contact_item.classList.add("pointer");
                          contact_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/refresh_navigator.png";
                          contact_item.addEventListener("click", function () {
                            if (reload_div) {
                              reload_div.click();
                            }
                          });
                        } else if (contact_item1[0] == "close") {
                          contact_item.classList.add("pointer");
                          contact_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/close_navigator.png";
                          contact_item.addEventListener("click", function () {
                            mainDiv.click();
                          });
                        } else if (contact_item1[0] == "live_chat") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/bot_mic.png";
                          contact_item.addEventListener("click", function (k) {
                            chat_with_us_cliked = !0;
                            var xhttp = new XMLHttpRequest();
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            xhttp.send(
                              "action=answer&answer_text=Clicked_tawk_to" +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              menu_option_question_id +
                              "&is_logical=0" +
                              "&sequence=" +
                              menu_option_sequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&is_help=1&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                            if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
                              window.Tawk_API.showWidget();
                              Tawk_API.maximize();
                            }
                            try {
                              zE("webWidget", "show");
                              zE("webWidget", "toggle");
                            } catch (e) {
                            } finally {
                            }
                            mainDiv.click();
                          });
                        } else if (contact_item1[0] == "url") {
                          contact_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/click_navigator.png";
                          contact_item.href = contact_item1[2];
                          if (contact_item1[3] && contact_item1[3].length > 0) {
                            if (contact_item1[3] == "2") {
                              contact_item.target = "_blank";
                            }
                          }
                        } else if (contact_item1[0] == "youtube") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/youtube_navigator.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "google") {
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/google-plus.png";
                          contact_item.href = contact_item1[2];
                        } else if (contact_item1[0] == "call") {
                          if (call_fore == "white") {
                            contact_icon.src =
                              "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/call_white.png";
                          } else {
                            contact_icon.src =
                              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/call_navigator.png";
                          }
                          contact_item.href = "tel:" + contact_item1[2];
                        } else if (contact_item1[0] == "schedule") {
                          contact_icon.classList.add("other-pointer");
                          contact_item.classList.add("other-pointer");
                          contact_icon.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/schedule.png";
                          contact_item.addEventListener("click", function (k) {
                            clickSchedule(contact_item1[1]);
                          });
                        } else if (contact_item1[0] == "whatsapp") {
                          contact_icon.target = "_blank";
                          contact_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/whatsapp_navigator.png";
                          var k = generateTranslatedContent(translations, "Hi team, I have some queries", main_lang_code, language_code, input);
                          if (
                            /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                              navigator.userAgent
                            )
                          ) {
                            contact_item.href =
                              "https://api.whatsapp.com/send?phone=" +
                              contact_item1[2].split("+").join("") +
                              contact_item1[3] +
                              "&text=" +
                              k;
                          } else {
                            contact_item.href =
                              "https://web.whatsapp.com/send?phone=" +
                              contact_item1[2] +
                              contact_item1[3] +
                              "&text=" +
                              k;
                          }
                        }
                        contact_icon.classList.add("contact-icon-smatest");
                        var contact_text;
                        if (chatbot_id == 10561 || chatbot_id == 14372) {
                          contact_text = document.createElement("P");
                        } else {
                          contact_text = document.createElement("SPAN");
                        }
                        var text10 = document.createTextNode(contact_item1[1]);
                        contact_text.appendChild(text10);
                        say(contact_text.innerText);
                        if (
                          contact_item1[0] != "call" &&
                          contact_item1[0] != "url"
                        ) {
                          contact_item.target = "_blank";
                        } else {
                          if (chatbot_id == 10561 || chatbot_id == 14372) {
                            contact_item.title = contact_item1[1];
                          }
                        }
                        contact_item.appendChild(contact_text);
                        contact_item.appendChild(contact_icon);
                        contact.appendChild(contact_item);
                        main_options_div.appendChild(contact);
                        setTimeout(function () { }, delay_time);
                      }
                    }
                  }
                }
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (n != 0) {
                  body.appendChild(otherSpinningDIv);
                  body.scrollTop = body.scrollHeight;
                }
                if (n == 0) {
                  body.appendChild(questionDIv);
                  questionDIv.appendChild(option_div);
                  if (n == question_arr.length - 1) {
                    if (
                      question_array[0].is_feedback &&
                      question_array[0].is_feedback == "1"
                    ) {
                      option_div.style.marginBottom = "15px";
                      addQuestionFeedback(option_div, question_array);
                    }
                    setTimeout(function () {
                      takingRadioValue("something", option_div, 1);
                    }, delay_time);
                  }
                  n++;
                  if (n == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      if (chatbot_id != 10561 && chatbot_id != 14372) {
                        body.scrollTop = body.scrollHeight;
                      }
                    }, delay_time + 10);
                    option_div.classList.remove("m-b-10");
                    iconDiv.classList.remove("m-b-10");
                  }
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    questionDIv.appendChild(option_div);
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    if (n == question_arr.length - 1) {
                      if (
                        question_array[0].is_feedback &&
                        question_array[0].is_feedback == "1"
                      ) {
                        option_div.style.marginBottom = "15px";
                        addQuestionFeedback(option_div, question_array);
                      }
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time);
                    }
                    n++;
                    if (n == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        if (chatbot_id != 10561 && chatbot_id != 14372) {
                          body.scrollTop = body.scrollHeight;
                        }
                      }, delay_time + 10);
                      option_div.classList.remove("m-b-10");
                      iconDiv.classList.remove("m-b-10");
                    }
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callRating(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest-rating");
                main_options_div.classList.add("some-animation");
                var rating_logo = document.createElement("DIV");
                rating_logo.classList.add("rating-logo-div");
                var rating_logo_image = document.createElement("IMG");
                // rating_logo_image.classList.add('fa');
                // rating_logo_image.classList.add('fa-star-o');
                if (answer_color == "white") {
                  rating_logo_image.src =
                    "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_white_empty.png";
                } else {
                  rating_logo_image.src =
                    "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_black_empty.png";
                }
                rating_logo.appendChild(rating_logo_image);
                main_options_div.appendChild(rating_logo);
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                option_question.classList.add("pull-left");
                option_question.classList.add("full-width");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  option_div.classList.add("options-div-smatest");
                  var optionsArray = question_array[0].default_options.split(";;");
                  var rating_type;
                  if (
                    question_array[0].auto_slide &&
                    question_array[0].auto_slide.length > 0 &&
                    question_array[0].auto_slide != "0"
                  ) {
                    rating_type = question_array[0].auto_slide;
                  } else {
                    rating_type = "1";
                  }
                  var rating_full_div = document.createElement("DIV");
                  rating_full_div.classList.add("rating-with-stars");
                  rating_full_div.classList.add("et-app-rating-stars");
                  var rating_label = document.createElement("LABEL");
                  rating_label.innerHTML = generateTranslatedContent(translations, "Please rate", main_lang_code, language_code, input);
                  rating_label.style.marginBottom = "10px";
                  rating_label.style.fontSize = "14px";
                  rating_label.classList.add("please-rate-us-text");
                  rating_label.classList.add("pull-left");
                  rating_label.classList.add("full-width");
                  var main_input = document.createElement("INPUT");
                  var rating_submit_button = document.createElement("BUTTON");
                  rating_submit_button.id = "rating-submit";
                  main_options_div.appendChild(rating_label);
                  rating_full_div.appendChild(main_input);
                  rating_submit_button.classList.add("confirm-btn-smatest");
                  rating_submit_button.style.width = "calc(100% - 30px)";
                  rating_submit_button.style.pointerEvents = "none";
                  rating_submit_button.style.opacity = "0.3";
                  translateContent(translations, rating_submit_button, "Submit", main_lang_code, language_code)
                  rating_submit_button.style.marginTop = "15px";
                  var main_rating_value;
                  rating_submit_button.addEventListener("click", function (k) {
                    if (main_rating_value) {
                      takingRadioValue(main_rating_value, main_options_div);
                    }
                  });
                  for (var i = 0; i < optionsArray.length; i++) {
                    switch (rating_type) {
                      case "1":
                        var ratingDiv = document.createElement("LABEL");
                        var ratingImg = document.createElement("IMG");
                        ratingDiv.classList.add("rating-div");
                        ratingImg.classList.add("rating-img");
                        if (i == 0) {
                          ratingImg.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/rating-1.png";
                        } else if (i == 1) {
                          ratingImg.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/rating-2.png";
                        } else if (i == 2) {
                          ratingImg.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/rating-3.png";
                        } else if (i == 3) {
                          ratingImg.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/rating-4.png";
                        } else if (i == 4) {
                          ratingImg.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/rating-5.png";
                        }
                        ratingDiv.appendChild(ratingImg);
                        var rating_text = document.createElement("p");
                        rating_text.classList.add("rating-p");
                        if (font && font.length > 0) {
                          rating_text.classList.add(font);
                        }
                        var text = document.createTextNode(optionsArray[i]);
                        rating_text.appendChild(text);
                        rating_text.style.display = "none";
                        speakable_str = speakable_str + " " + rating_text.innerText;
                        if (i != optionsArray.length - 1) {
                          speakable_str = speakable_str + " or ";
                        }
                        ratingDiv.appendChild(rating_text);
                        main_options_div.appendChild(ratingDiv);
                        ratingImg.title = optionsArray[i];
                        ratingImg.addEventListener("click", function () {
                          if (this.classList.contains("rating-animate")) {
                          } else {
                            this.classList.add("rating-animate");
                          }
                          takingRadioValue(
                            this.nextSibling.innerHTML,
                            main_options_div
                          );
                          option_div.style.pointerEvents = "none";
                        });
                        break;
                      case "2":
                        var t = i + 1;
                        var rating_button = document.createElement("BUTTON");
                        rating_button.classList.add("et-app-rating-star");
                        rating_button.setAttribute("data-star", t);
                        rating_button.id = optionsArray[i];
                        var unselected_star = document.createElement("IMG");
                        unselected_star.src =
                          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gray.png";
                        var selected_star = document.createElement("IMG");
                        selected_star.src =
                          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gold.png";
                        selected_star.classList.add("selected");
                        var rating_text = document.createElement("SPAN");
                        rating_text.classList.add("et-app-sr");
                        rating_text.innerHTML = "Rating: " + t + " star";
                        rating_button.appendChild(unselected_star);
                        rating_button.appendChild(rating_text);
                        rating_button.addEventListener("click", function () {
                          this.classList.add("select");
                          this.children[0].src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gold.png";
                          var children = this.parentElement.children;
                          var prev_childs = [];
                          var next_childs = [];
                          var index = Array.prototype.indexOf.call(
                            this.parentElement.children,
                            this
                          );
                          for (var t = 0; t < children.length; t++) {
                            if (t < index) {
                              prev_childs.push(children[t]);
                              if (children[t] && children[t].children[0]) {
                                children[t].children[0].src =
                                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gold.png";
                              }
                              children[t].classList.add("select");
                            }
                            if (t > index) {
                              next_childs.push(children[t]);
                              if (children[t].classList.contains("select")) {
                                if (children[t] && children[t].children[0]) {
                                  children[t].children[0].src =
                                    "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gray.png";
                                }
                                children[t].classList.remove("select");
                              }
                            }
                          }
                          main_rating_value = this.id;
                          rating_submit_button.style.opacity = "0.8";
                          rating_submit_button.style.pointerEvents = "auto";
                        });
                        rating_button.addEventListener("mouseover", function () {
                          if (!main_rating_value) {
                            this.classList.add("highlight");
                            this.children[0].src =
                              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gold.png";
                            var children = this.parentElement.children;
                            var prev_childs = [];
                            var next_childs = [];
                            var index = Array.prototype.indexOf.call(
                              this.parentElement.children,
                              this
                            );
                            for (var t = 0; t < children.length; t++) {
                              if (t < index) {
                                prev_childs.push(children[t]);
                                children[t].classList.add("highlight");
                                if (children[t] && children[t].children[0]) {
                                  children[t].children[0].src =
                                    "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gold.png";
                                }
                              }
                              if (t > index) {
                                next_childs.push(children[t]);
                                if (children[t].classList.contains("highlight")) {
                                  children[t].classList.remove("highlight");
                                  if (children[t] && children[t].children[0]) {
                                    children[t].children[0].src =
                                      "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gray.png";
                                  }
                                }
                              }
                            }
                          }
                        });
                        rating_button.addEventListener("mouseout", function () {
                          if (!main_rating_value) {
                            this.classList.remove("highlight");
                            this.children[0].src =
                              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gray.png";
                            var children = this.parentElement.children;
                            var prev_childs = [];
                            var next_childs = [];
                            var index = Array.prototype.indexOf.call(
                              this.parentElement.children,
                              this
                            );
                            for (var t = 0; t < children.length; t++) {
                              if (t < index) {
                                prev_childs.push(children[t]);
                                if (children[t].classList.contains("highlight")) {
                                  children[t].classList.remove("highlight");
                                  if (children[t] && children[t].children[0]) {
                                    children[t].children[0].src =
                                      "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/star_gray.png";
                                  }
                                }
                              }
                            }
                          }
                        });
                        rating_full_div.appendChild(rating_button);
                        break;
                      case "3":
                        var ratingDiv = document.createElement("LABEL");
                        var ratingImg = document.createElement("span");
                        ratingDiv.classList.add("rating-div");
                        ratingImg.classList.add("rating-img-number");
                        var t = i + 1;
                        ratingImg.innerHTML = t;
                        ratingDiv.appendChild(ratingImg);
                        var rating_text = document.createElement("p");
                        rating_text.classList.add("rating-p");
                        if (font && font.length > 0) {
                          rating_text.classList.add(font);
                        }
                        var text = document.createTextNode(optionsArray[i]);
                        rating_text.appendChild(text);
                        rating_text.style.display = "none";
                        speakable_str = speakable_str + " " + rating_text.innerText;
                        if (i != optionsArray.length - 1) {
                          speakable_str = speakable_str + " or ";
                        }
                        ratingDiv.appendChild(rating_text);
                        main_options_div.appendChild(ratingDiv);
                        ratingImg.addEventListener("click", function () {
                          if (this.classList.contains("rating-animate")) {
                          } else {
                            this.classList.add("rating-animate");
                          }
                          takingRadioValue(
                            this.nextSibling.innerHTML,
                            main_options_div
                          );
                          option_div.style.pointerEvents = "none";
                        });
                        break;
                      case "4":
                        var radio_text = document.createElement("label");
                        var span = document.createElement("span");
                        var str;
                        var k = i + 1;
                        if (k == 1) {
                          str = "Star";
                        } else {
                          str = "Stars";
                        }
                        span.innerHTML =
                          optionsArray[i] + " (" + k + " " + str + ")";
                        speakable_str = speakable_str + " " + span.innerText;
                        if (i != optionsArray.length - 1) {
                          speakable_str = speakable_str + " or ";
                        }
                        var check = document.createElement("DIV");
                        check.classList.add("check-smatest");
                        var radio = document.createElement("input");
                        radio.type = "radio";
                        radio.classList.add("rating-radio");
                        radio.name = "radio_option";
                        radio.value = optionsArray[i];
                        radio_text.id = optionsArray[i];
                        radio_text.classList.add("rating-radio-option");
                        radio_text.appendChild(radio);
                        radio_text.appendChild(check);
                        radio_text.appendChild(span);
                        main_options_div.appendChild(radio_text);
                        radio_text.addEventListener("click", function () {
                          if (this.classList.contains("rating-animate")) {
                          } else {
                            this.classList.add("rating-animate");
                          }
                          takingRadioValue(this.id, main_options_div);
                          option_div.style.pointerEvents = "none";
                        });
                      default:
                    }
                  }
                  if (rating_type == "2") {
                    main_options_div.appendChild(rating_full_div);
                    main_options_div.appendChild(rating_submit_button);
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callRange(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var range_div = document.createElement("DIV");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                range_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  range_div.classList.add("m-l-40");
                }
                range_div.classList.add("options-div-smatest");
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  var range_with_values = document.createElement("LABEL");
                  range_with_values.classList.add("simple-label-smatest");
                  range_with_values.classList.add("m-t-20");
                  if (font && font.length > 0) {
                    range_with_values.classList.add(font);
                  }
                  var range = document.createElement("INPUT");
                  range.classList.add("slider-smatest");
                  range.type = "range";
                  range.oninput = function () {
                    var value =
                      ((this.value - this.min) / (this.max - this.min)) * 100;
                    this.style.background =
                      "linear-gradient(to right, " +
                      themes_array[4] +
                      " 0%, " +
                      themes_array[4] +
                      " " +
                      value +
                      "%, #fff " +
                      value +
                      "%, #fff 100%)";
                  };
                  var len = 0;
                  var min_max = [];
                  min_max = question_array[0].default_options.split(";;");
                  range.min = min_max[0];
                  speakable_str = speakable_str + " from ";
                  speakable_str = speakable_str + " " + min_max[0];
                  range.max = min_max[1];
                  len = min_max[1].toString().length;
                  speakable_str = speakable_str + " to ";
                  speakable_str = speakable_str + " " + min_max[1];
                  range.value = min_max[0];
                  len = len + min_max[0].toString().length;
                  len = len * 10 + 18;
                  len = 0;
                  range.style.cssText =
                    range.style.cssText +
                    "width:calc(100% - " +
                    len +
                    "px) !important";
                  var min_value = document.createElement("LABEL");
                  var min = document.createTextNode(min_max[0]);
                  min_value.appendChild(min);
                  min_value.classList.add("range-value");
                  var max_value = document.createElement("LABEL");
                  var max = document.createTextNode(min_max[1]);
                  max_value.appendChild(max);
                  max_value.classList.add("range-value");
                  range_with_values.appendChild(range);
                  var range_value = document.createElement("LABEL");
                  range_value.classList.add("simple-label-smatest-other");
                  range_value.style.cssText =
                    range_value.style.cssText + "font-weight:600 !important";
                  if (font && font.length > 0) {
                    range_value.classList.add(font);
                  }
                  range_value.innerHTML = range.value;
                  range.addEventListener("change", function () {
                    range_value.innerHTML = this.value;
                  });
                  var confirm_button_div = document.createElement("DIV");
                  confirm_button_div.classList.add("pull-left");
                  confirm_button_div.classList.add("full-width");
                  confirm_button_div.classList.add("text-center");
                  var confirm_button = document.createElement("BUTTON");
                  confirm_button.classList.add("confirm-btn-smatest-other");
                  if (font && font.length > 0) {
                    confirm_button.classList.add(font);
                  }
                  confirm_button_div.appendChild(confirm_button);
                  translateContent(translations, confirm_button, "Confirm", main_lang_code, language_code)
                  confirm_button.addEventListener("click", function () {
                    takingRadioValue(range_value.innerHTML, range_div);
                  });
                  range_div.appendChild(range_with_values);
                  range_div.appendChild(range_value);
                  range_div.appendChild(confirm_button_div);
                }
                questionDIv.appendChild(range_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    body.scrollTop = body.scrollHeight;
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      body.scrollTop = body.scrollHeight;
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 1000);
        }

        function callCheckbox(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest");
                main_options_div.classList.add("some-animation");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                var is_dropdown;
                if (
                  question_array[0].error_text &&
                  question_array[0].error_text.length > 0
                ) {
                  if (question_array[0].error_text == "dropdown") {
                    is_dropdown = true;
                  }
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  option_div.classList.add("options-div-smatest");
                  var selectedOptions = [];
                  if (question_array[0].default_options.includes("::")) {
                    var max_options = parseInt(
                      question_array[0].default_options.split("::")[1]
                    );
                    var optionsArray = question_array[0].default_options
                      .split("::")[0]
                      .split(";;");
                  } else {
                    var optionsArray =
                      question_array[0].default_options.split(";;");
                    var max_options;
                    if (
                      question_array[0].auto_slide &&
                      question_array[0].auto_slide.length > 0
                    ) {
                      max_options = parseInt(question_array[0].auto_slide);
                    } else {
                      max_options = optionsArray.length;
                    }
                  }
                  if (is_dropdown) {
                    var optionsArray =
                      question_array[0].default_options.split(";;");
                    main_options_div.style.overflowY = "auto";
                    main_options_div.style.maxHeight = "400px";
                    var select = document.createElement("SELECT");
                    select.id = "checkbox-type-dropdown";
                    select.classList.add("options-dropdown");
                    // select.setAttribute("size", max_options);
                    // select.setAttribute("multiple", "true");
                    var height;
                    if (optionsArray.length < 11) {
                      height = optionsArray.length * 37 + 110;
                      main_options_div.style.minHeight = height + "px";
                    }
                    for (var i = 0; i < optionsArray.length; i++) {
                      var option = document.createElement("OPTION");
                      option.value = optionsArray[i];
                      option.innerHTML = optionsArray[i];
                      select.appendChild(option);
                      if (font && font.length > 0) {
                        option.classList.add(font);
                      }
                    }
                    if (font && font.length > 0) {
                      select.classList.add(font);
                    }
                    main_options_div.appendChild(select);
                    var main_div_loaded;

                    function openDropdown() {
                      if (!main_div_loaded) {
                        if (document.getElementById("checkbox-type-dropdown")) {
                          main_div_loaded = true;
                          checkboxDropdown = new vanillaSelectBox(
                            "#checkbox-type-dropdown",
                            {
                              search: true,
                              placeHolder: "Search Options ...",
                              maxSelect: max_options,
                            }
                          );
                          checkboxDropdown.enable();
                        }
                      } else {
                        stopInterval();
                      }
                    }

                    function stopInterval() {
                      clearInterval(timer);
                    }
                    // var timer = setInterval(openDropdown, 100);
                  } else {
                    for (var i = 0; i < optionsArray.length; i++) {
                      var radio_text = document.createElement("label");
                      var span = document.createElement("span");
                      var option = document.createTextNode(optionsArray[i]);
                      span.appendChild(option);
                      speakable_str = speakable_str + " " + span.innerText;
                      speakable_str = speakable_str + " and ";
                      if (question_array[0].error_text == "horizontal") {
                        span.classList.add("w-auto-i");
                      }
                      var check = document.createElement("DIV");
                      check.classList.add("check-box-smatest");
                      var radio = document.createElement("input");
                      radio.type = "checkbox";
                      radio.name = "radio_option_" + optionsArray[i];
                      radio.value = optionsArray[i];
                      radio.classList.add("radio-box-botest");
                      if (question_array[0].error_text == "horizontal") {
                        radio_text.classList.add("w-auto-i");
                        radio_text.classList.add("m-r-6");
                        radio_text.classList.add("pull-left");
                        radio_text.classList.add("m-b-6");
                      }
                      radio_text.classList.add("options-smatest-checkbox");
                      if (
                        (main_lang_code &&
                          (main_lang_code == "he" ||
                            main_lang_code == "ur" ||
                            main_lang_code == "ar")) ||
                        (main_lang_code == "default" &&
                          (language_code == "ar" ||
                            language_code == "he" ||
                            language_code == "ur"))
                      ) {
                        radio_text.classList.add("rtl");
                        radio_text.style.textAlign = "right";
                      }
                      radio_text.appendChild(radio);
                      radio_text.appendChild(check);
                      radio_text.appendChild(span);
                      main_options_div.appendChild(radio_text);
                      radio.addEventListener("click", function () {
                        if (selectedOptions.includes(this.value)) {
                          selectedOptions.splice(
                            selectedOptions.indexOf(this.value),
                            1
                          );
                        } else {
                          if (selectedOptions.length + 1 > max_options) {
                            if (
                              document.getElementsByName(
                                "radio_option_" +
                                selectedOptions[selectedOptions.length - 1]
                              ) &&
                              document.getElementsByName(
                                "radio_option_" +
                                selectedOptions[selectedOptions.length - 1]
                              ).length > 0
                            ) {
                              document.getElementsByName(
                                "radio_option_" +
                                selectedOptions[selectedOptions.length - 1]
                              )[0].checked = false;
                            }
                            selectedOptions.splice(selectedOptions.length - 1, 1);
                            selectedOptions.push(this.value);
                          } else {
                            selectedOptions.push(this.value);
                          }
                        }
                      });
                    }
                  }
                  var confirm_button = document.createElement("BUTTON");
                  confirm_button.classList.add("confirm-checkbox-btn-smatest");
                  if (font && font.length > 0) {
                    confirm_button.classList.add(font);
                  }
                  translateContent(translations, confirm_button, "Confirm", main_lang_code, language_code);
                  confirm_button.addEventListener("click", function () {
                    if (is_dropdown) {
                      var answer = document.getElementById("checkbox-type-dropdown").value;
                      if (
                        answer &&
                        answer.length > 0 &&
                        answer != "Search Options ..."
                      ) {
                        takingRadioValue(answer, main_options_div);
                      } else {
                      }
                    } else {
                      if (selectedOptions && selectedOptions.length > 0) {
                        var answer_text = selectedOptions.join(",");
                        takingRadioValue(answer_text, main_options_div);
                      } else {
                        var errorDiv = document.createElement("DIV");
                        errorDiv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          errorDiv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          errorDiv.classList.add(font);
                        }
                        var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                        error_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(error_icon);
                        iconDiv.classList.add("question-icon-div");
                        error_icon.classList.add("question-icon-smatest");
                        var error_text = document.createElement("LABEL");
                        var error_msg = document.createTextNode(
                          "Please select atleast one option"
                        );
                        error_text.appendChild(error_msg);
                        error_text.classList.add("question-text-error");
                        error_text.classList.add("options-div-smatest");
                        if (font && font.length > 0) {
                          error_text.classList.add(font);
                        }
                        errorDiv.appendChild(iconDiv);
                        errorDiv.appendChild(error_text);
                        body.appendChild(errorDiv);
                        playBotUserSound(1);
                        body.scrollTop = body.scrollHeight;
                      }
                    }
                  });
                  main_options_div.appendChild(confirm_button);
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                    option_div.classList.remove("m-b-10");
                    iconDiv.classList.remove("m-b-10");
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                      option_div.classList.remove("m-b-10");
                      iconDiv.classList.remove("m-b-10");
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }
        
        function createBrandWrapper(parentElement, brandName, mainUrl, fontClass) {
          var brandWrapper = document.createElement('DIV');
          brandWrapper.classList.add('brand_wrapper_sb');
          
          var brandTextLight = document.createElement('SPAN');
          brandTextLight.classList.add('brand_light_text_sb');
          if(totalData[0].custom_brand_name && totalData[0].custom_brand_name.toLowerCase() == "cloudway.ai") {
            brandTextLight.innerHTML = 'Powered by ';
          } else {
            brandTextLight.innerHTML = 'We run on ';
          }
          
      
          var brandTextDark = document.createElement('a');
          brandTextDark.classList.add('brand_dark_text_sb');
          if (chatbot_id == 527 || chatbot_id == 746  || chatbot_id == 3182) {
            brandTextDark.href = "https://www.firstmeridian.com/";
            var img_brand = document.createElement("IMG");
            brandTextDark.appendChild(img_brand);
            img_brand.src ="https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/digibot-logo.png";
            img_brand.style.height = "12px";
            img_brand.alt = "Digibot";
            img_brand.style.verticalAlign = "middle";
          } else{

            if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
              var medium = "mobile";
            } else {
              var medium = "desktop";
            }

            if(chatbot_id && (chatbot_id == 5486 || chatbot_id == 17113 || chatbot_id == 17030)) {
              brandTextDark.style.cursor = 'default';
            } else {
              if ( totalData[0].stop_redirection && totalData[0].stop_redirection == "0" ) {
                brandTextDark.href = main_url + "/";
                brandTextDark.addEventListener("click", function (k) {
                  if (brandTextDark && brandTextDark.href.includes("smatbot.com")) {
                    brandTextDark.href = main_url + "/";
                    brandTextDark.href = brandTextDark.href + "?utm_source=" + window.location.href +"&utm_medium=" + medium;
                  }
                });
              }
            }

            if(chatbot_id && (chatbot_id == 5486 || chatbot_id == 17113 || chatbot_id == 17030)) {
              brandTextDark.style.cursor = 'default';
            } else {
              brandTextDark.innerHTML = brandName;
              brandTextDark.target = "_blank";
              brandTextDark.href = mainUrl + "/";
            }
            
            if (
              totalData[0].custom_brand_enabled &&
              totalData[0].custom_brand_enabled == "1"
            ) {
              if (
                totalData[0].custom_brand_name &&
                totalData[0].custom_brand_name.length > 0
              ) {
                partner_client_details = true;
                brand_name_added = totalData[0].custom_brand_name;
                console.log("fyghjkl",brand_name_added);
                
                if (
                  totalData[0].custom_brand_url &&
                  totalData[0].custom_brand_url.length > 0
                ) {                  
                  if (totalData[0].custom_brand_name == "KP AI Solutions") { 
                    brandTextDark.href = totalData[0].custom_brand_url;
                  } else {
                    brandTextDark.innerHTML = totalData[0].custom_brand_name;                    

                    if (totalData[0].custom_brand_url.startsWith('http')) {
                      brandTextDark.href = totalData[0].custom_brand_url
                    }else{
                      brandTextDark.href =  `https://${totalData[0].custom_brand_url}` 
                    }
                    // brandTextDark.href = totalData[0].custom_brand_url;
                    if(totalData[0].custom_brand_name && totalData[0].custom_brand_name.toLowerCase() == "cloudway.ai") {
                      brandTextDark.title = 'Powered by  '+ totalData[0].custom_brand_name;
                    } else {
                      brandTextDark.title = 'We run on  '+ totalData[0].custom_brand_name;
                    }
                    // brandTextDark.title = 'We run on  '+ totalData[0].custom_brand_name;
                  }
                }
              }
            }

            if (chatbot_id == 23568) {
              brandTextDark.style.cssText = brandTextDark.style.cssText + "pointer-events: none;";
              brandTextDark.style.cssText = brandTextDark.style.cssText + "cursor: none;";
            }
          }

          if (fontClass && fontClass.length > 0) {
              brandWrapper.classList.add(fontClass);
          }

          brandWrapper.appendChild(brandTextLight);
          brandWrapper.appendChild(brandTextDark);

          parentElement.appendChild(brandWrapper);
        }
             
        function callRadio(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          var scrollable_height = body.scrollHeight;
          if (question_arr && question_arr.length > 0) {
            var j = 0;
            var speakable_str = "";
    
            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                if (currentMailSequence) {
                  questionDIv.id = "radio-question-div-" + currentMailSequence;
                } else {
                  questionDIv.id = "radio-question-div-" + 0;
                }
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest");
                main_options_div.style.cssText = main_options_div.style.cssText + "border-radius:0 !important";
                main_options_div.classList.add("some-animation");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                var is_dropdown;
                var is_hidden;
                if (
                  question_array[0].error_text &&
                  question_array[0].error_text.length > 0
                ) {
                  if (question_array[0].error_text == "dropdown") {
                    is_dropdown = true;
                  } else if (question_array[0].error_text == "hide") {
                    is_hidden = true;
                  } else if (question_array[0].error_text == 'list view') {
    
                    var main_opened_div = document.getElementById('opened');
        
                    if (
                      main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                    ) {
                      main_opened_div.removeChild(
                        document.getElementById('bg-shadow-overlay')
                      );
                    }
              
                    var openMenuSb = document.getElementById('open-menu-sb');
                    var optionsDiv = document.getElementsByClassName('options-div-smatest');
              
                    if (openMenuSb && optionsDiv.length > 0) {
                      if (
                        optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                      ) {
                        optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                      }
                    }
                    
                    var bg_shadow_radio = document.createElement('DIV');
                    bg_shadow_radio.style.visibility = 'hidden';
                    bg_shadow_radio.setAttribute('id', 'bg-shadow-overlay');
    
                    var whatsapp_list_container = document.createElement('DIV');
                    whatsapp_list_container.style.minHeight = 'auto'
                    whatsapp_list_container.setAttribute('id','whatsapp_list_container');

                    createAppMenu(option_div, 'Select Options', bg_shadow_radio, whatsapp_list_container)
    
                    var close_icon_div = document.createElement('DIV');
                    close_icon_div.setAttribute('class', 'close-icon-div-small_sb');
    
                    var close_icon_img = document.createElement('IMG');
                    close_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small+(2).svg'
                    close_icon_img.alt ='closeicon'
                    close_icon_img.style.width ='10px';
                    close_icon_img.style.height ='10px';
    
                    var left_icon_img = document.createElement('IMG');
                    left_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg'
                    left_icon_img.alt ='closeicon'
                    left_icon_img.style.width ='15px';
                    left_icon_img.style.height ='15px';
                    left_icon_img.style.cursor ='pointer';
    
                    var headder_main_div = document.createElement('DIV');
                    headder_main_div.classList.add('headder_main_div_sb');
    
                    var headder_main_text = document.createElement('DIV');
                    headder_main_text.innerHTML = generateTranslatedContent(translations, "Select Options", main_lang_code, language_code, input); 
                    headder_main_text.style.textAlign ='center';
                    headder_main_text.style.width ='90%';
                    headder_main_text.style.fontSize ='13px';
                    headder_main_text.style.fontWeight ='600';
                    if (font && font.length > 0) {
                      headder_main_text.classList.add(font);
                    }
    
                    close_icon_div.appendChild(close_icon_img)
                    headder_main_div.appendChild(left_icon_img); 
                    headder_main_div.appendChild(headder_main_text);
                    // headder_main_div.appendChild(close_icon_div);
    
                    var filter_outer_div = document.createElement('DIV');
                    filter_outer_div.classList.add('filter_outer_div');
    
                    var search_bar_div = document.createElement('DIV');
                    search_bar_div.setAttribute('class', 'search_bar_div_orderItems');
    
                    var search_icon = document.createElement('IMG');
                    search_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/search+(2).svg';
                    search_icon.alt ='SearchIcon';
                    search_icon.style.width = "16px";
                    search_icon.style.height = "16px";
    
                    var search_bar_Input = document.createElement('INPUT');
                    search_bar_Input.setAttribute('class', 'search_bar_input_orderItems');
                    search_bar_Input.placeholder = generateTranslatedContent(translations, "Search Options", main_lang_code, language_code, search_bar_Input);
                    if (font && font.length > 0) {
                      search_bar_Input.classList.add(font);
                    }
    
                    search_bar_div.appendChild(search_bar_Input)
                    search_bar_div.appendChild(search_icon)
                    filter_outer_div.appendChild(search_bar_div)
    
                    var inner_div = document.createElement('DIV');
                    inner_div.setAttribute('class','inner_div_scrool')
    
                    var form_whatsapp_list = document.createElement('FORM');
                    form_whatsapp_list.setAttribute('class','form_whatsapp_list')
                    form_whatsapp_list.setAttribute('id','dynamicFormRadio')
    
                    var submit_btn = document.createElement('Button');
                    submit_btn.classList.add('confirm-btn-smatest');
                    submit_btn.setAttribute('id','whatsapplist-submit_btn')
                    submit_btn.innerHTML = generateTranslatedContent(translations, "Submit", main_lang_code, language_code, input);
    
                      var submit_icon = document.createElement('IMG');
                      submit_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                      submit_icon.alt = 'SubmitIcon';
                      submit_icon.style.width = "18px";
                      submit_icon.style.height = "18px";
    
                      submit_btn.appendChild(submit_icon);
    
    
                    var opened_div = document.getElementById('opened');
    
                    if (font && font.length > 0) {
                      submit_btn.classList.add(font);
                    }
    
                    opened_div.appendChild(bg_shadow_radio);
                    bg_shadow_radio.appendChild(whatsapp_list_container);
                    whatsapp_list_container.appendChild(headder_main_div);  
                    whatsapp_list_container.appendChild(filter_outer_div)
                    whatsapp_list_container.appendChild(inner_div)
                    inner_div.appendChild(form_whatsapp_list)
                    whatsapp_list_container.appendChild(submit_btn)
                    createBrandWrapper(whatsapp_list_container, 'SmatBot', main_url, font);
    
                    left_icon_img.addEventListener('click', function () {
                      bg_shadow_radio.style.visibility = 'hidden';
                      whatsapp_list_container.style.opacity = '0.5';
                      whatsapp_list_container.style.transform = 'translateY(100%)';
                    });
                    close_icon_div.addEventListener('click', function () {
                      botWidget.minimise()
                      // bg_shadow_radio.style.visibility = 'hidden';
                      // whatsapp_list_container.style.opacity = '0.5';
                      // whatsapp_list_container.style.transform = 'translateY(100%)';
                    });
                  }
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  if (!is_hidden) {
                    is_radio_hidden = false;
                    if (is_dropdown) {
                      var select = document.createElement("SELECT");
                      select.id = "radio-type-dropdown";
                      select.classList.add("options-dropdown");
                      var optionsArray;
                      if (current_question_type == "whatsapp_list") {
                        optionsArray =
                          question_array[0].default_options.split(";;");
                        for (let index = 0; index < optionsArray.length; index++) {
                          optionsArray[index] = optionsArray[index].split("..")[0];
                        }
                      } else {
                        optionsArray =
                          question_array[0].default_options.split(";;");
                      }
                      var option = document.createElement("OPTION");
                      option.value = "";
                      option.innerHTML = generateTranslatedContent(translations, "Select an option", main_lang_code, language_code, input);
                      select.appendChild(option);
                      for (var i = 0; i < optionsArray.length; i++) {
                        var option = document.createElement("OPTION");
                        option.value = optionsArray[i];
                        option.innerHTML = optionsArray[i];
                        select.appendChild(option);
                        if (font && font.length > 0) {
                          option.classList.add(font);
                        }
                      }
                      var confirm_button = document.createElement("BUTTON");
                      confirm_button.classList.add("confirm-btn-smatest");
                      if (font && font.length > 0) {
                        confirm_button.classList.add(font);
                      }
                      translateContent(translations, confirm_button, "Confirm", main_lang_code, language_code)
                      confirm_button.style.pointerEvents = "none";
                      confirm_button.style.opacity = "0.6";
                      select.addEventListener("change", function (k) {
                        if (this.value && this.value.length > 0) {
                          confirm_button.style.pointerEvents = "auto";
                          confirm_button.style.opacity = "1";
                        } else {
                          confirm_button.style.pointerEvents = "none";
                          confirm_button.style.opacity = "0.6";
                        }
                      });
                      confirm_button.addEventListener("click", function (k) {
                        if (document.getElementById("radio-type-dropdown")) {
                          var drp = document.getElementById("radio-type-dropdown");
                          if (drp.value && drp.value.length > 0) {
                            if (agreed) {
                              takingRadioValue(drp.value, main_options_div);
                            } else {
                              k.preventDefault();
                            }
                          }
                        }
                      });
                      main_options_div.appendChild(select);
                      main_options_div.appendChild(confirm_button);
                      if (font && font.length > 0) {
                        select.classList.add(font);
                      }
                    }else if(question_array[0].error_text == 'list view'){
    
                      var optionsArray = question_array[0].default_options.split(";;");
                    
                      function createOptions(options) {
                        form_whatsapp_list.innerHTML = "";  
                        options.forEach(function(option, index) {
                            var label = document.createElement("label");
                            label.setAttribute("for", "0" + (index + 1));
                            label.textContent = option;
                    
                            var input = document.createElement("input");
                            input.setAttribute("id", "0" + (index + 1));
                            input.setAttribute("type", "radio");
                            input.setAttribute("name", "r");
                            input.setAttribute("value", option);
                            if (index == 0) input.setAttribute("checked", "checked");
                    
                            if (font && font.length > 0) {
                                label.classList.add(font);
                            }
                    
                            form_whatsapp_list.appendChild(label);
                            form_whatsapp_list.appendChild(input);
                        });
                     }
                    
                      createOptions(optionsArray);
                    
                      search_bar_Input.addEventListener('input', function() {
                          var searchTerm = search_bar_Input.value.toLowerCase();
                          var filteredOptions = optionsArray.filter(function(option) {
                              return option.toLowerCase().includes(searchTerm);
                          });
                          createOptions(filteredOptions);
                      });
                      
                          submit_btn.addEventListener("click", function() {
                            var selectedOption = document.querySelector('input[name="r"]:checked');
                            if (selectedOption) {
                                // console.log("Selected Value: " + selectedOption.value);
                                if (agreed) {
                                  
                              var radioMenu = document.getElementById("open-menu-sb");
                              var optionsDiv = document.getElementsByClassName('options-div-smatest');
                                  
                                if (radioMenu && optionsDiv.length > 0) {
                                  if (optionsDiv[optionsDiv.length - 1].contains(radioMenu)) {
                                      optionsDiv[optionsDiv.length - 1].removeChild(radioMenu);
                                  }
                                }
                    
                                  takingRadioValue(selectedOption.value, bg_shadow_radio);
                    
                                } else {
                                  k.preventDefault();
                                }
                            }
                        });
                    
                    } 
                     else {
                      var optionsArray =
                        question_array[0].default_options.split(";;");
                      for (var i = 0; i < optionsArray.length; i++) {
                        var radio_text = document.createElement("label");
                        var span = document.createElement("span");
                        span.innerHTML = optionsArray[i];
                        speakable_str = speakable_str + " " + span.innerText;
                        if (i != optionsArray.length - 1) {
                          speakable_str = speakable_str + " or ";
                        }
                        if (question_array[0].error_text == "horizontal") {
                          span.classList.add("w-auto-i");
                        }
                        var check = document.createElement("DIV");
                        check.classList.add("check-smatest");
                        var radio = document.createElement("input");
                        radio.type = "radio";
                        radio.name = "radio_option";
                        // radio.value = span.innerText;
                        radio.value = span.innerHTML;
                        radio.classList.add("radio-botest");
                        radio_text.classList.add("options-smatest");
                        radio_text.style.cssText = radio_text.style.cssText + "margin-bottom: 6px !important;";
                        if (
                          (main_lang_code &&
                            (main_lang_code == "he" ||
                              main_lang_code == "ur" ||
                              main_lang_code == "ar")) ||
                          (main_lang_code == "default" &&
                            (language_code == "ar" ||
                              language_code == "he" ||
                              language_code == "ur"))
                        ) {
                          radio_text.classList.add("rtl");
                          radio_text.style.textAlign = "right";
                        }
                        if (question_array[0].error_text == "horizontal") {
                          radio_text.classList.add("w-auto-i");
                          radio_text.classList.add("m-r-6");
                          radio_text.classList.add("pull-left");
                          radio_text.classList.add("m-b-6");
                        }
                        radio_text.id = span.innerText;
                        radio_text.appendChild(radio);
                        radio_text.appendChild(check);
                        radio_text.appendChild(span);
                        main_options_div.appendChild(radio_text);
                        if (
                          /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                            navigator.userAgent
                          )
                        ) {
                          radio_text.addEventListener("click", function (k) {
                            if (agreed) {
                              takingRadioValue(this.id, main_options_div);
                            } else {
                              k.preventDefault();
                            }
                          });
                        } else {
                          radio.addEventListener("click", function (k) {
                            if (agreed) {
                              takingRadioValue(this.value, main_options_div);
                            } else {
                              k.preventDefault();
                            }
                          });
                        }
                      }
                    }
                  } else {
                    is_radio_hidden = true;
                    radio_options = [];
                    radio_options = question_array[0].default_options.split(";;");
                    input.type = "text";
                    input.placeholder = "Enter your option";
                    input.style.pointerEvents = "auto";
                    enter.style.pointerEvents = "auto";
                    footer.style.display = "block";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.classList.remove("close");
                    input.value = "";
                    if (document.getElementById("live-file-input")) {
                      document.getElementById("live-file-input").value = "";
                    }
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                  if (optionsArray && optionsArray.length < 4) {
                  }
                }
                if (j == 0) {
                  j++;
                  body.appendChild(questionDIv);
                  if (optionsArray && optionsArray.length < 4) {
                  }
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      if (chatbot_id != 10561 && chatbot_id != 14372) {
                        body.scrollTop = body.scrollHeight - 70;
                      }
                    }, 0);
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      if (!is_hidden) {
                        if (question_array[0].error_text == 'list view') {
                          
                        }else{
                          body.appendChild(main_options_div);
                        }
                      }
                    }, delay_time);
                    setTimeout(function () {
                      if (chatbot_id != 10561 && chatbot_id != 14372) {
                        body.scrollTop = body.scrollHeight;
                      }
                    }, delay_time + 10);
                    option_div.classList.remove("m-b-10");
                    iconDiv.classList.remove("m-b-10");
                  }
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        if (chatbot_id != 10561 && chatbot_id != 14372) {
                          body.scrollTop = body.scrollHeight - 70;
                        }
                      }, 0);
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        if (chatbot_id != 10561 && chatbot_id != 14372) {
                          body.scrollTop = body.scrollHeight;
                        }
                      }, delay_time + 10);
                      option_div.classList.remove("m-b-10");
                      iconDiv.classList.remove("m-b-10");
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
        }
      
        function handleChangePostCode(k) {
          let post_code = k.target.value, address_dropdown = document.getElementById('form-input-1');
          let matched = post_code.match(/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$/gi);
          if (matched && matched.length > 0) {
            var xhr = new XMLHttpRequest();
            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4 && this.status === 200) {
                let address_json = JSON.parse(this.responseText);
                if (address_json && address_json.length > 0) {
                  address_json = address_json.map((item, innerIndex) => {
                    let option = document.createElement('OPTION');
                    option.value = item.Id;
                    if (innerIndex == 0) {
                      handleChangeAddress(item.Id);
                    }
                    option.innerHTML = item.Postcode;
                    if (address_dropdown) {
                      address_dropdown.appendChild(option);
                    }
                    return item;
                  })
                } else {
                  if (address_dropdown) {
                    address_dropdown.innerHTML = "";
                  }
                }
              } else if (this.readyState === 4) {
                if (address_dropdown) {
                  address_dropdown.innerHTML = "";
                }
              }
            });
            xhr.open("GET", "https://pm247uat.azurewebsites.net/Account/IsPostcodeValid?postcode=" + post_code);
            xhr.send();
          } else {
            if (address_dropdown) {
              address_dropdown.innerHTML = "";
            }
          }
        }

        function handleChangeAddress(address_val) {
          var xhr = new XMLHttpRequest();
          xhr.addEventListener("readystatechange", function () {
            if (this.readyState === 4) {
              if (this.status === 200) {
                let address_array = JSON.parse(this.responseText);
                if (address_array && address_array.length > 0) {
                  if (address_array[0].AddressLine1 && address_array[0].AddressLine1.length > 0) {
                    document.getElementById('form-input-2').value = address_array[0].AddressLine1;
                  }
                  if (address_array[0].AddressLine2 && address_array[0].AddressLine2.length > 0) {
                    document.getElementById('form-input-3').value = address_array[0].AddressLine2;
                  }
                  if (address_array[0].AddressLine3 && address_array[0].AddressLine3.length > 0) {
                    document.getElementById('form-input-4').value = address_array[0].AddressLine3;
                  }
                  if (address_array[0].Town && address_array[0].Town.length > 0) {
                    document.getElementById('form-input-5').value = address_array[0].Town;
                  }
                  if (address_array[0].County && address_array[0].County.length > 0) {
                    document.getElementById('form-input-6').value = address_array[0].County;
                  }
                  if (address_array[0].Company && address_array[0].Company.length > 0) {
                    document.getElementById('form-input-7').value = address_array[0].Company;
                  }
                  // if (address_array[0].Type && address_array[0].Type.length > 0) {
                  //   document.getElementById('form-input-9').value = address_array[0].Type;
                  // }
                }
              }
            }
          });
          xhr.open("GET", "https://pm247uat.azurewebsites.net/account/GetFullAddress?id=" + encodeURIComponent(address_val));
          xhr.send();
        }

        // Define the debounced function
        const debouncedCb = debounce(handleChangePostCode, 100);
        const debouncedCAddress = debounce(handleChangeAddress, 100);

        function callForm(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr, array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          var scrollable_height = body.scrollHeight;
          if (question_arr && question_arr.length > 0) {
            var j = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                if (currentMailSequence) {
                  questionDIv.id = "form-question-div-" + currentMailSequence;
                } else {
                  questionDIv.id = "form-question-div-" + 0;
                }
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest-for-form");
                main_options_div.classList.add("some-animation");
                main_options_div.style.background = '#fff'
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                var is_dropdown;
                if (
                  question_array[0].error_text &&
                  question_array[0].error_text.length > 0
                ) {
                  if (question_array[0].error_text == "dropdown") {
                    is_dropdown = true;
                  }
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var json = JSON.parse(question_array[0].default_options);
                    var form_questions = json.questions;
                    if (form_questions && form_questions.length > 0) {
                      for (var i = 0; i < form_questions.length; i++) {
                        if (form_questions[i].type == "question") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          form_question_label.style.fontSize = "13px";
                          form_question_label.style.cssText =
                            form_question_label.style.cssText +
                            "text-transform: capitalize !important";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          // if (
                          //   form_questions[i].desc &&
                          //   form_questions[i].desc.length > 0
                          // ) {
                          //   form_question_div.appendChild(form_question_desc);
                          // }
                          var form_question_input = document.createElement("INPUT");
                          if ((question_array[0].id == "937017" && form_questions[i].text == "Notes") || (question_array[0].id == "937021" && form_questions[i].text == "Notes")) {
                            form_question_input = document.createElement("TEXTAREA");
                          }
                          form_question_input.classList.add("form-question-input");
                          form_question_input.id = "form-input-" + i;
                          if (font && font.length > 0) {
                            form_question_input.classList.add(font);
                          }

                          if (
                            question_array[0].id == "936429" &&
                            form_questions[i].text == "Company Name"
                          ) {
                            form_question_div.style.display = 'none';
                          }

                          form_question_input.addEventListener("focus", function (e) {
                            e.target.style.cssText = e.target.style.cssText + "border:1px solid rgb(56, 97, 251) !important";
                            e.target.style.boxShadow = "0px 0px 0px 4px rgb(230, 240, 255)";
                          });
                          form_question_input.addEventListener("blur", function (e) {
                            e.target.style.border = ""; 
                            e.target.style.boxShadow = "";
                          });

                          if ((question_array[0].id == "1809559" || question_array[0].id == "937017" || question_array[0].id == "937036" || question_array[0].id == "937021") && form_questions[i].text == "Post Code") {
                            form_question_input.addEventListener(
                              "input",
                              function (k) {
                                let matched = this.value.match(/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})$/gi);
                                if (matched && matched.length > 0) {

                                } else {
                                  let address_line_dropdown = document.getElementById("form-input-1");
                                  if (address_line_dropdown) {
                                    address_line_dropdown.innerHTML = "";
                                  }
                                }
                              }
                            );
                            form_question_input.addEventListener(
                              "keypress",
                              debouncedCb
                            );
                          }
                          else {
                            form_question_input.addEventListener(
                              "keypress",
                              function (k) {
                                this.style.borderColor = "#e6e6e6";
                                this.previousSibling.click();
                              }
                            );
                            form_question_input.addEventListener(
                              "change",
                              function (k) {
                                this.style.borderColor = "#e6e6e6";
                                this.previousSibling.click();
                              }
                            );
                          }
                          if ( form_questions[i].desc && form_questions[i].desc.length > 0) {
                            form_question_input.placeholder =  form_questions[i].desc;  
                          }else{
                            form_question_input.placeholder =  form_questions[i].text;  
                          }
                          form_question_div.appendChild(form_question_input);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].type == "dropdown") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          // if (
                          //   form_questions[i].desc &&
                          //   form_questions[i].desc.length > 0
                          // ) {
                          //   form_question_div.appendChild(form_question_desc);
                          // }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          var form_options = form_questions[i].options.split(",");
                          if (form_options && form_options.length > 0) {
                            var option = document.createElement("option");
                            option.value = "";
                            option.innerHTML = form_questions[i].text;
                            form_question_select.appendChild(option);
                            for (var t = 0; t < form_options.length; t++) {
                              var option = document.createElement("option");
                              option.value = form_options[t];
                              option.innerHTML = form_options[t];
                              form_question_select.appendChild(option);
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          if (
                            question_array[0].id == "936429" &&
                            form_questions[i].text == "Customer Type"
                          ) {
                            form_question_select.addEventListener(
                              "change",
                              function (k) {
                                var k = this.value;
                                if (k == "Individual") {
                                  var elem =
                                    document.getElementById(
                                      "form-input-2"
                                    ).parentElement;

                                  elem.style.display = "none";
                                } else {
                                  var elem =
                                    document.getElementById(
                                      "form-input-2"
                                    ).parentElement;
                                  elem.style.display = "block";
                                }
                              }
                            );
                          } else if ((question_array[0].id == "1809559" || question_array[0].id == "937017" || question_array[0].id == "937036" || question_array[0].id == "937021") && form_questions[i].text == "Choose the Address") {
                            form_question_select.addEventListener(
                              "change",
                              function (k) {
                                let value = k.target.value;
                                handleChangeAddress(value);
                              }
                            );
                          }
                          else if (
                            question_array[0].id == "937021" &&
                            form_questions[i].text == "Customer Type"
                          ) {
                            form_question_select.addEventListener(
                              "change",
                              function (k) {
                                var k = this.value;
                                if (k == "Individual") {
                                  var elem =
                                    document.getElementById(
                                      "form-input-9"
                                    ).parentElement;

                                  elem.style.display = "none";
                                } else {
                                  var elem =
                                    document.getElementById(
                                      "form-input-9"
                                    ).parentElement;
                                  elem.style.display = "block";
                                }
                              }
                            );
                          }
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        }
                      }
                      var form_submit_btn = document.createElement("BUTTON");
                      form_submit_btn.classList.add("confirm-btn-smatest-other");
                      form_submit_btn.style.cssText = form_submit_btn.style.cssText + "margin-top: 10px !important";
                      if (font && font.length > 0) {
                        form_submit_btn.classList.add(font);
                      }
                      form_submit_btn.classList.add("m-t-5");
                      form_submit_btn.classList.add("m-b-5");
                      form_submit_btn.innerHTML = "Submit";
                      main_options_div.appendChild(form_submit_btn);
                      form_submit_btn.addEventListener("click", function (k) {
                        var object = {};
                        for (var i = 0; i < form_questions.length; i++) {
                          var proceed;
                          var regex;
                          if (
                            form_questions[i].regex &&
                            form_questions[i].regex.length > 0
                          ) {
                            try {
                              regex = new RegExp(form_questions[i].regex);
                            } catch (e) {
                              regex = form_questions[i].regex;
                            } finally {
                            }
                            var val = document.getElementById(
                              "form-input-" + i
                            ).value;
                            if (regex.test(val)) {
                              proceed = true;
                            } else {
                              if (form_questions[i].is_req) {
                                document.getElementById(
                                  "form-input-" + i
                                ).style.borderColor = "red";
                                proceed = false;
                                return false;
                              } else {
                                if (
                                  document.getElementById("form-input-" + i)
                                    .value &&
                                  document.getElementById("form-input-" + i).value
                                    .length > 0
                                ) {
                                  document.getElementById(
                                    "form-input-" + i
                                  ).style.borderColor = "red";
                                  proceed = false;
                                  return false;
                                }
                              }
                            }
                          }
                          if (form_questions[i].is_req) {
                            if (
                              document.getElementById("form-input-" + i) &&
                              document.getElementById("form-input-" + i).value &&
                              document.getElementById("form-input-" + i).value
                                .length > 0
                            ) {
                              document.getElementById(
                                "form-input-" + i
                              ).style.borderColor = "green";
                            } else {
                              document.getElementById(
                                "form-input-" + i
                              ).style.borderColor = "red";
                              return false;
                            }
                          }
                          object[form_questions[i].text] = document.getElementById(
                            "form-input-" + i
                          ).value;
                        }
                        form_value = JSON.stringify(object);
                        input.value = JSON.stringify(object);
                        main_options_div.parentElement.removeChild(
                          main_options_div
                        );
                        inputEntered();
                      });
                    }
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  body.appendChild(questionDIv);
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight - 70;
                    }, 0);
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                    option_div.classList.remove("m-b-10");
                    iconDiv.classList.remove("m-b-10");
                  }
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight - 70;
                      }, 0);
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                      option_div.classList.remove("m-b-10");
                      iconDiv.classList.remove("m-b-10");
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
        }

        function callOpstronForm(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          var scrollable_height = body.scrollHeight;
          if (question_arr && question_arr.length > 0) {
            var j = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                if (currentMailSequence) {
                  questionDIv.id = "form-question-div-" + currentMailSequence;
                } else {
                  questionDIv.id = "form-question-div-" + 0;
                }
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest-for-form");
                main_options_div.classList.add("some-animation");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                var is_dropdown;
                if (
                  question_array[0].error_text &&
                  question_array[0].error_text.length > 0
                ) {
                  if (question_array[0].error_text == "dropdown") {
                    is_dropdown = true;
                  }
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var json = JSON.parse(question_array[0].default_options);
                    var form_questions = json.questions;
                    if (form_questions && form_questions.length > 0) {
                      for (var i = 0; i < form_questions.length; i++) {
                        if (form_questions[i].text == "Customer Name") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          if (opstron_customers && opstron_customers.length > 0) {
                            let need_select = true;
                            let temp_qas = question_and_answers.map((qa_item) => {
                              if (qa_item.id == "937027" || qa_item.id == "2600847") {
                                need_select = false;
                              }
                            })
                            var select_option = document.createElement("option");
                            select_option.value = "";
                            select_option.innerHTML = generateTranslatedContent(translations, "Select", main_lang_code, language_code, input);
                            if (need_select) {
                              form_question_select.appendChild(select_option);
                            }
                            let final_customers = [], temp_final_customers = [];
                            final_customers.push(opstron_customers[0]);
                            for (let index_pp = 1; index_pp < opstron_customers.length; index_pp++) {
                              let temp_element = opstron_customers[index_pp];
                              temp_final_customers.push(temp_element);
                            }
                            temp_final_customers.sort((a, b) => a.FullName - b.FullName);
                            for (let index_pp = 0; index_pp < temp_final_customers.length; index_pp++) {
                              let temp_element = temp_final_customers[index_pp];
                              final_customers.push(temp_element);
                            }
                            console.log(final_customers);
                            // opstron_customers.sort((a, b) => a.FullName - b.FullName);
                            for (var t = 0; t < final_customers.length; t++) {
                              var option = document.createElement("option");
                              var obj = {
                                FullName: final_customers[t].FullName,
                                CustId: final_customers[t].CustId,
                              };
                              option.value = JSON.stringify(obj);
                              option.innerHTML = final_customers[t].FullName + " (" + final_customers[t].PostCode + ") " + final_customers[t].Email;
                              form_question_select.appendChild(option);
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          form_question_select.addEventListener(
                            "change",
                            function (k) {
                              var elem = document.getElementById(
                                "form-input-contact-number-1"
                              ), land_elem = document.getElementById(
                                "form-input-2"
                              );
                              var value = JSON.parse(this.value);
                              for (let k = 0; k < opstron_customers.length; k++) {
                                if (
                                  value &&
                                  value.FullName &&
                                  opstron_customers[k] &&
                                  opstron_customers[k].FullName == value.FullName
                                ) {
                                  const element = opstron_customers[k];
                                  var mobile, landline;
                                  if (
                                    element.MobileNo &&
                                    element.MobileNo != null
                                  ) {
                                    mobile = element.MobileNo;
                                  }
                                  if (
                                    element.Landline &&
                                    element.Landline != null
                                  ) {
                                    landline = element.Landline;
                                  }
                                  break;
                                }
                              }
                              if (mobile && mobile.length > 0) {
                                elem.value = mobile;
                              }
                              if (landline && landline.length > 0) {
                                land_elem.value = landline;
                              }
                            }
                          );
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].text == "Booking Agent") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          if (opstron_agents && opstron_agents.length > 0) {
                            var option_d = document.createElement("option");
                            option_d.value = "";
                            option_d.innerHTML = "Select";
                            form_question_select.appendChild(option_d);
                            opstron_agents = opstron_agents.sort((a, b) => a.Text - b.Text);
                            for (var t = 0; t < opstron_agents.length; t++) {
                              var option = document.createElement("option");
                              option.value = opstron_agents[t].Text;
                              option.innerHTML = opstron_agents[t].Text;
                              form_question_select.appendChild(option);
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].text == "Advertising Source") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          if (opstron_ads && opstron_ads.length > 0) {
                            var option_d = document.createElement("option");
                            option_d.value = "";
                            option_d.innerHTML = "Select";
                            form_question_select.appendChild(option_d);
                            opstron_ads = opstron_ads.sort((a, b) => a.ChannelName - b.ChannelName);
                            for (var t = 0; t < opstron_ads.length; t++) {
                              var option = document.createElement("option");
                              option.value = opstron_ads[t].ChannelName;
                              option.innerHTML = opstron_ads[t].ChannelName;
                              form_question_select.appendChild(option);
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].text == "Job Type") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          form_question_select.addEventListener(
                            "change",
                            function (k) {
                              var elem = document.getElementById(
                                "form-input-job-description-8"
                              );
                              var value = this.value;
                              if (
                                value &&
                                opstron_jds &&
                                elem &&
                                opstron_jds[value]
                              ) {
                                elem.value = opstron_jds[value];
                              } else {
                                elem.value = "";
                              }
                            }
                          );
                          var opstron_jds_keys = Object.keys(opstron_jds);
                          if (opstron_jds_keys && opstron_jds_keys.length > 0) {
                            var option_d = document.createElement("option");
                            option_d.value = "";
                            option_d.innerHTML = "Select";
                            form_question_select.appendChild(option_d);
                            opstron_jds_keys = opstron_jds_keys.sort((a, b) => a - b);
                            for (var t = 0; t < opstron_jds_keys.length; t++) {
                              var option = document.createElement("option");
                              option.value = opstron_jds_keys[t];
                              option.innerHTML = opstron_jds_keys[t];
                              form_question_select.appendChild(option);
                              for (let index_jt = 0; index_jt < question_and_answers.length; index_jt++) {
                                let single_qa = question_and_answers[index_jt];
                                if ((single_qa.id == '921416' || single_qa.id == '2600840') && single_qa.answer && single_qa.answer.length > 0 && single_qa.answer == opstron_jds_keys[t]) {
                                  form_question_select.value = opstron_jds_keys[t];
                                  break;
                                }
                              }
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].text == "Job Description") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }

                          var form_question_input = document.createElement("TEXTAREA");
                          form_question_input.classList.add("form-question-input");
                          form_question_input.id =
                            "form-input-job-description-" + i;
                          if (font && font.length > 0) {
                            form_question_input.classList.add(font);
                          }
                          var opstron_jds_keys = Object.keys(opstron_jds);
                          // if (opstron_jds_keys && opstron_jds_keys.length > 0) {
                          //   form_question_input.value =
                          //     opstron_jds[opstron_jds_keys[0]];
                          // }
                          var opstron_jds_keys = Object.keys(opstron_jds);
                          if (opstron_jds_keys && opstron_jds_keys.length > 0) {
                            opstron_jds_keys = opstron_jds_keys.sort((a, b) => a - b);
                            for (var t = 0; t < opstron_jds_keys.length; t++) {
                              for (let index_jt = 0; index_jt < question_and_answers.length; index_jt++) {
                                let single_qa = question_and_answers[index_jt];
                                if ((single_qa.id == '921416' || single_qa.id == '2600840') && single_qa.answer && single_qa.answer.length > 0 && single_qa.answer == opstron_jds_keys[t]) {
                                  form_question_input.value = opstron_jds[opstron_jds_keys[t]];
                                  break;
                                }
                              }
                            }
                          }
                          form_question_input.addEventListener(
                            "keypress",
                            function (k) {
                              this.style.borderColor = "#e6e6e6";
                              this.previousSibling.click();
                            }
                          );
                          form_question_input.addEventListener(
                            "change",
                            function (k) {
                              this.style.borderColor = "#e6e6e6";
                              this.previousSibling.click();
                            }
                          );
                          form_question_input.placeholder = form_questions[i].text;
                          form_question_div.appendChild(form_question_input);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].text == "Job Price") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          // var opstron_jds_keys = Object.keys(opstron_jds);
                          if (opstron_job_prices && opstron_job_prices.length > 0) {
                            opstron_job_prices = opstron_job_prices.sort((a, b) => a.JobPriceName - b.JobPriceName);
                            for (var t = 0; t < opstron_job_prices.length; t++) {
                              var option = document.createElement("option");
                              var obj = {
                                JobPriceName: opstron_job_prices[t].JobPriceName,
                                JobPriceId: opstron_job_prices[t].JobPriceId,
                              };
                              option.value = JSON.stringify(obj);
                              option.value = opstron_job_prices[t].JobPriceName;
                              option.innerHTML = opstron_job_prices[t].JobPriceName;
                              form_question_select.appendChild(option);
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].text == "Contact number") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          form_question_label.style.fontSize = "13px";
                          form_question_label.style.cssText =
                            form_question_label.style.cssText +
                            "text-transform: capitalize !important";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_input = document.createElement("INPUT");
                          form_question_input.classList.add("form-question-input");
                          form_question_input.id = "form-input-contact-number-" + i;
                          if (font && font.length > 0) {
                            form_question_input.classList.add(font);
                          }
                          if (opstron_customers && opstron_customers.length > 0) {
                            form_question_input.value =
                              opstron_customers[0].MobileNo;
                          }
                          form_question_input.addEventListener(
                            "keypress",
                            function (k) {
                              this.style.borderColor = "#e6e6e6";
                              this.previousSibling.click();
                            }
                          );
                          form_question_input.addEventListener(
                            "change",
                            function (k) {
                              this.style.borderColor = "#e6e6e6";
                              this.previousSibling.click();
                            }
                          );
                          form_question_input.placeholder = form_questions[i].text;
                          form_question_div.appendChild(form_question_input);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].type == "question") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          form_question_label.style.fontSize = "13px";
                          form_question_label.style.cssText =
                            form_question_label.style.cssText +
                            "text-transform: capitalize !important";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_input = document.createElement("INPUT");
                          form_question_input.classList.add("form-question-input");
                          form_question_input.id = "form-input-" + i;
                          if (font && font.length > 0) {
                            form_question_input.classList.add(font);
                          }
                          form_question_input.addEventListener(
                            "keypress",
                            function (k) {
                              this.style.borderColor = "#e6e6e6";
                              this.previousSibling.click();
                            }
                          );
                          form_question_input.addEventListener(
                            "change",
                            function (k) {
                              this.style.borderColor = "#e6e6e6";
                              this.previousSibling.click();
                            }
                          );
                          if (form_questions[i].text == "Landline") {
                            if (opstron_customers && opstron_customers.length > 0) {
                              form_question_input.value =
                                opstron_customers[0].Landline;
                            }
                          }
                          form_question_input.placeholder = form_questions[i].text;
                          form_question_div.appendChild(form_question_input);
                          main_options_div.appendChild(form_question_div);
                        } else if (form_questions[i].type == "dropdown") {
                          var form_question_div = document.createElement("DIV");
                          form_question_div.classList.add("pull-left");
                          form_question_div.classList.add("full-width");
                          form_question_div.classList.add("m-t-5");
                          var form_question_label = document.createElement("LABEL");
                          form_question_label.classList.add("pull-left");
                          form_question_label.classList.add("full-width");
                          form_question_label.innerHTML = form_questions[i].text;
                          form_question_label.style.fontSize = "13px";
                          var form_question_desc = document.createElement("LABEL");
                          form_question_desc.classList.add("pull-left");
                          form_question_desc.classList.add("full-width");
                          form_question_desc.innerHTML = form_questions[i].desc;
                          form_question_desc.style.fontSize = "11px";
                          form_question_desc.style.marginTop = "4px";
                          form_question_desc.style.marginBottom = "4px";
                          form_question_desc.style.color = "grey";
                          if (font && font.length > 0) {
                            form_question_label.classList.add(font);
                          }
                          if (form_questions[i].is_req) {
                            form_question_label.innerHTML =
                              form_question_label.innerHTML +
                              '<span class="red m-l-5">*</span>';
                          }
                          form_question_div.appendChild(form_question_label);
                          if (
                            form_questions[i].desc &&
                            form_questions[i].desc.length > 0
                          ) {
                            form_question_div.appendChild(form_question_desc);
                          }
                          var form_question_select =
                            document.createElement("SELECT");
                          form_question_select.id = "form-input-" + i;
                          var form_options = form_questions[i].options.split(",");
                          if (form_options && form_options.length > 0) {
                            form_options = form_options.sort((a, b) => a - b);
                            for (var t = 0; t < form_options.length; t++) {
                              var option = document.createElement("option");
                              option.value = form_options[t];
                              option.innerHTML = form_options[t];
                              form_question_select.appendChild(option);
                            }
                          }
                          if (font && font.length > 0) {
                            form_question_select.classList.add(font);
                          }
                          form_question_select.classList.add(
                            "form-question-select"
                          );
                          form_question_div.appendChild(form_question_select);
                          main_options_div.appendChild(form_question_div);
                        }
                      }
                      var form_submit_btn = document.createElement("BUTTON");
                      form_submit_btn.classList.add("confirm-btn-smatest-other");
                      if (font && font.length > 0) {
                        form_submit_btn.classList.add(font);
                      }
                      form_submit_btn.classList.add("m-t-5");
                      form_submit_btn.classList.add("m-b-5");
                      form_submit_btn.innerHTML = "Submit";
                      main_options_div.appendChild(form_submit_btn);
                      form_submit_btn.addEventListener("click", function (k) {
                        var object = {};
                        for (var i = 0; i < form_questions.length; i++) {
                          var proceed;
                          var regex;
                          if (
                            form_questions[i].regex &&
                            form_questions[i].regex.length > 0
                          ) {
                            try {
                              regex = new RegExp(form_questions[i].regex);
                            } catch (e) {
                              regex = form_questions[i].regex;
                            } finally {
                            }
                            var val = document.getElementById(
                              "form-input-" + i
                            ).value;
                            if (regex.test(val)) {
                              proceed = true;
                            } else {
                              if (form_questions[i].is_req) {
                                document.getElementById(
                                  "form-input-" + i
                                ).style.borderColor = "red";
                                proceed = false;
                                return false;
                              } else {
                                if (
                                  document.getElementById("form-input-" + i)
                                    .value &&
                                  document.getElementById("form-input-" + i).value
                                    .length > 0
                                ) {
                                  document.getElementById(
                                    "form-input-" + i
                                  ).style.borderColor = "red";
                                  proceed = false;
                                  return false;
                                }
                              }
                            }
                          }
                          if (form_questions[i].is_req) {
                            var id;
                            if (i == 1) {
                              id = "form-input-contact-number-" + i;
                            } else if (i == 8) {
                              id = "form-input-job-description-" + i;
                            } else {
                              id = "form-input-" + i;
                            }
                            if (
                              document.getElementById(id) &&
                              document.getElementById(id).value &&
                              document.getElementById(id).value.length > 0
                            ) {
                              document.getElementById(id).style.borderColor =
                                "green";
                            } else {
                              document.getElementById(id).style.borderColor = "red";
                              return false;
                            }
                          }
                          if (i == 1) {
                            object[form_questions[i].text] =
                              document.getElementById(
                                "form-input-contact-number-" + i
                              ).value;
                          } else if (i == 8) {
                            object[form_questions[i].text] =
                              document.getElementById(
                                "form-input-job-description-" + i
                              ).value;
                          } else {
                            object[form_questions[i].text] =
                              document.getElementById("form-input-" + i).value;
                          }
                        }
                        form_value = JSON.stringify(object);
                        input.value = JSON.stringify(object);
                        main_options_div.parentElement.removeChild(
                          main_options_div
                        );
                        inputEntered();
                      });
                    }
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  body.appendChild(questionDIv);
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight - 70;
                    }, 0);
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                    option_div.classList.remove("m-b-10");
                    iconDiv.classList.remove("m-b-10");
                  }
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight - 70;
                      }, 0);
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                      option_div.classList.remove("m-b-10");
                      iconDiv.classList.remove("m-b-10");
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
        }

        function selectedOrdersView(arr) {
          var selected_orders_div_delete =
            document.getElementById("selected-orders");
          if (
            selected_orders_div_delete &&
            footer.contains(selected_orders_div_delete)
          ) {
            footer.removeChild(selected_orders_div_delete);
          }
          var selected_orders_div = document.createElement("DIV");
          selected_orders_div.id = "selected-orders";
          selected_orders_div.classList.add("pull-left");
          selected_orders_div.classList.add("full-width");
          for (var i = 0; i < arr.length; i++) {
            var order_div = document.createElement("DIV");
            order_div.classList.add("selected-order-div");
            var order_label = document.createElement("LABEL");
            if (font && font.length > 0) {
              order_label.classList.add(font);
            }
            order_label.innerHTML = arr[i].display_name;
            var order_delete = document.createElement("I");
            order_delete.classList.add("selected-order-delete-icon");
            order_delete.id = arr[i].id;
            order_delete.addEventListener("click", function (k) {
              var id = this.id;
              for (var i = 0; i < selected_orders.length; i++) {
                if (selected_orders[i].id == this.id) {
                  selected_orders.splice(i, 1);
                  break;
                }
              }
              this.parentElement.parentElement.removeChild(this.parentElement);
              var auto_complete_div = document.getElementById(
                "order-autocomplete-list"
              );
              footer.style.height = "auto";
              var footer_height = input.parentElement.clientHeight + 33;
              if (auto_complete_div) {
                auto_complete_div.style.cssText =
                  auto_complete_div.style.cssText +
                  "bottom:" +
                  footer_height +
                  "px !important";
              }
              setTimeout(function () {
                var body_margin_height;
                if (header.contains(company_title_description)) {
                  body_margin_height = input.parentElement.clientHeight + 33 + 135;
                } else {
                  body_margin_height = input.parentElement.clientHeight + 33 + 60;
                }
                body.style.height = "calc(100% - " + body_margin_height + "px)";
              }, 10);
            });
            order_div.appendChild(order_label);
            order_div.appendChild(order_delete);
            selected_orders_div.appendChild(order_div);
          }
          footer.prepend(selected_orders_div);
          var auto_complete_div = document.getElementById(
            "order-autocomplete-list"
          );
          footer.style.height = "auto";
          var footer_height = input.parentElement.clientHeight + 33;
          auto_complete_div.style.cssText =
            auto_complete_div.style.cssText +
            "bottom:" +
            footer_height +
            "px !important";
          setTimeout(function () {
            var body_margin_height;
            if (header.contains(company_title_description)) {
              body_margin_height = input.parentElement.clientHeight + 33 + 135;
            } else {
              body_margin_height = input.parentElement.clientHeight + 33 + 60;
            }
            body.style.height = "calc(100% - " + body_margin_height + "px)";
          }, 10);
        }

        function orderAutocomplete() {
          var currentFocus;
          var inp = input;
          var a,
            b,
            i,
            val = inp.value;
          closeAllLists();
          currentFocus = -1;
          var arr = [];
          for (var t = 0; t < order_items.length; t++) {
            arr.push(order_items[t]);
          }
          a = document.createElement("DIV");
          a.setAttribute("id", inp.id + "order-autocomplete-list");
          a.setAttribute("class", "autocomplete-items");
          var left_scroll_icon = document.createElement("I");
          left_scroll_icon.id = "order-scroll-button-left";
          left_scroll_icon.classList.add("order-scroll-button-left");
          left_scroll_icon.addEventListener("click", function (k) {
            a.scrollLeft = a.scrollLeft - 170;
          });
          a.appendChild(left_scroll_icon);
          var right_scroll_icon = document.createElement("I");
          right_scroll_icon.id = "order-scroll-button";
          right_scroll_icon.classList.add("order-scroll-button");
          right_scroll_icon.addEventListener("click", function (k) {
            a.scrollLeft = a.scrollLeft + 170;
          });
          a.appendChild(right_scroll_icon);
          var footer_height = inp.parentElement.clientHeight + 33;
          a.style.cssText =
            a.style.cssText + "bottom:" + footer_height + "px !important";
          inp.parentNode.appendChild(a);
          if (!val) {
            if (selected_orders && selected_orders.length > 0) {
              for (var i = 0; i < selected_orders.length; i++) {
                for (var j = 0; j < arr.length; j++) {
                  if (selected_orders[i].id == arr[j].id) {
                    arr.splice(j, 1);
                    j--;
                  }
                }
              }
            }
            if (arr && arr.length > 0) {
              for (i = 0; i < arr.length; i++) {
                var start = arr[i].display_name.toLowerCase();
                var end = "";
                if (!start) {
                  start = "";
                }
                if (!end) {
                  end = "";
                }
                b = document.createElement("DIV");
                b.classList.add("single-order-div");
                if (arr[i].available_quantity && arr[i].available_quantity == "0") {
                  b.style.pointerEvents = "none";
                  b.style.background = "#d3d3d3";
                  b.style.opacity = "0.5";
                }
                var img = document.createElement("IMG");
                if (arr[i].image_url && arr[i].image_url.length > 0) {
                  img.src = arr[i].image_url;
                } else {
                  img.src =
                    "https://www.perform.network/upload/objave-paragrafi/main/default.png";
                }
                img.classList.add("single-order-image");
                b.appendChild(img);
                var details_div = document.createElement("DIV");
                details_div.classList.add("single-order-details-div");
                if (arr[i].available_quantity && arr[i].available_quantity == "0") {
                  details_div.style.pointerEvents = "none";
                  details_div.style.background = "#d3d3d3";
                  details_div.style.opacity = "0.5";
                }
                b.appendChild(details_div);
                var display_name = document.createElement("LABEL");
                display_name.classList.add("single-order-title");
                if (font && font.length > 0) {
                  display_name.classList.add(font);
                }
                display_name.innerHTML = start;
                display_name.innerHTML += end;
                display_name.innerHTML +=
                  "<input type='hidden' value='" + arr[i].id + "'>";
                details_div.appendChild(display_name);
                var quantity_label = document.createElement("LABEL");
                quantity_label.classList.add("single-order-quantity");
                var order_actions_div = document.createElement("DIV");
                order_actions_div.classList.add("order-actions");
                var add_order_button = document.createElement("I");
                add_order_button.classList.add("add-order-button");
                order_actions_div.appendChild(add_order_button);
                if (font && font.length > 0) {
                  quantity_label.classList.add(font);
                }
                quantity_label.innerHTML = arr[i].available_quantity + " left";
                var price_label = document.createElement("LABEL");
                price_label.classList.add("single-order-price");
                if (font && font.length > 0) {
                  price_label.classList.add(font);
                }
                price_label.innerHTML =
                  arr[i].currency + " " + parseInt(arr[i].price_per_item);
                details_div.appendChild(price_label);
                if (
                  arr[i].available_quantity &&
                  arr[i].available_quantity.length > 0
                ) {
                  details_div.appendChild(quantity_label);
                }
                details_div.appendChild(order_actions_div);
                b.addEventListener("click", function (e) {
                  for (var p = 0; p < order_items.length; p++) {
                    if (
                      order_items[p].id ==
                      this.getElementsByTagName("input")[0].value
                    ) {
                      selected_orders.push(order_items[p]);
                    }
                  }
                  selectedOrdersView(selected_orders);
                  inp.value = "";
                });
                a.appendChild(b);
              }
            } else {
              b = document.createElement("DIV");
              b.innerHTML = generateTranslatedContent(translations, "There are no items left", main_lang_code, language_code, input);
              b.innerHTML += "<input type='hidden' value=''>";
              b.addEventListener("click", function (e) {
                closeAllLists();
              });
              a.appendChild(b);
            }
          } else {
            if (selected_orders && selected_orders.length > 0) {
              for (var i = 0; i < selected_orders.length; i++) {
                for (var j = 0; j < arr.length; j++) {
                  if (selected_orders[i].id == arr[j].id) {
                    arr.splice(j, 1);
                    j--;
                  }
                }
              }
            }
            if (arr && arr.length > 0) {
              for (i = 0; i < arr.length; i++) {
                if (
                  arr[i] &&
                  ((arr[i].display_name &&
                    arr[i].display_name.toLowerCase().includes(val)) ||
                    (arr[i].search_keywords &&
                      arr[i].search_keywords.toLowerCase().includes(val)))
                ) {
                  var start = arr[i].display_name.toLowerCase().split(val)[0];
                  var end = arr[i].display_name.toLowerCase().split(val)[1];
                  if (!start) {
                    start = "";
                  }
                  if (!end) {
                    end = "";
                  }
                  b = document.createElement("DIV");
                  b.classList.add("single-order-div");
                  if (
                    arr[i].available_quantity &&
                    arr[i].available_quantity == "0"
                  ) {
                    b.style.pointerEvents = "none";
                    b.style.background = "#d3d3d3";
                    b.style.opacity = "0.5";
                  }
                  var img = document.createElement("IMG");
                  if (arr[i].image_url && arr[i].image_url.length > 0) {
                    img.src = arr[i].image_url;
                  } else {
                    img.src =
                      "https://www.perform.network/upload/objave-paragrafi/main/default.png";
                  }
                  img.classList.add("single-order-image");
                  b.appendChild(img);
                  var details_div = document.createElement("DIV");
                  details_div.classList.add("single-order-details-div");
                  if (
                    arr[i].available_quantity &&
                    arr[i].available_quantity == "0"
                  ) {
                    details_div.style.pointerEvents = "none";
                    details_div.style.background = "#d3d3d3";
                    details_div.style.opacity = "0.5";
                  }
                  b.appendChild(details_div);
                  var display_name = document.createElement("LABEL");
                  display_name.classList.add("single-order-title");
                  if (font && font.length > 0) {
                    display_name.classList.add(font);
                  }
                  display_name.innerHTML = start;
                  if (
                    arr[i].display_name &&
                    arr[i].display_name.toLowerCase().includes(val)
                  ) {
                    display_name.innerHTML += "<strong>" + val + "</strong>";
                  }
                  display_name.innerHTML += end;
                  display_name.innerHTML +=
                    "<input type='hidden' value='" + arr[i].id + "'>";
                  details_div.appendChild(display_name);
                  var quantity_label = document.createElement("LABEL");
                  quantity_label.classList.add("single-order-quantity");
                  var order_actions_div = document.createElement("DIV");
                  order_actions_div.classList.add("order-actions");
                  var add_order_button = document.createElement("I");
                  add_order_button.classList.add("add-order-button");
                  order_actions_div.appendChild(add_order_button);
                  if (font && font.length > 0) {
                    quantity_label.classList.add(font);
                  }
                  quantity_label.innerHTML = arr[i].available_quantity + " left";
                  var price_label = document.createElement("LABEL");
                  price_label.classList.add("single-order-price");
                  if (font && font.length > 0) {
                    price_label.classList.add(font);
                  }
                  price_label.innerHTML =
                    arr[i].currency + " " + parseInt(arr[i].price_per_item);
                  details_div.appendChild(price_label);
                  if (
                    arr[i].available_quantity &&
                    arr[i].available_quantity.length > 0
                  ) {
                    details_div.appendChild(quantity_label);
                  }
                  details_div.appendChild(order_actions_div);
                  b.addEventListener("click", function (e) {
                    for (var p = 0; p < order_items.length; p++) {
                      if (
                        order_items[p].id ==
                        this.getElementsByTagName("input")[0].value
                      ) {
                        selected_orders.push(order_items[p]);
                      }
                    }
                    selectedOrdersView(selected_orders);
                    inp.value = "";
                  });
                  a.appendChild(b);
                }
              }
            } else {
              b = document.createElement("DIV");
              b.innerHTML = generateTranslatedContent(translations, "There are no items left", main_lang_code, language_code, input);
              b.innerHTML += "<input type='hidden' value=''>";
              b.addEventListener("click", function (e) {
                closeAllLists();
              });
              a.appendChild(b);
            }
          }
          inp.addEventListener("keydown", function (e) {
            var x = document.getElementById(this.id + "autocomplete-list");
            if (x) x = x.getElementsByTagName("div");
            if (e.keyCode == 40) {
              currentFocus++;
              addActive(x);
            } else if (e.keyCode == 38) {
              currentFocus--;
              addActive(x);
            } else if (e.keyCode == 13) {
              e.preventDefault();
              if (currentFocus > -1) {
                if (x) x[currentFocus].click();
              }
            }
          });

          function addActive(x) {
            if (!x) return !1;
            removeActive(x);
            if (currentFocus >= x.length) currentFocus = 0;
            if (currentFocus < 0) currentFocus = x.length - 1;
            x[currentFocus].classList.add("autocomplete-active");
          }

          function removeActive(x) {
            for (var i = 0; i < x.length; i++) {
              x[i].classList.remove("autocomplete-active");
            }
          }

          function closeAllLists(elmnt) {
            var x = document.getElementsByClassName("autocomplete-items");
            for (var i = 0; i < x.length; i++) {
              if (elmnt != x[i] && elmnt != inp) {
                x[i].parentNode.removeChild(x[i]);
              }
            }
          }
          document.addEventListener("click", function (e) {
            if (
              e.target.id == "order-scroll-button" ||
              e.target.id == "order-scroll-button-left" ||
              e.target.id == "order-autocomplete-list"
            ) {
            } else {
              closeAllLists(e.target);
            }
          });
        }

        function autocomplete(inp, arr) {
          if (
            real_time_search_items &&
            real_time_search_items.length > 0 &&
            real_time_search_items[0]
          ) {
            real_time_search_type = typeof real_time_search_items[0];
          }
          var currentFocus;
          var inp = input;
          var a,
            b,
            i,
            val = inp.value;
          val = val.toLowerCase();
          closeAllLists();
          var arr = [];
          for (var t = 0; t < real_time_search_items.length; t++) {
            arr.push(real_time_search_items[t]);
          }
          currentFocus = -1;
          a = document.createElement("DIV");
          a.setAttribute("id", inp.id + "autocomplete-list");
          a.setAttribute("class", "new-autocomplete-items");
          var left_scroll_icon = document.createElement("I");
          left_scroll_icon.id = "order-scroll-button-left";
          left_scroll_icon.classList.add("order-scroll-button-left");
          left_scroll_icon.addEventListener("click", function (k) {
            a.scrollLeft = a.scrollLeft - 170;
          });
          // a.appendChild(left_scroll_icon);
          var right_scroll_icon = document.createElement("I");
          right_scroll_icon.id = "order-scroll-button";
          right_scroll_icon.classList.add("order-scroll-button");
          right_scroll_icon.addEventListener("click", function (k) {
            a.scrollLeft = a.scrollLeft + 170;
          });
          // a.appendChild(right_scroll_icon);
          inp.parentNode.appendChild(a);
          if (real_time_search_type == "object") {
            if (!val) {
              for (i = 0; i < arr.length; i++) {
                var start = arr[i].name;
                var end = "";
                if (!start) {
                  start = "";
                }
                if (!end) {
                  end = "";
                }
                b = document.createElement("DIV");
                b.classList.add("single-order-div");
                var img = document.createElement("IMG");
                if (arr[i].image_url && arr[i].image_url.length > 0) {
                  img.src = arr[i].image_url;
                } else {
                  img.src =
                    "https://www.perform.network/upload/objave-paragrafi/main/default.png";
                }
                img.classList.add("single-order-image");
                b.appendChild(img);
                var display_name = document.createElement("LABEL");
                display_name.classList.add("single-order-title");
                if (font && font.length > 0) {
                  display_name.classList.add(font);
                }
                display_name.innerHTML = start;
                display_name.innerHTML += "<strong>" + val + "</strong>";
                display_name.innerHTML += end;
                display_name.innerHTML +=
                  "<input type='hidden' value='" + arr[i].name + "'>";
                b.appendChild(display_name);
                b.addEventListener("click", function (e) {
                  inp.value = this.getElementsByTagName("input")[0].value;
                  closeAllLists();
                });
                a.appendChild(b);
              }
            } else {
              for (i = 0; i < arr.length; i++) {
                if (
                  arr[i] &&
                  arr[i].name &&
                  arr[i].name.toLowerCase().includes(val)
                ) {
                  var start = arr[i].name.toLowerCase().split(val)[0];
                  var end = arr[i].name.toLowerCase().split(val)[1];
                  if (!start) {
                    start = "";
                  }
                  if (!end) {
                    end = "";
                  }
                  b = document.createElement("DIV");
                  b.classList.add("single-order-div");
                  var img = document.createElement("IMG");
                  if (arr[i].image_url && arr[i].image_url.length > 0) {
                    img.src = arr[i].image_url;
                  } else {
                    img.src =
                      "https://www.perform.network/upload/objave-paragrafi/main/default.png";
                  }
                  img.classList.add("single-order-image");
                  b.appendChild(img);
                  var display_name = document.createElement("LABEL");
                  display_name.classList.add("single-order-title");
                  if (font && font.length > 0) {
                    display_name.classList.add(font);
                  }
                  display_name.innerHTML = start;
                  display_name.innerHTML += "<strong>" + val + "</strong>";
                  display_name.innerHTML += end;
                  display_name.innerHTML +=
                    "<input type='hidden' value='" + arr[i].name + "'>";
                  b.appendChild(display_name);
                  b.addEventListener("click", function (e) {
                    inp.value = this.getElementsByTagName("input")[0].value;
                    closeAllLists();
                  });
                  a.appendChild(b);
                }
              }
            }
          } else {
            if (!val) {
              for (i = 0; i < arr.length; i++) {
                var start = arr[i].toLowerCase();
                var end = "";
                if (!start) {
                  start = "";
                }
                if (!end) {
                  end = "";
                }
                b = document.createElement("DIV");
                b.innerHTML = start;
                b.innerHTML += "<strong>" + val + "</strong>";
                b.innerHTML += end;
                b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
                b.addEventListener("click", function (e) {
                  inp.value = this.getElementsByTagName("input")[0].value;
                  closeAllLists();
                });
                a.appendChild(b);
              }
            } else {
              for (i = 0; i < arr.length; i++) {
                if (arr[i] && arr[i] && arr[i].toLowerCase().includes(val)) {
                  var start = arr[i].toLowerCase().split(val)[0];
                  var end = arr[i].toLowerCase().split(val)[1];
                  if (!start) {
                    start = "";
                  }
                  if (!end) {
                    end = "";
                  }
                  b = document.createElement("DIV");
                  b.innerHTML = start;
                  b.innerHTML += "<strong>" + val + "</strong>";
                  b.innerHTML += end;
                  b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
                  b.addEventListener("click", function (e) {
                    inp.value = this.getElementsByTagName("input")[0].value;
                    closeAllLists();
                  });
                  a.appendChild(b);
                }
              }
            }
          }
          inp.addEventListener("keydown", function (e) {
            var x = document.getElementById(this.id + "autocomplete-list");
            if (x) x = x.getElementsByTagName("div");
            if (e.keyCode == 40) {
              currentFocus++;
              addActive(x);
            } else if (e.keyCode == 38) {
              currentFocus--;
              addActive(x);
            } else if (e.keyCode == 13) {
              e.preventDefault();
              if (currentFocus > -1) {
                if (x) x[currentFocus].click();
              }
            }
          });

          function addActive(x) {
            if (!x) return !1;
            removeActive(x);
            if (currentFocus >= x.length) currentFocus = 0;
            if (currentFocus < 0) currentFocus = x.length - 1;
            x[currentFocus].classList.add("autocomplete-active");
          }

          function removeActive(x) {
            for (var i = 0; i < x.length; i++) {
              x[i].classList.remove("autocomplete-active");
            }
          }

          function closeAllLists(elmnt) {
            var x = document.getElementsByClassName("autocomplete-items");
            for (var i = 0; i < x.length; i++) {
              if (elmnt != x[i] && elmnt != inp) {
                x[i].parentNode.removeChild(x[i]);
              }
            }
            var y = document.getElementsByClassName("new-autocomplete-items");
            for (var j = 0; j < y.length; j++) {
              if (elmnt != y[j] && elmnt != inp) {
                y[j].parentNode.removeChild(y[j]);
              }
            }
          }
          document.addEventListener("click", function (e) {
            if (
              e.target.id == "order-scroll-button" ||
              e.target.id == "order-scroll-button-left"
            ) {
            } else {
              closeAllLists(e.target);
            }
          });
        }

        function debounce(func, wait, immediate) {
          var timeout;
          return function () {
            var context = this,
              args = arguments;
            var later = function () {
              timeout = null;
              if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
          };
        }
        var realTimeSearch = debounce(function () {
          autocomplete(input);
        }, 1);

        function setupParticipantContainer(participant, room) {
          if (room.localParticipant != participant) {
            var check_for_tracks;
            setInterval(function () {
              if (!check_for_tracks) {
                if (participant.tracks && participant.tracks.size > 0) {
                  check_for_tracks = true;
                  participant.tracks.forEach((track) => {
                    var remoteMediaContainer =
                      document.getElementById("remote-media");
                    track.muted = true;
                    remoteMediaContainer.appendChild(track.attach());
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, 500);
                  });
                }
              }
            }, 100);
          }
        }

        function participantConnected(participant, room) {
          setupParticipantContainer(participant, room);
          participant.tracks.forEach((publication) => {
            trackPublished(publication, participant);
          });
          participant.on("trackPublished", (publication) => {
            trackPublished(publication, participant);
          });
        }

        function trackPublished(publication, participant) {
          if (publication.track) {
            attachTrack(publication.track, participant);
          }
          publication.on("subscribed", (track) => {
            attachTrack(track, participant);
          });
          publication.on("unsubscribed", (track) => {
            detachTrack(track, participant);
          });
        }

        function detachTrack(track, participant) {
          // console.log("we dont think action is needed here");
        }

        function attachTrack(track, participant) {
          if (track.kind === "video") {
            var remoteMediaContainer = document.getElementById("remote-media");
            track.muted = true;
            remoteMediaContainer.appendChild(track.attach());
            setTimeout(function () {
              body.scrollTop = body.scrollHeight;
            }, 500);
          }
        }

        function participantDisconnected(participant) {
          if (document.getElementById(participant.sid)) {
            document
              .getElementById(participant.sid)
              .parentElement.removeChild(document.getElementById(participant.sid));
          }
        }

        function trackSubscribed(div, track) {
          track.muted = true;
          div.appendChild(track.attach());
        }

        function trackUnsubscribed(track) {
          track.detach().forEach((element) => element.remove());
        }

        function shareScreenHandler() {
          video_call_room.localParticipant.unpublishTrack(screen_sharing_object);
          screen_sharing_object.stop();
          screen_sharing_object = null;
          var screen_share_icon = document.getElementById("screen-share-icon");
          screen_share_icon.src =
            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
          screen_share_icon.src =
            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
          var remote_div = document.getElementById("remote-media");
          remote_div.removeChild(remote_div.lastChild);
          sock.emit("stop-screen-share", {
            bot_id: chatbot_id,
            session_id: live_chat_cb_session,
            device_print: device_print,
          });
        }

        var proceed_to_live_chat = false;
        function callLiveAgent(question_array) {
          var proceed_to_live_chat = false;
          var video_call_key;
          // Refreshed Chats Popup (Websocket Disconnect Popup)
          // Function to display the modal
          function displayReconnectPopup() {
            let activeSockets = [];
            let reconnectAttempts = 0;
            const maxReconnectAttempts = 5;
            const reconnectDelay = 2000;

            var user_src = window.location.href;
            if (
              question_array[0].departments &&
              question_array[0].departments.length > 0
            ) {
              department_settings = question_array[0].departments;
            }
            var dept_value = "";
            if (json && json.is_custom_dept) {
              if (department_settings && department_settings.length > 0) {
                for (var n = 0; n < department_settings.length; n++) {
                  if (question_and_answers && question_and_answers.length > 0) {
                    for (var p = 0; p < question_and_answers.length; p++) {
                      if (
                        department_settings[n].question_id ==
                        question_and_answers[p].id &&
                        question_and_answers[p].answer ==
                        department_settings[n].option_value
                      ) {
                        dept_value = department_settings[n].department_id;
                      }
                    }
                  }
                }
              }
            } else {
              if (json && json.single_dept) {
                dept_value = json.single_dept;
              }
            }
            var main_notes;
            var notes = {};
            if (JSON.stringify(notes) && JSON.stringify(notes) == "{}") {
              main_notes = "";
            } else {
              main_notes = JSON.stringify(notes);
            }
            var d = new Date();
                var date = d.getDate();
                if (date < 10) {
                  date = "0" + date;
                }
                var month = d.getMonth() + 1;
                if (month < 10) {
                  month = "0" + month;
                }
                var hours = d.getHours();
                if (hours < 10) {
                  hours = "0" + hours;
                }
                var mins = d.getMinutes();
                if (mins < 10) {
                  mins = "0" + mins;
                }
                var seconds = d.getSeconds();
                if (seconds < 10) {
                  seconds = "0" + seconds;
                }
                d =
                  date +
                  "/" +
                  month +
                  "/" +
                  d.getFullYear() +
                  ", " +
                  hours +
                  ":" +
                  mins +
                  ":" +
                  seconds;
            const modalBg = document.createElement("div");
            modalBg.className = "relaod_model-div-bg";
            modalBg.style.zIndex = '999999999999999';

            const modalContent = document.createElement("div");
            modalContent.className = "relaod_model-inside_div";

            const heading = document.createElement("h2");
            heading.innerHTML = generateTranslatedContent(translations, "Connection lost", main_lang_code, language_code, input); 
            heading.style.fontSize = "16px";
            heading.style.margin = "0";
            heading.style.color = "#000";
            heading.style.fontWeight = "600";
            heading.style.textAlign = "center";

            modalContent.appendChild(heading);

            const message = document.createElement("p");
            let text1 = generateTranslatedContent(translations, "Do you want us to reconnect you to the agent?", main_lang_code, language_code, input); 
            // let text2 = generateTranslatedContent(translations, "This will create a new session", main_lang_code, language_code, input); 
            // message.innerHTML = text1 + '<br/>' + text2;
            message.innerHTML = text1;
            message.style.color = "#555";
            message.style.fontSize = "14px";
            message.style.margin = "0";
            message.style.textAlign = 'center';
            message.style.lineHeight = '24px';

            modalContent.appendChild(message);

            const Btn_div = document.createElement("div");
            Btn_div.style.display = "flex";

            const cancelButton = document.createElement("button");
            cancelButton.innerHTML = generateTranslatedContent(translations, "Cancel", main_lang_code, language_code, input); 
            cancelButton.style.marginRight = "10px";
            cancelButton.style.padding = "10px 20px";
            cancelButton.style.border = "none";
            cancelButton.style.borderRadius = "5px";
            cancelButton.style.cssText = cancelButton.style.cssText + "background-color:#fff !important";
            cancelButton.style.cssText = cancelButton.style.cssText + "color:#000 !important";
            cancelButton.style.cursor = "pointer";
            cancelButton.style.fontSize = "14px";
            cancelButton.style.fontWeight = "600";
            cancelButton.style.minWidth = "fit-content";
            cancelButton.style.width = "fit-content";

            // cancelButton.addEventListener("click", function () {
            //     modalBg.remove();
            // });

            cancelButton.addEventListener("click", function () {
              // manageSockets();
              if (alreadySockLoaded) {
                sock.emit("setausersession", {
                  session_id: live_chat_cb_session,
                });
              } else {
                sock.on("connect", function () {
                  sock.emit("setausersession", {
                    session_id: live_chat_cb_session,
                  });
                });
              }
              sock.emit('refreshed_chats', {
                room_id: live_chat_cb_session,
                type: 'user',
                agent_id: agent_id
              });
              

              sock.on("refreshed_chats", (data) => {
                if (data.data && data.data.room_id == live_chat_cb_session) { 
                  // remove the all the elements after connect to live agent Start Here
                  const agentJoiningDiv = document.getElementById("agent-joining-div");
                  if (agentJoiningDiv) {
                    let nextSibling = agentJoiningDiv.nextElementSibling;
                    while (nextSibling) {
                      if (nextSibling.classList.contains("question-div-smatest")) {
                        const elementToRemove = nextSibling;
                        nextSibling = nextSibling.nextElementSibling; 
                        elementToRemove.remove();
                      } else if (nextSibling.classList.contains("answer-div")) {
                        const elementToRemove = nextSibling;
                        nextSibling = nextSibling.nextElementSibling; 
                        elementToRemove.remove();
                      } else if (nextSibling.classList.contains("blink-animation")) {
                        const elementToRemove = nextSibling;
                        nextSibling = nextSibling.nextElementSibling; 
                        elementToRemove.remove();
                      } else {
                        nextSibling = nextSibling.nextElementSibling;
                      }
                    }
                  }
                  // remove the all the elements after connect to live agent end Here
                  // agent_id = data.data.room_id;
                  data?.data?.messages.forEach((message) => {
                    if (message.type == "user") {
                      // Here for User sent message code ********************************************
                      if (message.text && message.text.includes("live_chat_image_upload")) {
                        seen_cleared = true;
                        agent_message_timer = 0;

                        // Create the main container for the message
                        var answerDiv = document.createElement('DIV');
                        answerDiv.classList.add('answer-div');
                        setTimeout(function () {
                          answerDiv.classList.add('top-0');
                        }, transition_time);

                        // Create the label for the message content
                        var answer = document.createElement('LABEL');

                        // Helper function to get the file extension
                        const getFileExtension = (filename) => {
                          const dotIndex = filename.lastIndexOf('.');
                          return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                        };

                        // Helper function to convert file types into appropriate HTML
                        const fileTypeConvert = (fileData) => {
                          const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                          const extension = getFileExtension(filename).toLowerCase();
                          let FileContainer;

                          if (['png', 'jpg', 'jpeg', 'tif', 'gif', 'ico', 'webp'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <a href="${fileData}" target="_blank" width='100%' height='100%' style="display: flex; align-items:center; gap:12px; justify-content:flex-end;">
                                <img src="${fileData}" alt='${link}' class='file-upload_image_style_sb'/>
                              </a>
                            `;
                          } else if (['svg'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <a href="${fileData}" target="_blank" width='100%' height='100%' style="display: flex; align-items:center; gap:12px; justify-content:flex-end;">
                                ${link}
                              </a>
                            `;
                          } else if (['mp3', 'wav'].includes(extension)) {
                            FileContainer = `<audio style="width: 250px;" controls src="${fileData}"></audio>`;
                          } else if (['mp4', 'webm', 'flv', 'mov'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='150px'></video>`;
                          } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <div width='100%' height='100%' style="display: flex; align-items:center; gap:12px; justify-content:start; background: #F0F4F9; border: 1px solid #E0E6F0; border-radius: 8px; padding: 12px;">
                                <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt='' width='25px' height='25px'/>
                                <label style='word-break:break-all; cursor: pointer; color: black; white-space: nowrap; width: 65%; overflow: hidden; text-overflow: ellipsis;'>${link}</label>
                                <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px; height: 25px; border-radius:50%; display:flex; align-items:center; justify-content:center; margin-left: auto;'>
                                  <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg' width='15px' height='15px'/>
                                </a>
                              </div>
                            `;
                          } else {
                            FileContainer = fileData;
                          }

                          return FileContainer;
                        };

                        // Set the content of the message
                        answer.style.background = 'transparent';
                        answer.innerHTML = fileTypeConvert(message.text);
                        answer.classList.add('answer-label');
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }

                        // Append the message to the container
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);

                        // Scroll to the bottom of the chat
                        body.scrollTop = body.scrollHeight;

                        // Reset input and footer
                        input.type = 'text';
                        input.placeholder = 'Talk to our agent';
                        enter.style.pointerEvents = 'auto';
                        footer.style.display = 'block';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 226px)';
                        } else {
                          body.style.height = 'calc(100% - 150px)';
                        }
                        footer.classList.remove('close');
                        input.value = '';
                        if (document.getElementById('live-file-input')) {
                          document.getElementById('live-file-input').value = '';
                        }
                      } else {
                        seen_cleared = true;
                        agent_message_timer = 0;
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var str = urlify(message.text);
                        // answer.innerHTML = str;
                        const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                        if (anchorTagPattern.test(str)) {
                          answer.innerHTML = str;
                        }else{
                          answer.textContent = str;
                        }

                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        input.type = "text";
                        input.placeholder = "Talk to our agent";
                        footer.style.display = "block";
                        enter.style.pointerEvents = "auto";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                        footer.classList.remove("close");
                        input.value = "";
                      }
                      // Here for User sent message code ********************************************
                    } else {
                      seen_cleared = true;
                      agent_message_timer = 0;
                      start_live_chat_timer = false;
                      
                      var agentDiv = document.createElement("DIV");
                      agentDiv.classList.add("question-div-smatest");
                      setTimeout(function () {
                        agentDiv.classList.add("top-0");
                      }, transition_time);
                      if (font && font.length > 0) {
                        agentDiv.classList.add(font);
                      }
                      var agent_icon = document.createElement("IMG"); agent_icon.alt = "Logo of " + totalData[0].name;
                      if (message.agent_avatar && message.agent_avatar.length > 0) {
                        if (message.agent_avatar && message.agent_avatar.includes(",")) {
                          agent_icon.src = message.agent_avatar.split(",")[0];
                        } else {
                          agent_icon.src = message.agent_avatar;
                        }
                      } else {
                        agent_icon.src = avatar_icon;
                      }
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(agent_icon);
                      iconDiv.classList.add("question-icon-div");
                      agent_icon.classList.add("question-icon-smatest");
                      var agent_text_div = document.createElement("DIV");
                      var agent_text = document.createElement("LABEL");
                      if (
                        message.text &&
                        message.text.includes("live_chat_image_upload;;")
                      ) {
                        message.text = message.text.replace(
                          "live_chat_image_upload;;",
                          ""
                        );
                        var answer_a = document.createElement("a");
                        answer_a.href = message.text;
                        answer_a.target = "_blank";
                        answer_a.style.height = "100%";
                        answer_a.style.width = "fit-content";
                        answer_a.style.display = "block";
                        var answer_img = document.createElement("IMG");
                        answer_img.src = message.text;
                        answer_img.classList.add("contact-image-smatest");
                        agent_text_div.style.background = 'transparent'
                        agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                        answer_a.appendChild(answer_img);
                        agent_text.appendChild(answer_a);
                      } else {
                        var pattern = new RegExp(
                          "^(https?:\\/\\/)?" + // protocol
                          "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|" + // domain name
                          "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
                          "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
                          "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
                          "(\\#[-a-z\\d_]*)?$",
                          "i"
                        );
                        function isURL(str) {
                          const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
                          return urlPattern.test(str);
                        }
                        
                        const getFileExtension = (filename) => {
                          const dotIndex = filename.lastIndexOf('.');
                          return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                        };
                        
                        function insertLinkTags(text) {
                          // Define a regular expression pattern to match URLs
                          const urlPattern = /(https?:\/\/\S+)/g;
                        
                          // Replace each URL with a formatted link
                          const result = text.replace(urlPattern, '<div><a href="$1" target="_blank">$1</a></div>');
                        
                          return result;
                        }
                        
                        const fileTypeConvert = (fileData) => {
                          const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                          const extension = getFileExtension(filename).toLowerCase();
                          let FileContainer;
                        
                          if (['png', 'jpg', 'jpeg', 'svg', 'tif', 'gif','ico','webp'].includes(extension)) {
                            agent_text_div.style.background = 'transparent'
                            agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end " >
                                <img src="${fileData}" alt='${link}'  class='file-upload_image_style_sb'/>
                              </a>
                            `;
                          } else if (['mp3', 'wav'].includes(extension)) {
                              agent_text_div.style.background = 'transparent';
                              agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                            FileContainer = `<audio style="width: 100%;" controls src="${fileData}"></audio>`;
                          } else if (['mp4', 'webm', 'flv','mov'].includes(extension)) {
                            agent_text_div.style.background = 'transparent';
                            agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
    
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='100%'></video>`;
                          } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                              agent_text_div.style.background = 'transparent'
                              agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                            <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                              <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt=''  width='25px' height='25px'/>
                              <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                              <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                                <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                              </a>
                            </div>`
                          
                          } else if (fileData?.includes('https://') || fileData?.includes('http://')) {
    
                            const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                        
                            if (anchorTagPattern.test(fileData)) {
                              FileContainer = fileData
                            }else{
                              const words = fileData.split(/\s+/);
                              const urlPattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i;
                                FileContainer = insertLinkTags(fileData);
                            }
                              
                          }else{
                            FileContainer = fileData
                          }
                        
                          return FileContainer;
                        };
                        if (pattern.test(message.text)) {
                          agent_text.innerHTML = fileTypeConvert(message.text.trim());
                        } else {
                          const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                          if (anchorTagPattern.test(message.text.trim())) {
                          agent_text.textContent = fileTypeConvert(message.text.trim());
                          }
                          agent_text.innerHTML =  fileTypeConvert(message.text.trim());
                        }
    
                        // Check if the innerHTML contains data-list="bullet"
                        if (agent_text.innerHTML.includes('data-list="bullet"')) {
                          agent_text.querySelectorAll('li[data-list="bullet"]').forEach(li => {
                          li.style.listStyleType = 'disc';
                          });
                        }
                        if (agent_text.innerHTML.includes('data-list="ordered"')) {
                          agent_text.querySelectorAll('li[data-list="ordered"]').forEach(li => {
                          li.style.listStyleType = 'decimal';
                          });
                        }
                        if (agent_text.innerHTML.includes('data-list="ordered"') || agent_text.innerHTML.includes('data-list="bullet"')) {
                          agent_text.querySelectorAll('ol').forEach(ol => {
                          ol.style.listStyle = 'inside';
                          });
                        }
                      }
                      say(agent_text.innerText);
                      agent_text_div.classList.add("options-div-smatest");
                      agent_text_div.appendChild(agent_text);
                      var matchedUrls = urlsFromString(message.text);
                      if (
                        matchedUrls &&
                        matchedUrls.length > 0 &&
                        matchedUrls[0] &&
                        matchedUrls[0].length > 0
                      ) {
                        var extension = matchedUrls[0]
                          .split(/\#|\?/)[0]
                          .split(".")
                          .pop()
                          .trim();
                        var file_name =
                          matchedUrls[0].split("/")[
                          matchedUrls[0].split("/").length - 1
                          ];
                        var download_div = document.createElement("DIV");
                        download_div.classList.add("pull-left");
                        download_div.classList.add("full-width");
                        download_div.classList.add("text-center");
                        var download_a = document.createElement("A");
                        download_a.title = "Live chat file redirection";
                        if (file_name && file_name.length > 0) {
                          download_a.innerHTML = file_name;
                        } else {
                          download_a.innerHTML = "Open";
                        }
                        download_a.style.cursor = "pointer";
                        download_a.style.display = "inline-block";
                        download_a.addEventListener("click", function () { });
                        download_a.classList.add("confirm-btn-smatest");
                        download_a.setAttribute("href", matchedUrls[0]);
                        download_a.style.cssText =
                          download_a.style.cssText + "color:white !important;";
                        download_a.download = "file";
                        if (extension == "pdf") {
                          download_a.setAttribute("type", "application/octet-stream");
                        }
                        download_a.setAttribute("target", "_blank");
                        // download_div.appendChild(download_a);
                        if (
                          message.text &&
                          message.text.includes("live_chat_image_upload;;")
                        ) {
                        } else {
                          agent_text_div.appendChild(download_div);
                        }
                      }
                      if (font && font.length > 0) {
                        agent_text.classList.add(font);
                      }
                      var agent_time_name_div = document.createElement("DIV");
                      agent_time_name_div.style.marginLeft = "40px";
                      agent_time_name_div.style.width = "75%";
                      agent_time_name_div.classList.add("pull-left");
                      agent_time_name_div.classList.add("full-width");
                      var agent_name_time_span = document.createElement("SPAN");
                      agent_name_time_span.style.fontSize = "10px";
                      agent_name_time_span.style.color = "grey";
                      agent_name_time_span.style.display = "block";
                      agent_name_time_span.style.textAlign = "right";
                      var given_date = message.created_at.split(",")[0];
                      var d = new Date();
                      var date = d.getDate();
                      if (date < 10) {
                        date = "0" + date;
                      }
                      var month = d.getMonth() + 1;
                      if (month < 10) {
                        month = "0" + month;
                      }
                      d = date + "/" + month + "/" + d.getFullYear();
                      if (d == given_date) {
                        message.created_at = message.created_at.replace(given_date, "Today");
                      }
                      agent_name_time_span.innerHTML = message.created_at;
                      agent_time_name_div.appendChild(agent_name_time_span);
                      agent_time_name_div.classList.add("blink-animation");
                      var agentTypingDiv = document.getElementById("admin-typing-div");
                      if (agentTypingDiv && agentTypingDiv.parentElement) {
                        agentTypingDiv.parentElement.removeChild(agentTypingDiv);
                      }
                      agentDiv.appendChild(iconDiv);
                      agentDiv.appendChild(agent_text_div);
                      body.appendChild(agentDiv);
                      body.appendChild(agent_time_name_div);
                      setTimeout(function () {
                        agent_time_name_div.style.opacity = 0;
                      }, 1500);
                      body.scrollTop = body.scrollHeight;
                      agent_text_div.addEventListener("mouseover", function (k) {
                        agent_time_name_div.style.opacity = 1;
                      });
                      agent_text_div.addEventListener("mouseout", function (k) {
                        agent_time_name_div.style.opacity = 0;
                      });
                    }
                  });
                }
              });
      
              modalBg.remove();
            });
            Btn_div.appendChild(cancelButton);

            const reconnectButton = document.createElement("button");
            reconnectButton.innerHTML = generateTranslatedContent(translations, "Reconnect", main_lang_code, language_code, input); 
            reconnectButton.style.padding = "10px 20px";
            reconnectButton.style.border = "none";
            reconnectButton.style.borderRadius = "9px";
            reconnectButton.style.cssText = reconnectButton.style.cssText + "background-color:black !important";
            reconnectButton.style.cssText = reconnectButton.style.cssText + "color:white !important";
            reconnectButton.style.cursor = "pointer";
            reconnectButton.style.fontSize = "14px";
            reconnectButton.style.minWidth = "fit-content";
            reconnectButton.style.width = "fit-content";

            // reconnectButton.addEventListener("click", function () {
            //     if (reload_div) {
            //         reload_div.click();
            //     }
            //     modalBg.remove();
            // });

            function manageSockets() {
              // Disconnect all existing sockets if there are 2 or more
              if (activeSockets.length >= 2) {
                  console.log("Disconnecting all existing WebSocket connections...");
                  activeSockets.forEach((socket) => {
                      if (sock.connected) {
                          sock.disconnect();
                          console.log("Disconnected socket:", socket.id);
                      }
                  });
                  activeSockets = []; // Clear the active sockets array
              } else {
                sock.disconnect();
              }
            }
            
            reconnectButton.addEventListener("click", function () {
              // manageSockets();
              if (alreadySockLoaded) {
                sock.emit("setausersession", {
                  session_id: live_chat_cb_session,
                });
              } else {
                sock.on("connect", function () {
                  sock.emit("setausersession", {
                    session_id: live_chat_cb_session,
                  });
                });
              }
              sock.emit('refreshed_chats', {
                room_id: live_chat_cb_session,
                type: 'user',
                agent_id: agent_id
              });
              

              sock.on("refreshed_chats", (data) => {
                if (data.data && data.data.room_id == live_chat_cb_session) { 
                  // remove the all the elements after connect to live agent Start Here
                  const agentJoiningDiv = document.getElementById("agent-joining-div");
                  if (agentJoiningDiv) {
                    let nextSibling = agentJoiningDiv.nextElementSibling;
                    while (nextSibling) {
                      if (nextSibling.classList.contains("question-div-smatest")) {
                        const elementToRemove = nextSibling;
                        nextSibling = nextSibling.nextElementSibling; 
                        elementToRemove.remove();
                      } else if (nextSibling.classList.contains("answer-div")) {
                        const elementToRemove = nextSibling;
                        nextSibling = nextSibling.nextElementSibling; 
                        elementToRemove.remove();
                      } else if (nextSibling.classList.contains("blink-animation")) {
                        const elementToRemove = nextSibling;
                        nextSibling = nextSibling.nextElementSibling; 
                        elementToRemove.remove();
                      } else {
                        nextSibling = nextSibling.nextElementSibling;
                      }
                    }
                  }
                  // remove the all the elements after connect to live agent end Here
                  // agent_id = data.data.room_id;
                  data?.data?.messages.forEach((message) => {
                    if (message.type == "user") {
                      // Here for User sent message code ********************************************
                      if (message.text && message.text.includes("live_chat_image_upload")) {
                        seen_cleared = true;
                        agent_message_timer = 0;

                        // Create the main container for the message
                        var answerDiv = document.createElement('DIV');
                        answerDiv.classList.add('answer-div');
                        setTimeout(function () {
                          answerDiv.classList.add('top-0');
                        }, transition_time);

                        // Create the label for the message content
                        var answer = document.createElement('LABEL');

                        // Helper function to get the file extension
                        const getFileExtension = (filename) => {
                          const dotIndex = filename.lastIndexOf('.');
                          return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                        };

                        // Helper function to convert file types into appropriate HTML
                        const fileTypeConvert = (fileData) => {
                          const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                          const extension = getFileExtension(filename).toLowerCase();
                          let FileContainer;

                          if (['png', 'jpg', 'jpeg', 'tif', 'gif', 'ico', 'webp'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <a href="${fileData}" target="_blank" width='100%' height='100%' style="display: flex; align-items:center; gap:12px; justify-content:flex-end;">
                                <img src="${fileData}" alt='${link}' class='file-upload_image_style_sb'/>
                              </a>
                            `;
                          } else if (['svg'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <a href="${fileData}" target="_blank" width='100%' height='100%' style="display: flex; align-items:center; gap:12px; justify-content:flex-end;">
                                ${link}
                              </a>
                            `;
                          } else if (['mp3', 'wav'].includes(extension)) {
                            FileContainer = `<audio style="width: 250px;" controls src="${fileData}"></audio>`;
                          } else if (['mp4', 'webm', 'flv', 'mov'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='150px'></video>`;
                          } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <div width='100%' height='100%' style="display: flex; align-items:center; gap:12px; justify-content:start; background: #F0F4F9; border: 1px solid #E0E6F0; border-radius: 8px; padding: 12px;">
                                <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt='' width='25px' height='25px'/>
                                <label style='word-break:break-all; cursor: pointer; color: black; white-space: nowrap; width: 65%; overflow: hidden; text-overflow: ellipsis;'>${link}</label>
                                <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px; height: 25px; border-radius:50%; display:flex; align-items:center; justify-content:center; margin-left: auto;'>
                                  <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg' width='15px' height='15px'/>
                                </a>
                              </div>
                            `;
                          } else {
                            FileContainer = fileData;
                          }

                          return FileContainer;
                        };

                        // Set the content of the message
                        answer.style.background = 'transparent';
                        answer.innerHTML = fileTypeConvert(message.text);
                        answer.classList.add('answer-label');
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }

                        // Append the message to the container
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);

                        // Scroll to the bottom of the chat
                        body.scrollTop = body.scrollHeight;

                        // Reset input and footer
                        input.type = 'text';
                        input.placeholder = 'Talk to our agent';
                        enter.style.pointerEvents = 'auto';
                        footer.style.display = 'block';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 226px)';
                        } else {
                          body.style.height = 'calc(100% - 150px)';
                        }
                        footer.classList.remove('close');
                        input.value = '';
                        if (document.getElementById('live-file-input')) {
                          document.getElementById('live-file-input').value = '';
                        }
                      } else {
                        seen_cleared = true;
                        agent_message_timer = 0;
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var str = urlify(message.text);
                        // answer.innerHTML = str;
                        const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                        if (anchorTagPattern.test(str)) {
                          answer.innerHTML = str;
                        }else{
                          answer.textContent = str;
                        }

                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        input.type = "text";
                        input.placeholder = "Talk to our agent";
                        footer.style.display = "block";
                        enter.style.pointerEvents = "auto";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                        footer.classList.remove("close");
                        input.value = "";
                      }
                      // Here for User sent message code ********************************************
                    } else {
                      seen_cleared = true;
                      agent_message_timer = 0;
                      start_live_chat_timer = false;
                      
                      var agentDiv = document.createElement("DIV");
                      agentDiv.classList.add("question-div-smatest");
                      setTimeout(function () {
                        agentDiv.classList.add("top-0");
                      }, transition_time);
                      if (font && font.length > 0) {
                        agentDiv.classList.add(font);
                      }
                      var agent_icon = document.createElement("IMG"); agent_icon.alt = "Logo of " + totalData[0].name;
                      if (message.agent_avatar && message.agent_avatar.length > 0) {
                        if (message.agent_avatar && message.agent_avatar.includes(",")) {
                          agent_icon.src = message.agent_avatar.split(",")[0];
                        } else {
                          agent_icon.src = message.agent_avatar;
                        }
                      } else {
                        agent_icon.src = avatar_icon;
                      }
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(agent_icon);
                      iconDiv.classList.add("question-icon-div");
                      agent_icon.classList.add("question-icon-smatest");
                      var agent_text_div = document.createElement("DIV");
                      var agent_text = document.createElement("LABEL");
                      if (
                        message.text &&
                        message.text.includes("live_chat_image_upload;;")
                      ) {
                        message.text = message.text.replace(
                          "live_chat_image_upload;;",
                          ""
                        );
                        var answer_a = document.createElement("a");
                        answer_a.href = message.text;
                        answer_a.target = "_blank";
                        answer_a.style.height = "100%";
                        answer_a.style.width = "fit-content";
                        answer_a.style.display = "block";
                        var answer_img = document.createElement("IMG");
                        answer_img.src = message.text;
                        answer_img.classList.add("contact-image-smatest");
                        agent_text_div.style.background = 'transparent'
                        agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                        answer_a.appendChild(answer_img);
                        agent_text.appendChild(answer_a);
                      } else {
                        var pattern = new RegExp(
                          "^(https?:\\/\\/)?" + // protocol
                          "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|" + // domain name
                          "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
                          "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
                          "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
                          "(\\#[-a-z\\d_]*)?$",
                          "i"
                        );
                        function isURL(str) {
                          const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
                          return urlPattern.test(str);
                        }
                        
                        const getFileExtension = (filename) => {
                          const dotIndex = filename.lastIndexOf('.');
                          return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                        };
                        
                        function insertLinkTags(text) {
                          // Define a regular expression pattern to match URLs
                          const urlPattern = /(https?:\/\/\S+)/g;
                        
                          // Replace each URL with a formatted link
                          const result = text.replace(urlPattern, '<div><a href="$1" target="_blank">$1</a></div>');
                        
                          return result;
                        }
                        
                        const fileTypeConvert = (fileData) => {
                          const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                          const extension = getFileExtension(filename).toLowerCase();
                          let FileContainer;
                        
                          if (['png', 'jpg', 'jpeg', 'svg', 'tif', 'gif','ico','webp'].includes(extension)) {
                            agent_text_div.style.background = 'transparent'
                            agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                              <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end " >
                                <img src="${fileData}" alt='${link}'  class='file-upload_image_style_sb'/>
                              </a>
                            `;
                          } else if (['mp3', 'wav'].includes(extension)) {
                              agent_text_div.style.background = 'transparent';
                              agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                            FileContainer = `<audio style="width: 100%;" controls src="${fileData}"></audio>`;
                          } else if (['mp4', 'webm', 'flv','mov'].includes(extension)) {
                            agent_text_div.style.background = 'transparent';
                            agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
    
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='100%'></video>`;
                          } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                              agent_text_div.style.background = 'transparent'
                              agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                            let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                            FileContainer = `
                            <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                              <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt=''  width='25px' height='25px'/>
                              <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                              <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                                <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                              </a>
                            </div>`
                          
                          } else if (fileData?.includes('https://') || fileData?.includes('http://')) {
    
                            const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                        
                            if (anchorTagPattern.test(fileData)) {
                              FileContainer = fileData
                            }else{
                              const words = fileData.split(/\s+/);
                              const urlPattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i;
                                FileContainer = insertLinkTags(fileData);
                            }
                              
                          }else{
                            FileContainer = fileData
                          }
                        
                          return FileContainer;
                        };
                        if (pattern.test(message.text)) {
                          agent_text.innerHTML = fileTypeConvert(message.text.trim());
                        } else {
                          const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                          if (anchorTagPattern.test(message.text.trim())) {
                          agent_text.textContent = fileTypeConvert(message.text.trim());
                          }
                          agent_text.innerHTML =  fileTypeConvert(message.text.trim());
                        }
    
                        // Check if the innerHTML contains data-list="bullet"
                        if (agent_text.innerHTML.includes('data-list="bullet"')) {
                          agent_text.querySelectorAll('li[data-list="bullet"]').forEach(li => {
                          li.style.listStyleType = 'disc';
                          });
                        }
                        if (agent_text.innerHTML.includes('data-list="ordered"')) {
                          agent_text.querySelectorAll('li[data-list="ordered"]').forEach(li => {
                          li.style.listStyleType = 'decimal';
                          });
                        }
                        if (agent_text.innerHTML.includes('data-list="ordered"') || agent_text.innerHTML.includes('data-list="bullet"')) {
                          agent_text.querySelectorAll('ol').forEach(ol => {
                          ol.style.listStyle = 'inside';
                          });
                        }
                      }
                      say(agent_text.innerText);
                      agent_text_div.classList.add("options-div-smatest");
                      agent_text_div.appendChild(agent_text);
                      var matchedUrls = urlsFromString(message.text);
                      if (
                        matchedUrls &&
                        matchedUrls.length > 0 &&
                        matchedUrls[0] &&
                        matchedUrls[0].length > 0
                      ) {
                        var extension = matchedUrls[0]
                          .split(/\#|\?/)[0]
                          .split(".")
                          .pop()
                          .trim();
                        var file_name =
                          matchedUrls[0].split("/")[
                          matchedUrls[0].split("/").length - 1
                          ];
                        var download_div = document.createElement("DIV");
                        download_div.classList.add("pull-left");
                        download_div.classList.add("full-width");
                        download_div.classList.add("text-center");
                        var download_a = document.createElement("A");
                        download_a.title = "Live chat file redirection";
                        if (file_name && file_name.length > 0) {
                          download_a.innerHTML = file_name;
                        } else {
                          download_a.innerHTML = "Open";
                        }
                        download_a.style.cursor = "pointer";
                        download_a.style.display = "inline-block";
                        download_a.addEventListener("click", function () { });
                        download_a.classList.add("confirm-btn-smatest");
                        download_a.setAttribute("href", matchedUrls[0]);
                        download_a.style.cssText =
                          download_a.style.cssText + "color:white !important;";
                        download_a.download = "file";
                        if (extension == "pdf") {
                          download_a.setAttribute("type", "application/octet-stream");
                        }
                        download_a.setAttribute("target", "_blank");
                        // download_div.appendChild(download_a);
                        if (
                          message.text &&
                          message.text.includes("live_chat_image_upload;;")
                        ) {
                        } else {
                          agent_text_div.appendChild(download_div);
                        }
                      }
                      if (font && font.length > 0) {
                        agent_text.classList.add(font);
                      }
                      var agent_time_name_div = document.createElement("DIV");
                      agent_time_name_div.style.marginLeft = "40px";
                      agent_time_name_div.style.width = "75%";
                      agent_time_name_div.classList.add("pull-left");
                      agent_time_name_div.classList.add("full-width");
                      var agent_name_time_span = document.createElement("SPAN");
                      agent_name_time_span.style.fontSize = "10px";
                      agent_name_time_span.style.color = "grey";
                      agent_name_time_span.style.display = "block";
                      agent_name_time_span.style.textAlign = "right";
                      var given_date = message.created_at.split(",")[0];
                      var d = new Date();
                      var date = d.getDate();
                      if (date < 10) {
                        date = "0" + date;
                      }
                      var month = d.getMonth() + 1;
                      if (month < 10) {
                        month = "0" + month;
                      }
                      d = date + "/" + month + "/" + d.getFullYear();
                      if (d == given_date) {
                        message.created_at = message.created_at.replace(given_date, "Today");
                      }
                      agent_name_time_span.innerHTML = message.created_at;
                      agent_time_name_div.appendChild(agent_name_time_span);
                      agent_time_name_div.classList.add("blink-animation");
                      var agentTypingDiv = document.getElementById("admin-typing-div");
                      if (agentTypingDiv && agentTypingDiv.parentElement) {
                        agentTypingDiv.parentElement.removeChild(agentTypingDiv);
                      }
                      agentDiv.appendChild(iconDiv);
                      agentDiv.appendChild(agent_text_div);
                      body.appendChild(agentDiv);
                      body.appendChild(agent_time_name_div);
                      setTimeout(function () {
                        agent_time_name_div.style.opacity = 0;
                      }, 1500);
                      body.scrollTop = body.scrollHeight;
                      agent_text_div.addEventListener("mouseover", function (k) {
                        agent_time_name_div.style.opacity = 1;
                      });
                      agent_text_div.addEventListener("mouseout", function (k) {
                        agent_time_name_div.style.opacity = 0;
                      });
                    }
                  });
                }
              });
      
              modalBg.remove();
            });

            function attemptReconnect() {
              if (reconnectAttempts < maxReconnectAttempts) {
                  setTimeout(() => {
                      reconnectAttempts++;
                      console.log(`Reconnection attempt ${reconnectAttempts}`);
                      if (reconnectButton) {
                        reconnectButton.click();
                      } else {
                        console.error("Reconnect button not found.");
                      }
                  }, reconnectDelay * reconnectAttempts); // Exponential backoff
              } else {
                  console.error("Max reconnection attempts reached. Unable to reconnect.");
              }
            }

            if (font && font.length > 0) {
                heading.classList.add(font);
                message.classList.add(font);
                cancelButton.classList.add(font);
                reconnectButton.classList.add(font);
            }

            Btn_div.appendChild(reconnectButton);
            modalContent.appendChild(Btn_div);
            modalBg.appendChild(modalContent);

            const opened = document.getElementById("opened");
            if (opened) {
                opened.appendChild(modalBg);
            }
          }
          // Refreshed Chats Popup (Websocket Disconnect Popup)
          var json;
          if (
            question_array[0].departments &&
            question_array[0].departments.length > 0
          ) {
            department_settings = question_array[0].departments;
          }
          if (
            question_array[0].default_options &&
            question_array[0].default_options.length > 0
          ) {
            json = JSON.parse(question_array[0].default_options);
            video_call_key = json.video_call;
            var date = new Date();
            var todays_day;
            if (date.getDay() == 0) {
              todays_day = 7;
            } else {
              todays_day = date.getDay();
            }
            var week_days = json.weekdays;
            if (week_days && week_days.length > 0) {
              if (week_days.indexOf(todays_day) > -1) {
                proceed_to_live_chat = true;
              }
            }
            if (proceed_to_live_chat) {
              var d = new Date();
              var date = d.getDate();
              if (date < 10) {
                date = "0" + date;
              }
              var month = d.getMonth() + 1;
              if (month < 10) {
                month = "0" + month;
              }
              var new_from_date;
              var new_to_date;
              if (is_safari || is_firefox) {
                new_from_date = new Date(
                  d.getFullYear() +
                  "/" +
                  month +
                  "/" +
                  date +
                  " " +
                  json.from_timing
                );
                new_to_date = new Date(
                  d.getFullYear() + "/" + month + "/" + date + " " + json.to_timing
                );
              } else {
                new_from_date = new Date(
                  d.getFullYear() +
                  "-" +
                  month +
                  "-" +
                  date +
                  " " +
                  json.from_timing
                );
                new_to_date = new Date(
                  d.getFullYear() + "-" + month + "-" + date + " " + json.to_timing
                );
              }

              // Check if the to_timing is earlier than from_timing
              if (new_to_date.getTime() < new_from_date.getTime()) {
                // Shift the to_date to the next day
                new_to_date.setDate(new_to_date.getDate() + 1);
              }

              new_from_date = new_from_date.getTime();
              new_to_date = new_to_date.getTime();

              var current_utc_time = new Date();
              var timezone_val = current_utc_time.getTimezoneOffset() * 60 * 1000;
              current_utc_time = current_utc_time.getTime();
              current_utc_time = current_utc_time + timezone_val;
              var add_subtract;
              if (json.out_of_office_jump && json.out_of_office_jump.length > 0) {
                out_of_office_jump = json.out_of_office_jump;
              }
              if (json.timezone) {
                if (json.timezone.includes("+")) {
                  add_subtract = "add";
                  var timezone = json.timezone.substring(1, json.timezone.length);
                  timezone_arr = timezone.split(":");
                  var timezone_hours = parseInt(timezone_arr[0]);
                  var timezone_mins = parseInt(timezone_arr[1]);
                  var x = parseInt(
                    parseInt(timezone_hours * 60 * 60 * 1000) +
                    parseInt(timezone_mins * 60 * 1000)
                  );
                  current_utc_time = current_utc_time + x;
                } else if (json.timezone.includes("-")) {
                  add_subtract = "subtract";
                  var timezone = json.timezone.substring(1, json.timezone.length);
                  timezone_arr = timezone.split(":");
                  var timezone_hours = parseInt(timezone_arr[0]);
                  var timezone_mins = parseInt(timezone_arr[1]);
                  var x = parseInt(
                    parseInt(timezone_hours * 60 * 60 * 1000) +
                    parseInt(timezone_mins * 60 * 1000)
                  );
                  current_utc_time = current_utc_time - x;
                }
              }
              if (json.first_busy_message && json.first_busy_message) {
                first_busy_message = json.first_busy_message;
              }
              if (json.second_busy_message && json.second_busy_message) {
                second_busy_message = json.second_busy_message;
              }
              if (json.third_busy_message && json.third_busy_message) {
                third_busy_message = json.third_busy_message;
              }
              if ((current_utc_time > new_from_date && current_utc_time < new_to_date) || new_from_date == new_to_date) {
              
              } else {
                proceed_to_live_chat = false; // Outside the range
              }
              console.log("From Date (Original Timezone):", new Date(new_from_date).toString());
              console.log("To Date (Original Timezone):", new Date(new_to_date).toString());
              console.log("Current Time (Adjusted to Original Timezone):", new Date(current_utc_time).toString());
            }
          } else {
            proceed_to_live_chat = true;
          }
          if (proceed_to_live_chat) {
            if (ip_is_banned) {
              proceed_to_live_chat = false;
            }
          }
          if (proceed_to_live_chat) {
            if (video_call_key == "1") {
              header_menu_div.appendChild(video_call_icon_div);
              video_call_object = Twilio.Video;
              video_call_icon_div.addEventListener("click", function (data) {
                video_call_icon_div.style.pointerEvents = "none";
                var videos_div = document.createElement("DIV");
                videos_div.id = "video-container-div";
                videos_div.classList.add("videos-container");
                var local_media = document.createElement("DIV");
                local_media.id = "local-media";
                var remote_media = document.createElement("DIV");
                remote_media.id = "remote-media";
                var video_sound_image = document.createElement("IMG");
                video_sound_image.src =
                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/video_call_unmute.png";
                video_sound_image.classList.add("mute-icon");
                var screen_share_icon = document.createElement("IMG");
                screen_share_icon.src =
                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
                screen_share_icon.classList.add("screen-share-icon");
                screen_share_icon.id = "screen-share-icon";
                var disconnect_video = document.createElement("IMG");
                disconnect_video.src =
                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/ignore_video_call.png";
                disconnect_video.classList.add("disconnect-video-icon");
                disconnect_video.id = "disconnect-video-icon";
                var keep_video_sound = true;
                var modal_div = document.createElement("DIV");
                if (font && font.length > 0) {
                  modal_div.classList.add(font);
                }
                modal_div.classList.add("modal-smatest");
                modal_div.id = "video-call-full-screen-modal";
                var modal_content_div = document.createElement("DIV");
                modal_content_div.classList.add("modal-content-smatest");
                var modal_close_span = document.createElement("SPAN");
                modal_close_span.classList.add("close-modal");
                modal_close_span.innerHTML = "&times";
                modal_content_div.appendChild(videos_div);
                modal_content_div.appendChild(modal_close_span);
                modal_div.appendChild(modal_content_div);
                modal_div.style.display = "none";
                window.onclick = function (event) {
                  if (event.target == modal_div) {
                    modal_div.style.display = "none";
                    if (
                      body.contains(document.getElementById("video-container-div"))
                    ) {
                    } else {
                      body.appendChild(
                        document.getElementById("video-container-div")
                      );
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                };
                modal_close_span.addEventListener("click", function (k) {
                  modal_div.style.display = "none";
                  if (
                    body.contains(document.getElementById("video-container-div"))
                  ) {
                  } else {
                    body.appendChild(
                      document.getElementById("video-container-div")
                    );
                    body.scrollTop = body.scrollHeight;
                  }
                });
                document.body.appendChild(modal_div);
                video_sound_image.addEventListener("click", function (k) {
                  var audio = document.getElementsByTagName("AUDIO");
                  for (var i = 0; i < audio.length; i++) {
                    if (
                      audio[i].parentElement &&
                      audio[i].parentElement.id == "remote-media"
                    ) {
                      if (keep_video_sound) {
                        audio[i].muted = true;
                        keep_video_sound = true;
                        this.src =
                          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/video_call_mute.png";
                        video_sound_image.src =
                          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/video_call_mute.png";
                      } else {
                        audio[i].muted = false;
                        keep_video_sound = false;
                        this.src =
                          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/video_call_unmute.png";
                        video_sound_image.src =
                          "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/video_call_unmute.png";
                      }
                    }
                  }
                });
                screen_share_icon.addEventListener("click", function (k) {
                  if (!screen_share_from_agent) {
                    if (!screen_sharing_object) {
                      navigator.mediaDevices
                        .getDisplayMedia()
                        .then((stream) => {
                          screen_sharing_object = new Twilio.Video.LocalVideoTrack(
                            stream.getTracks()[0]
                          );
                          video_call_room.localParticipant.publishTrack(
                            screen_sharing_object
                          );
                          sock.emit("start-screen-share", {
                            bot_id: chatbot_id,
                            session_id: live_chat_cb_session,
                            device_print: device_print,
                            screen_share_object: screen_sharing_object,
                          });
                          screen_share_icon.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
                          this.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
                          screen_sharing_object.mediaStreamTrack.onended = () => {
                            shareScreenHandler();
                          };
                          setTimeout(function () {
                            body.scrollTop = body.scrollHeight;
                          }, 100);
                        })
                        .catch(() => {
                          alert("Could not share the screen.");
                        });
                    } else {
                      video_call_room.localParticipant.unpublishTrack(
                        screen_sharing_object
                      );
                      screen_sharing_object.stop();
                      screen_sharing_object = null;
                      screen_share_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
                      this.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/screen_share.png";
                      var remote_div = document.getElementById("remote-media");
                      remote_div.removeChild(remote_div.lastChild);
                      sock.emit("stop-screen-share", {
                        bot_id: chatbot_id,
                        session_id: live_chat_cb_session,
                        device_print: device_print,
                      });
                    }
                  } else {
                    alert("Someone is already sharing the screen");
                  }
                });
                body.style.position = "relative";
                var video_full_screen_image = document.createElement("IMG");
                video_full_screen_image.src =
                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/full_screen.png";
                video_full_screen_image.classList.add("video-full-screen-icon");
                video_full_screen_image.addEventListener("click", function (data) {
                  modal_div.style.display = "block";
                  if (
                    modal_content_div.contains(
                      document.getElementById("video-container-div")
                    )
                  ) {
                  } else {
                    modal_content_div.appendChild(
                      document.getElementById("video-container-div")
                    );
                  }
                });
                disconnect_video.addEventListener("click", function (k) {
                  video_call_room.disconnect();
                  video_call_icon_div.style.pointerEvents = "auto";
                  var localMedia = document.getElementById("local-media");
                  if (localMedia) {
                    localMedia.innerHTML = "";
                  }
                  var remoteMedia = document.getElementById("remote-media");
                  if (remoteMedia) {
                    remoteMedia.innerHTML = "";
                  }
                  var video_container = document.getElementById(
                    "video-container-div"
                  );
                  if (body.contains(video_container)) {
                    video_container.innerHTML = "";
                    body.removeChild(video_container);
                  }
                  var agent_left_div = document.createElement("DIV");
                  agent_left_div.classList.add("pull-left");
                  agent_left_div.classList.add("full-width");
                  agent_left_div.classList.add("m-t-10");
                  agent_left_div.classList.add("m-b-10");
                  var agent_left_label = document.createElement("LABEL");
                  agent_left_label.classList.add("text-line-combo");
                  var agent_left_span = document.createElement("SPAN");
                  agent_left_span.innerHTML = "Video Call Ended";
                  agent_left_label.appendChild(agent_left_span);
                  agent_left_div.appendChild(agent_left_label);
                  body.appendChild(agent_left_div);
                  body.scrollTop = body.scrollHeight;
                  footer.style.display = "none";
                  footer.classList.add("close");
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 168px)";
                  } else {
                    body.style.height = "calc(100% - 93px)";
                  }
                  sock.emit("video-disconnect", {
                    bot_id: chatbot_id,
                    session_id: live_chat_cb_session,
                    device_print: device_print,
                  });
                });
                videos_div.appendChild(local_media);
                videos_div.appendChild(remote_media);
                videos_div.appendChild(video_sound_image);
                videos_div.appendChild(screen_share_icon);
                videos_div.appendChild(disconnect_video);
                videos_div.appendChild(video_full_screen_image);
                body.appendChild(videos_div);
                body.scrollTop = body.scrollHeight;
                if (video_call_object.isSupported) {
                  video_call_object
                    .createLocalTracks({
                      audio: true,
                      video: {
                        width: 640,
                      },
                    })
                    .then(function (localTracks) {
                      return video_call_object
                        .connect(video_call_token, {
                          audio: true,
                          name: live_chat_cb_session,
                          tracks: localTracks,
                          video: {
                            width: 640,
                          },
                        })
                        .then(function (room) {
                          video_call_room = room;
                          sock.emit("start-video", {
                            bot_id: chatbot_id,
                            session_id: live_chat_cb_session,
                            device_print: device_print,
                          });
                          participantConnected(room.localParticipant, room);
                          room.participants.forEach((participant) => {
                            participantConnected(participant, room);
                          });
                          room.on("participantConnected", function (participant) {
                            participant.on("trackAdded", function (track) { });
                            participant.on("trackSubscribed", function (track) {
                              trackSubscribed(remote_media, track);
                            });
                            participant.on("trackUnsubscribed", trackUnsubscribed);
                          });
                          room.on(
                            "participantDisconnected",
                            participantDisconnected
                          );
                          room.once("disconnected", function (error) {
                            room.participants.forEach(participantDisconnected);
                          });
                        });
                    });
                  video_call_object.createLocalVideoTrack().then(function (track) {
                    var localMediaContainer =
                      document.getElementById("local-media");
                    track.muted = true;
                    localMediaContainer.appendChild(track.attach());
                  });
                } else {
                  var errorDiv = document.createElement("DIV");
                  errorDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    errorDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    errorDiv.classList.add(font);
                  }
                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                  error_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(error_icon);
                  iconDiv.classList.add("question-icon-div");
                  error_icon.classList.add("question-icon-smatest");
                  var error_text = document.createElement("LABEL");
                  var error_msg = document.createTextNode(
                    "Video Call is not supported"
                  );
                  error_text.appendChild(error_msg);
                  say(error_text.innerText);
                  error_text.classList.add("question-text-error");
                  error_text.classList.add("options-div-smatest");
                  if (font && font.length > 0) {
                    error_text.classList.add(font);
                  }
                  errorDiv.appendChild(iconDiv);
                  errorDiv.appendChild(error_text);
                  body.appendChild(errorDiv);
                  playBotUserSound(1);
                  body.scrollTop = body.scrollHeight;
                }
              });
            }
            footer.appendChild(live_file_input);
            footer.appendChild(attach_label);
            if (shouldShowMenu) {
              if (voice_input == "1") {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 118px) !important";
              } else {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 115px) !important";
              }
            } else {
              if (voice_input == "1") {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 118px) !important";
              } else {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 80px) !important";
              }
            }
            var live_chat_base64;
            var name = "user";
            var room_name = live_chat_cb_session;
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                video_call_token = JSON.parse(this.responseText).token_twilio;
              }
            };
            xhttp.open(
              "GET",
              "https://www.smatbot.com/8000/getToken?room=" +
              room_name +
              "&identity=" +
              name,
              !0
            );
            xhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            xhttp.send();

            function getOtherBase64(file) {
              var reader = new FileReader();
              reader.readAsDataURL(file);
              reader.onload = function () {
                live_chat_base64 = reader.result;
              };
              reader.onerror = function (error) {
                live_chat_base64 = "";
              };
            }
            live_file_input.onchange = function () {
              if (agreed) {
                var files = document.getElementById("live-file-input").files;
                if (files.length > 0) {
                  if (files[0] && files[0].size) {
                    var main_size = parseInt(files[0].size / 1024 / 1024);
                    if (main_size < 10) {
                      getOtherBase64(files[0]);
                      setTimeout(function () {
                        if (live_chat_base64 && live_chat_base64.length > 0) {
                          var file_name = files[0].name;
                          var timestamp = new Date();
                          timestamp = timestamp.getTime();
                          var ext =
                            file_name.split(".")[file_name.split(".").length - 1];
                          timestamp = timestamp + "." + ext;
                          var liveSpinningDIv = document.createElement("DIV");
                          var spinnerDiv = document.createElement("DIV");
                          spinnerDiv.classList.add("spinner2-smatest");
                          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                          ques_icon.src = avatar_icon;
                          ques_icon.classList.add("question-icon-smatest");
                          var inner1 = document.createElement("DIV");
                          inner1.classList.add("bounce1");
                          var inner2 = document.createElement("DIV");
                          inner2.classList.add("bounce2");
                          var inner3 = document.createElement("DIV");
                          inner3.classList.add("bounce3");
                          spinnerDiv.appendChild(inner1);
                          spinnerDiv.appendChild(inner2);
                          spinnerDiv.appendChild(inner3);
                          liveSpinningDIv.classList.add("m-l-40");
                          liveSpinningDIv.classList.add("m-t-5");
                          liveSpinningDIv.classList.add("pull-right");
                          liveSpinningDIv.appendChild(spinnerDiv);
                          body.appendChild(liveSpinningDIv);
                          body.scrollTop = body.scrollHeight;
                          var xhttp = new XMLHttpRequest();
                          xhttp.onreadystatechange = function () {
                            if (this.readyState == 4 && this.status == 200) {
                              attach_label.style.pointerEvents = "auto";
                              body.removeChild(liveSpinningDIv);
                              var response = JSON.parse(this.responseText);
                              if (
                                response &&
                                response.url &&
                                response.url.length > 0
                              ) {
                                var images_text;
                                if (files[0].type.includes("image")) {
                                  images_text =
                                    "live_chat_image_upload;;" + response.url;
                                } else {
                                  images_text = response.url;
                                }
                                var d = new Date();
                                var date = d.getDate();
                                if (date < 10) {
                                  date = "0" + date;
                                }
                                var month = d.getMonth() + 1;
                                if (month < 10) {
                                  month = "0" + month;
                                }
                                var hours = d.getHours();
                                if (hours < 10) {
                                  hours = "0" + hours;
                                }
                                var mins = d.getMinutes();
                                if (mins < 10) {
                                  mins = "0" + mins;
                                }
                                var seconds = d.getSeconds();
                                if (seconds < 10) {
                                  seconds = "0" + seconds;
                                }
                                d =
                                  date +
                                  "/" +
                                  month +
                                  "/" +
                                  d.getFullYear() +
                                  ", " +
                                  hours +
                                  ":" +
                                  mins +
                                  ":" +
                                  seconds;
                                if (
                                  ip_is_banned &&
                                  banned_reason &&
                                  banned_reason.length > 0
                                ) {
                                  var livechatEncourageDiv =
                                    document.createElement("DIV");
                                  livechatEncourageDiv.id = "user-banned-div";
                                  livechatEncourageDiv.classList.add(
                                    "question-div-smatest"
                                  );
                                  setTimeout(function () {
                                    livechatEncourageDiv.classList.add("top-0");
                                  }, transition_time);
                                  if (font && font.length > 0) {
                                    livechatEncourageDiv.classList.add(font);
                                  }
                                  var live_chat_encourage_icon =
                                    document.createElement("IMG");
                                  live_chat_encourage_icon.alt = "Logo of " + totalData[0].name;
                                  live_chat_encourage_icon.src = avatar_icon;
                                  var iconDiv = document.createElement("DIV");
                                  iconDiv.appendChild(live_chat_encourage_icon);
                                  iconDiv.classList.add("question-icon-div");
                                  live_chat_encourage_icon.classList.add(
                                    "question-icon-smatest"
                                  );
                                  var live_chat_encourage_text =
                                    document.createElement("LABEL");
                                  live_chat_encourage_text.innerHTML =
                                    '<label style="float:left;width:100%;margin-bottom:">You have been banned from interacting with our live agents</label><label style="float:left;width:100%">Reason : ' +
                                    banned_reason +
                                    "</label>";
                                  say(live_chat_encourage_text.innerText);
                                  live_chat_encourage_text.classList.add(
                                    "question-text-error"
                                  );
                                  live_chat_encourage_text.classList.add(
                                    "options-div-smatest"
                                  );
                                  if (font && font.length > 0) {
                                    live_chat_encourage_text.classList.add(font);
                                  }
                                  livechatEncourageDiv.appendChild(iconDiv);
                                  livechatEncourageDiv.appendChild(
                                    live_chat_encourage_text
                                  );
                                  var checking_div =
                                    document.getElementById("user-banned-div");
                                  if (body.contains(checking_div)) {
                                  } else {
                                    body.appendChild(livechatEncourageDiv);
                                  }
                                  playBotUserSound(1);
                                  body.scrollTop = body.scrollHeight;
                                  if (document.getElementById("live-file-input")) {
                                    document.getElementById(
                                      "live-file-input"
                                    ).value = "";
                                  }
                                } else {
                                  sock.emit("usersentmessage", {
                                    time: d,
                                    message: images_text,
                                    session_id: live_chat_cb_session,
                                    device_print: device_print,
                                    type: "user",
                                    bot_id: chatbot_id,
                                    name: "user",
                                    channel: "website",
                                    agent_id: agent_id,
                                  });
                                  seen_cleared = true;
                                  agent_message_timer = 0;
                                  var answerDiv = document.createElement("DIV");
                                  answerDiv.classList.add("answer-div");
                                  setTimeout(function () {
                                    answerDiv.classList.add("top-0");
                                  }, transition_time);
                                  var answer = document.createElement("LABEL");
                                  var ext =
                                    response.url.split(".")[
                                    response.url.split(".").length - 1
                                    ];
                                    const getFileExtension = (filename) => {
                                        const dotIndex = filename.lastIndexOf('.');
                                        return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                                    };
                                    const fileTypeConvert = (fileData) => {
                                      const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                                      const extension = getFileExtension(filename).toLowerCase();
                                      let FileContainer;
                                    
                                      if (['png', 'jpg', 'jpeg', 'tif', 'gif','ico','webp'].includes(extension)) {
                                        answer.style.background = 'transparent'
                                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                                        FileContainer = `
                                          <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end;" >
                                            <img src="${fileData}" alt='${link}'  class='file-upload_image_style_sb'/>
                                          </a>
                                        `;
                                      }else if (['svg'].includes(extension)) {
                                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                                        FileContainer = `
                                          <a href="${fileData}" class='answer-label' target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end;padding:0 " >
                                            ${link}
                                          </a>
                                        `;
                                      } else if (['mp3', 'wav'].includes(extension)) {
                                        answer.style.background = 'transparent'
                                        FileContainer = `<audio style="width: 250px;" controls src="${fileData}"></audio>`;
                                      } else if (['mp4', 'webm', 'flv','mov'].includes(extension)) {
                                        answer.style.background = 'transparent'
                                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                                        FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='150px'></video>`;
                                      } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                                        answer.style.background = 'transparent'
                                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                                        // FileContainer = `<a href="${fileData}" target="_blank">${link}</a>`;
                                        FileContainer = `
                                        <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                                          <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt=''  width='25px' height='25px'/>
                                          <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                                          <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                                            <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                                          </a>
                                        </div>`
                                      
                                      } else {
                                        answer.style.background = 'transparent'
                                        FileContainer = fileData;
                                      }
                                    
                                      return FileContainer;
                                    };
                                    
                                    answer.innerHTML = fileTypeConvert(response.url);
                                  answer.classList.add("answer-label");
                                  if (font && font.length > 0) {
                                    answer.classList.add(font);
                                  }
                                  answerDiv.appendChild(answer);
                                  body.appendChild(answerDiv);
                                  body.scrollTop = body.scrollHeight;
                                  input.type = "text";
                                  input.placeholder = "Talk to our agent";
                                  enter.style.pointerEvents = "auto";
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  footer.classList.remove("close");
                                  input.value = "";
                                  if (document.getElementById("live-file-input")) {
                                    document.getElementById(
                                      "live-file-input"
                                    ).value = "";
                                  }
                                }
                              }
                            } else if (
                              this.readyState == 4 &&
                              (this.status == 500 || this.status == 404)
                            ) {
                              var errorDiv = document.createElement("DIV");
                              errorDiv.classList.add("question-div-smatest");
                              setTimeout(function () {
                                errorDiv.classList.add("top-0");
                              }, transition_time);
                              if (font && font.length > 0) {
                                errorDiv.classList.add(font);
                              }
                              var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                              error_icon.src = avatar_icon;
                              var iconDiv = document.createElement("DIV");
                              iconDiv.appendChild(error_icon);
                              iconDiv.classList.add("question-icon-div");
                              error_icon.classList.add("question-icon-smatest");
                              var error_text = document.createElement("LABEL");
                              var error_msg = document.createTextNode(
                                "Please upload a smaller file"
                              );
                              error_text.appendChild(error_msg);
                              say(error_text.innerText);
                              error_text.classList.add("question-text-error");
                              error_text.classList.add("options-div-smatest");
                              if (font && font.length > 0) {
                                error_text.classList.add(font);
                              }
                              errorDiv.appendChild(iconDiv);
                              errorDiv.appendChild(error_text);
                              body.appendChild(errorDiv);
                              playBotUserSound(1);
                              body.scrollTop = body.scrollHeight;
                              if (document.getElementById("live-file-input")) {
                                document.getElementById("live-file-input").value =
                                  "";
                              }
                            }
                          };
                          xhttp.open(
                            "POST",
                            main_url + "/kya_backend/pagehub/uploadFilecb",
                            !0
                          );
                          xhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          xhttp.send(
                            "data=" +
                            live_chat_base64 +
                            "&file_name=" +
                            timestamp +
                            "&bot_id=" +
                            chatbot_id
                          );
                        }
                      }, 1000);
                    } else {
                      var errorDiv = document.createElement("DIV");
                      errorDiv.classList.add("question-div-smatest");
                      setTimeout(function () {
                        errorDiv.classList.add("top-0");
                      }, transition_time);
                      if (font && font.length > 0) {
                        errorDiv.classList.add(font);
                      }
                      var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                      error_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(error_icon);
                      iconDiv.classList.add("question-icon-div");
                      error_icon.classList.add("question-icon-smatest");
                      var error_text = document.createElement("LABEL");
                      var error_msg = document.createTextNode(
                        "File size cannot be more than 5 MB"
                      );
                      error_text.appendChild(error_msg);
                      say(error_text.innerText);
                      error_text.classList.add("question-text-error");
                      error_text.classList.add("options-div-smatest");
                      if (font && font.length > 0) {
                        error_text.classList.add(font);
                      }
                      errorDiv.appendChild(iconDiv);
                      errorDiv.appendChild(error_text);
                      body.appendChild(errorDiv);
                      playBotUserSound(1);
                      body.scrollTop = body.scrollHeight;
                      if (document.getElementById("live-file-input")) {
                        document.getElementById("live-file-input").value = "";
                      }
                    }
                  }
                }
              }
            };
           
            if (attach_label) {
              const computedStyle = window.getComputedStyle(attach_label);
              if (computedStyle.pointerEvents === 'auto') {
                  var openedDiv = document.getElementById('opened');
                  openedDiv.ondragover = function (event) {
                    event.preventDefault();
                  };
                  openedDiv.ondrop = function (event) {
                    event.preventDefault();
                    if (agreed && liveSessionSet) {
                      var files = event.dataTransfer.files;
                      if (files.length > 0) {
                        if (files[0] && files[0].size) {
                          var main_size = parseInt(files[0].size / 1024 / 1024);
                          if (main_size < 10) {
                            getOtherBase64(files[0]);
                            setTimeout(function () {
                              if (live_chat_base64 && live_chat_base64.length > 0) {
                                var file_name = files[0].name;
                                var timestamp = new Date();
                                timestamp = timestamp.getTime();
                                var ext = file_name.split('.')[file_name.split('.').length - 1];
                                timestamp = timestamp + '.' + ext;
                                var liveSpinningDIv = document.createElement('DIV');
                                var spinnerDiv = document.createElement('DIV');
                                spinnerDiv.classList.add('spinner2-smatest');
                                var ques_icon = document.createElement('IMG');
                                ques_icon.alt = 'Logo of ' + totalData[0].name;
                                ques_icon.src = avatar_icon;
                                ques_icon.classList.add('question-icon-smatest');
                                var inner1 = document.createElement('DIV');
                                inner1.classList.add('bounce1');
                                var inner2 = document.createElement('DIV');
                                inner2.classList.add('bounce2');
                                var inner3 = document.createElement('DIV');
                                inner3.classList.add('bounce3');
                                spinnerDiv.appendChild(inner1);
                                spinnerDiv.appendChild(inner2);
                                spinnerDiv.appendChild(inner3);
                                liveSpinningDIv.classList.add('m-l-40');
                                liveSpinningDIv.classList.add('m-t-5');
                                liveSpinningDIv.classList.add('pull-right');
                                liveSpinningDIv.appendChild(spinnerDiv);
                                body.appendChild(liveSpinningDIv);
                                body.scrollTop = body.scrollHeight;
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    attach_label.style.pointerEvents = 'auto';
                                    body.removeChild(liveSpinningDIv);
                                    var response = JSON.parse(this.responseText);
                                    if (response && response.url && response.url.length > 0) {
                                      var images_text;
                                      if (files[0].type.includes('image')) {
                                        images_text = 'live_chat_image_upload;;' + response.url;
                                      } else {
                                        images_text = response.url;
                                      }
                                      var d = new Date();
                                      var date = d.getDate();
                                      if (date < 10) {
                                        date = '0' + date;
                                      }
                                      var month = d.getMonth() + 1;
                                      if (month < 10) {
                                        month = '0' + month;
                                      }
                                      var hours = d.getHours();
                                      if (hours < 10) {
                                        hours = '0' + hours;
                                      }
                                      var mins = d.getMinutes();
                                      if (mins < 10) {
                                        mins = '0' + mins;
                                      }
                                      var seconds = d.getSeconds();
                                      if (seconds < 10) {
                                        seconds = '0' + seconds;
                                      }
                                      d =
                                        date +
                                        '/' +
                                        month +
                                        '/' +
                                        d.getFullYear() +
                                        ', ' +
                                        hours +
                                        ':' +
                                        mins +
                                        ':' +
                                        seconds;
                                      if (
                                        ip_is_banned &&
                                        banned_reason &&
                                        banned_reason.length > 0
                                      ) {
                                        var livechatEncourageDiv = document.createElement('DIV');
                                        livechatEncourageDiv.id = 'user-banned-div';
                                        livechatEncourageDiv.classList.add(
                                          'question-div-smatest'
                                        );
                                        setTimeout(function () {
                                          livechatEncourageDiv.classList.add('top-0');
                                        }, transition_time);
                                        if (font && font.length > 0) {
                                          livechatEncourageDiv.classList.add(font);
                                        }
                                        var live_chat_encourage_icon =
                                          document.createElement('IMG');
                                        live_chat_encourage_icon.alt =
                                          'Logo of ' + totalData[0].name;
                                        live_chat_encourage_icon.src = avatar_icon;
                                        var iconDiv = document.createElement('DIV');
                                        iconDiv.appendChild(live_chat_encourage_icon);
                                        iconDiv.classList.add('question-icon-div');
                                        live_chat_encourage_icon.classList.add(
                                          'question-icon-smatest'
                                        );
                                        var live_chat_encourage_text =
                                          document.createElement('LABEL');
                                        live_chat_encourage_text.innerHTML =
                                          '<label style="float:left;width:100%;margin-bottom:">You have been banned from interacting with our live agents</label><label style="float:left;width:100%">Reason : ' +
                                          banned_reason +
                                          '</label>';
                                        say(live_chat_encourage_text.innerText);
                                        live_chat_encourage_text.classList.add(
                                          'question-text-error'
                                        );
                                        live_chat_encourage_text.classList.add(
                                          'options-div-smatest'
                                        );
                                        if (font && font.length > 0) {
                                          live_chat_encourage_text.classList.add(font);
                                        }
                                        livechatEncourageDiv.appendChild(iconDiv);
                                        livechatEncourageDiv.appendChild(
                                          live_chat_encourage_text
                                        );
                                        var checking_div =
                                          document.getElementById('user-banned-div');
                                        if (body.contains(checking_div)) {
                                        } else {
                                          body.appendChild(livechatEncourageDiv);
                                        }
                                        playBotUserSound(1);
                                        body.scrollTop = body.scrollHeight;
                                        if (document.getElementById('live-file-input')) {
                                          document.getElementById('live-file-input').value = '';
                                        }
                                      } else {
                                        sock.emit('usersentmessage', {
                                          time: d,
                                          message: images_text,
                                          session_id: live_chat_cb_session,
                                          device_print: device_print,
                                          type: 'user',
                                          bot_id: chatbot_id,
                                          name: 'user',
                                          channel: 'website',
                                          agent_id: agent_id,
                                        });
                                        seen_cleared = true;
                                        agent_message_timer = 0;
                                        var answerDiv = document.createElement('DIV');
                                        answerDiv.classList.add('answer-div');
                                        setTimeout(function () {
                                          answerDiv.classList.add('top-0');
                                        }, transition_time);
                                        var answer = document.createElement('LABEL');
                                        var ext =
                                          response.url.split('.')[
                                            response.url.split('.').length - 1
                                          ];
                                        const getFileExtension = (filename) => {
                                          const dotIndex = filename.lastIndexOf('.');
                                          return dotIndex !== -1
                                            ? filename.slice(dotIndex + 1)
                                            : '';
                                        };
                                        const fileTypeConvert = (fileData) => {
                                          const filename = fileData
                                            ?.split(/\#|\?/)[0]
                                            .split('/')
                                            .pop()
                                            .trim();
                                          const extension =
                                            getFileExtension(filename).toLowerCase();
                                          let FileContainer;
      
                                          if (
                                            [
                                              'png',
                                              'jpg',
                                              'jpeg',
                                              'tif',
                                              'gif',
                                              'ico',
                                              'webp',
                                            ].includes(extension)
                                          ) {
                                            let link = fileData.substring(
                                              fileData.lastIndexOf('/') + 1
                                            );
                                            FileContainer = `
                                                            <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end " >
                                                              <img src="${fileData}" alt='${link}'  class='file-upload_image_style_sb'/>
                                                            </a>
                                                          `;
                                          } else if (['svg'].includes(extension)) {
                                            let link = fileData.substring(
                                              fileData.lastIndexOf('/') + 1
                                            );
                                            FileContainer = `
                                                            <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end " >
                                                              ${link}
                                                            </a>
                                                          `;
                                          } else if (['mp3', 'wav'].includes(extension)) {
                                            FileContainer = `<audio style="width: 250px;" controls src="${fileData}"></audio>`;
                                          } else if (
                                            ['mp4', 'webm', 'flv', 'mov'].includes(extension)
                                          ) {
                                            let link = fileData.substring(
                                              fileData.lastIndexOf('/') + 1
                                            );
                                            FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='150px'></video>`;
                                          } else if (
                                            [
                                              'pdf',
                                              'doc',
                                              'txt',
                                              'docx',
                                              'zip',
                                              'csv',
                                              'xlsx',
                                              'xls',
                                            ].includes(extension)
                                          ) {
                                            let link = fileData.substring(
                                              fileData.lastIndexOf('/') + 1
                                            );
                                            // FileContainer = `<a href="${fileData}" target="_blank">${link}</a>`;
                                            FileContainer = `
                                                          <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                                                            <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt=''  width='25px' height='25px'/>
                                                            <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                                                            <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                                                              <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                                                            </a>
                                                          </div>`;
                                          } else {
                                            FileContainer = fileData;
                                          }
      
                                          return FileContainer;
                                        };
                                        answer.style.background = 'transparent';
                                        answer.innerHTML = fileTypeConvert(response.url);
                                        answer.classList.add('answer-label');
                                        if (font && font.length > 0) {
                                          answer.classList.add(font);
                                        }
                                        answerDiv.appendChild(answer);
                                        body.appendChild(answerDiv);
                                        body.scrollTop = body.scrollHeight;
                                        input.type = 'text';
                                        input.placeholder = 'Talk to our agent';
                                        enter.style.pointerEvents = 'auto';
                                        footer.style.display = 'block';
                                        if (header.contains(company_title_description)) {
                                          body.style.height = 'calc(100% - 226px)';
                                        } else {
                                          body.style.height = 'calc(100% - 150px)';
                                        }
                                        footer.classList.remove('close');
                                        input.value = '';
                                        if (document.getElementById('live-file-input')) {
                                          document.getElementById('live-file-input').value = '';
                                        }
                                      }
                                    }
                                  } else if (
                                    this.readyState == 4 &&
                                    (this.status == 500 || this.status == 404)
                                  ) {
                                    var errorDiv = document.createElement('DIV');
                                    errorDiv.classList.add('question-div-smatest');
                                    setTimeout(function () {
                                      errorDiv.classList.add('top-0');
                                    }, transition_time);
                                    if (font && font.length > 0) {
                                      errorDiv.classList.add(font);
                                    }
                                    var error_icon = document.createElement('IMG');
                                    error_icon.alt = 'Logo of ' + totalData[0].name;
                                    error_icon.src = avatar_icon;
                                    var iconDiv = document.createElement('DIV');
                                    iconDiv.appendChild(error_icon);
                                    iconDiv.classList.add('question-icon-div');
                                    error_icon.classList.add('question-icon-smatest');
                                    var error_text = document.createElement('LABEL');
                                    var error_msg = document.createTextNode(
                                      'Please upload a smaller file'
                                    );
                                    error_text.appendChild(error_msg);
                                    say(error_text.innerText);
                                    error_text.classList.add('question-text-error');
                                    error_text.classList.add('options-div-smatest');
                                    if (font && font.length > 0) {
                                      error_text.classList.add(font);
                                    }
                                    errorDiv.appendChild(iconDiv);
                                    errorDiv.appendChild(error_text);
                                    body.appendChild(errorDiv);
                                    playBotUserSound(1);
                                    body.scrollTop = body.scrollHeight;
                                    if (document.getElementById('live-file-input')) {
                                      document.getElementById('live-file-input').value = '';
                                    }
                                  }
                                };
                                xhttp.open(
                                  'POST',
                                  main_url + '/kya_backend/pagehub/uploadFilecb',
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  'Content-type',
                                  'application/x-www-form-urlencoded'
                                );
                                xhttp.send(
                                  'data=' +
                                    live_chat_base64 +
                                    '&file_name=' +
                                    timestamp +
                                    '&bot_id=' +
                                    chatbot_id
                                );
                              }
                            }, 1000);
                          } else {
                            var errorDiv = document.createElement('DIV');
                            errorDiv.classList.add('question-div-smatest');
                            setTimeout(function () {
                              errorDiv.classList.add('top-0');
                            }, transition_time);
                            if (font && font.length > 0) {
                              errorDiv.classList.add(font);
                            }
                            var error_icon = document.createElement('IMG');
                            error_icon.alt = 'Logo of ' + totalData[0].name;
                            error_icon.src = avatar_icon;
                            var iconDiv = document.createElement('DIV');
                            iconDiv.appendChild(error_icon);
                            iconDiv.classList.add('question-icon-div');
                            error_icon.classList.add('question-icon-smatest');
                            var error_text = document.createElement('LABEL');
                            var error_msg = document.createTextNode(
                              'File size cannot be more than 5 MB'
                            );
                            error_text.appendChild(error_msg);
                            say(error_text.innerText);
                            error_text.classList.add('question-text-error');
                            error_text.classList.add('options-div-smatest');
                            if (font && font.length > 0) {
                              error_text.classList.add(font);
                            }
                            errorDiv.appendChild(iconDiv);
                            errorDiv.appendChild(error_text);
                            body.appendChild(errorDiv);
                            playBotUserSound(1);
                            body.scrollTop = body.scrollHeight;
                            if (document.getElementById('live-file-input')) {
                              document.getElementById('live-file-input').value = '';
                            }
                          }
                        }
                      }
                    }
                  };
              } 
            }


            if (!alreadySockLoaded) {
              sock = io.connect("https://www.smatbot.com", {
                rememberTransport: false,
                transports: ["websocket"],
                pingTimeout: 60000,
                pingInterval: 25000,
                "connect timeout": 1000,
                path: "/livechat/socket.io",
              });

              var typingDiv = document.createElement("DIV");
              typingDiv.classList.add("agent-typing-div");
              var typingLabel = document.createElement("LABEL");
              typingLabel.innerHTML = generateTranslatedContent(translations, "Agent is typing ...", main_lang_code, language_code, input);
              typingLabel.classList.add("agent-typing-label");
              if (font && font.length > 0) {
                typingLabel.classList.add(font);
              }
              typingDiv.style.display = "none";
              typingDiv.appendChild(typingLabel);
              body.appendChild(typingDiv);
              sock.on("setagentname", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                }
              });
              sock.on("setstatus", function (data) {
                if (data.assigned_sessions && data.assigned_sessions.length > 0) {
                  var arr;
                  if (data.assigned_sessions[0]) {
                    arr = data.assigned_sessions;
                  } else {
                    arr = data.assigned_sessions.split(",");
                  }
                  if (arr.indexOf(live_chat_cb_session) > -1) {
                    var agent_left_div = document.createElement("DIV");
                    agent_left_div.id = "agent-joining-div";
                    agent_left_div.classList.add("pull-left");
                    agent_left_div.classList.add("full-width");
                    agent_left_div.classList.add("m-t-10");
                    agent_left_div.classList.add("m-b-10");
                    var agent_left_label = document.createElement("LABEL");
                    var border_left_span = document.createElement("SPAN");
                    border_left_span.classList.add("left-border-combo");
                    var border_right_span = document.createElement("SPAN");
                    border_right_span.classList.add("right-border-combo");
                    var agent_left_span = document.createElement("SPAN");
                    agent_left_span.classList.add("center-text-combo");
                    var string;
                    if (data.status == "away") {
                      if (data.agent_name && data.agent_name.length > 0) {
                        string = data.agent_name + " left the chat";
                      } else {
                        string = "agent left the chat";
                      }
                    } else if (data.status == "online") {
                      if (data.agent_name && data.agent_name.length > 0) {
                        string = data.agent_name + " joined the chat";
                      } else {
                        string = "agent joined the chat";
                      }
                      enter.style.pointerEvents = "auto";
                      input.style.pointerEvents = "auto";
                    }
                  }
                }
              });
              sock.on("agentassigned", function (data) {
                try {
                  input.focus();
                  input.style.pointerEvents = "auto";
                  attach_label.style.pointerEvents = "auto";
                  microphone.style.pointerEvents = "auto";
                  microphone.style.opacity = 1;
                  enter.style.pointerEvents = "auto";
                } catch (error) { }
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  if (agent_id && agent_id.toString().length > 0) {
                    agent_id = agent_id + "";
                    var agents_list = agent_id.split(",");
                    var already_exists;
                    for (var i = 0; i < agents_list.length; i++) {
                      if (agents_list[i] == data.agent_id) {
                        already_exists = true;
                      }
                    }
                    if (!already_exists) {
                      agents_list.push(data.agent_id);
                    }
                    agent_id = agents_list.join(",");
                  } else {
                    agent_id = data.agent_id;
                  }
                  if (data.agent_name && data.agent_name.length > 0) {
                    agent_name = data.agent_name;
                  } else {
                    agent_name = "admin";
                  }
                  typingLabel.innerHTML = agent_name + " is typing ...";
                  var agent_left_div = document.createElement("DIV");
                  agent_left_div.id = "agent-joining-div";
                  agent_left_div.classList.add("pull-left");
                  agent_left_div.classList.add("full-width");
                  agent_left_div.classList.add("m-t-10");
                  agent_left_div.classList.add("m-b-10");
                  var agent_avather = document.createElement("img");
                  agent_avather.alt ='agent avather'
                  // if (agentTotalData && agentTotalData.customer_avatar && agentTotalData.customer_avatar.length > 0) {
                  //   agent_avather.src = agentTotalData.customer_avatar
                  // }else{
                  //   agent_avather.src = avatar_icon
                  // }
                    if (data && data.customer_avatar && data.customer_avatar !== null && data.customer_avatar !== undefined && data.customer_avatar.trim() !== "") {
                    const avatars = data.customer_avatar.split(",");
                    if (avatars.length > 1) {
                      agent_avather.src = avatar_icon;
                    } else {
                      agent_avather.src = avatars[0];
                    }
                    } else {
                    agent_avather.src = avatar_icon;
                    }
                  agent_avather.style.width = '40px';
                  agent_avather.style.height = '40px';
                  agent_avather.style.borderRadius = '50%';
                  var agent_left_label = document.createElement("LABEL");
                  agent_left_label.classList.add("text-line-combo");
                  agent_left_label.style.border='none'  
                  agent_left_label.style.margin='0'
                  agent_left_label.style.lineHeight='normal'
                  var agent_left_span = document.createElement("SPAN");
                  var string;
                  if (data.agent_name && data.agent_name.length > 0) {
                    let agent_name_uppercase = data.agent_name.charAt(0).toUpperCase() + data.agent_name.slice(1);
                    string = agent_name_uppercase + " Joined The Chat";
                  } else {
                    string = "Agent Joined The Chat";
                  }
                  agent_left_span.innerHTML = string;
                  agent_left_label.appendChild(agent_left_span);
                  agent_left_div.appendChild(agent_avather);
                  agent_left_div.appendChild(agent_left_label);
                  var elem = document.getElementById("agent-joining-div");
                  if (body.contains(elem)) {
                  } else {
                    body.appendChild(agent_left_div);
                    body.scrollTop = body.scrollHeight;
                  }
                }
              });
              sock.on("chatclosingreminder", function (data) {
                if (live_chat_cb_session == data.session_id) {
                  var errorDiv = document.createElement("DIV");
                  errorDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    errorDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    errorDiv.classList.add(font);
                  }
                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                  error_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(error_icon);
                  iconDiv.classList.add("question-icon-div");
                  error_icon.classList.add("question-icon-smatest");
                  var error_text = document.createElement("LABEL");
                  error_text.innerHTML =
                    "As there is no interaction from both agent and you, this chat will be closed in 1 min.";
                  say(error_text.innerText);
                  error_text.classList.add("question-text-error");
                  error_text.classList.add("options-div-smatest");
                  if (font && font.length > 0) {
                    error_text.classList.add(font);
                  }
                  errorDiv.appendChild(iconDiv);
                  errorDiv.appendChild(error_text);
                  body.appendChild(errorDiv);
                  body.scrollTop = body.scrollHeight;

                  // sock.emit('messageack', {
                  //   event_name: 'chatclosingreminder',
                  //   eventData:  data
                  // });

                }
              });
              sock.on("autoclose", function (data) {
                if (live_chat_cb_session == data.session_id) {
                  var errorDiv = document.createElement("DIV");
                  errorDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    errorDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    errorDiv.classList.add(font);
                  }
                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                  error_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(error_icon);
                  iconDiv.classList.add("question-icon-div");
                  error_icon.classList.add("question-icon-smatest");
                  var error_text = document.createElement("LABEL");
                  error_text.innerHTML =
                    "This conversation has been auto-closed as there has been no response.";
                  say(error_text.innerText);
                  error_text.classList.add("question-text-error");
                  error_text.classList.add("options-div-smatest");
                  if (font && font.length > 0) {
                    error_text.classList.add(font);
                  }
                  errorDiv.appendChild(iconDiv);
                  errorDiv.appendChild(error_text);
                  body.appendChild(errorDiv);
                  body.scrollTop = body.scrollHeight;
                  enter.style.pointerEvents = "none";
                  input.blur();
                  input.style.pointerEvents = "none";
                  attach_label.style.pointerEvents = "none";
                  start_live_chat_timer = false;

                  // sock.emit('messageack', {
                  //   event_name: 'autoclose',
                  //   eventData:  data
                  // });

                }
              });
              sock.on("whatsappagentsearching", function (data) {
                if (live_chat_cb_session == data.session_id) {
                  var errorDiv = document.createElement("DIV");
                  errorDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    errorDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    errorDiv.classList.add(font);
                  }
                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                  error_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(error_icon);
                  iconDiv.classList.add("question-icon-div");
                  error_icon.classList.add("question-icon-smatest");
                  var error_text = document.createElement("LABEL");
                  error_text.innerHTML =
                    "We are still trying to look for an agent.  Thank you for your patience. please stay connected while I'm looking for the next available agent.";
                  say(error_text.innerText);
                  error_text.classList.add("question-text-error");
                  error_text.classList.add("options-div-smatest");
                  if (font && font.length > 0) {
                    error_text.classList.add(font);
                  }
                  errorDiv.appendChild(iconDiv);
                  errorDiv.appendChild(error_text);
                  body.appendChild(errorDiv);
                  body.scrollTop = body.scrollHeight;
                }
              });
              sock.on("nowhatsappagents", function (data) {
                if (live_chat_cb_session == data.session_id) {
                  var errorDiv = document.createElement("DIV");
                  errorDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    errorDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    errorDiv.classList.add(font);
                  }
                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                  error_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(error_icon);
                  iconDiv.classList.add("question-icon-div");
                  error_icon.classList.add("question-icon-smatest");
                  var error_text = document.createElement("LABEL");
                  error_text.innerHTML =
                    "Unfortunately, no agents are online right now. Our team will get in touch with you in next 24 hours. Thank you for your patience.<br><br/>This conversation has been auto-closed as there are no agents available at this moment.";
                  say(error_text.innerText);
                  error_text.classList.add("question-text-error");
                  error_text.classList.add("options-div-smatest");
                  if (font && font.length > 0) {
                    error_text.classList.add(font);
                  }
                  errorDiv.appendChild(iconDiv);
                  errorDiv.appendChild(error_text);
                  body.appendChild(errorDiv);
                  body.scrollTop = body.scrollHeight;
                  enter.style.pointerEvents = "none";
                  input.blur();
                  input.style.pointerEvents = "none";
                  attach_label.style.pointerEvents = "none";
                }
              });
              sock.on("adminsentmessage", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  if (!adminMessaged) {
                    header_menu_div.appendChild(ask_live_chat_feedback_div);
                    updateMenuIcons()
                    ask_live_chat_feedback_div.addEventListener(
                      "click",
                      function (k) {
                        k.stopPropagation();
                        if (header_menu_div.classList.contains("closed-header-menu")) {
                        } else {
                          header_menu_div.classList.add("closed-header-menu");
                        }
                        if (live_chat_feedback_opened) {
                          if (document.getElementById("open-live-chat-feedback")) {
                            document
                              .getElementById("open-live-chat-feedback")
                              .click();
                          }
                          addLiveChatFeedback();
                        } else {
                          addLiveChatFeedback();
                        }
                      }
                    );
                    adminMessaged = true;
                  }
                  seen_cleared = false;
                  agent_message_timer = 0;
                  start_live_chat_timer = false;
                  if (data.agent_id && data.agent_id.length > 0) {
                    agent_id = data.agent_id;
                  }
                  var agentDiv = document.createElement("DIV");
                  agentDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    agentDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    agentDiv.classList.add(font);
                  }
                  var agent_icon = document.createElement("IMG"); agent_icon.alt = "Logo of " + totalData[0].name;
                  if (data.agent_avatar && data.agent_avatar.length > 0) {
                    if (data.agent_avatar && data.agent_avatar.includes(",")) {
                      agent_icon.src = data.agent_avatar.split(",")[0];
                    } else {
                      agent_icon.src = data.agent_avatar;
                    }
                  } else {
                    agent_icon.src = avatar_icon;
                  }
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(agent_icon);
                  iconDiv.classList.add("question-icon-div");
                  agent_icon.classList.add("question-icon-smatest");
                  var agent_text_div = document.createElement("DIV");
                  var agent_text = document.createElement("LABEL");
                  if (
                    data.message &&
                    data.message.includes("live_chat_image_upload;;")
                  ) {
                    data.message = data.message.replace(
                      "live_chat_image_upload;;",
                      ""
                    );
                    var answer_a = document.createElement("a");
                    answer_a.href = data.message;
                    answer_a.target = "_blank";
                    answer_a.style.height = "100%";
                    answer_a.style.width = "fit-content";
                    answer_a.style.display = "block";
                    var answer_img = document.createElement("IMG");
                    answer_img.src = data.message;
                    answer_img.classList.add("contact-image-smatest");
                    agent_text_div.style.background = 'transparent'
                    agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                    answer_a.appendChild(answer_img);
                    agent_text.appendChild(answer_a);
                  } else {
                    var pattern = new RegExp(
                      "^(https?:\\/\\/)?" + // protocol
                      "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|" + // domain name
                      "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
                      "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
                      "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
                      "(\\#[-a-z\\d_]*)?$",
                      "i"
                    );
                    function isURL(str) {
                      const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
                      return urlPattern.test(str);
                    }
                    
                    const getFileExtension = (filename) => {
                      const dotIndex = filename.lastIndexOf('.');
                      return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                    };
                    
                    function insertLinkTags(text) {
                      // Define a regular expression pattern to match URLs
                      const urlPattern = /(https?:\/\/\S+)/g;
                    
                      // Replace each URL with a formatted link
                      const result = text.replace(urlPattern, '<div><a href="$1" target="_blank">$1</a></div>');
                    
                      return result;
                    }
                    
                    const fileTypeConvert = (fileData) => {
                      const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                      const extension = getFileExtension(filename).toLowerCase();
                      let FileContainer;
                    
                      if (['png', 'jpg', 'jpeg', 'svg', 'tif', 'gif','ico','webp'].includes(extension)) {
                        agent_text_div.style.background = 'transparent'
                        agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                        FileContainer = `
                          <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end " >
                            <img src="${fileData}" alt='${link}'  class='file-upload_image_style_sb'/>
                          </a>
                        `;
                      } else if (['mp3', 'wav'].includes(extension)) {
                          agent_text_div.style.background = 'transparent';
                          agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                        FileContainer = `<audio style="width: 100%;" controls src="${fileData}"></audio>`;
                      } else if (['mp4', 'webm', 'flv','mov'].includes(extension)) {
                        agent_text_div.style.background = 'transparent';
                        agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";

                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                        FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='100%'></video>`;
                      } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                         agent_text_div.style.background = 'transparent'
                         agent_text_div.style.cssText = agent_text_div.style.cssText + "padding:5px !important;";
                        let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                        FileContainer = `
                        <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                          <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt=''  width='25px' height='25px'/>
                          <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                          <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                            <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                          </a>
                        </div>`
                      
                      } else if (fileData?.includes('https://') || fileData?.includes('http://')) {

                        const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                    
                        if (anchorTagPattern.test(fileData)) {
                          FileContainer = fileData
                        }else{
                          const words = fileData.split(/\s+/);
                          const urlPattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i;
                           FileContainer = insertLinkTags(fileData);
                        }
                          
                      }else{
                        FileContainer = fileData
                      }
                    
                      return FileContainer;
                    };
                    if (pattern.test(data.message)) {
                      agent_text.innerHTML = fileTypeConvert(data.message.trim());
                    } else {
                      const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
                      if (anchorTagPattern.test(data.message.trim())) {
                      agent_text.textContent = fileTypeConvert(data.message.trim());
                      }
                      agent_text.innerHTML =  fileTypeConvert(data.message.trim());
                    }

                    // Check if the innerHTML contains data-list="bullet"
                    if (agent_text.innerHTML.includes('data-list="bullet"')) {
                      agent_text.querySelectorAll('li[data-list="bullet"]').forEach(li => {
                      li.style.listStyleType = 'disc';
                      });
                    }
                    if (agent_text.innerHTML.includes('data-list="ordered"')) {
                      agent_text.querySelectorAll('li[data-list="ordered"]').forEach(li => {
                      li.style.listStyleType = 'decimal';
                      });
                    }
                    if (agent_text.innerHTML.includes('data-list="ordered"') || agent_text.innerHTML.includes('data-list="bullet"')) {
                      agent_text.querySelectorAll('ol').forEach(ol => {
                      ol.style.listStyle = 'inside';
                      });
                    }
                  }
                  say(agent_text.innerText);
                  agent_text_div.classList.add("options-div-smatest");
                  agent_text_div.appendChild(agent_text);
                  var matchedUrls = urlsFromString(data.message);
                  if (
                    matchedUrls &&
                    matchedUrls.length > 0 &&
                    matchedUrls[0] &&
                    matchedUrls[0].length > 0
                  ) {
                    var extension = matchedUrls[0]
                      .split(/\#|\?/)[0]
                      .split(".")
                      .pop()
                      .trim();
                    var file_name =
                      matchedUrls[0].split("/")[
                      matchedUrls[0].split("/").length - 1
                      ];
                    var download_div = document.createElement("DIV");
                    download_div.classList.add("pull-left");
                    download_div.classList.add("full-width");
                    download_div.classList.add("text-center");
                    var download_a = document.createElement("A");
                    download_a.title = "Live chat file redirection";
                    if (file_name && file_name.length > 0) {
                      download_a.innerHTML = file_name;
                    } else {
                      download_a.innerHTML = "Open";
                    }
                    download_a.style.cursor = "pointer";
                    download_a.style.display = "inline-block";
                    download_a.addEventListener("click", function () { });
                    download_a.classList.add("confirm-btn-smatest");
                    download_a.setAttribute("href", matchedUrls[0]);
                    download_a.style.cssText =
                      download_a.style.cssText + "color:white !important;";
                    download_a.download = "file";
                    if (extension == "pdf") {
                      download_a.setAttribute("type", "application/octet-stream");
                    }
                    download_a.setAttribute("target", "_blank");
                    // download_div.appendChild(download_a);
                    if (
                      data.message &&
                      data.message.includes("live_chat_image_upload;;")
                    ) {
                    } else {
                      agent_text_div.appendChild(download_div);
                    }
                  }
                  if (font && font.length > 0) {
                    agent_text.classList.add(font);
                  }
                  var agent_time_name_div = document.createElement("DIV");
                  agent_time_name_div.style.marginLeft = "40px";
                  agent_time_name_div.style.width = "75%";
                  agent_time_name_div.classList.add("pull-left");
                  agent_time_name_div.classList.add("full-width");
                  var agent_name_time_span = document.createElement("SPAN");
                  agent_name_time_span.style.fontSize = "10px";
                  agent_name_time_span.style.color = "grey";
                  agent_name_time_span.style.display = "block";
                  agent_name_time_span.style.textAlign = "right";
                  var given_date = data.time.split(",")[0];
                  var d = new Date();
                  var date = d.getDate();
                  if (date < 10) {
                    date = "0" + date;
                  }
                  var month = d.getMonth() + 1;
                  if (month < 10) {
                    month = "0" + month;
                  }
                  d = date + "/" + month + "/" + d.getFullYear();
                  if (d == given_date) {
                    data.time = data.time.replace(given_date, "Today");
                  }
                  agent_name_time_span.innerHTML = data.time;
                  agent_time_name_div.appendChild(agent_name_time_span);
                  agent_time_name_div.classList.add("blink-animation");
                  var agentTypingDiv = document.getElementById("admin-typing-div");
                  if (agentTypingDiv && agentTypingDiv.parentElement) {
                    agentTypingDiv.parentElement.removeChild(agentTypingDiv);
                  }
                  agentDiv.appendChild(iconDiv);
                  agentDiv.appendChild(agent_text_div);
                  body.appendChild(agentDiv);
                  body.appendChild(agent_time_name_div);
                  setTimeout(function () {
                    agent_time_name_div.style.opacity = 0;
                  }, 1500);
                  playBotUserSound(1);
                  body.scrollTop = body.scrollHeight;
                  agent_text_div.addEventListener("mouseover", function (k) {
                    agent_time_name_div.style.opacity = 1;
                  });
                  agent_text_div.addEventListener("mouseout", function (k) {
                    agent_time_name_div.style.opacity = 0;
                  });

                  // sock.emit('messageack', {
                  //   event_name: 'adminsentmessage',
                  //   eventData:  data
                  // });

                }
              });
              sock.on("noagentavailable", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  seen_cleared = false;
                  agent_message_timer = 0;
                  start_live_chat_timer = false;
                  alreadySockLoaded = undefined;
                  liveSessionSet = false;
                  if (data.agent_id && data.agent_id.length > 0) {
                    agent_id = data.agent_id;
                  }
                  var agentDiv = document.createElement("DIV");
                  agentDiv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    agentDiv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    agentDiv.classList.add(font);
                  }
                  var agent_icon = document.createElement("IMG"); agent_icon.alt = "Logo of " + totalData[0].name;
                  if (data.agent_avatar && data.agent_avatar.length > 0) {
                    if (data.agent_avatar && data.agent_avatar.includes(",")) {
                      agent_icon.src = data.agent_avatar.split(",")[0];
                    } else {
                      agent_icon.src = data.agent_avatar;
                    }
                  } else {
                    agent_icon.src = avatar_icon;
                  }
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(agent_icon);
                  iconDiv.classList.add("question-icon-div");
                  agent_icon.classList.add("question-icon-smatest");
                  var agent_text = document.createElement("LABEL");
                  agent_text.innerHTML = generateTranslatedContent(translations, "Currently none of our agents are online, Please check back later", main_lang_code, language_code, input);
                  say(agent_text.innerText);
                  agent_text.classList.add("question-text-error");
                  agent_text.classList.add("options-div-smatest");
                  if (font && font.length > 0) {
                    agent_text.classList.add(font);
                  }
                  agentDiv.appendChild(iconDiv);
                  agentDiv.appendChild(agent_text);
                  if (body && body.lastChild) {
                    body.removeChild(body.lastChild);
                  }
                  body.appendChild(agentDiv);
                  playBotUserSound(1);
                  body.scrollTop = body.scrollHeight;
                  enter.style.pointerEvents = "none";
                  input.blur();
                  input.style.pointerEvents = "none";
                  try {
                    sock.disconnect();
                  } catch (error) { }
                  if (out_of_office_jump && out_of_office_jump.length > 0) {
                    var selected_country =
                      document.getElementById("selected_country");
                    if (footer.contains(selected_country)) {
                      footer.removeChild(selected_country);
                    }
                    menu_options_div.classList.add("close");
                    if (!shouldShowMenu) {
                      footer.style.display = "none";
                      footer.classList.add("close");
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 168px)";
                      } else {
                        body.style.height = "calc(100% - 93px)";
                      }
                    } else {
                      if (entry_id) {
                        input.style.pointerEvents = "auto";
                        microphone.style.pointerEvents = "auto";
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = "auto";
                        setPlaceHolders();
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                      } else {
                        input.style.pointerEvents = "none";
                        microphone.style.pointerEvents = "none";
                        microphone.style.opacity = 0;
                        enter.style.pointerEvents = "none";
                        input.blur();
                        input.placeholder = "Choose from Menu";
                        input.type = "text";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                      }
                    }
                    var spinningDiv = document.createElement("DIV");
                    spinningDiv.classList.add("question-div-smatest");
                    spinningDiv.classList.add("top-0");
                    if (font && font.length > 0) {
                      spinningDiv.classList.add(font);
                    }
                    var spinnerDiv = document.createElement("DIV");
                    spinnerDiv.classList.add("spinner1-smatest");
                    var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon.src = avatar_icon;
                    ques_icon.classList.add("question-icon-smatest");
                    var inner1 = document.createElement("DIV");
                    inner1.classList.add("bounce1");
                    var inner2 = document.createElement("DIV");
                    inner2.classList.add("bounce2");
                    var inner3 = document.createElement("DIV");
                    inner3.classList.add("bounce3");
                    spinnerDiv.appendChild(inner1);
                    spinnerDiv.appendChild(inner2);
                    spinnerDiv.appendChild(inner3);
                    spinningDiv.appendChild(iconDiv);
                    spinningDiv.appendChild(spinnerDiv);
                    body.appendChild(spinningDiv);
                    var xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                      entered = !1;
                      footer.style.display = "none";
                      if (this.readyState == 4 && this.status == 200) {
                        shouldDisableTakeAction = !1;
                        cb_session = JSON.parse(this.response).cb_session;
                        live_chat_cb_session = JSON.parse(
                          this.response
                        ).livechat_session;
                        if (
                          JSON.parse(this.response).language_code &&
                          JSON.parse(this.response).language_code.length > 0 &&
                          JSON.parse(this.response).language_code != "default"
                        ) {
                          main_lang_code = JSON.parse(this.response).language_code;
                        }
                        session_feedback = JSON.parse(this.response).feedback;
                        question_array = JSON.parse(this.response).next_question;
                        if (question_array && question_array.length > 0) {
                          question_completed = !1;
                          input.value = "";
                          setTimeout(function () {
                            enter.style.pointerEvents = "auto";
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            current_question_type = question_array[0].type;
                            current_logical_jump = question_array[0].logical_jump;
                            currentMailSequence = question_array[0].sequence;
                            currentQuestionIsLead = question_array[0].send_mail;
                            question_id = question_array[0].id;
                            setAllInputs(question_array);
                            assignAllQuestionTypes(
                              current_question_type,
                              question_array
                            );
                          }, delay_time);
                        } else {
                          if (spinningDiv && spinningDiv.parentNode == body) {
                            body.removeChild(spinningDiv);
                          }
                          enter.style.pointerEvents = "auto";
                          question_completed = !0;
                          if (!mailSent || mailSent) {
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function () {
                              if (this.readyState == 4 && this.status == 200) {
                                var questionArray = [];
                                prev_questions_array = JSON.parse(
                                  this.response
                                ).qna_prev;
                                if (
                                  prev_questions_array &&
                                  prev_questions_array.length > 0
                                ) {
                                  for (
                                    var i = 0;
                                    i < prev_questions_array.length;
                                    i++
                                  ) {
                                    if (
                                      prev_questions_array[i].type == "contact" ||
                                      prev_questions_array[i].type == "slides" ||
                                      prev_questions_array[i].type == "statement" ||
                                      prev_questions_array[i].type ==
                                      "url_auto_redirect" ||
                                      prev_questions_array[i].type ==
                                      "custom_answer" ||
                                      prev_questions_array[i].type == "show_file" ||
                                      prev_questions_array[i].type ==
                                      "show_contacts" ||
                                      prev_questions_array[i].type ==
                                      "show_location"
                                    ) {
                                      prev_questions_array.splice(i, 1);
                                      i--;
                                    }
                                  }
                                  if (zapier_webhook && zapier_webhook.length > 0) {
                                    var output = {};
                                    output.timestamp = new Date();
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      var str =
                                        prev_questions_array[i].question_text;
                                      output[str] =
                                        prev_questions_array[i].answer_text;
                                    }
                                    var xhttp = new XMLHttpRequest();
                                    xhttp.onreadystatechange = function () {
                                      if (
                                        this.readyState == 4 &&
                                        this.status == 200
                                      ) {
                                      }
                                    };
                                    xhttp.open("POST", zapier_webhook, !0);
                                    xhttp.setRequestHeader(
                                      "Content-type",
                                      "application/x-www-form-urlencoded"
                                    );
                                    xhttp.send("output=" + JSON.stringify(output));
                                  }
                                  for (
                                    var i = 0;
                                    i < prev_questions_array.length;
                                    i++
                                  ) {
                                    questionArray.push({
                                      question:
                                        prev_questions_array[i].question_text,
                                      answer: prev_questions_array[i].answer_text,
                                    });
                                  }
                                }
                              }
                            };
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            var bot_widget_obj;
                            var is_sendable;
                            try {
                              checkSaveMAxUserLogin();
                              checkRateGainDetails();
                            } catch (error) { }
                            if (window.botWidget && window.botWidget.user) {
                              var keys = Object.keys(window.botWidget.user);
                              for (var t = 0; t < keys.length; t++) {
                                if (
                                  window.botWidget.user[keys[t]] &&
                                  window.botWidget.user[keys[t]].length > 0
                                ) {
                                  is_sendable = true;
                                }
                              }
                              if (is_sendable) {
                                bot_widget_obj = window.botWidget.user;
                              } else {
                                bot_widget_obj = "";
                              }
                              if (window.botWidget.user.bot_id) {
                                delete window.botWidget.user.bot_id;
                              }
                              if (window.botWidget.user.url) {
                                delete window.botWidget.user.url;
                              }
                            }
                            xhttp.send(
                              "action=init_chat&device_print=" +
                              device_print +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&language_code=" +
                              main_lang_code +
                              "&bot_widget_obj=" +
                              JSON.stringify(bot_widget_obj)
                            );
                          } else {
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function () {
                              if (this.readyState == 4 && this.status == 200) {
                                var questionArray = [];
                                prev_questions_array = JSON.parse(
                                  this.response
                                ).qna_prev;
                                if (
                                  prev_questions_array &&
                                  prev_questions_array.length > 0
                                ) {
                                  for (
                                    var i = 0;
                                    i < prev_questions_array.length;
                                    i++
                                  ) {
                                    if (
                                      prev_questions_array[i].type == "contact" ||
                                      prev_questions_array[i].type == "slides" ||
                                      prev_questions_array[i].type == "statement" ||
                                      prev_questions_array[i].type ==
                                      "url_auto_redirect" ||
                                      prev_questions_array[i].type ==
                                      "custom_answer" ||
                                      prev_questions_array[i].type == "show_file" ||
                                      prev_questions_array[i].type ==
                                      "show_contacts" ||
                                      prev_questions_array[i].type ==
                                      "show_location"
                                    ) {
                                      prev_questions_array.splice(i, 1);
                                      i--;
                                    }
                                  }
                                  for (
                                    var i = 0;
                                    i < prev_questions_array.length;
                                    i++
                                  ) {
                                    questionArray.push({
                                      question:
                                        prev_questions_array[i].question_text,
                                      answer: prev_questions_array[i].answer_text,
                                    });
                                  }
                                }
                              }
                            };
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            var bot_widget_obj;
                            var is_sendable;
                            try {
                              checkSaveMAxUserLogin();
                              checkRateGainDetails();
                            } catch (error) { }
                            if (window.botWidget && window.botWidget.user) {
                              var keys = Object.keys(window.botWidget.user);
                              for (var t = 0; t < keys.length; t++) {
                                if (
                                  window.botWidget.user[keys[t]] &&
                                  window.botWidget.user[keys[t]].length > 0
                                ) {
                                  is_sendable = true;
                                }
                              }
                              if (is_sendable) {
                                bot_widget_obj = window.botWidget.user;
                              } else {
                                bot_widget_obj = "";
                              }
                              if (window.botWidget.user.bot_id) {
                                delete window.botWidget.user.bot_id;
                              }
                              if (window.botWidget.user.url) {
                                delete window.botWidget.user.url;
                              }
                            }
                            xhttp.send(
                              "action=init_chat&device_print=" +
                              device_print +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&language_code=" +
                              main_lang_code +
                              "&bot_widget_obj=" +
                              JSON.stringify(bot_widget_obj)
                            );
                          }
                          if (!entry_id) {
                            showInput = !0;
                            if (!shouldShowMenu) {
                              footer.style.display = "none";
                              footer.classList.add("close");
                            } else {
                              if (entry_id) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                                setPlaceHolders();
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              } else {
                                input.style.pointerEvents = "none";
                                microphone.style.pointerEvents = "none";
                                microphone.style.opacity = 0;
                                enter.style.pointerEvents = "none";
                                input.blur();
                                input.placeholder = "Choose from Menu";
                              }
                            }
                          }
                          if (!shouldShowMenu) {
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 168px)";
                            } else {
                              body.style.height = "calc(100% - 93px)";
                            }
                          } else {
                            input.blur();
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          }
                        }
                      }
                    };
                    xhttp.open(
                      "POST",
                      main_url + "/kya_backend/pagehub/chatbot_utils?action=menu_jump_question",
                      !0
                    );
                    xhttp.setRequestHeader(
                      "Content-type",
                      "application/x-www-form-urlencoded"
                    );
                    if (
                      main_lang_code &&
                      main_lang_code.length > 0 &&
                      main_lang_code != language_code
                    ) {
                    } else {
                      main_lang_code = "default";
                    }
                    xhttp.send(
                      "action=menu_jump_question&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      out_of_office_jump +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&language_code=" +
                      main_lang_code
                    );
                  }
                }
              });
              sock.on("admintyping", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  var otherSpinningDIv = document.createElement("DIV");
                  otherSpinningDIv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    otherSpinningDIv.classList.add("top-0");
                  }, transition_time);
                  otherSpinningDIv.id = "admin-typing-div";
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                  if (data.agent_avatar && data.agent_avatar.length > 0) {
                    error_icon.src = data.agent_avatar;
                  } else {
                    error_icon.src = avatar_icon;
                  }
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(error_icon);
                  iconDiv.classList.add("question-icon-div");
                  error_icon.classList.add("question-icon-smatest");
                  otherSpinningDIv.appendChild(iconDiv);
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  otherSpinningDIv.classList.add("m-t-5");
                  otherSpinningDIv.classList.add("pull-left");
                  otherSpinningDIv.appendChild(spinnerDiv);
                  var checking_div = document.getElementById("admin-typing-div");
                  if (body.contains(checking_div)) {
                  } else {
                    body.appendChild(otherSpinningDIv);
                    body.scrollTop = body.scrollHeight;
                  }
                }
              });
              sock.on("admintypingstopped", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  var agentTypingDiv = document.getElementById("admin-typing-div");
                  if (agentTypingDiv && agentTypingDiv.parentElement) {
                    agentTypingDiv.parentElement.removeChild(agentTypingDiv);
                  }
                }
              });
              sock.on("closesessionfromadmin", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  alreadySockLoaded = undefined;
                  liveSessionSet = false;
                  try {
                    sock.disconnect();
                  } catch (error) { }
                  var agent_left_div = document.createElement("DIV");
                  agent_left_div.classList.add("pull-left");
                  agent_left_div.classList.add("full-width");
                  agent_left_div.classList.add("m-t-10");
                  agent_left_div.classList.add("m-b-10");
                  agent_left_div.id = "marked-it-closed";
                  var agent_left_label = document.createElement("LABEL");
                  agent_left_label.classList.add("text-line-combo");
                  agent_left_label.style.border = 'none';
                  agent_left_label.style.margin = '0';
                  agent_left_label.style.lineHeight = 'normal';
                  agent_left_label.style.width = 'fit-content';
                  var agent_left_span = document.createElement("SPAN");
                  agent_left_span.style.display = 'flex';
                  agent_left_span.style.alignItems = 'center';
                  agent_left_span.style.justifyContent = 'center';
                  agent_left_span.style.gap = '4px';
                  var string;
                  if (data.agent_name && data.agent_name.length > 0) {
                    let agent_name_uppercase = data.agent_name.charAt(0).toUpperCase() + data.agent_name.slice(1);
                    string = ` <img style='width: 12px;height: 12px;' src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/checkicon_widget_new.svg" alt="checkicon" />
                     <h5 style='font-weight:bold;font-size: 14px; margin: 0;'>${agent_name_uppercase} </h5>`  + " As Closed The Chat";
                  } else {
                    string = "agent has closed the chat";
                  }
                  agent_left_span.innerHTML = string;
                  agent_left_label.appendChild(agent_left_span);
                  agent_left_div.appendChild(agent_left_label);
                  body.appendChild(agent_left_div);
                  body.scrollTop = body.scrollHeight;
                  footer.style.display = "none";
                  footer.classList.add("close");
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 168px)";
                  } else {
                    body.style.height = "calc(100% - 93px)";
                  }

                  // sock.emit('messageack', {
                  //   event_name: 'closesessionfromadmin',
                  //   eventData:  data
                  // });

                }
              });
              sock.on("markresolved", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  var agent_left_div = document.createElement("DIV");
                  agent_left_div.classList.add("pull-left");
                  agent_left_div.classList.add("full-width");
                  agent_left_div.classList.add("m-t-10");
                  agent_left_div.classList.add("m-b-10");
                  agent_left_div.id = "marked-it-resolved";
                  var agent_left_label = document.createElement("LABEL");
                  agent_left_label.classList.add("text-line-combo");
                  agent_left_label.style.border = 'none';
                  agent_left_label.style.margin = '0';
                  agent_left_label.style.lineHeight = 'normal';
                  agent_left_label.style.width = 'fit-content';
                  var agent_left_span = document.createElement("SPAN");
                  agent_left_span.style.display = 'flex';
                  agent_left_span.style.alignItems = 'center';
                  agent_left_span.style.justifyContent = 'center';
                  agent_left_span.style.gap = '4px';
                  var string;
                  if (data.agent_name && data.agent_name.length > 0) {
                    var agent_name;
                    if (data.agent_name.length > 10) {
                      agent_name = data.agent_name.substring(0, 10) + "...";
                    } else {
                      agent_name = data.agent_name;
                    }
                    let agent_name_uppercase = agent_name.charAt(0).toUpperCase() + agent_name.slice(1);
                    string = ` <img style='width: 12px;height: 12px;' src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/checkicon_widget_new.svg" alt="checkicon" />
                     <h5 style='font-weight:bold;font-size: 14px; margin: 0;'>${agent_name_uppercase} </h5>`  + " Marked It Resolved";
                  } else {
                    string = "Agent Marked It Resolved";
                  }
                  agent_left_span.innerHTML = string;
                  agent_left_label.appendChild(agent_left_span);
                  agent_left_div.appendChild(agent_left_label);
                  var elem = document.getElementById("marked-it-resolved");
                  if (body.contains(elem)) {
                  } else {
                    body.appendChild(agent_left_div);
                    body.scrollTop = body.scrollHeight;
                  }
                  footer.style.display = "none";
                  footer.classList.add("close");
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 168px)";
                  } else {
                    body.style.height = "calc(100% - 93px)";
                  }

                  // sock.emit('messageack', {
                  //   event_name: 'markresolved',
                  //   eventData:  data
                  // });

                }
              });
              sock.on("requestfeedback", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  addLiveChatFeedback();
                }
              });
              sock.on("banip", function (data) {
                if (chatbot_id == data.bot_id) {
                  if (ip_address == data.ip_address) {
                    ip_is_banned = true;
                    banned_reason = data.reason;
                  }
                }
              });
              sock.on("unbanip", function (data) {
                if (chatbot_id == data.bot_id) {
                  if (ip_address == data.ip_address) {
                    ip_is_banned = false;
                    banned_reason = "";
                    var checking_div = document.getElementById("user-banned-div");
                    if (body.contains(checking_div)) {
                      body.removeChild(checking_div);
                    }
                  }
                }
              });
              sock.on("agentseenmessage", function (data) {
                if (
                  live_chat_cb_session == data.session_id &&
                  data.channel == "website"
                ) {
                  var agent_left_div = document.createElement("DIV");
                  var d = new Date();
                  agent_left_div.id = "agent-seen-" + d.getTime();
                  agent_left_div.classList.add("pull-left");
                  agent_left_div.classList.add("full-width");
                  var agent_left_label = document.createElement("LABEL");
                  agent_left_label.classList.add("pull-left");
                  agent_left_label.classList.add("full-width");
                  agent_left_label.style.fontSize = "10px";
                  agent_left_label.style.textAlign = "right";
                  agent_left_label.innerHTML =
                    '<img src="https://custpostimages.s3.ap-south-1.amazonaws.com/ss_images/double-tick-indicator.png" style="height:16px;margin-right:5px;margin-left:auto;max-width:100%;width:fit-content;">'
                  agent_left_div.appendChild(agent_left_label);
                  var last_child = body.lastChild;
                  if (
                    last_child &&
                    last_child.id &&
                    (last_child.id.includes("agent-seen-") || last_child.id.includes("admin-typing-"))
                  ) {
                  } else {
                    body.appendChild(agent_left_div);
                    body.scrollTop = body.scrollHeight;
                  }
                }
              });
              sock.on("video-declined", function (data) {
                if (
                  data.bot_id == chatbot_id &&
                  data.session_id == live_chat_cb_session
                ) {
                  var div = document.getElementById("video-container-div");
                  if (body.contains(div)) {
                    body.removeChild(div);
                    var agent_left_div = document.createElement("DIV");
                    agent_left_div.classList.add("pull-left");
                    agent_left_div.classList.add("full-width");
                    agent_left_div.classList.add("m-t-10");
                    agent_left_div.classList.add("m-b-10");
                    var agent_left_label = document.createElement("LABEL");
                    agent_left_label.classList.add("text-line-combo");
                    var agent_left_span = document.createElement("SPAN");
                    var string;
                    if (data.agent_name && data.agent_name.length > 0) {
                      string = data.agent_name + " declined";
                    } else {
                      string = "agent declined";
                    }
                    agent_left_span.innerHTML = string;
                    agent_left_label.appendChild(agent_left_span);
                    agent_left_div.appendChild(agent_left_label);
                    body.appendChild(agent_left_div);
                    body.scrollTop = body.scrollHeight;
                    footer.style.display = "none";
                    footer.classList.add("close");
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                  }
                }
              });
              sock.on("start-screen-share", function (data) {
                if (
                  data.bot_id == chatbot_id &&
                  data.session_id == live_chat_cb_session
                ) {
                  screen_share_from_agent = data.screen_share_object;
                  body.scrollTop = body.scrollHeight;
                }
              });
              sock.on("stop-screen-share", function (data) {
                if (
                  data.bot_id == chatbot_id &&
                  data.session_id == live_chat_cb_session
                ) {
                  screen_share_from_agent = undefined;
                  body.scrollTop = body.scrollHeight;
                  var remote_div = document.getElementById("remote-media");
                  remote_div.removeChild(remote_div.lastChild);
                }
              });
              sock.on("video-disconnect", function (data) {
                if (
                  data.bot_id == chatbot_id &&
                  data.session_id == live_chat_cb_session
                ) {
                  video_call_room.disconnect();
                  video_call_icon_div.style.pointerEvents = "auto";
                  var localMedia = document.getElementById("local-media");
                  if (localMedia) {
                    localMedia.innerHTML = "";
                  }
                  var remoteMedia = document.getElementById("remote-media");
                  if (remoteMedia) {
                    remoteMedia.innerHTML = "";
                  }
                  var video_container = document.getElementById(
                    "video-container-div"
                  );
                  if (body.contains(video_container)) {
                    video_container.innerHTML = "";
                    body.removeChild(video_container);
                  }
                }
              });
              sock.on("disconnect", function (data) {
                const agentJoiningDiv = document.getElementById("agent-joining-div");
                if(agentJoiningDiv) {
                  displayReconnectPopup()
                }
                // sock.emit('setausersession', {
                //   session_id: live_chat_cb_session,
                // });
              });
              sock.on("error", function (data) {
                // sock.emit('setausersession', {
                //   session_id: live_chat_cb_session,
                // });
              });
              sock.on("reconnect", function (data) {
                // sock.emit('setausersession', {
                //   session_id: live_chat_cb_session,
                // });
              });
              alreadySockLoaded = true;
            }
            if (!liveSessionSet) {
              var d = new Date();
              var date = d.getDate();
              if (date < 10) {
                date = "0" + date;
              }
              var month = d.getMonth() + 1;
              if (month < 10) {
                month = "0" + month;
              }
              var hours = d.getHours();
              if (hours < 10) {
                hours = "0" + hours;
              }
              var mins = d.getMinutes();
              if (mins < 10) {
                mins = "0" + mins;
              }
              var seconds = d.getSeconds();
              if (seconds < 10) {
                seconds = "0" + seconds;
              }
              d =
                date +
                "/" +
                month +
                "/" +
                d.getFullYear() +
                ", " +
                hours +
                ":" +
                mins +
                ":" +
                seconds;
              var user_location_string;
              if (user_location_enc && user_location_enc.length > 0) {
                user_location_string = user_location_enc;
              } else {
                if (user_location_array && user_location_array.length > 0) {
                  user_location_string = user_location_array.join();
                }
              }
              var user_src = window.location.href;
              var main_notes;
              var notes = {};
              if (JSON.stringify(notes) && JSON.stringify(notes) == "{}") {
                main_notes = "";
              } else {
                main_notes = JSON.stringify(notes);
              }
              if (alreadySockLoaded) {
                sock.emit("joinbotroom", {
                  session_id: live_chat_cb_session,
                });
              } else {
                sock.on("connect", function () {
                  sock.emit("joinbotroom", {
                    session_id: live_chat_cb_session,
                  });
                });
              }
              var dept_value = "";
              if (json && json.is_custom_dept) {
                if (department_settings && department_settings.length > 0) {
                  for (var n = 0; n < department_settings.length; n++) {
                    if (question_and_answers && question_and_answers.length > 0) {
                      for (var p = 0; p < question_and_answers.length; p++) {
                        if (
                          department_settings[n].question_id ==
                          question_and_answers[p].id &&
                          question_and_answers[p].answer ==
                          department_settings[n].option_value
                        ) {
                          dept_value = department_settings[n].department_id;
                        }
                      }
                    }
                  }
                }
              } else {
                if (json && json.single_dept) {
                  dept_value = json.single_dept;
                }
              }
              sock.emit("setsession", {
                session_id: live_chat_cb_session,
                device_print: device_print,
                bot_id: chatbot_id,
                time: d,
                ip_address: live_chat_ip_address,
                user_location: live_chat_location,
                user_url: user_src,
                channel: "website",
                bot_name: totalData[0].name,
                notes: main_notes,
                department_id: dept_value,
              });
              liveSessionSet = true;
              start_live_chat_timer = true;
            }
            if (
              question_array[0].question_text &&
              question_array[0].question_text.includes("{{") &&
              question_array[0].question_text.includes("}}")
            ) {
              parseDataReferring(question_array, 0);
            }
            var arr = getParagraphs(question_array[0].question_text);
            var x_arr = arr;
            array = [];
            for (var i = 0; i < x_arr.length; i++) {
              if (x_arr[i]) {
                if (
                  (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                  (x_arr[i].children && x_arr[i].children.length > 0)
                ) {
                  array.push(x_arr[i].outerHTML);
                } else {
                  x_arr.splice(i, 1);
                  i--;
                }
              }
            }
            var question_arr = [];
            if (array && array.length > 0) {
              question_arr = array;
            } else {
              question_arr.push(question_array[0].question_text);
            }
            if (question_arr && question_arr.length > 0) {
              var j = 0;

              function addQuestionArrays() {
                if (j < question_arr.length) {
                  var questionDIv = document.createElement("DIV");
                  questionDIv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    questionDIv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    questionDIv.classList.add(font);
                  }
                  var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon1);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon1.src = avatar_icon;
                  ques_icon1.classList.add("question-icon-smatest");
                  var option_div = document.createElement("DIV");
                  option_div.classList.add("options-div-smatest");
                  var option_question = document.createElement("LABEL");
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == "he" ||
                        main_lang_code == "ur" ||
                        main_lang_code == "ar")) ||
                    (main_lang_code == "default" &&
                      (language_code == "ar" ||
                        language_code == "he" ||
                        language_code == "ur"))
                  ) {
                    option_question.classList.add("rtl");
                  }
                  var emoji_arr = question_arr[j].match(/[a-f0-9]{5}/gi);
                  if (emoji_arr && emoji_arr.length > 0) {
                    for (var i = 0; i < emoji_arr.length; i++) {
                      question_arr[j] = question_arr[j].replace(
                        "0x" + emoji_arr[i],
                        String.fromCodePoint("0x" + emoji_arr[i])
                      );
                    }
                  }
                  option_question.innerHTML = question_arr[j].trim();
                  if (j == 0) {
                    say(option_question.innerText);
                  } else {
                    setTimeout(function () {
                      say(option_question.innerText);
                    }, 1000);
                  }
                  option_div.appendChild(option_question);
                  if (j != question_arr.length - 1) {
                    option_div.classList.add("m-l-40");
                  }
                  if (j == question_arr.length - 1) {
                    questionDIv.appendChild(iconDiv);
                    handleImageModal(question_array, option_div);
                    footer.style.display = "block";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.classList.remove("close");
                    if (!shouldShowMenu) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                    }
                    input.focus();
                    input.type = "text";
                    input.placeholder = "Talk to our live agent";
                    input.addEventListener("keyup", function (e) {
                      if (e.keyCode != 13) {
                        if (!typingMessageSent) {
                          sock.emit("usertyping", {
                            session_id: live_chat_cb_session,
                            device_print: device_print,
                            bot_id: chatbot_id,
                            channel: "webiste",
                            agent_id: agent_id,
                          });
                          typingMessageSent = true;
                        }
                      }
                    });
                    // input.addEventListener("input", function (e) {
                    //   if (input.value.length > 495) {
                    //     input.value = input.value.substring(0, 495);
                    //   }
                    // });
                    input.addEventListener("focusout", function (e) {
                      if (typingMessageSent) {
                        sock.emit("usertypingstopped", {
                          session_id: live_chat_cb_session,
                          device_print: device_print,
                          bot_id: chatbot_id,
                          channel: "webiste",
                          agent_id: agent_id,
                        });
                        typingMessageSent = false;
                      }
                    });
                    try {
                      input.blur();
                      input.style.pointerEvents = "none";
                      attach_label.style.pointerEvents = "none";
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      enter.style.pointerEvents = "none";
                    } catch (error) { }
                  }
                  questionDIv.appendChild(option_div);
                  var otherSpinningDIv = document.createElement("DIV");
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  otherSpinningDIv.classList.add("m-l-40");
                  otherSpinningDIv.classList.add("m-t-5");
                  otherSpinningDIv.classList.add("pull-left");
                  otherSpinningDIv.appendChild(spinnerDiv);
                  if (j != 0) {
                    body.appendChild(otherSpinningDIv);
                  }
                  if (j == 0) {
                    j++;
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  } else {
                    setTimeout(function () {
                      if (body.contains(otherSpinningDIv)) {
                        body.removeChild(otherSpinningDIv);
                      }
                      j++;
                      questionDIv.classList.add("m-t-5");
                      body.appendChild(questionDIv);
                      addQuestionArrays();
                    }, delay_time);
                  }
                }
              }
              addQuestionArrays();
            }
            setTimeout(function () {
              if (body.scrollHeight > 320) {
                body.scrollTop = body.scrollTop + body.offsetHeight + 30;
              } else {
                body.scrollTop = body.scrollHeight;
              }
            }, 100);
          } else {
            var livechatEncourageDiv = document.createElement("DIV");
            livechatEncourageDiv.id = "user-banned-div";
            livechatEncourageDiv.classList.add("question-div-smatest");
            setTimeout(function () {
              livechatEncourageDiv.classList.add("top-0");
            }, transition_time);
            if (font && font.length > 0) {
              livechatEncourageDiv.classList.add(font);
            }
            var live_chat_encourage_icon = document.createElement("IMG");
            live_chat_encourage_icon.alt = "Logo of " + totalData[0].name;
            live_chat_encourage_icon.src = avatar_icon;
            var iconDiv = document.createElement("DIV");
            iconDiv.appendChild(live_chat_encourage_icon);
            iconDiv.classList.add("question-icon-div");
            live_chat_encourage_icon.classList.add("question-icon-smatest");
            var live_chat_encourage_text = document.createElement("LABEL");
            if (ip_is_banned && banned_reason && banned_reason.length > 0) {
              live_chat_encourage_text.innerHTML =
                '<label style="float:left;width:100%;margin-bottom:">You have been banned from interacting with our live agents</label><label style="float:left;width:100%">Reason : ' +
                banned_reason +
                "</label>";
            } else {
              if (
                json.out_of_office_message &&
                json.out_of_office_message.length > 0
              ) {
                live_chat_encourage_text.innerHTML = json.out_of_office_message;
              } else {
                live_chat_encourage_text.innerHTML =
                  "Sorry, All our agents are offline now. Contact us after some time";
              }
            }
            say(live_chat_encourage_text.innerText);
            live_chat_encourage_text.classList.add("question-text-error");
            live_chat_encourage_text.classList.add("options-div-smatest");
            if (font && font.length > 0) {
              live_chat_encourage_text.classList.add(font);
            }
            livechatEncourageDiv.appendChild(iconDiv);
            livechatEncourageDiv.appendChild(live_chat_encourage_text);
            var checking_div = document.getElementById("user-banned-div");
            if (body.contains(checking_div)) {
              body.appendChild(checking_div);
            } else {
              body.appendChild(livechatEncourageDiv);
            }
            playBotUserSound(1);
            body.scrollTop = body.scrollHeight;
            if (
              json &&
              json.out_of_office_jump &&
              json.out_of_office_jump.length > 0
            ) {
              out_of_office_jump = json.out_of_office_jump;
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              menu_options_div.classList.add("close");
              if (!shouldShowMenu) {
                footer.style.display = "none";
                footer.classList.add("close");
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
              } else {
                if (entry_id) {
                  input.style.pointerEvents = "auto";
                  microphone.style.pointerEvents = "auto";
                  microphone.style.opacity = 1;
                  enter.style.pointerEvents = "auto";
                  setPlaceHolders();
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                } else {
                  input.style.pointerEvents = "none";
                  microphone.style.pointerEvents = "none";
                  microphone.style.opacity = 0;
                  enter.style.pointerEvents = "none";
                  input.blur();
                  input.placeholder = "Choose from Menu";
                  input.type = "text";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                }
              }
              var spinningDiv = document.createElement("DIV");
              spinningDiv.classList.add("question-div-smatest");
              spinningDiv.classList.add("top-0");
              if (font && font.length > 0) {
                spinningDiv.classList.add(font);
              }
              var spinnerDiv = document.createElement("DIV");
              spinnerDiv.classList.add("spinner1-smatest");
              var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
              var iconDiv = document.createElement("DIV");
              iconDiv.appendChild(ques_icon);
              iconDiv.classList.add("question-icon-div");
              ques_icon.src = avatar_icon;
              ques_icon.classList.add("question-icon-smatest");
              var inner1 = document.createElement("DIV");
              inner1.classList.add("bounce1");
              var inner2 = document.createElement("DIV");
              inner2.classList.add("bounce2");
              var inner3 = document.createElement("DIV");
              inner3.classList.add("bounce3");
              spinnerDiv.appendChild(inner1);
              spinnerDiv.appendChild(inner2);
              spinnerDiv.appendChild(inner3);
              spinningDiv.appendChild(iconDiv);
              spinningDiv.appendChild(spinnerDiv);
              body.appendChild(spinningDiv);
              var xhttp = new XMLHttpRequest();
              xhttp.onreadystatechange = function () {
                entered = !1;
                footer.style.display = "none";
                if (this.readyState == 4 && this.status == 200) {
                  shouldDisableTakeAction = !1;
                  cb_session = JSON.parse(this.response).cb_session;
                  live_chat_cb_session = JSON.parse(this.response).livechat_session;
                  if (
                    JSON.parse(this.response).language_code &&
                    JSON.parse(this.response).language_code.length > 0 &&
                    JSON.parse(this.response).language_code != "default"
                  ) {
                    main_lang_code = JSON.parse(this.response).language_code;
                  }
                  session_feedback = JSON.parse(this.response).feedback;
                  question_array = JSON.parse(this.response).next_question;
                  if (question_array && question_array.length > 0) {
                    question_completed = !1;
                    input.value = "";
                    setTimeout(function () {
                      enter.style.pointerEvents = "auto";
                      if (spinningDiv && spinningDiv.parentNode == body) {
                        body.removeChild(spinningDiv);
                      }
                      current_question_type = question_array[0].type;
                      current_logical_jump = question_array[0].logical_jump;
                      currentMailSequence = question_array[0].sequence;
                      currentQuestionIsLead = question_array[0].send_mail;
                      question_id = question_array[0].id;
                      setAllInputs(question_array);
                      assignAllQuestionTypes(current_question_type, question_array);
                    }, delay_time);
                  } else {
                    if (spinningDiv && spinningDiv.parentNode == body) {
                      body.removeChild(spinningDiv);
                    }
                    enter.style.pointerEvents = "auto";
                    question_completed = !0;
                    if (!mailSent || mailSent) {
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        if (this.readyState == 4 && this.status == 200) {
                          var questionArray = [];
                          prev_questions_array = JSON.parse(this.response).qna_prev;
                          if (
                            prev_questions_array &&
                            prev_questions_array.length > 0
                          ) {
                            for (var i = 0; i < prev_questions_array.length; i++) {
                              if (
                                prev_questions_array[i].type == "contact" ||
                                prev_questions_array[i].type == "slides" ||
                                prev_questions_array[i].type == "statement" ||
                                prev_questions_array[i].type ==
                                "url_auto_redirect" ||
                                prev_questions_array[i].type == "custom_answer" ||
                                prev_questions_array[i].type == "show_file" ||
                                prev_questions_array[i].type == "show_contacts" ||
                                prev_questions_array[i].type == "show_location"
                              ) {
                                prev_questions_array.splice(i, 1);
                                i--;
                              }
                            }
                            if (zapier_webhook && zapier_webhook.length > 0) {
                              var output = {};
                              output.timestamp = new Date();
                              for (
                                var i = 0;
                                i < prev_questions_array.length;
                                i++
                              ) {
                                var str = prev_questions_array[i].question_text;
                                output[str] = prev_questions_array[i].answer_text;
                              }
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                }
                              };
                              xhttp.open("POST", zapier_webhook, !0);
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              xhttp.send("output=" + JSON.stringify(output));
                            }
                            for (var i = 0; i < prev_questions_array.length; i++) {
                              questionArray.push({
                                question: prev_questions_array[i].question_text,
                                answer: prev_questions_array[i].answer_text,
                              });
                            }
                          }
                        }
                      };
                      xhttp.open(
                        "POST",
                        main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                        !0
                      );
                      xhttp.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0 &&
                        main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      var bot_widget_obj;
                      var is_sendable;
                      try {
                        checkSaveMAxUserLogin();
                        checkRateGainDetails();
                      } catch (error) { }
                      if (window.botWidget && window.botWidget.user) {
                        var keys = Object.keys(window.botWidget.user);
                        for (var t = 0; t < keys.length; t++) {
                          if (
                            window.botWidget.user[keys[t]] &&
                            window.botWidget.user[keys[t]].length > 0
                          ) {
                            is_sendable = true;
                          }
                        }
                        if (is_sendable) {
                          bot_widget_obj = window.botWidget.user;
                        } else {
                          bot_widget_obj = "";
                        }
                        if (window.botWidget.user.bot_id) {
                          delete window.botWidget.user.bot_id;
                        }
                        if (window.botWidget.user.url) {
                          delete window.botWidget.user.url;
                        }
                      }
                      xhttp.send(
                        "action=init_chat&device_print=" +
                        device_print +
                        "&chatbot_id=" +
                        chatbot_id +
                        "&language_code=" +
                        main_lang_code +
                        "&bot_widget_obj=" +
                        JSON.stringify(bot_widget_obj)
                      );
                    } else {
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        if (this.readyState == 4 && this.status == 200) {
                          var questionArray = [];
                          prev_questions_array = JSON.parse(this.response).qna_prev;
                          if (
                            prev_questions_array &&
                            prev_questions_array.length > 0
                          ) {
                            for (var i = 0; i < prev_questions_array.length; i++) {
                              if (
                                prev_questions_array[i].type == "contact" ||
                                prev_questions_array[i].type == "slides" ||
                                prev_questions_array[i].type == "statement" ||
                                prev_questions_array[i].type ==
                                "url_auto_redirect" ||
                                prev_questions_array[i].type == "custom_answer" ||
                                prev_questions_array[i].type == "show_file" ||
                                prev_questions_array[i].type == "show_contacts" ||
                                prev_questions_array[i].type == "show_location"
                              ) {
                                prev_questions_array.splice(i, 1);
                                i--;
                              }
                            }
                            for (var i = 0; i < prev_questions_array.length; i++) {
                              questionArray.push({
                                question: prev_questions_array[i].question_text,
                                answer: prev_questions_array[i].answer_text,
                              });
                            }
                          }
                        }
                      };
                      xhttp.open(
                        "POST",
                        main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                        !0
                      );
                      xhttp.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0 &&
                        main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      var bot_widget_obj;
                      var is_sendable;
                      try {
                        checkSaveMAxUserLogin();
                        checkRateGainDetails();
                      } catch (error) { }
                      if (window.botWidget && window.botWidget.user) {
                        var keys = Object.keys(window.botWidget.user);
                        for (var t = 0; t < keys.length; t++) {
                          if (
                            window.botWidget.user[keys[t]] &&
                            window.botWidget.user[keys[t]].length > 0
                          ) {
                            is_sendable = true;
                          }
                        }
                        if (is_sendable) {
                          bot_widget_obj = window.botWidget.user;
                        } else {
                          bot_widget_obj = "";
                        }
                        if (window.botWidget.user.bot_id) {
                          delete window.botWidget.user.bot_id;
                        }
                        if (window.botWidget.user.url) {
                          delete window.botWidget.user.url;
                        }
                      }
                      xhttp.send(
                        "action=init_chat&device_print=" +
                        device_print +
                        "&chatbot_id=" +
                        chatbot_id +
                        "&language_code=" +
                        main_lang_code +
                        "&bot_widget_obj=" +
                        JSON.stringify(bot_widget_obj)
                      );
                    }
                    if (!entry_id) {
                      showInput = !0;
                      if (!shouldShowMenu) {
                        footer.style.display = "none";
                        footer.classList.add("close");
                      } else {
                        if (entry_id) {
                          input.style.pointerEvents = "auto";
                          microphone.style.pointerEvents = "auto";
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = "auto";
                          setPlaceHolders();
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 226px)";
                          } else {
                            body.style.height = "calc(100% - 150px)";
                          }
                        } else {
                          input.style.pointerEvents = "none";
                          microphone.style.pointerEvents = "none";
                          microphone.style.opacity = 0;
                          enter.style.pointerEvents = "none";
                          input.blur();
                          input.placeholder = "Choose from Menu";
                        }
                      }
                    }
                    if (!shouldShowMenu) {
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 168px)";
                      } else {
                        body.style.height = "calc(100% - 93px)";
                      }
                    } else {
                      input.blur();
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    }
                  }
                }
              };
              xhttp.open(
                "POST",
                main_url + "/kya_backend/pagehub/chatbot_utils?action=menu_jump_question",
                !0
              );
              xhttp.setRequestHeader(
                "Content-type",
                "application/x-www-form-urlencoded"
              );
              if (
                main_lang_code &&
                main_lang_code.length > 0 &&
                main_lang_code != language_code
              ) {
              } else {
                main_lang_code = "default";
              }
              xhttp.send(
                "action=menu_jump_question&cb_session=" +
                cb_session +
                "&question_id=" +
                json.out_of_office_jump +
                "&chatbot_id=" +
                chatbot_id +
                "&language_code=" +
                main_lang_code
              );
            } else {
              if (!shouldShowMenu) {
                footer.style.display = "none";
                footer.classList.add("close");
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
              } else {
                if (entry_id) {
                  input.style.pointerEvents = "auto";
                  microphone.style.pointerEvents = "auto";
                  microphone.style.opacity = 1;
                  enter.style.pointerEvents = "auto";
                  setPlaceHolders();
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                } else {
                  input.style.pointerEvents = "none";
                  microphone.style.pointerEvents = "none";
                  microphone.style.opacity = 0;
                  enter.style.pointerEvents = "none";
                  input.blur();
                  input.placeholder = "Choose from Menu";
                  input.type = "text";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                }
              }
            }
          }
        }

        function callRealTimeSearch(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                var emoji_arr = question_arr[j].match(/[a-f0-9]{5}/gi);
                if (emoji_arr && emoji_arr.length > 0) {
                  for (var i = 0; i < emoji_arr.length; i++) {
                    question_arr[j] = question_arr[j].replace(
                      "0x" + emoji_arr[i],
                      String.fromCodePoint("0x" + emoji_arr[i])
                    );
                  }
                }
                option_question.innerHTML = question_arr[j].trim();
                say(option_question.innerText);
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, option_div);
                  footer.style.display = "block";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                  footer.classList.remove("close");
                  if (!shouldShowMenu) {
                    input.style.pointerEvents = "auto";
                    microphone.style.pointerEvents = "auto";
                    microphone.style.opacity = 1;
                    enter.style.pointerEvents = "auto";
                  }
                  input.focus();
                  input.type = "text";
                  input.placeholder = "Enter a keyword";
                  real_time_search_items = question_array[0].items_list;
                  input.addEventListener("keyup", realTimeSearch);
                  input.addEventListener("click", autocomplete);
                  setTimeout(function () {
                    // input.click();
                  }, 1);
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    if (body.contains(otherSpinningDIv)) {
                      body.removeChild(otherSpinningDIv);
                    }
                    j++;
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }
        var myEfficientFn = debounce(function () {
          orderAutocomplete(input);
        }, 1);
                    
        function callOrderItemsNew(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;
    
            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                var emoji_arr = question_arr[j].match(/[a-f0-9]{5}/gi);
                if (emoji_arr && emoji_arr.length > 0) {
                  for (var i = 0; i < emoji_arr.length; i++) {
                    question_arr[j] = question_arr[j].replace(
                      "0x" + emoji_arr[i],
                      String.fromCodePoint("0x" + emoji_arr[i])
                    );
                  }
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                      // Code start
    
                      var main_opened_div = document.getElementById('opened');
        
                      if ( main_opened_div.contains(document.getElementById('bg-shadow-overlay'))) {
                        main_opened_div.removeChild(
                          document.getElementById('bg-shadow-overlay')
                        );
                      }
    
                      var openMenuSb = document.getElementById('open-menu-sb');
                      var optionsDiv = document.getElementsByClassName('options-div-smatest');
    
                      if (openMenuSb && optionsDiv.length > 0) {
                        if (
                          optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                        ) {
                          optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                        }
                      }
    
                      var current_page = 'items';

                      var opened_div = document.getElementById('opened');
    
                      if (opened_div.contains(document.getElementById('bg-shadow-overlay'))) {
                          opened_div.removeChild(document.getElementById('bg-shadow-overlay'));
                      }
    
                      var close_icon_div = document.createElement('DIV');
                      close_icon_div.setAttribute('class', 'close-icon-div-small_sb');
    
                      var close_icon_img = document.createElement('IMG');
                      close_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small+(2).svg'
                      close_icon_img.alt ='closeicon'
                      close_icon_img.style.width ='10px';
                      close_icon_img.style.height ='10px';
    
                      var bg_shadow_orderItems = document.createElement('DIV');
                      bg_shadow_orderItems.setAttribute('id', 'bg-shadow-overlay');
    
                      var orderItems_container = document.createElement('DIV');
                      orderItems_container.setAttribute('id', 'orderItems_container');
                      orderItems_container.style.minHeight = '50%';
                      // orderItems_container.style.opacity = '1';
                      // orderItems_container.style.transform = 'translateY(0)';

                      try {
                        
                        var defaultoptions = JSON.parse(question_array[0].default_options);
                      } catch (error) {
                        
                      }

                      if (defaultoptions && defaultoptions.openMenu && defaultoptions.openMenu.length > 0) {
                        if (defaultoptions.openMenu == 'open') {
                          bg_shadow_orderItems.style.visibility = 'visible';
                          orderItems_container.style.opacity = '1';
                          orderItems_container.style.transform = 'translateY(0)';
                        }else{
                          bg_shadow_orderItems.style.visibility = 'hidden';
                          orderItems_container.style.opacity = '0.5';
                          orderItems_container.style.transform = 'translateY(100%)';
                        }
                      }else{
                        bg_shadow_orderItems.style.visibility = 'hidden';
                        orderItems_container.style.opacity = '0.5';
                        orderItems_container.style.transform = 'translateY(100%)';
                      }

                      createAppMenu(option_div, 'Select Items', bg_shadow_orderItems, orderItems_container)
                      
                      // orderItems_container.appendChild(close_icon_div);
                      close_icon_div.appendChild(close_icon_img);
    
                      var headder_main_div = document.createElement('DIV');
                      headder_main_div.classList.add('headder_main_div_sb');
    
                      var headder_main_text = document.createElement('DIV');
                      headder_main_text.innerHTML = generateTranslatedContent(translations, "Select items from the menu", main_lang_code, language_code, input);
                      headder_main_text.style.textAlign ='center';
                      headder_main_text.style.width ='90%';
                      headder_main_text.style.fontSize ='13px';
                      headder_main_text.style.fontWeight ='600';
    
                      var filter_outer_div = document.createElement('DIV');
                      filter_outer_div.classList.add('filter_outer_div');
    
                      var cart_icon_div = document.createElement('DIV');
                      cart_icon_div.style.position = 'relative';
    
                      var cart_icon = document.createElement('IMG');
                      cart_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cart-icon.svg';
                      cart_icon.alt ='CartIcon';
                      cart_icon.style.width = "20px";
                      cart_icon.style.height = "20px";
                      cart_icon.style.cursor = "pointer";
    
                      var search_bar_div = document.createElement('DIV');
                      search_bar_div.setAttribute('class', 'search_bar_div_orderItems');
    
                      var left_icon_img = document.createElement('IMG');
                      left_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg'
                      left_icon_img.alt ='lefticon'
                      left_icon_img.style.width ='15px';
                      left_icon_img.style.height ='15px';
                      left_icon_img.style.cursor ='pointer';
    
                      var search_icon = document.createElement('IMG');
                      search_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/search+(2).svg';
                      search_icon.alt ='SearchIcon';
                      search_icon.style.width = "16px";
                      search_icon.style.height = "16px";
    
                      var search_bar_Input = document.createElement('INPUT');
                      search_bar_Input.setAttribute('class', 'search_bar_input_orderItems');
                      search_bar_Input.placeholder = generateTranslatedContent(translations, "Search here for the items", main_lang_code, language_code, search_bar_Input);
    
                      var cart_total_badge = document.createElement('DIV');
                      cart_total_badge.classList.add('cart_total_badge')
                      cart_total_badge.innerHTML = '0'
    
                      if (font && font.length > 0) {
                        search_bar_Input.classList.add(font);
                        cart_total_badge.classList.add(font);
                        headder_main_text.classList.add(font);
                      }
                      var back_button_div = document.createElement('DIV');
                      back_button_div.classList.add('back_button_div')
    
                      var back_button_img = document.createElement('IMG');
                      back_button_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-left+(1).svg';
                      back_button_img.alt = 'backIcon';
                      back_button_img.style.width = "20px";
                      back_button_img.style.height = "20px";
                      back_button_img.style.cursor = "pointer";
                      back_button_div.style.display = 'none'; 
                      
                      back_button_div.addEventListener('click', function () {
                          displayAllItems();
                      });
    
                      var order_items_scroll_div = document.createElement('DIV');
                      order_items_scroll_div.setAttribute('class', 'order_items_scroll_div');
    
                      var TotalorderItemsArray = question_array[0].items_list;

                      var cart = {};
    
                      function createItemCard(item) {
                          var itemDiv = document.createElement('DIV');
                          itemDiv.classList.add('order_item_card');
    
                          var img = document.createElement('IMG');
                          img.src = item.image_url;
                          img.classList.add('order_item_image');
    
                          var itemInfo = document.createElement('DIV');
                          itemInfo.classList.add('order_item_info_details');
    
                          var itemName = document.createElement('DIV');
                          itemName.classList.add('order_item_name');
                          let name;
                          if (item.display_name.length > 30) {
                              name = item.display_name.substring(0, 30) + '...';
                          } else {
                              name = item.display_name;
                          }
                          itemName.innerHTML = name;
    
                          var itemPrice = document.createElement('DIV');
                          itemPrice.classList.add('order_item_price');
                          itemPrice.innerHTML = `${item.currency} ${Number(item.price_per_item).toFixed(2)}`;
    
                          var addButton = document.createElement('BUTTON');
                          addButton.classList.add('order_item_add_button');
                          addButton.innerHTML = '+ Add';
                          if (item.available_quantity === "0") {
                              addButton.disabled = true;
                          }
                          addButton.addEventListener('click', function () {
                              addItem(item.id, item.available_quantity);
                          });
    
                          var quantityDiv = document.createElement('DIV');
                          quantityDiv.classList.add('order_item_quantity_div');
    
                          var minusButton = document.createElement('BUTTON');
                          minusButton.classList.add('order_item_quantity_button');
                          minusButton.innerHTML = '-';
                          minusButton.addEventListener('click', function () {
                              changeQuantity(item.id, -1, item.available_quantity);
                              // console.log('cart-dec', cart);
                          });
    
                          var quantitySpan = document.createElement('SPAN');
                          quantitySpan.id = `quantity_${item.id}`;
                          quantitySpan.innerHTML = '0';
    
                          var plusButton = document.createElement('BUTTON');
                          plusButton.classList.add('order_item_quantity_button');
                          plusButton.innerHTML = '+';
                          plusButton.addEventListener('click', function () {
                              changeQuantity(item.id, 1, item.available_quantity);
                              // console.log('cart-inc', cart);
                          });
    
                          if (font && font.length > 0) {
                              itemName.classList.add(font);
                              itemPrice.classList.add(font);
                              quantitySpan.classList.add(font);
                              addButton.classList.add(font);
                              plusButton.classList.add(font);
                              minusButton.classList.add(font);
                          }
    
                          quantityDiv.appendChild(minusButton);
                          quantityDiv.appendChild(quantitySpan);
                          quantityDiv.appendChild(plusButton);
                          quantityDiv.style.display = 'none';
    
                          itemDiv.appendChild(img);
                          itemDiv.appendChild(itemInfo);
                          itemInfo.appendChild(itemName);
                          itemInfo.appendChild(itemPrice);
                          itemDiv.appendChild(addButton);
                          itemDiv.appendChild(quantityDiv);
    
                          // If item is in the cart, update the UI accordingly
                          if (cart[item.id]) {
                              quantitySpan.innerHTML = cart[item.id];
                              addButton.style.display = 'none';
                              quantityDiv.style.display = 'flex';
                          }
    
                          return itemDiv;
                      }
    
                      function addItem(itemId, availableQuantity) {
                          if (availableQuantity > 0) {
                              document.querySelector(`#quantity_${itemId}`).innerHTML = 1;
                              document.querySelector(`#item_${itemId} .order_item_add_button`).style.display = 'none';
                              document.querySelector(`#item_${itemId} .order_item_quantity_div`).style.display = 'flex';
                              cart[itemId] = 1; 
                              updateCheckoutButton();
                          }
                      }
    
                      function changeQuantity(itemId, change, availableQuantity) {
                          var quantitySpan = document.querySelector(`#quantity_${itemId}`);
                          var quantity = parseInt(quantitySpan.innerHTML) + change;
                          if (quantity <= 0) {
                              quantity = 0;
                              document.querySelector(`#item_${itemId} .order_item_add_button`).style.display = 'block';
                              document.querySelector(`#item_${itemId} .order_item_quantity_div`).style.display = 'none';
                              delete cart[itemId]; 
                          } else if (quantity > availableQuantity) {
                              quantity = availableQuantity;
                          }
                          quantitySpan.innerHTML = quantity;
                          if (quantity > 0) {
                              cart[itemId] = quantity; 
                          }
                          updateCheckoutButton();
                      }
    
                      var total_quantity_div;
                      var checkoutButton;

              
                      function updateCheckoutButton() {
                  cart_total_badge.innerHTML = Object.keys(cart).length;
                   checkoutButton = document.getElementById('orderItems_checkout_button');
                  if (Object.keys(cart).length > 0) {
                      if (!checkoutButton) {
                          checkoutButton = document.createElement('BUTTON');
                          checkoutButton.id = 'orderItems_checkout_button';
                          checkoutButton.innerHTML = generateTranslatedContent(translations, 'Proceed to Check Out', main_lang_code, language_code, input);
                          checkoutButton.classList.add('orderItems_checkout_button');
                          checkoutButton.classList.add('confirm-btn-smatest');
    
                          var submit_icon = document.createElement('IMG');
                          submit_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                          submit_icon.alt = 'SubmitIcon';
                          submit_icon.style.width = "18px";
                          submit_icon.style.height = "18px";
    
                          if (font && font.length > 0) {
                              checkoutButton.classList.add(font);
                          }
                          checkoutButton.addEventListener('click', function () {
                            search_bar_Input.value = '';
                            current_page = 'summary';
                              var selected_orders = [];
                              for (var itemId in cart) {
                                  var item = TotalorderItemsArray.find(i => i.id == itemId);
                                  if (item) {
                                      selected_orders.push({
                                          available_quantity: item.available_quantity,
                                          client_item_id: item.client_item_id,
                                          created_at: item.created_at,
                                          currency: item.currency,
                                          display_name: item.display_name,
                                          id: item.id,
                                          image_url: item.image_url,
                                          price_per_item: item.price_per_item,
                                          quantity: cart[itemId],
                                          question_id: item.question_id,
                                          redirect_url: item.redirect_url,
                                          search_keywords: item.search_keywords
                                      });
                                  }
                              }
                              if (selected_orders && selected_orders.length > 0) {
    
                                   total_quantity_div = document.createElement("DIV");
                                  total_quantity_div.classList.add("pull-left");
                                  total_quantity_div.classList.add("order_items_summery_scrool_div");
                                    
                                  var cart_summary_label = document.createElement("LABEL");
                                  cart_summary_label.classList.add("cart-summary-headder");
                                  cart_summary_label.innerHTML = generateTranslatedContent(translations, "Cart Summary", main_lang_code, language_code, input);
                                  cart_summary_label.style.cssText =
                                      cart_summary_label.style.cssText +
                                      "font-weight: 600 !important";
    
                                    if (font && font.length > 0) {
                                      total_quantity_div.classList.add(font);
                                      cart_summary_label.classList.add(font);
                                    }
    
                                  total_quantity_div.appendChild(cart_summary_label);
                                  var total_summary_price = 0;
                                  var total_order_amount = 0;
                                  for (var p = 0; p < selected_orders.length; p++) {
                                      var order_summery_item = document.createElement("DIV");
                                      order_summery_item.classList.add("order-summary-item");
                                      var order_summery_label = document.createElement("LABEL");
                                      var order_summery_quantity = document.createElement("LABEL");
                                      order_summery_label.innerHTML =
                                          selected_orders[p].display_name ;
                                          order_summery_quantity.innerHTML =
                                          '<span style="font-size:13px; font-weight:500;color:#24272d !important;"> x ' +
                                          parseInt(selected_orders[p].quantity) +
                                          "</span>";
                                      order_summery_label.classList.add("order-summary-label");
                                      order_summery_label.style.fontSize = '13px';
                                      order_summery_label.style.color = '#24272d';
                                      order_summery_label.style.cssText =
                                          order_summery_label.style.cssText +
                                          "font-weight:600 !important";
                                      var order_summery_price = document.createElement("LABEL");
                                      total_summary_price = parseFloat(
                                          parseInt(total_summary_price) +
                                          parseInt(
                                              parseFloat(selected_orders[p].price_per_item).toFixed(
                                                  2
                                              ) * parseInt(selected_orders[p].quantity)
                                          )
                                      ).toFixed(2);
                                      total_order_amount = parseFloat(
                                          parseInt(total_order_amount) +
                                          parseInt(
                                              parseFloat(selected_orders[p].price_per_item).toFixed(
                                                  2
                                              ) * parseInt(selected_orders[p].quantity)
                                          )
                                      ).toFixed(2);
                                      order_summery_price.innerHTML =
                                          selected_orders[p].currency +
                                          " " +
                                          parseFloat(
                                              parseFloat(selected_orders[p].price_per_item).toFixed(2) *
                                              parseInt(selected_orders[p].quantity)
                                          ).toFixed(2);
                                      order_summery_price.style.cssText =
                                          order_summery_price.style.cssText +
                                          "font-weight:600 !important";
                                      order_summery_price.classList.add("order-summary-price");
                                      order_summery_price.style.fontSize = '13px';
                                      order_summery_price.style.color = '#24272d';
                                      var order_summery_item_price =
                                          document.createElement("LABEL");
                                      order_summery_item_price.innerHTML =
                                          selected_orders[p].currency +
                                          " " +
                                          parseFloat(
                                              parseFloat(selected_orders[p].price_per_item).toFixed(2)
                                          ).toFixed(2) +
                                          ", Qty:" +
                                          parseInt(selected_orders[p].quantity);
                                      order_summery_item_price.classList.add(
                                          "order-summary-item-price"  
                                      );
                                      order_summery_item.appendChild(order_summery_label);
                                      order_summery_item.appendChild(order_summery_quantity);
                                      order_summery_item.appendChild(order_summery_price);
                                      total_quantity_div.appendChild(order_summery_item);
                                  }
                                  var json = JSON.parse(order_question_options);
                                  if (
                                      json.tax_percentage &&
                                      json.tax_percentage.toString().length > 0
                                  ) {
                                      var order_summery_item = document.createElement("DIV");
                                      order_summery_item.classList.add("order-summary-item");
                                      order_summery_item.style.borderTop = "1px solid lightgray";
                                      order_summery_item.style.paddingTop = "12px";
                                      order_summery_item.style.marginTop = "2px";
                                      var order_summery_label = document.createElement("LABEL");
                                      order_summery_label.style.fontSize = "13px";
                                      order_summery_label.style.lineHeight = "19px !important";
                                      order_summery_label.innerHTML =
                                          "Tax (" + json.tax_percentage + "%)";
                                      order_summery_label.classList.add("order-summary-label");
                                      order_summery_label.style.cssText =
                                          order_summery_label.style.cssText +
                                          "font-weight:500 !important";
                                      var order_summery_price = document.createElement("LABEL");
                                      var tax_order_amount = parseFloat(
                                          (total_order_amount * json.tax_percentage) / 100
                                      ).toFixed(2);
                                      order_summery_price.innerHTML =
                                          json.currency + " " + tax_order_amount;
                                      order_summery_price.style.cssText =
                                          order_summery_price.style.cssText +
                                          "font-weight:600 !important";
                                      total_summary_price =
                                          parseFloat(total_summary_price) +
                                          parseFloat(tax_order_amount);
                                      order_summery_price.classList.add("order-summary-price");
                                      order_summery_price.style.fontSize = '13px';
                                      order_summery_price.style.color = '#24272d';
                                      order_summery_item.appendChild(order_summery_label);
                                      order_summery_item.appendChild(order_summery_price);
                                      total_quantity_div.appendChild(order_summery_item);
                                  }
                                  if (
                                      json.discount_percentage &&
                                      json.discount_percentage.toString().length > 0
                                  ) {
                                      if (
                                          !(
                                              json.tax_percentage &&
                                              json.tax_percentage.toString().length > 0
                                          )
                                      ) {
                                          order_summery_item.style.borderTop = "1px solid lightgray";
                                          order_summery_item.style.paddingTop = "12px";
                                          order_summery_item.style.marginTop = "2px";
                                      }
                                      var order_summery_item = document.createElement("DIV");
                                      order_summery_item.classList.add("order-summary-item");
                                      var order_summery_label = document.createElement("LABEL");
                                      order_summery_label.style.fontSize = "13px";
                                      order_summery_label.style.lineHeight = "19px !important";
                                      order_summery_label.innerHTML =
                                          "Discount (" + json.discount_percentage + "%)";
                                      order_summery_label.classList.add("order-summary-label");
                                      order_summery_label.style.cssText =
                                          order_summery_label.style.cssText +
                                          "font-weight:500 !important";
                                      var order_summery_price = document.createElement("LABEL");
                                      var tax_order_amount = parseFloat(
                                          (total_order_amount * json.discount_percentage) / 100
                                      ).toFixed(2);
                                      order_summery_price.innerHTML =
                                          json.currency + " " + tax_order_amount;
                                      order_summery_price.style.cssText =
                                          order_summery_price.style.cssText +
                                          "font-weight:600 !important";
                                      total_summary_price =
                                          parseFloat(total_summary_price) -
                                          parseFloat(tax_order_amount);
                                      order_summery_price.classList.add("order-summary-price");
                                      order_summery_price.style.fontSize = '13px';
                                      order_summery_price.style.color = '#24272d';
                                      order_summery_item.appendChild(order_summery_label);
                                      order_summery_item.appendChild(order_summery_price);
                                      total_quantity_div.appendChild(order_summery_item);
                                  }
                                  if (
                                      json.delivery_charges &&
                                      json.delivery_charges.toString().length > 0
                                  ) {
                                      if (
                                          !(
                                              json.discount_percentage &&
                                              json.discount_percentage.toString().length > 0
                                          )
                                      ) {
                                          order_summery_item.style.borderTop = "1px solid lightgray";
                                          order_summery_item.style.paddingTop = "12px";
                                          order_summery_item.style.marginTop = "2px";
                                      }
                                      var order_summery_item = document.createElement("DIV");
                                      order_summery_item.classList.add("order-summary-item");
                                      var order_summery_label = document.createElement("LABEL");
                                      order_summery_label.innerHTML = generateTranslatedContent(translations, "Delivery Charges", main_lang_code, language_code, input); 
                                      order_summery_label.classList.add("order-summary-label");
                                      order_summery_label.style.fontSize = "13px";
                                      order_summery_label.style.lineHeight = "19px !important";
                                      order_summery_label.style.cssText =
                                          order_summery_label.style.cssText +
                                          "font-weight:500 !important";
                                      var order_summery_price = document.createElement("LABEL");
                                      var tax_order_amount = parseFloat(
                                          json.delivery_charges
                                      ).toFixed(2);
                                      order_summery_price.innerHTML =
                                          json.currency + " " + tax_order_amount;
                                      order_summery_price.style.cssText =
                                          order_summery_price.style.cssText +
                                          "font-weight:600 !important";
                                      total_summary_price =
                                          parseFloat(total_summary_price) +
                                          parseFloat(tax_order_amount);
                                      order_summery_price.classList.add("order-summary-price");
                                      order_summery_price.style.fontSize = '13px';
                                      order_summery_price.style.color = '#24272d';
                                      order_summery_item.appendChild(order_summery_label);
                                      order_summery_item.appendChild(order_summery_price);
                                      total_quantity_div.appendChild(order_summery_item);
                                  }
                                  var order_summery_item = document.createElement("DIV");
                                  order_summery_item.classList.add("order-summary-item");
                                  var order_summery_label = document.createElement("LABEL");
                                  order_summery_label.innerHTML = generateTranslatedContent(translations, "Total", main_lang_code, language_code, input);
                                  order_summery_label.classList.add("order-summary-label");
                                  order_summery_label.style.fontSize = "13px";
                                  order_summery_label.style.cssText =
                                      order_summery_label.style.cssText +
                                      "font-weight:500 !important";
                                  var order_summery_price = document.createElement("LABEL");
                                  order_summery_price.innerHTML =
                                      json.currency +
                                      " " +
                                      parseFloat(total_summary_price).toFixed(2);
                                  order_summery_price.style.cssText =
                                      order_summery_price.style.cssText +
                                      "font-weight:600 !important";
                                  order_summery_price.classList.add("order-summary-price");
                                  order_summery_price.style.fontSize = '13px';
                                  order_summery_price.style.color = '#24272d';
                                  order_summery_item.appendChild(order_summery_label);
                                  order_summery_item.appendChild(order_summery_price);
                                  total_quantity_div.appendChild(order_summery_item);
    
                                  // Add buttons
                                  var buttonContainer = document.createElement('DIV');
                                  buttonContainer.style.margin = 'auto auto 0px auto';
                                  buttonContainer.style.float = 'left';
                                  buttonContainer.style.width = '85%';
    
                                  var error_text = document.createElement('LABEL');
                                  error_text.classList.add('question-text-error');
                                  error_text.style.background = '#FFECEC';
                                  error_text.style.borderRadius = '6px';
                                  error_text.style.padding = '12px 16px';
    
                                  if (font && font.length > 0) {
                                    error_text.classList.add(font);
                                  }
    
                                  var editButton = document.createElement('BUTTON');
                                  editButton.innerHTML =  generateTranslatedContent(translations, 'Edit/Remove Items', main_lang_code, language_code, input);
                                  editButton.style.margin = '4px auto';
                                  editButton.style.fontSize = "12px";
                                  editButton.classList.add('confirm-btn-smatest');
    
                                  var addButton = document.createElement('BUTTON');
                                  addButton.innerHTML = generateTranslatedContent(translations, 'Add More Items', main_lang_code, language_code, input);
                                  addButton.style.margin = '4px auto';
                                  addButton.style.fontSize = "12px";
                                  addButton.classList.add('confirm-btn-smatest');
    
                                  var confirmButton = document.createElement('BUTTON');
                                  confirmButton.innerHTML = generateTranslatedContent(translations, 'Confirm Order', main_lang_code, language_code, input); 
                                  confirmButton.style.margin = '4px auto';
                                  confirmButton.style.fontSize = "12px";
                                  confirmButton.classList.add('confirm-btn-smatest');
    
                                  buttonContainer.appendChild(error_text);
                                  buttonContainer.appendChild(confirmButton);
                                  buttonContainer.appendChild(addButton);
                                  buttonContainer.appendChild(editButton);
    
    
                                  if (font && font.length > 0) {
                                    editButton.classList.add(font);
                                    addButton.classList.add(font);
                                    confirmButton.classList.add(font);
                                  }
    
                                  total_quantity_div.appendChild(buttonContainer);
    
                                  var minOrderAmountCheck;
                                  if (json.min_order_amount && json.min_order_amount.toString().length > 0) {
                                      // console.log("Total Order Amount:", total_order_amount);
                                      // console.log("Minimum Order Amount:", json.min_order_amount);
    
                                      if (Number(total_order_amount) >= Number(json.min_order_amount)) {
                                          minOrderAmountCheck = true;
                                      } else {
                                          minOrderAmountCheck = false;
                                      }
                                  } else {
                                      minOrderAmountCheck = true;
                                  }
    
                                  // console.log("Min Order Amount Check:", minOrderAmountCheck);
    
                                  if (minOrderAmountCheck) {
                                      confirmButton.removeAttribute('disabled');
                                      error_text.innerHTML = '';
                                      error_text.style.display = 'none';
                                  } else {
                                      error_text.style.display = 'block';
                                      confirmButton.style.border = '1px solid #D6E4F8';
                                      confirmButton.style.cursor = 'initial';
                                      confirmButton.style.margin = '4px 0';
                                      confirmButton.style.cssText = confirmButton.style.cssText + "background:none !important";
                                      confirmButton.style.cssText = confirmButton.style.cssText + "color:#1010104d !important";
                                      confirmButton.setAttribute('disabled', 'true');
                                      error_text.innerHTML = '</b> Minimum Order Amount is (<b>' +json.currency +' ' +json.min_order_amount +'</b>). Please add more items.'
                                  }
    
                                  // console.log(minOrderAmountCheck);
                                    
                                  editButton.addEventListener('click', function () {
                                      current_page = 'cart';
                                      total_quantity_div.style.display = 'none'
                                      filter_outer_div.style.display = 'none';
                                      order_items_scroll_div.style.display = 'block';
                                      checkoutButton.style.display = 'flex';
                                      order_items_scroll_div.style.marginBottom ='0px'
                                      back_button_div.style.display = 'flex';
                                      displayCartItems();
                                   });
    
                                  addButton.addEventListener('click', function () {
                                    current_page = 'items';
                                      total_quantity_div.style.display = 'none'
                                      back_button_div.style.display = 'none';
                                      filter_outer_div.style.display = 'flex';
                                      order_items_scroll_div.style.display = 'block';
                                      checkoutButton.style.display = 'flex';
                                      order_items_scroll_div.style.marginBottom ='0px'
                                      displayAllItems();
                                  });
    
                                  confirmButton.addEventListener('click', function (k) {
                                    var total_summary_price = 0;
                                    var total_order_amount = 0;
                                    for (var p = 0; p < selected_orders.length; p++) {
                                      total_summary_price = parseInt(
                                        parseInt(total_summary_price) +
                                          parseInt(
                                            parseFloat(selected_orders[p].price_per_item).toFixed(2) *
                                              parseInt(selected_orders[p].quantity)
                                          )
                                      );
                                      total_order_amount = parseInt(
                                        parseInt(total_order_amount) +
                                          parseInt(
                                            parseFloat(selected_orders[p].price_per_item).toFixed(2) *
                                              parseInt(selected_orders[p].quantity)
                                          )
                                      );
                                    }
                                    var json = JSON.parse(order_question_options);
                                    if (json.tax_percentage && json.tax_percentage.toString().length > 0) {
                                      var tax_order_amount = parseInt(
                                        (total_order_amount * json.tax_percentage) / 100
                                      );
                                      total_summary_price =
                                        parseInt(total_summary_price) + parseInt(tax_order_amount);
                                    }
                                    if (
                                      json.discount_percentage &&
                                      json.discount_percentage.toString().length > 0
                                    ) {
                                      var tax_order_amount = parseInt(
                                        (total_order_amount * json.discount_percentage) / 100
                                      );
                                      total_summary_price =
                                        parseInt(total_summary_price) - parseInt(tax_order_amount);
                                    }
                                    if (json.delivery_charges && json.delivery_charges.toString().length > 0) {
                                      var tax_order_amount = parseInt(json.delivery_charges);
                                      total_summary_price =
                                        parseInt(total_summary_price) + parseInt(tax_order_amount);
                                    }
                                    var minOrderAmountCheck = true;
                                    if (json.min_order_amount && json.min_order_amount.toString().length > 0) {
                                      if (total_order_amount >= json.min_order_amount) {
                                      } else {
                                        minOrderAmountCheck = false;
                                      }
                                    }
                                    if (minOrderAmountCheck) {
    
                                      var main_opened_div = document.getElementById('opened');
        
                                      if ( main_opened_div.contains(document.getElementById('bg-shadow-overlay'))) {
                                        main_opened_div.removeChild(
                                          document.getElementById('bg-shadow-overlay')
                                        );
                                      }
                    
                                      var openMenuSb = document.getElementById('open-menu-sb');
                                      var optionsDiv = document.getElementsByClassName('options-div-smatest');
                    
                                      if (openMenuSb && optionsDiv.length > 0) {
                                        if (
                                          optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                                        ) {
                                          optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                                        }
                                      }
    
                                      var answerDiv = document.createElement('DIV');
                                      answerDiv.classList.add('answer-div');
                                      setTimeout(function () {
                                        answerDiv.classList.add('top-0');
                                      }, transition_time);
                                      var answer = document.createElement('LABEL');
                                      var answer_text = document.createTextNode('Confirm Order');
                                      answer.appendChild(answer_text);
                                      answer.classList.add('answer-label');
                                      if (font && font.length > 0) {
                                        answer.classList.add(font);
                                      }
                                      answerDiv.appendChild(answer);
                                      body.appendChild(answerDiv);
                                      body.scrollTop = body.scrollHeight;
                                      var spinningDiv = document.createElement('DIV');
                                      spinningDiv.classList.add('question-div-smatest');
                                      spinningDiv.classList.add('top-0');
                                      if (font && font.length > 0) {
                                        spinningDiv.classList.add(font);
                                      }
                                      var spinnerDiv = document.createElement('DIV');
                                      spinnerDiv.classList.add('spinner1-smatest');
                                      var ques_icon = document.createElement('IMG');
                                      ques_icon.alt = 'Logo of ' + totalData[0].name;
                                      ques_icon.src = avatar_icon;
                                      var iconDiv = document.createElement('DIV');
                                      iconDiv.appendChild(ques_icon);
                                      iconDiv.classList.add('question-icon-div');
                                      ques_icon.classList.add('question-icon-smatest');
                                      var inner1 = document.createElement('DIV');
                                      inner1.classList.add('bounce1');
                                      var inner2 = document.createElement('DIV');
                                      inner2.classList.add('bounce2');
                                      var inner3 = document.createElement('DIV');
                                      inner3.classList.add('bounce3');
                                      spinnerDiv.appendChild(inner1);
                                      spinnerDiv.appendChild(inner2);
                                      spinnerDiv.appendChild(inner3);
                                      spinningDiv.appendChild(iconDiv);
                                      spinningDiv.appendChild(spinnerDiv);
                                      body.appendChild(spinningDiv);
                                      body.scrollTop = body.scrollHeight;
                                      this.parentElement.removeChild(this);
                                      var opened_div = document.getElementById('opened')
                                      if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                                        opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
                                      }
                                      try {
                                        input.removeEventListener('keyup', myEfficientFn);
                                        input.removeEventListener('click', orderAutocomplete);
                                        input.removeEventListener('keyup', realTimeSearch);
                                        input.removeEventListener('click', autocomplete);
                                      } catch (e) {
                                      } finally {
                                      }
                                      setTimeout(function () {
                                        var confirmed_items = [];
                                        for (var i = 0; i < selected_orders.length; i++) {
                                          if (
                                            selected_orders[i] &&
                                            selected_orders[i].quantity &&
                                            selected_orders[i].quantity.toString().length > 0
                                          ) {
                                            confirmed_items.push({
                                              id: selected_orders[i].id,
                                              display_name: selected_orders[i].display_name,
                                              price_per_item: selected_orders[i].price_per_item,
                                              quantity: selected_orders[i].quantity.toString(),
                                            });
                                          }
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (this.readyState == 4 && this.status == 200) {
                                            if (body.contains(spinningDiv)) {
                                              body.removeChild(spinningDiv);
                                            }
                                            entered = !1;
                                            shouldDisableTakeAction = !1;
                                            var xhttp = new XMLHttpRequest();
                                            xhttp.onreadystatechange = function () {
                                              entered = !1;
                                              if (this.readyState == 4 && this.status == 200) {
                                                shouldDisableTakeAction = !1;
                                                question_and_answers.push({
                                                  id: question_id,
                                                  answer: 'orders_confirmed',
                                                });
                                                if (currentQuestionIsLead == '1' && !mailSent) {
                                                  sendAlertCall();
                                                } else {
                                                  if (mailSequence < currentMailSequence) {
                                                    random_key = !0;
                                                  } else {
                                                    random_key = !1;
                                                  }
                                                }
                                                cb_session = JSON.parse(this.response).cb_session;
                                                live_chat_cb_session = JSON.parse(this.response).livechat_session;
                                                if (
                                                  JSON.parse(this.response).language_code &&
                                                  JSON.parse(this.response).language_code.length > 0 &&
                                                  JSON.parse(this.response).language_code != 'default'
                                                ) {
                                                  main_lang_code = JSON.parse(this.response).language_code;
                                                }
                                                session_feedback = JSON.parse(this.response).feedback;
                                                question_array = JSON.parse(this.response).next_question;
                                                if (question_array && question_array.length > 0) {
                                                  question_completed = !1;
                                                  input_value = '';
                                                  setTimeout(function () {
                                                    enter.style.pointerEvents = 'auto';
                                                    if (spinningDiv && spinningDiv.parentNode == body) {
                                                      body.removeChild(spinningDiv);
                                                    }
                                                    current_question_type = question_array[0].type;
                                                    current_logical_jump = question_array[0].logical_jump;
                                                    currentMailSequence = question_array[0].sequence;
                                                    currentQuestionIsLead = question_array[0].send_mail;
                                                    question_id = question_array[0].id;
                                                    setAllInputs(question_array);
                                                    assignAllQuestionTypes(current_question_type,question_array);
                                                  }, delay_time);
                                                } else {
                                                  if (spinningDiv && spinningDiv.parentNode == body) {
                                                    body.removeChild(spinningDiv);
                                                  }
                                                  enter.style.pointerEvents = 'auto';
                                                  question_completed = !0;
                                                  if (!mailSent || mailSent) {
                                                    var xhttp = new XMLHttpRequest();
                                                    xhttp.onreadystatechange = function () {
                                                      if (this.readyState == 4 && this.status == 200) {
                                                        var questionArray = [];
                                                        prev_questions_array = JSON.parse(this.response).qna_prev;
                                                        if (
                                                          prev_questions_array &&
                                                          prev_questions_array.length > 0
                                                        ) {
                                                          for (var i = 0; i < prev_questions_array.length; i++) {
                                                            if (
                                                              prev_questions_array[i].type == 'contact' ||
                                                              prev_questions_array[i].type == 'slides' ||
                                                              prev_questions_array[i].type == 'statement' ||
                                                              prev_questions_array[i].type ==
                                                                'url_auto_redirect' ||
                                                              prev_questions_array[i].type == 'custom_answer' ||
                                                              prev_questions_array[i].type == 'show_file' ||
                                                              prev_questions_array[i].type == 'show_contacts' ||
                                                              prev_questions_array[i].type == 'show_location'
                                                            ) {
                                                              prev_questions_array.splice(i, 1);
                                                              i--;
                                                            }
                                                          }
                                                          if (zapier_webhook && zapier_webhook.length > 0) {
                                                            var output = {};
                                                            output.timestamp = new Date();
                                                            for (
                                                              var i = 0;
                                                              i < prev_questions_array.length;
                                                              i++
                                                            ) {
                                                              var str = prev_questions_array[i].question_text;
                                                              output[str] = prev_questions_array[i].answer_text;
                                                            }
                                                            var xhttp = new XMLHttpRequest();
                                                            xhttp.onreadystatechange = function () {
                                                              if (this.readyState == 4 && this.status == 200) {
                                                              }
                                                            };
                                                            xhttp.open('POST', zapier_webhook, !0);
                                                            xhttp.setRequestHeader(
                                                              'Content-type',
                                                              'application/x-www-form-urlencoded'
                                                            );
                                                            xhttp.send('output=' + JSON.stringify(output));
                                                          }
                                                          for (var i = 0; i < prev_questions_array.length; i++) {
                                                            questionArray.push({
                                                              question: prev_questions_array[i].question_text,
                                                              answer: prev_questions_array[i].answer_text,
                                                            });
                                                          }
                                                        }
                                                      }
                                                    };
                                                    xhttp.open(
                                                      'POST',
                                                      main_url +
                                                        '/kya_backend/pagehub/chatbot_utils?action=init_chat',
                                                      !0
                                                    );
                                                    xhttp.setRequestHeader(
                                                      'Content-type',
                                                      'application/x-www-form-urlencoded'
                                                    );
                                                    if (
                                                      main_lang_code &&
                                                      main_lang_code.length > 0 &&
                                                      main_lang_code != language_code
                                                    ) {
                                                    } else {
                                                      main_lang_code = 'default';
                                                    }
                                                    var bot_widget_obj;
                                                    var is_sendable;
                                                    try {
                                                      checkSaveMAxUserLogin();
                                                      checkRateGainDetails();
                                                    } catch (error) {}
                                                    if (window.botWidget && window.botWidget.user) {
                                                      var keys = Object.keys(window.botWidget.user);
                                                      for (var t = 0; t < keys.length; t++) {
                                                        if (
                                                          window.botWidget.user[keys[t]] &&
                                                          window.botWidget.user[keys[t]].length > 0
                                                        ) {
                                                          is_sendable = true;
                                                        }
                                                      }
                                                      if (is_sendable) {
                                                        bot_widget_obj = window.botWidget.user;
                                                      } else {
                                                        bot_widget_obj = '';
                                                      }
                                                      if (window.botWidget.user.bot_id) {
                                                        delete window.botWidget.user.bot_id;
                                                      }
                                                      if (window.botWidget.user.url) {
                                                        delete window.botWidget.user.url;
                                                      }
                                                    }
                                                    xhttp.send(
                                                      'action=init_chat&device_print=' +
                                                        device_print +
                                                        '&chatbot_id=' +
                                                        chatbot_id +
                                                        '&language_code=' +
                                                        main_lang_code +
                                                        '&bot_widget_obj=' +
                                                        JSON.stringify(bot_widget_obj)
                                                    );
                                                  } else {
                                                    var xhttp = new XMLHttpRequest();
                                                    xhttp.onreadystatechange = function () {
                                                      if (this.readyState == 4 && this.status == 200) {
                                                        var questionArray = [];
                                                        prev_questions_array = JSON.parse(this.response).qna_prev;
                                                        if (
                                                          prev_questions_array &&
                                                          prev_questions_array.length > 0
                                                        ) {
                                                          for (var i = 0; i < prev_questions_array.length; i++) {
                                                            if (
                                                              prev_questions_array[i].type == 'contact' ||
                                                              prev_questions_array[i].type == 'slides' ||
                                                              prev_questions_array[i].type == 'statement' ||
                                                              prev_questions_array[i].type ==
                                                                'url_auto_redirect' ||
                                                              prev_questions_array[i].type == 'custom_answer' ||
                                                              prev_questions_array[i].type == 'show_file' ||
                                                              prev_questions_array[i].type == 'show_contacts' ||
                                                              prev_questions_array[i].type == 'show_location'
                                                            ) {
                                                              prev_questions_array.splice(i, 1);
                                                              i--;
                                                            }
                                                          }
                                                          for (var i = 0; i < prev_questions_array.length; i++) {
                                                            questionArray.push({
                                                              question: prev_questions_array[i].question_text,
                                                              answer: prev_questions_array[i].answer_text,
                                                            });
                                                          }
                                                        }
                                                      }
                                                    };
                                                    xhttp.open(
                                                      'POST',
                                                      main_url +
                                                        '/kya_backend/pagehub/chatbot_utils?action=init_chat',
                                                      !0
                                                    );
                                                    xhttp.setRequestHeader(
                                                      'Content-type',
                                                      'application/x-www-form-urlencoded'
                                                    );
                                                    if (
                                                      main_lang_code &&
                                                      main_lang_code.length > 0 &&
                                                      main_lang_code != language_code
                                                    ) {
                                                    } else {
                                                      main_lang_code = 'default';
                                                    }
                                                    var bot_widget_obj;
                                                    var is_sendable;
                                                    try {
                                                      checkSaveMAxUserLogin();
                                                      checkRateGainDetails();
                                                    } catch (error) {}
                                                    if (window.botWidget && window.botWidget.user) {
                                                      var keys = Object.keys(window.botWidget.user);
                                                      for (var t = 0; t < keys.length; t++) {
                                                        if (
                                                          window.botWidget.user[keys[t]] &&
                                                          window.botWidget.user[keys[t]].length > 0
                                                        ) {
                                                          is_sendable = true;
                                                        }
                                                      }
                                                      if (is_sendable) {
                                                        bot_widget_obj = window.botWidget.user;
                                                      } else {
                                                        bot_widget_obj = '';
                                                      }
                                                      if (window.botWidget.user.bot_id) {
                                                        delete window.botWidget.user.bot_id;
                                                      }
                                                      if (window.botWidget.user.url) {
                                                        delete window.botWidget.user.url;
                                                      }
                                                    }
                                                    xhttp.send(
                                                      'action=init_chat&device_print=' +
                                                        device_print +
                                                        '&chatbot_id=' +
                                                        chatbot_id +
                                                        '&language_code=' +
                                                        main_lang_code +
                                                        '&bot_widget_obj=' +
                                                        JSON.stringify(bot_widget_obj)
                                                    );
                                                  }
                                                  if (!entry_id) {
                                                    showInput = !0;
                                                    if (!shouldShowMenu) {
                                                      footer.style.display = 'none';
                                                      footer.classList.add('close');
                                                    } else {
                                                      if (entry_id) {
                                                        input.style.pointerEvents = 'auto';
                                                        microphone.style.pointerEvents = 'auto';
                                                        microphone.style.opacity = 1;
                                                        enter.style.pointerEvents = 'auto';
                                                        setPlaceHolders();
                                                        if (header.contains(company_title_description)) {
                                                          body.style.height = 'calc(100% - 218px)';
                                                        } else {
                                                          body.style.height = 'calc(100% - 143px)';
                                                        }
                                                      } else {
                                                        input.style.pointerEvents = 'none';
                                                        microphone.style.pointerEvents = 'none';
                                                        microphone.style.opacity = 0;
                                                        input.blur();
                                                        enter.style.pointerEvents = 'none';
                                                        input.placeholder = 'Choose from Menu';
                                                      }
                                                    }
                                                  }
                                                  if (!shouldShowMenu) {
                                                    if (header.contains(company_title_description)) {
                                                      body.style.height = 'calc(100% - 168px)';
                                                    } else {
                                                      body.style.height = 'calc(100% - 93px)';
                                                    }
                                                  } else {
                                                    if (header.contains(company_title_description)) {
                                                      body.style.height = 'calc(100% - 218px)';
                                                    } else {
                                                      body.style.height = 'calc(100% - 143px)';
                                                    }
                                                  }
                                                }
                                              }
                                            };
                                            xhttp.open(
                                              'POST',
                                              main_url + '/kya_backend/pagehub/chatbot_utils?action=answer',
                                              !0
                                            );
                                            xhttp.setRequestHeader(
                                              'Content-type',
                                              'application/x-www-form-urlencoded'
                                            );
                                            if (
                                              main_lang_code &&
                                              main_lang_code.length > 0 &&
                                              main_lang_code != language_code
                                            ) {
                                            } else {
                                              main_lang_code = 'default';
                                            }
                                            if (current_logical_jump == '1') {
                                              xhttp.send(
                                                'action=answer&answer_text=order_confirmed&cb_session=' +
                                                  cb_session +
                                                  '&question_id=' +
                                                  question_id +
                                                  '&is_logical=' +
                                                  current_logical_jump +
                                                  '&sequence=' +
                                                  currentMailSequence +
                                                  '&chatbot_id=' +
                                                  chatbot_id +
                                                  '&option=sometext&visitor_link_traversal=' +
                                                  visitedUrls +
                                                  '&language_code=' +
                                                  main_lang_code
                                              );
                                            } else {
                                              xhttp.send(
                                                'action=answer&answer_text=order_confirmed&cb_session=' +
                                                  cb_session +
                                                  '&question_id=' +
                                                  question_id +
                                                  '&is_logical=' +
                                                  current_logical_jump +
                                                  '&sequence=' +
                                                  currentMailSequence +
                                                  '&chatbot_id=' +
                                                  chatbot_id +
                                                  '&option=items_edited&visitor_link_traversal=' +
                                                  visitedUrls +
                                                  '&language_code=' +
                                                  main_lang_code
                                              );
                                            }
                                          }
                                        };
                                        
                                        xhttp.open('POST', main_url + '/kya_backend/pagehub/store_Items', !0);
                                        xhttp.setRequestHeader(
                                          'Content-type',
                                          'application/x-www-form-urlencoded'
                                        );
                                        setTimeout(() => {
                                          xhttp.send(
                                            'action=confirm&confirmed_items=' +
                                              JSON.stringify(confirmed_items) +
                                              '&cb_session=' +
                                              cb_session +
                                              '&order_amount=' +
                                              total_order_amount +
                                              '&total_amount=' +
                                              total_summary_price
                                          );
                                           }, 500);
    
                                        
                                      }, 1);
                                    } else {
                                      var errorDiv = document.createElement('DIV');
                                      errorDiv.classList.add('question-div-smatest');
                                      setTimeout(function () {
                                        errorDiv.classList.add('top-0');
                                      }, transition_time);
                                      if (font && font.length > 0) {
                                        errorDiv.classList.add(font);
                                      }
                                      var error_icon = document.createElement('IMG');
                                      error_icon.alt = 'Logo of ' + totalData[0].name;
                                      error_icon.src = avatar_icon;
                                      var iconDiv = document.createElement('DIV');
                                      iconDiv.appendChild(error_icon);
                                      iconDiv.classList.add('question-icon-div');
                                      error_icon.classList.add('question-icon-smatest');
                                      var error_text = document.createElement('LABEL');
                                      error_text.innerHTML =
                                        'Your Order Amount is <b>' +
                                        json.currency +
                                        ' ' +
                                        total_order_amount +
                                        '</b>, Which is less than the Minimum Order Amount (<b>' +
                                        json.currency +
                                        ' ' +
                                        json.min_order_amount +
                                        '</b>). Please make sure your order amount is greater that Minimum Order Amount.</b>';
                                      say(error_text.innerText);
                                      error_text.classList.add('question-text-error');
                                      error_text.classList.add('options-div-smatest');
                                      if (font && font.length > 0) {
                                        error_text.classList.add(font);
                                      }
                                      errorDiv.appendChild(iconDiv);
                                      errorDiv.appendChild(error_text);
                                      body.appendChild(errorDiv);
                                      body.scrollTop = body.scrollHeight;
                                    }
                                  });
                                  
    
                              }
                              orderItems_container.appendChild(total_quantity_div);
    
                              filter_outer_div.style.display = 'none';
                              order_items_scroll_div.style.display = 'none';
                              checkoutButton.style.display = 'none';
                              back_button_div.style.display = 'none';
                              headder_main_text.innerHTML = generateTranslatedContent(translations, 'Checkout', main_lang_code, language_code); 
                          });
                          orderItems_container.appendChild(checkoutButton);
                          order_items_scroll_div.style.marginBottom ='0px'
                          checkoutButton.appendChild(submit_icon);
                      }
                  } else {
                      if (checkoutButton) {
                          orderItems_container.removeChild(checkoutButton);
                      }
                  }
                }
    
                      // Initialize items
                      function initializeItems() {
                          order_items_scroll_div.innerHTML = ''; // Clear existing items
                        if (TotalorderItemsArray) {
                          TotalorderItemsArray?.forEach(item => {
                              var itemCard = createItemCard(item);
                              itemCard.setAttribute('id', `item_${item.id}`);
                              order_items_scroll_div.appendChild(itemCard);
                          });
                        }
                      }
                  // Function to display items in the cart
                  function displayCartItems() {
                    order_items_scroll_div.innerHTML = ''; // Clear the current items
                    var cartItems = TotalorderItemsArray.filter(item => cart[item.id]);
                    cartItems.forEach(item => {
                        var itemCard = createItemCard(item);
                        itemCard.setAttribute('id', `item_${item.id}`);
                        order_items_scroll_div.appendChild(itemCard);
                    });
                    filter_outer_div.style.display = 'none';
                    back_button_div.style.display = 'block';
                     headder_main_text.innerHTML = generateTranslatedContent(translations, 'Cart items', main_lang_code, language_code); 
                  }
    
                  function displayAllItems() {
                    order_items_scroll_div.innerHTML = ''; // Clear the current items
                    initializeItems(); // Reinitialize all items
                    filter_outer_div.style.display = 'flex';
                    back_button_div.style.display = 'none';
                     headder_main_text.innerHTML = generateTranslatedContent(translations, 'Select items from the menu', main_lang_code, language_code);  
                  }
                      // Function to filter items based on search query
                      function filterItems(query) {
                          order_items_scroll_div.innerHTML = ''; // Clear the current items
                          var filteredItems = TotalorderItemsArray.filter(item => item.display_name.toLowerCase().includes(query.trim().toLowerCase()));
                          filteredItems.forEach(item => {
                              var itemCard = createItemCard(item);
                              itemCard.setAttribute('id', `item_${item.id}`);
                              order_items_scroll_div.appendChild(itemCard);
                          });
                      }
    
                      search_bar_Input.addEventListener('input', function () {
                          filterItems(this.value);
                      });
    
                      cart_icon_div.addEventListener('click', function () {
                        current_page = 'cart';
                        search_bar_Input.value = ''
                        displayCartItems();
                      });
                      
                      setTimeout(() => {
                        opened_div.appendChild(bg_shadow_orderItems);
                      }, 1000);
                      bg_shadow_orderItems.appendChild(orderItems_container);
                      orderItems_container.appendChild(headder_main_div);   
                      headder_main_div.appendChild(left_icon_img); 
                      headder_main_div.appendChild(headder_main_text); 
                      // headder_main_div.appendChild(close_icon_div); 
                      orderItems_container.appendChild(filter_outer_div); 
                      // orderItems_container.appendChild(back_button_div);
                      // back_button_div.appendChild(back_button_img);
                      // filter_outer_div.appendChild(left_icon_img);
                      filter_outer_div.appendChild(search_bar_div);
                      filter_outer_div.appendChild(cart_icon_div);  
                      cart_icon_div.appendChild(cart_icon);
                      cart_icon_div.appendChild(cart_total_badge);
                      search_bar_div.appendChild(search_bar_Input);
                      search_bar_div.appendChild(search_icon); 
                      orderItems_container.appendChild(order_items_scroll_div); 
                      // orderItems_container.appendChild(brand_wrapper); 
                      createBrandWrapper(orderItems_container, 'SmatBot', main_url, font);
    
                      close_icon_div.addEventListener("click", function () {
                          if (opened_div.contains(bg_shadow_orderItems)) {
                              // bg_shadow_orderItems.style.visibility = 'hidden';
                              // orderItems_container.style.opacity = '0.5';
                              // orderItems_container.style.transform = 'translateY(100%)';
                              botWidget.minimise()
                          }
                      });
    
                      left_icon_img.addEventListener("click", function () {
                        if (current_page == 'items') {
                          if (opened_div.contains(bg_shadow_orderItems)) {
                              bg_shadow_orderItems.style.visibility = 'hidden';
                              orderItems_container.style.opacity = '0.5';
                              orderItems_container.style.transform = 'translateY(100%)';
                          }
                        }else if (current_page == 'cart') {
                          current_page = 'items';
                          displayAllItems();
                        }else{
                          current_page = 'cart';
                          total_quantity_div.style.display = 'none'
                          filter_outer_div.style.display = 'none';
                          order_items_scroll_div.style.display = 'block';
                          checkoutButton.style.display = 'flex';
                          order_items_scroll_div.style.marginBottom ='0px'
                          back_button_div.style.display = 'flex';
                          displayCartItems();
                        }
                      });
    
                      // Initialize the items when the script runs
                      initializeItems();
    
                      // Code end
    
                  footer.style.display = "block";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                  footer.classList.remove("close");
                  if (!shouldShowMenu) {
                    input.style.pointerEvents = "auto";
                    microphone.style.pointerEvents = "auto";
                    microphone.style.opacity = 1;
                    enter.style.pointerEvents = "auto";
                  }
                  input.focus();
                  input.placeholder = "Select items from the menu";
                  input.style.pointerEvents = 'none';
                  microphone.style.pointerEvents = "none";
                  microphone.style.opacity = 0;
                  // input.addEventListener("keyup", myEfficientFn);
                  // input.addEventListener("click", orderAutocomplete);
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    body.scrollTop = body.scrollHeight;
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    if (body.contains(otherSpinningDIv)) {
                      body.removeChild(otherSpinningDIv);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      body.scrollTop = body.scrollHeight;
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }
        function startWebkitRecognization() {
          if (isChrome || true) {
            try {
              recognition.start();
              if (main_lang_code == 'default') {
                main_lang_code = language_code;
              }

              let voiceName = 'en-US'

              if (main_lang_code && main_lang_code != 'en') {
                let voice = azure_language_voices?.find(v => v.lang === main_lang_code);
                voiceName = voice?.lang_code;
              }

              recognition.lang = voiceName || 'en-US';

              recognition.onstart = function () {
                microphone.style.pointerEvents = "none";
                microphone.style.opacity = 0;
                audio_loading_div.style.display = "block";
                var x = parseInt(anotherDiv.clientHeight / 2) - 50;
                audio_loading_div.style.paddingTop = x + "px";
              };
              recognition.onerror = function (event) {
                // console.log(event.error);
              };
              recognition.onspeechend = function () {
                microphone.style.pointerEvents = "auto";
                microphone.style.opacity = 1;
                recognition.stop();
                audio_loading_div.style.display = "none";
              };
              recognition.onend = function () {
                microphone.style.pointerEvents = "auto";
                microphone.style.opacity = 1;
                microphone.src =
                  // "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/bot_input_mic.svg";
                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/microphone-widget-new.svg"
                recognition.stop();
                audio_loading_div.style.display = "none";
              };
              recognition.interimResults = false;
              recognition.onresult = function (event) {
                if (
                  current_question_type == "phone" ||
                  current_question_type == "number"
                ) {
                  var x = input.value + " " + event.results[0][0].transcript;
                  x = x.split(" ").join("");
                  input.value = parseInt(x);
                } else {
                  input.value = input.value + " " + event.results[0][0].transcript;
                }
                var transcript = event.results[0][0].transcript;
                var confidence = event.results[0][0].confidence;
              };
            } catch (error) { }
          }
        }
        function startAzureRecognition() {

          if (window.SpeechSDK) {
            const subscriptionKey = "df2d60048d204bf6a00b7b85e2d92405";
            const region = "eastus";

            let speechConfig = window.SpeechSDK.SpeechConfig.fromSubscription(subscriptionKey, region);

            if (main_lang_code == 'default') {
              main_lang_code = language_code;
            }

            let voiceName = 'en-US'

            if (main_lang_code && main_lang_code != 'en') {
              let voice = azure_language_voices?.find(v => v.lang === main_lang_code);
              voiceName = voice?.lang_code;
            }

            speechConfig.speechRecognitionLanguage = voiceName ? voiceName : 'en-US';
            let audioConfig = window.SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
            let speechRecognizer = new window.SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);

            let timeoutId;

            const stopRecognitionAndClearTimeout = () => {
              clearTimeout(timeoutId);
              speechRecognizer.stopContinuousRecognitionAsync();
              console.log("Stopped recognition due to timeout.");
            };

            timeoutId = setTimeout(() => {
              stopRecognitionAndClearTimeout();
            }, 5000); // 5 seconds

            microphone.style.pointerEvents = "none";
            microphone.style.opacity = 0;
            audio_loading_div.style.display = "block";
            var x = parseInt(anotherDiv.clientHeight / 2) - 50;
            audio_loading_div.style.paddingTop = x + "px";

            speechRecognizer.recognizing = (s, e) => {
              console.log('RECOGNIZING');
              console.log(`RECOGNIZING: Text=${e.result.text}`);
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              audio_loading_div.style.display = "block";
              var x = parseInt(anotherDiv.clientHeight / 2) - 50;
              audio_loading_div.style.paddingTop = x + "px";
              clearTimeout(timeoutId);
            };

            speechRecognizer.recognized = (s, e) => {
              if (e.result.reason === window.SpeechSDK.ResultReason.RecognizedSpeech) {
                console.log(`RECOGNIZED: Text=${e.result.text}`);
                if (
                  current_question_type == "phone" ||
                  current_question_type == "number"
                ) {
                  var x = input.value + " " + e.result.text;
                  x = x.split(" ").join("");
                  input.value = parseInt(x);
                } else {
                  input.value = input.value + " " + e.result.text;
                }

                stopRecognitionAndClearTimeout();
              } else if (e.result.reason === window.SpeechSDK.ResultReason.NoMatch) {
                console.log("No match found.");
                stopRecognitionAndClearTimeout();
              }
            };

            speechRecognizer.canceled = (s, e) => {
              console.log(`CANCELED: Reason=${e.reason}`);
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              microphone.src = 
              // "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/bot_input_mic.svg";
              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/microphone-widget-new.svg"
              audio_loading_div.style.display = "none";
              if (e.reason === window.SpeechSDK.CancellationReason.Error) {
                console.log(`CANCELED: ErrorCode=${e.errorCode}`);
                console.log(`CANCELED: ErrorDetails=${e.errorDetails}`);
                if (e.errorDetails.includes("Quota exceeded")) {
                  console.log("Quota exceeded. Consider increasing your subscription limits.");
                } else if (e.errorDetails.includes("websocket error code: 1007")) {
                  console.log("WebSocket error 1007: Possible protocol issue or format error.");
                } else {
                  console.log("Other error. Ensure the speech resource key and region values are correct.");
                }
              }
              stopRecognitionAndClearTimeout();
            };

            speechRecognizer.sessionStopped = (s, e) => {
              console.log("Session stopped.");
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              microphone.src = 
              // "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/bot_input_mic.svg";
              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/microphone-widget-new.svg"
              audio_loading_div.style.display = "none";
              stopRecognitionAndClearTimeout();
            };

            speechRecognizer.startContinuousRecognitionAsync();
          } else {
            console.log("Speech SDK not loaded.");
          }
        }
        microphone.addEventListener("click", function (k) {
          try {
            if (isChrome) {
              startWebkitRecognization()
            } else {
              startAzureRecognition()
            }
            // startAzureRecognition()
            audio_loading_div.style.bottom = "15px";
          } catch (error) { }
        });

        function callOtherQuestions(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }

          function changeEmoji() {
            var regex = /\::(.*?)\::/g;
            var emojis_array = question_array[0].question_text.match(regex);
            for (var i = 0; i < emojis_array.length; i++) {
              for (var j = 0; j < all_emojis.length; j++) {
                if (emojis_array[i].split("::").join("") == all_emojis[j].title) {
                  question_array[0].question_text =
                    question_array[0].question_text.replace(
                      emojis_array[i],
                      all_emojis[j].value
                    );
                }
              }
            }
          }
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("::")
          ) {
            changeEmoji(question_array[0].question_text);
          }
          var arr;
          arr = getParagraphs(question_array[0].question_text);
          if (chatbot_id == 23895) {
            arr = getCustomParagraphs(question_array[0].question_text);
          }
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest-image");
                main_options_div.classList.add("some-animation");
                   var picker_div = document.createElement('DIV');
                  picker_div.id = 'date_picker_smatbot'
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  if (
                    question_array[0].image_url &&
                    question_array[0].image_url.length > 0 &&
                    question_array[0].image_url != "null"
                  ) {
                    var extension = question_array[0].image_url
                      .split(/\#|\?/)[0]
                      .split(".")
                      .pop()
                      .trim();
                    if (
                      extension.toLowerCase() == "png" ||
                      extension.toLowerCase() == "jpg" ||
                      extension.toLowerCase() == "jpeg" ||
                      extension.toLowerCase() == "svg" ||
                      extension.toLowerCase() == "tif" ||
                      extension.toLowerCase() == "gif" ||
                      extension.toLowerCase() == "webp"
                    ) {
                      var imgDiv = document.createElement("DIV");
                      imgDiv.classList.add("image-div-smatest");
                      var questionImg = document.createElement("IMG");
                      questionImg.src = question_array[0].image_url;
                      questionImg.classList.add("question-img-smatest");
                      imgDiv.appendChild(questionImg);
                      main_options_div.appendChild(imgDiv);
                      var modal_div = document.createElement("DIV");
                      if (font && font.length > 0) {
                        modal_div.classList.add(font);
                      }
                      modal_div.classList.add("modal-smatest");
                      modal_div.id = "myImageModal";
                      var modal_content_div = document.createElement("DIV");
                      modal_content_div.classList.add("modal-content-smatest");
                      var modal_close_span = document.createElement("SPAN");
                      modal_close_span.classList.add("close-modal");
                      modal_close_span.innerHTML = "&times";
                      modal_content_div.appendChild(modal_close_span);
                      modal_div.appendChild(modal_content_div);
                      modal_div.style.display = "block";
                      window.onclick = function (event) {
                        if (event.target == modal_div) {
                          if (modal_content_div.contains(imgDiv)) {
                            modal_content_div.removeChild(imgDiv);
                          }
                          questionImg.style.width = "100%";
                          main_options_div.appendChild(imgDiv);
                          if (document.body.contains(modal_div)) {
                            document.body.removeChild(modal_div);
                          }
                          imgDiv.children[0].classList.remove("fit-content-i");
                        }
                      };
                      modal_close_span.addEventListener("click", function (k) {
                        if (modal_content_div.contains(imgDiv)) {
                          modal_content_div.removeChild(imgDiv);
                        }
                        questionImg.style.width = "100%";
                        main_options_div.appendChild(imgDiv);
                        if (document.body.contains(modal_div)) {
                          document.body.removeChild(modal_div);
                        }
                        imgDiv.children[0].classList.remove("fit-content-i");
                      });
                      imgDiv.addEventListener("click", function (k) {
                        if (document.body.contains(modal_div)) {
                        } else {
                          modal_content_div.appendChild(imgDiv);
                          questionImg.style.width = "auto";
                          imgDiv.children[0].classList.add("fit-content-i");
                          document.body.appendChild(modal_div);
                        }
                      });
                    } else {
                      var doc_div = document.createElement("DIV");
                      doc_div.classList.add("pull-left");
                      doc_div.classList.add("full-width");
                      var doc_label = document.createElement("LABEL");
                      doc_label.style.marginTop = "10px";
                      doc_label.style.marginBottom = "10px";
                      doc_label.style.textAlign = "center";
                      var doc_a = document.createElement("A");
                      doc_a.title = "Statement image redirection";
                      doc_label.appendChild(doc_a);
                      doc_a.setAttribute("href", question_array[0].image_url);
                      doc_a.setAttribute("target", "_blank");
                      doc_a.innerHTML = question_array[0].image_url.substring(
                        question_array[0].image_url.lastIndexOf("/") + 1
                      );
                      doc_div.appendChild(doc_label);
                      if (chatbot_id == 13682 || chatbot_id == 13756) {
                        option_div.insertBefore(doc_div, option_div.firstChild);
                      } else {
                        option_div.appendChild(doc_div);
                      }
                    }
                  }
                  if (
                    question_array[0].is_skip &&
                    question_array[0].is_skip == "1"
                  ) {
                    option_div.style.position = "relative";
                    var skippable_div = document.createElement("DIV");
                    skippable_div.id = "skip-question-div";
                    skippable_div.classList.add("skip-question-div");
                    translateContent(translations, skippable_div, "Skip", main_lang_code, language_code);
                    if (font && font.length > 0) {
                      skippable_div.classList.add(font);
                    }
                    option_div.style.paddingBottom = "5px";
                    skippable_div.addEventListener("click", function (k) {
                      option_div.style.paddingBottom = "9px";
                      if (question_array[0].type == "location") {
                        locationSearchClicked = true;
                        location_skipped = true;
                      }
                      if (question_array[0].type == "question") {
                        question_skipped = true;
                      }
                      if (question_array[0].type == "number") {
                        if (is_safari) {
                          input.type = "value";
                        } else {
                          input.type = "text";
                        }
                        number_skipped = true;
                      }
                      if (question_array[0].type == "website") {
                        websited_skipped = true;
                      }
                      if (question_array[0].type == "ask_contacts") {
                        contacts_skipped = true;
                      }
                      input.value = "skipped";
                      enter.click();
                      option_div.style.cssText =
                        option_div.style.cssText + "background:darkgray !important";
                    });
                    option_div.appendChild(skippable_div);
                  }
                  if (
                    current_question_type == 'appointment' &&
                    appointment_timezone &&
                    appointment_timezone.length > 0
                  ) {
                    var bg_appointment = document.getElementById('inner_div_scrool-app');
                    var timezone_div = document.createElement('DIV');
                    timezone_div.classList.add('pull-left');
                    // timezone_div.classList.add("full-width");
                    timezone_div.classList.add('text-center');
                    // timezone_div.style.marginTop = '10px';
                    timezone_div.style.width = '85%';
                  
                    timezone_div.style.display = 'flex';
                    timezone_div.style.flexDirection = 'column';
                    timezone_div.style.alignItems = 'center';
                  
                    var timezone_label = document.createElement('LABEL');
                    timezone_label.classList.add('pull-left');
                    timezone_label.classList.add('full-width');
                    timezone_label.classList.add('bot-google-font');
                    timezone_label.style.marginTop = '16px';
                    timezone_label.style.marginBottom = '10px';
                    timezone_label.style.fontSize = '12px';
                    timezone_label.style.color = '#1D2D35';
                    timezone_label.style.fontWeight = '600';
                  
                    timezone_label.innerHTML = generateTranslatedContent(translations, "Select your slot to schedule a demo", main_lang_code, language_code, input);
                  
                    var close_icon_div = document.createElement('DIV');
                    close_icon_div.setAttribute('id', 'close-icon-div-small_sb');
                  
                    var close_icon_img = document.createElement('IMG');
                    close_icon_img.src =
                      'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small+(2).svg';
                    close_icon_img.alt = 'closeicon';
                    close_icon_img.style.width = '10px';
                    close_icon_img.style.height = '10px';
                  
                    var left_icon_div = document.createElement('DIV');
                    left_icon_div.setAttribute('id', 'left-icon-div-small_sb');
                  
                    var left_icon_img = document.createElement('IMG');
                    left_icon_img.src =
                      'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg';
                    left_icon_img.alt = 'lefticon';
                    left_icon_img.style.width = '15px';
                    left_icon_img.style.height = '15px';
                    left_icon_img.style.cursor = 'pointer';
                  
                    timezone_div.appendChild(timezone_label);
                    left_icon_div.appendChild(left_icon_img);
                    close_icon_div.appendChild(close_icon_img);
                    timezone_div.appendChild(left_icon_div);
                    // timezone_div.appendChild(close_icon_div);
                  
                    var select_div_style = document.createElement('DIV');
                    select_div_style.classList.add('timezone-dropdown-select-ui');
                  
                    var timezone_select = document.createElement('SELECT');
                    if (enable_timezone_selection) {
                      timezone_select.style.pointerEvents = 'auto';
                      timezone_select.disabled = false;
                    } else {
                      timezone_select.style.pointerEvents = 'none';
                      timezone_select.disabled = true;
                    }

                    timezone_select.id = 'timezone_select';
                    for (var i = 0; i < available_timezones.length; i++) {
                      var option = document.createElement('option');
                      option.value = available_timezones[i].value;
                      option.innerHTML = available_timezones[i].name;
                  
                      timezone_select.appendChild(option);
                    }
                    timezone_select.classList.add('timezone-dropdown-new');
                    if (font && font.length > 0) {
                      timezone_select.classList.add(font);
                    }
                    if (appointment_timezone) {
                      timezone_select.value = appointment_timezone;
                    } else {
                      timezone_select.value = '+05:30';
                    }
                    select_div_style.appendChild(timezone_select);
                    timezone_div.appendChild(select_div_style);
                  
                    createCustomDropdown(timezone_select);
                  
                    var appoint_new_div = document.getElementById('bg-shadow-overlay');
                    var bg_overlay = document.getElementById('appointment-container');
                  
                    close_icon_div.addEventListener('click', function () {
                      appoint_new_div.style.visibility = 'hidden';
                      bg_overlay.style.opacity = '0.5';
                      bg_overlay.style.transform = 'translateY(100%)';
                    });
                  
                    left_icon_div.addEventListener('click', function () {
                      appoint_new_div.style.visibility = 'hidden';
                      bg_overlay.style.opacity = '0.5';
                      bg_overlay.style.transform = 'translateY(100%)';
                    });
                  
                    function createCustomDropdown(dropdown) {
                      const options = dropdown.querySelectorAll('option');
                      const optionsArr = Array.prototype.slice.call(options);
                  
                      const customDropdown = document.createElement('div');
                      customDropdown.classList.add('dropdown_sb');
                      dropdown.insertAdjacentElement('afterend', customDropdown);

                      if (enable_timezone_selection == '0'){
                        customDropdown.style.pointerEvents = 'none'
                      }
                  
                      const selected = document.createElement('div');
                      selected.classList.add('dropdown-select-sb');
                      selected.textContent = optionsArr[0].textContent;
                      customDropdown.appendChild(selected);
                  
                      const menu = document.createElement('div');
                      menu.classList.add('dropdown-menu-sb');
                      customDropdown.appendChild(menu);
                      selected.addEventListener('click', toggleDropdown.bind(menu, selected));
                  
                      const search = document.createElement('input');
                      search.placeholder = 'Search...';
                      search.type = 'text';
                      search.classList.add('dropdown-menu-search-sb');
                  
                      if (font && font.length > 0) {
                        selected.classList.add(font);
                        search.classList.add(font);
                        menu.classList.add(font);
                      }
                  
                      menu.appendChild(search);
                  
                      const menuInnerWrapper = document.createElement('div');
                      menuInnerWrapper.classList.add('dropdown-menu-inner-sb');
                      menu.appendChild(menuInnerWrapper);
                  
                      optionsArr.forEach((option) => {
                        const item = document.createElement('div');
                        item.classList.add('dropdown-menu-item-sb');
                        item.dataset.value = option.value;
                        item.textContent = option.textContent;
                        menuInnerWrapper.appendChild(item);
                        if (font && font.length > 0) {
                          item.classList.add(font);
                        }
                  
                        item.addEventListener(
                          'click',
                          setSelected.bind(item, selected, dropdown, menu)
                        );
                      });
                  
                      const initialSelectedValue = dropdown.value;
                      const initialSelectedItem = Array.from(menuInnerWrapper.children).find(
                        (item) => item.dataset.value === initialSelectedValue
                      );
                      if (initialSelectedItem) {
                        initialSelectedItem.classList.add('selected');
                        selected.textContent = initialSelectedItem.textContent;
                      }
                  
                      search.addEventListener(
                        'input',
                        filterItems.bind(search, optionsArr, menu)
                      );
                      document.addEventListener(
                        'click',
                        closeIfClickedOutside.bind(customDropdown, menu, selected)
                      );
                      dropdown.style.display = 'none';
                    }
                  
                    function toggleDropdown(selected) {
                      if (this.offsetParent !== null) {
                        this.style.display = 'none';
                        selected.classList.remove('dropdown-open');
                      } else {
                        this.style.display = 'block';
                        selected.classList.add('dropdown-open');
                        this.querySelector('input').focus();
                      }
                    }
                  
                    function setSelected(selected, dropdown, menu) {
                      const value = this.dataset.value;
                      const label = this.textContent;
                  
                      this.parentNode.querySelectorAll('div').forEach((item) => {
                        item.classList.remove('selected');
                      });
                  
                      this.classList.add('selected');
                  
                      selected.textContent = label;
                  
                      dropdown.value = value;
                  
                      const event = new Event('change');
                      dropdown.dispatchEvent(event);
                  
                      menu.style.display = 'none';
                      selected.classList.remove('dropdown-open');
                    }
                  
                    function filterItems(optionsArr, menu) {
                      const searchValue = this.value.toLowerCase();
                      const items = menu.querySelectorAll('.dropdown-menu-item-sb');
                  
                      items.forEach((item) => {
                        if (item.textContent.toLowerCase().indexOf(searchValue) === -1) {
                          item.style.display = 'none';
                        } else {
                          item.style.display = 'block';
                        }
                      });
                    }
                  
                    function closeIfClickedOutside(menu, selected, e) {
                      if (e.target.closest('.dropdown_sb') === null) {
                        menu.style.display = 'none';
                        selected.classList.remove('dropdown-open');
                      }
                    }
                  
                    var intervalId = setInterval(function() {
                      let appointment_bg_shadow = document.getElementById('bg-shadow-overlay');
                      let appointment_container = document.getElementById('appointment-container');
                      if (appointment_bg_shadow && appointment_container) {
                          createAppMenu(option_div, 'Select Slots', appointment_bg_shadow, appointment_container);
                          clearInterval(intervalId);
                      }
                    }, 100); 
                  
                    if (bg_appointment) {
                      bg_appointment.appendChild(timezone_div);
                    }
                  
                  }
                }
                if (question_array[0].type == "email") {
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var json = JSON.parse(question_array[0].default_options);
                    if (json.is_strict_validation == false) {
                    } else {
                      json.is_strict_validation = true;
                    }
                    question_array[0].default_options = JSON.stringify(json);
                  } else {
                    var json = {};
                    json.is_strict_validation = true;
                    question_array[0].default_options = JSON.stringify(json);
                  }
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var json = JSON.parse(question_array[0].default_options);
                    if (json.company_emails_only) {
                      company_email_validation = !0;
                    } else {
                      company_email_validation = !1;
                    }
                    if (json.is_strict_validation) {
                      strictEmailValidation = true;
                    } else {
                      strictEmailValidation = false;
                    }
                  } else {
                    company_email_validation = !1;
                  }
                }
                if (question_array[0].type == "location") {

                  if (question_array[0].default_options && question_array[0].default_options.length > 0) {
                    
                    var json = JSON.parse(question_array[0].default_options) 
                  }
              
                  var location_type = '1'
        
                  if (json && json.interface && json.interface.length > 0) {
                    if (json.interface == 'modern') {
                       location_type = '2'
                    }else{
                      location_type = '1'
                    }
                  }

                  if (location_type == '2') {
                    var main_opened_div = document.getElementById('opened');
    
                    if (
                      main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                    ) {
                      main_opened_div.removeChild(
                        document.getElementById('bg-shadow-overlay')
                      );
                    }
              
                    var openMenuSb = document.getElementById('open-menu-sb');
                    var optionsDiv = document.getElementsByClassName('options-div-smatest');
              
                    if (openMenuSb && optionsDiv.length > 0) {
                      if (
                        optionsDiv[optionsDiv.length - 1].contains(openMenuSb)
                      ) {
                        optionsDiv[optionsDiv.length - 1].removeChild(openMenuSb);
                      }
                    }
                    
                    var intervalId = setInterval(function() {
                      let location_bg_shadow = document.getElementById('bg-shadow-overlay');
                      let location_container = document.getElementById('location_container_type_two');
                      if (location_bg_shadow && location_container) {
                          createAppMenu(option_div, 'Select location', location_bg_shadow, location_container);
                          clearInterval(intervalId);
                      }
                    }, 100); 
    
                  }
                }
                if (question_array[0].type == "date") {
                  main_options_div.id = 'smatbot_date_picker_container'
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  setTimeout(function () {
                    body.appendChild(questionDIv);
                  }, 100);
                  body.scrollTop = body.scrollHeight;
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    if (body.contains(otherSpinningDIv)) {
                      body.removeChild(otherSpinningDIv);
                    }
                    j++;
                    body.appendChild(questionDIv);
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add("m-t-5");
                    setTimeout(function () {
                      body.appendChild(questionDIv);
                    }, 100);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callDynamicQuestion() {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (x_arr[i].innerText && x_arr[i].innerText.length > 0) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                say(option_question.innerText);
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  option_div.classList.add("m-b-10");
                  iconDiv.classList.add("m-b-10");
                  handleImageModal(question_array, option_div);
                  setTimeout(function () {
                    var theCookies = document.cookie.split(";");
                    var needCookies = question_array[0].cookie_name;
                    var cookiesObject = {};
                    for (var i = 0; i < theCookies.length; i++) {
                      var keyValue = theCookies[i].split("=");
                      for (var j = 0; j < array.length; j++) {
                        if (needCookies[j] == keyValue[0]) {
                          cookiesObject[keyValue[0]] = keyValue[1];
                        }
                      }
                    }
                    takingRadioValue(JSON.stringify(cookiesObject), option_div, 4);
                  }, delay_time);
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    j++;
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function truncateHtml(html, maxLength) {
          // Strip tags to find where to cut without them
          const plainText = html.replace(/<[^>]*>/g, '');
          if (plainText.length <= maxLength) {
            return { html: html, readMore: false };
          }

          // Find the index in the original HTML up to which the plain text equals maxLength
          let idx = 0;
          let count = 0;
          let result = '';
          let tag = false;

          for (let char of html) {
            if (char === '<') {
              tag = true;
              result += char;
            } else if (char === '>') {
              tag = false;
              result += char;
            } else if (tag) {
              result += char;
            } else {
              if (count < maxLength) {
                result += char;
                count++;
              } else {
                // Close the tag if we're cutting in the middle of it
                if (tag) {
                  result += '>';
                }
                break;
              }
            }
          }

          // Make sure to close all opened tags
          const openTags = [];
          const regex = /<(\w+)[^>]*>|<\/(\w+)>/g;
          let match;
          while ((match = regex.exec(result)) !== null) {
            const [, openTag, closeTag] = match;
            if (openTag) {
              openTags.push(openTag);
            } else if (closeTag) {
              const lastOpenTag = openTags.pop();
              if (lastOpenTag !== closeTag) {
                console.error('Mismatched HTML tag found');
              }
            }
          }

          // Close all remaining open tags
          while (openTags.length > 0) {
            const tagToClose = openTags.pop();
            result += `</${tagToClose}>`;
          }
          result = result.replace(/<\/br><\/br><\/br>/g, "");
          result = result.replace(/(<br\s*\/?>\s*){3,}/gi, '');
          return { html: result, readMore: true };
        }

        function callStatement(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          if (
            question_array[0].question_text.includes("<table") &&
            question_array[0].question_text.includes("</table>")
          ) {
            isTableOpened = !0;
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            var modal_div = document.createElement("DIV");
            if (font && font.length > 0) {
              modal_div.classList.add(font);
            }
            modal_div.classList.add("modal-smatest");
            modal_div.id = "myModal";
            var modal_content_div = document.createElement("DIV");
            modal_content_div.classList.add("modal-content-smatest");
            var modal_close_span = document.createElement("SPAN");
            modal_close_span.classList.add("close-modal");
            modal_close_span.innerHTML = "&times";
            var table_div = document.createElement("DIV");
            table_div.style.color = "black";
            table_div.innerHTML = question_array[0].question_text;
            table_div.style.color = "black";
            modal_content_div.appendChild(modal_close_span);
            modal_content_div.appendChild(table_div);
            modal_div.appendChild(modal_content_div);
            modal_div.style.display = "block";
            window.onclick = function (event) {
              if (event.target == modal_div) {
                modal_div.style.display = "none";
                isTableOpened = !1;
                nothingWentOnFor = 0;
                encourageMessageIteration = 0;
              }
            };
            modal_close_span.addEventListener("click", function (k) {
              modal_div.style.display = "none";
              isTableOpened = !1;
              nothingWentOnFor = 0;
              encourageMessageIteration = 0;
            });
            document.body.appendChild(modal_div);
            var option_div = document.createElement("DIV");
            setTimeout(function () {
              takingRadioValue("something", option_div, 1);
            }, delay_time);
          } else {
            var k = document.createElement("DIV");
            k.innerHTML = question_array[0].question_text;
            var inner_text = k.innerText;
            if (!inner_text || inner_text.length == 0) {
              takingRadioValue("something", "", 1);
              return "";
            }
            var enable_read_more;
            var complete_text = question_array[0].question_text;
            if (inner_text && inner_text.length > 500) {
              enable_read_more = true;
              inner_text = inner_text.substring(0, 500) + "... ";
              k.innerText = inner_text;
              let { html, readMore } = truncateHtml(question_array[0].question_text, 500);
              question_array[0].question_text = html;
            }
            var arr = getParagraphs(question_array[0].question_text);
            var x_arr = arr;
            array = [];
            for (var i = 0; i < x_arr.length; i++) {
              if (x_arr[i]) {
                if (
                  (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                  (x_arr[i].children && x_arr[i].children.length > 0)
                ) {
                  array.push(x_arr[i].outerHTML);
                } else {
                  x_arr.splice(i, 1);
                  i--;
                }
              }
            }
            var question_arr = [];
            if (array && array.length > 0) {
              question_arr = array;
            } else {
              question_arr.push(question_array[0].question_text);
            }
            if (question_arr && question_arr.length > 0) {
              var j = 0;

              function addQuestionArrays() {
                if (j < question_arr.length) {
                  var questionDIv = document.createElement("DIV");
                  questionDIv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    questionDIv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    questionDIv.classList.add(font);
                  }
                  var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon1);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon1.src = avatar_icon;
                  ques_icon1.classList.add("question-icon-smatest");
                  var option_div = document.createElement("DIV");
                  option_div.classList.add("options-div-smatest");
                  var main_options_div = document.createElement("DIV");
                  main_options_div.classList.add("main-options-div-smatest-image");
                  main_options_div.classList.add("some-animation");
                  var option_question = document.createElement("LABEL");
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == "he" ||
                        main_lang_code == "ur" ||
                        main_lang_code == "ar")) ||
                    (main_lang_code == "default" &&
                      (language_code == "ar" ||
                        language_code == "he" ||
                        language_code == "ur"))
                  ) {
                    option_question.classList.add("rtl");
                  }
                  console.log(question_arr);
                  option_question.innerHTML = question_arr[j].trim();
                  if (j == 0) {
                    say(option_question.innerText);
                  } else {
                    setTimeout(function () {
                      say(option_question.innerText);
                    }, 1000);
                  }
                  option_div.appendChild(option_question);
                  var timeStamp = new Date().getTime() + Math.floor(Math.random() * 1000);
                  option_div.id = question_array[0].id + "-" + timeStamp;
                  if (j != question_arr.length - 1) {
                    option_div.classList.add("m-l-40");
                  }
                  if (j == question_arr.length - 1) {
                    questionDIv.appendChild(iconDiv);
                    option_div.classList.add("m-b-10");
                    iconDiv.classList.add("m-b-10");
                    if (enable_read_more) {
                      var read_more_span = document.createElement("LABEL");
                      read_more_span.innerHTML = generateTranslatedContent(translations, "Read more", main_lang_code, language_code, input);
                      read_more_span.style.cssText = read_more_span.style.cssText + "color:#007bff !important;";
                      read_more_span.style.fontSize = "14px";
                      read_more_span.style.cursor = "pointer";
                      if (font && font.length > 0) {
                        read_more_span.classList.add(font);
                      }
                      var modal_div = document.createElement("DIV");
                      if (font && font.length > 0) {
                        modal_div.classList.add(font);
                      }
                      modal_div.classList.add("modal-smatest");
                      modal_div.id = "myReadMoreModal" + "-" + question_array[0].id + "-" + timeStamp;
                      var modal_content_div = document.createElement("DIV");
                      modal_content_div.style.width = "60%";
                      modal_content_div.style.maxHeight = "calc(100vh - 50px)";
                      modal_content_div.style.overflowY = "scroll";
                      modal_content_div.classList.add("modal-content-smatest");
                      var modal_close_span = document.createElement("SPAN");
                      modal_close_span.classList.add("close-modal");
                      modal_close_span.innerHTML = "&times";
                      var table_div = document.createElement("DIV");
                      table_div.style.paddingTop = "15px";
                      table_div.style.paddingBotttom = "15px";
                      table_div.style.paddingLeft = "10px";
                      table_div.style.paddingRight = "10px";
                      table_div.style.marginTop = "10px";
                      table_div.style.marginBotttom = "10px";
                      table_div.style.color = "black";
                      table_div.innerHTML = complete_text;
                      if (font && font.length > 0) {
                        table_div.classList.add(font);
                      }
                      modal_content_div.appendChild(modal_close_span);
                      modal_content_div.appendChild(table_div);
                      modal_div.appendChild(modal_content_div);
                      modal_div.style.display = "none";
                      read_more_span.addEventListener("click", function () {
                        var modal_id = "myReadMoreModal" + "-" + this.parentElement.id;
                        if (document.getElementById(modal_id)) {
                          document.getElementById(modal_id).style.display = "block";
                        }
                      });
                      window.onclick = function (event) {
                        if (event.target == modal_div) {
                          if (modal_div) {
                            modal_div.style.display = "none";
                            isTableOpened = !1;
                            nothingWentOnFor = 0;
                            encourageMessageIteration = 0;
                          }
                        }
                      };
                      modal_close_span.addEventListener("click", function (k) {
                        if (this.parentElement.parentElement) {
                          this.parentElement.parentElement.style.display = "none";
                          isTableOpened = !1;
                          nothingWentOnFor = 0;
                          encourageMessageIteration = 0;
                        }
                      });
                      document.body.appendChild(modal_div);
                      option_div.appendChild(read_more_span);
                    }
                    if (
                      question_array[0].image_url &&
                      question_array[0].image_url.length > 0 &&
                      question_array[0].image_url != "null"
                    ) {
                      var extension = question_array[0].image_url
                        .split(/\#|\?/)[0]
                        .split(".")
                        .pop()
                        .trim();
                      if (
                        extension.toLowerCase() == "png" ||
                        extension.toLowerCase() == "jpg" ||
                        extension.toLowerCase() == "jpeg" ||
                        extension.toLowerCase() == "svg" ||
                        extension.toLowerCase() == "tif" ||
                        extension.toLowerCase() == "gif" ||
                        extension.toLowerCase() == "webp"
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = question_array[0].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_options_div.appendChild(imgDiv);
                        var modal_div = document.createElement("DIV");
                        if (font && font.length > 0) {
                          modal_div.classList.add(font);
                        }
                        modal_div.classList.add("modal-smatest");
                        modal_div.id = "myImageModal";
                        var modal_content_div = document.createElement("DIV");
                        modal_content_div.classList.add("modal-content-smatest");
                        var modal_close_span = document.createElement("SPAN");
                        modal_close_span.classList.add("close-modal");
                        modal_close_span.innerHTML = "&times";
                        modal_content_div.appendChild(modal_close_span);
                        modal_div.appendChild(modal_content_div);
                        modal_div.style.display = "block";
                        window.onclick = function (event) {
                          if (event.target == modal_div) {
                            if (modal_content_div.contains(imgDiv)) {
                              modal_content_div.removeChild(imgDiv);
                            }
                            questionImg.style.width = "100%";
                            main_options_div.appendChild(imgDiv);
                            if (document.body.contains(modal_div)) {
                              document.body.removeChild(modal_div);
                            }
                            imgDiv.children[0].classList.remove("fit-content-i");
                          }
                        };
                        modal_close_span.addEventListener("click", function (k) {
                          if (modal_content_div.contains(imgDiv)) {
                            modal_content_div.removeChild(imgDiv);
                          }
                          questionImg.style.width = "100%";
                          main_options_div.appendChild(imgDiv);
                          if (document.body.contains(modal_div)) {
                            document.body.removeChild(modal_div);
                          }
                          imgDiv.children[0].classList.remove("fit-content-i");
                        });
                        imgDiv.addEventListener("click", function (k) {
                          if (document.body.contains(modal_div)) {
                          } else {
                            modal_content_div.appendChild(imgDiv);
                            questionImg.style.width = "auto";
                            imgDiv.children[0].classList.add("fit-content-i");
                            document.body.appendChild(modal_div);
                          }
                        });
                      } else {
                        var doc_div = document.createElement("DIV");
                        doc_div.classList.add("pull-left");
                        doc_div.classList.add("full-width");
                        var doc_label = document.createElement("LABEL");
                        doc_label.style.marginTop = "10px";
                        doc_label.style.marginBottom = "10px";
                        doc_label.style.textAlign = "center";
                        var doc_a = document.createElement("A");
                        doc_a.title = "Statement image redirection";
                        doc_label.appendChild(doc_a);
                        doc_a.setAttribute("href", question_array[0].image_url);
                        doc_a.setAttribute("target", "_blank");
                        doc_a.innerHTML = question_array[0].image_url.substring(
                          question_array[0].image_url.lastIndexOf("/") + 1
                        );
                        doc_div.appendChild(doc_label);
                        if (chatbot_id == 13682 || chatbot_id == 13756) {
                          option_div.insertBefore(doc_div, option_div.firstChild);
                        } else {
                          option_div.appendChild(doc_div);
                        }
                      }
                    }
                    if (
                      question_array[0].is_feedback &&
                      question_array[0].is_feedback == "1"
                    ) {
                      option_div.style.marginBottom = "15px";
                      addQuestionFeedback(option_div, question_array);
                    }
                  }
                  questionDIv.appendChild(option_div);
                  var otherSpinningDIv = document.createElement("DIV");
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  otherSpinningDIv.classList.add("m-l-40");
                  otherSpinningDIv.classList.add("m-t-5");
                  otherSpinningDIv.classList.add("pull-left");
                  otherSpinningDIv.appendChild(spinnerDiv);
                  if (j != 0) {
                    body.appendChild(otherSpinningDIv);
                  }
                  if (j == 0) {
                    if (j == question_arr.length - 1) {
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  } else {
                    setTimeout(function () {
                      if (body.contains(otherSpinningDIv)) {
                        body.removeChild(otherSpinningDIv);
                      }
                      if (j == question_arr.length - 1) {
                        setTimeout(function () {
                          takingRadioValue("something", option_div, 1);
                        }, delay_time);
                      }
                      j++;
                      if (j == question_arr.length) {
                        setTimeout(function () {
                          body.appendChild(main_options_div);
                        }, delay_time);
                        setTimeout(function () {
                          body.scrollTop = body.scrollHeight;
                        }, delay_time + 10);
                      }
                      questionDIv.classList.add("m-t-5");
                      body.appendChild(questionDIv);
                      addQuestionArrays();
                    }, delay_time);
                  }
                }
              }
              addQuestionArrays();
            }
            setTimeout(function () {
              if (body.scrollHeight > 320) {
                body.scrollTop = body.scrollTop + body.offsetHeight + 30;
              } else {
                body.scrollTop = body.scrollHeight;
              }
            }, 100);
          }
        }

        function callURLAutoRedirect(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }

          function changeEmoji() {
            var regex = /\::(.*?)\::/g;
            var emojis_array = question_array[0].question_text.match(regex);
            for (var i = 0; i < emojis_array.length; i++) {
              for (var j = 0; j < all_emojis.length; j++) {
                if (emojis_array[i].split("::").join("") == all_emojis[j].title) {
                  question_array[0].question_text =
                    question_array[0].question_text.replace(
                      emojis_array[i],
                      all_emojis[j].value
                    );
                }
              }
            }
          }
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("::")
          ) {
            changeEmoji(question_array[0].question_text);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest-image");
                main_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_options_div);
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var json = JSON.parse(question_array[0].default_options);
                    if (json.url && json.url.length > 0) {
                      var delay;
                      if (json.delay.toString().length > 0) {
                        delay = parseInt(json.delay) * 1000;
                      } else {
                        delay = 0;
                      }
                      var tab;
                      if (json.tab && json.tab.length > 0) {
                        if (json.tab == "1") {
                          tab = "_self";
                        } else {
                          tab = "_blank";
                        }
                      }
                      var oneSpinningDIv = document.createElement("DIV");
                      oneSpinningDIv.id = "auto-url-loading";
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      oneSpinningDIv.classList.add("m-l-40");
                      oneSpinningDIv.classList.add("m-t-5");
                      oneSpinningDIv.classList.add("pull-left");
                      oneSpinningDIv.appendChild(spinnerDiv);
                      body.appendChild(oneSpinningDIv);
                      setTimeout(function () {
                        if (body.contains(oneSpinningDIv)) {
                          body.removeChild(oneSpinningDIv);
                        }
                        if (document.getElementById("auto-url-loading")) {
                          document
                            .getElementById("auto-url-loading")
                            .parentElement.removeChild(
                              document.getElementById("auto-url-loading")
                            );
                        }
                        var newWin = window.open(json.url, tab);
                        if (
                          !newWin ||
                          newWin.closed ||
                          typeof newWin.closed == "undefined"
                        ) {
                          var errorDiv = document.createElement("DIV");
                          errorDiv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            errorDiv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            errorDiv.classList.add(font);
                          }
                          var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                          error_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(error_icon);
                          iconDiv.classList.add("question-icon-div");
                          error_icon.classList.add("question-icon-smatest");
                          var error_text = document.createElement("LABEL");
                          error_text.innerHTML =
                            'Please click <a href="' +
                            json.url +
                            '" target="_blank">here</a>';
                          say(error_text.innerText);
                          error_text.classList.add("question-text-error");
                          error_text.classList.add("options-div-smatest");
                          if (font && font.length > 0) {
                            error_text.classList.add(font);
                          }
                          errorDiv.appendChild(iconDiv);
                          errorDiv.appendChild(error_text);
                          body.appendChild(errorDiv);
                          playBotUserSound(1);
                          body.scrollTop = body.scrollHeight;
                        }
                        setTimeout(function () {
                          takingRadioValue("something", option_div, 1);
                        }, delay_time);
                      }, delay);
                    }
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  setTimeout(function () {
                    body.appendChild(questionDIv);
                  }, 100);
                  body.scrollTop = body.scrollHeight;
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    if (body.contains(otherSpinningDIv)) {
                      body.removeChild(otherSpinningDIv);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add("m-t-5");
                    setTimeout(function () {
                      body.appendChild(questionDIv);
                    }, 100);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callShowContacts(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest-image");
                main_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  option_div.classList.add("m-b-10");
                  iconDiv.classList.add("m-b-10");
                  handleImageModal(question_array, main_options_div);
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var contacts_array = JSON.parse(
                      question_array[0].default_options
                    );
                    if (
                      contacts_array &&
                      contacts_array.length > 0 &&
                      contacts_array[0].contact &&
                      contacts_array[0].name
                    ) {
                      var contacts_html =
                        '<table class="table-contacts" style="width:100%;text-align:left;border: 1px solid #ddd;"><tbody><tr><th>Name</th><th>Contact(s)</th></tr>';
                      for (var t = 0; t < contacts_array.length; t++) {
                        contacts_html = contacts_html + "<tr>";
                        contacts_html =
                          contacts_html + "<td>" + contacts_array[t].name + "</td>";
                        contacts_array[t].contact = contacts_array[
                          t
                        ].contact.replace("-", "");
                        contacts_array[t].contact = contacts_array[
                          t
                        ].contact.replace(" ", "");
                        contacts_html =
                          contacts_html +
                          '<td><a href="tel:' +
                          contacts_array[t].contact +
                          '">' +
                          contacts_array[t].contact +
                          "</a>" +
                          "</td>";
                        contacts_html = contacts_html + "<tr>";
                      }
                      contacts_html = contacts_html + "</tr>";
                      var contacts_list_btn = document.createElement("BUTTON");
                      contacts_list_btn.classList.add("contact-list-btn");
                      if (font && font.length > 0) {
                        contacts_list_btn.classList.add(font);
                      }
                      if (contacts_array && contacts_array.length > 1) {
                        contacts_list_btn.innerHTML = "Show Contacts";
                      } else {
                        contacts_list_btn.innerHTML = "Show Contact";
                      }
                      option_div.appendChild(contacts_list_btn);
                      var modal_div = document.createElement("DIV");
                      if (font && font.length > 0) {
                        modal_div.classList.add(font);
                      }
                      modal_div.classList.add("modal-smatest");
                      modal_div.id = "myModal";
                      var modal_content_div = document.createElement("DIV");
                      modal_content_div.classList.add("modal-content-smatest");
                      var modal_close_span = document.createElement("SPAN");
                      modal_close_span.classList.add("close-modal");
                      modal_close_span.innerHTML = "&times";
                      var table_div = document.createElement("DIV");
                      table_div.innerHTML = contacts_html;
                      modal_content_div.appendChild(modal_close_span);
                      modal_content_div.appendChild(table_div);
                      modal_div.appendChild(modal_content_div);
                      modal_div.style.display = "none";
                      window.onclick = function (event) {
                        if (event.target == modal_div) {
                          modal_div.style.display = "none";
                          isTableOpened = !1;
                          nothingWentOnFor = 0;
                          encourageMessageIteration = 0;
                        }
                      };
                      modal_close_span.addEventListener("click", function (k) {
                        modal_div.style.display = "none";
                        isTableOpened = !1;
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                      });
                      document.body.appendChild(modal_div);
                      contacts_list_btn.addEventListener("click", function (k) {
                        modal_div.style.display = "block";
                      });
                    } else if (
                      contacts_array &&
                      contacts_array.length > 0 &&
                      contacts_array[0].Cust_Name &&
                      contacts_array[0].Clo_Mobile
                    ) {
                      var contacts_html =
                        '<table class="table-contacts" style="width:100%;text-align:left;border: 1px solid #ddd;"><tbody><tr><th>Dealer Name</th><th>Dealer Phone</th><th>Dealer Location</th></tr>';
                      for (var t = 0; t < contacts_array.length; t++) {
                        contacts_html = contacts_html + "<tr>";
                        contacts_html =
                          contacts_html +
                          "<td>" +
                          contacts_array[t].Cust_Name +
                          "</td>";
                        contacts_array[t].contact = contacts_array[
                          t
                        ].Clo_Mobile.replace("-", "");
                        contacts_array[t].contact = contacts_array[
                          t
                        ].Clo_Mobile.replace(" ", "");
                        contacts_html =
                          contacts_html +
                          '<td><a href="tel:' +
                          contacts_array[t].Clo_Mobile +
                          '">' +
                          contacts_array[t].Clo_Mobile +
                          "</a>" +
                          "</td>";
                        var urlstring =
                          "https://maps.google.com/?q=" +
                          contacts_array[t].lat +
                          "," +
                          contacts_array[t].lng;
                        contacts_html =
                          contacts_html +
                          '<td><a target="_blank" href="' +
                          urlstring +
                          '">' +
                          urlstring +
                          "</a>" +
                          "</td>";
                        contacts_html = contacts_html + "<tr>";
                      }
                      contacts_html = contacts_html + "</tr>";
                      var contacts_list_btn = document.createElement("BUTTON");
                      contacts_list_btn.classList.add("contact-list-btn");
                      if (font && font.length > 0) {
                        contacts_list_btn.classList.add(font);
                      }
                      if (contacts_array && contacts_array.length > 1) {
                        contacts_list_btn.innerHTML = "Show Ramco Dealers";
                      } else {
                        contacts_list_btn.innerHTML = "Show Ramco Dealer";
                      }
                      option_div.appendChild(contacts_list_btn);
                      var modal_div = document.createElement("DIV");
                      if (font && font.length > 0) {
                        modal_div.classList.add(font);
                      }
                      modal_div.classList.add("modal-smatest");
                      modal_div.id = "myModal";
                      var modal_content_div = document.createElement("DIV");
                      modal_content_div.classList.add("modal-content-smatest");
                      var modal_close_span = document.createElement("SPAN");
                      modal_close_span.classList.add("close-modal");
                      modal_close_span.innerHTML = "&times";
                      var table_div = document.createElement("DIV");
                      table_div.innerHTML = contacts_html;
                      modal_content_div.appendChild(modal_close_span);
                      modal_content_div.appendChild(table_div);
                      modal_div.appendChild(modal_content_div);
                      modal_div.style.display = "none";
                      window.onclick = function (event) {
                        if (event.target == modal_div) {
                          modal_div.style.display = "none";
                          isTableOpened = !1;
                          nothingWentOnFor = 0;
                          encourageMessageIteration = 0;
                        }
                      };
                      modal_close_span.addEventListener("click", function (k) {
                        modal_div.style.display = "none";
                        isTableOpened = !1;
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                      });
                      document.body.appendChild(modal_div);
                      contacts_list_btn.addEventListener("click", function (k) {
                        modal_div.style.display = "block";
                      });
                    }
                  }
                  if (
                    question_array[0].is_feedback &&
                    question_array[0].is_feedback == "1"
                  ) {
                    option_div.style.marginBottom = "15px";
                    addQuestionFeedback(option_div, question_array);
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  if (j == question_arr.length - 1) {
                    setTimeout(function () {
                      takingRadioValue("something", option_div, 1);
                    }, delay_time);
                  }
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    if (j == question_arr.length - 1) {
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callShowLocation(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                var main_options_div = document.createElement("DIV");
                main_options_div.classList.add("main-options-div-smatest");
                main_options_div.classList.add("some-animation");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                option_div.classList.add("options-div-smatest");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  var location_obj = JSON.parse(question_array[0].default_options);
                  if (location_obj) {
                    var location_div = document.createElement("DIV");
                    location_div.classList.add("location-box");
                    var location_frame = document.createElement("IFRAME");
                    location_div.appendChild(location_frame);
                    location_div.style.border = "0";
                    location_frame.style.borderRadius = "6px";
                    location_frame.style.border = "0";
                    location_frame.src =
                      "https://maps.google.com/maps?q=" +
                      location_obj.lat +
                      "," +
                      location_obj.long +
                      "&z=14&amp&ie=UTF8&iwloc=&output=embed&hl=" +
                      language_code;
                    location_frame.style.maxWidth = "100%";
                    location_frame.style.height = "100%";
                    main_options_div.appendChild(location_div);
                  }
                  if (
                    question_array[0].is_feedback &&
                    question_array[0].is_feedback == "1"
                  ) {
                    option_div.style.marginBottom = "15px";
                    addQuestionFeedback(option_div, question_array);
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  if (j == question_arr.length - 1) {
                    setTimeout(function () {
                      takingRadioValue("something", option_div, 1);
                    }, delay_time);
                  }
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.appendChild(main_options_div);
                    }, delay_time);
                    setTimeout(function () {
                      body.scrollTop = body.scrollHeight;
                    }, delay_time + 10);
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    if (j == question_arr.length - 1) {
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.appendChild(main_options_div);
                      }, delay_time);
                      setTimeout(function () {
                        body.scrollTop = body.scrollHeight;
                      }, delay_time + 10);
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callShowFile(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  option_div.classList.add("m-b-10");
                  iconDiv.classList.add("m-b-10");
                  if (
                    question_array[0].image_url &&
                    question_array[0].image_url.length > 0 &&
                    question_array[0].image_url != "null"
                  ) {
                    var extension = question_array[0].image_url
                      .split(/\#|\?/)[0]
                      .split(".")
                      .pop()
                      .trim();
                    if (
                      extension.toLowerCase() == "png" ||
                      extension.toLowerCase() == "jpg" ||
                      extension.toLowerCase() == "jpeg" ||
                      extension.toLowerCase() == "svg" ||
                      extension.toLowerCase() == "tif" ||
                      extension.toLowerCase() == "gif" ||
                      extension.toLowerCase() == "webp"
                    ) {
                      var imgDiv = document.createElement("DIV");
                      imgDiv.classList.add("image-div-smatest");
                      var questionImg = document.createElement("IMG");
                      questionImg.src = question_array[0].image_url;
                      questionImg.classList.add("question-img-smatest");
                      imgDiv.appendChild(questionImg);
                      main_image_options_div.appendChild(imgDiv);
                      var modal_div = document.createElement("DIV");
                      if (font && font.length > 0) {
                        modal_div.classList.add(font);
                      }
                      modal_div.classList.add("modal-smatest");
                      modal_div.id = "myImageModal";
                      var modal_content_div = document.createElement("DIV");
                      modal_content_div.classList.add("modal-content-smatest");
                      var modal_close_span = document.createElement("SPAN");
                      modal_close_span.classList.add("close-modal");
                      modal_close_span.innerHTML = "&times";
                      modal_content_div.appendChild(modal_close_span);
                      modal_div.appendChild(modal_content_div);
                      modal_div.style.display = "block";
                      window.onclick = function (event) {
                        if (event.target == modal_div) {
                          if (modal_content_div.contains(imgDiv)) {
                            modal_content_div.removeChild(imgDiv);
                          }
                          questionImg.style.width = "100%";
                          main_image_options_div.appendChild(imgDiv);
                          if (document.body.contains(modal_div)) {
                            document.body.removeChild(modal_div);
                          }
                          imgDiv.children[0].classList.remove("fit-content-i");
                        }
                      };
                      modal_close_span.addEventListener("click", function (k) {
                        if (modal_content_div.contains(imgDiv)) {
                          modal_content_div.removeChild(imgDiv);
                        }
                        questionImg.style.width = "100%";
                        main_image_options_div.appendChild(imgDiv);
                        if (document.body.contains(modal_div)) {
                          document.body.removeChild(modal_div);
                        }
                        imgDiv.children[0].classList.remove("fit-content-i");
                      });
                      imgDiv.addEventListener("click", function (k) {
                        if (document.body.contains(modal_div)) {
                        } else {
                          modal_content_div.appendChild(imgDiv);
                          questionImg.style.width = "auto";
                          imgDiv.children[0].classList.add("fit-content-i");
                          document.body.appendChild(modal_div);
                        }
                      });
                    } else if (
                      extension.toLowerCase() == "mp3" ||
                      extension.toLowerCase() == "wav"
                    ) {
                      var slides_div = document.createElement("DIV");
                      slides_div.classList.add("pull-left");
                      slides_div.classList.add("full-width");
                      var audio_div = document.createElement("AUDIO");
                      audio_div.id = "audio";
                      audio_div.controls = !0;
                      audio_div.setAttribute("src", question_array[0].image_url);
                      audio_div.classList.add("audio-player");
                      slides_div.appendChild(audio_div);
                      option_div.appendChild(slides_div);
                    } else if (
                      extension.toLowerCase() == "mp4" ||
                      extension.toLowerCase() == "webm" ||
                      extension.toLowerCase() == "flv"
                    ) {
                      var slides_div = document.createElement("DIV");
                      slides_div.classList.add("pull-left");
                      slides_div.classList.add("full-width");
                      var video_div = document.createElement("VIDEO");
                      video_div.id = "video";
                      video_div.style.marginTop = "10px";
                      video_div.style.maxWidth = "100%";
                      video_div.controls = !0;
                      var video_src = document.createElement("SOURCE");
                      video_src.setAttribute("src", question_array[0].image_url);
                      video_src.setAttribute("type", "video/mp4");
                      var video_src_other = document.createElement("SOURCE");
                      video_src_other.setAttribute(
                        "src",
                        question_array[0].image_url
                      );
                      video_src_other.setAttribute("type", "video/mp4");
                      video_div.appendChild(video_src);
                      video_div.appendChild(video_src_other);
                      slides_div.appendChild(video_div);
                      option_div.appendChild(slides_div);
                    } else if (extension.toLowerCase() == "pdf") {
                      var download_div = document.createElement("DIV");
                      download_div.classList.add("pull-left");
                      download_div.classList.add("full-width");
                      download_div.classList.add("text-center");
                      var download_a = document.createElement("A");
                      download_a.title = "File upload file redirection";
                      if (chatbot_id == 20609) {
                        download_a.innerHTML = "Download brochure 📄";
                        download_a.style.cssText = download_a.style.cssText + "color: white !important;"
                        download_a.style.textDecoration = "none";
                      } else {
                        download_a.innerHTML = "Open PDF";
                      }
                      download_a.style.cursor = "pointer";
                      download_a.style.display = "inline-block";
                      download_a.addEventListener("click", function () { });
                      download_a.classList.add("confirm-btn-smatest");
                      download_a.download = "file";
                      download_a.setAttribute("href", question_array[0].image_url);
                      download_a.setAttribute("type", "application/octet-stream");
                      download_a.setAttribute("target", "_blank");
                      download_div.appendChild(download_a);
                      option_div.appendChild(download_div);
                    } else {
                      var doc_div = document.createElement("DIV");
                      doc_div.classList.add("pull-left");
                      doc_div.classList.add("full-width");
                      var doc_label = document.createElement("LABEL");
                      doc_label.style.marginTop = "10px";
                      doc_label.style.marginBottom = "10px";
                      doc_label.style.textAlign = "center";
                      var doc_a = document.createElement("A");
                      doc_a.title = "File upload file redirection";
                      doc_label.appendChild(doc_a);
                      doc_a.setAttribute("href", question_array[0].image_url);
                      doc_a.setAttribute("target", "_blank");
                      doc_a.innerHTML = question_array[0].image_url.substring(
                        question_array[0].image_url.lastIndexOf("/") + 1
                      );
                      doc_div.appendChild(doc_label);
                      option_div.appendChild(doc_div);
                    }
                  }
                  if (
                    question_array[0].is_feedback &&
                    question_array[0].is_feedback == "1"
                  ) {
                    option_div.style.marginBottom = "15px";
                    addQuestionFeedback(option_div, question_array);
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  if (j == question_arr.length - 1) {
                    setTimeout(function () {
                      takingRadioValue("something", option_div, 1);
                    }, delay_time);
                  }
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    body.scrollTop = body.scrollHeight;
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    if (j == question_arr.length - 1) {
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      body.scrollTop = body.scrollHeight;
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callAudio(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var j = 0;

            function addQuestionArrays() {
              if (j < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[j].trim();
                if (j == 0) {
                  say(option_question.innerText);
                } else {
                  setTimeout(function () {
                    say(option_question.innerText);
                  }, 1000);
                }
                option_div.appendChild(option_question);
                if (j != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (j == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  option_div.classList.add("m-b-10");
                  iconDiv.classList.add("m-b-10");
                  handleImageModal(question_array, main_image_options_div);
                  var slides_div = document.createElement("DIV");
                  slides_div.classList.add("pull-left");
                  slides_div.classList.add("full-width");
                  if (question_array[0].default_options) {
                    var url = question_array[0].default_options;
                    var audio_div = document.createElement("AUDIO");
                    audio_div.id = "audio";
                    audio_div.controls = !0;
                    audio_div.setAttribute(
                      "src",
                      question_array[0].default_options
                    );
                    audio_div.classList.add("audio-player");
                    slides_div.appendChild(audio_div);
                  }
                  option_div.appendChild(slides_div);
                  if (
                    question_array[0].is_feedback &&
                    question_array[0].is_feedback == "1"
                  ) {
                    addQuestionFeedback(option_div, question_array);
                    option_div.style.marginBottom = "15px";
                  }
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (j != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (j == 0) {
                  if (j == question_arr.length - 1) {
                    setTimeout(function () {
                      takingRadioValue("something", option_div, 1);
                    }, delay_time);
                  }
                  j++;
                  if (j == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    body.scrollTop = body.scrollHeight;
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    if (j == question_arr.length - 1) {
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time);
                    }
                    j++;
                    if (j == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      body.scrollTop = body.scrollHeight;
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callCustomAnswer(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var i = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (i < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.id = "custom-answer-question-div-" + i;
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[i].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                handleImageModal(question_array, main_image_options_div);
                option_div.classList.add("m-l-40");
                if (i == question_arr.length - 1) {
                  var take_actions_div = document.createElement("DIV");
                  take_actions_div.classList.add("question-div-smatest");
                  setTimeout(function () {
                    take_actions_div.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    take_actions_div.classList.add(font);
                  }
                  take_actions_div.appendChild(iconDiv);
                  var other_option_div = document.createElement("DIV");
                  other_option_div.classList.add("options-div-smatest");
                  var other_take_actions_div = document.createElement("DIV");
                  other_take_actions_div.classList.add("question-div-smatest");
                  setTimeout(function () {
                    other_take_actions_div.classList.add("top-0");
                  }, transition_time);
                  var option_question = document.createElement("LABEL");
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == "he" ||
                        main_lang_code == "ur" ||
                        main_lang_code == "ar")) ||
                    (main_lang_code == "default" &&
                      (language_code == "ar" ||
                        language_code == "he" ||
                        language_code == "ur"))
                  ) {
                    option_question.classList.add("rtl");
                  }
                  option_question.innerHTML = "what would you like to know more?";
                  speakable_str = speakable_str + " " + option_question.innerText;
                  option_question.classList.add("white-space-normal");
                  var faqs_div = document.createElement("DIV");
                  var signle_options_div = document.createElement("DIV");
                  signle_options_div.appendChild(option_question);
                  signle_options_div.classList.add("options-div-smatest");
                  signle_options_div.classList.add("dialogs-div-more-smatest");
                  faqs_div.classList.add("avatar-scrollbar");
                  faqs_div.style.cssText =
                    faqs_div.style.cssText + "max-height: fit-content !important";
                  faqs_div.classList.add("slides-random");
                  faqs_div.id = "avatar-scroll";
                  if (
                    firstCustomSingleChoiceOptions &&
                    firstCustomSingleChoiceOptions.length > 0
                  ) {
                    var customSingleOptions =
                      firstCustomSingleChoiceOptions.split(";;");
                    for (var p = customSingleOptions.length - 1; p > 0; p--) {
                      var r = Math.floor(Math.random() * (p + 1));
                      var temp = customSingleOptions[p];
                      customSingleOptions[p] = customSingleOptions[r];
                      customSingleOptions[r] = temp;
                    }
                    firstCustomSingleChoiceOptions = customSingleOptions.join(";;");
                    other_take_actions_div.classList.add("m-l-40");
                    var slides_div = document.createElement("DIV");
                    var customSingleOptions =
                      firstCustomSingleChoiceOptions.split(";;");
                    if (customSingleOptions && customSingleOptions.length > 0) {
                      for (var n = 0; n < customSingleOptions.length; n++) {
                        var selectedKey;
                        var contact = document.createElement("DIV");
                        contact.classList.add("dialogs-div-smatest");
                        if (font && font.length > 0) {
                          contact.classList.add(font);
                        }
                        var label = document.createElement("LABEL");
                        var text = document.createTextNode(customSingleOptions[n]);
                        label.appendChild(text);
                        speakable_str = speakable_str + " " + label.innerText;
                        if (n != customSingleOptions.length - 1) {
                          speakable_str = speakable_str + " or ";
                        }
                        contact.appendChild(label);
                        faqs_div.appendChild(contact);
                        contact.addEventListener("click", function (e) {
                          var value = this.children[0].innerHTML;
                          var arr =
                            this.parentElement.parentElement.previousSibling.id.split(
                              ".."
                            );
                          if (!shouldDisableTakeAction) {
                            if (
                              footer &&
                              (input.style.pointerEvents == "none" ||
                                footer.style.display == "none")
                            ) {
                              takingRadioValue(
                                value,
                                this.parentElement,
                                2,
                                firstCustomSingleChoiceId,
                                firstCustomSingleChoiceSequence,
                                "c_s_c"
                              );
                            } else {
                              if (input && input.placeholder == "Type your query") {
                                takingRadioValue(
                                  value,
                                  this.parentElement,
                                  2,
                                  firstCustomSingleChoiceId,
                                  firstCustomSingleChoiceSequence,
                                  "c_s_c"
                                );
                              }
                            }
                          }
                        });
                        faqs_div.appendChild(contact);
                      }
                      signle_options_div.appendChild(faqs_div);
                      other_take_actions_div.appendChild(signle_options_div);
                    }
                  }
                  var slides_div = document.createElement("DIV");
                  if (
                    question_array[0].default_options &&
                    question_array[0].default_options.length > 0
                  ) {
                    var optionsArray =
                      question_array[0].default_options.split(";;");
                    if (optionsArray && optionsArray.length > 0) {
                      for (var j = 0; j < optionsArray.length; j++) {
                        var selectedKey;
                        var contact_icon = document.createElement("A");
                        contact_icon.title = "contact redirection";
                        contact_icon.classList.add("extra-help-a");
                        if (font && font.length > 0) {
                          contact_icon.classList.add(font);
                        }
                        var contact_item1 = optionsArray[j].split("..");
                        var contact_img = document.createElement("IMG");
                        contact_img.classList.add("extra-help-icon");
                        contact_icon.appendChild(contact_img);
                        if (contact_item1[0] == "call") {
                          contact_icon.classList.add("other-pointer");
                          if (call_fore == "white") {
                            contact_img.src =
                              "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/call_white.png";
                          } else {
                            contact_img.src =
                              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/call_navigator.png";
                          }
                          contact_icon.href = "tel:" + contact_item1[2];
                          contact_icon.title = contact_item1[1];
                          contact_icon.addEventListener("click", function (k) {
                            var arr = [];
                            arr.push(custom_action_id);
                            arr.push(custom_action_sequence);
                            inTheMiddle = !0;
                            var xhttp = new XMLHttpRequest();
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            xhttp.send(
                              "action=answer&answer_text=Called" +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              arr[0] +
                              "&is_logical=0" +
                              "&sequence=" +
                              arr[1] +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&is_help=1&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          });
                          slides_div.appendChild(contact_icon);
                        } else if (contact_item1[0] == "schedule") {
                          contact_icon.classList.add("other-pointer");
                          contact_img.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/schedule.png";
                          var key = contact_item1[1];
                          contact_icon.title = contact_item1[1];
                          contact_icon.addEventListener("click", function (k) {
                            if (!scheduleClicked) {
                              scheduleClicked = !0;
                              var arr = [];
                              arr.push(custom_action_id);
                              arr.push(custom_action_sequence);
                              if (!shouldDisableTakeAction) {
                                if (
                                  footer &&
                                  (input.style.pointerEvents == "none" ||
                                    footer.style.display == "none")
                                ) {
                                  takingRadioValue(
                                    "Booked",
                                    this.parentElement,
                                    2,
                                    arr[0],
                                    arr[1],
                                    "take_action_flow"
                                  );
                                } else {
                                  if (
                                    input &&
                                    input.placeholder == "Type your query"
                                  ) {
                                    takingRadioValue(
                                      "Booked",
                                      this.parentElement,
                                      2,
                                      arr[0],
                                      arr[1],
                                      "take_action_flow"
                                    );
                                  }
                                }
                              }
                            } else {
                              this.title = "Already Scheduled";
                            }
                          });
                          slides_div.appendChild(contact_icon);
                        } else if (contact_item1[0] == "faqs") {
                        } else if (contact_item1[0] == "whatsapp") {
                          contact_icon.classList.add("other-pointer");
                          contact_icon.target = "_blank";
                          contact_icon.title = contact_item1[1];
                          contact_img.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/whatsapp_navigator.png";
                          contact_icon.addEventListener("click", function (k) {
                            var arr = [];
                            arr.push(custom_action_id);
                            arr.push(custom_action_sequence);
                            inTheMiddle = !0;
                            var xhttp = new XMLHttpRequest();
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            xhttp.send(
                              "action=answer&answer_text=Whatsapped" +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              arr[0] +
                              "&is_logical=0" +
                              "&sequence=" +
                              arr[1] +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&is_help=1&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          });
                          var k = generateTranslatedContent(translations, "Hi team, I have some queries", main_lang_code, language_code, input);
                          if (
                            /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                              navigator.userAgent
                            )
                          ) {
                            contact_icon.href =
                              "https://api.whatsapp.com/send?phone=" +
                              contact_item1[2].split("+").join("") +
                              contact_item1[3] +
                              "&text=" +
                              k;
                          } else {
                            contact_icon.href =
                              "https://web.whatsapp.com/send?phone=" +
                              contact_item1[2] +
                              contact_item1[3] +
                              "&text=" +
                              k;
                          }
                          slides_div.appendChild(contact_icon);
                        } else if (contact_item1[0] == "live_chat") {
                          contact_img.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/bot_mic.png";
                          contact_icon.classList.add("other-pointer");
                          contact_icon.title = contact_item1[1];
                          contact_icon.addEventListener("click", function (k) {
                            chat_with_us_cliked = !0;
                            mainDiv.click();
                            if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
                              window.Tawk_API.showWidget();
                              Tawk_API.maximize();
                            }
                            try {
                              zE("webWidget", "show");
                              zE("webWidget", "toggle");
                            } catch (e) {
                            } finally {
                            }
                          });
                          slides_div.appendChild(contact_icon);
                        }
                      }
                    }
                    other_option_div.appendChild(slides_div);
                  } else {
                    if (
                      firstCustomSingleChoiceOptions &&
                      firstCustomSingleChoiceOptions.length > 0
                    ) {
                      var first_child = other_take_actions_div.children[0];
                      other_take_actions_div.removeChild(first_child);
                      other_take_actions_div.classList.remove("m-l-40");
                      other_take_actions_div.appendChild(iconDiv);
                      other_take_actions_div.appendChild(first_child);
                    } else {
                      option_div.classList.remove("m-l-40");
                      questionDIv.appendChild(iconDiv);
                    }
                  }
                  take_actions_div.appendChild(other_option_div);
                  setTimeout(function () {
                    if (body.contains(otherSpinningDIv)) {
                      body.appendChild(otherSpinningDIv);
                    }
                    if (body.contains(otherSpinningDIv)) {
                      body.appendChild(otherSpinningDIv);
                    }
                    if (
                      question_array[0].default_options &&
                      question_array[0].default_options.length > 0
                    ) {
                      body.appendChild(take_actions_div);
                    }
                  }, delay_time + 20);
                  setTimeout(function () {
                    if (
                      firstCustomSingleChoiceOptions &&
                      firstCustomSingleChoiceOptions.length > 0 &&
                      other_take_actions_div
                    ) {
                      body.appendChild(other_take_actions_div);
                      if (body.contains(otherSpinningDIv)) {
                        body.appendChild(otherSpinningDIv);
                      }
                    }
                  }, delay_time + 10);
                }
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-10");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (i != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (i == 0) {
                  body.appendChild(questionDIv);
                  questionDIv.appendChild(option_div);
                  if (i == question_arr.length - 1) {
                    if (
                      question_array[0].is_feedback &&
                      question_array[0].is_feedback == "1"
                    ) {
                      option_div.style.marginBottom = "15px";
                      addQuestionFeedback(option_div, question_array);
                    }
                    setTimeout(function () {
                      takingRadioValue("something", option_div, 1);
                    }, delay_time + 40);
                  }
                  i++;
                  if (i == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    body.scrollTop = body.scrollHeight;
                  }
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    body.appendChild(questionDIv);
                    questionDIv.appendChild(option_div);
                    if (i == question_arr.length - 1) {
                      if (
                        question_array[0].is_feedback &&
                        question_array[0].is_feedback == "1"
                      ) {
                        option_div.style.marginBottom = "15px";
                        addQuestionFeedback(option_div, question_array);
                      }
                      setTimeout(function () {
                        takingRadioValue("something", option_div, 1);
                      }, delay_time + 40);
                    }
                    i++;
                    if (i == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      body.scrollTop = body.scrollHeight;
                    }
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            var children = Array.from(body.children);
            var scrollDiv;
            for (var i = children.length - 1; i > 0; i--) {
              if (children[i].id == "custom-answer-question-div-0") {
                scrollDiv = children[i];
                break;
              }
            }
            if (scrollDiv) {
              body.scrollTop = scrollDiv.offsetTop - 75;
            }
          }, 500);
        }

        function callCustomEndChoice(question_array) {
          if (
            question_array[0].question_text &&
            question_array[0].question_text.includes("{{") &&
            question_array[0].question_text.includes("}}")
          ) {
            parseDataReferring(question_array, 0);
          }
          var arr = getParagraphs(question_array[0].question_text);
          var x_arr = arr;
          array = [];
          for (var i = 0; i < x_arr.length; i++) {
            if (x_arr[i]) {
              if (
                (x_arr[i].innerText && x_arr[i].innerText.length > 0) ||
                (x_arr[i].children && x_arr[i].children.length > 0)
              ) {
                array.push(x_arr[i].outerHTML);
              } else {
                x_arr.splice(i, 1);
                i--;
              }
            }
          }
          var question_arr = [];
          if (array && array.length > 0) {
            question_arr = array;
          } else {
            question_arr.push(question_array[0].question_text);
          }
          if (question_arr && question_arr.length > 0) {
            var k = 0;
            var speakable_str = "";

            function addQuestionArrays() {
              if (k < question_arr.length) {
                var questionDIv = document.createElement("DIV");
                questionDIv.classList.add("question-div-smatest");
                setTimeout(function () {
                  questionDIv.classList.add("top-0");
                }, transition_time);
                questionDIv.id =
                  question_array[0].id + ".." + question_array[0].sequence;
                if (font && font.length > 0) {
                  questionDIv.classList.add(font);
                }
                var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                var iconDiv = document.createElement("DIV");
                iconDiv.appendChild(ques_icon1);
                iconDiv.classList.add("question-icon-div");
                ques_icon1.src = avatar_icon;
                ques_icon1.classList.add("question-icon-smatest");
                var option_div = document.createElement("DIV");
                option_div.classList.add("options-div-smatest");
                var main_image_options_div = document.createElement("DIV");
                main_image_options_div.classList.add(
                  "main-options-div-smatest-image"
                );
                main_image_options_div.classList.add("some-animation");
                var option_question = document.createElement("LABEL");
                if (font && font.length > 0) {
                  option_question.classList.add(font);
                }
                if (
                  (main_lang_code &&
                    (main_lang_code == "he" ||
                      main_lang_code == "ur" ||
                      main_lang_code == "ar")) ||
                  (main_lang_code == "default" &&
                    (language_code == "ar" ||
                      language_code == "he" ||
                      language_code == "ur"))
                ) {
                  option_question.classList.add("rtl");
                }
                option_question.innerHTML = question_arr[k].trim();
                speakable_str = speakable_str + " " + option_question.innerText;
                option_div.appendChild(option_question);
                if (k != question_arr.length - 1) {
                  option_div.classList.add("m-l-40");
                }
                if (k == question_arr.length - 1) {
                  questionDIv.appendChild(iconDiv);
                  handleImageModal(question_array, main_image_options_div);
                  var slides_div = document.createElement("DIV");
                  slides_div.classList.add("dialogs-div-more-smatest");
                  slides_div.classList.add("avatar-scrollbar");
                  slides_div.style.cssText =
                    slides_div.style.cssText + "max-height: fit-content !important";
                  slides_div.classList.add("slides-random");
                  slides_div.id = "avatar-scroll";
                  var optionsArray = question_array[0].default_options.split(";;");
                  if (optionsArray && optionsArray.length > 0) {
                    for (var j = 0; j < optionsArray.length; j++) {
                      var selectedKey;
                      var contact = document.createElement("DIV");
                      contact.classList.add("dialogs-div-smatest");
                      if (font && font.length > 0) {
                        contact.classList.add(font);
                      }
                      var label = document.createElement("LABEL");
                      var text = document.createTextNode(optionsArray[j]);
                      label.appendChild(text);
                      speakable_str = speakable_str + " " + label.innerText;
                      if (j != optionsArray.length - 1) {
                        speakable_str = speakable_str + " or ";
                      }
                      contact.appendChild(label);
                      slides_div.appendChild(contact);
                      contact.addEventListener("click", function (e) {
                        var otherSpinningDIv = document.createElement("DIV");
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        otherSpinningDIv.classList.add("m-l-40");
                        otherSpinningDIv.classList.add("m-t-5");
                        otherSpinningDIv.classList.add("pull-left");
                        otherSpinningDIv.appendChild(spinnerDiv);
                        body.appendChild(otherSpinningDIv);
                        body.scrollTop = body.scrollHeight;
                        var value = this.children[0].innerHTML;
                        var arr =
                          this.parentElement.parentElement.previousSibling.id.split(
                            ".."
                          );
                        var xhttpOther = new XMLHttpRequest();
                        xhttpOther.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            if (body.contains(otherSpinningDIv)) {
                              body.removeChild(otherSpinningDIv);
                            }
                            if (
                              JSON.parse(this.responseText).answer_text &&
                              JSON.parse(this.responseText).answer_text.length > 0
                            ) {
                              var answerDialog = JSON.parse(
                                this.responseText
                              ).answer_text;
                            } else {
                              var answerDialog = "";
                            }
                            question_array = JSON.parse(
                              this.responseText
                            ).next_question;
                            input_value = "";
                            var question_arr;
                            setTimeout(function () {
                              footer.style.display = "block";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                              footer.classList.remove("close");
                              if (shouldShowMenu) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                              }
                              input.focus();
                              enter.style.pointerEvents = "auto";
                              if (!entry_id) {
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.blur();
                                    input.placeholder = "Choose from Menu";
                                    input.type = "text";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  }
                                }
                              }
                              enter.style.pointerEvents = "auto";
                              if (answerDialog && answerDialog.length > 0) {
                                if (
                                  answerDialog.includes("<table") &&
                                  answerDialog.includes("</table>")
                                ) {
                                  isTableOpened = !0;
                                  playBotUserSound(1);
                                  nothingWentOnFor = 0;
                                  encourageMessageIteration = 0;
                                  var modal_div = document.createElement("DIV");
                                  if (font && font.length > 0) {
                                    modal_div.classList.add(font);
                                  }
                                  modal_div.classList.add("modal-smatest");
                                  modal_div.id = "myModal";
                                  var modal_content_div =
                                    document.createElement("DIV");
                                  modal_content_div.classList.add(
                                    "modal-content-smatest"
                                  );
                                  var modal_close_span =
                                    document.createElement("SPAN");
                                  modal_close_span.classList.add("close-modal");
                                  modal_close_span.innerHTML = "&times";
                                  var table_div = document.createElement("DIV");
                                  table_div.innerHTML = answerDialog;
                                  table_div.style.color = "black";
                                  modal_content_div.appendChild(modal_close_span);
                                  modal_content_div.appendChild(table_div);
                                  modal_div.appendChild(modal_content_div);
                                  modal_div.style.display = "block";
                                  window.onclick = function (event) {
                                    if (event.target == modal_div) {
                                      modal_div.style.display = "none";
                                      isTableOpened = !1;
                                      nothingWentOnFor = 0;
                                      encourageMessageIteration = 0;
                                    }
                                  };
                                  modal_close_span.addEventListener(
                                    "click",
                                    function (k) {
                                      modal_div.style.display = "none";
                                      isTableOpened = !1;
                                      nothingWentOnFor = 0;
                                      encourageMessageIteration = 0;
                                    }
                                  );
                                  document.body.appendChild(modal_div);
                                } else {
                                  var k = document.createElement("DIV");
                                  k.innerHTML = answerDialog;
                                  var inner_text = k.innerText;
                                  var enable_read_more;
                                  var complete_text = answerDialog;
                                  if (answerDialog && answerDialog.length > 500) {
                                    enable_read_more = true;
                                    answerDialog =
                                      answerDialog.substring(0, 500) + "... ";
                                    k.innerHTML = answerDialog;
                                    answerDialog = k.innerHTML;
                                  }
                                  if (answerDialog.includes("<br/>")) {
                                    question_arr = answerDialog.split("<br/>");
                                  } else if (answerDialog.includes(" /n")) {
                                    question_arr = answerDialog.split(" /n");
                                  } else if (answerDialog.includes(" \n")) {
                                    question_arr = answerDialog.split(" \n");
                                  } else {
                                    question_arr = [];
                                    question_arr.push(answerDialog);
                                  }
                                  if (question_arr && question_arr.length > 0) {
                                    var i = 0;

                                    function addQuestionArrays() {
                                      if (i < question_arr.length) {
                                        var questionDIv =
                                          document.createElement("DIV");
                                        questionDIv.classList.add(
                                          "question-div-smatest"
                                        );
                                        setTimeout(function () {
                                          questionDIv.classList.add("top-0");
                                        }, transition_time);
                                        if (font && font.length > 0) {
                                          questionDIv.classList.add(font);
                                        }
                                        var ques_icon1 =
                                          document.createElement("IMG");
                                        ques_icon1.alt = "Logo of " + totalData[0].name;
                                        ques_icon1.src = avatar_icon;
                                        var iconDiv = document.createElement("DIV");
                                        iconDiv.appendChild(ques_icon1);
                                        iconDiv.classList.add("question-icon-div");
                                        ques_icon1.classList.add(
                                          "question-icon-smatest"
                                        );
                                        var option_div =
                                          document.createElement("DIV");
                                        option_div.classList.add(
                                          "options-div-smatest"
                                        );
                                        var option_question =
                                          document.createElement("LABEL");
                                        option_question.innerHTML =
                                          question_arr[i].trim();
                                        say(option_question.innerText);
                                        option_div.appendChild(option_question);
                                        var timeStamp = new Date().getTime() + Math.floor(Math.random() * 1000);
                                        option_div.id = question_array[0].id + "-" + timeStamp;
                                        // option_div.id = question_array[0].id;
                                        option_div.classList.add("m-l-40");
                                        if (i == question_arr.length - 1) {
                                          if (df_options && df_options.length > 0) {
                                            var optionsArray =
                                              df_options.split(";;");
                                          }
                                          questionDIv.appendChild(iconDiv);
                                          option_div.classList.remove("m-l-40");
                                          questionDIv.appendChild(option_div);
                                          if (enable_read_more) {
                                            var read_more_span =
                                              document.createElement("LABEL");
                                            read_more_span.innerHTML = generateTranslatedContent(translations, "Read more", main_lang_code, language_code, input);
                                            read_more_span.style.cssText = read_more_span.style.cssText + "color:#007bff !important;";
                                            read_more_span.style.fontSize = "14px";
                                            read_more_span.style.cursor = "pointer";
                                            if (font && font.length > 0) {
                                              read_more_span.classList.add(font);
                                            }
                                            var modal_div =
                                              document.createElement("DIV");
                                            if (font && font.length > 0) {
                                              modal_div.classList.add(font);
                                            }
                                            modal_div.classList.add(
                                              "modal-smatest"
                                            );
                                            modal_div.id = "myReadMoreModal" + "-" + question_array[0].id + "-" + timeStamp;
                                            var modal_content_div =
                                              document.createElement("DIV");
                                            modal_content_div.style.width = "60%";
                                            modal_content_div.style.maxHeight =
                                              "calc(100vh - 50px)";
                                            modal_content_div.style.overflowY =
                                              "scroll";
                                            modal_content_div.classList.add(
                                              "modal-content-smatest"
                                            );
                                            var modal_close_span =
                                              document.createElement("SPAN");
                                            modal_close_span.classList.add(
                                              "close-modal"
                                            );
                                            modal_close_span.innerHTML = "&times";
                                            var table_div =
                                              document.createElement("DIV");
                                            table_div.style.paddingTop = "15px";
                                            table_div.style.paddingBotttom = "15px";
                                            table_div.style.paddingLeft = "10px";
                                            table_div.style.paddingRight = "10px";
                                            table_div.style.marginTop = "10px";
                                            table_div.style.marginBotttom = "10px";
                                            table_div.style.color = "black";
                                            table_div.innerHTML = complete_text;
                                            if (font && font.length > 0) {
                                              table_div.classList.add(font);
                                            }
                                            modal_content_div.appendChild(
                                              modal_close_span
                                            );
                                            modal_content_div.appendChild(
                                              table_div
                                            );
                                            modal_div.appendChild(
                                              modal_content_div
                                            );
                                            modal_div.style.display = "none";
                                            read_more_span.addEventListener(
                                              "click",
                                              function () {
                                                var modal_id = "myReadMoreModal" + "-" + this.parentElement.id;
                                                if (
                                                  document.getElementById(modal_id)
                                                ) {
                                                  document.getElementById(
                                                    modal_id
                                                  ).style.display = "block";
                                                }
                                              }
                                            );
                                            window.onclick = function (event) {
                                              if (event.target == modal_div) {
                                                if (modal_div) {
                                                  modal_div.style.display = "none";
                                                  isTableOpened = !1;
                                                  nothingWentOnFor = 0;
                                                  encourageMessageIteration = 0;
                                                }
                                              }
                                            };
                                            modal_close_span.addEventListener(
                                              "click",
                                              function (k) {
                                                if (
                                                  this.parentElement.parentElement
                                                ) {
                                                  this.parentElement.parentElement.style.display =
                                                    "none";
                                                  isTableOpened = !1;
                                                  nothingWentOnFor = 0;
                                                  encourageMessageIteration = 0;
                                                }
                                              }
                                            );
                                            document.body.appendChild(modal_div);
                                            option_div.appendChild(read_more_span);
                                          }
                                          if (
                                            firstCustomSingleChoiceOptions &&
                                            firstCustomSingleChoiceOptions.length >
                                            0
                                          ) {
                                          } else {
                                          }
                                          var take_actions_div =
                                            document.createElement("DIV");
                                          take_actions_div.classList.add(
                                            "question-div-smatest"
                                          );
                                          setTimeout(function () {
                                            take_actions_div.classList.add("top-0");
                                          }, transition_time);
                                          if (font && font.length > 0) {
                                            take_actions_div.classList.add(font);
                                          }
                                          if (font && font.length > 0) {
                                            option_question.classList.add(font);
                                          }
                                          if (
                                            (main_lang_code &&
                                              (main_lang_code == "he" ||
                                                main_lang_code == "ur" ||
                                                main_lang_code == "ar")) ||
                                            (main_lang_code == "default" &&
                                              (language_code == "ar" ||
                                                language_code == "he" ||
                                                language_code == "ur"))
                                          ) {
                                            option_question.classList.add("rtl");
                                          }
                                        }
                                        questionDIv.appendChild(option_div);
                                        var otherSpinningDIv = document.createElement("DIV");
                                        var spinnerDiv =
                                          document.createElement("DIV");
                                        spinnerDiv.classList.add(
                                          "spinner1-smatest"
                                        );
                                        var ques_icon =
                                          document.createElement("IMG");
                                        ques_icon.src = avatar_icon;
                                        ques_icon.alt = "Logo of " + totalData[0].name;
                                        ques_icon.classList.add(
                                          "question-icon-smatest"
                                        );
                                        var inner1 = document.createElement("DIV");
                                        inner1.classList.add("bounce1");
                                        var inner2 = document.createElement("DIV");
                                        inner2.classList.add("bounce2");
                                        var inner3 = document.createElement("DIV");
                                        inner3.classList.add("bounce3");
                                        spinnerDiv.appendChild(inner1);
                                        spinnerDiv.appendChild(inner2);
                                        spinnerDiv.appendChild(inner3);
                                        otherSpinningDIv.classList.add("m-t-10");
                                        otherSpinningDIv.classList.add("m-l-40");
                                        otherSpinningDIv.classList.add("pull-left");
                                        otherSpinningDIv.appendChild(spinnerDiv);
                                        if (i != 0) {
                                          body.appendChild(otherSpinningDIv);
                                          body.scrollTop = body.scrollHeight;
                                        }
                                        if (i == 0) {
                                          if (i == question_arr.length - 1) {
                                            playBotUserSound(1);
                                          }
                                          i++;
                                          body.appendChild(questionDIv);
                                          body.scrollTop = body.scrollHeight;
                                          addQuestionArrays();
                                        } else {
                                          setTimeout(function () {
                                            body.removeChild(otherSpinningDIv);
                                            if (i == question_arr.length - 1) {
                                              playBotUserSound(1);
                                            }
                                            i++;
                                            questionDIv.id = i;
                                            body.appendChild(questionDIv);
                                            body.scrollTop = body.scrollHeight;
                                            addQuestionArrays();
                                          }, delay_time);
                                        }
                                        footer.style.display = "block";
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                        if (shouldShowMenu) {
                                          input.style.pointerEvents = "auto";
                                          microphone.style.pointerEvents = "auto";
                                          microphone.style.opacity = 1;
                                          enter.style.pointerEvents = "auto";
                                        }
                                        input.focus();
                                        footer.classList.remove("close");
                                      }
                                    }
                                    addQuestionArrays();
                                  }
                                }
                              }
                              if (question_array && question_array.length > 0) {
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.blur();
                                    input.placeholder = "Choose from Menu";
                                    input.type = "text";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  }
                                }
                                question_completed = !1;
                                input_value = "";
                                if (question_array && question_array.length > 0) {
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(
                                      current_question_type,
                                      question_array
                                    );
                                  }, delay_time * question_array.length + 100);
                                } else {
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(
                                      current_question_type,
                                      question_array
                                    );
                                  }, 100);
                                }
                              }
                            }, 100);
                          } else if (this.readyState == 4 && this.status == 400) {
                            try {
                              if (body.contains(otherSpinningDIv)) {
                                body.removeChild(otherSpinningDIv);
                              }
                            } catch (error) {
                            }
                            let resp_json = JSON.parse(this.responseText);
                            var errorDiv = document.createElement("DIV");
                            errorDiv.classList.add("question-div-smatest");
                            setTimeout(function () {
                              errorDiv.classList.add("top-0");
                            }, transition_time);
                            if (font && font.length > 0) {
                              errorDiv.classList.add(font);
                            }
                            var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                            error_icon.src = avatar_icon;
                            var iconDiv = document.createElement("DIV");
                            iconDiv.appendChild(error_icon);
                            iconDiv.classList.add("question-icon-div");
                            error_icon.classList.add("question-icon-smatest");
                            var error_text = document.createElement("LABEL");
                            if (
                              resp_json.message &&
                              resp_json.message.length > 0
                            ) {
                              error_text.innerHTML = resp_json.message;
                              say(resp_json.message);
                            } else {
                              error_text.innerHTML =
                                "This feature works only in the Pro plan along with the ChatGPT Addon";
                              say(error_text.innerText);
                            }
                            error_text.classList.add("question-text-error");
                            error_text.classList.add("options-div-smatest");
                            if (font && font.length > 0) {
                              error_text.classList.add(font);
                            }
                            errorDiv.appendChild(iconDiv);
                            errorDiv.appendChild(error_text);
                            body.appendChild(errorDiv);
                            playBotUserSound(1);
                          }
                        };
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0
                          // main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttpOther.open(
                          "GET",
                          main_url +
                          "/kya_backend/pagehub/getChatBotAnswerv2?answer_text=" +
                          encodeURIComponent(value) +
                          "&question_id=" +
                          arr[0] +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&language_code=" +
                          main_lang_code +
                          "&cb_session=" +
                          cb_session,
                          !0
                        );
                        xhttpOther.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        xhttpOther.send();
                      });
                    }
                  }
                  option_div.appendChild(slides_div);
                }
                questionDIv.appendChild(option_div);
                var otherSpinningDIv = document.createElement("DIV");
                var spinnerDiv = document.createElement("DIV");
                spinnerDiv.classList.add("spinner1-smatest");
                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                ques_icon.src = avatar_icon;
                ques_icon.classList.add("question-icon-smatest");
                var inner1 = document.createElement("DIV");
                inner1.classList.add("bounce1");
                var inner2 = document.createElement("DIV");
                inner2.classList.add("bounce2");
                var inner3 = document.createElement("DIV");
                inner3.classList.add("bounce3");
                spinnerDiv.appendChild(inner1);
                spinnerDiv.appendChild(inner2);
                spinnerDiv.appendChild(inner3);
                otherSpinningDIv.classList.add("m-l-40");
                otherSpinningDIv.classList.add("m-t-5");
                otherSpinningDIv.classList.add("pull-left");
                otherSpinningDIv.appendChild(spinnerDiv);
                if (k != 0) {
                  body.appendChild(otherSpinningDIv);
                }
                if (k == 0) {
                  k++;
                  if (k == question_arr.length) {
                    setTimeout(function () {
                      body.appendChild(main_image_options_div);
                    }, delay_time);
                    body.scrollTop = body.scrollHeight;
                  }
                  body.appendChild(questionDIv);
                  addQuestionArrays();
                } else {
                  setTimeout(function () {
                    body.removeChild(otherSpinningDIv);
                    k++;
                    if (k == question_arr.length) {
                      setTimeout(function () {
                        body.appendChild(main_image_options_div);
                      }, delay_time);
                      body.scrollTop = body.scrollHeight;
                    }
                    questionDIv.classList.add("m-t-5");
                    body.appendChild(questionDIv);
                    addQuestionArrays();
                  }, delay_time);
                }
              }
            }
            addQuestionArrays();
            say(speakable_str);
          }
          setTimeout(function () {
            if (body.scrollHeight > 320) {
              body.scrollTop = body.scrollTop + body.offsetHeight + 30;
            } else {
              body.scrollTop = body.scrollHeight;
            }
          }, 100);
        }

        function callTakeAction(question_array, id, seq) {
          setTimeout(function () {
            takingRadioValue("something", "", 1);
          }, 1);
        }

        function callCustomAction() {
          custom_action_id = question_array[0].id;
          custom_action_sequence = question_array[0].sequence;
          setTimeout(function () {
            takingRadioValue("something", "", 1);
          }, 1);
        }

        function callUrlBasedFlow() {
          setTimeout(function () {
            takingRadioValue(window.location.href, "", 1);
          }, 1);
        }

        function callCountryBasedFlow() {
          setTimeout(function () {
            takingRadioValue(user_country_code, "", 1);
          }, 1);
        }

        function previousQuestionsView(prev_questions_array) {
          for (var i = 0; i < prev_questions_array.length; i++) {
            question_and_answers.push({
              id: prev_questions_array[i].question_id,
              answer: prev_questions_array[i].answer_text,
            });
            if (prev_questions_array[i].type == "take_action") {
              take_action_id = prev_questions_array[i].question_id;
              take_action_sequence = prev_questions_array[i].sequence;
            }
            if (prev_questions_array[i].type == "custom_actions") {
              custom_action_id = prev_questions_array[i].question_id;
              custom_action_sequence = prev_questions_array[i].sequence;
            }
            if (prev_questions_array[i].type == "custom_entry") {
              entry_id = prev_questions_array[i].question_id;
              df_options = prev_questions_array[i].default_options;
              footer.style.display = "block";
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              footer.classList.remove("close");
              if (shouldShowMenu) {
                input.style.pointerEvents = "auto";
                microphone.style.pointerEvents = "auto";
                microphone.style.opacity = 1;
                enter.style.pointerEvents = "auto";
              }
              input.focus();
              translateContent(translations, input, "Type your query", main_lang_code, language_code, 2);
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
            }
            if (
              prev_questions_array[i].type != "contact" &&
              prev_questions_array[i].type != "slides" &&
              prev_questions_array[i].type != "custom_single_choice" &&
              prev_questions_array[i].type != "take_action" &&
              prev_questions_array[i].type != "custom_actions" &&
              prev_questions_array[i].type != "user_question" &&
              prev_questions_array[i].type != "images_slider" &&
              prev_questions_array[i].type != "audio" &&
              prev_questions_array[i].type != "show_file" &&
              prev_questions_array[i].type != "show_location" &&
              prev_questions_array[i].type != "show_contacts"
            ) {
              if (prev_questions_array[i].type == "location") {
                if (
                  prev_questions_array[i].question_text &&
                  prev_questions_array[i].question_text.includes("{{") &&
                  prev_questions_array[i].question_text.includes("}}")
                ) {
                  parseDataReferring(prev_questions_array, i);
                }
                var arr = getParagraphs(prev_questions_array[i].question_text);
                var x_arr = arr;
                array = [];
                for (var p = 0; p < x_arr.length; p++) {
                  if (x_arr[p]) {
                    if (
                      (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                      (x_arr[p].children && x_arr[p].children.length > 0)
                    ) {
                      array.push(x_arr[p].outerHTML);
                    } else {
                      x_arr.splice(p, 1);
                      p--;
                    }
                  }
                }
                var question_arr = [];
                if (array && array.length > 0) {
                  question_arr = array;
                } else {
                  question_arr.push(prev_questions_array[i].question_text);
                }
                if (question_arr && question_arr.length > 0) {
                  var k = 0;

                  function addQuestionArrays() {
                    if (k < question_arr.length) {
                      var questionDIv = document.createElement("DIV");
                      questionDIv.classList.add("question-div-smatest");
                      questionDIv.classList.add("top-0");
                      if (font && font.length > 0) {
                        questionDIv.classList.add(font);
                      }
                      var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                      ques_icon1.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon1);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon1.classList.add("question-icon-smatest");
                      var option_div = document.createElement("DIV");
                      var option_question = document.createElement("LABEL");
                      option_div.classList.add("options-div-smatest");
                      var main_image_options_div = document.createElement("DIV");
                      main_image_options_div.classList.add(
                        "main-options-div-smatest-image"
                      );
                      main_image_options_div.classList.add("some-animation");
                      var option_question = document.createElement("LABEL");
                      if (font && font.length > 0) {
                        option_question.classList.add(font);
                      }
                      if (
                        (main_lang_code &&
                          (main_lang_code == "he" ||
                            main_lang_code == "ur" ||
                            main_lang_code == "ar")) ||
                        (main_lang_code == "default" &&
                          (language_code == "ar" ||
                            language_code == "he" ||
                            language_code == "ur"))
                      ) {
                        option_question.classList.add("rtl");
                      }
                      option_question.innerHTML = question_arr[k].trim();
                      say(option_question.innerText);
                      option_div.appendChild(option_question);
                      if (k != question_arr.length - 1) {
                        option_div.classList.add("m-l-40");
                      }
                      if (k == question_arr.length - 1) {
                        questionDIv.appendChild(iconDiv);
                        if (
                          prev_questions_array[i].image_url &&
                          prev_questions_array[i].image_url.length > 0 &&
                          prev_questions_array[i].image_url != "null" &&
                          (prev_questions_array[i].image_url.includes(
                            "s3.ap-south-1.amazonaws.com"
                          ) ||
                            prev_questions_array[i].image_url.includes(
                              "media.tenor.com"
                            ) ||
                            prev_questions_array[i].image_url.includes("giphy.com"))
                        ) {
                          var imgDiv = document.createElement("DIV");
                          imgDiv.classList.add("image-div-smatest");
                          var questionImg = document.createElement("IMG");
                          questionImg.src = prev_questions_array[i].image_url;
                          questionImg.classList.add("question-img-smatest");
                          imgDiv.appendChild(questionImg);
                          main_image_options_div.appendChild(imgDiv);
                        }
                        if (
                          prev_questions_array[i].type == "statement" ||
                          prev_questions_array[i].type == "url_auto_redirect"
                        ) {
                          option_div.classList.add("m-b-10");
                          iconDiv.classList.add("m-b-10");
                        }
                      }
                      questionDIv.appendChild(option_div);
                      k++;
                      if (k == question_arr.length) {
                        body.appendChild(main_image_options_div);
                        body.scrollTop = body.scrollHeight;
                      }
                      body.appendChild(questionDIv);
                      body.scrollTop = body.scrollHeight;
                      addQuestionArrays();
                      if (k != 0) {
                        questionDIv.classList.add("m-t-5");
                      }
                    }
                  }
                  addQuestionArrays();
                }
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                var locationAns = prev_questions_array[i].answer_text;
                var text2 = document.createTextNode(locationAns);
                answer_text1.appendChild(text2);
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                if (
                  prev_questions_array[i].type != "statement" &&
                  prev_questions_array[i].type != "url_auto_redirect"
                ) {
                  body.appendChild(prevAnswerDiv);
                  body.scrollTop = body.scrollHeight;
                }
              } else if (prev_questions_array[i].type == "url_flow") {
              } else if (prev_questions_array[i].type == "country_based_flow") {
              } else if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.length > 0
              ) {
                if (
                  prev_questions_array[i].question_text &&
                  prev_questions_array[i].question_text.includes("{{") &&
                  prev_questions_array[i].question_text.includes("}}")
                ) {
                  parseDataReferring(prev_questions_array, i);
                }
                var enable_read_more;
                var complete_text;
                if (prev_questions_array[i].type == "statement") {
                  var k = document.createElement("DIV");
                  k.innerHTML = prev_questions_array[i].question_text;
                  var inner_text = k.innerText;
                  complete_text = prev_questions_array[i].question_text;
                  if (inner_text && inner_text.length > 500) {
                    enable_read_more = true;
                    inner_text = inner_text.substring(0, 500) + "... ";
                    k.innerText = inner_text;
                    prev_questions_array[i].question_text = k.innerHTML;
                  }
                }
                var arr = getParagraphs(prev_questions_array[i].question_text);
                var x_arr = arr;
                array = [];
                for (var p = 0; p < x_arr.length; p++) {
                  if (x_arr[i]) {
                    if (
                      (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                      (x_arr[p].children && x_arr[p].children.length > 0)
                    ) {
                      array.push(x_arr[p].outerHTML);
                    } else {
                      x_arr.splice(p, 1);
                      p--;
                    }
                  }
                }
                var question_arr = [];
                if (array && array.length > 0) {
                  question_arr = array;
                } else {
                  question_arr.push(prev_questions_array[i].question_text);
                }
                if (question_arr && question_arr.length > 0) {
                  var k = 0;

                  function addQuestionArrays() {
                    if (k < question_arr.length) {
                      var questionDIv = document.createElement("DIV");
                      questionDIv.classList.add("question-div-smatest");
                      questionDIv.classList.add("top-0");
                      if (font && font.length > 0) {
                        questionDIv.classList.add(font);
                      }
                      var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                      ques_icon1.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon1);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon1.classList.add("question-icon-smatest");
                      var option_div = document.createElement("DIV");
                      var option_question = document.createElement("LABEL");
                      option_div.classList.add("options-div-smatest");
                      var main_image_options_div = document.createElement("DIV");
                      main_image_options_div.classList.add(
                        "main-options-div-smatest-image"
                      );
                      main_image_options_div.classList.add("some-animation");
                      var option_question = document.createElement("LABEL");
                      if (font && font.length > 0) {
                        option_question.classList.add(font);
                      }
                      if (
                        (main_lang_code &&
                          (main_lang_code == "he" ||
                            main_lang_code == "ur" ||
                            main_lang_code == "ar")) ||
                        (main_lang_code == "default" &&
                          (language_code == "ar" ||
                            language_code == "he" ||
                            language_code == "ur"))
                      ) {
                        option_question.classList.add("rtl");
                      }
                      option_question.innerHTML = question_arr[k].trim();
                      say(option_question.innerText);
                      option_div.appendChild(option_question);
                      if (k != question_arr.length - 1) {
                        option_div.classList.add("m-l-40");
                      }
                      if (k == question_arr.length - 1) {
                        questionDIv.appendChild(iconDiv);
                        if (
                          enable_read_more &&
                          prev_questions_array[i].type == "statement"
                        ) {
                          enable_read_more = false
                          var timeStamp = new Date().getTime() + Math.floor(Math.random() * 1000);
                          option_div.id = prev_questions_array[i].id + "-" + timeStamp;
                          var read_more_span = document.createElement("LABEL");
                          read_more_span.innerHTML = generateTranslatedContent(translations, "Read more", main_lang_code, language_code, input);
                          read_more_span.style.cssText = read_more_span.style.cssText + "color:#007bff !important;";
                          read_more_span.style.fontSize = "14px";
                          read_more_span.style.cursor = "pointer";
                          if (font && font.length > 0) {
                            read_more_span.classList.add(font);
                          }
                          var modal_div = document.createElement("DIV");
                          if (font && font.length > 0) {
                            modal_div.classList.add(font);
                          }
                          modal_div.classList.add("modal-smatest");
                          modal_div.id = "myReadMoreModal" + "-" + prev_questions_array[i].id + "-" + timeStamp;
                          var modal_content_div = document.createElement("DIV");
                          modal_content_div.style.width = "60%";
                          modal_content_div.style.maxHeight = "calc(100vh - 50px)";
                          modal_content_div.style.overflowY = "scroll";
                          modal_content_div.classList.add("modal-content-smatest");
                          var modal_close_span = document.createElement("SPAN");
                          modal_close_span.classList.add("close-modal");
                          modal_close_span.innerHTML = "&times";
                          var table_div = document.createElement("DIV");
                          table_div.style.paddingTop = "15px";
                          table_div.style.paddingBotttom = "15px";
                          table_div.style.paddingLeft = "10px";
                          table_div.style.paddingRight = "10px";
                          table_div.style.marginTop = "10px";
                          table_div.style.marginBotttom = "10px";
                          table_div.style.color = "black";
                          table_div.innerHTML = complete_text;
                          if (font && font.length > 0) {
                            table_div.classList.add(font);
                          }
                          modal_content_div.appendChild(modal_close_span);
                          modal_content_div.appendChild(table_div);
                          modal_div.appendChild(modal_content_div);
                          modal_div.style.display = "none";
                          read_more_span.addEventListener("click", function () {
                            var modal_id =
                              "myReadMoreModal" + "-" + this.parentElement.id;
                            if (document.getElementById(modal_id)) {
                              document.getElementById(modal_id).style.display =
                                "block";
                            }
                          });
                          window.onclick = function (event) {
                            if (event.target == modal_div) {
                              if (modal_div) {
                                modal_div.style.display = "none";
                                isTableOpened = !1;
                                nothingWentOnFor = 0;
                                encourageMessageIteration = 0;
                              }
                            }
                          };
                          modal_close_span.addEventListener("click", function (k) {
                            if (this.parentElement.parentElement) {
                              this.parentElement.parentElement.style.display =
                                "none";
                              isTableOpened = !1;
                              nothingWentOnFor = 0;
                              encourageMessageIteration = 0;
                            }
                          });
                          document.body.appendChild(modal_div);
                          option_div.appendChild(read_more_span);
                        }
                        if (
                          prev_questions_array[i].type == "statement" ||
                          prev_questions_array[i].type == "url_auto_redirect" ||
                          prev_questions_array[i].type == "slides" ||
                          prev_questions_array[i].type == "contact" ||
                          prev_questions_array[i].type == "show_file" ||
                          prev_questions_array[i].type == "show_contacts" ||
                          prev_questions_array[i].type == "show_location"
                        ) {
                          option_div.classList.add("m-b-10");
                          iconDiv.classList.add("m-b-10");
                        }
                        if (
                          prev_questions_array[i].image_url &&
                          prev_questions_array[i].image_url.length > 0 &&
                          prev_questions_array[i].image_url != "null" &&
                          (prev_questions_array[i].image_url.includes(
                            "s3.ap-south-1.amazonaws.com"
                          ) ||
                            prev_questions_array[i].image_url.includes(
                              "media.tenor.com"
                            ) ||
                            prev_questions_array[i].image_url.includes("giphy.com"))
                        ) {
                          var imgDiv = document.createElement("DIV");
                          imgDiv.classList.add("image-div-smatest");
                          var questionImg = document.createElement("IMG");
                          questionImg.src = prev_questions_array[i].image_url;
                          questionImg.classList.add("question-img-smatest");
                          imgDiv.appendChild(questionImg);
                          main_image_options_div.appendChild(imgDiv);
                        }
                        if (
                          prev_questions_array[i].is_feedback &&
                          prev_questions_array[i].is_feedback == "1"
                        ) {
                          var arr = [];
                          arr.push(prev_questions_array[i]);
                          option_div.style.marginBottom = "15px";
                          addQuestionFeedback(option_div, arr);
                        }
                      }
                      questionDIv.appendChild(option_div);
                      k++;
                      if (
                        prev_questions_array[i].type == "custom_entry" &&
                        prev_questions_array[i].answer_text == "Booked"
                      ) {
                      } else {
                        body.appendChild(questionDIv);
                        body.scrollTop = body.scrollHeight;
                      }
                      addQuestionArrays();
                      if (k != 0) {
                        questionDIv.classList.add("m-t-5");
                      }
                      if (k == question_arr.length) {
                        body.appendChild(main_image_options_div);
                        body.scrollTop = body.scrollHeight;
                      }
                    }
                  }
                  addQuestionArrays();
                }
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                if (prev_questions_array[i].type == "form") {
                  try {
                    var json = JSON.parse(prev_questions_array[i].answer_text);
                    var keys = Object.keys(json);
                    var loc_div = document.createElement("DIV");
                    var label = document.createElement("LABEL");
                    label.innerHTML = "Form Submitted Successfully";
                    label.style.marginBottom = "10px";
                    label.style.fontWeight = "bold";
                    label.style.borderBottom = "1px dotted white";
                    label.style.paddingBottom = "10px";
                    label.style.float = "left";
                    label.style.width = "100%";
                    if (font && font.length > 0) {
                      label.classList.add(font);
                    }
                    loc_div.appendChild(label);
                    for (var n = 0; n < keys.length; n++) {
                      var label = document.createElement("LABEL");
                      label.style.float = "left";
                      label.style.width = "100%";
                      label.style.marginTop = "3px";
                      label.style.marginBottom = "3px";
                      if (font && font.length > 0) {
                        label.classList.add(font);
                      }
                      label.innerHTML = keys[n] + " : " + json[keys[n]];
                      loc_div.appendChild(label);
                    }
                    if (answer_text1) {
                      answer_text1.innerHTML = loc_div.innerHTML;
                    }
                  } catch (e) {
                  } finally {
                  }
                } else {
                }
                if (prev_questions_array[i].type == "file_upload") {

                  var valArray = prev_questions_array[i].answer_text.split(',');
    
                  function isURL(str) {
                    const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
                    return urlPattern.test(str);
                  }
                  
                  const getFileExtension = (filename) => {
                    const dotIndex = filename.lastIndexOf('.');
                    return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
                  };
                  
                  function insertLinkTags(text) {
                    // Define a regular expression pattern to match URLs
                    const urlPattern = /(https?:\/\/\S+)/g;
                  
                    // Replace each URL with a formatted link
                    const result = text.replace(urlPattern, '<div><a href="$1" target="_blank">$1</a></div>');
                  
                    return result;
                  }
                  
                  const fileTypeConvert = (fileData) => {
                    const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                    const extension = getFileExtension(filename).toLowerCase();
                    let FileContainer;
                  
                    if (['png', 'jpg', 'jpeg', 'svg', 'tif', 'gif','ico','webp'].includes(extension)) {
                      let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                      FileContainer = `
                        <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end " >
                          <img src="${fileData}" alt='${link}'  class='file-upload_image_style_sb'/>
                        </a>
                      `;
                    } else if (['mp3', 'wav'].includes(extension)) {
                      FileContainer = `<audio style="width: 285px;" controls src="${fileData}"></audio>`;
                    } else if (['mp4', 'webm', 'flv','mov'].includes(extension)) {
                      let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                      FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;" width='100%' height='150px'></video>`;
                    } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                      let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                      // FileContainer = `<a href="${fileData}" target="_blank">${link}</a>`;
                      FileContainer = `
                      <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                        <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt=''  width='25px' height='25px'/>
                        <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                        <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                          <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                        </a>
                      </div>`
                    
                    } else if (fileData.includes('https://') || fileData.includes('http://')) {
                      FileContainer = insertLinkTags(fileData);
                    } else {
                      FileContainer = fileData;
                    }
                  
                    return FileContainer;
                  };
    
                  valArray.forEach(function(item) {
                
        
                    const linkElement = document.createElement('div');
                    linkElement.style.margin ='12px auto'
                    linkElement.innerHTML = fileTypeConvert(item.trim());
                    answer_text1.appendChild(linkElement);
        
                  });
                  answer_text1.style.background ='transparent'
        
                  
                }else{}
    
                if (prev_questions_array[i].type != "form" && prev_questions_array[i].type != "file_upload") {

                  if (prev_questions_array[i].type == "question") {
                    if (prev_questions_array[i].default_options && prev_questions_array[i].default_options.length > 0) {
                      var json = JSON.parse(prev_questions_array[i].default_options);
                      if (json.data_mask && prev_questions_array[i].answer_text != 'skipped') {
                        var text2 = document.createTextNode(prev_questions_array[i].answer_text.replace(/./g, '*'));
                      } else {
                        var text2 = document.createTextNode(prev_questions_array[i].answer_text);
                      }
                    } else {
                      var text2 = document.createTextNode(prev_questions_array[i].answer_text);
                    }
                  } else {
                    if (prev_questions_array[i].type == "radio") {
                      // var text2 = document.createTextNode(prev_questions_array[i].answer_text);
                      var text2 = document.createElement("DIV")
                      text2.innerHTML = prev_questions_array[i].answer_text;
                    }else{
                      var text2 = document.createTextNode(prev_questions_array[i].answer_text);
                    }
                  }

                  // var text2 = document.createTextNode( prev_questions_array[i].answer_text);

                  answer_text1.appendChild(text2);
                }
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                if (
                  prev_questions_array[i].type != "statement" &&
                  prev_questions_array[i].type != "url_auto_redirect"
                ) {
                  if (
                    prev_questions_array[i].type == "custom_entry" &&
                    prev_questions_array[i].answer_text == "Booked"
                  ) {
                  } else {
                    body.appendChild(prevAnswerDiv);
                    body.scrollTop = body.scrollHeight;
                  }
                }
              }
            } else if (prev_questions_array[i].type == "custom_single_choice") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;

                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      ".." +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var main_options_div = document.createElement("DIV");
                    main_options_div.classList.add("main-options-div-smatest");
                    main_options_div.classList.add("some-animation");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.classList.add("white-space-normal");
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (k != question_arr.length - 1) {
                      option_div.classList.add("m-l-40");
                    }
                    if (k == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com"))
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = prev_questions_array[i].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_image_options_div.appendChild(imgDiv);
                      }
                      option_div.classList.add("options-div-smatest");
                      option_div.classList.add("dialogs-div-more-vertical-smatest");
                      var slides_div = document.createElement("DIV");
                      slides_div.classList.add("avatar-vertical-scrollbar");
                      slides_div.style.cssText =
                        slides_div.style.cssText +
                        "max-height: fit-content !important";
                      slides_div.classList.add("slides-random");
                      slides_div.id = "avatar-scroll";
                      if (prev_questions_array[i].error_text && prev_questions_array[i].error_text == 'dropdown') {
                        var select = document.createElement("SELECT");
                        select.id = "csc-type-dropdown";
                        select.classList.add("options-dropdown");
                        var optionsArray =
                          prev_questions_array[i].default_options.split(";;");
                        var option = document.createElement("OPTION");
                        option.value = "";
                        option.innerHTML = generateTranslatedContent(translations, "Select an option", main_lang_code, language_code, input);
                        select.appendChild(option);
                        for (var p = 0; p < optionsArray.length; p++) {
                          var option = document.createElement("OPTION");
                          option.value = optionsArray[p];
                          if (prev_questions_array[i].answer_text == optionsArray[p]) {
                            option.selected = true;
                            select.value = optionsArray[p];
                          }
                          option.innerHTML = optionsArray[p];
                          select.appendChild(option);
                          if (font && font.length > 0) {
                            option.classList.add(font);
                          }
                        }
                        var confirm_button = document.createElement("BUTTON");
                        confirm_button.classList.add("confirm-btn-smatest");
                        if (font && font.length > 0) {
                          confirm_button.classList.add(font);
                        }
                        if (translations && translations.length > 0) {
                          for (var t = 0; t < translations.length; t++) {
                            if (translations[t].keyword == "Confirm") {
                              confirm_button.innerHTML = translations[t].translation;
                              if (
                                (main_lang_code &&
                                  (main_lang_code == "he" ||
                                    main_lang_code == "ur" ||
                                    main_lang_code == "ar")) ||
                                (main_lang_code == "default" &&
                                  (language_code == "ar" ||
                                    language_code == "he" ||
                                    language_code == "ur"))
                              ) {
                                confirm_button.classList.add("rtl");
                              }
                            }
                          }
                          if (confirm_button.innerHTML == "") {
                            confirm_button.innerHTML = "Confirm";
                          }
                        } else {
                          confirm_button.innerHTML = "Confirm";
                        }
                        confirm_button.style.pointerEvents = "none";
                        confirm_button.style.opacity = "0.6";
                        select.addEventListener("change", function (k) {
                          if (this.value && this.value.length > 0) {
                            confirm_button.style.pointerEvents = "auto";
                            confirm_button.style.opacity = "1";
                          } else {
                            confirm_button.style.pointerEvents = "none";
                            confirm_button.style.opacity = "0.6";
                          }
                        });
                        confirm_button.addEventListener("click", function (k) {
                          if (document.getElementById("csc-type-dropdown")) {
                            var drp = document.getElementById("csc-type-dropdown");
                            if (drp.value && drp.value.length > 0) {
                              if (agreed) {
                                var arr =
                                  this.parentElement.previousSibling.id.split(
                                    ".."
                                  );
                                if (!shouldDisableTakeAction) {
                                  if (
                                    footer &&
                                    (input.style.pointerEvents == "none" ||
                                      footer.style.display == "none")
                                  ) {
                                    takingRadioValue(
                                      drp.value,
                                      this.parentElement,
                                      2,
                                      arr[0],
                                      arr[1],
                                      "c_s_c"
                                    );
                                  } else {
                                    if (input && input.placeholder == "Type your query") {
                                      takingRadioValue(
                                        drp.value,
                                        this.parentElement,
                                        2,
                                        arr[0],
                                        arr[1],
                                        "c_s_c"
                                      );
                                    } else {
                                      if (
                                        current_question_type != "statement" &&
                                        current_question_type != "url_auto_redirect" &&
                                        current_question_type != "contact" &&
                                        current_question_type != "slides" &&
                                        current_question_type != "audio" &&
                                        current_question_type != "custom_answer" &&
                                        current_question_type != "custom_actions" &&
                                        current_question_type != "show_file" &&
                                        current_question_type != "show_location" &&
                                        current_question_type != "show_contacts"
                                      ) {
                                        // if (body && body.lastChild) {
                                        //   body.removeChild(body.lastChild);
                                        // }
                                      }
                                      takingRadioValue(
                                        drp.value,
                                        this.parentElement,
                                        2,
                                        arr[0],
                                        arr[1],
                                        "c_s_c"
                                      );
                                    }
                                  }
                                }
                              } else {
                                k.preventDefault();
                              }
                            }
                          }
                        });
                        main_options_div.appendChild(select);
                        main_options_div.appendChild(confirm_button);
                        if (font && font.length > 0) {
                          select.classList.add(font);
                        }
                      } else {
                        var optionsArray =
                          prev_questions_array[i].default_options.split(";;");
                        if (optionsArray && optionsArray.length > 0) {
                          for (var j = 0; j < optionsArray.length; j++) {
                            var selectedKey;
                            var contact = document.createElement("DIV");
                            contact.classList.add("dialogs-div-vertical-smatest");
                            if (font && font.length > 0) {
                              contact.classList.add(font);
                            }
                            var label = document.createElement("LABEL");
                            var text = document.createTextNode(optionsArray[j]);
                            label.appendChild(text);
                            contact.appendChild(label);
                            slides_div.appendChild(contact);
                            contact.addEventListener("click", function (e) {
                              var value = this.children[0].innerHTML;
                              var arr =
                                this.parentElement.parentElement.previousSibling.id.split(
                                  ".."
                                );
                              if (!shouldDisableTakeAction) {
                                if (
                                  footer &&
                                  (input.style.pointerEvents == "none" ||
                                    footer.style.display == "none")
                                ) {
                                  takingRadioValue(
                                    value,
                                    this.parentElement,
                                    2,
                                    arr[0],
                                    arr[1],
                                    "c_s_c"
                                  );
                                } else {
                                  if (
                                    input &&
                                    input.placeholder == "Type your query"
                                  ) {
                                    takingRadioValue(
                                      value,
                                      this.parentElement,
                                      2,
                                      arr[0],
                                      arr[1],
                                      "c_s_c"
                                    );
                                  }
                                }
                              }
                            });
                          }
                          main_options_div.appendChild(slides_div);
                        }
                      }
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.appendChild(main_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
              var prevAnswerDiv = document.createElement("DIV");
              prevAnswerDiv.classList.add("answer-div");
              prevAnswerDiv.classList.add("top-0");
              var answer_text1 = document.createElement("LABEL");
              var text2 = document.createTextNode(
                prev_questions_array[i].answer_text
              );
              answer_text1.appendChild(text2);
              answer_text1.classList.add("answer-label");
              if (font && font.length > 0) {
                answer_text1.classList.add(font);
              }
              if (font && font.length > 0) {
                answer_text1.classList.add(font);
              }
              prevAnswerDiv.appendChild(answer_text1);
              if (
                prev_questions_array[i].type != "statement" &&
                prev_questions_array[i].type != "url_auto_redirect"
              ) {
                if (
                  prev_questions_array[i].type == "custom_entry" &&
                  prev_questions_array[i].answer_text == "Booked"
                ) {
                } else {
                  body.appendChild(prevAnswerDiv);
                  body.scrollTop = body.scrollHeight;
                }
              }
            } else if (prev_questions_array[i].type == "contact") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                // var k = 0;
                function addQuestionArrays() {
                  if (contact_key < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var main_options_div = document.createElement("DIV");
                    main_options_div.classList.add("main-options-div-smatest");
                    main_options_div.classList.add("some-animation");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.innerHTML = question_arr[contact_key].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (contact_key != question_arr.length - 1) {
                      option_div.classList.add("m-l-40");
                    }
                    if (contact_key == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      option_div.classList.add("m-b-10");
                      iconDiv.classList.add("m-b-10");
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com"))
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = prev_questions_array[i].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_image_options_div.appendChild(imgDiv);
                      }
                      option_div.classList.add("options-div-smatest");
                      if (prev_questions_array[i].default_options) {
                        var contact_list =
                          prev_questions_array[i].default_options.split(";;");
                        for (var j = 0; j < contact_list.length; j++) {
                          var contact_item1 = contact_list[j].split("..");
                          if (
                            contact_item1[0] != "faqs" &&
                            contact_item1[0] != "schedule"
                          ) {
                            var contact = document.createElement("DIV");
                            contact.classList.add("contact-div-smatest");
                            if (font && font.length > 0) {
                              contact.classList.add(font);
                            }
                            var contact_icon = document.createElement("IMG");
                            var contact_item = document.createElement("A");
                            contact_item.title = "Contact redirection";
                            if (chatbot_id != 10561 && chatbot_id != 14372) {
                              contact_item.style.height = "20px";
                              contact_item.style.lineHeight = "20px";
                            }
                            contact_item.classList.add("text-black");
                            if (font && font.length > 0) {
                              contact_item.classList.add(font);
                            }
                            if (contact_item1[0] == "facebook") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/fb_navigator.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "twitter") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/twitter_navigator.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "instagram") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/insta_navigator.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "linkedin") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/linkedin_navigator.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "messenger") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/messenger_navigator.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "zendesk") {
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/zendesk_navigator.png";
                              contact_item.addEventListener("click", function () {
                                try {
                                  mainDiv.click();
                                  zE("webWidget", "show");
                                  zE("webWidget", "toggle");
                                } catch (e) {
                                } finally {
                                }
                              });
                            } else if (contact_item1[0] == "tawkto") {
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/tawkto_navigator.png";
                              contact_item.addEventListener("click", function () {
                                chat_with_us_cliked = true;
                                try {
                                  if (
                                    window.Tawk_API &&
                                    window.Tawk_API.isChatHidden()
                                  ) {
                                    window.Tawk_API.showWidget();
                                    Tawk_API.maximize();
                                  } else if (window.Tawk_API) {
                                    Tawk_API.maximize();
                                  }
                                } catch (e) {
                                } finally {
                                }
                                mainDiv.click();
                              });
                            } else if (contact_item1[0] == "refresh") {
                              contact_item.classList.add("pointer");
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/refresh_navigator.png";
                              contact_item.addEventListener("click", function () {
                                if (reload_div) {
                                  reload_div.click();
                                }
                              });
                            } else if (contact_item1[0] == "close") {
                              contact_item.classList.add("pointer");
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/close_navigator.png";
                              contact_item.addEventListener("click", function () {
                                mainDiv.click();
                              });
                            } else if (contact_item1[0] == "url") {
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/click_navigator.png";
                              contact_item.href = contact_item1[2];
                              if (contact_item1[3] && contact_item1[3].length > 0) {
                                if (contact_item1[3] == "2") {
                                  contact_item.target = "_blank";
                                }
                              }
                            } else if (contact_item1[0] == "youtube") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/youtube_navigator.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "google") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/google-plus.png";
                              contact_item.href = contact_item1[2];
                            } else if (contact_item1[0] == "call") {
                              if (call_fore == "white") {
                                contact_icon.src =
                                  "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/call_white.png";
                              } else {
                                contact_icon.src =
                                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/call_navigator.png";
                              }
                              contact_item.href = "tel:" + contact_item1[2];
                            } else if (contact_item1[0] == "schedule") {
                              contact_icon.classList.add("other-pointer");
                              contact_item.classList.add("other-pointer");
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/schedule.png";
                              contact_item.addEventListener("click", function (k) {
                                clickSchedule(contact_item1[1]);
                              });
                            } else if (contact_item1[0] == "whatsapp") {
                              contact_icon.target = "_blank";
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/whatsapp_navigator.png";
                              var k;
                              if (translations && translations.length > 0) {
                                for (var x = 0; x < translations.length; x++) {
                                  if (
                                    translations[x].keyword ==
                                    "Hi team, I have some queries"
                                  ) {
                                    k = translations[x].translation;
                                    if (
                                      (main_lang_code &&
                                        (main_lang_code == "he" ||
                                          main_lang_code == "ur" ||
                                          main_lang_code == "ar")) ||
                                      (main_lang_code == "default" &&
                                        (language_code == "ar" ||
                                          language_code == "he" ||
                                          language_code == "ur"))
                                    ) {
                                      input.classList.add("rtl");
                                    }
                                  }
                                }
                              } else {
                                k = "Hi team, I have some queries";
                              }
                              if (
                                /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                                  navigator.userAgent
                                )
                              ) {
                                contact_item.href =
                                  "https://api.whatsapp.com/send?phone=" +
                                  contact_item1[2].split("+").join("") +
                                  contact_item1[3] +
                                  "&text=" +
                                  k;
                              } else {
                                contact_item.href =
                                  "https://web.whatsapp.com/send?phone=" +
                                  contact_item1[2] +
                                  contact_item1[3] +
                                  "&text=" +
                                  k;
                              }
                            }
                            contact_icon.classList.add("contact-icon-smatest");
                            var contact_text;
                            if (chatbot_id == 10561 || chatbot_id == 14372) {
                              contact_text = document.createElement("P");
                            } else {
                              contact_text = document.createElement("SPAN");
                            }
                            var text10 = document.createTextNode(contact_item1[1]);
                            contact_text.appendChild(text10);
                            if (
                              contact_item1[0] != "call" &&
                              contact_item1[0] != "url"
                            ) {
                              contact_item.target = "_blank";
                            } else {
                              if (chatbot_id == 10561 || chatbot_id == 14372) {
                                contact_item.title = contact_item1[1];
                              }
                            }
                            contact_item.appendChild(contact_text);
                            contact_item.appendChild(contact_icon);
                            contact.appendChild(contact_item);
                            main_options_div.appendChild(contact);
                          }
                        }
                      }
                    }
                    questionDIv.appendChild(option_div);
                    contact_key++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (contact_key != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (contact_key == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.appendChild(main_options_div);
                      body.scrollTop = body.scrollHeight;
                      option_div.classList.remove("m-b-10");
                      iconDiv.classList.remove("m-b-10");
                    }
                  }
                }
                addQuestionArrays();
              }
            } else if (prev_questions_array[i].type == "images_slider") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;
                var prev_qsn = prev_questions_array[i];
    
                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement('DIV');
                    questionDIv.classList.add('question-div-smatest');
                    questionDIv.classList.add('top-0');
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement('IMG');
                    ques_icon1.alt = 'Logo of ' + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement('DIV');
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add('question-icon-div');
                    ques_icon1.classList.add('question-icon-smatest');
                    var option_div = document.createElement('DIV');
                    var main_options_div = document.createElement('DIV');
                    main_options_div.classList.add('some-animation');
                    var option_question = document.createElement('LABEL');
                    option_div.classList.add('options-div-smatest');
                    var option_question = document.createElement('LABEL');
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == 'he' ||
                          main_lang_code == 'ur' ||
                          main_lang_code == 'ar')) ||
                      (main_lang_code == 'default' &&
                        (language_code == 'ar' ||
                          language_code == 'he' ||
                          language_code == 'ur'))
                    ) {
                      option_question.classList.add('rtl');
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (k != question_arr.length - 1) {
                      option_div.classList.add('m-l-40');
                    }
                    if (k == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      option_div.classList.add('options-div-smatest');
                      if (
                        prev_questions_array[i].default_options &&
                        prev_questions_array[i].default_options.length > 0
                      ) {
                        main_options_div.style.height = '270px';
                      }
    
                      main_options_div.style.width = '100%';
                      main_options_div.style.position = 'relative';
                      main_options_div.style.float = 'left';
                      main_options_div.style.overflowY = 'hidden';
                      main_options_div.style.top = '4px';
    
                      var slides_div = document.createElement('DIV');
                      slides_div.classList.add('swiper-container_sb');
                      slides_div.style.overflow = 'hidden';
                      slides_div.style.position = 'relative';
                      slides_div.style.width = '100%';
                      slides_div.style.height = '100%';
                      slides_div.style.perspective = '1000px';
    
                      var wrapper_div = document.createElement('DIV');
                      wrapper_div.classList.add('swiper-wrapper_sb');
                      wrapper_div.style.display = 'flex';
                      wrapper_div.style.transition = 'transform 0.5s ease';
                      wrapper_div.style.transformStyle = 'preserve-3d';
                      wrapper_div.style.height = '100%';
    
                      var prevButton = document.createElement('BUTTON');
                      prevButton.classList.add('swiper-button_sb', 'prev');
                      prevButton.innerText = '❮';
                      prevButton.style.position = 'absolute';
                      prevButton.style.top = '50%';
                      prevButton.style.left = '12%';
                      prevButton.style.transform = 'translateY(-50%)';
                      prevButton.style.background = '#fff';
                      prevButton.style.color = '#000';
                      prevButton.style.boxShadow =
                        'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                      prevButton.style.border = 'none';
                      prevButton.style.padding = '10px';
                      prevButton.style.cursor = 'pointer';
                      prevButton.style.zIndex = '2';
                      prevButton.style.borderRadius = '50%';
                      prevButton.style.width = '34px';
                      prevButton.style.height = '34px';
                      prevButton.style.display = 'flex';
                      prevButton.style.alignItems = 'center';
                      prevButton.style.justifyContent = 'center';
    
                      var nextButton = document.createElement('BUTTON');
                      nextButton.classList.add('swiper-button_sb', 'next');
                      nextButton.innerText = '❯';
                      nextButton.style.position = 'absolute';
                      nextButton.style.top = '50%';
                      nextButton.style.right = '12%';
                      nextButton.style.transform = 'translateY(-50%)';
                      nextButton.style.background = ' #fff';
                      nextButton.style.color = '#000';
                      nextButton.style.boxShadow =
                        'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                      nextButton.style.border = 'none';
                      nextButton.style.padding = '10px';
                      nextButton.style.cursor = 'pointer';
                      nextButton.style.zIndex = '2';
                      nextButton.style.borderRadius = '50%';
                      nextButton.style.width = '34px';
                      nextButton.style.height = '34px';
                      nextButton.style.display = 'flex';
                      nextButton.style.alignItems = 'center';
                      nextButton.style.justifyContent = 'center';
    
                      slides_div.appendChild(prevButton);
                      slides_div.appendChild(nextButton);
    
                      var main_var = 0;
                      if (prev_questions_array[i].default_options) {
                        var contact_list =
                          prev_questions_array[i].default_options.split(';;');
                        var wo_key;
                        for (var j = 0; j < contact_list.length; j++) {
                          var slide = document.createElement('DIV');
                          slide.classList.add('swiper-slide_sb');
                          slide.style.flex = '0 0 auto';
                          slide.style.width = '200px';
                          slide.style.height = '240px';
                          slide.style.margin = '10px 10px';
                          slide.style.transition =
                            'transform 0.5s ease, opacity 0.5s ease';
                          slide.style.backfaceVisibility = 'hidden';
    
                          var contact_img_a = document.createElement('A');
                          // contact_img_a.title = 'Images slider';
                          contact_img_a.href = contact_list[j];
                          contact_img_a.target = '_blank';
                          contact_img_a.style.width = '100%';
                          contact_img_a.style.height = '100%';
                          contact_img_a.style.float = 'left';
                          contact_img_a.style.borderRadius = '10px';
    
                          var contact_image = document.createElement('IMG');
                          contact_image.src = contact_list[j];
                          contact_image.style.width = '100%';
                          contact_image.style.height = '100%';
                          contact_image.style.objectFit = 'cover';
                          contact_image.style.borderRadius = '10px';
    
                          contact_img_a.appendChild(contact_image);
                          slide.appendChild(contact_img_a);
                          wrapper_div.appendChild(slide);
                        }
                        slides_div.appendChild(wrapper_div);
                      }
    
                      var activeIndex = 0;
                      var autoScrollInterval;
                      var autoSlideEnabled = false;
                      var autoSlideTimeTnterval = 1000;
    
                      function updateSlides() {
                        var containerWidth = slides_div?.offsetWidth;
                        const slideWidthWithMargin = 200 + 20;
                        const offset =
                          -activeIndex * slideWidthWithMargin +
                          containerWidth / 2 -
                          slideWidthWithMargin / 2;
                        wrapper_div.style.transform = `translateX(${offset}px)`;
                        Array.from(wrapper_div.children).forEach((slide, index) => {
                          slide.classList.remove('active', 'left', 'right');
                          if (index == activeIndex) {
                            slide.classList.add('active');
                            slide.style.transform = 'translateZ(0px) scale(1.1)';
                            slide.style.zIndex = '1';
                          } else if (index < activeIndex) {
                            slide.classList.add('left');
                            slide.style.transform =
                              'translateZ(-100px) rotateY(50deg)';
                          } else {
                            slide.classList.add('right');
                            slide.style.transform =
                              'translateZ(-100px) rotateY(-50deg)';
                          }
                        });
    
                        prevButton.disabled = activeIndex == 0;
                        nextButton.disabled =
                          activeIndex == contact_list?.length - 1;
                        if (prevButton.disabled) {
                          prevButton.style.opacity = '0.3';
                          prevButton.style.cursor = 'not-allowed';
                        } else {
                          prevButton.style.opacity = '1';
                          prevButton.style.cursor = 'pointer';
                        }
    
                        if (nextButton.disabled) {
                          nextButton.style.opacity = '0.3';
                          nextButton.style.cursor = 'not-allowed';
                        } else {
                          nextButton.style.opacity = '1';
                          nextButton.style.cursor = 'pointer';
                        }
                      }
    
                      function startAutoScroll() {
                        if (autoSlideEnabled) {
                          autoScrollInterval = setInterval(() => {
                            activeIndex = (activeIndex + 1) % contact_list?.length;
                            updateSlides();
                          }, autoSlideTimeTnterval);
                        }
                      }
    
                      function stopAutoScroll() {
                        clearInterval(autoScrollInterval);
                      }
    
                      prevButton.addEventListener('click', () => {
                        stopAutoScroll();
                        if (activeIndex > 0) {
                          activeIndex--;
                        }
                        updateSlides();
                      });
    
                      nextButton.addEventListener('click', () => {
                        stopAutoScroll();
                        if (activeIndex < contact_list.length - 1) {
                          activeIndex++;
                        }
                        updateSlides();
                      });
        
                      if (
                        prev_qsn.default_options &&
                        prev_qsn.default_options.length > 0
                      ) {
                        if (
                          prev_qsn.auto_slide &&
                          prev_qsn.auto_slide.length > 0 &&
                          parseInt(prev_qsn.auto_slide) > 0
                        ) {
                          autoSlideEnabled = true;
                          autoSlideTimeTnterval =
                            parseInt(prev_qsn.auto_slide) * 1000;
                        }
                      }
    
                      if (
                        prev_questions_array[i].default_options &&
                        prev_questions_array[i].default_options.length > 0
                      ) {
                        main_options_div.appendChild(slides_div);
                      }
                      setTimeout(() => {
                        updateSlides();
                        startAutoScroll();
                      }, 1000)
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.appendChild(main_options_div);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add('m-t-5');
                    }
                  }
                }
                var k = 0;
                addQuestionArrays();
              }
            } else if (prev_questions_array[i].type == "take_action") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;

                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      ".." +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    option_div.classList.add("m-l-40");
                    if (k == question_arr.length - 1) {
                      var take_actions_div = document.createElement("DIV");
                      take_actions_div.classList.add("question-div-smatest");
                      take_actions_div.classList.add("top-0");
                      if (font && font.length > 0) {
                        take_actions_div.classList.add(font);
                      }
                      take_actions_div.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com"))
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = prev_questions_array[i].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_image_options_div.appendChild(imgDiv);
                      }
                      var other_option_div = document.createElement("DIV");
                      other_option_div.classList.add("options-div-smatest");
                      if (!alreadyShowedActions) {
                        if (
                          prev_questions_array[i].default_options &&
                          prev_questions_array[i].default_options.length > 0
                        ) {
                          alreadyShowedActions = !0;
                          var contact_list =
                            prev_questions_array[i].default_options.split(";;");
                          for (var j = 0; j < contact_list.length; j++) {
                            var contact_item1 = contact_list[j].split("..");
                            var contact = document.createElement("DIV");
                            contact.classList.add("contact-div-smatest");
                            if (font && font.length > 0) {
                              contact.classList.add(font);
                            }
                            var contact_icon = document.createElement("IMG");
                            var contact_item = document.createElement("A");
                            contact_item.title = "Contact redirection";
                            contact_item.classList.add("text-black");
                            if (font && font.length > 0) {
                              contact_item.classList.add(font);
                            }
                            if (contact_item1[0] == "call") {
                              if (call_fore == "white") {
                                contact_icon.src =
                                  "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/call_white.png";
                              } else {
                                contact_icon.src =
                                  "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/call_navigator.png";
                              }
                              contact_item.href = "tel:" + contact_item1[2];
                              contact_item.classList.add("other-pointer");
                              contact_icon.title = contact_item1[1];
                              contact_item.addEventListener("click", function (k) {
                                var arr =
                                  this.parentElement.parentElement.previousSibling.id.split(
                                    ".."
                                  );
                                var xhttp = new XMLHttpRequest();
                                inTheMiddle = !0;
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                xhttp.send(
                                  "action=answer&answer_text=Called" +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  arr[0] +
                                  "&is_logical=0" +
                                  "&sequence=" +
                                  arr[1] +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&is_help=1&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              });
                            } else if (contact_item1[0] == "schedule") {
                              contact_icon.classList.add("other-pointer");
                              contact_item.classList.add("other-pointer");
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/schedule.png";
                              var key = contact_item1[1];
                              contact_icon.title = contact_item1[1];
                              contact_item.addEventListener("click", function (k) {
                                if (!scheduleClicked) {
                                  scheduleClicked = !0;
                                  var arr =
                                    this.parentElement.parentElement.previousSibling.id.split(
                                      ".."
                                    );
                                  if (!shouldDisableTakeAction) {
                                    if (
                                      footer &&
                                      (input.style.pointerEvents == "none" ||
                                        footer.style.display == "none")
                                    ) {
                                      takingRadioValue(
                                        "Booked",
                                        this.parentElement,
                                        2,
                                        arr[0],
                                        arr[1],
                                        "take_action_flow"
                                      );
                                    } else {
                                      if (
                                        input &&
                                        input.placeholder == "Type your query"
                                      ) {
                                        takingRadioValue(
                                          "Booked",
                                          this.parentElement,
                                          2,
                                          arr[0],
                                          arr[1],
                                          "take_action_flow"
                                        );
                                      }
                                    }
                                  }
                                } else {
                                  this.title = "Already Scheduled";
                                }
                              });
                            } else if (contact_item1[0] == "whatsapp") {
                              contact_icon.src =
                                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/whatsapp_navigator.png";
                              contact_icon.classList.add("other-pointer");
                              contact_item.classList.add("other-pointer");
                              contact_icon.title = contact_item1[1];
                              contact_icon.target = "_blank";
                              contact_item.addEventListener("click", function (k) {
                                var arr =
                                  this.parentElement.parentElement.parentElement.id.split(
                                    ".."
                                  );
                                inTheMiddle = !0;
                                var xhttp = new XMLHttpRequest();
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                xhttp.send(
                                  "action=answer&answer_text=Whatsapped" +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  arr[0] +
                                  "&is_logical=0" +
                                  "&sequence=" +
                                  arr[1] +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&is_help=1&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              });
                              var k = generateTranslatedContent(translations, "Hi team, I have some queries", main_lang_code, language_code, input);
                              if (
                                /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                                  navigator.userAgent
                                )
                              ) {
                                contact_item.href =
                                  "https://api.whatsapp.com/send?phone=" +
                                  contact_item1[2].split("+").join("") +
                                  contact_item1[3] +
                                  "&text=" +
                                  k;
                              } else {
                                contact_item.href =
                                  "https://web.whatsapp.com/send?phone=" +
                                  contact_item1[2] +
                                  contact_item1[3] +
                                  "&text=" +
                                  k;
                              }
                            } else if (contact_item1[0] == "faqs") {
                              contact_icon.classList.add("other-pointer");
                              contact_item.classList.add("other-pointer");
                              contact_icon.title = contact_item1[1];
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/faqs.png";
                              contact_item.addEventListener("click", function (k) {
                                var arr = [];
                                arr.push(take_action_id);
                                arr.push(take_action_sequence);
                                if (!shouldDisableTakeAction) {
                                  if (
                                    footer &&
                                    (input.style.pointerEvents == "none" ||
                                      footer.style.display == "none")
                                  ) {
                                    inTheMiddle = !0;
                                    var xhttp = new XMLHttpRequest();
                                    xhttp.open(
                                      "POST",
                                      main_url +
                                      "/kya_backend/pagehub/chatbot_utils?action=answer",
                                      !0
                                    );
                                    xhttp.setRequestHeader(
                                      "Content-type",
                                      "application/x-www-form-urlencoded"
                                    );
                                    if (
                                      main_lang_code &&
                                      main_lang_code.length > 0 &&
                                      main_lang_code != language_code
                                    ) {
                                    } else {
                                      main_lang_code = "default";
                                    }
                                    xhttp.send(
                                      "action=answer&answer_text=clicked FAQ" +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      arr[0] +
                                      "&is_logical=0" +
                                      "&sequence=" +
                                      arr[1] +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&is_help=1&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                    clickFaq();
                                  } else {
                                    if (
                                      input &&
                                      input.placeholder == "Type your query"
                                    ) {
                                      inTheMiddle = !0;
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.open(
                                        "POST",
                                        main_url +
                                        "/kya_backend/pagehub/chatbot_utils?action=answer",
                                        !0
                                      );
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      if (
                                        main_lang_code &&
                                        main_lang_code.length > 0 &&
                                        main_lang_code != language_code
                                      ) {
                                      } else {
                                        main_lang_code = "default";
                                      }
                                      xhttp.send(
                                        "action=answer&answer_text=clicked FAQ" +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        arr[0] +
                                        "&is_logical=0" +
                                        "&sequence=" +
                                        arr[1] +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&is_help=1&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                      clickFaq();
                                    }
                                  }
                                }
                              });
                            } else if (contact_item1[0] == "live_chat") {
                              contact_icon.src =
                                "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/bot_mic.png";
                              contact_icon.classList.add("other-pointer");
                              contact_item.classList.add("other-pointer");
                              contact_icon.title = contact_item1[1];
                              contact_item.addEventListener("click", function (k) {
                                chat_with_us_cliked = !0;
                                if (
                                  window.Tawk_API &&
                                  window.Tawk_API.isChatHidden()
                                ) {
                                  window.Tawk_API.showWidget();
                                  Tawk_API.maximize();
                                }
                                try {
                                  zE("webWidget", "show");
                                  zE("webWidget", "toggle");
                                } catch (e) {
                                } finally {
                                }
                                mainDiv.click();
                              });
                            }
                            contact_icon.classList.add("contact-icon-smatest");
                            var contact_text = document.createElement("SPAN");
                            var text10 = document.createTextNode(contact_item1[1]);
                            contact_text.appendChild(text10);
                            if (contact_item1[0] != "call") {
                              contact_item.target = "_blank";
                            }
                            contact_item.appendChild(contact_text);
                            contact_item.appendChild(contact_icon);
                            contact.appendChild(contact_item);
                            other_option_div.appendChild(contact);
                          }
                          take_actions_div.appendChild(other_option_div);
                          setTimeout(function () {
                            body.appendChild(take_actions_div);
                            body.scrollTop = body.scrollHeight;
                          }, other_delay_time);
                        }
                      }
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
              if (
                prev_questions_array[i].answer_text &&
                prev_questions_array[i].answer_text != "something"
              ) {
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                var text2 = document.createTextNode(
                  prev_questions_array[i].answer_text
                );
                answer_text1.appendChild(text2);
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                body.appendChild(prevAnswerDiv);
                body.scrollTop = body.scrollHeight;
              }
            } else if (prev_questions_array[i].type == "audio") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;

                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      ".." +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (k == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com"))
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = prev_questions_array[i].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_image_options_div.appendChild(imgDiv);
                      }
                      var slides_div = document.createElement("DIV");
                      slides_div.classList.add("pull-left");
                      slides_div.classList.add("full-width");
                      if (prev_questions_array[i].default_options) {
                        var url = prev_questions_array[i].default_options;
                        var audio_div = document.createElement("AUDIO");
                        audio_div.id = "audio";
                        audio_div.controls = !0;
                        audio_div.setAttribute(
                          "src",
                          prev_questions_array[i].default_options
                        );
                        audio_div.classList.add("audio-player");
                        slides_div.appendChild(audio_div);
                      }
                      option_div.appendChild(slides_div);
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
              if (
                prev_questions_array[i].answer_text &&
                prev_questions_array[i].answer_text != "something"
              ) {
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                var text2 = document.createTextNode(
                  prev_questions_array[i].answer_text
                );
                answer_text1.appendChild(text2);
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                body.appendChild(prevAnswerDiv);
                body.scrollTop = body.scrollHeight;
              }
            } else if (prev_questions_array[i].type == "show_contacts") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;

                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      ".." +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (k == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com"))
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = prev_questions_array[i].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_image_options_div.appendChild(imgDiv);
                      }
                      if (
                        prev_questions_array[i].default_options &&
                        prev_questions_array[i].default_options.length > 0
                      ) {
                        var contacts_array = JSON.parse(
                          prev_questions_array[i].default_options
                        );
                        if (contacts_array && contacts_array.length > 0) {
                          var contacts_html =
                            '<table class="table-contacts" style="width:100%;text-align:left;border: 1px solid #ddd;"><tbody><tr><th>Name</th><th>Contact(s)</th></tr>';
                          for (var t = 0; t < contacts_array.length; t++) {
                            contacts_html = contacts_html + "<tr>";
                            contacts_html =
                              contacts_html +
                              "<td>" +
                              contacts_array[t].name +
                              "</td>";
                            contacts_array[t].contact = contacts_array[
                              t
                            ].contact.replace("-", "");
                            contacts_array[t].contact = contacts_array[
                              t
                            ].contact.replace(" ", "");
                            contacts_html =
                              contacts_html +
                              '<td><a href="tel:' +
                              contacts_array[t].contact +
                              '">' +
                              contacts_array[t].contact +
                              "</a>" +
                              "</td>";
                            contacts_html = contacts_html + "<tr>";
                          }
                          contacts_html = contacts_html + "</tr>";
                          var contacts_list_btn = document.createElement("BUTTON");
                          contacts_list_btn.classList.add("contact-list-btn");
                          if (font && font.length > 0) {
                            contacts_list_btn.classList.add(font);
                          }
                          if (contacts_array && contacts_array.length > 1) {
                            contacts_list_btn.innerHTML = "Show Contacts";
                          } else {
                            contacts_list_btn.innerHTML = "Show Contact";
                          }
                          option_div.appendChild(contacts_list_btn);
                          var modal_div = document.createElement("DIV");
                          if (font && font.length > 0) {
                            modal_div.classList.add(font);
                          }
                          modal_div.classList.add("modal-smatest");
                          modal_div.id = "myModal";
                          var modal_content_div = document.createElement("DIV");
                          modal_content_div.classList.add("modal-content-smatest");
                          var modal_close_span = document.createElement("SPAN");
                          modal_close_span.classList.add("close-modal");
                          modal_close_span.innerHTML = "&times";
                          var table_div = document.createElement("DIV");
                          table_div.innerHTML = contacts_html;
                          modal_content_div.appendChild(modal_close_span);
                          modal_content_div.appendChild(table_div);
                          modal_div.appendChild(modal_content_div);
                          modal_div.style.display = "none";
                          window.onclick = function (event) {
                            if (event.target == modal_div) {
                              modal_div.style.display = "none";
                              isTableOpened = !1;
                              nothingWentOnFor = 0;
                              encourageMessageIteration = 0;
                            }
                          };
                          modal_close_span.addEventListener("click", function (k) {
                            modal_div.style.display = "none";
                            isTableOpened = !1;
                            nothingWentOnFor = 0;
                            encourageMessageIteration = 0;
                          });
                          document.body.appendChild(modal_div);
                          contacts_list_btn.addEventListener("click", function (k) {
                            modal_div.style.display = "block";
                          });
                        }
                      }
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
              if (
                prev_questions_array[i].answer_text &&
                prev_questions_array[i].answer_text != "something"
              ) {
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                var text2 = document.createTextNode(
                  prev_questions_array[i].answer_text
                );
                answer_text1.appendChild(text2);
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                body.appendChild(prevAnswerDiv);
                body.scrollTop = body.scrollHeight;
              }
            } else if (prev_questions_array[i].type == "show_file") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;

                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      ".." +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    option_div.classList.add("m-l-40");
                    if (k == question_arr.length - 1) {
                      var take_actions_div = document.createElement("DIV");
                      take_actions_div.classList.add("question-div-smatest");
                      take_actions_div.classList.add("top-0");
                      if (font && font.length > 0) {
                        take_actions_div.classList.add(font);
                      }
                      take_actions_div.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com") ||
                          prev_questions_array[i].image_url.includes("finideas"))
                      ) {
                        var extension = prev_questions_array[i].image_url
                          .split(/\#|\?/)[0]
                          .split(".")
                          .pop()
                          .trim();
                        if (
                          extension.toLowerCase() == "png" ||
                          extension.toLowerCase() == "jpg" ||
                          extension.toLowerCase() == "jpeg" ||
                          extension.toLowerCase() == "svg" ||
                          extension.toLowerCase() == "tif" ||
                          extension.toLowerCase() == "gif" ||
                          extension.toLowerCase() == "webp"
                        ) {
                          var imgDiv = document.createElement("DIV");
                          imgDiv.classList.add("image-div-smatest");
                          var questionImg = document.createElement("IMG");
                          questionImg.src = prev_questions_array[i].image_url;
                          questionImg.classList.add("question-img-smatest");
                          imgDiv.appendChild(questionImg);
                          main_image_options_div.appendChild(imgDiv);
                        } else if (
                          extension.toLowerCase() == "mp3" ||
                          extension.toLowerCase() == "wav"
                        ) {
                          var slides_div = document.createElement("DIV");
                          slides_div.classList.add("pull-left");
                          slides_div.classList.add("full-width");
                          var audio_div = document.createElement("AUDIO");
                          audio_div.id = "audio";
                          audio_div.controls = !0;
                          audio_div.setAttribute(
                            "src",
                            prev_questions_array[i].image_url
                          );
                          audio_div.classList.add("audio-player");
                          slides_div.appendChild(audio_div);
                          option_div.appendChild(slides_div);
                        } else if (
                          extension.toLowerCase() == "mp4" ||
                          extension.toLowerCase() == "webm" ||
                          extension.toLowerCase() == "flv"
                        ) {
                          var slides_div = document.createElement("DIV");
                          slides_div.classList.add("pull-left");
                          slides_div.classList.add("full-width");
                          var video_div = document.createElement("VIDEO");
                          video_div.id = "video";
                          video_div.style.marginTop = "10px";
                          video_div.style.maxWidth = "100%";
                          video_div.controls = !0;
                          var video_src = document.createElement("SOURCE");
                          video_src.setAttribute(
                            "src",
                            prev_questions_array[i].image_url
                          );
                          video_src.setAttribute("type", "video/mp4");
                          var video_src_other = document.createElement("SOURCE");
                          video_src_other.setAttribute(
                            "src",
                            prev_questions_array[i].image_url
                          );
                          video_src_other.setAttribute("type", "video/mp4");
                          video_div.appendChild(video_src);
                          video_div.appendChild(video_src_other);
                          slides_div.appendChild(video_div);
                          option_div.appendChild(slides_div);
                        } else if (extension.toLowerCase() == "pdf") {
                          var download_div = document.createElement("DIV");
                          download_div.classList.add("pull-left");
                          download_div.classList.add("full-width");
                          download_div.classList.add("text-center");
                          var download_a = document.createElement("A");
                          download_a.title = "File upload file redirection";
                          if (chatbot_id == 20609) {
                            download_a.innerHTML = "Download brochure 📄";
                            download_a.style.cssText = download_a.style.cssText + "color: white !important;"
                            download_a.style.textDecoration = "none";
                          } else {
                            download_a.innerHTML = "Open PDF";
                          }
                          download_a.style.cursor = "pointer";
                          download_a.style.display = "inline-block";
                          download_a.addEventListener("click", function () { });
                          download_a.classList.add("confirm-btn-smatest");
                          download_a.download = "file";
                          download_a.setAttribute(
                            "href",
                            prev_questions_array[i].image_url
                          );
                          download_a.setAttribute(
                            "type",
                            "application/octet-stream"
                          );
                          download_a.setAttribute("target", "_blank");
                          download_div.appendChild(download_a);
                          option_div.appendChild(download_div);
                        } else {
                          var doc_div = document.createElement("DIV");
                          doc_div.classList.add("pull-left");
                          doc_div.classList.add("full-width");
                          var doc_label = document.createElement("LABEL");
                          doc_label.style.marginTop = "10px";
                          doc_label.style.marginBottom = "10px";
                          doc_label.style.textAlign = "center";
                          var doc_a = document.createElement("A");
                          doc_a.title = "File upload file redirection";
                          doc_label.appendChild(doc_a);
                          doc_a.setAttribute(
                            "href",
                            prev_questions_array[i].image_url
                          );
                          doc_a.setAttribute("target", "_blank");
                          doc_a.innerHTML = prev_questions_array[
                            i
                          ].image_url.substring(
                            prev_questions_array[i].image_url.lastIndexOf("/") + 1
                          );
                          doc_div.appendChild(doc_label);
                          option_div.appendChild(doc_div);
                        }
                      }
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
              if (
                prev_questions_array[i].answer_text &&
                prev_questions_array[i].answer_text != "something"
              ) {
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                var text2 = document.createTextNode(
                  prev_questions_array[i].answer_text
                );
                answer_text1.appendChild(text2);
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                body.appendChild(prevAnswerDiv);
                body.scrollTop = body.scrollHeight;
              }
            } else if (prev_questions_array[i].type == "show_location") {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;

                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement("DIV");
                    questionDIv.classList.add("question-div-smatest");
                    questionDIv.classList.add("top-0");
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      ".." +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                    ques_icon1.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add("question-icon-div");
                    ques_icon1.classList.add("question-icon-smatest");
                    var option_div = document.createElement("DIV");
                    var main_options_div = document.createElement("DIV");
                    main_options_div.classList.add("main-options-div-smatest");
                    main_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    option_div.classList.add("options-div-smatest");
                    var main_image_options_div = document.createElement("DIV");
                    main_image_options_div.classList.add(
                      "main-options-div-smatest-image"
                    );
                    main_image_options_div.classList.add("some-animation");
                    var option_question = document.createElement("LABEL");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (k == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != "null" &&
                        (prev_questions_array[i].image_url.includes(
                          "s3.ap-south-1.amazonaws.com"
                        ) ||
                          prev_questions_array[i].image_url.includes(
                            "media.tenor.com"
                          ) ||
                          prev_questions_array[i].image_url.includes("giphy.com"))
                      ) {
                        var imgDiv = document.createElement("DIV");
                        imgDiv.classList.add("image-div-smatest");
                        var questionImg = document.createElement("IMG");
                        questionImg.src = prev_questions_array[i].image_url;
                        questionImg.classList.add("question-img-smatest");
                        imgDiv.appendChild(questionImg);
                        main_image_options_div.appendChild(imgDiv);
                      }
                      var location_obj = JSON.parse(
                        prev_questions_array[i].default_options
                      );
                      if (location_obj) {
                        var location_div = document.createElement("DIV");
                        location_div.classList.add("location-box");
                        var location_frame = document.createElement("IFRAME");
                        location_div.appendChild(location_frame);
                        location_div.style.border = "0";
                        location_frame.style.borderRadius = "6px";
                        location_frame.style.border = "0";
                        if (!language_code || language_code != "default") {
                          location_frame.src =
                            "https://maps.google.com/maps?q=17.4400802,78.3489168&z=14&amp&ie=UTF8&iwloc=&output=embed";
                        } else {
                          location_frame.src =
                            "https://maps.google.com/maps?q=" +
                            location_obj.lat +
                            "," +
                            location_obj.long +
                            "&z=14&amp&ie=UTF8&iwloc=&output=embed&hl=" +
                            language_code;
                        }
                        location_frame.style.maxWidth = "100%";
                        location_frame.style.height = "100%";
                        main_options_div.appendChild(location_div);
                      }
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    body.appendChild(questionDIv);
                    body.scrollTop = body.scrollHeight;
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add("m-t-5");
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.appendChild(main_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
              if (
                prev_questions_array[i].answer_text &&
                prev_questions_array[i].answer_text != "something"
              ) {
                var prevAnswerDiv = document.createElement("DIV");
                prevAnswerDiv.classList.add("answer-div");
                prevAnswerDiv.classList.add("top-0");
                var answer_text1 = document.createElement("LABEL");
                var text2 = document.createTextNode(
                  prev_questions_array[i].answer_text
                );
                answer_text1.appendChild(text2);
                answer_text1.classList.add("answer-label");
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                if (font && font.length > 0) {
                  answer_text1.classList.add(font);
                }
                prevAnswerDiv.appendChild(answer_text1);
                body.appendChild(prevAnswerDiv);
                body.scrollTop = body.scrollHeight;
              }
            } else if (prev_questions_array[i].type == "custom_actions") {
            } else if (prev_questions_array[i].type == "user_question") {
              var prevAnswerDiv = document.createElement("DIV");
              prevAnswerDiv.classList.add("answer-div");
              prevAnswerDiv.classList.add("top-0");
              var answer_text1 = document.createElement("LABEL");
              var text2 = document.createTextNode(
                prev_questions_array[i].question_text
              );
              answer_text1.appendChild(text2);
              answer_text1.classList.add("answer-label");
              if (font && font.length > 0) {
                answer_text1.classList.add(font);
              }
              if (font && font.length > 0) {
                answer_text1.classList.add(font);
              }
              prevAnswerDiv.appendChild(answer_text1);
              body.appendChild(prevAnswerDiv);
              body.scrollTop = body.scrollHeight;
              var arr = getParagraphs(prev_questions_array[i].answer_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                if (prev_questions_array[i].answer_text.includes("<br/>")) {
                  question_arr = prev_questions_array[i].answer_text.split("<br/>");
                } else if (prev_questions_array[i].answer_text.includes(" /n")) {
                  question_arr = prev_questions_array[i].answer_text.split(" /n");
                } else if (prev_questions_array[i].answer_text.includes(" \n")) {
                  question_arr = prev_questions_array[i].answer_text.split(" \n");
                } else {
                  question_arr.push(prev_questions_array[i].answer_text);
                }
              }
              if (question_arr && question_arr.length > 0) {
                for (var j = 0; j < question_arr.length; j++) {
                  var questionDIv = document.createElement("DIV");
                  questionDIv.classList.add("question-div-smatest");
                  questionDIv.classList.add("top-0");
                  if (font && font.length > 0) {
                    questionDIv.classList.add(font);
                  }
                  var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                  ques_icon1.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon1);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon1.classList.add("question-icon-smatest");
                  var option_div = document.createElement("DIV");
                  option_div.classList.add("options-div-smatest");
                  var option_question = document.createElement("LABEL");
                  option_question.innerHTML = question_arr[j].trim();
                  say(option_question.innerText);
                  option_div.appendChild(option_question);
                  option_div.classList.add("m-l-40");
                  if (j == question_arr.length - 1) {
                    var take_actions_div = document.createElement("DIV");
                    take_actions_div.classList.add("question-div-smatest");
                    take_actions_div.classList.add("top-0");
                    if (font && font.length > 0) {
                      take_actions_div.classList.add(font);
                    }
                    take_actions_div.appendChild(iconDiv);
                    var other_option_div = document.createElement("DIV");
                    other_option_div.classList.add("options-div-smatest");
                    option_div.classList.add("m-b-10");
                    iconDiv.classList.add("m-b-10");
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == "he" ||
                          main_lang_code == "ur" ||
                          main_lang_code == "ar")) ||
                      (main_lang_code == "default" &&
                        (language_code == "ar" ||
                          language_code == "he" ||
                          language_code == "ur"))
                    ) {
                      option_question.classList.add("rtl");
                    }
                    if (df_options && df_options.length > 0) {
                      var optionsArray = df_options.split(";;");
                    }
                    if (optionsArray && optionsArray.length > 0) {
                      var slides_div = document.createElement("DIV");
                      for (var k = 0; k < optionsArray.length; k++) {
                        var selectedKey;
                        var contact_icon = document.createElement("A");
                        contact_icon.title = "Contact redirection";
                        contact_icon.classList.add("extra-help-a");
                        if (font && font.length > 0) {
                          contact_icon.classList.add(font);
                        }
                        var contact_item1 = optionsArray[k].split("..");
                        var contact_img = document.createElement("IMG");
                        contact_img.classList.add("extra-help-icon");
                        contact_icon.appendChild(contact_img);
                        if (contact_item1[0] == "call") {
                          contact_icon.classList.add("other-pointer");
                          if (call_fore == "white") {
                            contact_img.src =
                              "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/call_white.png";
                          } else {
                            contact_img.src =
                              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/call_navigator.png";
                          }
                          contact_icon.href = "tel:" + contact_item1[2];
                          contact_icon.title = contact_item1[1];
                          contact_icon.addEventListener("click", function (k) {
                            var arr = [];
                            if (take_action_id && take_action_sequence) {
                              arr.push(take_action_id);
                              arr.push(take_action_sequence);
                            } else if (custom_action_id && custom_action_sequence) {
                              arr.push(custom_action_id);
                              arr.push(custom_action_sequence);
                            }
                            inTheMiddle = !0;
                            var xhttp = new XMLHttpRequest();
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            xhttp.send(
                              "action=answer&answer_text=Called" +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              arr[0] +
                              "&is_logical=0" +
                              "&sequence=" +
                              arr[1] +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&is_help=1&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          });
                        } else if (contact_item1[0] == "schedule") {
                          contact_icon.classList.add("other-pointer");
                          contact_icon.title = contact_item1[1];
                          contact_img.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/schedule.png";
                          var key = contact_item1[1];
                          contact_icon.addEventListener("click", function (k) {
                            if (!scheduleClicked) {
                              scheduleClicked = !0;
                              var arr = [];
                              if (take_action_id && take_action_sequence) {
                                arr.push(take_action_id);
                                arr.push(take_action_sequence);
                              } else if (
                                custom_action_id &&
                                custom_action_sequence
                              ) {
                                arr.push(custom_action_id);
                                arr.push(custom_action_sequence);
                              }
                              if (!shouldDisableTakeAction) {
                                if (
                                  footer &&
                                  (input.style.pointerEvents == "none" ||
                                    footer.style.display == "none")
                                ) {
                                  takingRadioValue(
                                    "Booked",
                                    this.parentElement,
                                    2,
                                    arr[0],
                                    arr[1],
                                    "take_action_flow"
                                  );
                                } else {
                                  if (
                                    input &&
                                    input.placeholder == "Type your query"
                                  ) {
                                    takingRadioValue(
                                      "Booked",
                                      this.parentElement,
                                      2,
                                      arr[0],
                                      arr[1],
                                      "take_action_flow"
                                    );
                                  }
                                }
                              }
                            } else {
                              this.title = "Already Scheduled";
                            }
                          });
                        } else if (contact_item1[0] == "faqs") {
                          contact_icon.classList.add("other-pointer");
                          contact_icon.classList.add("other-pointer");
                          contact_icon.title = contact_item1[1];
                          contact_img.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/faqs.png";
                          contact_icon.addEventListener("click", function (k) {
                            var arr = [];
                            if (take_action_id && take_action_sequence) {
                              arr.push(take_action_id);
                              arr.push(take_action_sequence);
                            } else if (custom_action_id && custom_action_sequence) {
                              arr.push(custom_action_id);
                              arr.push(custom_action_sequence);
                            }
                            inTheMiddle = !0;
                            var xhttp = new XMLHttpRequest();
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            xhttp.send(
                              "action=answer&answer_text=clicked FAQ" +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              arr[0] +
                              "&is_logical=0" +
                              "&sequence=" +
                              arr[1] +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&is_help=1&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                            clickFaq();
                          });
                        } else if (contact_item1[0] == "whatsapp") {
                          contact_icon.classList.add("other-pointer");
                          contact_icon.target = "_blank";
                          contact_icon.title = contact_item1[1];
                          contact_img.src =
                            "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/whatsapp_navigator.png";
                          contact_icon.addEventListener("click", function (k) {
                            var arr = [];
                            if (take_action_id && take_action_sequence) {
                              arr.push(take_action_id);
                              arr.push(take_action_sequence);
                            } else if (custom_action_id && custom_action_sequence) {
                              arr.push(custom_action_id);
                              arr.push(custom_action_sequence);
                            }
                            inTheMiddle = !0;
                            var xhttp = new XMLHttpRequest();
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            xhttp.send(
                              "action=answer&answer_text=Whatsapped" +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              arr[0] +
                              "&is_logical=0" +
                              "&sequence=" +
                              arr[1] +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&is_help=1&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          });
                          var k = generateTranslatedContent(translations, "Hi team, I have some queries", main_lang_code, language_code, input);
                          if (
                            /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                              navigator.userAgent
                            )
                          ) {
                            contact_icon.href =
                              "https://api.whatsapp.com/send?phone=" +
                              contact_item1[2].split("+").join("") +
                              contact_item1[3] +
                              "&text=" +
                              k;
                          } else {
                            contact_icon.href =
                              "https://web.whatsapp.com/send?phone=" +
                              contact_item1[2] +
                              contact_item1[3] +
                              "&text=" +
                              k;
                          }
                        } else if (contact_item1[0] == "live_chat") {
                          contact_img.src =
                            "https://s3.ap-south-1.amazonaws.com/custpostimages/ss_images/bot_mic.png";
                          contact_icon.classList.add("other-pointer");
                          contact_icon.title = contact_item1[1];
                          contact_icon.addEventListener("click", function (k) {
                            chat_with_us_cliked = !0;
                            mainDiv.click();
                            if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
                              window.Tawk_API.showWidget();
                              Tawk_API.maximize();
                            }
                            try {
                              zE("webWidget", "show");
                              zE("webWidget", "toggle");
                            } catch (e) {
                            } finally {
                            }
                          });
                        }
                        slides_div.appendChild(contact_icon);
                      }
                      other_option_div.appendChild(slides_div);
                      take_actions_div.appendChild(other_option_div);
                      setTimeout(function () {
                        body.appendChild(take_actions_div);
                        body.scrollTop = body.scrollHeight;
                      }, other_delay_time);
                    }
                  }
                  questionDIv.appendChild(option_div);
                  body.appendChild(questionDIv);
                  body.scrollTop = body.scrollHeight;
                  footer.style.display = "block";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                  footer.classList.remove("close");
                  if (shouldShowMenu) {
                    input.style.pointerEvents = "auto";
                    microphone.style.pointerEvents = "auto";
                    microphone.style.opacity = 1;
                    enter.style.pointerEvents = "auto";
                  }
                  input.focus();
                }
              }
            } else if (prev_questions_array[i].type == "url_flow") {
            } else if (prev_questions_array[i].type == "country_based_flow") {
            } else {
              if (
                prev_questions_array[i].question_text &&
                prev_questions_array[i].question_text.includes("{{") &&
                prev_questions_array[i].question_text.includes("}}")
              ) {
                parseDataReferring(prev_questions_array, i);
              }
              var arr = getParagraphs(prev_questions_array[i].question_text);
              var x_arr = arr;
              array = [];
              for (var p = 0; p < x_arr.length; p++) {
                if (x_arr[p]) {
                  if (
                    (x_arr[p].innerText && x_arr[p].innerText.length > 0) ||
                    (x_arr[p].children && x_arr[p].children.length > 0)
                  ) {
                    array.push(x_arr[p].outerHTML);
                  } else {
                    x_arr.splice(p, 1);
                    p--;
                  }
                }
              }
              var question_arr = [];
              if (array && array.length > 0) {
                question_arr = array;
              } else {
                question_arr.push(prev_questions_array[i].question_text);
              }
              if (question_arr && question_arr.length > 0) {
                var k = 0;
                var prev_qsn = prev_questions_array[i];
    
                function addQuestionArrays() {
                  if (k < question_arr.length) {
                    var questionDIv = document.createElement('DIV');
                    questionDIv.classList.add('question-div-smatest');
                    questionDIv.classList.add('top-0');
                    questionDIv.id =
                      prev_questions_array[i].question_id +
                      '..' +
                      prev_questions_array[i].sequence;
                    if (font && font.length > 0) {
                      questionDIv.classList.add(font);
                    }
                    var ques_icon1 = document.createElement('IMG');
                    ques_icon1.alt = 'Logo of ' + totalData[0].name;
                    var iconDiv = document.createElement('DIV');
                    iconDiv.appendChild(ques_icon1);
                    iconDiv.classList.add('question-icon-div');
                    ques_icon1.src = avatar_icon;
                    ques_icon1.classList.add('question-icon-smatest');
                    var option_div = document.createElement('DIV');
                    var main_options_div = document.createElement('DIV');
                    // main_options_div.classList.add('main-options-div-smatest-slides');
                    main_options_div.classList.add('some-animation');
                    var option_question = document.createElement('LABEL');
                    option_div.classList.add('options-div-smatest');
                    var main_image_options_div = document.createElement('DIV');
                    main_image_options_div.classList.add('main-options-div-smatest-image');
                    main_image_options_div.classList.add('some-animation');
                    var option_question = document.createElement('LABEL');
                    if (font && font.length > 0) {
                      option_question.classList.add(font);
                    }
                    if (
                      (main_lang_code &&
                        (main_lang_code == 'he' ||
                          main_lang_code == 'ur' ||
                          main_lang_code == 'ar')) ||
                      (main_lang_code == 'default' &&
                        (language_code == 'ar' ||
                          language_code == 'he' ||
                          language_code == 'ur'))
                    ) {
                      option_question.classList.add('rtl');
                    }
                    option_question.innerHTML = question_arr[k].trim();
                    say(option_question.innerText);
                    option_div.appendChild(option_question);
                    if (k != question_arr.length - 1) {
                      option_div.classList.add('m-l-40');
                    }
                    if (k == question_arr.length - 1) {
                      questionDIv.appendChild(iconDiv);
                      if (
                        prev_questions_array[i].image_url &&
                        prev_questions_array[i].image_url.length > 0 &&
                        prev_questions_array[i].image_url != 'null' &&
                        (prev_questions_array[i].image_url.includes(
                          's3.ap-south-1.amazonaws.com'
                        ) ||
                          prev_questions_array[i].image_url.includes('media.tenor.com') ||
                          prev_questions_array[i].image_url.includes('giphy.com'))
                      ) {
                        var extension = question_array[0].image_url
                          .split(/\#|\?/)[0]
                          .split('.')
                          .pop()
                          .trim();
                        if (
                          extension.toLowerCase() == 'png' ||
                          extension.toLowerCase() == 'jpg' ||
                          extension.toLowerCase() == 'jpeg' ||
                          extension.toLowerCase() == 'svg' ||
                          extension.toLowerCase() == 'tif' ||
                          extension.toLowerCase() == 'gif' ||
                          extension.toLowerCase() == 'webp'
                        ) {
                          var imgDiv = document.createElement('DIV');
                          imgDiv.classList.add('image-div-smatest');
                          var questionImg = document.createElement('IMG');
                          questionImg.src = question_array[0].image_url;
                          questionImg.classList.add('question-img-smatest');
                          imgDiv.appendChild(questionImg);
                          main_image_options_div.appendChild(imgDiv);
                        } else {
                          var doc_div = document.createElement('DIV');
                          doc_div.classList.add('pull-left');
                          doc_div.classList.add('full-width');
                          var doc_label = document.createElement('LABEL');
                          doc_label.style.marginTop = '10px';
                          doc_label.style.marginBottom = '10px';
                          doc_label.style.textAlign = 'center';
                          var doc_a = document.createElement('A');
                          doc_a.title = 'File upload file redirection';
                          doc_label.appendChild(doc_a);
                          doc_a.setAttribute('href', question_array[0].image_url);
                          doc_a.setAttribute('target', '_blank');
                          doc_a.innerHTML = question_array[0].image_url.substring(
                            question_array[0].image_url.lastIndexOf('/') + 1
                          );
                          doc_div.appendChild(doc_label);
                          if (chatbot_id == 13682 || chatbot_id == 13756) {
                            main_image_options_div.insertBefore(doc_div, option_div.firstChild);
                          } else {
                            main_image_options_div.appendChild(doc_div);
                          }
                        }
                      }
                      option_question.classList.add('slides-label');
                      option_div.classList.add('options-div-smatest');
    
                      main_options_div.style.height = '270px';
                      main_options_div.style.width = '100%';
                      main_options_div.style.position = 'relative';
                      main_options_div.style.float = 'left';
                      main_options_div.style.overflowY = 'hidden';
                      main_options_div.style.top = '4px';
                
                      var slides_div = document.createElement('DIV');
                      slides_div.classList.add('swiper-container_sb');
                      slides_div.style.overflow = 'hidden';
                      slides_div.style.position = 'relative';
                      slides_div.style.width = '100%';
                      slides_div.style.height = '100%';
                      slides_div.style.perspective = '1000px';
                
                      var wrapper_div = document.createElement('DIV');
                      wrapper_div.classList.add('swiper-wrapper_sb');
                      wrapper_div.style.display = 'flex';
                      wrapper_div.style.transition = 'transform 0.5s ease';
                      wrapper_div.style.transformStyle = 'preserve-3d';
                      wrapper_div.style.height = '100%';
                
                      var prevButton = document.createElement('BUTTON');
                      prevButton.classList.add('swiper-button_sb', 'prev');
                      prevButton.innerText = '❮';
                      prevButton.style.position = 'absolute';
                      prevButton.style.top = '50%';
                      prevButton.style.left = '12%';
                      prevButton.style.transform = 'translateY(-50%)';
                      prevButton.style.background = '#fff';
                      prevButton.style.color = '#000';
                      prevButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                      prevButton.style.border = 'none';
                      prevButton.style.padding = '10px';
                      prevButton.style.cursor = 'pointer';
                      prevButton.style.zIndex = '2';
                      prevButton.style.borderRadius = '50%';
                      prevButton.style.width = '34px';
                      prevButton.style.height = '34px';
                      prevButton.style.display = 'flex';
                      prevButton.style.alignItems = 'center';
                      prevButton.style.justifyContent = 'center';
                
                      var nextButton = document.createElement('BUTTON');
                      nextButton.classList.add('swiper-button_sb', 'next');
                      nextButton.innerText = '❯';
                      nextButton.style.position = 'absolute';
                      nextButton.style.top = '50%';
                      nextButton.style.right = '12%';
                      nextButton.style.transform = 'translateY(-50%)';
                      nextButton.style.background = ' #fff';
                      nextButton.style.color = '#000';
                      nextButton.style.boxShadow = 'rgba(0, 0, 0, 0.58) 0px 0px 5px';
                      nextButton.style.border = 'none';
                      nextButton.style.padding = '10px';
                      nextButton.style.cursor = 'pointer';
                      nextButton.style.zIndex = '2';
                      nextButton.style.borderRadius = '50%';
                      nextButton.style.width = '34px';
                      nextButton.style.height = '34px';
                      nextButton.style.display = 'flex';
                      nextButton.style.alignItems = 'center';
                      nextButton.style.justifyContent = 'center';
                
                      slides_div.appendChild(prevButton);
                      slides_div.appendChild(nextButton);
                
                      if (prev_questions_array[i].default_options) {
                        var contact_list = prev_questions_array[i].default_options.split(';;');
                        var wo_key;
                        for (var j = 0; j < contact_list.length; j++) {
                          var slides_item = contact_list[j].split('..');
                
                          var slide = document.createElement('DIV');
                          slide.classList.add('swiper-slide_sb');
                          slide.style.position = 'relative';
                          slide.style.flex = '0 0 auto';
                          slide.style.width = '200px';
                          slide.style.height = '240px';
                          slide.style.margin = '10px 10px';
                          slide.style.transition = 'transform 0.5s ease, opacity 0.5s ease';
                          slide.style.backfaceVisibility = 'hidden';
                          slide.style.background = 'none';
                          slide.style.padding = '0';
                          slide.style.boxShadow = '0';
                          slides_div.appendChild(wrapper_div);
                          if (font && font.length > 0) {
                            slide.classList.add(font);
                          }
                
                          if (slides_item[5] == 'image') {
                            if (slides_item[0] == 'null') {
                            } else {
                              var contact_img_a = document.createElement('A');
                              contact_img_a.title = 'Slides image redirection';
                
                              contact_img_a.href = slides_item[1];
                              contact_img_a.target = '_blank';
                              contact_img_a.style.width = '100%';
                              contact_img_a.style.height = '100%';
                              contact_img_a.style.float = 'left';
                              contact_img_a.style.borderRadius = '10px';
                
                              var contact_image = document.createElement('IMG');
                              contact_image.src = slides_item[0];
                              contact_image.style.width = '100%';
                              contact_image.style.height = '100%';
                              contact_image.style.objectFit = 'cover';
                              contact_image.style.borderRadius = '10px';
                
                              var overley = document.createElement('DIV');
                              overley.style.width = '100%';
                              overley.style.position = 'absolute';
                              overley.style.left = '0';
                              overley.style.bottom = '0';
                              overley.style.height = '45%';
                              overley.style.borderRadius = '10px';
                              overley.style.display = 'block';
                              overley.style.transition = 'all 0.5s ease 0s';
                              overley.style.background =
                                'linear-gradient(rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.69) 100%) transparent';
                
                              var slidesOverlay = document.createElement('DIV');
                              slidesOverlay.style.position = 'absolute';
                              slidesOverlay.style.display = 'flex';
                              slidesOverlay.style.flexDirection = 'column';
                              slidesOverlay.style.margin = 'auto';
                              slidesOverlay.style.textAlign = 'center';
                              slidesOverlay.style.bottom = '0px';
                              slidesOverlay.style.width = '100%';
                
                              var contact_title = document.createElement('A');
                              contact_title.innerHTML = slides_item[2];
                              contact_title.href = slides_item[1];
                              contact_title.target = '_blank';
                              contact_title.style.color = '#fff';
                              contact_title.style.marginBottom = '0.5rem';
                              contact_title.style.textAlign = 'left';
                              contact_title.style.marginLeft = '1rem';
                              contact_title.style.marginRight = '1rem';
                              contact_title.style.textDecoration = 'none';
                              contact_title.style.maxWidth = '100%';
                              contact_title.style.overflow = 'hidden';
                              contact_title.style.whiteSpace = 'nowrap';
                              contact_title.style.textOverflow = 'ellipsis';
                              contact_title.style.display = 'inline-block';
                              contact_title.style.lineHeight = '16px';
                              contact_title.style.fontWeight = '500';
                              contact_title.style.fontSize = '14px';
                
                              var contact_desc = document.createElement('A');
                              contact_desc.title = slides_item[6];
                              contact_desc.innerHTML = slides_item[6];
                              contact_desc.target = '_blank';
                              contact_desc.style.color = '#fff';
                              contact_desc.style.marginBottom = '0.5rem';
                              contact_desc.style.textAlign = 'left';
                              contact_desc.style.marginLeft = '1rem';
                              contact_desc.style.marginRight = '1rem';
                              contact_desc.style.textDecoration = 'none';
                              contact_desc.style.maxWidth = '100%';
                              contact_desc.style.overflow = 'hidden';
                              contact_desc.style.whiteSpace = 'nowrap';
                              contact_desc.style.textOverflow = 'ellipsis';
                              contact_desc.style.display = 'inline-block';
                              contact_desc.style.lineHeight = '16px';
                              contact_desc.style.fontWeight = '500';
                              contact_desc.style.fontSize = '12px';
                
                              if (font && font.length > 0) {
                                contact_title.classList.add(font);
                                contact_desc.classList.add(font);
                              }
                
                              if (slides_item[3] && slides_item[3].length > 0) {
                                var btnDiv = document.createElement('DIV');
                                btnDiv.classList.add('btn-div-smatest');
                                var contact_button = document.createElement('button');
                                contact_button.style.padding = '0';
                                contact_button.style.border = '0';
                                contact_button.style.background = 'transparent';
                                contact_button.style.float = 'left';
                                contact_button.style.width = '100%';
                                contact_button.style.display = 'inline-block';
                                var contact_btn_a = document.createElement('A');
                                contact_btn_a.title = 'Slides button redirection';
                                var button_text = document.createTextNode(slides_item[3]);
                                contact_btn_a.appendChild(button_text);
                                contact_btn_a.classList.add('btn-a');
                                contact_btn_a.href = slides_item[4];
                                contact_btn_a.target = '_blank';
                                contact_button.appendChild(contact_btn_a);
                                contact_btn_a.classList.add('contact-btn-smatest');
                                contact_btn_a.style.float = 'left';
                                contact_btn_a.style.fontSize = '12px';
                                contact_btn_a.style.padding = '8px 15px';
                                contact_btn_a.style.marginLeft = '15px';
                                contact_btn_a.style.marginTop = '5px';
                                contact_btn_a.style.cssText =
                                  contact_btn_a.style.cssText + 'width:calc(100% - 30px)';
                                contact_btn_a.style.boxSizing = 'border-box';
                
                                if (font && font.length > 0) {
                                  contact_button.classList.add(font);
                                }
                
                                btnDiv.appendChild(contact_button);
                              }
                
                              contact_img_a.appendChild(contact_image);
                              slide.appendChild(contact_img_a);
                              if (prev_questions_array[i].id == '2393737') {
                                
                              }else{
                                slide.appendChild(overley);
                                slide.appendChild(slidesOverlay);
                                slidesOverlay.appendChild(contact_title);
                                slidesOverlay.appendChild(contact_desc);
                                slidesOverlay.appendChild(contact_button);
                              }
                            }
                          } else if (slides_item[5] == 'video') {
                            var video_frame = document.createElement('IFRAME');
                            var embed_str;
                            if (
                              slides_item[0] &&
                              slides_item[0].includes('youtube') &&
                              slides_item[0].includes('watch?v=')
                            ) {
                              embed_str = slides_item[0].split('watch?v=')[1];
                            } else if (
                              slides_item[0].includes('youtube') ||
                              slides_item[0].includes('youtu.be')
                            ) {
                              var arr = slides_item[0].split('/');
                              embed_str = arr[arr.length - 1];
                            }
                            video_frame.src = 'https://www.youtube.com/embed/' + embed_str;
                            video_frame.frameborder = 0;
                            video_frame.classList.add('contact-image-smatest');
                            video_frame.style.borderRadius = '10px';
                            slide.appendChild(video_frame);
                          } else {
                            var contact_img_a = document.createElement('A');
                            contact_img_a.title = 'Slides image redirection';
                
                            contact_img_a.href = slides_item[1];
                            contact_img_a.target = '_blank';
                            contact_img_a.style.width = '100%';
                            contact_img_a.style.height = '100%';
                            contact_img_a.style.float = 'left';
                            contact_img_a.style.borderRadius = '10px';
                
                            var contact_image = document.createElement('IMG');
                            contact_image.src = slides_item[0];
                            contact_image.style.width = '100%';
                            contact_image.style.height = '100%';
                            contact_image.style.objectFit = 'cover';
                            contact_image.style.borderRadius = '10px';
                
                            contact_img_a.appendChild(contact_image);
                            slide.appendChild(contact_img_a);
                          }
                
                          wrapper_div.appendChild(slide);
                        }
                      }
                
                      var activeIndex = 0;
                      var autoScrollInterval;
                      var autoSlideEnabled = false;
                      var autoSlideTimeTnterval = 1000;
                
                      function updateSlides() {
                        var containerWidth = slides_div?.offsetWidth;
                        // const slideWidthWithMargin = 200 + 20; 
                        let slideWidthWithMargin = 200 + 20
                        if(contact_list?.length > 15){
                           slideWidthWithMargin = 200 + 21.5
                        }else{
                           slideWidthWithMargin = 200 + 20
                        }
                        const offset =
                          -activeIndex * slideWidthWithMargin +
                          containerWidth / 2 -
                          slideWidthWithMargin / 2;
                        wrapper_div.style.transform = `translateX(${offset}px)`;
                        Array.from(wrapper_div.children).forEach((slide, index) => {
                          slide.classList.remove('active', 'left', 'right');
                          if (index == activeIndex) {
                            slide.classList.add('active');
                            slide.style.transform = 'translateZ(0px) scale(1.1)';
                            slide.style.zIndex = '1';
                          } else if (index < activeIndex) {
                            slide.classList.add('left');
                            slide.style.transform = 'translateZ(-100px) rotateY(50deg)';
                          } else {
                            slide.classList.add('right');
                            slide.style.transform = 'translateZ(-100px) rotateY(-50deg)';
                          }
                        });
                
                        prevButton.disabled = activeIndex == 0;
                        nextButton.disabled = activeIndex == contact_list?.length - 1;
                        if (prevButton.disabled) {
                          prevButton.style.opacity = '0.3';
                          prevButton.style.cursor = 'not-allowed';
                        } else {
                          prevButton.style.opacity = '1';
                          prevButton.style.cursor = 'pointer';
                        }
                
                        if (nextButton.disabled) {
                          nextButton.style.opacity = '0.3';
                          nextButton.style.cursor = 'not-allowed';
                        } else {
                          nextButton.style.opacity = '1';
                          nextButton.style.cursor = 'pointer';
                        }
                      }
                      function startAutoScroll() {
                        if (autoSlideEnabled) {
                          autoScrollInterval = setInterval(() => {
                            activeIndex = (activeIndex + 1) % contact_list?.length;
                            updateSlides();
                          }, autoSlideTimeTnterval); 
                        }
                      }
                
                      function stopAutoScroll() {
                        clearInterval(autoScrollInterval);
                      }
                
                      prevButton.addEventListener('click', () => {
                        stopAutoScroll();
                        if (activeIndex > 0) {
                          activeIndex--;
                        }
                        updateSlides();
                      });
                
                      nextButton.addEventListener('click', () => {
                        stopAutoScroll();
                        if (activeIndex < contact_list.length - 1) {
                          activeIndex++;
                        }
                        updateSlides();
                      });
                
                      slides_div.addEventListener('mouseenter', stopAutoScroll);
                      slides_div.addEventListener('mouseleave', startAutoScroll);
                      window.addEventListener('resize', updateSlides);
                
                      if (
                        prev_questions_array[i].auto_slide &&
                        prev_questions_array[i].auto_slide.length > 0 &&
                        parseInt(prev_questions_array[i].auto_slide) > 0
                      ) {
                        autoSlideEnabled = true;
                        autoSlideTimeTnterval =
                          parseInt(prev_questions_array[i].auto_slide) * 1000 + 1000;
                      }
                
                      if (
                        prev_questions_array[i].default_options &&
                        prev_questions_array[i].default_options.length > 0
                      ) {
                        main_options_div.appendChild(slides_div);
                        setTimeout(() => {
                          updateSlides();
                          startAutoScroll();
                        }, 300);
                      }
                    }
                    questionDIv.appendChild(option_div);
                    k++;
                    if (
                      prev_questions_array[i].type == 'custom_entry' &&
                      prev_questions_array[i].answer_text == 'Booked'
                    ) {
                    } else {
                      body.appendChild(questionDIv);
                      body.scrollTop = body.scrollHeight;
                    }
                    addQuestionArrays();
                    if (k != 0) {
                      questionDIv.classList.add('m-t-5');
                    }
                    if (k == question_arr.length) {
                      body.appendChild(main_image_options_div);
                      body.appendChild(main_options_div);
                      body.scrollTop = body.scrollHeight;
                    }
                  }
                }
                addQuestionArrays();
              }
            }
          }
        }

        function playBotUserSound(id) {
          if (id == 1 && notification_sound_enabled) {
            var audio = new Audio(
              "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_response_sound.mp3"
            );
            var playPromise = audio.play();
          } else if (id == 2 && notification_sound_enabled) {
          }
        }

        var opstron_customers, opstron_agents, opstron_jds, opstron_job_prices, opstron_ads;

        function getOpstronData(id) {
          var xhr = new XMLHttpRequest();
          xhr.addEventListener("readystatechange", function () {
            if (this.readyState === 4) {
              var json = JSON.parse(this.responseText);
              if (json && json.length > 0) {
                opstron_customers = json;
              }
            }
          });
          xhr.open("GET", "https://pm247ai.azurewebsites.net/Home/GetCustomerList");
          xhr.send();
          if (!id) {
            var agents_xhr = new XMLHttpRequest();
            agents_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var agents_json = JSON.parse(this.responseText);
                if (agents_json && agents_json.length > 0) {
                  opstron_agents = agents_json;
                }
              }
            });
            agents_xhr.open(
              "GET",
              "https://pm247ai.azurewebsites.net/Home/GetBookingAgent"
            );
            agents_xhr.send();
            var jds_xhr = new XMLHttpRequest();
            jds_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var jds_json = JSON.parse(this.responseText);
                opstron_jds = jds_json;
              }
            });
            jds_xhr.open(
              "GET",
              "https://pm247ai.azurewebsites.net/Home/GetJobDescription"
            );
            jds_xhr.send();
            var job_prices_xhr = new XMLHttpRequest();
            job_prices_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var job_prices_json = JSON.parse(this.responseText);
                if (job_prices_json && job_prices_json.length > 0) {
                  opstron_job_prices = job_prices_json;
                }
              }
            });
            job_prices_xhr.open(
              "GET",
              "https://pm247ai.azurewebsites.net/Home/GetJobPrice"
            );
            job_prices_xhr.send();
            var ads_xhr = new XMLHttpRequest();
            ads_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var ads_json = JSON.parse(this.responseText);
                if (ads_json && ads_json.length > 0) {
                  opstron_ads = ads_json;
                }
              }
            });
            ads_xhr.open("GET", "https://pm247uat.azurewebsites.net/Account/GetAdvertisingChannelList");
            ads_xhr.send();
          }
        }

        function getOpstronDataStage(id) {
          var xhr = new XMLHttpRequest();
          xhr.addEventListener("readystatechange", function () {
            if (this.readyState === 4) {
              var json = JSON.parse(this.responseText);
              if (json && json.length > 0) {
                opstron_customers = json;
              }
            }
          });
          xhr.open("GET", "https://pm247uat-ai.azurewebsites.net/Home/GetCustomerList");
          xhr.send();
          if (!id) {
            var agents_xhr = new XMLHttpRequest();
            agents_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var agents_json = JSON.parse(this.responseText);
                if (agents_json && agents_json.length > 0) {
                  opstron_agents = agents_json;
                }
              }
            });
            agents_xhr.open(
              "GET",
              "https://pm247uat-ai.azurewebsites.net/Home/GetBookingAgent"
            );
            agents_xhr.send();
            var jds_xhr = new XMLHttpRequest();
            jds_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var jds_json = JSON.parse(this.responseText);
                opstron_jds = jds_json;
              }
            });
            jds_xhr.open(
              "GET",
              "https://pm247uat-ai.azurewebsites.net/Home/GetJobDescription"
            );
            jds_xhr.send();
            var job_prices_xhr = new XMLHttpRequest();
            job_prices_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var job_prices_json = JSON.parse(this.responseText);
                if (job_prices_json && job_prices_json.length > 0) {
                  opstron_job_prices = job_prices_json;
                }
              }
            });
            job_prices_xhr.open(
              "GET",
              "https://pm247uat-ai.azurewebsites.net/Home/GetJobPrice"
            );
            job_prices_xhr.send();
            var ads_xhr = new XMLHttpRequest();
            ads_xhr.addEventListener("readystatechange", function () {
              if (this.readyState === 4) {
                var ads_json = JSON.parse(this.responseText);
                if (ads_json && ads_json.length > 0) {
                  opstron_ads = ads_json;
                }
              }
            });
            ads_xhr.open("GET", "https://pm247uat.azurewebsites.net/Account/GetAdvertisingChannelList");
            ads_xhr.send();
          }
        }

        if (chatbot_id == 17271) {
          getOpstronData();
        }

        if (chatbot_id == 24709) {
          getOpstronDataStage();
        }

        function assignAllQuestionTypes(current_question_type, arr) {
          playBotUserSound(1);
          if (question_array[0].id == '937026') {
            // console.log(question_and_answers);
            getOpstronData(1);
          }
          if (question_array[0].id == '2600846') {
            getOpstronDataStage(1);
          }
          if (arr && arr.length > 0) {
            question_array = arr;
          }
          if (current_question_type != "live_agent") {
            if (footer.contains(attach_label)) {
              footer.removeChild(attach_label);
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
            }
          }
          if (
            current_question_type == "radio" ||
            current_question_type == "whatsapp_buttons" ||
            current_question_type == "whatsapp_list"
          ) {
            if (current_question_type == "whatsapp_list") {
              let temp_options = question_array[0].default_options.split(";;");
              temp_options = temp_options.map((item) => {
                return item.split("..")[0];
              })
              question_array[0].default_options = temp_options.join(";;");
            }
            callRadio(question_array);
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              if (question_array[0].error_text != "hide") {
                input.style.pointerEvents = "none";
                microphone.style.pointerEvents = "none";
                microphone.style.opacity = 0;
                enter.style.pointerEvents = "none";
              } else {
                input.style.pointerEvents = "auto";
                enter.style.pointerEvents = "auto";
                footer.style.display = "block";
              }
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                if (question_array[0].error_text != "hide") {
                  footer.style.display = "none";
                } else {
                  footer.style.display = "block";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                }
              }
            }
          } else if (current_question_type == "checkbox") {
            callCheckbox(question_array);
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                footer.style.display = "none";
              }
            }
          } else if (current_question_type == "statement") {
            callStatement(question_array);
          } else if (current_question_type == "url_auto_redirect") {
            callURLAutoRedirect(question_array);
          } else if (current_question_type == "show_contacts") {
            callShowContacts(question_array);
          } else if (current_question_type == "show_file") {
            callShowFile(question_array);
          } else if (current_question_type == "show_location") {
            callShowLocation(question_array);
          } else if (current_question_type == "audio") {
            callAudio(question_array);
          } else if (current_question_type == "rating") {
            callRating(question_array);
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                footer.style.display = "none";
              }
            }
          } else if (current_question_type == "range") {
            callRange(question_array);
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                footer.style.display = "none";
              }
            }
          } else if (current_question_type == "contact") {
            callContact(question_array);
          } else if (
            current_question_type == "take_action" ||
            current_question_type == "whatsapp_message_based_flow" ||
            current_question_type == "whatsapp_template_message" ||
            current_question_type == "whatsapp_ad_based_flow"
          ) {
            callTakeAction(question_array, question_id, currentMailSequence);
          } else if (current_question_type == "custom_actions") {
            callCustomAction(question_array, question_id, currentMailSequence);
          } else if (current_question_type == "url_flow") {
            callUrlBasedFlow(question_array);
          } else if (current_question_type == "country_based_flow") {
            callCountryBasedFlow(question_array);
          } else if (current_question_type == "slides") {
            callSlides(question_array);
          } else if (current_question_type == "form") {
            if (question_id == 921417) {
              callOpstronForm(question_array);
            }else if(question_id == 2600841){
              callOpstronForm(question_array);
            } else {
              callForm(question_array);
            }
          } else if (current_question_type == "radio_slides") {
            callRadioSlides(question_array);
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                footer.style.display = "none";
              }
            }
          } else if (current_question_type == "custom_single_choice") {
            callCustomSingleChoice(question_array);
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                footer.style.display = "none";
              }
            }
          } else if (current_question_type == "custom_end_choice") {
            callCustomEndChoice(question_array);
          } else if (current_question_type == "custom_answer") {
            callCustomAnswer(question_array);
            footer.style.display = "block";
            input.style.pointerEvents = "auto";
            microphone.style.pointerEvents = "auto";
            microphone.style.opacity = 1;
            enter.style.pointerEvents = "auto";
          } else if (current_question_type == "images_slider") {
            callImagesSlider(question_array);
          } else if (current_question_type == "dynamic_question") {
            callDynamicQuestion(question_array);
          } else if (current_question_type == "real_time_search") {
            callRealTimeSearch(question_array);
            footer.style.display = "block";
            input.style.pointerEvents = "auto";
            microphone.style.pointerEvents = "auto";
            microphone.style.opacity = 1;
            enter.style.pointerEvents = "auto";
          } else if (current_question_type == "live_agent") {
            footer.style.display = "block";
            input.style.pointerEvents = "auto";
            microphone.style.pointerEvents = "auto";
            microphone.style.opacity = 1;
            enter.style.pointerEvents = "auto";
            callLiveAgent(question_array);
          } else if (current_question_type == "order_items") {
            order_question_id = question_array[0].id;
            order_items_question = question_array[0];
            order_question_options = question_array[0].default_options;
            order_items = [];
            if (
              question_array[0].total_items_list &&
              question_array[0].total_items_list.length > 0
            ) {
              for (var t = 0; t < question_array[0].total_items_list.length; t++) {
                order_items.push(question_array[0].total_items_list[t]);
              }
            } else {
              for (var t = 0; t < question_array[0].items_list.length; t++) {
                order_items.push(question_array[0].items_list[t]);
              }
            }
            callOrderItemsNew(question_array)
            footer.style.display = "block";
            input.style.pointerEvents = "none";
            microphone.style.pointerEvents = "none";
            microphone.style.opacity = 0;
            enter.style.pointerEvents = "none";
            input.blur()
          } else if (current_question_type == "order_items_edit") {
          } else if (current_question_type == "order_items_submit") {
          } else if (current_question_type == "file_upload") {
            callFileUpload(question_array);
            input.blur()
            if (question_array[0].is_ai_available == "1") {
              footer.style.display = "block";
              input.type = "text";
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
              setPlaceHolders();
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              entry_id = question_array[0].ai_question_id;
            } else {
              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";
              setPlaceHolders();
              if (shouldShowMenu) {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
                footer.style.display = "block";
              } else {
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
                footer.style.display = "none";
              }
            }
          } else {
            callOtherQuestions(question_array);
            footer.style.display = "block";
            input.style.pointerEvents = "auto";
            microphone.style.pointerEvents = "auto";
            microphone.style.opacity = 1;
            enter.style.pointerEvents = "auto";
          }
        }

        function setPlaceHolders() {
          if (
            current_question_type == "radio" ||
            current_question_type == "radio_slides" ||
            current_question_type == "whatsapp_buttons" ||
            current_question_type == "whatsapp_list"
          ) {
            input.placeholder = "Select one option";
          } else if (current_question_type == "checkbox") {
            input.placeholder = "Select one or more option(s)";
          } else if (current_question_type == "range") {
            input.placeholder = "Use the slider";
          } else if (current_question_type == "rating") {
            input.placeholder = "Rate";
          } else if (current_question_type == "form") {
            input.placeholder = "Fill the form";
          } else if (current_question_type == "custom_single_choice") {
            input.placeholder = "Select one option";
          } else {
            input.placeholder = "Type your query";
          }
        }

        function setAllInputs(question_array) {
          if (question_array[0].type == "appointment") {
            if (
              question_array[0].default_options &&
              question_array[0].default_options.length > 0
            ) {
              appointment_timezone = JSON.parse(
                question_array[0].default_options
              ).timezone;
              if (
                JSON.parse(question_array[0].default_options)
                  .enable_timezone_selection == "1"
              ) {
                enable_timezone_selection = true;
              } else {
                enable_timezone_selection = false;
              }
            }
          }
          if (question_array[0].type == "live_agent") {
            var selected_country = document.getElementById("selected_country");
            if (footer.contains(selected_country)) {
              footer.removeChild(selected_country);
            }
            if (footer.contains(attach_label)) {
              footer.removeChild(attach_label);
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
            }
          }
          if (
            question_array[0].default_options &&
            question_array[0].default_options.length > 0 &&
            question_array[0].type != "form"
          ) {
            question_array[0].default_options =
              question_array[0].default_options.replace(/\\/g, "");
          }
          if (
            question_array[0].type == "email" ||
            question_array[0].type == "phone" ||
            question_array[0].type == "question" ||
            question_array[0].type == "ask_contacts" ||
            question_array[0].type == "date" ||
            question_array[0].type == "appointment" ||
            question_array[0].type == "time" ||
            question_array[0].type == "location" ||
            question_array[0].type == "number" ||
            question_array[0].type == "custom_entry" ||
            question_array[0].type == "website"
          ) {
            footer.style.display = "block";
            footer.classList.remove("close");
            if (shouldShowMenu) {
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
            }
            input.focus();
            if (header.contains(company_title_description)) {
              body.style.height = "calc(100% - 226px)";
            } else {
              body.style.height = "calc(100% - 150px)";
            }
            if (question_array[0].type == "email") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              if (is_firefox) {
                input.type = "text";
              } else {
                input.type = "email";
              }
              input.id = "";
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Enter your email", main_lang_code, language_code, 2);
            } else if (question_array[0].type == "location") {
              try {
                if (google && google.maps && google.maps.places) {
                } else {
                  var url =
                    "https://maps.googleapis.com/maps/api/js?key=AIzaSyCz-wSt1gcqHYjGt2GJoO8kPepV_QwXZOg&loading=async&libraries=places,marker",
                    script = document.createElement("script");
                  script.type = "text/javascript";
                  script.src = url;
                  head.appendChild(script);
                }
              } catch (e) {
                var url =
                  "https://maps.googleapis.com/maps/api/js?key=AIzaSyCz-wSt1gcqHYjGt2GJoO8kPepV_QwXZOg&loading=async&libraries=places,marker",
    
                  script = document.createElement("script");
                script.type = "text/javascript";
                script.src = url;
                head.appendChild(script);
              }
              var google_places_loaded;
              if (question_array[0].default_options && question_array[0].default_options.length > 0) {
                var json = JSON.parse(question_array[0].default_options)    
              }
              
              var location_type = '1'
    
              if (json && json.interface && json.interface.length > 0) {
                if (json.interface == 'modern') {
                   location_type = '2'
                }else{
                  location_type = '1'
                }
              }

              function openMaps() {
                if (!google_places_loaded) {
                  try {
                    if (google && google.maps && google.maps.places) {
                      google_places_loaded = true;
                      var selected_country =
                        document.getElementById('selected_country');
                      if (footer.contains(selected_country)) {
                        footer.removeChild(selected_country);
                      }
                      enter.style.pointerEvents = 'none';
                      input.id = 'pac-input-botest';
                      translateContent(translations, input, "Enter a place", main_lang_code, language_code, 2);
                      
                      footer.id = 'pac-container-botest';
                      if (is_safari) {
                        input.type = 'value';
                      } else {
                        input.type = 'text';
                      }
                      input.autocomplete = 'on';
                      if (shouldShowMenu) {
                        if (voice_input == '1') {
                          input.style.cssText =
                            input.style.cssText +
                            'width:calc(100% - 115px) !important';
                        } else {
                          input.style.cssText =
                            input.style.cssText +
                            'width:calc(100% - 80px) !important';
                        }
                      } else {
                        if (voice_input == '1') {
                          input.style.cssText =
                            input.style.cssText +
                            'width:calc(100% - 75px) !important';
                        } else {
                          input.style.cssText =
                            input.style.cssText +
                            'width:calc(100% - 45px) !important';
                        }
                      }
                      input.style.cssText =
                        input.style.cssText + 'min-height:24px !important';
                      input.style.cssText = input.style.cssText + "height:24px !important";
                      input.style.cssText = input.style.cssText + "border:none !important";

                      // input.style.cssText =
                      //   input.style.cssText + "max-height:72px !important";
                      var main_div_loaded;
    
                      var current_location = document.createElement('BUTTON');
                      current_location.classList.add('curent-locaion-button');
                      if (font && font.length > 0) {
                        current_location.classList.add(font);
                      }
    
                      function addClass() {
                        if (!main_div_loaded) {
                          var pacContainers =
                            document.getElementsByClassName('pac-container');
                          if (pacContainers.length > 0) {
                            main_div_loaded = true;
    
                            var opened_div = document.getElementById('opened');
    
                            if (
                              opened_div.contains(
                                document.getElementById('bg-shadow-overlay')
                              )
                            ) {
                              opened_div.removeChild(
                                document.getElementById('bg-shadow-overlay')
                              );
                            }
    
                            var close_icon_div = document.createElement('DIV');
                            close_icon_div.setAttribute('class', 'close-icon-div');
    
                            var close_icon_img = document.createElement('IMG');
                            close_icon_img.src =
                              'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small.svg';
                            close_icon_img.alt = 'closeicon';
                            close_icon_img.style.width = '10px';
                            close_icon_img.style.height = '10px';
    
                            var bg_shadow_location = document.createElement('DIV');
                            bg_shadow_location.setAttribute(
                              'id',
                              'bg-shadow-overlay'
                            );
                            bg_shadow_location.style.height = '84.5%';
                            bg_shadow_location.style.visibility = 'hidden';
    
                            var orderItems_container =
                              document.createElement('DIV');
                            orderItems_container.setAttribute(
                              'id',
                              'location_container'
                            );
                            orderItems_container.style.minHeight = '15%';
                            orderItems_container.style.opacity = '1';
                            orderItems_container.style.transform = 'translateY(0)';
    
                            // orderItems_container.appendChild(close_icon_div);
                            // close_icon_div.appendChild(close_icon_img);
    
                            Array.from(pacContainers).forEach(function (
                              pacContainer
                            ) {
                              if (
                                !pacContainer.classList.contains(
                                  'pac-container-thopest'
                                )
                              ) {
                                pacContainer.classList.add('pac-container-thopest');
                                opened_div.appendChild(bg_shadow_location);
                                bg_shadow_location.appendChild(
                                  orderItems_container
                                );
                                orderItems_container.appendChild(pacContainer);
                                // opened_div.appendChild(pacContainer);
                              }
                              current_location.innerHTML = generateTranslatedContent(translations, "Get Current Location", main_lang_code, language_code, input);
                              orderItems_container.appendChild(current_location);
                            });
                            stopIntervalGoogle();
                          }
                        } else {
                          stopIntervalGoogle();
                        }
                      }
    
                      current_location.addEventListener('click', function (k) {
                        getLocation();
                      });
    
                      function getLocation() {
                        if (navigator.geolocation) {
                          navigator.geolocation.getCurrentPosition(
                            showPosition,
                            showError,
                            {
                              enableHighAccuracy: true,
                              timeout: 5000,
                              maximumAge: 0,
                            }
                          );
                        } else {
                          window.alert(
                            'Geolocation is not supported by this browser.'
                          );
                        }
                      }
                      function showError(error) {
                        switch (error.code) {
                          case error.PERMISSION_DENIED:
                            window.alert(
                              'User denied the request for Geolocation.'
                            );
                            break;
                          case error.POSITION_UNAVAILABLE:
                            window.alert('Location information is unavailable.');
                            break;
                          case error.TIMEOUT:
                            window.alert(
                              'The request to get user location timed out.'
                            );
                            break;
                          case error.UNKNOWN_ERROR:
                            window.alert('An unknown error occurred.');
                            break;
                        }
                      }
    
                      function calculateDistance(lat1, lon1, lat2, lon2) {
                        var p = 0.017453292519943295; // Math.PI / 180
                        var c = Math.cos;
                        var a =
                          0.5 -
                          c((lat2 - lat1) * p) / 2 +
                          (c(lat1 * p) * c(lat2 * p) * (1 - c((lon2 - lon1) * p))) /
                            2;
    
                        return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
                      }
    
                      function showPosition(position) {
                        var lat = position.coords.latitude;
                        var lng = position.coords.longitude;
                        var geocoder = new google.maps.Geocoder();
                        var latlng = { lat: lat, lng: lng };
                        // console.log(latlng);
                        geocoder.geocode(
                          { location: latlng },
                          function (results, status) {
                            if (status === 'OK') {
                              if (results[0]) {
                                // console.log(results);
                                locationSearchClicked = !0;
                                enter.style.pointerEvents = 'auto';
                                place_id = results[0].place_id;
                                input.value = results[0].formatted_address;
                                if (document.getElementById('bg-shadow-overlay')) {
                                  document.getElementById(
                                    'bg-shadow-overlay'
                                  ).style.visibility = 'hidden';
                                }
                              } else {
                                window.alert('No results found');
                              }
                            } else {
                              window.alert('Geocoder failed due to: ' + status);
                            }
                          }
                        );
                      }
    
                      input.addEventListener('input', function (k) {
                        if (this.value?.length > 0) {
                          if (document.getElementById('bg-shadow-overlay')) {
                            document.getElementById(
                              'bg-shadow-overlay'
                            ).style.visibility = 'visible';
                          }
                        } else {
                          if (document.getElementById('bg-shadow-overlay')) {
                            document.getElementById(
                              'bg-shadow-overlay'
                            ).style.visibility = 'hidden';
                          }
                        }
                      });
    
                      function stopIntervalGoogle() {
                        clearInterval(timer);
                      }
    
                      var timer = setInterval(addClass, 100);
                      var options;
                      if (chatbot_id == '18664' || chatbot_id == '19819') {
                        options = {
                          componentRestrictions: { country: 'ca' },
                          strictBounds: false,
                        };
                      } else {
                        options = {};
                      }
                      var autocomplete = new google.maps.places.Autocomplete(
                        input,
                        options
                      );
    
                      autocomplete.addListener('place_changed', function () {
                        var place = autocomplete.getPlace();
                        if (place && place.geometry) {
                          locationSearchClicked = !0;
                          lat = place.geometry.location.lat();
                          lng = place.geometry.location.lng();
                          place_id = place.place_id;
                          enter.style.pointerEvents = 'auto';
                          input.value = place.formatted_address;
                          if (document.getElementById('bg-shadow-overlay')) {
                            document.getElementById(
                              'bg-shadow-overlay'
                            ).style.visibility = 'hidden';
                          }
                          var distance = calculateDistance(
                            '17.4354259',
                            '78.4183355',
                            lat,
                            lng
                          );
                          // console.log('Distance: ' + distance.toFixed(2) + ' km');
                        } else {
                          locationSearchClicked = !1;
                          enter.style.pointerEvents = 'none';
                        }
                      });
                    }
                  } catch (e) {
                  } finally {
                  }
                } else {
                  stopInterval();
                }
              }
    
              function openMapsNew() {
                if (!google_places_loaded) {
                  try {
                    if (google && google.maps && google.maps.places) {
                      google_places_loaded = true;
                      var selected_country = document.getElementById('selected_country');
                      if (footer.contains(selected_country)) {
                        footer.removeChild(selected_country);
                      }
                      enter.style.pointerEvents = 'none';
                      // input.id = 'pac-input-botest';
                      translateContent(translations, input, "Select location from menu", main_lang_code, language_code, 2);
                      input.style.pointerEvents = 'none';
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      footer.id = 'pac-container-botest';
                      if (is_safari) {
                        input.type = 'value';
                      } else {
                        input.type = 'text';
                      }
                      input.autocomplete = 'on';

                      if (shouldShowMenu) {
                        if (voice_input == '1') {
                          input.style.cssText =
                            input.style.cssText + 'width:calc(100% - 115px) !important';
                        } else {
                          input.style.cssText =
                            input.style.cssText + 'width:calc(100% - 80px) !important';
                        }
                      } else {
                        if (voice_input == '1') {
                          input.style.cssText =
                            input.style.cssText + 'width:calc(100% - 75px) !important';
                        } else {
                          input.style.cssText =
                            input.style.cssText + 'width:calc(100% - 45px) !important';
                        }
                      }
                      input.style.cssText =
                        input.style.cssText + 'min-height:24px !important';
                      input.style.cssText = input.style.cssText + "height:24px !important";
                      input.style.cssText = input.style.cssText + "border:none !important";
                      // input.style.cssText =
                      //   input.style.cssText + "max-height:72px !important";
                      var main_div_loaded;
              
                      var current_location = document.createElement('BUTTON');
                      current_location.classList.add('curent-locaion-button');
                      if (font && font.length > 0) {
                        current_location.classList.add(font);
                      }
              
                      function addClass() {
                        if (!main_div_loaded) {
                          var pacContainers =
                            document.getElementsByClassName('pac-container');
                          if (pacContainers.length == 0) {
                            main_div_loaded = true;
              
                            var opened_div = document.getElementById('opened');
              
                            if (
                              opened_div.contains(
                                document.getElementById('bg-shadow-overlay')
                              )
                            ) {
                              opened_div.removeChild(
                                document.getElementById('bg-shadow-overlay')
                              );
                            }
                        
                            var bg_shadow_location = document.createElement('DIV');
                            bg_shadow_location.id = 'bg-shadow-overlay';

                            if (json && json.openMenu && json.openMenu.length > 0) {
                              if (json.openMenu == 'open') {
                                bg_shadow_location.style.visibility = 'visible';
                              }else{
                                bg_shadow_location.style.visibility = 'hidden';
                              }
                            }else{
                              bg_shadow_location.style.visibility = 'hidden';
                            }
              
                            var loaction_container = document.createElement('DIV');
                            loaction_container.id = 'location_container_type_two'
  
                            var close_icon_div = document.createElement('DIV');
                            close_icon_div.setAttribute('class', 'close-icon-div-small_sb');
              
                            var close_icon_img = document.createElement('IMG');
                            close_icon_img.src =
                              'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small+(2).svg';
                            close_icon_img.alt = 'closeicon';
                            close_icon_img.style.width = '10px';
                            close_icon_img.style.height = '10px';
              
                            var left_icon_img = document.createElement('IMG');
                            left_icon_img.src =
                              'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg';
                            left_icon_img.alt = 'closeicon';
                            left_icon_img.style.width = '10px';
                            left_icon_img.style.height = '10px';
                            left_icon_img.style.cursor = 'pointer';
              
                            var headder_main_div = document.createElement('DIV');
                            headder_main_div.classList.add('headder_main_div_sb');
              
                            var headder_main_text = document.createElement('DIV');
                            headder_main_text.innerHTML = generateTranslatedContent(translations, 'Select Your Location', main_lang_code, language_code); 
                            headder_main_text.style.textAlign = 'center';
                            headder_main_text.style.width = '90%';
                            headder_main_text.style.fontSize = '13px';
                            headder_main_text.style.fontWeight = '600';
                            if (font && font.length > 0) {
                              headder_main_text.classList.add(font);
                            }
              
                            close_icon_div.appendChild(close_icon_img);
                            headder_main_div.appendChild(left_icon_img);
                            headder_main_div.appendChild(headder_main_text);
                            // headder_main_div.appendChild(close_icon_div);
              
                            var filter_outer_div = document.createElement('DIV');
                            filter_outer_div.classList.add('filter_outer_div');
              
                            var current_location_div = document.createElement('DIV');
                            current_location_div.id = 'current_Location_Button_sb'

                            var current_location_icon = document.createElement('IMG');
                            current_location_icon.src =
                              'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/location-crosshairs-widget-sb.svg';
                            current_location_icon.alt = 'location icon';
                            current_location_icon.style.width = '16px';
                            current_location_icon.style.height = '16px';
              
                            current_location_div.appendChild(current_location_icon);
                            var search_bar_div = document.createElement('DIV');
                            search_bar_div.setAttribute('class', 'search_bar_div_orderItems');
              
                            var search_icon = document.createElement('IMG');
                            search_icon.src =
                              'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/search+(2).svg';
                            search_icon.alt = 'SearchIcon';
                            search_icon.style.width = '16px';
                            search_icon.style.height = '16px';
              
                            var search_bar_Input = document.createElement('INPUT');
                            search_bar_Input.setAttribute(
                              'class',
                              'search_bar_input_orderItems'
                            );
                            search_bar_Input.setAttribute('id', 'pac-input-botest-new');
                            search_bar_Input.placeholder = generateTranslatedContent(translations, 'Search your location', main_lang_code, language_code);
                            if (font && font.length > 0) {
                              search_bar_Input.classList.add(font);
                            }
              
                            search_bar_div.appendChild(search_bar_Input);
                            search_bar_div.appendChild(search_icon);
                            filter_outer_div.appendChild(search_bar_div);
                            filter_outer_div.appendChild(current_location_div);
              
                            var map_container = document.createElement('DIV');
                            map_container.setAttribute('id', 'map_new_sb');
              
                            var selected_location_container = document.createElement('DIV');
                            selected_location_container.classList.add(
                              'selected_location_container_sb'
                            );
              
                            var label_location_header = document.createElement('LABEL');
                            label_location_header.innerHTML = generateTranslatedContent(translations, 'Your Selected Location', main_lang_code, language_code);
                            label_location_header.style.color = '#1D2D35';
                            label_location_header.style.fontSize = '14px';
                            label_location_header.style.fontWeight = '600';
              
                            var label_location_text = document.createElement('LABEL');
                            label_location_text.style.color = '#576E93';
                            label_location_text.style.fontSize = '14px';
                            label_location_text.style.fontWeight = '500';
                            label_location_text.style.overflow = 'hidden';
                            label_location_text.style.textOverflow = 'ellipsis';
                            label_location_text.style.overflowWrap = 'anywhere';
    
                            var submit_btn = document.createElement('Button');
                            submit_btn.classList.add('confirm-btn-smatest');
                            submit_btn.style.marginBottom = '22px'
                            submit_btn.setAttribute('id', 'whatsapplist-submit_btn');
                            submit_btn.style.width = '100%'
                            submit_btn.innerHTML = generateTranslatedContent(translations, 'Submit', main_lang_code, language_code);
              
                            var submit_icon = document.createElement('IMG');
                            submit_icon.src =
                              'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
                            submit_icon.alt = 'SubmitIcon';
                            submit_icon.style.width = '18px';
                            submit_icon.style.height = '18px';
              
                            submit_btn.appendChild(submit_icon);
              
                            selected_location_container.appendChild(label_location_header);
                            selected_location_container.appendChild(label_location_text);
              
                            if (font && font.length > 0) {
                              label_location_header.classList.add(font);
                              label_location_text.classList.add(font);
                              submit_btn.classList.add(font);
                            }
              
                            loaction_container.appendChild(headder_main_div);
                            loaction_container.appendChild(filter_outer_div);
                            loaction_container.appendChild(map_container);
                            loaction_container.appendChild(selected_location_container);
                            bg_shadow_location.appendChild(loaction_container);
                            createBrandWrapper(bg_shadow_location, 'SmatBot', main_url, font);
                            opened_div.appendChild(bg_shadow_location);
              
                            const mapFrame = document.createElement('IFRAME');
                            mapFrame.setAttribute('id', 'map_frame');
                            mapFrame.style.height = '200px';
                            mapFrame.style.width = '100%';
                            map_container.appendChild(mapFrame);

                            left_icon_img.addEventListener('click', function () {
                              bg_shadow_location.style.visibility = 'hidden';
                              loaction_container.style.opacity = '0.5';
                              loaction_container.style.transform = 'translateY(100%)';
                            });
                            close_icon_div.addEventListener('click', function () {
                              botWidget.minimise();
                            });
              
                            setTimeout(() => {
                              Array.from(pacContainers).forEach(function (pacContainer) {
                                if (
                                  !pacContainer.classList.contains(
                                    'pac-container-thopest-newType'
                                  )
                                ) {
                                  pacContainer.classList.add('pac-container-thopest-newType');
                                  filter_outer_div.appendChild(pacContainer);
                                }
                              });
                            }, 500);
              
                            let map;
                            let marker;
                            let geocoder;
                            let infoWindow;
                            let autocomplete;
              
                            const mapContainer = document.getElementById('map_new_sb');
                            const input = document.getElementById('pac-input-botest-new');
                            const currentLocationButton = document.getElementById(
                              'current_Location_Button_sb'
                            );
              
                            function initMap() {
                              map = new google.maps.Map(mapContainer, {
                                center: { lat: 20.5937, lng: 78.9629 },
                                zoom: 5,
                                mapId: 'a8309201f6864e2a',
                              });
              
                              geocoder = new google.maps.Geocoder();
                              infoWindow = new google.maps.InfoWindow();
              
                              autocomplete = new google.maps.places.Autocomplete(input);
              
                              autocomplete.addListener('place_changed', () => {
                                const place = autocomplete.getPlace();
                                if (place.geometry) {
                                  if (marker) marker.setMap(null);
                                  map.setCenter(place.geometry.location);
                                  map.setZoom(15);
                                  marker = new google.maps.Marker({
                                    position: place.geometry.location,
                                    map: map,
                                    title: place.formatted_address,
                                    draggable: true, 
                                  });
              
                                  if (selected_location_container.contains(submit_btn)) {
                                  }else{
                                    selected_location_container.appendChild(submit_btn)
                                  }
    
                                    // Add click event listener to the map
                                  google.maps.event.addListener(map, 'click', (event) => {
                                    const pos = {
                                      lat: event.latLng.lat(),
                                      lng: event.latLng.lng(),
                                    };
                                    geocodeLatLng(geocoder, map, pos, (address) => {
                                      // updateUI(pos, address);
                                      input.value = address;
                                      label_location_text.innerHTML = address;
                                      marker.setPosition(pos); // Update marker position
                                      marker.setTitle(address); // Update the marker's title
                                      infoWindow.setContent(address);
                                      infoWindow.open(map, marker);
                                    });
                                  });
              
                                  google.maps.event.addListener(
                                    marker,
                                    'dragend',
                                    (event) => {
                                      const newPos = {
                                        lat: event.latLng.lat(),
                                        lng: event.latLng.lng(),
                                      };
                                      geocodeLatLng(geocoder, map, newPos, (address) => {
                                        input.value = address;
                                        label_location_text.innerHTML = address;
                                        infoWindow.setContent(address);
                                        infoWindow.open(map, marker);
                                      if (selected_location_container.contains(submit_btn)) {
                                      }else{
                                         selected_location_container.appendChild(submit_btn)
                                      }
                                        marker.setTitle(address); // Finalize marker title after drag
                                      });
                                    }
                                  );
              
                                  label_location_text.innerHTML = place.formatted_address;
              
                                  // console.log('Selected Place:', place);
                                  infoWindow.setContent(place.formatted_address);
                                  infoWindow.open(map, marker);
                                } else {
                                  console.error(
                                    'No details available for input: ' + input.value
                                  );
                                }
                              });
              
                              // Set up event listener for current location button
                              currentLocationButton.addEventListener('click', () => {
                                getCurrentLocation();
                              });
                            }
    
                            function getCurrentLocation() {
                              if (navigator.geolocation) {
                                navigator.geolocation.getCurrentPosition(
                                  (position) => {
                                    // console.log('accuracy---',position.coords.accuracy)
                                    // console.log('position---',position)
                                    const pos = {
                                      lat: position.coords.latitude,
                                      lng: position.coords.longitude,
                                    };
                                    map.setCenter(pos);
                                    map.setZoom(15);
              
                                    // Update search input with current location
                                    geocodeLatLng(geocoder, map, pos, (address) => {
                                      input.value = address;
                                      label_location_text.innerHTML = address;
                                      if (marker) marker.setMap(null); // Remove previous marker
                                      marker = new google.maps.Marker({
                                        position: pos,
                                        map: map,
                                        title: address,
                                        draggable: true, // Make the marker draggable
                                      });
    
                                      if (selected_location_container.contains(submit_btn)) {
                                      }else{
                                        selected_location_container.appendChild(submit_btn)
                                      }
    
                                         // Add click event listener to the map
                                      google.maps.event.addListener(map, 'click', (event) => {
                                        const pos = {
                                          lat: event.latLng.lat(),
                                          lng: event.latLng.lng(),
                                        };
                                        geocodeLatLng(geocoder, map, pos, (address) => {
                                          // updateUI(pos, address);
                                          input.value = address;
                                          label_location_text.innerHTML = address;
                                          marker.setPosition(pos); // Update marker position
                                          marker.setTitle(address); // Update the marker's title
                                          infoWindow.setContent(address);
                                          infoWindow.open(map, marker);
                                        });
                                      });
                       
                                      google.maps.event.addListener(
                                        marker,
                                        'dragend',
                                        (event) => {
                                          const newPos = {
                                            lat: event.latLng.lat(),
                                            lng: event.latLng.lng(),
                                          };
                                          geocodeLatLng(geocoder, map, newPos, (newAddress) => {
                                            input.value = newAddress;
                                            label_location_text.innerHTML = newAddress;
                                            marker.setTitle(newAddress); // Finalize marker title after drag
                                            infoWindow.setContent(newAddress);
                                            infoWindow.open(map, marker);
                                            if (selected_location_container.contains(submit_btn)) {
                                            }else{
                                              selected_location_container.appendChild(submit_btn)
                                            }
                                          });
                                        }
                                      );
              
                                      infoWindow.setContent(address);
                                      infoWindow.open(map, marker);
                                    });
                                  },
                                  () => {
                                    handleLocationError(true, infoWindow, map.getCenter());
                                  },
                                  {
                                    enableHighAccuracy: true, // Request high accuracy
                                    timeout: 5000, // Timeout after 5 seconds
                                    maximumAge: 0, // Do not use a cached position
                                  }
                                );
                              } else {
                                handleLocationError(false, infoWindow, map.getCenter());
                              }
                            }
              
                            function geocodeLatLng(geocoder, map, pos, callback) {
                              geocoder.geocode({ location: pos }, (results, status) => {
                                if (status === 'OK') {
                                  if (results[0]) {
                                    if (callback) callback(results[0].formatted_address);
                                  } else {
                                    console.log('No results found');
                                  }
                                } else {
                                  console.log('Geocoder failed due to: ' + status);
                                }
                              });
                            }
              
                            function handleLocationError(
                              browserHasGeolocation,
                              infoWindow,
                              pos
                            ) {
                              infoWindow.setContent(
                                browserHasGeolocation
                                  ? 'Error: The Geolocation service failed.'
                                  : "Error: Your browser doesn't support geolocation."
                              );
                              infoWindow.setPosition(pos);
                              infoWindow.open(map);
                            }
              
                            initMap();
                            
              
                            submit_btn.addEventListener('click', function () {
                              if (label_location_text.innerHTML.length > 0) {
              
                                var radioMenu = document.getElementById('open-menu-sb');
                                var optionsDiv = document.getElementsByClassName(
                                  'options-div-smatest'
                                );
              
                                if (radioMenu && optionsDiv.length > 0) {
                                  if (optionsDiv[optionsDiv.length - 1].contains(radioMenu)) {
                                    optionsDiv[optionsDiv.length - 1].removeChild(radioMenu);
                                  }
                                }
              
                                takingRadioValue(
                                  label_location_text.innerHTML,
                                  bg_shadow_location
                                );

                                var main_opened_div = document.getElementById('opened');
        
                                if (
                                  main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                                ) {
                                  main_opened_div.removeChild(
                                    document.getElementById('bg-shadow-overlay')
                                  );
                                }

                              }
                            });
              
                            stopIntervalGoogle();
                          }
                        } else {
                          stopIntervalGoogle();
                        }
                      }
              
                      function stopIntervalGoogle() {
                        clearInterval(timer);
                      }
              
                      var timer = setInterval(addClass, 100);
                    }
                  } catch (e) {
                  } finally {
                  }
                } else {
                  stopInterval();
                }
              }
              
              function stopInterval() {
                clearInterval(timer);
              }
    
              if (location_type == '1') {
                var timer = setInterval(openMaps, 100);
              }else{
                var timer = setInterval(openMapsNew, 100);
                input.blur();
              }
    
            } else if (question_array[0].type == "phone") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              var select_country = document.createElement("SELECT");
              select_country.id = "selected_country";
              select_country.style.cssText = select_country.style.cssText + "margin:0 !important";
              select_country.style.cssText = select_country.style.cssText + "height:34px !important";
              for (var i = 0; i < countries.length; i++) {
                var option = document.createElement("option");
                option.value = countries[i];
                option.innerHTML = countries[i];
                select_country.appendChild(option);
              }
              select_country.classList.add("smat-dropdown-botest");
              if (font && font.length > 0) {
                select_country.classList.add(font);
              }
              if (user_dial_code) {
                select_country.value = user_dial_code;
              } else {
                select_country.value = "India +91";
              }
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 185px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 150px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 150px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              if (is_firefox) {
                input.type = "text";
              } else {
                input.type = "number";
              }
              input.id = "";
              footer.id = "";
              input.value = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Enter your phone number", main_lang_code, language_code, 2);
              var shouldNotInsert;
              var childs = footer.children;
              for (var i = 0; i < childs.length; i++) {
                if (childs[i].id == "selected_country") {
                  shouldNotInsert = !0;
                }
              }
              if (!shouldNotInsert) {
                if (shouldShowMenu) {
                  footer.insertBefore(select_country, footer.children[2]);
                } else {
                  footer.insertBefore(select_country, footer.firstChild);
                }
              }
            } else if (question_array[0].type == "number") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              if (
                question_array[0].default_options &&
                question_array[0].default_options.length > 0
              ) {
                var default_obj = JSON.parse(question_array[0].default_options);
                input.min = default_obj.min;
                input.max = default_obj.max;
              }
              if (is_firefox) {
                input.type = "text";
              } else {
                input.type = "number";
              }
              input.id = "";
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Enter a number", main_lang_code, language_code, 2);
            } else if (question_array[0].type == "website") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              if (is_safari) {
                input.type = "value";
              } else {
                input.type = "text";
              }
              input.id = "";
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Enter website url", main_lang_code, language_code, 2);
            } else if (question_array[0].type == "question") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              if (is_safari) {
                if (question_array[0].default_options && question_array[0].default_options.length > 0) {
                  var json = JSON.parse(question_array[0].default_options);
                  if (json.data_mask) {
                    input.type = 'password';
                  } else {
                    input.type = 'value';
                  }
                } else {
                  input.type = 'value';
                }
              } else {
                if (question_array[0].default_options && question_array[0].default_options.length > 0) {
                  var json = JSON.parse(question_array[0].default_options);
                  if (json.data_mask) {
                    input.type = 'password';
                  } else {
                    input.type = 'text';
                  }
                } else {
                  input.type = 'text';
                }
              }
              input.id = "";
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Type your answer", main_lang_code, language_code, 2);
            } else if (question_array[0].type == "ask_contacts") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              if (is_safari) {
                input.type = "value";
              } else {
                input.type = "text";
              }
              input.id = "";
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Contact in Name, Phone Number format", main_lang_code, language_code, 2);
            } else if (question_array[0].type == "custom_entry") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              if (is_safari) {
                input.type = "value";
              } else {
                input.type = "text";
              }
              entry_id = question_array[0].id;
              df_options = question_array[0].default_options;
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              input.id = "";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Type your query", main_lang_code, language_code, 2);
            } else if (question_array[0].type == "date") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              input.type = "text";
              translateContent(translations, input, "Select date", main_lang_code, language_code, 2);
              // input.placeholder = "Enter date in dd/mm/yyyy format";
              input.id = "smatest_datepicker";
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "smatest_date_container";
              input.autocomplete = "off";
              showDatePicker(question_array[0].default_options);
              if (
                question_array[0].default_options &&
                question_array[0].default_options.length > 0
              ) {
                var json = JSON.parse(question_array[0].default_options);
                if (json.date_output_format && json.date_output_format.length > 0) {
                  date_output_format = json.date_output_format;
                } else {
                  date_output_format = "dd-mm-yyyy";
                }
              } else {
                date_output_format = "dd-mm-yyyy";
              }
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
            } else if (question_array[0].type == "appointment") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              input.type = "text";
              // input.placeholder = "Enter date in dd/mm/yyyy format";
              input.id = "smatest_datepicker";
              input.placeholder =  generateTranslatedContent(translations, 'Select your slot from menu', main_lang_code, language_code, input);

              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "smatest_date_container";
              input.autocomplete = "off";

              input.style.pointerEvents = "none";
              microphone.style.pointerEvents = "none";
              microphone.style.opacity = 0;
              enter.style.pointerEvents = "none";

              showAppointmentBooking(question_array[0].default_options, 1, question_array[0].id)
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
            } else if (question_array[0].type == "time") {
              var selected_country = document.getElementById("selected_country");
              if (footer.contains(selected_country)) {
                footer.removeChild(selected_country);
              }
              input.type = "text";
              input.classList.add("timepicker-ui-input");
              input.id = "";
              input.value = "12:00 AM";
              var is_mobile;
              if (
                /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                  navigator.userAgent
                )
              ) {
                is_mobile = true;
              } else {
                is_mobile = false;
              }
              appendScriptLinks("https://smatbot.s3.amazonaws.com/files/timepicker.js", "script");
              const interval = setInterval(() => {
                if (typeof TimepickerUI !== "undefined") {
                  clearInterval(interval); 
                  const timePicker = new TimepickerUI(footer, {
                    mobile: false,
                    enableSwitchIcon: true,
                    backdrop: true,
                  });
                  timePicker.create();
                }
              }, 100); 
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
            }
          } else if (
            question_array[0].type == "order_items" ||
            question_array[0].type == "order_items_edit" ||
            question_array[0].type == "order_items_submit"
          ) {
            input.placeholder = "Select item(s) and click enter";
            input.type = "text";
            input.style.pointerEvents = 'none';
            microphone.style.pointerEvents = "none";
            microphone.style.opacity = 0;
            input.blur()
            if (
              question_array[0].type == "order_items_edit" ||
              question_array[0].type == "order_items_submit"
            ) {
              if (!shouldShowMenu) {
                footer.style.display = "none";
                footer.classList.add("close");
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
              } else {
                if (entry_id) {
                  input.style.pointerEvents = "auto";
                  microphone.style.pointerEvents = "auto";
                  microphone.style.opacity = 1;
                  enter.style.pointerEvents = "auto";
                  setPlaceHolders();
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                } else {
                  input.blur();
                  input.style.pointerEvents = "none";
                  microphone.style.pointerEvents = "none";
                  microphone.style.opacity = 0;
                  enter.style.pointerEvents = "none";
                  input.placeholder = "Choose from Menu";
                  input.type = "text";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                }
              }
            }
          } else {
            if (entry_id) {
              if (is_safari) {
                input.type = "value";
              } else {
                input.type = "text";
              }
              input.id = "";
              footer.id = "";
              input.autocomplete = "off";
              try {
                google.maps.event.clearInstanceListeners(input);
              } catch (e) {
              } finally {
              }
              translateContent(translations, input, "Type your query", main_lang_code, language_code, 2);
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
              input.style.cssText = input.style.cssText + "min-height:24px !important";
              input.style.cssText = input.style.cssText + "height:24px !important";
              input.style.cssText = input.style.cssText + "border:none !important";
              // input.style.cssText = input.style.cssText + "max-height:72px !important";
            } else {
              if (!shouldShowMenu) {
                footer.style.display = "none";
                footer.classList.add("close");
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 168px)";
                } else {
                  body.style.height = "calc(100% - 93px)";
                }
              } else {
                if (entry_id) {
                  input.style.pointerEvents = "auto";
                  microphone.style.pointerEvents = "auto";
                  microphone.style.opacity = 1;
                  enter.style.pointerEvents = "auto";
                  setPlaceHolders();
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                } else {
                  if (question_array[0].type == "form") {
                    footer.style.display = "none";
                    footer.classList.add("close");
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                  }else{
                    input.blur();
                    input.style.pointerEvents = "none";
                    microphone.style.pointerEvents = "none";
                    microphone.style.opacity = 0;
                    enter.style.pointerEvents = "none";
                    input.placeholder = "Choose from Menu";
                    input.type = "text";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                  }
                }
              }
            }
          }
          if (question_array[0].is_set_dynamic == "1") {
            if (
              question_array[0].prefill_value &&
              question_array[0].prefill_value != null &&
              question_array[0].prefill_value.length > 0
            ) {
              if (question_array[0].type == "number") {
                input.value = parseInt(question_array[0].prefill_value);
              } else {
                input.value = question_array[0].prefill_value;
              }
            }
          }
        }

        function mainApiCall() {
          var otherSpinningDiv = document.createElement("DIV");
          otherSpinningDiv.classList.add("question-div-smatest");
          otherSpinningDiv.classList.add("top-0");
          if (font && font.length > 0) {
            otherSpinningDiv.classList.add(font);
          }
          var otherSpinnerDiv = document.createElement("DIV");
          otherSpinnerDiv.classList.add("spinner1-smatest");
          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
          ques_icon.src = avatar_icon;
          var iconDiv = document.createElement("DIV");
          iconDiv.appendChild(ques_icon);
          iconDiv.classList.add("question-icon-div");
          ques_icon.classList.add("question-icon-smatest");
          var inner1 = document.createElement("DIV");
          inner1.classList.add("bounce1");
          var inner2 = document.createElement("DIV");
          inner2.classList.add("bounce2");
          var inner3 = document.createElement("DIV");
          inner3.classList.add("bounce3");
          otherSpinnerDiv.appendChild(inner1);
          otherSpinnerDiv.appendChild(inner2);
          otherSpinnerDiv.appendChild(inner3);
          otherSpinningDiv.appendChild(iconDiv);
          otherSpinningDiv.appendChild(otherSpinnerDiv);
          body.appendChild(otherSpinningDiv);
          var cookiesObject;
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
              body.removeChild(otherSpinningDiv);
              lead_revisited = !0;
              try {
                if (
                  JSON.parse(this.response).is_live_chat_started &&
                  JSON.parse(this.response).is_live_chat_started == "1"
                ) {
                }
              } catch (e) {
              } finally {
              }
              cb_session = JSON.parse(this.response).cb_session;
              live_chat_cb_session = JSON.parse(this.response).livechat_session;
              if (
                JSON.parse(this.response).language_code &&
                JSON.parse(this.response).language_code.length > 0 &&
                JSON.parse(this.response).language_code != "default"
              ) {
                main_lang_code = JSON.parse(this.response).language_code;
              }
              session_feedback = JSON.parse(this.response).feedback;
              question_array = JSON.parse(this.response).init_question;
              prev_questions_array = JSON.parse(this.response).qna_prev;
              is_user_answered_session = JSON.parse(
                this.response
              ).is_user_answered_session;
              if (is_user_answered_session) {
                if (!store_session) {
                  if (reload_div && !store_session_called) {
                    store_session_called = true;
                    reload_div.click();
                  }
                } else {
                  agreed = true;
                  var questionDIv = document.createElement("DIV");
                  questionDIv.classList.add("question-div-smatest");
                  setTimeout(function () {
                    questionDIv.classList.add("top-0");
                  }, transition_time);
                  if (font && font.length > 0) {
                    questionDIv.classList.add(font);
                  }
                  var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon1);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon1.src = avatar_icon;
                  ques_icon1.classList.add("question-icon-smatest");
                  var option_div = document.createElement("DIV");
                  option_div.classList.add("options-div-smatest");
                  var option_question = document.createElement("LABEL");
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == "he" ||
                        main_lang_code == "ur" ||
                        main_lang_code == "ar")) ||
                    (main_lang_code == "default" &&
                      (language_code == "ar" ||
                        language_code == "he" ||
                        language_code == "ur"))
                  ) {
                    option_question.classList.add("rtl");
                  }
                  translateContent(translations, option_question, "Hey! This is not the first time you are here. What would you like to do?", main_lang_code, language_code);
                  say(option_question.innerText);
                  option_div.appendChild(option_question);
                  questionDIv.appendChild(iconDiv);
                  option_question.classList.add("slides-label");
                  if (font && font.length > 0) {
                    option_question.classList.add(font);
                  }
                  if (
                    (main_lang_code &&
                      (main_lang_code == "he" ||
                        main_lang_code == "ur" ||
                        main_lang_code == "ar")) ||
                    (main_lang_code == "default" &&
                      (language_code == "ar" ||
                        language_code == "he" ||
                        language_code == "ur"))
                  ) {
                    option_question.classList.add("rtl");
                  }
                  option_div.appendChild(option_question);
                  option_div.classList.add("dialogs-div-more-smatest");
                  var slides_div = document.createElement("DIV");
                  slides_div.classList.add("avatar-scrollbar");
                  slides_div.classList.add("slides-random");
                  slides_div.id = "avatar-scroll";
                  var selectedKey;
                  var contact = document.createElement("DIV");
                  contact.classList.add("dialogs-div-smatest");
                  if (font && font.length > 0) {
                    contact.classList.add(font);
                  }
                  var label = document.createElement("LABEL");
                  translateContent(translations, label, "Start Again", main_lang_code, language_code);
                  label.style.cssText =
                    label.style.cssText + "color:" + answer_color + " !important;";
                  contact.appendChild(label);
                  slides_div.appendChild(contact);
                  contact.addEventListener("click", function (e) {
                    shouldStartEncourageTimer = !0;
                    nothingWentOnFor = 0;
                    encourageMessageIteration = 0;
                    if (reload_div) {
                      start_again_clicked = true;
                      reload_div.click();
                    }
                    try {
                      window.speechSynthesis.cancel();
                    } catch (e) {
                    } finally {
                    }
                  });
                  var selectedKey;
                  var otherContact = document.createElement("DIV");
                  otherContact.classList.add("dialogs-div-smatest");
                  if (font && font.length > 0) {
                    otherContact.classList.add(font);
                  }
                  var label = document.createElement("LABEL");
                  translateContent(translations, label, "Continue", main_lang_code, language_code);
                  label.style.cssText = label.style.cssText + "color:" + answer_color + " !important;";
                  label.style.cssText = label.style.cssText + "margin:0px !important";
                  otherContact.appendChild(label);
                  slides_div.appendChild(otherContact);
                  otherContact.addEventListener("click", function (e) {
                    shouldStartEncourageTimer = !0;
                    nothingWentOnFor = 0;
                    encourageMessageIteration = 0;
                    agreed = !0;
                    footer.style.display = "block";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.classList.remove("close");
                    if (shouldShowMenu) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                    }
                    try {
                      window.speechSynthesis.cancel();
                    } catch (e) {
                    } finally {
                    }
                    if (
                      document.getElementsByClassName("upload-button-sb") &&
                      document.getElementsByClassName("upload-button-sb").length > 0
                    ) {
                      document
                        .getElementsByClassName("upload-button-sb")[0]
                        .classList.remove("no-pointer-events");
                    }
                    var continueDiv =
                      this.parentElement.parentElement.parentElement;
                    if (body.contains(continueDiv)) {
                      body.removeChild(continueDiv);
                    }
                    if (prev_questions_array && prev_questions_array.length > 0) {
                      for (var i = 0; i < prev_questions_array.length; i++) {
                        if (prev_questions_array[i].type == "email") {
                          needPrivacy = "email";
                          privacyAnswer = prev_questions_array[i].answer_text;
                        }
                        if (prev_questions_array[i].type == "phone") {
                          needPrivacy = "phone";
                          privacyAnswer = prev_questions_array[i].answer_text;
                        }
                      }
                    }
                    if (!start_again_switch) {
                      needPrivacy = "";
                    }
                    if (needPrivacy && needPrivacy.length > 0) {
                      footer.style.display = "block";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                      footer.classList.remove("close");
                      if (shouldShowMenu) {
                        input.style.pointerEvents = "auto";
                        microphone.style.pointerEvents = "auto";
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = "auto";
                      }
                      input.focus();
                      if (needPrivacy == "email") {
                        if (is_firefox) {
                          input.type = "text";
                        } else {
                          input.type = "email";
                        }
                        input.id = "";
                        if (shouldShowMenu) {
                          if (voice_input == "1") {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 115px) !important";
                          } else {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 80px) !important";
                          }
                        } else {
                          if (voice_input == "1") {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 75px) !important";
                          } else {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 45px) !important";
                          }
                        }
                        input.style.cssText =
                          input.style.cssText + "min-height:24px !important";
                          input.style.cssText = input.style.cssText + "height:24px !important";
                          input.style.cssText = input.style.cssText + "border:none !important";
                        // input.style.cssText =
                        // input.style.cssText + "max-height:72px !important";
                        footer.id = "";
                        input.autocomplete = "off";
                        try {
                          google.maps.event.clearInstanceListeners(input);
                        } catch (e) {
                        } finally {
                        }
                        translateContent(translations, input, "Enter your email", main_lang_code, language_code, 2);
                      } else if (needPrivacy == "phone") {
                        var selected_country =
                          document.getElementById("selected_country");
                        if (footer.contains(selected_country)) {
                          footer.removeChild(selected_country);
                        }
                        var select_country = document.createElement("SELECT");
                        select_country.id = "selected_country";
                        select_country.style.cssText = select_country.style.cssText + "margin:0 !important";
                        select_country.style.cssText = select_country.style.cssText + "height:34px !important";
                        for (var i = 0; i < countries.length; i++) {
                          var option = document.createElement("option");
                          option.value = countries[i];
                          option.innerHTML = countries[i];
                          select_country.appendChild(option);
                        }
                        select_country.classList.add("smat-dropdown-botest");
                        if (font && font.length > 0) {
                          select_country.classList.add(font);
                        }
                        if (user_dial_code) {
                          select_country.value = user_dial_code;
                        } else {
                          select_country.value = "India +91";
                        }
                        if (shouldShowMenu) {
                          if (voice_input == "1") {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 185px) !important";
                          } else {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 150px) !important";
                          }
                        } else {
                          if (voice_input == "1") {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 150px) !important";
                          } else {
                            input.style.cssText =
                              input.style.cssText +
                              "width:calc(100% - 115px) !important";
                          }
                        }
                        input.style.cssText =
                          input.style.cssText + "min-height:24px !important";
                          input.style.cssText = input.style.cssText + "height:24px !important";
                          input.style.cssText = input.style.cssText + "border:none !important";
                        // input.style.cssText =
                        // input.style.cssText + "max-height:72px !important";
                        if (is_firefox) {
                          input.type = "text";
                        } else {
                          input.type = "number";
                        }
                        input.id = "";
                        footer.id = "";
                        input.value = "";
                        input.autocomplete = "off";
                        try {
                          google.maps.event.clearInstanceListeners(input);
                        } catch (e) {
                        } finally {
                        }
                        translateContent(translations, input, "Enter your phone number", main_lang_code, language_code, 2);
                        var shouldNotInsert;
                        var childs = footer.children;
                        for (var i = 0; i < childs.length; i++) {
                          if (childs[i].id == "selected_country") {
                            shouldNotInsert = !0;
                          }
                        }
                        if (!shouldNotInsert) {
                          if (shouldShowMenu) {
                            footer.insertBefore(select_country, footer.children[2]);
                          } else {
                            footer.insertBefore(select_country, footer.firstChild);
                          }
                        }
                      }
                      var questionDIv = document.createElement("DIV");
                      questionDIv.classList.add("question-div-smatest");
                      setTimeout(function () {
                        questionDIv.classList.add("top-0");
                      }, transition_time);
                      if (font && font.length > 0) {
                        questionDIv.classList.add(font);
                      }
                      var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon1);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon1.src = avatar_icon;
                      ques_icon1.classList.add("question-icon-smatest");
                      var option_div = document.createElement("DIV");
                      option_div.classList.add("options-div-smatest");
                      var option_question = document.createElement("LABEL");
                      if (font && font.length > 0) {
                        option_question.classList.add(font);
                      }
                      if (
                        (main_lang_code &&
                          (main_lang_code == "he" ||
                            main_lang_code == "ur" ||
                            main_lang_code == "ar")) ||
                        (main_lang_code == "default" &&
                          (language_code == "ar" ||
                            language_code == "he" ||
                            language_code == "ur"))
                      ) {
                        option_question.classList.add("rtl");
                      }
                      if (needPrivacy == "email") {
                        translateContent(translations, option_question, "For Security reasons, Please fill your Email again or restart a new chat session.", main_lang_code, language_code);
                        say(option_question.innerText);
                      } else if (needPrivacy == "phone") {
                        translateContent(translations, option_question, "For Security reasons, Please fill your Phone Number again or restart a new chat session.", main_lang_code, language_code);
                        say(option_question.innerText);
                      }
                      option_div.appendChild(option_question);
                      questionDIv.appendChild(iconDiv);
                      questionDIv.appendChild(option_div);
                      body.appendChild(questionDIv);
                      body.scrollTop = body.scrollHeight;
                    }
                    if (needPrivacy) {
                    } else {
                      previousQuestionsView(prev_questions_array);
                      var last_prev_question =
                        prev_questions_array[prev_questions_array.length - 1];
                      var wait_for_init_question;
                      if (
                        last_prev_question.type == "order_items" &&
                        last_prev_question.answer_text == "items_added" &&
                        last_prev_question.items_list &&
                        last_prev_question.items_list.length > 0
                      ) {
                        wait_for_init_question = true;
                      } else if (
                        last_prev_question.type == "order_items" &&
                        last_prev_question.answer_text == "items_edited" &&
                        last_prev_question.items_list &&
                        last_prev_question.items_list.length > 0
                      ) {
                        wait_for_init_question = true;
                      } else {
                      }
                      body.scrollTop = body.scrollHeight;
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      if (wait_for_init_question) {
                        if (spinningDiv && spinningDiv.parentNode == body) {
                          body.removeChild(spinningDiv);
                        }
                        order_items_question = last_prev_question;
                        selected_orders = last_prev_question.items_list;
                        order_question_options = last_prev_question.default_options;
                        order_items = [];
                        for (
                          var t = 0;
                          t < last_prev_question.total_items_list.length;
                          t++
                        ) {
                          order_items.push(last_prev_question.total_items_list[t]);
                        }
                        if (last_prev_question.answer_text == "items_added") {
                          var question = last_prev_question;
                          question.type = "order_items_edit";
                          question.question_text =
                            '<label style="font-weight: 600 !important;text-align: center;margin-bottom: 10px;color:black !important;">Choose Quantity</label>';
                          question_completed = !1;
                          input_value = "";
                          question_array = [];
                          question_array.push(question);
                          enter.style.pointerEvents = "auto";
                          current_question_type = "order_items_edit";
                          order_question_id = last_prev_question.id;
                          order_question_options =
                            last_prev_question.default_options;
                          current_logical_jump = last_prev_question.logical_jump;
                          currentMailSequence = last_prev_question.sequence;
                          currentQuestionIsLead = last_prev_question.send_mail;
                          question_id = last_prev_question.id;
                          setAllInputs(question_array);
                          assignAllQuestionTypes(current_question_type);
                          order_status_string = "items_edited";
                        } else if (
                          last_prev_question.answer_text == "items_edited"
                        ) {
                          var question = order_items_question;
                          question.type = "order_items_submit";
                          question.question_text =
                            '<label style="font-size: 15px !important;font-weight: 500 !important;text-align: center;margin-bottom: 10px;width:102%;">Order Details</label>';
                          question_completed = !1;
                          input_value = "";
                          question_array = [];
                          question_array.push(question);
                          enter.style.pointerEvents = "auto";
                          current_question_type = "order_items_submit";
                          current_logical_jump = question_array[0].logical_jump;
                          currentMailSequence = question_array[0].sequence;
                          currentQuestionIsLead = question_array[0].send_mail;
                          question_id = question_array[0].id;
                          setAllInputs(question_array);
                          assignAllQuestionTypes(current_question_type);
                          order_status_string = "order_items_submit";
                        }
                      } else {
                        if (question_array && question_array.length > 0) {
                          question_completed = !1;
                          setTimeout(function () {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            current_question_type = question_array[0].type;
                            current_logical_jump = question_array[0].logical_jump;
                            currentMailSequence = question_array[0].sequence;
                            currentQuestionIsLead = question_array[0].send_mail;
                            question_id = question_array[0].id;
                            setAllInputs(question_array);
                            question_id = question_array[0].id;
                            assignAllQuestionTypes(current_question_type);
                          }, delay_time);
                        } else {
                          if (entry_id) {
                            current_question_type = "custom_entry";
                          } else {
                            if (!shouldShowMenu) {
                              footer.style.display = "none";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 168px)";
                              } else {
                                body.style.height = "calc(100% - 93px)";
                              }
                              footer.classList.add("close");
                            } else {
                              if (entry_id) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                                setPlaceHolders();
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              } else {
                                input.style.pointerEvents = "none";
                                microphone.style.pointerEvents = "none";
                                microphone.style.opacity = 0;
                                enter.style.pointerEvents = "none";
                                input.blur();
                                input.placeholder = "Choose from Menu";
                                input.type = "text";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                          if (spinningDiv && spinningDiv.parentNode == body) {
                            body.removeChild(spinningDiv);
                          }
                        }
                      }
                    }
                  });
                  option_div.appendChild(slides_div);
                  questionDIv.appendChild(option_div);
                  body.appendChild(questionDIv);
                  body.scrollTop = body.scrollHeight;
                  if (footer.style.display == "block") {
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                  }
                }
              } else {
                if (prev_questions_array && prev_questions_array.length > 0) {
                  agreed = true;
                  if (
                    question_array &&
                    question_array.length > 0 &&
                    question_array[0].type == "url_flow" &&
                    chatbot_id == 10783
                  ) {
                  } else {
                    if (chatbot_id == 10783) {
                      for (var i = 0; i < prev_questions_array.length; i++) {
                        for (var j = 0; j < prev_questions_array.length; j++) {
                          if (
                            i != j &&
                            prev_questions_array[i] &&
                            prev_questions_array[j] &&
                            prev_questions_array[i].question_id ==
                            prev_questions_array[j].question_id
                          ) {
                            prev_questions_array.splice(j, 1);
                            j--;
                          }
                        }
                      }
                    }
                    previousQuestionsView(prev_questions_array);
                  }
                  var last_prev_question =
                    prev_questions_array[prev_questions_array.length - 1];
                  var wait_for_init_question;
                  if (
                    last_prev_question.type == "order_items" &&
                    last_prev_question.answer_text == "items_added" &&
                    last_prev_question.items_list &&
                    last_prev_question.items_list.length > 0
                  ) {
                    wait_for_init_question = true;
                  } else if (
                    last_prev_question.type == "order_items" &&
                    last_prev_question.answer_text == "items_edited" &&
                    last_prev_question.items_list &&
                    last_prev_question.items_list.length > 0
                  ) {
                    wait_for_init_question = true;
                  } else {
                  }
                  body.scrollTop = body.scrollHeight;
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  if (wait_for_init_question) {
                    if (spinningDiv && spinningDiv.parentNode == body) {
                      body.removeChild(spinningDiv);
                    }
                    order_items_question = last_prev_question;
                    selected_orders = last_prev_question.items_list;
                    order_question_options = last_prev_question.default_options;
                    order_items = [];
                    for (
                      var t = 0;
                      t < last_prev_question.total_items_list.length;
                      t++
                    ) {
                      order_items.push(last_prev_question.total_items_list[t]);
                    }
                    if (last_prev_question.answer_text == "items_added") {
                      var question = last_prev_question;
                      question.type = "order_items_edit";
                      question.question_text =
                        '<label style="font-weight: 600 !important;text-align: center;margin-bottom: 10px;color:black !important;">Choose Quantity</label>';
                      question_completed = !1;
                      input_value = "";
                      question_array = [];
                      question_array.push(question);
                      enter.style.pointerEvents = "auto";
                      current_question_type = "order_items_edit";
                      order_question_id = last_prev_question.id;
                      order_question_options = last_prev_question.default_options;
                      current_logical_jump = last_prev_question.logical_jump;
                      currentMailSequence = last_prev_question.sequence;
                      currentQuestionIsLead = last_prev_question.send_mail;
                      question_id = last_prev_question.id;
                      setAllInputs(question_array);
                      assignAllQuestionTypes(current_question_type);
                      order_status_string = "items_edited";
                    } else if (last_prev_question.answer_text == "items_edited") {
                      var question = order_items_question;
                      question.type = "order_items_submit";
                      question.question_text =
                        '<label style="font-size: 16px !important;font-weight: 500 !important;text-align: center;margin-bottom: 10px;width:102%;">Order Details</label>';
                      question_completed = !1;
                      input_value = "";
                      question_array = [];
                      question_array.push(question);
                      enter.style.pointerEvents = "auto";
                      current_question_type = "order_items_submit";
                      current_logical_jump = question_array[0].logical_jump;
                      currentMailSequence = question_array[0].sequence;
                      currentQuestionIsLead = question_array[0].send_mail;
                      question_id = question_array[0].id;
                      setAllInputs(question_array);
                      assignAllQuestionTypes(current_question_type);
                      order_status_string = "order_items_submit";
                    }
                  } else {
                    if (question_array && question_array.length > 0) {
                      question_completed = !1;
                      shouldStartEncourageTimer = !0;
                      nothingWentOnFor = 0;
                      encourageMessageIteration = 0;
                      setTimeout(function () {
                        if (spinningDiv && spinningDiv.parentNode == body) {
                          body.removeChild(spinningDiv);
                        }
                        current_question_type = question_array[0].type;
                        current_logical_jump = question_array[0].logical_jump;
                        currentMailSequence = question_array[0].sequence;
                        currentQuestionIsLead = question_array[0].send_mail;
                        question_id = question_array[0].id;
                        setAllInputs(question_array);
                        question_id = question_array[0].id;
                        assignAllQuestionTypes(current_question_type);
                      }, delay_time);
                    } else {
                      if (entry_id) {
                        current_question_type = "custom_entry";
                      } else {
                        if (!shouldShowMenu) {
                          footer.style.display = "none";
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 168px)";
                          } else {
                            body.style.height = "calc(100% - 93px)";
                          }
                          footer.classList.add("close");
                        } else {
                          if (entry_id) {
                            input.style.pointerEvents = "auto";
                            microphone.style.pointerEvents = "auto";
                            microphone.style.opacity = 1;
                            enter.style.pointerEvents = "auto";
                            setPlaceHolders();
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          } else {
                            input.style.pointerEvents = "none";
                            microphone.style.pointerEvents = "none";
                            microphone.style.opacity = 0;
                            enter.style.pointerEvents = "none";
                            input.blur();
                            input.placeholder = "Choose from Menu";
                            input.type = "text";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          }
                        }
                      }
                      if (spinningDiv && spinningDiv.parentNode == body) {
                        body.removeChild(spinningDiv);
                      }
                    }
                  }
                } else {
                  if (body.contains(consentDiv)) {
                  } else {
                    if (
                      totalData[0].consent_enabled &&
                      totalData[0].consent_enabled == "0"
                    ) {
                      agreed = !0;
                    } else if (
                      totalData[0].consent_enabled &&
                      totalData[0].consent_enabled == "1"
                    ) {
                      agreed = !1;
                    }
                    if (
                      totalData[0].consent_enabled_for_euro &&
                      totalData[0].consent_enabled_for_euro == "0"
                    ) {
                      if (euro_country_codes.indexOf(user_country_code) > -1) {
                        agreed = false;
                      }
                    } else {
                      if (euro_country_codes.indexOf(user_country_code) > -1) {
                        agreed = false;
                      } else {
                        if (
                          totalData[0].consent_enabled &&
                          totalData[0].consent_enabled == "0"
                        ) {
                          agreed = true;
                        } else if (
                          totalData[0].consent_enabled &&
                          totalData[0].consent_enabled == "1"
                        ) {
                          agreed = !1;
                        }
                      }
                    }
                    if (!agreed) {
                      body.appendChild(consentDiv);
                    }
                  }
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  if (question_array && question_array.length > 0) {
                    question_completed = !1;
                    shouldStartEncourageTimer = !0;
                    nothingWentOnFor = 0;
                    encourageMessageIteration = 0;
                    setTimeout(function () {
                      if (spinningDiv && spinningDiv.parentNode == body) {
                        body.removeChild(spinningDiv);
                      }
                      current_question_type = question_array[0].type;
                      current_logical_jump = question_array[0].logical_jump;
                      currentMailSequence = question_array[0].sequence;
                      currentQuestionIsLead = question_array[0].send_mail;
                      question_id = question_array[0].id;
                      if (
                        current_question_type == "url_flow" ||
                        current_question_type == "country_based_flow"
                      ) {
                        is_first_question_url_flow = !0;
                      } else {
                        is_first_question_url_flow = !1;
                      }
                      setAllInputs(question_array);
                      question_id = question_array[0].id;
                      assignAllQuestionTypes(current_question_type);
                    }, delay_time);
                  } else {
                    if (spinningDiv && spinningDiv.parentNode == body) {
                      body.removeChild(spinningDiv);
                    }
                  }
                }
              }
              if (
                (!question_array || question_array.length == 0) &&
                (!prev_questions_array || prev_questions_array.length == 0)
              ) {
                if (document.getElementById("opened")) {
                  document.getElementById("opened").style.display = "none";
                }
                if (document.getElementById("closed")) {
                  document.getElementById("closed").style.display = "none";
                }
                if (
                  document.getElementById("pulse") &&
                  document.getElementById("pulse") != null
                ) {
                  document.getElementById("pulse").style.display = "none";
                }
              } else {
                question_completed = !0;
                if (!entry_id) {
                  showInput = !0;
                  if (!shouldShowMenu) {
                    footer.style.display = "none";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                    footer.classList.add("close");
                  } else {
                    if (entry_id) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                      setPlaceHolders();
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    } else {
                      input.style.pointerEvents = "none";
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      enter.style.pointerEvents = "none";
                      input.blur();
                      input.placeholder = "Choose from Menu";
                      input.type = "text";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    }
                  }
                } else {
                  footer.style.display = "block";
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                  footer.classList.remove("close");
                  if (shouldShowMenu) {
                    input.style.pointerEvents = "auto";
                    microphone.style.pointerEvents = "auto";
                    microphone.style.opacity = 1;
                    enter.style.pointerEvents = "auto";
                  }
                  input.focus();
                  translateContent(translations, input, "Type your query", main_lang_code, language_code, 2);
                  if (shouldShowMenu) {
                    if (voice_input == "1") {
                      input.style.cssText =
                        input.style.cssText + "width:calc(100% - 115px) !important";
                    } else {
                      input.style.cssText =
                        input.style.cssText + "width:calc(100% - 80px) !important";
                    }
                  } else {
                    if (voice_input == "1") {
                      input.style.cssText =
                        input.style.cssText + "width:calc(100% - 75px) !important";
                    } else {
                      input.style.cssText =
                        input.style.cssText + "width:calc(100% - 45px) !important";
                    }
                  }
                  input.style.cssText =
                    input.style.cssText + "min-height:24px !important";
                    input.style.cssText = input.style.cssText + "height:24px !important";
                    input.style.cssText = input.style.cssText + "border:none !important";
                  // input.style.cssText =
                  // input.style.cssText + "max-height:72px !important";
                  current_question_type =
                    prev_questions_array[prev_questions_array.length - 1].type;
                }
                if (footer.style.display == "block") {
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 226px)";
                  } else {
                    body.style.height = "calc(100% - 150px)";
                  }
                } else {
                  if (header.contains(company_title_description)) {
                    body.style.height = "calc(100% - 168px)";
                  } else {
                    body.style.height = "calc(100% - 93px)";
                  }
                }
              }
              setTimeout(function () {
                reload_div.style.pointerEvents = "auto";
                reload_div.firstChild.style.pointerEvents = 'auto';
                reload_div.children[1].style.pointerEvents = 'auto';
              }, 4 * delay_time);
            }
          };
          xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat", !0);
          xhttp.setRequestHeader(
            "Content-type",
            "application/x-www-form-urlencoded"
          );
          if (
            main_lang_code &&
            main_lang_code.length > 0 &&
            main_lang_code != language_code
          ) {
          } else {
            main_lang_code = "default";
          }
          var bot_widget_obj;
          var is_sendable;
          try {
            checkSaveMAxUserLogin();
            checkRateGainDetails();
          } catch (error) { }
          if (window.botWidget && window.botWidget.user) {
            var keys = Object.keys(window.botWidget.user);
            for (var t = 0; t < keys.length; t++) {
              if (
                window.botWidget.user[keys[t]] &&
                window.botWidget.user[keys[t]].length > 0
              ) {
                is_sendable = true;
              }
            }
            if (is_sendable) {
              bot_widget_obj = window.botWidget.user;
            } else {
              bot_widget_obj = "";
            }
            if (window.botWidget.user.bot_id) {
              delete window.botWidget.user.bot_id;
            }
            if (window.botWidget.user.url) {
              delete window.botWidget.user.url;
            }
          }
          if (src && src.length > 0) {
            var user_location_string;
            if (user_location_enc && user_location_enc.length > 0) {
              user_location_string = user_location_enc;
            } else {
              if (user_location_array && user_location_array.length > 0) {
                user_location_string = user_location_array.join();
              }
            }
            var d = new Date();
            var source_obj = {
              url: encodeURIComponent(src),
              timezone: d.getTimezoneOffset(),
              date: d,
              channel: "Web",
              client_ip_address: ip_address,
              user_location: user_location_string,
              bot_url: encodeURIComponent(window.location.href),
            };
            if (user_location && user_location.length > 0) {
              user_location =
                userResponseText.city + "," + userResponseText.regionName;
            }
            var bot_widget_obj;
            var is_sendable;
            try {
              checkSaveMAxUserLogin();
              checkRateGainDetails();
            } catch (error) { }
            if (window.botWidget && window.botWidget.user) {
              var keys = Object.keys(window.botWidget.user);
              for (var t = 0; t < keys.length; t++) {
                if (
                  window.botWidget.user[keys[t]] &&
                  window.botWidget.user[keys[t]].length > 0
                ) {
                  is_sendable = true;
                }
              }
              if (is_sendable) {
                bot_widget_obj = window.botWidget.user;
              } else {
                bot_widget_obj = "";
              }
              if (window.botWidget.user.bot_id) {
                delete window.botWidget.user.bot_id;
              }
              if (window.botWidget.user.url) {
                delete window.botWidget.user.url;
              }
            }
            if (lead_revisited) {
              xhttp.send(
                "action=init_chat&device_print=" +
                device_print +
                "&chatbot_id=" +
                chatbot_id +
                "&source=" +
                JSON.stringify(source_obj) +
                "&language_code=" +
                main_lang_code +
                "&bot_widget_obj=" +
                JSON.stringify(bot_widget_obj)
              );
            } else {
              xhttp.send(
                "action=init_chat&device_print=" +
                device_print +
                "&chatbot_id=" +
                chatbot_id +
                "&source=" +
                JSON.stringify(source_obj) +
                "&language_code=" +
                main_lang_code +
                "&bot_widget_obj=" +
                JSON.stringify(bot_widget_obj) +
                "&lead_revisited=0&name=" +
                encodeURIComponent(totalData[0].name) +
                "&lead_revisit_notification=" +
                lead_revisit_notification
              );
            }
          } else {
            var user_location_string;
            if (user_location_enc && user_location_enc.length > 0) {
              user_location_string = user_location_enc;
            } else {
              if (user_location_array && user_location_array.length > 0) {
                user_location_string = user_location_array.join();
              }
            }
            var d = new Date();
            var source_obj = {
              date: new Date(),
              channel: "Web",
              timezone: d.getTimezoneOffset(),
              client_ip_address: ip_address,
              user_location: user_location_string,
              bot_url: encodeURIComponent(window.location.href),
            };
            var bot_widget_obj;
            var is_sendable;
            try {
              checkSaveMAxUserLogin();
              checkRateGainDetails();
            } catch (error) { }
            if (window.botWidget && window.botWidget.user) {
              var keys = Object.keys(window.botWidget.user);
              for (var t = 0; t < keys.length; t++) {
                if (
                  window.botWidget.user[keys[t]] &&
                  window.botWidget.user[keys[t]].length > 0
                ) {
                  is_sendable = true;
                }
              }
              if (is_sendable) {
                bot_widget_obj = window.botWidget.user;
              } else {
                bot_widget_obj = "";
              }
              if (window.botWidget.user.bot_id) {
                delete window.botWidget.user.bot_id;
              }
              if (window.botWidget.user.url) {
                delete window.botWidget.user.url;
              }
            }
            if (lead_revisited) {
              xhttp.send(
                "action=init_chat&device_print=" +
                device_print +
                "&chatbot_id=" +
                chatbot_id +
                "&source=" +
                JSON.stringify(source_obj) +
                "&language_code=" +
                main_lang_code +
                "&bot_widget_obj=" +
                JSON.stringify(bot_widget_obj)
              );
            } else {
              xhttp.send(
                "action=init_chat&device_print=" +
                device_print +
                "&chatbot_id=" +
                chatbot_id +
                "&source=" +
                JSON.stringify(source_obj) +
                "&language_code=" +
                main_lang_code +
                "&bot_widget_obj=" +
                JSON.stringify(bot_widget_obj) +
                "&lead_revisited=0&name=" +
                encodeURIComponent(totalData[0].name) +
                "&lead_revisit_notification=" +
                lead_revisit_notification
              );
            }
          }
        }
        var fullFeedbackDiv;
        var closedFeedbackIcon;
        var negativeFeedbackDiv;

        function addFullFeedback() {
          if (session_feedback && session_feedback.length > 0) {
          } else {
            if (body.contains(fullFeedbackDiv)) {
            } else {
              fullFeedbackDiv = document.createElement("DIV");
              fullFeedbackDiv.classList.add("feedback-full-div");
              var x = anotherDiv.clientHeight;
              if (header.contains(company_title_description)) {
                x = x - 135 + 15;
              } else {
                x = x - 60 + 15;
              }
              fullFeedbackDiv.style.top = "calc(100vh - " + x + "px)";
              fullFeedbackDiv.classList.add("p-t-8");
              fullFeedbackDiv.classList.add("p-b-8");
              if (fullFeedbackDiv.classList.contains("closed")) {
                fullFeedbackDiv.classList.remove("closed");
              } else {
                fullFeedbackDiv.classList.add("closed");
                fullFeedbackDiv.classList.remove("closed");
              }
              var full_feedback_label = document.createElement("LABEL");
              full_feedback_label.classList.add("consent-label");
              full_feedback_label.classList.add("text-center");
              full_feedback_label.style.marginTop = "10px";
              full_feedback_label.innerHTML = "How would you rate us?";
              fullFeedbackDiv.appendChild(full_feedback_label);
              var uppder_fieldset_div = document.createElement("DIV");
              uppder_fieldset_div.classList.add("inline-block");
              var filedset_rating = document.createElement("FIELDSET");
              uppder_fieldset_div.appendChild(filedset_rating);
              filedset_rating.classList.add("rating-stars");
              for (var i = 1; i < 6; i++) {
                var rating_input = document.createElement("INPUT");
                rating_input.type = "radio";
                var x = 6 - i;
                rating_input.id = "star" + x;
                rating_input.value = 6 - i;
                rating_input.name = "rating";
                var rating_label = document.createElement("LABEL");
                rating_label.htmlFor = "star" + x;
                if (i == 1) {
                  rating_label.title = "Excellent";
                } else if (i == 2) {
                  rating_label.title = "Great";
                } else if (i == 3) {
                  rating_label.title = "Okay";
                } else if (i == 4) {
                  rating_label.title = "Bad";
                } else if (i == 5) {
                  rating_label.title = "Terrible";
                }
                filedset_rating.appendChild(rating_input);
                filedset_rating.appendChild(rating_label);
                rating_input.addEventListener("click", function (k) {
                  nothingWentOnFor = 0;
                  encourageMessageIteration = 0;
                  fullFeedbackDiv.classList.add("closed");
                  var submitFeedbackXhttp = new XMLHttpRequest();
                  submitFeedbackXhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      var appreciation_div = document.createElement("DIV");
                      appreciation_div.classList.add("appreciation-div");
                      var progress_parent_div = document.createElement("DIV");
                      progress_parent_div.id = "myProgress";
                      var progress_child_div = document.createElement("DIV");
                      progress_child_div.id = "myBar";
                      progress_parent_div.appendChild(progress_child_div);
                      appreciation_div.appendChild(progress_parent_div);
                      var appreciation_label = document.createElement("LABEL");
                      appreciation_label.innerHTML =
                        generateTranslatedContent(translations, "Thanks for submitting your feedback.", main_lang_code, language_code, input);
                      appreciation_div.appendChild(appreciation_label);
                      var progressLoaded;
                      body.appendChild(appreciation_div);
                      setInterval(function () {
                        if (!progressLoaded) {
                          if (document.getElementById("myBar")) {
                            if (footer.style.display == "block") {
                              appreciation_div.style.bottom = "97px";
                            } else {
                              appreciation_div.style.bottom = "38px";
                            }
                            progressLoaded = !0;
                            moveProgress("myBar");
                          }
                        }
                      });
                      setTimeout(function () {
                        body.removeChild(appreciation_div);
                      }, 2000);
                    }
                  };
                  submitFeedbackXhttp.open(
                    "POST",
                    main_url + "/kya_backend/pagehub/feedback",
                    !0
                  );
                  submitFeedbackXhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  submitFeedbackXhttp.send(
                    "chatbot_id=" +
                    chatbot_id +
                    "&action=chat_feedback" +
                    "&feedback=" +
                    this.value +
                    "&cb_session=" +
                    cb_session
                  );
                });
              }
              var closeFeedbackWrapper = document.createElement("DIV");
              closeFeedbackWrapper.classList.add("inline-block");
              closeFeedbackWrapper.classList.add("full-width");
              closeFeedbackWrapper.classList.add("text-center");
              closeFeedbackWrapper.classList.add("closed-feedback-wrapper");
              closeFeedbackWrapper.style.cursor = "pointer";
              var closedFeedbackDiv = document.createElement("DIV");
              closedFeedbackDiv.classList.add("closed-feedback-div");
              closedFeedbackDiv.classList.add("inline-block");
              var closedFeedbackIcon = document.createElement("IMG");
              closedFeedbackIcon.src =
                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/down-arrow.png";
              // closedFeedbackIcon.classList.add('fa');
              // closedFeedbackIcon.classList.add('fa-chevron-circle-down');
              closedFeedbackDiv.appendChild(closedFeedbackIcon);
              closeFeedbackWrapper.appendChild(closedFeedbackDiv);
              var close_feedback_icon = document.createElement("IMG");
              close_feedback_icon.src =
                "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/close_feedback.png";
              // close_feedback_icon.classList.add('fa');
              // close_feedback_icon.classList.add('fa-times');
              close_feedback_icon.classList.add("feedback-icon");
              close_feedback_icon.style.right = "10px";
              close_feedback_icon.style.top = "10px";
              close_feedback_icon.style.position = "absolute";
              close_feedback_icon.style.cursor = "pointer";
              close_feedback_icon.addEventListener("click", function (k) {
                if (body.contains(fullFeedbackDiv)) {
                  fullFeedbackDiv.classList.add("closed");
                  nothingWentOnFor = 0;
                  encourageMessageIteration = 0;
                  body.appendChild(closeFeedbackWrapper);
                }
              });
              closeFeedbackWrapper.addEventListener("click", function (k) {
                if (body.contains(fullFeedbackDiv)) {
                  fullFeedbackDiv.classList.remove("closed");
                  nothingWentOnFor = 0;
                  encourageMessageIteration = 0;
                  body.removeChild(closeFeedbackWrapper);
                }
              });
              fullFeedbackDiv.appendChild(uppder_fieldset_div);
              fullFeedbackDiv.appendChild(close_feedback_icon);
              body.appendChild(fullFeedbackDiv);
            }
          }
        }

        function addLiveChatFeedback() {
          if (live_chat_session_feedback && live_chat_session_feedback.length > 0) {
          } else {
    
            var opened_div = document.getElementById('opened');
    
            if (opened_div.contains(bg_shadow_rating)) {
              if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
              }
            } else {

              var bg_shadow_rating_div = document.getElementById('bg-shadow-overlay')
              var rate_rating_div = document.getElementById('rating-live-chat-feedback_div_sb')

              if (opened_div.contains(bg_shadow_rating_div)) {
                opened_div.removeChild(bg_shadow_rating_div);
              }
              if (opened_div.contains(rate_rating_div)) {
                opened_div.removeChild(rate_rating_div);
              }
              
              live_chat_feedback_opened = true;
    
              var close_icon_div = document.createElement('DIV');
              close_icon_div.setAttribute('class', 'close-icon-div-small_sb');
    
              var close_icon_img = document.createElement('IMG');
              close_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/cross-small+(2).svg'
              close_icon_img.alt ='closeicon'
              close_icon_img.style.width ='10px';
              close_icon_img.style.height ='10px';
    
              var left_icon_img = document.createElement('IMG');
              left_icon_img.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/angle-small-down+(1).svg'
              left_icon_img.alt ='closeicon'
              left_icon_img.style.width ='10px';
              left_icon_img.style.height ='10px';
              left_icon_img.style.cursor ='pointer';
    
              var headder_main_div = document.createElement('DIV');
              headder_main_div.classList.add('headder_main_div_sb');
    
              var headder_main_text = document.createElement('DIV');
              headder_main_text.innerHTML = generateTranslatedContent(translations, 'Rating', main_lang_code, language_code, input);  
              headder_main_text.style.textAlign ='center';
              headder_main_text.style.width ='90%';
              headder_main_text.style.fontSize ='13px';
              headder_main_text.style.fontWeight ='600';
              if (font && font.length > 0) {
                headder_main_text.classList.add(font);
              }
    
              close_icon_div.appendChild(close_icon_img)
              headder_main_div.appendChild(left_icon_img); 
              headder_main_div.appendChild(headder_main_text);
              // headder_main_div.appendChild(close_icon_div);
    
              var bg_shadow_rating = document.createElement('DIV');
              bg_shadow_rating.setAttribute('id', 'bg-shadow-overlay'); 
    
              var live_chat_rate_container = document.createElement('DIV');
              live_chat_rate_container.setAttribute( 'id', 'live_chat_rate_container');
              live_chat_rate_container.style.minHeight = '50%';
              live_chat_rate_container.style.opacity = '1';
              live_chat_rate_container.style.transform = 'translateY(0)';
    
              // live_chat_rate_container.appendChild(close_icon_div);
              // close_icon_div.appendChild(close_icon_img);
              
              liveChatFeedbackDiv = document.createElement("DIV");
              liveChatFeedbackDiv.classList.add("rating-feedback-full-div");
    
              var live_chat_feedback_label = document.createElement("LABEL");
              live_chat_feedback_label.classList.add("consent-label");
              live_chat_feedback_label.classList.add("text-center");
              live_chat_feedback_label.style.color = '#1D2D35';
              live_chat_feedback_label.style.fontWeight = '600';
              live_chat_feedback_label.style.margin = '12px 0';
    
              // live_chat_feedback_label.innerHTML = "Please rate this conversation";
              live_chat_feedback_label.innerHTML = generateTranslatedContent(translations, "How would you rate the experience ?", main_lang_code, language_code, input);  
    
              if (font && font.length > 0) {
                live_chat_feedback_label.classList.add(font);
              }
    
              live_chat_rate_container.appendChild(headder_main_div);
              liveChatFeedbackDiv.appendChild(live_chat_feedback_label);
    
              var ratingContainer = document.createElement('div');
              ratingContainer.className = 'rating-container_sb';
    
              var emojiDiv = document.createElement('div');
              emojiDiv.className = 'emoji_sb';
              emojiDiv.id = 'emoji';
              
              var emojiImg = document.createElement('img');
              emojiImg.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/neutral.gif';
              emojiImg.style.width = '100px';
    
              emojiDiv.appendChild(emojiImg);
    
              var starsDiv = document.createElement('div');
              starsDiv.className = 'stars_sb';
    
              var emojis = [
                  'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bored.gif',
                  'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/sad.gif',
                  'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/happy-emoji-rate.gif',
                  'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/happy.gif',
                  'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/surprised.gif',
              ];
    
              let selectedRating = 0;
    
              for (let i = 1; i <= 5; i++) {
                const star = document.createElement('span');
                star.className = 'star_sb';
                star.dataset.rating = i;
    
                star.addEventListener('mouseover', () => {
                    emojiImg.src = emojis[i - 1];
                    highlightStars(i);
                });
    
                star.addEventListener('mouseout', () => {
                    emojiImg.src = selectedRating ? emojis[selectedRating - 1] : 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bored.gif';
                    highlightStars(selectedRating);
                });
    
                star.addEventListener('click', () => {
                    selectedRating = i;
                    emojiImg.src = emojis[i - 1];
                    highlightStars(i);
    
                    var d = new Date();
                    var date = d.getDate();
                    if (date < 10) {
                      date = '0' + date;
                    }
                    var month = d.getMonth() + 1;
                    if (month < 10) {
                      month = '0' + month;
                    }
                    var hours = d.getHours();
                    if (hours < 10) {
                      hours = '0' + hours;
                    }
                    var mins = d.getMinutes();
                    if (mins < 10) {
                      mins = '0' + mins;
                    }
                    var seconds = d.getSeconds();
                    if (seconds < 10) {
                      seconds = '0' + seconds;
                    }
                    d =
                      date +
                      '/' +
                      month +
                      '/' +
                      d.getFullYear() +
                      ', ' +
                      hours +
                      ':' +
                      mins +
                      ':' +
                      seconds;
                    if (ip_is_banned && banned_reason && banned_reason.length > 0) {
                      var livechatEncourageDiv = document.createElement('DIV');
                      livechatEncourageDiv.id = 'user-banned-div';
                      livechatEncourageDiv.classList.add('question-div-smatest');
                      setTimeout(function () {
                        livechatEncourageDiv.classList.add('top-0');
                      }, transition_time);
                      if (font && font.length > 0) {
                        livechatEncourageDiv.classList.add(font);
                      }
                      var live_chat_encourage_icon = document.createElement('IMG');
                      live_chat_encourage_icon.alt = 'Logo of ' + totalData[0].name;
                      live_chat_encourage_icon.src = avatar_icon;
                      var iconDiv = document.createElement('DIV');
                      iconDiv.appendChild(live_chat_encourage_icon);
                      iconDiv.classList.add('question-icon-div');
                      live_chat_encourage_icon.classList.add('question-icon-smatest');
                      var live_chat_encourage_text = document.createElement('LABEL');
                      live_chat_encourage_text.innerHTML =
                        '<label style="float:left;width:100%;margin-bottom:">You have been banned from interacting with our live agents</label><label style="float:left;width:100%">Reason : ' +
                        banned_reason +
                        '</label>';
                      say(live_chat_encourage_text.innerText);
                      live_chat_encourage_text.classList.add('question-text-error');
                      live_chat_encourage_text.classList.add('options-div-smatest');
                      if (font && font.length > 0) {
                        live_chat_encourage_text.classList.add(font);
                      }
                      livechatEncourageDiv.appendChild(iconDiv);
                      livechatEncourageDiv.appendChild(live_chat_encourage_text);
                      var checking_div = document.getElementById('user-banned-div');
                      if (body.contains(checking_div)) {
                        body.appendChild(checking_div);
                      } else {
                        body.appendChild(livechatEncourageDiv);
                      }
                      playBotUserSound(1);
                      body.scrollTop = body.scrollHeight;
                    } else {
                      live_chat_feedback_rated = true;
                      sock.emit('submitfeedback', {
                        session_id: live_chat_cb_session,
                        device_print: device_print,
                        bot_id: chatbot_id,
                        time: d,
                        rating: i,
                        channel: 'website',
                        agent_id: agent_id,
                      });
                    }
                    if (live_chat_feedback_submitted && live_chat_feedback_rated) {
                      // liveChatFeedbackDiv.classList.add('closed');
                      if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                        opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
                      }
                    }
    
                });
    
                starsDiv.appendChild(star);
              }
    
              ratingContainer.appendChild(emojiDiv); 
              ratingContainer.appendChild(starsDiv);
              liveChatFeedbackDiv.appendChild(ratingContainer);
    
              function highlightStars(rating) {
                const stars = document.querySelectorAll('.star_sb');
                stars.forEach(star => {
                    star.classList.remove('hover', 'selected');
                    if (star.dataset.rating <= rating) {
                        star.classList.add('hover');
                        if (rating === selectedRating) {
                            star.classList.add('selected');
                        }
                    }
                });
              }
    
              var closeLiveChatFeedbackWrapper = document.createElement("DIV");
              closeLiveChatFeedbackWrapper.setAttribute('id',"rating-live-chat-feedback_div_sb");
              closeLiveChatFeedbackWrapper.classList.add("inline-block");
              // closeLiveChatFeedbackWrapper.classList.add("full-width");
              closeLiveChatFeedbackWrapper.classList.add("text-center"); 
              closeLiveChatFeedbackWrapper.style.width = "calc( 100% - 24px )";
              closeLiveChatFeedbackWrapper.style.background = "#fff";
              closeLiveChatFeedbackWrapper.style.display = "flex";
              closeLiveChatFeedbackWrapper.style.alignItems = "center";
              closeLiveChatFeedbackWrapper.style.justifyContent = "space-between";
              closeLiveChatFeedbackWrapper.style.borderTop = "0px solid lightgray";
              closeLiveChatFeedbackWrapper.style.zIndex = "99";
              closeLiveChatFeedbackWrapper.style.boxShadow = "0 1pt 6pt rgb(0 0 0 / 15%)";
              closeLiveChatFeedbackWrapper.style.borderRadius = "0 0 0px 0px";
              closeLiveChatFeedbackWrapper.style.padding = "12px";
              closeLiveChatFeedbackWrapper.style.top = "60px";
              closeLiveChatFeedbackWrapper.style.left = "0px";
    
              let headder_height = document.querySelector('.header-div');
              setTimeout(() => {
                if (headder_height) {
                    const height = window.getComputedStyle(headder_height).height;
                    if (height == '135px') {
                      closeLiveChatFeedbackWrapper.style.top = "135px";
                    } else {
                      closeLiveChatFeedbackWrapper.style.top = "60px";
                    }
                } 
              }, 1000);
    
              closeLiveChatFeedbackWrapper.classList.add("closed-feedback-wrapper");
    
              var agent_name_div = document.createElement("DIV");
              agent_name_div.style.display ='flex';
              agent_name_div.style.flexDirection ='row';
              agent_name_div.style.alignItems ='center';
              agent_name_div.style.gap ='12px';
              agent_name_div.style.marginLeft ='12px';
              agent_name_div.style.maxWidth ='60%';
              agent_name_div.style.overflow ='hidden';
    
              var agent_logo = document.createElement("IMG");
              if (agentTotalData && agentTotalData.customer_avatar && agentTotalData.customer_avatar.length > 0) {
                agent_logo.src = agentTotalData.customer_avatar
              }else{
                agent_logo.src = avatar_icon
              }
              agent_logo.alt = 'avathar icon'
              agent_logo.style.width ='30px';
              agent_logo.style.height ='30px';
              agent_logo.style.borderRadius ='50%';
    
              var name_label = document.createElement("DIV");
              name_label.style.textAlign ='left';
              name_label.style.width ='80%';

              var agent_name_h4 = document.createElement("H4");
              agent_name_h4.style.fontSize ='14px';
              agent_name_h4.style.fontWeight ='500';
              agent_name_h4.style.margin ='0';
              agent_name_h4.style.overflow ='hidden';
              agent_name_h4.style.textOverflow ='ellipsis';
              agent_name_h4.style.whiteSpace ='nowrap';
              agent_name_h4.innerHTML = agent_name
    
              var agent_status_p = document.createElement("P");
              agent_status_p.innerHTML = 'Online'
              agent_status_p.style.fontSize ='10px';
              agent_status_p.style.fontWeight ='500';
              agent_status_p.style.margin ='0';
              agent_status_p.style.color ='green';
    
              // closeLiveChatFeedbackWrapper.style.cursor = "pointer";
              var closedLiveChatFeedbackDiv = document.createElement("DIV");
              // closedLiveChatFeedbackDiv.classList.add("closed-feedback-div");
              closedLiveChatFeedbackDiv.style.position ='relative';
              closedLiveChatFeedbackDiv.style.marginLeft ='0';
              closedLiveChatFeedbackDiv.style.marginRight ='12px';
              closedLiveChatFeedbackDiv.classList.add("inline-block");
              
              // var closedLiveChatFeedbackIcon = document.createElement("IMG");
              // closedLiveChatFeedbackIcon.id = "open-live-chat-feedback";
              // closedLiveChatFeedbackIcon.src =
              //   "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/down-arrow.png";
              // closedLiveChatFeedbackDiv.appendChild(closedLiveChatFeedbackIcon);
    
              var rate_Button = document.createElement("BUTTON");
              rate_Button.style.border = 'none';
              rate_Button.style.outline = 'none';
              rate_Button.style.fontSize = '12px';
              rate_Button.style.padding = '8px 16px';
              rate_Button.style.borderRadius = '6px';
              rate_Button.style.background = '#ECF4FF';
              rate_Button.style.color = '#096AF9';
              rate_Button.style.cursor = "pointer";
              rate_Button.style.fontWeight = "600";
    
              rate_Button.innerHTML = generateTranslatedContent(translations, 'Rate Agent', main_lang_code, language_code, input);  
    
              closedLiveChatFeedbackDiv.appendChild(rate_Button); 
    
              closeLiveChatFeedbackWrapper.appendChild(agent_name_div);
    
              agent_name_div.appendChild(agent_logo);
              name_label.appendChild(agent_name_h4);
              name_label.appendChild(agent_status_p);
              agent_name_div.appendChild(name_label);
    
              closeLiveChatFeedbackWrapper.appendChild(closedLiveChatFeedbackDiv);
    
              if (font && font.length > 0) {
                rate_Button.classList.add(font);
                name_label.classList.add(font);
              }
    
              left_icon_img.addEventListener("click", function (k) {
                if (opened_div.contains(bg_shadow_rating)) {
                  bg_shadow_rating.style.visibility = 'hidden'
                  live_chat_rate_container.style.opacity = '0.5';
                  live_chat_rate_container.style.transform = 'translateY(100%)';
                  opened_div.appendChild(closeLiveChatFeedbackWrapper);
                }
              });
    
              close_icon_div.addEventListener("click", function (k) {
                if (opened_div.contains(bg_shadow_rating)) {
                  botWidget.minimise()
                }
              });
              
              rate_Button.addEventListener("click", function (k) {
                k.preventDefault()
                if (opened_div.contains(bg_shadow_rating)) {
                  bg_shadow_rating.style.visibility = 'visible'
                  live_chat_rate_container.style.opacity = '1';
                  live_chat_rate_container.style.transform = 'translateY(0)';
                  opened_div.removeChild(closeLiveChatFeedbackWrapper);
                }
              });
    
              liveChatFeedbackInput = document.createElement("TEXTAREA");
              liveChatFeedbackInput.classList.add("rating-live-chat-feedback-input");
              if (font && font.length > 0) {
                liveChatFeedbackInput.classList.add(font);
              }
              liveChatFeedbackInput.placeholder =  generateTranslatedContent(translations, "Tell us More ( Optional )", main_lang_code, language_code, input);  
    
              liveChatInputSubmit = document.createElement("BUTTON");
              // liveChatInputSubmit.classList.add("live-chat-feedback-submit");
              liveChatInputSubmit.setAttribute('id',"rating-live-chat-submit_btn");
              if (font && font.length > 0) {
                liveChatInputSubmit.classList.add(font);
              }
              liveChatInputSubmit.classList.add('confirm-btn-smatest');
    
              liveChatInputSubmit.innerHTML = generateTranslatedContent(translations, 'Submit Feedback', main_lang_code, language_code, input); 
    
              var submit_icon = document.createElement('IMG');
              submit_icon.src = 'https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/submit-new-icon.svg';
              submit_icon.alt = 'SubmitIcon';
              submit_icon.style.width = "18px";
              submit_icon.style.height = "18px";
    
              liveChatInputSubmit.appendChild(submit_icon);
    
              liveChatFeedbackInput.addEventListener("keydown", function (e) {
                if (e.keyCode === 13) {
                  if (this.value && this.value.length > 0) {
                    live_chat_feedback_submitted = true;
                    this.nextSibling.style.pointerEvents = "none";
                    this.style.pointerEvents = "none";
                    // microphone.style.pointerEvents = "none";
                    // microphone.style.opacity = 0;
                    sock.emit("submitfeedbackmessage", {
                      session_id: live_chat_cb_session,
                      device_print: device_print,
                      bot_id: chatbot_id,
                      message: this.value,
                      channel: "website",
                      agent_id: agent_id,
                    });
                    if (live_chat_feedback_rated) {
                      if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                        opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
                      }
                      if (header_menu_div.contains(ask_live_chat_feedback_div)) {
                        header_menu_div.removeChild(ask_live_chat_feedback_div);
                        adminMessaged = false;
                        updateMenuIcons()
                      }
                    }
                  }else{
                    if (live_chat_feedback_rated) {
                      // liveChatFeedbackDiv.classList.add('closed');
                      if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                        opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
                      }
                      if (header_menu_div.contains(ask_live_chat_feedback_div)) {
                        header_menu_div.removeChild(ask_live_chat_feedback_div);
                        adminMessaged = false;
                        updateMenuIcons()
                      }
                    }
                  }
                }
              });
    
              liveChatInputSubmit.addEventListener("click", function (k) {
                if (
                  liveChatFeedbackInput.value &&
                  liveChatFeedbackInput.value.length > 0
                ) {
                  live_chat_feedback_submitted = true;
                  liveChatInputSubmit.style.pointerEvents = "none";
                  this.previousSibling.style.pointerEvents = "none";
                  // microphone.style.pointerEvents = "none";
                  // microphone.style.opacity = 0;
                  sock.emit("submitfeedbackmessage", {
                    session_id: live_chat_cb_session,
                    device_print: device_print,
                    bot_id: chatbot_id,
                    message: liveChatFeedbackInput.value,
                    channel: "website",
                    agent_id: agent_id,
                  });
                  if (live_chat_feedback_rated) {
                    if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                      opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
                    }
                    if (header_menu_div.contains(ask_live_chat_feedback_div)) {
                      header_menu_div.removeChild(ask_live_chat_feedback_div);
                      adminMessaged = false;
                    }
                  }
                }else{
                  if (live_chat_feedback_rated) {
                    // liveChatFeedbackDiv.classList.add('closed');
                    if ( opened_div.contains(document.getElementById('bg-shadow-overlay')) ) {
                      opened_div.removeChild( document.getElementById('bg-shadow-overlay') );
                    }
                    if (header_menu_div.contains(ask_live_chat_feedback_div)) {
                      header_menu_div.removeChild(ask_live_chat_feedback_div);
                      adminMessaged = false;
                    }
                  }
                }
              });
    
              // liveChatFeedbackDiv.appendChild(live_chat_fieldset_div);
              liveChatFeedbackDiv.appendChild(liveChatFeedbackInput);
              liveChatFeedbackDiv.appendChild(liveChatInputSubmit);
    
              opened_div.appendChild(bg_shadow_rating);
              bg_shadow_rating.appendChild(live_chat_rate_container);
              live_chat_rate_container.appendChild(liveChatFeedbackDiv);
              createBrandWrapper(live_chat_rate_container, 'SmatBot', main_url, font);
              // body.appendChild(liveChatFeedbackDiv);
            }
          }
        }

        function mainClick(id) {
          if (header.contains(icon_header_div)) {
            if (launcher_position == "RM") {
            }
          } else {
            if (launcher_position == "RM") {
            }
          }

          firstTimeClicked = !0;
          alreadyClicked = !0;
          if (id && id == 1) {
            body.classList.add("body-div");
            if (font && font.length > 0) {
              body.classList.add(font);
            }
          }
          body.style.display = "block";
          anotherDiv.style.display = "block";
          anotherDiv.style.bottom = "15px";
          anotherDiv.style.visibility = "visible";
          anotherDiv.style.transform = "translateX(0) translateY(0) scale(1)";
          setTimeout(function () {
            totalWidth = anotherDiv.clientWidth;
            updateMenuIcons()
          }, 100);
          var otherSpinningDiv = document.createElement("DIV");
          otherSpinningDiv.classList.add("question-div-smatest");
          otherSpinningDiv.classList.add("top-0");
          if (font && font.length > 0) {
            otherSpinningDiv.classList.add(font);
          }
          var otherSpinnerDiv = document.createElement("DIV");
          otherSpinnerDiv.classList.add("spinner1-smatest");
          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
          ques_icon.src = avatar_icon;
          var iconDiv = document.createElement("DIV");
          iconDiv.appendChild(ques_icon);
          iconDiv.classList.add("question-icon-div");
          ques_icon.classList.add("question-icon-smatest");
          var inner1 = document.createElement("DIV");
          inner1.classList.add("bounce1");
          var inner2 = document.createElement("DIV");
          inner2.classList.add("bounce2");
          var inner3 = document.createElement("DIV");
          inner3.classList.add("bounce3");
          otherSpinnerDiv.appendChild(inner1);
          otherSpinnerDiv.appendChild(inner2);
          otherSpinnerDiv.appendChild(inner3);
          otherSpinningDiv.appendChild(iconDiv);
          otherSpinningDiv.appendChild(otherSpinnerDiv);
          body.appendChild(otherSpinningDiv);
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
              body.innerHTML = "";
              // body.removeChild(otherSpinningDiv);
              menu_options_array = JSON.parse(this.response).menu_bar;
              roinet_old_session = JSON.parse(this.response).cb_session;
              if (menu_options_array && menu_options_array.length > 0) {
                menu_option_question_id = menu_options_array[0].id;
                menu_option_sequence = menu_options_array[0].sequence;
                if (
                  menu_options_array[0].default_options &&
                  menu_options_array[0].default_options.length > 0
                ) {
                  var menu_default_options =
                    menu_options_array[0].default_options.split(";;");
                  if (menu_default_options && menu_default_options.length > 0) {
                    shouldShowMenu = !0;
                    footer.removeChild(input);
                    footer.appendChild(menu);
                    footer.appendChild(opened_menu);
                    footer.appendChild(input);
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.style.display = "block";
                  } else {
                    shouldShowMenu = !1;
                  }
                  for (var i = 0; i < menu_default_options.length; i++) {
                    var menu_details = menu_default_options[i].split("..");
                    var menu_option_div = document.createElement("DIV");
                    menu_option_div.classList.add("pull-left");
                    menu_option_div.classList.add("full-width");
                    menu_option_div.classList.add("menu-option-div");
                    if (i != menu_default_options.length - 1) {
                      menu_option_div.classList.add("border-bottom");
                    }
                    menu_option_label = document.createElement("LABEL");
                    menu_option_label.classList.add("pull-left");
                    menu_option_label.classList.add("full-width");
                    menu_option_label.classList.add("pointer");
                    menu_option_label.classList.add("menu-option-label");
                    var contact_item = document.createElement("A");
                    contact_item.title = "Contact redirection";
                    var contact_icon = document.createElement("IMG");
                    contact_item.classList.add("text-black");
                    contact_item.style.display = 'block';
                    contact_item.style.width = '100%';
                    if (font && font.length > 0) {
                      contact_item.classList.add(font);
                    }
                    contact_icon.classList.add("menu-icon-smatest");
                    var contact_text = document.createElement("SPAN");
                    if (menu_details[0] == "whatsapp") {
                      contact_item.target = "_blank";
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/whatsapp_.svg";
                      var k = generateTranslatedContent(translations, "Hi team, I have some queries", main_lang_code, language_code, input);
                      if (
                        /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                          navigator.userAgent
                        )
                      ) {
                        contact_item.href =
                          "https://api.whatsapp.com/send?phone=" +
                          menu_details[2].split("+").join("") +
                          menu_details[3] +
                          "&text=" +
                          k;
                      } else {
                        contact_item.href =
                          "https://web.whatsapp.com/send?phone=" +
                          menu_details[2] +
                          menu_details[3] +
                          "&text=" +
                          k;
                      }
                      contact_item.addEventListener("click", function (k) {
                        menu_options_div.classList.add("close");
                        opened_menu.classList.add("opacity-0");
                        menu.classList.remove("opacity-0");
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttp.send(
                          "action=answer&answer_text=Whatsapped" +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          menu_option_question_id +
                          "&is_logical=0" +
                          "&sequence=" +
                          menu_option_sequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&is_help=1&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                      });
                    } else if (menu_details[0] == "call") {
                      menu_options_div.classList.add("close");
                      opened_menu.classList.add("opacity-0");
                      menu.classList.remove("opacity-0");
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/Call_.svg";
                      contact_item.href = "tel:" + menu_details[2];
                      contact_item.addEventListener("click", function (k) {
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttp.send(
                          "action=answer&answer_text=Called" +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          menu_option_question_id +
                          "&is_logical=0" +
                          "&sequence=" +
                          menu_option_sequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&is_help=1&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                      });
                    } else if (menu_details[0] == "url") {
                      menu_options_div.classList.add("close");
                      opened_menu.classList.add("opacity-0");
                      menu.classList.remove("opacity-0");
                      contact_item.target = "_blank";
                      contact_icon.src =
                        "https://s3.ap-south-1.amazonaws.com/custpostimages/navigation_.png";
                      contact_item.href = menu_details[2];
                      if (menu_details[3] && menu_details[3].length > 0) {
                        if (menu_details[3] == "2") {
                          contact_item.target = "_blank";
                        }
                      }
                      contact_item.addEventListener("click", function (k) {
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttp.send(
                          "action=answer&answer_text=Clicked_url" +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          menu_option_question_id +
                          "&is_logical=0" +
                          "&sequence=" +
                          menu_option_sequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&is_help=1&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                      });
                    } else if (menu_details[0] == "jump_to") {
                      contact_item.id = menu_details[2];
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/bot_images/jump_to_.svg";
                      contact_item.addEventListener("click", function () {
                        if (
                          current_question_type != "statement" &&
                          current_question_type != "url_auto_redirect" &&
                          current_question_type != "contact" &&
                          current_question_type != "slides" &&
                          current_question_type != "audio" &&
                          current_question_type != "custom_answer" &&
                          current_question_type != "custom_actions" &&
                          current_question_type != "show_file" &&
                          current_question_type != "show_location" &&
                          current_question_type != "show_contacts"
                        ) {
                          if (body && body.lastChild) {
                            body.removeChild(body.lastChild);
                          }
                        }
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                        var selected_country =
                          document.getElementById("selected_country");
                        if (footer.contains(selected_country)) {
                          footer.removeChild(selected_country);
                        }
                        menu_options_div.classList.add("close");
                        opened_menu.classList.add("opacity-0");
                        menu.classList.remove("opacity-0");
                        if (!shouldShowMenu) {
                          footer.style.display = "none";
                          footer.classList.add("close");
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 168px)";
                          } else {
                            body.style.height = "calc(100% - 93px)";
                          }
                        } else {
                          if (entry_id) {
                            input.style.pointerEvents = "auto";
                            microphone.style.pointerEvents = "auto";
                            microphone.style.opacity = 1;
                            enter.style.pointerEvents = "auto";
                            setPlaceHolders();
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          } else {
                            input.style.pointerEvents = "none";
                            microphone.style.pointerEvents = "none";
                            microphone.style.opacity = 0;
                            enter.style.pointerEvents = "none";
                            input.blur();
                            input.placeholder = "Choose from Menu";
                            input.type = "text";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          }
                        }
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.src = avatar_icon;
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input.value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                reload_div.style.pointerEvents = "auto";
                                reload_div.firstChild.style.pointerEvents = 'auto';
                                reload_div.children[1].style.pointerEvents = 'auto';
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
    
                                if (current_question_type) {
                                  var main_opened_div = document.getElementById('opened');
    
                                  if (
                                    main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                                  ) {
                                    main_opened_div.removeChild(
                                      document.getElementById('bg-shadow-overlay')
                                    );
                                  }
                            
                                  var openMenuSb = document.getElementById('open-menu-sb');
                                  var optionsDiv = document.getElementsByClassName('options-div-smatest');
                            
                                  if (openMenuSb && optionsDiv?.length > 0) {
                                    for (var i = 0; i < optionsDiv.length; i++) {
                                      if (optionsDiv[i].contains(openMenuSb)) {
                                        optionsDiv[i].removeChild(openMenuSb);
                                      }
                                    }
                                  }
                  
                                  setAllInputs(question_array);
                                  assignAllQuestionTypes(current_question_type);
                                  
                                }
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.blur();
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                input.blur();
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=menu_jump_question",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        var menusession ;
                        if (cb_session) {
                          menusession = cb_session
                        }else if(roinet_old_session){
                          menusession = roinet_old_session
                        }else{
                          menusession = cb_session
                        }
                        xhttp.send(
                          "action=menu_jump_question&&cb_session=" +
                          menusession +
                          "&question_id=" +
                          this.id +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&language_code=" +
                          main_lang_code
                        );
                      });
                    } else if (menu_details[0] == "zendesk") {
                      contact_item.classList.add("pointer");
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/zendesk_navigator.png";
                      contact_item.addEventListener("click", function () {
                        menu_options_div.classList.add("close");
                        opened_menu.classList.add("opacity-0");
                        menu.classList.remove("opacity-0");
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttp.send(
                          "action=answer&answer_text=Clicked_zendesk" +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          menu_option_question_id +
                          "&is_logical=0" +
                          "&sequence=" +
                          menu_option_sequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&is_help=1&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                        try {
                          mainDiv.click();
                          zE("webWidget", "show");
                          zE("webWidget", "toggle");
                        } catch (e) {
                        } finally {
                        }
                      });
                    } else if (menu_details[0] == "tawkto") {
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/tawkto_navigator.png";
                      contact_item.addEventListener("click", function () {
                        chat_with_us_cliked = true;
                        try {
                          if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
                            window.Tawk_API.showWidget();
                            Tawk_API.maximize();
                          } else if (window.Tawk_API) {
                            Tawk_API.maximize();
                          }
                        } catch (e) {
                        } finally {
                        }
                        mainDiv.click();
                      });
                    } else if (menu_details[0] == "refresh") {
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/refresh_navigator.png";
                      contact_item.addEventListener("click", function () {
                        if (reload_div) {
                          reload_div.click();
                        }
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                      });
                    } else if (menu_details[0] == "close") {
                      contact_icon.src =
                        "https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/close_navigator.png";
                      contact_item.addEventListener("click", function () {
                        mainDiv.click();
                      });
                    } else if (menu_details[0] == "live_chat") {
                      contact_icon.src =
                        "https://s3.ap-south-1.amazonaws.com/custpostimages/sb_images/chat_agent_menu.png";
                      contact_item.classList.add("other-pointer");
                      contact_icon.title = menu_details[1];
                      contact_item.addEventListener("click", function (k) {
                        menu_options_div.classList.add("close");
                        opened_menu.classList.add("opacity-0");
                        menu.classList.remove("opacity-0");
                        nothingWentOnFor = 0;
                        encourageMessageIteration = 0;
                        chat_with_us_cliked = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttp.send(
                          "action=answer&answer_text=Clicked_tawk_to" +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          menu_option_question_id +
                          "&is_logical=0" +
                          "&sequence=" +
                          menu_option_sequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&is_help=1&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                        if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
                          window.Tawk_API.showWidget();
                          Tawk_API.maximize();
                        }
                        try {
                          zE("webWidget", "show");
                          zE("webWidget", "toggle");
                        } catch (e) {
                        } finally {
                        }
                        mainDiv.click();
                      });
                    }
                    contact_text.innerHTML = menu_details[1];
                    contact_item.appendChild(contact_text);
                    contact_item.appendChild(contact_icon);
                    menu_option_label.appendChild(contact_item);
                    menu_option_div.appendChild(menu_option_label);
                    menu_options_div.appendChild(menu_option_div);
                  }
                }
              }
              var man_opened_div = document.getElementById("opened")
              if (footer) {
                footer.appendChild(menu_options_div);
              }
              var prev_array = JSON.parse(this.response).qna_prev;
              if (prev_array && prev_array.length > 0) {
                if (chatbot_id == 10561) {
                  var xhttp = new XMLHttpRequest();
                  xhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      mainApiCall();
                    }
                  };
                  xhttp.open(
                    "POST",
                    main_url + "/kya_backend/pagehub/chatbot_utils?action=refresh_chat",
                    !0
                  );
                  xhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  xhttp.send(
                    "action=refresh_chat&cb_session=" +
                    roinet_old_session +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&device_print=" +
                    device_print
                  );
                } else {
                  mainApiCall();
                }
              } else {
                if (
                  lang_json &&
                  lang_json.multi_lingual &&
                  lang_json.multi_lingual == 1 &&
                  multi_lingual_switch
                ) {
                  if (body.contains(multiLangDiv)) {
                  } else {
                    body.appendChild(multiLangDiv);
                    if (microphone) {
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      input.style.pointerEvents = "none"
                      input.placeholder = 'Choose from Menu'
                    }
                    multiLangDiv.classList.add("scale-1");
                  }
                } else {
                  mainApiCall();
                }
              }
            }
          };
          xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat", !0);
          xhttp.setRequestHeader(
            "Content-type",
            "application/x-www-form-urlencoded"
          );
          if (
            main_lang_code &&
            main_lang_code.length > 0 &&
            main_lang_code != language_code
          ) {
          } else {
            main_lang_code = "default";
          }
          var cookiesObject;
          var bot_widget_obj;
          var is_sendable;
          try {
            checkSaveMAxUserLogin();
            checkRateGainDetails();
          } catch (error) { }
          if (window.botWidget && window.botWidget.user) {
            var keys = Object.keys(window.botWidget.user);
            for (var t = 0; t < keys.length; t++) {
              if (
                window.botWidget.user[keys[t]] &&
                window.botWidget.user[keys[t]].length > 0
              ) {
                is_sendable = true;
              }
            }
            if (is_sendable) {
              bot_widget_obj = window.botWidget.user;
            } else {
              bot_widget_obj = "";
            }
            if (window.botWidget.user.bot_id) {
              delete window.botWidget.user.bot_id;
            }
            if (window.botWidget.user.url) {
              delete window.botWidget.user.url;
            }
          }
          xhttp.send(
            "action=init_chat&device_print=" +
            device_print +
            "&chatbot_id=" +
            chatbot_id +
            "&name=" +
            encodeURIComponent(totalData[0].name) +
            "&language_code=" +
            main_lang_code +
            "&bot_widget_obj=" +
            JSON.stringify(bot_widget_obj)
          );
        }
        close.addEventListener(
          "click",
          function (k) {
            if (
              /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                navigator.userAgent
              )
            ) {
              k.stopPropagation();
            }
            mainDiv.click();
          },
          !1
        );
        header.addEventListener(
          "click",
          function (k) {
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            if (
              /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
                navigator.userAgent
              )
            ) {
              try {
                if (
                  body.parentElement &&
                  body.parentElement.parentElement &&
                  body.parentElement.parentElement.parentElement
                ) {
                  var main_body = body.parentElement.parentElement.parentElement;
                  if (
                    main_body.clientWidth == 361 ||
                    main_body.clientWidth == 150
                  ) {
                    if (window.parent) {
                      window.parent.postMessage("disappear", "*");
                    }
                  }
                }
              } catch (e) {
              } finally {
              }
              var label = document.getElementsByClassName(
                "launcher-label-smatest"
              )[0];
              if (label) {
                label.parentElement.style.display = "none";
              }
              if (document.getElementsByClassName("smat-lb-div")[0]) {
                document.getElementsByClassName("smat-lb-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-other-div")[0]) {
                document.getElementsByClassName("smat-other-div")[0].style.padding =
                  "0px";
              } else if (document.getElementsByClassName("smat-rm-div")[0]) {
                document.getElementsByClassName("smat-rm-div")[0].style.padding =
                  "0px";
              }
              if (mainDiv.className.includes("smat-other-div")) {
                mainDiv.classList.remove("smat-other-div");
                mainDiv.classList.add("smat-div");
              }
              if (mainDiv.className.includes("smat-lb-other-div")) {
                mainDiv.classList.remove("smat-lb-other-div");
                mainDiv.classList.add("smat-lb-div");
              }
              if (mainDiv.className.includes("smat-rm-other-div")) {
                mainDiv.classList.remove("smat-rm-other-div");
                mainDiv.classList.add("smat-rm-div");
              }
              if (pulseDiv.className.includes("pulse-rm-other-div")) {
                pulseDiv.classList.remove("pulse-rm-other-div");
                pulseDiv.classList.add("pulse-rm-div");
              }
              body.style.display = "none";
              mainDiv.style.display = "block";
              var img = document.getElementById("main_icon_smatest");
              if (img.className.includes("height-25")) {
                img.classList.remove("height-25");
              }
              if (img.className.includes("width-25")) {
                img.classList.remove("width-25");
              }
              img.src = avatar_icon;
              img.currentSrc = avatar_icon;
              if (mainDiv.className.includes("padding-15")) {
                mainDiv.classList.remove("padding-15");
              }
              // anotherDiv.style.display = "none";
              // anotherDiv.style.bottom = "-100%";
              anotherDiv.style.visibility = "hidden";
              if (launcher_position == "LB") {
                anotherDiv.style.transform = "translateX(-40%) translateY(40%) scale(0)";
              }else{
                anotherDiv.style.transform = "translateX(40%) translateY(40%) scale(0)";
              }

              // mainDiv.style.background = 'transparent';
              if (mainDiv.classList.contains("bg-green-gradient")) {
                mainDiv.classList.remove("bg-green-gradient");
              }
              if (header.contains(company_title_description)) {
                header.removeChild(company_title_description);
                header.style.textAlign = "center";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                imgLogo.style.top = "0";
                company_name_dec.style.display = "inline-flex";
                header.style.height = "60px";
                company_name_dec.style.float = "left";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                  document.getElementById('rating-live-chat-feedback_div_sb').style.top = '60px'
                }
                if (header.classList.contains("header-ease-in")) {
                  header.classList.remove("header-ease-in");
                }
                var selected_orders_div =
                  document.getElementById("selected-orders");
                if (footer.style.display == "none") {
                  body.style.height = "calc(100% - 93px)";
                } else if (footer.contains(selected_orders_div)) {
                  body.style.height = "calc(100% - 174px)";
                } else {
                  if (footer.style.height == "230px") {
                    body.style.height = "calc(100% - 323px)";
                  } else if (footer.style.height == "315px") {
                    body.style.height = "calc(100% - 408px)";
                  } else {
                    var x = footer.offsetHeight + 93 +13;
                    body.style.height = "calc(100% - " + x + "px)";
                  }
                }
                if (
                  document.getElementsByClassName("feedback-full-div") &&
                  document.getElementsByClassName("feedback-full-div").length > 0
                ) {
                  var elem =
                    document.getElementsByClassName("feedback-full-div")[0];
                  var x = anotherDiv.clientHeight;
                  if (header.contains(company_title_description)) {
                    x = x - 135 + 15;
                  } else {
                    x = x - 60 + 15;
                  }
                  elem.style.top = "calc(100vh - " + x + "px)";
                }
              }
            } else {
              if (header.contains(company_title_description)) {
                header.removeChild(company_title_description);
                header.style.textAlign = "center";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                imgLogo.style.top = "0";
                company_name_dec.style.display = "inline-flex";
                header.style.height = "60px";
                company_name_dec.style.float = "left";
                imgLogo.style.marginLeft = "0px";
                imgLogo.style.height = "36px";
                imgLogo.style.width = "36px";
                if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                  document.getElementById('rating-live-chat-feedback_div_sb').style.top = '60px'
                }
                if (header.classList.contains("header-ease-in")) {
                  header.classList.remove("header-ease-in");
                }
                var selected_orders_div =
                  document.getElementById("selected-orders");
                if (footer.style.display == "none") {
                  body.style.height = "calc(100% - 93px)";
                } else if (footer.contains(selected_orders_div)) {
                  body.style.height = "calc(100% - 215px)";
                } else {
                  if (footer.style.height == "230px") {
                    body.style.height = "calc(100% - 323px)";
                  } else if (footer.style.height == "315px") {
                    body.style.height = "calc(100% - 408px)";
                  } else {
                    var x = footer.offsetHeight + 93 + 13;
                    body.style.height = "calc(100% - " + x + "px)";
                  }
                }
                if (
                  document.getElementsByClassName("feedback-full-div") &&
                  document.getElementsByClassName("feedback-full-div").length > 0
                ) {
                  var elem =
                    document.getElementsByClassName("feedback-full-div")[0];
                  var x = anotherDiv.clientHeight;
                  if (header.contains(company_title_description)) {
                    x = x - 135 + 15;
                  } else {
                    x = x - 60 + 15;
                  }
                  elem.style.top = "calc(100vh - " + x + "px)";
                }
              } else {
                if (company_description_label.innerHTML != "") {
                  header.appendChild(company_title_description);
                  header.style.height = "135px";
                  header.style.textAlign = "center";
                  imgLogo.style.cssText =
                    imgLogo.style.cssText +
                    "margin-left:calc(50% - 25px) !important";
                  imgLogo.style.height = "44px";
                  imgLogo.style.width = "44px";
                  imgLogo.style.top = "9px";
                  company_name_dec.style.display = "none";
                  if (document.getElementById('rating-live-chat-feedback_div_sb')) {
                    document.getElementById('rating-live-chat-feedback_div_sb').style.top = '135px'
                  }
                  if (header.classList.contains("header-ease-in")) {
                  } else {
                    header.classList.add("header-ease-in");
                  }
                  var selected_orders_div =
                    document.getElementById("selected-orders");
                  if (footer.style.display == "none") {
                    body.style.height = "calc(100% - 168px)";
                  } else if (footer.contains(selected_orders_div)) {
                    body.style.height = "calc(100% - 285px)";
                  } else {
                    if (footer.style.height == "230px") {
                      body.style.height = "calc(100% - 398px)";
                    } else if (footer.style.height == "315px") {
                      body.style.height = "calc(100% - 483px)";
                    } else {
                      var x = footer.offsetHeight + 168 + 14;
                      body.style.height = "calc(100% - " + x + "px)";
                    }
                  }
                  if (
                    document.getElementsByClassName("feedback-full-div") &&
                    document.getElementsByClassName("feedback-full-div").length > 0
                  ) {
                    var elem =
                      document.getElementsByClassName("feedback-full-div")[0];
                    var x = anotherDiv.clientHeight;
                    if (header.contains(company_title_description)) {
                      x = x - 135 + 15;
                    } else {
                      x = x - 60 + 15;
                    }
                    elem.style.top = "calc(100vh - " + x + "px)";
                  }
                }
              }
            }
          },
          !1
        );
        body.addEventListener("click", function (k) {
          if (header.contains(company_title_description)) {
            header.removeChild(company_title_description);
            header.style.textAlign = "center";
            imgLogo.style.marginLeft = "0px";
            imgLogo.style.height = "36px";
            imgLogo.style.width = "36px";
            imgLogo.style.top = "0";
            company_name_dec.style.display = "inline-flex";
            header.style.height = "60px";
            company_name_dec.style.float = "left";
            imgLogo.style.marginLeft = "0px";
            imgLogo.style.height = "36px";
            imgLogo.style.width = "36px";
            if (document.getElementById('rating-live-chat-feedback_div_sb')) {
              document.getElementById('rating-live-chat-feedback_div_sb').style.top = '60px'
            }
            if (header.classList.contains("header-ease-in")) {
              header.classList.remove("header-ease-in");
            }
            var selected_orders_div = document.getElementById("selected-orders");
            if (footer.style.display == "none") {
              body.style.height = "calc(100% - 93px)";
            } else if (footer.contains(selected_orders_div)) {
              body.style.height = "calc(100% - 174px)";
            } else {
              if (footer.style.height == "230px") {
                body.style.height = "calc(100% - 323px)";
              } else if (footer.style.height == "315px") {
                body.style.height = "calc(100% - 408px)";
              } else {
                var x = footer.offsetHeight + 93 +13;
                body.style.height = "calc(100% - " + x + "px)";
              }
            }
          }
        });
        body.addEventListener("wheel", function (event) {
          const atBottom = body.scrollTop + body.clientHeight >= body.scrollHeight;
          const atTop = body.scrollTop === 0;
          if ((atBottom && event.deltaY > 0) || (atTop && event.deltaY < 0)) {
            event.preventDefault();
          }
        });
        var question_completed = !1;
        bot_mic.addEventListener("click", function (k) {
          chat_with_us_cliked = !0;
          nothingWentOnFor = 0;
          encourageMessageIteration = 0;
          mainDiv.click();
          if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
            window.Tawk_API.showWidget();
            Tawk_API.maximize();
          }
          try {
            zE("webWidget", "show");
            zE("webWidget", "toggle");
          } catch (e) {
          } finally {
          }
        });

        function setCustomTimeout(callback, delay) {
          const timeoutId = setTimeout(() => {
            // Execute the callback only if the chatbot is not reloaded
            if (!isReloaded) {
              callback();
            } else {
              callback();
            }
            // Remove the timeout ID from the activeTimeouts array
            activeTimeouts = activeTimeouts.filter(id => id !== timeoutId);
          }, delay);
          // Store the timeout ID in the activeTimeouts array
          activeTimeouts.push(timeoutId);
          return timeoutId;
        }

        reload_div.addEventListener(
          "click",
          function (k) {
            isReloaded = true;
            try {
              window.stop();
              audio_going_on = false;
              document.close();
              player.pause();
              speechQueue = [];
              synthesizer.close();
              activeTimeouts.forEach(timeoutId => clearTimeout(timeoutId));
              activeTimeouts = [];
              if (audioElement) {
                audioElement.pause()
                audioElement = null
              }
            } catch (error) {
            }
            agreed = !0;
            liveSessionSet = false;
            if (document.getElementById("opened")) {
              if (document.getElementById("opened").contains(document.getElementById("rating-live-chat-feedback_div_sb"))) {
                document.getElementById("opened").removeChild(document.getElementById("rating-live-chat-feedback_div_sb"))
              } 
            }
            var main_opened_div = document.getElementById('opened');
            var bgShadowOverlays = main_opened_div.querySelectorAll('#bg-shadow-overlay');
            bgShadowOverlays?.forEach(function(bgShadowOverlay) {
              if (main_opened_div.contains(bgShadowOverlay)) {
                main_opened_div.removeChild(bgShadowOverlay);
              }
            });
            if (header_menu_div.classList.contains("closed-header-menu")) {
            } else {
              header_menu_div.classList.add("closed-header-menu");
            }
            if (header_menu_div.contains(ask_live_chat_feedback_div)) {
              header_menu_div.removeChild(ask_live_chat_feedback_div);
              adminMessaged = false;
            }
            var audio = document.getElementById("audioPlayback");
            if (audio) {
              audio.pause();
              audio.currentTime = 0;
            }
            agent_message_timer = 0;
            start_live_chat_timer = false;
            try {
              if (liveChatFeedbackInput) {
                liveChatFeedbackinput.style.pointerEvents = "auto";
                microphone.style.pointerEvents = "auto";
                microphone.style.opacity = 1;
              }
              if (liveChatInputSubmit) {
                liveChatInputSubmit.style.pointerEvents = "auto";
              }
              var rtl_elems = anotherDiv.getElementsByClassName("rtl");
              if (rtl_elems && rtl_elems.length > 0) {
                for (var i = 0; i < rtl_elems.length; i++) {
                  rtl_elems[i].classList.remove("rtl");
                  i--;
                }
              }
            } catch (e) {
            } finally {
            }
            if (footer.contains(attach_label)) {
              footer.removeChild(attach_label);
              if (shouldShowMenu) {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 115px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 80px) !important";
                }
              } else {
                if (voice_input == "1") {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 75px) !important";
                } else {
                  input.style.cssText =
                    input.style.cssText + "width:calc(100% - 45px) !important";
                }
              }
            }
            if (header_menu_div.contains(video_call_icon_div)) {
              header_menu_div.removeChild(video_call_icon_div);
            }
            var video_container = document.getElementById("video-container-div");
            if (body.contains(video_container)) {
              video_container.innerHTML = "";
              video_call_icon_div.style.pointerEvents = "auto";
              body.removeChild(video_container);
            }
            if (!start_again_clicked) {
              try {
                var d = new Date();
                var date = d.getDate();
                if (date < 10) {
                  date = "0" + date;
                }
                var month = d.getMonth() + 1;
                if (month < 10) {
                  month = "0" + month;
                }
                var hours = d.getHours();
                if (hours < 10) {
                  hours = "0" + hours;
                }
                var mins = d.getMinutes();
                if (mins < 10) {
                  mins = "0" + mins;
                }
                var seconds = d.getSeconds();
                if (seconds < 10) {
                  seconds = "0" + seconds;
                }
                d =
                  date +
                  "/" +
                  month +
                  "/" +
                  d.getFullYear() +
                  ", " +
                  hours +
                  ":" +
                  mins +
                  ":" +
                  seconds;
                sock.emit("closesession", {
                  session_id: live_chat_cb_session,
                  device_print: device_print,
                  bot_id: chatbot_id,
                  time: d,
                  channel: "website",
                  agent_id: agent_id,
                });
              } catch (e) {
              } finally {
              }
            } else {
              start_again_clicked = false;
            }
            var selected_orders_div_delete =
              document.getElementById("selected-orders");
            if (
              selected_orders_div_delete &&
              footer.contains(selected_orders_div_delete)
            ) {
              footer.removeChild(selected_orders_div_delete);
            }
            if (document.getElementById(input.id + "order-autocomplete-list")) {
              document
                .getElementById(input.id + "order-autocomplete-list")
                .parentElement.removeChild(
                  document.getElementById(input.id + "order-autocomplete-list")
                );
            }
            add_more_clicked = false;
            updateMenuIcons()
            try {
              input.removeEventListener("keyup", myEfficientFn);
              input.removeEventListener("click", orderAutocomplete);
              input.removeEventListener("keyup", realTimeSearch);
              input.removeEventListener("click", autocomplete);
            } catch (e) {
            } finally {
            }
            footer.style.height = "49px";
            footer.style.maxHeight = "310px";
            footer.style.padding = "6px 15px";
            input.style.display = "block";
            enter.style.display = "flex";
            live_chat_feedback_submitted = false;
            live_chat_feedback_rated = false;
            if (menu_options_div) {
              menu_options_div.innerHTML = "";
            }
            selected_orders = [];
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            mailSent = !1;
            alreadyWebpageClosed = !1;
            var selected_country = document.getElementById("selected_country");
            if (footer.contains(selected_country)) {
              footer.removeChild(selected_country);
            }
            var slots_div = document.getElementById("slot-scroll");
            if (document.getElementsByClassName("pika-single")[0]) {
              document.getElementsByClassName("pika-single")[0].style.bottom =
                "33px";
            }
            if (footer.contains(slots_div)) {
              footer.removeChild(slots_div);
            }
            if (picker) {
              try {
                picker.destroy();
              } catch (e) {
              } finally {
              }
            }
            session_feedback = undefined;
            needPrivacy = !1;
            otp_verified = !1;
            prev_email_text = undefined;
            alreadyEmailChecked = !1;
            k.stopPropagation();
            input.value = "";
            input.id = "";
            if (!shouldShowMenu) {
              footer.style.display = "none";
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 168px)";
              } else {
                body.style.height = "calc(100% - 93px)";
              }
              footer.classList.add("close");
            } else {
              if (entry_id) {
                input.style.pointerEvents = "auto";
                microphone.style.pointerEvents = "auto";
                microphone.style.opacity = 1;
                enter.style.pointerEvents = "auto";
                setPlaceHolders();
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
              } else {
                input.style.pointerEvents = "none";
                microphone.style.pointerEvents = "none";
                microphone.style.opacity = 0;
                enter.style.pointerEvents = "none";
                input.blur();
                input.placeholder = "Choose from Menu";
                input.type = "text";
                if (header.contains(company_title_description)) {
                  body.style.height = "calc(100% - 226px)";
                } else {
                  body.style.height = "calc(100% - 150px)";
                }
              }
            }
            while (body.firstChild) {
              body.removeChild(body.firstChild);
            }
            if (footer.firstChild && footer.firstChild.id == "selected_country") {
              footer.removeChild(footer.firstChild);
            }
            var spinningDiv = document.createElement("DIV");
            spinningDiv.classList.add("question-div-smatest");
            spinningDiv.classList.add("top-0");
            if (font && font.length > 0) {
              spinningDiv.classList.add(font);
            }
            var spinnerDiv = document.createElement("DIV");
            spinnerDiv.classList.add("spinner1-smatest");
            var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
            ques_icon.src = avatar_icon;
            var iconDiv = document.createElement("DIV");
            iconDiv.appendChild(ques_icon);
            iconDiv.classList.add("question-icon-div");
            ques_icon.classList.add("question-icon-smatest");
            var inner1 = document.createElement("DIV");
            inner1.classList.add("bounce1");
            var inner2 = document.createElement("DIV");
            inner2.classList.add("bounce2");
            var inner3 = document.createElement("DIV");
            inner3.classList.add("bounce3");
            spinnerDiv.appendChild(inner1);
            spinnerDiv.appendChild(inner2);
            spinnerDiv.appendChild(inner3);
            spinningDiv.appendChild(iconDiv);
            spinningDiv.appendChild(spinnerDiv);
            body.appendChild(spinningDiv);
            reload_div.style.pointerEvents = "none";
            reload_div.firstChild.style.pointerEvents = 'none';
            reload_div.children[1].style.pointerEvents = 'none';
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                isReloaded = true;
                body.innerHTML = "";
                window.stop();
                document.close();
                scheduleClicked = !1;
                alreadyEmailChecked = !1;
                question_and_answers = [];
                // body.removeChild(spinningDiv);
                entry_id = !1;
                main_lang_code = "default";
                if (!question_completed && random_key) {
                  mailSent = !1;
                  var xhttp = new XMLHttpRequest();
                  xhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      var questionArray = [];
                      prev_questions_array = JSON.parse(this.response).qna_prev;
                      if (prev_questions_array && prev_questions_array.length > 0) {
                        for (var i = 0; i < prev_questions_array.length; i++) {
                          if (
                            prev_questions_array[i].type == "contact" ||
                            prev_questions_array[i].type == "slides" ||
                            prev_questions_array[i].type == "statement" ||
                            prev_questions_array[i].type == "url_auto_redirect" ||
                            prev_questions_array[i].type == "custom_answer" ||
                            prev_questions_array[i].type == "show_file" ||
                            prev_questions_array[i].type == "show_contacts" ||
                            prev_questions_array[i].type == "show_location"
                          ) {
                            prev_questions_array.splice(i, 1);
                            i--;
                          }
                        }
                        if (zapier_webhook && zapier_webhook.length > 0) {
                          var output = {};
                          output.timestamp = new Date();
                          for (var i = 0; i < prev_questions_array.length; i++) {
                            var str = prev_questions_array[i].question_text;
                            output[str] = prev_questions_array[i].answer_text;
                          }
                          var xhttp = new XMLHttpRequest();
                          xhttp.onreadystatechange = function () {
                            if (this.readyState == 4 && this.status == 200) {
                            }
                          };
                          xhttp.open("POST", zapier_webhook, !0);
                          xhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          xhttp.send("output=" + JSON.stringify(output));
                        }
                        for (var i = 0; i < prev_questions_array.length; i++) {
                          questionArray.push({
                            question: prev_questions_array[i].question_text,
                            answer: prev_questions_array[i].answer_text,
                          });
                        }
                      }
                    }
                  };
                  xhttp.open(
                    "POST",
                    main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                    !0
                  );
                  xhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  if (
                    main_lang_code &&
                    main_lang_code.length > 0 &&
                    main_lang_code != language_code
                  ) {
                  } else {
                    main_lang_code = "default";
                  }
                  var bot_widget_obj;
                  var is_sendable;
                  try {
                    checkSaveMAxUserLogin();
                    checkRateGainDetails();
                  } catch (error) { }
                  if (window.botWidget && window.botWidget.user) {
                    var keys = Object.keys(window.botWidget.user);
                    for (var t = 0; t < keys.length; t++) {
                      if (
                        window.botWidget.user[keys[t]] &&
                        window.botWidget.user[keys[t]].length > 0
                      ) {
                        is_sendable = true;
                      }
                    }
                    if (is_sendable) {
                      bot_widget_obj = window.botWidget.user;
                    } else {
                      bot_widget_obj = "";
                    }
                    if (window.botWidget.user.bot_id) {
                      delete window.botWidget.user.bot_id;
                    }
                    if (window.botWidget.user.url) {
                      delete window.botWidget.user.url;
                    }
                  }
                  xhttp.send(
                    "action=init_chat&device_print=" +
                    device_print +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&language_code=" +
                    main_lang_code +
                    "&bot_widget_obj=" +
                    JSON.stringify(bot_widget_obj)
                  );
                  mainClick();
                } else {
                  mainClick();
                }
              } else if (this.readyState == 4) {
                isReloaded = true;
                reload_div.style.pointerEvents = "auto";
                reload_div.firstChild.style.pointerEvents = 'auto';
                reload_div.children[1].style.pointerEvents = 'auto';
              }
            };
            xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=refresh_chat", !0);
            xhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            xhttp.send(
              "action=refresh_chat&cb_session=" +
              cb_session +
              "&chatbot_id=" +
              chatbot_id +
              "&device_print=" +
              device_print
            );
          },
          !1
        );
        sound_icon_div.addEventListener(
          "click",
          function (k) {
            k.stopPropagation();
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            is_sound_on = !is_sound_on;
            if (is_sound_on) {
              sound_icon.classList.remove("sound-off-icon");
              sound_icon.classList.add("sound-icon");
              sound_text.innerHTML = "Mute Notifications";
            } else {
              window.speechSynthesis.cancel();
              sound_icon.classList.remove("sound-icon");
              sound_icon.classList.add("sound-off-icon");
              sound_text.innerHTML = "Unmute Notifications";
            }
          },
          !1
        );

        if(chatbot_id && chatbot_id == "25016") { 
          mainClick();
        }

        var entered;
        var otp_entered = 0;

        function urlify(str) {
          var urlRegex =
            /((?:(http|https|Http|Https|rtsp|Rtsp):\/\/(?:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,64}(?:\:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,25})?\@)?)?((?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}\.)+(?:(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])|(?:biz|b[abdefghijmnorstvwyz])|(?:cat|com|coop|c[acdfghiklmnoruvxyz])|d[ejkmoz]|(?:edu|e[cegrstu])|f[ijkmor]|(?:gov|g[abdefghilmnpqrstuwy])|h[kmnrtu]|(?:info|int|i[delmnoqrst])|(?:jobs|j[emop])|k[eghimnrwyz]|l[abcikrstuvy]|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])|(?:name|net|n[acefgilopruz])|(?:org|om)|(?:pro|p[aefghklmnrstwy])|qa|r[eouw]|s[abcdeghijklmnortuvyz]|(?:tel|travel|t[cdfghjklmnoprtvwz])|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]))|(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])))(?:\:\d{1,5})?)(\/(?:(?:[a-zA-Z0-9\;\/\?\:\@\&\=\#\~\-\.\+\!\*\'\(\)\,\_])|(?:\%[a-fA-F0-9]{2}))*)?(?:\b|$)/gi;
          return str.replace(urlRegex, function (url) {
            return '<a target="_blank" href="' + url + '">' + url + "</a>";
          });
        }

        function urlsFromString(str) {
          var urlRegex =
            /((?:(http|https|Http|Https|rtsp|Rtsp):\/\/(?:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,64}(?:\:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,25})?\@)?)?((?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}\.)+(?:(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])|(?:biz|b[abdefghijmnorstvwyz])|(?:cat|com|coop|c[acdfghiklmnoruvxyz])|d[ejkmoz]|(?:edu|e[cegrstu])|f[ijkmor]|(?:gov|g[abdefghilmnpqrstuwy])|h[kmnrtu]|(?:info|int|i[delmnoqrst])|(?:jobs|j[emop])|k[eghimnrwyz]|l[abcikrstuvy]|(?:mil|mobi|museum|m[acdghklmnopqrstuvwxyz])|(?:name|net|n[acefgilopruz])|(?:org|om)|(?:pro|p[aefghklmnrstwy])|qa|r[eouw]|s[abcdeghijklmnortuvyz]|(?:tel|travel|t[cdfghjklmnoprtvwz])|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]))|(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])))(?:\:\d{1,5})?)(\/(?:(?:[a-zA-Z0-9\;\/\?\:\@\&\=\#\~\-\.\+\!\*\'\(\)\,\_])|(?:\%[a-fA-F0-9]{2}))*)?(?:\b|$)/gi;
          var urls = [];
          str.replace(urlRegex, function (url) {
            urls.push(url);
          });
          return urls;
        }

        function addReEnterMobileDiv(resend_div) {
          var re_enter_div = document.createElement("DIV");
          re_enter_div.classList.add("file-input-div");
          re_enter_div.classList.add("pull-left");
          re_enter_div.classList.add("full-width");
          re_enter_div.classList.add("text-center");
          var re_enter_btn = document.createElement("BUTTON");
          re_enter_btn.innerHTML = "Re-Enter Mobile number";
          re_enter_btn.classList.add("confirm-btn-smatest");
          if (font && font.length > 0) {
            re_enter_btn.classList.add(font);
          }
          re_enter_div.appendChild(re_enter_btn);
          re_enter_btn.addEventListener("click", function (k) {
            current_question_type = "phone";
            footer.style.display = "block";
            phoneValidated = !0;
            var errorDiv = document.createElement("DIV");
            errorDiv.classList.add("question-div-smatest");
            setTimeout(function () {
              errorDiv.classList.add("top-0");
            }, transition_time);
            if (font && font.length > 0) {
              errorDiv.classList.add(font);
            }
            var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
            error_icon.src = avatar_icon;
            var iconDiv = document.createElement("DIV");
            iconDiv.appendChild(error_icon);
            iconDiv.classList.add("question-icon-div");
            error_icon.classList.add("question-icon-smatest");
            var error_text = document.createElement("LABEL");
            error_text.innerHTML = "Please enter your mobile number again";
            say(error_text.innerText);
            error_text.classList.add("question-text-error");
            error_text.classList.add("options-div-smatest");
            if (font && font.length > 0) {
              error_text.classList.add(font);
            }
            errorDiv.appendChild(iconDiv);
            errorDiv.appendChild(error_text);
            body.appendChild(errorDiv);
            playBotUserSound(1);
            body.scrollTop = body.scrollHeight;
            var selected_country = document.getElementById("selected_country");
            if (footer.contains(selected_country)) {
              footer.removeChild(selected_country);
            }
            var select_country = document.createElement("SELECT");
            select_country.id = "selected_country";
            select_country.style.cssText = select_country.style.cssText + "margin:0 !important";
            select_country.style.cssText = select_country.style.cssText + "height:34px !important";
            for (var i = 0; i < countries.length; i++) {
              var option = document.createElement("option");
              option.value = countries[i];
              option.innerHTML = countries[i];
              select_country.appendChild(option);
            }
            select_country.classList.add("smat-dropdown-botest");
            if (font && font.length > 0) {
              select_country.classList.add(font);
            }
            if (user_dial_code) {
              select_country.value = user_dial_code;
            } else {
              select_country.value = "India +91";
            }
            if (shouldShowMenu) {
              if (voice_input == "1") {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 185px) !important";
              } else {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 150px) !important";
              }
            } else {
              if (voice_input == "1") {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 150px) !important";
              } else {
                input.style.cssText =
                  input.style.cssText + "width:calc(100% - 115px) !important";
              }
            }
            input.style.cssText = input.style.cssText + "min-height:24px !important";
            input.style.cssText = input.style.cssText + "height:24px !important";
            input.style.cssText = input.style.cssText + "border:none !important";
            // input.style.cssText = input.style.cssText + "max-height:72px !important";
            if (is_firefox) {
              input.type = "text";
            } else {
              input.type = "number";
            }
            input.id = "";
            footer.id = "";
            input.value = "";
            input.autocomplete = "off";
            try {
              google.maps.event.clearInstanceListeners(input);
            } catch (e) {
            } finally {
            }
            translateContent(translations, input, "Enter your phone number", main_lang_code, language_code, 2);
            var shouldNotInsert;
            var childs = footer.children;
            for (var i = 0; i < childs.length; i++) {
              if (childs[i].id == "selected_country") {
                shouldNotInsert = !0;
              }
            }
            if (!shouldNotInsert) {
              if (shouldShowMenu) {
                footer.insertBefore(select_country, footer.children[2]);
              } else {
                footer.insertBefore(select_country, footer.firstChild);
              }
            }
            // resend_div.parentElement.removeChild(resend_div);
            if (resend_div && resend_div.parentElement) {
              resend_div.parentElement.removeChild(resend_div);
            }
          });
          resend_div.appendChild(re_enter_div);
          enter.style.pointerEvents = "auto"
          input.style.pointerEvents = "auto"
        }

        function addTextDivToBot(str) {
          var errorDiv = document.createElement("DIV");
          errorDiv.classList.add("question-div-smatest");
          setTimeout(function () {
            errorDiv.classList.add("top-0");
          }, transition_time);
          if (font && font.length > 0) {
            errorDiv.classList.add(font);
          }
          var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
          error_icon.src = avatar_icon;
          var iconDiv = document.createElement("DIV");
          iconDiv.appendChild(error_icon);
          iconDiv.classList.add("question-icon-div");
          error_icon.classList.add("question-icon-smatest");
          var option_div = document.createElement("DIV");
          option_div.classList.add("options-div-smatest");
          var option_question = document.createElement("LABEL");
          if (font && font.length > 0) {
            option_question.classList.add(font);
          }
          if (
            (main_lang_code &&
              (main_lang_code == "he" ||
                main_lang_code == "ur" ||
                main_lang_code == "ar")) ||
            (main_lang_code == "default" &&
              (language_code == "ar" ||
                language_code == "he" ||
                language_code == "ur"))
          ) {
            option_question.classList.add("rtl");
          }
          option_question.innerHTML = "<div>" + str + "</div>";
          say(option_question.innerText);
          option_div.appendChild(option_question);
          errorDiv.appendChild(iconDiv);
          errorDiv.appendChild(option_div);
          body.appendChild(errorDiv);
          playBotUserSound(1);
          body.scrollTop = body.scrollHeight;
        }

        function handleResendOTPCase(response) {
          try {
            var temp_div = document.getElementById("resend-email-div");
            if (temp_div && temp_div.parentElement) {
              temp_div.parentElement.removeChild(temp_div);
            }
          } catch (error) { }
          email_timestamp = response.timestamp;
          var spinningDiv = document.createElement("DIV");
          spinningDiv.classList.add("question-div-smatest");
          spinningDiv.classList.add("top-0");
          if (font && font.length > 0) {
            spinningDiv.classList.add(font);
          }
          var spinnerDiv = document.createElement("DIV");
          spinnerDiv.classList.add("spinner1-smatest");
          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
          ques_icon.src = avatar_icon;
          var iconDiv = document.createElement("DIV");
          iconDiv.appendChild(ques_icon);
          iconDiv.classList.add("question-icon-div");
          ques_icon.classList.add("question-icon-smatest");
          var inner1 = document.createElement("DIV");
          inner1.classList.add("bounce1");
          var inner2 = document.createElement("DIV");
          inner2.classList.add("bounce2");
          var inner3 = document.createElement("DIV");
          inner3.classList.add("bounce3");
          spinnerDiv.appendChild(inner1);
          spinnerDiv.appendChild(inner2);
          spinnerDiv.appendChild(inner3);
          spinningDiv.appendChild(iconDiv);
          spinningDiv.appendChild(spinnerDiv);
          body.appendChild(spinningDiv);
          body.scrollTop = body.scrollHeight;
          setTimeout(function () {
            enter.style.pointerEvents = "auto";
            footer.style.display = "block";
            if (header.contains(company_title_description)) {
              body.style.height = "calc(100% - 226px)";
            } else {
              body.style.height = "calc(100% - 150px)";
            }
            footer.classList.remove("close");
            if (shouldShowMenu) {
              input.style.pointerEvents = "auto";
              microphone.style.pointerEvents = "auto";
              microphone.style.opacity = 1;
              enter.style.pointerEvents = "auto";
            }
            input.focus();
            if (spinningDiv && spinningDiv.parentNode == body) {
              body.removeChild(spinningDiv);
            }
            current_logical_jump = question_array[0].logical_jump;
            currentMailSequence = question_array[0].sequence;
            currentQuestionIsLead = question_array[0].send_mail;
            var errorDiv = document.createElement("DIV");
            errorDiv.classList.add("question-div-smatest");
            setTimeout(function () {
              errorDiv.classList.add("top-0");
            }, transition_time);
            if (font && font.length > 0) {
              errorDiv.classList.add(font);
            }
            var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
            error_icon.src = avatar_icon;
            var iconDiv = document.createElement("DIV");
            iconDiv.appendChild(error_icon);
            iconDiv.classList.add("question-icon-div");
            error_icon.classList.add("question-icon-smatest");
            var option_div = document.createElement("DIV");
            option_div.classList.add("options-div-smatest");
            var option_question = document.createElement("LABEL");
            if (font && font.length > 0) {
              option_question.classList.add(font);
            }
            if (
              (main_lang_code &&
                (main_lang_code == "he" ||
                  main_lang_code == "ur" ||
                  main_lang_code == "ar")) ||
              (main_lang_code == "default" &&
                (language_code == "ar" ||
                  language_code == "he" ||
                  language_code == "ur"))
            ) {
              option_question.classList.add("rtl");
            }
            option_question.innerHTML = "<div>" + response.message + "</div>";
            say(option_question.innerText);
            option_div.appendChild(option_question);
            var resend_div = document.createElement("DIV");
            resend_div.id = "resend-email-div";
            resend_div.classList.add("file-input-div");
            resend_div.classList.add("pull-left");
            resend_div.classList.add("full-width");
            resend_div.classList.add("text-center");
            var otp_remaining_time = 45;
            var otp_time = document.createElement("LABEL");
            otp_time.classList.add("pull-left");
            otp_time.classList.add("full-width");
            otp_time.classList.add("text-center");
            otp_time.classList.add("m-t-5");
            otp_time.classList.add("m-b-10");
            if (font && font.length > 0) {
              otp_time.classList.add(font);
            }
            otp_time.classList.add("limegreen");
            otp_time.innerHTML = otp_remaining_time + "s Remaining";
            resend_div.appendChild(otp_time);
            var resend_label = document.createElement("LABEL");
            var resend_span = document.createElement("SPAN");
            resend_span.innerHTML = "Resend OTP";
            resend_span.classList.add("p-r-12");
            resend_label.appendChild(resend_span);
            resend_label.htmlFor = "capture-input";
            resend_label.classList.add("upload-button-sb");
            if (!agreed) {
              resend_label.classList.add("no-pointer-events");
            }
            var change_email_label = document.createElement("LABEL");
            var change_email_span = document.createElement("SPAN");
            change_email_span.innerHTML = "Change Email";
            change_email_span.classList.add("p-r-12");
            change_email_label.appendChild(change_email_span);
            change_email_label.htmlFor = "capture-input";
            change_email_label.classList.add("upload-button-sb");
            if (!agreed) {
              change_email_label.classList.add("no-pointer-events");
            }
            var otp_sent = 0;
            var shouldStopChecking;
            setInterval(function () {
              if (!shouldStopChecking) {
                otp_remaining_time = otp_remaining_time - 1;
                otp_time.innerHTML = otp_remaining_time + "s Remaining";
                if (otp_remaining_time == 5) {
                  otp_time.classList.remove("limegreen");
                  otp_time.classList.add("red");
                }
                if (otp_remaining_time == 0) {
                  shouldStopChecking = !0;
                  if (resend_div.contains(otp_time)) {
                    resend_div.removeChild(otp_time);
                  }
                  if (resend_div.contains(resend_label)) {
                    resend_div.removeChild(resend_label);
                  }
                  if (resend_div.contains(change_email_label)) {
                    resend_div.removeChild(change_email_label);
                  }

                  otp_sent = otp_sent + 1;
                }
              }
            }, 1000);
            resend_label.addEventListener("click", function (k) {
              var phoneXhttp = new XMLHttpRequest();
              phoneXhttp.onreadystatechange = function () {
                resend_span.innerHTML = "Resending OTP";
                resend_label.classList.add("no-pointer-events");
                resend_label.classList.add("bg-lightgray");
                if (this.readyState == 4 && this.status == 200) {
                  var response = JSON.parse(this.response);
                  if (response && response.status) {
                    email_timestamp = response.timestamp;
                    resend_label.classList.remove("bg-lightgray");
                    resend_label.classList.remove("no-pointer-events");
                    resend_span.innerHTML = "Resend OTP";
                    footer.style.display = "block";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.classList.remove("close");
                    if (shouldShowMenu) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                    }
                    input_value = "";
                    input.focus();
                    handleResendOTPCase(response);
                  } else {
                    resend_label.classList.remove("bg-lightgray");
                    resend_label.classList.remove("no-pointer-events");
                    resend_span.innerHTML = "Resend OTP";
                    setTimeout(function () {
                      input_value = "";
                      footer.style.display = "block";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                      footer.classList.remove("close");
                      if (shouldShowMenu) {
                        input.style.pointerEvents = "auto";
                        microphone.style.pointerEvents = "auto";
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = "auto";
                      }
                      input.focus();
                      body.removeChild(spinningDiv);
                      enter.style.pointerEvents = "auto";
                      var errorDiv = document.createElement("DIV");
                      current_logical_jump = question_array[0].logical_jump;
                      currentMailSequence = question_array[0].sequence;
                      currentQuestionIsLead = question_array[0].send_mail;
                      errorDiv.classList.add("question-div-smatest");
                      setTimeout(function () {
                        errorDiv.classList.add("top-0");
                      }, transition_time);
                      if (font && font.length > 0) {
                        errorDiv.classList.add(font);
                      }
                      var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                      error_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(error_icon);
                      iconDiv.classList.add("question-icon-div");
                      error_icon.classList.add("question-icon-smatest");
                      var error_text = document.createElement("LABEL");
                      var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                      if (matched && matched.length > 0) {
                        error_text.innerHTML = matched;
                        say(error_text.innerText);
                        if (
                          (main_lang_code &&
                            (main_lang_code == "he" ||
                              main_lang_code == "ur" ||
                              main_lang_code == "ar")) ||
                          (main_lang_code == "default" &&
                            (language_code == "ar" ||
                              language_code == "he" ||
                              language_code == "ur"))
                        ) {
                          error_text.classList.add("rtl");
                          error_text.style.textAlign = "right";
                        }
                      } else {
                        error_text.innerHTML = question_array[0].error_text;
                        say(error_text.innerText);
                      }
                      error_text.classList.add("question-text-error");
                      error_text.classList.add("options-div-smatest");
                      if (font && font.length > 0) {
                        error_text.classList.add(font);
                      }
                      errorDiv.appendChild(iconDiv);
                      errorDiv.appendChild(error_text);
                      body.appendChild(errorDiv);
                      playBotUserSound(1);
                      body.scrollTop = body.scrollHeight;
                    }, delay_time);
                  }
                } else if (this.readyState == 4 && this.status != 200) {
                  var response = JSON.parse(this.response);
                  resend_label.classList.remove("bg-lightgray");
                  resend_label.classList.remove("no-pointer-events");
                  resend_span.innerHTML = "Resend OTP";
                  setTimeout(function () {
                    input_value = "";
                    footer.style.display = "block";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.classList.remove("close");
                    if (shouldShowMenu) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                    }
                    input.focus();
                    body.removeChild(spinningDiv);
                    enter.style.pointerEvents = "auto";
                    var errorDiv = document.createElement("DIV");
                    current_logical_jump = question_array[0].logical_jump;
                    currentMailSequence = question_array[0].sequence;
                    currentQuestionIsLead = question_array[0].send_mail;
                    errorDiv.classList.add("question-div-smatest");
                    setTimeout(function () {
                      errorDiv.classList.add("top-0");
                    }, transition_time);
                    if (font && font.length > 0) {
                      errorDiv.classList.add(font);
                    }
                    var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                    error_icon.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(error_icon);
                    iconDiv.classList.add("question-icon-div");
                    error_icon.classList.add("question-icon-smatest");
                    var error_text = document.createElement("LABEL");
                    var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                    if (matched && matched.length > 0) {
                      error_text.innerHTML = matched;
                      say(error_text.innerText);
                      if (
                        (main_lang_code &&
                          (main_lang_code == "he" ||
                            main_lang_code == "ur" ||
                            main_lang_code == "ar")) ||
                        (main_lang_code == "default" &&
                          (language_code == "ar" ||
                            language_code == "he" ||
                            language_code == "ur"))
                      ) {
                        error_text.classList.add("rtl");
                        error_text.style.textAlign = "right";
                      }
                    } else {
                      error_text.innerHTML = question_array[0].error_text;
                      say(error_text.innerText);
                    }
                    error_text.classList.add("question-text-error");
                    error_text.classList.add("options-div-smatest");
                    if (font && font.length > 0) {
                      error_text.classList.add(font);
                    }
                    errorDiv.appendChild(iconDiv);
                    errorDiv.appendChild(error_text);
                    body.appendChild(errorDiv);
                    playBotUserSound(1);
                    body.scrollTop = body.scrollHeight;
                  }, delay_time);
                }
              };
              phoneXhttp.open(
                "POST",
                main_url + "/kya_backend/runtimeUtils/Emailvalidate",
                !0
              );
              phoneXhttp.setRequestHeader(
                "Content-type",
                "application/x-www-form-urlencoded"
              );
              phoneXhttp.send(
                "email=" +
                alredyThereEmail +
                "&chatbot_id=" +
                chatbot_id +
                "&cb_session=" +
                cb_session
              );
            });
            change_email_label.addEventListener("click", function (k) {
              current_question_type = "email";
              footer.style.display = "block";
              email_otp_validated = !0;
              input.placeholder = "Enter your email again";
              option_div.removeChild(resend_div);
              addTextDivToBot("Please enter the email again");
            });
            option_div.appendChild(resend_div);
            errorDiv.appendChild(iconDiv);
            errorDiv.appendChild(option_div);
            body.appendChild(errorDiv);
            playBotUserSound(1);
            body.scrollTop = body.scrollHeight;
            footer.style.display = "block";
            input.placeholder = "Enter the OTP";
            input.focus();
          }, 500);
        }

        function convertDateFormat(date, format) {
          const day = ("0" + date.getDate()).slice(-2);  // Two-digit day
          const numericMonth = ("0" + (date.getMonth() + 1)).slice(-2);  // Two-digit month
          const year = date.getFullYear();  // Full year
          const shortYear = year.toString().slice(-2);  // Last two digits of year
          const shortMonth = date.toLocaleString('default', { month: 'short' }).slice(0, 3); // Short month name

          // Define replacements for different format tokens
          const formats = {
            "dd": day,
            "mm": numericMonth,
            "yyyy": year,
            "yy": shortYear,
            "mmm": shortMonth
          };

          // Replace tokens in the format string with corresponding values
          return format.replace(/dd|mmm|mm|yyyy|yy/gi, matched => formats[matched]);
        }

        function inputEntered() {
          if (current_question_type == "live_agent") {
            var d = new Date();
            var date = d.getDate();
            if (date < 10) {
              date = "0" + date;
            }
            var month = d.getMonth() + 1;
            if (month < 10) {
              month = "0" + month;
            }
            var hours = d.getHours();
            if (hours < 10) {
              hours = "0" + hours;
            }
            var mins = d.getMinutes();
            if (mins < 10) {
              mins = "0" + mins;
            }
            var seconds = d.getSeconds();
            if (seconds < 10) {
              seconds = "0" + seconds;
            }
            d =
              date +
              "/" +
              month +
              "/" +
              d.getFullYear() +
              ", " +
              hours +
              ":" +
              mins +
              ":" +
              seconds;
            if (typingMessageSent) {
              sock.emit("usertypingstopped", {
                session_id: live_chat_cb_session,
                device_print: device_print,
                bot_id: chatbot_id,
                channel: "webiste",
                agent_id: agent_id,
              });
              typingMessageSent = false;
            }
            if (ip_is_banned && banned_reason && banned_reason.length > 0) {
              var livechatEncourageDiv = document.createElement("DIV");
              livechatEncourageDiv.id = "user-banned-div";
              livechatEncourageDiv.classList.add("question-div-smatest");
              setTimeout(function () {
                livechatEncourageDiv.classList.add("top-0");
              }, transition_time);
              if (font && font.length > 0) {
                livechatEncourageDiv.classList.add(font);
              }
              var live_chat_encourage_icon = document.createElement("IMG");
              live_chat_encourage_icon.src = avatar_icon;
              live_chat_encourage_icon.alt = "Logo of " + totalData[0].name;
              var iconDiv = document.createElement("DIV");
              iconDiv.appendChild(live_chat_encourage_icon);
              iconDiv.classList.add("question-icon-div");
              live_chat_encourage_icon.classList.add("question-icon-smatest");
              var live_chat_encourage_text = document.createElement("LABEL");
              live_chat_encourage_text.innerHTML =
                '<label style="float:left;width:100%;margin-bottom:">You have been banned from interacting with our live agents</label><label style="float:left;width:100%">Reason : ' +
                banned_reason +
                "</label>";
              say(live_chat_encourage_text.innerText);
              live_chat_encourage_text.classList.add("question-text-error");
              live_chat_encourage_text.classList.add("options-div-smatest");
              if (font && font.length > 0) {
                live_chat_encourage_text.classList.add(font);
              }
              livechatEncourageDiv.appendChild(iconDiv);
              livechatEncourageDiv.appendChild(live_chat_encourage_text);
              var checking_div = document.getElementById("user-banned-div");
              if (body.contains(checking_div)) {
              } else {
                body.appendChild(livechatEncourageDiv);
              }
              playBotUserSound(1);
              body.scrollTop = body.scrollHeight;
            } else {
              sock.emit("usersentmessage", {
                time: d,
                message: input.value,
                session_id: live_chat_cb_session,
                device_print: device_print,
                type: "user",
                bot_id: chatbot_id,
                name: "user",
                channel: "website",
                agent_id: agent_id,
              });
              seen_cleared = true;
              agent_message_timer = 0;
              var answerDiv = document.createElement("DIV");
              answerDiv.classList.add("answer-div");
              setTimeout(function () {
                answerDiv.classList.add("top-0");
              }, transition_time);
              var answer = document.createElement("LABEL");
              var str = urlify(input.value);
              // answer.innerHTML = str;
              const anchorTagPattern = /<a\s+[^>]*href=["'][^"']*["'][^>]*>/i;
              if (anchorTagPattern.test(str)) {
                answer.innerHTML = str;
              }else{
                answer.textContent = str;
              }

              answer.classList.add("answer-label");
              if (font && font.length > 0) {
                answer.classList.add(font);
              }
              answerDiv.appendChild(answer);
              body.appendChild(answerDiv);
              body.scrollTop = body.scrollHeight;
              input.type = "text";
              input.placeholder = "Talk to our agent";
              footer.style.display = "block";
              enter.style.pointerEvents = "auto";
              if (header.contains(company_title_description)) {
                body.style.height = "calc(100% - 226px)";
              } else {
                body.style.height = "calc(100% - 150px)";
              }
              footer.classList.remove("close");
              input.value = "";
            }
          } else {
            var input_value;
            if (current_question_type == "appointment") {
              input_value = input.defaultValue;
            } else {
              if (current_question_type == "location" && (chatbot_id == "18664" || chatbot_id == "19819")) {
                input_value = input.value.trim();
                input_value = input_value.replace("Blvd,", "Boulevard,");
              } else {
                input_value = input.value.trim();
              }
            }
            isSomethingGoingOn = !0;
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            input.value = "";
            atleastOneAnswered = !0;
            try {
              window.speechSynthesis.cancel();
            } catch (e) {
            } finally {
            }
            entered = !0;
            if (needPrivacy) {
              var inputText;
              if (input_value && input_value.length > 0) {
                if (needPrivacy == "phone") {
                  if (document.getElementById("selected_country")) {
                    selectedCode = document
                      .getElementById("selected_country")
                      .value.split("+")[1];
                  }
                  inputText = selectedCode + "-" + input_value;
                } else {
                  inputText = input_value;
                }
                if (inputText.toLowerCase() == privacyAnswer.toLowerCase()) {
                  input.id = "";
                  enter.style.pointerEvents = "auto";
                  needPrivacy = !1;
                  if (!shouldShowMenu) {
                    footer.style.display = "none";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                    footer.classList.add("close");
                  } else {
                    if (entry_id) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                      setPlaceHolders();
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    } else {
                      input.style.pointerEvents = "none";
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      input.blur();
                      enter.style.pointerEvents = "none";
                      input.placeholder = "Choose from Menu";
                      input.type = "text";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    }
                  }
                  input_value = "";
                  while (body.firstChild) {
                    body.removeChild(body.firstChild);
                  }
                  var selected_country =
                    document.getElementById("selected_country");
                  if (footer.contains(selected_country)) {
                    footer.removeChild(selected_country);
                  }
                  previousQuestionsView(prev_questions_array);
                  var last_prev_question =
                    prev_questions_array[prev_questions_array.length - 1];
                  var wait_for_init_question;
                  if (
                    last_prev_question.type == "order_items" &&
                    last_prev_question.answer_text == "items_added" &&
                    last_prev_question.items_list &&
                    last_prev_question.items_list.length > 0
                  ) {
                    wait_for_init_question = true;
                  } else if (
                    last_prev_question.type == "order_items" &&
                    last_prev_question.answer_text == "items_edited" &&
                    last_prev_question.items_list &&
                    last_prev_question.items_list.length > 0
                  ) {
                    wait_for_init_question = true;
                  } else {
                  }
                  body.scrollTop = body.scrollHeight;
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  if (wait_for_init_question) {
                    if (spinningDiv && spinningDiv.parentNode == body) {
                      body.removeChild(spinningDiv);
                    }
                    order_items_question = last_prev_question;
                    selected_orders = last_prev_question.items_list;
                    order_question_options = last_prev_question.default_options;
                    order_items = [];
                    for (
                      var t = 0;
                      t < last_prev_question.total_items_list.length;
                      t++
                    ) {
                      order_items.push(last_prev_question.total_items_list[t]);
                    }
                    if (last_prev_question.answer_text == "items_added") {
                      var question = last_prev_question;
                      question.type = "order_items_edit";
                      question.question_text =
                        '<label style="font-weight: 600 !important;text-align: center;margin-bottom: 10px;color:black !important;">Choose Quantity</label>';
                      question_completed = !1;
                      input_value = "";
                      question_array = [];
                      question_array.push(question);
                      enter.style.pointerEvents = "auto";
                      current_question_type = "order_items_edit";
                      order_question_id = last_prev_question.id;
                      current_logical_jump = last_prev_question.logical_jump;
                      currentMailSequence = last_prev_question.sequence;
                      currentQuestionIsLead = last_prev_question.send_mail;
                      question_id = last_prev_question.id;
                      setAllInputs(question_array);
                      assignAllQuestionTypes(current_question_type);
                      order_status_string = "items_edited";
                    } else if (last_prev_question.answer_text == "items_edited") {
                      var question = order_items_question;
                      question.type = "order_items_submit";
                      question.question_text =
                        '<label style="font-size: 16px !important;font-weight: 500 !important;text-align: center;margin-bottom: 10px;width:102%;">Order Details</label>';
                      question_completed = !1;
                      input_value = "";
                      question_array = [];
                      question_array.push(question);
                      enter.style.pointerEvents = "auto";
                      current_question_type = "order_items_submit";
                      current_logical_jump = question_array[0].logical_jump;
                      currentMailSequence = question_array[0].sequence;
                      currentQuestionIsLead = question_array[0].send_mail;
                      question_id = question_array[0].id;
                      setAllInputs(question_array);
                      assignAllQuestionTypes(current_question_type);
                      order_status_string = "order_items_submit";
                    }
                  } else {
                    if (question_array && question_array.length > 0) {
                      question_completed = !1;
                      setTimeout(function () {
                        if (spinningDiv && spinningDiv.parentNode == body) {
                          body.removeChild(spinningDiv);
                        }
                        current_question_type = question_array[0].type;
                        current_logical_jump = question_array[0].logical_jump;
                        currentMailSequence = question_array[0].sequence;
                        currentQuestionIsLead = question_array[0].send_mail;
                        question_id = question_array[0].id;
                        setAllInputs(question_array);
                        question_id = question_array[0].id;
                        assignAllQuestionTypes(current_question_type);
                      }, delay_time);
                    } else {
                      if (entry_id) {
                        current_question_type = "custom_entry";
                      } else {
                        if (!shouldShowMenu) {
                          footer.style.display = "none";
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 168px)";
                          } else {
                            body.style.height = "calc(100% - 93px)";
                          }
                          footer.classList.add("close");
                        } else {
                          if (entry_id) {
                            input.style.pointerEvents = "auto";
                            microphone.style.pointerEvents = "auto";
                            microphone.style.opacity = 1;
                            enter.style.pointerEvents = "auto";
                            setPlaceHolders();
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          } else {
                            input.style.pointerEvents = "none";
                            microphone.style.pointerEvents = "none";
                            microphone.style.opacity = 0;
                            input.blur();
                            enter.style.pointerEvents = "none";
                            input.placeholder = "Choose from Menu";
                            input.type = "text";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                          }
                        }
                      }
                      if (spinningDiv && spinningDiv.parentNode == body) {
                        body.removeChild(spinningDiv);
                      }
                    }
                  }
                } else {
                  var answerDiv = document.createElement("DIV");
                  answerDiv.classList.add("answer-div");
                  setTimeout(function () {
                    answerDiv.classList.add("top-0");
                  }, transition_time);
                  var answer = document.createElement("LABEL");
                  if (needPrivacy == "phone") {
                    var answer_text = document.createTextNode(
                      selectedCode + "-" + input_value
                    );
                  } else if (needPrivacy == "email") {
                    var answer_text = document.createTextNode(input_value);
                  }
                  answer.appendChild(answer_text);
                  answer.classList.add("answer-label");
                  if (font && font.length > 0) {
                    answer.classList.add(font);
                  }
                  answerDiv.appendChild(answer);
                  body.appendChild(answerDiv);
                  body.scrollTop = body.scrollHeight;
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  setTimeout(function () {
                    enter.style.pointerEvents = "auto";
                    if (spinningDiv && spinningDiv.parentNode == body) {
                      body.removeChild(spinningDiv);
                    }
                    var errorDiv = document.createElement("DIV");
                    errorDiv.classList.add("question-div-smatest");
                    setTimeout(function () {
                      errorDiv.classList.add("top-0");
                    }, transition_time);
                    if (font && font.length > 0) {
                      errorDiv.classList.add(font);
                    }
                    var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                    error_icon.src = avatar_icon;
                    var iconDiv = document.createElement("DIV");
                    iconDiv.appendChild(error_icon);
                    iconDiv.classList.add("question-icon-div");
                    error_icon.classList.add("question-icon-smatest");
                    var error_text = document.createElement("LABEL");
                    translateContent(translations, error_text, "Looks like you entered wrong data, Please try again", main_lang_code, language_code);
                    say(error_text.innerText);
                    error_text.classList.add("question-text-error");
                    error_text.classList.add("options-div-smatest");
                    if (font && font.length > 0) {
                      error_text.classList.add(font);
                    }
                    errorDiv.appendChild(iconDiv);
                    errorDiv.appendChild(error_text);
                    body.appendChild(errorDiv);
                    playBotUserSound(1);
                    body.scrollTop = body.scrollHeight;
                  }, 500);
                }
              }
            } else {
              var rightCode = !1;
              if (document.getElementById("selected_country")) {
                selectedCode = document
                  .getElementById("selected_country")
                  .value.split("+")[1];
              }
              var canOrdersProceed;
              if (current_question_type == "order_items") {
                if (selected_orders && selected_orders.length > 0) {
                  canOrdersProceed = true;
                }
              }
              if (current_question_type == "form") {
                if (input_value && input_value.length > 0) {
                } else {
                  if (form_value && form_value.length > 0) {
                    input_value = form_value;
                  }
                }
              }
              if ((input_value && input_value.length > 0) || canOrdersProceed) {
                if (input.placeholder && input.placeholder == "visit") {
                  var date = new Date(input_value).getDate();
                  var month = new Date(input_value).getMonth() + 1;
                  var year = new Date(input_value).getFullYear();
                  var actualDate = date + "-" + month + "-" + year;
                  var answerDiv = document.createElement("DIV");
                  answerDiv.classList.add("answer-div");
                  setTimeout(function () {
                    answerDiv.classList.add("top-0");
                  }, transition_time);
                  var answer = document.createElement("LABEL");
                  var answer_text = document.createTextNode(actualDate);
                  answer.appendChild(answer_text);
                  answer.classList.add("answer-label");
                  if (font && font.length > 0) {
                    answer.classList.add(font);
                  }
                  answerDiv.appendChild(answer);
                  body.appendChild(answerDiv);
                  body.scrollTop = body.scrollHeight;
                  if (prev_should_show) {
                    footer.style.display = "block";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                    footer.classList.remove("close");
                    if (shouldShowMenu) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                    }
                    input.focus();
                  } else {
                    if (!shouldShowMenu) {
                      footer.style.display = "none";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 168px)";
                      } else {
                        body.style.height = "calc(100% - 93px)";
                      }
                      footer.classList.add("close");
                    } else {
                      if (entry_id) {
                        input.style.pointerEvents = "auto";
                        microphone.style.pointerEvents = "auto";
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = "auto";
                        setPlaceHolders();
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                      } else {
                        input.style.pointerEvents = "none";
                        microphone.style.pointerEvents = "none";
                        microphone.style.opacity = 0;
                        input.blur();
                        enter.style.pointerEvents = "none";
                        input.placeholder = "Choose from Menu";
                        input.type = "text";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                      }
                    }
                  }
                  input.type = prev_input_type;
                  input.placeholder = prev_placeholder;
                  input.style.cssText = prev_style;
                  input.id = prev_id;
                  input_value = "";
                  prev_placeholder = "visit";
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  inTheMiddle = !0;
                  var xhttp = new XMLHttpRequest();
                  xhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      shouldDisableTakeAction = !1;
                      setTimeout(function () {
                        body.removeChild(spinningDiv);
                        var questionDIv = document.createElement("DIV");
                        questionDIv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          questionDIv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          questionDIv.classList.add(font);
                        }
                        var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                        ques_icon1.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon1);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon1.classList.add("question-icon-smatest");
                        var option_div = document.createElement("DIV");
                        option_div.classList.add("options-div-smatest");
                        var option_question = document.createElement("LABEL");
                        if (font && font.length > 0) {
                          option_question.classList.add(font);
                        }
                        if (
                          (main_lang_code &&
                            (main_lang_code == "he" ||
                              main_lang_code == "ur" ||
                              main_lang_code == "ar")) ||
                          (main_lang_code == "default" &&
                            (language_code == "ar" ||
                              language_code == "he" ||
                              language_code == "ur"))
                        ) {
                          option_question.classList.add("rtl");
                        }
                        option_question.innerHTML =
                          "Thanks, our team will confirm the booking over phone";
                        say(option_question.innerText);
                        enter.style.pointerEvents = "auto";
                        option_div.appendChild(option_question);
                        questionDIv.appendChild(iconDiv);
                        questionDIv.appendChild(option_div);
                        body.appendChild(questionDIv);
                        body.scrollTop = body.scrollHeight;
                      }, delay_time);
                    }
                  };
                  xhttp.open(
                    "POST",
                    main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                    !0
                  );
                  xhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  if (
                    main_lang_code &&
                    main_lang_code.length > 0 &&
                    main_lang_code != language_code
                  ) {
                  } else {
                    main_lang_code = "default";
                  }
                  if (take_action_id && take_action_sequence) {
                    xhttp.send(
                      "action=answer&answer_text=Booked : " +
                      actualDate +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      take_action_id +
                      "&is_logical=0" +
                      "&sequence=" +
                      take_action_sequence +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&is_help=1&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  } else if (custom_action_id && custom_action_sequence) {
                    xhttp.send(
                      "action=answer&answer_text=Booked : " +
                      actualDate +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      custom_action_id +
                      "&is_logical=0" +
                      "&sequence=" +
                      custom_action_sequence +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&is_help=1&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  }
                } else if (input.placeholder && input.placeholder == "Enter OTP") {
                  var answerDiv = document.createElement("DIV");
                  answerDiv.classList.add("answer-div");
                  setTimeout(function () {
                    answerDiv.classList.add("top-0");
                  }, transition_time);
                  var answer = document.createElement("LABEL");
                  var answer_text = document.createTextNode(input_value);
                  answer.appendChild(answer_text);

                   var resend_div = document.getElementById("resend-div");
                   if (resend_div) {
                    resend_div.remove()
                   }

                  answer.classList.add("answer-label");
                  if (font && font.length > 0) {
                    answer.classList.add(font);
                  }
                  answerDiv.appendChild(answer);
                  body.appendChild(answerDiv);
                  body.scrollTop = body.scrollHeight;
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  if (!shouldShowMenu) {
                    footer.style.display = "none";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                    footer.classList.add("close");
                  } else {
                    if (entry_id) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                      setPlaceHolders();
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    } else {
                      input.style.pointerEvents = "none";
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      input.blur();
                      enter.style.pointerEvents = "none";
                      input.placeholder = "Choose from Menu";
                      input.type = "text";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    }
                  }
                  var otpXhttp = new XMLHttpRequest();
                  otpXhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      var response = JSON.parse(this.response);
                      var otp_value = input_value;
                      var resend_div = document.getElementById("resend-div");
                      if (resend_div && resend_div.parentElement) {
                        resend_div.parentElement.removeChild(resend_div);
                      }
                      if (response && response.status) {
                        input.placeholder = "Type your query";
                        var xhttp = new XMLHttpRequest();
                        inTheMiddle = !0;
                        otp_verified = !0;
                        try {
                          var temp_div =
                            document.getElementById("resend-email-div");
                          if (temp_div && temp_div.parentElement) {
                            temp_div.parentElement.removeChild(temp_div);
                          }
                        } catch (error) { }
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          phoneValidated = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            body.removeChild(spinningDiv);
                            shouldDisableTakeAction = !1;
                            if (selectedCode && selectedCode.length > 0) {
                              question_and_answers.push({
                                id: question_id,
                                answer: selectedCode + "-" + input_value,
                              });
                            } else {
                              question_and_answers.push({
                                id: question_id,
                                answer: input_value,
                              });
                            }
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            body.scrollTop = body.scrollHeight;
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              if (
                                footer.firstChild &&
                                footer.firstChild.id == "selected_country"
                              ) {
                                footer.removeChild(footer.firstChild);
                              }
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          if (selectedCode && selectedCode.length > 0) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyTherePhoneProper) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&phone_otp=" +
                              otp_value
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyTherePhoneProper) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&phone_otp=" +
                              otp_value
                            );
                          }
                        } else {
                          if (selectedCode && selectedCode.length > 0) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyTherePhoneProper) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              encodeURIComponent(alredyTherePhoneProper) +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&phone_otp=" +
                              otp_value
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyTherePhoneProper) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              encodeURIComponent(alredyTherePhoneProper) +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&phone_otp=" +
                              otp_value
                            );
                          }
                        }
                      } else {
                        otp_entered = otp_entered + 1;
                        setTimeout(function () {
                          body.removeChild(spinningDiv);
                          var questionDIv = document.createElement("DIV");
                          if (currentMailSequence) {
                            questionDIv.id =
                              "radio-question-div-" + currentMailSequence;
                          } else {
                            questionDIv.id = "radio-question-div-" + 0;
                          }
                          questionDIv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            questionDIv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            questionDIv.classList.add(font);
                          }
                          var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(ques_icon1);
                          iconDiv.classList.add("question-icon-div");
                          ques_icon1.src = avatar_icon;
                          ques_icon1.classList.add("question-icon-smatest");
                          var option_div = document.createElement("DIV");
                          option_div.classList.add("options-div-smatest");
                          var option_question = document.createElement("LABEL");
                          if (font && font.length > 0) {
                            option_question.classList.add(font);
                          }
                          if (
                            (main_lang_code &&
                              (main_lang_code == "he" ||
                                main_lang_code == "ur" ||
                                main_lang_code == "ar")) ||
                            (main_lang_code == "default" &&
                              (language_code == "ar" ||
                                language_code == "he" ||
                                language_code == "ur"))
                          ) {
                            option_question.classList.add("rtl");
                          }
                          option_question.innerHTML =
                            "<div>" + response.message + "</div>";
                          say(option_question.innerText);
                          option_div.appendChild(option_question);
                          questionDIv.appendChild(iconDiv);
                          var resend_div = document.createElement("DIV");
                          resend_div.id = "resend-div";
                          resend_div.classList.add("file-input-div");
                          resend_div.classList.add("pull-left");
                          resend_div.classList.add("full-width");
                          resend_div.classList.add("text-center");
                          var resend_label = document.createElement("LABEL");
                          var resend_span = document.createElement("SPAN");
                          resend_span.innerHTML = "Resend OTP";
                          resend_span.classList.add("p-r-12");
                          resend_label.appendChild(resend_span);
                          resend_label.htmlFor = "capture-input";
                          resend_label.classList.add("upload-button-sb");
                          if (!agreed) {
                            resend_label.classList.add("no-pointer-events");
                          }
                          resend_label.addEventListener("click", function (k) {
                            var phoneXhttp = new XMLHttpRequest();
                            phoneXhttp.onreadystatechange = function () {
                              resend_span.innerHTML = "Resending OTP";
                              resend_label.classList.add("no-pointer-events");
                              resend_label.classList.add("bg-lightgray");
                              if (this.readyState == 4 && this.status == 200) {
                                var response = JSON.parse(this.response);
                                if (response && response.status) {
                                  resend_label.classList.remove("bg-lightgray");
                                  resend_label.classList.remove(
                                    "no-pointer-events"
                                  );
                                  resend_span.innerHTML = "Resend OTP";
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  footer.classList.remove("close");
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                  input_value = "";
                                } else {
                                  if (
                                    response.message &&
                                    response.message.includes(
                                      "Insufficient credits"
                                    )
                                  ) {
                                    var alredyTherePhoneProper =
                                      selectedCode + "-" + input_value;
                                    var xhttp = new XMLHttpRequest();
                                    inTheMiddle = !0;
                                    xhttp.onreadystatechange = function () {
                                      entered = !1;
                                      phoneValidated = !1;
                                      if (
                                        this.readyState == 4 &&
                                        this.status == 200
                                      ) {
                                        body.removeChild(spinningDiv);
                                        shouldDisableTakeAction = !1;
                                        if (
                                          selectedCode &&
                                          selectedCode.length > 0
                                        ) {
                                          question_and_answers.push({
                                            id: question_id,
                                            answer:
                                              selectedCode + "-" + input_value,
                                          });
                                        } else {
                                          question_and_answers.push({
                                            id: question_id,
                                            answer: input_value,
                                          });
                                        }
                                        if (
                                          currentQuestionIsLead == "1" &&
                                          !mailSent
                                        ) {
                                          sendAlertCall();
                                        } else {
                                          if (mailSequence < currentMailSequence) {
                                            random_key = !0;
                                          } else {
                                            random_key = !1;
                                          }
                                        }
                                        body.scrollTop = body.scrollHeight;
                                        cb_session = JSON.parse(
                                          this.response
                                        ).cb_session;
                                        live_chat_cb_session = JSON.parse(
                                          this.response
                                        ).livechat_session;
                                        if (
                                          JSON.parse(this.response).language_code &&
                                          JSON.parse(this.response).language_code
                                            .length > 0
                                        ) {
                                          main_lang_code = JSON.parse(
                                            this.response
                                          ).language_code;
                                        }
                                        session_feedback = JSON.parse(
                                          this.response
                                        ).feedback;
                                        question_array = JSON.parse(
                                          this.response
                                        ).next_question;
                                        if (
                                          question_array &&
                                          question_array.length > 0
                                        ) {
                                          question_completed = !1;
                                          input_value = "";
                                          if (
                                            footer.firstChild &&
                                            footer.firstChild.id ==
                                            "selected_country"
                                          ) {
                                            footer.removeChild(footer.firstChild);
                                          }
                                          setTimeout(function () {
                                            enter.style.pointerEvents = "auto";
                                            if (
                                              spinningDiv &&
                                              spinningDiv.parentNode == body
                                            ) {
                                              body.removeChild(spinningDiv);
                                            }
                                            current_question_type =
                                              question_array[0].type;
                                            current_logical_jump =
                                              question_array[0].logical_jump;
                                            currentMailSequence =
                                              question_array[0].sequence;
                                            currentQuestionIsLead =
                                              question_array[0].send_mail;
                                            question_id = question_array[0].id;
                                            setAllInputs(question_array);
                                            assignAllQuestionTypes(
                                              current_question_type
                                            );
                                          }, delay_time);
                                        } else {
                                          if (
                                            spinningDiv &&
                                            spinningDiv.parentNode == body
                                          ) {
                                            body.removeChild(spinningDiv);
                                          }
                                          enter.style.pointerEvents = "auto";
                                          question_completed = !0;
                                          if (!mailSent || mailSent) {
                                            var xhttp = new XMLHttpRequest();
                                            xhttp.onreadystatechange = function () {
                                              if (
                                                this.readyState == 4 &&
                                                this.status == 200
                                              ) {
                                                var questionArray = [];
                                                prev_questions_array = JSON.parse(
                                                  this.response
                                                ).qna_prev;
                                                if (
                                                  prev_questions_array &&
                                                  prev_questions_array.length > 0
                                                ) {
                                                  for (
                                                    var i = 0;
                                                    i < prev_questions_array.length;
                                                    i++
                                                  ) {
                                                    if (
                                                      prev_questions_array[i]
                                                        .type == "contact" ||
                                                      prev_questions_array[i]
                                                        .type == "slides" ||
                                                      prev_questions_array[i]
                                                        .type == "statement" ||
                                                      prev_questions_array[i]
                                                        .type ==
                                                      "url_auto_redirect" ||
                                                      prev_questions_array[i]
                                                        .type == "custom_answer" ||
                                                      prev_questions_array[i]
                                                        .type == "show_file" ||
                                                      prev_questions_array[i]
                                                        .type == "show_contacts" ||
                                                      prev_questions_array[i]
                                                        .type == "show_location"
                                                    ) {
                                                      prev_questions_array.splice(
                                                        i,
                                                        1
                                                      );
                                                      i--;
                                                    }
                                                  }
                                                  if (
                                                    zapier_webhook &&
                                                    zapier_webhook.length > 0
                                                  ) {
                                                    var output = {};
                                                    output.timestamp = new Date();
                                                    for (
                                                      var i = 0;
                                                      i <
                                                      prev_questions_array.length;
                                                      i++
                                                    ) {
                                                      var str =
                                                        prev_questions_array[i]
                                                          .question_text;
                                                      output[str] =
                                                        prev_questions_array[
                                                          i
                                                        ].answer_text;
                                                    }
                                                    var xhttp =
                                                      new XMLHttpRequest();
                                                    xhttp.onreadystatechange =
                                                      function () {
                                                        if (
                                                          this.readyState == 4 &&
                                                          this.status == 200
                                                        ) {
                                                        }
                                                      };
                                                    xhttp.open(
                                                      "POST",
                                                      zapier_webhook,
                                                      !0
                                                    );
                                                    xhttp.setRequestHeader(
                                                      "Content-type",
                                                      "application/x-www-form-urlencoded"
                                                    );
                                                    xhttp.send(
                                                      "output=" +
                                                      JSON.stringify(output)
                                                    );
                                                  }
                                                  for (
                                                    var i = 0;
                                                    i < prev_questions_array.length;
                                                    i++
                                                  ) {
                                                    questionArray.push({
                                                      question:
                                                        prev_questions_array[i]
                                                          .question_text,
                                                      answer:
                                                        prev_questions_array[i]
                                                          .answer_text,
                                                    });
                                                  }
                                                }
                                              }
                                            };
                                            xhttp.open(
                                              "POST",
                                              url +
                                              "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                              !0
                                            );
                                            xhttp.setRequestHeader(
                                              "Content-type",
                                              "application/x-www-form-urlencoded"
                                            );
                                            if (
                                              main_lang_code &&
                                              main_lang_code.length > 0 &&
                                              main_lang_code != language_code
                                            ) {
                                            } else {
                                              main_lang_code = "default";
                                            }
                                            var bot_widget_obj;
                                            var is_sendable;
                                            if (
                                              window.botWidget &&
                                              window.botWidget.user
                                            ) {
                                              var keys = Object.keys(
                                                window.botWidget.user
                                              );
                                              for (
                                                var t = 0;
                                                t < keys.length;
                                                t++
                                              ) {
                                                if (
                                                  window.botWidget.user[keys[t]] &&
                                                  window.botWidget.user[keys[t]]
                                                    .length > 0
                                                ) {
                                                  is_sendable = true;
                                                }
                                              }
                                              if (is_sendable) {
                                                bot_widget_obj =
                                                  window.botWidget.user;
                                              } else {
                                                bot_widget_obj = "";
                                              }
                                              if (window.botWidget.user.bot_id) {
                                                delete window.botWidget.user.bot_id;
                                              }
                                              if (window.botWidget.user.url) {
                                                delete window.botWidget.user.url;
                                              }
                                            }
                                            xhttp.send(
                                              "action=init_chat&device_print=" +
                                              device_print +
                                              "&chatbot_id=" +
                                              chatbot_id +
                                              "&language_code=" +
                                              main_lang_code +
                                              "&bot_widget_obj=" +
                                              JSON.stringify(bot_widget_obj)
                                            );
                                          } else {
                                            var xhttp = new XMLHttpRequest();
                                            xhttp.onreadystatechange = function () {
                                              if (
                                                this.readyState == 4 &&
                                                this.status == 200
                                              ) {
                                                var questionArray = [];
                                                prev_questions_array = JSON.parse(
                                                  this.response
                                                ).qna_prev;
                                                if (
                                                  prev_questions_array &&
                                                  prev_questions_array.length > 0
                                                ) {
                                                  for (
                                                    var i = 0;
                                                    i < prev_questions_array.length;
                                                    i++
                                                  ) {
                                                    if (
                                                      prev_questions_array[i]
                                                        .type == "contact" ||
                                                      prev_questions_array[i]
                                                        .type == "slides" ||
                                                      prev_questions_array[i]
                                                        .type == "statement" ||
                                                      prev_questions_array[i]
                                                        .type ==
                                                      "url_auto_redirect" ||
                                                      prev_questions_array[i]
                                                        .type == "custom_answer" ||
                                                      prev_questions_array[i]
                                                        .type == "show_file" ||
                                                      prev_questions_array[i]
                                                        .type == "show_contacts" ||
                                                      prev_questions_array[i]
                                                        .type == "show_location"
                                                    ) {
                                                      prev_questions_array.splice(
                                                        i,
                                                        1
                                                      );
                                                      i--;
                                                    }
                                                  }
                                                  for (
                                                    var i = 0;
                                                    i < prev_questions_array.length;
                                                    i++
                                                  ) {
                                                    questionArray.push({
                                                      question:
                                                        prev_questions_array[i]
                                                          .question_text,
                                                      answer:
                                                        prev_questions_array[i]
                                                          .answer_text,
                                                    });
                                                  }
                                                }
                                              }
                                            };
                                            xhttp.open(
                                              "POST",
                                              url +
                                              "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                              !0
                                            );
                                            xhttp.setRequestHeader(
                                              "Content-type",
                                              "application/x-www-form-urlencoded"
                                            );
                                            if (
                                              main_lang_code &&
                                              main_lang_code.length > 0 &&
                                              main_lang_code != language_code
                                            ) {
                                            } else {
                                              main_lang_code = "default";
                                            }
                                            var bot_widget_obj;
                                            var is_sendable;
                                            if (
                                              window.botWidget &&
                                              window.botWidget.user
                                            ) {
                                              var keys = Object.keys(
                                                window.botWidget.user
                                              );
                                              for (
                                                var t = 0;
                                                t < keys.length;
                                                t++
                                              ) {
                                                if (
                                                  window.botWidget.user[keys[t]] &&
                                                  window.botWidget.user[keys[t]]
                                                    .length > 0
                                                ) {
                                                  is_sendable = true;
                                                }
                                              }
                                              if (is_sendable) {
                                                bot_widget_obj =
                                                  window.botWidget.user;
                                              } else {
                                                bot_widget_obj = "";
                                              }
                                              if (window.botWidget.user.bot_id) {
                                                delete window.botWidget.user.bot_id;
                                              }
                                              if (window.botWidget.user.url) {
                                                delete window.botWidget.user.url;
                                              }
                                            }
                                            xhttp.send(
                                              "action=init_chat&device_print=" +
                                              device_print +
                                              "&chatbot_id=" +
                                              chatbot_id +
                                              "&language_code=" +
                                              main_lang_code +
                                              "&bot_widget_obj=" +
                                              JSON.stringify(bot_widget_obj)
                                            );
                                          }
                                          if (!entry_id) {
                                            showInput = !0;
                                            if (!shouldShowMenu) {
                                              footer.style.display = "none";
                                              footer.classList.add("close");
                                            } else {
                                              if (entry_id) {
                                                input.style.pointerEvents = "auto";
                                                microphone.style.pointerEvents =
                                                  "auto";
                                                microphone.style.opacity = 1;
                                                enter.style.pointerEvents = "auto";
                                                setPlaceHolders();
                                                if (
                                                  header.contains(
                                                    company_title_description
                                                  )
                                                ) {
                                                  body.style.height =
                                                    "calc(100% - 218px)";
                                                } else {
                                                  body.style.height =
                                                    "calc(100% - 143px)";
                                                }
                                              } else {
                                                input.blur();
                                                input.style.pointerEvents = "none";
                                                microphone.style.pointerEvents =
                                                  "none";
                                                microphone.style.opacity = 0;
                                                enter.style.pointerEvents = "none";
                                                input.placeholder =
                                                  "Choose from Menu";
                                              }
                                            }
                                          }
                                          if (!shouldShowMenu) {
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 168px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 93px)";
                                            }
                                          } else {
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 218px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 143px)";
                                            }
                                          }
                                        }
                                      }
                                    };
                                    xhttp.open(
                                      "POST",
                                      main_url +
                                      "/kya_backend/pagehub/chatbot_utils?action=answer",
                                      !0
                                    );
                                    xhttp.setRequestHeader(
                                      "Content-type",
                                      "application/x-www-form-urlencoded"
                                    );
                                    if (
                                      main_lang_code &&
                                      main_lang_code.length > 0 &&
                                      main_lang_code != language_code
                                    ) {
                                    } else {
                                      main_lang_code = "default";
                                    }
                                    if (
                                      current_logical_jump == "1" &&
                                      current_question_type != "radio" &&
                                      current_question_type != "rating"
                                    ) {
                                      if (selectedCode && selectedCode.length > 0) {
                                        xhttp.send(
                                          "action=answer&answer_text=" +
                                          encodeURIComponent(
                                            alredyTherePhoneProper
                                          ) +
                                          "&cb_session=" +
                                          cb_session +
                                          "&question_id=" +
                                          question_id +
                                          "&is_logical=" +
                                          current_logical_jump +
                                          "&sequence=" +
                                          currentMailSequence +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&option=" +
                                          "sometext&visitor_link_traversal=" +
                                          visitedUrls +
                                          "&language_code=" +
                                          main_lang_code
                                        );
                                      } else {
                                        xhttp.send(
                                          "action=answer&answer_text=" +
                                          encodeURIComponent(
                                            alredyTherePhoneProper
                                          ) +
                                          "&cb_session=" +
                                          cb_session +
                                          "&question_id=" +
                                          question_id +
                                          "&is_logical=" +
                                          current_logical_jump +
                                          "&sequence=" +
                                          currentMailSequence +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&option=" +
                                          "sometext&visitor_link_traversal=" +
                                          visitedUrls +
                                          "&language_code=" +
                                          main_lang_code
                                        );
                                      }
                                    } else {
                                      if (selectedCode && selectedCode.length > 0) {
                                        xhttp.send(
                                          "action=answer&answer_text=" +
                                          encodeURIComponent(
                                            alredyTherePhoneProper
                                          ) +
                                          "&cb_session=" +
                                          cb_session +
                                          "&question_id=" +
                                          question_id +
                                          "&is_logical=" +
                                          current_logical_jump +
                                          "&sequence=" +
                                          currentMailSequence +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&option=" +
                                          encodeURIComponent(
                                            alredyTherePhoneProper
                                          ) +
                                          "&visitor_link_traversal=" +
                                          visitedUrls +
                                          "&language_code=" +
                                          main_lang_code
                                        );
                                      } else {
                                        xhttp.send(
                                          "action=answer&answer_text=" +
                                          encodeURIComponent(
                                            alredyTherePhoneProper
                                          ) +
                                          "&cb_session=" +
                                          cb_session +
                                          "&question_id=" +
                                          question_id +
                                          "&is_logical=" +
                                          current_logical_jump +
                                          "&sequence=" +
                                          currentMailSequence +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&option=" +
                                          encodeURIComponent(
                                            alredyTherePhoneProper
                                          ) +
                                          "&visitor_link_traversal=" +
                                          visitedUrls +
                                          "&language_code=" +
                                          main_lang_code
                                        );
                                      }
                                    }
                                  } else {
                                    resend_label.classList.remove("bg-lightgray");
                                    resend_label.classList.remove(
                                      "no-pointer-events"
                                    );
                                    resend_span.innerHTML = "Resend OTP";
                                    setTimeout(function () {
                                      input_value = "";
                                      footer.style.display = "block";
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                      if (shouldShowMenu) {
                                        input.style.pointerEvents = "auto";
                                        microphone.style.pointerEvents = "auto";
                                        microphone.style.opacity = 1;
                                        enter.style.pointerEvents = "auto";
                                      }
                                      input.focus();
                                      footer.classList.remove("close");
                                      body.removeChild(spinningDiv);
                                      enter.style.pointerEvents = "auto";
                                      var errorDiv = document.createElement("DIV");
                                      current_logical_jump =
                                        question_array[0].logical_jump;
                                      currentMailSequence =
                                        question_array[0].sequence;
                                      currentQuestionIsLead =
                                        question_array[0].send_mail;
                                      errorDiv.classList.add(
                                        "question-div-smatest"
                                      );
                                      setTimeout(function () {
                                        errorDiv.classList.add("top-0");
                                      }, transition_time);
                                      if (font && font.length > 0) {
                                        errorDiv.classList.add(font);
                                      }
                                      var error_icon =
                                        document.createElement("IMG");
                                      error_icon.src = avatar_icon;
                                      error_icon.alt = "Logo of " + totalData[0].name;
                                      var iconDiv = document.createElement("DIV");
                                      iconDiv.appendChild(error_icon);
                                      iconDiv.classList.add("question-icon-div");
                                      error_icon.classList.add(
                                        "question-icon-smatest"
                                      );
                                      var error_text =
                                        document.createElement("LABEL");
                                      var matched;
                                      if (translations && translations.length > 0) {
                                        for (
                                          var i = 0;
                                          i < translations.length;
                                          i++
                                        ) {
                                          if (
                                            translations[i].keyword ==
                                            "Please enter a valid Phone Number"
                                          ) {
                                            matched = translations[i].translation;
                                          }
                                        }
                                      }
                                      if (matched && matched.length > 0) {
                                        error_text.innerHTML = matched;
                                        say(error_text.innerText);
                                        if (
                                          (main_lang_code &&
                                            (main_lang_code == "he" ||
                                              main_lang_code == "ur" ||
                                              main_lang_code == "ar")) ||
                                          (main_lang_code == "default" &&
                                            (language_code == "ar" ||
                                              language_code == "he" ||
                                              language_code == "ur"))
                                        ) {
                                          error_text.classList.add("rtl");
                                          error_text.style.textAlign = "right";
                                        }
                                      } else {
                                        error_text.innerHTML =
                                          question_array[0].error_text;
                                        say(error_text.innerText);
                                      }
                                      error_text.classList.add(
                                        "question-text-error"
                                      );
                                      error_text.classList.add(
                                        "options-div-smatest"
                                      );
                                      if (font && font.length > 0) {
                                        error_text.classList.add(font);
                                      }
                                      errorDiv.appendChild(iconDiv);
                                      errorDiv.appendChild(error_text);
                                      body.appendChild(errorDiv);
                                      playBotUserSound(1);
                                      body.scrollTop = body.scrollHeight;
                                    }, delay_time);
                                  }
                                }
                              } else if (
                                this.readyState == 4 &&
                                this.status != 200
                              ) {
                                var response = JSON.parse(this.response);
                                if (
                                  response.message &&
                                  response.message.includes("Insufficient credits")
                                ) {
                                  var alredyTherePhoneProper =
                                    selectedCode + "-" + input_value;
                                  var xhttp = new XMLHttpRequest();
                                  inTheMiddle = !0;
                                  xhttp.onreadystatechange = function () {
                                    entered = !1;
                                    phoneValidated = !1;
                                    if (
                                      this.readyState == 4 &&
                                      this.status == 200
                                    ) {
                                      body.removeChild(spinningDiv);
                                      shouldDisableTakeAction = !1;
                                      if (selectedCode && selectedCode.length > 0) {
                                        question_and_answers.push({
                                          id: question_id,
                                          answer: selectedCode + "-" + input_value,
                                        });
                                      } else {
                                        question_and_answers.push({
                                          id: question_id,
                                          answer: input_value,
                                        });
                                      }
                                      if (
                                        currentQuestionIsLead == "1" &&
                                        !mailSent
                                      ) {
                                        sendAlertCall();
                                      } else {
                                        if (mailSequence < currentMailSequence) {
                                          random_key = !0;
                                        } else {
                                          random_key = !1;
                                        }
                                      }
                                      body.scrollTop = body.scrollHeight;
                                      cb_session = JSON.parse(
                                        this.response
                                      ).cb_session;
                                      live_chat_cb_session = JSON.parse(
                                        this.response
                                      ).livechat_session;
                                      if (
                                        JSON.parse(this.response).language_code &&
                                        JSON.parse(this.response).language_code
                                          .length > 0
                                      ) {
                                        main_lang_code = JSON.parse(
                                          this.response
                                        ).language_code;
                                      }
                                      session_feedback = JSON.parse(
                                        this.response
                                      ).feedback;
                                      question_array = JSON.parse(
                                        this.response
                                      ).next_question;
                                      if (
                                        question_array &&
                                        question_array.length > 0
                                      ) {
                                        question_completed = !1;
                                        input_value = "";
                                        if (
                                          footer.firstChild &&
                                          footer.firstChild.id == "selected_country"
                                        ) {
                                          footer.removeChild(footer.firstChild);
                                        }
                                        setTimeout(function () {
                                          enter.style.pointerEvents = "auto";
                                          if (
                                            spinningDiv &&
                                            spinningDiv.parentNode == body
                                          ) {
                                            body.removeChild(spinningDiv);
                                          }
                                          current_question_type =
                                            question_array[0].type;
                                          current_logical_jump =
                                            question_array[0].logical_jump;
                                          currentMailSequence =
                                            question_array[0].sequence;
                                          currentQuestionIsLead =
                                            question_array[0].send_mail;
                                          question_id = question_array[0].id;
                                          setAllInputs(question_array);
                                          assignAllQuestionTypes(
                                            current_question_type
                                          );
                                        }, delay_time);
                                      } else {
                                        if (
                                          spinningDiv &&
                                          spinningDiv.parentNode == body
                                        ) {
                                          body.removeChild(spinningDiv);
                                        }
                                        enter.style.pointerEvents = "auto";
                                        question_completed = !0;
                                        if (!mailSent || mailSent) {
                                          var xhttp = new XMLHttpRequest();
                                          xhttp.onreadystatechange = function () {
                                            if (
                                              this.readyState == 4 &&
                                              this.status == 200
                                            ) {
                                              var questionArray = [];
                                              prev_questions_array = JSON.parse(
                                                this.response
                                              ).qna_prev;
                                              if (
                                                prev_questions_array &&
                                                prev_questions_array.length > 0
                                              ) {
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  if (
                                                    prev_questions_array[i].type ==
                                                    "contact" ||
                                                    prev_questions_array[i].type ==
                                                    "slides" ||
                                                    prev_questions_array[i].type ==
                                                    "statement" ||
                                                    prev_questions_array[i].type ==
                                                    "url_auto_redirect" ||
                                                    prev_questions_array[i].type ==
                                                    "custom_answer" ||
                                                    prev_questions_array[i].type ==
                                                    "show_file" ||
                                                    prev_questions_array[i].type ==
                                                    "show_contacts" ||
                                                    prev_questions_array[i].type ==
                                                    "show_location"
                                                  ) {
                                                    prev_questions_array.splice(
                                                      i,
                                                      1
                                                    );
                                                    i--;
                                                  }
                                                }
                                                if (
                                                  zapier_webhook &&
                                                  zapier_webhook.length > 0
                                                ) {
                                                  var output = {};
                                                  output.timestamp = new Date();
                                                  for (
                                                    var i = 0;
                                                    i < prev_questions_array.length;
                                                    i++
                                                  ) {
                                                    var str =
                                                      prev_questions_array[i]
                                                        .question_text;
                                                    output[str] =
                                                      prev_questions_array[
                                                        i
                                                      ].answer_text;
                                                  }
                                                  var xhttp = new XMLHttpRequest();
                                                  xhttp.onreadystatechange =
                                                    function () {
                                                      if (
                                                        this.readyState == 4 &&
                                                        this.status == 200
                                                      ) {
                                                      }
                                                    };
                                                  xhttp.open(
                                                    "POST",
                                                    zapier_webhook,
                                                    !0
                                                  );
                                                  xhttp.setRequestHeader(
                                                    "Content-type",
                                                    "application/x-www-form-urlencoded"
                                                  );
                                                  xhttp.send(
                                                    "output=" +
                                                    JSON.stringify(output)
                                                  );
                                                }
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  questionArray.push({
                                                    question:
                                                      prev_questions_array[i]
                                                        .question_text,
                                                    answer:
                                                      prev_questions_array[i]
                                                        .answer_text,
                                                  });
                                                }
                                              }
                                            }
                                          };
                                          xhttp.open(
                                            "POST",
                                            url +
                                            "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                            !0
                                          );
                                          xhttp.setRequestHeader(
                                            "Content-type",
                                            "application/x-www-form-urlencoded"
                                          );
                                          if (
                                            main_lang_code &&
                                            main_lang_code.length > 0 &&
                                            main_lang_code != language_code
                                          ) {
                                          } else {
                                            main_lang_code = "default";
                                          }
                                          var bot_widget_obj;
                                          var is_sendable;
                                          if (
                                            window.botWidget &&
                                            window.botWidget.user
                                          ) {
                                            var keys = Object.keys(
                                              window.botWidget.user
                                            );
                                            for (var t = 0; t < keys.length; t++) {
                                              if (
                                                window.botWidget.user[keys[t]] &&
                                                window.botWidget.user[keys[t]]
                                                  .length > 0
                                              ) {
                                                is_sendable = true;
                                              }
                                            }
                                            if (is_sendable) {
                                              bot_widget_obj =
                                                window.botWidget.user;
                                            } else {
                                              bot_widget_obj = "";
                                            }
                                            if (window.botWidget.user.bot_id) {
                                              delete window.botWidget.user.bot_id;
                                            }
                                            if (window.botWidget.user.url) {
                                              delete window.botWidget.user.url;
                                            }
                                          }
                                          xhttp.send(
                                            "action=init_chat&device_print=" +
                                            device_print +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&language_code=" +
                                            main_lang_code +
                                            "&bot_widget_obj=" +
                                            JSON.stringify(bot_widget_obj)
                                          );
                                        } else {
                                          var xhttp = new XMLHttpRequest();
                                          xhttp.onreadystatechange = function () {
                                            if (
                                              this.readyState == 4 &&
                                              this.status == 200
                                            ) {
                                              var questionArray = [];
                                              prev_questions_array = JSON.parse(
                                                this.response
                                              ).qna_prev;
                                              if (
                                                prev_questions_array &&
                                                prev_questions_array.length > 0
                                              ) {
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  if (
                                                    prev_questions_array[i].type ==
                                                    "contact" ||
                                                    prev_questions_array[i].type ==
                                                    "slides" ||
                                                    prev_questions_array[i].type ==
                                                    "statement" ||
                                                    prev_questions_array[i].type ==
                                                    "url_auto_redirect" ||
                                                    prev_questions_array[i].type ==
                                                    "custom_answer" ||
                                                    prev_questions_array[i].type ==
                                                    "show_file" ||
                                                    prev_questions_array[i].type ==
                                                    "show_contacts" ||
                                                    prev_questions_array[i].type ==
                                                    "show_location"
                                                  ) {
                                                    prev_questions_array.splice(
                                                      i,
                                                      1
                                                    );
                                                    i--;
                                                  }
                                                }
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  questionArray.push({
                                                    question:
                                                      prev_questions_array[i]
                                                        .question_text,
                                                    answer:
                                                      prev_questions_array[i]
                                                        .answer_text,
                                                  });
                                                }
                                              }
                                            }
                                          };
                                          xhttp.open(
                                            "POST",
                                            url +
                                            "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                            !0
                                          );
                                          xhttp.setRequestHeader(
                                            "Content-type",
                                            "application/x-www-form-urlencoded"
                                          );
                                          if (
                                            main_lang_code &&
                                            main_lang_code.length > 0 &&
                                            main_lang_code != language_code
                                          ) {
                                          } else {
                                            main_lang_code = "default";
                                          }
                                          var bot_widget_obj;
                                          var is_sendable;
                                          if (
                                            window.botWidget &&
                                            window.botWidget.user
                                          ) {
                                            var keys = Object.keys(
                                              window.botWidget.user
                                            );
                                            for (var t = 0; t < keys.length; t++) {
                                              if (
                                                window.botWidget.user[keys[t]] &&
                                                window.botWidget.user[keys[t]]
                                                  .length > 0
                                              ) {
                                                is_sendable = true;
                                              }
                                            }
                                            if (is_sendable) {
                                              bot_widget_obj =
                                                window.botWidget.user;
                                            } else {
                                              bot_widget_obj = "";
                                            }
                                            if (window.botWidget.user.bot_id) {
                                              delete window.botWidget.user.bot_id;
                                            }
                                            if (window.botWidget.user.url) {
                                              delete window.botWidget.user.url;
                                            }
                                          }
                                          xhttp.send(
                                            "action=init_chat&device_print=" +
                                            device_print +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&language_code=" +
                                            main_lang_code +
                                            "&bot_widget_obj=" +
                                            JSON.stringify(bot_widget_obj)
                                          );
                                        }
                                        if (!entry_id) {
                                          showInput = !0;
                                          if (!shouldShowMenu) {
                                            footer.style.display = "none";
                                            footer.classList.add("close");
                                          } else {
                                            if (entry_id) {
                                              input.style.pointerEvents = "auto";
                                              microphone.style.pointerEvents =
                                                "auto";
                                              microphone.style.opacity = 1;
                                              enter.style.pointerEvents = "auto";
                                              setPlaceHolders();
                                              if (
                                                header.contains(
                                                  company_title_description
                                                )
                                              ) {
                                                body.style.height =
                                                  "calc(100% - 218px)";
                                              } else {
                                                body.style.height =
                                                  "calc(100% - 143px)";
                                              }
                                            } else {
                                              input.blur();
                                              input.style.pointerEvents = "none";
                                              microphone.style.pointerEvents =
                                                "none";
                                              microphone.style.opacity = 0;
                                              enter.style.pointerEvents = "none";
                                              input.placeholder =
                                                "Choose from Menu";
                                            }
                                          }
                                        }
                                        if (!shouldShowMenu) {
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 168px)";
                                          } else {
                                            body.style.height = "calc(100% - 93px)";
                                          }
                                        } else {
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                        }
                                      }
                                    }
                                  };
                                  xhttp.open(
                                    "POST",
                                    main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                    !0
                                  );
                                  xhttp.setRequestHeader(
                                    "Content-type",
                                    "application/x-www-form-urlencoded"
                                  );
                                  if (
                                    main_lang_code &&
                                    main_lang_code.length > 0 &&
                                    main_lang_code != language_code
                                  ) {
                                  } else {
                                    main_lang_code = "default";
                                  }
                                  if (
                                    current_logical_jump == "1" &&
                                    current_question_type != "radio" &&
                                    current_question_type != "rating"
                                  ) {
                                    if (selectedCode && selectedCode.length > 0) {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        "sometext&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    } else {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        "sometext&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    }
                                  } else {
                                    if (selectedCode && selectedCode.length > 0) {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    } else {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    }
                                  }
                                } else {
                                  resend_label.classList.remove("bg-lightgray");
                                  resend_label.classList.remove(
                                    "no-pointer-events"
                                  );
                                  resend_span.innerHTML = "Resend OTP";
                                  setTimeout(function () {
                                    input_value = "";
                                    footer.style.display = "block";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                    if (shouldShowMenu) {
                                      input.style.pointerEvents = "auto";
                                      microphone.style.pointerEvents = "auto";
                                      microphone.style.opacity = 1;
                                      enter.style.pointerEvents = "auto";
                                    }
                                    input.focus();
                                    footer.classList.remove("close");
                                    body.removeChild(spinningDiv);
                                    enter.style.pointerEvents = "auto";
                                    var errorDiv = document.createElement("DIV");
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    errorDiv.classList.add("question-div-smatest");
                                    setTimeout(function () {
                                      errorDiv.classList.add("top-0");
                                    }, transition_time);
                                    if (font && font.length > 0) {
                                      errorDiv.classList.add(font);
                                    }
                                    var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                    error_icon.src = avatar_icon;
                                    var iconDiv = document.createElement("DIV");
                                    iconDiv.appendChild(error_icon);
                                    iconDiv.classList.add("question-icon-div");
                                    error_icon.classList.add(
                                      "question-icon-smatest"
                                    );
                                    var error_text =
                                      document.createElement("LABEL");
                                    var matched;
                                    if (translations && translations.length > 0) {
                                      for (
                                        var i = 0;
                                        i < translations.length;
                                        i++
                                      ) {
                                        if (
                                          translations[i].keyword ==
                                          "Please enter a valid Phone Number"
                                        ) {
                                          matched = translations[i].translation;
                                        }
                                      }
                                    }
                                    if (matched && matched.length > 0) {
                                      error_text.innerHTML = matched;
                                      say(error_text.innerText);
                                      if (
                                        (main_lang_code &&
                                          (main_lang_code == "he" ||
                                            main_lang_code == "ur" ||
                                            main_lang_code == "ar")) ||
                                        (main_lang_code == "default" &&
                                          (language_code == "ar" ||
                                            language_code == "he" ||
                                            language_code == "ur"))
                                      ) {
                                        error_text.classList.add("rtl");
                                        error_text.style.textAlign = "right";
                                      }
                                    } else {
                                      error_text.innerHTML =
                                        question_array[0].error_text;
                                      say(error_text.innerText);
                                    }
                                    error_text.classList.add("question-text-error");
                                    error_text.classList.add("options-div-smatest");
                                    if (font && font.length > 0) {
                                      error_text.classList.add(font);
                                    }
                                    errorDiv.appendChild(iconDiv);
                                    errorDiv.appendChild(error_text);
                                    body.appendChild(errorDiv);
                                    playBotUserSound(1);
                                    body.scrollTop = body.scrollHeight;
                                  }, delay_time);
                                }
                              }
                            };
                            phoneXhttp.open(
                              "POST",
                              main_url + "/kya_backend/runtimeUtils/phonevalidate",
                              !0
                            );
                            phoneXhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            phoneXhttp.send(
                              "phone=" +
                              alredyTherePhone +
                              "&chatbot_name=" +
                              encodeURIComponent(totalData[0].name) +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id
                            );
                          });
                          var skip_div = document.createElement("DIV");
                          skip_div.classList.add("file-input-div");
                          skip_div.classList.add("pull-left");
                          skip_div.classList.add("full-width");
                          skip_div.classList.add("text-center");
                          var skip_btn = document.createElement("LABEL");
                          skip_btn.innerHTML = "Skip Validation";
                          skip_btn.classList.add("pull-left");
                          skip_btn.classList.add("full-width");
                          skip_btn.classList.add("m-t-5");
                          skip_btn.classList.add("text-underline");
                          skip_btn.classList.add("skip-text");
                          skip_btn.classList.add("other-pointer");
                          skip_div.appendChild(skip_btn);
                          var otp_sent = 0;
                          skip_btn.addEventListener("click", function (k) {
                            var answerDiv = document.createElement("DIV");
                            answerDiv.classList.add("answer-div");
                            setTimeout(function () {
                              answerDiv.classList.add("top-0");
                            }, transition_time);
                            var answer = document.createElement("LABEL");
                            var answer_text = document.createTextNode(
                              alredyTherePhoneProper
                            );
                            answer.appendChild(answer_text);
                            answer.classList.add("answer-label");
                            if (font && font.length > 0) {
                              answer.classList.add(font);
                            }
                            answerDiv.appendChild(answer);
                            body.appendChild(answerDiv);
                            body.scrollTop = body.scrollHeight;
                            if (prev_should_show) {
                              footer.style.display = "block";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                              footer.classList.remove("close");
                              if (shouldShowMenu) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                              }
                              input.focus();
                            } else {
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  input.blur();
                                  enter.style.pointerEvents = "none";
                                  input.placeholder = "Choose from Menu";
                                  input.type = "text";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                }
                              }
                            }
                            var spinningDiv = document.createElement("DIV");
                            spinningDiv.classList.add("question-div-smatest");
                            spinningDiv.classList.add("top-0");
                            if (font && font.length > 0) {
                              spinningDiv.classList.add(font);
                            }
                            var spinnerDiv = document.createElement("DIV");
                            spinnerDiv.classList.add("spinner1-smatest");
                            var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                            ques_icon.src = avatar_icon;
                            var iconDiv = document.createElement("DIV");
                            iconDiv.appendChild(ques_icon);
                            iconDiv.classList.add("question-icon-div");
                            ques_icon.classList.add("question-icon-smatest");
                            var inner1 = document.createElement("DIV");
                            inner1.classList.add("bounce1");
                            var inner2 = document.createElement("DIV");
                            inner2.classList.add("bounce2");
                            var inner3 = document.createElement("DIV");
                            inner3.classList.add("bounce3");
                            spinnerDiv.appendChild(inner1);
                            spinnerDiv.appendChild(inner2);
                            spinnerDiv.appendChild(inner3);
                            spinningDiv.appendChild(iconDiv);
                            spinningDiv.appendChild(spinnerDiv);
                            body.appendChild(spinningDiv);
                            body.scrollTop = body.scrollHeight;
                            var xhttp = new XMLHttpRequest();
                            inTheMiddle = !0;
                            xhttp.onreadystatechange = function () {
                              entered = !1;
                              phoneValidated = !1;
                              if (this.readyState == 4 && this.status == 200) {
                                resend_div.removeChild(resend_label);
                                if (skip_otp_validation) {
                                  resend_div.removeChild(skip_div);
                                }
                                body.removeChild(spinningDiv);
                                shouldDisableTakeAction = !1;
                                if (selectedCode && selectedCode.length > 0) {
                                  question_and_answers.push({
                                    id: question_id,
                                    answer: selectedCode + "-" + input_value,
                                  });
                                } else {
                                  question_and_answers.push({
                                    id: question_id,
                                    answer: input_value,
                                  });
                                }
                                if (currentQuestionIsLead == "1" && !mailSent) {
                                  sendAlertCall();
                                } else {
                                  if (mailSequence < currentMailSequence) {
                                    random_key = !0;
                                  } else {
                                    random_key = !1;
                                  }
                                }
                                body.scrollTop = body.scrollHeight;
                                cb_session = JSON.parse(this.response).cb_session;
                                live_chat_cb_session = JSON.parse(
                                  this.response
                                ).livechat_session;
                                if (
                                  JSON.parse(this.response).language_code &&
                                  JSON.parse(this.response).language_code.length >
                                  0 &&
                                  JSON.parse(this.response).language_code !=
                                  "default"
                                ) {
                                  main_lang_code = JSON.parse(
                                    this.response
                                  ).language_code;
                                }
                                session_feedback = JSON.parse(
                                  this.response
                                ).feedback;
                                question_array = JSON.parse(
                                  this.response
                                ).next_question;
                                if (question_array && question_array.length > 0) {
                                  question_completed = !1;
                                  input_value = "";
                                  if (
                                    footer.firstChild &&
                                    footer.firstChild.id == "selected_country"
                                  ) {
                                    footer.removeChild(footer.firstChild);
                                  }
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(current_question_type);
                                  }, delay_time);
                                } else {
                                  if (
                                    spinningDiv &&
                                    spinningDiv.parentNode == body
                                  ) {
                                    body.removeChild(spinningDiv);
                                  }
                                  enter.style.pointerEvents = "auto";
                                  question_completed = !0;
                                  if (!mailSent || mailSent) {
                                    var xhttp = new XMLHttpRequest();
                                    xhttp.onreadystatechange = function () {
                                      if (
                                        this.readyState == 4 &&
                                        this.status == 200
                                      ) {
                                        var questionArray = [];
                                        prev_questions_array = JSON.parse(
                                          this.response
                                        ).qna_prev;
                                        if (
                                          prev_questions_array &&
                                          prev_questions_array.length > 0
                                        ) {
                                          for (
                                            var i = 0;
                                            i < prev_questions_array.length;
                                            i++
                                          ) {
                                            if (
                                              prev_questions_array[i].type ==
                                              "contact" ||
                                              prev_questions_array[i].type ==
                                              "slides" ||
                                              prev_questions_array[i].type ==
                                              "statement" ||
                                              prev_questions_array[i].type ==
                                              "url_auto_redirect" ||
                                              prev_questions_array[i].type ==
                                              "custom_answer" ||
                                              prev_questions_array[i].type ==
                                              "show_file" ||
                                              prev_questions_array[i].type ==
                                              "show_contacts" ||
                                              prev_questions_array[i].type ==
                                              "show_location"
                                            ) {
                                              prev_questions_array.splice(i, 1);
                                              i--;
                                            }
                                          }
                                          if (
                                            zapier_webhook &&
                                            zapier_webhook.length > 0
                                          ) {
                                            var output = {};
                                            output.timestamp = new Date();
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              var str =
                                                prev_questions_array[i]
                                                  .question_text;
                                              output[str] =
                                                prev_questions_array[i].answer_text;
                                            }
                                            var xhttp = new XMLHttpRequest();
                                            xhttp.onreadystatechange = function () {
                                              if (
                                                this.readyState == 4 &&
                                                this.status == 200
                                              ) {
                                              }
                                            };
                                            xhttp.open("POST", zapier_webhook, !0);
                                            xhttp.setRequestHeader(
                                              "Content-type",
                                              "application/x-www-form-urlencoded"
                                            );
                                            xhttp.send(
                                              "output=" + JSON.stringify(output)
                                            );
                                          }
                                          for (
                                            var i = 0;
                                            i < prev_questions_array.length;
                                            i++
                                          ) {
                                            questionArray.push({
                                              question:
                                                prev_questions_array[i]
                                                  .question_text,
                                              answer:
                                                prev_questions_array[i].answer_text,
                                            });
                                          }
                                        }
                                      }
                                    };
                                    xhttp.open(
                                      "POST",
                                      main_url +
                                      "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                      !0
                                    );
                                    xhttp.setRequestHeader(
                                      "Content-type",
                                      "application/x-www-form-urlencoded"
                                    );
                                    if (
                                      main_lang_code &&
                                      main_lang_code.length > 0 &&
                                      main_lang_code != language_code
                                    ) {
                                    } else {
                                      main_lang_code = "default";
                                    }
                                    var bot_widget_obj;
                                    var is_sendable;
                                    try {
                                      checkSaveMAxUserLogin();
                                      checkRateGainDetails();
                                    } catch (error) { }
                                    if (window.botWidget && window.botWidget.user) {
                                      var keys = Object.keys(window.botWidget.user);
                                      for (var t = 0; t < keys.length; t++) {
                                        if (
                                          window.botWidget.user[keys[t]] &&
                                          window.botWidget.user[keys[t]].length > 0
                                        ) {
                                          is_sendable = true;
                                        }
                                      }
                                      if (is_sendable) {
                                        bot_widget_obj = window.botWidget.user;
                                      } else {
                                        bot_widget_obj = "";
                                      }
                                      if (window.botWidget.user.bot_id) {
                                        delete window.botWidget.user.bot_id;
                                      }
                                      if (window.botWidget.user.url) {
                                        delete window.botWidget.user.url;
                                      }
                                    }
                                    xhttp.send(
                                      "action=init_chat&device_print=" +
                                      device_print +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&language_code=" +
                                      main_lang_code +
                                      "&bot_widget_obj=" +
                                      JSON.stringify(bot_widget_obj)
                                    );
                                  } else {
                                    var xhttp = new XMLHttpRequest();
                                    xhttp.onreadystatechange = function () {
                                      if (
                                        this.readyState == 4 &&
                                        this.status == 200
                                      ) {
                                        var questionArray = [];
                                        prev_questions_array = JSON.parse(
                                          this.response
                                        ).qna_prev;
                                        if (
                                          prev_questions_array &&
                                          prev_questions_array.length > 0
                                        ) {
                                          for (
                                            var i = 0;
                                            i < prev_questions_array.length;
                                            i++
                                          ) {
                                            if (
                                              prev_questions_array[i].type ==
                                              "contact" ||
                                              prev_questions_array[i].type ==
                                              "slides" ||
                                              prev_questions_array[i].type ==
                                              "statement" ||
                                              prev_questions_array[i].type ==
                                              "url_auto_redirect" ||
                                              prev_questions_array[i].type ==
                                              "custom_answer" ||
                                              prev_questions_array[i].type ==
                                              "show_file" ||
                                              prev_questions_array[i].type ==
                                              "show_contacts" ||
                                              prev_questions_array[i].type ==
                                              "show_location"
                                            ) {
                                              prev_questions_array.splice(i, 1);
                                              i--;
                                            }
                                          }
                                          for (
                                            var i = 0;
                                            i < prev_questions_array.length;
                                            i++
                                          ) {
                                            questionArray.push({
                                              question:
                                                prev_questions_array[i]
                                                  .question_text,
                                              answer:
                                                prev_questions_array[i].answer_text,
                                            });
                                          }
                                        }
                                      }
                                    };
                                    xhttp.open(
                                      "POST",
                                      main_url +
                                      "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                      !0
                                    );
                                    xhttp.setRequestHeader(
                                      "Content-type",
                                      "application/x-www-form-urlencoded"
                                    );
                                    if (
                                      main_lang_code &&
                                      main_lang_code.length > 0 &&
                                      main_lang_code != language_code
                                    ) {
                                    } else {
                                      main_lang_code = "default";
                                    }
                                    var bot_widget_obj;
                                    var is_sendable;
                                    try {
                                      checkSaveMAxUserLogin();
                                      checkRateGainDetails();
                                    } catch (error) { }
                                    if (window.botWidget && window.botWidget.user) {
                                      var keys = Object.keys(window.botWidget.user);
                                      for (var t = 0; t < keys.length; t++) {
                                        if (
                                          window.botWidget.user[keys[t]] &&
                                          window.botWidget.user[keys[t]].length > 0
                                        ) {
                                          is_sendable = true;
                                        }
                                      }
                                      if (is_sendable) {
                                        bot_widget_obj = window.botWidget.user;
                                      } else {
                                        bot_widget_obj = "";
                                      }
                                      if (window.botWidget.user.bot_id) {
                                        delete window.botWidget.user.bot_id;
                                      }
                                      if (window.botWidget.user.url) {
                                        delete window.botWidget.user.url;
                                      }
                                    }
                                    xhttp.send(
                                      "action=init_chat&device_print=" +
                                      device_print +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&language_code=" +
                                      main_lang_code +
                                      "&bot_widget_obj=" +
                                      JSON.stringify(bot_widget_obj)
                                    );
                                  }
                                  if (!entry_id) {
                                    showInput = !0;
                                    if (!shouldShowMenu) {
                                      footer.style.display = "none";
                                      footer.classList.add("close");
                                    } else {
                                      if (entry_id) {
                                        input.style.pointerEvents = "auto";
                                        microphone.style.pointerEvents = "auto";
                                        microphone.style.opacity = 1;
                                        enter.style.pointerEvents = "auto";
                                        setPlaceHolders();
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                      } else {
                                        input.style.pointerEvents = "none";
                                        microphone.style.pointerEvents = "none";
                                        microphone.style.opacity = 0;
                                        input.blur();
                                        enter.style.pointerEvents = "none";
                                        input.placeholder = "Choose from Menu";
                                      }
                                    }
                                  }
                                  if (!shouldShowMenu) {
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 168px)";
                                    } else {
                                      body.style.height = "calc(100% - 93px)";
                                    }
                                  } else {
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  }
                                }
                              }
                            };
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            if (
                              current_logical_jump == "1" &&
                              current_question_type != "radio" &&
                              current_question_type != "rating"
                            ) {
                              if (selectedCode && selectedCode.length > 0) {
                                xhttp.send(
                                  "action=answer&answer_text=" +
                                  encodeURIComponent(alredyTherePhoneProper) +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id +
                                  "&is_logical=" +
                                  current_logical_jump +
                                  "&sequence=" +
                                  currentMailSequence +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&option=" +
                                  "sometext&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              } else {
                                xhttp.send(
                                  "action=answer&answer_text=" +
                                  encodeURIComponent(alredyTherePhoneProper) +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id +
                                  "&is_logical=" +
                                  current_logical_jump +
                                  "&sequence=" +
                                  currentMailSequence +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&option=" +
                                  "sometext&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              }
                            } else {
                              if (selectedCode && selectedCode.length > 0) {
                                xhttp.send(
                                  "action=answer&answer_text=" +
                                  encodeURIComponent(alredyTherePhoneProper) +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id +
                                  "&is_logical=" +
                                  current_logical_jump +
                                  "&sequence=" +
                                  currentMailSequence +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&option=" +
                                  encodeURIComponent(alredyTherePhoneProper) +
                                  "&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              } else {
                                xhttp.send(
                                  "action=answer&answer_text=" +
                                  encodeURIComponent(alredyTherePhoneProper) +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id +
                                  "&is_logical=" +
                                  current_logical_jump +
                                  "&sequence=" +
                                  currentMailSequence +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&option=" +
                                  encodeURIComponent(alredyTherePhoneProper) +
                                  "&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              }
                            }
                          });
                          resend_div.appendChild(resend_label);
                          if (otp_entered == 2) {
                            if (skip_otp_validation) {
                              resend_div.appendChild(skip_div);
                            }
                          }
                          addReEnterMobileDiv(resend_div);
                          option_div.appendChild(resend_div);
                          questionDIv.appendChild(option_div);
                          body.appendChild(questionDIv);
                          body.scrollTop = body.scrollHeight;
                          footer.style.display = "block";
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 226px)";
                          } else {
                            body.style.height = "calc(100% - 150px)";
                          }
                          footer.classList.remove("close");
                          if (shouldShowMenu) {
                            input.style.pointerEvents = "auto";
                            microphone.style.pointerEvents = "auto";
                            microphone.style.opacity = 1;
                            enter.style.pointerEvents = "auto";
                          }
                          input.focus();
                        }, delay_time);
                      }
                    } else if (this.readyState == 4 && this.status != 200) {
                      var response = JSON.parse(this.response);
                      otp_entered = otp_entered + 1;
                      setTimeout(function () {
                        body.removeChild(spinningDiv);
                        var questionDIv = document.createElement("DIV");
                        if (currentMailSequence) {
                          questionDIv.id =
                            "radio-question-div-" + currentMailSequence;
                        } else {
                          questionDIv.id = "radio-question-div-" + 0;
                        }
                        questionDIv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          questionDIv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          questionDIv.classList.add(font);
                        }
                        var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon1);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon1.src = avatar_icon;
                        ques_icon1.classList.add("question-icon-smatest");
                        var option_div = document.createElement("DIV");
                        option_div.classList.add("options-div-smatest");
                        var option_question = document.createElement("LABEL");
                        if (font && font.length > 0) {
                          option_question.classList.add(font);
                        }
                        if (
                          (main_lang_code &&
                            (main_lang_code == "he" ||
                              main_lang_code == "ur" ||
                              main_lang_code == "ar")) ||
                          (main_lang_code == "default" &&
                            (language_code == "ar" ||
                              language_code == "he" ||
                              language_code == "ur"))
                        ) {
                          option_question.classList.add("rtl");
                        }
                        option_question.innerHTML =
                          "<div>" + response.message + "</div>";
                        say(option_question.innerText);
                        option_div.appendChild(option_question);
                        questionDIv.appendChild(iconDiv);
                        var resend_div = document.createElement("DIV");
                        resend_div.id = "resend-div";
                        resend_div.classList.add("file-input-div");
                        resend_div.classList.add("pull-left");
                        resend_div.classList.add("full-width");
                        resend_div.classList.add("text-center");
                        var resend_label = document.createElement("LABEL");
                        var resend_span = document.createElement("SPAN");
                        resend_span.innerHTML = "Resend OTP";
                        resend_span.classList.add("p-r-12");
                        resend_label.appendChild(resend_span);
                        resend_label.htmlFor = "capture-input";
                        resend_label.classList.add("upload-button-sb");
                        if (!agreed) {
                          resend_label.classList.add("no-pointer-events");
                        }
                        resend_label.addEventListener("click", function (k) {
                          var phoneXhttp = new XMLHttpRequest();
                          phoneXhttp.onreadystatechange = function () {
                            resend_span.innerHTML = "Resending OTP";
                            resend_label.classList.add("no-pointer-events");
                            resend_label.classList.add("bg-lightgray");
                            if (this.readyState == 4 && this.status == 200) {
                              var response = JSON.parse(this.response);
                              if (response && response.status) {
                                resend_label.classList.remove("bg-lightgray");
                                resend_label.classList.remove("no-pointer-events");
                                resend_span.innerHTML = "Resend OTP";
                                footer.style.display = "block";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                                footer.classList.remove("close");
                                if (shouldShowMenu) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                }
                                input.focus();
                                input_value = "";
                                input.placeholder = "Enter OTP";
                              } else {
                                if (
                                  response.message &&
                                  response.message.includes("Insufficient credits")
                                ) {
                                  var alredyTherePhoneProper =
                                    selectedCode + "-" + input_value;
                                  var xhttp = new XMLHttpRequest();
                                  inTheMiddle = !0;
                                  xhttp.onreadystatechange = function () {
                                    entered = !1;
                                    phoneValidated = !1;
                                    if (
                                      this.readyState == 4 &&
                                      this.status == 200
                                    ) {
                                      body.removeChild(spinningDiv);
                                      shouldDisableTakeAction = !1;
                                      if (selectedCode && selectedCode.length > 0) {
                                        question_and_answers.push({
                                          id: question_id,
                                          answer: selectedCode + "-" + input_value,
                                        });
                                      } else {
                                        question_and_answers.push({
                                          id: question_id,
                                          answer: input_value,
                                        });
                                      }
                                      if (
                                        currentQuestionIsLead == "1" &&
                                        !mailSent
                                      ) {
                                        sendAlertCall();
                                      } else {
                                        if (mailSequence < currentMailSequence) {
                                          random_key = !0;
                                        } else {
                                          random_key = !1;
                                        }
                                      }
                                      body.scrollTop = body.scrollHeight;
                                      cb_session = JSON.parse(
                                        this.response
                                      ).cb_session;
                                      live_chat_cb_session = JSON.parse(
                                        this.response
                                      ).livechat_session;
                                      if (
                                        JSON.parse(this.response).language_code &&
                                        JSON.parse(this.response).language_code
                                          .length > 0
                                      ) {
                                        main_lang_code = JSON.parse(
                                          this.response
                                        ).language_code;
                                      }
                                      session_feedback = JSON.parse(
                                        this.response
                                      ).feedback;
                                      question_array = JSON.parse(
                                        this.response
                                      ).next_question;
                                      if (
                                        question_array &&
                                        question_array.length > 0
                                      ) {
                                        question_completed = !1;
                                        input_value = "";
                                        if (
                                          footer.firstChild &&
                                          footer.firstChild.id == "selected_country"
                                        ) {
                                          footer.removeChild(footer.firstChild);
                                        }
                                        setTimeout(function () {
                                          enter.style.pointerEvents = "auto";
                                          if (
                                            spinningDiv &&
                                            spinningDiv.parentNode == body
                                          ) {
                                            body.removeChild(spinningDiv);
                                          }
                                          current_question_type =
                                            question_array[0].type;
                                          current_logical_jump =
                                            question_array[0].logical_jump;
                                          currentMailSequence =
                                            question_array[0].sequence;
                                          currentQuestionIsLead =
                                            question_array[0].send_mail;
                                          question_id = question_array[0].id;
                                          setAllInputs(question_array);
                                          assignAllQuestionTypes(
                                            current_question_type
                                          );
                                        }, delay_time);
                                      } else {
                                        if (
                                          spinningDiv &&
                                          spinningDiv.parentNode == body
                                        ) {
                                          body.removeChild(spinningDiv);
                                        }
                                        enter.style.pointerEvents = "auto";
                                        question_completed = !0;
                                        if (!mailSent || mailSent) {
                                          var xhttp = new XMLHttpRequest();
                                          xhttp.onreadystatechange = function () {
                                            if (
                                              this.readyState == 4 &&
                                              this.status == 200
                                            ) {
                                              var questionArray = [];
                                              prev_questions_array = JSON.parse(
                                                this.response
                                              ).qna_prev;
                                              if (
                                                prev_questions_array &&
                                                prev_questions_array.length > 0
                                              ) {
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  if (
                                                    prev_questions_array[i].type ==
                                                    "contact" ||
                                                    prev_questions_array[i].type ==
                                                    "slides" ||
                                                    prev_questions_array[i].type ==
                                                    "statement" ||
                                                    prev_questions_array[i].type ==
                                                    "url_auto_redirect" ||
                                                    prev_questions_array[i].type ==
                                                    "custom_answer" ||
                                                    prev_questions_array[i].type ==
                                                    "show_file" ||
                                                    prev_questions_array[i].type ==
                                                    "show_contacts" ||
                                                    prev_questions_array[i].type ==
                                                    "show_location"
                                                  ) {
                                                    prev_questions_array.splice(
                                                      i,
                                                      1
                                                    );
                                                    i--;
                                                  }
                                                }
                                                if (
                                                  zapier_webhook &&
                                                  zapier_webhook.length > 0
                                                ) {
                                                  var output = {};
                                                  output.timestamp = new Date();
                                                  for (
                                                    var i = 0;
                                                    i < prev_questions_array.length;
                                                    i++
                                                  ) {
                                                    var str =
                                                      prev_questions_array[i]
                                                        .question_text;
                                                    output[str] =
                                                      prev_questions_array[
                                                        i
                                                      ].answer_text;
                                                  }
                                                  var xhttp = new XMLHttpRequest();
                                                  xhttp.onreadystatechange =
                                                    function () {
                                                      if (
                                                        this.readyState == 4 &&
                                                        this.status == 200
                                                      ) {
                                                      }
                                                    };
                                                  xhttp.open(
                                                    "POST",
                                                    zapier_webhook,
                                                    !0
                                                  );
                                                  xhttp.setRequestHeader(
                                                    "Content-type",
                                                    "application/x-www-form-urlencoded"
                                                  );
                                                  xhttp.send(
                                                    "output=" +
                                                    JSON.stringify(output)
                                                  );
                                                }
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  questionArray.push({
                                                    question:
                                                      prev_questions_array[i]
                                                        .question_text,
                                                    answer:
                                                      prev_questions_array[i]
                                                        .answer_text,
                                                  });
                                                }
                                              }
                                            }
                                          };
                                          xhttp.open(
                                            "POST",
                                            url +
                                            "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                            !0
                                          );
                                          xhttp.setRequestHeader(
                                            "Content-type",
                                            "application/x-www-form-urlencoded"
                                          );
                                          if (
                                            main_lang_code &&
                                            main_lang_code.length > 0 &&
                                            main_lang_code != language_code
                                          ) {
                                          } else {
                                            main_lang_code = "default";
                                          }
                                          var bot_widget_obj;
                                          var is_sendable;
                                          if (
                                            window.botWidget &&
                                            window.botWidget.user
                                          ) {
                                            var keys = Object.keys(
                                              window.botWidget.user
                                            );
                                            for (var t = 0; t < keys.length; t++) {
                                              if (
                                                window.botWidget.user[keys[t]] &&
                                                window.botWidget.user[keys[t]]
                                                  .length > 0
                                              ) {
                                                is_sendable = true;
                                              }
                                            }
                                            if (is_sendable) {
                                              bot_widget_obj =
                                                window.botWidget.user;
                                            } else {
                                              bot_widget_obj = "";
                                            }
                                            if (window.botWidget.user.bot_id) {
                                              delete window.botWidget.user.bot_id;
                                            }
                                            if (window.botWidget.user.url) {
                                              delete window.botWidget.user.url;
                                            }
                                          }
                                          xhttp.send(
                                            "action=init_chat&device_print=" +
                                            device_print +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&language_code=" +
                                            main_lang_code +
                                            "&bot_widget_obj=" +
                                            JSON.stringify(bot_widget_obj)
                                          );
                                        } else {
                                          var xhttp = new XMLHttpRequest();
                                          xhttp.onreadystatechange = function () {
                                            if (
                                              this.readyState == 4 &&
                                              this.status == 200
                                            ) {
                                              var questionArray = [];
                                              prev_questions_array = JSON.parse(
                                                this.response
                                              ).qna_prev;
                                              if (
                                                prev_questions_array &&
                                                prev_questions_array.length > 0
                                              ) {
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  if (
                                                    prev_questions_array[i].type ==
                                                    "contact" ||
                                                    prev_questions_array[i].type ==
                                                    "slides" ||
                                                    prev_questions_array[i].type ==
                                                    "statement" ||
                                                    prev_questions_array[i].type ==
                                                    "url_auto_redirect" ||
                                                    prev_questions_array[i].type ==
                                                    "custom_answer" ||
                                                    prev_questions_array[i].type ==
                                                    "show_file" ||
                                                    prev_questions_array[i].type ==
                                                    "show_contacts" ||
                                                    prev_questions_array[i].type ==
                                                    "show_location"
                                                  ) {
                                                    prev_questions_array.splice(
                                                      i,
                                                      1
                                                    );
                                                    i--;
                                                  }
                                                }
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  questionArray.push({
                                                    question:
                                                      prev_questions_array[i]
                                                        .question_text,
                                                    answer:
                                                      prev_questions_array[i]
                                                        .answer_text,
                                                  });
                                                }
                                              }
                                            }
                                          };
                                          xhttp.open(
                                            "POST",
                                            url +
                                            "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                            !0
                                          );
                                          xhttp.setRequestHeader(
                                            "Content-type",
                                            "application/x-www-form-urlencoded"
                                          );
                                          if (
                                            main_lang_code &&
                                            main_lang_code.length > 0 &&
                                            main_lang_code != language_code
                                          ) {
                                          } else {
                                            main_lang_code = "default";
                                          }
                                          var bot_widget_obj;
                                          var is_sendable;
                                          if (
                                            window.botWidget &&
                                            window.botWidget.user
                                          ) {
                                            var keys = Object.keys(
                                              window.botWidget.user
                                            );
                                            for (var t = 0; t < keys.length; t++) {
                                              if (
                                                window.botWidget.user[keys[t]] &&
                                                window.botWidget.user[keys[t]]
                                                  .length > 0
                                              ) {
                                                is_sendable = true;
                                              }
                                            }
                                            if (is_sendable) {
                                              bot_widget_obj =
                                                window.botWidget.user;
                                            } else {
                                              bot_widget_obj = "";
                                            }
                                            if (window.botWidget.user.bot_id) {
                                              delete window.botWidget.user.bot_id;
                                            }
                                            if (window.botWidget.user.url) {
                                              delete window.botWidget.user.url;
                                            }
                                          }
                                          xhttp.send(
                                            "action=init_chat&device_print=" +
                                            device_print +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&language_code=" +
                                            main_lang_code +
                                            "&bot_widget_obj=" +
                                            JSON.stringify(bot_widget_obj)
                                          );
                                        }
                                        if (!entry_id) {
                                          showInput = !0;
                                          if (!shouldShowMenu) {
                                            footer.style.display = "none";
                                            footer.classList.add("close");
                                          } else {
                                            if (entry_id) {
                                              input.style.pointerEvents = "auto";
                                              microphone.style.pointerEvents =
                                                "auto";
                                              microphone.style.opacity = 1;
                                              enter.style.pointerEvents = "auto";
                                              setPlaceHolders();
                                              if (
                                                header.contains(
                                                  company_title_description
                                                )
                                              ) {
                                                body.style.height =
                                                  "calc(100% - 218px)";
                                              } else {
                                                body.style.height =
                                                  "calc(100% - 143px)";
                                              }
                                            } else {
                                              input.blur();
                                              input.style.pointerEvents = "none";
                                              microphone.style.pointerEvents =
                                                "none";
                                              microphone.style.opacity = 0;
                                              enter.style.pointerEvents = "none";
                                              input.placeholder =
                                                "Choose from Menu";
                                            }
                                          }
                                        }
                                        if (!shouldShowMenu) {
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 168px)";
                                          } else {
                                            body.style.height = "calc(100% - 93px)";
                                          }
                                        } else {
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                        }
                                      }
                                    }
                                  };
                                  xhttp.open(
                                    "POST",
                                    main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                    !0
                                  );
                                  xhttp.setRequestHeader(
                                    "Content-type",
                                    "application/x-www-form-urlencoded"
                                  );
                                  if (
                                    main_lang_code &&
                                    main_lang_code.length > 0 &&
                                    main_lang_code != language_code
                                  ) {
                                  } else {
                                    main_lang_code = "default";
                                  }
                                  if (
                                    current_logical_jump == "1" &&
                                    current_question_type != "radio" &&
                                    current_question_type != "rating"
                                  ) {
                                    if (selectedCode && selectedCode.length > 0) {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        "sometext&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    } else {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        "sometext&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    }
                                  } else {
                                    if (selectedCode && selectedCode.length > 0) {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    } else {
                                      xhttp.send(
                                        "action=answer&answer_text=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&cb_session=" +
                                        cb_session +
                                        "&question_id=" +
                                        question_id +
                                        "&is_logical=" +
                                        current_logical_jump +
                                        "&sequence=" +
                                        currentMailSequence +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&option=" +
                                        encodeURIComponent(
                                          alredyTherePhoneProper
                                        ) +
                                        "&visitor_link_traversal=" +
                                        visitedUrls +
                                        "&language_code=" +
                                        main_lang_code
                                      );
                                    }
                                  }
                                } else {
                                  resend_label.classList.remove("bg-lightgray");
                                  resend_label.classList.remove(
                                    "no-pointer-events"
                                  );
                                  resend_span.innerHTML = "Resend OTP";
                                  setTimeout(function () {
                                    input_value = "";
                                    footer.style.display = "block";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                    if (shouldShowMenu) {
                                      input.style.pointerEvents = "auto";
                                      microphone.style.pointerEvents = "auto";
                                      microphone.style.opacity = 1;
                                      enter.style.pointerEvents = "auto";
                                    }
                                    input.focus();
                                    footer.classList.remove("close");
                                    body.removeChild(spinningDiv);
                                    enter.style.pointerEvents = "auto";
                                    var errorDiv = document.createElement("DIV");
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    errorDiv.classList.add("question-div-smatest");
                                    setTimeout(function () {
                                      errorDiv.classList.add("top-0");
                                    }, transition_time);
                                    if (font && font.length > 0) {
                                      errorDiv.classList.add(font);
                                    }
                                    var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                    error_icon.src = avatar_icon;
                                    var iconDiv = document.createElement("DIV");
                                    iconDiv.appendChild(error_icon);
                                    iconDiv.classList.add("question-icon-div");
                                    error_icon.classList.add(
                                      "question-icon-smatest"
                                    );
                                    var error_text =
                                      document.createElement("LABEL");
                                    var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                    if (matched && matched.length > 0) {
                                      error_text.innerHTML = matched;
                                      say(error_text.innerText);
                                      if (
                                        (main_lang_code &&
                                          (main_lang_code == "he" ||
                                            main_lang_code == "ur" ||
                                            main_lang_code == "ar")) ||
                                        (main_lang_code == "default" &&
                                          (language_code == "ar" ||
                                            language_code == "he" ||
                                            language_code == "ur"))
                                      ) {
                                        error_text.classList.add("rtl");
                                        error_text.style.textAlign = "right";
                                      }
                                    } else {
                                      error_text.innerHTML =
                                        question_array[0].error_text;
                                      say(error_text.innerText);
                                    }
                                    error_text.classList.add("question-text-error");
                                    error_text.classList.add("options-div-smatest");
                                    if (font && font.length > 0) {
                                      error_text.classList.add(font);
                                    }
                                    errorDiv.appendChild(iconDiv);
                                    errorDiv.appendChild(error_text);
                                    body.appendChild(errorDiv);
                                    playBotUserSound(1);
                                    body.scrollTop = body.scrollHeight;
                                  }, delay_time);
                                }
                              }
                            } else if (this.readyState == 4 && this.status != 200) {
                              var response = JSON.parse(this.response);
                              if (
                                response.message &&
                                response.message.includes("Insufficient credits")
                              ) {
                                var alredyTherePhoneProper =
                                  selectedCode + "-" + input_value;
                                var xhttp = new XMLHttpRequest();
                                inTheMiddle = !0;
                                xhttp.onreadystatechange = function () {
                                  entered = !1;
                                  phoneValidated = !1;
                                  if (this.readyState == 4 && this.status == 200) {
                                    body.removeChild(spinningDiv);
                                    shouldDisableTakeAction = !1;
                                    if (selectedCode && selectedCode.length > 0) {
                                      question_and_answers.push({
                                        id: question_id,
                                        answer: selectedCode + "-" + input_value,
                                      });
                                    } else {
                                      question_and_answers.push({
                                        id: question_id,
                                        answer: input_value,
                                      });
                                    }
                                    if (currentQuestionIsLead == "1" && !mailSent) {
                                      sendAlertCall();
                                    } else {
                                      if (mailSequence < currentMailSequence) {
                                        random_key = !0;
                                      } else {
                                        random_key = !1;
                                      }
                                    }
                                    body.scrollTop = body.scrollHeight;
                                    cb_session = JSON.parse(
                                      this.response
                                    ).cb_session;
                                    live_chat_cb_session = JSON.parse(
                                      this.response
                                    ).livechat_session;
                                    if (
                                      JSON.parse(this.response).language_code &&
                                      JSON.parse(this.response).language_code
                                        .length > 0
                                    ) {
                                      main_lang_code = JSON.parse(
                                        this.response
                                      ).language_code;
                                    }
                                    session_feedback = JSON.parse(
                                      this.response
                                    ).feedback;
                                    question_array = JSON.parse(
                                      this.response
                                    ).next_question;
                                    if (
                                      question_array &&
                                      question_array.length > 0
                                    ) {
                                      question_completed = !1;
                                      input_value = "";
                                      if (
                                        footer.firstChild &&
                                        footer.firstChild.id == "selected_country"
                                      ) {
                                        footer.removeChild(footer.firstChild);
                                      }
                                      setTimeout(function () {
                                        enter.style.pointerEvents = "auto";
                                        if (
                                          spinningDiv &&
                                          spinningDiv.parentNode == body
                                        ) {
                                          body.removeChild(spinningDiv);
                                        }
                                        current_question_type =
                                          question_array[0].type;
                                        current_logical_jump =
                                          question_array[0].logical_jump;
                                        currentMailSequence =
                                          question_array[0].sequence;
                                        currentQuestionIsLead =
                                          question_array[0].send_mail;
                                        question_id = question_array[0].id;
                                        setAllInputs(question_array);
                                        assignAllQuestionTypes(
                                          current_question_type
                                        );
                                      }, delay_time);
                                    } else {
                                      if (
                                        spinningDiv &&
                                        spinningDiv.parentNode == body
                                      ) {
                                        body.removeChild(spinningDiv);
                                      }
                                      enter.style.pointerEvents = "auto";
                                      question_completed = !0;
                                      if (!mailSent || mailSent) {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              if (
                                                zapier_webhook &&
                                                zapier_webhook.length > 0
                                              ) {
                                                var output = {};
                                                output.timestamp = new Date();
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  var str =
                                                    prev_questions_array[i]
                                                      .question_text;
                                                  output[str] =
                                                    prev_questions_array[
                                                      i
                                                    ].answer_text;
                                                }
                                                var xhttp = new XMLHttpRequest();
                                                xhttp.onreadystatechange =
                                                  function () {
                                                    if (
                                                      this.readyState == 4 &&
                                                      this.status == 200
                                                    ) {
                                                    }
                                                  };
                                                xhttp.open(
                                                  "POST",
                                                  zapier_webhook,
                                                  !0
                                                );
                                                xhttp.setRequestHeader(
                                                  "Content-type",
                                                  "application/x-www-form-urlencoded"
                                                );
                                                xhttp.send(
                                                  "output=" + JSON.stringify(output)
                                                );
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      } else {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      }
                                      if (!entry_id) {
                                        showInput = !0;
                                        if (!shouldShowMenu) {
                                          footer.style.display = "none";
                                          footer.classList.add("close");
                                        } else {
                                          if (entry_id) {
                                            input.style.pointerEvents = "auto";
                                            microphone.style.pointerEvents = "auto";
                                            microphone.style.opacity = 1;
                                            enter.style.pointerEvents = "auto";
                                            setPlaceHolders();
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 218px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 143px)";
                                            }
                                          } else {
                                            input.blur();
                                            input.style.pointerEvents = "none";
                                            microphone.style.pointerEvents = "none";
                                            microphone.style.opacity = 0;
                                            enter.style.pointerEvents = "none";
                                            input.placeholder = "Choose from Menu";
                                          }
                                        }
                                      }
                                      if (!shouldShowMenu) {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 168px)";
                                        } else {
                                          body.style.height = "calc(100% - 93px)";
                                        }
                                      } else {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                if (
                                  current_logical_jump == "1" &&
                                  current_question_type != "radio" &&
                                  current_question_type != "rating"
                                ) {
                                  if (selectedCode && selectedCode.length > 0) {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      "sometext&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  } else {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      "sometext&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  }
                                } else {
                                  if (selectedCode && selectedCode.length > 0) {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  } else {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  }
                                }
                              } else {
                                resend_label.classList.remove("bg-lightgray");
                                resend_label.classList.remove("no-pointer-events");
                                resend_span.innerHTML = "Resend OTP";
                                setTimeout(function () {
                                  input_value = "";
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                  footer.classList.remove("close");
                                  body.removeChild(spinningDiv);
                                  enter.style.pointerEvents = "auto";
                                  var errorDiv = document.createElement("DIV");
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  errorDiv.classList.add("question-div-smatest");
                                  setTimeout(function () {
                                    errorDiv.classList.add("top-0");
                                  }, transition_time);
                                  if (font && font.length > 0) {
                                    errorDiv.classList.add(font);
                                  }
                                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                  error_icon.src = avatar_icon;
                                  var iconDiv = document.createElement("DIV");
                                  iconDiv.appendChild(error_icon);
                                  iconDiv.classList.add("question-icon-div");
                                  error_icon.classList.add("question-icon-smatest");
                                  var error_text = document.createElement("LABEL");
                                  var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                  if (matched && matched.length > 0) {
                                    error_text.innerHTML = matched;
                                    say(error_text.innerText);
                                    if (
                                      (main_lang_code &&
                                        (main_lang_code == "he" ||
                                          main_lang_code == "ur" ||
                                          main_lang_code == "ar")) ||
                                      (main_lang_code == "default" &&
                                        (language_code == "ar" ||
                                          language_code == "he" ||
                                          language_code == "ur"))
                                    ) {
                                      error_text.classList.add("rtl");
                                      error_text.style.textAlign = "right";
                                    }
                                  } else {
                                    error_text.innerHTML =
                                      question_array[0].error_text;
                                    say(error_text.innerText);
                                  }
                                  error_text.classList.add("question-text-error");
                                  error_text.classList.add("options-div-smatest");
                                  if (font && font.length > 0) {
                                    error_text.classList.add(font);
                                  }
                                  errorDiv.appendChild(iconDiv);
                                  errorDiv.appendChild(error_text);
                                  body.appendChild(errorDiv);
                                  playBotUserSound(1);
                                  body.scrollTop = body.scrollHeight;
                                }, delay_time);
                              }
                            }
                          };
                          phoneXhttp.open(
                            "POST",
                            main_url + "/kya_backend/runtimeUtils/phonevalidate",
                            !0
                          );
                          phoneXhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          phoneXhttp.send(
                            "phone=" +
                            alredyTherePhone +
                            "&chatbot_name=" +
                            encodeURIComponent(totalData[0].name) +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id
                          );
                        });
                        var skip_div = document.createElement("DIV");
                        skip_div.classList.add("file-input-div");
                        skip_div.classList.add("pull-left");
                        skip_div.classList.add("full-width");
                        skip_div.classList.add("text-center");
                        var skip_btn = document.createElement("LABEL");
                        skip_btn.innerHTML = "Skip Validation";
                        skip_btn.classList.add("pull-left");
                        skip_btn.classList.add("full-width");
                        skip_btn.classList.add("m-t-5");
                        skip_btn.classList.add("text-underline");
                        skip_btn.classList.add("skip-text");
                        skip_btn.classList.add("other-pointer");
                        skip_div.appendChild(skip_btn);
                        var otp_sent = 0;
                        skip_btn.addEventListener("click", function (k) {
                          var answerDiv = document.createElement("DIV");
                          answerDiv.classList.add("answer-div");
                          setTimeout(function () {
                            answerDiv.classList.add("top-0");
                          }, transition_time);
                          var answer = document.createElement("LABEL");
                          var answer_text = document.createTextNode(
                            alredyTherePhoneProper
                          );
                          answer.appendChild(answer_text);
                          answer.classList.add("answer-label");
                          if (font && font.length > 0) {
                            answer.classList.add(font);
                          }
                          answerDiv.appendChild(answer);
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                          if (prev_should_show) {
                            footer.style.display = "block";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                            footer.classList.remove("close");
                            if (shouldShowMenu) {
                              input.style.pointerEvents = "auto";
                              microphone.style.pointerEvents = "auto";
                              microphone.style.opacity = 1;
                              enter.style.pointerEvents = "auto";
                            }
                            input.focus();
                          } else {
                            if (!shouldShowMenu) {
                              footer.style.display = "none";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 168px)";
                              } else {
                                body.style.height = "calc(100% - 93px)";
                              }
                              footer.classList.add("close");
                            } else {
                              if (entry_id) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                                setPlaceHolders();
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              } else {
                                input.style.pointerEvents = "none";
                                microphone.style.pointerEvents = "none";
                                microphone.style.opacity = 0;
                                input.blur();
                                enter.style.pointerEvents = "none";
                                input.placeholder = "Choose from Menu";
                                input.type = "text";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                          var spinningDiv = document.createElement("DIV");
                          spinningDiv.classList.add("question-div-smatest");
                          spinningDiv.classList.add("top-0");
                          if (font && font.length > 0) {
                            spinningDiv.classList.add(font);
                          }
                          var spinnerDiv = document.createElement("DIV");
                          spinnerDiv.classList.add("spinner1-smatest");
                          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                          ques_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(ques_icon);
                          iconDiv.classList.add("question-icon-div");
                          ques_icon.classList.add("question-icon-smatest");
                          var inner1 = document.createElement("DIV");
                          inner1.classList.add("bounce1");
                          var inner2 = document.createElement("DIV");
                          inner2.classList.add("bounce2");
                          var inner3 = document.createElement("DIV");
                          inner3.classList.add("bounce3");
                          spinnerDiv.appendChild(inner1);
                          spinnerDiv.appendChild(inner2);
                          spinnerDiv.appendChild(inner3);
                          spinningDiv.appendChild(iconDiv);
                          spinningDiv.appendChild(spinnerDiv);
                          body.appendChild(spinningDiv);
                          body.scrollTop = body.scrollHeight;
                          var xhttp = new XMLHttpRequest();
                          inTheMiddle = !0;
                          xhttp.onreadystatechange = function () {
                            entered = !1;
                            phoneValidated = !1;
                            if (this.readyState == 4 && this.status == 200) {
                              resend_div.removeChild(resend_label);
                              if (skip_otp_validation) {
                                resend_div.removeChild(skip_div);
                              }
                              body.removeChild(spinningDiv);
                              shouldDisableTakeAction = !1;
                              if (selectedCode && selectedCode.length > 0) {
                                question_and_answers.push({
                                  id: question_id,
                                  answer: selectedCode + "-" + input_value,
                                });
                              } else {
                                question_and_answers.push({
                                  id: question_id,
                                  answer: input_value,
                                });
                              }
                              if (currentQuestionIsLead == "1" && !mailSent) {
                                sendAlertCall();
                              } else {
                                if (mailSequence < currentMailSequence) {
                                  random_key = !0;
                                } else {
                                  random_key = !1;
                                }
                              }
                              body.scrollTop = body.scrollHeight;
                              cb_session = JSON.parse(this.response).cb_session;
                              live_chat_cb_session = JSON.parse(
                                this.response
                              ).livechat_session;
                              if (
                                JSON.parse(this.response).language_code &&
                                JSON.parse(this.response).language_code.length >
                                0 &&
                                JSON.parse(this.response).language_code != "default"
                              ) {
                                main_lang_code = JSON.parse(
                                  this.response
                                ).language_code;
                              }
                              session_feedback = JSON.parse(this.response).feedback;
                              question_array = JSON.parse(
                                this.response
                              ).next_question;
                              if (question_array && question_array.length > 0) {
                                question_completed = !1;
                                input_value = "";
                                if (
                                  footer.firstChild &&
                                  footer.firstChild.id == "selected_country"
                                ) {
                                  footer.removeChild(footer.firstChild);
                                }
                                setTimeout(function () {
                                  enter.style.pointerEvents = "auto";
                                  if (
                                    spinningDiv &&
                                    spinningDiv.parentNode == body
                                  ) {
                                    body.removeChild(spinningDiv);
                                  }
                                  current_question_type = question_array[0].type;
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  question_id = question_array[0].id;
                                  setAllInputs(question_array);
                                  assignAllQuestionTypes(current_question_type);
                                }, delay_time);
                              } else {
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                enter.style.pointerEvents = "auto";
                                question_completed = !0;
                                if (!mailSent || mailSent) {
                                  var xhttp = new XMLHttpRequest();
                                  xhttp.onreadystatechange = function () {
                                    if (
                                      this.readyState == 4 &&
                                      this.status == 200
                                    ) {
                                      var questionArray = [];
                                      prev_questions_array = JSON.parse(
                                        this.response
                                      ).qna_prev;
                                      if (
                                        prev_questions_array &&
                                        prev_questions_array.length > 0
                                      ) {
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          if (
                                            prev_questions_array[i].type ==
                                            "contact" ||
                                            prev_questions_array[i].type ==
                                            "slides" ||
                                            prev_questions_array[i].type ==
                                            "statement" ||
                                            prev_questions_array[i].type ==
                                            "url_auto_redirect" ||
                                            prev_questions_array[i].type ==
                                            "custom_answer" ||
                                            prev_questions_array[i].type ==
                                            "show_file" ||
                                            prev_questions_array[i].type ==
                                            "show_contacts" ||
                                            prev_questions_array[i].type ==
                                            "show_location"
                                          ) {
                                            prev_questions_array.splice(i, 1);
                                            i--;
                                          }
                                        }
                                        if (
                                          zapier_webhook &&
                                          zapier_webhook.length > 0
                                        ) {
                                          var output = {};
                                          output.timestamp = new Date();
                                          for (
                                            var i = 0;
                                            i < prev_questions_array.length;
                                            i++
                                          ) {
                                            var str =
                                              prev_questions_array[i].question_text;
                                            output[str] =
                                              prev_questions_array[i].answer_text;
                                          }
                                          var xhttp = new XMLHttpRequest();
                                          xhttp.onreadystatechange = function () {
                                            if (
                                              this.readyState == 4 &&
                                              this.status == 200
                                            ) {
                                            }
                                          };
                                          xhttp.open("POST", zapier_webhook, !0);
                                          xhttp.setRequestHeader(
                                            "Content-type",
                                            "application/x-www-form-urlencoded"
                                          );
                                          xhttp.send(
                                            "output=" + JSON.stringify(output)
                                          );
                                        }
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          questionArray.push({
                                            question:
                                              prev_questions_array[i].question_text,
                                            answer:
                                              prev_questions_array[i].answer_text,
                                          });
                                        }
                                      }
                                    }
                                  };
                                  xhttp.open(
                                    "POST",
                                    main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                    !0
                                  );
                                  xhttp.setRequestHeader(
                                    "Content-type",
                                    "application/x-www-form-urlencoded"
                                  );
                                  if (
                                    main_lang_code &&
                                    main_lang_code.length > 0 &&
                                    main_lang_code != language_code
                                  ) {
                                  } else {
                                    main_lang_code = "default";
                                  }
                                  var bot_widget_obj;
                                  var is_sendable;
                                  try {
                                    checkSaveMAxUserLogin();
                                    checkRateGainDetails();
                                  } catch (error) { }
                                  if (window.botWidget && window.botWidget.user) {
                                    var keys = Object.keys(window.botWidget.user);
                                    for (var t = 0; t < keys.length; t++) {
                                      if (
                                        window.botWidget.user[keys[t]] &&
                                        window.botWidget.user[keys[t]].length > 0
                                      ) {
                                        is_sendable = true;
                                      }
                                    }
                                    if (is_sendable) {
                                      bot_widget_obj = window.botWidget.user;
                                    } else {
                                      bot_widget_obj = "";
                                    }
                                    if (window.botWidget.user.bot_id) {
                                      delete window.botWidget.user.bot_id;
                                    }
                                    if (window.botWidget.user.url) {
                                      delete window.botWidget.user.url;
                                    }
                                  }
                                  xhttp.send(
                                    "action=init_chat&device_print=" +
                                    device_print +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&language_code=" +
                                    main_lang_code +
                                    "&bot_widget_obj=" +
                                    JSON.stringify(bot_widget_obj)
                                  );
                                } else {
                                  var xhttp = new XMLHttpRequest();
                                  xhttp.onreadystatechange = function () {
                                    if (
                                      this.readyState == 4 &&
                                      this.status == 200
                                    ) {
                                      var questionArray = [];
                                      prev_questions_array = JSON.parse(
                                        this.response
                                      ).qna_prev;
                                      if (
                                        prev_questions_array &&
                                        prev_questions_array.length > 0
                                      ) {
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          if (
                                            prev_questions_array[i].type ==
                                            "contact" ||
                                            prev_questions_array[i].type ==
                                            "slides" ||
                                            prev_questions_array[i].type ==
                                            "statement" ||
                                            prev_questions_array[i].type ==
                                            "url_auto_redirect" ||
                                            prev_questions_array[i].type ==
                                            "custom_answer" ||
                                            prev_questions_array[i].type ==
                                            "show_file" ||
                                            prev_questions_array[i].type ==
                                            "show_contacts" ||
                                            prev_questions_array[i].type ==
                                            "show_location"
                                          ) {
                                            prev_questions_array.splice(i, 1);
                                            i--;
                                          }
                                        }
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          questionArray.push({
                                            question:
                                              prev_questions_array[i].question_text,
                                            answer:
                                              prev_questions_array[i].answer_text,
                                          });
                                        }
                                      }
                                    }
                                  };
                                  xhttp.open(
                                    "POST",
                                    main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                    !0
                                  );
                                  xhttp.setRequestHeader(
                                    "Content-type",
                                    "application/x-www-form-urlencoded"
                                  );
                                  if (
                                    main_lang_code &&
                                    main_lang_code.length > 0 &&
                                    main_lang_code != language_code
                                  ) {
                                  } else {
                                    main_lang_code = "default";
                                  }
                                  var bot_widget_obj;
                                  var is_sendable;
                                  try {
                                    checkSaveMAxUserLogin();
                                    checkRateGainDetails();
                                  } catch (error) { }
                                  if (window.botWidget && window.botWidget.user) {
                                    var keys = Object.keys(window.botWidget.user);
                                    for (var t = 0; t < keys.length; t++) {
                                      if (
                                        window.botWidget.user[keys[t]] &&
                                        window.botWidget.user[keys[t]].length > 0
                                      ) {
                                        is_sendable = true;
                                      }
                                    }
                                    if (is_sendable) {
                                      bot_widget_obj = window.botWidget.user;
                                    } else {
                                      bot_widget_obj = "";
                                    }
                                    if (window.botWidget.user.bot_id) {
                                      delete window.botWidget.user.bot_id;
                                    }
                                    if (window.botWidget.user.url) {
                                      delete window.botWidget.user.url;
                                    }
                                  }
                                  xhttp.send(
                                    "action=init_chat&device_print=" +
                                    device_print +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&language_code=" +
                                    main_lang_code +
                                    "&bot_widget_obj=" +
                                    JSON.stringify(bot_widget_obj)
                                  );
                                }
                                if (!entry_id) {
                                  showInput = !0;
                                  if (!shouldShowMenu) {
                                    footer.style.display = "none";
                                    footer.classList.add("close");
                                  } else {
                                    if (entry_id) {
                                      input.style.pointerEvents = "auto";
                                      microphone.style.pointerEvents = "auto";
                                      microphone.style.opacity = 1;
                                      enter.style.pointerEvents = "auto";
                                      setPlaceHolders();
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                    } else {
                                      input.style.pointerEvents = "none";
                                      microphone.style.pointerEvents = "none";
                                      microphone.style.opacity = 0;
                                      input.blur();
                                      enter.style.pointerEvents = "none";
                                      input.placeholder = "Choose from Menu";
                                    }
                                  }
                                }
                                if (!shouldShowMenu) {
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                } else {
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                }
                              }
                            }
                          };
                          xhttp.open(
                            "POST",
                            main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                            !0
                          );
                          xhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          if (
                            main_lang_code &&
                            main_lang_code.length > 0 &&
                            main_lang_code != language_code
                          ) {
                          } else {
                            main_lang_code = "default";
                          }
                          if (
                            current_logical_jump == "1" &&
                            current_question_type != "radio" &&
                            current_question_type != "rating"
                          ) {
                            if (selectedCode && selectedCode.length > 0) {
                              xhttp.send(
                                "action=answer&answer_text=" +
                                encodeURIComponent(alredyTherePhoneProper) +
                                "&cb_session=" +
                                cb_session +
                                "&question_id=" +
                                question_id +
                                "&is_logical=" +
                                current_logical_jump +
                                "&sequence=" +
                                currentMailSequence +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&option=" +
                                "sometext&visitor_link_traversal=" +
                                visitedUrls +
                                "&language_code=" +
                                main_lang_code
                              );
                            } else {
                              xhttp.send(
                                "action=answer&answer_text=" +
                                encodeURIComponent(alredyTherePhoneProper) +
                                "&cb_session=" +
                                cb_session +
                                "&question_id=" +
                                question_id +
                                "&is_logical=" +
                                current_logical_jump +
                                "&sequence=" +
                                currentMailSequence +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&option=" +
                                "sometext&visitor_link_traversal=" +
                                visitedUrls +
                                "&language_code=" +
                                main_lang_code
                              );
                            }
                          } else {
                            if (selectedCode && selectedCode.length > 0) {
                              xhttp.send(
                                "action=answer&answer_text=" +
                                encodeURIComponent(alredyTherePhoneProper) +
                                "&cb_session=" +
                                cb_session +
                                "&question_id=" +
                                question_id +
                                "&is_logical=" +
                                current_logical_jump +
                                "&sequence=" +
                                currentMailSequence +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&option=" +
                                encodeURIComponent(alredyTherePhoneProper) +
                                "&visitor_link_traversal=" +
                                visitedUrls +
                                "&language_code=" +
                                main_lang_code
                              );
                            } else {
                              xhttp.send(
                                "action=answer&answer_text=" +
                                encodeURIComponent(alredyTherePhoneProper) +
                                "&cb_session=" +
                                cb_session +
                                "&question_id=" +
                                question_id +
                                "&is_logical=" +
                                current_logical_jump +
                                "&sequence=" +
                                currentMailSequence +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&option=" +
                                encodeURIComponent(alredyTherePhoneProper) +
                                "&visitor_link_traversal=" +
                                visitedUrls +
                                "&language_code=" +
                                main_lang_code
                              );
                            }
                          }
                        });
                        resend_div.appendChild(resend_label);
                        if (otp_entered == 2) {
                          if (skip_otp_validation) {
                            resend_div.appendChild(skip_div);
                          }
                        }
                        addReEnterMobileDiv(resend_div);
                        option_div.appendChild(resend_div);
                        questionDIv.appendChild(option_div);
                        body.appendChild(questionDIv);
                        body.scrollTop = body.scrollHeight;
                        footer.style.display = "block";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                        footer.classList.remove("close");
                        if (shouldShowMenu) {
                          input.style.pointerEvents = "auto";
                          microphone.style.pointerEvents = "auto";
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = "auto";
                        }
                        // input.style.pointerEvents = "none";
                        // enter.style.pointerEvents = "none";
                        // input.focus();
                      }, delay_time);
                    }
                  };
                  otpXhttp.open(
                    "POST",
                    main_url + "/kya_backend/runtimeUtils/verify",
                    !0
                  );
                  otpXhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  otpXhttp.send(
                    "phone=" +
                    alredyTherePhone +
                    "&chatbot_name=" +
                    encodeURIComponent(totalData[0].name) +
                    "&otp=" +
                    input_value +
                    "&cb_session=" +
                    cb_session +
                    "&chatbot_id=" +
                    chatbot_id
                  );
                } else if (
                  input.placeholder &&
                  input.placeholder == "Enter the OTP"
                ) {
                  var answerDiv = document.createElement("DIV");
                  answerDiv.classList.add("answer-div");
                  setTimeout(function () {
                    answerDiv.classList.add("top-0");
                  }, transition_time);
                  var answer = document.createElement("LABEL");
                  var answer_text = document.createTextNode(input_value);
                  answer.appendChild(answer_text);
                  answer.classList.add("answer-label");
                  if (font && font.length > 0) {
                    answer.classList.add(font);
                  }
                  answerDiv.appendChild(answer);
                  body.appendChild(answerDiv);
                  body.scrollTop = body.scrollHeight;
                  var spinningDiv = document.createElement("DIV");
                  spinningDiv.classList.add("question-div-smatest");
                  spinningDiv.classList.add("top-0");
                  if (font && font.length > 0) {
                    spinningDiv.classList.add(font);
                  }
                  var spinnerDiv = document.createElement("DIV");
                  spinnerDiv.classList.add("spinner1-smatest");
                  var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                  ques_icon.src = avatar_icon;
                  var iconDiv = document.createElement("DIV");
                  iconDiv.appendChild(ques_icon);
                  iconDiv.classList.add("question-icon-div");
                  ques_icon.classList.add("question-icon-smatest");
                  var inner1 = document.createElement("DIV");
                  inner1.classList.add("bounce1");
                  var inner2 = document.createElement("DIV");
                  inner2.classList.add("bounce2");
                  var inner3 = document.createElement("DIV");
                  inner3.classList.add("bounce3");
                  spinnerDiv.appendChild(inner1);
                  spinnerDiv.appendChild(inner2);
                  spinnerDiv.appendChild(inner3);
                  spinningDiv.appendChild(iconDiv);
                  spinningDiv.appendChild(spinnerDiv);
                  body.appendChild(spinningDiv);
                  body.scrollTop = body.scrollHeight;
                  if (!shouldShowMenu) {
                    footer.style.display = "none";
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                    footer.classList.add("close");
                  } else {
                    if (entry_id) {
                      input.style.pointerEvents = "auto";
                      microphone.style.pointerEvents = "auto";
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = "auto";
                      setPlaceHolders();
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    } else {
                      input.style.pointerEvents = "none";
                      microphone.style.pointerEvents = "none";
                      microphone.style.opacity = 0;
                      input.blur();
                      enter.style.pointerEvents = "none";
                      input.placeholder = "Choose from Menu";
                      input.type = "text";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                    }
                  }
                  var otpXhttp = new XMLHttpRequest();
                  otpXhttp.onreadystatechange = function () {
                    if (this.readyState == 4 && this.status == 200) {
                      var response = JSON.parse(this.response);
                      var email_otp_value = input_value;
                      var resend_div = document.getElementById("resend-email-div");
                      // resend_div.parentElement.removeChild(resend_div);
                      if (resend_div && resend_div.parentElement) {
                        resend_div.parentElement.removeChild(resend_div);
                      }
                      if (response && response.status) {
                        input.placeholder = "Type your query";
                        var xhttp = new XMLHttpRequest();
                        inTheMiddle = !0;
                        try {
                          var temp_div =
                            document.getElementById("resend-email-div");
                          if (temp_div && temp_div.parentElement) {
                            temp_div.parentElement.removeChild(temp_div);
                          }
                        } catch (error) { }
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          phoneValidated = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            body.removeChild(spinningDiv);
                            shouldDisableTakeAction = !1;
                            if (selectedCode && selectedCode.length > 0) {
                              question_and_answers.push({
                                id: question_id,
                                answer: selectedCode + "-" + input_value,
                              });
                            } else {
                              question_and_answers.push({
                                id: question_id,
                                answer: input_value,
                              });
                            }
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            body.scrollTop = body.scrollHeight;
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              if (
                                footer.firstChild &&
                                footer.firstChild.id == "selected_country"
                              ) {
                                footer.removeChild(footer.firstChild);
                              }
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          if (selectedCode && selectedCode.length > 0) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyThereEmail) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&email_otp=" +
                              email_otp_value +
                              "&timestamp=" +
                              email_timestamp
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyThereEmail) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&email_otp=" +
                              email_otp_value +
                              "&timestamp=" +
                              email_timestamp
                            );
                          }
                        } else {
                          if (selectedCode && selectedCode.length > 0) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyThereEmail) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              encodeURIComponent(alredyThereEmail) +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&email_otp=" +
                              email_otp_value +
                              "&timestamp=" +
                              email_timestamp
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(alredyThereEmail) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              encodeURIComponent(alredyThereEmail) +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code +
                              "&email_otp=" +
                              email_otp_value +
                              "&timestamp=" +
                              email_timestamp
                            );
                          }
                        }
                      } else {
                        otp_entered = otp_entered + 1;
                        try {
                          var temp_div =
                            document.getElementById("resend-email-div");
                          if (temp_div && temp_div.parentElement) {
                            temp_div.parentElement.removeChild(temp_div);
                          }
                        } catch (error) { }
                        setTimeout(function () {
                          body.removeChild(spinningDiv);
                          var questionDIv = document.createElement("DIV");
                          if (currentMailSequence) {
                            questionDIv.id =
                              "radio-question-div-" + currentMailSequence;
                          } else {
                            questionDIv.id = "radio-question-div-" + 0;
                          }
                          questionDIv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            questionDIv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            questionDIv.classList.add(font);
                          }
                          var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(ques_icon1);
                          iconDiv.classList.add("question-icon-div");
                          ques_icon1.src = avatar_icon;
                          ques_icon1.classList.add("question-icon-smatest");
                          var option_div = document.createElement("DIV");
                          option_div.classList.add("options-div-smatest");
                          var option_question = document.createElement("LABEL");
                          if (font && font.length > 0) {
                            option_question.classList.add(font);
                          }
                          if (
                            (main_lang_code &&
                              (main_lang_code == "he" ||
                                main_lang_code == "ur" ||
                                main_lang_code == "ar")) ||
                            (main_lang_code == "default" &&
                              (language_code == "ar" ||
                                language_code == "he" ||
                                language_code == "ur"))
                          ) {
                            option_question.classList.add("rtl");
                          }
                          option_question.innerHTML =
                            "<div>" + response.message + "</div>";
                          say(option_question.innerText);
                          option_div.appendChild(option_question);
                          questionDIv.appendChild(iconDiv);
                          var resend_div = document.createElement("DIV");
                          resend_div.id = "resend-email-div";
                          resend_div.classList.add("file-input-div");
                          resend_div.classList.add("pull-left");
                          resend_div.classList.add("full-width");
                          resend_div.classList.add("text-center");
                          var resend_label = document.createElement("LABEL");
                          var resend_span = document.createElement("SPAN");
                          resend_span.innerHTML = "Resend OTP";
                          resend_span.classList.add("p-r-12");
                          resend_label.appendChild(resend_span);
                          resend_label.htmlFor = "capture-input";
                          resend_label.classList.add("upload-button-sb");
                          if (!agreed) {
                            resend_label.classList.add("no-pointer-events");
                          }
                          var otp_remaining_time = 45;
                          var otp_time = document.createElement("LABEL");
                          otp_time.classList.add("pull-left");
                          otp_time.classList.add("full-width");
                          otp_time.classList.add("text-center");
                          otp_time.classList.add("m-t-5");
                          otp_time.classList.add("m-b-10");
                          if (font && font.length > 0) {
                            otp_time.classList.add(font);
                          }
                          otp_time.classList.add("limegreen");
                          otp_time.innerHTML = otp_remaining_time + "s Remaining";
                          var change_email_label = document.createElement("LABEL");
                          var change_email_span = document.createElement("SPAN");
                          change_email_span.innerHTML = "Change Email";
                          change_email_span.classList.add("p-r-12");
                          change_email_label.appendChild(change_email_span);
                          change_email_label.htmlFor = "capture-input";
                          change_email_label.classList.add("upload-button-sb");
                          if (!agreed) {
                            change_email_label.classList.add("no-pointer-events");
                          }
                          var otp_sent = 0;
                          var shouldStopChecking;
                          setInterval(function () {
                            if (!shouldStopChecking) {
                              otp_remaining_time = otp_remaining_time - 1;
                              otp_time.innerHTML =
                                otp_remaining_time + "s Remaining";
                              if (otp_remaining_time == 5) {
                                otp_time.classList.remove("limegreen");
                                otp_time.classList.add("red");
                              }
                              if (otp_remaining_time == 0) {
                                shouldStopChecking = !0;
                                if (resend_div.contains(otp_time)) {
                                  resend_div.removeChild(otp_time);
                                }
                                if (resend_div.contains(resend_label)) {
                                  resend_div.removeChild(resend_label);
                                }
                                if (resend_div.contains(change_email_label)) {
                                  resend_div.removeChild(change_email_label);
                                }
                                otp_sent = otp_sent + 1;
                              }
                            }
                          }, 1000);
                          resend_label.addEventListener("click", function (k) {
                            otp_remaining_time = 45;
                            resend_div.removeChild(resend_label);
                            resend_div.removeChild(change_email_label);
                            resend_div.appendChild(otp_time);
                            var phoneXhttp = new XMLHttpRequest();
                            phoneXhttp.onreadystatechange = function () {
                              resend_span.innerHTML = "Resending OTP";
                              resend_label.classList.add("no-pointer-events");
                              resend_label.classList.add("bg-lightgray");
                              if (this.readyState == 4 && this.status == 200) {
                                var response = JSON.parse(this.response);
                                email_timestamp = response.timestamp;
                                if (response && response.status) {
                                  resend_label.classList.remove("bg-lightgray");
                                  resend_label.classList.remove(
                                    "no-pointer-events"
                                  );
                                  resend_span.innerHTML = "Resend OTP";
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  footer.classList.remove("close");
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                  input_value = "";
                                  handleResendOTPCase(response);
                                } else {
                                  resend_label.classList.remove("bg-lightgray");
                                  resend_label.classList.remove(
                                    "no-pointer-events"
                                  );
                                  resend_span.innerHTML = "Resend OTP";
                                  setTimeout(function () {
                                    input_value = "";
                                    footer.style.display = "block";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                    if (shouldShowMenu) {
                                      input.style.pointerEvents = "auto";
                                      microphone.style.pointerEvents = "auto";
                                      microphone.style.opacity = 1;
                                      enter.style.pointerEvents = "auto";
                                    }
                                    input.focus();
                                    footer.classList.remove("close");
                                    body.removeChild(spinningDiv);
                                    enter.style.pointerEvents = "auto";
                                    var errorDiv = document.createElement("DIV");
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    errorDiv.classList.add("question-div-smatest");
                                    setTimeout(function () {
                                      errorDiv.classList.add("top-0");
                                    }, transition_time);
                                    if (font && font.length > 0) {
                                      errorDiv.classList.add(font);
                                    }
                                    var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                    error_icon.src = avatar_icon;
                                    var iconDiv = document.createElement("DIV");
                                    iconDiv.appendChild(error_icon);
                                    iconDiv.classList.add("question-icon-div");
                                    error_icon.classList.add(
                                      "question-icon-smatest"
                                    );
                                    var error_text =
                                      document.createElement("LABEL");
                                    var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                    if (matched && matched.length > 0) {
                                      error_text.innerHTML = matched;
                                      say(error_text.innerText);
                                      if (
                                        (main_lang_code &&
                                          (main_lang_code == "he" ||
                                            main_lang_code == "ur" ||
                                            main_lang_code == "ar")) ||
                                        (main_lang_code == "default" &&
                                          (language_code == "ar" ||
                                            language_code == "he" ||
                                            language_code == "ur"))
                                      ) {
                                        error_text.classList.add("rtl");
                                        error_text.style.textAlign = "right";
                                      }
                                    } else {
                                      error_text.innerHTML =
                                        question_array[0].error_text;
                                      say(error_text.innerText);
                                    }
                                    error_text.classList.add("question-text-error");
                                    error_text.classList.add("options-div-smatest");
                                    if (font && font.length > 0) {
                                      error_text.classList.add(font);
                                    }
                                    errorDiv.appendChild(iconDiv);
                                    errorDiv.appendChild(error_text);
                                    body.appendChild(errorDiv);
                                    playBotUserSound(1);
                                    body.scrollTop = body.scrollHeight;
                                  }, delay_time);
                                }
                              } else if (
                                this.readyState == 4 &&
                                this.status != 200
                              ) {
                                var response = JSON.parse(this.response);
                                resend_label.classList.remove("bg-lightgray");
                                resend_label.classList.remove("no-pointer-events");
                                resend_span.innerHTML = "Resend OTP";
                                setTimeout(function () {
                                  input_value = "";
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                  footer.classList.remove("close");
                                  body.removeChild(spinningDiv);
                                  enter.style.pointerEvents = "auto";
                                  var errorDiv = document.createElement("DIV");
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  errorDiv.classList.add("question-div-smatest");
                                  setTimeout(function () {
                                    errorDiv.classList.add("top-0");
                                  }, transition_time);
                                  if (font && font.length > 0) {
                                    errorDiv.classList.add(font);
                                  }
                                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                  error_icon.src = avatar_icon;
                                  var iconDiv = document.createElement("DIV");
                                  iconDiv.appendChild(error_icon);
                                  iconDiv.classList.add("question-icon-div");
                                  error_icon.classList.add("question-icon-smatest");
                                  var error_text = document.createElement("LABEL");
                                  var matched = generateTranslatedContent(translations, "Please enter a valid Email", main_lang_code, language_code, input);
                                  if (matched && matched.length > 0) {
                                    error_text.innerHTML = matched;
                                    say(error_text.innerText);
                                    if (
                                      (main_lang_code &&
                                        (main_lang_code == "he" ||
                                          main_lang_code == "ur" ||
                                          main_lang_code == "ar")) ||
                                      (main_lang_code == "default" &&
                                        (language_code == "ar" ||
                                          language_code == "he" ||
                                          language_code == "ur"))
                                    ) {
                                      error_text.classList.add("rtl");
                                      error_text.style.textAlign = "right";
                                    }
                                  } else {
                                    error_text.innerHTML =
                                      question_array[0].error_text;
                                    say(error_text.innerText);
                                  }
                                  error_text.classList.add("question-text-error");
                                  error_text.classList.add("options-div-smatest");
                                  if (font && font.length > 0) {
                                    error_text.classList.add(font);
                                  }
                                  errorDiv.appendChild(iconDiv);
                                  errorDiv.appendChild(error_text);
                                  body.appendChild(errorDiv);
                                  playBotUserSound(1);
                                  body.scrollTop = body.scrollHeight;
                                }, delay_time);
                              }
                            };
                            phoneXhttp.open(
                              "POST",
                              main_url + "/kya_backend/runtimeUtils/Emailvalidate",
                              !0
                            );
                            phoneXhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            phoneXhttp.send(
                              "email=" +
                              alredyThereEmail +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&cb_session=" +
                              cb_session
                            );
                          });
                          change_email_label.addEventListener(
                            "click",
                            function (k) {
                              current_question_type = "email";
                              footer.style.display = "block";
                              email_otp_validated = !0;
                              input.placeholder = "Enter your email again";
                              option_div.removeChild(resend_div);
                              addTextDivToBot("Please enter the email again");
                            }
                          );
                          resend_div.appendChild(resend_label);
                          resend_div.appendChild(change_email_label);
                          option_div.appendChild(resend_div);
                          questionDIv.appendChild(option_div);
                          body.appendChild(questionDIv);
                          body.scrollTop = body.scrollHeight;
                          footer.style.display = "block";
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 226px)";
                          } else {
                            body.style.height = "calc(100% - 150px)";
                          }
                          footer.classList.remove("close");
                          if (shouldShowMenu) {
                            input.style.pointerEvents = "auto";
                            microphone.style.pointerEvents = "auto";
                            microphone.style.opacity = 1;
                            enter.style.pointerEvents = "auto";
                          }
                          input.focus();
                        }, delay_time);
                      }
                    } else if (this.readyState == 4 && this.status != 200) {
                      var response = JSON.parse(this.response);
                      otp_entered = otp_entered + 1;
                      try {
                        var temp_div = document.getElementById("resend-email-div");
                        if (temp_div && temp_div.parentElement) {
                          temp_div.parentElement.removeChild(temp_div);
                        }
                      } catch (error) { }
                      setTimeout(function () {
                        body.removeChild(spinningDiv);
                        var questionDIv = document.createElement("DIV");
                        if (currentMailSequence) {
                          questionDIv.id =
                            "radio-question-div-" + currentMailSequence;
                        } else {
                          questionDIv.id = "radio-question-div-" + 0;
                        }
                        questionDIv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          questionDIv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          questionDIv.classList.add(font);
                        }
                        var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon1);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon1.src = avatar_icon;
                        ques_icon1.classList.add("question-icon-smatest");
                        var option_div = document.createElement("DIV");
                        option_div.classList.add("options-div-smatest");
                        var option_question = document.createElement("LABEL");
                        if (font && font.length > 0) {
                          option_question.classList.add(font);
                        }
                        if (
                          (main_lang_code &&
                            (main_lang_code == "he" ||
                              main_lang_code == "ur" ||
                              main_lang_code == "ar")) ||
                          (main_lang_code == "default" &&
                            (language_code == "ar" ||
                              language_code == "he" ||
                              language_code == "ur"))
                        ) {
                          option_question.classList.add("rtl");
                        }
                        option_question.innerHTML =
                          "<div>" + response.message + "</div>";
                        say(option_question.innerText);
                        option_div.appendChild(option_question);
                        questionDIv.appendChild(iconDiv);
                        var resend_div = document.createElement("DIV");
                        resend_div.id = "resend-email-div";
                        resend_div.classList.add("file-input-div");
                        resend_div.classList.add("pull-left");
                        resend_div.classList.add("full-width");
                        resend_div.classList.add("text-center");
                        var resend_label = document.createElement("LABEL");
                        var resend_span = document.createElement("SPAN");
                        resend_span.innerHTML = "Resend OTP";
                        resend_span.classList.add("p-r-12");
                        resend_label.appendChild(resend_span);
                        resend_label.htmlFor = "capture-input";
                        resend_label.classList.add("upload-button-sb");
                        if (!agreed) {
                          resend_label.classList.add("no-pointer-events");
                        }
                        var otp_remaining_time = 45;
                        var otp_time = document.createElement("LABEL");
                        otp_time.classList.add("pull-left");
                        otp_time.classList.add("full-width");
                        otp_time.classList.add("text-center");
                        otp_time.classList.add("m-t-5");
                        otp_time.classList.add("m-b-10");
                        if (font && font.length > 0) {
                          otp_time.classList.add(font);
                        }
                        otp_time.classList.add("limegreen");
                        otp_time.innerHTML = otp_remaining_time + "s Remaining";
                        var change_email_label = document.createElement("LABEL");
                        var change_email_span = document.createElement("SPAN");
                        change_email_span.innerHTML = "Change Email";
                        change_email_span.classList.add("p-r-12");
                        change_email_label.appendChild(change_email_span);
                        change_email_label.htmlFor = "capture-input";
                        change_email_label.classList.add("upload-button-sb");
                        if (!agreed) {
                          change_email_label.classList.add("no-pointer-events");
                        }
                        var otp_sent = 0;
                        var shouldStopChecking;
                        setInterval(function () {
                          if (!shouldStopChecking) {
                            otp_remaining_time = otp_remaining_time - 1;
                            otp_time.innerHTML = otp_remaining_time + "s Remaining";
                            if (otp_remaining_time == 5) {
                              otp_time.classList.remove("limegreen");
                              otp_time.classList.add("red");
                            }
                            if (otp_remaining_time == 0) {
                              shouldStopChecking = !0;
                              if (resend_div.contains(otp_time)) {
                                resend_div.removeChild(otp_time);
                              }
                              if (resend_div.contains(resend_label)) {
                                resend_div.removeChild(resend_label);
                              }
                              if (resend_div.contains(change_email_label)) {
                                resend_div.removeChild(change_email_label);
                              }
                              otp_sent = otp_sent + 1;
                            }
                          }
                        }, 1000);
                        resend_label.addEventListener("click", function (k) {
                          otp_remaining_time = 45;
                          resend_div.removeChild(resend_label);
                          resend_div.removeChild(change_email_label);
                          resend_div.appendChild(otp_time);
                          var phoneXhttp = new XMLHttpRequest();
                          phoneXhttp.onreadystatechange = function () {
                            resend_span.innerHTML = "Resending OTP";
                            resend_label.classList.add("no-pointer-events");
                            resend_label.classList.add("bg-lightgray");
                            if (this.readyState == 4 && this.status == 200) {
                              var response = JSON.parse(this.response);
                              email_timestamp = response.timestamp;
                              if (response && response.status) {
                                resend_label.classList.remove("bg-lightgray");
                                resend_label.classList.remove("no-pointer-events");
                                resend_span.innerHTML = "Resend OTP";
                                footer.style.display = "block";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                                footer.classList.remove("close");
                                if (shouldShowMenu) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                }
                                input.focus();
                                input_value = "";
                                handleResendOTPCase(response);
                              } else {
                                resend_label.classList.remove("bg-lightgray");
                                resend_label.classList.remove("no-pointer-events");
                                resend_span.innerHTML = "Resend OTP";
                                setTimeout(function () {
                                  input_value = "";
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                  footer.classList.remove("close");
                                  body.removeChild(spinningDiv);
                                  enter.style.pointerEvents = "auto";
                                  var errorDiv = document.createElement("DIV");
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  errorDiv.classList.add("question-div-smatest");
                                  setTimeout(function () {
                                    errorDiv.classList.add("top-0");
                                  }, transition_time);
                                  if (font && font.length > 0) {
                                    errorDiv.classList.add(font);
                                  }
                                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                  error_icon.src = avatar_icon;
                                  var iconDiv = document.createElement("DIV");
                                  iconDiv.appendChild(error_icon);
                                  iconDiv.classList.add("question-icon-div");
                                  error_icon.classList.add("question-icon-smatest");
                                  var error_text = document.createElement("LABEL");
                                  var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                  if (matched && matched.length > 0) {
                                    error_text.innerHTML = matched;
                                    say(error_text.innerText);
                                    if (
                                      (main_lang_code &&
                                        (main_lang_code == "he" ||
                                          main_lang_code == "ur" ||
                                          main_lang_code == "ar")) ||
                                      (main_lang_code == "default" &&
                                        (language_code == "ar" ||
                                          language_code == "he" ||
                                          language_code == "ur"))
                                    ) {
                                      error_text.classList.add("rtl");
                                      error_text.style.textAlign = "right";
                                    }
                                  } else {
                                    error_text.innerHTML =
                                      question_array[0].error_text;
                                    say(error_text.innerText);
                                  }
                                  error_text.classList.add("question-text-error");
                                  error_text.classList.add("options-div-smatest");
                                  if (font && font.length > 0) {
                                    error_text.classList.add(font);
                                  }
                                  errorDiv.appendChild(iconDiv);
                                  errorDiv.appendChild(error_text);
                                  body.appendChild(errorDiv);
                                  playBotUserSound(1);
                                  body.scrollTop = body.scrollHeight;
                                }, delay_time);
                              }
                            } else if (this.readyState == 4 && this.status != 200) {
                              var response = JSON.parse(this.response);
                              resend_label.classList.remove("bg-lightgray");
                              resend_label.classList.remove("no-pointer-events");
                              resend_span.innerHTML = "Resend OTP";
                              setTimeout(function () {
                                input_value = "";
                                footer.style.display = "block";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                                if (shouldShowMenu) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                }
                                input.focus();
                                footer.classList.remove("close");
                                body.removeChild(spinningDiv);
                                enter.style.pointerEvents = "auto";
                                var errorDiv = document.createElement("DIV");
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                errorDiv.classList.add("question-div-smatest");
                                setTimeout(function () {
                                  errorDiv.classList.add("top-0");
                                }, transition_time);
                                if (font && font.length > 0) {
                                  errorDiv.classList.add(font);
                                }
                                var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                error_icon.src = avatar_icon;
                                var iconDiv = document.createElement("DIV");
                                iconDiv.appendChild(error_icon);
                                iconDiv.classList.add("question-icon-div");
                                error_icon.classList.add("question-icon-smatest");
                                var error_text = document.createElement("LABEL");
                                var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                if (matched && matched.length > 0) {
                                  error_text.innerHTML = matched;
                                  say(error_text.innerText);
                                  if (
                                    (main_lang_code &&
                                      (main_lang_code == "he" ||
                                        main_lang_code == "ur" ||
                                        main_lang_code == "ar")) ||
                                    (main_lang_code == "default" &&
                                      (language_code == "ar" ||
                                        language_code == "he" ||
                                        language_code == "ur"))
                                  ) {
                                    error_text.classList.add("rtl");
                                    error_text.style.textAlign = "right";
                                  }
                                } else {
                                  error_text.innerHTML =
                                    question_array[0].error_text;
                                  say(error_text.innerText);
                                }
                                error_text.classList.add("question-text-error");
                                error_text.classList.add("options-div-smatest");
                                if (font && font.length > 0) {
                                  error_text.classList.add(font);
                                }
                                errorDiv.appendChild(iconDiv);
                                errorDiv.appendChild(error_text);
                                body.appendChild(errorDiv);
                                playBotUserSound(1);
                                body.scrollTop = body.scrollHeight;
                              }, delay_time);
                            }
                          };
                          phoneXhttp.open(
                            "POST",
                            main_url + "/kya_backend/runtimeUtils/Emailvalidate",
                            !0
                          );
                          phoneXhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          phoneXhttp.send(
                            "email=" +
                            alredyThereEmail +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&cb_session=" +
                            cb_session
                          );
                        });
                        change_email_label.addEventListener("click", function (k) {
                          current_question_type = "email";
                          footer.style.display = "block";
                          email_otp_validated = !0;
                          input.placeholder = "Enter your email again";
                          option_div.removeChild(resend_div);
                          addTextDivToBot("Please enter the email again");
                        });
                        resend_div.appendChild(resend_label);
                        resend_div.appendChild(change_email_label);
                        option_div.appendChild(resend_div);
                        questionDIv.appendChild(option_div);
                        body.appendChild(questionDIv);
                        body.scrollTop = body.scrollHeight;
                        footer.style.display = "block";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                        footer.classList.remove("close");
                        if (shouldShowMenu) {
                          input.style.pointerEvents = "auto";
                          microphone.style.pointerEvents = "auto";
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = "auto";
                        }
                        input.focus();
                      }, delay_time);
                    }
                  };
                  otpXhttp.open(
                    "POST",
                    main_url + "/kya_backend/runtimeUtils/Emailverify",
                    !0
                  );
                  otpXhttp.setRequestHeader(
                    "Content-type",
                    "application/x-www-form-urlencoded"
                  );
                  otpXhttp.send(
                    "chatbot_id=" +
                    chatbot_id +
                    "&timestamp=" +
                    email_timestamp +
                    "&otp=" +
                    input_value +
                    "&email=" +
                    alredyThereEmail +
                    "&cb_session=" +
                    cb_session
                  );
                } else {
                  var arr = input_value.split("@");
                  var regexSpecial = /[ !@#%$^&*()+\-=\[\]{};':"\\|,<>\/?]/;
                  var allNumber = /^\d+$/;
                  var atleastAlpha = /^.*[a-zA-Z]/;
                  if (
                    current_question_type == "email" &&
                    /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(
                      input_value
                    ) &&
                    arr[0].length > 1 &&
                    arr[0].length < 31 &&
                    !regexSpecial.test(arr[0]) &&
                    arr[0].substring(arr[0].length - 1, arr[0].length) != "." &&
                    !allNumber.test(arr[0]) &&
                    atleastAlpha.test(arr[0])
                  ) {
                    var shouldProceed;
                    if (company_email_validation) {
                      var reg =
                        /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!yahoo.co.in)(?!aol.com)(?!abc.com)(?!xyz.com)(?!pqr.com)(?!rediffmail.com)(?!live.com)(?!outlook.com)(?!me.com)(?!msn.com)(?!ymail.com)(?!yahoo.in)(?!gmail.in)(?!hotmail.in)(?!outlook.in)(?!rediff.co.in)(?!rediff.com)([\w-]+\.)+[\w-]{2,4})?$/;
                      if (reg.test(input_value)) {
                        shouldProceed = !0;
                      } else {
                        shouldProceed = !1;
                      }
                    } else {
                      shouldProceed = !0;
                    }
                    if (shouldProceed) {
                      if (email_otp_validated) {
                        alredyThereEmail = input_value;
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        var otherSpinningDiv = document.createElement("DIV");
                        otherSpinningDiv.classList.add("question-div-smatest");
                        otherSpinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          otherSpinningDiv.classList.add(font);
                        }
                        var otherSpinnerDiv = document.createElement("DIV");
                        otherSpinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        otherSpinnerDiv.appendChild(inner1);
                        otherSpinnerDiv.appendChild(inner2);
                        otherSpinnerDiv.appendChild(inner3);
                        otherSpinningDiv.appendChild(iconDiv);
                        otherSpinningDiv.appendChild(otherSpinnerDiv);
                        body.appendChild(otherSpinningDiv);
                        body.scrollTop = body.scrollHeight;
                        var emailOtpXhttp = new XMLHttpRequest();
                        emailOtpXhttp.onreadystatechange = function () {
                          if (this.readyState == 4 && this.status == 200) {
                            if (body.contains(otherSpinningDiv)) {
                              body.removeChild(otherSpinningDiv);
                            }
                            var response = JSON.parse(this.responseText);
                            if (response.status == !1 && response.code == 301) {
                              var spinningDiv = document.createElement("DIV");
                              spinningDiv.classList.add("question-div-smatest");
                              spinningDiv.classList.add("top-0");
                              if (font && font.length > 0) {
                                spinningDiv.classList.add(font);
                              }
                              var spinnerDiv = document.createElement("DIV");
                              spinnerDiv.classList.add("spinner1-smatest");
                              var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                              ques_icon.src = avatar_icon;
                              var iconDiv = document.createElement("DIV");
                              iconDiv.appendChild(ques_icon);
                              iconDiv.classList.add("question-icon-div");
                              ques_icon.classList.add("question-icon-smatest");
                              var inner1 = document.createElement("DIV");
                              inner1.classList.add("bounce1");
                              var inner2 = document.createElement("DIV");
                              inner2.classList.add("bounce2");
                              var inner3 = document.createElement("DIV");
                              inner3.classList.add("bounce3");
                              spinnerDiv.appendChild(inner1);
                              spinnerDiv.appendChild(inner2);
                              spinnerDiv.appendChild(inner3);
                              spinningDiv.appendChild(iconDiv);
                              spinningDiv.appendChild(spinnerDiv);
                              body.appendChild(spinningDiv);
                              body.scrollTop = body.scrollHeight;
                              inTheMiddle = !0;
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  shouldDisableTakeAction = !1;
                                  question_and_answers.push({
                                    id: question_id,
                                    answer: input_value,
                                  });
                                  entered = !1;
                                  if (currentQuestionIsLead == "1" && !mailSent) {
                                    sendAlertCall();
                                  } else {
                                    if (mailSequence < currentMailSequence) {
                                      random_key = !0;
                                    } else {
                                      random_key = !1;
                                    }
                                  }
                                  cb_session = JSON.parse(this.response).cb_session;
                                  live_chat_cb_session = JSON.parse(
                                    this.response
                                  ).livechat_session;
                                  if (
                                    JSON.parse(this.response).language_code &&
                                    JSON.parse(this.response).language_code.length >
                                    0
                                  ) {
                                    main_lang_code = JSON.parse(
                                      this.response
                                    ).language_code;
                                  }
                                  session_feedback = JSON.parse(
                                    this.response
                                  ).feedback;
                                  question_array = JSON.parse(
                                    this.response
                                  ).next_question;
                                  if (question_array && question_array.length > 0) {
                                    question_completed = !1;
                                    input_value = "";
                                    setTimeout(function () {
                                      enter.style.pointerEvents = "auto";
                                      if (
                                        spinningDiv &&
                                        spinningDiv.parentNode == body
                                      ) {
                                        body.removeChild(spinningDiv);
                                      }
                                      current_question_type =
                                        question_array[0].type;
                                      current_logical_jump =
                                        question_array[0].logical_jump;
                                      currentMailSequence =
                                        question_array[0].sequence;
                                      question_id = question_array[0].id;
                                      currentQuestionIsLead =
                                        question_array[0].send_mail;
                                      setAllInputs(question_array);
                                      assignAllQuestionTypes(current_question_type);
                                    }, delay_time);
                                  } else {
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    enter.style.pointerEvents = "auto";
                                    question_completed = !0;
                                    if (!mailSent || mailSent) {
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                          var questionArray = [];
                                          prev_questions_array = JSON.parse(
                                            this.response
                                          ).qna_prev;
                                          if (
                                            prev_questions_array &&
                                            prev_questions_array.length > 0
                                          ) {
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              if (
                                                prev_questions_array[i].type ==
                                                "contact" ||
                                                prev_questions_array[i].type ==
                                                "slides" ||
                                                prev_questions_array[i].type ==
                                                "statement" ||
                                                prev_questions_array[i].type ==
                                                "url_auto_redirect" ||
                                                prev_questions_array[i].type ==
                                                "custom_answer" ||
                                                prev_questions_array[i].type ==
                                                "show_file" ||
                                                prev_questions_array[i].type ==
                                                "show_contacts" ||
                                                prev_questions_array[i].type ==
                                                "show_location"
                                              ) {
                                                prev_questions_array.splice(i, 1);
                                                i--;
                                              }
                                            }
                                            if (
                                              zapier_webhook &&
                                              zapier_webhook.length > 0
                                            ) {
                                              var output = {};
                                              output.timestamp = new Date();
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                var str =
                                                  prev_questions_array[i]
                                                    .question_text;
                                                output[str] =
                                                  prev_questions_array[
                                                    i
                                                  ].answer_text;
                                              }
                                              var xhttp = new XMLHttpRequest();
                                              xhttp.onreadystatechange =
                                                function () {
                                                  if (
                                                    this.readyState == 4 &&
                                                    this.status == 200
                                                  ) {
                                                  }
                                                };
                                              xhttp.open(
                                                "POST",
                                                zapier_webhook,
                                                !0
                                              );
                                              xhttp.setRequestHeader(
                                                "Content-type",
                                                "application/x-www-form-urlencoded"
                                              );
                                              xhttp.send(
                                                "output=" + JSON.stringify(output)
                                              );
                                            }
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              questionArray.push({
                                                question:
                                                  prev_questions_array[i]
                                                    .question_text,
                                                answer:
                                                  prev_questions_array[i]
                                                    .answer_text,
                                              });
                                            }
                                          }
                                        }
                                      };
                                      xhttp.open(
                                        "POST",
                                        main_url +
                                        "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                        !0
                                      );
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      if (
                                        main_lang_code &&
                                        main_lang_code.length > 0 &&
                                        main_lang_code != language_code
                                      ) {
                                      } else {
                                        main_lang_code = "default";
                                      }
                                      var bot_widget_obj;
                                      var is_sendable;
                                      if (
                                        window.botWidget &&
                                        window.botWidget.user
                                      ) {
                                        var keys = Object.keys(
                                          window.botWidget.user
                                        );
                                        for (var t = 0; t < keys.length; t++) {
                                          if (
                                            window.botWidget.user[keys[t]] &&
                                            window.botWidget.user[keys[t]].length >
                                            0
                                          ) {
                                            is_sendable = true;
                                          }
                                        }
                                        if (is_sendable) {
                                          bot_widget_obj = window.botWidget.user;
                                        } else {
                                          bot_widget_obj = "";
                                        }
                                        if (window.botWidget.user.bot_id) {
                                          delete window.botWidget.user.bot_id;
                                        }
                                        if (window.botWidget.user.url) {
                                          delete window.botWidget.user.url;
                                        }
                                      }
                                      xhttp.send(
                                        "action=init_chat&device_print=" +
                                        device_print +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&language_code=" +
                                        main_lang_code +
                                        "&bot_widget_obj=" +
                                        JSON.stringify(bot_widget_obj)
                                      );
                                    } else {
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                          var questionArray = [];
                                          prev_questions_array = JSON.parse(
                                            this.response
                                          ).qna_prev;
                                          if (
                                            prev_questions_array &&
                                            prev_questions_array.length > 0
                                          ) {
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              if (
                                                prev_questions_array[i].type ==
                                                "contact" ||
                                                prev_questions_array[i].type ==
                                                "slides" ||
                                                prev_questions_array[i].type ==
                                                "statement" ||
                                                prev_questions_array[i].type ==
                                                "url_auto_redirect" ||
                                                prev_questions_array[i].type ==
                                                "custom_answer" ||
                                                prev_questions_array[i].type ==
                                                "show_file" ||
                                                prev_questions_array[i].type ==
                                                "show_contacts" ||
                                                prev_questions_array[i].type ==
                                                "show_location"
                                              ) {
                                                prev_questions_array.splice(i, 1);
                                                i--;
                                              }
                                            }
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              questionArray.push({
                                                question:
                                                  prev_questions_array[i]
                                                    .question_text,
                                                answer:
                                                  prev_questions_array[i]
                                                    .answer_text,
                                              });
                                            }
                                          }
                                        }
                                      };
                                      xhttp.open(
                                        "POST",
                                        main_url +
                                        "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                        !0
                                      );
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      if (
                                        main_lang_code &&
                                        main_lang_code.length > 0 &&
                                        main_lang_code != language_code
                                      ) {
                                      } else {
                                        main_lang_code = "default";
                                      }
                                      var bot_widget_obj;
                                      var is_sendable;
                                      if (
                                        window.botWidget &&
                                        window.botWidget.user
                                      ) {
                                        var keys = Object.keys(
                                          window.botWidget.user
                                        );
                                        for (var t = 0; t < keys.length; t++) {
                                          if (
                                            window.botWidget.user[keys[t]] &&
                                            window.botWidget.user[keys[t]].length >
                                            0
                                          ) {
                                            is_sendable = true;
                                          }
                                        }
                                        if (is_sendable) {
                                          bot_widget_obj = window.botWidget.user;
                                        } else {
                                          bot_widget_obj = "";
                                        }
                                        if (window.botWidget.user.bot_id) {
                                          delete window.botWidget.user.bot_id;
                                        }
                                        if (window.botWidget.user.url) {
                                          delete window.botWidget.user.url;
                                        }
                                      }
                                      xhttp.send(
                                        "action=init_chat&device_print=" +
                                        device_print +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&language_code=" +
                                        main_lang_code +
                                        "&bot_widget_obj=" +
                                        JSON.stringify(bot_widget_obj)
                                      );
                                    }
                                    if (!entry_id) {
                                      showInput = !0;
                                      if (!shouldShowMenu) {
                                        footer.style.display = "none";
                                        footer.classList.add("close");
                                      } else {
                                        if (entry_id) {
                                          input.style.pointerEvents = "auto";
                                          microphone.style.pointerEvents = "auto";
                                          microphone.style.opacity = 1;
                                          enter.style.pointerEvents = "auto";
                                          setPlaceHolders();
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                        } else {
                                          input.style.pointerEvents = "none";
                                          microphone.style.pointerEvents = "none";
                                          microphone.style.opacity = 0;
                                          input.blur();
                                          enter.style.pointerEvents = "none";
                                          input.placeholder = "Choose from Menu";
                                        }
                                      }
                                    }
                                    if (!shouldShowMenu) {
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 168px)";
                                      } else {
                                        body.style.height = "calc(100% - 93px)";
                                      }
                                    } else {
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              if (
                                current_logical_jump == "1" &&
                                current_question_type != "radio" &&
                                current_question_type != "rating"
                              ) {
                                xhttp.send(
                                  "action=answer&answer_text=" +
                                  encodeURIComponent(input_value) +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id +
                                  "&is_logical=" +
                                  current_logical_jump +
                                  "&sequence=" +
                                  currentMailSequence +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&option=" +
                                  "sometext&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              } else {
                                xhttp.send(
                                  "action=answer&answer_text=" +
                                  encodeURIComponent(input_value) +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id +
                                  "&is_logical=" +
                                  current_logical_jump +
                                  "&sequence=" +
                                  currentMailSequence +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&option=" +
                                  encodeURIComponent(input_value) +
                                  "&visitor_link_traversal=" +
                                  visitedUrls +
                                  "&language_code=" +
                                  main_lang_code
                                );
                              }
                            } else {
                              email_timestamp = response.timestamp;
                              var spinningDiv = document.createElement("DIV");
                              spinningDiv.classList.add("question-div-smatest");
                              spinningDiv.classList.add("top-0");
                              if (font && font.length > 0) {
                                spinningDiv.classList.add(font);
                              }
                              var spinnerDiv = document.createElement("DIV");
                              spinnerDiv.classList.add("spinner1-smatest");
                              var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                              ques_icon.src = avatar_icon;
                              var iconDiv = document.createElement("DIV");
                              iconDiv.appendChild(ques_icon);
                              iconDiv.classList.add("question-icon-div");
                              ques_icon.classList.add("question-icon-smatest");
                              var inner1 = document.createElement("DIV");
                              inner1.classList.add("bounce1");
                              var inner2 = document.createElement("DIV");
                              inner2.classList.add("bounce2");
                              var inner3 = document.createElement("DIV");
                              inner3.classList.add("bounce3");
                              spinnerDiv.appendChild(inner1);
                              spinnerDiv.appendChild(inner2);
                              spinnerDiv.appendChild(inner3);
                              spinningDiv.appendChild(iconDiv);
                              spinningDiv.appendChild(spinnerDiv);
                              body.appendChild(spinningDiv);
                              body.scrollTop = body.scrollHeight;
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                footer.style.display = "block";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                                footer.classList.remove("close");
                                if (shouldShowMenu) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                }
                                input.focus();
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                var errorDiv = document.createElement("DIV");
                                errorDiv.classList.add("question-div-smatest");
                                setTimeout(function () {
                                  errorDiv.classList.add("top-0");
                                }, transition_time);
                                if (font && font.length > 0) {
                                  errorDiv.classList.add(font);
                                }
                                var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                error_icon.src = avatar_icon;
                                var iconDiv = document.createElement("DIV");
                                iconDiv.appendChild(error_icon);
                                iconDiv.classList.add("question-icon-div");
                                error_icon.classList.add("question-icon-smatest");
                                var option_div = document.createElement("DIV");
                                option_div.classList.add("options-div-smatest");
                                var option_question =
                                  document.createElement("LABEL");
                                if (font && font.length > 0) {
                                  option_question.classList.add(font);
                                }
                                if (
                                  (main_lang_code &&
                                    (main_lang_code == "he" ||
                                      main_lang_code == "ur" ||
                                      main_lang_code == "ar")) ||
                                  (main_lang_code == "default" &&
                                    (language_code == "ar" ||
                                      language_code == "he" ||
                                      language_code == "ur"))
                                ) {
                                  option_question.classList.add("rtl");
                                }
                                option_question.innerHTML =
                                  "<div>" + response.message + "</div>";
                                say(option_question.innerText);
                                option_div.appendChild(option_question);
                                var resend_div = document.createElement("DIV");
                                resend_div.id = "resend-email-div";
                                resend_div.classList.add("file-input-div");
                                resend_div.classList.add("pull-left");
                                resend_div.classList.add("full-width");
                                resend_div.classList.add("text-center");
                                var otp_remaining_time = 45;
                                var otp_time = document.createElement("LABEL");
                                otp_time.classList.add("pull-left");
                                otp_time.classList.add("full-width");
                                otp_time.classList.add("text-center");
                                otp_time.classList.add("m-t-5");
                                otp_time.classList.add("m-b-10");
                                if (font && font.length > 0) {
                                  otp_time.classList.add(font);
                                }
                                otp_time.classList.add("limegreen");
                                otp_time.innerHTML =
                                  otp_remaining_time + "s Remaining";
                                resend_div.appendChild(otp_time);
                                var resend_label = document.createElement("LABEL");
                                var resend_span = document.createElement("SPAN");
                                resend_span.innerHTML = "Resend OTP";
                                resend_span.classList.add("p-r-12");
                                resend_label.appendChild(resend_span);
                                resend_label.htmlFor = "capture-input";
                                resend_label.classList.add("upload-button-sb");
                                if (!agreed) {
                                  resend_label.classList.add("no-pointer-events");
                                }
                                var change_email_label =
                                  document.createElement("LABEL");
                                var change_email_span =
                                  document.createElement("SPAN");
                                change_email_span.innerHTML = "Change Email";
                                change_email_span.classList.add("p-r-12");
                                change_email_label.appendChild(change_email_span);
                                change_email_label.htmlFor = "capture-input";
                                change_email_label.classList.add(
                                  "upload-button-sb"
                                );
                                if (!agreed) {
                                  change_email_label.classList.add(
                                    "no-pointer-events"
                                  );
                                }
                                var otp_sent = 0;
                                var shouldStopChecking;
                                setInterval(function () {
                                  if (!shouldStopChecking) {
                                    otp_remaining_time = otp_remaining_time - 1;
                                    otp_time.innerHTML =
                                      otp_remaining_time + "s Remaining";
                                    if (otp_remaining_time == 5) {
                                      otp_time.classList.remove("limegreen");
                                      otp_time.classList.add("red");
                                    }
                                    if (otp_remaining_time == 0) {
                                      shouldStopChecking = !0;
                                      if (resend_div.contains(otp_time)) {
                                        resend_div.removeChild(otp_time);
                                      }
                                      if (resend_div.contains(resend_label)) {
                                        resend_div.removeChild(resend_label);
                                      }
                                      if (resend_div.contains(change_email_label)) {
                                        resend_div.removeChild(change_email_label);
                                      }
                                      otp_sent = otp_sent + 1;
                                    }
                                  }
                                }, 1000);
                                resend_label.addEventListener(
                                  "click",
                                  function (k) {
                                    var phoneXhttp = new XMLHttpRequest();
                                    phoneXhttp.onreadystatechange = function () {
                                      resend_span.innerHTML = "Resending OTP";
                                      resend_label.classList.add(
                                        "no-pointer-events"
                                      );
                                      resend_label.classList.add("bg-lightgray");
                                      if (
                                        this.readyState == 4 &&
                                        this.status == 200
                                      ) {
                                        var response = JSON.parse(this.response);
                                        if (response && response.status) {
                                          email_timestamp = response.timestamp;
                                          resend_label.classList.remove(
                                            "bg-lightgray"
                                          );
                                          resend_label.classList.remove(
                                            "no-pointer-events"
                                          );
                                          resend_span.innerHTML = "Resend OTP";
                                          footer.style.display = "block";
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                          footer.classList.remove("close");
                                          if (shouldShowMenu) {
                                            input.style.pointerEvents = "auto";
                                            microphone.style.pointerEvents = "auto";
                                            microphone.style.opacity = 1;
                                            enter.style.pointerEvents = "auto";
                                          }
                                          input_value = "";
                                          input.focus();
                                          handleResendOTPCase(response);
                                        } else {
                                          resend_label.classList.remove(
                                            "bg-lightgray"
                                          );
                                          resend_label.classList.remove(
                                            "no-pointer-events"
                                          );
                                          resend_span.innerHTML = "Resend OTP";
                                          setTimeout(function () {
                                            input_value = "";
                                            footer.style.display = "block";
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 218px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 143px)";
                                            }
                                            footer.classList.remove("close");
                                            if (shouldShowMenu) {
                                              input.style.pointerEvents = "auto";
                                              microphone.style.pointerEvents =
                                                "auto";
                                              microphone.style.opacity = 1;
                                              enter.style.pointerEvents = "auto";
                                            }
                                            input.focus();
                                            body.removeChild(spinningDiv);
                                            enter.style.pointerEvents = "auto";
                                            var errorDiv =
                                              document.createElement("DIV");
                                            current_logical_jump =
                                              question_array[0].logical_jump;
                                            currentMailSequence =
                                              question_array[0].sequence;
                                            currentQuestionIsLead =
                                              question_array[0].send_mail;
                                            errorDiv.classList.add(
                                              "question-div-smatest"
                                            );
                                            setTimeout(function () {
                                              errorDiv.classList.add("top-0");
                                            }, transition_time);
                                            if (font && font.length > 0) {
                                              errorDiv.classList.add(font);
                                            }
                                            var error_icon =
                                              document.createElement("IMG");
                                            error_icon.src = avatar_icon;
                                            error_icon.alt = "Logo of " + totalData[0].name;
                                            var iconDiv =
                                              document.createElement("DIV");
                                            iconDiv.appendChild(error_icon);
                                            iconDiv.classList.add(
                                              "question-icon-div"
                                            );
                                            error_icon.classList.add(
                                              "question-icon-smatest"
                                            );
                                            var error_text =
                                              document.createElement("LABEL");
                                            var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                            if (matched && matched.length > 0) {
                                              error_text.innerHTML = matched;
                                              say(error_text.innerText);
                                              if (
                                                (main_lang_code &&
                                                  (main_lang_code == "he" ||
                                                    main_lang_code == "ur" ||
                                                    main_lang_code == "ar")) ||
                                                (main_lang_code == "default" &&
                                                  (language_code == "ar" ||
                                                    language_code == "he" ||
                                                    language_code == "ur"))
                                              ) {
                                                error_text.classList.add("rtl");
                                                error_text.style.textAlign =
                                                  "right";
                                              }
                                            } else {
                                              error_text.innerHTML =
                                                question_array[0].error_text;
                                              say(error_text.innerText);
                                            }
                                            error_text.classList.add(
                                              "question-text-error"
                                            );
                                            error_text.classList.add(
                                              "options-div-smatest"
                                            );
                                            if (font && font.length > 0) {
                                              error_text.classList.add(font);
                                            }
                                            errorDiv.appendChild(iconDiv);
                                            errorDiv.appendChild(error_text);
                                            body.appendChild(errorDiv);
                                            playBotUserSound(1);
                                            body.scrollTop = body.scrollHeight;
                                          }, delay_time);
                                        }
                                      } else if (
                                        this.readyState == 4 &&
                                        this.status != 200
                                      ) {
                                        var response = JSON.parse(this.response);
                                        resend_label.classList.remove(
                                          "bg-lightgray"
                                        );
                                        resend_label.classList.remove(
                                          "no-pointer-events"
                                        );
                                        resend_span.innerHTML = "Resend OTP";
                                        setTimeout(function () {
                                          input_value = "";
                                          footer.style.display = "block";
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                          footer.classList.remove("close");
                                          if (shouldShowMenu) {
                                            input.style.pointerEvents = "auto";
                                            microphone.style.pointerEvents = "auto";
                                            microphone.style.opacity = 1;
                                            enter.style.pointerEvents = "auto";
                                          }
                                          input.focus();
                                          body.removeChild(spinningDiv);
                                          enter.style.pointerEvents = "auto";
                                          var errorDiv =
                                            document.createElement("DIV");
                                          current_logical_jump =
                                            question_array[0].logical_jump;
                                          currentMailSequence =
                                            question_array[0].sequence;
                                          currentQuestionIsLead =
                                            question_array[0].send_mail;
                                          errorDiv.classList.add(
                                            "question-div-smatest"
                                          );
                                          setTimeout(function () {
                                            errorDiv.classList.add("top-0");
                                          }, transition_time);
                                          if (font && font.length > 0) {
                                            errorDiv.classList.add(font);
                                          }
                                          var error_icon =
                                            document.createElement("IMG");
                                          error_icon.src = avatar_icon;
                                          error_icon.alt = "Logo of " + totalData[0].name;
                                          var iconDiv =
                                            document.createElement("DIV");
                                          iconDiv.appendChild(error_icon);
                                          iconDiv.classList.add(
                                            "question-icon-div"
                                          );
                                          error_icon.classList.add(
                                            "question-icon-smatest"
                                          );
                                          var error_text =
                                            document.createElement("LABEL");
                                          var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                          if (matched && matched.length > 0) {
                                            error_text.innerHTML = matched;
                                            say(error_text.innerText);
                                            if (
                                              (main_lang_code &&
                                                (main_lang_code == "he" ||
                                                  main_lang_code == "ur" ||
                                                  main_lang_code == "ar")) ||
                                              (main_lang_code == "default" &&
                                                (language_code == "ar" ||
                                                  language_code == "he" ||
                                                  language_code == "ur"))
                                            ) {
                                              error_text.classList.add("rtl");
                                              error_text.style.textAlign = "right";
                                            }
                                          } else {
                                            error_text.innerHTML =
                                              question_array[0].error_text;
                                            say(error_text.innerText);
                                          }
                                          error_text.classList.add(
                                            "question-text-error"
                                          );
                                          error_text.classList.add(
                                            "options-div-smatest"
                                          );
                                          if (font && font.length > 0) {
                                            error_text.classList.add(font);
                                          }
                                          errorDiv.appendChild(iconDiv);
                                          errorDiv.appendChild(error_text);
                                          body.appendChild(errorDiv);
                                          playBotUserSound(1);
                                          body.scrollTop = body.scrollHeight;
                                        }, delay_time);
                                      }
                                    };
                                    phoneXhttp.open(
                                      "POST",
                                      main_url +
                                      "/kya_backend/runtimeUtils/Emailvalidate",
                                      !0
                                    );
                                    phoneXhttp.setRequestHeader(
                                      "Content-type",
                                      "application/x-www-form-urlencoded"
                                    );
                                    phoneXhttp.send(
                                      "email=" +
                                      alredyThereEmail +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&cb_session=" +
                                      cb_session
                                    );
                                  }
                                );
                                change_email_label.addEventListener(
                                  "click",
                                  function (k) {
                                    current_question_type = "email";
                                    footer.style.display = "block";
                                    email_otp_validated = !0;
                                    input.placeholder = "Enter your email again";
                                    option_div.removeChild(resend_div);
                                    addTextDivToBot("Please enter the email again");
                                  }
                                );
                                option_div.appendChild(resend_div);
                                errorDiv.appendChild(iconDiv);
                                errorDiv.appendChild(option_div);
                                body.appendChild(errorDiv);
                                playBotUserSound(1);
                                body.scrollTop = body.scrollHeight;
                                footer.style.display = "block";
                                input.placeholder = "Enter the OTP";
                                input.focus();
                              }, 500);
                            }
                          }
                        };
                        emailOtpXhttp.open(
                          "POST",
                          main_url + "/kya_backend/runtimeUtils/Emailvalidate",
                          !0
                        );
                        emailOtpXhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        emailOtpXhttp.send(
                          "email=" +
                          input_value +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&cb_session=" +
                          cb_session
                        );
                      } else {
                        if (strictEmailValidation) {
                          var answerDiv = document.createElement("DIV");
                          answerDiv.classList.add("answer-div");
                          setTimeout(function () {
                            answerDiv.classList.add("top-0");
                          }, transition_time);
                          var answer = document.createElement("LABEL");
                          var answer_text = document.createTextNode(input_value);
                          answer.appendChild(answer_text);
                          answer.classList.add("answer-label");
                          if (font && font.length > 0) {
                            answer.classList.add(font);
                          }
                          answerDiv.appendChild(answer);
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                          var otherSpinningDiv = document.createElement("DIV");
                          otherSpinningDiv.classList.add("question-div-smatest");
                          otherSpinningDiv.classList.add("top-0");
                          if (font && font.length > 0) {
                            otherSpinningDiv.classList.add(font);
                          }
                          var otherSpinnerDiv = document.createElement("DIV");
                          otherSpinnerDiv.classList.add("spinner1-smatest");
                          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                          ques_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(ques_icon);
                          iconDiv.classList.add("question-icon-div");
                          ques_icon.classList.add("question-icon-smatest");
                          var inner1 = document.createElement("DIV");
                          inner1.classList.add("bounce1");
                          var inner2 = document.createElement("DIV");
                          inner2.classList.add("bounce2");
                          var inner3 = document.createElement("DIV");
                          inner3.classList.add("bounce3");
                          otherSpinnerDiv.appendChild(inner1);
                          otherSpinnerDiv.appendChild(inner2);
                          otherSpinnerDiv.appendChild(inner3);
                          otherSpinningDiv.appendChild(iconDiv);
                          otherSpinningDiv.appendChild(otherSpinnerDiv);
                          body.appendChild(otherSpinningDiv);
                          body.scrollTop = body.scrollHeight;
                          var emailVerifyXhttp = new XMLHttpRequest();
                          emailVerifyXhttp.onreadystatechange = function () {
                            if (this.readyState == 4 && this.status == 200) {
                              doneChecking = !0;
                              email_delay = 0;
                              alreadyCheckedEmail = !0;
                              if (body.contains(otherSpinningDiv)) {
                                body.removeChild(otherSpinningDiv);
                              }
                              var response = JSON.parse(this.responseText);
                              if (
                                !(
                                  response &&
                                  response.length > 0 &&
                                  response[0] != null &&
                                  response[0].email_status == !1
                                )
                              ) {
                                prev_email_text = undefined;
                                var spinningDiv = document.createElement("DIV");
                                spinningDiv.classList.add("question-div-smatest");
                                spinningDiv.classList.add("top-0");
                                if (font && font.length > 0) {
                                  spinningDiv.classList.add(font);
                                }
                                var spinnerDiv = document.createElement("DIV");
                                spinnerDiv.classList.add("spinner1-smatest");
                                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                                ques_icon.src = avatar_icon;
                                var iconDiv = document.createElement("DIV");
                                iconDiv.appendChild(ques_icon);
                                iconDiv.classList.add("question-icon-div");
                                ques_icon.classList.add("question-icon-smatest");
                                var inner1 = document.createElement("DIV");
                                inner1.classList.add("bounce1");
                                var inner2 = document.createElement("DIV");
                                inner2.classList.add("bounce2");
                                var inner3 = document.createElement("DIV");
                                inner3.classList.add("bounce3");
                                spinnerDiv.appendChild(inner1);
                                spinnerDiv.appendChild(inner2);
                                spinnerDiv.appendChild(inner3);
                                spinningDiv.appendChild(iconDiv);
                                spinningDiv.appendChild(spinnerDiv);
                                body.appendChild(spinningDiv);
                                body.scrollTop = body.scrollHeight;
                                inTheMiddle = !0;
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    shouldDisableTakeAction = !1;
                                    question_and_answers.push({
                                      id: question_id,
                                      answer: input_value,
                                    });
                                    entered = !1;
                                    if (currentQuestionIsLead == "1" && !mailSent) {
                                      sendAlertCall();
                                    } else {
                                      if (mailSequence < currentMailSequence) {
                                        random_key = !0;
                                      } else {
                                        random_key = !1;
                                      }
                                    }
                                    cb_session = JSON.parse(
                                      this.response
                                    ).cb_session;
                                    live_chat_cb_session = JSON.parse(
                                      this.response
                                    ).livechat_session;
                                    if (
                                      JSON.parse(this.response).language_code &&
                                      JSON.parse(this.response).language_code
                                        .length > 0
                                    ) {
                                      main_lang_code = JSON.parse(
                                        this.response
                                      ).language_code;
                                    }
                                    session_feedback = JSON.parse(
                                      this.response
                                    ).feedback;
                                    question_array = JSON.parse(
                                      this.response
                                    ).next_question;
                                    if (
                                      question_array &&
                                      question_array.length > 0
                                    ) {
                                      question_completed = !1;
                                      input_value = "";
                                      setTimeout(function () {
                                        enter.style.pointerEvents = "auto";
                                        if (
                                          spinningDiv &&
                                          spinningDiv.parentNode == body
                                        ) {
                                          body.removeChild(spinningDiv);
                                        }
                                        current_question_type =
                                          question_array[0].type;
                                        current_logical_jump =
                                          question_array[0].logical_jump;
                                        currentMailSequence =
                                          question_array[0].sequence;
                                        currentQuestionIsLead =
                                          question_array[0].send_mail;
                                        question_id = question_array[0].id;
                                        setAllInputs(question_array);
                                        assignAllQuestionTypes(
                                          current_question_type
                                        );
                                      }, delay_time);
                                    } else {
                                      if (
                                        spinningDiv &&
                                        spinningDiv.parentNode == body
                                      ) {
                                        body.removeChild(spinningDiv);
                                      }
                                      enter.style.pointerEvents = "auto";
                                      question_completed = !0;
                                      if (!mailSent || mailSent) {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              if (
                                                zapier_webhook &&
                                                zapier_webhook.length > 0
                                              ) {
                                                var output = {};
                                                output.timestamp = new Date();
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  var str =
                                                    prev_questions_array[i]
                                                      .question_text;
                                                  output[str] =
                                                    prev_questions_array[
                                                      i
                                                    ].answer_text;
                                                }
                                                var xhttp = new XMLHttpRequest();
                                                xhttp.onreadystatechange =
                                                  function () {
                                                    if (
                                                      this.readyState == 4 &&
                                                      this.status == 200
                                                    ) {
                                                    }
                                                  };
                                                xhttp.open(
                                                  "POST",
                                                  zapier_webhook,
                                                  !0
                                                );
                                                xhttp.setRequestHeader(
                                                  "Content-type",
                                                  "application/x-www-form-urlencoded"
                                                );
                                                xhttp.send(
                                                  "output=" + JSON.stringify(output)
                                                );
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      } else {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      }
                                      if (!entry_id) {
                                        showInput = !0;
                                        if (!shouldShowMenu) {
                                          footer.style.display = "none";
                                          footer.classList.add("close");
                                        } else {
                                          if (entry_id) {
                                            input.style.pointerEvents = "auto";
                                            enter.style.pointerEvents = "auto";
                                            setPlaceHolders();
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 218px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 143px)";
                                            }
                                          } else {
                                            input.style.pointerEvents = "none";
                                            input.blur();
                                            enter.style.pointerEvents = "none";
                                            input.placeholder = "Choose from Menu";
                                          }
                                        }
                                      }
                                      if (!shouldShowMenu) {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 168px)";
                                        } else {
                                          body.style.height = "calc(100% - 93px)";
                                        }
                                      } else {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                if (
                                  current_logical_jump == "1" &&
                                  current_question_type != "radio" &&
                                  current_question_type != "rating"
                                ) {
                                  xhttp.send(
                                    "action=answer&answer_text=" +
                                    encodeURIComponent(input_value) +
                                    "&cb_session=" +
                                    cb_session +
                                    "&question_id=" +
                                    question_id +
                                    "&is_logical=" +
                                    current_logical_jump +
                                    "&sequence=" +
                                    currentMailSequence +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&option=" +
                                    "sometext&visitor_link_traversal=" +
                                    visitedUrls +
                                    "&language_code=" +
                                    main_lang_code
                                  );
                                } else {
                                  xhttp.send(
                                    "action=answer&answer_text=" +
                                    encodeURIComponent(input_value) +
                                    "&cb_session=" +
                                    cb_session +
                                    "&question_id=" +
                                    question_id +
                                    "&is_logical=" +
                                    current_logical_jump +
                                    "&sequence=" +
                                    currentMailSequence +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&option=" +
                                    encodeURIComponent(input_value) +
                                    "&visitor_link_traversal=" +
                                    visitedUrls +
                                    "&language_code=" +
                                    main_lang_code
                                  );
                                }
                              } else {
                                prev_email_text = input_value;
                                footer.style.display = "block";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                                footer.classList.remove("close");
                                if (shouldShowMenu) {
                                  input.style.pointerEvents = "auto";
                                  enter.style.pointerEvents = "auto";
                                }
                                input.focus();
                                body.scrollTop = body.scrollHeight;
                                var spinningDiv = document.createElement("DIV");
                                spinningDiv.classList.add("question-div-smatest");
                                spinningDiv.classList.add("top-0");
                                if (font && font.length > 0) {
                                  spinningDiv.classList.add(font);
                                }
                                var spinnerDiv = document.createElement("DIV");
                                spinnerDiv.classList.add("spinner1-smatest");
                                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                                ques_icon.src = avatar_icon;
                                var iconDiv = document.createElement("DIV");
                                iconDiv.appendChild(ques_icon);
                                iconDiv.classList.add("question-icon-div");
                                ques_icon.classList.add("question-icon-smatest");
                                var inner1 = document.createElement("DIV");
                                inner1.classList.add("bounce1");
                                var inner2 = document.createElement("DIV");
                                inner2.classList.add("bounce2");
                                var inner3 = document.createElement("DIV");
                                inner3.classList.add("bounce3");
                                spinnerDiv.appendChild(inner1);
                                spinnerDiv.appendChild(inner2);
                                spinnerDiv.appendChild(inner3);
                                spinningDiv.appendChild(iconDiv);
                                spinningDiv.appendChild(spinnerDiv);
                                body.appendChild(spinningDiv);
                                body.scrollTop = body.scrollHeight;
                                setTimeout(function () {
                                  enter.style.pointerEvents = "auto";
                                  if (
                                    spinningDiv &&
                                    spinningDiv.parentNode == body
                                  ) {
                                    body.removeChild(spinningDiv);
                                  }
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  var errorDiv = document.createElement("DIV");
                                  errorDiv.classList.add("question-div-smatest");
                                  setTimeout(function () {
                                    errorDiv.classList.add("top-0");
                                  }, transition_time);
                                  if (font && font.length > 0) {
                                    errorDiv.classList.add(font);
                                  }
                                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                  error_icon.src = avatar_icon;
                                  var iconDiv = document.createElement("DIV");
                                  iconDiv.appendChild(error_icon);
                                  iconDiv.classList.add("question-icon-div");
                                  error_icon.classList.add("question-icon-smatest");
                                  var error_text = document.createElement("LABEL");
                                  translateContent(translations, error_text, "Please recheck your email address", main_lang_code, language_code);
                                  say(error_text.innerText);
                                  error_text.classList.add("question-text-error");
                                  error_text.classList.add("options-div-smatest");
                                  if (font && font.length > 0) {
                                    error_text.classList.add(font);
                                  }
                                  errorDiv.appendChild(iconDiv);
                                  errorDiv.appendChild(error_text);
                                  body.appendChild(errorDiv);
                                  playBotUserSound(1);
                                  body.scrollTop = body.scrollHeight;
                                }, 500);
                              }
                            }
                          };
                          emailVerifyXhttp.open(
                            "POST",
                            main_url + "/kya_backend/Kya/validateEmail",
                            !0
                          );
                          emailVerifyXhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          emailVerifyXhttp.send("email=" + input_value);
                        } else {
                          var answerDiv = document.createElement("DIV");
                          answerDiv.classList.add("answer-div");
                          setTimeout(function () {
                            answerDiv.classList.add("top-0");
                          }, transition_time);
                          var answer = document.createElement("LABEL");
                          var answer_text = document.createTextNode(input_value);
                          answer.appendChild(answer_text);
                          answer.classList.add("answer-label");
                          if (font && font.length > 0) {
                            answer.classList.add(font);
                          }
                          answerDiv.appendChild(answer);
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                          var spinningDiv = document.createElement("DIV");
                          spinningDiv.classList.add("question-div-smatest");
                          spinningDiv.classList.add("top-0");
                          if (font && font.length > 0) {
                            spinningDiv.classList.add(font);
                          }
                          var spinnerDiv = document.createElement("DIV");
                          spinnerDiv.classList.add("spinner1-smatest");
                          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                          ques_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(ques_icon);
                          iconDiv.classList.add("question-icon-div");
                          ques_icon.classList.add("question-icon-smatest");
                          var inner1 = document.createElement("DIV");
                          inner1.classList.add("bounce1");
                          var inner2 = document.createElement("DIV");
                          inner2.classList.add("bounce2");
                          var inner3 = document.createElement("DIV");
                          inner3.classList.add("bounce3");
                          spinnerDiv.appendChild(inner1);
                          spinnerDiv.appendChild(inner2);
                          spinnerDiv.appendChild(inner3);
                          spinningDiv.appendChild(iconDiv);
                          spinningDiv.appendChild(spinnerDiv);
                          body.appendChild(spinningDiv);
                          body.scrollTop = body.scrollHeight;
                          inTheMiddle = !0;
                          var xhttp = new XMLHttpRequest();
                          xhttp.onreadystatechange = function () {
                            if (this.readyState == 4 && this.status == 200) {
                              shouldDisableTakeAction = !1;
                              question_and_answers.push({
                                id: question_id,
                                answer: input_value,
                              });
                              entered = !1;
                              if (currentQuestionIsLead == "1" && !mailSent) {
                                sendAlertCall();
                              } else {
                                if (mailSequence < currentMailSequence) {
                                  random_key = !0;
                                } else {
                                  random_key = !1;
                                }
                              }
                              cb_session = JSON.parse(this.response).cb_session;
                              live_chat_cb_session = JSON.parse(
                                this.response
                              ).livechat_session;
                              if (
                                JSON.parse(this.response).language_code &&
                                JSON.parse(this.response).language_code.length >
                                0 &&
                                JSON.parse(this.response).language_code != "default"
                              ) {
                                main_lang_code = JSON.parse(
                                  this.response
                                ).language_code;
                              }
                              session_feedback = JSON.parse(this.response).feedback;
                              question_array = JSON.parse(
                                this.response
                              ).next_question;
                              if (question_array && question_array.length > 0) {
                                question_completed = !1;
                                input_value = "";
                                setTimeout(function () {
                                  enter.style.pointerEvents = "auto";
                                  if (
                                    spinningDiv &&
                                    spinningDiv.parentNode == body
                                  ) {
                                    body.removeChild(spinningDiv);
                                  }
                                  current_question_type = question_array[0].type;
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  question_id = question_array[0].id;
                                  setAllInputs(question_array);
                                  assignAllQuestionTypes(current_question_type);
                                }, delay_time);
                              } else {
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                enter.style.pointerEvents = "auto";
                                question_completed = !0;
                                if (!mailSent || mailSent) {
                                  var xhttp = new XMLHttpRequest();
                                  xhttp.onreadystatechange = function () {
                                    if (
                                      this.readyState == 4 &&
                                      this.status == 200
                                    ) {
                                      var questionArray = [];
                                      prev_questions_array = JSON.parse(
                                        this.response
                                      ).qna_prev;
                                      if (
                                        prev_questions_array &&
                                        prev_questions_array.length > 0
                                      ) {
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          if (
                                            prev_questions_array[i].type ==
                                            "contact" ||
                                            prev_questions_array[i].type ==
                                            "slides" ||
                                            prev_questions_array[i].type ==
                                            "statement" ||
                                            prev_questions_array[i].type ==
                                            "url_auto_redirect" ||
                                            prev_questions_array[i].type ==
                                            "custom_answer" ||
                                            prev_questions_array[i].type ==
                                            "show_file" ||
                                            prev_questions_array[i].type ==
                                            "show_contacts" ||
                                            prev_questions_array[i].type ==
                                            "show_location"
                                          ) {
                                            prev_questions_array.splice(i, 1);
                                            i--;
                                          }
                                        }
                                        if (
                                          zapier_webhook &&
                                          zapier_webhook.length > 0
                                        ) {
                                          var output = {};
                                          output.timestamp = new Date();
                                          for (
                                            var i = 0;
                                            i < prev_questions_array.length;
                                            i++
                                          ) {
                                            var str =
                                              prev_questions_array[i].question_text;
                                            output[str] =
                                              prev_questions_array[i].answer_text;
                                          }
                                          var xhttp = new XMLHttpRequest();
                                          xhttp.onreadystatechange = function () {
                                            if (
                                              this.readyState == 4 &&
                                              this.status == 200
                                            ) {
                                            }
                                          };
                                          xhttp.open("POST", zapier_webhook, !0);
                                          xhttp.setRequestHeader(
                                            "Content-type",
                                            "application/x-www-form-urlencoded"
                                          );
                                          xhttp.send(
                                            "output=" + JSON.stringify(output)
                                          );
                                        }
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          questionArray.push({
                                            question:
                                              prev_questions_array[i].question_text,
                                            answer:
                                              prev_questions_array[i].answer_text,
                                          });
                                        }
                                      }
                                    }
                                  };
                                  xhttp.open(
                                    "POST",
                                    main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                    !0
                                  );
                                  xhttp.setRequestHeader(
                                    "Content-type",
                                    "application/x-www-form-urlencoded"
                                  );
                                  if (
                                    main_lang_code &&
                                    main_lang_code.length > 0 &&
                                    main_lang_code != language_code
                                  ) {
                                  } else {
                                    main_lang_code = "default";
                                  }
                                  var bot_widget_obj;
                                  var is_sendable;
                                  try {
                                    checkSaveMAxUserLogin();
                                    checkRateGainDetails();
                                  } catch (error) { }
                                  if (window.botWidget && window.botWidget.user) {
                                    var keys = Object.keys(window.botWidget.user);
                                    for (var t = 0; t < keys.length; t++) {
                                      if (
                                        window.botWidget.user[keys[t]] &&
                                        window.botWidget.user[keys[t]].length > 0
                                      ) {
                                        is_sendable = true;
                                      }
                                    }
                                    if (is_sendable) {
                                      bot_widget_obj = window.botWidget.user;
                                    } else {
                                      bot_widget_obj = "";
                                    }
                                    if (window.botWidget.user.bot_id) {
                                      delete window.botWidget.user.bot_id;
                                    }
                                    if (window.botWidget.user.url) {
                                      delete window.botWidget.user.url;
                                    }
                                  }
                                  xhttp.send(
                                    "action=init_chat&device_print=" +
                                    device_print +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&language_code=" +
                                    main_lang_code +
                                    "&bot_widget_obj=" +
                                    JSON.stringify(bot_widget_obj)
                                  );
                                } else {
                                  var xhttp = new XMLHttpRequest();
                                  xhttp.onreadystatechange = function () {
                                    if (
                                      this.readyState == 4 &&
                                      this.status == 200
                                    ) {
                                      var questionArray = [];
                                      prev_questions_array = JSON.parse(
                                        this.response
                                      ).qna_prev;
                                      if (
                                        prev_questions_array &&
                                        prev_questions_array.length > 0
                                      ) {
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          if (
                                            prev_questions_array[i].type ==
                                            "contact" ||
                                            prev_questions_array[i].type ==
                                            "slides" ||
                                            prev_questions_array[i].type ==
                                            "statement" ||
                                            prev_questions_array[i].type ==
                                            "url_auto_redirect" ||
                                            prev_questions_array[i].type ==
                                            "custom_answer" ||
                                            prev_questions_array[i].type ==
                                            "show_file" ||
                                            prev_questions_array[i].type ==
                                            "show_contacts" ||
                                            prev_questions_array[i].type ==
                                            "show_location"
                                          ) {
                                            prev_questions_array.splice(i, 1);
                                            i--;
                                          }
                                        }
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          questionArray.push({
                                            question:
                                              prev_questions_array[i].question_text,
                                            answer:
                                              prev_questions_array[i].answer_text,
                                          });
                                        }
                                      }
                                    }
                                  };
                                  xhttp.open(
                                    "POST",
                                    main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                    !0
                                  );
                                  xhttp.setRequestHeader(
                                    "Content-type",
                                    "application/x-www-form-urlencoded"
                                  );
                                  if (
                                    main_lang_code &&
                                    main_lang_code.length > 0 &&
                                    main_lang_code != language_code
                                  ) {
                                  } else {
                                    main_lang_code = "default";
                                  }
                                  var bot_widget_obj;
                                  var is_sendable;
                                  try {
                                    checkSaveMAxUserLogin();
                                    checkRateGainDetails();
                                  } catch (error) { }
                                  if (window.botWidget && window.botWidget.user) {
                                    var keys = Object.keys(window.botWidget.user);
                                    for (var t = 0; t < keys.length; t++) {
                                      if (
                                        window.botWidget.user[keys[t]] &&
                                        window.botWidget.user[keys[t]].length > 0
                                      ) {
                                        is_sendable = true;
                                      }
                                    }
                                    if (is_sendable) {
                                      bot_widget_obj = window.botWidget.user;
                                    } else {
                                      bot_widget_obj = "";
                                    }
                                    if (window.botWidget.user.bot_id) {
                                      delete window.botWidget.user.bot_id;
                                    }
                                    if (window.botWidget.user.url) {
                                      delete window.botWidget.user.url;
                                    }
                                  }
                                  xhttp.send(
                                    "action=init_chat&device_print=" +
                                    device_print +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&language_code=" +
                                    main_lang_code +
                                    "&bot_widget_obj=" +
                                    JSON.stringify(bot_widget_obj)
                                  );
                                }
                                if (!entry_id) {
                                  showInput = !0;
                                  if (!shouldShowMenu) {
                                    footer.style.display = "none";
                                    footer.classList.add("close");
                                  } else {
                                    if (entry_id) {
                                      input.style.pointerEvents = "auto";
                                      microphone.style.pointerEvents = "auto";
                                      microphone.style.opacity = 1;
                                      enter.style.pointerEvents = "auto";
                                      setPlaceHolders();
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                    } else {
                                      input.style.pointerEvents = "none";
                                      microphone.style.pointerEvents = "none";
                                      microphone.style.opacity = 0;
                                      input.blur();
                                      enter.style.pointerEvents = "none";
                                      input.placeholder = "Choose from Menu";
                                    }
                                  }
                                }
                                if (!shouldShowMenu) {
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                } else {
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                }
                              }
                            }
                          };
                          xhttp.open(
                            "POST",
                            main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                            !0
                          );
                          xhttp.setRequestHeader(
                            "Content-type",
                            "application/x-www-form-urlencoded"
                          );
                          if (
                            main_lang_code &&
                            main_lang_code.length > 0 &&
                            main_lang_code != language_code
                          ) {
                          } else {
                            main_lang_code = "default";
                          }
                          if (
                            current_logical_jump == "1" &&
                            current_question_type != "radio" &&
                            current_question_type != "rating"
                          ) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(input_value) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(input_value) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              encodeURIComponent(input_value) +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          }
                        }
                      }
                    } else {
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(input_value);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      body.appendChild(answerDiv);
                      body.scrollTop = body.scrollHeight;
                      prev_email_text = input_value;
                      footer.style.display = "block";
                      if (header.contains(company_title_description)) {
                        body.style.height = "calc(100% - 226px)";
                      } else {
                        body.style.height = "calc(100% - 150px)";
                      }
                      footer.classList.remove("close");
                      if (shouldShowMenu) {
                        input.style.pointerEvents = "auto";
                        microphone.style.pointerEvents = "auto";
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = "auto";
                      }
                      input.focus();
                      body.scrollTop = body.scrollHeight;
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      setTimeout(function () {
                        enter.style.pointerEvents = "auto";
                        footer.style.display = "block";
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                        footer.classList.remove("close");
                        if (shouldShowMenu) {
                          input.style.pointerEvents = "auto";
                          microphone.style.pointerEvents = "auto";
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = "auto";
                        }
                        input.focus();
                        if (spinningDiv && spinningDiv.parentNode == body) {
                          body.removeChild(spinningDiv);
                        }
                        current_logical_jump = question_array[0].logical_jump;
                        currentMailSequence = question_array[0].sequence;
                        currentQuestionIsLead = question_array[0].send_mail;
                        var errorDiv = document.createElement("DIV");
                        errorDiv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          errorDiv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          errorDiv.classList.add(font);
                        }
                        var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                        error_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(error_icon);
                        iconDiv.classList.add("question-icon-div");
                        error_icon.classList.add("question-icon-smatest");
                        var error_text = document.createElement("LABEL");
                        translateContent(translations, error_text, "Please enter your company email ID", main_lang_code, language_code);
                        say(error_text.innerText);
                        error_text.classList.add("question-text-error");
                        error_text.classList.add("options-div-smatest");
                        if (font && font.length > 0) {
                          error_text.classList.add(font);
                        }
                        errorDiv.appendChild(iconDiv);
                        errorDiv.appendChild(error_text);
                        body.appendChild(errorDiv);
                        playBotUserSound(1);
                        body.scrollTop = body.scrollHeight;
                      }, 500);
                    }
                  } else {
                    var regex = /^[0]?[6789]\d{9}$/;
                    var phoneValidated;
                    if (selectedCode && selectedCode == "91") {
                      if (
                        (input_value + "").length > 9 &&
                        (input_value + "").length < 15 &&
                        regex.test(input_value)
                      ) {
                        phoneValidated = !0;
                      } else {
                        phoneValidated = !1;
                      }
                      otp_validation = old_otp_validation;
                      try {
                        if (
                          question_array &&
                          question_array.length > 0 &&
                          question_array[0].default_options &&
                          question_array[0].default_options.length > 0
                        ) {
                          var json = JSON.parse(question_array[0].default_options);
                          if (json && json.no_otp_validation) {
                            otp_validation = !1;
                          }
                        }
                      } catch (e) {
                      } finally {
                      }
                    } else if (
                      selectedCode &&
                      (selectedCode == "973" ||
                        selectedCode == "965" ||
                        selectedCode == "968" ||
                        selectedCode == "974" ||
                        selectedCode == "966" ||
                        selectedCode == "971" ||
                        selectedCode == "44" ||
                        selectedCode == "86" ||
                        selectedCode == "852" ||
                        selectedCode == "27")
                    ) {
                      if (current_question_type == "phone") {
                        otp_validation = !1;
                      }
                      var prefix_regex = new RegExp(
                        phone_validation_regex[selectedCode].prefix
                      );
                      if (
                        prefix_regex &&
                        prefix_regex.test(input_value) &&
                        phone_validation_regex[selectedCode].length[0] ==
                        input_value.length
                      ) {
                        phoneValidated = !0;
                      } else {
                        phoneValidated = !1;
                      }
                    } else {
                      if (current_question_type == "phone") {
                        otp_validation = !1;
                      }
                      if ((input_value + "").length > 5) {
                        phoneValidated = !0;
                      } else {
                        phoneValidated = !1;
                      }
                    }
                    if (current_question_type == "phone" && phoneValidated) {
                      alredyTherePhoneProper = selectedCode + "-" + input_value;
                      if (otp_validation && !otp_verified) {
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        if (selectedCode && selectedCode.length > 0) {
                          var answer_text = document.createTextNode(
                            selectedCode + "-" + input_value
                          );
                        } else {
                          var answer_text = document.createTextNode(input_value);
                        }
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (
                          current_question_type != "statement" &&
                          current_question_type != "url_auto_redirect" &&
                          current_question_type != "contact" &&
                          current_question_type != "slides" &&
                          current_question_type != "custom_answer" &&
                          current_question_type != "show_file" &&
                          current_question_type != "show_location" &&
                          current_question_type != "show_contacts"
                        ) {
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                        }
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        var phoneXhttp = new XMLHttpRequest();
                        phoneXhttp.onreadystatechange = function () {
                          if (this.readyState == 4 && this.status == 200) {
                            var response = JSON.parse(this.response);
                            if (response && response.status) {
                              alredyTherePhone = selectedCode + "-" + input_value;
                              alredyTherePhoneProper =
                                selectedCode + "-" + input_value;
                              var selected_country =
                                document.getElementById("selected_country");
                              if (footer.contains(selected_country)) {
                                footer.removeChild(selected_country);
                              }
                              input_value = "";
                              body.removeChild(spinningDiv);
                              footer.style.display = "block";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                              footer.classList.remove("close");
                              if (shouldShowMenu) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                              }
                              input.focus();
                              enter.style.pointerEvents = "auto";
                              var questionDIv = document.createElement("DIV");
                              if (currentMailSequence) {
                                questionDIv.id =
                                  "radio-question-div-" + currentMailSequence;
                              } else {
                                questionDIv.id = "radio-question-div-" + 0;
                              }
                              questionDIv.classList.add("question-div-smatest");
                              setTimeout(function () {
                                questionDIv.classList.add("top-0");
                              }, transition_time);
                              if (font && font.length > 0) {
                                questionDIv.classList.add(font);
                              }
                              var ques_icon1 = document.createElement("IMG"); ques_icon1.alt = "Logo of " + totalData[0].name;
                              var iconDiv = document.createElement("DIV");
                              iconDiv.appendChild(ques_icon1);
                              iconDiv.classList.add("question-icon-div");
                              ques_icon1.src = avatar_icon;
                              ques_icon1.classList.add("question-icon-smatest");
                              var option_div = document.createElement("DIV");
                              option_div.classList.add("options-div-smatest");
                              var option_question = document.createElement("LABEL");
                              if (font && font.length > 0) {
                                option_question.classList.add(font);
                              }
                              if (
                                (main_lang_code &&
                                  (main_lang_code == "he" ||
                                    main_lang_code == "ur" ||
                                    main_lang_code == "ar")) ||
                                (main_lang_code == "default" &&
                                  (language_code == "ar" ||
                                    language_code == "he" ||
                                    language_code == "ur"))
                              ) {
                                option_question.classList.add("rtl");
                              }
                              option_question.innerHTML =
                                "<div>" + response.message + "</div>";
                              say(option_question.innerText);
                              option_div.appendChild(option_question);
                              questionDIv.appendChild(iconDiv);
                              var resend_div = document.createElement("DIV");
                              resend_div.id = "resend-div";
                              resend_div.classList.add("file-input-div");
                              resend_div.classList.add("pull-left");
                              resend_div.classList.add("full-width");
                              resend_div.classList.add("text-center");
                              var otp_remaining_time = 30;
                              var otp_time = document.createElement("LABEL");
                              otp_time.classList.add("pull-left");
                              otp_time.classList.add("full-width");
                              otp_time.classList.add("text-center");
                              otp_time.classList.add("m-t-5");
                              otp_time.classList.add("m-b-10");
                              if (font && font.length > 0) {
                                otp_time.classList.add(font);
                              }
                              otp_time.classList.add("limegreen");
                              otp_time.innerHTML =
                                otp_remaining_time + "s Remaining";
                              resend_div.appendChild(otp_time);
                              var resend_label = document.createElement("LABEL");
                              var resend_span = document.createElement("SPAN");
                              resend_span.innerHTML = "Resend OTP";
                              resend_span.classList.add("p-r-12");
                              resend_label.appendChild(resend_span);
                              resend_label.htmlFor = "capture-input";
                              resend_label.classList.add("upload-button-sb");
                              if (!agreed) {
                                resend_label.classList.add("no-pointer-events");
                              }
                              var shouldStopChecking;
                              var skip_div = document.createElement("DIV");
                              skip_div.classList.add("file-input-div");
                              skip_div.classList.add("pull-left");
                              skip_div.classList.add("full-width");
                              skip_div.classList.add("text-center");
                              var skip_btn = document.createElement("LABEL");
                              skip_btn.innerHTML = "Skip Validation";
                              skip_btn.classList.add("pull-left");
                              skip_btn.classList.add("full-width");
                              skip_btn.classList.add("m-t-5");
                              skip_btn.classList.add("text-underline");
                              skip_btn.classList.add("skip-text");
                              skip_btn.classList.add("other-pointer");
                              skip_div.appendChild(skip_btn);
                              var otp_sent = 0;
                              skip_btn.addEventListener("click", function (k) {
                                var answerDiv = document.createElement("DIV");
                                answerDiv.classList.add("answer-div");
                                setTimeout(function () {
                                  answerDiv.classList.add("top-0");
                                }, transition_time);
                                var answer = document.createElement("LABEL");
                                var answer_text = document.createTextNode(
                                  alredyTherePhoneProper
                                );
                                answer.appendChild(answer_text);
                                answer.classList.add("answer-label");
                                if (font && font.length > 0) {
                                  answer.classList.add(font);
                                }
                                answerDiv.appendChild(answer);
                                body.appendChild(answerDiv);
                                body.scrollTop = body.scrollHeight;
                                if (prev_should_show) {
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  footer.classList.remove("close");
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                } else {
                                  if (!shouldShowMenu) {
                                    footer.style.display = "none";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 168px)";
                                    } else {
                                      body.style.height = "calc(100% - 93px)";
                                    }
                                    footer.classList.add("close");
                                  } else {
                                    if (entry_id) {
                                      input.style.pointerEvents = "auto";
                                      microphone.style.pointerEvents = "auto";
                                      microphone.style.opacity = 1;
                                      enter.style.pointerEvents = "auto";
                                      setPlaceHolders();
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                    } else {
                                      input.blur();
                                      input.style.pointerEvents = "none";
                                      microphone.style.pointerEvents = "none";
                                      microphone.style.opacity = 0;
                                      enter.style.pointerEvents = "none";
                                      input.placeholder = "Choose from Menu";
                                    }
                                  }
                                }
                                var spinningDiv = document.createElement("DIV");
                                spinningDiv.classList.add("question-div-smatest");
                                spinningDiv.classList.add("top-0");
                                if (font && font.length > 0) {
                                  spinningDiv.classList.add(font);
                                }
                                var spinnerDiv = document.createElement("DIV");
                                spinnerDiv.classList.add("spinner1-smatest");
                                var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                                ques_icon.src = avatar_icon;
                                var iconDiv = document.createElement("DIV");
                                iconDiv.appendChild(ques_icon);
                                iconDiv.classList.add("question-icon-div");
                                ques_icon.classList.add("question-icon-smatest");
                                var inner1 = document.createElement("DIV");
                                inner1.classList.add("bounce1");
                                var inner2 = document.createElement("DIV");
                                inner2.classList.add("bounce2");
                                var inner3 = document.createElement("DIV");
                                inner3.classList.add("bounce3");
                                spinnerDiv.appendChild(inner1);
                                spinnerDiv.appendChild(inner2);
                                spinnerDiv.appendChild(inner3);
                                spinningDiv.appendChild(iconDiv);
                                spinningDiv.appendChild(spinnerDiv);
                                body.appendChild(spinningDiv);
                                body.scrollTop = body.scrollHeight;
                                var xhttp = new XMLHttpRequest();
                                inTheMiddle = !0;
                                xhttp.onreadystatechange = function () {
                                  entered = !1;
                                  phoneValidated = !1;
                                  if (this.readyState == 4 && this.status == 200) {

                                    if (resend_div) {
                                      if (resend_div.contains(resend_label)) {
                                        resend_div.removeChild(resend_label);
                                      }
                                      if (skip_otp_validation && resend_div.contains(skip_div)) {
                                        resend_div.removeChild(skip_div);
                                      }
                                      resend_div.remove();
                                    }
                                    
                                    body.removeChild(spinningDiv);
                                    shouldDisableTakeAction = !1;
                                    if (selectedCode && selectedCode.length > 0) {
                                      question_and_answers.push({
                                        id: question_id,
                                        answer: selectedCode + "-" + input_value,
                                      });
                                    } else {
                                      question_and_answers.push({
                                        id: question_id,
                                        answer: input_value,
                                      });
                                    }
                                    if (currentQuestionIsLead == "1" && !mailSent) {
                                      sendAlertCall();
                                    } else {
                                      if (mailSequence < currentMailSequence) {
                                        random_key = !0;
                                      } else {
                                        random_key = !1;
                                      }
                                    }
                                    body.scrollTop = body.scrollHeight;
                                    cb_session = JSON.parse(
                                      this.response
                                    ).cb_session;
                                    live_chat_cb_session = JSON.parse(
                                      this.response
                                    ).livechat_session;
                                    if (
                                      JSON.parse(this.response).language_code &&
                                      JSON.parse(this.response).language_code
                                        .length > 0
                                    ) {
                                      main_lang_code = JSON.parse(
                                        this.response
                                      ).language_code;
                                    }
                                    session_feedback = JSON.parse(
                                      this.response
                                    ).feedback;
                                    question_array = JSON.parse(
                                      this.response
                                    ).next_question;
                                    if (
                                      question_array &&
                                      question_array.length > 0
                                    ) {
                                      question_completed = !1;
                                      input_value = "";
                                      if (
                                        footer.firstChild &&
                                        footer.firstChild.id == "selected_country"
                                      ) {
                                        footer.removeChild(footer.firstChild);
                                      }
                                      setTimeout(function () {
                                        enter.style.pointerEvents = "auto";
                                        if (
                                          spinningDiv &&
                                          spinningDiv.parentNode == body
                                        ) {
                                          body.removeChild(spinningDiv);
                                        }
                                        current_question_type =
                                          question_array[0].type;
                                        current_logical_jump =
                                          question_array[0].logical_jump;
                                        currentMailSequence =
                                          question_array[0].sequence;
                                        currentQuestionIsLead =
                                          question_array[0].send_mail;
                                        question_id = question_array[0].id;
                                        setAllInputs(question_array);
                                        assignAllQuestionTypes(
                                          current_question_type
                                        );
                                      }, delay_time);
                                    } else {
                                      if (
                                        spinningDiv &&
                                        spinningDiv.parentNode == body
                                      ) {
                                        body.removeChild(spinningDiv);
                                      }
                                      enter.style.pointerEvents = "auto";
                                      question_completed = !0;
                                      if (!mailSent || mailSent) {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              if (
                                                zapier_webhook &&
                                                zapier_webhook.length > 0
                                              ) {
                                                var output = {};
                                                output.timestamp = new Date();
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  var str =
                                                    prev_questions_array[i]
                                                      .question_text;
                                                  output[str] =
                                                    prev_questions_array[
                                                      i
                                                    ].answer_text;
                                                }
                                                var xhttp = new XMLHttpRequest();
                                                xhttp.onreadystatechange =
                                                  function () {
                                                    if (
                                                      this.readyState == 4 &&
                                                      this.status == 200
                                                    ) {
                                                    }
                                                  };
                                                xhttp.open(
                                                  "POST",
                                                  zapier_webhook,
                                                  !0
                                                );
                                                xhttp.setRequestHeader(
                                                  "Content-type",
                                                  "application/x-www-form-urlencoded"
                                                );
                                                xhttp.send(
                                                  "output=" + JSON.stringify(output)
                                                );
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      } else {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      }
                                      if (!entry_id) {
                                        showInput = !0;
                                        if (!shouldShowMenu) {
                                          footer.style.display = "none";
                                          footer.classList.add("close");
                                        } else {
                                          if (entry_id) {
                                            input.style.pointerEvents = "auto";
                                            microphone.style.pointerEvents = "auto";
                                            microphone.style.opacity = 1;
                                            enter.style.pointerEvents = "auto";
                                            setPlaceHolders();
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 218px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 143px)";
                                            }
                                          } else {
                                            input.style.pointerEvents = "none";
                                            microphone.style.pointerEvents = "none";
                                            microphone.style.opacity = 0;
                                            input.blur();
                                            enter.style.pointerEvents = "none";
                                            input.placeholder = "Choose from Menu";
                                          }
                                        }
                                      }
                                      if (!shouldShowMenu) {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 168px)";
                                        } else {
                                          body.style.height = "calc(100% - 93px)";
                                        }
                                      } else {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                if (
                                  current_logical_jump == "1" &&
                                  current_question_type != "radio" &&
                                  current_question_type != "rating"
                                ) {
                                  if (selectedCode && selectedCode.length > 0) {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      "sometext&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  } else {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      "sometext&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  }
                                } else {
                                  if (selectedCode && selectedCode.length > 0) {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  } else {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  }
                                }
                              });
                              setInterval(function () {
                                if (!shouldStopChecking) {
                                  otp_remaining_time = otp_remaining_time - 1;
                                  otp_time.innerHTML =
                                    otp_remaining_time + "s Remaining";
                                  if (otp_remaining_time == 5) {
                                    otp_time.classList.remove("limegreen");
                                    otp_time.classList.add("red");
                                  }
                                  if (otp_remaining_time == 0) {
                                    otp_sent = otp_sent + 1;
                                    shouldStopChecking = !0;
                                    if (resend_div.contains(otp_time)) {
                                      resend_div.removeChild(otp_time);
                                    }
                                    if (resend_div.contains(resend_label)) {
                                      resend_div.removeChild(resend_label);
                                    }
                                    // if (otp_sent == 2) {
                                      if (skip_otp_validation) {
                                        resend_div.appendChild(skip_div);
                                      }
                                    // }
                                  }
                                }
                              }, 1000);
                              resend_label.addEventListener("click", function (k) {
                                var phoneXhttp = new XMLHttpRequest();
                                phoneXhttp.onreadystatechange = function () {
                                  resend_span.innerHTML = "Resending OTP";
                                  resend_label.classList.add("no-pointer-events");
                                  resend_label.classList.add("bg-lightgray");
                                  if (this.readyState == 4 && this.status == 200) {
                                    var response = JSON.parse(this.response);
                                    if (response && response.status) {
                                      resend_label.classList.remove("bg-lightgray");
                                      resend_label.classList.remove(
                                        "no-pointer-events"
                                      );
                                      resend_span.innerHTML = "Resend OTP";
                                      footer.style.display = "block";
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                      footer.classList.remove("close");
                                      if (shouldShowMenu) {
                                        input.style.pointerEvents = "auto";
                                        microphone.style.pointerEvents = "auto";
                                        microphone.style.opacity = 1;
                                        enter.style.pointerEvents = "auto";
                                      }
                                      input_value = "";
                                      input.focus();
                                    } else {
                                      if (
                                        response &&
                                        response.message &&
                                        response.message.includes(
                                          "Insufficient credits"
                                        )
                                      ) {
                                        var alredyTherePhoneProper =
                                          selectedCode + "-" + input_value;
                                        var xhttp = new XMLHttpRequest();
                                        inTheMiddle = !0;
                                        xhttp.onreadystatechange = function () {
                                          entered = !1;
                                          phoneValidated = !1;
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            body.removeChild(spinningDiv);
                                            shouldDisableTakeAction = !1;
                                            if (
                                              selectedCode &&
                                              selectedCode.length > 0
                                            ) {
                                              question_and_answers.push({
                                                id: question_id,
                                                answer:
                                                  selectedCode + "-" + input_value,
                                              });
                                            } else {
                                              question_and_answers.push({
                                                id: question_id,
                                                answer: input_value,
                                              });
                                            }
                                            if (
                                              currentQuestionIsLead == "1" &&
                                              !mailSent
                                            ) {
                                              sendAlertCall();
                                            } else {
                                              if (
                                                mailSequence < currentMailSequence
                                              ) {
                                                random_key = !0;
                                              } else {
                                                random_key = !1;
                                              }
                                            }
                                            body.scrollTop = body.scrollHeight;
                                            cb_session = JSON.parse(
                                              this.response
                                            ).cb_session;
                                            live_chat_cb_session = JSON.parse(
                                              this.response
                                            ).livechat_session;
                                            if (
                                              JSON.parse(this.response)
                                                .language_code &&
                                              JSON.parse(this.response)
                                                .language_code.length > 0
                                            ) {
                                              main_lang_code = JSON.parse(
                                                this.response
                                              ).language_code;
                                            }
                                            session_feedback = JSON.parse(
                                              this.response
                                            ).feedback;
                                            question_array = JSON.parse(
                                              this.response
                                            ).next_question;
                                            if (
                                              question_array &&
                                              question_array.length > 0
                                            ) {
                                              question_completed = !1;
                                              input_value = "";
                                              if (
                                                footer.firstChild &&
                                                footer.firstChild.id ==
                                                "selected_country"
                                              ) {
                                                footer.removeChild(
                                                  footer.firstChild
                                                );
                                              }
                                              setTimeout(function () {
                                                enter.style.pointerEvents = "auto";
                                                if (
                                                  spinningDiv &&
                                                  spinningDiv.parentNode == body
                                                ) {
                                                  body.removeChild(spinningDiv);
                                                }
                                                current_question_type =
                                                  question_array[0].type;
                                                current_logical_jump =
                                                  question_array[0].logical_jump;
                                                currentMailSequence =
                                                  question_array[0].sequence;
                                                currentQuestionIsLead =
                                                  question_array[0].send_mail;
                                                question_id = question_array[0].id;
                                                setAllInputs(question_array);
                                                assignAllQuestionTypes(
                                                  current_question_type
                                                );
                                              }, delay_time);
                                            } else {
                                              if (
                                                spinningDiv &&
                                                spinningDiv.parentNode == body
                                              ) {
                                                body.removeChild(spinningDiv);
                                              }
                                              enter.style.pointerEvents = "auto";
                                              question_completed = !0;
                                              if (!mailSent || mailSent) {
                                                var xhttp = new XMLHttpRequest();
                                                xhttp.onreadystatechange =
                                                  function () {
                                                    if (
                                                      this.readyState == 4 &&
                                                      this.status == 200
                                                    ) {
                                                      var questionArray = [];
                                                      prev_questions_array =
                                                        JSON.parse(
                                                          this.response
                                                        ).qna_prev;
                                                      if (
                                                        prev_questions_array &&
                                                        prev_questions_array.length >
                                                        0
                                                      ) {
                                                        for (
                                                          var i = 0;
                                                          i <
                                                          prev_questions_array.length;
                                                          i++
                                                        ) {
                                                          if (
                                                            prev_questions_array[i]
                                                              .type == "contact" ||
                                                            prev_questions_array[i]
                                                              .type == "slides" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "statement" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "url_auto_redirect" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "custom_answer" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "show_file" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "show_contacts" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "show_location"
                                                          ) {
                                                            prev_questions_array.splice(
                                                              i,
                                                              1
                                                            );
                                                            i--;
                                                          }
                                                        }
                                                        if (
                                                          zapier_webhook &&
                                                          zapier_webhook.length > 0
                                                        ) {
                                                          var output = {};
                                                          output.timestamp =
                                                            new Date();
                                                          for (
                                                            var i = 0;
                                                            i <
                                                            prev_questions_array.length;
                                                            i++
                                                          ) {
                                                            var str =
                                                              prev_questions_array[
                                                                i
                                                              ].question_text;
                                                            output[str] =
                                                              prev_questions_array[
                                                                i
                                                              ].answer_text;
                                                          }
                                                          var xhttp =
                                                            new XMLHttpRequest();
                                                          xhttp.onreadystatechange =
                                                            function () {
                                                              if (
                                                                this.readyState ==
                                                                4 &&
                                                                this.status == 200
                                                              ) {
                                                              }
                                                            };
                                                          xhttp.open(
                                                            "POST",
                                                            zapier_webhook,
                                                            !0
                                                          );
                                                          xhttp.setRequestHeader(
                                                            "Content-type",
                                                            "application/x-www-form-urlencoded"
                                                          );
                                                          xhttp.send(
                                                            "output=" +
                                                            JSON.stringify(output)
                                                          );
                                                        }
                                                        for (
                                                          var i = 0;
                                                          i <
                                                          prev_questions_array.length;
                                                          i++
                                                        ) {
                                                          questionArray.push({
                                                            question:
                                                              prev_questions_array[
                                                                i
                                                              ].question_text,
                                                            answer:
                                                              prev_questions_array[
                                                                i
                                                              ].answer_text,
                                                          });
                                                        }
                                                      }
                                                    }
                                                  };
                                                xhttp.open(
                                                  "POST",
                                                  url +
                                                  "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                                  !0
                                                );
                                                xhttp.setRequestHeader(
                                                  "Content-type",
                                                  "application/x-www-form-urlencoded"
                                                );
                                                if (
                                                  main_lang_code &&
                                                  main_lang_code.length > 0 &&
                                                  main_lang_code != language_code
                                                ) {
                                                } else {
                                                  main_lang_code = "default";
                                                }
                                                var bot_widget_obj;
                                                var is_sendable;
                                                if (
                                                  window.botWidget &&
                                                  window.botWidget.user
                                                ) {
                                                  var keys = Object.keys(
                                                    window.botWidget.user
                                                  );
                                                  for (
                                                    var t = 0;
                                                    t < keys.length;
                                                    t++
                                                  ) {
                                                    if (
                                                      window.botWidget.user[
                                                      keys[t]
                                                      ] &&
                                                      window.botWidget.user[keys[t]]
                                                        .length > 0
                                                    ) {
                                                      is_sendable = true;
                                                    }
                                                  }
                                                  if (is_sendable) {
                                                    bot_widget_obj =
                                                      window.botWidget.user;
                                                  } else {
                                                    bot_widget_obj = "";
                                                  }
                                                  if (
                                                    window.botWidget.user.bot_id
                                                  ) {
                                                    delete window.botWidget.user
                                                      .bot_id;
                                                  }
                                                  if (window.botWidget.user.url) {
                                                    delete window.botWidget.user
                                                      .url;
                                                  }
                                                }
                                                xhttp.send(
                                                  "action=init_chat&device_print=" +
                                                  device_print +
                                                  "&chatbot_id=" +
                                                  chatbot_id +
                                                  "&language_code=" +
                                                  main_lang_code +
                                                  "&bot_widget_obj=" +
                                                  JSON.stringify(bot_widget_obj)
                                                );
                                              } else {
                                                var xhttp = new XMLHttpRequest();
                                                xhttp.onreadystatechange =
                                                  function () {
                                                    if (
                                                      this.readyState == 4 &&
                                                      this.status == 200
                                                    ) {
                                                      var questionArray = [];
                                                      prev_questions_array =
                                                        JSON.parse(
                                                          this.response
                                                        ).qna_prev;
                                                      if (
                                                        prev_questions_array &&
                                                        prev_questions_array.length >
                                                        0
                                                      ) {
                                                        for (
                                                          var i = 0;
                                                          i <
                                                          prev_questions_array.length;
                                                          i++
                                                        ) {
                                                          if (
                                                            prev_questions_array[i]
                                                              .type == "contact" ||
                                                            prev_questions_array[i]
                                                              .type == "slides" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "statement" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "url_auto_redirect" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "custom_answer" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "show_file" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "show_contacts" ||
                                                            prev_questions_array[i]
                                                              .type ==
                                                            "show_location"
                                                          ) {
                                                            prev_questions_array.splice(
                                                              i,
                                                              1
                                                            );
                                                            i--;
                                                          }
                                                        }
                                                        for (
                                                          var i = 0;
                                                          i <
                                                          prev_questions_array.length;
                                                          i++
                                                        ) {
                                                          questionArray.push({
                                                            question:
                                                              prev_questions_array[
                                                                i
                                                              ].question_text,
                                                            answer:
                                                              prev_questions_array[
                                                                i
                                                              ].answer_text,
                                                          });
                                                        }
                                                      }
                                                    }
                                                  };
                                                xhttp.open(
                                                  "POST",
                                                  url +
                                                  "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                                  !0
                                                );
                                                xhttp.setRequestHeader(
                                                  "Content-type",
                                                  "application/x-www-form-urlencoded"
                                                );
                                                if (
                                                  main_lang_code &&
                                                  main_lang_code.length > 0 &&
                                                  main_lang_code != language_code
                                                ) {
                                                } else {
                                                  main_lang_code = "default";
                                                }
                                                var bot_widget_obj;
                                                var is_sendable;
                                                if (
                                                  window.botWidget &&
                                                  window.botWidget.user
                                                ) {
                                                  var keys = Object.keys(
                                                    window.botWidget.user
                                                  );
                                                  for (
                                                    var t = 0;
                                                    t < keys.length;
                                                    t++
                                                  ) {
                                                    if (
                                                      window.botWidget.user[
                                                      keys[t]
                                                      ] &&
                                                      window.botWidget.user[keys[t]]
                                                        .length > 0
                                                    ) {
                                                      is_sendable = true;
                                                    }
                                                  }
                                                  if (is_sendable) {
                                                    bot_widget_obj =
                                                      window.botWidget.user;
                                                  } else {
                                                    bot_widget_obj = "";
                                                  }
                                                  if (
                                                    window.botWidget.user.bot_id
                                                  ) {
                                                    delete window.botWidget.user
                                                      .bot_id;
                                                  }
                                                  if (window.botWidget.user.url) {
                                                    delete window.botWidget.user
                                                      .url;
                                                  }
                                                }
                                                xhttp.send(
                                                  "action=init_chat&device_print=" +
                                                  device_print +
                                                  "&chatbot_id=" +
                                                  chatbot_id +
                                                  "&language_code=" +
                                                  main_lang_code +
                                                  "&bot_widget_obj=" +
                                                  JSON.stringify(bot_widget_obj)
                                                );
                                              }
                                              if (!entry_id) {
                                                showInput = !0;
                                                if (!shouldShowMenu) {
                                                  footer.style.display = "none";
                                                  footer.classList.add("close");
                                                } else {
                                                  if (entry_id) {
                                                    input.style.pointerEvents =
                                                      "auto";
                                                    microphone.style.pointerEvents =
                                                      "auto";
                                                    microphone.style.opacity = 1;
                                                    enter.style.pointerEvents =
                                                      "auto";
                                                    input.placeholder =
                                                      "Type your query";
                                                  } else {
                                                    input.style.pointerEvents =
                                                      "none";
                                                    microphone.style.pointerEvents =
                                                      "none";
                                                    microphone.style.opacity = 0;
                                                    input.blur();
                                                    enter.style.pointerEvents =
                                                      "none";
                                                    input.placeholder =
                                                      "Choose from Menu";
                                                  }
                                                }
                                              }
                                              if (!shouldShowMenu) {
                                                if (
                                                  header.contains(
                                                    company_title_description
                                                  )
                                                ) {
                                                  body.style.height =
                                                    "calc(100% - 168px)";
                                                } else {
                                                  body.style.height =
                                                    "calc(100% - 93px)";
                                                }
                                              } else {
                                                if (
                                                  header.contains(
                                                    company_title_description
                                                  )
                                                ) {
                                                  body.style.height =
                                                    "calc(100% - 218px)";
                                                } else {
                                                  body.style.height =
                                                    "calc(100% - 143px)";
                                                }
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=answer",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        if (
                                          current_logical_jump == "1" &&
                                          current_question_type != "radio" &&
                                          current_question_type != "rating"
                                        ) {
                                          if (
                                            selectedCode &&
                                            selectedCode.length > 0
                                          ) {
                                            xhttp.send(
                                              "action=answer&answer_text=" +
                                              encodeURIComponent(
                                                alredyTherePhoneProper
                                              ) +
                                              "&cb_session=" +
                                              cb_session +
                                              "&question_id=" +
                                              question_id +
                                              "&is_logical=" +
                                              current_logical_jump +
                                              "&sequence=" +
                                              currentMailSequence +
                                              "&chatbot_id=" +
                                              chatbot_id +
                                              "&option=" +
                                              "sometext&visitor_link_traversal=" +
                                              visitedUrls +
                                              "&language_code=" +
                                              main_lang_code
                                            );
                                          } else {
                                            xhttp.send(
                                              "action=answer&answer_text=" +
                                              encodeURIComponent(
                                                alredyTherePhoneProper
                                              ) +
                                              "&cb_session=" +
                                              cb_session +
                                              "&question_id=" +
                                              question_id +
                                              "&is_logical=" +
                                              current_logical_jump +
                                              "&sequence=" +
                                              currentMailSequence +
                                              "&chatbot_id=" +
                                              chatbot_id +
                                              "&option=" +
                                              "sometext&visitor_link_traversal=" +
                                              visitedUrls +
                                              "&language_code=" +
                                              main_lang_code
                                            );
                                          }
                                        } else {
                                          if (
                                            selectedCode &&
                                            selectedCode.length > 0
                                          ) {
                                            xhttp.send(
                                              "action=answer&answer_text=" +
                                              encodeURIComponent(
                                                alredyTherePhoneProper
                                              ) +
                                              "&cb_session=" +
                                              cb_session +
                                              "&question_id=" +
                                              question_id +
                                              "&is_logical=" +
                                              current_logical_jump +
                                              "&sequence=" +
                                              currentMailSequence +
                                              "&chatbot_id=" +
                                              chatbot_id +
                                              "&option=" +
                                              encodeURIComponent(
                                                alredyTherePhoneProper
                                              ) +
                                              "&visitor_link_traversal=" +
                                              visitedUrls +
                                              "&language_code=" +
                                              main_lang_code
                                            );
                                          } else {
                                            xhttp.send(
                                              "action=answer&answer_text=" +
                                              encodeURIComponent(
                                                alredyTherePhoneProper
                                              ) +
                                              "&cb_session=" +
                                              cb_session +
                                              "&question_id=" +
                                              question_id +
                                              "&is_logical=" +
                                              current_logical_jump +
                                              "&sequence=" +
                                              currentMailSequence +
                                              "&chatbot_id=" +
                                              chatbot_id +
                                              "&option=" +
                                              encodeURIComponent(
                                                alredyTherePhoneProper
                                              ) +
                                              "&visitor_link_traversal=" +
                                              visitedUrls +
                                              "&language_code=" +
                                              main_lang_code
                                            );
                                          }
                                        }
                                      } else {
                                        resend_label.classList.remove(
                                          "bg-lightgray"
                                        );
                                        resend_label.classList.remove(
                                          "no-pointer-events"
                                        );
                                        resend_span.innerHTML = "Resend OTP";
                                        setTimeout(function () {
                                          input_value = "";
                                          footer.style.display = "block";
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                          footer.classList.remove("close");
                                          if (shouldShowMenu) {
                                            input.style.pointerEvents = "auto";
                                            microphone.style.pointerEvents = "auto";
                                            microphone.style.opacity = 1;
                                            enter.style.pointerEvents = "auto";
                                          }
                                          input.focus();
                                          body.removeChild(spinningDiv);
                                          enter.style.pointerEvents = "auto";
                                          var errorDiv =
                                            document.createElement("DIV");
                                          current_logical_jump =
                                            question_array[0].logical_jump;
                                          currentMailSequence =
                                            question_array[0].sequence;
                                          currentQuestionIsLead =
                                            question_array[0].send_mail;
                                          errorDiv.classList.add(
                                            "question-div-smatest"
                                          );
                                          setTimeout(function () {
                                            errorDiv.classList.add("top-0");
                                          }, transition_time);
                                          if (font && font.length > 0) {
                                            errorDiv.classList.add(font);
                                          }
                                          var error_icon =
                                            document.createElement("IMG");
                                          error_icon.src = avatar_icon;
                                          error_icon.alt = "Logo of " + totalData[0].name;
                                          var iconDiv =
                                            document.createElement("DIV");
                                          iconDiv.appendChild(error_icon);
                                          iconDiv.classList.add(
                                            "question-icon-div"
                                          );
                                          error_icon.classList.add(
                                            "question-icon-smatest"
                                          );
                                          var error_text =
                                            document.createElement("LABEL");
                                          var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                          if (matched && matched.length > 0) {
                                            error_text.innerHTML = matched;
                                            say(error_text.innerText);
                                            if (
                                              (main_lang_code &&
                                                (main_lang_code == "he" ||
                                                  main_lang_code == "ur" ||
                                                  main_lang_code == "ar")) ||
                                              (main_lang_code == "default" &&
                                                (language_code == "ar" ||
                                                  language_code == "he" ||
                                                  language_code == "ur"))
                                            ) {
                                              error_text.classList.add("rtl");
                                              error_text.style.textAlign = "right";
                                            }
                                          } else {
                                            error_text.innerHTML =
                                              question_array[0].error_text;
                                            say(error_text.innerText);
                                          }
                                          error_text.classList.add(
                                            "question-text-error"
                                          );
                                          error_text.classList.add(
                                            "options-div-smatest"
                                          );
                                          if (font && font.length > 0) {
                                            error_text.classList.add(font);
                                          }
                                          errorDiv.appendChild(iconDiv);
                                          errorDiv.appendChild(error_text);
                                          body.appendChild(errorDiv);
                                          playBotUserSound(1);
                                          body.scrollTop = body.scrollHeight;
                                        }, delay_time);
                                      }
                                    }
                                  } else if (
                                    this.readyState == 4 &&
                                    this.status != 200
                                  ) {
                                    var response = JSON.parse(this.response);
                                    if (
                                      response &&
                                      response.message &&
                                      response.message.includes(
                                        "Insufficient credits"
                                      )
                                    ) {
                                      var alredyTherePhoneProper =
                                        selectedCode + "-" + input_value;
                                      var xhttp = new XMLHttpRequest();
                                      inTheMiddle = !0;
                                      xhttp.onreadystatechange = function () {
                                        entered = !1;
                                        phoneValidated = !1;
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                          body.removeChild(spinningDiv);
                                          shouldDisableTakeAction = !1;
                                          if (
                                            selectedCode &&
                                            selectedCode.length > 0
                                          ) {
                                            question_and_answers.push({
                                              id: question_id,
                                              answer:
                                                selectedCode + "-" + input_value,
                                            });
                                          } else {
                                            question_and_answers.push({
                                              id: question_id,
                                              answer: input_value,
                                            });
                                          }
                                          if (
                                            currentQuestionIsLead == "1" &&
                                            !mailSent
                                          ) {
                                            sendAlertCall();
                                          } else {
                                            if (
                                              mailSequence < currentMailSequence
                                            ) {
                                              random_key = !0;
                                            } else {
                                              random_key = !1;
                                            }
                                          }
                                          body.scrollTop = body.scrollHeight;
                                          cb_session = JSON.parse(
                                            this.response
                                          ).cb_session;
                                          live_chat_cb_session = JSON.parse(
                                            this.response
                                          ).livechat_session;
                                          if (
                                            JSON.parse(this.response)
                                              .language_code &&
                                            JSON.parse(this.response).language_code
                                              .length > 0
                                          ) {
                                            main_lang_code = JSON.parse(
                                              this.response
                                            ).language_code;
                                          }
                                          session_feedback = JSON.parse(
                                            this.response
                                          ).feedback;
                                          question_array = JSON.parse(
                                            this.response
                                          ).next_question;
                                          if (
                                            question_array &&
                                            question_array.length > 0
                                          ) {
                                            question_completed = !1;
                                            input_value = "";
                                            if (
                                              footer.firstChild &&
                                              footer.firstChild.id ==
                                              "selected_country"
                                            ) {
                                              footer.removeChild(footer.firstChild);
                                            }
                                            setTimeout(function () {
                                              enter.style.pointerEvents = "auto";
                                              if (
                                                spinningDiv &&
                                                spinningDiv.parentNode == body
                                              ) {
                                                body.removeChild(spinningDiv);
                                              }
                                              current_question_type =
                                                question_array[0].type;
                                              current_logical_jump =
                                                question_array[0].logical_jump;
                                              currentMailSequence =
                                                question_array[0].sequence;
                                              currentQuestionIsLead =
                                                question_array[0].send_mail;
                                              question_id = question_array[0].id;
                                              setAllInputs(question_array);
                                              assignAllQuestionTypes(
                                                current_question_type
                                              );
                                            }, delay_time);
                                          } else {
                                            if (
                                              spinningDiv &&
                                              spinningDiv.parentNode == body
                                            ) {
                                              body.removeChild(spinningDiv);
                                            }
                                            enter.style.pointerEvents = "auto";
                                            question_completed = !0;
                                            if (!mailSent || mailSent) {
                                              var xhttp = new XMLHttpRequest();
                                              xhttp.onreadystatechange =
                                                function () {
                                                  if (
                                                    this.readyState == 4 &&
                                                    this.status == 200
                                                  ) {
                                                    var questionArray = [];
                                                    prev_questions_array =
                                                      JSON.parse(
                                                        this.response
                                                      ).qna_prev;
                                                    if (
                                                      prev_questions_array &&
                                                      prev_questions_array.length >
                                                      0
                                                    ) {
                                                      for (
                                                        var i = 0;
                                                        i <
                                                        prev_questions_array.length;
                                                        i++
                                                      ) {
                                                        if (
                                                          prev_questions_array[i]
                                                            .type == "contact" ||
                                                          prev_questions_array[i]
                                                            .type == "slides" ||
                                                          prev_questions_array[i]
                                                            .type == "statement" ||
                                                          prev_questions_array[i]
                                                            .type ==
                                                          "url_auto_redirect" ||
                                                          prev_questions_array[i]
                                                            .type ==
                                                          "custom_answer" ||
                                                          prev_questions_array[i]
                                                            .type == "show_file" ||
                                                          prev_questions_array[i]
                                                            .type ==
                                                          "show_contacts" ||
                                                          prev_questions_array[i]
                                                            .type == "show_location"
                                                        ) {
                                                          prev_questions_array.splice(
                                                            i,
                                                            1
                                                          );
                                                          i--;
                                                        }
                                                      }
                                                      if (
                                                        zapier_webhook &&
                                                        zapier_webhook.length > 0
                                                      ) {
                                                        var output = {};
                                                        output.timestamp =
                                                          new Date();
                                                        for (
                                                          var i = 0;
                                                          i <
                                                          prev_questions_array.length;
                                                          i++
                                                        ) {
                                                          var str =
                                                            prev_questions_array[i]
                                                              .question_text;
                                                          output[str] =
                                                            prev_questions_array[
                                                              i
                                                            ].answer_text;
                                                        }
                                                        var xhttp =
                                                          new XMLHttpRequest();
                                                        xhttp.onreadystatechange =
                                                          function () {
                                                            if (
                                                              this.readyState ==
                                                              4 &&
                                                              this.status == 200
                                                            ) {
                                                            }
                                                          };
                                                        xhttp.open(
                                                          "POST",
                                                          zapier_webhook,
                                                          !0
                                                        );
                                                        xhttp.setRequestHeader(
                                                          "Content-type",
                                                          "application/x-www-form-urlencoded"
                                                        );
                                                        xhttp.send(
                                                          "output=" +
                                                          JSON.stringify(output)
                                                        );
                                                      }
                                                      for (
                                                        var i = 0;
                                                        i <
                                                        prev_questions_array.length;
                                                        i++
                                                      ) {
                                                        questionArray.push({
                                                          question:
                                                            prev_questions_array[i]
                                                              .question_text,
                                                          answer:
                                                            prev_questions_array[i]
                                                              .answer_text,
                                                        });
                                                      }
                                                    }
                                                  }
                                                };
                                              xhttp.open(
                                                "POST",
                                                url +
                                                "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                                !0
                                              );
                                              xhttp.setRequestHeader(
                                                "Content-type",
                                                "application/x-www-form-urlencoded"
                                              );
                                              if (
                                                main_lang_code &&
                                                main_lang_code.length > 0 &&
                                                main_lang_code != language_code
                                              ) {
                                              } else {
                                                main_lang_code = "default";
                                              }
                                              var bot_widget_obj;
                                              var is_sendable;
                                              if (
                                                window.botWidget &&
                                                window.botWidget.user
                                              ) {
                                                var keys = Object.keys(
                                                  window.botWidget.user
                                                );
                                                for (
                                                  var t = 0;
                                                  t < keys.length;
                                                  t++
                                                ) {
                                                  if (
                                                    window.botWidget.user[
                                                    keys[t]
                                                    ] &&
                                                    window.botWidget.user[keys[t]]
                                                      .length > 0
                                                  ) {
                                                    is_sendable = true;
                                                  }
                                                }
                                                if (is_sendable) {
                                                  bot_widget_obj =
                                                    window.botWidget.user;
                                                } else {
                                                  bot_widget_obj = "";
                                                }
                                                if (window.botWidget.user.bot_id) {
                                                  delete window.botWidget.user
                                                    .bot_id;
                                                }
                                                if (window.botWidget.user.url) {
                                                  delete window.botWidget.user.url;
                                                }
                                              }
                                              xhttp.send(
                                                "action=init_chat&device_print=" +
                                                device_print +
                                                "&chatbot_id=" +
                                                chatbot_id +
                                                "&language_code=" +
                                                main_lang_code +
                                                "&bot_widget_obj=" +
                                                JSON.stringify(bot_widget_obj)
                                              );
                                            } else {
                                              var xhttp = new XMLHttpRequest();
                                              xhttp.onreadystatechange =
                                                function () {
                                                  if (
                                                    this.readyState == 4 &&
                                                    this.status == 200
                                                  ) {
                                                    var questionArray = [];
                                                    prev_questions_array =
                                                      JSON.parse(
                                                        this.response
                                                      ).qna_prev;
                                                    if (
                                                      prev_questions_array &&
                                                      prev_questions_array.length >
                                                      0
                                                    ) {
                                                      for (
                                                        var i = 0;
                                                        i <
                                                        prev_questions_array.length;
                                                        i++
                                                      ) {
                                                        if (
                                                          prev_questions_array[i]
                                                            .type == "contact" ||
                                                          prev_questions_array[i]
                                                            .type == "slides" ||
                                                          prev_questions_array[i]
                                                            .type == "statement" ||
                                                          prev_questions_array[i]
                                                            .type ==
                                                          "url_auto_redirect" ||
                                                          prev_questions_array[i]
                                                            .type ==
                                                          "custom_answer" ||
                                                          prev_questions_array[i]
                                                            .type == "show_file" ||
                                                          prev_questions_array[i]
                                                            .type ==
                                                          "show_contacts" ||
                                                          prev_questions_array[i]
                                                            .type == "show_location"
                                                        ) {
                                                          prev_questions_array.splice(
                                                            i,
                                                            1
                                                          );
                                                          i--;
                                                        }
                                                      }
                                                      for (
                                                        var i = 0;
                                                        i <
                                                        prev_questions_array.length;
                                                        i++
                                                      ) {
                                                        questionArray.push({
                                                          question:
                                                            prev_questions_array[i]
                                                              .question_text,
                                                          answer:
                                                            prev_questions_array[i]
                                                              .answer_text,
                                                        });
                                                      }
                                                    }
                                                  }
                                                };
                                              xhttp.open(
                                                "POST",
                                                url +
                                                "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                                !0
                                              );
                                              xhttp.setRequestHeader(
                                                "Content-type",
                                                "application/x-www-form-urlencoded"
                                              );
                                              if (
                                                main_lang_code &&
                                                main_lang_code.length > 0 &&
                                                main_lang_code != language_code
                                              ) {
                                              } else {
                                                main_lang_code = "default";
                                              }
                                              var bot_widget_obj;
                                              var is_sendable;
                                              if (
                                                window.botWidget &&
                                                window.botWidget.user
                                              ) {
                                                var keys = Object.keys(
                                                  window.botWidget.user
                                                );
                                                for (
                                                  var t = 0;
                                                  t < keys.length;
                                                  t++
                                                ) {
                                                  if (
                                                    window.botWidget.user[
                                                    keys[t]
                                                    ] &&
                                                    window.botWidget.user[keys[t]]
                                                      .length > 0
                                                  ) {
                                                    is_sendable = true;
                                                  }
                                                }
                                                if (is_sendable) {
                                                  bot_widget_obj =
                                                    window.botWidget.user;
                                                } else {
                                                  bot_widget_obj = "";
                                                }
                                                if (window.botWidget.user.bot_id) {
                                                  delete window.botWidget.user
                                                    .bot_id;
                                                }
                                                if (window.botWidget.user.url) {
                                                  delete window.botWidget.user.url;
                                                }
                                              }
                                              xhttp.send(
                                                "action=init_chat&device_print=" +
                                                device_print +
                                                "&chatbot_id=" +
                                                chatbot_id +
                                                "&language_code=" +
                                                main_lang_code +
                                                "&bot_widget_obj=" +
                                                JSON.stringify(bot_widget_obj)
                                              );
                                            }
                                            if (!entry_id) {
                                              showInput = !0;
                                              if (!shouldShowMenu) {
                                                footer.style.display = "none";
                                                footer.classList.add("close");
                                              } else {
                                                if (entry_id) {
                                                  input.style.pointerEvents =
                                                    "auto";
                                                  microphone.style.pointerEvents =
                                                    "auto";
                                                  microphone.style.opacity = 1;
                                                  enter.style.pointerEvents =
                                                    "auto";
                                                  input.placeholder =
                                                    "Type your query";
                                                } else {
                                                  input.style.pointerEvents =
                                                    "none";
                                                  microphone.style.pointerEvents =
                                                    "none";
                                                  microphone.style.opacity = 0;
                                                  input.blur();
                                                  enter.style.pointerEvents =
                                                    "none";
                                                  input.placeholder =
                                                    "Choose from Menu";
                                                }
                                              }
                                            }
                                            if (!shouldShowMenu) {
                                              if (
                                                header.contains(
                                                  company_title_description
                                                )
                                              ) {
                                                body.style.height =
                                                  "calc(100% - 168px)";
                                              } else {
                                                body.style.height =
                                                  "calc(100% - 93px)";
                                              }
                                            } else {
                                              if (
                                                header.contains(
                                                  company_title_description
                                                )
                                              ) {
                                                body.style.height =
                                                  "calc(100% - 218px)";
                                              } else {
                                                body.style.height =
                                                  "calc(100% - 143px)";
                                              }
                                            }
                                          }
                                        }
                                      };
                                      xhttp.open(
                                        "POST",
                                        main_url +
                                        "/kya_backend/pagehub/chatbot_utils?action=answer",
                                        !0
                                      );
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      if (
                                        main_lang_code &&
                                        main_lang_code.length > 0 &&
                                        main_lang_code != language_code
                                      ) {
                                      } else {
                                        main_lang_code = "default";
                                      }
                                      if (
                                        current_logical_jump == "1" &&
                                        current_question_type != "radio" &&
                                        current_question_type != "rating"
                                      ) {
                                        if (
                                          selectedCode &&
                                          selectedCode.length > 0
                                        ) {
                                          xhttp.send(
                                            "action=answer&answer_text=" +
                                            encodeURIComponent(
                                              alredyTherePhoneProper
                                            ) +
                                            "&cb_session=" +
                                            cb_session +
                                            "&question_id=" +
                                            question_id +
                                            "&is_logical=" +
                                            current_logical_jump +
                                            "&sequence=" +
                                            currentMailSequence +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&option=" +
                                            "sometext&visitor_link_traversal=" +
                                            visitedUrls +
                                            "&language_code=" +
                                            main_lang_code
                                          );
                                        } else {
                                          xhttp.send(
                                            "action=answer&answer_text=" +
                                            encodeURIComponent(
                                              alredyTherePhoneProper
                                            ) +
                                            "&cb_session=" +
                                            cb_session +
                                            "&question_id=" +
                                            question_id +
                                            "&is_logical=" +
                                            current_logical_jump +
                                            "&sequence=" +
                                            currentMailSequence +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&option=" +
                                            "sometext&visitor_link_traversal=" +
                                            visitedUrls +
                                            "&language_code=" +
                                            main_lang_code
                                          );
                                        }
                                      } else {
                                        if (
                                          selectedCode &&
                                          selectedCode.length > 0
                                        ) {
                                          xhttp.send(
                                            "action=answer&answer_text=" +
                                            encodeURIComponent(
                                              alredyTherePhoneProper
                                            ) +
                                            "&cb_session=" +
                                            cb_session +
                                            "&question_id=" +
                                            question_id +
                                            "&is_logical=" +
                                            current_logical_jump +
                                            "&sequence=" +
                                            currentMailSequence +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&option=" +
                                            encodeURIComponent(
                                              alredyTherePhoneProper
                                            ) +
                                            "&visitor_link_traversal=" +
                                            visitedUrls +
                                            "&language_code=" +
                                            main_lang_code
                                          );
                                        } else {
                                          xhttp.send(
                                            "action=answer&answer_text=" +
                                            encodeURIComponent(
                                              alredyTherePhoneProper
                                            ) +
                                            "&cb_session=" +
                                            cb_session +
                                            "&question_id=" +
                                            question_id +
                                            "&is_logical=" +
                                            current_logical_jump +
                                            "&sequence=" +
                                            currentMailSequence +
                                            "&chatbot_id=" +
                                            chatbot_id +
                                            "&option=" +
                                            encodeURIComponent(
                                              alredyTherePhoneProper
                                            ) +
                                            "&visitor_link_traversal=" +
                                            visitedUrls +
                                            "&language_code=" +
                                            main_lang_code
                                          );
                                        }
                                      }
                                    } else {
                                      resend_label.classList.remove("bg-lightgray");
                                      resend_label.classList.remove(
                                        "no-pointer-events"
                                      );
                                      resend_span.innerHTML = "Resend OTP";
                                      setTimeout(function () {
                                        input_value = "";
                                        footer.style.display = "block";
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                        footer.classList.remove("close");
                                        if (shouldShowMenu) {
                                          input.style.pointerEvents = "auto";
                                          microphone.style.pointerEvents = "auto";
                                          microphone.style.opacity = 1;
                                          enter.style.pointerEvents = "auto";
                                        }
                                        input.focus();
                                        body.removeChild(spinningDiv);
                                        enter.style.pointerEvents = "auto";
                                        var errorDiv =
                                          document.createElement("DIV");
                                        current_logical_jump =
                                          question_array[0].logical_jump;
                                        currentMailSequence =
                                          question_array[0].sequence;
                                        currentQuestionIsLead =
                                          question_array[0].send_mail;
                                        errorDiv.classList.add(
                                          "question-div-smatest"
                                        );
                                        setTimeout(function () {
                                          errorDiv.classList.add("top-0");
                                        }, transition_time);
                                        if (font && font.length > 0) {
                                          errorDiv.classList.add(font);
                                        }
                                        var error_icon =
                                          document.createElement("IMG");
                                        error_icon.src = avatar_icon;
                                        error_icon.alt = "Logo of " + totalData[0].name;
                                        var iconDiv = document.createElement("DIV");
                                        iconDiv.appendChild(error_icon);
                                        iconDiv.classList.add("question-icon-div");
                                        error_icon.classList.add(
                                          "question-icon-smatest"
                                        );
                                        var error_text =
                                          document.createElement("LABEL");
                                        var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                        if (matched && matched.length > 0) {
                                          error_text.innerHTML = matched;
                                          say(error_text.innerText);
                                          if (
                                            (main_lang_code &&
                                              (main_lang_code == "he" ||
                                                main_lang_code == "ur" ||
                                                main_lang_code == "ar")) ||
                                            (main_lang_code == "default" &&
                                              (language_code == "ar" ||
                                                language_code == "he" ||
                                                language_code == "ur"))
                                          ) {
                                            error_text.classList.add("rtl");
                                            error_text.style.textAlign = "right";
                                          }
                                        } else {
                                          error_text.innerHTML =
                                            question_array[0].error_text;
                                          say(error_text.innerText);
                                        }
                                        error_text.classList.add(
                                          "question-text-error"
                                        );
                                        error_text.classList.add(
                                          "options-div-smatest"
                                        );
                                        if (font && font.length > 0) {
                                          error_text.classList.add(font);
                                        }
                                        errorDiv.appendChild(iconDiv);
                                        errorDiv.appendChild(error_text);
                                        body.appendChild(errorDiv);
                                        playBotUserSound(1);
                                        body.scrollTop = body.scrollHeight;
                                      }, delay_time);
                                    }
                                  }
                                };
                                phoneXhttp.open(
                                  "POST",
                                  main_url +
                                  "/kya_backend/runtimeUtils/phonevalidate",
                                  !0
                                );
                                phoneXhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                phoneXhttp.send(
                                  "phone=" +
                                  alredyTherePhone +
                                  "&chatbot_name=" +
                                  encodeURIComponent(totalData[0].name) +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&cb_session=" +
                                  cb_session +
                                  "&question_id=" +
                                  question_id
                                );
                              });
                              addReEnterMobileDiv(resend_div);
                              option_div.appendChild(resend_div);
                              questionDIv.appendChild(option_div);
                              body.appendChild(questionDIv);
                              body.scrollTop = body.scrollHeight;
                              var selected_country =
                                document.getElementById("selected_country");
                              if (footer.contains(selected_country)) {
                                footer.removeChild(selected_country);
                              }
                              if (shouldShowMenu) {
                                if (voice_input == "1") {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 115px) !important";
                                } else {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 80px) !important";
                                }
                              } else {
                                if (voice_input == "1") {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 75px) !important";
                                } else {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 45px) !important";
                                }
                              }
                              input.style.cssText =
                                input.style.cssText + "min-height:24px !important";
                                input.style.cssText = input.style.cssText + "height:24px !important";
                                input.style.cssText = input.style.cssText + "border:none !important";
                              // input.style.cssText =
                              // input.style.cssText + "max-height:72px !important";
                              if (is_firefox) {
                                input.type = "text";
                              } else {
                                input.type = "number";
                              }
                              input.id = "";
                              footer.id = "";
                              input.autocomplete = "off";
                              try {
                                google.maps.event.clearInstanceListeners(input);
                              } catch (e) {
                              } finally {
                              }
                              input.placeholder = "Enter OTP";
                            } else {
                              if (
                                response &&
                                response.message &&
                                response.message.includes("Insufficient credits")
                              ) {
                                var alredyTherePhoneProper =
                                  selectedCode + "-" + input_value;
                                var xhttp = new XMLHttpRequest();
                                inTheMiddle = !0;
                                xhttp.onreadystatechange = function () {
                                  entered = !1;
                                  phoneValidated = !1;
                                  if (this.readyState == 4 && this.status == 200) {
                                    body.removeChild(spinningDiv);
                                    shouldDisableTakeAction = !1;
                                    if (selectedCode && selectedCode.length > 0) {
                                      question_and_answers.push({
                                        id: question_id,
                                        answer: selectedCode + "-" + input_value,
                                      });
                                    } else {
                                      question_and_answers.push({
                                        id: question_id,
                                        answer: input_value,
                                      });
                                    }
                                    if (currentQuestionIsLead == "1" && !mailSent) {
                                      sendAlertCall();
                                    } else {
                                      if (mailSequence < currentMailSequence) {
                                        random_key = !0;
                                      } else {
                                        random_key = !1;
                                      }
                                    }
                                    body.scrollTop = body.scrollHeight;
                                    cb_session = JSON.parse(
                                      this.response
                                    ).cb_session;
                                    live_chat_cb_session = JSON.parse(
                                      this.response
                                    ).livechat_session;
                                    if (
                                      JSON.parse(this.response).language_code &&
                                      JSON.parse(this.response).language_code
                                        .length > 0
                                    ) {
                                      main_lang_code = JSON.parse(
                                        this.response
                                      ).language_code;
                                    }
                                    session_feedback = JSON.parse(
                                      this.response
                                    ).feedback;
                                    question_array = JSON.parse(
                                      this.response
                                    ).next_question;
                                    if (
                                      question_array &&
                                      question_array.length > 0
                                    ) {
                                      question_completed = !1;
                                      input_value = "";
                                      if (
                                        footer.firstChild &&
                                        footer.firstChild.id == "selected_country"
                                      ) {
                                        footer.removeChild(footer.firstChild);
                                      }
                                      setTimeout(function () {
                                        enter.style.pointerEvents = "auto";
                                        if (
                                          spinningDiv &&
                                          spinningDiv.parentNode == body
                                        ) {
                                          body.removeChild(spinningDiv);
                                        }
                                        current_question_type =
                                          question_array[0].type;
                                        current_logical_jump =
                                          question_array[0].logical_jump;
                                        currentMailSequence =
                                          question_array[0].sequence;
                                        currentQuestionIsLead =
                                          question_array[0].send_mail;
                                        question_id = question_array[0].id;
                                        setAllInputs(question_array);
                                        assignAllQuestionTypes(
                                          current_question_type
                                        );
                                      }, delay_time);
                                    } else {
                                      if (
                                        spinningDiv &&
                                        spinningDiv.parentNode == body
                                      ) {
                                        body.removeChild(spinningDiv);
                                      }
                                      enter.style.pointerEvents = "auto";
                                      question_completed = !0;
                                      if (!mailSent || mailSent) {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              if (
                                                zapier_webhook &&
                                                zapier_webhook.length > 0
                                              ) {
                                                var output = {};
                                                output.timestamp = new Date();
                                                for (
                                                  var i = 0;
                                                  i < prev_questions_array.length;
                                                  i++
                                                ) {
                                                  var str =
                                                    prev_questions_array[i]
                                                      .question_text;
                                                  output[str] =
                                                    prev_questions_array[
                                                      i
                                                    ].answer_text;
                                                }
                                                var xhttp = new XMLHttpRequest();
                                                xhttp.onreadystatechange =
                                                  function () {
                                                    if (
                                                      this.readyState == 4 &&
                                                      this.status == 200
                                                    ) {
                                                    }
                                                  };
                                                xhttp.open(
                                                  "POST",
                                                  zapier_webhook,
                                                  !0
                                                );
                                                xhttp.setRequestHeader(
                                                  "Content-type",
                                                  "application/x-www-form-urlencoded"
                                                );
                                                xhttp.send(
                                                  "output=" + JSON.stringify(output)
                                                );
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      } else {
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                            var questionArray = [];
                                            prev_questions_array = JSON.parse(
                                              this.response
                                            ).qna_prev;
                                            if (
                                              prev_questions_array &&
                                              prev_questions_array.length > 0
                                            ) {
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                if (
                                                  prev_questions_array[i].type ==
                                                  "contact" ||
                                                  prev_questions_array[i].type ==
                                                  "slides" ||
                                                  prev_questions_array[i].type ==
                                                  "statement" ||
                                                  prev_questions_array[i].type ==
                                                  "url_auto_redirect" ||
                                                  prev_questions_array[i].type ==
                                                  "custom_answer" ||
                                                  prev_questions_array[i].type ==
                                                  "show_file" ||
                                                  prev_questions_array[i].type ==
                                                  "show_contacts" ||
                                                  prev_questions_array[i].type ==
                                                  "show_location"
                                                ) {
                                                  prev_questions_array.splice(i, 1);
                                                  i--;
                                                }
                                              }
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                questionArray.push({
                                                  question:
                                                    prev_questions_array[i]
                                                      .question_text,
                                                  answer:
                                                    prev_questions_array[i]
                                                      .answer_text,
                                                });
                                              }
                                            }
                                          }
                                        };
                                        xhttp.open(
                                          "POST",
                                          url +
                                          "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                          !0
                                        );
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        if (
                                          main_lang_code &&
                                          main_lang_code.length > 0 &&
                                          main_lang_code != language_code
                                        ) {
                                        } else {
                                          main_lang_code = "default";
                                        }
                                        var bot_widget_obj;
                                        var is_sendable;
                                        if (
                                          window.botWidget &&
                                          window.botWidget.user
                                        ) {
                                          var keys = Object.keys(
                                            window.botWidget.user
                                          );
                                          for (var t = 0; t < keys.length; t++) {
                                            if (
                                              window.botWidget.user[keys[t]] &&
                                              window.botWidget.user[keys[t]]
                                                .length > 0
                                            ) {
                                              is_sendable = true;
                                            }
                                          }
                                          if (is_sendable) {
                                            bot_widget_obj = window.botWidget.user;
                                          } else {
                                            bot_widget_obj = "";
                                          }
                                          if (window.botWidget.user.bot_id) {
                                            delete window.botWidget.user.bot_id;
                                          }
                                          if (window.botWidget.user.url) {
                                            delete window.botWidget.user.url;
                                          }
                                        }
                                        xhttp.send(
                                          "action=init_chat&device_print=" +
                                          device_print +
                                          "&chatbot_id=" +
                                          chatbot_id +
                                          "&language_code=" +
                                          main_lang_code +
                                          "&bot_widget_obj=" +
                                          JSON.stringify(bot_widget_obj)
                                        );
                                      }
                                      if (!entry_id) {
                                        showInput = !0;
                                        if (!shouldShowMenu) {
                                          footer.style.display = "none";
                                          footer.classList.add("close");
                                        } else {
                                          if (entry_id) {
                                            input.style.pointerEvents = "auto";
                                            microphone.style.pointerEvents = "auto";
                                            microphone.style.opacity = 1;
                                            enter.style.pointerEvents = "auto";
                                            setPlaceHolders();
                                            if (
                                              header.contains(
                                                company_title_description
                                              )
                                            ) {
                                              body.style.height =
                                                "calc(100% - 218px)";
                                            } else {
                                              body.style.height =
                                                "calc(100% - 143px)";
                                            }
                                          } else {
                                            input.style.pointerEvents = "none";
                                            microphone.style.pointerEvents = "none";
                                            microphone.style.opacity = 0;
                                            input.blur();
                                            enter.style.pointerEvents = "none";
                                            input.placeholder = "Choose from Menu";
                                          }
                                        }
                                      }
                                      if (!shouldShowMenu) {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 168px)";
                                        } else {
                                          body.style.height = "calc(100% - 93px)";
                                        }
                                      } else {
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                if (
                                  current_logical_jump == "1" &&
                                  current_question_type != "radio" &&
                                  current_question_type != "rating"
                                ) {
                                  if (selectedCode && selectedCode.length > 0) {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      "sometext&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  } else {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      "sometext&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  }
                                } else {
                                  if (selectedCode && selectedCode.length > 0) {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  } else {
                                    xhttp.send(
                                      "action=answer&answer_text=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&cb_session=" +
                                      cb_session +
                                      "&question_id=" +
                                      question_id +
                                      "&is_logical=" +
                                      current_logical_jump +
                                      "&sequence=" +
                                      currentMailSequence +
                                      "&chatbot_id=" +
                                      chatbot_id +
                                      "&option=" +
                                      encodeURIComponent(alredyTherePhoneProper) +
                                      "&visitor_link_traversal=" +
                                      visitedUrls +
                                      "&language_code=" +
                                      main_lang_code
                                    );
                                  }
                                }
                              } else {
                                setTimeout(function () {
                                  footer.style.display = "block";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                  footer.classList.remove("close");
                                  if (shouldShowMenu) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                  }
                                  input.focus();
                                  body.removeChild(spinningDiv);
                                  enter.style.pointerEvents = "auto";
                                  var errorDiv = document.createElement("DIV");
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  errorDiv.classList.add("question-div-smatest");
                                  setTimeout(function () {
                                    errorDiv.classList.add("top-0");
                                  }, transition_time);
                                  if (font && font.length > 0) {
                                    errorDiv.classList.add(font);
                                  }
                                  var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                  error_icon.src = avatar_icon;
                                  var iconDiv = document.createElement("DIV");
                                  iconDiv.appendChild(error_icon);
                                  iconDiv.classList.add("question-icon-div");
                                  error_icon.classList.add("question-icon-smatest");
                                  var error_text = document.createElement("LABEL");
                                  var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                  if (matched && matched.length > 0) {
                                    error_text.innerHTML = matched;
                                    say(error_text.innerText);
                                    if (
                                      (main_lang_code &&
                                        (main_lang_code == "he" ||
                                          main_lang_code == "ur" ||
                                          main_lang_code == "ar")) ||
                                      (main_lang_code == "default" &&
                                        (language_code == "ar" ||
                                          language_code == "he" ||
                                          language_code == "ur"))
                                    ) {
                                      error_text.classList.add("rtl");
                                      error_text.style.textAlign = "right";
                                    }
                                  } else {
                                    error_text.innerHTML =
                                      question_array[0].error_text;
                                    say(error_text.innerText);
                                  }
                                  error_text.classList.add("question-text-error");
                                  error_text.classList.add("options-div-smatest");
                                  if (font && font.length > 0) {
                                    error_text.classList.add(font);
                                  }
                                  errorDiv.appendChild(iconDiv);
                                  errorDiv.appendChild(error_text);
                                  body.appendChild(errorDiv);
                                  playBotUserSound(1);
                                  body.scrollTop = body.scrollHeight;
                                }, delay_time);
                              }
                            }
                          } else if (this.readyState == 4 && this.status != 200) {
                            var response = JSON.parse(this.response);
                            if (
                              response &&
                              response.message &&
                              response.message.includes("Insufficient credits")
                            ) {
                              var alredyTherePhoneProper =
                                selectedCode + "-" + input_value;
                              var xhttp = new XMLHttpRequest();
                              inTheMiddle = !0;
                              xhttp.onreadystatechange = function () {
                                entered = !1;
                                phoneValidated = !1;
                                if (this.readyState == 4 && this.status == 200) {
                                  body.removeChild(spinningDiv);
                                  shouldDisableTakeAction = !1;
                                  if (selectedCode && selectedCode.length > 0) {
                                    question_and_answers.push({
                                      id: question_id,
                                      answer: selectedCode + "-" + input_value,
                                    });
                                  } else {
                                    question_and_answers.push({
                                      id: question_id,
                                      answer: input_value,
                                    });
                                  }
                                  if (currentQuestionIsLead == "1" && !mailSent) {
                                    sendAlertCall();
                                  } else {
                                    if (mailSequence < currentMailSequence) {
                                      random_key = !0;
                                    } else {
                                      random_key = !1;
                                    }
                                  }
                                  body.scrollTop = body.scrollHeight;
                                  cb_session = JSON.parse(this.response).cb_session;
                                  live_chat_cb_session = JSON.parse(
                                    this.response
                                  ).livechat_session;
                                  if (
                                    JSON.parse(this.response).language_code &&
                                    JSON.parse(this.response).language_code.length >
                                    0
                                  ) {
                                    main_lang_code = JSON.parse(
                                      this.response
                                    ).language_code;
                                  }
                                  session_feedback = JSON.parse(
                                    this.response
                                  ).feedback;
                                  question_array = JSON.parse(
                                    this.response
                                  ).next_question;
                                  if (question_array && question_array.length > 0) {
                                    question_completed = !1;
                                    input_value = "";
                                    if (
                                      footer.firstChild &&
                                      footer.firstChild.id == "selected_country"
                                    ) {
                                      footer.removeChild(footer.firstChild);
                                    }
                                    setTimeout(function () {
                                      enter.style.pointerEvents = "auto";
                                      if (
                                        spinningDiv &&
                                        spinningDiv.parentNode == body
                                      ) {
                                        body.removeChild(spinningDiv);
                                      }
                                      current_question_type =
                                        question_array[0].type;
                                      current_logical_jump =
                                        question_array[0].logical_jump;
                                      currentMailSequence =
                                        question_array[0].sequence;
                                      currentQuestionIsLead =
                                        question_array[0].send_mail;
                                      question_id = question_array[0].id;
                                      setAllInputs(question_array);
                                      assignAllQuestionTypes(current_question_type);
                                    }, delay_time);
                                  } else {
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    enter.style.pointerEvents = "auto";
                                    question_completed = !0;
                                    if (!mailSent || mailSent) {
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                          var questionArray = [];
                                          prev_questions_array = JSON.parse(
                                            this.response
                                          ).qna_prev;
                                          if (
                                            prev_questions_array &&
                                            prev_questions_array.length > 0
                                          ) {
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              if (
                                                prev_questions_array[i].type ==
                                                "contact" ||
                                                prev_questions_array[i].type ==
                                                "slides" ||
                                                prev_questions_array[i].type ==
                                                "statement" ||
                                                prev_questions_array[i].type ==
                                                "url_auto_redirect" ||
                                                prev_questions_array[i].type ==
                                                "custom_answer" ||
                                                prev_questions_array[i].type ==
                                                "show_file" ||
                                                prev_questions_array[i].type ==
                                                "show_contacts" ||
                                                prev_questions_array[i].type ==
                                                "show_location"
                                              ) {
                                                prev_questions_array.splice(i, 1);
                                                i--;
                                              }
                                            }
                                            if (
                                              zapier_webhook &&
                                              zapier_webhook.length > 0
                                            ) {
                                              var output = {};
                                              output.timestamp = new Date();
                                              for (
                                                var i = 0;
                                                i < prev_questions_array.length;
                                                i++
                                              ) {
                                                var str =
                                                  prev_questions_array[i]
                                                    .question_text;
                                                output[str] =
                                                  prev_questions_array[
                                                    i
                                                  ].answer_text;
                                              }
                                              var xhttp = new XMLHttpRequest();
                                              xhttp.onreadystatechange =
                                                function () {
                                                  if (
                                                    this.readyState == 4 &&
                                                    this.status == 200
                                                  ) {
                                                  }
                                                };
                                              xhttp.open(
                                                "POST",
                                                zapier_webhook,
                                                !0
                                              );
                                              xhttp.setRequestHeader(
                                                "Content-type",
                                                "application/x-www-form-urlencoded"
                                              );
                                              xhttp.send(
                                                "output=" + JSON.stringify(output)
                                              );
                                            }
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              questionArray.push({
                                                question:
                                                  prev_questions_array[i]
                                                    .question_text,
                                                answer:
                                                  prev_questions_array[i]
                                                    .answer_text,
                                              });
                                            }
                                          }
                                        }
                                      };
                                      xhttp.open(
                                        "POST",
                                        main_url +
                                        "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                        !0
                                      );
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      if (
                                        main_lang_code &&
                                        main_lang_code.length > 0 &&
                                        main_lang_code != language_code
                                      ) {
                                      } else {
                                        main_lang_code = "default";
                                      }
                                      var bot_widget_obj;
                                      var is_sendable;
                                      if (
                                        window.botWidget &&
                                        window.botWidget.user
                                      ) {
                                        var keys = Object.keys(
                                          window.botWidget.user
                                        );
                                        for (var t = 0; t < keys.length; t++) {
                                          if (
                                            window.botWidget.user[keys[t]] &&
                                            window.botWidget.user[keys[t]].length >
                                            0
                                          ) {
                                            is_sendable = true;
                                          }
                                        }
                                        if (is_sendable) {
                                          bot_widget_obj = window.botWidget.user;
                                        } else {
                                          bot_widget_obj = "";
                                        }
                                        if (window.botWidget.user.bot_id) {
                                          delete window.botWidget.user.bot_id;
                                        }
                                        if (window.botWidget.user.url) {
                                          delete window.botWidget.user.url;
                                        }
                                      }
                                      xhttp.send(
                                        "action=init_chat&device_print=" +
                                        device_print +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&language_code=" +
                                        main_lang_code +
                                        "&bot_widget_obj=" +
                                        JSON.stringify(bot_widget_obj)
                                      );
                                    } else {
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                          var questionArray = [];
                                          prev_questions_array = JSON.parse(
                                            this.response
                                          ).qna_prev;
                                          if (
                                            prev_questions_array &&
                                            prev_questions_array.length > 0
                                          ) {
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              if (
                                                prev_questions_array[i].type ==
                                                "contact" ||
                                                prev_questions_array[i].type ==
                                                "slides" ||
                                                prev_questions_array[i].type ==
                                                "statement" ||
                                                prev_questions_array[i].type ==
                                                "url_auto_redirect" ||
                                                prev_questions_array[i].type ==
                                                "custom_answer" ||
                                                prev_questions_array[i].type ==
                                                "show_file" ||
                                                prev_questions_array[i].type ==
                                                "show_contacts" ||
                                                prev_questions_array[i].type ==
                                                "show_location"
                                              ) {
                                                prev_questions_array.splice(i, 1);
                                                i--;
                                              }
                                            }
                                            for (
                                              var i = 0;
                                              i < prev_questions_array.length;
                                              i++
                                            ) {
                                              questionArray.push({
                                                question:
                                                  prev_questions_array[i]
                                                    .question_text,
                                                answer:
                                                  prev_questions_array[i]
                                                    .answer_text,
                                              });
                                            }
                                          }
                                        }
                                      };
                                      xhttp.open(
                                        "POST",
                                        main_url +
                                        "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                        !0
                                      );
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      if (
                                        main_lang_code &&
                                        main_lang_code.length > 0 &&
                                        main_lang_code != language_code
                                      ) {
                                      } else {
                                        main_lang_code = "default";
                                      }
                                      var bot_widget_obj;
                                      var is_sendable;
                                      if (
                                        window.botWidget &&
                                        window.botWidget.user
                                      ) {
                                        var keys = Object.keys(
                                          window.botWidget.user
                                        );
                                        for (var t = 0; t < keys.length; t++) {
                                          if (
                                            window.botWidget.user[keys[t]] &&
                                            window.botWidget.user[keys[t]].length >
                                            0
                                          ) {
                                            is_sendable = true;
                                          }
                                        }
                                        if (is_sendable) {
                                          bot_widget_obj = window.botWidget.user;
                                        } else {
                                          bot_widget_obj = "";
                                        }
                                        if (window.botWidget.user.bot_id) {
                                          delete window.botWidget.user.bot_id;
                                        }
                                        if (window.botWidget.user.url) {
                                          delete window.botWidget.user.url;
                                        }
                                      }
                                      xhttp.send(
                                        "action=init_chat&device_print=" +
                                        device_print +
                                        "&chatbot_id=" +
                                        chatbot_id +
                                        "&language_code=" +
                                        main_lang_code +
                                        "&bot_widget_obj=" +
                                        JSON.stringify(bot_widget_obj)
                                      );
                                    }
                                    if (!entry_id) {
                                      showInput = !0;
                                      if (!shouldShowMenu) {
                                        footer.style.display = "none";
                                        footer.classList.add("close");
                                      } else {
                                        if (entry_id) {
                                          input.style.pointerEvents = "auto";
                                          microphone.style.pointerEvents = "auto";
                                          microphone.style.opacity = 1;
                                          enter.style.pointerEvents = "auto";
                                          setPlaceHolders();
                                          if (
                                            header.contains(
                                              company_title_description
                                            )
                                          ) {
                                            body.style.height =
                                              "calc(100% - 218px)";
                                          } else {
                                            body.style.height =
                                              "calc(100% - 143px)";
                                          }
                                        } else {
                                          input.style.pointerEvents = "none";
                                          microphone.style.pointerEvents = "none";
                                          microphone.style.opacity = 0;
                                          input.blur();
                                          enter.style.pointerEvents = "none";
                                          input.placeholder = "Choose from Menu";
                                        }
                                      }
                                    }
                                    if (!shouldShowMenu) {
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 168px)";
                                      } else {
                                        body.style.height = "calc(100% - 93px)";
                                      }
                                    } else {
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              if (
                                current_logical_jump == "1" &&
                                current_question_type != "radio" &&
                                current_question_type != "rating"
                              ) {
                                if (selectedCode && selectedCode.length > 0) {
                                  xhttp.send(
                                    "action=answer&answer_text=" +
                                    encodeURIComponent(alredyTherePhoneProper) +
                                    "&cb_session=" +
                                    cb_session +
                                    "&question_id=" +
                                    question_id +
                                    "&is_logical=" +
                                    current_logical_jump +
                                    "&sequence=" +
                                    currentMailSequence +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&option=" +
                                    "sometext&visitor_link_traversal=" +
                                    visitedUrls +
                                    "&language_code=" +
                                    main_lang_code
                                  );
                                } else {
                                  xhttp.send(
                                    "action=answer&answer_text=" +
                                    encodeURIComponent(alredyTherePhoneProper) +
                                    "&cb_session=" +
                                    cb_session +
                                    "&question_id=" +
                                    question_id +
                                    "&is_logical=" +
                                    current_logical_jump +
                                    "&sequence=" +
                                    currentMailSequence +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&option=" +
                                    "sometext&visitor_link_traversal=" +
                                    visitedUrls +
                                    "&language_code=" +
                                    main_lang_code
                                  );
                                }
                              } else {
                                if (selectedCode && selectedCode.length > 0) {
                                  xhttp.send(
                                    "action=answer&answer_text=" +
                                    encodeURIComponent(alredyTherePhoneProper) +
                                    "&cb_session=" +
                                    cb_session +
                                    "&question_id=" +
                                    question_id +
                                    "&is_logical=" +
                                    current_logical_jump +
                                    "&sequence=" +
                                    currentMailSequence +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&option=" +
                                    encodeURIComponent(alredyTherePhoneProper) +
                                    "&visitor_link_traversal=" +
                                    visitedUrls +
                                    "&language_code=" +
                                    main_lang_code
                                  );
                                } else {
                                  xhttp.send(
                                    "action=answer&answer_text=" +
                                    encodeURIComponent(alredyTherePhoneProper) +
                                    "&cb_session=" +
                                    cb_session +
                                    "&question_id=" +
                                    question_id +
                                    "&is_logical=" +
                                    current_logical_jump +
                                    "&sequence=" +
                                    currentMailSequence +
                                    "&chatbot_id=" +
                                    chatbot_id +
                                    "&option=" +
                                    encodeURIComponent(alredyTherePhoneProper) +
                                    "&visitor_link_traversal=" +
                                    visitedUrls +
                                    "&language_code=" +
                                    main_lang_code
                                  );
                                }
                              }
                            } else {
                              setTimeout(function () {
                                footer.style.display = "block";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                                footer.classList.remove("close");
                                if (shouldShowMenu) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                }
                                input.focus();
                                body.removeChild(spinningDiv);
                                enter.style.pointerEvents = "auto";
                                var errorDiv = document.createElement("DIV");
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                errorDiv.classList.add("question-div-smatest");
                                setTimeout(function () {
                                  errorDiv.classList.add("top-0");
                                }, transition_time);
                                if (font && font.length > 0) {
                                  errorDiv.classList.add(font);
                                }
                                var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                                error_icon.src = avatar_icon;
                                var iconDiv = document.createElement("DIV");
                                iconDiv.appendChild(error_icon);
                                iconDiv.classList.add("question-icon-div");
                                error_icon.classList.add("question-icon-smatest");
                                var error_text = document.createElement("LABEL");
                                var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                                if (matched && matched.length > 0) {
                                  error_text.innerHTML = matched;
                                  say(error_text.innerText);
                                  if (
                                    (main_lang_code &&
                                      (main_lang_code == "he" ||
                                        main_lang_code == "ur" ||
                                        main_lang_code == "ar")) ||
                                    (main_lang_code == "default" &&
                                      (language_code == "ar" ||
                                        language_code == "he" ||
                                        language_code == "ur"))
                                  ) {
                                    error_text.classList.add("rtl");
                                    error_text.style.textAlign = "right";
                                  }
                                } else {
                                  error_text.innerHTML =
                                    question_array[0].error_text;
                                  say(error_text.innerText);
                                }
                                error_text.classList.add("question-text-error");
                                error_text.classList.add("options-div-smatest");
                                if (font && font.length > 0) {
                                  error_text.classList.add(font);
                                }
                                errorDiv.appendChild(iconDiv);
                                errorDiv.appendChild(error_text);
                                body.appendChild(errorDiv);
                                playBotUserSound(1);
                                body.scrollTop = body.scrollHeight;
                              }, delay_time);
                            }
                          }
                        };
                        phoneXhttp.open(
                          "POST",
                          main_url + "/kya_backend/runtimeUtils/phonevalidate",
                          !0
                        );
                        phoneXhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        phoneXhttp.send(
                          "phone=" +
                          selectedCode +
                          "-" +
                          input_value +
                          "&chatbot_name=" +
                          encodeURIComponent(totalData[0].name) +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          question_id
                        );
                      } else {
                        var xhttp = new XMLHttpRequest();
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        if (selectedCode && selectedCode.length > 0) {
                          var answer_text = document.createTextNode(
                            selectedCode + "-" + input_value
                          );
                        } else {
                          var answer_text = document.createTextNode(input_value);
                        }
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (
                          current_question_type != "statement" &&
                          current_question_type != "url_auto_redirect" &&
                          current_question_type != "contact" &&
                          current_question_type != "slides" &&
                          current_question_type != "custom_answer" &&
                          current_question_type != "show_file" &&
                          current_question_type != "show_location" &&
                          current_question_type != "show_contacts"
                        ) {
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                        }
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          phoneValidated = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            var selected_country =
                              document.getElementById("selected_country");
                            if (footer.contains(selected_country)) {
                              footer.removeChild(selected_country);
                            }
                            shouldDisableTakeAction = !1;
                            if (selectedCode && selectedCode.length > 0) {
                              question_and_answers.push({
                                id: question_id,
                                answer: selectedCode + "-" + input_value,
                              });
                            } else {
                              question_and_answers.push({
                                id: question_id,
                                answer: input_value,
                              });
                            }
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            body.scrollTop = body.scrollHeight;
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              if (
                                footer.firstChild &&
                                footer.firstChild.id == "selected_country"
                              ) {
                                footer.removeChild(footer.firstChild);
                              }
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.blur();
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          if (selectedCode && selectedCode.length > 0) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              selectedCode +
                              "-" +
                              input_value +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(input_value) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              "sometext&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          }
                        } else {
                          if (selectedCode && selectedCode.length > 0) {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              selectedCode +
                              "-" +
                              input_value +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              selectedCode +
                              "-" +
                              input_value +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          } else {
                            xhttp.send(
                              "action=answer&answer_text=" +
                              encodeURIComponent(input_value) +
                              "&cb_session=" +
                              cb_session +
                              "&question_id=" +
                              question_id +
                              "&is_logical=" +
                              current_logical_jump +
                              "&sequence=" +
                              currentMailSequence +
                              "&chatbot_id=" +
                              chatbot_id +
                              "&option=" +
                              encodeURIComponent(input_value) +
                              "&visitor_link_traversal=" +
                              visitedUrls +
                              "&language_code=" +
                              main_lang_code
                            );
                          }
                        }
                      }
                    } else if (current_question_type == "email") {
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(input_value);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      body.appendChild(answerDiv);
                      body.scrollTop = body.scrollHeight;
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      setTimeout(function () {
                        enter.style.pointerEvents = "auto";
                        if (spinningDiv && spinningDiv.parentNode == body) {
                          body.removeChild(spinningDiv);
                        }
                        current_logical_jump = question_array[0].logical_jump;
                        currentMailSequence = question_array[0].sequence;
                        currentQuestionIsLead = question_array[0].send_mail;
                        var errorDiv = document.createElement("DIV");
                        errorDiv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          errorDiv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          errorDiv.classList.add(font);
                        }
                        var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                        error_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(error_icon);
                        iconDiv.classList.add("question-icon-div");
                        error_icon.classList.add("question-icon-smatest");
                        var error_text = document.createElement("LABEL");
                        var matched = generateTranslatedContent(translations, "Please recheck your email address", main_lang_code, language_code, input);
                        if (matched && matched.length > 0) {
                          error_text.innerHTML = matched;
                          say(error_text.innerText);
                          if (
                            (main_lang_code &&
                              (main_lang_code == "he" ||
                                main_lang_code == "ur" ||
                                main_lang_code == "ar")) ||
                            (main_lang_code == "default" &&
                              (language_code == "ar" ||
                                language_code == "he" ||
                                language_code == "ur"))
                          ) {
                            error_text.classList.add("rtl");
                            error_text.style.textAlign = "right";
                          }
                        } else {
                          error_text.innerHTML = question_array[0].error_text;
                          say(error_text.innerText);
                        }
                        error_text.classList.add("question-text-error");
                        error_text.classList.add("options-div-smatest");
                        if (font && font.length > 0) {
                          error_text.classList.add(font);
                        }
                        errorDiv.appendChild(iconDiv);
                        errorDiv.appendChild(error_text);
                        body.appendChild(errorDiv);
                        playBotUserSound(1);
                        body.scrollTop = body.scrollHeight;
                      }, delay_time);
                    } else if (current_question_type == "phone") {
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(
                        selectedCode + "-" + input_value
                      );
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      body.appendChild(answerDiv);
                      body.scrollTop = body.scrollHeight;
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      setTimeout(function () {
                        enter.style.pointerEvents = "auto";
                        if (spinningDiv && spinningDiv.parentNode == body) {
                          body.removeChild(spinningDiv);
                        }
                        var errorDiv = document.createElement("DIV");
                        current_logical_jump = question_array[0].logical_jump;
                        currentMailSequence = question_array[0].sequence;
                        currentQuestionIsLead = question_array[0].send_mail;
                        errorDiv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          errorDiv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          errorDiv.classList.add(font);
                        }
                        var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                        error_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(error_icon);
                        iconDiv.classList.add("question-icon-div");
                        error_icon.classList.add("question-icon-smatest");
                        var error_text = document.createElement("LABEL");
                        var matched = generateTranslatedContent(translations, "Please enter a valid Phone Number", main_lang_code, language_code, input);
                        if (matched && matched.length > 0) {
                          error_text.innerHTML = matched;
                          say(error_text.innerText);
                          if (
                            (main_lang_code &&
                              (main_lang_code == "he" ||
                                main_lang_code == "ur" ||
                                main_lang_code == "ar")) ||
                            (main_lang_code == "default" &&
                              (language_code == "ar" ||
                                language_code == "he" ||
                                language_code == "ur"))
                          ) {
                            error_text.classList.add("rtl");
                            error_text.style.textAlign = "right";
                          }
                        } else {
                          error_text.innerHTML = question_array[0].error_text;
                          say(error_text.innerText);
                        }
                        error_text.classList.add("question-text-error");
                        error_text.classList.add("options-div-smatest");
                        if (font && font.length > 0) {
                          error_text.classList.add(font);
                        }
                        errorDiv.appendChild(iconDiv);
                        errorDiv.appendChild(error_text);
                        body.appendChild(errorDiv);
                        playBotUserSound(1);
                        body.scrollTop = body.scrollHeight;
                      }, delay_time);
                    } else if (current_question_type == "website") {
                      var regex =
                        /^((https?|ftp|smtp):\/\/)?(www.)?[a-z0-9]+(\.[a-z]{2,}){1,3}(#?\/?[a-zA-Z0-9#]+)*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/;
                      if (
                        (input_value &&
                          input_value.length > 0 &&
                          regex.test(input_value.toLowerCase())) ||
                        websited_skipped
                      ) {
                        var skip_dv = document.getElementById("skip-question-div");
                        if (skip_dv) {
                          skip_dv.parentElement.style.marginBottom = "0";
                          skip_dv.parentElement.removeChild(skip_dv);
                        }
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (websited_skipped) {
                          websited_skipped = false;
                        } else {
                          body.appendChild(answerDiv);
                        }
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      } else {
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        setTimeout(function () {
                          enter.style.pointerEvents = "auto";
                          if (spinningDiv && spinningDiv.parentNode == body) {
                            body.removeChild(spinningDiv);
                          }
                          current_logical_jump = question_array[0].logical_jump;
                          currentMailSequence = question_array[0].sequence;
                          currentQuestionIsLead = question_array[0].send_mail;
                          var errorDiv = document.createElement("DIV");
                          errorDiv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            errorDiv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            errorDiv.classList.add(font);
                          }
                          var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                          error_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(error_icon);
                          iconDiv.classList.add("question-icon-div");
                          error_icon.classList.add("question-icon-smatest");
                          var error_text = document.createElement("LABEL");
                          translateContent(translations, error_text, "Please enter a valid url", main_lang_code, language_code);
                          say(error_text.innerText);
                          error_text.classList.add("question-text-error");
                          error_text.classList.add("options-div-smatest");
                          if (font && font.length > 0) {
                            error_text.classList.add(font);
                          }
                          errorDiv.appendChild(iconDiv);
                          errorDiv.appendChild(error_text);
                          body.appendChild(errorDiv);
                          playBotUserSound(1);
                          body.scrollTop = body.scrollHeight;
                        }, delay_time);
                      }
                    } else if (current_question_type == "date") {
                      // let actualDate = convertDateFormat(new Date(input_value), date_output_format);
                      input.id = ''
                      let actualDate = input_value
                      if (picker) {
                          picker.destroy();
                      }
                      // var date = new Date(input_value).getDate();
                      // var month = new Date(input_value).getMonth();
                      // var year = new Date(input_value).getFullYear();
                      // month = parseInt(month) + 1;
                      // var actualDate;
                      // if (date_output_format && date_output_format.length > 0) {
                      //   var temp_string = date_output_format;
                      //   if (temp_string.includes("dd")) {
                      //     if (parseInt(date) > 9) {
                      //     } else {
                      //       date = "0" + date;
                      //     }
                      //     temp_string = temp_string.replace("dd", date);
                      //   } else if (temp_string.includes("d")) {
                      //     temp_string = temp_string.replace("d", date);
                      //   }
                      //   if (temp_string.includes("mm")) {
                      //     if (parseInt(month) > 9) {
                      //     } else {
                      //       month = "0" + month;
                      //     }
                      //     temp_string = temp_string.replace("mm", month);
                      //   } else if (temp_string.includes("m")) {
                      //     temp_string = temp_string.replace("m", month);
                      //   }
                      //   if (temp_string.includes("yyyy")) {
                      //     temp_string = temp_string.replace("yyyy", year);
                      //   } else if (temp_string.includes("yy")) {
                      //     year = year.slice(-2);
                      //     temp_string = temp_string.replace("yy", year);
                      //   }
                      //   actualDate = temp_string;
                      // } else {
                      //   actualDate = date + "-" + month + "-" + year;
                      // }

                      const date_picker_div = document.querySelector('#smatbot_date_picker_container');
                      if (date_picker_div) {
                        date_picker_div.remove();
                      }

                      date_output_format = undefined;
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(actualDate);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      if (
                        current_question_type != "statement" &&
                        current_question_type != "url_auto_redirect" &&
                        current_question_type != "contact" &&
                        current_question_type != "slides" &&
                        current_question_type != "custom_answer" &&
                        current_question_type != "show_file" &&
                        current_question_type != "show_location" &&
                        current_question_type != "show_contacts"
                      ) {
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                      }
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      inTheMiddle = !0;
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        entered = !1;
                        if (this.readyState == 4 && this.status == 200) {
                          question_and_answers.push({
                            id: question_id,
                            answer: actualDate,
                          });
                          shouldDisableTakeAction = !1;
                          if (currentQuestionIsLead == "1" && !mailSent) {
                            sendAlertCall();
                          } else {
                            if (mailSequence < currentMailSequence) {
                              random_key = !0;
                            } else {
                              random_key = !1;
                            }
                          }
                          cb_session = JSON.parse(this.response).cb_session;
                          live_chat_cb_session = JSON.parse(
                            this.response
                          ).livechat_session;
                          if (
                            JSON.parse(this.response).language_code &&
                            JSON.parse(this.response).language_code.length > 0 &&
                            JSON.parse(this.response).language_code != "default"
                          ) {
                            main_lang_code = JSON.parse(
                              this.response
                            ).language_code;
                          }
                          session_feedback = JSON.parse(this.response).feedback;
                          question_array = JSON.parse(this.response).next_question;
                          if (question_array && question_array.length > 0) {
                            question_completed = !1;
                            input_value = "";
                            setTimeout(function () {
                              enter.style.pointerEvents = "auto";
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              current_question_type = question_array[0].type;
                              current_logical_jump = question_array[0].logical_jump;
                              currentMailSequence = question_array[0].sequence;
                              currentQuestionIsLead = question_array[0].send_mail;
                              question_id = question_array[0].id;
                              setAllInputs(question_array);
                              assignAllQuestionTypes(current_question_type);
                            }, delay_time);
                          } else {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            enter.style.pointerEvents = "auto";
                            question_completed = !0;
                            if (!mailSent || mailSent) {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    if (
                                      zapier_webhook &&
                                      zapier_webhook.length > 0
                                    ) {
                                      var output = {};
                                      output.timestamp = new Date();
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        var str =
                                          prev_questions_array[i].question_text;
                                        output[str] =
                                          prev_questions_array[i].answer_text;
                                      }
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                        }
                                      };
                                      xhttp.open("POST", zapier_webhook, !0);
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      xhttp.send(
                                        "output=" + JSON.stringify(output)
                                      );
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            } else {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            }
                            if (!entry_id) {
                              showInput = !0;
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  input.blur();
                                  enter.style.pointerEvents = "none";
                                  input.placeholder = "Choose from Menu";
                                }
                              }
                            }
                            if (!shouldShowMenu) {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 168px)";
                              } else {
                                body.style.height = "calc(100% - 93px)";
                              }
                            } else {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                            }
                          }
                        }
                      };
                      xhttp.open(
                        "POST",
                        main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                        !0
                      );
                      xhttp.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0 &&
                        main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      if (
                        current_logical_jump == "1" &&
                        current_question_type != "radio" &&
                        current_question_type != "rating"
                      ) {
                        if (doneThatTAF) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&is_booked=1" +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      } else {
                        if (doneThatTAF) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&is_booked=1" +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      }
                    } else if (current_question_type == "appointment") {
                      var actualDate = input_value;
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(actualDate);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      if (
                        current_question_type != "statement" &&
                        current_question_type != "url_auto_redirect" &&
                        current_question_type != "contact" &&
                        current_question_type != "slides" &&
                        current_question_type != "custom_answer" &&
                        current_question_type != "show_file" &&
                        current_question_type != "show_location" &&
                        current_question_type != "show_contacts"
                      ) {
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                      }
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      inTheMiddle = !0;
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        entered = !1;
                        if (this.readyState == 4 && this.status == 200) {
                          question_and_answers.push({
                            id: question_id,
                            answer: actualDate,
                          });
                          shouldDisableTakeAction = !1;
                          input.value = "";
                          input.setAttribute("value", "");
                          if (currentQuestionIsLead == "1" && !mailSent) {
                            sendAlertCall();
                          } else {
                            if (mailSequence < currentMailSequence) {
                              random_key = !0;
                            } else {
                              random_key = !1;
                            }
                          }
                          if (document.getElementById("timezone_select")) {
                            document.getElementById(
                              "timezone_select"
                            ).style.pointerEvents = "none";
                          }
                          cb_session = JSON.parse(this.response).cb_session;
                          live_chat_cb_session = JSON.parse(
                            this.response
                          ).livechat_session;
                          if (
                            JSON.parse(this.response).language_code &&
                            JSON.parse(this.response).language_code.length > 0 &&
                            JSON.parse(this.response).language_code != "default"
                          ) {
                            main_lang_code = JSON.parse(
                              this.response
                            ).language_code;
                          }
                          session_feedback = JSON.parse(this.response).feedback;
                          question_array = JSON.parse(this.response).next_question;
                          if (question_array && question_array.length > 0) {
                            question_completed = !1;
                            input_value = "";
                            setTimeout(function () {
                              enter.style.pointerEvents = "auto";
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              current_question_type = question_array[0].type;
                              current_logical_jump = question_array[0].logical_jump;
                              currentMailSequence = question_array[0].sequence;
                              currentQuestionIsLead = question_array[0].send_mail;
                              question_id = question_array[0].id;
                              setAllInputs(question_array);
                              assignAllQuestionTypes(current_question_type);
                            }, delay_time);
                          } else {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            enter.style.pointerEvents = "auto";
                            question_completed = !0;
                            if (!mailSent || mailSent) {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    if (
                                      zapier_webhook &&
                                      zapier_webhook.length > 0
                                    ) {
                                      var output = {};
                                      output.timestamp = new Date();
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        var str =
                                          prev_questions_array[i].question_text;
                                        output[str] =
                                          prev_questions_array[i].answer_text;
                                      }
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                        }
                                      };
                                      xhttp.open("POST", zapier_webhook, !0);
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      xhttp.send(
                                        "output=" + JSON.stringify(output)
                                      );
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            } else {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            }
                            if (!entry_id) {
                              showInput = !0;
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  input.blur();
                                  enter.style.pointerEvents = "none";
                                  input.placeholder = "Choose from Menu";
                                }
                              }
                            }
                            if (!shouldShowMenu) {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 168px)";
                              } else {
                                body.style.height = "calc(100% - 93px)";
                              }
                            } else {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                            }
                          }
                        }
                      };
                      xhttp.open(
                        "POST",
                        main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                        !0
                      );
                      xhttp.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0 &&
                        main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      if (
                        current_logical_jump == "1" &&
                        current_question_type != "radio" &&
                        current_question_type != "rating"
                      ) {
                        if (doneThatTAF) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&is_booked=1" +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      } else {
                        if (doneThatTAF) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&is_booked=1" +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            actualDate +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      }
                    } else if (current_question_type == "time") {
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(input_value);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      if (
                        current_question_type != "statement" &&
                        current_question_type != "url_auto_redirect" &&
                        current_question_type != "contact" &&
                        current_question_type != "slides" &&
                        current_question_type != "custom_answer" &&
                        current_question_type != "show_file" &&
                        current_question_type != "show_location" &&
                        current_question_type != "show_contacts"
                      ) {
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                      }
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      inTheMiddle = !0;
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        entered = !1;
                        if (this.readyState == 4 && this.status == 200) {
                          question_and_answers.push({
                            id: question_id,
                            answer: input_value,
                          });
                          var attrs = input.attributes;
                          for (var i = 0; i < attrs.length; i++) {
                            if (attrs[i].name == "data-open") {
                              input.removeAttribute("data-open");
                            }
                          }
                          if (input.classList.contains("timepicker-ui-input")) {
                            input.classList.remove("timepicker-ui-input");
                          }
                          if (
                            input.classList.contains("timepicker-ui-open-element")
                          ) {
                            input.classList.remove("timepicker-ui-open-element");
                          }
                          if (footer.classList.contains("timepicker-ui")) {
                            footer.classList.remove("timepicker-ui");
                          }
                          try {
                            if (
                              document.getElementsByClassName(
                                "timepicker-ui-modal"
                              )[0]
                            ) {
                              document
                                .getElementsByClassName("timepicker-ui-modal")[0]
                                .parentElement.removeChild(
                                  document.getElementsByClassName(
                                    "timepicker-ui-modal"
                                  )[0]
                                );
                            }
                            if (timePicker) {
                              timePicker.close();
                            }
                          } catch (e) {
                          } finally {
                          }
                          shouldDisableTakeAction = !1;
                          if (currentQuestionIsLead == "1" && !mailSent) {
                            sendAlertCall();
                          } else {
                            if (mailSequence < currentMailSequence) {
                              random_key = !0;
                            } else {
                              random_key = !1;
                            }
                          }
                          cb_session = JSON.parse(this.response).cb_session;
                          live_chat_cb_session = JSON.parse(
                            this.response
                          ).livechat_session;
                          if (
                            JSON.parse(this.response).language_code &&
                            JSON.parse(this.response).language_code.length > 0 &&
                            JSON.parse(this.response).language_code != "default"
                          ) {
                            main_lang_code = JSON.parse(
                              this.response
                            ).language_code;
                          }
                          session_feedback = JSON.parse(this.response).feedback;
                          question_array = JSON.parse(this.response).next_question;
                          if (question_array && question_array.length > 0) {
                            question_completed = !1;
                            input_value = "";
                            setTimeout(function () {
                              enter.style.pointerEvents = "auto";
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              current_question_type = question_array[0].type;
                              current_logical_jump = question_array[0].logical_jump;
                              currentMailSequence = question_array[0].sequence;
                              currentQuestionIsLead = question_array[0].send_mail;
                              question_id = question_array[0].id;
                              setAllInputs(question_array);
                              assignAllQuestionTypes(current_question_type);
                            }, delay_time);
                          } else {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            enter.style.pointerEvents = "auto";
                            question_completed = !0;
                            if (!mailSent || mailSent) {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    if (
                                      zapier_webhook &&
                                      zapier_webhook.length > 0
                                    ) {
                                      var output = {};
                                      output.timestamp = new Date();
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        var str =
                                          prev_questions_array[i].question_text;
                                        output[str] =
                                          prev_questions_array[i].answer_text;
                                      }
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                        }
                                      };
                                      xhttp.open("POST", zapier_webhook, !0);
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      xhttp.send(
                                        "output=" + JSON.stringify(output)
                                      );
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            } else {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            }
                            if (!entry_id) {
                              showInput = !0;
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  enter.style.pointerEvents = "none";
                                  input.blur();
                                  input.placeholder = "Choose from Menu";
                                }
                              }
                            }
                            if (!shouldShowMenu) {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 168px)";
                              } else {
                                body.style.height = "calc(100% - 93px)";
                              }
                            } else {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                            }
                          }
                        }
                      };
                      xhttp.open(
                        "POST",
                        main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                        !0
                      );
                      xhttp.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0 &&
                        main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      if (
                        current_logical_jump == "1" &&
                        current_question_type != "radio" &&
                        current_question_type != "rating"
                      ) {
                        if (doneThatTAF) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&is_booked=1" +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      } else {
                        if (doneThatTAF) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            encodeURIComponent(input_value) +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&is_booked=1" +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            encodeURIComponent(input_value) +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      }
                    } else if (current_question_type == "location") {
                      if (locationSearchClicked) {
                        var skip_dv = document.getElementById("skip-question-div");
                        if (skip_dv) {
                          skip_dv.parentElement.style.marginBottom = "0";
                          skip_dv.parentElement.removeChild(skip_dv);
                        }
                        locationSearchClicked = !1;
                        var jsonObj = {};
                        jsonObj.text = input_value;
                        jsonObj.lat = lat;
                        jsonObj.lng = lng;
                        jsonObj.id = place_id;
                        var jsonString = JSON.stringify(jsonObj);
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (
                          current_question_type != "statement" &&
                          current_question_type != "url_auto_redirect" &&
                          current_question_type != "contact" &&
                          current_question_type != "slides" &&
                          current_question_type != "custom_answer" &&
                          current_question_type != "show_file" &&
                          current_question_type != "show_location" &&
                          current_question_type != "show_contacts"
                        ) {
                          if (location_skipped) {
                            location_skipped = false;
                          } else {
                            body.appendChild(answerDiv);
                          }
                          body.scrollTop = body.scrollHeight;
                        }
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          var arr =
                            document.getElementsByClassName("pac-container");
                          if (arr && arr.length > 0) {
                            for (var i = 0; i < arr.length; i++) {
                              arr[i].parentNode.removeChild(arr[i]);
                            }
                          }
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            question_and_answers.push({
                              id: question_id,
                              answer: jsonObj.text,
                            });
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            jsonObj.text +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            jsonObj.text +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            jsonObj.text +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      }
                    } else if (current_question_type == "real_time_search") {
                      var real_time_search_selected;
                      if (real_time_search_type == "object") {
                        for (var i = 0; i < real_time_search_items.length; i++) {
                          if (
                            input_value.toLowerCase() ==
                            real_time_search_items[i].name.toLowerCase()
                          ) {
                            real_time_search_selected = true;
                          }
                        }
                      } else {
                        for (var i = 0; i < real_time_search_items.length; i++) {
                          if (
                            input_value.toLowerCase() ==
                            real_time_search_items[i].toLowerCase()
                          ) {
                            real_time_search_selected = true;
                          }
                        }
                      }
                      if (real_time_search_selected) {
                        try {
                          input.removeEventListener("keyup", myEfficientFn);
                          input.removeEventListener("click", orderAutocomplete);
                          input.removeEventListener("keyup", realTimeSearch);
                          input.removeEventListener("click", autocomplete);
                        } catch (e) {
                        } finally {
                        }
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (
                          current_question_type != "statement" &&
                          current_question_type != "url_auto_redirect" &&
                          current_question_type != "contact" &&
                          current_question_type != "slides" &&
                          current_question_type != "custom_answer" &&
                          current_question_type != "show_file" &&
                          current_question_type != "show_location" &&
                          current_question_type != "show_contacts"
                        ) {
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                        }
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          var arr =
                            document.getElementsByClassName("pac-container");
                          if (arr && arr.length > 0) {
                            for (var i = 0; i < arr.length; i++) {
                              arr[i].parentNode.removeChild(arr[i]);
                            }
                          }
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            question_and_answers.push({
                              id: question_id,
                              answer: input_value,
                            });
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.blur();
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            encodeURIComponent(input_value) +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      } else {
                        var errorDiv = document.createElement("DIV");
                        errorDiv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          errorDiv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          errorDiv.classList.add(font);
                        }
                        var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                        error_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(error_icon);
                        iconDiv.classList.add("question-icon-div");
                        error_icon.classList.add("question-icon-smatest");
                        var error_text = document.createElement("LABEL");
                        error_text.innerHTML = "Unfortunately, the entered text does not match any of the results. Kindly select an option from the list.";
                        error_text.classList.add("question-text-error");
                        error_text.classList.add("options-div-smatest");
                        if (font && font.length > 0) {
                          error_text.classList.add(font);
                        }
                        errorDiv.appendChild(iconDiv);
                        errorDiv.appendChild(error_text);
                        body.appendChild(errorDiv);
                        body.scrollTop = body.scrollHeight;
                        setTimeout(function () {
                          enter.style.pointerEvents = "auto";
                          input.style.pointerEvents = "auto";
                          microphone.style.pointerEvents = "auto";
                          microphone.style.opacity = 1;
                          footer.style.display = "block";
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 226px)";
                          } else {
                            body.style.height = "calc(100% - 150px)";
                          }
                          footer.classList.remove("close");
                        }, 100);
                      }
                    } else if (
                      current_question_type == "order_items" ||
                      current_question_type == "order_items_edit" ||
                      current_question_type == "order_items_submit"
                    ) {
                      if (selected_orders && selected_orders.length > 0) {
                        var selected_orders_strings = [];
                        var added_iems = [];
                        for (var i = 0; i < selected_orders.length; i++) {
                          selected_orders_strings.push(
                            selected_orders[i].display_name
                          );
                          added_iems.push(parseInt(selected_orders[i].id));
                        }
                        var selected_orders_string =
                          selected_orders_strings.join(",");
                        var selected_orders_div_delete =
                          document.getElementById("selected-orders");
                        if (
                          selected_orders_div_delete &&
                          footer.contains(selected_orders_div_delete)
                        ) {
                          footer.removeChild(selected_orders_div_delete);
                        }
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(
                          selected_orders_string
                        );
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          if (this.readyState == 4 && this.status == 200) {
                            entered = !1;
                            shouldDisableTakeAction = !1;
                            question_and_answers.push({
                              id: question_id,
                              answer: selected_orders_string,
                            });
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function () {
                              if (this.readyState == 4 && this.status == 200) {
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                var question = order_items_question;
                                question.type = "order_items_edit";
                                question.question_text =
                                  '<label style="font-weight: 600 !important;text-align: center;margin-bottom: 10px;color:black !important;">Choose Quantity</label>';
                                question_completed = !1;
                                input_value = "";
                                question_array = [];
                                question_array.push(question);
                                enter.style.pointerEvents = "auto";
                                current_question_type = "order_items_edit";
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                                order_status_string = "items_edited";
                              }
                            };
                            xhttp.open(
                              "POST",
                              main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                              !0
                            );
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            if (
                              main_lang_code &&
                              main_lang_code.length > 0 &&
                              main_lang_code != language_code
                            ) {
                            } else {
                              main_lang_code = "default";
                            }
                            if (current_logical_jump == "1") {
                              xhttp.send(
                                "action=answer&answer_text=items_added&cb_session=" +
                                cb_session +
                                "&question_id=" +
                                question_id +
                                "&is_logical=" +
                                current_logical_jump +
                                "&sequence=" +
                                currentMailSequence +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&option=" +
                                "sometext&visitor_link_traversal=" +
                                visitedUrls +
                                "&language_code=" +
                                main_lang_code
                              );
                            } else {
                              xhttp.send(
                                "action=answer&answer_text=items_added&cb_session=" +
                                cb_session +
                                "&question_id=" +
                                question_id +
                                "&is_logical=" +
                                current_logical_jump +
                                "&sequence=" +
                                currentMailSequence +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&option=" +
                                encodeURIComponent(input_value) +
                                "&visitor_link_traversal=" +
                                visitedUrls +
                                "&language_code=" +
                                main_lang_code
                              );
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/storeItems",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (add_more_clicked) {
                          xhttp.send(
                            "action=reset&added_items=" +
                            JSON.stringify(added_iems) +
                            "&cb_session=" +
                            cb_session
                          );
                        } else {
                          xhttp.send(
                            "action=add&added_items=" +
                            JSON.stringify(added_iems) +
                            "&cb_session=" +
                            cb_session
                          );
                        }
                      } else {
                        var errorDiv = document.createElement("DIV");
                        errorDiv.classList.add("question-div-smatest");
                        setTimeout(function () {
                          errorDiv.classList.add("top-0");
                        }, transition_time);
                        if (font && font.length > 0) {
                          errorDiv.classList.add(font);
                        }
                        var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                        error_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(error_icon);
                        iconDiv.classList.add("question-icon-div");
                        error_icon.classList.add("question-icon-smatest");
                        var error_text = document.createElement("LABEL");
                        error_text.innerHTML = "Please choose order from the list";
                        error_text.classList.add("question-text-error");
                        error_text.classList.add("options-div-smatest");
                        if (font && font.length > 0) {
                          error_text.classList.add(font);
                        }
                        errorDiv.appendChild(iconDiv);
                        errorDiv.appendChild(error_text);
                        body.appendChild(errorDiv);
                      }
                    } else if (current_question_type == "custom_entry") {
                      if (question_array && question_array.length > 0) {
                        var these_options =
                          question_array[0].default_options.split(";;");
                      }
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(input_value);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      if (
                        current_question_type != "statement" &&
                        current_question_type != "url_auto_redirect" &&
                        current_question_type != "contact" &&
                        current_question_type != "slides" &&
                        current_question_type != "custom_answer" &&
                        current_question_type != "show_file" &&
                        current_question_type != "show_location" &&
                        current_question_type != "show_contacts"
                      ) {
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                      }
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      var xhttpOther = new XMLHttpRequest();
                      xhttpOther.onreadystatechange = function () {
                        entered = !1;
                        if (this.readyState == 4 && this.status == 200) {
                          shouldDisableTakeAction = !1;
                          if (
                            JSON.parse(this.responseText).answer_text &&
                            JSON.parse(this.responseText).answer_text.length > 0
                          ) {
                            var answerDialog = JSON.parse(
                              this.responseText
                            ).answer_text;
                          } else {
                            var answerDialog = "";
                          }
                          question_array = JSON.parse(
                            this.responseText
                          ).next_question;
                          input_value = "";
                          var question_arr;
                          setTimeout(function () {
                            footer.style.display = "block";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                            footer.classList.remove("close");
                            if (shouldShowMenu) {
                              input.style.pointerEvents = "auto";
                              microphone.style.pointerEvents = "auto";
                              microphone.style.opacity = 1;
                              enter.style.pointerEvents = "auto";
                            }
                            input.focus();
                            enter.style.pointerEvents = "auto";
                            if (!entry_id) {
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  enter.style.pointerEvents = "none";
                                  input.placeholder = "Choose from Menu";
                                  input.type = "text";
                                  input.blur();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                }
                              }
                            }
                            enter.style.pointerEvents = "auto";
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            if (answerDialog && answerDialog.length > 0) {
                              if (
                                answerDialog.includes("<table") &&
                                answerDialog.includes("</table>")
                              ) {
                                isTableOpened = !0;
                                playBotUserSound(1);
                                nothingWentOnFor = 0;
                                encourageMessageIteration = 0;
                                var modal_div = document.createElement("DIV");
                                if (font && font.length > 0) {
                                  modal_div.classList.add(font);
                                }
                                modal_div.classList.add("modal-smatest");
                                modal_div.id = "myModal";
                                var modal_content_div =
                                  document.createElement("DIV");
                                modal_content_div.classList.add(
                                  "modal-content-smatest"
                                );
                                var modal_close_span =
                                  document.createElement("SPAN");
                                modal_close_span.classList.add("close-modal");
                                modal_close_span.innerHTML = "&times";
                                var table_div = document.createElement("DIV");
                                table_div.style.color = "black";
                                table_div.innerHTML = answerDialog;
                                modal_content_div.appendChild(modal_close_span);
                                modal_content_div.appendChild(table_div);
                                modal_div.appendChild(modal_content_div);
                                modal_div.style.display = "block";
                                window.onclick = function (event) {
                                  if (event.target == modal_div) {
                                    modal_div.style.display = "none";
                                    isTableOpened = !1;
                                    nothingWentOnFor = 0;
                                    encourageMessageIteration = 0;
                                  }
                                };
                                modal_close_span.addEventListener(
                                  "click",
                                  function (k) {
                                    modal_div.style.display = "none";
                                    isTableOpened = !1;
                                    nothingWentOnFor = 0;
                                    encourageMessageIteration = 0;
                                  }
                                );
                                document.body.appendChild(modal_div);
                              } else {
                                var k = document.createElement("DIV");
                                k.innerHTML = answerDialog;
                                var inner_text = k.innerText;
                                var enable_read_more;
                                var complete_text = answerDialog;
                                if (answerDialog && answerDialog.length > 500) {
                                  enable_read_more = true;
                                  answerDialog =
                                    answerDialog.substring(0, 500) + "... ";
                                  k.innerHTML = answerDialog;
                                  answerDialog = k.innerHTML;
                                }
                                if (answerDialog.includes("<br/>")) {
                                  question_arr = answerDialog.split("<br/>");
                                } else if (answerDialog.includes(" /n")) {
                                  question_arr = answerDialog.split(" /n");
                                } else if (answerDialog.includes(" \n")) {
                                  question_arr = answerDialog.split(" \n");
                                } else {
                                  question_arr = [];
                                  question_arr.push(answerDialog);
                                }
                                if (question_arr && question_arr.length > 0) {
                                  var i = 0;

                                  function addQuestionArrays() {
                                    if (i < question_arr.length) {
                                      var questionDIv =
                                        document.createElement("DIV");
                                      questionDIv.classList.add(
                                        "question-div-smatest"
                                      );
                                      setTimeout(function () {
                                        questionDIv.classList.add("top-0");
                                      }, transition_time);
                                      if (font && font.length > 0) {
                                        questionDIv.classList.add(font);
                                      }
                                      var ques_icon1 =
                                        document.createElement("IMG");
                                      ques_icon1.src = avatar_icon;
                                      ques_icon1.alt = "Logo of " + totalData[0].name;
                                      var iconDiv = document.createElement("DIV");
                                      iconDiv.appendChild(ques_icon1);
                                      iconDiv.classList.add("question-icon-div");
                                      ques_icon1.classList.add(
                                        "question-icon-smatest"
                                      );
                                      var option_div =
                                        document.createElement("DIV");
                                      option_div.classList.add(
                                        "options-div-smatest"
                                      );
                                      var option_question =
                                        document.createElement("LABEL");
                                      option_question.innerHTML =
                                        question_arr[i].trim();
                                      say(option_question.innerText);
                                      option_div.appendChild(option_question);
                                      option_div.classList.add("m-l-40");
                                      if (i == question_arr.length - 1) {
                                        if (df_options && df_options.length > 0) {
                                          var optionsArray = df_options.split(";;");
                                        }
                                        questionDIv.appendChild(iconDiv);
                                        option_div.classList.remove("m-l-40");
                                        questionDIv.appendChild(option_div);
                                        if (enable_read_more) {
                                          var read_more_span =
                                            document.createElement("LABEL");
                                          read_more_span.innerHTML = generateTranslatedContent(translations, "Read more", main_lang_code, language_code, input);
                                          read_more_span.style.cssText = read_more_span.style.cssText + "color:#007bff !important;";
                                          read_more_span.style.fontSize = "14px";
                                          read_more_span.style.cursor = "pointer";
                                          if (font && font.length > 0) {
                                            read_more_span.classList.add(font);
                                          }
                                          var modal_div =
                                            document.createElement("DIV");
                                          if (font && font.length > 0) {
                                            modal_div.classList.add(font);
                                          }
                                          modal_div.classList.add("modal-smatest");
                                          modal_div.id = "myReadMoreModal";
                                          var modal_content_div =
                                            document.createElement("DIV");
                                          modal_content_div.style.width = "60%";
                                          modal_content_div.style.maxHeight =
                                            "calc(100vh - 50px)";
                                          modal_content_div.style.overflowY =
                                            "scroll";
                                          modal_content_div.classList.add(
                                            "modal-content-smatest"
                                          );
                                          var modal_close_span =
                                            document.createElement("SPAN");
                                          modal_close_span.classList.add(
                                            "close-modal"
                                          );
                                          modal_close_span.innerHTML = "&times";
                                          var table_div =
                                            document.createElement("DIV");
                                          table_div.style.paddingTop = "15px";
                                          table_div.style.paddingBotttom = "15px";
                                          table_div.style.paddingLeft = "10px";
                                          table_div.style.paddingRight = "10px";
                                          table_div.style.marginTop = "10px";
                                          table_div.style.marginBotttom = "10px";
                                          table_div.style.color = "black";
                                          table_div.innerHTML = complete_text;
                                          if (font && font.length > 0) {
                                            table_div.classList.add(font);
                                          }
                                          modal_content_div.appendChild(
                                            modal_close_span
                                          );
                                          modal_content_div.appendChild(table_div);
                                          modal_div.appendChild(modal_content_div);
                                          modal_div.style.display = "none";
                                          read_more_span.addEventListener(
                                            "click",
                                            function () {
                                              modal_div.style.display = "block";
                                            }
                                          );
                                          window.onclick = function (event) {
                                            if (event.target == modal_div) {
                                              modal_div.style.display = "none";
                                              isTableOpened = !1;
                                              nothingWentOnFor = 0;
                                              encourageMessageIteration = 0;
                                            }
                                          };
                                          modal_close_span.addEventListener(
                                            "click",
                                            function (k) {
                                              modal_div.style.display = "none";
                                              isTableOpened = !1;
                                              nothingWentOnFor = 0;
                                              encourageMessageIteration = 0;
                                            }
                                          );
                                          document.body.appendChild(modal_div);
                                          option_div.appendChild(read_more_span);
                                        }
                                        if (
                                          (firstCustomSingleChoiceOptions &&
                                            firstCustomSingleChoiceOptions.length >
                                            0) ||
                                          (these_options &&
                                            these_options.length > 0 &&
                                            these_options[0].length > 0)
                                        ) {
                                        } else {
                                        }
                                        var take_actions_div =
                                          document.createElement("DIV");
                                        take_actions_div.classList.add(
                                          "question-div-smatest"
                                        );
                                        setTimeout(function () {
                                          take_actions_div.classList.add("top-0");
                                        }, transition_time);
                                        if (font && font.length > 0) {
                                          take_actions_div.classList.add(font);
                                        }
                                        if (font && font.length > 0) {
                                          option_question.classList.add(font);
                                        }
                                        if (
                                          (main_lang_code &&
                                            (main_lang_code == "he" ||
                                              main_lang_code == "ur" ||
                                              main_lang_code == "ar")) ||
                                          (main_lang_code == "default" &&
                                            (language_code == "ar" ||
                                              language_code == "he" ||
                                              language_code == "ur"))
                                        ) {
                                          option_question.classList.add("rtl");
                                        }
                                      }
                                      questionDIv.appendChild(option_div);
                                      var otherSpinningDIv =
                                        document.createElement("DIV");
                                      var spinnerDiv =
                                        document.createElement("DIV");
                                      spinnerDiv.classList.add("spinner1-smatest");
                                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                                      ques_icon.src = avatar_icon;
                                      ques_icon.classList.add(
                                        "question-icon-smatest"
                                      );
                                      var inner1 = document.createElement("DIV");
                                      inner1.classList.add("bounce1");
                                      var inner2 = document.createElement("DIV");
                                      inner2.classList.add("bounce2");
                                      var inner3 = document.createElement("DIV");
                                      inner3.classList.add("bounce3");
                                      spinnerDiv.appendChild(inner1);
                                      spinnerDiv.appendChild(inner2);
                                      spinnerDiv.appendChild(inner3);
                                      otherSpinningDIv.classList.add("m-t-10");
                                      otherSpinningDIv.classList.add("m-l-40");
                                      otherSpinningDIv.classList.add("pull-left");
                                      otherSpinningDIv.appendChild(spinnerDiv);
                                      if (i != 0) {
                                        body.appendChild(otherSpinningDIv);
                                        body.scrollTop = body.scrollHeight;
                                      }
                                      if (i == 0) {
                                        if (i == question_arr.length - 1) {
                                          playBotUserSound(1);
                                        }
                                        i++;
                                        body.appendChild(questionDIv);
                                        body.scrollTop = body.scrollHeight;
                                        addQuestionArrays();
                                      } else {
                                        setTimeout(function () {
                                          body.removeChild(otherSpinningDIv);
                                          if (i == question_arr.length - 1) {
                                            playBotUserSound(1);
                                          }
                                          i++;
                                          questionDIv.id = i;
                                          body.appendChild(questionDIv);
                                          body.scrollTop = body.scrollHeight;
                                          addQuestionArrays();
                                        }, delay_time);
                                      }
                                      footer.style.display = "block";
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                      if (shouldShowMenu) {
                                        input.style.pointerEvents = "auto";
                                        microphone.style.pointerEvents = "auto";
                                        microphone.style.opacity = 1;
                                        enter.style.pointerEvents = "auto";
                                      }
                                      input.focus();
                                      footer.classList.remove("close");
                                    }
                                  }
                                  addQuestionArrays();
                                }
                              }
                            }
                            setTimeout(function () {
                              if (question_array && question_array.length > 0) {
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                    input.type = "text";
                                    input.blur();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  }
                                }
                                question_completed = !1;
                                input_value = "";
                                if (question_arr && question_arr.length > 0) {
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(question_array[0].type);
                                  }, delay_time * question_arr.length + 100);
                                } else {
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(question_array[0].type);
                                  }, 100);
                                }
                              }
                            }, 100);
                          }, 100);
                        } else if (this.readyState == 4 && this.status == 400) {
                          try {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                          } catch (error) {
                          }
                          let resp_json = JSON.parse(this.responseText);
                          var errorDiv = document.createElement("DIV");
                          errorDiv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            errorDiv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            errorDiv.classList.add(font);
                          }
                          var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                          error_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(error_icon);
                          iconDiv.classList.add("question-icon-div");
                          error_icon.classList.add("question-icon-smatest");
                          var error_text = document.createElement("LABEL");
                          if (
                            resp_json.message &&
                            resp_json.message.length > 0
                          ) {
                            error_text.innerHTML = resp_json.message;
                            say(resp_json.message);
                          } else {
                            error_text.innerHTML =
                              "This feature works only in the Pro plan along with the ChatGPT Addon";
                            say(error_text.innerText);
                          }
                          error_text.classList.add("question-text-error");
                          error_text.classList.add("options-div-smatest");
                          if (font && font.length > 0) {
                            error_text.classList.add(font);
                          }
                          errorDiv.appendChild(iconDiv);
                          errorDiv.appendChild(error_text);
                          body.appendChild(errorDiv);
                          playBotUserSound(1);
                        }
                      };
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0
                        // main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      xhttpOther.open(
                        "GET",
                        main_url +
                        "/kya_backend/pagehub/getChatBotAnswerv2?answer_text=" +
                        encodeURIComponent(input_value) +
                        "&question_id=" +
                        entry_id +
                        "&chatbot_id=" +
                        chatbot_id +
                        "&cb_session=" +
                        cb_session +
                        "&language_code=" +
                        main_lang_code,
                        !0
                      );
                      xhttpOther.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      xhttpOther.send();
                    } else if (
                      current_question_type == "custome_type" ||
                      current_question_type == "custom_single_choice" ||
                      current_question_type == "slides" ||
                      current_question_type == "statement" ||
                      current_question_type == "url_auto_redirect" ||
                      current_question_type == "custom_answer" ||
                      current_question_type == "user_question" ||
                      current_question_type == "take_action" ||
                      current_question_type == "custom_actions" ||
                      current_question_type == "images_slider" ||
                      current_question_type == "contact" ||
                      current_question_type == "show_file" ||
                      current_question_type == "show_location" ||
                      current_question_type == "show_contacts"
                    ) {
                      if (entry_id) {
                        if (body.lastChild && body.lastChild.lastChild) {
                          var div = body.lastChild.lastChild;
                          var firstChild = div.firstChild;
                          if (div.childNodes[1].className == "image-div-smatest") {
                            var anotherDiv = div.childNodes[1];
                          }
                          while (div.firstChild) {
                            div.removeChild(div.firstChild);
                          }
                          div.appendChild(firstChild);
                          if (anotherDiv) {
                            div.appendChild(anotherDiv);
                          }
                        }
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        var xhttpOther = new XMLHttpRequest();
                        xhttpOther.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            if (
                              JSON.parse(this.responseText).answer_text &&
                              JSON.parse(this.responseText).answer_text.length > 0
                            ) {
                              var answerDialog = JSON.parse(
                                this.responseText
                              ).answer_text;
                            } else {
                              var answerDialog = "";
                            }
                            question_array = JSON.parse(
                              this.responseText
                            ).next_question;
                            input_value = "";
                            var question_arr;
                            setTimeout(function () {
                              footer.style.display = "block";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                              footer.classList.remove("close");
                              if (shouldShowMenu) {
                                input.style.pointerEvents = "auto";
                                microphone.style.pointerEvents = "auto";
                                microphone.style.opacity = 1;
                                enter.style.pointerEvents = "auto";
                              }
                              input.focus();
                              enter.style.pointerEvents = "auto";
                              if (!entry_id) {
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.blur();
                                    input.placeholder = "Choose from Menu";
                                    input.type = "text";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  }
                                }
                              }
                              enter.style.pointerEvents = "auto";
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              if (answerDialog && answerDialog.length > 0) {
                                if (
                                  answerDialog.includes("<table") &&
                                  answerDialog.includes("</table>")
                                ) {
                                  isTableOpened = !0;
                                  playBotUserSound(1);
                                  nothingWentOnFor = 0;
                                  encourageMessageIteration = 0;
                                  var modal_div = document.createElement("DIV");
                                  if (font && font.length > 0) {
                                    modal_div.classList.add(font);
                                  }
                                  modal_div.classList.add("modal-smatest");
                                  modal_div.id = "myModal";
                                  var modal_content_div =
                                    document.createElement("DIV");
                                  modal_content_div.classList.add(
                                    "modal-content-smatest"
                                  );
                                  var modal_close_span =
                                    document.createElement("SPAN");
                                  modal_close_span.classList.add("close-modal");
                                  modal_close_span.innerHTML = "&times";
                                  var table_div = document.createElement("DIV");
                                  table_div.style.color = "black";
                                  table_div.innerHTML = answerDialog;
                                  modal_content_div.appendChild(modal_close_span);
                                  modal_content_div.appendChild(table_div);
                                  modal_div.appendChild(modal_content_div);
                                  modal_div.style.display = "block";
                                  window.onclick = function (event) {
                                    if (event.target == modal_div) {
                                      modal_div.style.display = "none";
                                      isTableOpened = !1;
                                      nothingWentOnFor = 0;
                                      encourageMessageIteration = 0;
                                    }
                                  };
                                  modal_close_span.addEventListener(
                                    "click",
                                    function (k) {
                                      modal_div.style.display = "none";
                                      isTableOpened = !1;
                                      nothingWentOnFor = 0;
                                      encourageMessageIteration = 0;
                                    }
                                  );
                                  document.body.appendChild(modal_div);
                                } else {
                                  var k = document.createElement("DIV");
                                  k.innerHTML = answerDialog;
                                  var inner_text = k.innerText;
                                  var enable_read_more;
                                  var complete_text = answerDialog;
                                  if (answerDialog && answerDialog.length > 500) {
                                    enable_read_more = true;
                                    answerDialog =
                                      answerDialog.substring(0, 500) + "... ";
                                    k.innerHTML = answerDialog;
                                    answerDialog = k.innerHTML;
                                  }
                                  if (answerDialog.includes("<br/>")) {
                                    question_arr = answerDialog.split("<br/>");
                                  } else if (answerDialog.includes(" /n")) {
                                    question_arr = answerDialog.split(" /n");
                                  } else if (answerDialog.includes(" \n")) {
                                    question_arr = answerDialog.split(" \n");
                                  } else {
                                    question_arr = [];
                                    question_arr.push(answerDialog);
                                  }
                                  if (question_arr && question_arr.length > 0) {
                                    var i = 0;

                                    function addQuestionArrays() {
                                      if (i < question_arr.length) {
                                        var questionDIv =
                                          document.createElement("DIV");
                                        questionDIv.classList.add(
                                          "question-div-smatest"
                                        );
                                        setTimeout(function () {
                                          questionDIv.classList.add("top-0");
                                        }, transition_time);
                                        if (font && font.length > 0) {
                                          questionDIv.classList.add(font);
                                        }
                                        var ques_icon1 =
                                          document.createElement("IMG");
                                        ques_icon1.alt = "Logo of " + totalData[0].name;
                                        ques_icon1.src = avatar_icon;
                                        var iconDiv = document.createElement("DIV");
                                        iconDiv.appendChild(ques_icon1);
                                        iconDiv.classList.add("question-icon-div");
                                        ques_icon1.classList.add(
                                          "question-icon-smatest"
                                        );
                                        var option_div =
                                          document.createElement("DIV");
                                        option_div.classList.add(
                                          "options-div-smatest"
                                        );
                                        var option_question =
                                          document.createElement("LABEL");
                                        option_question.innerHTML =
                                          question_arr[i].trim();
                                        say(option_question.innerText);
                                        option_div.appendChild(option_question);
                                        option_div.classList.add("m-l-40");
                                        if (i == question_arr.length - 1) {
                                          if (df_options && df_options.length > 0) {
                                            var optionsArray =
                                              df_options.split(";;");
                                          }
                                          questionDIv.appendChild(iconDiv);
                                          option_div.classList.remove("m-l-40");
                                          questionDIv.appendChild(option_div);
                                          if (enable_read_more) {
                                            var read_more_span =
                                              document.createElement("LABEL");
                                            read_more_span.innerHTML = generateTranslatedContent(translations, "Read more", main_lang_code, language_code, input);
                                            read_more_span.style.cssText = read_more_span.style.cssText + "color:#007bff !important;";
                                            read_more_span.style.fontSize = "14px";
                                            read_more_span.style.cursor = "pointer";
                                            if (font && font.length > 0) {
                                              read_more_span.classList.add(font);
                                            }
                                            var modal_div =
                                              document.createElement("DIV");
                                            if (font && font.length > 0) {
                                              modal_div.classList.add(font);
                                            }
                                            modal_div.classList.add(
                                              "modal-smatest"
                                            );
                                            modal_div.id = "myReadMoreModal";
                                            var modal_content_div =
                                              document.createElement("DIV");
                                            modal_content_div.style.width = "60%";
                                            modal_content_div.style.maxHeight =
                                              "calc(100vh - 50px)";
                                            modal_content_div.style.overflowY =
                                              "scroll";
                                            modal_content_div.classList.add(
                                              "modal-content-smatest"
                                            );
                                            var modal_close_span =
                                              document.createElement("SPAN");
                                            modal_close_span.classList.add(
                                              "close-modal"
                                            );
                                            modal_close_span.innerHTML = "&times";
                                            var table_div =
                                              document.createElement("DIV");
                                            table_div.style.paddingTop = "15px";
                                            table_div.style.paddingBotttom = "15px";
                                            table_div.style.paddingLeft = "10px";
                                            table_div.style.paddingRight = "10px";
                                            table_div.style.marginTop = "10px";
                                            table_div.style.marginBotttom = "10px";
                                            table_div.style.color = "black";
                                            table_div.innerHTML = complete_text;
                                            if (font && font.length > 0) {
                                              table_div.classList.add(font);
                                            }
                                            modal_content_div.appendChild(
                                              modal_close_span
                                            );
                                            modal_content_div.appendChild(
                                              table_div
                                            );
                                            modal_div.appendChild(
                                              modal_content_div
                                            );
                                            modal_div.style.display = "none";
                                            read_more_span.addEventListener(
                                              "click",
                                              function () {
                                                modal_div.style.display = "block";
                                              }
                                            );
                                            window.onclick = function (event) {
                                              if (event.target == modal_div) {
                                                modal_div.style.display = "none";
                                                isTableOpened = !1;
                                                nothingWentOnFor = 0;
                                                encourageMessageIteration = 0;
                                              }
                                            };
                                            modal_close_span.addEventListener(
                                              "click",
                                              function (k) {
                                                modal_div.style.display = "none";
                                                isTableOpened = !1;
                                                nothingWentOnFor = 0;
                                                encourageMessageIteration = 0;
                                              }
                                            );
                                            document.body.appendChild(modal_div);
                                            option_div.appendChild(read_more_span);
                                          }
                                          if (
                                            (firstCustomSingleChoiceOptions &&
                                              firstCustomSingleChoiceOptions.length >
                                              0) ||
                                            (these_options &&
                                              these_options.length > 0 &&
                                              these_options[0].length > 0)
                                          ) {
                                          } else {
                                          }
                                          var take_actions_div =
                                            document.createElement("DIV");
                                          take_actions_div.classList.add(
                                            "question-div-smatest"
                                          );
                                          setTimeout(function () {
                                            take_actions_div.classList.add("top-0");
                                          }, transition_time);
                                          if (font && font.length > 0) {
                                            take_actions_div.classList.add(font);
                                          }
                                          if (font && font.length > 0) {
                                            option_question.classList.add(font);
                                          }
                                          if (
                                            (main_lang_code &&
                                              (main_lang_code == "he" ||
                                                main_lang_code == "ur" ||
                                                main_lang_code == "ar")) ||
                                            (main_lang_code == "default" &&
                                              (language_code == "ar" ||
                                                language_code == "he" ||
                                                language_code == "ur"))
                                          ) {
                                            option_question.classList.add("rtl");
                                          }
                                        }
                                        questionDIv.appendChild(option_div);
                                        var otherSpinningDIv =
                                          document.createElement("DIV");
                                        var spinnerDiv =
                                          document.createElement("DIV");
                                        spinnerDiv.classList.add(
                                          "spinner1-smatest"
                                        );
                                        var ques_icon =
                                          document.createElement("IMG");
                                        ques_icon.src = avatar_icon;
                                        ques_icon.alt = "Logo of " + totalData[0].name;
                                        ques_icon.classList.add(
                                          "question-icon-smatest"
                                        );
                                        var inner1 = document.createElement("DIV");
                                        inner1.classList.add("bounce1");
                                        var inner2 = document.createElement("DIV");
                                        inner2.classList.add("bounce2");
                                        var inner3 = document.createElement("DIV");
                                        inner3.classList.add("bounce3");
                                        spinnerDiv.appendChild(inner1);
                                        spinnerDiv.appendChild(inner2);
                                        spinnerDiv.appendChild(inner3);
                                        otherSpinningDIv.classList.add("m-t-10");
                                        otherSpinningDIv.classList.add("m-l-40");
                                        otherSpinningDIv.classList.add("pull-left");
                                        otherSpinningDIv.appendChild(spinnerDiv);
                                        if (i != 0) {
                                          body.appendChild(otherSpinningDIv);
                                          body.scrollTop = body.scrollHeight;
                                        }
                                        if (i == 0) {
                                          if (i == question_arr.length - 1) {
                                            playBotUserSound(1);
                                          }
                                          i++;
                                          body.appendChild(questionDIv);
                                          body.scrollTop = body.scrollHeight;
                                          addQuestionArrays();
                                        } else {
                                          setTimeout(function () {
                                            body.removeChild(otherSpinningDIv);
                                            if (i == question_arr.length - 1) {
                                              playBotUserSound(1);
                                            }
                                            i++;
                                            questionDIv.id = i;
                                            body.appendChild(questionDIv);
                                            body.scrollTop = body.scrollHeight;
                                            addQuestionArrays();
                                          }, delay_time);
                                        }
                                        footer.style.display = "block";
                                        if (
                                          header.contains(company_title_description)
                                        ) {
                                          body.style.height = "calc(100% - 226px)";
                                        } else {
                                          body.style.height = "calc(100% - 150px)";
                                        }
                                        if (shouldShowMenu) {
                                          input.style.pointerEvents = "auto";
                                          microphone.style.pointerEvents = "auto";
                                          microphone.style.opacity = 1;
                                          enter.style.pointerEvents = "auto";
                                        }
                                        input.focus();
                                        footer.classList.remove("close");
                                      }
                                    }
                                    addQuestionArrays();
                                  }
                                }
                              }
                              if (question_array && question_array.length > 0) {
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 168px)";
                                  } else {
                                    body.style.height = "calc(100% - 93px)";
                                  }
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    enter.style.pointerEvents = "none";
                                    input.blur();
                                    input.placeholder = "Choose from Menu";
                                    input.type = "text";
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  }
                                }
                                question_completed = !1;
                                input_value = "";
                                if (question_arr && question_arr.length > 0) {
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(current_question_type);
                                  }, delay_time * question_arr.length + 100);
                                } else {
                                  setTimeout(function () {
                                    enter.style.pointerEvents = "auto";
                                    if (
                                      spinningDiv &&
                                      spinningDiv.parentNode == body
                                    ) {
                                      body.removeChild(spinningDiv);
                                    }
                                    current_question_type = question_array[0].type;
                                    current_logical_jump =
                                      question_array[0].logical_jump;
                                    currentMailSequence =
                                      question_array[0].sequence;
                                    currentQuestionIsLead =
                                      question_array[0].send_mail;
                                    question_id = question_array[0].id;
                                    setAllInputs(question_array);
                                    assignAllQuestionTypes(current_question_type);
                                  }, 100);
                                }
                              }
                            }, 100);
                          } else if (this.readyState == 4 && this.status == 400) {
                            try {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                            } catch (error) {
                            }
                            let resp_json = JSON.parse(this.responseText);
                            var errorDiv = document.createElement("DIV");
                            errorDiv.classList.add("question-div-smatest");
                            setTimeout(function () {
                              errorDiv.classList.add("top-0");
                            }, transition_time);
                            if (font && font.length > 0) {
                              errorDiv.classList.add(font);
                            }
                            var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                            error_icon.src = avatar_icon;
                            var iconDiv = document.createElement("DIV");
                            iconDiv.appendChild(error_icon);
                            iconDiv.classList.add("question-icon-div");
                            error_icon.classList.add("question-icon-smatest");
                            var error_text = document.createElement("LABEL");
                            if (
                              resp_json.message &&
                              resp_json.message.length > 0
                            ) {
                              error_text.innerHTML = resp_json.message;
                              say(resp_json.message);
                            } else {
                              error_text.innerHTML =
                                "This feature works only in the Pro plan along with the ChatGPT Addon";
                              say(error_text.innerText);
                            }
                            error_text.classList.add("question-text-error");
                            error_text.classList.add("options-div-smatest");
                            if (font && font.length > 0) {
                              error_text.classList.add(font);
                            }
                            errorDiv.appendChild(iconDiv);
                            errorDiv.appendChild(error_text);
                            body.appendChild(errorDiv);
                            playBotUserSound(1);
                          }
                        };
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0
                          // main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        xhttpOther.open(
                          "GET",
                          main_url +
                          "/kya_backend/pagehub/getChatBotAnswerv2?answer_text=" +
                          encodeURIComponent(input_value) +
                          "&question_id=" +
                          entry_id +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&cb_session=" +
                          cb_session +
                          "&language_code=" +
                          main_lang_code,
                          !0
                        );
                        xhttpOther.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        xhttpOther.send();
                      }
                    } else if (current_question_type == "number") {
                      var proceed;
                      question_and_answers.push({
                        id: question_id,
                        answer: input_value,
                      });
                      if (!number_skipped) {
                        if (
                          question_array[0].default_options &&
                          question_array[0].default_options.length > 0
                        ) {
                          var obj = JSON.parse(question_array[0].default_options);
                          if (
                            parseInt(input_value) >= obj.min &&
                            parseInt(input_value) <= obj.max
                          ) {
                            proceed = !0;
                          } else {
                            var answerDiv = document.createElement("DIV");
                            answerDiv.classList.add("answer-div");
                            setTimeout(function () {
                              answerDiv.classList.add("top-0");
                            }, transition_time);
                            var answer = document.createElement("LABEL");
                            var answer_text = document.createTextNode(input_value);
                            answer.appendChild(answer_text);
                            answer.classList.add("answer-label");
                            if (font && font.length > 0) {
                              answer.classList.add(font);
                            }
                            answerDiv.appendChild(answer);
                            body.appendChild(answerDiv);
                            body.scrollTop = body.scrollHeight;
                            var spinningDiv = document.createElement("DIV");
                            spinningDiv.classList.add("question-div-smatest");
                            spinningDiv.classList.add("top-0");
                            if (font && font.length > 0) {
                              spinningDiv.classList.add(font);
                            }
                            var spinnerDiv = document.createElement("DIV");
                            spinnerDiv.classList.add("spinner1-smatest");
                            var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                            ques_icon.src = avatar_icon;
                            var iconDiv = document.createElement("DIV");
                            iconDiv.appendChild(ques_icon);
                            iconDiv.classList.add("question-icon-div");
                            ques_icon.classList.add("question-icon-smatest");
                            var inner1 = document.createElement("DIV");
                            inner1.classList.add("bounce1");
                            var inner2 = document.createElement("DIV");
                            inner2.classList.add("bounce2");
                            var inner3 = document.createElement("DIV");
                            inner3.classList.add("bounce3");
                            spinnerDiv.appendChild(inner1);
                            spinnerDiv.appendChild(inner2);
                            spinnerDiv.appendChild(inner3);
                            spinningDiv.appendChild(iconDiv);
                            spinningDiv.appendChild(spinnerDiv);
                            body.appendChild(spinningDiv);
                            body.scrollTop = body.scrollHeight;
                            setTimeout(function () {
                              enter.style.pointerEvents = "auto";
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              current_logical_jump = question_array[0].logical_jump;
                              currentMailSequence = question_array[0].sequence;
                              currentQuestionIsLead = question_array[0].send_mail;
                              var errorDiv = document.createElement("DIV");
                              errorDiv.classList.add("question-div-smatest");
                              setTimeout(function () {
                                errorDiv.classList.add("top-0");
                              }, transition_time);
                              if (font && font.length > 0) {
                                errorDiv.classList.add(font);
                              }
                              var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                              error_icon.src = avatar_icon;
                              var iconDiv = document.createElement("DIV");
                              iconDiv.appendChild(error_icon);
                              iconDiv.classList.add("question-icon-div");
                              error_icon.classList.add("question-icon-smatest");
                              var error_text = document.createElement("LABEL");
                              translateContent(translations, error_text, "Please enter a valid url", main_lang_code, language_code);
                              say(error_text.innerText);
                              if (translations && translations.length > 0) {
                                translateContent(translations, error_text, "Please enter a valid url", main_lang_code, language_code);
                              } else {
                                if (chatbot_id == 12063) {
                                  translateContent(translations, error_text, "Sorry, we don't work on that price. Please increase your budget to secure your publication.", main_lang_code, language_code);
                                } else {
                                  translateContent(translations, error_text, "Please enter a number between " + obj.min + " and " + obj.max, main_lang_code, language_code);
                                }
                                say(error_text.innerText);
                              }
                              error_text.classList.add("question-text-error");
                              error_text.classList.add("options-div-smatest");
                              if (font && font.length > 0) {
                                error_text.classList.add(font);
                              }
                              errorDiv.appendChild(iconDiv);
                              errorDiv.appendChild(error_text);
                              body.appendChild(errorDiv);
                              playBotUserSound(1);
                              body.scrollTop = body.scrollHeight;
                              footer.style.display = "block";
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                              footer.classList.remove("close");
                              if (is_firefox) {
                                input.type = "text";
                              } else {
                                input.type = "number";
                              }
                              input.style.pointerEvents = "auto";
                              microphone.style.pointerEvents = "auto";
                              microphone.style.opacity = 1;
                              input.id = "";
                              if (shouldShowMenu) {
                                if (voice_input == "1") {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 115px) !important";
                                } else {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 80px) !important";
                                }
                              } else {
                                if (voice_input == "1") {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 75px) !important";
                                } else {
                                  input.style.cssText =
                                    input.style.cssText +
                                    "width:calc(100% - 45px) !important";
                                }
                              }
                              input.style.cssText =
                                input.style.cssText + "min-height:24px !important";
                                input.style.cssText = input.style.cssText + "height:24px !important";
                                input.style.cssText = input.style.cssText + "border:none !important";
                              // input.style.cssText =
                              // input.style.cssText + "max-height:72px !important";
                              footer.id = "";
                              input.autocomplete = "off";
                              try {
                                google.maps.event.clearInstanceListeners(input);
                              } catch (e) {
                              } finally {
                              }
                              translateContent(translations, input, "Enter a number", main_lang_code, language_code, 2);
                              input.focus();
                            }, delay_time);
                          }
                        } else {
                          proceed = !0;
                        }
                      }
                      if (number_skipped) {
                        proceed = true;
                      }
                      if (proceed) {
                        var skip_dv = document.getElementById("skip-question-div");
                        if (skip_dv) {
                          skip_dv.parentElement.style.marginBottom = "0";
                          skip_dv.parentElement.removeChild(skip_dv);
                        }
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (number_skipped) {
                          number_skipped = false;
                        } else {
                          body.appendChild(answerDiv);
                        }
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            question_and_answers.push({
                              id: question_id,
                              answer: input_value,
                            });
                            shouldDisableTakeAction = !1;
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      }
                    } else if (current_question_type == "question") {
                      var proceed;
                      if (
                        question_array[0].default_options &&
                        question_array[0].default_options.length > 0
                      ) {
                        var obj = JSON.parse(question_array[0].default_options);
                        var regex = new RegExp(obj.regex);
                        if (regex.test(input_value)) {
                          proceed = !0;
                        } else {
                          var answerDiv = document.createElement("DIV");
                          answerDiv.classList.add("answer-div");
                          setTimeout(function () {
                            answerDiv.classList.add("top-0");
                          }, transition_time);
                          var answer = document.createElement("LABEL");
                          var answer_text = document.createTextNode(input_value);
                          answer.appendChild(answer_text);
                          answer.classList.add("answer-label");
                          if (font && font.length > 0) {
                            answer.classList.add(font);
                          }
                          answerDiv.appendChild(answer);
                          body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                          var spinningDiv = document.createElement("DIV");
                          spinningDiv.classList.add("question-div-smatest");
                          spinningDiv.classList.add("top-0");
                          if (font && font.length > 0) {
                            spinningDiv.classList.add(font);
                          }
                          var spinnerDiv = document.createElement("DIV");
                          spinnerDiv.classList.add("spinner1-smatest");
                          var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                          ques_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(ques_icon);
                          iconDiv.classList.add("question-icon-div");
                          ques_icon.classList.add("question-icon-smatest");
                          var inner1 = document.createElement("DIV");
                          inner1.classList.add("bounce1");
                          var inner2 = document.createElement("DIV");
                          inner2.classList.add("bounce2");
                          var inner3 = document.createElement("DIV");
                          inner3.classList.add("bounce3");
                          spinnerDiv.appendChild(inner1);
                          spinnerDiv.appendChild(inner2);
                          spinnerDiv.appendChild(inner3);
                          spinningDiv.appendChild(iconDiv);
                          spinningDiv.appendChild(spinnerDiv);
                          body.appendChild(spinningDiv);
                          body.scrollTop = body.scrollHeight;
                          setTimeout(function () {
                            enter.style.pointerEvents = "auto";
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            current_logical_jump = question_array[0].logical_jump;
                            currentMailSequence = question_array[0].sequence;
                            currentQuestionIsLead = question_array[0].send_mail;
                            var errorDiv = document.createElement("DIV");
                            errorDiv.classList.add("question-div-smatest");
                            setTimeout(function () {
                              errorDiv.classList.add("top-0");
                            }, transition_time);
                            if (font && font.length > 0) {
                              errorDiv.classList.add(font);
                            }
                            var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                            error_icon.src = avatar_icon;
                            var iconDiv = document.createElement("DIV");
                            iconDiv.appendChild(error_icon);
                            iconDiv.classList.add("question-icon-div");
                            error_icon.classList.add("question-icon-smatest");
                            var error_text = document.createElement("LABEL");
                            if (
                              question_array[0].error_text &&
                              question_array[0].error_text.length > 0
                            ) {
                              error_text.innerHTML = question_array[0].error_text;
                              say(question_array[0].error_text);
                            } else {
                              translateContent(translations, error_text, "Please enter a valid answer", main_lang_code, language_code);
                              say(error_text.innerText);
                            }
                            error_text.classList.add("question-text-error");
                            error_text.classList.add("options-div-smatest");
                            if (font && font.length > 0) {
                              error_text.classList.add(font);
                            }
                            errorDiv.appendChild(iconDiv);
                            errorDiv.appendChild(error_text);
                            body.appendChild(errorDiv);
                            playBotUserSound(1);
                            footer.style.display = "block";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                            footer.classList.remove("close");
                            var selected_country =
                              document.getElementById("selected_country");
                            if (footer.contains(selected_country)) {
                              footer.removeChild(selected_country);
                            }
                            if (is_safari) {
                              input.type = "value";
                            } else {
                              input.type = "text";
                            }
                            input.id = "";
                            if (shouldShowMenu) {
                              if (voice_input == "1") {
                                input.style.cssText =
                                  input.style.cssText +
                                  "width:calc(100% - 115px) !important";
                              } else {
                                input.style.cssText =
                                  input.style.cssText +
                                  "width:calc(100% - 80px) !important";
                              }
                            } else {
                              if (voice_input == "1") {
                                input.style.cssText =
                                  input.style.cssText +
                                  "width:calc(100% - 75px) !important";
                              } else {
                                input.style.cssText =
                                  input.style.cssText +
                                  "width:calc(100% - 45px) !important";
                              }
                            }
                            input.style.pointerEvents = "auto";
                            microphone.style.pointerEvents = "auto";
                            microphone.style.opacity = 1;
                            input.style.cssText =
                              input.style.cssText + "min-height:24px !important";
                              input.style.cssText = input.style.cssText + "height:24px !important";
                              input.style.cssText = input.style.cssText + "border:none !important";
                            // input.style.cssText =
                            // input.style.cssText + "max-height:72px !important";
                            footer.id = "";
                            input.autocomplete = "off";
                            try {
                              google.maps.event.clearInstanceListeners(input);
                            } catch (e) {
                            } finally {
                            }
                            translateContent(translations, input, "Type your answer", main_lang_code, language_code, 2);
                            input.focus();
                            setTimeout(function () {
                              body.scrollTop = body.scrollHeight;
                            }, 500);
                          }, delay_time);
                        }
                      } else {
                        proceed = !0;
                      }
                      if (question_skipped) {
                        proceed = true;
                      }
                      if (proceed) {
                        var skip_dv = document.getElementById("skip-question-div");
                        if (skip_dv) {
                          skip_dv.parentElement.style.marginBottom = "0";
                          skip_dv.parentElement.removeChild(skip_dv);
                        }
                        question_and_answers.push({
                          id: question_id,
                          answer: input_value,
                        });
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        if (question_array[0].default_options && question_array[0].default_options.length > 0) {
                          var json = JSON.parse(question_array[0].default_options);
                          if (json.data_mask) {
                            var answer_text = document.createTextNode(input_value.replace(/./g, '*'));
                          } else {
                            var answer_text = document.createTextNode(input_value);
                          }
                        } else {
                          var answer_text = document.createTextNode(input_value);
                        }
                        // var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (question_skipped) {
                          question_skipped = false;
                        } else {
                          body.appendChild(answerDiv);
                        }
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            encodeURIComponent(input_value) +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      }
                    } else if (current_question_type == "ask_contacts") {
                      var proceed;
                      var error_message;
                      var name_conatct_array = input_value.split(",");
                      if (name_conatct_array && name_conatct_array.length > 0) {
                        if (
                          name_conatct_array[0] &&
                          name_conatct_array[0].length > 0
                        ) {
                          if (
                            name_conatct_array[1] &&
                            name_conatct_array[1].length > 0
                          ) {
                            proceed = true;
                          } else {
                            error_message = "Phone Number cannot be empty";
                          }
                        } else {
                          error_message = "Name cannot be empty";
                        }
                      } else {
                        error_message =
                          "Please enter your contact in Name, Phone Number format";
                      }
                      if (proceed || contacts_skipped) {
                        var skip_dv = document.getElementById("skip-question-div");
                        if (skip_dv) {
                          skip_dv.parentElement.style.marginBottom = "0";
                          skip_dv.parentElement.removeChild(skip_dv);
                        }
                        var answer_obj = {};
                        if (contacts_skipped) {
                          answer_obj.name = "skipped";
                          answer_obj.number = "skipped";
                        } else {
                          answer_obj.name = name_conatct_array[0].trim();
                          answer_obj.number = name_conatct_array[1].trim();
                        }
                        question_and_answers.push({
                          id: question_id,
                          answer: JSON.stringify(answer_obj),
                        });
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        if (contacts_skipped) {
                          contacts_skipped = false;
                        } else {
                          body.appendChild(answerDiv);
                        }
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        inTheMiddle = !0;
                        var xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                          entered = !1;
                          if (this.readyState == 4 && this.status == 200) {
                            shouldDisableTakeAction = !1;
                            if (currentQuestionIsLead == "1" && !mailSent) {
                              sendAlertCall();
                            } else {
                              if (mailSequence < currentMailSequence) {
                                random_key = !0;
                              } else {
                                random_key = !1;
                              }
                            }
                            cb_session = JSON.parse(this.response).cb_session;
                            live_chat_cb_session = JSON.parse(
                              this.response
                            ).livechat_session;
                            if (
                              JSON.parse(this.response).language_code &&
                              JSON.parse(this.response).language_code.length > 0 &&
                              JSON.parse(this.response).language_code != "default"
                            ) {
                              main_lang_code = JSON.parse(
                                this.response
                              ).language_code;
                            }
                            session_feedback = JSON.parse(this.response).feedback;
                            question_array = JSON.parse(
                              this.response
                            ).next_question;
                            if (question_array && question_array.length > 0) {
                              question_completed = !1;
                              input_value = "";
                              setTimeout(function () {
                                enter.style.pointerEvents = "auto";
                                if (spinningDiv && spinningDiv.parentNode == body) {
                                  body.removeChild(spinningDiv);
                                }
                                current_question_type = question_array[0].type;
                                current_logical_jump =
                                  question_array[0].logical_jump;
                                currentMailSequence = question_array[0].sequence;
                                currentQuestionIsLead = question_array[0].send_mail;
                                question_id = question_array[0].id;
                                setAllInputs(question_array);
                                assignAllQuestionTypes(current_question_type);
                              }, delay_time);
                            } else {
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              enter.style.pointerEvents = "auto";
                              question_completed = !0;
                              if (!mailSent || mailSent) {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      if (
                                        zapier_webhook &&
                                        zapier_webhook.length > 0
                                      ) {
                                        var output = {};
                                        output.timestamp = new Date();
                                        for (
                                          var i = 0;
                                          i < prev_questions_array.length;
                                          i++
                                        ) {
                                          var str =
                                            prev_questions_array[i].question_text;
                                          output[str] =
                                            prev_questions_array[i].answer_text;
                                        }
                                        var xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                          if (
                                            this.readyState == 4 &&
                                            this.status == 200
                                          ) {
                                          }
                                        };
                                        xhttp.open("POST", zapier_webhook, !0);
                                        xhttp.setRequestHeader(
                                          "Content-type",
                                          "application/x-www-form-urlencoded"
                                        );
                                        xhttp.send(
                                          "output=" + JSON.stringify(output)
                                        );
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              } else {
                                var xhttp = new XMLHttpRequest();
                                xhttp.onreadystatechange = function () {
                                  if (this.readyState == 4 && this.status == 200) {
                                    var questionArray = [];
                                    prev_questions_array = JSON.parse(
                                      this.response
                                    ).qna_prev;
                                    if (
                                      prev_questions_array &&
                                      prev_questions_array.length > 0
                                    ) {
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        if (
                                          prev_questions_array[i].type ==
                                          "contact" ||
                                          prev_questions_array[i].type ==
                                          "slides" ||
                                          prev_questions_array[i].type ==
                                          "statement" ||
                                          prev_questions_array[i].type ==
                                          "url_auto_redirect" ||
                                          prev_questions_array[i].type ==
                                          "custom_answer" ||
                                          prev_questions_array[i].type ==
                                          "show_file" ||
                                          prev_questions_array[i].type ==
                                          "show_contacts" ||
                                          prev_questions_array[i].type ==
                                          "show_location"
                                        ) {
                                          prev_questions_array.splice(i, 1);
                                          i--;
                                        }
                                      }
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        questionArray.push({
                                          question:
                                            prev_questions_array[i].question_text,
                                          answer:
                                            prev_questions_array[i].answer_text,
                                        });
                                      }
                                    }
                                  }
                                };
                                xhttp.open(
                                  "POST",
                                  main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                  !0
                                );
                                xhttp.setRequestHeader(
                                  "Content-type",
                                  "application/x-www-form-urlencoded"
                                );
                                if (
                                  main_lang_code &&
                                  main_lang_code.length > 0 &&
                                  main_lang_code != language_code
                                ) {
                                } else {
                                  main_lang_code = "default";
                                }
                                var bot_widget_obj;
                                var is_sendable;
                                try {
                                  checkSaveMAxUserLogin();
                                  checkRateGainDetails();
                                } catch (error) { }
                                if (window.botWidget && window.botWidget.user) {
                                  var keys = Object.keys(window.botWidget.user);
                                  for (var t = 0; t < keys.length; t++) {
                                    if (
                                      window.botWidget.user[keys[t]] &&
                                      window.botWidget.user[keys[t]].length > 0
                                    ) {
                                      is_sendable = true;
                                    }
                                  }
                                  if (is_sendable) {
                                    bot_widget_obj = window.botWidget.user;
                                  } else {
                                    bot_widget_obj = "";
                                  }
                                  if (window.botWidget.user.bot_id) {
                                    delete window.botWidget.user.bot_id;
                                  }
                                  if (window.botWidget.user.url) {
                                    delete window.botWidget.user.url;
                                  }
                                }
                                xhttp.send(
                                  "action=init_chat&device_print=" +
                                  device_print +
                                  "&chatbot_id=" +
                                  chatbot_id +
                                  "&language_code=" +
                                  main_lang_code +
                                  "&bot_widget_obj=" +
                                  JSON.stringify(bot_widget_obj)
                                );
                              }
                              if (!entry_id) {
                                showInput = !0;
                                if (!shouldShowMenu) {
                                  footer.style.display = "none";
                                  footer.classList.add("close");
                                } else {
                                  if (entry_id) {
                                    input.style.pointerEvents = "auto";
                                    microphone.style.pointerEvents = "auto";
                                    microphone.style.opacity = 1;
                                    enter.style.pointerEvents = "auto";
                                    setPlaceHolders();
                                    if (
                                      header.contains(company_title_description)
                                    ) {
                                      body.style.height = "calc(100% - 226px)";
                                    } else {
                                      body.style.height = "calc(100% - 150px)";
                                    }
                                  } else {
                                    input.style.pointerEvents = "none";
                                    microphone.style.pointerEvents = "none";
                                    microphone.style.opacity = 0;
                                    input.blur();
                                    enter.style.pointerEvents = "none";
                                    input.placeholder = "Choose from Menu";
                                  }
                                }
                              }
                              if (!shouldShowMenu) {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                              } else {
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 226px)";
                                } else {
                                  body.style.height = "calc(100% - 150px)";
                                }
                              }
                            }
                          }
                        };
                        xhttp.open(
                          "POST",
                          main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                          !0
                        );
                        xhttp.setRequestHeader(
                          "Content-type",
                          "application/x-www-form-urlencoded"
                        );
                        if (
                          main_lang_code &&
                          main_lang_code.length > 0 &&
                          main_lang_code != language_code
                        ) {
                        } else {
                          main_lang_code = "default";
                        }
                        if (
                          current_logical_jump == "1" &&
                          current_question_type != "radio" &&
                          current_question_type != "rating"
                        ) {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            "sometext&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        } else {
                          xhttp.send(
                            "action=answer&answer_text=" +
                            encodeURIComponent(input_value) +
                            "&cb_session=" +
                            cb_session +
                            "&question_id=" +
                            question_id +
                            "&is_logical=" +
                            current_logical_jump +
                            "&sequence=" +
                            currentMailSequence +
                            "&chatbot_id=" +
                            chatbot_id +
                            "&option=" +
                            actualDate +
                            "&visitor_link_traversal=" +
                            visitedUrls +
                            "&language_code=" +
                            main_lang_code
                          );
                        }
                      } else {
                        var answer_obj = {};
                        var answerDiv = document.createElement("DIV");
                        answerDiv.classList.add("answer-div");
                        setTimeout(function () {
                          answerDiv.classList.add("top-0");
                        }, transition_time);
                        var answer = document.createElement("LABEL");
                        var answer_text = document.createTextNode(input_value);
                        answer.appendChild(answer_text);
                        answer.classList.add("answer-label");
                        if (font && font.length > 0) {
                          answer.classList.add(font);
                        }
                        answerDiv.appendChild(answer);
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                        var spinningDiv = document.createElement("DIV");
                        spinningDiv.classList.add("question-div-smatest");
                        spinningDiv.classList.add("top-0");
                        if (font && font.length > 0) {
                          spinningDiv.classList.add(font);
                        }
                        var spinnerDiv = document.createElement("DIV");
                        spinnerDiv.classList.add("spinner1-smatest");
                        var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                        ques_icon.src = avatar_icon;
                        var iconDiv = document.createElement("DIV");
                        iconDiv.appendChild(ques_icon);
                        iconDiv.classList.add("question-icon-div");
                        ques_icon.classList.add("question-icon-smatest");
                        var inner1 = document.createElement("DIV");
                        inner1.classList.add("bounce1");
                        var inner2 = document.createElement("DIV");
                        inner2.classList.add("bounce2");
                        var inner3 = document.createElement("DIV");
                        inner3.classList.add("bounce3");
                        spinnerDiv.appendChild(inner1);
                        spinnerDiv.appendChild(inner2);
                        spinnerDiv.appendChild(inner3);
                        spinningDiv.appendChild(iconDiv);
                        spinningDiv.appendChild(spinnerDiv);
                        body.appendChild(spinningDiv);
                        body.scrollTop = body.scrollHeight;
                        setTimeout(function () {
                          body.removeChild(spinningDiv);
                          var errorDiv = document.createElement("DIV");
                          errorDiv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            errorDiv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            errorDiv.classList.add(font);
                          }
                          var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                          error_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(error_icon);
                          iconDiv.classList.add("question-icon-div");
                          error_icon.classList.add("question-icon-smatest");
                          var error_text = document.createElement("LABEL");
                          error_text.innerHTML = error_message;
                          say(error_text.innerText);
                          error_text.classList.add("question-text-error");
                          error_text.classList.add("options-div-smatest");
                          if (font && font.length > 0) {
                            error_text.classList.add(font);
                          }
                          errorDiv.appendChild(iconDiv);
                          errorDiv.appendChild(error_text);
                          body.appendChild(errorDiv);
                          playBotUserSound(1);
                          footer.style.display = "block";
                          footer.classList.remove("close");
                          input.style.pointerEvents = "auto";
                          microphone.style.pointerEvents = "auto";
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = "auto";
                          translateContent(translations, input, "Contact in Name, Phone Number format", main_lang_code, language_code, 2);
                          if (header.contains(company_title_description)) {
                            body.style.height = "calc(100% - 226px)";
                          } else {
                            body.style.height = "calc(100% - 150px)";
                          }
                          body.scrollTop = body.scrollHeight;
                        }, 1000);
                      }
                    } else if (
                      current_question_type == "radio" ||
                      current_question_type == "whatsapp_buttons" ||
                      current_question_type == "whatsapp_list" ||
                      current_question_type == "radio_slides" ||
                      current_question_type == "custom_single_choice" ||
                      current_question_type == "rating" ||
                      current_question_type == "range" ||
                      current_question_type == "file_upload" ||
                      current_question_type == "checkbox"
                    ) {
                      if (body.lastChild && body.lastChild.lastChild) {
                        var div = body.lastChild.lastChild;
                        var firstChild = div.firstChild;
                        if (
                          div &&
                          div.childNodes &&
                          div.childNodes[1] &&
                          div.childNodes[1].className == "image-div-smatest"
                        ) {
                          var anotherDiv = div.childNodes[1];
                        }
                        while (div.firstChild) {
                          div.removeChild(div.firstChild);
                        }
                        div.appendChild(firstChild);
                        if (anotherDiv) {
                          div.appendChild(anotherDiv);
                        }
                      }
                      if (
                        current_question_type == "radio" ||
                        current_question_type == "whatsapp_buttons" ||
                        current_question_type == "whatsapp_list"
                      ) {
                        if (
                          radio_options &&
                          radio_options.length > 0 &&
                          is_radio_hidden
                        ) {
                          var temp_options = [];
                          for (var t = 0; t < radio_options.length; t++) {
                            temp_options.push(radio_options[t].toLowerCase());
                          }
                          if (
                            temp_options.indexOf(input_value.toLowerCase()) > -1
                          ) {
                            current_question_type = "question";
                            input.value = input_value;
                            var answerDiv = document.createElement("DIV");
                            answerDiv.classList.add("answer-div");
                            setTimeout(function () {
                              answerDiv.classList.add("top-0");
                            }, transition_time);
                            var answer = document.createElement("LABEL");
                            var answer_text = document.createTextNode(input_value);
                            answer.appendChild(answer_text);
                            answer.classList.add("answer-label");
                            if (font && font.length > 0) {
                              answer.classList.add(font);
                            }
                            answerDiv.appendChild(answer);
                            body.appendChild(answerDiv);
                            body.scrollTop = body.scrollHeight;
                            takingRadioValue(
                              radio_options[
                              temp_options.indexOf(input_value.toLowerCase())
                              ],
                              undefined,
                              1
                            );
                            return;
                          } else {
                            input.type = "text";
                            input.placeholder = "Enter your option";
                            enter.style.pointerEvents = "auto";
                            footer.style.display = "block";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                            footer.classList.remove("close");
                            input.value = "";
                            if (document.getElementById("live-file-input")) {
                              document.getElementById("live-file-input").value = "";
                            }
                            var answerDiv = document.createElement("DIV");
                            answerDiv.classList.add("answer-div");
                            setTimeout(function () {
                              answerDiv.classList.add("top-0");
                            }, transition_time);
                            var answer = document.createElement("LABEL");
                            var answer_text = document.createTextNode(input_value);
                            answer.appendChild(answer_text);
                            answer.classList.add("answer-label");
                            if (font && font.length > 0) {
                              answer.classList.add(font);
                            }
                            answerDiv.appendChild(answer);
                            body.appendChild(answerDiv);
                            body.scrollTop = body.scrollHeight;
                            var errorDiv = document.createElement("DIV");
                            errorDiv.classList.add("question-div-smatest");
                            setTimeout(function () {
                              errorDiv.classList.add("top-0");
                            }, transition_time);
                            if (font && font.length > 0) {
                              errorDiv.classList.add(font);
                            }
                            var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                            error_icon.src = avatar_icon;
                            var iconDiv = document.createElement("DIV");
                            iconDiv.appendChild(error_icon);
                            iconDiv.classList.add("question-icon-div");
                            error_icon.classList.add("question-icon-smatest");
                            var error_text = document.createElement("LABEL");
                            error_text.innerHTML = "Please enter a valid option";
                            say(error_text.innerText);
                            error_text.classList.add("question-text-error");
                            error_text.classList.add("options-div-smatest");
                            if (font && font.length > 0) {
                              error_text.classList.add(font);
                            }
                            errorDiv.appendChild(iconDiv);
                            errorDiv.appendChild(error_text);
                            body.appendChild(errorDiv);
                            playBotUserSound(1);
                            body.scrollTop = body.scrollHeight;
                            return;
                          }
                        }
                        if (!question_array[0] || !question_array[0].ai_question_id || !question_array[0].ai_question_id.toString().length == 0) {
                          current_question_type = "question";
                          input.value = input_value;
                          var answerDiv = document.createElement("DIV");
                          answerDiv.classList.add("answer-div");
                          setTimeout(function () {
                            answerDiv.classList.add("top-0");
                          }, transition_time);
                          var answer = document.createElement("LABEL");
                          var answer_text = document.createTextNode(input_value);
                          answer.appendChild(answer_text);
                          answer.classList.add("answer-label");
                          if (font && font.length > 0) {
                            answer.classList.add(font);
                          }
                          answerDiv.appendChild(answer);
                          takingRadioValue(
                            input_value,
                            body.lastChild,
                            6
                          );
                          // body.appendChild(answerDiv);
                          body.scrollTop = body.scrollHeight;
                          return;
                        }
                      }
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      var answer_text = document.createTextNode(input_value);
                      answer.appendChild(answer_text);
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      body.appendChild(answerDiv);
                      body.scrollTop = body.scrollHeight;
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      var xhttpOther = new XMLHttpRequest();
                      xhttpOther.onreadystatechange = function () {
                        entered = !1;
                        if (this.readyState == 4 && this.status == 200) {
                          shouldDisableTakeAction = !1;
                          if (
                            JSON.parse(this.responseText).answer_text &&
                            JSON.parse(this.responseText).answer_text.length > 0
                          ) {
                            var answerDialog = JSON.parse(
                              this.responseText
                            ).answer_text;
                          } else {
                            var answerDialog = "";
                          }
                          question_array = JSON.parse(
                            this.responseText
                          ).next_question;
                          input_value = "";
                          var question_arr;
                          setTimeout(function () {
                            footer.style.display = "block";
                            if (header.contains(company_title_description)) {
                              body.style.height = "calc(100% - 226px)";
                            } else {
                              body.style.height = "calc(100% - 150px)";
                            }
                            footer.classList.remove("close");
                            if (shouldShowMenu) {
                              input.style.pointerEvents = "auto";
                              microphone.style.pointerEvents = "auto";
                              microphone.style.opacity = 1;
                              enter.style.pointerEvents = "auto";
                            }
                            input.focus();
                            enter.style.pointerEvents = "auto";
                            if (!entry_id) {
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  enter.style.pointerEvents = "none";
                                  input.blur();
                                  input.placeholder = "Choose from Menu";
                                  input.type = "text";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                }
                              }
                            }
                            enter.style.pointerEvents = "auto";
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            if (answerDialog && answerDialog.length > 0) {
                              if (
                                answerDialog.includes("<table") &&
                                answerDialog.includes("</table>")
                              ) {
                                isTableOpened = !0;
                                playBotUserSound(1);
                                nothingWentOnFor = 0;
                                encourageMessageIteration = 0;
                                var modal_div = document.createElement("DIV");
                                if (font && font.length > 0) {
                                  modal_div.classList.add(font);
                                }
                                modal_div.classList.add("modal-smatest");
                                modal_div.id = "myModal";
                                var modal_content_div =
                                  document.createElement("DIV");
                                modal_content_div.classList.add(
                                  "modal-content-smatest"
                                );
                                var modal_close_span =
                                  document.createElement("SPAN");
                                modal_close_span.classList.add("close-modal");
                                modal_close_span.innerHTML = "&times";
                                var table_div = document.createElement("DIV");
                                table_div.style.color = "black";
                                table_div.innerHTML = answerDialog;
                                modal_content_div.appendChild(modal_close_span);
                                modal_content_div.appendChild(table_div);
                                modal_div.appendChild(modal_content_div);
                                modal_div.style.display = "block";
                                window.onclick = function (event) {
                                  if (event.target == modal_div) {
                                    modal_div.style.display = "none";
                                    isTableOpened = !1;
                                    nothingWentOnFor = 0;
                                    encourageMessageIteration = 0;
                                  }
                                };
                                modal_close_span.addEventListener(
                                  "click",
                                  function (k) {
                                    modal_div.style.display = "none";
                                    isTableOpened = !1;
                                    nothingWentOnFor = 0;
                                    encourageMessageIteration = 0;
                                  }
                                );
                                document.body.appendChild(modal_div);
                              } else {
                                var k = document.createElement("DIV");
                                k.innerHTML = answerDialog;
                                var inner_text = k.innerText;
                                var enable_read_more;
                                var complete_text = answerDialog;
                                if (answerDialog && answerDialog.length > 500) {
                                  enable_read_more = true;
                                  answerDialog =
                                    answerDialog.substring(0, 500) + "... ";
                                  k.innerHTML = answerDialog;
                                  answerDialog = k.innerHTML;
                                }
                                if (answerDialog.includes("<br/>")) {
                                  question_arr = answerDialog.split("<br/>");
                                } else if (answerDialog.includes(" /n")) {
                                  question_arr = answerDialog.split(" /n");
                                } else if (answerDialog.includes(" \n")) {
                                  question_arr = answerDialog.split(" \n");
                                } else {
                                  question_arr = [];
                                  question_arr.push(answerDialog);
                                }
                                if (question_arr && question_arr.length > 0) {
                                  var i = 0;

                                  function addQuestionArrays() {
                                    if (i < question_arr.length) {
                                      var questionDIv =
                                        document.createElement("DIV");
                                      questionDIv.classList.add(
                                        "question-div-smatest"
                                      );
                                      setTimeout(function () {
                                        questionDIv.classList.add("top-0");
                                      }, transition_time);
                                      if (font && font.length > 0) {
                                        questionDIv.classList.add(font);
                                      }
                                      var ques_icon1 =
                                        document.createElement("IMG");
                                      ques_icon1.src = avatar_icon;
                                      ques_icon1.alt = "Logo of " + totalData[0].name;
                                      var iconDiv = document.createElement("DIV");
                                      iconDiv.appendChild(ques_icon1);
                                      iconDiv.classList.add("question-icon-div");
                                      ques_icon1.classList.add(
                                        "question-icon-smatest"
                                      );
                                      var option_div =
                                        document.createElement("DIV");
                                      option_div.classList.add(
                                        "options-div-smatest"
                                      );
                                      var option_question =
                                        document.createElement("LABEL");
                                      option_question.innerHTML =
                                        question_arr[i].trim();
                                      say(option_question.innerText);
                                      option_div.appendChild(option_question);
                                      option_div.classList.add("m-l-40");
                                      if (i == question_arr.length - 1) {
                                        if (df_options && df_options.length > 0) {
                                          var optionsArray = df_options.split(";;");
                                        }
                                        questionDIv.appendChild(iconDiv);
                                        option_div.classList.remove("m-l-40");
                                        questionDIv.appendChild(option_div);
                                        if (enable_read_more) {
                                          var read_more_span =
                                            document.createElement("LABEL");
                                          read_more_span.innerHTML = generateTranslatedContent(translations, "Read more", main_lang_code, language_code, input);
                                          read_more_span.style.cssText = read_more_span.style.cssText + "color:#007bff !important;";
                                          read_more_span.style.fontSize = "14px";
                                          read_more_span.style.cursor = "pointer";
                                          if (font && font.length > 0) {
                                            read_more_span.classList.add(font);
                                          }
                                          var modal_div =
                                            document.createElement("DIV");
                                          if (font && font.length > 0) {
                                            modal_div.classList.add(font);
                                          }
                                          modal_div.classList.add("modal-smatest");
                                          modal_div.id = "myReadMoreModal";
                                          var modal_content_div =
                                            document.createElement("DIV");
                                          modal_content_div.style.width = "60%";
                                          modal_content_div.style.maxHeight =
                                            "calc(100vh - 50px)";
                                          modal_content_div.style.overflowY =
                                            "scroll";
                                          modal_content_div.classList.add(
                                            "modal-content-smatest"
                                          );
                                          var modal_close_span =
                                            document.createElement("SPAN");
                                          modal_close_span.classList.add(
                                            "close-modal"
                                          );
                                          modal_close_span.innerHTML = "&times";
                                          var table_div =
                                            document.createElement("DIV");
                                          table_div.style.paddingTop = "15px";
                                          table_div.style.paddingBotttom = "15px";
                                          table_div.style.paddingLeft = "10px";
                                          table_div.style.paddingRight = "10px";
                                          table_div.style.marginTop = "10px";
                                          table_div.style.marginBotttom = "10px";
                                          table_div.style.color = "black";
                                          table_div.innerHTML = complete_text;
                                          if (font && font.length > 0) {
                                            table_div.classList.add(font);
                                          }
                                          modal_content_div.appendChild(
                                            modal_close_span
                                          );
                                          modal_content_div.appendChild(table_div);
                                          modal_div.appendChild(modal_content_div);
                                          modal_div.style.display = "none";
                                          read_more_span.addEventListener(
                                            "click",
                                            function () {
                                              modal_div.style.display = "block";
                                            }
                                          );
                                          window.onclick = function (event) {
                                            if (event.target == modal_div) {
                                              modal_div.style.display = "none";
                                              isTableOpened = !1;
                                              nothingWentOnFor = 0;
                                              encourageMessageIteration = 0;
                                            }
                                          };
                                          modal_close_span.addEventListener(
                                            "click",
                                            function (k) {
                                              modal_div.style.display = "none";
                                              isTableOpened = !1;
                                              nothingWentOnFor = 0;
                                              encourageMessageIteration = 0;
                                            }
                                          );
                                          document.body.appendChild(modal_div);
                                          option_div.appendChild(read_more_span);
                                        }
                                        if (
                                          (firstCustomSingleChoiceOptions &&
                                            firstCustomSingleChoiceOptions.length >
                                            0) ||
                                          (these_options &&
                                            these_options.length > 0 &&
                                            these_options[0].length > 0)
                                        ) {
                                        } else {
                                        }
                                        var take_actions_div =
                                          document.createElement("DIV");
                                        take_actions_div.classList.add(
                                          "question-div-smatest"
                                        );
                                        setTimeout(function () {
                                          take_actions_div.classList.add("top-0");
                                        }, transition_time);
                                        if (font && font.length > 0) {
                                          take_actions_div.classList.add(font);
                                        }
                                        if (font && font.length > 0) {
                                          option_question.classList.add(font);
                                        }
                                        if (
                                          (main_lang_code &&
                                            (main_lang_code == "he" ||
                                              main_lang_code == "ur" ||
                                              main_lang_code == "ar")) ||
                                          (main_lang_code == "default" &&
                                            (language_code == "ar" ||
                                              language_code == "he" ||
                                              language_code == "ur"))
                                        ) {
                                          option_question.classList.add("rtl");
                                        }
                                      }
                                      questionDIv.appendChild(option_div);
                                      var otherSpinningDIv =
                                        document.createElement("DIV");
                                      var spinnerDiv =
                                        document.createElement("DIV");
                                      spinnerDiv.classList.add("spinner1-smatest");
                                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                                      ques_icon.src = avatar_icon;
                                      ques_icon.classList.add(
                                        "question-icon-smatest"
                                      );
                                      var inner1 = document.createElement("DIV");
                                      inner1.classList.add("bounce1");
                                      var inner2 = document.createElement("DIV");
                                      inner2.classList.add("bounce2");
                                      var inner3 = document.createElement("DIV");
                                      inner3.classList.add("bounce3");
                                      spinnerDiv.appendChild(inner1);
                                      spinnerDiv.appendChild(inner2);
                                      spinnerDiv.appendChild(inner3);
                                      otherSpinningDIv.classList.add("m-t-10");
                                      otherSpinningDIv.classList.add("m-l-40");
                                      otherSpinningDIv.classList.add("pull-left");
                                      otherSpinningDIv.appendChild(spinnerDiv);
                                      if (i != 0) {
                                        body.appendChild(otherSpinningDIv);
                                        body.scrollTop = body.scrollHeight;
                                      }
                                      if (i == 0) {
                                        if (i == question_arr.length - 1) {
                                          playBotUserSound(1);
                                        }
                                        i++;
                                        body.appendChild(questionDIv);
                                        body.scrollTop = body.scrollHeight;
                                        addQuestionArrays();
                                      } else {
                                        setTimeout(function () {
                                          body.removeChild(otherSpinningDIv);
                                          if (i == question_arr.length - 1) {
                                            playBotUserSound(1);
                                          }
                                          i++;
                                          questionDIv.id = i;
                                          body.appendChild(questionDIv);
                                          body.scrollTop = body.scrollHeight;
                                          addQuestionArrays();
                                        }, delay_time);
                                      }
                                      footer.style.display = "block";
                                      if (
                                        header.contains(company_title_description)
                                      ) {
                                        body.style.height = "calc(100% - 226px)";
                                      } else {
                                        body.style.height = "calc(100% - 150px)";
                                      }
                                      if (shouldShowMenu) {
                                        input.style.pointerEvents = "auto";
                                        microphone.style.pointerEvents = "auto";
                                        microphone.style.opacity = 1;
                                        enter.style.pointerEvents = "auto";
                                      }
                                      input.focus();
                                      footer.classList.remove("close");
                                    }
                                  }
                                  addQuestionArrays();
                                }
                              }
                            }
                            if (question_array && question_array.length > 0) {
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                if (header.contains(company_title_description)) {
                                  body.style.height = "calc(100% - 168px)";
                                } else {
                                  body.style.height = "calc(100% - 93px)";
                                }
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  enter.style.pointerEvents = "none";
                                  input.blur();
                                  input.placeholder = "Choose from Menu";
                                  input.type = "text";
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                }
                              }
                              question_completed = !1;
                              input_value = "";
                              if (question_arr && question_arr.length > 0) {
                                setTimeout(function () {
                                  enter.style.pointerEvents = "auto";
                                  if (
                                    spinningDiv &&
                                    spinningDiv.parentNode == body
                                  ) {
                                    body.removeChild(spinningDiv);
                                  }
                                  current_question_type = question_array[0].type;
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  question_id = question_array[0].id;
                                  setAllInputs(question_array);
                                  assignAllQuestionTypes(current_question_type);
                                }, delay_time * question_arr.length + 100);
                              } else {
                                setTimeout(function () {
                                  enter.style.pointerEvents = "auto";
                                  if (
                                    spinningDiv &&
                                    spinningDiv.parentNode == body
                                  ) {
                                    body.removeChild(spinningDiv);
                                  }
                                  current_question_type = question_array[0].type;
                                  current_logical_jump =
                                    question_array[0].logical_jump;
                                  currentMailSequence = question_array[0].sequence;
                                  currentQuestionIsLead =
                                    question_array[0].send_mail;
                                  question_id = question_array[0].id;
                                  setAllInputs(question_array);
                                  assignAllQuestionTypes(current_question_type);
                                }, 100);
                              }
                            }
                          }, 100);
                        } else if (this.readyState == 4 && this.status == 400) {
                          try {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                          } catch (error) {
                          }
                          let resp_json = JSON.parse(this.responseText);
                          var errorDiv = document.createElement("DIV");
                          errorDiv.classList.add("question-div-smatest");
                          setTimeout(function () {
                            errorDiv.classList.add("top-0");
                          }, transition_time);
                          if (font && font.length > 0) {
                            errorDiv.classList.add(font);
                          }
                          var error_icon = document.createElement("IMG"); error_icon.alt = "Logo of " + totalData[0].name;
                          error_icon.src = avatar_icon;
                          var iconDiv = document.createElement("DIV");
                          iconDiv.appendChild(error_icon);
                          iconDiv.classList.add("question-icon-div");
                          error_icon.classList.add("question-icon-smatest");
                          var error_text = document.createElement("LABEL");
                          if (
                            resp_json.message &&
                            resp_json.message.length > 0
                          ) {
                            error_text.innerHTML = resp_json.message;
                            say(resp_json.message);
                          } else {
                            error_text.innerHTML =
                              "This feature works only in the Pro plan along with the ChatGPT Addon";
                            say(error_text.innerText);
                          }
                          error_text.classList.add("question-text-error");
                          error_text.classList.add("options-div-smatest");
                          if (font && font.length > 0) {
                            error_text.classList.add(font);
                          }
                          errorDiv.appendChild(iconDiv);
                          errorDiv.appendChild(error_text);
                          body.appendChild(errorDiv);
                          playBotUserSound(1);
                        }
                      };
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0
                        // main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      xhttpOther.open(
                        "GET",
                        main_url +
                        "/kya_backend/pagehub/getChatBotAnswerv2?answer_text=" +
                        encodeURIComponent(input_value) +
                        "&question_id=" +
                        question_array[0].ai_question_id +
                        "&chatbot_id=" +
                        chatbot_id +
                        "&cb_session=" +
                        cb_session +
                        "&language_code=" +
                        main_lang_code,
                        !0
                      );
                      xhttpOther.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      xhttpOther.send();
                    } else {
                      var answerDiv = document.createElement("DIV");
                      answerDiv.classList.add("answer-div");
                      setTimeout(function () {
                        answerDiv.classList.add("top-0");
                      }, transition_time);
                      var answer = document.createElement("LABEL");
                      if (current_question_type == "form") {
                        try {
                          var json = JSON.parse(input_value);
                          var keys = Object.keys(json);
                          var loc_div = document.createElement("DIV");
                          var label = document.createElement("LABEL");
                          label.innerHTML = generateTranslatedContent(translations, "Form Submitted Successfully.", main_lang_code, language_code, input);
                          label.style.marginBottom = "10px";
                          label.style.fontWeight = "bold";
                          label.style.borderBottom = "1px dotted white";
                          label.style.paddingBottom = "10px";
                          label.style.float = "left";
                          label.style.width = "100%";
                          label.classList.add("answer-opp-color-text");
                          if (font && font.length > 0) {
                            label.classList.add(font);
                          }
                          loc_div.appendChild(label);
                          for (var i = 0; i < keys.length; i++) {
                            var label = document.createElement("LABEL");
                            label.style.float = "left";
                            label.style.width = "100%";
                            label.style.marginTop = "3px";
                            label.style.marginBottom = "3px";
                            label.classList.add("answer-opp-color-text");
                            if (font && font.length > 0) {
                              label.classList.add(font);
                            }
                            label.innerHTML = keys[i] + " : " + json[keys[i]];
                            loc_div.appendChild(label);
                          }
                          if (answer) {
                            answer.innerHTML = loc_div.innerHTML;
                          }
                        } catch (e) {
                          answer.innerHTML = input_value;
                        } finally {
                        }
                      } else {
                        answer.innerHTML = input_value;
                      }
                      answer.classList.add("answer-label");
                      if (font && font.length > 0) {
                        answer.classList.add(font);
                      }
                      answerDiv.appendChild(answer);
                      if (
                        current_question_type != "statement" &&
                        current_question_type != "url_auto_redirect" &&
                        current_question_type != "contact" &&
                        current_question_type != "slides" &&
                        current_question_type != "custom_answer" &&
                        current_question_type != "show_file" &&
                        current_question_type != "show_location" &&
                        current_question_type != "show_contacts"
                      ) {
                        body.appendChild(answerDiv);
                        body.scrollTop = body.scrollHeight;
                      }
                      var spinningDiv = document.createElement("DIV");
                      spinningDiv.classList.add("question-div-smatest");
                      spinningDiv.classList.add("top-0");
                      if (font && font.length > 0) {
                        spinningDiv.classList.add(font);
                      }
                      var spinnerDiv = document.createElement("DIV");
                      spinnerDiv.classList.add("spinner1-smatest");
                      var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
                      ques_icon.src = avatar_icon;
                      var iconDiv = document.createElement("DIV");
                      iconDiv.appendChild(ques_icon);
                      iconDiv.classList.add("question-icon-div");
                      ques_icon.classList.add("question-icon-smatest");
                      var inner1 = document.createElement("DIV");
                      inner1.classList.add("bounce1");
                      var inner2 = document.createElement("DIV");
                      inner2.classList.add("bounce2");
                      var inner3 = document.createElement("DIV");
                      inner3.classList.add("bounce3");
                      spinnerDiv.appendChild(inner1);
                      spinnerDiv.appendChild(inner2);
                      spinnerDiv.appendChild(inner3);
                      spinningDiv.appendChild(iconDiv);
                      spinningDiv.appendChild(spinnerDiv);
                      body.appendChild(spinningDiv);
                      body.scrollTop = body.scrollHeight;
                      inTheMiddle = !0;
                      var xhttp = new XMLHttpRequest();
                      xhttp.onreadystatechange = function () {
                        entered = !1;
                        if (this.readyState == 4 && this.status == 200) {
                          shouldDisableTakeAction = !1;
                          question_and_answers.push({
                            id: question_id,
                            answer: input_value,
                          });
                          if (currentQuestionIsLead == "1" && !mailSent) {
                            sendAlertCall();
                          } else {
                            if (mailSequence < currentMailSequence) {
                              random_key = !0;
                            } else {
                              random_key = !1;
                            }
                          }
                          cb_session = JSON.parse(this.response).cb_session;
                          live_chat_cb_session = JSON.parse(
                            this.response
                          ).livechat_session;
                          if (
                            JSON.parse(this.response).language_code &&
                            JSON.parse(this.response).language_code.length > 0 &&
                            JSON.parse(this.response).language_code != "default"
                          ) {
                            main_lang_code = JSON.parse(
                              this.response
                            ).language_code;
                          }
                          session_feedback = JSON.parse(this.response).feedback;
                          question_array = JSON.parse(this.response).next_question;
                          if (question_array && question_array.length > 0) {
                            question_completed = !1;
                            input_value = "";
                            setTimeout(function () {
                              enter.style.pointerEvents = "auto";
                              if (spinningDiv && spinningDiv.parentNode == body) {
                                body.removeChild(spinningDiv);
                              }
                              current_question_type = question_array[0].type;
                              current_logical_jump = question_array[0].logical_jump;
                              currentMailSequence = question_array[0].sequence;
                              currentQuestionIsLead = question_array[0].send_mail;
                              question_id = question_array[0].id;
                              setAllInputs(question_array);
                              assignAllQuestionTypes(current_question_type);
                            }, delay_time);
                          } else {
                            if (spinningDiv && spinningDiv.parentNode == body) {
                              body.removeChild(spinningDiv);
                            }
                            showInput = !0;
                            enter.style.pointerEvents = "auto";
                            question_completed = !0;
                            if (!mailSent || mailSent) {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    if (
                                      zapier_webhook &&
                                      zapier_webhook.length > 0
                                    ) {
                                      var output = {};
                                      output.timestamp = new Date();
                                      for (
                                        var i = 0;
                                        i < prev_questions_array.length;
                                        i++
                                      ) {
                                        var str =
                                          prev_questions_array[i].question_text;
                                        output[str] =
                                          prev_questions_array[i].answer_text;
                                      }
                                      var xhttp = new XMLHttpRequest();
                                      xhttp.onreadystatechange = function () {
                                        if (
                                          this.readyState == 4 &&
                                          this.status == 200
                                        ) {
                                        }
                                      };
                                      xhttp.open("POST", zapier_webhook, !0);
                                      xhttp.setRequestHeader(
                                        "Content-type",
                                        "application/x-www-form-urlencoded"
                                      );
                                      xhttp.send(
                                        "output=" + JSON.stringify(output)
                                      );
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            } else {
                              var xhttp = new XMLHttpRequest();
                              xhttp.onreadystatechange = function () {
                                if (this.readyState == 4 && this.status == 200) {
                                  var questionArray = [];
                                  prev_questions_array = JSON.parse(
                                    this.response
                                  ).qna_prev;
                                  if (
                                    prev_questions_array &&
                                    prev_questions_array.length > 0
                                  ) {
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      if (
                                        prev_questions_array[i].type == "contact" ||
                                        prev_questions_array[i].type == "slides" ||
                                        prev_questions_array[i].type ==
                                        "statement" ||
                                        prev_questions_array[i].type ==
                                        "url_auto_redirect" ||
                                        prev_questions_array[i].type ==
                                        "custom_answer" ||
                                        prev_questions_array[i].type ==
                                        "show_file" ||
                                        prev_questions_array[i].type ==
                                        "show_contacts" ||
                                        prev_questions_array[i].type ==
                                        "show_location"
                                      ) {
                                        prev_questions_array.splice(i, 1);
                                        i--;
                                      }
                                    }
                                    for (
                                      var i = 0;
                                      i < prev_questions_array.length;
                                      i++
                                    ) {
                                      questionArray.push({
                                        question:
                                          prev_questions_array[i].question_text,
                                        answer: prev_questions_array[i].answer_text,
                                      });
                                    }
                                  }
                                }
                              };
                              xhttp.open(
                                "POST",
                                main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                                !0
                              );
                              xhttp.setRequestHeader(
                                "Content-type",
                                "application/x-www-form-urlencoded"
                              );
                              if (
                                main_lang_code &&
                                main_lang_code.length > 0 &&
                                main_lang_code != language_code
                              ) {
                              } else {
                                main_lang_code = "default";
                              }
                              var bot_widget_obj;
                              var is_sendable;
                              try {
                                checkSaveMAxUserLogin();
                                checkRateGainDetails();
                              } catch (error) { }
                              if (window.botWidget && window.botWidget.user) {
                                var keys = Object.keys(window.botWidget.user);
                                for (var t = 0; t < keys.length; t++) {
                                  if (
                                    window.botWidget.user[keys[t]] &&
                                    window.botWidget.user[keys[t]].length > 0
                                  ) {
                                    is_sendable = true;
                                  }
                                }
                                if (is_sendable) {
                                  bot_widget_obj = window.botWidget.user;
                                } else {
                                  bot_widget_obj = "";
                                }
                                if (window.botWidget.user.bot_id) {
                                  delete window.botWidget.user.bot_id;
                                }
                                if (window.botWidget.user.url) {
                                  delete window.botWidget.user.url;
                                }
                              }
                              xhttp.send(
                                "action=init_chat&device_print=" +
                                device_print +
                                "&chatbot_id=" +
                                chatbot_id +
                                "&language_code=" +
                                main_lang_code +
                                "&bot_widget_obj=" +
                                JSON.stringify(bot_widget_obj)
                              );
                            }
                            if (!entry_id) {
                              showInput = !0;
                              if (!shouldShowMenu) {
                                footer.style.display = "none";
                                footer.classList.add("close");
                              } else {
                                if (entry_id) {
                                  input.style.pointerEvents = "auto";
                                  microphone.style.pointerEvents = "auto";
                                  microphone.style.opacity = 1;
                                  enter.style.pointerEvents = "auto";
                                  setPlaceHolders();
                                  if (header.contains(company_title_description)) {
                                    body.style.height = "calc(100% - 226px)";
                                  } else {
                                    body.style.height = "calc(100% - 150px)";
                                  }
                                } else {
                                  input.style.pointerEvents = "none";
                                  microphone.style.pointerEvents = "none";
                                  microphone.style.opacity = 0;
                                  input.blur();
                                  enter.style.pointerEvents = "none";
                                  input.placeholder = "Choose from Menu";
                                }
                              }
                            }
                            if (!shouldShowMenu) {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 168px)";
                              } else {
                                body.style.height = "calc(100% - 93px)";
                              }
                            } else {
                              if (header.contains(company_title_description)) {
                                body.style.height = "calc(100% - 226px)";
                              } else {
                                body.style.height = "calc(100% - 150px)";
                              }
                            }
                          }
                        }
                      };
                      xhttp.open(
                        "POST",
                        main_url + "/kya_backend/pagehub/chatbot_utils?action=answer",
                        !0
                      );
                      xhttp.setRequestHeader(
                        "Content-type",
                        "application/x-www-form-urlencoded"
                      );
                      if (
                        main_lang_code &&
                        main_lang_code.length > 0 &&
                        main_lang_code != language_code
                      ) {
                      } else {
                        main_lang_code = "default";
                      }
                      if (
                        current_logical_jump == "1" &&
                        current_question_type != "radio" &&
                        current_question_type != "rating"
                      ) {
                        xhttp.send(
                          "action=answer&answer_text=" +
                          encodeURIComponent(input_value) +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          question_id +
                          "&is_logical=" +
                          current_logical_jump +
                          "&sequence=" +
                          currentMailSequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&option=" +
                          "sometext&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                      } else {
                        xhttp.send(
                          "action=answer&answer_text=" +
                          encodeURIComponent(input_value) +
                          "&cb_session=" +
                          cb_session +
                          "&question_id=" +
                          question_id +
                          "&is_logical=" +
                          current_logical_jump +
                          "&sequence=" +
                          currentMailSequence +
                          "&chatbot_id=" +
                          chatbot_id +
                          "&option=" +
                          encodeURIComponent(input_value) +
                          "&visitor_link_traversal=" +
                          visitedUrls +
                          "&language_code=" +
                          main_lang_code
                        );
                      }
                    }
                  }
                }
              }
            }
          }
        }

        function takingRadioValue(val, div, id, ques_id, seq, string) {
          isSomethingGoingOn = !0;
          nothingWentOnFor = 0;
          encourageMessageIteration = 0;
          if (val != "something") {
            try {
              window.speechSynthesis.cancel();
            } catch (error) { }
          } else {
            atleastOneAnswered = !0;
          }
          if (
            agreed ||
            val == "something" ||
            current_question_type == "url_flow" ||
            current_question_type == "country_based_flow"
          ) {
            if (id && (id == 1 || id == 2 || id == 3 || id == 4)) {
            } else if (id == 6) {
              div.parentElement.removeChild(div);
            }
            var answerDiv = document.createElement("DIV");
            var answerDivOther = document.createElement("DIV");
            if (id && id == 3 && current_question_type == "file_upload") {
              div.parentElement.removeChild(div);
            } else if (
              current_question_type == "radio" ||
              current_question_type == "whatsapp_buttons" ||
              current_question_type == "whatsapp_list" ||
              current_question_type == "checkbox" ||
              current_question_type == "rating"
            ) {
              if (string != 'c_s_c') {
                div.parentElement.removeChild(div);
              }
            } else if (current_question_type == "radio_slides") {
              if (string != 'r_s_c') {
                div.parentElement.removeChild(div);
              }
            } else {
              if (id && (id == 1 || id == 2 || id == 3 || id == 4 || id == 6)) {
              } else {
                var firstChild = div.firstChild;
                if (
                  div &&
                  div.childNodes[1] &&
                  div.childNodes[1].className == "image-div-smatest"
                ) {
                  var anotherDiv = div.childNodes[1];
                }
                while (div.firstChild) {
                  div.removeChild(div.firstChild);
                }
                div.appendChild(firstChild);
                if (anotherDiv) {
                  div.appendChild(anotherDiv);
                }
              }
            }
            if (id && id == 3) {
              var skip_dv = document.getElementById("skip-question-div");
              if (skip_dv) {
                skip_dv.parentElement.style.marginBottom = "0";
                skip_dv.parentElement.removeChild(skip_dv);
              }
              answerDiv.classList.add("answer-div");
              setTimeout(function () {
                answerDiv.classList.add("top-0");
              }, transition_time);
              answerDiv.classList.add("m-t-0");
              var answer = document.createElement("LABEL");
    
              var valArray = val.split(',');
    
              function isURL(str) {
                const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
                return urlPattern.test(str);
              }
              
              const getFileExtension = (filename) => {
                const dotIndex = filename.lastIndexOf('.');
                return dotIndex !== -1 ? filename.slice(dotIndex + 1) : '';
              };
              
              function insertLinkTags(text) {
                // Define a regular expression pattern to match URLs
                const urlPattern = /(https?:\/\/\S+)/g;
              
                // Replace each URL with a formatted link
                const result = text.replace(urlPattern, '<div><a href="$1" target="_blank">$1</a></div>');
              
                return result;
              }
              
              const fileTypeConvert = (fileData) => {
                const filename = fileData?.split(/\#|\?/)[0].split('/').pop().trim();
                const extension = getFileExtension(filename).toLowerCase();
                let FileContainer;
              
                if (['png', 'jpg', 'jpeg', 'svg', 'tif', 'gif','ico','webp'].includes(extension)) {
                  let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                  FileContainer = `
                    <a href="${fileData}" target="_blank" width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:flex-end;" >
                      <img src="${fileData}" alt='${link}' class='file-upload_image_style_sb'/>
                    </a>
                  `;
                } else if (['mp3', 'wav'].includes(extension)) {
                  FileContainer = `<audio style="width: 285px;" controls src="${fileData}"></audio>`;
                } else if (['mp4', 'webm', 'flv','mov'].includes(extension)) {
                  let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                  FileContainer = `<video controls type='video/mp4' src="${fileData}" style="border-radius:10px;"  width='100%' height='150px'></video>`;
                } else if (['pdf', 'doc', 'txt', 'docx', 'zip', 'csv', 'xlsx', 'xls'].includes(extension)) {
                  let link = fileData.substring(fileData.lastIndexOf('/') + 1);
                  // FileContainer = `<a href="${fileData}" target="_blank">${link}</a>`;
                  FileContainer = `
                      <div width='100%' height='100%'  style="display: flex; align-items:center; gap:12px;justify-content:start;background: #F0F4F9;border: 1px solid #E0E6F0;border-radius: 8px;padding: 12px; " >
                        <img src="https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/folder-upload.svg" alt='' width='25px' height='25px'/>
                        <label style='word-break:break-all;cursor: pointer;color: black;white-space: nowrap;width: 65%;overflow: hidden;text-overflow: ellipsis;'>${link}</label>
                        <a href="${fileData}" target="_blank" rel="noopener noreferrer" style='width: 25px;height: 25px;border-radius:50%;display:flex;align-items:center;justify-content:center;margin-left: auto;' >
                          <img src='https://custpostimages.s3.ap-south-1.amazonaws.com/sb_images/download-icon.svg'   width='15px' height='15px' />
                        </a>
                      </div>`
                
                } else if (fileData.includes('https://') || fileData.includes('http://')) {
                  FileContainer = insertLinkTags(fileData);
                } else {
                  FileContainer = fileData;
                }
              
                return FileContainer;
              };
    
              valArray.forEach(function(item) {
                
                const linkElement = document.createElement('div');
                linkElement.style.margin ='12px auto'
                // linkElement.style.float ='right'
                linkElement.innerHTML = fileTypeConvert(item.trim());
                answer.appendChild(linkElement);
    
              });
    
              answer.classList.add("answer-label");
              answer.style.background = 'transparent'
              if (font && font.length > 0) {
                answer.classList.add(font);
              }
              answerDiv.appendChild(answer);
              answerDivOther.classList.add("answer-div");
              setTimeout(function () {
                answerDivOther.classList.add("top-0");
              }, transition_time);
              var answerOther = document.createElement("LABEL");
              answerOther.innerHTML = generateTranslatedContent(translations, "Uploaded Here", main_lang_code, language_code, input);
              answerOther.classList.add("answer-label");
              if (font && font.length > 0) {
                answerOther.classList.add(font);
              }
              answerDivOther.appendChild(answerOther);
            } else {
              answerDiv.classList.add("answer-div");
              setTimeout(function () {
                answerDiv.classList.add("top-0");
              }, transition_time);
              var answer = document.createElement("LABEL");

              if (current_question_type == "radio") {
                var answer_text = document.createElement("DIV")
                answer_text.innerHTML = val
              }else{
                var answer_text = document.createTextNode(val);
              }

              answer.appendChild(answer_text);
              answer.classList.add("answer-label");
              if (font && font.length > 0) {
                answer.classList.add(font);
              }
              answerDiv.appendChild(answer);
            }
            if (id && (id == 1 || id == 4)) {
            } else {
              if (string == "take_action_flow") {
              } else {
                if (id && id == 3) {
                  body.appendChild(answerDivOther);
                }
                if (id && id == 5) {
                  div.parentElement.removeChild(div);
                } else {
                  body.appendChild(answerDiv);
                }
                if (val == "something") {
                } else {
                  body.scrollTop = body.scrollHeight;
                }
              }
            }
            var spinningDiv = document.createElement("DIV");
            spinningDiv.classList.add("question-div-smatest");
            spinningDiv.classList.add("top-0");
            if (font && font.length > 0) {
              spinningDiv.classList.add(font);
            }
            var spinnerDiv = document.createElement("DIV");
            spinnerDiv.classList.add("spinner1-smatest");
            var ques_icon = document.createElement("IMG"); ques_icon.alt = "Logo of " + totalData[0].name;
            ques_icon.src = avatar_icon;
            var iconDiv = document.createElement("DIV");
            iconDiv.appendChild(ques_icon);
            iconDiv.classList.add("question-icon-div");
            ques_icon.classList.add("question-icon-smatest");
            var inner1 = document.createElement("DIV");
            inner1.classList.add("bounce1");
            var inner2 = document.createElement("DIV");
            inner2.classList.add("bounce2");
            var inner3 = document.createElement("DIV");
            inner3.classList.add("bounce3");
            spinnerDiv.appendChild(inner1);
            spinnerDiv.appendChild(inner2);
            spinnerDiv.appendChild(inner3);
            spinningDiv.appendChild(iconDiv);
            spinningDiv.appendChild(spinnerDiv);
            body.appendChild(spinningDiv);
            if (val == "something") {
              body.scrollTop = body.scrollHeight;
            } else {
              body.scrollTop = body.scrollHeight;
            }
            inTheMiddle = !0;
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                if (string && string == "take_action_flow") {
                  doneThatTAF = !0;
                }
                if (ques_id && seq) {
                  if (
                    question_array[0] &&
                    question_array[0].question_text.length > 0
                  ) {
                    question_and_answers.push({
                      id: ques_id,
                      answer: val,
                      question_text: question_array[0].question_text,
                    });
                  } else {
                    question_and_answers.push({
                      id: ques_id,
                      answer: val,
                    });
                  }
                } else {
                  if (
                    question_array[0] &&
                    question_array[0].question_text.length > 0
                  ) {
                    question_and_answers.push({
                      id: question_id,
                      answer: val,
                      question_text: question_array[0].question_text,
                    });
                  } else {
                    question_and_answers.push({
                      id: question_id,
                      answer: val,
                    });
                  }
                }
                if (currentQuestionIsLead == "1" && !mailSent) {
                  sendAlertCall();
                } else {
                  if (mailSequence < currentMailSequence) {
                    random_key = !0;
                  } else {
                    random_key = !1;
                  }
                }
                cb_session = JSON.parse(this.response).cb_session;
                live_chat_cb_session = JSON.parse(this.response).livechat_session;
                if (
                  JSON.parse(this.response).language_code &&
                  JSON.parse(this.response).language_code.length > 0 &&
                  JSON.parse(this.response).language_code != "default"
                ) {
                  main_lang_code = JSON.parse(this.response).language_code;
                }
                session_feedback = JSON.parse(this.response).feedback;
                question_array = JSON.parse(this.response).next_question;
                if (question_array && question_array.length > 0) {
                  if (current_question_type == "custom_entry") {
                    entry_question = question_array[0];
                  }
                  question_completed = !1;
                  input.value = "";
                  setTimeout(function () {
                    if (spinningDiv && spinningDiv.parentNode == body) {
                      body.removeChild(spinningDiv);
                    }
                    current_question_type = question_array[0].type;
                    current_logical_jump = question_array[0].logical_jump;
                    currentMailSequence = question_array[0].sequence;
                    currentQuestionIsLead = question_array[0].send_mail;
                    question_id = question_array[0].id;
                    setAllInputs(question_array);
                    assignAllQuestionTypes(current_question_type);
                  }, delay_time);
                } else {
                  if (spinningDiv && spinningDiv.parentNode == body) {
                    body.removeChild(spinningDiv);
                  }
                  question_completed = !0;
                  if (!mailSent || mailSent) {
                    var xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                      if (this.readyState == 4 && this.status == 200) {
                        var questionArray = [];
                        prev_questions_array = JSON.parse(this.response).qna_prev;
                        if (
                          prev_questions_array &&
                          prev_questions_array.length > 0
                        ) {
                          for (var i = 0; i < prev_questions_array.length; i++) {
                            if (
                              prev_questions_array[i].type == "contact" ||
                              prev_questions_array[i].type == "slides" ||
                              prev_questions_array[i].type == "statement" ||
                              prev_questions_array[i].type == "url_auto_redirect" ||
                              prev_questions_array[i].type == "custom_answer" ||
                              prev_questions_array[i].type == "show_file" ||
                              prev_questions_array[i].type == "show_contacts" ||
                              prev_questions_array[i].type == "show_location"
                            ) {
                              prev_questions_array.splice(i, 1);
                              i--;
                            }
                          }
                          if (zapier_webhook && zapier_webhook.length > 0) {
                            var output = {};
                            output.timestamp = new Date();
                            for (var i = 0; i < prev_questions_array.length; i++) {
                              var str = prev_questions_array[i].question_text;
                              output[str] = prev_questions_array[i].answer_text;
                            }
                            var xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function () {
                              if (this.readyState == 4 && this.status == 200) {
                              }
                            };
                            xhttp.open("POST", zapier_webhook, !0);
                            xhttp.setRequestHeader(
                              "Content-type",
                              "application/x-www-form-urlencoded"
                            );
                            xhttp.send("output=" + JSON.stringify(output));
                          }
                          for (var i = 0; i < prev_questions_array.length; i++) {
                            questionArray.push({
                              question: prev_questions_array[i].question_text,
                              answer: prev_questions_array[i].answer_text,
                            });
                          }
                        }
                      }
                    };
                    xhttp.open(
                      "POST",
                      main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                      !0
                    );
                    xhttp.setRequestHeader(
                      "Content-type",
                      "application/x-www-form-urlencoded"
                    );
                    if (
                      main_lang_code &&
                      main_lang_code.length > 0 &&
                      main_lang_code != language_code
                    ) {
                    } else {
                      main_lang_code = "default";
                    }
                    var bot_widget_obj;
                    var is_sendable;
                    try {
                      checkSaveMAxUserLogin();
                      checkRateGainDetails();
                    } catch (error) { }
                    if (window.botWidget && window.botWidget.user) {
                      var keys = Object.keys(window.botWidget.user);
                      for (var t = 0; t < keys.length; t++) {
                        if (
                          window.botWidget.user[keys[t]] &&
                          window.botWidget.user[keys[t]].length > 0
                        ) {
                          is_sendable = true;
                        }
                      }
                      if (is_sendable) {
                        bot_widget_obj = window.botWidget.user;
                      } else {
                        bot_widget_obj = "";
                      }
                      if (window.botWidget.user.bot_id) {
                        delete window.botWidget.user.bot_id;
                      }
                      if (window.botWidget.user.url) {
                        delete window.botWidget.user.url;
                      }
                    }
                    xhttp.send(
                      "action=init_chat&device_print=" +
                      device_print +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&language_code=" +
                      main_lang_code +
                      "&bot_widget_obj=" +
                      JSON.stringify(bot_widget_obj)
                    );
                  } else {
                    var xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                      if (this.readyState == 4 && this.status == 200) {
                        var questionArray = [];
                        prev_questions_array = JSON.parse(this.response).qna_prev;
                        if (
                          prev_questions_array &&
                          prev_questions_array.length > 0
                        ) {
                          for (var i = 0; i < prev_questions_array.length; i++) {
                            if (
                              prev_questions_array[i].type == "contact" ||
                              prev_questions_array[i].type == "slides" ||
                              prev_questions_array[i].type == "statement" ||
                              prev_questions_array[i].type == "url_auto_redirect" ||
                              prev_questions_array[i].type == "custom_answer" ||
                              prev_questions_array[i].type == "show_file" ||
                              prev_questions_array[i].type == "show_contacts" ||
                              prev_questions_array[i].type == "show_location"
                            ) {
                              prev_questions_array.splice(i, 1);
                              i--;
                            }
                          }
                          for (var i = 0; i < prev_questions_array.length; i++) {
                            questionArray.push({
                              question: prev_questions_array[i].question_text,
                              answer: prev_questions_array[i].answer_text,
                            });
                          }
                        }
                      }
                    };
                    xhttp.open(
                      "POST",
                      main_url + "/kya_backend/pagehub/chatbot_utils?action=init_chat",
                      !0
                    );
                    xhttp.setRequestHeader(
                      "Content-type",
                      "application/x-www-form-urlencoded"
                    );
                    if (
                      main_lang_code &&
                      main_lang_code.length > 0 &&
                      main_lang_code != language_code
                    ) {
                    } else {
                      main_lang_code = "default";
                    }
                    var bot_widget_obj;
                    var is_sendable;
                    try {
                      checkSaveMAxUserLogin();
                      checkRateGainDetails();
                    } catch (error) { }
                    if (window.botWidget && window.botWidget.user) {
                      var keys = Object.keys(window.botWidget.user);
                      for (var t = 0; t < keys.length; t++) {
                        if (
                          window.botWidget.user[keys[t]] &&
                          window.botWidget.user[keys[t]].length > 0
                        ) {
                          is_sendable = true;
                        }
                      }
                      if (is_sendable) {
                        bot_widget_obj = window.botWidget.user;
                      } else {
                        bot_widget_obj = "";
                      }
                      if (window.botWidget.user.bot_id) {
                        delete window.botWidget.user.bot_id;
                      }
                      if (window.botWidget.user.url) {
                        delete window.botWidget.user.url;
                      }
                    }
                    xhttp.send(
                      "action=init_chat&device_print=" +
                      device_print +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&language_code=" +
                      main_lang_code +
                      "&bot_widget_obj=" +
                      JSON.stringify(bot_widget_obj)
                    );
                  }
                  if (!entry_id) {
                    showInput = !0;
                    if (!shouldShowMenu) {
                      footer.style.display = "none";
                      footer.classList.add("close");
                    } else {
                      if (entry_id) {
                        input.style.pointerEvents = "auto";
                        microphone.style.pointerEvents = "auto";
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = "auto";
                        setPlaceHolders();
                        if (header.contains(company_title_description)) {
                          body.style.height = "calc(100% - 226px)";
                        } else {
                          body.style.height = "calc(100% - 150px)";
                        }
                      } else {
                        input.style.pointerEvents = "none";
                        microphone.style.pointerEvents = "none";
                        microphone.style.opacity = 0;
                        input.blur();
                        enter.style.pointerEvents = "none";
                        input.placeholder = "Choose from Menu";
                      }
                    }
                  }
                  if (!shouldShowMenu) {
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 168px)";
                    } else {
                      body.style.height = "calc(100% - 93px)";
                    }
                  } else {
                    if (header.contains(company_title_description)) {
                      body.style.height = "calc(100% - 226px)";
                    } else {
                      body.style.height = "calc(100% - 150px)";
                    }
                  }
                }
              }
            };
            xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=answer", !0);
            xhttp.setRequestHeader(
              "Content-type",
              "application/x-www-form-urlencoded"
            );
            if (
              main_lang_code &&
              main_lang_code.length > 0 &&
              main_lang_code != language_code
            ) {
            } else {
              main_lang_code = "default";
            }
            if (ques_id && seq) {
              if (
                current_logical_jump == "1" &&
                current_question_type != "radio" &&
                current_question_type != "whatsapp_list" &&
                current_question_type != "whatsapp_buttons" &&
                current_question_type != "rating" &&
                current_question_type != "radio_slides" &&
                current_question_type != "custom_single_choice" &&
                current_question_type != "url_flow" &&
                current_question_type != "country_based_flow"
              ) {
                if (current_question_type == "checkbox") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    ques_id +
                    "&is_logical=1" +
                    "&sequence=" +
                    seq +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=sometext&is_help=1&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "c_s_c") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    ques_id +
                    "&is_logical=1" +
                    "&sequence=" +
                    seq +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_help=1&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "take_action_flow") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    ques_id +
                    "&is_logical=1" +
                    "&sequence=" +
                    seq +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_help=1&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&custom_entry_qid=" +
                    entry_id +
                    "&language_code=" +
                    main_lang_code
                  );
                } else {
                  if (id && id == 4) {
                    xhttp.send(
                      "action=dynamic_response&cookies=" +
                      val +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      ques_id +
                      "&is_logical=1" +
                      "&sequence=" +
                      seq +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      encodeURIComponent(val) +
                      "&is_help=1&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  } else {
                    xhttp.send(
                      "action=answer&answer_text=" +
                      encodeURIComponent(val) +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      ques_id +
                      "&is_logical=1" +
                      "&sequence=" +
                      seq +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      encodeURIComponent(val) +
                      "&is_help=1&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  }
                }
              } else {
                if (string && string == "c_s_c") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    ques_id +
                    "&is_logical=1" +
                    "&sequence=" +
                    seq +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_help=1&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "take_action_flow") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    ques_id +
                    "&is_logical=1" +
                    "&sequence=" +
                    seq +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_help=1&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&custom_entry_qid=" +
                    entry_id +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "r_s_c") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    ques_id +
                    "&is_logical=1" +
                    "&sequence=" +
                    seq +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=sometext&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else {
                  if (id && id == 4) {
                    xhttp.send(
                      "action=dynamic_response&cookies=" +
                      val +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      ques_id +
                      "&is_logical=1" +
                      "&sequence=" +
                      seq +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      encodeURIComponent(val) +
                      "&is_help=1&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  } else {
                    xhttp.send(
                      "action=answer&answer_text=" +
                      encodeURIComponent(val) +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      ques_id +
                      "&is_logical=1" +
                      "&sequence=" +
                      seq +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      encodeURIComponent(val) +
                      "&is_help=1&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  }
                }
              }
            } else {
              if (
                current_logical_jump == "1" &&
                current_question_type != "radio" &&
                current_question_type != "whatsapp_list" &&
                current_question_type != "whatsapp_buttons" &&
                current_question_type != "rating" &&
                current_question_type != "radio_slides" &&
                current_question_type != "custom_single_choice" &&
                current_question_type != "url_flow" &&
                current_question_type != "country_based_flow"
              ) {
                if (current_question_type == "checkbox") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id +
                    "&is_logical=" +
                    current_logical_jump +
                    "&sequence=" +
                    currentMailSequence +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=sometext&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "c_s_c") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id +
                    "&is_logical=" +
                    current_logical_jump +
                    "&sequence=" +
                    currentMailSequence +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "take_action_flow") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id +
                    "&is_logical=" +
                    current_logical_jump +
                    "&sequence=" +
                    currentMailSequence +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&custom_entry_qid=" +
                    entry_id +
                    "&language_code=" +
                    main_lang_code
                  );
                } else {
                  if (id && id == 4) {
                    xhttp.send(
                      "action=dynamic_response&cookies=" +
                      val +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      question_id +
                      "&is_logical=" +
                      current_logical_jump +
                      "&sequence=" +
                      currentMailSequence +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      "sometext&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  } else {
                    xhttp.send(
                      "action=answer&answer_text=" +
                      val +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      question_id +
                      "&is_logical=" +
                      current_logical_jump +
                      "&sequence=" +
                      currentMailSequence +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      "sometext&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  }
                }
              } else {
                if (string && string == "c_s_c") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id +
                    "&is_logical=" +
                    current_logical_jump +
                    "&sequence=" +
                    currentMailSequence +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "take_action_flow") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id +
                    "&is_logical=" +
                    current_logical_jump +
                    "&sequence=" +
                    currentMailSequence +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=" +
                    encodeURIComponent(val) +
                    "&is_statement=1&visitor_link_traversal=" +
                    visitedUrls +
                    "&custom_entry_qid=" +
                    entry_id +
                    "&language_code=" +
                    main_lang_code
                  );
                } else if (string && string == "r_s_c") {
                  xhttp.send(
                    "action=answer&answer_text=" +
                    encodeURIComponent(val) +
                    "&cb_session=" +
                    cb_session +
                    "&question_id=" +
                    question_id +
                    "&is_logical=" +
                    current_logical_jump +
                    "&sequence=" +
                    currentMailSequence +
                    "&chatbot_id=" +
                    chatbot_id +
                    "&option=sometext&visitor_link_traversal=" +
                    visitedUrls +
                    "&language_code=" +
                    main_lang_code
                  );
                } else {
                  if (id && id == 4) {
                    xhttp.send(
                      "action=dynamic_response&cookies=" +
                      val +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      question_id +
                      "&is_logical=" +
                      current_logical_jump +
                      "&sequence=" +
                      currentMailSequence +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      encodeURIComponent(val) +
                      "&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  } else {
                    xhttp.send(
                      "action=answer&answer_text=" +
                      encodeURIComponent(val) +
                      "&cb_session=" +
                      cb_session +
                      "&question_id=" +
                      question_id +
                      "&is_logical=" +
                      current_logical_jump +
                      "&sequence=" +
                      currentMailSequence +
                      "&chatbot_id=" +
                      chatbot_id +
                      "&option=" +
                      encodeURIComponent(val) +
                      "&visitor_link_traversal=" +
                      visitedUrls +
                      "&language_code=" +
                      main_lang_code
                    );
                  }
                }
              }
            }
          }
        }
        function handleSubmitEnteredValue() {
          if (current_question_type == 'order_items') {
            if (selected_orders && selected_orders.length > 0) {
              inputEntered();
            }
          } else {
            if (
              input &&
              input.value &&
              input.value.trim().length > 0 &&
              input.value.trim().length < 495
            ) {
              enter.style.pointerEvents = 'none';
              inputEntered();
              if (needPrivacy) {
              } else {
                if (current_question_type == 'email') {
                  if (
                    /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(input.value)
                  ) {
                    var arr = input.value.split('@');
                    var allNumber = /^\d+$/;
                    var atleastAlpha = /^.*[a-zA-Z]/;
                    var regexSpecial = /[ !@#%$^&*()+\-=\[\]{};':"\\|,<>\/?]/;
                    if (
                      arr[0].length > 1 &&
                      arr[0].length < 31 &&
                      !regexSpecial.test(arr[0]) &&
                      arr[0].substring(arr[0].length - 1, arr[0].length) != '.' &&
                      !allNumber.test(arr[0]) &&
                      atleastAlpha.test(arr[0])
                    ) {
                      if (!shouldShowMenu) {
                        footer.style.display = 'none';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 168px)';
                        } else {
                          body.style.height = 'calc(100% - 93px)';
                        }
                        footer.classList.add('close');
                      } else {
                        if (entry_id) {
                          input.style.pointerEvents = 'auto';
                          microphone.style.pointerEvents = 'auto';
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = 'auto';
                          setPlaceHolders();
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        } else {
                          input.style.pointerEvents = 'none';
                          microphone.style.pointerEvents = 'none';
                          microphone.style.opacity = 0;
                          input.blur();
                          enter.style.pointerEvents = 'none';
                          input.placeholder = 'Choose from Menu';
                          input.type = 'text';
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        }
                      }
                    }
                  }
                } else if (current_question_type == 'phone') {
                  if (selectedCode && selectedCode == '91') {
                    var regex = /^[0]?[6789]\d{9}$/;
                    if (
                      input.value &&
                      (input.value + '').length > 9 &&
                      (input.value + '').length < 15 &&
                      regex.test(input.value)
                    ) {
                      if (!shouldShowMenu) {
                        footer.style.display = 'none';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 168px)';
                        } else {
                          body.style.height = 'calc(100% - 93px)';
                        }
                        footer.classList.add('close');
                      } else {
                        if (entry_id) {
                          input.style.pointerEvents = 'auto';
                          microphone.style.pointerEvents = 'auto';
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = 'auto';
                          setPlaceHolders();
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        } else {
                          input.style.pointerEvents = 'none';
                          microphone.style.pointerEvents = 'none';
                          microphone.style.opacity = 0;
                          input.blur();
                          enter.style.pointerEvents = 'none';
                          input.placeholder = 'Choose from Menu';
                          input.type = 'text';
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        }
                      }
                    }
                  } else if (
                    selectedCode &&
                    (selectedCode == '973' ||
                      selectedCode == '965' ||
                      selectedCode == '968' ||
                      selectedCode == '974' ||
                      selectedCode == '966' ||
                      selectedCode == '971' ||
                      selectedCode == '44' ||
                      selectedCode == '86' ||
                      selectedCode == '852' ||
                      selectedCode == '27')
                  ) {
                    var prefix_regex = new RegExp(
                      phone_validation_regex[selectedCode].prefix
                    );
                    if (
                      prefix_regex.test(input.value) &&
                      phone_validation_regex[selectedCode].length[0] ==
                        input.value.length
                    ) {
                      if (!shouldShowMenu) {
                        footer.style.display = 'none';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 168px)';
                        } else {
                          body.style.height = 'calc(100% - 93px)';
                        }
                        footer.classList.add('close');
                      } else {
                        if (entry_id) {
                          input.style.pointerEvents = 'auto';
                          microphone.style.pointerEvents = 'auto';
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = 'auto';
                          setPlaceHolders();
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        } else {
                          input.style.pointerEvents = 'none';
                          microphone.style.pointerEvents = 'none';
                          microphone.style.opacity = 0;
                          input.blur();
                          enter.style.pointerEvents = 'none';
                          input.placeholder = 'Choose from Menu';
                          input.type = 'text';
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        }
                      }
                    }
                  } else {
                    if (input.value && (input.value + '').length > 5) {
                      if (!shouldShowMenu) {
                        footer.style.display = 'none';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 168px)';
                        } else {
                          body.style.height = 'calc(100% - 93px)';
                        }
                        footer.classList.add('close');
                      } else {
                        if (entry_id) {
                          input.style.pointerEvents = 'auto';
                          microphone.style.pointerEvents = 'auto';
                          microphone.style.opacity = 1;
                          enter.style.pointerEvents = 'auto';
                          setPlaceHolders();
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        } else {
                          input.style.pointerEvents = 'none';
                          microphone.style.pointerEvents = 'none';
                          microphone.style.opacity = 0;
                          input.blur();
                          enter.style.pointerEvents = 'none';
                          input.placeholder = 'Choose from Menu';
                          input.type = 'text';
                          if (header.contains(company_title_description)) {
                            body.style.height = 'calc(100% - 218px)';
                          } else {
                            body.style.height = 'calc(100% - 143px)';
                          }
                        }
                      }
                    }
                  }
                } else if (current_question_type == 'website') {
                  var regex =
                    /^((https?|ftp|smtp):\/\/)?(www.)?[a-z0-9]+(\.[a-z]{2,}){1,3}(#?\/?[a-zA-Z0-9#]+)*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/;
                  if (
                    (input.value &&
                      (input.value + '').length > 0 &&
                      regex.test(input.value.toLowerCase())) ||
                    websited_skipped
                  ) {
                    if (!shouldShowMenu) {
                      footer.style.display = 'none';
                      if (header.contains(company_title_description)) {
                        body.style.height = 'calc(100% - 168px)';
                      } else {
                        body.style.height = 'calc(100% - 93px)';
                      }
                      footer.classList.add('close');
                    } else {
                      if (entry_id) {
                        input.style.pointerEvents = 'auto';
                        microphone.style.pointerEvents = 'auto';
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = 'auto';
                        setPlaceHolders();
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 218px)';
                        } else {
                          body.style.height = 'calc(100% - 143px)';
                        }
                      } else {
                        input.style.pointerEvents = 'none';
                        microphone.style.pointerEvents = 'none';
                        microphone.style.opacity = 0;
                        input.blur();
                        enter.style.pointerEvents = 'none';
                        input.placeholder = 'Choose from Menu';
                        input.type = 'text';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 218px)';
                        } else {
                          body.style.height = 'calc(100% - 143px)';
                        }
                      }
                    }
                  }
                } else if (prev_placeholder == 'visit') {
                  prev_placeholder = '';
                } else if (current_question_type == 'location') {

                  var main_opened_div = document.getElementById('opened');
        
                  if (
                    main_opened_div.contains(document.getElementById('bg-shadow-overlay'))
                  ) {
                    main_opened_div.removeChild(
                      document.getElementById('bg-shadow-overlay')
                    );
                  }

                  if (locationSearchClicked) {
                    if (!shouldShowMenu) {
                      footer.style.display = 'none';
                      if (header.contains(company_title_description)) {
                        body.style.height = 'calc(100% - 168px)';
                      } else {
                        body.style.height = 'calc(100% - 93px)';
                      }
                      footer.classList.add('close');
                    } else {
                      if (entry_id) {
                        input.style.pointerEvents = 'auto';
                        microphone.style.pointerEvents = 'auto';
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = 'auto';
                        setPlaceHolders();
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 218px)';
                        } else {
                          body.style.height = 'calc(100% - 143px)';
                        }
                      } else {
                        input.style.pointerEvents = 'none';
                        microphone.style.pointerEvents = 'none';
                        microphone.style.opacity = 0;
                        input.blur();
                        enter.style.pointerEvents = 'none';
                        input.placeholder = 'Choose from Menu';
                        input.type = 'text';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 218px)';
                        } else {
                          body.style.height = 'calc(100% - 143px)';
                        }
                      }
                    }
                  }
                } else if (current_question_type == 'live_agent') {
                } else if (
                  current_question_type == 'radio' ||
                  current_question_type == 'whatsapp_list' ||
                  current_question_type == 'whatsapp_buttons'
                ) {
                  var should_show_input;
                  if (is_radio_hidden && radio_options && radio_options.length > 0) {
                    if (radio_options.indexOf(input.value) == -1) {
                      should_show_input = true;
                    }
                  }
                  if (!should_show_input) {
                    if (!shouldShowMenu) {
                      footer.style.display = 'none';
                      if (header.contains(company_title_description)) {
                        body.style.height = 'calc(100% - 168px)';
                      } else {
                        body.style.height = 'calc(100% - 93px)';
                      }
                      footer.classList.add('close');
                    } else {
                      if (entry_id) {
                        input.style.pointerEvents = 'auto';
                        microphone.style.pointerEvents = 'auto';
                        microphone.style.opacity = 1;
                        enter.style.pointerEvents = 'auto';
                        setPlaceHolders();
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 218px)';
                        } else {
                          body.style.height = 'calc(100% - 143px)';
                        }
                      } else {
                        input.style.pointerEvents = 'none';
                        microphone.style.pointerEvents = 'none';
                        microphone.style.opacity = 0;
                        input.blur();
                        enter.style.pointerEvents = 'none';
                        input.placeholder = 'Choose from Menu';
                        input.type = 'text';
                        if (header.contains(company_title_description)) {
                          body.style.height = 'calc(100% - 218px)';
                        } else {
                          body.style.height = 'calc(100% - 143px)';
                        }
                      }
                    }
                  }
                } else {
                  if (!shouldShowMenu) {
                    footer.style.display = 'none';
                    if (header.contains(company_title_description)) {
                      body.style.height = 'calc(100% - 168px)';
                    } else {
                      body.style.height = 'calc(100% - 93px)';
                    }
                    footer.classList.add('close');
                  } else {
                    if (entry_id) {
                      input.style.pointerEvents = 'auto';
                      microphone.style.pointerEvents = 'auto';
                      microphone.style.opacity = 1;
                      enter.style.pointerEvents = 'auto';
                      setPlaceHolders();
                      if (header.contains(company_title_description)) {
                        body.style.height = 'calc(100% - 218px)';
                      } else {
                        body.style.height = 'calc(100% - 143px)';
                      }
                    } else {
                      input.style.pointerEvents = 'none';
                      microphone.style.pointerEvents = 'none';
                      microphone.style.opacity = 0;
                      input.blur();
                      enter.style.pointerEvents = 'none';
                      input.placeholder = 'Choose from Menu';
                      input.type = 'text';
                      if (header.contains(company_title_description)) {
                        body.style.height = 'calc(100% - 218px)';
                      } else {
                        body.style.height = 'calc(100% - 143px)';
                      }
                    }
                  }
                }
              }
            }else{
                if (input.value.trim().length > 495) {
                  if (!document.querySelector('.toast-file-message')) {
                    const toast = document.createElement('div');
                    toast.classList.add('toast-file-message');
                    toast.style.top = '60px'
                    toast.style.padding = '12px 10px'
                    toast.style.background = 'black'
                    toast.style.color = '#fff'
                    if (font && font.length > 0) {
                      toast.classList.add(font);
                    }
                  
                    toast.innerHTML = `Input text should not exceed 495 characters.`;
                    if (document.getElementById("opened")) {
                      document.getElementById("opened").appendChild(toast);
                    }
                  
                    setTimeout(() => {
                      toast.remove();
                    }, 5000);
                  }
                }
            }
          }
        }
        input.addEventListener("focus", function (e) {
          footer.style.cssText = footer.style.cssText + "border:1px solid rgb(56, 97, 251) !important";
          footer.style.boxShadow = "0px 0px 0px 4px rgb(230, 240, 255)";
        });
        input.addEventListener("blur", function (e) {
          footer.style.border = ""; 
          footer.style.boxShadow = "";
        });
        input.addEventListener("keydown", function (e) {
          if (agreed) {
            isSomethingGoingOn = !0;
            nothingWentOnFor = 0;
            encourageMessageIteration = 0;
            if (e.keyCode === 13 && enter.style.pointerEvents != "none") {
              handleSubmitEnteredValue()
            }
          }
        });
        enter.addEventListener("click", function (e) {
          if (agreed) {
            handleSubmitEnteredValue()
          }
        });
      }
      window.totalFn = totalFn;
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
          totalData = JSON.parse(this.response).chatbot_details;
          agentTotalData = JSON.parse(this.response).agent_details;
          var device;
          if (
            /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
              navigator.userAgent
            )
          ) {
            device = "mobile";
          } else {
            device = "desktop";
          }
          device_blocked = false;
          if (
            totalData[0].available_platforms &&
            totalData[0].available_platforms.length > 0
          ) {
            if (totalData[0].available_platforms.includes(device)) {
            } else {
              device_blocked = true;
            }
          }
          banned_ips = JSON.parse(this.response).banned_ips;
          if (
            ip_address &&
            ip_address.length > 0 &&
            banned_ips &&
            banned_ips.length > 0
          ) {
            for (var i = 0; i < banned_ips.length; i++) {
              if (banned_ips[i].banned_ip == ip_address) {
                ip_is_banned = true;
                banned_reason = banned_ips[i].reason;
              }
            }
          }
          var urlDer;
          var whiteUrlDer;
          if (
            JSON.parse(this.response).chatbot_details &&
            JSON.parse(this.response).chatbot_details.length > 0
          ) {
            if (
              JSON.parse(this.response).chatbot_details[0].whitelisting_urls &&
              JSON.parse(this.response).chatbot_details[0].whitelisting_urls
                .length > 0 &&
              JSON.parse(this.response).chatbot_details[0].whitelisting_urls != null
            ) {
              white_urls = JSON.parse(
                this.response
              ).chatbot_details[0].whitelisting_urls.split(",");
              for (var i = 0; i < white_urls.length; i++) {
                var url_without_starting = window.location.href;
                if (url_without_starting.includes("https://")) {
                  url_without_starting = url_without_starting.replace(
                    "https://",
                    ""
                  );
                }
                if (url_without_starting.includes("http://")) {
                  url_without_starting = url_without_starting.replace(
                    "http://",
                    ""
                  );
                }
                if (url_without_starting.includes("www.")) {
                  url_without_starting = url_without_starting.replace("www.", "");
                }
                var current_url = white_urls[i];
                if (current_url.includes("https://")) {
                  current_url = current_url.replace("https://", "");
                }
                if (current_url.includes("http://")) {
                  current_url = current_url.replace("http://", "");
                }
                if (current_url.includes("www.")) {
                  current_url = current_url.replace("www.", "");
                }
                if (url_without_starting.includes(current_url.trim())) {
                  whiteUrlDer = !0;
                }
              }
              if (whiteUrlDer) {
                if (document.getElementById("closed")) {
                  document.getElementById("closed").style.display = "block";
                }
                if (
                  document.getElementById("pulse") &&
                  document.getElementById("pulse") != null
                ) {
                  document.getElementById("pulse").style.display = "block";
                }
              }
            }
            if (
              JSON.parse(this.response).chatbot_details[0].blacklisting_urls &&
              JSON.parse(this.response).chatbot_details[0].blacklisting_urls
                .length > 0 &&
              JSON.parse(this.response).chatbot_details[0].blacklisting_urls != null
            ) {
              urls = JSON.parse(
                this.response
              ).chatbot_details[0].blacklisting_urls.split(",");
              for (var i = 0; i < urls.length; i++) {
                var url_without_starting = window.location.href;
                if (url_without_starting.includes("https://")) {
                  url_without_starting = url_without_starting.replace(
                    "https://",
                    ""
                  );
                }
                if (url_without_starting.includes("http://")) {
                  url_without_starting = url_without_starting.replace(
                    "http://",
                    ""
                  );
                }
                if (url_without_starting.includes("www.")) {
                  url_without_starting = url_without_starting.replace("www.", "");
                }
                var current_url = urls[i];
                if (current_url.includes("https://")) {
                  current_url = current_url.replace("https://", "");
                }
                if (current_url.includes("http://")) {
                  current_url = current_url.replace("http://", "");
                }
                if (current_url.includes("www.")) {
                  current_url = current_url.replace("www.", "");
                }
                if (url_without_starting.includes(current_url.trim())) {
                  urlDer = !0;
                }
              }
              if (urlDer) {
                if (document.getElementById("opened")) {
                  document.getElementById("opened").style.display = "none";
                }
                if (document.getElementById("closed")) {
                  document.getElementById("closed").style.display = "none";
                }
                if (
                  document.getElementById("pulse") &&
                  document.getElementById("pulse") != null
                ) {
                  document.getElementById("pulse").style.display = "none";
                }
              }
            }
            if (
              JSON.parse(this.response).chatbot_details[0].enable_live_online == "1"
            ) {
              enable_live_online = !0;
            } else if (
              JSON.parse(this.response).chatbot_details[0].enable_live_online == "0"
            ) {
              enable_live_online = !1;
            }
            if (
              JSON.parse(this.response).chatbot_details[0].office_timings &&
              JSON.parse(this.response).chatbot_details[0].office_timings.length > 0
            ) {
              var json = JSON.parse(
                JSON.parse(this.response).chatbot_details[0].office_timings
              );
              var date = new Date();
              var todays_day;
              if (date.getDay() == 0) {
                todays_day = 7;
              } else {
                todays_day = date.getDay();
              }
              var week_days = json.weekdays;
              if (week_days && week_days.length > 0) {
                if (week_days.indexOf(todays_day) > -1) {
                  proceed_to_start_bot = true;
                }
              }
              if (proceed_to_start_bot) {
                if (json.from_timing && json.from_timing.length > 0) {
                  if (json.to_timing && json.to_timing.length > 0) {
                    var d = new Date();
                    var date = d.getDate();
                    if (date < 10) {
                      date = "0" + date;
                    }
                    var month = d.getMonth() + 1;
                    if (month < 10) {
                      month = "0" + month;
                    }
                    var new_from_date;
                    var new_to_date;
                    if (is_safari || is_firefox) {
                      new_from_date = new Date(
                        d.getFullYear() +
                        "/" +
                        month +
                        "/" +
                        date +
                        " " +
                        json.from_timing
                      );
                      new_to_date = new Date(
                        d.getFullYear() +
                        "/" +
                        month +
                        "/" +
                        date +
                        " " +
                        json.to_timing
                      );
                    } else {
                      new_from_date = new Date(
                        d.getFullYear() +
                        "-" +
                        month +
                        "-" +
                        date +
                        " " +
                        json.from_timing
                      );
                      new_to_date = new Date(
                        d.getFullYear() +
                        "-" +
                        month +
                        "-" +
                        date +
                        " " +
                        json.to_timing
                      );
                    }
                    new_from_date = new_from_date.getTime();
                    new_to_date = new_to_date.getTime();
                    var current_utc_time = new Date();
                    var timezone_val =
                      current_utc_time.getTimezoneOffset() * 60 * 1000;
                    current_utc_time = current_utc_time.getTime();
                    current_utc_time = current_utc_time + timezone_val;
                    var add_subtract;
                    if (json.timezone) {
                      if (json.timezone.includes("+")) {
                        add_subtract = "add";
                        var timezone = json.timezone.substring(
                          1,
                          json.timezone.length
                        );
                        timezone_arr = timezone.split(":");
                        var timezone_hours = parseInt(timezone_arr[0]);
                        var timezone_mins = parseInt(timezone_arr[1]);
                        var x = parseInt(
                          parseInt(timezone_hours * 60 * 60 * 1000) +
                          parseInt(timezone_mins * 60 * 1000)
                        );
                        current_utc_time = current_utc_time + x;
                      } else if (json.timezone.includes("-")) {
                        add_subtract = "subtract";
                        var timezone = json.timezone.substring(
                          1,
                          json.timezone.length
                        );
                        timezone_arr = timezone.split(":");
                        var timezone_hours = parseInt(timezone_arr[0]);
                        var timezone_mins = parseInt(timezone_arr[1]);
                        var x = parseInt(
                          parseInt(timezone_hours * 60 * 60 * 1000) +
                          parseInt(timezone_mins * 60 * 1000)
                        );
                        current_utc_time = current_utc_time - x;
                      }
                    }
                    if (
                      current_utc_time > new_from_date &&
                      current_utc_time < new_to_date
                    ) {
                    } else {
                      proceed_to_start_bot = false;
                    }
                  } else {
                    proceed_to_start_bot = true;
                  }
                } else {
                  proceed_to_start_bot = true;
                }
              }
            } else {
              proceed_to_start_bot = true;
            }
            if (enable_live_online) {
              try {
                if (
                  (window.Tawk_API && window.Tawk_API.getStatus() == "online") ||
                  (window.LC_API && window.LC_API.agents_are_available())
                ) {
                  is_online = !0;
                } else {
                  is_online = !1;
                }
              } catch (e) {
              } finally {
              }
              try {
                if (window.Tawk_API && window.Tawk_API.getStatus() == "online") {
                } else if (window.Tawk_API) {
                  if (!chat_with_us_cliked) {
                    window.Tawk_API.hideWidget();
                  }
                }
              } catch (e) {
              } finally {
              }
              if (window.LC_API && window.LC_API.agents_are_available()) {
              } else if (window.LC_API) {
                try {
                  window.LC_API.hide_chat_window();
                } catch (e) {
                } finally {
                }
              }
            } else {
              try {
                zE("webWidget", "hide");
              } catch (e) {
              } finally {
              }
              if (window.Tawk_API || window.LC_API) {
                is_online = !0;
              } else {
                is_online = !1;
              }
            }
            if (white_urls && white_urls != "null" && white_urls.length > 0) {
              for (var i = 0; i < white_urls.length; i++) {
                var url_without_starting = window.location.href;
                if (url_without_starting.includes("https://")) {
                  url_without_starting = url_without_starting.replace(
                    "https://",
                    ""
                  );
                }
                if (url_without_starting.includes("http://")) {
                  url_without_starting = url_without_starting.replace(
                    "http://",
                    ""
                  );
                }
                if (url_without_starting.includes("www.")) {
                  url_without_starting = url_without_starting.replace("www.", "");
                }
                var current_url = white_urls[i];
                if (current_url.includes("https://")) {
                  current_url = current_url.replace("https://", "");
                }
                if (current_url.includes("http://")) {
                  current_url = current_url.replace("http://", "");
                }
                if (current_url.includes("www.")) {
                  current_url = current_url.replace("www.", "");
                }
                if (url_without_starting.includes(current_url.trim())) {
                  whiteUrlDer = !0;
                }
              }
              if (whiteUrlDer) {
                if (enable_live_online && is_online) {
                } else {
                  if (
                    proceed_to_start_bot &&
                    !device_blocked
                  ) {
                    if (!already_total_fn_loaded) {
                      totalFn();
                      already_total_fn_loaded = true;
                    }
                  } else {
                    setTimeout(function () {
                      if (document.getElementById("pulse_smatbot_unique")) {
                        document.getElementById("pulse_smatbot_unique").innerHTML =
                          "";
                      }
                    }, 500);
                  }
                }
              } else {
              }
            } else {
            }
            if (urls && urls != "null" && urls.length > 0) {
              for (var i = 0; i < urls.length; i++) {
                var url_without_starting = window.location.href;
                if (url_without_starting.includes("https://")) {
                  url_without_starting = url_without_starting.replace(
                    "https://",
                    ""
                  );
                }
                if (url_without_starting.includes("http://")) {
                  url_without_starting = url_without_starting.replace(
                    "http://",
                    ""
                  );
                }
                if (url_without_starting.includes("www.")) {
                  url_without_starting = url_without_starting.replace("www.", "");
                }
                var current_url = urls[i];
                if (current_url.includes("https://")) {
                  current_url = current_url.replace("https://", "");
                }
                if (current_url.includes("http://")) {
                  current_url = current_url.replace("http://", "");
                }
                if (current_url.includes("www.")) {
                  current_url = current_url.replace("www.", "");
                }
                if (url_without_starting.includes(current_url.trim())) {
                  urlDer = !0;
                }
              }
              if (urlDer) {
              } else {
                if (enable_live_online && is_online) {
                } else {
                  if (
                    proceed_to_start_bot &&
                    !device_blocked
                  ) {
                    if (!already_total_fn_loaded) {
                      totalFn();
                      already_total_fn_loaded = true;
                    }
                  } else {
                    setTimeout(function () {
                      if (document.getElementById("pulse_smatbot_unique")) {
                        document.getElementById("pulse_smatbot_unique").innerHTML =
                          "";
                      }
                    }, 500);
                  }
                }
              }
            } else {
              if (white_urls && white_urls != "null" && white_urls.length > 0) {
              } else {
                if (enable_live_online && is_online) {
                } else {
                  if (
                    proceed_to_start_bot &&
                    !device_blocked
                  ) {
                    if (!already_total_fn_loaded) {
                      totalFn();
                      already_total_fn_loaded = true;
                    }
                  } else {
                    setTimeout(function () {
                      if (document.getElementById("pulse_smatbot_unique")) {
                        document.getElementById("pulse_smatbot_unique").innerHTML =
                          "";
                      }
                    }, 500);
                  }
                }
              }
            }
            setInterval(function () {
              try {
                if (
                  (window.Tawk_API && window.Tawk_API.getStatus() == "online") ||
                  (window.LC_API && window.LC_API.agents_are_available())
                ) {
                  is_online = !0;
                } else {
                  is_online = !1;
                }
              } catch (e) {
              } finally {
              }
              if (enable_live_online && is_online) {
                if (inTheMiddle) {
                  if (window.Tawk_API) {
                    if (!chat_with_us_cliked) {
                      window.Tawk_API.hideWidget();
                    }
                  }
                  if (window.LC_API) {
                    try {
                      window.LC_API.hide_chat_window();
                    } catch (e) {
                    } finally {
                    }
                  }
                } else {
                  if (document.getElementById("opened")) {
                    document.getElementById("opened").style.display = "none";
                  }
                  if (document.getElementById("closed")) {
                    document.getElementById("closed").style.display = "none";
                  }
                  if (
                    document.getElementById("pulse") &&
                    document.getElementById("pulse") != null
                  ) {
                    document.getElementById("pulse").style.display = "none";
                  }
                  if (window.Tawk_API && window.Tawk_API.isChatHidden()) {
                    window.Tawk_API.showWidget();
                  }
                  if (window.LC_API && window.LC_API.chat_window_hidden()) {
                    window.LC_API.open_chat_window();
                  }
                }
              } else if (window.Tawk_API && window.Tawk_API.isVisitorEngaged()) {
                if (
                  document.getElementById("opened") ||
                  document.getElementById("closed") ||
                  document.getElementById("pulse")
                ) {
                  if (window.Tawk_API) {
                    if (!chat_with_us_cliked) {
                      window.Tawk_API.hideWidget();
                    }
                  }
                  if (window.LC_API) {
                    try {
                      window.LC_API.hide_chat_window();
                    } catch (e) {
                    } finally {
                    }
                  }
                }
              } else {
                if (
                  document.getElementById("opened") ||
                  document.getElementById("closed") ||
                  (document.getElementById("pulse") &&
                    document.getElementById("pulse") != null)
                ) {
                  if (
                    document.getElementById("pulse") &&
                    document.getElementById("pulse") != null
                  ) {
                    document.getElementById("pulse").style.display = "block";
                  }
                  document.getElementById("closed").style.display = "block";
                  if (window.Tawk_API) {
                    if (!chat_with_us_cliked) {
                      window.Tawk_API.hideWidget();
                    }
                  }
                  if (window.LC_API) {
                    try {
                      window.LC_API.hide_chat_window();
                    } catch (e) {
                    } finally {
                    }
                  }
                  if (
                    white_urls &&
                    white_urls != "null" &&
                    white_urls.length > 0
                  ) {
                    for (var i = 0; i < white_urls.length; i++) {
                      var url_without_starting = window.location.href;
                      if (url_without_starting.includes("https://")) {
                        url_without_starting = url_without_starting.replace(
                          "https://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("http://")) {
                        url_without_starting = url_without_starting.replace(
                          "http://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("www.")) {
                        url_without_starting = url_without_starting.replace(
                          "www.",
                          ""
                        );
                      }
                      var current_url = white_urls[i];
                      if (current_url.includes("https://")) {
                        current_url = current_url.replace("https://", "");
                      }
                      if (current_url.includes("http://")) {
                        current_url = current_url.replace("http://", "");
                      }
                      if (current_url.includes("www.")) {
                        current_url = current_url.replace("www.", "");
                      }
                      if (url_without_starting.includes(current_url.trim())) {
                        whiteUrlDer = !0;
                        break;
                      } else {
                        whiteUrlDer = !1;
                      }
                    }
                    if (whiteUrlDer) {
                      if (document.getElementById("closed")) {
                        document.getElementById("closed").style.display = "block";
                      }
                      if (
                        document.getElementById("pulse") &&
                        document.getElementById("pulse") != null
                      ) {
                        document.getElementById("pulse").style.display = "block";
                      }
                    } else {
                      if (
                        document.getElementById("pulse") &&
                        document.getElementById("pulse") != null
                      ) {
                        document.getElementById("pulse").style.display = "none";
                      }
                      if (
                        document.getElementById("closed") &&
                        document.getElementById("closed") != null
                      ) {
                        document.getElementById("closed").style.display = "none";
                      }
                      if (
                        document.getElementById("opened") &&
                        document.getElementById("opened") != null
                      ) {
                        document.getElementById("opened").style.display = "none";
                      }
                    }
                  }
                  if (urls && urls != "null" && urls.length > 0) {
                    for (var i = 0; i < urls.length; i++) {
                      var url_without_starting = window.location.href;
                      if (url_without_starting.includes("https://")) {
                        url_without_starting = url_without_starting.replace(
                          "https://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("http://")) {
                        url_without_starting = url_without_starting.replace(
                          "http://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("www.")) {
                        url_without_starting = url_without_starting.replace(
                          "www.",
                          ""
                        );
                      }
                      var current_url = urls[i];
                      if (current_url.includes("https://")) {
                        current_url = current_url.replace("https://", "");
                      }
                      if (current_url.includes("http://")) {
                        current_url = current_url.replace("http://", "");
                      }
                      if (current_url.includes("www.")) {
                        current_url = current_url.replace("www.", "");
                      }
                      if (url_without_starting.includes(current_url.trim())) {
                        urlDer = !0;
                        break;
                      } else {
                        urlDer = !1;
                      }
                    }
                    if (urlDer) {
                      if (
                        document.getElementById("pulse") &&
                        document.getElementById("pulse") != null
                      ) {
                        document.getElementById("pulse").style.display = "none";
                      }
                      if (document.getElementById("closed")) {
                        document.getElementById("closed").style.display = "none";
                      }
                      if (document.getElementById("opened")) {
                        document.getElementById("opened").style.display = "none";
                      }
                    }
                  }
                } else {
                  if (
                    white_urls &&
                    white_urls != "null" &&
                    white_urls.length > 0
                  ) {
                    for (var i = 0; i < white_urls.length; i++) {
                      var url_without_starting = window.location.href;
                      if (url_without_starting.includes("https://")) {
                        url_without_starting = url_without_starting.replace(
                          "https://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("http://")) {
                        url_without_starting = url_without_starting.replace(
                          "http://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("www.")) {
                        url_without_starting = url_without_starting.replace(
                          "www.",
                          ""
                        );
                      }
                      var current_url = white_urls[i];
                      if (current_url.includes("https://")) {
                        current_url = current_url.replace("https://", "");
                      }
                      if (current_url.includes("http://")) {
                        current_url = current_url.replace("http://", "");
                      }
                      if (current_url.includes("www.")) {
                        current_url = current_url.replace("www.", "");
                      }
                      if (url_without_starting.includes(current_url.trim())) {
                        whiteUrlDer = !0;
                      }
                    }
                    if (whiteUrlDer) {
                      if (
                        proceed_to_start_bot &&
                        !device_blocked
                      ) {
                        if (!already_total_fn_loaded) {
                          totalFn();
                          already_total_fn_loaded = true;
                        }
                      } else {
                        setTimeout(function () {
                          if (document.getElementById("pulse_smatbot_unique")) {
                            document.getElementById(
                              "pulse_smatbot_unique"
                            ).innerHTML = "";
                          }
                        }, 500);
                      }
                    } else {
                    }
                  }
                  if (urls && urls != "null" && urls.length > 0) {
                    for (var i = 0; i < urls.length; i++) {
                      var url_without_starting = window.location.href;
                      if (url_without_starting.includes("https://")) {
                        url_without_starting = url_without_starting.replace(
                          "https://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("http://")) {
                        url_without_starting = url_without_starting.replace(
                          "http://",
                          ""
                        );
                      }
                      if (url_without_starting.includes("www.")) {
                        url_without_starting = url_without_starting.replace(
                          "www.",
                          ""
                        );
                      }
                      var current_url = urls[i];
                      if (current_url.includes("https://")) {
                        current_url = current_url.replace("https://", "");
                      }
                      if (current_url.includes("http://")) {
                        current_url = current_url.replace("http://", "");
                      }
                      if (current_url.includes("www.")) {
                        current_url = current_url.replace("www.", "");
                      }
                      if (url_without_starting.includes(current_url.trim())) {
                        urlDer = !0;
                      }
                    }
                    if (urlDer) {
                    } else {
                      if (
                        proceed_to_start_bot &&
                        !device_blocked
                      ) {
                        if (!already_total_fn_loaded) {
                          totalFn();
                          already_total_fn_loaded = true;
                        }
                      } else {
                        setTimeout(function () {
                          if (document.getElementById("pulse_smatbot_unique")) {
                            document.getElementById(
                              "pulse_smatbot_unique"
                            ).innerHTML = "";
                          }
                        }, 500);
                      }
                    }
                  } else {
                    if (
                      white_urls &&
                      white_urls != "null" &&
                      white_urls.length > 0
                    ) {
                    } else {
                      if (
                        proceed_to_start_bot &&
                        !device_blocked
                      ) {
                        if (!already_total_fn_loaded) {
                          totalFn();
                          already_total_fn_loaded = true;
                        }
                      } else {
                        setTimeout(function () {
                          if (document.getElementById("pulse_smatbot_unique")) {
                            document.getElementById(
                              "pulse_smatbot_unique"
                            ).innerHTML = "";
                          }
                        }, 500);
                      }
                    }
                  }
                }
              }
            }, 1000);
          }
        }
      };
      xhttp.open("POST", main_url + "/kya_backend/pagehub/chatbot_utils?action=read_cb_by_id", !0);
      xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhttp.send("action=read_cb_by_id&chatbot_id=" + chatbot_id);
    }
  });
  xhr.open("GET", main_url + "/kya_backend/Api/chatbot?chatbot_id=" + chatbot_id);
  xhr.send();
}
if (window.location.host == "savemax.com" || window.location.host == "richlandinfra.com" || window.location.host == "www.oakridge.in" || window.location.host == "www.indianarmour.com") {
  mainBot();
} else {
  if (window.attachEvent) {
    window.attachEvent("onload", mainBot);
  } else if (window.addEventListener) {
    window.addEventListener("load", mainBot, !1);
  } else {
    document.addEventListener("load", mainBot, !1);
  }
}