<!--
function MortgageCalculator(sale_price, annual_interest_percent, year_term, down_percent) {
	this.sale_price = sale_price;
	this.annual_interest_percent = annual_interest_percent;
	this.year_term = year_term;
	this.down_percent = down_percent;
	this.base_rate = 0;
	this.down_payment = 0;
	this.annual_interest_rate    = 0;
	this.financing_price         = 0;
	this.monthly_factor          = 0;
	
	this.monthly_payment = 0;
	this.monthly_interest_rate = 0;
	this.getInterestFactor = getInterestFactorJSMC;
	this.calculateMonthlyPayment  = calculateMonthlyPaymentJSMC;
	this.getMonthlyPayment = getMonthlyPaymentJSMC;
	this.getMonthlyInterest = getMonthlyInterestJSMC;
}	

	// This function does the actual mortgage calculations
	// by plotting a PVIFA (Present Value Interest Factor of Annuity)
	function getInterestFactorJSMC() {
		factor = 0;
		this.base_rate = 1 + this.monthly_interest_rate;
		denominator = this.base_rate;
		for (i = 0; i < (this.year_term * 12); i++) {
			factor += (1 / denominator);
			denominator *= this.base_rate;
		}
		return factor;
	}		

	// This function calculates the monthly payment
	function calculateMonthlyPaymentJSMC() {			
			this.month_term = this.year_term * 12;
			this.down_payment            = this.sale_price * (this.down_percent / 100);
			this.annual_interest_rate    = this.annual_interest_percent / 100;
			this.monthly_interest_rate  = this.annual_interest_rate / 12;
			this.financing_price         = this.sale_price - this.down_payment;
			this.monthly_factor          = this.getInterestFactor();
			this.monthly_payment	= this.financing_price / this.monthly_factor;
			return this.monthly_payment;
	}
	
	// This function calculates and returns the monthly payment
	function getMonthlyPaymentJSMC() {	
		this.calculateMonthlyPayment();
		return this.monthly_payment;	
	}
	
	function getMonthlyInterestJSMC() {		
		this.calculateMonthlyPayment();
		return this.monthly_interest_rate;	
	}
//-->