/* The Insurance Council has estimated the cost per month of insurance claims to be $20,000,000.
This script takes 12 months worth of this value, and divides by 31536000 (number of seconds per year) to get
a per-second value of claims. This value is added to the running total every second. 

Values are only estimates.
*/

var avgCostPerSecond = 240000000 / (365*24*60*60);

function updateCost(){
theCost = addCommas(Math.round(avgCostPerSecond * getSecondsCount() * 100)/100).replace('.00' , '');
//	theCost = addCommas(Math.round(avgCostPerSecond * getSecondsCount() * 100)/100).replace('.00' , '');
	if (document.getElementById && document.getElementById("cost")){
		document.getElementById("cost").innerHTML= "$" +  theCost;
	}
	setTimeout("updateCost()", 1000)
}



function getSecondsCount()
{
	var today=new Date()
	var newyears = new Date(today.getFullYear(), 0, 1) //Happy New Year
	return (today - newyears)/1000;
}


function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '.00';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	
	total = x1 + x2;
	var rgx = /\.[0-9]$/;
	if (rgx.test(total)) {
		total = total + "0"
	}

	return total;
}


// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id){
var obj = null;
if(document.getElementById){
/* Prefer the widely supported W3C DOM method, if
available:-
*/
obj = document.getElementById(id);
}else if(document.all){
/* Branch to use document.all on document.all only
browsers. Requires that IDs are unique to the page
and do not coincide with NAME attributes on other
elements:-
*/
obj = document.all[id];
}
/* If no appropriate element retrieval mechanism exists on
this browser this function always returns null:-
*/
return obj;
}


updateCost();

