<!-- 

// 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 () {
  // '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       = 45964800000;
  var initialdollars= 50000000000;
  var totaldollars  = 135000000000 - initialdollars;
  var rateperms     = totaldollars / totalms;
          
  var startofwar = new Date ("Apr 17, 2003");
  var curdate = new Date ();
  var 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!");
  }
  
  // Do the actual calculations and get the amount before and after interest.
  // Note that we include the geographicscale as well.
  curamount = (initialdollars + diff * rateperms) * geographicscale;
}

// 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 = curamount / 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);
}


// -->
