// JavaScript Document
window.onload = initForm;

function initForm()
	{
	// Update the totals if the quantity or the state changes
	document.getElementById("state").onchange = quantityChanged;
	document.getElementById("quantity").onchange = quantityChanged;
	}
	
// Come here when the quantity has been changed
function quantityChanged()
	{
	var stemp = document.getElementById("quantity").value;		// The quantity for this item
	var nUnitPrice = 49.95;				// Place to set the unit price
	
	// Don't charge sales tax outside of CA
	var bSalesTax = true;				// Default
	if (document.getElementById("state").value != "CA")
		{
		bSalesTax = false;
		}
	
	
	var nSubTotal = stemp * nUnitPrice;
	var nTaxRate = 0.0725;
	nSubTotal = nSubTotal.toFixed(2);	// Keep only 2 digits to the right of the decimal point
	var nSalesTax = 0.00;				// Initialize
	if (bSalesTax == true)
		{
		nSalesTax = nSubTotal * nTaxRate;
		}
	nSalesTax = nSalesTax.toFixed(2);
	var nShipping = 4.95 + (0.50 * stemp);
	nShipping = nShipping.toFixed(2);
	var nTotal = parseFloat(nSubTotal) + parseFloat(nSalesTax) + parseFloat(nShipping);
	nTotal = nTotal.toFixed(2);
	
	document.getElementById("Item1Quandiv").innerHTML = stemp;
	document.getElementById("itemTest").innerHTML = "$" + nSubTotal;		// Set the item total
	document.getElementById("ItemSubtotaldiv").innerHTML = "$" + nSubTotal;	// Set the subtotal
	document.getElementById("Salestaxdiv").innerHTML = "$" + nSalesTax;		// Set the sales tax
	document.getElementById("Shippingdiv").innerHTML = "$" + nShipping;		// Set the shipping
	document.getElementById("Totaldiv").innerHTML = "$" + nTotal;			// Set the total
	document.getElementById("total").value = nTotal;						// Set the total hidden field
	document.getElementById("SubTotal").value = nSubTotal;					// Set the subtotal hidden field
	document.getElementById("SalesTax").value = nSalesTax;					// Set the sales tax hidden field
	document.getElementById("Shipping").value = nShipping;					// Set the shipping hidden field
	}
