//==========================================================================
// Function: fmtPrice(value)
// Description : Formats decimals to two places

function fmtPrice(value)
  {
    var result = Math.floor(value) + ".";
    var cents = 100*(value - Math.floor(value))+0.5;
    result += Math.floor(cents/10);
    result += Math.floor(cents%10);
    return result;
 }


//===========================================================================

//==========================================================================
// Function: calculate()
// Description : Orderform calculation

function calculate()
{
	//Calculate Celebrating Pregnancy - BEFORE SHIPPING AND TAXES
	
	qty_PregEng = document.sendorder.Qty_PregEng.value;
	PregEng_total = (document.sendorder.price_PregEng.value)*(document.sendorder.Qty_PregEng.value);
	document.sendorder.Amount_PregEng.value = fmtPrice(PregEng_total);
	
	qty_PregSpan = document.sendorder.Qty_PregSpan.value;
	PregSpan_total = (document.sendorder.price_PregSpan.value)*(document.sendorder.Qty_PregSpan.value);
	document.sendorder.Amount_PregSpan.value = fmtPrice(PregSpan_total);
	
	qty_PregPun = document.sendorder.Qty_PregPun.value;
	PregPun_total = (document.sendorder.price_PregPun.value)*(document.sendorder.Qty_PregPun.value);
	document.sendorder.Amount_PregPun.value = fmtPrice(PregPun_total);
	
	qty_PregViet = document.sendorder.Qty_PregViet.value;
	PregViet_total = (document.sendorder.price_PregViet.value)*(document.sendorder.Qty_PregViet.value);
	document.sendorder.Amount_PregViet.value = fmtPrice(PregViet_total);
	
	////////////////////////////////////////////////////
	
	qty_NewLifeEng = document.sendorder.Qty_NewLifeEng.value;
	NewLifeEng_total = (document.sendorder.price_NewLifeEng.value)*(document.sendorder.Qty_NewLifeEng.value);
	document.sendorder.Amount_NewLifeEng.value = fmtPrice(NewLifeEng_total);
	
	qty_NewLifeSpan = document.sendorder.Qty_NewLifeSpan.value;
	NewLifeSpan_total = (document.sendorder.price_NewLifeSpan.value)*(document.sendorder.Qty_NewLifeSpan.value);
	document.sendorder.Amount_NewLifeSpan.value = fmtPrice(NewLifeSpan_total);
	
	qty_NewLifePun = document.sendorder.Qty_NewLifePun.value;
	NewLifePun_total = (document.sendorder.price_NewLifePun.value)*(document.sendorder.Qty_NewLifePun.value);
	document.sendorder.Amount_NewLifePun.value = fmtPrice(NewLifePun_total);
	
	qty_NewLifeViet = document.sendorder.Qty_NewLifeViet.value;
	NewLifeViet_total = (document.sendorder.price_NewLifeViet.value)*(document.sendorder.Qty_NewLifeViet.value);
	document.sendorder.Amount_NewLifeViet.value = fmtPrice(NewLifeViet_total);
	
	////////////////////////////////////////////////////
	
	qty_Nutrition = document.sendorder.Qty_Nutrition.value;
	Nutrition_total = (document.sendorder.price_Nutrition.value)*(document.sendorder.Qty_Nutrition.value);
	document.sendorder.Amount_Nutrition.value = fmtPrice(Nutrition_total);
	
	////////////////////////////////////////////////////
	
	//Calculate Subtotal	
	subtotal = +(PregEng_total) + +(PregSpan_total) + +(PregPun_total) + +(PregViet_total) + +(NewLifeEng_total) + +(NewLifeSpan_total) + +(NewLifePun_total) + +(NewLifeViet_total) + +(Nutrition_total) ;
	document.sendorder.Subtotal.value = fmtPrice(subtotal);	
	
	//Calculate Shipping
	
	shipping_total = +(subtotal) * 0.05;
	
	if (shipping_total < 15.00)
	{
		shipping_total = 15.00;
	}
	else
	{
		// same shipping rate as previously calculated
	}
		

	document.sendorder.Shipping_Handling.value = fmtPrice(shipping_total);
	
	//Calculate GST
	//GST = ((+(subtotal) + +(shipping_total)) * 0.07);
	//document.sendorder.Sales_Tax.value = fmtPrice(GST);
	
	//Calculate Grand Total
	grandtotal = +(subtotal) + +(shipping_total);
	
	document.sendorder.TOTAL.value = fmtPrice(grandtotal);
	
}



//===========================================================================