NET2Util = function() {}

NET2Util.formatNumber = function(number, precision) {
	return NET2Util.addCommas(number.toFixed(precision));
}

NET2Util.formatCurrency = function(number) {
	return NET2Util.formatNumber(number, 2);
}
	
NET2Util.addCommas = function(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;
}

NET2Util.parseNumber = function(numStr)  {
	if (numStr == "") {
		return 0.0;
	}
	comma = numStr.lastIndexOf(",");
	dot = numStr.lastIndexOf(".");
	
	if (comma > -1 && dot > -1) {
		// Handle both a comma and a dot
		var dSep = comma > dot ? comma : dot;
		var tSep = comma > dot ? "." : ",";
		var decimals = numStr.substring(dSep+1);
		var number = numStr.substring(0, dSep).replace(tSep, "");
		return parseFloat(number + "." + decimals);
	} else if (comma > -1) {
		// Handle that there is only a comma
		return parseFloat(numStr.replace(",", "."));
	} else {
		// Handle that there is only a dot (or no dot)
		return parseFloat(numStr);
	}
}