<!-- 

// Please see http://costofwar.com/costofwar-large.js for comments and
// more details.  This is a stripped down version designed for embedding.

var curamount=0;  	   // total amount spent on war in dollars
var curscale=0;   	   // number of dollars per alternate scale
var curunit="";   	   // name of the alternate scale
var geographicscale=1; // scale the final number by this amount

function calc_amount () {
  startofwar = new Date ("Apr 17, 2003"); // see numbers.html for explanation
  curdate = new Date ();
  diff = curdate - startofwar;

  if (diff < 0) {
    alert ("costofwar.com uses your computers date to calculate the cost. "+
           "Yours must be wrong because according to your computer the war "+
	   "hasn't even started yet!");
  }
  
  var millispermonth = 2678400000;                // 31*24*60*60*1000
  var initialamount = 34000000000;                // 34 billion spent by Apr 17
  var sincethen = 3900000000 / millispermonth;    // 3.9 bil / month
  var interest = 1.4;                             // 40% more due to interest

  compareamount = (initialamount + diff * sincethen) * geographicscale;
  curamount = compareamount * interest;
}

// Converts a number 'n' to a string with commas every three characters.
function number_str (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 inc_totals_at_rate(rate) {
  calc_amount ();
  document.getElementById ("raw").firstChild.nodeValue = 
  "$" + number_str(curamount);
  try {
    if (curscale != 0) {
  	    var altamount = compareamount / curscale;
  	    document.getElementById ("alt").firstChild.nodeValue =
  	    number_str(altamount) + curunit;
    }
    else {
  	    document.getElementById ("alt").firstChild.nodeValue = "";
    }
  } catch (e)
  {
     // ignore if there is no 'alt' element
  }
  setTimeout('inc_totals_at_rate('+rate+');', rate);
}

// For backwards compatibility, this function will cause the totals to
// increment at a rate of 100ms.
function inc_totals ()
{
  inc_totals_at_rate (100);
}


// -->
