// This variable is used to check if the related items feature is turned on or off. // In document.ready on catalogue_list, catalogue_detail, catalogue_latest, and catalogue_seach // this variable is set to 1 if the feature is turned on, else it stays at 0 var bRelatedItems = 0; // UPDATE BASKET COUNT // =================== // - function to update the counter shown on the web site of how many items are in the basket function fShopBasketUpdateCounter() { // define the url to call sAjaxURL = "ajax/shop_basket_item-count.php"; // open URL using AJAX $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // save the results var nShopBasketItemCount = parseInt(data); // update the div document.getElementById('nShopBasketItemCount').innerHTML=nShopBasketItemCount; $(".nShopBasketItemCount").html(nShopBasketItemCount); }); } // ADD TO BASKET // ============== // - used on catalogue_list.php and catalogue_detail.php // - needs dialogAddToBasket_Inner to be on the page // - is reliant on various fields being in place on the page (bShopLimitOrderByStockLevels) // show buy modal // =============== function fBuy_ShowModal(nShopProd_ID) { // load the add to basket modal $nVariation_ID = 0; nNewShopProd_ID = 0; if($("#nShopProdOption_ID").length!=0&&$("#productsList").length==0) { $nVariation_ID = $("#nShopProdOption_ID").val(); if($nVariation_ID==0) return; } else $nVariation_ID=0; $( "#dialogAddToBasket" ).dialog(); $( "#dialogAddToBasket" ).dialog( "option", "height", 550 ); $( "#dialogAddToBasket" ).dialog( "option", "width", 500 ); // get the add form page $.get('ajax/shop_basket_add_form.php?nShopProd_ID='+nShopProd_ID+'&nVariation_ID='+$nVariation_ID, function(data) { // get the result $('.result').html(data); // save to the empty div in the modal box we have just loaded $('#dialogAddToBasket_Inner').html(data); }); } // add to basket validate function (called by the add to basket button) // ===================================================================== function fBuy_AddToBasket_Validate(nShopProd_ID, nParentShopProd_ID, bShopLimitOrderByStockLevels, bCalledFromModal) { // Store this pages nShopProd_ID nCurrentShopProd_ID = nParentShopProd_ID; // If a variation nShopProd_ID has been selected from drop downs, use that if(nNewShopProd_ID!=0) { nShopProd_ID = nNewShopProd_ID; } // If we have multiple nQty boxes, they're displaying a variation table var bMultipleVariationsInTable = 0; if($("input[name$='_nQty']").length) { bMultipleVariationsInTable = 1; var bError = 0; $("input[name$='_nQty']").each(function(){ if(bError) return; if($(this).val()==="") $(this).val("0"); if(!$.isNumeric($(this).val())) { bError = 1; alert("Please check the quantity you're trying to add to the basket"); $(this).focus(); return; } }); if(bError) return; } else { // validate qty // ============= var nQty = document.getElementById('nQty').value; // get the value form the qty box if ( (nQty=="") || (!$.isNumeric(nQty)) ) { // check that it has a valid value // if not, display an error and exit alert("Please check the quantity you're trying to add to the basket"); return; } } // check if they have agreed to the delivery lead times // ===================================================== // we gonna check if an id exists if ($('#bDelivery_LeadTimes_VisitorMustAgreeToLeadTimeWhenAddingToBasket').length > 0) { // the id exists! so lets check if the checkbox is checked if (!$('#bDelivery_LeadTimes_VisitorMustAgreeToLeadTimeWhenAddingToBasket').is(':checked')) { // it isnt checked so tell them to sort it out and tick the box to agree and return false so that they cant buy it alert("Please tick the checkbox to confirm you are happy with the delivery information quoted on the page"); return false; } } // validate option (if applicable) // ================================ var bVariationCheck = 1; $("select[name$='nShopProdVariationOption_ID']").each(function(){ if($(this).val()=="0") { bVariationCheck = 0; } }); if (bVariationCheck == 0) { alert("Please choose an option from the drop down menu of which version of this item you would like"); return; } // validate required fields // ================================ // Set a flag depending on whether or not it fails var bValidationCheck = 1; // Loop through all required inputs $(":input").filter("[required]").each(function(){ // Check if it has no value if($(this).val()=="" && bValidationCheck) { // If the value is empty/blank, they haven't filled in a required field, tell them so! alert("Please fill in all of the required fields!"); bValidationCheck = 0; $(this).focus(); return; } }); if(!bValidationCheck) return; // check that they aren't already ordering more than available // ============================================================ if (bShopLimitOrderByStockLevels==1) { // check bShopLimitOrderByStockLevels which defines whether to limit by stock levels (this comes from the Settings managed in the WSM) if(!bMultipleVariationsInTable) fStockCheck([nShopProd_ID], [nQty], nParentShopProd_ID, bCalledFromModal); else { var aShopProd_IDs = []; var aQtys = []; $("input[name$='_nQty']").each(function(){ aShopProd_IDs.push($(this).attr("name").replace("_nQty", "")); aQtys.push($(this).val()); }); fStockCheck(aShopProd_IDs, aQtys, nParentShopProd_ID, bCalledFromModal); } } else { // log this in goal tracking $.get("ajax/shop_basket_goal-track.php?nShopProd_ID="+nShopProd_ID, function(GoalScript) { $("head").append(GoalScript); }); // call add to basket go function if(!bMultipleVariationsInTable) fBuy_AddToBasket_Go([nShopProd_ID], [nQty], nParentShopProd_ID, bCalledFromModal); else { var aShopProd_IDs = []; var aQtys = []; $("input[name$='_nQty']").each(function(){ if(parseInt($(this).val())) { aShopProd_IDs.push($(this).attr("name").replace("_nQty", "")); aQtys.push($(this).val()); } }); fBuy_AddToBasket_Go(aShopProd_IDs, aQtys, nParentShopProd_ID, bCalledFromModal); } } } // function to check stock // ======================== function fStockCheck(aShopProd_IDs, aQtys, nParentShopProd_ID, bCalledFromModal) { // Check to see if all the stock is valid var bStockAllValid = 1; // For each product for(var i=0; i nStockAvailable) { // Mark this stock check as invalid bStockAllValid = 0; // log this in the goal tracking $.ajax({ url:"ajax/shop_basket_goal-track_out-of-stock.php?nShopProd_ID="+nShopProd_ID, async:false }).done(function(GoalScript) { $("head").append(GoalScript); }); // display an error message // work out how many are in the basket so this can be reflected in the error message (if applicable) $.ajax({ url:sAjaxURL_ForStockInBasket, async:false }).done(function(data) { // get the result $('.result').html(data); // save the results var nStockInBasket = parseInt(data); // populate the start of the error message var sError = "I'm sorry but we can't add the required quantity of this item into your basket because we don't have enough available.\n\nPlease find information below -:

