'use strict'

document.addEventListener('DOMContentLoaded', () => {
    let mailConfig = {
        "default": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@icloud.com", "@msn.com", "@live.com", "@mail.com", "@aol.com", "@googlemail.com", "@me.com", "@ymail.com", "@rocketmail.com"],
        "ca": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@yahoo.ca", "@icloud.com", "@hotmail.ca", "@live.ca", "@videotron.ca", "@rogers.com", "@hotmail.fr", "@shaw.ca", "@telus.net", "@msn.com", "@yahoo.fr", "@live.com", "@me.com", "@sympatico.ca", "@bell.net", "@outlook.fr", "@aol.com", "@ymail.com", "@live.fr", "@mail.com", "@sasktel.net", "@cogeco.ca", "@yahoo.co.uk", "@protonmail.com", "@cgocable.ca", "@eastlink.ca", "@rocketmail.com", "@mymts.net", "@bellaliant.net", "@mac.com", "@xplornet.com", "@globetrotter.net", "@gmx.com", "@email.com", "@hotmail.co.uk", "@tbaytel.net", "@ccapcable.com", "@telusplanet.net", "@xplornet.ca", "@bellnet.ca", "@royallepage.ca"],
        "co": ["@gmail.com", "@hotmail.com", "@outlook.com", "@yahoo.es", "@hotmail.es", "@yahoo.com", "@outlook.es", "@live.com", "@icloud.com", "@mail.com", "@msn.com"],
        "de": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@icloud.com", "@msn.com", "@live.com", "@mail.com", "@aol.com", "@googlemail.com", "@me.com", "@ymail.com", "@rocketmail.com", "@web.de", "@gmx.de", "@t-online.de", "@yahoo.de", "@hotmail.de", "@gmx.net", "@freenet.de", "@outlook.de", "@live.de", "@arcor.de", "@mail.de", "@online.de", "@aol.de", "@msn.com", "@kabelmail.de", "@mail.ru", "@vodafone.de", "@email.de", "@ewetel.net", "@hn-ewv.de", "@kabelbw.de", "@netcologne.de", "@gmx.at", "@gmx.ch", "@onlinehome.de", "@ok.de", "@posteo.de", "@magenta.de", "@o2online.de", "@ewe.net", "@e-mail.de"],
        "mx": ["@gmail.com", "@hotmail.com", "@outlook.com", "@yahoo.com.mx", "@live.com.mx", "@icloud.com", "@yahoo.com", "@outlook.es", "@live.com", "@hotmail.es", "@mail.com", "@msn.com", "@hotmail.com.mx", "@prodigy.net.mx", "@yahoo.es", "@email.com"],
        "uk": ["@gmail.com", "@hotmail.com", "@hotmail.co.uk", "@yahoo.com", "@yahoo.co.uk", "@icloud.com", "@outlook.com", "@btinternet.com", "@aol.com", "@googlemail.com", "@live.co.uk", "@sky.com", "@me.com", "@msn.com", "@live.com", "@mail.com", "@ntlworld.com", "@ymail.com", "@talktalk.net", "@blueyonder.co.uk", "@virginmedia.com", "@aol.co.uk", "@rocketmail.com", "@abv.bg", "@tiscali.co.uk", "@mac.com", "@btopenworld.com", "@wp.pl", "@btconnect.com", "@gmx.co.uk", "@gmx.com", "@protonmail.com", "@yahoo.fr", "@inbox.lv", "@yahoo.co.in", "@talk21.com", "@yahoo.it", "@mail.ru", "@uwclub.net", "@email.com", "@hotmail.it", "@hotmail.fr", "@nhs.net", "@o2.pl", "@seznam.cz", "@virgin.net", "@yahoo.ro", "@yahoo.es", "@op.pl", "@yahoo.ie"],
        "fr": ["@gmail.com", "@hotmail.fr", "@orange.fr", "@yahoo.fr", "@hotmail.com", "@live.fr", "@outlook.fr", "@wanadoo.fr", "@sfr.fr", "@free.fr", "@icloud.com", "@laposte.net", "@yahoo.com", "@outlook.com", "@neuf.fr", "@aol.com", "@msn.com", "@me.com", "@gmx.fr", "@bbox.fr", "@ymail.com", "@live.com", "@club-internet.fr", "@protonmail.com", "@aol.fr", "@gmx.com", "@cegetel.net", "@numericable.fr", "@mac.com", "@netcourrier.com", "@aliceadsl.fr", "@mail.com", "@mail.ru", "@abv.bg", "@noos.fr", "@hotmail.it", "@yahoo.co.uk", "@rocketmail.com", "@googlemail.com", "@yahoo.it", "@my.com", "@yahoo.es"],
        "tr": ["@gmail.com", "@hotmail.com", "@icloud.com", "@outlook.com", "@yahoo.com", "@windowslive.com", "@hotmail.com.tr", "@msn.com", "@mail.com", "@yandex.com", "@yahoo.com.tr", "@hotmail.de", "@mail.ru", "@outlook.com.tr", "@web.de", "@mynet.com", "@live.com", "@hotmail.co.uk", "@hotmail.fr", "@gmx.de", "@yahoo.de"],
        "es": ["@gmail.com", "@hotmail.com", "@hotmail.es", "@yahoo.es", "@yahoo.com", "@icloud.com", "@outlook.com", "@outlook.es", "@hotmail.fr", "@live.com", "@hotmail.co.uk", "@msn.com", "@aol.com", "@yahoo.co.uk", "@yahoo.fr", "@gmx.de", "@web.de", "@orange.fr", "@abv.bg", "@me.com", "@googlemail.com", "@btinternet.com", "@mail.com", "@yahoo.de", "@sky.com", "@live.co.uk"],
        "br": ["@gmail.com", "@hotmail.com", "@yahoo.com.br", "@outlook.com", "@yahoo.com", "@bol.com.br", "@icloud.com", "@live.com", "@terra.com.br", "@uol.com.br", "@hotmail.com.br", "@outlook.com.br", "@msn.com", "@ymail.com", "@mail.com", "@ig.com.br", "@me.com"],
        "nl": ["@gmail.com", "@hotmail.com", "@live.nl", "@outlook.com", "@ziggo.nl", "@icloud.com", "@hotmail.nl", "@yahoo.com", "@kpnmail.nl", "@home.nl", "@msn.com", "@upcmail.nl", "@planet.nl", "@me.com", "@hetnet.nl", "@chello.nl", "@quicknet.nl", "@casema.nl", "@xs4all.nl", "@zeelandnet.nl", "@kpnplanet.nl", "@telfort.nl", "@live.com", "@online.nl", "@yahoo.co.uk", "@wp.pl", "@abv.bg", "@mail.com", "@caiway.nl", "@yahoo.fr", "@protonmail.com", "@gmx.de", "@aol.com", "@mac.com", "@kabelfoon.nl", "@solcon.nl", "@o2.pl", "@tele2.nl", "@yahoo.nl", "@zonnet.nl", "@gmx.net", "@telenet.be", "@versatel.nl", "@t-mobilethuis.nl", "@yahoo.de", "@hccnet.nl", "@interia.pl", "@ymail.com", "@wxs.nl", "@seznam.cz", "@cs.com", "@caiway.net", "@hotmail.de", "@hotmail.fr", "@aol.nl", "@inbox.lv", "@t-online.de", "@web.de", "@live.be", "@hotmail.be"],
        "be": ["@gmail.com", "@hotmail.com", "@telenet.be", "@outlook.com", "@hotmail.be", "@live.be", "@yahoo.fr", "@skynet.be", "@yahoo.com", "@icloud.com", "@hotmail.fr", "@outlook.be", "@msn.com", "@outlook.fr", "@live.fr", "@me.com", "@proximus.be", "@live.com", "@live.nl", "@pandora.be", "@yahoo.be", "@gmx.fr", "@mail.com", "@abv.bg", "@hotmail.nl", "@scarlet.be", "@gmx.com", "@ymail.com", "@hotmail.de", "@protonmail.com", "@belgacom.net", "@voo.be", "@mail.ru", "@laposte.net", "@mac.com", "@orange.fr", "@wp.pl", "@hotmail.it", "@web.de", "@yahoo.es", "@sfr.fr"],
        "cl": ["@gmail.com", "@hotmail.com", "@live.cl", "@hotmail.cl", "@yahoo.com", "@yahoo.es", "@hotmail.es", "@icloud.com", "@outlook.com", "@live.com", "@outlook.es", "@mail.com", "@vtr.net", "@outlook.cl", "@msn.com", "@yahoo.cl", "@bomberos.cl"],
        "ec": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@hotmail.es", "@outlook.com", "@yahoo.es", "@outlook.es", "@live.com", "@icloud.com", "@mail.com", "@aol.com"],
        "ch": ["@gmail.com", "@hotmail.com", "@bluewin.ch", "@icloud.com", "@gmx.ch", "@outlook.com", "@hotmail.ch", "@yahoo.com", "@yahoo.fr", "@hotmail.fr", "@me.com", "@sunrise.ch", "@hotmail.it", "@netplus.ch", "@msn.com", "@gmx.net", "@hispeed.ch", "@outlook.fr", "@yahoo.it", "@live.fr", "@windowslive.com", "@yahoo.de", "@orange.fr", "@web.de", "@bluemail.ch", "@gmx.de", "@libero.it", "@live.com", "@hotmail.de", "@live.it", "@googlemail.com", "@net2000.ch", "@live.com.pt", "@protonmail.com", "@ymail.com", "@wanadoo.fr", "@ticino.com", "@outlook.de", "@sapo.pt", "@mail.ch", "@gmx.at", "@aol.com", "@ik.me", "@swissonline.ch", "@outlook.it", "@t-online.de", "@free.fr", "@sfr.fr", "@rocketmail.com", "@mac.com", "@virgilio.it", "@live.de", "@abv.bg", "@laposte.net"],
        "it": ["@gmail.com", "@libero.it", "@hotmail.it", "@yahoo.it", "@hotmail.com", "@icloud.com", "@alice.it", "@virgilio.it", "@yahoo.com", "@tiscali.it", "@live.it", "@outlook.it", "@me.com", "@outlook.com", "@tin.it", "@live.com", "@msn.com", "@inwind.it", "@tim.it", "@email.it", "@ymail.com", "@mail.com", "@mail.ru", "@fastwebnet.it", "@web.de", "@gmx.de", "@yahoo.fr", "@yahoo.de", "@yahoo.co.uk", "@protonmail.com", "@aol.com", "@email.com", "@hotmail.de", "@t-online.de"],
        "jp": ["@gmail.com", "@yahoo.co.jp", "@icloud.com", "@au.com", "@docomo.ne.jp", "@i.softbank.jp", "@ezweb.ne.jp", "@softbank.ne.jp", "@hotmail.com", "@me.com", "@nifty.com", "@outlook.jp", "@ybb.ne.jp", "@yahoo.ne.jp", "@mac.com", "@hotmail.co.jp", "@live.jp", "@yahoo.com", "@outlook.com", "@msn.com", "@jcom.home.ne.jp", "@ymobile.ne.jp", "@jcom.zaq.ne.jp", "@ymail.ne.jp", "@aol.com", "@nifty.ne.jp", "@beetle.ocn.ne.jp", "@rakuten.jp", "@kpe.biglobe.ne.jp"],
        "pe": ["@gmail.com", "@hotmail.com", "@outlook.com", "@yahoo.es", "@yahoo.com", "@outlook.es", "@hotmail.es", "@mail.com", "@icloud.com", "@live.com", "@outlook.com.pe"],
        "hu": ["@gmail.com", "@freemail.hu", "@citromail.hu", "@hotmail.com", "@gmail.hu", "@icloud.com", "@yahoo.com", "@t-online.hu", "@vipmail.hu", "@indamail.hu", "@gmai.com", "@hotmail.hu", "@outlook.hu", "@t-email.hu", "@outlook.com", "@mail.com", "@windowslive.com", "@me.com", "@protonmail.com", "@msn.com", "@index.hu", "@invitel.hu", "@digikabel.hu"],
        "au": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@yahoo.com.au", "@bigpond.com", "@icloud.com", "@live.com.au", "@live.com", "@y7mail.com", "@mail.com", "@optusnet.com.au", "@iinet.net.au", "@outlook.com.au", "@bigpond.net.au", "@hotmail.com.au", "@me.com", "@ymail.com", "@msn.com", "@tpg.com.au", "@yahoo.co.uk", "@westnet.com.au", "@hotmail.co.uk", "@internode.on.net", "@protonmail.com", "@aol.com", "@bigpond.com.au", "@rocketmail.com", "@gmx.com", "@adam.com.au", "@email.com", "@yahoo.co.nz", "@dodo.com.au", "@iprimus.com.au", "@aapt.net.au", "@live.co.uk"],
        "dk": ["@gmail.com", "@hotmail.com", "@live.dk", "@yahoo.com", "@outlook.dk", "@yahoo.dk", "@icloud.com", "@hotmail.dk", "@mail.dk", "@outlook.com", "@msn.com", "@me.com", "@godmail.dk", "@stofanet.dk", "@jubii.dk", "@mail.com", "@webspeed.dk", "@youmail.dk", "@privat.dk", "@mail.tele.dk", "@gmx.de", "@pc.dk", "@post.tele.dk", "@abv.bg", "@live.com", "@tdcadsl.dk", "@os.dk", "@it.dk", "@bbsyd.dk", "@sol.dk", "@dadlnet.dk", "@email.dk", "@c.dk", "@wp.pl", "@t-online.de", "@inbox.lv", "@protonmail.com", "@ymail.com", "@mac.com", "@web.de", "@aol.com", "@profibermail.dk", "@netmail.dk"],
        "hr": ["@gmail.com", "@yahoo.com", "@hotmail.com", "@net.hr", "@inet.hr", "@mup.hr", "@icloud.com", "@outlook.com", "@mail.com", "@live.com", "@windowslive.com", "@gmx.de", "@web.de", "@zg.t-com.hr", "@zd.ht.hr", "@skole.hr", "@pu.t-com.hr", "@a1net.hr", "@me.com", "@optinet.hr"],
        "se": ["@gmail.com", "@hotmail.com", "@outlook.com", "@live.se", "@telia.com", "@yahoo.com", "@hotmail.se", "@icloud.com", "@yahoo.se", "@msn.com", "@me.com", "@live.com", "@bredband.net", "@mail.com", "@spray.se", "@bahnhof.se", "@ymail.com", "@yahoo.fr", "@protonmail.com"],
        "pl": ["@gmail.com", "@wp.pl", "@o2.pl", "@interia.pl", "@op.pl", "@onet.pl", "@vp.pl", "@icloud.com", "@tlen.pl", "@onet.eu", "@poczta.onet.pl", "@poczta.fm", "@interia.eu", "@hotmail.com", "@yahoo.com", "@mail.ru", "@outlook.com", "@gazeta.pl", "@autograf.pl", "@me.com", "@spoko.pl", "@ukr.net", "@googlemail.com", "@yahoo.pl", "@onet.com.pl", "@buziaczek.pl", "@go2.pl", "@adres.pl", "@protonmail.com", "@mail.com", "@ymail.com", "@aol.com", "@live.com", "@amorki.pl", "@wp.eu", "@poczta.onet.eu", "@web.de", "@cyberia.pl", "@opoczta.pl"],
        "pt": ["@gmail.com", "@hotmail.com", "@sapo.pt", "@live.com.pt", "@icloud.com", "@outlook.pt", "@outlook.com", "@yahoo.com", "@yahoo.com.br", "@msn.com", "@live.com", "@netcabo.pt", "@hotmail.fr", "@me.com", "@hotmail.co.uk", "@yahoo.fr", "@mail.com", "@email.com", "@live.fr", "@portugalmail.pt", "@aol.com", "@orange.fr", "@protonmail.com"],
        "ro": ["@gmail.com", "@yahoo.com", "@yahoo.ro", "@icloud.com", "@hotmail.com", "@yahoo.it", "@ymail.com", "@yahoo.co.uk", "@yahoo.es", "@yahoo.fr", "@mail.com", "@freemail.hu", "@yahoo.de", "@outlook.com", "@email.com", "@rocketmail.com", "@libero.it"],
        "at": ["@gmail.com", "@gmx.at", "@hotmail.com", "@yahoo.com", "@icloud.com", "@gmx.net", "@aon.at", "@yahoo.de", "@outlook.com", "@live.at", "@a1.net", "@web.de", "@chello.at", "@hotmail.de", "@drei.at", "@outlook.de", "@me.com", "@gmx.de", "@live.de", "@sbg.at", "@msn.com", "@azet.sk", "@abv.bg", "@outlook.at", "@seznam.cz", "@liwest.at", "@freemail.hu", "@ymail.com", "@gmx.com", "@yahoo.at", "@googlemail.com", "@inode.at", "@live.com", "@vol.at", "@aol.com", "@mail.com", "@mail.ru", "@citromail.hu", "@gmx.ch"],
        "no": ["@gmail.com", "@hotmail.com", "@online.no", "@yahoo.com", "@outlook.com", "@live.no", "@yahoo.no", "@hotmail.no", "@icloud.com", "@lyse.net", "@msn.com", "@me.com", "@wp.pl", "@hovda.net", "@live.com", "@inbox.lv", "@mail.ru", "@ntebb.no", "@abv.bg", "@ymail.com", "@broadpark.no", "@frisurf.no", "@altiboxmail.no", "@wemail.no", "@yahoo.co.uk", "@nenett.no", "@signalbox.no", "@em1nn.no"],
        "bg": ["@abv.bg", "@gmail.com", "@mail.bg", "@yahoo.com", "@hotmail.com", "@icloud.com", "@mail.com", "@outlook.com", "@abv.com", "@gbg.bg", "@yahoo.co.uk", "@dir.bg", "@mail.ru", "@start.bg", "@googlemail.com"],
        "za": ["@gmail.com", "@yahoo.com", "@icloud.com", "@hotmail.com", "@outlook.com", "@mweb.co.za", "@ymail.com", "@live.co.za", "@live.com", "@yahoo.co.uk", "@telkomsa.net", "@vodamail.co.za", "@me.com", "@webmail.co.za", "@hotmail.co.za", "@mail.com", "@absamail.co.za", "@lantic.net", "@rocketmail.com", "@aol.com", "@worldonline.co.za", "@protonmail.com", "@email.com"],
        "th": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@icloud.com", "@hotmail.co.th", "@mail.com", "@outlook.com", "@outlook.co.th", "@windowslive.com", "@yahoo.fr", "@aol.com", "@yahoo.co.th", "@email.com"],
        "gr": ["@gmail.com", "@hotmail.com", "@yahoo.gr", "@yahoo.com", "@hotmail.gr", "@icloud.com", "@outlook.com", "@windowslive.com", "@otenet.gr", "@hotmail.co.uk", "@outlook.com.gr", "@abv.bg", "@mail.ru", "@googlemail.com", "@web.de", "@yahoo.co.uk", "@aol.com", "@mail.com", "@live.com", "@btinternet.com", "@me.com", "@sky.com", "@orange.fr", "@gmx.de", "@yahoo.de", "@msn.com", "@yahoo.fr"],
        "nz": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@xtra.co.nz", "@yahoo.co.nz", "@outlook.com", "@icloud.com", "@hotmail.co.nz", "@outlook.co.nz", "@live.com", "@windowslive.com", "@msn.com", "@yahoo.com.au", "@mail.com", "@ymail.com", "@hotmail.co.uk", "@me.com", "@farmside.co.nz", "@slingshot.co.nz", "@rocketmail.com", "@protonmail.com", "@kinect.co.nz", "@orcon.net.nz", "@yahoo.co.uk"],
        "sk": ["@gmail.com", "@azet.sk", "@centrum.sk", "@zoznam.sk", "@post.sk", "@seznam.cz", "@hotmail.com", "@yahoo.com", "@icloud.com", "@pobox.sk", "@atlas.sk", "@mail.com", "@citromail.hu", "@freemail.hu", "@hotmail.sk", "@email.cz", "@centrum.cz", "@orangemail.sk", "@googlemail.com", "@outlook.sk", "@outlook.com", "@me.com"],
        "cz": ["@seznam.cz", "@gmail.com", "@email.cz", "@centrum.cz", "@post.cz", "@icloud.com", "@volny.cz", "@atlas.cz", "@yahoo.com", "@tiscali.cz", "@hotmail.com", "@azet.sk", "@me.com", "@outlook.com", "@mail.ru", "@abv.bg", "@outlook.cz", "@protonmail.com", "@hotmail.cz", "@yahoo.fr"],
        "ie": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@yahoo.ie", "@yahoo.co.uk", "@icloud.com", "@outlook.com", "@live.ie", "@ymail.com", "@hotmail.co.uk", "@live.com", "@inbox.lv", "@eircom.net", "@mail.com", "@mail.ru", "@wp.pl", "@outlook.ie", "@googlemail.com", "@live.co.uk", "@msn.com", "@au.com", "@rocketmail.com", "@aol.com"],
        "fi": ["@gmail.com", "@hotmail.com", "@outlook.com", "@luukku.com", "@yahoo.com", "@meiliboxi.fi", "@icloud.com", "@hotmail.fi", "@pp.inet.fi", "@hot.ee", "@kolumbus.fi", "@saunalahti.fi", "@msn.com", "@mail.ee", "@live.fi", "@elisanet.fi", "@windowslive.com", "@inbox.lv", "@live.com", "@netti.fi", "@mail.com", "@me.com"],
        "sg": ["@gmail.com", "@yahoo.com", "@hotmail.com", "@yahoo.com.sg", "@outlook.com", "@icloud.com", "@ymail.com", "@live.com", "@singnet.com.sg", "@live.com.sg", "@mail.com", "@hotmail.sg", "@outlook.sg"],
        "lu": ["@gmail.com", "@hotmail.com", "@pt.lu", "@hotmail.fr", "@yahoo.fr", "@icloud.com", "@yahoo.com", "@outlook.com", "@yahoo.de", "@live.fr", "@outlook.fr", "@hotmail.de", "@msn.com", "@me.com", "@live.com", "@orange.fr", "@outlook.de"],
        "lt": ["@gmail.com", "@yahoo.com", "@inbox.lt", "@mail.ru", "@hotmail.com", "@icloud.com", "@yahoo.co.uk", "@yandex.ru", "@mail.com", "@googlemail.com", "@outlook.com"],
        "pa": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@hotmail.es", "@yahoo.es", "@icloud.com", "@live.com", "@mail.com", "@outlook.es"],
        "cr": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@hotmail.es", "@icloud.com", "@yahoo.es", "@outlook.com", "@live.com", "@mail.com", "@outlook.es"],
        "my": ["@gmail.com", "@yahoo.com", "@hotmail.com", "@yahoo.com.my", "@icloud.com", "@ymail.com", "@yahoo.co.uk", "@yahoo.com.sg", "@email.com", "@mail.com", "@outlook.com"],
        "kr": ["@naver.com", "@gmail.com", "@hanmail.net", "@daum.net", "@nate.com", "@kakao.com", "@hotmail.com", "@korea.kr", "@yahoo.co.kr", "@korea.com", "@yahoo.com"],
        "ee": ["@gmail.com", "@hot.ee", "@mail.ee", "@hotmail.com", "@mail.ru", "@online.ee", "@outlook.com", "@yahoo.com", "@icloud.com", "@live.com", "@list.ru", "@windowslive.com"],
        "in": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@icloud.com", "@rediffmail.com", "@msn.com", "@live.com", "@mail.com", "@aol.com", "@googlemail.com", "@me.com", "@ymail.com", "@rocketmail.com", "@yahoo.co.in", "@yahoo.co.uk", "@yahoo.in"],
        "sv": ["@gmail.com", "@hotmail.com", "@yahoo.com", "@outlook.com", "@hotmail.es", "@yahoo.es", "@outlook.es", "@mail.com"],
        "is": ["@gmail.com", "@simnet.is", "@hotmail.com", "@internet.is", "@yahoo.com", "@outlook.com", "@icloud.com", "@live.com", "@mi.is", "@wp.pl", "@visir.is"],
        "lv": ["@inbox.lv", "@gmail.com", "@mail.ru", "@yahoo.com", "@tvnet.lv", "@hotmail.com", "@icloud.com", "@outlook.com"]
    };

  let _countryCode = countryCode.toLowerCase();
  let thisCountryEmail = mailConfig.hasOwnProperty(_countryCode) ? mailConfig[_countryCode] : mailConfig['default'];
  
  $("input[name='sendingmail']").each(function() {
      const input = $(this);
      const presentation = $('<div>', { class: "presentation-mail", style: "display:none;" });
  
      input.after(presentation);
  
      thisCountryEmail.forEach(function (obj) {
          const div = $('<div>', { class: "mail-ext", text: obj });
          presentation.append(div);
      });
  
      function searchItems(thisobj) {
          const key = $(thisobj).val().toLowerCase();
          const atIndex = key.indexOf('@');
          const currentPresentation = input.next('.presentation-mail');
  
          if (key === "") {
              currentPresentation.hide();
          } else if (atIndex > -1) {
              currentPresentation.empty();
              const ext = key.substring(atIndex);
              const pre = key.substring(0, atIndex);
              let itemCount = 0;
  
              thisCountryEmail.forEach(obj => {
                  if (obj.indexOf(ext) === 0) {
                      itemCount++;
                      currentPresentation.append(`<div class="mail-ext">${pre}${obj}</div>`);
                  }
              });
  
              if (itemCount > 0) {
                  currentPresentation.show();
              } else {
                  currentPresentation.hide();
              }
          } else {
              currentPresentation.empty();
              thisCountryEmail.forEach(obj => {
                  currentPresentation.append(`<div class="mail-ext">${key}${obj}</div>`);
              });
              currentPresentation.show();
          }
      }
  
      input.on({
          "click": function(e) { showList(e, input); },
          "focus": function(e) { showList(e, input); },
          "input": function(e) {
              e.stopPropagation();
              searchItems(this);
          }
      });
  
      function showList(e, input) {
          e.stopPropagation();
          let val = input.val();
          if (val !== '') {
              input.next('.presentation-mail').show();
          }
      }
      $(document).click(function (e) {
          $('.presentation-mail').hide();
      });
  
      $(document).on("click", ".presentation-mail .mail-ext", function(event) {
          input.val($(this).text());
          input.next('.presentation-mail').hide();
      });
  });


//  loader animation

const loaderMessage = {
    "default": ["loading data"],
    "fr" : ["chargement de données"],
    "mx" : ["cargando datos"],
    "ca" : ["loading data"],
    "au" : ["loading data"],
    "hk" : ["loading data"],
    "es" : ["cargando datos"],
    "ec" : ["cargando datos"],
    "cl" : ["cargando datos"],
    "ch" : ["Laden von Daten"],
    "tr" : ["veri yükleniyor"],
    "fi" : ["tietojen lataaminen"],
    "sv" : ["cargando datos"],
    "sk" : ["načítavanie údajov"],
    "pt" : ["carregando dados"],
    "ph" : ["loading data"],
    "kr" : ["데이터 로딩"],
    "jp" : ["データのロード"],
    "dk" : ["indlæsning af data"],
    "co" : ["cargando datos"],
    "ar" : ["chargement de données"],
    "th" : ["กำลังโหลดข้อมูล"],
    "pe" : ["chargement de données"],
    "nz" : ["cargando datos"],
    "my" : ["loading data"],
    "tw" : ["cargando datos"],
    "se" : ["laddar data"],
    "nl" : ["gegevens laden"],
    "it" : ["caricamento dei dati"],
    "br" : ["carregando dados"],
    "be" : ["chargement de données"],
    "gb" : ["loading data"],
    "ae" : ["تحميل البيانات"],
    "pl" : ["ładowanie danych"],
    "mu" : ["cargando datos"],
    "ch" : ["Laden von Daten"],
    "za" : ["loading data"],
    "sg" : ["loading data"],
  	"gr" : ["φόρτωση δεδομένων"],
	"in" : ["loading data"],
  	"cz" : ["načítání dat"],
	"de" : ["Laden von Daten"],
  	"at" : ["Laden von Daten"],
};

function loaderHolder(msg, form){
    if(!msg){
        msg = loaderMessage["default"];
    }
    const loaderContainer = document.createElement("div");
    loaderContainer.classList = "intgrtn-loader-holder";
    loaderContainer.style.display = "block";
    const loaderBox = document.createElement("div");
    loaderBox.classList = "intgrtn-loader-text-holder";
    const loaderAnimation = document.createElement("div");
    loaderAnimation.classList = "intgrtn-lds-dual-ring";
    const loaderText = document.createElement("div");
    loaderText.classList = "intgrtn-loader-text";
    loaderText.textContent = msg

    loaderBox.appendChild(loaderAnimation);
    loaderBox.appendChild(loaderText);
    loaderContainer.appendChild(loaderBox);
    form.style.position = "relative";
    form.appendChild(loaderContainer);
}


// validation google

const errorMap = {
  "default" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "fr" : ["Numéro invalide", "Code pays invalide", "Trop court", "Trop long", "Numéro invalide"],
    "mx" : ["Número no válido", "Código de país no válido", "Demasiado corto", "Demasiado largo", "Número no válido"],
    "ca" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "au" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "hk" : ["Invalid number", "Invalid country code", "Too short", "Too long", "Invalid number"],
    "es" : ["Nommer inválida", "Código de país no válido", "Bahía corta", "demasiado lacio", "Nommer inválida"],
    "ec" : ["Nommer inválida", "Código de país no válido", "Bahía corta", "demasiado lacio", "Nommer inválida"],
    "cl" : ["Nommer inválida", "Código de país no válido", "Bahía corta", "demasiado lacio", "Nommer inválida"],
    "ch" : ["Ungültige Nummer", "Ungültige Landesvorwahl", "Sehr kurz", "Zu lang", "Ungültige Nummer"],
    "tr" : ["Geçersiz numara", "Geçersiz ülke kodu", "Çok kısa", "Çok uzun", "Geçersiz numara"],
    "fi" : ["Virheellinen numero", "Virheellinen maakoodi", "Liian lyhyt", "Liian pitkä", "Virheellinen numero"],
    "sv" : ["Número no válido", "Código de país no válido", "Muy corto", "Demasiado largo", "Número no válido"],
    "sk" : ["Nommer neplatný", "Neplatný kód krajiny", "Krátka zátoka", "príliš rovný", "Nommer neplatný"],
    "pt" : ["Número inválido", "Código de país inválido", "Muito curto", "Muito longo", "Número inválido"],
    "ph" : ["Invalid number", "Invalid country code", "Too short", "Too long", "Invalid number"],
    "kr" : ["잘못된 번호", "잘못된 국가 코드", "너무 짧음", "너무 길다", "잘못된 번호"],
    "jp" : ["無効な番号", "無効な国コード", "とても短い", "長すぎる", "無効な番号"],
    "dk" : ["Ugyldigt nummer", "Ugyldig landekode", "Meget kort", "For langt", "Ugyldigt nummer"],
    "co" : ["Nommer inválida", "Código de país no válido", "Bahía corta", "demasiado lacio", "Nommer inválida"],
    "ar" : ["Numéro invalide", "Code de pays invalide", "Très court", "Trop long", "Numéro invalide"],
    "th" : ["หมายเลขไม่ถูกต้อง", "รหัสประเทศไม่ถูกต้อง", "สั้นมาก", "ยาวเกินไป", "หมายเลข"],
    "pe" : ["Numéro invalide", "Code de pays invalide", "Très court", "Trop long", "Numéro invalide"],
    "nz" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "my" : ["Invalid number", "Invalid country code", "Too short", "Too long", "Invalid number"],
    "tw" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "se" : ["Ogiltigt nummer", "Ogiltig landskod", "Mycket kort", "För lång", "Ogiltigt nummer"],
    "nl" : ["Ongeldig nummer", "Ongeldige landcode", "Zeer kort", "Te lang", "Ongeldig nummer"],
    "it" : ["Numero non valido", "Codice paese non valido", "Troppo corto", "Troppo lungo", "Numero non valido"],
    "br" : ["Número inválido", "Código de país inválido", "Muito curto", "Muito longo", "Número inválido"],
    "be" : ["Numéro non valide", "Code pays non valide", "Très courte", "Trop long", "Numéro non valide"],
    "gb" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "ae" : ["اسم غير صالح", "رمز البلد غير صالح", "قصير جدا", "مستقيم جدًا", "اسم غير صالح"],
    "pl" : ["Nieprawidłowy numer", "Nieprawidłowy kod kraju", "Zbyt krótki", "Zbyt długi", "Nieprawidłowy numer"],
    "mu" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "ch" : ["Ungültige Nummer", "Ungültige Landesvorwahl", "Sehr kurz", "Zu lang", "Ungültige Nummer"],
    "za" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
    "sg" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
  	"gr" : ["Μη έγκυρος αριθμός", "Μη έγκυρος κωδικός χώρας", "Πολύ σύντομος", "Πολύ μεγάλος", "Μη έγκυρος αριθμός"],
  	"in" : ["Invalid number", "Invalid country code", "Very short", "Too long", "Invalid number"],
  	"cz" : ["Neplatné číslo", "Neplatný kód země", "Velmi krátké", "Příliš dlouhé", "Neplatné číslo"],
  	"de" : ["Ungültige Nummer", "Ungültige Landesvorwahl", "Sehr kurz", "Zu lang", "Ungültige Nummer"],
  	"at" : ["Ungültige Nummer", "Ungültige Landesvorwahl", "Sehr kurz", "Zu lang", "Ungültige Nummer"],
};

const agreementMessage = {
    "default": ["You must agree to the terms and conditions!"],
    "fr": ["Vous devez accepter les conditions!"],
    "mx": ["Debes aceptar los términos y condiciones!"],
    "ca": ["You must agree to the terms and conditions!"],
    "au": ["You must agree to the terms and conditions!"],
    "hk": ["You must agree to the terms and conditions!"],
    "es": ["Debes aceptar las condiciones!"],
    "ec": ["Debes aceptar los términos y condiciones!"],
    "cl": ["Debes aceptar los términos y condiciones!"],
    "ch": ["Sie müssen den Bedingungen zustimmen!"],
    "tr": ["Şartları kabul etmelisiniz!"],
    "fi": ["Sinun pitää hyväksyä ehdot!"],
    "sv": ["Du måste godkänna villkoren!"],
    "sk": ["Musíte súhlasiť so zmluvnými podmienkami!"],
    "pt": ["É preciso concordar com os termos e condições!"],
    "ph": ["Kailangan mong tanggapin ang mga termino at konditon!"],
    "kr": ["조건에 동의해야 합니다!"],
    "jp": ["条件に同意する必要があります！"],
    "dk": ["Du skal give samtykke til vilkårene!"],
    "co": ["Debes aceptar los términos y condiciones!"],
    "ar": ["يجب قبول الشروط والأحكام!"],
    "th": ["คุณต้องรับรายละเอียดนี้!"],
    "pe": ["Debes aceptar los términos y condiciones!"],
    "nz": ["You must agree to the terms and conditions!"],
    "my": ["You must agree to the terms and conditions!"],
    "tw": ["您必須接受條款和條件！"],
    "se": ["Du måste godkänna villkoren!"],
    "nl": ["U moet instemmen met de voorwaarden!"],
    "it": ["Devi accettare le condizioni!"],
    "br": ["Você precisa aceitar os termos e condições!"],
    "be": ["Vous devez accepter les conditions!"],
    "gb": ["You must agree to the terms and conditions!"],
    "ae": ["من الضروري الموافقة على الشروط والأحكام!"],
    "pl": ["Należy wyrazić zgodę na warunki!"],
    "mu": ["You must agree to the terms and conditions!"],
    "za": ["You must agree to the terms and conditions!"],
    "sg": ["You must agree to the terms and conditions!"],
    "gr": ["Πρέπει να συμφωνήσετε με τους όρους και τους όρους παραγγελίας!"],
    "in": ["You must agree to the terms and conditions!"],
    "cz": ["Je nutné souhlasit se závazky!"],
    "de": ["Sie müssen den Bedingungen zustimmen!"],
    "at": ["Sie müssen den Bedingungen zustimmen!"]
};


function addFingerprint(containerForm){
  const fpPromise = import('./v4.js')
    .then(FingerprintJS => FingerprintJS.load())

  fpPromise
    .then(fp => fp.get())
    .then(result => {
      const visitorId = result.visitorId
      if(visitorId){
        console.log(visitorId);
        const inputHidden = document.createElement("input");
        inputHidden.type = "hidden";
        inputHidden.name = "aff_sub13";
        inputHidden.value = visitorId;
        console.log(inputHidden);
        containerForm.appendChild(inputHidden);
      }
    })
}


const inputs = [...document.querySelectorAll("#phone")];

inputs.forEach(input => {
    const containerForm = input.closest("form");
    const button = containerForm.querySelector("#buttonSbmt");
    const errorMsg = containerForm.querySelector("#error-msg");
    const validMsg = containerForm.querySelector("#valid-msg");



    let isValidFN = true;
    let isValidLN = true;
    let isValidSM = true;
    let isValidCB = true;

function toValidateInputs(){
  const inputs = containerForm.querySelectorAll('input');
  inputs.forEach(input => {
      input.classList.remove('error-input');
  });
  const firstName = containerForm.querySelector('[name="first_name"]');
  const lastName = containerForm.querySelector('[name="last_name"]');
  const sendingMail = containerForm.querySelector('[name="sendingmail"]');
  const checkbox = containerForm.querySelector('#agreementCheckbox');
  
  firstName.value.trim();
  lastName.value.trim();
  sendingMail.value.trim();
  
 const emailPattern = /^(\w+|[\w+\-\.\w+]*\w)+@(\w+|[\w+\-\w+]*\w)+([\.a-zA-z])*\.[a-z]{2,6}/;
 
  if ( firstName.value.trim() === '') {
    event.preventDefault();
      firstName.value.trim();
      firstName.classList.add('error-input');
      const closestHolder = firstName.closest('.intgrtn-input-holder');
      if (closestHolder) {
          const errorEl = closestHolder.querySelector('.intgrtn-input-message-error');
          if (errorEl) {
              errorEl.style.display = "block";
          }
      }
      isValidFN = false;
  }else {isValidFN = true;}
  
  if (lastName.value.trim() === '') {
    event.preventDefault();
      lastName.value.trim();
      lastName.classList.add('error-input');
      const closestHolder = lastName.closest('.intgrtn-input-holder');
      if (closestHolder) {
          const errorEl = closestHolder.querySelector('.intgrtn-input-message-error');
          if (errorEl) {
              errorEl.style.display = "block";
          }
      }
      isValidLN = false;
  }else {isValidLN = true;}
  
  if (!emailPattern.test(sendingMail.value) || sendingMail.value.trim() === '') {
    event.preventDefault();
      sendingMail.value.trim();
      sendingMail.classList.add('error-input');
      const closestHolder = sendingMail.closest('.intgrtn-input-holder');
      if (closestHolder) {
          const errorEl = closestHolder.querySelector('.intgrtn-input-message-error');
          if (errorEl) {
              errorEl.style.display = "block";
          }
      }
      isValidSM = false;
  }else {isValidSM = true;};
  
  if (checkbox) {
    const existingError = document.querySelector("#msgErrCheckbox");
        if (existingError) {
            existingError.remove();
        }

        if (!checkbox.checked) {
            event.preventDefault();
            const msgErrCheckbox = document.createElement("div");
            msgErrCheckbox.id = "msgErrCheckbox";
            msgErrCheckbox.style.display = "block";
            msgErrCheckbox.textContent = agreementMessage[_countryCode] || agreementMessage["default"];
            msgErrCheckbox.style.color = "red";
            msgErrCheckbox.style.fontSize = "15px";
            msgErrCheckbox.style.marginTop = "10px";
            msgErrCheckbox.style.marginBottom= "10px";
            msgErrCheckbox.style.paddingLeft = "1em";
            msgErrCheckbox.style.clear = "both";
            checkbox.style.border = "red";
           
            button.insertAdjacentElement('beforebegin', msgErrCheckbox);


            isValidCB = false;
        } else { isValidCB = true; }
    }


  if (isValidFN && isValidSM && isValidLN && isValidCB){
    return true;
  }
  
}
    


       // initialise plugin
       const iti = window.intlTelInput(input, {
        initialCountry: _countryCode,
        onlyCountries: [_countryCode],
        autoFormat: true,
        autoPlaceholder: "aggressive",
        hiddenInput: () => ({ phone: "full_phone", country: "country_code" }),
        separateDialCode: true,
        showSelectedDialCode: true,
        utilsScript: "../../build/js/utils.js",
        allowLandline: true
      });
      
        
        const reset = () => {
            input.classList.remove("error");
            errorMsg.innerHTML = "";
            errorMsg.classList.add("hide");
            validMsg.classList.add("hide");
        };
        
        const showError = (msg) => {
            input.classList.add("error");
            errorMsg.innerHTML = msg;
            errorMsg.classList.remove("hide");
        };
        
        // on click button: validate
        button.addEventListener('click', () => {
            reset();
            
            const countryData = iti.getSelectedCountryData();
             console.log(toValidateInputs())
            const dialCode = countryData.dialCode;
            document.querySelector("#dial_code").value = dialCode;
            let errorsForCountry = errorMap.hasOwnProperty(_countryCode) ? errorMap[_countryCode] : errorMap['default'];

            if (!input.value.trim()) {
                event.preventDefault();
                showError(errorsForCountry[0]);
            
            } else if (countryData.iso2 !== _countryCode) {
            event.preventDefault();
            showError(errorsForCountry[1]);
            
            } else if (iti.isValidNumber()) {
              validMsg.classList.remove("hide");
               const isvalid = toValidateInputs();
                if(isvalid){
                  loaderHolder(loaderMessage[_countryCode], containerForm);
                }
            } else {
        
            event.preventDefault();
            const errorCode = iti.getValidationError();
            const msg = errorsForCountry[errorCode] || errorsForCountry[0];
            showError(msg);
            }
        });

        input.addEventListener('change', reset);
        input.addEventListener('keyup', reset);
});


  
    inputs.forEach(input => {
        const containerForm = input.closest("form");
          addFingerprint(containerForm);
          
    });


});