function ShoppingCart() { this.items = new Array(); this.loaded = false; this.orderPage = ((document.location.toString().indexOf('/homepages/')==-1)&&(typeof category != "undefined")); this.handlingCharge = 5.95; if(typeof ShoppingCart._initialized == "undefined") { ShoppingCart.prototype.printMiniCart = function() { document.write('
'); if(this.orderPage) { document.write('Add to order'); } else { if(document.forms[0].Template && document.forms[0].Template.value != 'domPrimaryHome') { document.write('Add to order'); } } if(this.items.length > 0) { document.write('View order'); document.write('Checkout'); } else { document.write('View order'); document.write('Checkout'); } document.write('

Shopping Summary

'); document.write('

No. of items: ',this.getItemsQuantity(),'

'); document.write('

Current total: $',this.getTotal(),'

'); if((typeof checkTC != "undefined")&&(checkTC == true)) { document.write('

e-Club total: $',this.getEClubTotal(),'

'); } document.write('
'); }; ShoppingCart.prototype.load = function() { if(!getCookie('MacPrimary') || getCookie('MacPrimary')=="") return false; //this.items = new Array(); if(this.items.length == 0) { var oCookie = getCookie('MacPrimary').split(';'); for(var i=0; i < oCookie.length; i++) { var oCartItem = new CartItem(this.loadOnixBook(oCookie[i]).split('|')); this.items.push(oCartItem); } } this.loaded = true; /* var oStr = "cart items:" + this.items.length + "\n\n"; for(var i=0; i' + unescape(searchOnixResultsCartBook[1].viewCol13).toLowerCase().replace(/[\s\W]/gi,"") + '>' + unescape(searchOnixResultsCartBook[1].viewCol15).toLowerCase().replace(/[\s\W]/gi,"")); } else { item.push(splitStr[3] + '>' + unescape(searchOnixResultsCartBook[1].viewCol13).toLowerCase().replace(/[\s\W]/gi,"")); } } return item.join('|'); }; ShoppingCart.prototype.save = function() { //if(this.items.length == 0) return false; var cookieExpires = new Date(); cookieExpires.setTime(cookieExpires.getTime() + (1 * 60 * 60 * 1000 )); var tmpCookie = new Array(); //for(var i=0; i < this.items.length; i++) tmpCookie.push(this.items[i].cookieString()); for(var i=0; i < this.items.length; i++) tmpCookie.push(this.items[i].newCookieString()); //alert(tmpCookie.join(';')); setCookie('MacPrimary', tmpCookie.join(';'), cookieExpires, '/'); this.loaded = false; this.load(); } ShoppingCart.prototype.isCartPage = function () { var section = (document.forms[0].Section != 'undefined' && document.forms[0].Section.value.length > 0) ? unescape(document.forms[0].Section.value) : ''; var subsection = (document.forms[0].Subsection != 'undefined' && document.forms[0].Subsection.value.length > 0) ? unescape(document.forms[0].Subsection.value) : ''; if(section && subsection && section == 'Library' && subsection == 'Shopping cart') { return true; } return false; }; ShoppingCart.prototype.isIsbnInCart = function (isbn) { if(!this.loaded) return false; for(var i=0; i < this.items.length; i++) { if(this.items[i].isbn.toLowerCase() == isbn.toLowerCase()) return true; } return false; }; ShoppingCart.prototype.addToCart = function (isbn,title,price,buyInspect,quantity,divCatStr) { if(this.isIsbnInCart(isbn)) return false; var tempArray = new Array(isbn,title,price,buyInspect,quantity,divCatStr); var tempItem = new CartItem(tempArray); this.items.push(tempItem); this.save(); }; ShoppingCart.prototype.deleteFromCart = function(isbn) { if(!this.isIsbnInCart(isbn)) return false; var tempArray = new Array(); for(var i=0; i < this.items.length; i++) { if(isbn.toLowerCase() != this.items[i].isbn.toLowerCase()) tempArray.push(this.items[i]); } this.items = new Array(); for(var i=0; i < tempArray.length; i++) this.items.push(tempArray[i]); this.save(); }; ShoppingCart.prototype.updateShoppingSummary = function () { var cart = document.getElementById('cart'); cart.innerHTML = ""; if(this.orderPage) { var addToCart = document.createElement('a'); addToCart.setAttribute('href','#'); if(document.attachEvent) { addToCart.onclick = function(oEvent){addItemsToCart(event);}; } else { addToCart.setAttribute('onclick','addItemsToCart(event)'); } } else { var addToCart = document.createElement('span'); } addToCart.className = "addToCart"; addToCart.appendChild(document.createTextNode('Add to order')); cart.appendChild(addToCart); if(this.items.length != 0) { var viewOrder = document.createElement('a'); viewOrder.setAttribute('href','libraries/Shopping+cart+summary'); } else { var viewOrder = document.createElement('span'); viewOrder.className = "viewOrder"; } viewOrder.appendChild(document.createTextNode('View order')); cart.appendChild(viewOrder); if(this.items.length != 0) { var checkout = document.createElement('a'); checkout.setAttribute('href','libraries/CheckoutNew'); } else { var checkout = document.createElement('span'); checkout.className = "checkout"; } checkout.appendChild(document.createTextNode('Checkout')); cart.appendChild(checkout); var oHeading = document.createElement('h3'); oHeading.appendChild(document.createTextNode('Shopping Summary')); cart.appendChild(oHeading); var oItems = document.createElement('p'); oItems.setAttribute('id','items'); oItems.appendChild(document.createTextNode('No. of items: ' + this.getItemsQuantity())); cart.appendChild(oItems); var oTotal = document.createElement('p'); oTotal.setAttribute('id','total'); oTotal.appendChild(document.createTextNode('Current total: $' + this.getTotal())); cart.appendChild(oTotal); if((typeof checkTC != "undefined")&&(checkTC == true)) { var oETotal = document.createElement('p'); oETotal.setAttribute('id','etotal'); oETotal.appendChild(document.createTextNode('e-Club total: $' + this.getEClubTotal())); cart.appendChild(oETotal); } }; ShoppingCart.prototype.isItemInspect = function(isbn) { if(!this.isIsbnInCart(isbn)) return false; for(var i=0; i < this.items.length; i++) { if((this.items[i].isbn.toLowerCase() == isbn.toLowerCase())&&(this.items[i].buyInspect.substring(1) == "I")) return true; } return false; }; ShoppingCart.prototype.getItemQuantity = function(isbn) { if(!this.isIsbnInCart(isbn)) return false; for(var i=0; i < this.items.length; i++) { if(this.items[i].isbn.toLowerCase() == isbn.toLowerCase()) return this.items[i].quantity; } return false; } ShoppingCart.prototype.getItemsQuantity = function() { if(!this.loaded) return 0; var quantity = 0; for(var i=0; i < this.items.length; i++) quantity += parseInt(this.items[i].quantity); return quantity; }; ShoppingCart.prototype.getTotal = function() { if(!this.loaded) return "0.0"; var total = 0; for(var i=0; i < this.items.length; i++) { if(this.items[i].buyInspect.substring(1) != "I") { if(this.items[i].price.indexOf('$') == -1) { var tempPrice = Number(this.items[i].price); } else { var tempPrice = Number(this.items[i].price.substring(1)); } total += (tempPrice) * (Number(this.items[i].quantity)); } } if((typeof oCartForm == "object")&&((oCartForm.step == "2")||(oCartForm.step == "3"))&&(oCartForm.payType == "2")&&(checkTC == false)) { total += this.handlingCharge; } return total.toFixed(2); }; ShoppingCart.prototype.getEClubTotal = function() { if(!this.loaded) return "0.0"; var total = 0; for(var i=0; i < this.items.length; i++) { if(this.items[i].buyInspect.substring(1) != "I") { if(this.items[i].price.indexOf('$') == -1) { var tempPrice = Number(this.items[i].price); } else { var tempPrice = Number(this.items[i].price.substring(1)); } if(this.items[i].isEClub()&&((typeof checkTC != "undefined")&&(checkTC == true))) { tempPrice = tempPrice * 0.9; } total += (tempPrice) * (Number(this.items[i].quantity)); } } if((typeof oCartForm == "object")&&((oCartForm.step == "2")||(oCartForm.step == "3"))&&(oCartForm.payType == "2")&&(checkTC == false)) { total += this.handlingCharge; } return total.toFixed(2); }; ShoppingCart.prototype.eClubPrice = function(i) { if(this.items[i].price.indexOf('$') == -1) { var ePrice = Number(this.items[i].price); } else { var ePrice = Number(this.items[i].price.substring(1)); } return (ePrice * 0.9).toFixed(2); }; ShoppingCart.prototype.setAddToOrder = function() { }; ShoppingCart.prototype.printShoppingCartOverviewHeader = function() { document.write(''); document.write(''); document.write('ISBN'); document.write('Title'); document.write('RRP'); document.write('e-Club price'); document.write('Quantity'); document.write('Inspect'); document.write('Buy'); document.write(''); document.write(''); document.write(''); }; ShoppingCart.prototype.printInspectBuy = function(ib,i) { if(ib.toUpperCase() == (this.items[i].buyInspect.substring(1)).toUpperCase())return 'checked'; return ""; }; ShoppingCart.prototype.inspectAvailable = function(i) { if((this.items[i].buyInspect.substring(0,1)).toUpperCase() == "I")return ''; return 'disabled'; }; ShoppingCart.prototype.isInspected = function(i) { if(this.items[i].buyInspect == "II")return 'disabled="disabled"'; return ''; }; ShoppingCart.prototype.printShoppingCartOverview = function() { if(this.items.length == 0)return false; document.write(''); document.write(''); this.printShoppingCartOverviewHeader(); document.write(''); for(var i=0; i < this.items.length; i++) { document.write(''); document.write(''); var bookLink = this.items[i].getBookLink(); //var bookLink = "/primary/newonix/domisbn/" + this.items[i].isbn + "?open&template=domPrimary&ed=site/primed3.nsf"; document.write(''); if(this.items[i].isEClub()&&((typeof checkTC != "undefined")&&(checkTC == true))) { document.write(''); document.write(''); } else { document.write(''); document.write(''); } document.write(''); document.write(''); document.write(''); //document.write(''); document.write(''); document.write(''); } document.write(''); document.write('
Book information
',isbn10to13(this.items[i].isbn),'',this.items[i].title,'-$',this.eClubPrice(i),'',this.items[i].price,'-remove
'); if((typeof checkTC != "undefined")&&(checkTC == true)) { document.write('

Total purchase
$',this.getEClubTotal(),'

'); } else { document.write('

Total purchase
$',this.getTotal(),'

'); } //document.write('
update order
'); document.write('
'); }; ShoppingCart.prototype.updateShoppingCartOverview = function() { var oBody = document.getElementById('bodyMiddle'); var tBody = oBody.getElementsByTagName('tbody'); var trItems = tBody[0].getElementsByTagName('tr'); for (var i = (trItems.length - 1); i > -1; i--) { tBody[0].removeChild(trItems[i]); } for(var i=0; i < this.items.length; i++) { tBody[0].appendChild(this.attachItem(i)); } var oTotal = document.getElementById('totalPrice'); if((typeof checkTC != "undefined")&&(checkTC == true)) { oTotal.innerHTML = "Total purchase
$" + this.getEClubTotal() + "
"; } else { oTotal.innerHTML = "Total purchase
$" + this.getTotal() + "
"; } this.checkRadioButtons(); }; ShoppingCart.prototype.checkRadioButtons = function() { var oTBody = document.getElementsByTagName('tbody'); var itemHolders = oTBody[0].getElementsByTagName('tr'); for(var i=0; i < itemHolders.length; i++) { var oTempInputs = itemHolders[i].getElementsByTagName('input'); var oInputs = new Array(); for(var n=0; n < oTempInputs.length; n++) { if(oTempInputs[n].type == "radio") oInputs.push(oTempInputs[n]); } oInputs[0].checked = false; oInputs[1].checked = false; if(this.items[i].buyInspect == "II") { oInputs[0].checked = true; } else { oInputs[1].checked = true; } } }; ShoppingCart.prototype.checkInspectBuy = function(ib,i) { if((this.items[i].buyInspect.substring(1)).toUpperCase() == ib)return true; return false; }; } this.load(); } function CartItem(item) { this.isbn = item[0]; this.title = item[1]; this.price = item[2]; this.buyInspect = item[3]; this.quantity = item[4]; this.divCatStr = item[5]; if(typeof CartItem._initialized == "undefined") { CartItem.prototype.cookieString = function() { return (this.isbn + "|" + this.title + "|" + this.price + "|" + this.buyInspect + "|" + this.quantity + "|" + this.divCatStr); }; CartItem.prototype.newCookieString = function() { if(this.divCatStr.indexOf('>') != -1) { var ciDivision = this.divCatStr.split('>')[0]; } else { var ciDivision = this.divCatStr; } return (this.isbn + "|" + this.buyInspect + "|" + this.quantity + "|" + ciDivision); }; } CartItem._initialized = true; } oCart = new ShoppingCart();