function calculatePrice(DownPayment, InterestRate, MortgageYears, PaymentAmount) {
	var MonthlyRate = Number(InterestRate)/12/100;
	var NumPayments = Number(MortgageYears) * 12;
	//var LoanAmount = Number(PaymentAmount) * ((1 / Number(MonthlyRate)) * Math.pow(1 - (1/(1 + Number(MonthlyRate)))), Number(NumPayments));
	var LoanAmount = Number(PaymentAmount) * ((1/Number(MonthlyRate)) * (1 - Math.pow((1/(1+Number(MonthlyRate))), Number(NumPayments))));
	return Number(LoanAmount) + Number(DownPayment);
}

function fillPrices(DownPayment, InterestRate, MortgageYears, MinPaymentAmount, MaxPaymentAmount, MinInput, MaxInput) {
	if ((DownPayment != '' && IsNumeric(DownPayment)) && (InterestRate != '' && IsNumeric(InterestRate)) && (MortgageYears != '' && IsNumeric(MortgageYears)) && (MinPaymentAmount != '' && IsNumeric(MinPaymentAmount))) {
		MinInput.value = calculatePrice(DownPayment, InterestRate, MortgageYears, MinPaymentAmount).toFixed(0);
	};
	if ((DownPayment != '' && IsNumeric(DownPayment)) && (InterestRate != '' && IsNumeric(InterestRate)) && (MortgageYears != '' && IsNumeric(MortgageYears))&& (MaxPaymentAmount != '' && IsNumeric(MaxPaymentAmount))) {
		MaxInput.value = calculatePrice(DownPayment, InterestRate, MortgageYears, MaxPaymentAmount).toFixed(0);
	}
}

function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
 		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}