// JavaScript Document var iType = 0; $('#search_button').click(function(e) { e.preventDefault(); if ($(".search_box").is(":visible")) { if ($(".search_box .search_criteria").val() + "" != "") { $("#frmSearch").submit(); } $(".search_box").hide("slide", {direction: "right"}); } else { $(".search_box").show("slide", {direction: "right"}, function() { $(".search_box .search_criteria").focus(); }); } }); function stayStandalone(remotes) { // Mobile Safari in standalone mode if(("standalone" in window.navigator) && window.navigator.standalone){ // If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true var noddy; document.addEventListener('click', function(event) { noddy = event.target; // Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") { noddy = noddy.parentNode; } if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) { event.preventDefault(); document.location.href = noddy.href; } },false); } } function getlocationNearMe(iTypeID) { iType = iTypeID; navigator.geolocation.getCurrentPosition(nearMeURL, nearMeURLNoGeo); } function getlocationCriteria() { navigator.geolocation.getCurrentPosition(criteriaURL, criteriaURLNoGeo); } function nearMeURL(position) { if(iType == 2) { window.location = '/results/1/1/10?iNearMe=1&iBrewery=1&iLatitude=' + position.coords.latitude + '&iLongitude=' + position.coords.longitude; } else if(iType == 3) { window.location = '/results/1/1/10?iNearMe=1&iFestival=1&iLatitude=' + position.coords.latitude + '&iLongitude=' + position.coords.longitude; } else { window.location = '/results/1/1/10?iNearMe=1&iLatitude=' + position.coords.latitude + '&iLongitude=' + position.coords.longitude; } } function nearMeURLNoGeo() { if(iType == 2) { window.location = '/results/1/1/10?iNearMe=1&iBrewery=1&iLatitude=0&iLongitude=0'; } else if(iType == 3) { window.location = '/results/1/1/10?iNearMe=1&iFestival=1&iLatitude=0&iLongitude=0'; } else { window.location = '/results/1/1/10?iNearMe=1&iLatitude=0&iLongitude=0'; } } function criteriaURL(position) { document.getElementById('iLatitude').value = position.coords.latitude; document.getElementById('iLongitude').value = position.coords.longitude; } function criteriaURLNoGeo(position) { document.getElementById('iLatitude').value = 0; document.getElementById('iLongitude').value = 0; } function hideAdvert() { document.getElementById('ads').style.display='none'; } function showAdvert() { document.getElementById('ads').style.display=''; } function like(iType, iID) { $.ajax({url: "/include/like.asp?iType=" + iType + "&iID=" + iID, cache: false}).done(function(data) { if (data != "") { if ($('.like_button').hasClass("liked")) { $('.like_button').removeClass("liked"); } else { $('.like_button').addClass("liked"); } $('.like_button span').html(data); } }); } function rating(iType, iID, iRating, sElem) { $.ajax({url: "/include/rate.asp?iType=" + iType + "&iID=" + iID + "&iRating=" + iRating, cache: false}).done(function(data) { if (data != "") { $("#" + sElem + " .rating").each(function(index) { $(this).data("currentrating", iRating); if (iRating - 1 >= index) { $(this).removeClass("fa-star-o"); $(this).addClass("fa-star"); } else { $(this).addClass("fa-star-o"); $(this).removeClass("fa-star"); } }); $("#" + sElem + " #yourRating").html(iRating); averageRating = parseInt(data); $("#" + sElem + " .average-rating").each(function(index) { if (averageRating - 1 >= index) { $(this).removeClass("fa-star-o"); $(this).addClass("fa-star"); } else { $(this).addClass("fa-star-o"); $(this).removeClass("fa-star"); } }); } }); } function claim(iType, iID) { $.ajax({url: "/include/claim.asp?iType=" + iType + "&iID=" + iID, cache: false}).done(function(data) { if (data != "") { if (iType == 1) { $('#modal_claim_brewery').fadeOut('fast'); $('.modal_claim_brewery').html(data); } else if (iType == 2) { $('#modal_claim_pub').fadeOut('fast'); $('#modal_claim_pub').remove(); $("#pubClaim").addClass("liked"); $("#pubClaim").html(' Claimed'); } } }); } function loginValidate() { event.preventDefault(); var bErrorOccured = false; if ($("#username").val() === "") { bErrorOccured = true; $("#modal_login_email_error").text("Please enter either your username or email address"); $("#modal_login_email_error").show(100); $("#username").addClass("modal_form_text_error"); } else if ($("#username").val().length < 2) { bErrorOccured = true; $("#modal_login_email_error").text("Please enter a value greater than 3 characters"); $("#modal_login_email_error").show(100); $("#username").addClass("modal_form_text_error"); } else if ($("#password").val() === "") { bErrorOccured = true; $("#modal_login_password_error").text("Please enter your password"); $("#modal_login_password_error").show(100); $("#password").addClass("modal_form_text_error"); }; if (!bErrorOccured) { $("#modal_login_form").submit(); }; } function forgotValidate() { event.preventDefault(); var bErrorOccured = false; if ($("#forgotUsername").val() === "") { bErrorOccured = true; $("#modal_forgot_email_error").text("Please enter either your username or email address"); $("#modal_forgot_email_error").show(100); $("#forgotUsername").addClass("modal_form_text_error"); } else if ($("#forgotUsername").val().length < 2) { bErrorOccured = true; $("#modal_forgot_email_error").text("Please enter a valid username or email address"); $("#modal_forgot_email_error").show(100); $("#forgotUsername").addClass("modal_form_text_error"); }; if (!bErrorOccured) { $("#modal_forgot_form").submit(); }; } function validUsername(sUsernameCheck) { check = false; const regex = /^[a-z0-9_-]+$/giy; let m; while ((m = regex.exec(sUsernameCheck)) !== null) { if (m.index === regex.lastIndex) { regex.lastIndex++; } m.forEach((match, groupIndex) => { check = true; }); } return check; } function uniqueUsername(sUsernameCheck) { } function signupValidate() { event.preventDefault(); $.ajax({url: "/include/check-username.asp?sUsername=" + $("#signupUsername").val(), cache: false}).done(function(data) { $("#usernameUnique").val(data); var bErrorOccured = false; if ($("#signupUsername").val() === "") { bErrorOccured = true; $("#modal_signup_username_error").text("Please enter a username"); $("#modal_signup_username_error").show(100); $("#signupUsername").addClass("modal_form_text_error"); } else if ($("#signupUsername").val().length < 3 || $("#signupUsername").val().length > 15) { bErrorOccured = true; $("#modal_signup_username_error").text("Please enter a username greater than 3 characters and less than 15 characters"); $("#modal_signup_username_error").show(100); $("#signupUsername").addClass("modal_form_text_error"); } else if (validUsername($("#signupUsername").val()) === false) { bErrorOccured = true; $("#modal_signup_username_error").text("Please enter only letters, numbers, '-' and '_' characters"); $("#modal_signup_username_error").show(100); $("#signupUsername").addClass("modal_form_text_error"); } else if ($("#usernameUnique").val() === "True") { bErrorOccured = true; $("#modal_signup_username_error").text("This username is already in use, try adding a number"); $("#modal_signup_username_error").show(100); $("#signupUsername").addClass("modal_form_text_error"); } else if ($("#iDOBDay").val() === "" || $("#iDOBMonth").val() === "" || $("#iDOBYear").val() === "") { bErrorOccured = true; $("#modal_signup_dob_error").text("Please enter a valid date of birth"); $("#modal_signup_dob_error").show(100); $("#iDOBDay").addClass("modal_form_text_error"); $("#iDOBMonth").addClass("modal_form_text_error"); $("#iDOBYear").addClass("modal_form_text_error"); } else if ($("#postcode").val() === "") { bErrorOccured = true; $("#modal_signup_postcode_error").text("Please enter your postcode"); $("#modal_signup_postcode_error").show(100); $("#postcode").addClass("modal_form_text_error"); } else if ($("#email").val() === "") { bErrorOccured = true; $("#modal_signup_email_error").text("Please enter a valid mail address"); $("#modal_signup_email_error").show(100); $("#email").addClass("modal_form_text_error"); } else if ($("#signupPassword").val() === "") { bErrorOccured = true; $("#modal_signup_password_error").text("Please enter a password"); $("#modal_signup_password_error").show(100); $("#signupPassword").addClass("modal_form_text_error"); } else if ($("#signupPassword").val() != $("#confirmPassword").val()) { bErrorOccured = true; $("#modal_signup_confirm_password_error").text("Your password and confirm password fields do not match"); $("#modal_signup_confirm_password_error").show(100); $("#confirmPassword").addClass("modal_form_text_error"); }; if (!bErrorOccured) { $("#modal_signup_form").submit(); }; }); } function deleteActivity(user_venue_id) { $.ajax({url: "/include/delete-activity.asp?user_venue_id=" + user_venue_id, cache: false }).done(function(data) { $("#edit_activity_" + user_venue_id).closest(".activity_thumbnail").remove() $("#activityCount").val(0); $(".activity_results").html(""); loadActivity(); }).fail(function() { alert("Unable to delete the activity"); }); } $(document).ready(function(event) { $("#modal_login").click(function() { $("#modal_login").fadeOut("fast"); }); $('.modal_login').click(function(event) { event.stopPropagation(); }); $("#modal_login_form #username").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_login_email_error").hide(100); }); $("#modal_login_form #password").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_login_password_error").hide(100); }); $("#modal_forgot").click(function() { $("#modal_forgot").fadeOut("fast"); }); $('.modal_forgot').click(function(event) { event.stopPropagation(); }); $("#modal_forgot_form #forgotUsername").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_forgot_email_error").hide(100); }); $("#modal_signup").click(function() { $("#modal_signup").fadeOut("fast"); }); $('.modal_signup').click(function(event) { event.stopPropagation(); }); $("#modal_signup_form #signupUsername").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_signup_username_error").hide(100); }); $("#modal_signup_form #iDOBDay, #modal_signup_form #iDOBMonth, #modal_signup_form #iDOBYear").focus(function() { $("#iDOBDay").removeClass("modal_form_text_error"); $("#iDOBMonth").removeClass("modal_form_text_error"); $("#iDOBYear").removeClass("modal_form_text_error"); $("#modal_signup_dob_error").hide(100); }); $("#modal_signup_form #postcode").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_signup_postcode_error").hide(100); }); $("#modal_signup_form #email").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_signup_email_error").hide(100); }); $("#modal_signup_form #signupPassword").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_signup_password_error").hide(100); }); $("#modal_signup_form #confirmPassword").focus(function() { $(this).removeClass("modal_form_text_error"); $("#modal_signup_confirm_password_error").hide(100); }); $(".tab_outer li a").click(function() { $(this).closest(".tab_outer").find("li a").removeClass("active"); $(this).addClass("active"); if ($(this).data("scroll-top")) { sScrollTop = $(this).attr("href"); $(sScrollTop).scrollTop(1); } }) $(document).on("click", ".edit_activity", function() { $(".activity_menu").remove(); $("#iCurrentActivityID").val($(this).attr("id").replace("edit_activity_", "")); $.ajax({url: "/include/show-activity-menu.asp?user_venue_id=" + $(this).attr("id").replace("edit_activity_", ""), cache: false }).done(function(data) { $("#edit_activity_" + $("#iCurrentActivityID").val()).append(data); }).fail(function() { alert("Unable to show the edit menu"); }); }); $("#body").on("mouseover", ".rating", function() { sElem = $(this).closest("div").attr("id"); iRating = $(this).data("rating"); $("#" + sElem + " .rating").each(function(index) { if (iRating - 1 >= index) { $(this).removeClass("far"); $(this).addClass("fas"); } else { $(this).addClass("far"); $(this).removeClass("fas"); } }); }); $("#body").on("mouseout", ".rating", function() { sElem = $(this).closest("div").attr("id"); iRating = $(this).data("currentrating"); $("#" + sElem + " .rating").each(function(index) { if (iRating - 1 >= index) { $(this).removeClass("far"); $(this).addClass("fas"); } else { $(this).addClass("far"); $(this).removeClass("fas"); } }); }); });