var stop;
var ticker;


function IframeOnLoad() {
  if (!loginTime) {
    loginTime = (new Date()).getTime();
  }
}
function el(id) {
  if (document.getElementById) {
    return document.getElementById(id);
  } else if (window[id]) {
    return window[id];
  }
  return null;
}



/* the format function from: http://javascript.internet.com/forms/currency-format.html
Original:  Cyanide_7 (leo7278@hotmail.com)
*/
function format(num) {
  num = num.toString().replace(/\$|\,/g,'');
      if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
            if(cents<10)
              cents = "0" + cents;
                    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                      num = num.substring(0,num.length-(4*i+3))+','+
                      num.substring(num.length-(4*i+3));
                      //return (((sign)?'':'-') + '$' + num + '.' + cents);
				return (((sign)?'':'-') + '$' + num);

}


//FUNCTIONS FOR GETTING INITIAL AMOUNT.



//Calculate the days Elapsed between 31 July 2004 (dateStart) and today.
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function daysElapsed() {
	//*****************NEED TO ADD LEAPYEAR CALCS.*************
	//for testing, this is set to 2003.
	//Javascript wierdness--06 returns July b/c Jan is 00.
	var dateStart = new Date(2005,04,20);
	var dateToday = new Date();
    var difference = Date.UTC(y2k(dateToday.getYear()),dateToday.getMonth(),dateToday.getDate(),0,0,0) - Date.UTC(y2k(dateStart.getYear()),dateStart.getMonth(),dateStart.getDate(),0,0,0);
    return difference/1000/60/60/24;
}

//Calculate the amount spent today and include the amount from the days before.
function calculateAmountSpent(){
	//Spending amounts  
	var baseSpendingAmount = (1712080000000);
	var spendingPerMinute = (120244); //*******THIS VALUE CAN CHANGE FOR UPDATES
	var spendingPerSecond = (spendingPerMinute/60); 
	var spendingPerMillisecond = (spendingPerMinute/60000);
	var spendingPerHour = (spendingPerMinute * 60);
	var spendingPerDay = (spendingPerHour * 24);
	var now = new Date();
	
	//amount up until now.
	var daysElapsedValue = daysElapsed()
	var daysElapsedAmount = (spendingPerDay * daysElapsedValue);
	
	var hoursElapsedValue = now.getHours();
	var hoursElapsedAmount = (spendingPerHour * hoursElapsedValue);
	
	var minutesElapsedValue = now.getMinutes();
	var minutesElapsedAmount = (spendingPerMinute * minutesElapsedValue);
	
	var secondsElapsedValue = now.getSeconds();
	var secondsElapsedAmount = (spendingPerSecond * secondsElapsedValue);

	var millisecondsElapsedValue = now.getMilliseconds();
	var millisecondsElapsedAmount = (spendingPerMillisecond * millisecondsElapsedValue)
	
	var amountSpent = baseSpendingAmount + daysElapsedAmount + hoursElapsedAmount + minutesElapsedAmount + secondsElapsedAmount + millisecondsElapsedAmount;

	ticker.innerHTML = format(amountSpent);
    if (document.frmReform.runTimer.value == "true")
	{
		setTimeout(calculateAmountSpent, 50);
	}
	
}
//END FUNCTIONS FOR INTIAL CALCULATIONS.

function reformSwap()
	{
		document.reform.src=document.frmReform.reformImage.value;
		if (document.frmReform.reformImage.value=="http://www.heritage.org/Research/Features/socialsecurity/js/noReform.gif")
		{
			document.frmReform.reformImage.value="http://www.heritage.org/Research/Features/socialsecurity/js/Reform.gif";
			document.frmReform.runTimer.value = "true";
		}else{
			document.frmReform.reformImage.value="http://www.heritage.org/Research/Features/socialsecurity/js/noReform.gif";
			document.frmReform.runTimer.value = "false";
		}
		calculateAmountSpent()
	}


document.write('<form name="frmReform"><input type="hidden" name="reformImage" value="http://www.heritage.org/Research/Features/socialsecurity/js/reform.gif"><input type="hidden" name="runTimer" value="true"></form><table width=149 height=110 border=0 cellpadding=0 cellspacing=0 background="http://www.heritage.org/Research/Features/socialsecurity/js/nodometer3.gif" style="background-repeat:no-repeat;"><tr><td align=center valign=middle width=149 height=88><a href="http://www.heritage.org/Research/SocialSecurity/NOdometer.cfm"><SPAN style="font-size:12px; font-family: courier new, courier; font-weight: bold; background-color:black; color:white;" id=ticker></SPAN></a></td></tr><tr><td><img src="http://www.heritage.org/Research/Features/socialsecurity/js/NoReform.gif" name="reform" OnClick="reformSwap();"></td></tr></table>');



ticker = el("ticker");
calculateAmountSpent();

