'; } else { price_change_warning_container.style.display = 'none'; price_change_warning_container.innerHTML = ''; } } checkForPriceChange(); $(document).ready( function() { // Prepopulate Zip Code container if we know what it is already var zip_code = localStorage.getItem("rws_cart_zip"); var zip_code_container_original_html = ""; if ( zip_code == null ) { // Check consumer profile instead zip_code = ''; if ( zip_code != null && zip_code.length <= 0 ) zip_code = null; } var shipping_valid = false; if ( typeof zip_code != 'undefined' && zip_code != null ) { document.getElementById('zip').value = zip_code; checkShipping(function() { $('#add_to_cart_button').removeClass('disabled'); prepopulateZipCodeContainer(); }); } $('#add_to_cart_button.disabled').parent().click(function () { if ( zip_code == 'undefined' || zip_code == null ) { $('#zip').css('border','1px solid red'); $('#zip_error').html("Please enter your zip code"); } }); }); // Instantiate the object (via local storage, or a blank slate AddToCartManager.setup('ASHLEY:B560B4'); // Set up the controls on this page populateAddToCartFields(); // Add to Cart AJAX functions // Set the cart type to order and add to cart function addToCartAJAX() { AddToCartManager.setTypeOrder(); if ( onSaveInitial() == false ) return; // If the site has the appropriate columns set to NA, do not show item level delivery // Show Item Level delivery by default $('#add_to_cart_initial_container').slideToggle(200); $('#delivery_container').slideToggle(200); modifyAddToCartButtonHandler(function(){ completeAddAJAX(); }); } // Set the cart type to quote and add to cart function addToQuoteAJAX() { AddToCartManager.setTypeQuoteRequest(); onSaveInitial(); // Skip delivery options for quote request completeAddAJAX(); } // Add to cart function completeAddAJAX() { AddToCartManager.setDeliveryType($("input:radio[name='DELIVERY']:checked").val()); AddToCartManager.setQuantity($('#quantity').val()); if ( typeof zip_code != 'undefined' ) { AddToCartManager.setZipCode(zip_code); } AddToCartManager.addToCart(afterAddToCart); } function onSaveInitial() { // Check if this MaxShippingDistance call evaluated properly, unless we have a zip code already if ( typeof zip_code != 'undefined' && zip_code == null && shipping_valid == false ) { $('#add_to_cart_button').addClass('disabled'); $('#zip_error').html("Please Enter A Valid Zip Code"); $('#zip').parent().addClass("has-error"); return false; } AddToCartManager.setWarrantyLength($("input:radio[name='warranty']:checked").val()); AddToCartManager.setSellAsId($('input[name=SELL_AS_ID]:checked').val()); setPackages(); setRelatedItems(); setAddOns(); return true; } function onBackDelivery() { $('#add_to_cart_initial_container').slideToggle(200); $('#delivery_container').slideToggle(200); modifyAddToCartButtonHandler(function(){ addToCartAJAX(); }); } function modifyAddToCartButtonHandler(new_handler) { $('#add_to_cart_button').attr('onclick', ''); $('#add_to_cart_button').attr('onclick', ''); $('#add_to_cart_button').unbind('click'); $('#add_to_cart_button').click(new_handler); } function setPackages() { // Assemble a list of pick group ids var pick_group_ids = []; var pick_group_inputs = $('input[id^="pick_group_selector_"]'); for ( var i = 0; i < pick_group_inputs.length; i++ ) { var id = $(pick_group_inputs[i]).attr('id'); var id_key = id.substring("pick_group_selector_".length, id.length); var pick_group_id = id_key.substring(0, id_key.indexOf("_")); if ( $.inArray(pick_group_id, pick_group_ids) == -1 ) { pick_group_ids.push(pick_group_id); } } for ( var i = 0; i < pick_group_ids.length; i++ ) { var id = pick_group_ids[i]; var key = $('input[name=pick_group_selector_'+id+']:checked').val(); AddToCartManager.setPickGroupOption(id, key); } } function setRelatedItems() { // Look through all controls on page that start with the RELATED_ and grab the keys from them to add to the JSON $.each($('[id^="RELATED_"]'), function(index, input) { if ( input.checked == true ) { var id = $(input).attr('id'); var key = id.replace("RELATED_",""); AddToCartManager.addRelatedItemKey(key); } }); } function setAddOns() { // Look through all controls on page that start with the RELATED_ and grab the keys from them to add to the JSON $.each($('[id^="INC_"]'), function(index, input) { if ( input.checked == true ) { var id = $(input).attr('id'); var key = id.replace("INC_",""); AddToCartManager.addAddOnKey(key); } }); } function populateAddToCartFields() { if ( AddToCartManager.getQuantity() >= 0 ) $('#quantity').val(AddToCartManager.getQuantity()); if ( AddToCartManager.getWarrantyLength() >= 0 ) $('#warranty').val(AddToCartManager.getWarrantyLength()); } function postalFilter (postalCode) { if (! postalCode) { return false; } postalCode = postalCode.toString().trim(); var us = new RegExp("^\\d{5}(-{0,1}\\d{4})?$"); var ca = new RegExp(/([ABCEGHJKLMNPRSTVXY]\d)([ABCEGHJKLMNPRSTVWXYZ]\d){2}/i); if (us.test(postalCode.toString())) { return true; } if (ca.test(postalCode.toString().replace(/\W+/g, ''))) { return true; } return false; } function sanitizeZipCode(zip) { var zipcode = zip.toUpperCase(); zipcode = zipcode.trim(); // if characters are found in the zip code, we will treat it as a Canadian postal code if (zipcode.search(/[A-Z]/) > -1 && (zipcode.length === 6 && zipcode[3] !== ' ')) { zipcode = zipcode.slice(0,3) + ' ' + zipcode.substring (zipcode.length-3); return zipcode } return zip; } function checkShipping(success_handler) { var zipInput = document.getElementById('zip'); var zip = zipInput.value.toUpperCase(); zipInput.value = sanitizeZipCode(zip) var is_quote = true; is_quote = false; if ( postalFilter(zip) ) { $('#zip_error').html(""); $('#add_to_cart_button').removeClass('disabled'); MaxShippingDistance.checkSimpleNoWaitFade('ASHLEY:B560B4', zip, is_quote, createAfterZip(success_handler)); } else { $('#add_to_cart_button').addClass('disabled'); $('#zip_error').html("