// Calculate the soap and grand totals 
function calculateTotals()  {
    var soapTotal, orderTotal;
   
    orderTotal = 0;

    for (i = 0; i <= document.getElementById("totalItems").value - 1; i++)  {
        soapTotal = document.getElementById("purchAmt" + i).value * document.getElementById("qty" + i).value;
        document.getElementById("soapTotal" + i).innerHTML = formatAsMoney(soapTotal);
        orderTotal += soapTotal
    }

    document.getElementById("orderTotal").innerHTML = "$&nbsp;&nbsp;" + formatAsMoney(orderTotal);
}

// Formats a number to two decimal places for currency values
 
function formatAsMoney(mnt) {
    mnt -= 0;

    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);    
}	 



