/*********************************************************************** * * getCartItem - Gets the Actinic Cart Value & No of Items * * Input: nIndex - Cart item index to retrieve * 1 = TOTAL_VALUE * 3 = CART_COUNT * * Returns: Requested cart item or 0 (zero) if not found * ************************************************************************/ //CART_CONTENT = Cookie name //1 = TOTAL_VALUE //3 = CART_COUNT function getCartItem(nIndex) { var act_cart= getCookie("CART_CONTENT") var sTemp =(act_cart != null) ? sTemp=act_cart.split("\t"):0; return (sTemp.length > 0) ? sTemp[nIndex] : 0; } /*********************************************************************** * * GotoAnchor - JS for jumping to an anchor - some user agents don't handle * anchors correctly if BASE HREF is present * * Input: sAnchor * * Returns: nothing * ************************************************************************/ function GotoAnchor(sAnchor) { window.location.hash = sAnchor; } // The following block implements the string.parseJSON method (function (s) { // This prototype has been released into the Public Domain, 2007-03-20 // Original Authorship: Douglas Crockford // Originating Website: http://www.JSON.org // Originating URL : http://www.JSON.org/JSON.js // Augment String.prototype. We do this in an immediate anonymous function to // avoid defining global variables. // m is a table of character substitutions. var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }; s.parseJSON = function (filter) { // Parsing happens in three stages. In the first stage, we run the text against // a regular expression which looks for non-JSON characters. We are especially // concerned with '()' and 'new' because they can cause invocation, and '=' // because it can cause mutation. But just to be safe, we will reject all // unexpected characters. try { if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/. test(this)) { // In the second stage we use the eval function to compile the text into a // JavaScript structure. The '{' operator is subject to a syntactic ambiguity // in JavaScript: it can begin a block or an object literal. We wrap the text // in parens to eliminate the ambiguity. var j = eval('(' + this + ')'); // In the optional third stage, we recursively walk the new structure, passing // each name/value pair to a filter function for possible transformation. if (typeof filter === 'function') { function walk(k, v) { if (v && typeof v === 'object') { for (var i in v) { if (v.hasOwnProperty(i)) { v[i] = walk(i, v[i]); } } } return filter(k, v); } j = walk('', j); } return j; } } catch (e) { // Fall through if the regexp test fails. } throw new SyntaxError("parseJSON"); }; } ) (String.prototype); // End public domain parseJSON block /*********************************************************************** * * ajaxObject - ajax communication library * * Input: url - the url of the json provider * callbackFunction - what function to call after communication * * Returns: nothing * ************************************************************************/ function ajaxObject(url, callbackFunction) { var that=this; this.updating = false; this.abort = function() { if (that.updating) { that.updating=false; that.AJAX.abort(); that.AJAX=null; } } this.update = function(passData,postMethod) { if (that.updating) { return false; } that.AJAX = null; if (window.XMLHttpRequest) { that.AJAX=new XMLHttpRequest(); } else { that.AJAX=new ActiveXObject("Microsoft.XMLHTTP"); } if (that.AJAX==null) { return false; } else { that.AJAX.onreadystatechange = function() { if (that.AJAX.readyState==4) { that.updating=false; that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML); that.AJAX=null; } } that.updating = new Date(); if (/post/i.test(postMethod)) { var uri=urlCall+'?'+that.updating.getTime(); that.AJAX.open("POST", uri, true); that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); that.AJAX.setRequestHeader("Content-Length", passData.length); that.AJAX.send(passData); } else { var uri=urlCall+'?'+passData+'×tamp='+(that.updating.getTime()); that.AJAX.open("GET", uri, true); that.AJAX.send(null); } return true; } } var urlCall = url; this.callback = callbackFunction || function () { }; } /*********************************************************************** * * getStockNodes - Get the nodes of the DOM tree where nodes are used to * dynamic stock display. These tags are marked with "ActinicRTS" class * * Output: array of elements matching the above criteria * ************************************************************************/ function getStockNodes() { var arrOut = new Array(); if (document.evaluate) { var xpathString = "//*[@class='ActinicRTS']" var xpathResult = document.evaluate(xpathString, document, null, 0, null); while ((arrOut[arrOut.length] = xpathResult.iterateNext())) { } arrOut.pop(); } else if (document.getElementsByTagName) { var aEl = document.getElementsByTagName( '*' ); for(var i=0,j=aEl.length;i 0) { arrStockElems[nIndex].style.visibility = "visible"; arrStockElems[nIndex].style.display = "inline"; } else { arrStockElems[nIndex].style.visibility = "hidden"; arrStockElems[nIndex].style.display = "none"; } } if (sIDStart == 'RemoveIfInStock') { if (mapStockByRef[sProdRef] > 0) { arrStockElems[nIndex].innerHTML = ""; } } // // Generic flag to indicate ajax call went fine // if (sIDStart == 'EnableIfStockOk') { arrStockElems[nIndex].style.visibility = "visible"; arrStockElems[nIndex].style.display = "inline"; } } } } /*********************************************************************** * * AttachEvent - Cross browser attachEvent function * * Input: obj - object which event is to be attached * eventName - name of the event to listen * eventHandler - the function to attach to the event * ************************************************************************/ function AttachEvent(obj, eventName, eventHandler) { if(obj) { if (eventName.substring(0, 2) == "on") { eventName = eventName.substring(2, eventName.length); } if (obj.addEventListener) { obj.addEventListener(eventName, eventHandler, false); } else if (obj.attachEvent) { obj.attachEvent("on" + eventName, eventHandler); } } } /*********************************************************************** * * ValidateCartNameDetails - Validate the cart name and password for saving * * Returns: true if data is OK * ************************************************************************/ function ValidateCartNameDetails() { var elemDiv = document.getElementById("idRowCartNamePassword"); if (!elemDiv) { return true; } if (elemDiv.style.display == "none") { elemDiv.style.display = ""; return (false); } var elemInput = document.getElementById("idCartName"); if (elemInput.value == '') { alert('Username must be filled in'); return false; } elemInput = document.getElementById("idCartPassword"); if (elemInput.value == '') { alert('Password must be filled in'); return false; } return true; } /*********************************************************************** * * DeliveryCountryChanged - Handler for dynamic delivery state selection * ************************************************************************/ function DeliveryCountryChanged() { CountryChanged('Delivery'); } /*********************************************************************** * * InvoiceCountryChanged - Handler for dynamic invoice state selection * ************************************************************************/ function InvoiceCountryChanged() { CountryChanged('Invoice'); } /*********************************************************************** * * CountryChanged - Handler for dynamic state selection * * Input: sLocationType - 'Invoice' or 'Delivery' * ************************************************************************/ function CountryChanged(sLocationType) { // // Get appropriate country select element // var cmbCountry = document.getElementById('lst' + sLocationType + 'Country'); if (!cmbCountry) { return; } SetCountryTextFieldDisplay(sLocationType, ''); // // Get appropriate state/region select element // var cmbState = document.getElementById('lst' + sLocationType + 'Region'); if (!cmbState || !cmbState.options) { return; } // // Get appropriate state/region text element // var editState = document.getElementById('id' + sLocationType + 'RegionEdit'); var sStateName = editState ? editState.value : ''; // // Save current state value // var sCurrentState = cmbState.value; cmbState.options.length = 1; // clear the state select options if (cmbCountry.value == "UndefinedRegion") // if no country is selected { cmbState.style.display = "none"; // hide state select if (editState) { editState.style.display = ""; } return; } var chkSeparateShip = document.getElementById("idSEPARATESHIP"); var bSeparateShip = chkSeparateShip && chkSeparateShip.checked; // // Get the js country state map // var mapCountries = (sLocationType == 'Delivery') ? g_mapDeliveryCountryStateMap : g_mapInvoiceCountryStateMap; // // Get states from the map // var arrOptions = mapCountries[cmbCountry.value]; if (!arrOptions && sLocationType == 'Invoice' && !bSeparateShip && g_mapDeliveryCountryStateMap[cmbCountry.value] ) { arrOptions = g_mapDeliveryCountryStateMap[cmbCountry.value]; } if (!arrOptions) // if there are no states { cmbState.style.display = "none"; // hide state select if (editState) { editState.style.display = ""; } return; } cmbState.style.display = ""; // show the state select if (editState) { editState.style.display = "none"; } var bFound = false; for (var i = 0; i < arrOptions.length; i += 2) // go through state data { var oOption = document.createElement("OPTION"); // create an option oOption.text = arrOptions[i + 1]; // set state name oOption.value = arrOptions[i]; // set state code if (oOption.value == sCurrentState || // is this our current value? oOption.text == sStateName) // or it matches the text field { bFound = true; // mark as selected sCurrentState = oOption.value; oOption.selected = true; } cmbState.options.add(oOption); // add option to select element } if (bFound) { cmbState.value = sCurrentState; // restore current selection } } /*********************************************************************** * * SetCountryTextFieldDisplay - Set display of country text field * * Input: sLocationType - 'Invoice' or 'Delivery' * sDisplay - '' to display or 'none' to hide * ************************************************************************/ function SetCountryTextFieldDisplay(sLocationType, sDisplay) { var sTextID = (sLocationType == 'Delivery') ? 'idDELIVERCOUNTRYText' : 'idINVOICECOUNTRYText'; var elemCountryText = document.getElementById(sTextID); if (elemCountryText) { // // Get appropriate country select element // var cmbCountry = document.getElementById('lst' + sLocationType + 'Country'); elemCountryText.style.display = (cmbCountry && cmbCountry.value == '---') ? sDisplay : 'none'; } } /*********************************************************************** * * SetDeliveryAddressVisibility - Handler for showing or hiding delivery address fields * ************************************************************************/ function SetDeliveryAddressVisibility() { if (document.getElementById("idInvoiceRule") || document.getElementById("idDeliveryRule")) { SetAccountAddressVisibility(); return; } SetInvoiceCountries(); var chkSeparateShip = document.getElementById("idSEPARATESHIP"); var sDisplay = "none"; if (chkSeparateShip.checked) { sDisplay = ""; } var cellSeparateShip = document.getElementById("idSeparateShipCell"); if (document.getElementById("idDeliverHeader")) { if (cellSeparateShip) { cellSeparateShip.colSpan = sDisplay ? 1 : 2; } } SetTableCellsDisplay("idBothAddressesTable", "DeliverField", sDisplay); var chkResidential = document.getElementById("idINVOICERESIDENTIAL"); if (chkResidential) { chkResidential.style.display = (chkSeparateShip.checked) ? 'none' : ''; } InvoiceCountryChanged(); } /*********************************************************************** * * SetAccountAddressVisibility - Handler for showing or hiding delivery address fields * ************************************************************************/ function SetAccountAddressVisibility() { var sDisplay = ""; var bNewInvoiceAddress = IsElementChecked("idINVOICEADDRESSSELECT_0"); var bNewDeliverAddress = IsElementChecked("idDELIVERADDRESSSELECT_0"); // // Hide address fields is neither 'Or enter new address is enabled // if (!bNewInvoiceAddress && !bNewDeliverAddress) { sDisplay = "none"; } // // Show or hide table rows as appropriate // var tblTarget = document.getElementById("idBothAddressesTable"); if (!tblTarget) { return; } for (var nRow = 0; nRow < tblTarget.rows.length; nRow++) { var elemRow = tblTarget.rows[nRow]; if (elemRow.className != "ShowAlways") { elemRow.style.display = sDisplay; } } if (sDisplay == 'none') // nothing more to do if we're hiding rows { return; } // // Handle invoice fields // sDisplay = bNewInvoiceAddress ? "" : "none"; SetTableCellsChildDisplay("idBothAddressesTable", "InvoiceField", sDisplay); if (sDisplay != 'none') { InvoiceCountryChanged(); } // // Handle delivery fields // sDisplay = "none"; if (bNewDeliverAddress) { if (!bNewInvoiceAddress || // if we're just showing delivery fields IsElementChecked("idSEPARATESHIP")) // or we showing a different delivery address from user entered invoice address { sDisplay = ""; // display delivery fields } } SetTableCellsChildDisplay("idBothAddressesTable", "DeliverField", sDisplay); if (sDisplay != 'none') { DeliveryCountryChanged(); } // // Hide different delivery address unless user is entering both addresses // var rowSeparateShip = document.getElementById("idSeparateShipRow"); if (rowSeparateShip) { rowSeparateShip.style.display = bNewInvoiceAddress && bNewDeliverAddress ? '' : 'none'; } } /*********************************************************************** * * IsElementChecked - Returns whether a radio-button or checkbox is checked * * Input: sID - id of element to check * * Returns: true if element exists and ic checked * ************************************************************************/ function IsElementChecked(sID) { var elemCheck = document.getElementById(sID); if (elemCheck && elemCheck.checked) { return true; } return false; } /*********************************************************************** * * SetTableCellsDisplay - Show or hide cells in a table based on cell class name * * Input: sTableID - id of table * sClassName - class name of cells to show or hide * sDisplay - value for display style, "" to show, "none" to display * ************************************************************************/ function SetTableCellsDisplay(sTableID, sClassName, sDisplay) { var tblTarget = document.getElementById(sTableID); if (!tblTarget) { return; } for (var nRow in tblTarget.rows) { var elemRow = tblTarget.rows[nRow]; for (var nCell in elemRow.cells) { var elemCell = elemRow.cells[nCell]; if (elemCell.className && elemCell.className == sClassName) { elemCell.style.display = sDisplay; } } } } /*********************************************************************** * * SetTableCellsChildDisplay - Show or hide cell's children in a table based on cell class name * * Input: sTableID - id of table * sClassName - class name of cells to show or hide * sDisplay - value for display style, "" to show, "none" to display * ************************************************************************/ function SetTableCellsChildDisplay(sTableID, sClassName, sDisplay) { var tblTarget = document.getElementById(sTableID); if (!tblTarget) { return; } for (var nRow = 0; nRow < tblTarget.rows.length; nRow++) { var elemRow = tblTarget.rows[nRow]; if (elemRow.className != 'ShowAlways') { for (var nCell = 0; nCell < elemRow.cells.length; nCell++) { var elemCell = elemRow.cells[nCell]; if (elemCell.className && elemCell.className == sClassName) { for (var i = 0; i < elemCell.childNodes.length; i++) { var elemChild = elemCell.childNodes[i]; if (elemChild.style && elemChild.id.indexOf('pcaDiv') != 0) { elemCell.childNodes[i].style.display = sDisplay; } } } } } } } /*********************************************************************** * * SetShoppingCartVisibility - Handler for showing or hiding cart details * ************************************************************************/ function SetShoppingCartVisibility() { var elemShowHide = document.getElementById("idShowHide"); if (!elemShowHide) { return; } var spanShoppingCart = document.getElementById("idShoppingCartGrid"); if (!spanShoppingCart) { return; } var elemCartHeadingTotal = document.getElementById("idCartHeadingTotal"); var elemCartChangeCell = document.getElementById("idCartChangeCell"); if (spanShoppingCart.style.display == "none") { spanShoppingCart.style.display = ""; elemShowHide.innerHTML = 'hide'; elemCartHeadingTotal.style.display = 'none'; if (elemCartChangeCell) { document.getElementById("idCartChangeCell").style.display = ''; } } else { spanShoppingCart.style.display = "none"; elemShowHide.innerHTML = 'show'; elemCartHeadingTotal.style.display = ''; if (elemCartChangeCell) { document.getElementById("idCartChangeCell").style.display = 'none'; } } } /*********************************************************************** * * SetCreditCardFieldsVisibility - Handler for showing or hiding credit card fields * ************************************************************************/ function SetCreditCardFieldsVisibility() { var nPaymentMethod = GetPaymentMethod(); var sDisplay = "none"; if (nPaymentMethod == "10005") { sDisplay = ""; } SetTableRowsDisplay("idPaymentMethodTable", "CreditCardField", sDisplay); } /*********************************************************************** * * SetTableRowsDisplay - Show or hide rows in a table based on row class name * * Input: sTableID - id of table * sClassName - class name of rows to show or hide * sDisplay - value for display style, "" to show, "none" to display * ************************************************************************/ function SetTableRowsDisplay(sTableID, sClassName, sDisplay) { var tblTarget = document.getElementById(sTableID); if (!tblTarget) { return; } for (var nRow in tblTarget.rows) { var elemRow = tblTarget.rows[nRow]; if (elemRow.className && elemRow.className == sClassName) { elemRow.style.display = sDisplay; } } } /*********************************************************************** * * CheckForm - Validate a form before submission * * Input: elemBtn - element doing the submission * * Returns: true to let form submit, false to prevent bubbling up * ************************************************************************/ function CheckForm(elemBtn) { // // Find the form element in ancestors // var elemForm = elemBtn.parentElement ? elemBtn.parentElement : elemBtn.parentNode; while (elemForm && elemForm.tagName != "FORM") { elemForm = elemForm.parentElement ? elemForm.parentElement : elemForm.parentNode; } if (!elemForm) // if form doesn't exist, bail out { return true; } // // Decide whether we should validate the confirmation email address // We don't confirm emails if we're selecting an account address // or a delivery address if it is the same as invoice address // var bAccountCustomer = (document.getElementsByName('INVOICEADDRESSSELECT').length > 0); var bSkipInvoice = false; if (bAccountCustomer) { bSkipInvoice = !IsElementChecked("idINVOICEADDRESSSELECT_0"); // skip invoice if we're selecting an address } var chkSeparateShip = document.getElementById('idSEPARATESHIP'); var bSkipDeliver = false; if (bAccountCustomer) { bSkipDeliver = !IsElementChecked("idDELIVERADDRESSSELECT_0"); // skip delivery if we're selecting an address } if (!bSkipDeliver) // if we're not selecting an address { bSkipDeliver = (chkSeparateShip && !chkSeparateShip.checked); // skip if delivery is same as invoice } if (bSkipInvoice && bSkipDeliver) // if we skip both addresses { return true; // nothing to check } var arrDescendants = GetAllElements(elemForm); for (var i = 0; i < arrDescendants.length; i++) { var elemThis = arrDescendants[i]; if ((elemThis.id == 'idINVOICEEMAIL_CONFIRM' && !bSkipInvoice) || (elemThis.id == 'idDELIVEREMAIL_CONFIRM' && !bSkipDeliver)) { var elemEmail = document.getElementById(elemThis.id.replace(/_CONFIRM$/, '')); if (elemEmail.style.display != 'none' && elemEmail.value != elemThis.value) { var sMsg = GetLabelText(elemThis) + "\n\n"; sMsg += "'" + elemThis.value + "' does not match '" + elemEmail.value + "'"; alert(sMsg); elemThis.focus(); return false; } } } if (bSkipInvoice && !bSkipDeliver) { chkSeparateShip.checked = true; } return true; } /*********************************************************************** * * GetAllElements - Get all descendants of an element * * Input: elemParent - parent element * * Returns: collection of descendant elements * ************************************************************************/ function GetAllElements(elemParent) { if (elemParent.all) // IE-specific { return elemParent.all; } else if (elemParent.getElementsByTagName) // W3C compliant browsers { return elemParent.getElementsByTagName('*'); } } /*********************************************************************** * * SubmitPSPForm - Submit a form to a PSP * * Returns: true to let form submit, false to prevent bubbling up * ************************************************************************/ var g_sConfirmOrderInitText = ''; function SubmitPSPForm() { var sSendingOrder = "Saving your order"; var elemConfirmOrder = document.getElementById("idBtnConfirm"); if (elemConfirmOrder.value == sSendingOrder) { if (confirm("Are you sure") == false) { return false; } } else { g_sConfirmOrderInitText = elemConfirmOrder.value; } elemConfirmOrder.value = sSendingOrder; var nPaymentMethod = GetPaymentMethod(); if (nPaymentMethod == -1) { return true; } if (nPaymentMethod >= 10000) { return true; } GetPSPFormAndSubmit(nPaymentMethod); return false; } /*********************************************************************** * * GetPaymentMethod - Get the payment method * * Returns: payment method or -1 if not found * ************************************************************************/ function GetPaymentMethod() { var cmbPaymentMethod = document.getElementById("idPAYMENTMETHOD"); if (cmbPaymentMethod) // if we have an element with correct id { return cmbPaymentMethod.value; // return it } // // Get radio buttons or hidden by name if present // var collPaymentMethods = document.getElementsByName("PAYMENTMETHOD"); if (!collPaymentMethods) { return -1; } if (collPaymentMethods.length == 1) // might have a single method in which case it will be hidden input { return collPaymentMethods[0].value; } for (var i = 0; i < collPaymentMethods.length; i++) // find checked radio button { if (collPaymentMethods[i].checked) { return collPaymentMethods[i].value; } } return -1; } /*********************************************************************** * * GetPSPFormAndSubmit - Submit a form to a PSP * * Input: nPaymentMethod - payment method * ************************************************************************/ function GetPSPFormAndSubmit(nPaymentMethod) { var ajaxRequest = new ajaxObject(document.location.href.split('?')[0]); ajaxRequest.callback = function (responseText) { if (responseText.substring(0, 6) == "Error:") { alert(responseText); var elemConfirmOrder = document.getElementById("idBtnConfirm"); if (elemConfirmOrder) { elemConfirmOrder.value = g_sConfirmOrderInitText; } return; } // // Get the placeholder span for the PSP form // var elemSpanPSPForm = document.getElementById("idSpanPSPForm"); if (!elemSpanPSPForm) { return; } elemSpanPSPForm.innerHTML = responseText; // // Get the PSP form // var elemPSPForm = document.getElementById("idPSPForm"); if (!elemPSPForm) { return; } // // Submit the PSP form // elemPSPForm.submit(); } var sParams = "ACTION=GETPSPFORM&PAYMENTMETHOD=" + nPaymentMethod; var elemPONumber = document.getElementsByName('PAYMENTPONO'); if (elemPONumber.length) { sParams += '&PAYMENTPONO=' + escape(elemPONumber[0].value); } var elemPayUserDef = document.getElementsByName('PAYMENTUSERDEFINED'); if (elemPayUserDef.length) { sParams += '&PAYMENTUSERDEFINED=' + escape(elemPayUserDef[0].value); } ajaxRequest.update(sParams, "GET"); } /*********************************************************************** * * SFDropDownMenu - Javascript function to handle Suckerfish drop-down menus in IE * * Input: sID - ID of the