// 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; }); } // 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(nShopProd_ID) { // load the add to basket modal $( "#dialogAddToBasket" ).dialog(); $( "#dialogAddToBasket" ).dialog( "option", "height", 350 ); $( "#dialogAddToBasket" ).dialog( "option", "width", 350 ); // get the add form page $.get('ajax/shop_basket_add_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 document.getElementById('dialogAddToBasket_Inner').innerHTML=data; }); } // add to basket button // ===================== function fBuy_AddToBasket(nShopProd_ID) { // check that they aren't already ordering more than available // ============================================================ if (document.getElementById('bShopLimitOrderByStockLevels').value=="1") { // check the hidden field with bShopLimitOrderByStockLevels which defines whether to limit by stock levels (this comes from tblSettings in the DB) // check whether there are options for this product if (document.getElementById('nProdOptionCount').value>0) { // there are options var sAjaxURL = "ajax/shop_basket_already-in-basket.php?nShopProd_ID="+nShopProd_ID+"&nShopProdOption_ID="+document.getElementById('nShopProdOption_ID').value; } else { // no options var sAjaxURL = "ajax/shop_basket_already-in-basket.php?nShopProd_ID="+nShopProd_ID; } // work out how many of this item are already in the basket $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // save the results var nStockAlreadyInBasket = parseInt(data); /// get the stock count if (parseInt($('#nProdOptionCount').val()) == 0) { var nStockCount = $('#nStockCount').val(); } else { var nStockCount = $('input[name="nStockCount_option_' + $('#nShopProdOption_ID').val() + '"]').val(); } // check to see if the qty being ordered is greater than the amount in stock + amount already in basket if (parseInt(document.getElementById('nQty').value) > (parseInt(nStockCount) - parseInt(nStockAlreadyInBasket))) { sError = "Sorry there aren't enough of this item in stock to be able to add "+document.getElementById('nQty').value+" to your basket."; if (parseInt(nStockAlreadyInBasket)>0) { sError+= "\n\n\nThere is "+nStockCount+" in stock, and "+nStockAlreadyInBasket+" already in your basket. Did you realise you already had this item in your basket?"; } else { sError+= "\n\n\nThere is "+nStockCount+" in stock."; } sError+="\n\n\nPlease change the amount you're trying to order or contact us about availability if you need more than we have available"; alert(sError); } else { // call add to basket go function fBuy_AddToBasket_Go(nShopProd_ID); } }); } else { // call add to basket go function fBuy_AddToBasket_Go(nShopProd_ID); } } // add to basket button // ===================== function fBuy_AddToBasket_Go(nShopProd_ID) { // work out the URL to call if (document.getElementById('nProdOptionCount').value>0) { // work out if there are options // thera are options var sAjaxURL = 'ajax/shop_basket_add_exec.php?nShopProd_ID='+nShopProd_ID+'&nShopProdOption_ID=' + document.getElementById('nShopProdOption_ID').value + '&nQty='+document.getElementById('nQty').value; } else { // there are no options var sAjaxURL = 'ajax/shop_basket_add_exec.php?nShopProd_ID='+nShopProd_ID+'&nQty='+document.getElementById('nQty').value; } // call the add basket exec page $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // close the modal window $( "#dialogAddToBasket" ).dialog( "close" ); // alert the results alert(data); }); // update the basket counter fShopBasketUpdateCounter(); } // add to basket button // ===================== function fBuy_Close() { // close the modal window $( "#dialogAddToBasket" ).dialog( "close" ); } // page numbers // ============= 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) { window.scrollTo(0,0); window.location.reload(); } }, error: function(response) { console.log(response); } }); } // ITEMS PER PAGE // =============== function fItemsPerPage(nItemsPerPage, bTop) { $.cookie('nItemsPerPage', nItemsPerPage); // Get values var nCurrentItemsPerPage = $("input[name='nItemsPerPage']").val(); var nCurrentPageNo = $("input[name='nPageNo']").val(); var nTotalItems = $("input[name='nProdCount']").val(); if(bTop) { var nProductID = $(".ProductListing").first().attr("data-productid"); } else var nProductID = $(".ProductListing").last().attr("data-productid"); $.cookie('nProductToScrollTo', nProductID); if(nCurrentPageNo > 1) { // Work out items seen already var nItemsSeenAlready = nCurrentItemsPerPage*(nCurrentPageNo-1); // Work out how many pages worth to skip var nNewPageNo = Math.ceil((nItemsSeenAlready+1)/nItemsPerPage); // Change to the new page fPageChange(nNewPageNo, true); } else { fPageChange(1,true); } } $(window).on("load", function(){ if (typeof $.cookie('nProductToScrollTo') !== 'undefined'){ if($(".ProductListing[data-productid='"+$.cookie('nProductToScrollTo')+"']").length) { $("html, body").animate({ scrollTop: $(".ProductListing[data-productid='"+$.cookie('nProductToScrollTo')+"']").offset().top-20}, 10); } $.removeCookie("nProductToScrollTo"); } }); // EMAIL TO A FRIEND // ================== // show modal box // =============== function fEmailToAFriend_Show() { // load the add to basket modal $( "#dialogEmailToAFriend" ).dialog(); $( "#dialogEmailToAFriend" ).dialog( "option", "height", 350 ); $( "#dialogEmailToAFriend" ).dialog( "option", "width", 350 ); } // 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 (sErr!="") { alert("There were some problems submitting the form. Please see below:\n"+sErr); } else { fEmailToAFriend_Process(nShopProd_ID); } // submit form via ajax } // submit form (process) // ================================ function fEmailToAFriend_Process(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; // 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; // call ajax URL $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // close the modal window $( "#dialogEmailToAFriend" ).dialog( "close" ); // alert the results alert(data); }); } // EMAIL ENQUIRY // ============== // show modal box // =============== function fEmailEnquiry_Show() { // load the add to basket modal $( "#dialogEmailEnquiry" ).dialog(); $( "#dialogEmailEnquiry" ).dialog( "option", "height", 420 ); $( "#dialogEmailEnquiry" ).dialog( "option", "width", 350 ); } // close modal box // =============== function fEmailEnquiry_Close() { // load the add to basket modal $( "#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 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 (sEnquiry=="") { sErr+="\n - Please enter your enquiry / message"; } if (sErr!="") { alert("There were some problems submitting the form. Please see below:\n"+sErr); } else { fEmailEnquiry_Process(nShopProd_ID); } // submit form via ajax } // submit form (process) // ================================ function fEmailEnquiry_Process(nShopProd_ID) { // form fields var sYourName = document.getElementById('sEmailEnquiry_YourName').value; var sYourEmail = document.getElementById('sEmailEnquiry_YourEmail').value; var sEnquiry = document.getElementById('sEmailEnquiry_Enquiry').value; // define AJAX url var sAjaxURL = "ajax/catalogue_detail_enquiry_exec.php?sYourName=" + sYourName + "&sYourEmail=" + sYourEmail + "&sEnquiry=" + sEnquiry + "&nShopProd_ID=" + nShopProd_ID; // call ajax URL $.get(sAjaxURL, function(data) { // get the result $('.result').html(data); // close the modal window $( "#dialogEmailEnquiry" ).dialog( "close" ); // alert the results alert(data); }); } // dimension handler function fShowInches() { // hide metric and show inches $('#metric').stop().animate({"top" : "50px"}); $('#inches').stop().animate({"top" : "0px"}); $('#metricHandler').removeClass('selectedDimension'); $('#inchesHandler').addClass('selectedDimension'); fDimensionCookieSet('inches'); } function fShowMetric() { // hide inches and show metric $('#metric').stop().animate({"top" : "0px"}); $('#inches').stop().animate({"top" : "50px"}); //$('#inches').slideUp(); //$('#metric').slideDown(); // change the colours of the handlers $('#metricHandler').addClass('selectedDimension'); $('#inchesHandler').removeClass('selectedDimension'); fDimensionCookieSet('metric'); } function fDimensionCookieSet(sDimensionType){ $.ajax({ data: 'sDimensionType=' + sDimensionType, type: 'post', url: 'ajax/dimension-cookie-set.php', success: function(response) { //No response required } }); } function fDimensionHandler() { $('#questionHandler').fadeIn(); } function fDimensionHandlerHide() { $('#questionHandler').fadeOut(); } // show sales enquiry field function fSalesEnquiry() { $('.topSection').fadeOut(); $('#salesEnquiry').delay(500).fadeIn(); $('#name').focus(); } function fHideEnquiry() { $('#salesEnquiry').fadeOut(); $('.topSection').delay(500).fadeIn(); }