if (Calculators == undefined) {
    var Calculators = {};
}
if (Calculators.type == undefined) {
    Calculators.type = {};
}
Calculators.type.Money = function Money(amount){
	// Allow for passing in a Money object or a number into the constructor
	if (amount.getAmount == undefined) {
		this.amount = new Number(amount);
		// If this isn't a Money object and it isn't a number, then default to zero
		if (isNaN(amount)) {
			this.amount = new Number(0.0);
		}
	}
	else {
		this.amount = new Number(amount.getAmount());
	}
    
    this.add = function(value){
		// Allow for passing in a Money object or a number
		if (value.getAmount == undefined) {
			return new Money(this.amount + value);
		}
		else {
			return new Money(this.amount + value.getAmount());
		}
    }
    
    this.subtract = function(value) {
		// Allow for passing in a Money object or a number
		if (value.getAmount == undefined) {
			return new Money(this.amount - value);
		}
		else {
			return new Money(this.amount - value.getAmount());
		}
    }
/*    
	this.getAmount = function() {
		return new Number(4);
		//return Math.round((this.amount * 100)) / 100;
	}
*/
    this.formatted = function(){
        return formatNumber(
			this.amount, // 1 - Number to format
			2, // 2 - decimal places
			',', // 3 - thousands separator
			'.', // 4 - decimal point
			'$', // 5 - Currency symbol prefix
			'', // 6 - Currency symbol suffix
			'-', // 7 - Negative number prefix
			'' // 8 - Negative number suffix
			);
    }
    
    // number formatting function
    // copyright Stephen Chapman 24th March 2006, 10th February 2007
    // permission to use this function is granted provided
    // that this copyright notice is retained intact
    
    function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2){
        var x = Math.round(num * Math.pow(10, dec));
        if (x >= 0) 
            n1 = n2 = '';
        var y = ('' + Math.abs(x)).split('');
        var z = y.length - dec;
        if (z < 0) 
            z--;
        for (var i = z; i < 0; i++) 
            y.unshift('0');
        y.splice(z, 0, pnt);
        if (y[0] == pnt) 
            y.unshift('0');
        while (z > 3) {
            z -= 3;
            y.splice(z, 0, thou);
        }
        var r = curr1 + n1 + y.join('') + n2 + curr2;
        return r;
    }
    
    this.rounded = function(){
        //return (Math.round(this.amount * 100)) / 100;
		return new Number(this.amount.toFixed(2));
    }
    
    this.getAmount = function(){
        return this.amount;
    }
}

