if (Calculators == undefined) {
	var Calculators = {};
}
if (Calculators.loan == undefined) {
	Calculators.loan = {};
}
Calculators.loan.UnknownLoanVariable = function UnknownLoanVariable(rate, periods) {
	this.rate = new Calculators.type.Rate(rate);
	this.periods = new Number(periods);
	this.loan = null;
	
	this.findLoanAmount = function(payment) {
		// PV(rate.monthly(), (periods), (-1 * payment), 0)
		var formula = new Calculators.math.Formulas();
		var amount = (-1 * formula.pv(this.rate.monthly(), this.periods, (-1 * payment), 0));
		this.loan = new Calculators.loan.Loan(this.rate.getAmount(), this.periods, amount);
		
		return new Calculators.type.Money(amount);
	}
	
	this.findMonthlyPayment = function(amount) {
		var formula = new Calculators.math.Formulas();
		var payment = (-1 * formula.pmt(this.rate.monthly(), this.periods, amount, 0, false));
		this.loan = new Calculators.loan.Loan(this.rate.getAmount(), this.periods, amount);
		
		return new Calculators.type.Money(payment);
	}
	
	this.getLoan = function() {
		return this.loan;
	}
	
	this.getMonthlyPayment = function() {
		if (this.loan == null) {
			return new Calculators.type.Money(0.00);
		}
		else {
			return this.loan.getMonthlyPayment();
		}
	}
	
	this.getLoanAmount = function() {
		if (this.loan == null) {
			return new Calculators.type.Money(0.00);
		}
		else {
			return this.loan.getPv();
		}
	}
	
	this.getInterestRate = function() {
		return this.rate;
	}
	
	this.getPeriods = function() {
		return this.periods;
	}
}

