// search function fSearchTheSite() { // get the search value var sSearch = document.getElementById('headerSearchInput').value; // is it longer than 2 chars? if (sSearch.length>2) { // reset the page number to page 1 $.ajax({ data: 'nPageNumber=1', url: 'ajax/pagination.php', type: 'POST', success: function(response) { }, error: function(response) { console.log(response); } }); // do the search location.href="site-search.php?sSearch=" + sSearch; } else { alert("Please enter a search at least 3 characters long"); } // prevent form from completing return false; } function fJoinForm() { var sName = $("#joinName").val(); var sEmail = $("#joinEmail").val(); var bPrivacyPolicy = $("#joinUsPrivacyPolicy").is(":checked"); var aInterests = []; $(':checkbox[name^="interest_"]').each(function(index){ if(this.checked) { aInterests.push(this.attributes["name"].value); } }); var sFind = $("#joinFind").val(); var sMessage = $("#joinMessage").val(); if(sEmail=="") alert("Please insert your email."); else if(aInterests.length=="0") alert("Please choose an interest."); else if(!bPrivacyPolicy) alert("Please tick the box to confirm you agree with our privacy policy."); else { // show the loading bar $('.join-us-loading').show(); // ajax request $.ajax({ url: 'ajax/subscribe.php', type: 'POST', data: 'sName='+encodeURIComponent(sName)+'&sEmail='+encodeURIComponent(sEmail)+'&sInterest='+encodeURIComponent(JSON.stringify(aInterests))+'&sFind='+encodeURIComponent(sFind)+'&sMessage='+encodeURIComponent(sMessage), success: function(data) { alert("Thank You\r\nYou have been successfully added to our mailing list!"); // hide loader and form $('.join-us-loading').hide(); $('#joinUsForm').slideUp(); } }); } } //On document ready dynamically retrieve the notepad content and insert it at the top of the inner ID (the base of the header) $(document).ready(function(){ $.ajax({ data: 'action=include', url: 'ajax/notepad.php', type: 'GET', success: function(response) { $('#inner').prepend(response); } }); }); function fDisplayNotepad() { $('#theNotepad').fadeIn(250); } function fNotepadHide() { $('#theNotepad').fadeOut(250); } function fNotepadRefresh() { $('#theNotepad').fadeOut(250); $('#theNotepad').delay(300).fadeIn(250); } function fNotepadEmailComplete() { $('#notepadEmailFormSend').removeAttr('disabled'); $('#notepadEmailFormSend').css('background', '#8CB664'); $('#notepadEmailFormSend').val('Send Enquiry'); $('.notepadEmailBox').fadeOut(250); $('#notepadContent').delay(250).fadeIn(250); } // add items to notepad function fAddToNotepad(nProduct_ID) { $.ajax({ data: 'action=add&nProductID='+nProduct_ID, url: 'ajax/notepad.php', type: 'GET', success: function(response) { if(response!='\nItem is already in your bookmarks.'){ alert("Item added to bookmarks"); $('#notepad').replaceWith(response); fNotepadRefresh(); }else{ alert(response); } } }); } // notepad click to view item function fNotepad_ViewItem(sItemURL) { document.cookie="catalogue_list_pagetype=notepad"; location.href=sItemURL; } //Enail regex function fValidateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } $(document).ready(function(){ $('input, textarea').placeholder(); $(document.body).on('click', 'span.remove', function(){ var nProduct_ID = $(this).attr('data-product'); $.ajax({ data: 'action=delete&nProductID='+nProduct_ID, url: 'ajax/notepad.php', type: 'GET', success: function(response) { $('#notepad').replaceWith(response); fNotepadRefresh(); } }); }); $('input#ckSubscribe').click(function(){ var sEmailAddress = $(this).parent().find('input[name="sHomeMailingEmail"]').val(); $.ajax({ data: 'sEmailAddress=' + sEmailAddress, type: 'post', url: 'ajax/homemailinglist.php', success: function(response) { alert(response); } }); }); /* $(document.body).on('click', '#notepadEmail', function(){ $(this).parent().fadeOut(250); $('#notepadEmailForm').delay(250).fadeIn(250); }); */ $(document.body).on('click', '#notepadEmail', function(){ $(this).parent().fadeOut(250); $('#notepadEmailSelect').delay(250).fadeIn(250); }); $(document.body).on('click', '#notepadEmailToEnglishSalvage', function(){ $(this).parent().parent().fadeOut(250); $('#notepadEmailForm').delay(250).fadeIn(250); var sFormBase = $(this).parent().parent().parent(); sFormBase.find('input[name="sFormType"]').val("English Salvage"); sFormBase.find('input[name="sName"]').attr("placeholder", "Full Name").show(); sFormBase.find('input[name="sTel"]').show(); sFormBase.find('input[name="sEmail"]').attr("placeholder", "Email Address"); sFormBase.find('input[name="sTheirName"]').hide(); sFormBase.find('input[name="sTheirEmail"]').hide(); sFormBase.find('input[name="sLocation"]').show(); sFormBase.find('textarea[name="sMessage"]').show(); sFormBase.find('.emailToEnglishSalvage').show(); sFormBase.find('.emailToMe').hide(); sFormBase.find('.emailToFriend').hide(); }); $(document.body).on('click', '#notepadEmailToMe', function(){ $(this).parent().parent().fadeOut(250); $('#notepadEmailForm').delay(250).fadeIn(250); var sFormBase = $(this).parent().parent().parent(); sFormBase.find('input[name="sFormType"]').val("Me"); sFormBase.find('input[name="sName"]').hide(); sFormBase.find('input[name="sTel"]').hide(); sFormBase.find('input[name="sEmail"]').attr("placeholder", "Email Address"); sFormBase.find('input[name="sTheirName"]').hide(); sFormBase.find('input[name="sTheirEmail"]').hide(); sFormBase.find('input[name="sLocation"]').hide(); sFormBase.find('textarea[name="sMessage"]').hide(); sFormBase.find('.emailToEnglishSalvage').hide(); sFormBase.find('.emailToMe').show(); sFormBase.find('.emailToFriend').hide(); }); $(document.body).on('click', '#notepadEmailToSomeoneElse', function(){ $(this).parent().parent().fadeOut(250); $('#notepadEmailForm').delay(250).fadeIn(250); var sFormBase = $(this).parent().parent().parent(); sFormBase.find('input[name="sFormType"]').val("Someone else"); sFormBase.find('input[name="sName"]').attr("placeholder", "Your Name").show(); sFormBase.find('input[name="sTel"]').hide(); sFormBase.find('input[name="sEmail"]').attr("placeholder", "Your Email"); sFormBase.find('input[name="sTheirName"]').show(); sFormBase.find('input[name="sTheirEmail"]').show(); sFormBase.find('input[name="sLocation"]').hide(); sFormBase.find('textarea[name="sMessage"]').show(); sFormBase.find('.emailToEnglishSalvage').hide(); sFormBase.find('.emailToMe').hide(); sFormBase.find('.emailToFriend').show(); }); $(document.body).on('click', '#notepadEmailFormHide', function(){ $(this).parent().parent().parent().fadeOut(250); $('#notepadEmailSelect').delay(250).fadeIn(250); }); $(document.body).on('click', '.cancelButtonHolder button', function(){ fNotepadEmailComplete(); }); $(document.body).on('click', '#notepadEmailFormSend', function(){ var sFormBase = $(this).parent().parent(); var sFormType = sFormBase.find('input[name="sFormType"]').val(); var bName = 0; var bTel = 0; var bEmail = 0; var bTheirName = 0; var bTheirEmail = 0; var bLocation = 0; var bMessage = 0; if(sFormType === "English Salvage") { bName = bTel = bEmail = bLocation = bMessage = 1; } if(sFormType === "Someone else") { bName = bEmail = bTheirName = bTheirEmail = bMessage = 1; } if(sFormType === "Me") { bEmail = 1; } var sName = sFormBase.find('input[name="sName"]').val(); var sTel = sFormBase.find('input[name="sTel"]').val(); var sEmail = sFormBase.find('input[name="sEmail"]').val(); var sTheirName = sFormBase.find('input[name="sTheirName"]').val(); var sTheirEmail = sFormBase.find('input[name="sTheirEmail"]').val(); var sLocation = sFormBase.find('input[name="sLocation"]').val(); var sMessage = sFormBase.find('textarea[name="sMessage"]').val(); var sErr = ''; if(bName && sName=='') sErr += '\nNo Name provided'; if(bTel && sTel=='') sErr += '\nNo Contact Number provided'; if(sEmail==''){ //If no email address is provided then notify client sErr += '\nNo Email Address provided'; }else{ //otherwise run a regex check to see if it is a valid email if(fValidateEmail(sEmail)==false) sErr+= '\nInvalid email address provided'; } if(bTheirName && sTheirName=='') sErr += '\nNo Name for recepient provided'; if(bTheirEmail && sTheirEmail==''){ //If no email address is provided then notify client sErr += '\nNo Email Address for recepient provided'; }else if(bTheirEmail){ //otherwise run a regex check to see if it is a valid email if(fValidateEmail(sTheirEmail)==false) sErr+= '\nInvalid email address for recepient provided'; } if(bLocation && sLocation=='') sErr += '\nNo Location provided'; if(!$("#notepadPrivacyPolicy").is(":checked")) sErr += "\nPlease tick the box to show you agree to our Privacy Policy."; if(sErr!=''){ alert('Please check the following:\n' + sErr); }else{ $('#notepadEmailFormSend').attr('disabled', 'disabled'); $('#notepadEmailFormSend').css('background', '#B3B3B3'); $('#notepadEmailFormSend').val('Sending...'); $.ajax({ data: sFormBase.serialize(), type: 'post', url: 'ajax/notepad-email-send.php', success: function(response) { var sReturnMessage = 'Your bookmarks have been sent!'; alert(sReturnMessage); //var sReturnMessage = response; //$('#notepadEmailForm').html(sReturnMessage); fNotepadEmailComplete(); } }); } }); $(document.body).on('click', '#emptyNotepad', function(){ var r = confirm("Are you sure you want to empty your notepad? This cannot be undone."); if (r == true) { $.ajax({ data: 'action=empty', url: 'ajax/notepad.php', type: 'GET', success: function(response) { $('#notepad').replaceWith(response); fNotepadRefresh(); setTimeout(function(){ fNotepadHide(); }, 5000); } }); } }); $(".newsletter-signup-button").on("click", function(){ // Check the email address in the input box is valid if(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test($("input[name='sNewsletterEmailAddress']").val().toLowerCase())) { // Show the popup modal $(".modal-backdrop").show(); } else { alert("Please enter a valid email address."); $("input[name='sNewsletterEmailAddress']").focus(); } }); $(".modal button.cancel").on("click", function(){ $(".modal-backdrop").hide(); }); $(".modal button.sign-up").on("click", function(){ if(!$("#bPrivacyPolicy_Newsletter").is(":checked")) { alert("Please check the box to show you agree to our Privacy Policy"); return; } $.ajax({ type: "POST", url: "ajax/newsletter_exec.php", data: {sEmailAddress: $("input[name='sNewsletterEmailAddress']").val().toLowerCase()}, success: function(){ alert("Thank you\n\nYou will soon receive an email confirming your subscription"); $(".modal-backdrop").hide(); } }); }); }); function fShowPageMessage(sPageMessage, bHideCloseButton = false){ $("#page-message").html(sPageMessage); $("#page-message-modal").modal('show'); $('body').addClass("no-padding"); $('#page-message-modal').addClass("no-padding"); if (bHideCloseButton==true) { document.getElementById('modalCloseButton').style.display='none'; } else { document.getElementById('modalCloseButton').style.display=''; } } function fShowPageMessages() { if(aMessages.length > 0) { var sMessage = aMessages.shift(); fShowPageMessage(sMessage); $('#page-message-modal').on('hidden', function () { fShowPageMessages(); }); } } function fShowPageMessage_HTMLFromURL(sURLToGrabHTMLFrom, bHideCloseButton = false){ $.get( sURLToGrabHTMLFrom, function( data ) { $("#page-message").html(data); $("#page-message-modal").modal('show'); $('body').addClass("no-padding"); $('#page-message-modal').addClass("no-padding"); if (bHideCloseButton==true) { document.getElementById('modalCloseButton').style.display='none'; } else { document.getElementById('modalCloseButton').style.display=''; } }); }