
formatNumber = function(num, curr ) {
	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));
	if (curr == true) {
		return (((sign)?'':'-') + '$' + num + '.' + cents);
	} else {
		return (((sign)?'':'-') + num);
	}
};

buildTable = function( id, title ) { 
	var div = document.getElementById( id );
	var heading = document.createElement( 'div' );
	heading.id = id+'_title';
	heading.className = 'calc-title';
	heading.innerHTML = title;
	div.appendChild( heading );
	
	var inner = document.createElement( 'div' );
	inner.id = id+'_inner';
	inner.className = 'calc-inner';	
	
	var table = document.createElement( 'table' );
	table.width = '100%';
	table.id = id+'_table';
	var tbody = document.createElement("tbody");
	
	table.appendChild( tbody );
	inner.appendChild( table );

	var bottom = document.createElement( 'div' );
	bottom.className = 'calc-bottom';
	
	div.appendChild( inner );
	div.appendChild( bottom );
	
	return [ inner, table, tbody ];
};

buildTooltip = function( td, text ) {
	td.innerHTML += ' [?]';
	td.style.position = 'relative';
	td.style.cursor = 'pointer';
	var tooltip = document.createElement( 'div' );
	tooltip.className = 'tooltip';
	tooltip.innerHTML = text;
	td.onmouseover = function() { tooltip.style.display = 'block'; };
	td.onmouseout = function() { tooltip.style.display = 'none'; };
	td.appendChild( tooltip );
};