function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
  
function removeCommas(nStr)
{
	return nStr.replace(/\,/g, "");
}
 
//formats a number 
//arguments:@num = number to format
//			@rnd = number of decimal places to round to, -1 = dont round
//			@commas = 0 = dont add commas, 1 = add commas
//			@currency = 0 = don't format as currency, 1 = format as currency
function formatNum(num, rnd, commas, currency)
{
	num = parseFloat(num);
	
	if(rnd >= 0) {
		num = num.toFixed(rnd);
	}
	
	if(commas == 1) {
		num = addCommas(num);
	}
	
	if(currency == 1) {
		num = "$" + num;
	}
	
	return num;
}
