// This Calculator generated by the
// Budget Calculator Generator Javascript
// at http://javascript.about.com/library/blbudget.htm

function stripBlanks(fld) 
{
  var result = "";
  var c = 0;

  for (i=0; i < fld.length; i++)
  {
    if (fld.charAt(i) != " " || c > 0)
    {
      result += fld.charAt(i); 
      if (fld.charAt(i) != " ") c = result.length;
    }
  } 
  return result.substr(0,c);
}

function formatCurrency(num) 
{
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
    num = "0";

  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
    cents = "0" + cents;

  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));

  return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function budget(thisform) 
{
  var result =  0;
  var pd     = 17;
//   var in1 = stripBlanks(thisform.in1.value);
//   if (in1 != '' && in1 != parseFloat(in1)) 
//   {
//     alert("FundDesc must be numeric");thisform.in1.focus();return false;
//   }
//   result += Number(in1);

//   var pd = stripBlanks(thisform.pd.value);
//   if (pd != parseInt(pd)) 
//   {
//     alert("period must be numeric");thisform.pd.focus();return false;
//   }

  var qty1 = stripBlanks(thisform.qty1.value);
  if (qty1 != '' && qty1 != parseFloat(qty1)) 
  {
    alert("Quantity must be numeric");thisform.qty1.focus();return false;
  }
  result += (qty1 * pd);

  var qty2 = stripBlanks(thisform.qty2.value);
  if (qty2 != '' && qty2 != parseFloat(qty2)) 
  {
    alert("Quantity must be numeric");thisform.qty2.focus();return false;
  }
  result += (qty2 * pd);

  var qty3 = stripBlanks(thisform.qty3.value);
  if (qty3 != '' && qty3 != parseFloat(qty3)) 
  {
    alert("Quantity must be numeric");thisform.qty3.focus();return false;
  }
  result += (qty3 * pd);

  var qty4 = stripBlanks(thisform.qty4.value);
  if (qty4 != '' && qty4 != parseFloat(qty4)) 
  {
    alert("Quantity must be numeric");thisform.qty4.focus();return false;
  }
  result += (qty4 * pd);

//   var qty5 = stripBlanks(thisform.qty5.value);
//   if (qty5 != '' && qty5 != parseFloat(qty5)) 
//   {
//     alert("Quantity must be numeric");thisform.qty5.focus();return false;
//   }
//   result += (qty5 * pd);

//   var amount = "$0.00";
  var amount = formatCurrency(result);

  thisform.res.value = amount;
}
