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");
}
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 = "
";
jqr("#addBeforeMe").before(html);
jqr('#lastrow').val(nextrow);
}
var jqr = jQuery.noConflict();
document.addEventListener('click', function (event) {
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 = "";
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() {
var loadUrl = "/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(), "credits": jqr('#credits').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) {
var loadUrl = "/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) {
var loadUrl = "/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") {
fetch('/hot-list/' + touserId + '/' + touser)
.then(response => {
if (response.status === 200) {
return response.text().then(data => {
alert('Profile was added to Favorites'); // Success message
});
} else {
alert('Could not add user to your favorites.'); // Handle other status codes
}
})
.catch(error => {
alert('An error occurred: ' + error.message); // Network error handling
});
} 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") {
reportUser(touserId);
} 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");
if (divid === 'credit') {
jqr("#div" + divid).css('display', 'block');
} else {
jqr("#div" + divid).css('display', 'flex');
}
}
function saveMembershipLevel(uid) {
var loadUrl = "/action.php";
var level = jqr("#membership_level_id_" + uid).val();
jqr.ajax({
url: loadUrl,
method: 'POST',
data: {"user_id": uid, "type": "updateMembershipLevel", "level": level},
success: function (data) {
},
error: function (data) {
}
});
}
function saveExpDate(uid) {
var loadUrl = "/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) {
var loadUrl = "/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) {
var loadUrl = "/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) {
var loadUrl = "/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'});
jqr('#QuickBoxQuize').css({'display': 'block'});
//alert(jqr('#frmQuize').serialize());
var loadUrl = "/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 {
jqr('#QuickBoxQuize').css({'display': 'block'});
//alert(jqr('#frmQuiz'+currentQID).serialize());
var loadUrl = "/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() {
var loadUrl = "/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;
}
});
/*********************/
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 (!validation) {
return false;
} else {
return true
}
}
function submitKYC() {
var loadUrl = "/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");
} else {
classes.push("width100");
}
CHOICES_INSTANCES[selectElementId] = {
geographyType: geographyType,
onChange: onChange,
element: element,
choices: new Choices(element, {
classNames: {
containerInner: ['choices__inner', "select_home", "form-control"],
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) {
if(selectElementId.startsWith('invalid')) {
return;
}
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);
console.log(error);
});
}
VALIDATORS = {};
document.addEventListener('DOMContentLoaded', function () {
var choicesLibraryIsLoaded = typeof Choices !== 'undefined';
if (!choicesLibraryIsLoaded) {
console.log("INFO: Geography dropdowns not loaded on current page (no Choices library)");
return;
}
const groupNames = {};
document.querySelectorAll('.country-combo-box-list').forEach(function (element) {
var countryBoxId = element.id;
var groupName = element.dataset.geographyGroupName;
groupNames[groupName] = true;
var stateElement = document.querySelector('.state-combo-box-list.geography-group-' + groupName);
var cityElement = document.querySelector('.city-combo-box-list.geography-group-' + groupName);
var stateBoxId = stateElement?.id ?? 'invalid-state-box';
var cityBoxId = cityElement?.id ?? 'invalid-city-box';
if (element.tagName === 'SELECT') {
initializeGeographyDropdown(countryBoxId, 'country', (country) => {
fillGeographyDropdown(stateBoxId, (state) => ({
value: state.id,
label: state.name
}), {countryCode: country});
emptyGeographyDropdown(cityBoxId);
});
}
if (!stateElement) {
console.info("No state element for country combo box with group: " + groupName);
} else {
initializeGeographyDropdown(stateBoxId, 'state', (state) => {
if(cityElement) {
fillGeographyDropdown(cityBoxId, (city) => ({
value: city.id,
label: city.name
}), {stateCode: state});
}
});
if(cityElement) {
initializeGeographyDropdown(cityBoxId, 'city');
}
}
if(element.tagName === 'SELECT') {
fillGeographyDropdown(countryBoxId, (country) => ({
value: country.code,
label: country.name
}));
} else {
var country = element.value;
fillGeographyDropdown(stateBoxId, (state) => ({
value: state.id,
label: state.name
}), {countryCode: country});
}
});
document.querySelectorAll('.state-combo-box-list').forEach(function (element) {
var processedAlready = groupNames[element.dataset.geographGroupName];
if(!processedAlready) {
var groupName = element.dataset.geographyGroupName;
groupNames[groupName] = true;
var cityElement = document.querySelector('.city-combo-box-list.geography-group-' + groupName);
var fetchArgs = element.dataset.fetchArgs;
var args = {};
if(fetchArgs) {
var arr = fetchArgs.split('=');
if (arr.length === 2) {
args[arr[0]] = arr[1];
}
}
if(cityElement) {
fillGeographyDropdown(cityElement.id, (state) => {
if (state.countryCode) {
return {
value: state.id + '-' + state.countryCode,
label: state.name
}
}
return {
value: state.id,
label: state.name
}
}, args);
}
}
});
document.querySelectorAll('.city-combo-box-list').forEach(function (element) {
var processedAlready = groupNames[element.dataset.geographyGroupName];
if(!processedAlready) {
fillGeographyDropdown(element.id, (city) => ({
value: city.id,
label: city.name
}));
}
});
});
document.addEventListener('DOMContentLoaded', function () {
// Format the country code with a '+' prefix
let countryCodeElement = document.getElementById('country-code');
if (countryCodeElement) {
countryCodeElement.addEventListener('input', function (e) {
let x = e.target.value.replace(/\D/g, ''); // Remove non-numeric characters
e.target.value = '+' + x.slice(0, 3); // Limit to 3 digits for the country code
updateHiddenMobileField();
});
}
let phoneNumberElement = document.getElementById('txtPhone');
if (phoneNumberElement && countryCodeElement) {
// Format the phone number field and handle pasted input with or without country code
phoneNumberElement.addEventListener('input', function (e) {
let x = e.target.value.replace(/\D/g, ''); // Remove all non-numeric characters
// If pasted number includes a country code (e.g., 11234567890), remove first 1-3 digits as country code
if (x.length > 10) {
const countryCode = x.slice(0, x.length - 10); // Get country code
x = x.slice(x.length - 10); //keep only the last 10 digits
countryCodeElement.value = '+' + countryCode;
}
// Format the phone number in (123) 456-7890 style
let formatted = x.match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
e.target.value = !formatted[2] ? formatted[1]
: '(' + formatted[1] + ') ' + formatted[2] + (formatted[3] ? '-' + formatted[3] : '');
updateHiddenMobileField();
});
}
});
document.addEventListener('DOMContentLoaded', function () {
//var VALIDATORS =
document.querySelectorAll('form.validated').forEach(function (form) {
var validator = new JustValidate(form, {
validateBeforeSubmitting: true,
submitFormAutomatically: true
});
VALIDATORS[form.id] = validator;
var validatedElements = form.querySelectorAll('input.validated , select.validated, textarea.validated');
validatedElements.forEach(function (element) {
var 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.startsWith("age-limit-")) {
const age = parseInt(validationRule.split("-")[2], 10);
rules.push({
validator: (value, fields) => {
return is18OrOlder(value, age);
},
errorMessage: "You must be " + age + ' 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) {
var config = {};
if (element.classList.contains("country-combo-box-list")) {
config['errorsContainer'] = '#errorLabel-country';
} else if (element.classList.contains("state-combo-box-list")) {
config['errorsContainer'] = '#errorLabel-state';
} else if (element.classList.contains("city-combo-box-list")) {
config['errorsContainer'] = '#errorLabel-city';
} else if (element.id === 'txtValidOtp') {
config['errorsContainer'] = '#errorLabel-otp';
}
validator.addField(element, rules, config);
}
});
});
});
function updateHiddenMobileField() {
var countryCode = document.getElementById('country-code').value.replace(/\D/g, '');
var phoneNumber = document.getElementById('txtPhone').value.replace(/\D/g, '');
var hiddenMobileField = document.getElementById('txtMobile');
if (phoneNumber.length === 10 && countryCode.length > 0) {
document.getElementById('verifyBtnContainer').style.display = "inline-block";
} else {
document.getElementById('verifyBtnContainer').style.display = "none";
}
hiddenMobileField.value = '+' + countryCode + phoneNumber;
}
function is18OrOlder(birthday, limit) {
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 >= limit;
}
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.add-to-favorite').forEach(clickedElement => {
clickedElement.addEventListener('click', function () {
const userId = this.dataset.userId;
const userName = this.dataset.userName;
fetch('/hot-list/' + userId + '/' + userName)
.then(response => {
if (response.status === 200) {
return response.text().then(data => {
alert('Profile was added to Favorites'); // Success message
});
} else {
alert('Could not add user to your favorites.'); // Handle other status codes
}
})
.catch(error => {
alert('An error occurred: ' + error.message); // Network error handling
});
});
});
});
document.addEventListener('DOMContentLoaded', function () {
//fill the country field with the user's country, from an ajax request
//{$value[0] ?? ''}
document.querySelectorAll('.static-geography').forEach(staticGeographyElement => {
const geographyType = staticGeographyElement.dataset.geography;
const id = staticGeographyElement.innerHTML;
fetch('/geo_lookup.php?id=' + id + '&geography=' + geographyType)
.then(response => {
if (response.status === 200) {
return response.text().then(data => {
staticGeographyElement.innerHTML = data;
});
} else {
console.warn('Could not geography name for ' + geographyType + ': '+id);
}
})
.catch(error => {
console.error('Could not geography name for ' + geographyType + ': '+id);
});
});
});
document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll("img").forEach(function (img) {
img.addEventListener("contextmenu", function (e) {
e.preventDefault();
});
img.addEventListener("dragstart", function (e) {
e.preventDefault();
});
});
});
document.addEventListener('DOMContentLoaded', () => {
// Select all images with the class "watermark"
const watermarkImages = document.querySelectorAll('img.watermark');
watermarkImages.forEach(addWaterMark);
document.body.addEventListener("click", function (event) {
const target = event.target;
if(target.tagName === 'IMG') {
setTimeout(()=>{
document.querySelectorAll('img.lb-image').forEach(addWaterMark);
}, 500);
}
if (
(target.tagName === "A" || target.tagName === "AREA") &&
(target.getAttribute("rel")?.startsWith("lightbox") || target.hasAttribute("data-lightbox"))
) {
target.getElementsByTagName('img').forEach(addWaterMark);
}
});
});
function addWaterMark(img) {
const originalSrc = img.src; // Get the original image source
// Define your watermark parameters
const watermarkText = ''; // TODO: Create configuration
const textStyle = '15px serif'; // Font size and style
const textColor = '#fff'; // Color of the text
const transparency = 0.7; // Transparency level
// Apply the watermark
watermark([originalSrc])
.image(watermark.text.lowerRight(watermarkText, textStyle, textColor, transparency))
.then((watermarkedImage) => {
// Replace the original image with the watermarked image
img.src = watermarkedImage.src;
})
.catch((err) => {
console.error('Error applying watermark:', err);
});
}
lightbox.option({
'fadeDuration': 50,
'resizeDuration': 50,
'wrapAround': false
})