function gradient(id, level) { var box = document.getElementById(id); box.style.opacity = level; box.style.MozOpacity = level; box.style.KhtmlOpacity = level; box.style.filter = "alpha(opacity=" + level * 100 + ")"; box.style.display = "block"; return; } function fadein(id) { var level = 0; while (level <= 1) { setTimeout("gradient('" + id + "'," + level + ")", (level * 300) + 10); level += 0.01; } } // Open the lightbox function openbox(formtitle, fadin, boxname) { document.getElementById("log_in_dropdown").style.display = "none"; var box = document.getElementById(boxname); document.getElementById('filter').style.display = 'block'; var btitle = document.getElementById('boxtitle'); btitle.innerHTML = formtitle; if (fadin) { gradient(boxname, 0); fadein(boxname); } else { box.style.display = 'block'; } } // Close the lightbox function closebox(boxname) { document.getElementById(boxname).style.display = 'none'; document.getElementById('filter').style.display = 'none'; } function openHomePage(type, obj) { var jqr = jQuery.noConflict(); if (type == "browse") { jqr("#browseArea").css('display', 'block'); jqr("#dv_home_dynamic").css('display', 'none'); jqr('.dv_home_rt_2 div').removeClass(); jqr(obj).addClass('dv_nav_active'); } else { jqr("#dv_home_dynamic").css('display', 'block'); jqr("#browseArea").css('display', 'none'); jqr("#dv_home_dynamic").html(""); jqr("#loadingIcon").css('display', 'block'); jqr('.dv_home_rt_2 div').removeClass(); jqr(obj).addClass('dv_nav_active'); url = jqr("#site_url").val(); var loadUrl = url + "/action.php?type=" + type; // alert(loadUrl); jqr.ajax({ url: loadUrl, method: 'POST', data: {"type": type}, success: function (data) { jqr("#loadingIcon").css('display', 'none'); jqr("#dv_home_dynamic").html(data); }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } } function openRegistrationPanel(div, id) { var jqr = jQuery.noConflict(); jqr(".rgspanel").css('display', 'none'); jqr("#" + div).css('display', 'block'); jqr(".editmenu").removeClass("rgsactive"); jqr("#" + id).addClass("rgsactive"); jqr([document.documentElement, document.body]).animate({ scrollTop: jqr("#" + id).offset().top }, 250); } function openPFPage(type, obj, userid) { var jqr = jQuery.noConflict(); jqr("#dv_home_dynamic").html(""); if (type == "about") { jqr("#dv_pf_fix").css('display', 'block'); jqr("#dv_pf_dynamic").html(""); jqr('.dv_home_rt_2 div').removeClass(); jqr(obj).addClass('dv_nav_active'); } else { jqr("#dv_pf_fix").css('display', 'none'); jqr("#loadingIcon").css('display', 'block'); jqr('.dv_home_rt_2 div').removeClass(); jqr(obj).addClass('dv_nav_active'); url = jqr("#site_url").val(); var loadUrl = url + "/action.php?type=" + type + '&user_id=' + userid; //alert(loadUrl); jqr.ajax({ url: loadUrl, method: 'POST', data: {"type": type}, success: function (data) { jqr("#loadingIcon").css('display', 'none'); jqr("#dv_pf_dynamic").html(data); }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } } function openUrl(url) { window.location.href = url; } function blockMe(user_id, isblock, reloadme) { var jqr = jQuery.noConflict(); url = jqr("#site_url").val(); var loadUrl = url + '/action.php'; //alert(loadUrl); var data = 'type=blockUser&user_id=' + user_id + '&isblock=' + isblock // alert(loadUrl+'type=blockUser&user_id='+user_id+'&isblock='+isblock); jqr.ajax({ url: loadUrl, method: 'POST', data: {"type": "blockUser", "user_id": user_id, "isblock": isblock}, success: function (data) { if (reloadme == 'yes') { window.location.reload(); } else { if (isblock == "yes") { alert('User has been blocked'); } else { alert('User has been unblocked'); } } }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } function displayAlert(msg) { alert(msg); } function updateOther(txtvalue, id) { var jqr = jQuery.noConflict(); jqr("#" + id).val(txtvalue); } function delMe(id) { var jqr = jQuery.noConflict(); jqr("#menurow" + id).remove(); } function delMeRight(id) { var jqr = jQuery.noConflict(); jqr("#menurowright" + id).remove(); } function addMore() { var jqr = jQuery.noConflict(); nextrow = parseInt(jqr('#lastrow').val()) + 1; var html = "Delete"; jqr("#addBeforeMe").before(html); jqr('#lastrow').val(nextrow); } var jqr = jQuery.noConflict(); document.addEventListener('click', function (event) { if (event.target.matches('.menu_right')) { jqr(".fadermenu").slideUp(); jqr("#fadermenu").slideToggle(); } else if (event.target.matches('.menu_left')) { jqr(".fadermenu").slideUp(); jqr("#fadermenuleft").slideToggle(); } else if (event.target.matches('.menubottom')) { jqr(".fadermenu").slideUp(); jqr("#fadermenubottom").slideToggle(); } else if (event.target.matches('.menumail')) { jqr(".fadermenu").slideUp(); jqr("#fadermenumail").slideToggle(); } else if (event.target.matches('.menuprofile')) { jqr(".fadermenu").slideUp(); jqr("#fadermenuprofile").slideToggle(); } else if (event.target.matches('.menuupgrade')) { jqr(".fadermenu").slideUp(); jqr("#fadermenuupgrade").slideToggle(); } else if (event.target.matches('.menueditprofile')) { jqr(".fadermenu").slideUp(); jqr("#fadermenueditprofile").slideToggle(); } else if (event.target.matches('.browse_menu')) { jqr(".fadermenu").slideUp(); jqr("#fadermenubrowse").slideToggle(); } else { jqr(".fadermenu").slideUp(); return; } // Don't follow the link event.preventDefault(); }, false); function closePrefPopup() { jqr("#fadermenubrowse").slideUp(); } function submitPagination(page, size) { jqr('#page').val(page); jqr('#shownum').val(size); showMoreResult(); //jqr('#search_pager_myForm').submit(); } function submitPaginationForm() { jqr("#shownum").val(jqr("#lstShownum").val()); jqr('#search_pager_myForm').submit(); } function addMoreRight() { var jqr = jQuery.noConflict(); nextrow = parseInt(jqr('#lastrowRight').val()) + 1; var html = "Delete"; jqr("#addBeforeMeRight").before(html); jqr('#lastrowRight').val(nextrow); } function closeCommentBox(box) { jqr('#' + box).css({'display': 'none'}); } function openGiftBox() { jqr('#QuickBoxGifts').css({'display': 'block'}); } function selectGift(img, thisobj) { jqr('.dv_gft').children('div').removeClass('selectme'); jqr(thisobj).children('div').addClass('selectme'); jqr('#giftId').val(img); } function sendGift() { url = jqr("#site_url").val(); var loadUrl = url + "/action.php?type=gift&action=send"; if (jqr('#giftId').val()) { jqr("#loading_img").css('display', 'block'); jqr.ajax({ url: loadUrl, method: 'POST', data: {"gift": jqr('#giftId').val(), "toUserId": jqr('#toUserId').val()}, success: function (data) { jqr("#loading_img").css('display', 'none'); alert("Gift sent successfully"); jqr('#QuickBoxGifts').css({'display': 'none'}); }, error: function (data) { alert(data.responseText); jqr("#loading_img").css('display', 'none'); } }); } else { alert('Please select a gift first.'); } } function delGift(id, page) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php?type=delGift"; //alert(loadUrl+'&id='+id); if (confirm('Are you sure to delete?')) { jqr("#loadingIcon").css('display', 'block'); jqr.ajax({ url: loadUrl, method: 'POST', data: {"id": id}, success: function (data) { jqr("#loadingIcon").css('display', 'none'); if (page == 'home') { openHomePage('gifts', this); } else { window.location.reload(); } }, error: function (data) { alert("Please try again."); jqr("#loadingIcon").css('display', 'none'); } }); } } function openRequest() { jqr('#reqFrm').submit(); } function displayNextPrf(cID, nID) { jqr("#prfProfile" + cID).remove(); jqr("#prfProfile" + nID).css('display', 'block'); } function saveInst(uid, cID, nID, interest) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php?type=saveInterest"; jqr.ajax({ url: loadUrl, method: 'POST', data: {"id": uid, "interest": interest}, success: function (data) { jqr("#prfProfile" + cID).remove(); jqr("#prfProfile" + nID).css('display', 'block'); }, error: function (data) { alert("Please try again."); jqr("#loadingIcon").css('display', 'none'); } }); } function changeSearchView(varclass, act) { jqr(".searchView").css('display', 'none'); jqr("." + varclass).css('display', 'block'); jqr(".schview").removeClass('activeview'); jqr('.' + act).addClass('activeview'); if (varclass == "listview") { jqr('#lstResultAs').val('list'); } else { jqr('#lstResultAs').val('gallery'); } } function processFunction(action, touser, touserId) { url = jqr("#site_url").val(); userId = jqr("#currentUserId").val(); if (action == "message") { window.location.href = url + '/send-mail/' + userId + '/' + touser; } else if (action == "addFriend") { addFriend(url, touserId); refreshDD('select_search_res_div', touserId); } else if (action == "addToFavorite") { window.open(url + '/hot-list/' + userId + '/' + touser, '', 'toolbar=no,menubar=no,height=150,width=200,left=' + (screen.width / 2 - 100) + ',top=' + (screen.height / 2 - 75) + ''); } else if (action == "sendFlirt") { window.location.href = url + '/send-flirt/' + userId + '/' + touser; } else if (action == "sendGift") { jqr('#toUserId').val(touserId); openGiftBox(); } else if (action == "report") { } else if (action == "block") { blockMe(touserId, 'yes', 'no'); refreshDD('select_search_res_div', touserId); } else if (action == "removeFriend") { removeFriend(url, touserId); refreshDD('select_search_res_div', touserId); } else if (action == "unblock") { blockMe(touserId, 'no', 'no'); refreshDD('select_search_res_div', touserId); } } function refreshDD(id, userid) { var loadUrl = url + "/action.php"; jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": userid, "type": "refreshDD"}, success: function (data) { jqr("#" + id + userid).html(data); }, error: function (data) { //alert("Please try again."); } }); } function addFriend(url, user_id) { var loadUrl = url + "/action.php"; jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": user_id, "type": "addFriend"}, success: function (data) { alert(data); }, error: function (data) { alert("Please try again."); } }); } function removeFriend(url, user_id) { var loadUrl = url + "/action.php"; jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": user_id, "type": "removeFriend"}, success: function (data) { alert(data); }, error: function (data) { alert("Please try again."); } }); } jqr(document).ready(function ($) { jqr(".search_result").mouseover(function () { meid = jqr(this).attr('id'); jqr("#more" + meid).css('display', 'block'); }); jqr(".search_result").mouseout(function () { meid = jqr(this).attr('id'); jqr("#more" + meid).css('display', 'none'); }); }); function viewGiftBox(touserId) { jqr('#toUserId').val(touserId); openGiftBox(); } function checkAllOpt(cls) { jqr('.chk-' + cls).prop('checked', true); } function uncheckkAllOpt(cls) { jqr('.chk-' + cls).prop('checked', false); } function showMoreResult() { url = jqr("#site_url").val(); var loadUrl = url + "/prgsearchpagination.php"; jqr("#loading_simg").css('display', 'inline'); jqr.ajax({ url: loadUrl, method: 'POST', data: jq('#search_pager_myForm').serialize(), success: function (data) { jqr(".searchpagination").remove(); // alert(data); jqr(".searchresult").append(data); scroll = jqr("#scroll").val() + 800; jqr("#scroll").val(scroll); jqr("#loading_simg").css('display', 'none'); jqr(".searchresult").scrollTop(scroll); }, error: function (data) { jqr("#loading_simg").css('display', 'none'); alert("Please try again."); } }); } function displayMembership(divid) { jqr(".dvupfull").css('display', 'none'); jqr(".dvuptoggleme").removeClass("dvuptogglactive"); jqr("#toggle" + divid).addClass("dvuptogglactive"); jqr("#div" + divid).css('display', 'block'); } function saveExpDate(uid) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php"; var date = jqr("#dd_year" + uid).val() + '-' + jqr("#dd_month" + uid).val() + '-' + jqr("#dd_day" + uid).val(); jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": uid, "type": "updateExpDate", "date": date}, success: function (data) { }, error: function (data) { } }); } function changePwd(uid) { jqr("#pwd" + uid).val(""); jqr("#pwd" + uid).prop('disabled', false); jqr("#change" + uid).css('display', 'none'); jqr("#savepwd" + uid).css('display', 'block'); } function updatePwd(uid) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php"; var pwd = jqr("#pwd" + uid).val(); if (pwd != "") { jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": uid, "type": "updatePwd", "pwd": pwd}, success: function (data) { jqr("#pwd" + uid).val(data); jqr("#pwd" + uid).prop('disabled', true); jqr("#change" + uid).css('display', 'block'); jqr("#savepwd" + uid).css('display', 'none'); }, error: function (data) { } }); } } function markFeature(uid) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php"; var pwd = jqr().val(); if (!jqr("#feature" + uid).is(':checked')) { var feature = 0; } else { var feature = 1; } jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": uid, "type": "markFeature", "feature": feature}, success: function (data) { }, error: function (data) { } }); } function checkme() { if (!jqr('#checkAll').is(':checked')) { jqr('.chk_user_id').prop('checked', false); } else { jqr('.chk_user_id').prop('checked', true); } } function openFeature() { var ele = jqr('#fa_featured'); if (ele.hasClass('fa-plus')) { ele.removeClass('fa-plus') .addClass('fa-minus') } else { ele.addClass('fa-plus') .removeClass('fa-minus') } jqr("#dv_featured_inner").slideToggle(); } function readMore(id) { jq("#moreText" + id).slideToggle(100, "linear"); jq('#moreText' + id).css('display', 'contents'); jq('#readMore' + id).css('display', 'none'); jq('#readLess' + id).css('display', 'contents'); } function readLess(id) { jq("#moreText" + id).slideToggle(50, "linear"); jq('#readMore' + id).css('display', 'contents'); jq('#readLess' + id).css('display', 'none'); } function sendInstMessage(bmsg) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php?type=sendInstantMsg"; if (jqr(".inst_txt").val() != "") { jqr("#instmsgres").html(""); jqr.ajax({ url: loadUrl, method: 'POST', data: jqr('#frminstmsg').serialize(), success: function (data) { jqr("#loadingIcon").css('display', 'none'); var json = jq.parseJSON(data); //now json variable contains data in json format //let's display a few items for (var i = 0; i < json.length; ++i) { var result = json[i].result; var message = json[i].msg; } if (result == "success") { jqr(".inst_txt").val(""); } jqr("#instmsgres").html(message); }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } else { jqr(".inst_txt").focus(); jqr("#instmsgres").html(bmsg); } } function openKYCBox() { jqr('#KYCBox').css({'display': 'block'}); } function changeUserType(uid, userType) { url = jqr("#site_url").val(); var loadUrl = url + "/action.php"; jqr.ajax({ url: loadUrl, method: 'POST', data: {"user_id": uid, "type": "userType", "user_type": userType}, success: function (data) { }, error: function (data) { } }); } function startQuize() { jqr("#quizeinner").html(""); jqr("#quizeInnerHeader").css('display', 'block'); jqr('#QuickBoxQuize').css({'display': 'block'}); url = jqr("#siteUrl").val(); jqr('#QuickBoxQuize').css({'display': 'block'}); //alert(jqr('#frmQuize').serialize()); var loadUrl = url + "/action.php?type=getQuizeQues"; //alert(loadUrl); jqr.ajax({ url: loadUrl, method: 'GET', success: function (data) { jqr("#loadingIcon").css('display', 'none'); jqr("#quizeInnerHeader").css('display', 'none'); jqr("#quizeinner").html(data); }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } function nextQuize(qID, currentQID, final) { if (currentQID == 0) { jqr(".quizQues").css('display', 'none'); jqr("#quizQues" + qID).css('display', 'block'); } else { url = jqr("#siteUrl").val(); jqr('#QuickBoxQuize').css({'display': 'block'}); //alert(jqr('#frmQuiz'+currentQID).serialize()); var loadUrl = url + "/action.php?type=saveQuiz"; // alert(jqr('#frmQuiz'+currentQID).serialize()); jqr.ajax({ url: loadUrl, method: 'GET', data: jqr('#frmQuiz' + currentQID).serialize(), success: function (data) { if (data == "success") { if (!final) { updateQuizProgress(); jqr("#loadingIcon").css('display', 'none'); jqr(".quizQues").css('display', 'none'); jqr("#quizQues" + qID).css('display', 'block'); } else { jqr("#QuickBoxQuize").css('display', 'none'); jqr("#quizeinner").html(""); alert("You have completed the quiz successfully!"); window.location.href = url; } } else { alert(data); } }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } } function updateQuizProgress() { url = jqr("#siteUrl").val(); var loadUrl = url + "/action.php?type=getQuizProgress"; //alert(loadUrl); jqr.ajax({ url: loadUrl, method: 'GET', success: function (data) { //alert(data); jqr("#prf_progress_p").css("width", data + '%'); jqr("#quizSpan").html(data + '%'); }, error: function (data) { } }); } function reportUser(userId) { jqr("#loadingIcon").css('display', 'block'); url = jqr("#site_url").val(); var loadUrl = url + "/action.php"; // alert(loadUrl); jqr.ajax({ url: loadUrl, method: 'POST', data: {"type": "reportUser", "user_id": userId}, success: function (data) { alert("Reported successfully!"); jqr("#loadingIcon").css('display', 'none'); jqr("#report-user-button-" + userId) .addClass('disabledbutton') .attr('disabled', 'disabled') .attr('onclick', null) .attr('value', 'reported'); }, error: function (data) { jqr("#loadingIcon").css('display', 'none'); } }); } function saveCaption(field) { // jqr("#loadingIcon").css('display', 'block'); url = jqr("#site_url").val(); var caption = jqr("#cpt_" + field).val(); if (caption != "") { var loadUrl = url + "/action.php"; jqr.ajax({ url: loadUrl, method: 'POST', data: {"type": "updateCaption", "field": field, "caption": caption}, success: function (data) { alert("Tool-tip updated successfully!"); //jqr("#loadingIcon").css('display', 'none'); }, error: function (data) { //jqr("#loadingIcon").css('display', 'none'); } }); } else { jqr("#cpt_" + field).focus(); alert("Please enter tooltip!!"); } } function prevQuize(qID) { jqr(".quizQues").css('display', 'none'); jqr("#quizQues" + qID).css('display', 'block'); } function validateEditProfile() { validation = true; /* for panel one*/ jqr(".rsrequired").each(function (item) { if (jqr(this).val() == "") { alert(jqr(this).attr('title') + ' is mandatory!'); validation = false; jqr(this).focus(); return false; } }); if (!validation) { return false; } /* for panel two*/ jqr(".rsrequiredpanel2").each(function (item) { if (jqr(this).val() == "") { alert(jqr(this).attr('title') + ' is mandatory!'); validation = false; jqr(this).focus(); return false; } }); if (!validation) { return false; } /***************************/ /* for panel three*/ jqr(".rsrequiredpanel3").each(function (item) { if (jqr(this).val() == "") { alert(jqr(this).attr('title') + ' is mandatory!'); validation = false; jqr(this).focus(); return false; } }); /***************************/ if (jqr('.chkseeking:checkbox:checked').length == 0) { validation = false; alert("Please select seeking!"); jqr(".chkseeking").focus(); return false; } /*********************/ var totalMultiChkCount = jqr("#totalMultiChkCount").val(); for (var chkct = 1; chkct <= totalMultiChkCount; chkct++) { if (jqr('.rsrequiredchkpanel' + chkct + ':checkbox:checked').length == 0) { validation = false; alert("Please check " + jqr('.rsrequiredchkpanel' + chkct).attr('title')); jqr('.rsrequiredchkpanel' + chkct).focus(); return false; } } /******************/ if (jqr("#txtComment").val().length < 20) { alert("Please enter 20 character in message field!"); validation = false; return false; } /********************/ if (!validation) { return false; } else { return true } } function submitKYC() { url = jqr("#siteUrl").val(); var loadUrl = url + "/prgkycupload.php"; if (jqr('#kyc_address_proof').get(0).files.length === 0 || jqr('#kyc_id_proof').get(0).files.length === 0) { jqr("#kyc_id_proof").focus(); alert("Please upload all files!!"); } else { var formData = new FormData(jqr("#frmKyc")[0]); jqr.ajax({ url: loadUrl, type: 'POST', data: formData, mimeType: "multipart/form-data", contentType: false, cache: false, processData: false, success: function (data, textStatus, jqXHR) { //alert(data); //console.log(data); var json = jqr.parseJSON(data); //now json variable contains data in json format //let's display a few items for (var i = 0; i < json.length; ++i) { var result = json[i].result; var message = json[i].msg; } if (result == "success") { jqr("#kycpanel").html(""); jqr("#kycpanel").html('
' + message + '
'); jqr("#kycpanel").css({'height': '300px'}); // } else { alert(message); } }, error: function (jqXHR, textStatus, errorThrown) { alert('error'); } }); } } var CHOICES_INSTANCES = {}; var GEOGRAPHY_ARGS = {}; function initializeGeographyDropdown(selectElementId, geographyType, onChange) { const element = document.getElementById(selectElementId); var placeholderText = element.getAttribute("placeholder") ?? 'Select a ' + geographyType + '...'; var removeItemButton = (element.dataset.removeItemButton ?? "false") === "true"; var fullWidth = (element.dataset.fullWidth ?? "false") === "true"; var classes = ['choices']; if (!fullWidth) { classes.push("width85"); } CHOICES_INSTANCES[selectElementId] = { geographyType: geographyType, onChange: onChange, element: element, choices: new Choices(element, { classNames: { containerInner: ['choices__inner', "inputselect"], containerOuter: classes }, choices: [], placeholder: true, // Enable placeholder placeholderValue: placeholderText, searchEnabled: true, searchChoices: true, removeItemButton: removeItemButton, duplicateItemsAllowed: false, searchResultLimit: 10, renderChoiceLimit: -1, itemSelectText: '', shouldSort: false }) }; } function convertToIntOrUseString(input) { const parsedValue = parseInt(input, 10); // Check if the parsed value is NaN (Not-a-Number) if (isNaN(parsedValue)) { return input; // Return the original string if conversion failed } return parsedValue; // Return the integer if conversion succeeded } function emptyGeographyDropdown(selectElementId) { var choiceInstance = CHOICES_INSTANCES[selectElementId]; var choices = choiceInstance.choices; choices.removeActiveItems(); choices.clearChoices(); } function fillGeographyDropdown(selectElementId, mapper, args) { var choiceInstance = CHOICES_INSTANCES[selectElementId]; var element = choiceInstance.element; var choices = choiceInstance.choices; var geographyType = choiceInstance.geographyType; var onChange = choiceInstance.onChange; GEOGRAPHY_ARGS = {...GEOGRAPHY_ARGS, ...args}; var searchParams = new URLSearchParams(GEOGRAPHY_ARGS); fetch('/get_' + geographyType + '_list.php?' + searchParams.toString()) .then(response => { if (!response.ok) { // If the response is not OK, get the response text and throw an error return response.text().then(text => { const error = new Error('Network Error'); error.responseText = text; throw error; }); } // Parse the JSON data return response.json(); }) .then(data => { // Create a list item for each country and store its ID const choicesData = data.map(mapper); const previousValue = element.value; //the value of the selected item. var initialValue = element.getAttribute('value'); //this is the value when the page is initially loaded (i.e. from the database) if(geographyType === "country") { initialValue = initialValue ?? "CA"; // Canada } else if (geographyType === "state") { initialValue = initialValue ?? "08"; // Ontario } else if (geographyType === "city") { initialValue = initialValue ?? "6167865"; // Toronto } choices.removeActiveItems(); choices.clearChoices(); choices.setChoices(choicesData, 'value', 'label', false); element.addEventListener('change', function (event) { var value = event.detail.value; if (onChange) { onChange(value); } }); var valueToSelect = previousValue === "" ? initialValue : previousValue; if (geographyType == "city") { valueToSelect = convertToIntOrUseString(valueToSelect); } element.value = valueToSelect; choices.setChoiceByValue(valueToSelect); var event = new Event('change'); event.detail = {value: valueToSelect}; element.dispatchEvent(event); }) .catch(error => { console.error("Failed to fetch " + geographyType + " list: " + error.message + "==>" + error.responseText); if (error.responseText) { console.log(error.responseText); } }); } document.addEventListener('DOMContentLoaded', function () { var loadGeography = false; if (document.getElementById('countryComboBoxList') && document.getElementById('stateComboBoxList') && document.getElementById('cityComboBoxList')) { loadGeography = true; } var choicesLibraryIsLoaded = typeof Choices !== 'undefined'; if (loadGeography && choicesLibraryIsLoaded) { initializeGeographyDropdown('countryComboBoxList', 'country', (country) => { fillGeographyDropdown('stateComboBoxList', (state) => ({ value: state.id, // Use state code as the value label: state.name // Use state name as the label }), {countryCode: country}); emptyGeographyDropdown('cityComboBoxList'); }); initializeGeographyDropdown('stateComboBoxList', 'state', (state) => { fillGeographyDropdown('cityComboBoxList', (city) => ({ value: city.id, // Use state code as the value label: city.name // Use state name as the label }), {stateCode: state}); }); initializeGeographyDropdown('cityComboBoxList', 'city'); fillGeographyDropdown("countryComboBoxList", (country) => ({ value: country.code, label: country.name })); } else { console.log("INFO: Geography dropdowns not loaded on current page"); } //var VALIDATORS = document.querySelectorAll('form.validated').forEach(function (form) { var validator = new JustValidate(form, { validateBeforeSubmitting: true, submitFormAutomatically: true, }); var validatedElements = form.querySelectorAll('input.validated , select.validated, textarea.validated'); validatedElements.forEach(function (element) { rules = []; if (element.hasAttribute("required")) { rules.push({ rule: 'required' }); } if (element.hasAttribute("minlength")) { rules.push({ rule: 'minLength', value: parseInt(element.getAttribute("minlength")) }); } if (element.hasAttribute("type") && element.getAttribute("type") === "date") { const validationRule = element.dataset.validationRule ?? ""; if (validationRule === "is-18-or-older") { rules.push({ validator: (value, fields) => { return is18OrOlder(value); }, errorMessage: 'You must be 18 or older' }); } } if (element.hasAttribute("type") && element.getAttribute("type") === "email") { rules.push({ rule: 'email' }); } if (element.hasAttribute("type") && element.getAttribute("type") === "password") { if(element.dataset.validationMatchesElementId) { //confirm password field const id = element.dataset.validationMatchesElementId; rules.push({ validator: (value, fields) => { const field = document.getElementById(id) if (field) { const repeatPasswordValue = field.value; return value === repeatPasswordValue; } return true; }, errorMessage: 'Passwords should be the same' }); } else { //normal password field rules.push({ rule: 'password' }); } } if (element.hasAttribute("pattern")) { rules.push({ rule: 'customRegexp', value: new RegExp(element.getAttribute("pattern"), 'i'), errorMessage: element.dataset.patternValidationMessage }); } if(rules.length > 0) { validator.addField(element, rules); } }); }); }); function is18OrOlder(birthday) { const birthDate = new Date(birthday); const today = new Date(); let age = today.getFullYear() - birthDate.getFullYear(); const monthDiff = today.getMonth() - birthDate.getMonth(); // Adjust age if birthday hasn't occurred this year yet if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) { age--; } return age >= 18; }