var basebookprice = 13.99; var baseaudioprice = 19.99; var shiponethrufour = 3.75; var shipfivethrunine = 6.75; var shiptenthrutwentyfour = 10.25; var shipovertwentyfive = 12.50; shiponethrufour = shiponethrufour.toFixed(2); shipfivethrunine = shipfivethrunine.toFixed(2); shiptenthrutwentyfour = shiptenthrutwentyfour.toFixed(2); shipovertwentyfive = shipovertwentyfive.toFixed(2); var discountonethrufour = 10; var discountfivethrunine = 15; var discounttenthrutwentyfour = 20; var discountovertwentyfive = 25; function bookunits(units) { /* make sure we have a real number to work with */ if (isNaN(units)) { alert ("Error: \n\nThis field can only contain numbers."); zeroout(); } else { /* update the price if a discount applies */ var newbookprice = basebookprice - discount(basebookprice, units); newbookprice = newbookprice.toFixed(2); document.forms[0].bookprice.value = newbookprice; document.getElementById("book_price").innerHTML = newbookprice; /* update the total */ var newbooktotal = newbookprice * units; document.getElementById("book_total").innerHTML = newbooktotal.toFixed(2); document.forms[0].booktotal.value = newbooktotal.toFixed(2); /* update total units */ document.getElementById("totalunits").innerHTML = Math.round(document.getElementById("book_units").value) + Math.round(document.getElementById("audio_units").value); /* update the subtotal */ var subt = (document.getElementById("book_total").innerHTML - 0) + (document.getElementById("audio_total").innerHTML - 0); document.getElementById("subtotal").innerHTML = subt.toFixed(2); document.forms[0].subtotal.value = subt.toFixed(2); /* update the shipping */ shipping(); /* update the grand total */ grandtotal(); } } function audiounits(units) { /* make sure we have a real number to work with */ if (isNaN(units)) { alert ("Error: \n\nThis field can only contain numbers."); zeroout(); } else { /* update the price if a discount applies */ var newaudioprice = baseaudioprice - discount(baseaudioprice, units); newaudioprice = newaudioprice.toFixed(2); document.forms[0].audioprice.value = newaudioprice; document.getElementById("audio_price").innerHTML = newaudioprice; /* update the total */ var newaudiototal = newaudioprice * units; document.getElementById("audio_total").innerHTML = newaudiototal.toFixed(2); document.forms[0].audiototal.value = newaudiototal.toFixed(2); /* update total units */ document.getElementById("totalunits").innerHTML = Math.round(document.getElementById("audio_units").value) + Math.round(document.getElementById("book_units").value); /* update the subtotal */ var subt = (document.getElementById("book_total").innerHTML - 0) + (document.getElementById("audio_total").innerHTML - 0); document.getElementById("subtotal").innerHTML = subt.toFixed(2); document.forms[0].subtotal.value = subt.toFixed(2); /* update the shipping */ shipping(); /* update the grand total */ grandtotal(); } } function shipping() { /* figure out the shipping charge */ var totunits = document.getElementById("totalunits").innerHTML; if (totunits <= 4) { document.getElementById("shippingtotal").innerHTML = shiponethrufour; document.forms[0].shippingtotal.value = shiponethrufour; } else if (totunits <= 9) { document.getElementById("shippingtotal").innerHTML = shipfivethrunine; document.forms[0].shippingtotal.value = shipfivethrunine; } else if (totunits <= 24) { document.getElementById("shippingtotal").innerHTML = shiptenthrutwentyfour; document.forms[0].shippingtotal.value = shiptenthrutwentyfour; } else if (totunits == 25) { document.getElementById("shippingtotal").innerHTML = shipovertwentyfive; document.forms[0].shippingtotal.value = shipovertwentyfive; } else if (totunits > 25) { var numunits = (totunits - 0); var cases = (numunits / 25); document.getElementById("shippingtotal").innerHTML = (shipovertwentyfive * cases); document.forms[0].shippingtotal.value = (shipovertwentyfive * cases); } } function grandtotal() { var gtotal = (document.getElementById("shippingtotal").innerHTML - 0) + (document.getElementById("subtotal").innerHTML - 0); document.getElementById("grandtotal").innerHTML = gtotal.toFixed(2); document.forms[0].grandtotal.value = gtotal.toFixed(2); } function discount (price, units) { /* figure out the discount applied */ if (units <= 4) { var disc = price * 0.1; disc = disc.toFixed(2); return disc; } else if (units <= 9) { var disc = price * 0.15; disc = disc.toFixed(2); return disc; } else if (units <= 24) { var disc = price * 0.2; disc = disc.toFixed(2); return disc; } else if (units >= 25) { var disc = price * 0.25; disc = disc.toFixed(2); return disc; } } function zeroout() { document.getElementById("audio_units").value = ""; document.getElementById("book_units").value = ""; document.getElementById("book_price").innerHTML = basebookprice; document.getElementById("audio_price").innerHTML = baseaudioprice; document.forms[0].bookprice.value = basebookprice; document.forms[0].audioprice.value = baseaudioprice; document.getElementById("grandtotal").innerHTML = "0"; document.getElementById("shippingtotal").innerHTML = "0"; document.forms[0].shippingtotal.value = "0"; document.forms[0].subtotal.value = "0"; document.getElementById("audio_total").innerHTML = "0"; document.forms[0].audiototal.value = "0"; document.getElementById("book_total").innerHTML = "0"; document.forms[0].booktotal.value = "0"; document.getElementById("subtotal").innerHTML = "0"; document.getElementById("totalunits").innerHTML = "0"; }