/*** /live_chat.js **********************************/ function liveChatInit(liveChatHref, isOnProductAlternatives){ try{ //alert('liveChatInit starts...'); if(!liveChatHref){ return; } var els = $$('a.live_support'); var len = els.length; var strippedHref = liveChatHref.gsub('&', '&'); strippedHref = strippedHref.gsub('&', '&'); for(var i = 0; i < len; i++){ els[i].href = strippedHref; } var iframes = $$('iframe'); var len1 = iframes.length; for(var j = 0; j < len1; j++){ var iframe_doc = getIframeDocument(iframes[j]); if(iframe_doc){ els = iframe_doc.getElementsByName('live_support'); len = els.length; for(i = 0; i < len; i++){ if(els[i].tagName == 'A' || els[i].tagName == 'a'){ els[i].href = strippedHref; // Remove onClick els[i].onclick = ''; } } } } }catch(e){ // do nothing alert('exception'); } /* if(isOnProductAlternatives == 'true'){ // open LiveChat window eval(strippedHref); } */ } /** This function was added to prevent exceptions if the access to iframe.contentWindow.document is denied */ function getIframeDocument(iframe){ try{ if(iframe.contentWindow.document){ return iframe.contentWindow.document; }else{ return false; } }catch(e){ return false; } } /*** /product_lookup.js **********************************/ /** * Retrieves all My Catalogue items */ function findAllCatalogueFolders(onLoad) { $('foldersContainer').update(''); createFolder(0, false, false); } /** * function retrieves all categories and populates the container. * * @param Function onLoad function called when the records have loaded. */ function findAllCategories (onLoad) { if(lookup) { $('browsing-panel-category-2').innerHTML = ''; return lookup.findAllCategories('browsing-panel-category-1', function (id) { findAllSubCategories('browsing-panel-category-2', id, null, null); }, onLoad); } return false; } /** * retrieves a list of new categories */ function findAllNewCategories () { if (lookup) { $('browsing-panel-new-2').innerHTML = ''; return lookup.findAllNewCategories('browsing-panel-new-1', function (id) { findAllSubCategories('browsing-panel-new-2', id, 'new', null); }); } return false; } /** * retrieves a list of clearance categories */ function findAllClearanceCategories () { if (lookup) { $('browsing-panel-clearance-2').innerHTML = ''; return lookup.findAllClearanceCategories('browsing-panel-clearance-1', function (id) { findAllSubCategories('browsing-panel-clearance-2', id, 'clearance', null); }); } return false; } /** * retrieves a list of all manufacturers */ function findAllManufacturers (letter, onLoad) { $('browsing-panel-man-2').innerHTML = ''; $('browsing-panel-man-3').innerHTML = ''; if (lookup) { if (!letter) { letter = 'A'; } return lookup.findAllManufacturers(letter, 'browsing-panel-man-1', function (id) { findAllCategoriesForManufacturer(id); }, onLoad); } } /** * retrieves all categories for a manufacturer */ function findAllCategoriesForManufacturer (vendor) { $('browsing-panel-man-3').update(''); return lookup.findAllCategoriesForManufacturer(vendor, 'browsing-panel-man-2', function (id) { findAllSubCategories('browsing-panel-man-3', id, null, vendor); }); } /** * function retrieves all sub-categories into the designated * container. */ function findAllSubCategories(container, parentId, status, vendor, onLoad) { Products.Listing.retainAll(); $(container).innerHTML = ''; var productListingContainer = $('product-listing-container'); if (productListingContainer) { productListingContainer.innerHTML = ''; } productInquiry.fire(ProductInquiry.Event.PRODUCT_LISTING_REMOVED); return lookup.findAllSubCategories(parentId, status, vendor, container, function (id) { status = status == 'null' ? '' : status; findProducts(id, status, vendor); }, onLoad); } /** * Function returns a list of products */ function findProducts(categoryId, status, vendorId) { if (lookup.webroot) { productInquiry.setWebroot(lookup.webroot); } productInquiry.findProducts(categoryId, status, vendorId); return false; } /** * Function selects a category by loading the list then * highlighting the item. * * @param Number categoryId The id of the category */ function selectCategory(categoryId) { findAllCategories(function (e) { ProductLookup.selectItem('browsing-panel-category-1', 'category_' + categoryId); findAllSubCategories('browsing-panel-category-2', categoryId); }); } /** * Function selects a sub category by loading the list then * highlighting the item of the category * and the sub category. * * @param Number categoryId The id of the category * @param Number subCategoryId The id of the sub-category */ function selectSubCategory(categoryId, subCategoryId) { findAllCategories(function (e) { ProductLookup.selectItem('browsing-panel-category-1', 'category_' + categoryId); findAllSubCategories('browsing-panel-category-2', categoryId, null, null, function (e) { ProductLookup.selectItem('browsing-panel-category-2', 'category_' + subCategoryId); findProducts(subCategoryId); }); }); } /** * Function selects a manufacturer and displays all categories * for it. * * @param Number vendorId The manufacturer */ function selectManufacturer(vendorId, firstLetter) { var tab = $('power_search-2-link'); tab.tabs.select(2); findAllManufacturers(firstLetter, function (e) { ProductLookup.selectItem('browsing-panel-man-1', 'vendor_' + vendorId); findAllCategoriesForManufacturer(vendorId); }); } /** * Retrieves alternative products contact information * * @access public * @param string productId The id of the product for which to find alternatives * @param string|Node update The container to update * @param source The source of the request * @return void */ function showAlternatives(url, productId, update, source) { //alert('showAlternatives('+url+', '+productId+', '+update+')'); //alert('update('+update+'): ' + $(update)); var sourceParam = (source ? '?source=' + source : ''); var container = document.getElementById(update); if (!container) { update = 'product-alternatives-container-orders'; } new Ajax.Updater( update, url + productId + '/' + update + '/true' + sourceParam, { 'evalScripts': true } ); } /** * Clears the product listing container */ function clearProductListing() { Products.Listing.retainAll(); if ($('product-listing-container')) { $('product-listing-container').update(''); } if ($('productListing')) { $('productListing').update(''); } } /** * Object handles the searching for products using * the Search Products tab. * * @author Dimitry Zolotaryov */ var ProductSearch = { form: null, parent: null, results: null, activeRequest: null, addFields: null, addFieldsOn: true } /** * Initializes the product search * * @param string|Node form The search form * @param string|Node results The results container */ ProductSearch.initialize = function(form, results, id) { this.form = $(form); this.results = $(results); if (!id) { id = 'product-search'; } this.id = id; // Finds the parent var parent = this.form; while (parent && (parent.nodeName.toLowerCase() != 'div' && parent.nodeName.toLowerCase() != 'table')) { parent = parent.parentNode; } this.parent = parent || this.form; this.title = $(id + '-form-title'); this.tips = $(id + '-tips'); Event.observe(this.form, 'submit', ProductSearch.submitForm.bindAsEventListener(this)); this.addFields = new Array(); var form = this.form; var inputs = this.form.getElementsByTagName('input'); for (var i = 0, c = inputs.length; i < c; i++) { var input = inputs[i]; if (input.type == 'text' && input.id && input.id.match(/^UniProduct/)) { Event.observe(input, 'keypress', ProductSearch.onEnter.bindAsEventListener(this)); var name = input.id.replace(/^UniProduct/, ''); if (name != 'ProductCode' && name != 'Keyword') { this.addFields.push(input.parentNode.parentNode); } } } Event.observe( this.getFormElement('keyword'), 'keyup', this.checkFieldState.bind(this) ); Event.observe( this.getFormElement('product_code'), 'keyup', this.checkFieldState.bind(this) ); this.checkFieldState(); } ProductSearch.KeywordRefinementFields = [ 'manufacturer', 'size', 'weight', 'color' ]; /** * Returns the full form element name (i.e. the value of the name attribute) * corresponding to the specified search field name * * @param String fieldName the abbreviated element name (e.g. 'keyword', 'manufacturer') * * @return HTMLElement */ ProductSearch.getFormElementName = function(fieldName) { return 'data[UniProduct][' + fieldName + ']'; } /** * Returns the form element that corresponds to the specified * search field name * * @param String fieldName the abbreviated element name (e.g. 'keyword', 'manufacturer') * * @return HTMLElement */ ProductSearch.getFormElement = function(fieldName) { return $(this.form.elements[this.getFormElementName(fieldName)]); } /** * Enables the form field with the specified name and removes * "disabled" styling * * @param String fieldName the abbreviated element name (e.g. 'keyword', 'manufacturer') * * @return HTMLElement */ ProductSearch.enableField = function(fieldName) { var field = this.getFormElement(fieldName); if (field !== null && field.disabled) { field.disabled = false; field.removeClassName('disabled'); } } /** * Sets the source identifier to configure the product listings * * @param string source the new source */ /** * Disables the form field with the specified name and adds * "disabled" styling * * @param String fieldName the abbreviated element name (e.g. 'keyword', 'manufacturer') * * @return HTMLElement */ ProductSearch.disableField = function(fieldName) { var field = this.getFormElement(fieldName); if (field !== null && !field.disabled) { field.disabled = true; field.addClassName('disabled'); } } /** * Enables or disables the form field with the specified name and styles * it accordingly, depending on the value of the enabled argument * * @param String fieldName the abbreviated element name (e.g. 'keyword', 'manufacturer') * @param bool enabled whether the field should be enabled or disabled * * @return HTMLElement */ ProductSearch.setFieldEnabled = function(fieldName, enabled) { if (enabled) { this.enableField(fieldName); } else { this.disableField(fieldName); } } /** * Ensures that * * - The keyword refinement fields ("Refine your Keyword Search:") are only * available if there are keywords * * - All keyword-related fields are disabled when there is a product code * - The product code is disabled if there are keywords */ ProductSearch.checkFieldState = function() { var keywordField = this.getFormElement('keyword'); var productCodeField = this.getFormElement('product_code'); var keywordFieldEnabled = productCodeField.value == ''; var keywordRefinementFieldsEnabled = keywordFieldEnabled && keywordField.value != ''; var productCodeFieldEnabled = keywordField.value == ''; this.setFieldEnabled('keyword', keywordFieldEnabled); $A(ProductSearch.KeywordRefinementFields).each( function(fieldName) { this.setFieldEnabled(fieldName, keywordRefinementFieldsEnabled); }.bind(this) ); this.setFieldEnabled('product_code', productCodeFieldEnabled); } /** * Returns the search form to its initial state */ ProductSearch.clear = function() { this.form.reset(); this.checkFieldState(); } /** * Hack event handler for submitting the form. * See the form for notes. * * @param Event event The event */ ProductSearch.onEnter = function (event) { if (!event) event = window.Event; if (event.keyCode && event.keyCode == Event.KEY_RETURN) { this.submitForm(event); } } /** * Fired when the user goes from one tab to another, regardless * of sequence */ ProductSearch.onTabChanged = function() { productInquiry.fire(ProductInquiry.Event.PRODUCT_LISTING_REMOVED); } /** * Function called when the form is submitted. * * @param Event event The event object */ ProductSearch.submitForm = function (event) { if (!this.form) { return; } if (event) { Event.stop(event); } this.results.innerHTML = ''; if( this.activeRequest != null ) { if( this.activeRequest.transport ) { this.activeRequest.transport.abort(); } this.activeRequest = null; } productInquiry.fire(ProductInquiry.Event.LOADING); var reqOptions = { method: 'post', parameters: Form.serialize(this.form), evalScripts: true }; this.activeRequest = new Ajax.Updater(this.results, this.form.action, reqOptions); this.hideForm(); } /** * Toggles the additional search fields on and off * */ ProductSearch.toggleAdditionalFields = function () { if (!this.form) { return; } var display = null; if (this.addFieldsOn) { var display = 'none'; this.addFieldsOn = false; } else { if (document.all) { // MSIE var display = 'block'; } else { var display = 'table-row'; } this.addFieldsOn = true; } for (var i = 0, c = this.addFields.length; i < c; i++) { this.addFields[i].style.display = display; } } /** * Hides the form * */ ProductSearch.hideForm = function () { this.form.collapse(); this.title.collapse(); if( this.tips ) this.tips.collapse(); productInquiry.fire(ProductInquiry.Event.PRODUCT_LISTING_REMOVED); } /** * Shows the form. * * If the first parameter is set to true (default), * the user is redirected to the search page when no * valid form object is found or has not been assigned. * * @param Boolean redirect Redirects the user to the search page if ProductSearch.initialize not called */ ProductSearch.showForm = function () { if (!this.parent) { window.location.href = Paths.www + '/pages/power_search/search_products/'; return; } this.results.innerHTML = ''; this.parent.style.display = ''; this.form.expand(); this.title.expand(); if( this.tips ) this.tips.expand(); this.onShowForm(); } /** * Callback function called whenever the form * is displayed. */ ProductSearch.onShowForm = function () { return; } ProductSearch.dispaySubCategoryList = function(categoryId, matched, source) { var fieldName = (matched) ? 'category_id' : 'unmatched_category_id'; var url = Paths.www + '/UniProducts/powerSearchProducts/?data[UniProduct][' + fieldName + ']=' + categoryId + '&source=' + source; new Ajax.Updater( 'subcategory-search-results', url, { evalScripts: true } ); } /*** /character_limit.js **********************************/ CharacterLimit = Class.create(); CharacterLimit.prototype = { initialize: function(id, limit) { this.limit = limit; this.element = $(id); this.countElement = $(id + '-character-count'); Event.observe( this.element, 'keyup', this.onChange.bindAsEventListener(this) ); this.onChange(); }, checkLimit : function() { if (this.element.value.length > this.limit) { this.element.value = this.element.value.substr(0, this.limit); } }, updateCounter : function() { var count = this.limit - this.element.value.length; this.countElement.update(count); }, onChange: function() { this.checkLimit(); this.updateCounter(); } }; /*** /unisource/calendar.js **********************************/ /** * A convenience class that helps retrieve dates from calendars * in the form of JavaScript Date objects. */ UniCalendar = Class.create(); UniCalendar.prototype = { monthSelector : null, daySelector : null, yearSelector : null, initialize : function(id) { this.id = id; if($(id)) { this.attach(); } else { Event.observe( window, 'load', this.attach.bindAsEventListener(this) ); } }, attach: function() { this.yearSelector = $(this.id); this.monthSelector = $(this.id + '-mm'); this.daySelector = $(this.id + '-dd'); this.yearSelector.unicalendar = this; }, getDate : function() { var date = new Date(); date.setMonth(this.monthSelector.value - 1); date.setDate(this.daySelector.value); date.setFullYear(this.yearSelector.value); return date; }, isDateValid : function() { return Date.isValidDate( this.monthSelector.value - 1, this.daySelector.value, this.yearSelector.value ); } }; Date.REGEX_ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})/; Date.prototype.setISODate = function(isoDate) { var matches = isoDate.match(Date.REGEX_ISO_DATE); if (!matches) { throw new BadDateFormatException(isoDate); } this.setYear(matches[1]); this.setMonth(matches[2] - 1); this.setDate(matches[3]); this.setHours(0); this.setMinutes(0); this.setSeconds(0); }; BadDateFormatException = Class.create(); BadDateFormatException.PREFIX = 'BAD DATE FORMAT - '; BadDateFormatException.prototype = Object.extend(new UniException(), { initialize : function(dateString) { this.dateString = dateString; UniException.prototype.initialize.apply( this, [BadDateFormatException.PREFIX + dateString] ); } } ); Date.MONTH_LENGTHS = [ 31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] Date.MIN_YEAR = 1980; Date.MAX_YEAR = 2999; Date.MIN_MONTH = 0; Date.MAX_MONTH = 11; Date.MIN_DAY = 1; Date.MAX_DAY = 31; Date.FEBRUARY = 1; Date.FEBRUARY_LEAP_DAYS = 29; Date.FEBRUARY_REGULAR_DAYS = 28; Date.isValidDate = function(month, day, year) { var valid = ( (year >= Date.MIN_YEAR && year <= Date.MAX_YEAR) && (month >= Date.MIN_MONTH && month <= Date.MAX_MONTH) && (Date.isValidDay(month, day, year)) ); return valid; }; Date.isValidDay = function (month, day, year) { var valid; if (day < Date.MIN_DAY || day > Date.MAX_DAY) { valid = false; } if (month == Date.FEBRUARY) { valid = (Date.isLeap(year)) ? (day <= Date.FEBRUARY_LEAP_DAYS) : (day <= Date.FEBRUARY_REGULAR_DAYS); } else { valid = (day <= Date.MONTH_LENGTHS[month]); } return valid; }; Date.isLeap = function(year) { var leap; if (year % 4 != 0) { leap = false; } else if (year % 100 == 0) { leap = (year % 400 == 0); } else { leap = true; } return leap; }; /*** /product_utility.js **********************************/ // Selects the li element with id='id' in a container with id='into' function preselectCategory(into, id) { window.setTimeout( function() { var li_list = $(into).getElementsByTagName('li'); for(var i=0; i < li_list.length; i++) { if (li_list[i].id == id ) { $(li_list[i]).addClassName('selected'); break; } } }, 50 ); }