if (
    $('#mobile').length
    || $('#tel').length
    || $('#register-shipping_address-tel').length
    || $('#register-shipping_address-mobil').length
) {
    var icon_whatsApp = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-whatsapp mr-2 me-2" viewBox="0 0 16 16"><path d="M13.601 2.326A7.854 7.854 0 0 0 7.994 0C3.627 0 .068 3.558.064 7.926c0 1.399.366 2.76 1.057 3.965L0 16l4.204-1.102a7.933 7.933 0 0 0 3.79.965h.004c4.368 0 7.926-3.558 7.93-7.93A7.898 7.898 0 0 0 13.6 2.326zM7.994 14.521a6.573 6.573 0 0 1-3.356-.92l-.24-.144-2.494.654.666-2.433-.156-.251a6.56 6.56 0 0 1-1.007-3.505c0-3.626 2.957-6.584 6.591-6.584a6.56 6.56 0 0 1 4.66 1.931 6.557 6.557 0 0 1 1.928 4.66c-.004 3.639-2.961 6.592-6.592 6.592zm3.615-4.934c-.197-.099-1.17-.578-1.353-.646-.182-.065-.315-.099-.445.099-.133.197-.513.646-.627.775-.114.133-.232.148-.43.05-.197-.1-.836-.308-1.592-.985-.59-.525-.985-1.175-1.103-1.372-.114-.198-.011-.304.088-.403.087-.088.197-.232.296-.346.1-.114.133-.198.198-.33.065-.134.034-.248-.015-.347-.05-.099-.445-1.076-.612-1.47-.16-.389-.323-.335-.445-.34-.114-.007-.247-.007-.38-.007a.729.729 0 0 0-.529.247c-.182.198-.691.677-.691 1.654 0 .977.71 1.916.81 2.049.098.133 1.394 2.132 3.383 2.992.47.205.84.326 1.129.418.475.152.904.129 1.246.08.38-.058 1.171-.48 1.338-.943.164-.464.164-.86.114-.943-.049-.084-.182-.133-.38-.232z"/></svg>';

    var icon_mobile = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-phone mr-2 me-2" viewBox="0 0 16 16"><path d="M11 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h6zM5 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H5z"/><path d="M8 14a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/></svg>';

    var icon_phone = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-telephone mr-2 me-2" viewBox="0 0 16 16"><path d="M3.654 1.328a.678.678 0 0 0-1.015-.063L1.605 2.3c-.483.484-.661 1.169-.45 1.77a17.568 17.568 0 0 0 4.168 6.608 17.569 17.569 0 0 0 6.608 4.168c.601.211 1.286.033 1.77-.45l1.034-1.034a.678.678 0 0 0-.063-1.015l-2.307-1.794a.678.678 0 0 0-.58-.122l-2.19.547a1.745 1.745 0 0 1-1.657-.459L5.482 8.062a1.745 1.745 0 0 1-.46-1.657l.548-2.19a.678.678 0 0 0-.122-.58L3.654 1.328zM1.884.511a1.745 1.745 0 0 1 2.612.163L6.29 2.98c.329.423.445.974.315 1.494l-.547 2.19a.678.678 0 0 0 .178.643l2.457 2.457a.678.678 0 0 0 .644.178l2.189-.547a1.745 1.745 0 0 1 1.494.315l2.306 1.794c.829.645.905 1.87.163 2.611l-1.034 1.034c-.74.74-1.846 1.065-2.877.702a18.634 18.634 0 0 1-7.01-4.42 18.634 18.634 0 0 1-4.42-7.009c-.362-1.03-.037-2.137.703-2.877L1.885.511z"/></svg>';


    var dropDownData = [
        {isoCode: "af", iName: "Afghanistan (&#x202B;افغانستان&#x202C;&lrm;)", ext: "+93"},
        {isoCode: "al", iName: "Albania (Shqipëri)", ext: "+355"},
        {isoCode: "dz", iName: "Algeria (&#x202B;الجزائر&#x202C;&lrm;)", ext: "+213"},
        {isoCode: "as", iName: "American Samoa", ext: "+1"},
        {isoCode: "ad", iName: "Andorra", ext: "+376"},
        {isoCode: "ao", iName: "Angola", ext: "+244"},
        {isoCode: "ai", iName: "Anguilla", ext: "+1"},
        {isoCode: "ag", iName: "Antigua and Barbuda", ext: "+1"},
        {isoCode: "ar", iName: "Argentina", ext: "+54"},
        {isoCode: "am", iName: "Armenia (Հայաստան)", ext: "+374"},
        {isoCode: "aw", iName: "Aruba", ext: "+297"},
        {isoCode: "au", iName: "Australia", ext: "+61"},
        {isoCode: "at", iName: "Austria (Österreich)", ext: "+43"},
        {isoCode: "az", iName: "Azerbaijan (Azərbaycan)", ext: "+994"},
        {isoCode: "bs", iName: "Bahamas", ext: "+1"},
        {isoCode: "bh", iName: "Bahrain (&#x202B;البحرين&#x202C;&lrm;)", ext: "+973"},
        {isoCode: "bd", iName: "Bangladesh (বাংলাদেশ)", ext: "+880"},
        {isoCode: "bb", iName: "Barbados", ext: "+1"},
        {isoCode: "by", iName: "Belarus (Беларусь)", ext: "+375"},
        {isoCode: "be", iName: "Belgium (België)", ext: "+32"},
        {isoCode: "bz", iName: "Belize", ext: "+501"},
        {isoCode: "bj", iName: "Benin (Bénin)", ext: "+229"},
        {isoCode: "bm", iName: "Bermuda", ext: "+1"},
        {isoCode: "bt", iName: "Bhutan (འབྲུག)", ext: "+975"},
        {isoCode: "bo", iName: "Bolivia", ext: "+591"},
        {isoCode: "ba", iName: "Bosnia and Herzegovina (Босна и Херцеговина)", ext: "+387"},
        {isoCode: "bw", iName: "Botswana", ext: "+267"},
        {isoCode: "br", iName: "Brazil (Brasil)", ext: "+55"},
        {isoCode: "io", iName: "British Indian Ocean Territory", ext: "+246"},
        {isoCode: "vg", iName: "British Virgin Islands", ext: "+1"},
        {isoCode: "bn", iName: "Brunei", ext: "+673"},
        {isoCode: "bg", iName: "Bulgaria (България)", ext: "+359"},
        {isoCode: "bf", iName: "Burkina Faso", ext: "+226"},
        {isoCode: "bi", iName: "Burundi (Uburundi)", ext: "+257"},
        {isoCode: "kh", iName: "Cambodia (កម្ពុជា)", ext: "+855"},
        {isoCode: "cm", iName: "Cameroon (Cameroun)", ext: "+237"},
        {isoCode: "ca", iName: "Canada", ext: "+1"},
        {isoCode: "cv", iName: "Cape Verde (Kabu Verdi)", ext: "+238"},
        {isoCode: "bq", iName: "Caribbean Netherlands", ext: "+599"},
        {isoCode: "ky", iName: "Cayman Islands", ext: "+1"},
        {isoCode: "cf", iName: "Central African Republic (République centrafricaine)", ext: "+236"},
        {isoCode: "td", iName: "Chad (Tchad)", ext: "+235"},
        {isoCode: "cl", iName: "Chile", ext: "+56"},
        {isoCode: "cn", iName: "China (中国)", ext: "+86"},
        {isoCode: "cx", iName: "Christmas Island", ext: "+61"},
        {isoCode: "cc", iName: "Cocos (Keeling) Islands", ext: "+61"},
        {isoCode: "co", iName: "Colombia", ext: "+57"},
        {isoCode: "km", iName: "Comoros (&#x202B;جزر القمر&#x202C;&lrm;)", ext: "+269"},
        {isoCode: "cd", iName: "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", ext: "+243"},
        {isoCode: "cg", iName: "Congo (Republic) (Congo-Brazzaville)", ext: "+242"},
        {isoCode: "ck", iName: "Cook Islands", ext: "+682"},
        {isoCode: "cr", iName: "Costa Rica", ext: "+506"},
        {isoCode: "ci", iName: "Côte d'Ivoire", ext: "+225"},
        {isoCode: "hr", iName: "Croatia (Hrvatska)", ext: "+385"},
        {isoCode: "cu", iName: "Cuba", ext: "+53"},
        {isoCode: "cw", iName: "Curaçao", ext: "+599"},
        {isoCode: "cy", iName: "Cyprus (Κύπρος)", ext: "+357"},
        {isoCode: "cz", iName: "Czech Republic (Česká republika)", ext: "+420"},
        {isoCode: "dk", iName: "Denmark (Danmark)", ext: "+45"},
        {isoCode: "dj", iName: "Djibouti", ext: "+253"},
        {isoCode: "dm", iName: "Dominica", ext: "+1"},
        {isoCode: "do", iName: "Dominican Republic (República Dominicana)", ext: "+1"},
        {isoCode: "ec", iName: "Ecuador", ext: "+593"},
        {isoCode: "eg", iName: "Egypt (&#x202B;مصر&#x202C;&lrm;)", ext: "+20"},
        {isoCode: "sv", iName: "El Salvador", ext: "+503"},
        {isoCode: "gq", iName: "Equatorial Guinea (Guinea Ecuatorial)", ext: "+240"},
        {isoCode: "er", iName: "Eritrea", ext: "+291"},
        {isoCode: "ee", iName: "Estonia (Eesti)", ext: "+372"},
        {isoCode: "et", iName: "Ethiopia", ext: "+251"},
        {isoCode: "fk", iName: "Falkland Islands (Islas Malvinas)", ext: "+500"},
        {isoCode: "fo", iName: "Faroe Islands (Føroyar)", ext: "+298"},
        {isoCode: "fj", iName: "Fiji", ext: "+679"},
        {isoCode: "fi", iName: "Finland (Suomi)", ext: "+358"},
        {isoCode: "fr", iName: "France", ext: "+33"},
        {isoCode: "gf", iName: "French Guiana (Guyane française)", ext: "+594"},
        {isoCode: "pf", iName: "French Polynesia (Polynésie française)", ext: "+689"},
        {isoCode: "ga", iName: "Gabon", ext: "+241"},
        {isoCode: "gm", iName: "Gambia", ext: "+220"},
        {isoCode: "ge", iName: "Georgia (საქართველო)", ext: "+995"},
        {isoCode: "de", iName: "Germany (Deutschland)", ext: "+49"},
        {isoCode: "gh", iName: "Ghana (Gaana)", ext: "+233"},
        {isoCode: "gi", iName: "Gibraltar", ext: "+350"},
        {isoCode: "gr", iName: "Greece (Ελλάδα)", ext: "+30"},
        {isoCode: "gl", iName: "Greenland (Kalaallit Nunaat)", ext: "+299"},
        {isoCode: "gd", iName: "Grenada", ext: "+1"},
        {isoCode: "gp", iName: "Guadeloupe", ext: "+590"},
        {isoCode: "gu", iName: "Guam", ext: "+1"},
        {isoCode: "gt", iName: "Guatemala", ext: "+502"},
        {isoCode: "gg", iName: "Guernsey", ext: "+44"},
        {isoCode: "gn", iName: "Guinea (Guinée)", ext: "+224"},
        {isoCode: "gw", iName: "Guinea-Bissau (Guiné Bissau)", ext: "+245"},
        {isoCode: "gy", iName: "Guyana", ext: "+592"},
        {isoCode: "ht", iName: "Haiti", ext: "+509"},
        {isoCode: "hn", iName: "Honduras", ext: "+504"},
        {isoCode: "hk", iName: "Hong Kong (香港)", ext: "+852"},
        {isoCode: "hu", iName: "Hungary (Magyarország)", ext: "+36"},
        {isoCode: "is", iName: "Iceland (Ísland)", ext: "+354"},
        {isoCode: "in", iName: "India (भारत)", ext: "+91"},
        {isoCode: "id", iName: "Indonesia", ext: "+62"},
        {isoCode: "ir", iName: "Iran (&#x202B;ایران&#x202C;&lrm;)", ext: "+98"},
        {isoCode: "iq", iName: "Iraq (&#x202B;العراق&#x202C;&lrm;)", ext: "+964"},
        {isoCode: "ie", iName: "Ireland", ext: "+353"},
        {isoCode: "im", iName: "Isle of Man", ext: "+44"},
        {isoCode: "il", iName: "Israel (&#x202B;ישראל&#x202C;&lrm;)", ext: "+972"},
        {isoCode: "it", iName: "Italy (Italia)", ext: "+39"},
        {isoCode: "jm", iName: "Jamaica", ext: "+1"},
        {isoCode: "jp", iName: "Japan (日本)", ext: "+81"},
        {isoCode: "je", iName: "Jersey", ext: "+44"},
        {isoCode: "jo", iName: "Jordan (&#x202B;الأردن&#x202C;&lrm;)", ext: "+962"},
        {isoCode: "kz", iName: "Kazakhstan (Казахстан)", ext: "+7"},
        {isoCode: "ke", iName: "Kenya", ext: "+254"},
        {isoCode: "ki", iName: "Kiribati", ext: "+686"},
        {isoCode: "xk", iName: "Kosovo", ext: "+383"},
        {isoCode: "kw", iName: "Kuwait (&#x202B;الكويت&#x202C;&lrm;)", ext: "+965"},
        {isoCode: "kg", iName: "Kyrgyzstan (Кыргызстан)", ext: "+996"},
        {isoCode: "la", iName: "Laos (ລາວ)", ext: "+856"},
        {isoCode: "lv", iName: "Latvia (Latvija)", ext: "+371"},
        {isoCode: "lb", iName: "Lebanon (&#x202B;لبنان&#x202C;&lrm;)", ext: "+961"},
        {isoCode: "ls", iName: "Lesotho", ext: "+266"},
        {isoCode: "lr", iName: "Liberia", ext: "+231"},
        {isoCode: "ly", iName: "Libya (&#x202B;ليبيا&#x202C;&lrm;)", ext: "+218"},
        {isoCode: "li", iName: "Liechtenstein", ext: "+423"},
        {isoCode: "lt", iName: "Lithuania (Lietuva)", ext: "+370"},
        {isoCode: "lu", iName: "Luxembourg", ext: "+352"},
        {isoCode: "mo", iName: "Macau (澳門)", ext: "+853"},
        {isoCode: "mk", iName: "Macedonia (FYROM) (Македонија)", ext: "+389"},
        {isoCode: "mg", iName: "Madagascar (Madagasikara)", ext: "+261"},
        {isoCode: "mw", iName: "Malawi", ext: "+265"},
        {isoCode: "my", iName: "Malaysia", ext: "+60"},
        {isoCode: "mv", iName: "Maldives", ext: "+960"},
        {isoCode: "ml", iName: "Mali", ext: "+223"},
        {isoCode: "mt", iName: "Malta", ext: "+356"},
        {isoCode: "mh", iName: "Marshall Islands", ext: "+692"},
        {isoCode: "mq", iName: "Martinique", ext: "+596"},
        {isoCode: "mr", iName: "Mauritania (&#x202B;موريتانيا&#x202C;&lrm;)", ext: "+222"},
        {isoCode: "mu", iName: "Mauritius (Moris)", ext: "+230"},
        {isoCode: "yt", iName: "Mayotte", ext: "+262"},
        {isoCode: "mx", iName: "Mexico (México)", ext: "+52"},
        {isoCode: "fm", iName: "Micronesia", ext: "+691"},
        {isoCode: "md", iName: "Moldova (Republica Moldova)", ext: "+373"},
        {isoCode: "mc", iName: "Monaco", ext: "+377"},
        {isoCode: "mn", iName: "Mongolia (Монгол)", ext: "+976"},
        {isoCode: "me", iName: "Montenegro (Crna Gora)", ext: "+382"},
        {isoCode: "ms", iName: "Montserrat", ext: "+1"},
        {isoCode: "ma", iName: "Morocco (&#x202B;المغرب&#x202C;&lrm;)", ext: "+212"},
        {isoCode: "mz", iName: "Mozambique (Moçambique)", ext: "+258"},
        {isoCode: "mm", iName: "Myanmar (Burma) (မြန်မာ)", ext: "+95"},
        {isoCode: "na", iName: "Namibia (Namibië)", ext: "+264"},
        {isoCode: "nr", iName: "Nauru", ext: "+674"},
        {isoCode: "np", iName: "Nepal (नेपाल)", ext: "+977"},
        {isoCode: "nl", iName: "Netherlands (Nederland)", ext: "+31"},
        {isoCode: "nc", iName: "New Caledonia (Nouvelle-Calédonie)", ext: "+687"},
        {isoCode: "nz", iName: "New Zealand", ext: "+64"},
        {isoCode: "ni", iName: "Nicaragua", ext: "+505"},
        {isoCode: "ne", iName: "Niger (Nijar)", ext: "+227"},
        {isoCode: "ng", iName: "Nigeria", ext: "+234"},
        {isoCode: "nu", iName: "Niue", ext: "+683"},
        {isoCode: "nf", iName: "Norfolk Island", ext: "+672"},
        {isoCode: "kp", iName: "North Korea (조선 민주주의 인민 공화국)", ext: "+850"},
        {isoCode: "mp", iName: "Northern Mariana Islands", ext: "+1"},
        {isoCode: "no", iName: "Norway (Norge)", ext: "+47"},
        {isoCode: "om", iName: "Oman (&#x202B;عُمان&#x202C;&lrm;)", ext: "+968"},
        {isoCode: "pk", iName: "Pakistan (&#x202B;پاکستان&#x202C;&lrm;)", ext: "+92"},
        {isoCode: "pw", iName: "Palau", ext: "+680"},
        {isoCode: "ps", iName: "Palestine (&#x202B;فلسطين&#x202C;&lrm;)", ext: "+970"},
        {isoCode: "pa", iName: "Panama (Panamá)", ext: "+507"},
        {isoCode: "pg", iName: "Papua New Guinea", ext: "+675"},
        {isoCode: "py", iName: "Paraguay", ext: "+595"},
        {isoCode: "pe", iName: "Peru (Perú)", ext: "+51"},
        {isoCode: "ph", iName: "Philippines", ext: "+63"},
        {isoCode: "pl", iName: "Poland (Polska)", ext: "+48"},
        {isoCode: "pt", iName: "Portugal", ext: "+351"},
        {isoCode: "pr", iName: "Puerto Rico", ext: "+1"},
        {isoCode: "qa", iName: "Qatar (&#x202B;قطر&#x202C;&lrm;)", ext: "+974"},
        {isoCode: "re", iName: "Réunion (La Réunion)", ext: "+262"},
        {isoCode: "ro", iName: "Romania (România)", ext: "+40"},
        {isoCode: "ru", iName: "Russia (Россия)", ext: "+7"},
        {isoCode: "rw", iName: "Rwanda", ext: "+250"},
        {isoCode: "bl", iName: "Saint Barthélemy", ext: "+590"},
        {isoCode: "sh", iName: "Saint Helena", ext: "+290"},
        {isoCode: "kn", iName: "Saint Kitts and Nevis", ext: "+1"},
        {isoCode: "lc", iName: "Saint Lucia", ext: "+1"},
        {isoCode: "mf", iName: "Saint Martin (Saint-Martin (partie française))", ext: "+590"},
        {isoCode: "pm", iName: "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", ext: "+508"},
        {isoCode: "vc", iName: "Saint Vincent and the Grenadines", ext: "+1"},
        {isoCode: "ws", iName: "Samoa", ext: "+685"},
        {isoCode: "sm", iName: "San Marino", ext: "+378"},
        {isoCode: "st", iName: "São Tomé and Príncipe (São Tomé e Príncipe)", ext: "+239"},
        {isoCode: "sa", iName: "Saudi Arabia (&#x202B;المملكة العربية السعودية&#x202C;&lrm;)", ext: "+966"},
        {isoCode: "sn", iName: "Senegal (Sénégal)", ext: "+221"},
        {isoCode: "rs", iName: "Serbia (Србија)", ext: "+381"},
        {isoCode: "sc", iName: "Seychelles", ext: "+248"},
        {isoCode: "sl", iName: "Sierra Leone", ext: "+232"},
        {isoCode: "sg", iName: "Singapore", ext: "+65"},
        {isoCode: "sx", iName: "Sint Maarten", ext: "+1"},
        {isoCode: "sk", iName: "Slovakia (Slovensko)", ext: "+421"},
        {isoCode: "si", iName: "Slovenia (Slovenija)", ext: "+386"},
        {isoCode: "sb", iName: "Solomon Islands", ext: "+677"},
        {isoCode: "so", iName: "Somalia (Soomaaliya)", ext: "+252"},
        {isoCode: "za", iName: "South Africa", ext: "+27"},
        {isoCode: "kr", iName: "South Korea (대한민국)", ext: "+82"},
        {isoCode: "ss", iName: "South Sudan (&#x202B;جنوب السودان&#x202C;&lrm;)", ext: "+211"},
        {isoCode: "es", iName: "Spain (España)", ext: "+34"},
        {isoCode: "lk", iName: "Sri Lanka (ශ්&zwj;රී ලංකාව)", ext: "+94"},
        {isoCode: "sd", iName: "Sudan (&#x202B;السودان&#x202C;&lrm;)", ext: "+249"},
        {isoCode: "sr", iName: "Suriname", ext: "+597"},
        {isoCode: "sj", iName: "Svalbard and Jan Mayen", ext: "+47"},
        {isoCode: "sz", iName: "Swaziland", ext: "+268"},
        {isoCode: "se", iName: "Sweden (Sverige)", ext: "+46"},
        {isoCode: "ch", iName: "Switzerland (Schweiz)", ext: "+41"},
        {isoCode: "sy", iName: "Syria (&#x202B;سوريا&#x202C;&lrm;)", ext: "+963"},
        {isoCode: "tw", iName: "Taiwan (台灣)", ext: "+886"},
        {isoCode: "tj", iName: "Tajikistan", ext: "+992"},
        {isoCode: "tz", iName: "Tanzania", ext: "+255"},
        {isoCode: "th", iName: "Thailand (ไทย)", ext: "+66"},
        {isoCode: "tl", iName: "Timor-Leste", ext: "+670"},
        {isoCode: "tg", iName: "Togo", ext: "+228"},
        {isoCode: "tk", iName: "Tokelau", ext: "+690"},
        {isoCode: "to", iName: "Tonga", ext: "+676"},
        {isoCode: "tt", iName: "Trinidad and Tobago", ext: "+1"},
        {isoCode: "tn", iName: "Tunisia (&#x202B;تونس&#x202C;&lrm;)", ext: "+216"},
        {isoCode: "tr", iName: "Turkey (Türkiye)", ext: "+90"},
        {isoCode: "tm", iName: "Turkmenistan", ext: "+993"},
        {isoCode: "tc", iName: "Turks and Caicos Islands", ext: "+1"},
        {isoCode: "tv", iName: "Tuvalu", ext: "+688"},
        {isoCode: "vi", iName: "U.S. Virgin Islands", ext: "+1"},
        {isoCode: "ug", iName: "Uganda", ext: "+256"},
        {isoCode: "ua", iName: "Ukraine (Україна)", ext: "+380"},
        {isoCode: "ae", iName: "United Arab Emirates (&#x202B;الإمارات العربية المتحدة&#x202C;&lrm;)", ext: "+971"},
        {isoCode: "gb", iName: "United Kingdom", ext: "+44"},
        {isoCode: "us", iName: "United States", ext: "+1"},
        {isoCode: "uy", iName: "Uruguay", ext: "+598"},
        {isoCode: "uz", iName: "Uzbekistan (Oʻzbekiston)", ext: "+998"},
        {isoCode: "vu", iName: "Vanuatu", ext: "+678"},
        {isoCode: "va", iName: "Vatican City (Città del Vaticano)", ext: "+39"},
        {isoCode: "ve", iName: "Venezuela", ext: "+58"},
        {isoCode: "vn", iName: "Vietnam (Việt Nam)", ext: "+84"},
        {isoCode: "wf", iName: "Wallis and Futuna (Wallis-et-Futuna)", ext: "+681"},
        {isoCode: "eh", iName: "Western Sahara (&#x202B;الصحراء الغربية&#x202C;&lrm;)", ext: "+212"},
        {isoCode: "ye", iName: "Yemen (&#x202B;اليمن&#x202C;&lrm;)", ext: "+967"},
        {isoCode: "zm", iName: "Zambia", ext: "+260"},
        {isoCode: "zw", iName: "Zimbabwe", ext: "+263"},
        {isoCode: "ax", iName: "Åland Islands", ext: "+358"}
    ];

    $(function () {
        function formatPhoneNumber(input)
        {
            if (input.val().substring(0, 2) === '00') {
                input.val('+' + input.val().substring(2));
            }
            // Remove leading zero from German numbers
            if (input.val().startsWith('+49')) {
                input.val(
                    input.val().replace(/\+49 ?[()0]+/, '+49 ')
                );
            }
        }

        // Verify that inputs are not empty and have the correct format
        $('input[name="tel"],'
            + 'input[name="mobil"],'
            + 'input[name="register[shipping_address][mobil]"],'
            + 'input[name="register[shipping_address][tel]"]').closest('form').on('submit', function () {
                let error  = false;
                let inputs = $(this).find(
                    'input[name="tel"],'
                    + 'input[name="mobil"],'
                    + 'input[name="register[shipping_address][mobil]"],'
                    + 'input[name="register[shipping_address][tel]"]'
                );
                inputs.each(function () {
                    if ($(this).length) {
                        if ($(this).val().length <= 4) {
                            $(this).val('');

                            return true;
                        }
                        formatPhoneNumber($(this));
                        if (pluginConfig["tnt_ip_phone_prefix"] === 'yes') {
                            if (!$(this).val().startsWith('+')) {
                                let title = pluginConfig['tnt_ip_lang_vars']['tnt_ip_error1_title']
                                    ?? 'Error: Missing dialling code',
                                msg       = pluginConfig['tnt_ip_lang_vars']['tnt_ip_error1_text']
                                    ?? 'Please, type in your international dialling code for the field';
                                eModal.alert({
                                    message: msg + ' ' + $(this).closest('form').find('label[for="'
                                    + $(this).attr('id')
                                    + '"]').html(),
                                title: title
                                });
                                $(this).focus();
                                $("button[type='submit']").removeAttr("disabled");
                                error = true;
                            }
                        }
                    }
                });
                if (error) {
                    return false;
                }

            });

        function initComponent(onElem, icon = "", elemName = null)
        {
            elemName = elemName ?? onElem.attr("name");
            var dd   = $("<div />", {
                class: "dropdown",
                id: "tnt_waapi_dd_" + elemName,
                attr: {
                    "data-reference": "parent",
                    "data-bs-reference": "parent"
                }
            });
            var dd_btn = $("<div />", {
                type: "button",
                class: "dropdown-toggle",
                id: "intCodePhone_" + elemName,
                html: "",
                attr: {
                    "data-toggle": "dropdown",
                    "aria-expanded": "false",
                    "data-bs-toggle": "dropdown"
                }
            });
            var dd_menu = $("<div />", {
                class: "dropdown-menu iti__country-list",
                attr: {
                    "aria-labelledby": "intCodePhone_" + elemName
                }
            });
            dd_btn.appendTo(dd);

            $.each(dropDownData, function (key, obj) {
                $("<a />", {
                    href: "#" + obj["isoCode"],
                    class: "dropdown-item",
                    html: "<span class='iti__flag iti__" + obj["isoCode"] + "'></span> " + obj["iName"] + " " + obj["ext"],
                    attr: {
                        "data-ext": obj["ext"]
                    },
                    on: {
                        click: function (e) {
                            e.preventDefault();
                            $("#intCodePhone_" + elemName).html("<span class='iti__flag iti__" + $(this).attr("href").substring(1) + "'></span>");
                            onElem.val($(this).attr("data-ext"));
                            onElem.focus();
                        }
                    }
                }).appendTo(dd_menu);
            });

            dd_menu.appendTo(dd);

            var inputGroup        = $("<div />", {
                class: "input-group mb-2"
            });
            var inputGroupPrepend = $("<div />", {
                class: "input-group-prepend"
            });
            var inputGroupText    = $("<div />", {
                class: "input-group-text",
                html: icon
            });
            // NOW CREATE SELECT AND APPEND TO TEXT.html ATTRIBUTE
            var container = onElem.parent();
            dd.appendTo(inputGroupText);
            inputGroupText.appendTo(inputGroupPrepend);
            inputGroupPrepend.appendTo(inputGroup);
            onElem.appendTo(inputGroup);
            inputGroup.appendTo(container);

            var act_search = "";
            var timeoutFunc;

            function selectInList(str)
            {
                var result = 0;
                $.each(dropDownData, function (key, obj) {
                    if (str === obj["iName"].substring(0, str.length).toLowerCase()) {
                        result = key;
                        return false;
                    }
                });
                if (result === 0) {
                    $.each(dropDownData, function (key, obj) {
                        if (obj["iName"].toLowerCase().includes(str)) {
                            result = key;
                            return false;
                        }
                    });
                }
                return result;
            }

            var searchForCode = function (e) {
                var code   = e.keyCode || e.which;
                code       = String.fromCharCode(code);
                act_search += code;
                clearTimeout(timeoutFunc);
                timeoutFunc = setTimeout(function () {
                    var listIndex  = selectInList(act_search.toLowerCase());
                    var activeElem = $("#tnt_waapi_dd_" + elemName + " .dropdown-menu a.dropdown-item").eq(listIndex),
                        container  = $("#tnt_waapi_dd_" + elemName + " .dropdown-menu");
                    activeElem.focus();
                    container.animate({
                        scrollTop: activeElem.offset().top - container.offset().top + container.scrollTop()
                    }, 500);
                    act_search = ""
                }, 500);
            };
            $("#tnt_waapi_dd_" + elemName).on("show.bs.dropdown", function () {
                $(document).bind("keypress", searchForCode);
            });
            $("#tnt_waapi_dd_" + elemName).on("hidden.bs.dropdown", function () {
                $(document).unbind("keypress", searchForCode);
            });
            /* PRESELECT */
            if (onElem.val() === '') {
                $("#tnt_waapi_dd_" + elemName + " .dropdown-menu a.dropdown-item[href='#"
                    + pluginConfig["tnt_ip_default"] + "']").trigger("click");
            } else {
                var value  = onElem.val();
                var result = "";
                if (value[0] === "+" && value.length > 1) {
                    $.each(dropDownData, function (key, obj) {
                        if (value.includes(obj["ext"])) {
                            result = obj["isoCode"];
                            return false;
                        }
                    });
                    if (result !== "") {
                        $("#intCodePhone_" + elemName).html("<span class='iti__flag iti__" + result + "'></span>");
                    }
                }
            }
            /* ON SMARTPHONES PEOPLE WILL OFTEN JUST TYPE THE CODE */
            onElem.on("keyup", function () {
                formatPhoneNumber($(this));
                var value  = $(this).val();
                var result = "";
                if (value[0] === "+" && value.length > 1) {
                    $.each(dropDownData, function (key, obj) {
                        if (value.includes(obj["ext"])) {
                            result = obj["isoCode"];
                            return false;
                        }
                    });
                    if (result !== "") {
                        $("#intCodePhone_" + elemName + " .iti__flag").attr("class", "iti__flag iti__" + result);
                    }
                }
            });
        }

        if ($("#tel").length) {
            if (pluginConfig["tnt_ip_phone_icon"] === "keinlogo") {
                initComponent($("#tel"));
            } else {
                initComponent($("#tel"), icon_phone);
            }
        }
        if ($("#register-shipping_address-tel").length) {
            if (pluginConfig["tnt_ip_phone_icon"] === "keinlogo") {
                initComponent($("#register-shipping_address-tel"), '', 'register-shipping_address-tel');
            } else {
                initComponent($("#register-shipping_address-tel"), icon_phone, 'register-shipping_address-tel');
            }
        }
        if ($("#mobile").length) {
            if (pluginConfig["tnt_ip_mobile_icon"] === "keinlogo") {
                initComponent($("#mobile"));
            } else if (pluginConfig["tnt_ip_mobile_icon"] === "whatsapp") {
                initComponent($("#mobile"), icon_whatsApp);
            } else {
                initComponent($("#mobile"), icon_mobile);
            }
        }
        if ($("#register-shipping_address-mobil").length) {
            if (pluginConfig["tnt_ip_mobile_icon"] === "keinlogo") {
                initComponent($("#register-shipping_address-mobil"), '', 'register-shipping_address-mobil');
            } else if (pluginConfig["tnt_ip_mobile_icon"] === "whatsapp") {
                initComponent($("#register-shipping_address-mobil"), icon_whatsApp, 'register-shipping_address-mobil');
            } else {
                initComponent($("#register-shipping_address-mobil"), icon_mobile, 'register-shipping_address-mobil');
            }
        }
    });
}
