var Product = {}; $load_library('SHARED', 'ajax_functions.js'); $load_library('SHARED', 'Product/external.js'); $load_library('SHARED', 'Product/social.js'); $load_library('SHARED', 'protozoom.js'); Product.alert = (function(alert_message, additional_options, track_alert) { CMSTemplate.alert(alert_message, additional_options); if(!track_alert) CMSTemplate.Site.Analytics.addEvent('Product', 'Alert', alert_message); }); document.addEventListener("DOMContentLoaded", function() { let form_obj = Product.getInstance('Form'), form_elm = form_obj.getElement('addProduct'); if(form_elm) { form_obj.watchElements(); form_elm.addEventListener('submit', Product.Cart.Submit.bind(this)); } Product.Rating = new ProductRating(window.starcount); Product.External.getInstance(); new Product.Social(); if(CMSTemplate.getSetting('large_order') !== null) { form_obj.getElement('quantity').addEventListener('change', function() { if(form_obj.getElement('quantity').getValue() > 1) alert(CMSTemplate.getSetting('large_order')); }); } if(form_elm) form_obj.updatePrice(); new Product.Comments(); }); Product.Image = Class.create({ initialize: function(options) { if(Product.Image.initialized) return false; Product.Image.initialized = this; Product.Image.Hooks = { FileName: [this.mainFilename.bind(this)], Failure : [], Loading : [] }; this.options = Object.extend({ currentImage: -1, imageZoom : function(evt) {}, imageSelect : this.imageSelect.bind(this) }, options || {}); this.main_image = document.getElementById('main-image'); this.product_image = document.getElementById('product-image'); this.image_selector = $$('.image-selector a'); this.image_link = this.main_image.down('a.image-link') || document.createElement('a'); this.image_title_text = document.getElementById('image_title_text') || document.createElement('div'); this.fail_notice = this.main_image.down('.fail-notice') || document.createElement('div'); this.main_video = document.getElementById('main-video') || document.createElement('div'); this.image_link.addEventListener('click', this.zoomImage.bind(this)); this.product_image.addEventListener('error', this.imageFailure.bind(this, this.product_image, 'medium')); this.product_image.addEventListener('load', this.imageLoaded.bind(this)); this.thumbnails = {}; counter = 0; this.image_selector.each(function(x) { var imageId = x.readAttribute('id'); if(imageId === null) { // For legacy templates (v. 1, 2, 3) imageId = counter++; x.setAttribute('id', 'selectImage' + imageId); } else { imageId = imageId.replace('selectImage', ''); } x.addEventListener('click', function(evt) { evt.stopPropagation(); evt.preventDefault(); this.changeImage(imageId); }.bind(this)); this.thumbnails[imageId] = x.down('img.thumb-image'); if(this.thumbnails[imageId]) { this.thumbnails[imageId].store('image_id', imageId) .addEventListener('error', this.imageFailure.bind(this, this.thumbnails[imageId], 'thumb')); } }.bind(this)); }, cartPrimaryImage: function() { if(typeof this.cart_primary_image === 'undefined') { this.cart_primary_image = {}; ['large', 'medium', 'thumb'].each(function(x) { this.cart_primary_image[x] = new Element('input', { type: 'hidden', name: 'cartImage[' + x + ']' }); }.bind(this)); var add_product = Product.getInstance('Form') .getElement('addProduct'); if(typeof add_product.insert !== 'undefined') { add_product.insert(this.cart_primary_image.large); add_product.insert(this.cart_primary_image.medium); add_product.insert(this.cart_primary_image.thumb); } } this.cart_primary_image.large.setValue(Product.Image.List[0].filenames.large); this.cart_primary_image.medium.setValue(Product.Image.List[0].filenames.medium); this.cart_primary_image.thumb.setValue(Product.Image.List[0].filenames.thumb); }, getSelectedImage: function() { return this.product_image; }, zoomImage: function(evt) { if(this.product_image.hasClassName('load-fail')) { Product.alert('The image failed to load. This error has been logged and we are working to get it resolved.'); } this.options.imageZoom(evt); }, displayYouTubeVideo: function(imageId) { var image = Product.Image.List[imageId]; var video_iframe = ''; this.main_video.update(video_iframe); return this; }, /** * @deprecated legacy video viewer; all videos should be youtube now * @param {Integer} imageId Image id with video */ displayVideo: function(imageId) { var image = Product.Image.List[imageId], v = new SWFObject('{$const.HTTP_SHARED}/swf/player.swf', 'player', 326, 227, '9'); v.addParam('allowfullscreen', 'true'); v.addParam('allowscriptaccess', 'always'); v.addParam('wmode', 'transparent'); v.addParam('flashvars', 'file={$const.HTTP_VIDEOS}/' + image.video + '&image=' + image.image_directory + '/medium/' + image.image_filename + '&plugins=googlytics-1&autostart=true&stretching=exactfit'); v.write('main-video'); }, mainFilename: function(image_info) { if(!image_info.filenames) { image_info.filenames = { thumb : image_info.thumb_image, medium: image_info.medium_image, large : image_info.large_image }; } }, showVideo: function(hide) { if(typeof this.main_video_loc === 'undefined') this.main_video_loc = this.main_video.up('#main-image') ? true : false; if(!hide) { this.main_video .update('') .hide(); this.product_image.show(); if(!this.main_video_loc) this.main_image.show(); } else { this.main_video.show(); this.product_image.hide(); if(!this.main_video_loc) this.main_image.hide(); } return this; }, imageFailure: function(element, size) { if(element.hasClassName('load-fail')) return false; element.addClassName('load-fail'); var newImageName = null; Product.Image.Hooks.Failure.each(function(x) { newImageName = x(element, size); }); if(newImageName === null) { var image_id = element.retrieve('image_id'); var image_info = Product.Image.List[image_id]; if(!image_info) return false; var image_url = image_info[size + '_image']; if(!image_url) image_url = null; } CMSTemplate.Site.Analytics.addEvent('Product Image', 'Failure', element.readAttribute('src')); element.writeAttribute('src', image_url); if(size === 'medium') this.showImageFailure(true); return true; }, showImageFailure: function(show) { if(show) { this.fail_notice.update('There was a problem showing this product image. This may be due to the option\ not being in the system or a network problem. You are being shown the default image for this product, and it may\ not reflect selected options.'); } this.fail_notice[show ? 'show' : 'hide'](); return this; }, _createLoading: function() { this.loading_div = new Element('div') .addClassName('loading-img') .update(new Element('div').addClassName('loading-img-icon')); this.main_image.insert({ top: this.loading_div }); }, imageLoading: function() { if(!this.loading_div) this._createLoading(); else if(!this.loading_div.visible()) this.loading_div.show(); }, imageLoaded: function() { if(this.loading_div && this.loading_div.visible()) this.loading_div.hide(); }, changeImage: function(imageId) { if(!Product.Image.List[imageId]) return false; this.options.currentImage = imageId; var image = Product.Image.List[imageId]; Product.Image.Hooks.FileName.each(function(x) { x(image); }); if(this.product_image.readAttribute('src') === image.filenames.large) return this; if(CMSTemplate.Site.Analytics.experimentDisableScene7 && image.filenames.medium.indexOf('scene7.com') !== -1) { image.filenames.medium = image.image_directory + '/medium/' + image.image_filename; /** same rule used to load original image - image.tpl */ image.filenames.large = image.image_directory + '/large/' + image.image_filename; } this.imageLoading(); this.showImageFailure(false); this.product_image.store('image_id', imageId) .removeClassName('load-fail') .writeAttribute('src', image.filenames.large) .writeAttribute('alt', image.alt_text); this.image_title_text.update(image.alt_title); this.main_image.down('a').writeAttribute('href', image.filenames.large). writeAttribute('title', image.alt_title.unescapeHTML().replace(/(\"\;|\”\;)/g, '"').replace(/(\’|\')/g, '\'')); if(image.video) this.displayVideo(imageId).showVideo(true); else if(image.youtube) this.displayYouTubeVideo(imageId).showVideo(true); else this.showVideo(false); this.options.imageSelect(imageId); return this; }, imageDeselect: function() { this.image_selector.each(function(x) { x.removeClassName('selected'); }); return this; }, redrawImages: function(initialize) { if(initialize) this.options.currentImage = 0; if(this.options.currentImage === -1) return; Product.Image.List.each(function(image, image_id) { Product.Image.Hooks.FileName.each(function(x) { x(Product.Image.List[image_id]); }); if(this.thumbnails && this.thumbnails[image_id]) { var image = Product.Image.List[image_id]; if(CMSTemplate.Site.Analytics.experimentDisableScene7 && image.filenames.thumb.indexOf('scene7.com') !== -1) { image.filenames.thumb = image.image_directory + '/medium/' + image.image_filename; } this.thumbnails[image_id].setAttribute('src', image.filenames.thumb); this.thumbnails[image_id].setAttribute('data-img', image.filenames.thumb); this.thumbnails[image_id].classList.toggle('load-fail'); } }.bind(this)); this.changeImage(this.options.currentImage); }, imageSelect: function(imageId) { this.imageDeselect(); var select_image = $('selectImage' + imageId); if(select_image) select_image.addClassName('selected'); return this; } }); /** * @deprecated */ checkOptionImage = (function() {}); Product.Image.initialized = false; Product.Image.Hooks = {}; Product.Image.Zoomy = Class.create(Product.Image, { initialize: function($super) { if(!$super({imageSelect: this.imageSelect.bind(this)}) === false) return false; new Zoomy(this.image_link, { isZoomable: this.isZoomable.bind(this) }); return true; }, isZoomable: function() { return !this.product_image.hasClassName('load-fail'); } }); Product.Discount = Class.create({ initialize: function(disc) { this.discs = !disc ? [] : disc.reverse(); }, /** * Determine the volume discount for this product * * @param {Number} quant Quantity desired * @return {Number} */ getVolumeDiscount: function(quant) { var res = 1.00; this.discs.each(function(disc) { if(quant >= disc.qty) { res = 1 - (disc.discount / 100); throw $break; } }); return res; } }); Product.Calculator = Class.create({ initialize: function() { this.option = new Product.Options(); this.calculations = 0; this.cache = {}; // Cache of warning messages this._msg_cache = []; }, getDirection: function(calc_param, option_id) { if(!calc_param && typeof option_id !== 'undefined') calc_param = window.calcparam.index(option_id); if(!calc_param) return false; var direction_name = Product.Calculator.Directions.get(calc_param); if(!direction_name) return false; var dir_id = this.getValue(direction_name); if(!this.option.isDisabled(dir_id)) { var direction = window.poption.get(dir_id).get(this.option.getValue(dir_id)).get('calc'); return direction; } return false; }, /** * Return calculator parameter value that would be used for calculators * @param {String} param_name */ getParamaterValue: function(param_name) { var option_id = this.getValue(param_name); if(option_id === false) return null; var value_id = this.option.getValue(option_id); return window.poption.get(option_id).get(value_id).get('calc') || null; }, /** * Get's the value from a calculator form parameter * @param {String} param_name */ getValue: function(param_name) { if(!window.calc_parameters || !window.calc_parameters[param_name]) return false; var value_id = null; window.calc_parameters[param_name].each(function(value_id_test) { option_value = this.option.findElement(value_id_test); if(option_value && !option_value.disabled) { value_id = value_id_test; throw $break; } }.bind(this)); return value_id; }, getElement: function(calc_param) { return this.option.findElement(this.getValue(calc_param)); }, getUserValue: function(param_name) { let option_id = this.getValue(param_name); if(option_id !== null) option_id = this.option.getSelectedValue(option_id); return option_id; }, displayWarning: function (warning) { if(typeof warning.SEAM !== 'undefined' || typeof warning.PAPASAN_SEAM !== 'undefined') { if(typeof warning.PAPASAN_SEAM !== 'undefined') { let warningMessage = '
Due to the size of the cushion, visible seams may be present on the top and bottom of the cushion and will not be able to be hidden.
'; $j("#seam_warning_papasan").show(); $j("#seam_warning").hide(); } else { let warningMessage = 'Due to the direction of the fabric pattern, visible seams may be present on the top and bottom of the cushion and will not be able to be hidden.
To prevent this, you will need to change the direction of the fabric on your order.
'; $j("#seam_warning_papasan").hide(); $j("#seam_warning").show(); } if (!$j('#mute').prop.checked) { toggleModal('seam_warning_modal', true); } } }, _calcSuccess: function(call_number, cache_key, upcharge, transport) { if(cache_key !== null) this.cache[cache_key] = transport; if(call_number !== this.calculations) return; var form_obj = Product.getInstance('Form'); if(!transport.responseText.isJSON() || !isNaN(transport.responseText)) { form_obj.postPrice(transport.responseText === 'undefined' ? false : (transport.responseText + upcharge)); return; } var jreturn = transport.responseText.evalJSON(); if(!jreturn.success) form_obj.postPrice(false); else form_obj.postPrice(jreturn.price + upcharge); if(typeof callback !== 'undefined' && typeof window[callback] !== 'undefined') window[callback](jreturn, product_options); var err_list = this._parseMessages(jreturn.messages); if(err_list !== '') Product.alert(err_list, false); if(typeof jreturn.warnings !== 'undefined') this.displayWarning(jreturn.warnings); if(jreturn.option_prices) new Product.Options().setExtraPrice(jreturn.option_prices); }, _parseMessages: function(messages) { var errors = [], message_list = [], warn_list = []; if(!messages || !messages.size()) { Product.last_error = ''; this._msg_cache = []; return ''; } messages.each(function(x) { var msg = x.message; if(x.severity > 3) errors.push(msg); else warn_list.push(msg); if(this._msg_cache.indexOf(msg) === -1) message_list.push(msg); }.bind(this)); // If errors, we want to prevent users from carting item Product.last_error = errors.join("\n"); this._msg_cache = warn_list; return message_list.join("\n"); }, _calcFailure: function(call_number, transport) { if(call_number !== this.calculations) return; var form_object = Product.getInstance('Form'); var try_again = { type : 'button', text : 'Try again', click: form_object.updatePrice.bind(form_object) }; Product.alert('There was a problem communicating with the server. Please contact customer service if you continue to experience this problem.', [try_again]); form_object.postPrice(false); }, recalculate: function(ajax_url, params, upcharge) { if(!params) params = {}; if(!upcharge) upcharge = 0; var current = ++this.calculations; var product_options = new Product.Options().clearExtraPricing(); query_params = Object.toQueryString(params); var additional_pricing = product_options.getExtraPricing(params); if(additional_pricing.size()) query_params += '&' + additional_pricing.join('&'); var cache_key = ajax_url + query_params; if(this.cache[cache_key]) { this._calcSuccess(current, null, upcharge, this.cache[cache_key]); return; } new Ajax.Request(Product.Calculator.API_ENDPOINT + ajax_url + '&price', { method: 'post', parameters: query_params, onSuccess: this._calcSuccess.bind(this, current, cache_key, upcharge), onFailure: this._calcFailure.bind(this, current) }); } }); Product.Calculator.API_ENDPOINT = '/content/calculator_shared.php?calc='; Product.Calculator.CALC_METHOD = 'cart_calculate'; Product.Form = Class.create({ initialize: function() { this.loaded = false; this.option_obj = new Product.Options(); this.discount = new Product.Discount(window.discount); }, watchElements: function() { let update_price = this._retrieveCache('updatePrice'); let update_price_click = this._retrieveCache('updatePrice_click'); let form = document.getElementById('addProduct'); if(!update_price) { update_price = form.querySelectorAll('.updatePrice'); update_price_click = form.querySelectorAll('.updatePrice_click'); this._storeCache('updatePrice', update_price) ._storeCache('updatePrice_click', update_price_click); } update_price.forEach(elm => { elm.addEventListener('change', evt => this.updatePrice(evt)); elm.addEventListener('keypress', evt => this.stopSubmit(evt)); }); update_price_click.forEach(elm => { elm.addEventListener('click', evt => this.updateRadioPrice(elm, evt)); }); this.checkConditions(); // Get the default form options so we can toss up a message if user leaves with data filled in this.form_defaults = form.serialize(); return this; }, watchUnload: function(new_options) { if(typeof INTERNAL_USER !== 'undefined') return this; if(!new_options) { window.onbeforeunload = null; } else { window.onbeforeunload = (function(x) { return 'There are options that were changed on this product. Are you sure you want to leave this page?'; }); } return this; }, stopSubmit: function(evt) { if(evt.which === Event.KEY_RETURN || evt.keyCode === Event.KEY_RETURN) Event.stop(evt); }, isRadioOutOfStock: function(elm) { var elm = elm.up('.ppRadOptionsItem'); return elm && elm.readAttribute('data-remaining') === "0"; }, updateRadioPrice: function(elm, evt) { evt.cancelBubble = true; if(evt.stopPropagation) evt.stopPropagation(); if(this.isRadioOutOfStock(evt.element())) { Event.stop(evt); evt.out_of_stock = true; return Product.alert('The option you selected is currently out of stock, please select another option.'); } var radio_input = elm.down('input'); if(!radio_input.checked) { radio_input.checked = true; this.updatePrice(evt); } }, updatePrice: function(evt) { if(evt) Event.stop(evt); var price = window.baseprice; var upcharge = 0.0; var use_ajax_func = null; var use_function = false; // Make sure no new conditions have been met and need to be activated this.checkConditions(); var current_options = this.getElement('addProduct').serialize(true); if(!current_options.Quant) return; this.priceLoading(true); window.poption.each(function(option) { var key = option.key; var value = option.value; var ajax_info = value.get('ajax'); if(ajax_info) { var ajax_file = ajax_info.get('file'); var func = ajax_info.get('func') || Product.Calculator.CALC_METHOD; if(!func || !ajax_file || use_ajax_func === func) return; use_ajax_func = func; var fn = window[func]; if(typeof fn !== 'function') return; use_function = fn.bind(document.window, ajax_file); return; } var option_val = current_options['OptionList[' + key + '][1]']; var option_info = value.get(option_val); if(!option_info || typeof option_val === 'undefined') return; if(option_info.get('percentage')) upcharge += (price * (option_info.get('percentage') / 100)); else if(option_info.get('price')) upcharge += option_info.get('price'); }); if(use_function !== false) use_function(upcharge, current_options); else this.postPrice(price + upcharge); // Change images if neccessary if(this.loaded && Product.Image.initialized) Product.Image.initialized.redrawImages(); else this.loaded = true; this.watchUnload(this.form_defaults !== this.getElement('addProduct').serialize()); setTimeout(recordProductOption(evt), 0); }, priceLoading: function(show) { var updating_price = this.getElement('.ppPriceUpdating', true); if(updating_price.length !== 0) { updating_price.invoke(show ? 'show' : 'hide'); return; } // Legacy image loader if(show !== true) return; this.getElement('price') .insert(' ') .insert(new Element('img', { src: '{$const.HTTP_SHARED}/img/loading.gif' })); }, changePrice: function(new_price) { var update_price = this.getElement('.ppPrice', true); if(update_price.length === 0) update_price = this.getElement('#price', true); update_price.invoke('update', new_price); return true; }, changeBulkDiscounts: function(new_price) { var update_elm = this.getElement('.bulkDiscountPrice', true); if(!update_elm.length) return; update_elm.each(function(elm) { var discount = elm.getAttribute('data-discount-rate'); if(!discount) return; elm.update(addCommas(this.ceiling(new_price - (new_price * (discount * 0.01))))); }.bind(this)); }, getElement: function(element_name, class_selector) { var result = this._retrieveCache(element_name); if(typeof result === 'undefined') { result = !class_selector ? $(element_name) : $$(element_name); if(!result) result = null; } return result; }, _storeCache: function(key, value) { Product.Form.cache[key] = value; return this; }, _retrieveCache: function(key) { if(typeof(Product.Form.cache[key]) === 'undefined') return undefined; else return Product.Form.cache[key]; }, getQuantity: function() { var qty_field = this.getElement('quantity'); var qty = parseInt(qty_field.getValue()) || 1; // Change to 1 if NaN if(typeof(quantity) !== 'undefined' && qty > quantity) { qty = quantity; Product.alert('There are only ' + quantity + ' of these items in stock, your quantity has been set to ' + quantity + '.'); } if(qty >= 999 || qty <= 0) qty = 1; qty_field.setValue(qty); return qty; }, /** * Change price displayed * @param {Float|Boolean} price Price to display. If price is false, shows customer that price was unavailable */ postPrice: function(price) { var qty = this.getQuantity(); this.priceLoading(false); // Error with pricing if(isNaN(price) || price === false) { this.changePrice(price === false ? '--.-- (Price Unavailable)' : price); Product.Cart.changeStatus(true); // Disable the submit button document.querySelectorAll('.ppCartButton').forEach(button => { button.disabled = true; }); return; } else { // Enable the submit button if the price is valid document.querySelectorAll('.ppCartButton').forEach(button => { button.disabled = false; }); } Product.Cart.changeStatus(false); yourDiscount = this.discount.getVolumeDiscount(qty) || 1; if(this.getElement('price-before-discount')) this.getElement('price-before-discount').update(price); if(this.getElement('discount-amount')) this.getElement('discount-amount').update(yourDiscount); var single_qty_price = price; if(yourDiscount !== 1.0) { price *= yourDiscount; price = this.ceiling(price, 2); } if(this.getElement('price-no-qty')) this.getElement('price-no-qty').update(this.ceiling(price, 2)); price *= qty || 1; // Show the price this.changePrice(addCommas(price)); this.changeBulkDiscounts(single_qty_price); if(this.getElement('discounts')) { if(yourDiscount < 1) this.getElement('discounts').update(parseInt((100 - yourDiscount * 100)) + '% discount'); else this.getElement('discounts').update(''); } }, ceiling: function(value, precision) { if(!precision) precision = 2; precision = Math.pow(10, parseInt(precision)); value = parseFloat(value) * precision; value = Math.ceil(value); return (value / precision); }, _conditionalItem: function(current_options, pair) { var cond_opt_value = current_options['OptionList[' + pair.key + '][1]']; pair.value.each(function(opt_hide_pair) { var opt_changed; if(!cond_opt_value || opt_hide_pair.value.indexOf(parseInt(cond_opt_value)) === -1) { opt_changed = this.option_obj.changeHiddenStatus(opt_hide_pair.key, true); } else { opt_changed = this.option_obj.changeHiddenStatus(opt_hide_pair.key, false); } if(opt_changed && this._opt_changed === false) this._opt_changed = true; }.bind(this)); }, /** * Check conditionals and turn on/off if neccessary * @param {Integer} [recurse_count] Number of times method has recursed */ checkConditions: function(recurse_count) { var current_options = this.getElement('addProduct') .serialize(true); if(!recurse_count) recurse_count = 0; this._opt_changed = false; window.conditions.each(this._conditionalItem.bind(this, current_options)); // If there were any changes we need to cycle back through a max of five times ... if(this._opt_changed && recurse_count < 5) this.checkConditions(++recurse_count); } }); Product.Form.cache = {}; class ProductRating { constructor(cur_rating) { let stars_elm = document.getElementById('ppStars'); if(!stars_elm) return; this.stars = stars_elm.querySelectorAll('.ppStar'); this.stars.forEach((elm, count) => { ++count; elm.addEventListener('mouseover', count => this.rebuildStars(count)); elm.addEventListener('mouseout', () => this.rebuildStars(false)); elm.addEventListener('click', this.submitStar.bind(this, count)); }); this.setNewDefault(cur_rating); } rebuildStars(new_count) { if(new_count === false) new_count = this.default_count; this.stars.forEach(function(elm, count) { if(new_count > count) elm.classList.add('selected'); else elm.classList.remove('selected'); }); } setNewDefault(cur_rating) { this.default_count = cur_rating; this.rebuildStars(false); return this; } submitStar(count) { fetch('/ajax/product/rating/add?product_id=' + window.product_id + '&rate=' + count) .then(response => response.json()) .then(response => { if(!response.success) { Product.alert(response.message); return; } this.setNewDefault(response.rating); Product.alert('Your vote has been counted.', [ { type: 'title', value: 'Success' } ]); }) .catch(() => alert('Unable to save your feedback')); } } Product.Cart = ({ canSubmit: true, cartable : true, hasSteps : false, changeStatus: function(status) { Product.Cart.cartable = !status; }, isCartable: function() { return Product.Cart.cartable; }, Events: { onFailure: [], onSuccess: [] }, Submit: function(evt) { if(!evt) evt = null; else Event.stop(evt); Product.Cart.canSubmit = true; if(!Product.Cart.cartable) { Product.Cart.canSubmit = false; var cart_fail_message = 'There are errors that need correcting before this product can be carted.'; if(Product.last_error !== '' && Product.last_error.length <= 125) { cart_fail_message += "\n" + Product.last_error; } Product.alert(cart_fail_message); Product.Cart.Events.onFailure.each(function(failureCallback) { failureCallback(evt); }); } else { Product.Cart.Events.onSuccess.each(function(successCallback) { successCallback(evt); }); } if(Product.Cart.canSubmit) { if(!Product.Cart.hasSteps) { recordProductCustomization('1', 'All Steps'); } Product.getInstance('Form') .watchUnload(false) .getElement('addProduct') .submit(); } } }); Product.Options = Class.create({ initialize: function() { this.form = this.findElement('addProduct', 'default'); this.get_fabric = false; this.show_actual = true; this.show_upcharges = false; }, getForm: function() { return this.form; }, getValueDesc: function(option_id) { var val_desc = this._retreiveCache(option_id, 'val_desc'); if(val_desc === undefined) { var option_elm = this.getSelectedElement(option_id); if(option_elm !== false) { val_desc = option_elm.up() .down('.value_description'); if(typeof val_desc !== 'undefined') val_desc = val_desc.innerHTML.strip(); else val_desc = ''; } else { val_desc = ''; } this._storeCache(option_id, 'val_desc', val_desc); } return val_desc; }, buildSelectedOptions: function() { var return_list = []; this.getOptionList().each(function(option_id) { var option_name = this.findElement(option_id, 0); var option_value = this.getUserValue(option_id); if(option_name.disabled || !option_value) return; return_list.push({ name : option_name.getValue(), id : option_id, value: option_value, desc : this.getValueDesc(option_id) }); }.bind(this)); return return_list; }, /** * Draw Options * New templates build a "product configuration" area * @return {Boolean} If element is found, returns true otherwise returns false */ drawOptions: function() { var option_list = this.findElement('optionlist', 'default'); if(!option_list) return false; var current_step = null; var table = new Element('table'); var counter = 0; this.buildSelectedOptions().each(function(option) { var step_id = this.getStepId(option.id); if(step_id === false) { throw $break; } else if(step_id != current_step) { table.insert(new Element('tr').insert( new Element('th', {colspan: 2}) .addClassName('voltab-titlel') .update(this.getStepTitle(step_id))) ); current_step = step_id; } var row = new Element('tr') .addClassName(counter++ % 2 ? 'row' : 'rowalt').insert( new Element('td') .addClassName('title') .update(option.name) ).insert( new Element('td') .addClassName('pp-Litem') .update(option.value + ' ' + option.desc) ); table.insert(row); }.bind(this)); if(current_step !== null) { option_list.update( new Element('div') .addClassName('ppLContent') .addClassName('nobord') .update('