function poOrderRecalc(e)
{
      if(!e) e = window.event;
      var item = e.target || e.srcElement;
      if(item != null && item.tagName == "INPUT")
	{
		    if(item.value.replace(/^\s+|\s+$/, '')=="")
			  item.value = "0";

	      var bookIds = getElementsByClassName(document, "table", "item");

	      var books = new Array(bookIds.length);
	      for(var i=0; i<bookIds.length; i++)
		    books[i] = new Book(bookIds[i].id);

	      var total = 0;
	      var subtotal = 0;
	      var itemTotal = 0;
	      var shipping = 0;
	      for(var i=0; i<books.length; i++)
		    for(var j=1; j<=books[i].getFormats(); j++)
		    {
			  if(!isInteger(document.getElementById(books[i].getId() + "_" + j + "_qty").value))
				return false;
			  itemTotal = parseBase10(document.getElementById(books[i].getId() + "_" + j + "_qty").value) * parseFloat(document.getElementById(books[i].getId() + "_" + j + "_price").innerHTML.substring(1).replace(',', ''));
			  document.getElementById(books[i].getId() + "_" + j + "_total").innerHTML = "$" + CommaFormatted(itemTotal.toFixed(2));
			  subtotal += itemTotal; 
		    }

		subtotal = subtotal.toFixed(2);
	      document.getElementById("poSubtotal").innerHTML = "$" + CommaFormatted(subtotal);

	      if(subtotal == 0)
		     shipping = 0;
	      else if(subtotal >= 25)
		    shipping = subtotal * 0.09;
	      else
		    shipping = 2.25;

		shipping = shipping.toFixed(2);
	      document.getElementById("poSH").innerHTML = "$" + CommaFormatted(shipping);

	      var tax = parseFloat(document.getElementById("poTaxInput").value);
	      var poTax = (subtotal * tax / 100.0).toFixed(2);
	      document.getElementById("poTax").innerHTML = "$" + CommaFormatted(poTax);

	      total = parseFloat(subtotal) + parseFloat(poTax) + parseFloat(shipping);
	      total = total.toFixed(2);
	      document.getElementById("poTotal").innerHTML = "$" + CommaFormatted(total);

	}
}

function Book(tagId)
{
	this.getId = getBookId;
	this.getFormats = getBookFormats;

	function getBookId() { return tagId.split("_")[0]; }
	function getBookFormats() { return parseInt(tagId.split("_")[1]); }
}

if (window.ActiveXObject)
      window.attachEvent('onload', poOrderRecalc);
else
      window.addEventListener('load', poOrderRecalc, false);