var CalcUtils = {

	roundUp : function(num, to){
		return Math.ceil(num / to) * to;	
	},

	roundTo : function(num, to){
		return Math.round(num / to) * to;
	},

	roundToHundredths : function(num){
		return this.roundTo(num, .01);
	},

	cleanNumber : function(num){
		var val = (num && num.replace) ? num.replace(/\(([^)]+)\)$/, '-$1').replace(/[^\d\.\-]/g, '') : num;
		if(val == ''){
			return 0;
		}
		if(isFinite(val)){
			return parseFloat(val);
		}
		return 0;
	},	
	
	formatNumberTo: function(num, to, useBlank){
		var roundedNum = this.roundTo(num, to);
		var decimal = Math.round((Math.abs(roundedNum) / to) % (1 / to)).toString();
		var numeral = (Math.floor(Math.abs(roundedNum))).toString();
		var digits = Math.round(Math.log(1/to)/Math.log(10));
		while(decimal.length < digits) decimal = '0' + decimal;
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(numeral)) {
			numeral = numeral.replace(rgx, "$1,$2");
		}
		return useBlank && num == 0 ? '' : num < 0 ? '(' + numeral + '.' + decimal + ')' : numeral + '.' + decimal;
	},
	
	cleanAndRoundTo: function(num, to){
		return this.roundTo(this.cleanNumber(num),to);
	},
	
	cleanAndRound : function(num){
		return this.cleanAndRoundTo(num,.01);
	},	
	
	formatNumber : function(num, useBlank){
		return this.formatNumberTo(num,.01, useBlank);
	}
};