// Welcome Visitors: I have tried to make the JavaScript here inviting
// so that you can read it and point out any mistakes I may have made
// in the calculation.  Feel free to e-mail me at niko@alum.mit.edu 
// if something is confusing or you think you have found a mistake.
// Vill du också ha en räknare? Kolla in: http://www.milspend.org/
// ===========================================================================
// Number Display and Updater

// This function modifies the global variable 'curamount' 
// to contain the total number of dollars spent on the war so far given the 
// estimates described in numbers.html.  
var totalms       = 31557600000;
var initialdollars= 0;
var totaldollars  = 1464000000000 - initialdollars;
var rateperms     = totaldollars / totalms;
thisyear			= new Date ();
dateStr = "Jan 1, "+thisyear.getFullYear();
var startofspend = new Date (dateStr);

function calc_amount ()
{
	var curdate = new Date ();
	var diff = curdate - startofspend;
	curamount = (initialdollars + diff * rateperms);
}

function number_str (n)
{
	var x = n.toString ();
	var dot = x.lastIndexOf ('.');
	x = x.substr (0, dot);
	var l = x.length;
	var res = "";
	for (l -= 3; l > 0; l -= 3)
	{
		res = " " + x.substr (l, 3) + res;
	}
	res = x.substr (0, l+3) + res;
	return res;
}

function inc_totals_at_rate(rate)
{
	calc_amount ();
	document.getElementById ("raw").innerHTML = "" + number_str(curamount);
	setTimeout('inc_totals_at_rate('+rate+');', rate);
}

function inc_totals ()
{
	inc_totals_at_rate (50);
}