// JavaScript Document

function formatNumber(myNum, numOfDec) 
   { 
      var decimal = 1 
      for(i=1; i<=numOfDec;i++) 
         decimal = decimal *10 

      var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec) 
      return myFormattedNum;
   } 

function getSMOKECOST() 
{
sessioncost=200;
cost = document.SMOKEform.cost.value;
costs = parseFloat(cost);
if (isNaN(costs) || (costs==0))
   {
   alert("Please enter a number for your cost per pack");
   }
pack = document.SMOKEform.pack.value;
packs = parseInt(pack);
if (isNaN(packs) || (packs==0))
   {
   alert("Please enter a whole number for the number of packs smoked");
   }
weeklycost = packs*cost;
weekstosave = parseInt(sessioncost/weeklycost)+1;
SMOKECOST = (weeklycost*52)/12;
SMOKECOST = formatNumber(SMOKECOST,2);
oneyearsaving = ((weeklycost*52)-sessioncost);
oneyearsaving = formatNumber(oneyearsaving,2);
document.SMOKEform.SMOKECOST.value = SMOKECOST;
}
// JavaScript Document