// New (Non-CPU Intensive) Spend-o-meter code

var budgetBegin = 'July 1, 2009'; // Start of the fiscal year
//var budgetTotal = 7097129152				// Yearly Budget - FY 2008
// var budgetTotal = 7089139923		// Yearly Budget - FY 2009
var budgetTotal = 7236409345;
var budgetBeginTime = new Date(budgetBegin).getTime();
var budgetInc = budgetTotal/365/24/60/60/1000;		// $$ per ms
var budgetSpeed = 100;					// Key to being Non-CPU intensive

function updateSpendometerInput() {
  amount = ((new Date()).getTime()-budgetBeginTime)*budgetInc;

  if (amount > budgetTotal) {
    amount = budgetTotal; // If the amount is greater than the budget, only show the budget.
  } else {
    amount = currency(amount); // Translate this into currency w/ $ sign.
  }
  	document.getElementById('spendBox').value = amount; // Set input box value\
	setTimeout(updateSpendometerInput, budgetSpeed);
}

function updateSpendometerDiv() {
  amount = ((new Date()).getTime()-budgetBeginTime)*budgetInc;

  if (amount > budgetTotal) {
    amount = budgetTotal; // If the amount is greater than the budget, only show the budget.
  } else {
    amount = currency(amount); // Translate this into currency w/ $ sign.
  }
  	document.getElementById('redspend').innerHTML = amount; // Set input box value\
	setTimeout(updateSpendometerDiv, budgetSpeed);
}

function currency(nStr)
{
	nStr += '.00';
	x = nStr.split('.');
	x1 = x[0];
        x[1] = '.' + x[1] + '00';
	x2 = x[1].substr(0,3);
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return '$' + x1 + x2;
}