<!-- 

// Based on original code from costofwar.com/costofwar.js

var cur_war = 0;            // total amount spent on war in dollars
var cur_debt = 0;
var geographicscale = 1;    // scale the final number by this amount

function CalcWar ()
	{
	// 'totalms' is the number of milliseconds between Apr 17, 2003 (at which
	// point $50 billion had been spent) and Sep 30, 2004 (at which point
	// we'll have spent $135 billion).

	// We just accrue the amount linearly for now.  Close enough for government
	// work, as they say.
	//var totalms       = 53825644800;
	//var totalms       = 93139200000;

	//below value is number of milliseconds between april 17 2003 and september 30 2006
	//  var totalms       = 109036800000;
	//below value is number of milliseconds between april 17 2003 and March 31 2007
	//  var totalms       = 124761000000;
	//  var initialdollars= 0;
	//  var totaldollars  = 378000000000 - initialdollars;
	//  var rateperms     = totaldollars / totalms;
	// Updated since Jan 2007
	//   var totalms       = 137808000000;
	// Start Apr 17 2003 - Sept 30 2007

	var totalms = 140659200000;
	//var totalms = 2387520000;

	var initialdollars = 0;
	var totaldollars   = 456100000000 - initialdollars;
	var rateperms      = totaldollars / totalms;

	var startofwar = new Date ("Apr 17, 2003");
	var curdate = new Date ();
	var diff = curdate - startofwar;

	// If the current date precedes the start of war, then the calculation is invalid

	if (diff > 0)
		{
		cur_war = (initialdollars + diff * rateperms) * geographicscale;
		return true;
		}

	return false;
	}

// TreasuryDirect.gov provides historical debt records to the penny
// See http://www.treasurydirect.gov/NP/BPDLogin?application=np

// On 3/28/2007 the total outstanding debt was $8,840,925,181,060
// On 3/28/2008 the total outstanding debt was $9,407,933,186,655
// There are 365*24*60*60*1000 milliseconds in a year = 31,536,000,000

// The rate per year is:
//  Amount on (3/28/2008 - Amount on 3/28/2007) = 567,008,005,595
// The rate per millisecond is:
//  Amount on (Rate per year) / (365*24*60*60*1000) = 17.9797

// The calculation below should compensate for leap years. It
// calculates the current debt starting from last year's in case
// the user's calendar or clock are behind.

function CalcDebt ()
	{
	var strtamnt = 8840925181060;             // Debt amount on 3/28/2007
	var stopamnt = 9407933186655;             // Debt amount on 3/28/2008
	var strtdate = new Date ("Mar 28, 2007");
	var stopdate = new Date ("Mar 28, 2008");

	var debtrate = (stopamnt - strtamnt) / (stopdate - strtdate);
	var cur_date = new Date ();
	var timediff = cur_date - strtdate;       // Difference in milleseconds

	if (timediff > 0)
		{
		cur_debt = (strtamnt + timediff * debtrate) * geographicscale;
		return true;
		}

	return false;
	}

// Converts a number 'n' to a string with commas every three characters

function FormatDollars (n)
	{
	//var x = n.toFixed (0);  this doesn't seem to work on some browsers
	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 IncrementCounters (rate)
	{
	var  ele_war  = document.getElementById ("war");
	var  ele_debt = document.getElementById ("debt");
	var  txt_war; 
	var  txt_debt;

	if (ele_war && CalcWar ())
		{
		txt_war = FormatDollars (cur_war);
		}

	if (ele_debt && CalcDebt ())
		{
		txt_debt = FormatDollars (cur_debt);
		}

	// Modify the page quickly to prevent flicker
	if (txt_war)   ele_war.innerHTML = txt_war;
	if (txt_debt) ele_debt.innerHTML = txt_debt;

	setTimeout ('IncrementCounters('+rate+');', rate);
	}

// -->