"; // add information // qty user is trying to add sError += "Number you're trying to add to the basket: " + nQty + "

"; // qty available sError += "Number we have available: " + nStockAvailable + "

"; // qty in basket if (nStockInBasket>0) { sError += "Number already in your basket: " + nStockInBasket + "

"; } else { sError += "
"; } // If the dialog add to basket exists if( $("#dialogAddToBasket").length ) { // If dialog has been initalised if( $("#dialogAddToBasket").hasClass("ui-dialog-content") ) { // If the dialog is open if( $("#dialogAddToBasket").dialog('isOpen') === true ) { // Close it $("#dialogAddToBasket").dialog('close'); } } } // If we have some stock in basket if (nStockInBasket>0) { // Display the error message fShowPageMessage_WithAdditionalButton(sError + "\n", "View item in your basket", function() { // Redirect the user if they press the "View your basket" button location.href='en-GB//page_907'; }); } // we dont have stock in basket, it has just ran out else { // Show error fShowPageMessage(sError); } }); } // Its not out of stock so fire event else { // log this in the goal tracking $.ajax({ url:"ajax/shop_basket_goal-track.php?nShopProd_ID="+nShopProd_ID, async:false }).done(function(GoalScript) { $("head").append(GoalScript); }); } }); } // If all the stock checks are valid, send them through to the add to basket function if(bStockAllValid) fBuy_AddToBasket_Go(aShopProd_IDs, aQtys, nParentShopProd_ID, bCalledFromModal); } // add to basket go function // ========================= var aMessages = []; function fBuy_AddToBasket_Go(aShopProd_IDs, aQtys, nParentShopProd_ID, bCalledFromModal) { var oData = null; var nShopProd_ID = null; var nQty = null; var bItemAddedToBasket = 0; var sMessage = ""; // For each product, add it to the basket! for(var i=0; i= 0) { bItemAddedToBasket = 1; } // close the modal window (if this has been called from the modal) sMessage+= sData+"
"; }); } // this does something but nobody commented it. thanks for that if (bCalledFromModal==1) { $( "#dialogAddToBasket" ).dialog( "close" ); } // update the basket counter // eg if we have a basket counter in the header or something (eg showing X items in the basket), then this // will update that fShopBasketUpdateCounter(); // display confirmation message // should we display the confirmation message? // the website owner can choose whether to display a confirmation message // this is defined in tblSettings.eBasket_WhatToDoAfterAddingToBasket if ( ('Display confirmation message'=="Display confirmation message") || ('Display confirmation message'=="Display confirmation message, and go to the basket afterwards") ) { // show the confirmation message /* after showing this message (eg when pressing "close" on the modal), resulting actions will happen... See the line:- $("#page-message-modal").on("hidden.bs.modal", function(){ */ fShowPageMessage(sMessage); } else { // show the related items modal /* Normally this would be loaded by pressing the "Close" button on the confirmation message after adding to basket. However, as the confirmation message is disabled, we need to trigger this here */ if(bItemAddedToBasket) { // show related items (or in turn call redirect function - fBuy_AddToBasket_Redirect) fRelatedItemsModal_Show(nShopProd_ID); } } //alert(sData); // RELATED ITEMS SYSTEM / AFTER CLOSE BUTTON ON ADD TO BASKET CONFIRMATION MODAL IS CLICKED // ==================== // Check if item was successfully added to the basket if(bItemAddedToBasket) { /* load the related items window when you press the "Close" button on the confirmation modal after adding to basket */ $("#page-message-modal").on("hidden.bs.modal", function(){ if(aMessages.count > 0) return; // show related items (or in turn call redirect function - fBuy_AddToBasket_Redirect) fRelatedItemsModal_Show(nShopProd_ID); }); } // end if item successfully added to basket, check for related items } // related items modal function // ============================= /* The website has the functionality to show related items after you've added an item to the basket The idea is that you add item X to the basket, and after adding to the basket, you're asked if you'd like to purchae relevant items Y and Z This comes up in a modal, and will only display if the feature is enabled, if there are related items for the product just added to the basket, and if other criteria are set This function is called from the fBuy_AddToBasket_Go function. At the time of writing, this is in two scenarios (if the feature is enabled etc) :- 1) When you press the "Close" button on the confirmation modal message you get after adding an item to the basket 2) After adding the item to the basket if the confirmation modal message is disabled by the website owner in settings (note - you can reference the above in tblSettings.eBasket_WhatToDoAfterAddingToBasket) Note this function will also call fBuy_AddToBasket_Redirect which will redirect (if specified) if:- a) No related items are clicked on b) Related items feature is disabled c) No related items are found for this item */ function fRelatedItemsModal_Show(nShopProd_ID) { if(bRelatedItems) { // is the related items feature turned on for this website? // Check for related items for the product that has been added to basket // ===================================================================== // Create FormData() variable to pass information to AJAX file var oData = new FormData(); // Create string to store what's going into the modal var sModalData = ""; // Create array to store all related items so we can check if an item already exists before we store it in the modal data var aRelatedItems = new Array(); // Append trigger nShopProd_ID to related items array so the same item doesn't get shown as a related item that has just been bought aRelatedItems.push(parseInt(nShopProd_ID)); // Append nShopProd_ID to be passed through AJAX oData.append("nShopProd_ID", nShopProd_ID); // AJAX function to return all rules triggered by product added to basket $.ajax({ url: 'ajax/shop_basket_add_exec_related-item-rules_get-rules-for-trigger-product.php', method: 'POST', data: oData, processData: false, contentType: false }).success(function(sData){ // GET ALL RULES TRIGGERED BY THIS PRODUCT // ======================================= // Parse JSON Data to get rules var oRuleResult = JSON.parse(sData); // If the parsed data isn't empty, there are rules triggered by this product if(oRuleResult.length > 0) { // Set flag to 0 so we can check if new items exist for this rule that haven't already // been shown. If there aren't any new items then we won't store the rule explanation // as we won't want to show an empty rule with no related items, or a rule with duplicate // related items //var bNewItemsFlag = 0; // FOR EACH RULE // ============= // A callback function to parse the rule results and get related items for each rule function ajaxLoop(nCurrentIndex, nMaxIndex, oRuleResult) { // Create a string for HTML for each item for this rule to be shown in modal var sItemData = ""; // Get the rule id and store it to pass through with AJAX var nRule_ID = oRuleResult[nCurrentIndex].nShopRelatedItemsRule_ID; oData.append("nRule_ID", nRule_ID); // Get the rule explanation to store in the modal data later if there are related items for that rule var sExplanation = "
"+oRuleResult[nCurrentIndex].sExplanation+"
"; // GET RELATED ITEMS // ================= // Find all the related items for this rule $.ajax({ url: 'ajax/shop_basket_add_exec_related-item-rules_get-related-prods-for-a-rule.php', method: 'POST', data: oData, processData: false, contentType: false }).success(function(sData){ // Parse JSON Data to get related items var oResult = JSON.parse(sData); // Make sure new items flag is 0 before we start checking all the related items bNewItemsFlag = 0; // If there are related items... if(oResult.length > 0) { // For each related item, check if nShopProd_ID already exists in related items for(var i = 0; i < oResult.length; i++) { // Get nShopProd_ID and HTML for related item var nShopProd_ID = oResult[i]; var sHTML = oResult[i+1]; // Does nShopProd_ID already exist in related items array? if(aRelatedItems.indexOf(parseInt(nShopProd_ID)) < 0) { // If nShopProd_ID doesn't exist in array, store related item id in array to check for duplicates later aRelatedItems.push(parseInt(nShopProd_ID)); // Store the HTML for the new item in sItemData to be shown later in modal sItemData += sHTML; // Change flag to 1 as there are new things to show in modal bNewItemsFlag = 1; } // Increment counter so the for loop goes to the next shop prod in the array i++; } } // end if there are related items // If there are new items, put explanation and related items into a ModalData to append to modal-body for this rule later if(bNewItemsFlag == 1) { // div to surround rule and related items sModalData += '
'; // rule explanation sModalData += sExplanation; // related items, with the same article, section, and div surrounding them that they have on catalogue list sModalData += '
'+sItemData+'
'; // end of surrounding div sModalData += '
'; } // If we've looked at the last rule, we're done and can append the data and show the modal if(nCurrentIndex == nMaxIndex) { if(sModalData != "") { $('#relatedItemsModal .modal-body').html(sModalData); $('#relatedItemsModal').modal('show'); } } // If there are more rules to look at, run this callback function again but increase the current index else { ajaxLoop(nCurrentIndex+1, nMaxIndex, oRuleResult); } }); // end ajax function } // End of callback function // Call the AJAX function to loop through the rules ajaxLoop(0, oRuleResult.length-1, oRuleResult); } // end if parsed data isn't empty else { // if there are no related items, pass over to the redirect function fBuy_AddToBasket_Redirect() } }); // end ajax function for checking for rule // function to run if the user presses "no thanks" on related items modal $("#relatedItemsModal").on("hidden.bs.modal", function(){ // display the function to redirect afterwards (if applicable) fBuy_AddToBasket_Redirect() }); } else { // if related items feature isn't enabled, pass over to the redirect function fBuy_AddToBasket_Redirect() } }; // add to basket redirect function // ================================ /* This will add to the basket (if this option is set in tblSettings.eBasket_WhatToDoAfterAddingToBasket) This function is called when the adding to basket routine is finished. As adding to the basket can involve multiple scenarios (eg related items being shown, not being shown, etc), this funtion is called in multiple places As it needs to be called in multiple places, this is why this logic has been put into a seperate function */ function fBuy_AddToBasket_Redirect() { if ( ('Display confirmation message'=='Display confirmation message, and go to the basket afterwards') || ('Display confirmation message'=='Do not display confirmation message, and go to the basket afterwards') ) { // redirect to basket location.href='en-GB//page_907'; } } var bMessagesEventApplied = 0; function fShowPageMessages() { if(aMessages.length > 0) { var sMessage = aMessages.shift(); fShowPageMessage(sMessage); if(!bMessagesEventApplied) { bMessagesEventApplied = 1; $('#page-message-modal').on('hidden.bs.modal', function () { fShowPageMessages(); }); } } } function fShopProdOptions_LoadTradePriceBands (sCSSClassNaming, nShopProd_ID) { var bFilledIn = 0; var sVariationOptions = ""; if($(".ShopProd_"+sCSSClassNaming+"_OptionsDropDown").length) { $(".ShopProd_"+sCSSClassNaming+"_OptionsDropDown").each(function(){ if($(this).val()!="0") { bFilledIn++; sVariationOptions += $(this).val()+","; } }); if(bFilledIn<$(".ShopProd_"+sCSSClassNaming+"_OptionsDropDown").length || bFilledIn == 0) { sVariationOptions = ""; } } if (sVariationOptions!="") { // nShopProdOption_ID is specified - so go get the data $.ajax({ method: "POST", url: "ajax/catalogue_detail_trade-price-band-table-for-variations.php", data: {sCSSClassNaming:sCSSClassNaming, nShopProd_ID:nShopProd_ID, nShopProdVariationOption_IDs:sVariationOptions} }).done(function(msg){ $("#ShopProd_TradePriceBands").html(msg); }); } else { // no nShopProdOption_ID specified so empty the div $("#ShopProd_TradePriceBands").html(""); } } // close buy modal // ===================== function fBuy_Close() { // close the modal window $( "#dialogAddToBasket" ).dialog( "close" ); } // page numbers // ============= /* DEPRECATED 10TH FEB 2022 WE NO LONGER USE COOKIES TO SWITCH PAGES INSTEAD IT IS ALL IN THE $_GET FOR SIMPLICITY */ function fPageChange(nPageNo, reload) { if(typeof(reload) === 'undefined') { reload = true; } $.ajax({ data: 'nPageNumber=' + escape(nPageNo), url: 'ajax/pagination.php', type: 'POST', success: function(response) { if(reload) { $('html, body').animate({ scrollTop: 0 }, 0); var sURL = window.location.href; sURL = sURL.replace("reset", "pagechange"); window.location.href=sURL; //window.location.reload(); } }, error: function(response) { console.log(response); } }); } // ITEMS PER PAGE // =============== function fItemsPerPage(nItemsPerPage) { $.cookie('nItemsPerPage', nItemsPerPage); fPageChange(1,true); } // EMAIL TO A FRIEND // ================== // show modal box // =============== function fEmailToAFriend_Show() { // If the modal loaded has the class .is-dialog (meaning the user has selected to use modals in the shop settings) if( $("#dialogEmailToAFriend").hasClass("is-dialog") ) { // load the enquire modal as a modal $( "#dialogEmailToAFriend" ).dialog(); $( "#dialogEmailToAFriend" ).dialog( "option", "height", 650 ); $( "#dialogEmailToAFriend" ).dialog( "option", "width", 460 ); } // If the user doesn't want the enquiry form shown as a modal else { // Show the modal by sliding it down $("#dialogEmailToAFriend").slideDown("slow"); // Hide the enquire modal by sliding it up if( $("#dialogEmailEnquiry").length ) { $("#dialogEmailEnquiry").slideUp(0); } // Scroll to the element to ensure users can see the bloody thing! $([document.documentElement, document.body]).animate ( { scrollTop: $("#dialogEmailToAFriend").offset().top - 100 } , 700); } } // close modal box // =============== function fEmailToAFriend_Close() { // load the add to basket modal $( "#dialogEmailToAFriend" ).dialog( "close" ); } // submit form (form verification) // ================================ function fEmailToAFriend_Submit(nShopProd_ID) { // form fields var sYourName = document.getElementById('sEmailToAFriend_YourName').value; var sYourEmail = document.getElementById('sEmailToAFriend_YourEmail').value; var sTheirName = document.getElementById('sEmailToAFriend_TheirName').value; var sTheirEmail = document.getElementById('sEmailToAFriend_TheirEmail').value; // form verification var sErr = ""; if (sYourName=="") { sErr+="\n - Please enter your name"; } if (fCheckEmail(sYourEmail)=="invalid") { sErr+="\n - Your email address isn't valid"; } if (sTheirName=="") { sErr+="\n - Please enter your friend's name"; } if (fCheckEmail(sTheirEmail)=="invalid") { sErr+="\n - Your friend's email address isn't valid"; } if(!$("#bEmailToAFriend_PrivacyPolicy").is(":checked")) { sErr+="\n - Please tick the Privacy Policy box to confirm you've read our Privacy Policy before continuing."; } if (sErr!="") { alert("There were some problems submitting the form. Please see below:\n"+sErr); } else { // before we continue, check the google recaptcha var response = grecaptcha.getResponse( $('#recaptcha2').attr('data-widget-id') ); if (response.length > 0) { fEmailToAFriend_Process(nShopProd_ID); } else { alert("Please tick the checkbox in the anti-spam box"); } } // submit form via ajax } // submit form (process) // ================================ function fEmailToAFriend_Process(nShopProd_ID) { // form fields var sYourName = escape(document.getElementById('sEmailToAFriend_YourName').value); var sYourEmail = escape(document.getElementById('sEmailToAFriend_YourEmail').value); var sTheirName = escape(document.getElementById('sEmailToAFriend_TheirName').value); var sTheirEmail = escape(document.getElementById('sEmailToAFriend_TheirEmail').value); var bSubscribe = document.getElementById('bEmailToAFriend_Subscribe').checked; var response = grecaptcha.getResponse( $('#recaptcha2').attr('data-widget-id') ); var sRecaptchaResponse = response; // define AJAX url var sAjaxURL = "ajax/catalogue_detail_email-to-a-friend_exec.php?sYourName=" + sYourName + "&sYourEmail=" + sYourEmail + "&sTheirName=" + sTheirName + "&sTheirEmail=" + sTheirEmail + "&nShopProd_ID=" + nShopProd_ID + "&bSubscribe=" + bSubscribe + '&g-recaptcha-response=' + sRecaptchaResponse; // call ajax URL $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // If the dialog is a modal (As set in shop settings) if( $( "#dialogEmailToAFriend" ).is(':ui-dialog') ) { // Close the dialog $( "#dialogEmailToAFriend" ).dialog( "close" ); } // If it isn't a modal set else { // Close the dialog form $( "#dialogEmailToAFriend" ).slideUp("slow"); // Scroll the user back to items information $([document.documentElement, document.body]).animate ( { scrollTop: $("#CatDetail_DescDiv").offset().top - 75 } , 700); } // alert the results $("head").append(data); // Reset google recaptcha grecaptcha.reset( $('#recaptcha2').attr('data-widget-id') ); // Reset google recaptcha grecaptcha.reset( $('#recaptcha1').attr('data-widget-id') ); }); } // EMAIL ENQUIRY // ============== // show modal box // =============== function fEmailEnquiry_Show() { // If the modal loaded has the class .is-dialog (meaning the user has selected to use modals in the shop settings) if( $("#dialogEmailEnquiry").hasClass("is-dialog") ) { // load the enquire modal as a modal $( "#dialogEmailEnquiry" ).dialog(); $( "#dialogEmailEnquiry" ).dialog( "option", "height", 750 ); $( "#dialogEmailEnquiry" ).dialog( "option", "width", 460 ); } // If the user doesn't want the enquiry form shown as a modal else { // Show the modal by sliding it down $("#dialogEmailEnquiry").slideDown("slow"); // Close the dialog form for email to a friend if( $("#dialogEmailToAFriend").length ) { $("#dialogEmailToAFriend").slideUp(0); } // Scroll to the element to ensure users can see the bloody thing! $([document.documentElement, document.body]).animate ( { scrollTop: $("#dialogEmailEnquiry").offset().top - 100 } , 700); } } // close modal box // =============== function fEmailEnquiry_Close() { // Close the dialog $( "#dialogEmailEnquiry" ).dialog( "close" ); } // submit form (form verification) // ================================ function fEmailEnquiry_Submit(nShopProd_ID) { // form fields var sYourName = document.getElementById('sEmailEnquiry_YourName').value; var sYourEmail = document.getElementById('sEmailEnquiry_YourEmail').value; var sYourTel = document.getElementById('sEmailEnquiry_YourTel').value; var sEnquiry = document.getElementById('sEmailEnquiry_Enquiry').value; // form verification var sErr = ""; if (sYourName=="") { sErr+="\n - Please enter your name"; } if (fCheckEmail(sYourEmail)=="invalid") { sErr+="\n - Your email address isn't valid"; } if (sYourTel=="") { sErr+="\n - Please enter a contact number"; } if (sEnquiry=="") { sErr+="\n - Please enter your enquiry / message"; } if(!$("#bEmailEnquiry_PrivacyPolicy").is(":checked")) { sErr+="\n - Please tick the Privacy Policy box to confirm you've read our Privacy Policy before continuing."; } if (sErr!="") { alert("There were some problems submitting the form. Please see below:\n"+sErr); } else { // before we continue, check the google recaptcha var response = grecaptcha.getResponse( $('#recaptcha1').attr('data-widget-id') ); if (response.length > 0) { fEmailEnquiry_Process(nShopProd_ID); } else { alert("Please tick the checkbox in the anti-spam box"); } } // submit form via ajax } // submit form (process) // ================================ function fEmailEnquiry_Process(nShopProd_ID) { // form fields var sYourName = escape(document.getElementById('sEmailEnquiry_YourName').value); var sYourEmail = escape(document.getElementById('sEmailEnquiry_YourEmail').value); var sYourTel = escape(document.getElementById('sEmailEnquiry_YourTel').value); var sEnquiry = escape(document.getElementById('sEmailEnquiry_Enquiry').value); var bSubscribe = document.getElementById('bEmailEnquiry_Subscribe').checked; var response = grecaptcha.getResponse( $('#recaptcha1').attr('data-widget-id') ); var sRecaptchaResponse = response; // This isn't real, and is a hidden input to catch bots out var sEmailEnquiry_sMessage = escape(document.getElementById('sEmailEnquiry_sMessage').value); // define AJAX url var sAjaxURL = "ajax/catalogue_detail_enquiry_exec.php?sYourName=" + sYourName + "&sYourEmail=" + sYourEmail + "&sYourTel=" + sYourTel + "&sEnquiry=" + sEnquiry + "&nShopProd_ID=" + nShopProd_ID + '&bSubscribe=' + bSubscribe + '&g-recaptcha-response=' + sRecaptchaResponse + '&sEmailEnquiry_sMessage=' + sEmailEnquiry_sMessage; // call ajax URL $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // If the dialog is a modal (As set in shop settings) if( $( "#dialogEmailEnquiry" ).is(':ui-dialog') ) { // Close the dialog $( "#dialogEmailEnquiry" ).dialog( "close" ); } // If it isn't a modal set else { // Close the dialog form $( "#dialogEmailEnquiry" ).slideUp("slow"); // Scroll the user back to items information $([document.documentElement, document.body]).animate ( { scrollTop: $("#CatDetail_DescDiv").offset().top - 75 } , 700); } // alert the results $("head").append(data); grecaptcha.reset( $('#recaptcha2').attr('data-widget-id') ); grecaptcha.reset( $('#recaptcha1').attr('data-widget-id') ); }); } // MADE TO ORDER // ============== // show modal box // =============== function fMadeToOrder_Show(nShopProd_ID) { // load the made to order modal $( "#dialogMadeToOrder" ).dialog(); $( "#dialogMadeToOrder" ).dialog( "option", "height", 650 ); $( "#dialogMadeToOrder" ).dialog( "option", "width", 460 ); // get the add form page $.get('ajax/shop_basket_made-to-order_form.php?nShopProd_ID='+nShopProd_ID, function(data) { // get the result $('.result').html(data); // save to the empty div in the modal box we have just loaded $('#dialogMadeToOrder_Inner').append(data); }); } // close modal box // =============== function fMadeToOrder_Close() { // load the add to basket modal $( "#dialogMadeToOrder" ).dialog( "close" ); } // submit form (form verification) // ================================ function fMadeToOrder_Submit(nShopProd_ID) { // form fields var sYourName = document.getElementById('sMadeToOrder_Name').value; var sYourEmail = document.getElementById('sMadeToOrder_Email').value; var sYourTel = document.getElementById('sMadeToOrder_Tel').value; var sRequirements = document.getElementById('sMadeToOrder_Requirements').value; // form verification var sErr = ""; if (sYourName=="") { sErr+="\n - Please enter your name"; } if (fCheckEmail(sYourEmail)=="invalid") { sErr+="\n - Your email address isn't valid"; } if (sYourTel=="") { sErr+="\n - Please enter a contact number"; } if (sRequirements=="") { sErr+="\n - Please enter your requirements"; } if (sErr!="") { alert("There were some problems submitting the form. Please see below:\n"+sErr); } else { fMadeToOrder_Process(nShopProd_ID); } // submit form via ajax } // submit form (process) // ================================ function fMadeToOrder_Process(nShopProd_ID) { // form fields var sYourName = escape(document.getElementById('sMadeToOrder_Name').value); var sYourEmail = escape(document.getElementById('sMadeToOrder_Email').value); var sYourTel = escape(document.getElementById('sMadeToOrder_Tel').value); var sRequirements = escape(document.getElementById('sMadeToOrder_Requirements').value); // define AJAX url var sAjaxURL = "ajax/catalogue_detail_made-to-order_exec.php?sYourName=" + sYourName + "&sYourTel=" + sYourTel + "&sYourEmail=" + sYourEmail + "&sRequirements=" + sRequirements + "&nShopProd_ID=" + nShopProd_ID; // call ajax URL $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // close the modal window $( "#dialogMadeToOrder" ).dialog( "close" ); // alert the results fShowPageMessage(data); }); } // WISHLIST - ADD // ============== function fWishlist_Add_ShopProd(nShopProd_ID) { var sAjaxURL = "ajax/wishlist/wishlist_add_shopprod.php?nShopProd_ID=" + nShopProd_ID; $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // save the results var nWishlistItemCount = parseInt(data); // update counter in the header (if there is one) if($('#nWishlistItemCount').length) { document.getElementById('nWishlistItemCount').innerHTML=nWishlistItemCount; } // Confirm fShowPageMessage("Item added to 'Saved items'"); }); } function fUpdateCountdown(oElement, nMaxLength) { var ID = oElement.id.replace("inputfield",""); nMaxLength = nMaxLength - oElement.value.length; $('.sCountdown'+ID).text(nMaxLength); if(nMaxLength!=1) { $('.sCountdownPlural'+ID).text("s"); } else { $('.sCountdownPlural'+ID).text(""); } } /* * VARIATION SYSTEM * */ var sOriginalPriceRange = ''; var nNewShopProd_ID = 0; var nCurrentShopProd_ID = 0; function fUpdateDropdowns() { // We do these in order that we find them. if (typeof aOptionsArray !== 'undefined') { var aTmpArray = aOptionsArray; var sCombination = ""; var bAllFound = 1; $("select[name$='nShopProdVariationOption_ID']").each(function(){ // First, get it's currently selected option var nCurrentVal = $(this).val(); // For each option it CAN have, check it exists in this context, if it doesn't, hide it $(this).children().each(function(){ if(!aTmpArray.hasOwnProperty($(this).attr("value")) && $(this).attr("value") != "0") { $(this).hide(); } else { $(this).show(); } }); // Check if it IS in the array, if it IS, set aTmpArray to it, if it isn't, set our value to 0 if(aTmpArray.hasOwnProperty(nCurrentVal)) { // Add it to the combination if(sCombination == "") { sCombination = nCurrentVal; } else { sCombination += "_" + nCurrentVal; } aTmpArray = aTmpArray[nCurrentVal]; } else { $(this).val('0'); bAllFound = 0; } }); // If all options were found, get the combination ID, price and stock count if(bAllFound == 1) { if(sOriginalPriceRange=="") { sOriginalPriceRange = $(".ShopProd_"+sCSSClassNaming+"_Price_MainPrice").html(); } nNewShopProd_ID = aCombinationsArray[sCombination]; var oShopProd = aShopProdArray[nNewShopProd_ID]; if(bTrade == 0) { $(".ShopProd_"+sCSSClassNaming+"_Price_MainPrice").html(oShopProd.nTotal); } $("#nStockTotal").val(oShopProd.nStockTotal); } // If not, reset price and stock else { if(sOriginalPriceRange!="") { $(".ShopProd_"+sCSSClassNaming+"_Price_MainPrice").html(sOriginalPriceRange); } $("#nStockTotal").val(0); } } }