<!-- 

// 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 ("Mar 30, 2004"); // 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!");
  }
  
  // Define some constants:
  var millisperday = 86400000;
  var initialamount = 108900241935;
  var sincethenperday = 104943725;

  // How many days have passed since Mar 30?
  var diffdays = diff / millisperday;

  // Do the actual calculations and get the amount before and after interest.
  // Note that we include the geographicscale as well.
  curamount = (initialamount + diffdays * sincethenperday) * 
                                 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);
}


// -->

