$(window).on("unload", function(e){ }); $(function(){ var changedCombos = false; var viewingPartDetails = showingPartDetails(); // Populate the combos from any values in localStorage if(!viewingPartDetails) { changedCombos = populateCombosFromLocalStorage(); } if(localStorage.getItem('free_text') != undefined && localStorage.getItem('free_text') != ''){ // update the free text - text value (shown to the user) $('#free-text').html(localStorage.getItem('free_text')); // trigger the change event in to determine if the removeClass should be invoked to grey out the text or not. if($('#free-text').html() != 'Enter Part Details (e.g. Ford Focus 2008 Petrol Engine)'){ // Clear the initial suggest message. $('#free-text').removeClass('free-text-suggest'); } } // if we don't have a "Z" then we DO NOT want to trigger a change // other wise we end up not being able to show a part if the user has selected one. // If any of the combos have been changed then fire the search again if(!viewingPartDetails && changedCombos){ $('#free-text-search-btn').trigger('click'); } // Add an event listener for the shipping description combo. $(".shipping-select-combo").change(function(e) { // Find the selected option's description from the data attribute 'desc' var ship_desc = $(this).find('option:selected').data('desc'); // update the text of the shipping description to be the value of the changed select $(this).siblings(".shipping-option-description").html('
Shipping Description

' + ship_desc + '

'); }); // Adds a listener to the reset button on the search_criteria.php (part lookup) $('.search_reset').on('click', function(e){ // Abort any currently running AJAX calls. abortAllAjax(); e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); // Reset any of the PHP Session information. $.ajax({ type: 'GET', url: "https://www.carparts-uk.com/ops/resetVRMPartLookup.php?opsId=global", processData: false, complete: function(jqXHR, textStatus) { resetUI(); } }); }); // Adds a click event to the cookie_accept identifier. $('.cookie_accept, .mobile_cookie_accept').on('click', function(eventObject){ eventObject.preventDefault(); eventObject.stopImmediatePropagation(); // Check to see if we have local storage available. if ('localStorage' in window && window['localStorage'] !== null) { localStorage.setItem('COOKIES_ACCEPTED', 'true'); // hide the cookie warning from the display. // Now that the localStorage has been set the next time the // local storage is accessed it should get written to the $_COOKIE variable $(".cookie-warning").hide(); } }); $('#reglookup #submit').on('click', function(eventObject){ eventObject.preventDefault(); eventObject.stopImmediatePropagation(); var vrm = $('#reglookup input[name=regNumber]').val(); if(vrm == 'ENTER REG'){ $('#regNumber, #regNumberSearch #submit').prop('disabled', false); return false; } // hide any currently visible info or error message $('.info_msg, .err_msg').hide(); // in the named container "reglookup" find an attribute of the tag called "action" var action = $('#reglookup').attr('action'); // see if we can set the PartsLookupService reg_number value. // Which is only valid for a parts by VRM lookup. $('#part_lookup_reg_number').val(vrm); var vin = ""; var data = {"vehicleRegistrationMark": vrm, "vehicleIdentificationNumber": vin}; function error_msg(err){ $('#reglookup').unbind(); $('#reglookup').find('input[name=regNumber]').prop('disabled', true); $('#vehicleDetailsFromReg').html('

'+err+'

'); $('#vehicleDetailsFromReg').slideDown(500); } var ajax = $.ajax({ dataType: "json", type: 'POST', url: action, data: JSON.stringify(data), contentType: 'application/json', processData: false, success: function(jsonData, textStatus, jqXHR) { if(jsonData.error_msg != undefined && jsonData.error_msg != ''){ error_msg(jsonData.error_msg); $('#regNumber, #regNumberSearch #submit').prop('disabled', false); }else if(jsonData.type == 'hpi_vin_decoder'){ matchHpi(jsonData); $('#regNumber, #regNumberSearch #submit').prop('disabled', false); }else if (jsonData.vrmmatch != undefined && jsonData.vrmmatch == "true") { window.location.href = jsonData.location; }else { doFreeTextSearch(jsonData); $('#regNumber, #regNumberSearch #submit').prop('disabled', false); } }, error: function(jqXHR, textStatus, errorThrown){ error_msg('Sorry, unable to find vehicle details at this time.'); } }); }); $('#tabs').on('click', function(e){ e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); $('.active_ovs_tab').addClass('inactive_ovs_tab').removeClass('active_ovs_tab'); $(e.target).addClass('active_ovs_tab vehicleSelected').removeClass('inactive_ovs_tab'); }); $('.shoppingCartContainerButton').on('click', function(e){ e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); $('#shoppingCartContentsTable_div').toggle(); $('#showShoppingCartContents_yes').toggle(); $('#showShoppingCartContents_no').toggle(); }); // adds an onClick event handler to the dismiss button of the PayPal message which informs users that there is // not a requirement to pay by PayPal $('.paypal_notification').on('click', function(eventObject){ //set the cookie to stop this message from showing to the user in the future. setCookie("payPalNotRequiredNotification", "notDisplay", 1); }); // Initialise the add to cart facility. initAddToCart(); $(window).on('hashchange', function(e){ restorePageStateFromHash(e); if(ga != undefined) ga('send', 'pageview', '/?page=' + window.location.hash); if(ga != undefined) ga('opsTracker.send', 'pageview', '/?page=' + window.location.hash); }); $(window).on('load', function(e){ restorePageStateFromHash(e); if(ga != undefined) ga('send', 'pageview', '/?page=' + window.location.hash); if(ga != undefined) ga('opsTracker.send', 'pageview', '/?page=' + window.location.hash); }); });