/* Copyright (c) On Technology Australia Pty Ltd - All Rights Reserved. */ var g_CartDisplay = false; var colProductPrice = 0; var colFreightLocal = 1; var colFreightDomestic = 2; var colFreightInternational = 3; var colProductWeight = 4; var colTaxLocal = 5; var colTaxDomestic = 6; var colTaxInternational = 7; var colProductCode = 0; var colProductDesc = 1; var colCustomFieldKeys = 2; var bProcessCart = true; function nA() { var myProductArray = new Array(0,0,0,0,0,0,0,0); for (var x = 0; x < arguments.length; x++) { myProductArray[x] = arguments[x]; } return myProductArray; } function getProductPrice(curSymbol, thousandsSeparator, decPlaces, decSeparator, truncateDec, blnSymbolAtFront, pid, local, domestic, international, defaultRegion, blnIncludeTax) { var curPrice = NaN; if (typeof(getProduct) == "function") { var Info = getProduct(pid); if (Info) { switch(blnIncludeTax ? getRegion(defaultRegion) : 99) { case 0: curPrice = Info[colProductPrice] * (1 + Info[colTaxLocal]); break; case 1: curPrice = Info[colProductPrice] * (1 + Info[colTaxDomestic]); break; case 2: curPrice = Info[colProductPrice] * (1 + Info[colTaxInternational]); break; case 99: curPrice = Info[colProductPrice]; break; } } } return "" + htmlEncode(formatCurrency(curSymbol, thousandsSeparator, decPlaces, decSeparator, truncateDec, blnSymbolAtFront, curPrice)) + ""; } function getPriceInfo(pid, local, domestic, international, defaultRegion, blnIncludeTax) { var strTaxString; var curPrice; if (typeof(getProduct) == "function") { var Info = getProduct(pid); if (Info) { switch(blnIncludeTax ? getRegion(defaultRegion) : 99) { case 0: curPrice = Info[colProductPrice] * (1.0 + Info[colTaxLocal]); if (curPrice != Info[colProductPrice]) strTaxString = local; else strTaxString = ""; break; case 1: curPrice = Info[colProductPrice] * (1.0 + Info[colTaxDomestic]); if (curPrice != Info[colProductPrice]) strTaxString = domestic; else strTaxString = ""; break; case 2: curPrice = Info[colProductPrice] * (1 + Info[colTaxInternational]); if (curPrice != Info[colProductPrice]) strTaxString = international; else strTaxString = ""; break; case 99: curPrice = Info[colProductPrice]; strTaxString = ""; break; } return htmlEncode(strTaxString); } } } function CartLine() { this.toString = function() { var CartLine = this.id + "&" + this.quantity + "&"; if (this.priceCustom) CartLine += this.price + "&"; else CartLine += "&"; if (this.customfieldvalues) { var CustomData = ""; for(var cf in this.customfieldvalues) CustomData += encodeURIComponent(this.customfieldvalues[cf]) + "&"; CartLine += escape(CustomData.slice(0, -1)); } return CartLine; }; this.populate = function() { if (this.price || this.price == 0) this.priceCustom = true; else this.priceCustom = false; if (typeof(getProductInfo) == "function") { var Info = getProductInfo(this.id); this.code = Info[colProductCode]; this.name = Info[colProductDesc]; if (this.customfieldvalues) { var CustomFieldNames = Info[colCustomFieldKeys]; this.customfields = new Array(); for(var CustomField in this.customfieldvalues) { var oCustomField = new Object(); oCustomField.name = getCustomField(CustomFieldNames[CustomField]); oCustomField.value = this.customfieldvalues[CustomField]; this.customfields.push(oCustomField); } } } if (typeof(getProduct) == "function") { var Info = getProduct(this.id); if (Info) { if (!this.price && this.price != 0) this.price = Info[colProductPrice]; this.prices = new Array(this.price * (1.0 + Info[colTaxLocal]), this.price * (1.0 + Info[colTaxDomestic]), this.price * (1.0 + Info[colTaxInternational])); this.prices[99] = this.price; this.taxes = new Array(Info[colTaxLocal], Info[colTaxDomestic], Info[colTaxInternational]); this.weight = Info[colProductWeight]; this.freight = new Array(Info[colFreightLocal], Info[colFreightDomestic], Info[colFreightInternational]); } } } this.fromString = function(line) { var LineData = line.split("&"); var ProductID = parseInt(LineData[0]); var Quantity = parseInt(LineData[1]); var Price = parseFloat(LineData[2]); var CustomData = LineData[3]; this.id = ProductID; this.quantity = Quantity; this.price = Price; if (CustomData) { this.customfieldvalues = unescape(CustomData).split("&"); if (this.customfieldvalues.length == 0) { delete this.customfieldvalues; } else { for(var cf in this.customfieldvalues) this.customfieldvalues[cf] = decodeURIComponent(this.customfieldvalues[cf]); } } this.populate(); }; this.equals = function(RHS) { if (this.id == RHS.id) { if (this.price == RHS.price) { if (!this.customfieldvalues && !RHS.customfieldvalues) return true; if (this.customfieldvalues && RHS.customfieldvalues) { if (this.customfieldvalues.join("&") == RHS.customfieldvalues.join("&")) return true; } } } return false; }; this.valid = function() { if (this.id && this.quantity && getProduct(this.id)) return true; return false; }; if (arguments.length == 1 && typeof(arguments[0]) == "string") { this.fromString(arguments[0]); return; } if (arguments.length == 4) { this.id = arguments[0]; this.quantity = arguments[1]; this.price = arguments[2]; this.customfieldvalues = arguments[3]; this.populate(); } } function Cart() { this.fromString = function(cart) { var lines = cart.replace(/^\s*lines=|^\s*lines/, "").split("#"); if (lines.length == 0 || (lines.length == 1 && !lines[0])) return; this.lines.length = 0; for(var idx in lines) this.lines.push(new CartLine(lines[idx])); }; this.toString = function() { return "lines=" + this.lines.join("#"); }; this.toHTML = function() { var args = arguments[0]; var decPlaces = args[2]; var decSeparator = args[3]; var truncateDec = args[4]; var showExTax = args[6]; var showIncTax = args[7]; var showTaxPercent = args[8]; var showTaxAmount = args[9]; var region = getRegion(args[10]); var removeText = args[26]; var imagePath = args[29]; var headerFont = args[11]; var headerSize = args[12]; var headerBackgnd = args[13]; var headerForegnd = args[14]; var headerText = args[15]; var cartFontOdd = args[16]; var cartFontSizeOdd = args[17]; var cartBackgndOdd = args[18]; var cartForegndOdd = args[19]; var cartFontEven = args[20]; var cartFontSizeEven = args[21]; var cartBackgndEven = args[22]; var cartForegndEven = args[23]; var totTaxLabel = args[24]; var totLabel = args[25]; var emptyCart = args[27]; var verStr = args[28]; var NotRegisteredMessage = args[32]; var columns = 4 + showExTax + showTaxPercent + showTaxAmount + showIncTax; var format = function(amt) { return formatCurrency(args[0], args[1], args[2], args[3], args[4], args[5], amt); } if (!document.cookie) { document.cookie = "test"; if (!document.cookie) { return "" + "
" + "

We're Sorry


" + "It appears your browser is set to refuse cookies. Our online purchasing " + "system requires that you have cookies enabled on your browser.
" + "

If you don't know how to enable this " + "feature we have provided instructions on enabling cookies for various " + "browsers at www.ezimerchant.com" + "

 

"; } } var CartHtml = ""; if (this.lines.length == 0) { CartHtml += ""; } else { CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += showExTax ? "" : ""; CartHtml += showTaxPercent ? "" : ""; CartHtml += showTaxAmount ? "" : ""; CartHtml += showIncTax ? "" : ""; CartHtml += ""; CartHtml += ""; var TaxTotal = 0; var SubTotal = 0; var LineTotal; for(var line in this.lines) { var oLine = this.lines[line]; if (oLine.valid()) { if (truncateDec) { LineTotal = Math.floor(oLine.quantity * oLine.prices[region] * Math.pow(10, decPlaces)) / Math.pow(10, decPlaces); TaxTotal += Math.floor(oLine.quantity * (oLine.prices[region] - oLine.price) * Math.pow(10, decPlaces)) / Math.pow(10, decPlaces); } else { LineTotal = Math.round(oLine.quantity * oLine.prices[region] * Math.pow(10, decPlaces)) / Math.pow(10, decPlaces); TaxTotal += Math.round(oLine.quantity * (oLine.prices[region] - oLine.price) * Math.pow(10, decPlaces)) / Math.pow(10, decPlaces); } SubTotal += LineTotal; CartHtml += "" + "" + "" + ""; if (showExTax) CartHtml += ""; if (showTaxPercent) CartHtml += ""; if (showTaxAmount) CartHtml += ""; if (showIncTax) CartHtml += ""; CartHtml += ""; CartHtml += ""; } } CartHtml += ""; CartHtml += ""; CartHtml += ""; } } if (TaxTotal > 0) { CartHtml += "" + "" + ""; } else { CartHtml += ""; } CartHtml += ""; CartHtml += ""; } CartHtml += "
" + htmlEncode(emptyCart) + "
" + headerText[0] + "" + headerText[1] + "" + headerText[2] + "" + headerText[3] + "" + headerText[4] + "" + headerText[5] + "" + headerText[6] + "" + headerText[7] + " 
" + htmlEncode(oLine.name) + "" + htmlEncode(oLine.code) + "" + htmlEncode(format(oLine.price)) + "" + oLine.taxes[region] * 100 + "%" + htmlEncode(format(oLine.price * oLine.taxes[region])) + "" + htmlEncode(format(oLine.prices[region])) + "" + htmlEncode(format(LineTotal)) + ""; // hidden fields sent to server per orderline CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; CartHtml += ""; // process custom fields into hidden fields to be sent to server var CustomFieldNames = ""; var CustomFieldValues = ""; if (oLine.customfields) { for(var CustomField in oLine.customfields) { if (CustomField > 0) { CustomFieldNames += "|"; CustomFieldValues += "|"; } CustomFieldNames += escape(oLine.customfields[CustomField].name); CustomFieldValues += escape(oLine.customfields[CustomField].value); } if (oLine.customfields.length > 0) { CartHtml += "
 "; for(var CustomField in oLine.customfields) { if (!oLine.customfields[CustomField].name) CartHtml += ""; else CartHtml += ""; } CartHtml += "
" + htmlEncode(oLine.customfields[CustomField].value) + "
" + htmlEncode(oLine.customfields[CustomField].name) + ":" + htmlEncode(oLine.customfields[CustomField].value) + "
" + "" + "" + htmlEncode(totLabel) + " (" + htmlEncode(totTaxLabel) + " " + htmlEncode(format(TaxTotal)) + "):" + "" + "" + "" + "" + htmlEncode(format(SubTotal)) + "" + "" + "
" + htmlEncode(totLabel) + ":" + htmlEncode(format(SubTotal)) + "
"; CartHtml += ""; CartHtml += ""; CartHtml += "
"; CartHtml += "
"; CartHtml += "
"; CartHtml += "
"; return CartHtml; } this.addLine = function(id, qty, price, cf) { var oCartLine = new CartLine(id, qty, price, cf); for(var i = 0; i < this.lines.length; i++) { if (this.lines[i].equals(oCartLine)) { this.lines[i].quantity += qty; return; } } this.lines.push(oCartLine); }; this.updateLine = function(item, qty) { if (isNaN(qty)) return; if (qty < 1) this.lines.splice(item, 1); else this.lines[item].quantity = qty; }; this.deleteLine = function(item) { if (typeof(item) == "number") { this.lines.splice(item, 1); } }; this.total = function(defaultRegion) { var region = getRegion(defaultRegion); var total = 0; for(var Line in this.lines) { var oLine = this.lines[Line]; total += oLine.prices[region] * oLine.quantity; } return total; } this.save = function() { document.cookie = this.toString() +";"; }; this.lines = new Array(); if (arguments.length == 1 && typeof(arguments[0]) == "string") { var cookies = arguments[0].split(";"); for(var cookie in cookies) { if (/^\s*lines/i.test(cookies[cookie])) this.fromString(cookies[cookie]); } } } function addProductToCart(frm, strAddMessage, strErrMsg, strFileName, Price) { var ProductID = frm && frm.elements["pid"] ? parseInt(frm.elements["pid"].value) : NaN; var Quantity = frm && frm.elements["qty"] ? parseInt(frm.elements["qty"].value) : NaN; var CustomFields; if (!Price && frm && frm.elements["price"]) Price = parseFloat(frm.elements["price"].value); if (!Quantity) { if (Quantity == 0) return; Quantity = 1; } for(var i = 0; i < frm.elements.length; i++) { if (frm.elements[i].name == "cf") { if (!CustomFields) CustomFields = new Array(); switch(frm.elements[i].type) { case "checkbox": CustomFields.push(frm.elements[i].checked ? "Yes" : "No"); break; default: CustomFields.push(frm.elements[i].value); break; } } } var oCart = new Cart(document.cookie); oCart.addLine(ProductID, Quantity, Price, CustomFields); oCart.save(); if (typeof(strAddMessage) == "undefined") { window.location = "viewcart.htm"; return true; } if (strAddMessage != "") { alert(strAddMessage); if (g_CartDisplay) window.location.reload(); return false; } } function updateCartLine(x, qty) { var oCart = new Cart(document.cookie); oCart.updateLine(x, qty); oCart.save(); window.location.reload(); } function deleteCartLine(x) { var oCart = new Cart(document.cookie); oCart.deleteLine(x); oCart.save(); window.location.reload(); } function submitCart() { if (arguments.length == 1 && arguments[0]) { alert(arguments[0]); return; } if (document.forms["ordercart"].getAttribute('target') == '' || document.forms["ordercart"].getAttribute('target') == null) { document.forms["ordercart"].target="_top"; } document.forms["ordercart"].submit(); return false; } function getCart() { return new Cart(document.cookie).toHTML(arguments); } function getCartCount() { g_CartDisplay = true; return new Cart(document.cookie).lines.length; } function getCartItemCount() { g_CartDisplay = true; var count = 0; var cart = new Cart(document.cookie); for(var line in cart.lines) count += cart.lines[line].quantity; return count; } function getCartTotal(curSymbol, thousandsSeparator, decPlaces, decSeparator, truncateDec, blnSymbolAtFront, defaultRegion) { g_CartDisplay = true; return htmlEncode(formatCurrency(curSymbol, thousandsSeparator, decPlaces, decSeparator, truncateDec, blnSymbolAtFront, new Cart(document.cookie).total(defaultRegion))); } function formatCurrency(curSymbol, thousandsSeparator, decPlaces, decSeparator, truncateDec, blnSymbolAtFront, curValue) { var hashCurrency = {"£" : 163, "€" : 8364, "¤" : 164, "¥" : 165, "¢" : 162}; curSymbol = new String(curSymbol).replace(/&#(\d+);|(&[A-Za-z]+;)/ig, function() { var charCode = parseInt(arguments[1], 10); if (!isNaN(charCode)) return String.fromCharCode(charCode); charCode = hashCurrency[new String(arguments[0]).toLowerCase()]; if (charCode) return String.fromCharCode(charCode); return arguments[0]; }); var strCurrency; if (truncateDec) { strCurrency = new String(Math.floor(parseFloat(curValue) * Math.pow(10, decPlaces))); }else { strCurrency = new String(Math.round(parseFloat(curValue) * Math.pow(10, decPlaces))); } while (strCurrency.length <= decPlaces) strCurrency = "0" + strCurrency; var decValue = strCurrency.substr(strCurrency.length - decPlaces, strCurrency.length); strCurrency = strCurrency.substr(0, strCurrency.length - decPlaces); var s; if (strCurrency.length > 3) { s = strCurrency.substr(strCurrency.length-3, 3); for (var i = 4; i <= strCurrency.length; i++){ if (((i - 4) % 3) == 0){ s = strCurrency.substr(strCurrency.length - i,1) + thousandsSeparator + s; } else{ s = strCurrency.substr(strCurrency.length - i,1) + s; } } } else { s = strCurrency; } if (decPlaces != 0) { strCurrency = s + decSeparator + decValue; }else{ strCurrency = s; } return blnSymbolAtFront ? curSymbol + strCurrency : strCurrency + curSymbol; } function setRegion(region) { var dtExpiry = new Date(); dtExpiry.setFullYear(dtExpiry.getFullYear() + 5); document.cookie = "region=" + escape(region); window.location.reload(); return false; } function getRegion(defaultRegion) { if (document.cookie) { var cookies = document.cookie.split(";"); for(var cookie in cookies) { if (/^\s*region=\d{1,2}/i.test(cookies[cookie])) { var cookieData = cookies[cookie].split("="); if (cookieData[1] == "0" || cookieData[1] == "1" || cookieData[1] == "2" || cookieData[1] == "99") { return parseInt(cookieData[1]); } break; } } } return parseInt(defaultRegion); } function getLocalButton(defaultregion, OnlyInCart) { if (OnlyInCart) { var oCart = new Cart(document.cookie); if (oCart.lines.length == 0) return ""; } var strBtn = ""; strBtn += getRegion(defaultregion) == 0 ? "" : ""; return strBtn; } function getDomesticButton(defaultregion, OnlyInCart) { if (OnlyInCart) { var oCart = new Cart(document.cookie); if (oCart.lines.length == 0) return ""; } var strBtn = ""; strBtn += getRegion(defaultregion) == 1 ? "" : ""; return strBtn; } function getInternationalButton(defaultregion, OnlyInCart) { if (OnlyInCart) { var oCart = new Cart(document.cookie); if (oCart.lines.length == 0) return ""; } var strBtn = ""; strBtn += getRegion(defaultregion) == 2 ? "" : ""; return strBtn; } function FormatSeparator(strValue,decSeparator) { var re = /\./; var newValue = strValue.toString(); newValue = newValue.replace(re, decSeparator); return newValue; } function htmlEncode(str) { return new String(str).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); }