function BookSelectCount() { this.count = 0; if(typeof BookSelectCount._initialized == "undefined") { BookSelectCount.prototype.load = function() { var packInputs = document.getElementsByClassName('input','lpUnits'); var bookInputs = document.getElementsByClassName('input','bUnits'); this.inputs = new Array(); this.inputs = packInputs.concat(bookInputs); //alert(packInputs.length + ' + ' + bookInputs.length + ' = ' + this.inputs.length); for(var i = 0; i < this.inputs.length; i++) { if(document.attachEvent) { this.inputs[i].onblur = function(oEvent){countBookSelected();}; } else { this.inputs[i].setAttribute('onblur','countBookSelected(event)'); } } }; BookSelectCount._VALIDPAGE = (typeof document.forms[0].PageType != 'undefined' && document.forms[0].PageType.value != 'onixProduct' && document.forms[0].PageType.value != 'home' && typeof document.forms[0].Template != 'undefined' && document.forms[0].Template.value == 'domPrimary'); } BookSelectCount._initialized = true; if(BookSelectCount._VALIDPAGE) { this.load(); } } function countBookSelected(oEvent) { var target = stopEvent(oEvent); var counted = (target.getAttribute('counted') != null && target.getAttribute('counted')== 'yes'); if(oCart.items.length < 85 && booksSelected.count < 85 &&((oCart.items.length + booksSelected.count) < 85)) { if(!counted && target.value != "") { booksSelected.count += 1; target.setAttribute('counted','yes'); } else { if(counted)booksSelected.count -= 1; target.setAttribute('counted','no'); } } else { if(oCart.items.length >= 85) { if(target.value != "") { alert('You have reached the maximum number of items allowed per order.\nPlease click Checkout to finalise this order before ordering more items.'); } } else { alert('You have selected the maximum number of items allowed per order.\nPlease click Add to order and then Checkout to finalise this order before selecting more items.'); } target.setAttribute('counted','no'); target.value = ""; } // target.value = booksSelected.count; } //addLoadEvent(function(){var booksSelected = new BookSelectCount();}); var booksSelected = new BookSelectCount(); //alert(booksSelected.count);