if (Calculators == undefined) {
	var Calculators = {};
}
if (Calculators.loan == undefined) {
	Calculators.loan = {};
}
Calculators.loan.Lease = function Lease(downPayment, leaseTerms, monthlyPayment, rateOfReturn) {
	
	this.downPayment = new Calculators.type.Money(downPayment);
	this.leaseTerms = new Number(leaseTerms);
	this.monthlyPayment = new Calculators.type.Money(monthlyPayment);
	this.rateOfReturn = new Calculators.type.Rate(rateOfReturn);


    this.getDownpayment = function() {
		return this.downPayment;
	}

    this.getNumberOfTerms = function() {
		return this.leaseTerms;
	}
	
    this.getMonthlyPayment = function() {
		return this.monthlyPayment;
	}
	
    this.getRateOfReturn = function() {
		return this.rateOfReturn;
	}
	
	this.getTotalMonthlyPayments = function() {
		return new Calculators.type.Money(this.leaseTerms * this.monthlyPayment.getAmount());
	}
	
	this.getInterestLostOnDownPayment = function() {
		var formula = new Calculators.math.Formulas();
		var fv = formula.fv(this.rateOfReturn.monthly(), this.leaseTerms, 0, this.downPayment.getAmount());
		var value = (-1 * fv) - this.downPayment.getAmount();
		return new Calculators.type.Money(value);
	}
	
	this.getInterestLostOnPayments = function() {
		var totalPayments = this.getTotalMonthlyPayments().getAmount();
		var formula = new Calculators.math.Formulas();
		var fv = formula.fv(this.rateOfReturn.monthly(), this.leaseTerms, this.monthlyPayment.getAmount(), 0);
		var value = (-1 * fv) - totalPayments;
		return new Calculators.type.Money(value);
	}
	
	this.getInterestLost = function() {
		return this.getInterestLostOnDownPayment().add(this.getInterestLostOnPayments());
	}
	
	this.getNetCost = function() {
		var totalPayments = this.getTotalMonthlyPayments().getAmount();
		var lostInterest = this.getInterestLost().getAmount();
		return new Calculators.type.Money(this.downPayment.getAmount() +
			totalPayments + lostInterest);
	}
}

