function MM_openBrWindow(theURL,winName,features) { //v1.0
 window.open(theURL,winName,features);
}


<!-- /******************************************************************/ -->
<!-- /* calculateLoanAmount() - Invoked after pushbutton press. */ -->
<!-- /* Ensure that all fields are in a valid format, and that term, */ -->
<!-- /* interest rate, and monthly payment are filled prior to doing */ -->
<!-- /* calculation. */ -->
<!-- /******************************************************************/ -->
function doerase()
{
 var form = document.fincalc;
form.loanterm.value = "";
form.loaninterest.value= "";
form.loanpayment.value= "";
form.loanamount.value= "";
}
function calculateLoanAmount()
{
 var form = document.fincalc;

 if (fieldsValid(form, true)) {
 if (form.loanterm.value.length == 0) {
 alert("Debe indicar el número de cuotas.");
 form.loanterm.focus();
 }
 else if (form.loaninterest.value.length == 0) {
 alert("Debo conocer la tasa de Interes.");
 form.loaninterest.focus();
 }
 else if (form.loanpayment.value.length == 0) {
 alert("Para calcular el monto del prestamo original, debo conocer cuanto paga mensualmente.");
 form.loanpayment.focus();
 }
 else {
 doCalculateLoanAmount(form);
 }
 }
}

<!-- /******************************************************************/ -->
<!-- /* calculateMonthlyPayment() - Invoked after pushbutton press. */ -->
<!-- /* Ensure that all fields are in a valid format, and that term, */ -->
<!-- /* interest rate, and loan amount are filled prior to doing */ -->
<!-- /* calculation. */ -->
<!-- /******************************************************************/ -->
function calculateMonthlyPayment()
{
 var form = document.fincalc;

 if (fieldsValid(form, false)) {
 if (form.loanamount.value.length == 0) {
 alert("Debo saber cuanto fue el monto original para calcular sus cuotas mensuales");
 form.loanamount.focus();
 }
 else if (form.loanterm.value.length == 0) {
 alert("Cuantas cuotas son debe estar seleccionado.");
 form.loanterm.focus();
 }
 else if (form.loaninterest.value.length == 0) {
 alert("Debo conocer la tasa de Interes.");
 form.loaninterest.focus();
 }
 else {
 doCalculateMonthlyPayment(form);
 }
 }
}

<!-- /******************************************************************/ -->
<!-- /* doCalculateLoanAmount() - Calculates total amount of the loan */ -->
<!-- /* based on the term, interest, and monthly payment. For the */ -->
<!-- /* calculation, I will convert the yearly interest rate into a */ -->
<!-- /* monthly amount, then use the annuity formula to figure out */ -->
<!-- /* the total amount. */ -->
<!-- /******************************************************************/ -->
function doCalculateLoanAmount(form)
{
 var dMonthlyInterest = parseFloat(form.loaninterest.value) / (12*100);
 var dTerm = parseInt(form.loanterm.value);
 var dMoPmt = parseFloat(form.loanpayment.value);

 var dLoanAmount = dMoPmt * ((1/dMonthlyInterest) - 
 (1/(dMonthlyInterest * 
 Math.pow(dMonthlyInterest+1, dTerm))));
 
 // Round it to nearest cent...
 dLoanAmount = roundToCents(dLoanAmount);
 form.loanamount.value = "" + dLoanAmount;
} 

<!-- /******************************************************************/ -->
<!-- /* doCalculateMonthlyPayment() - Calculates mon. pmt. of the loan */ -->
<!-- /* based on the term, interest, and amount of loan. For the */ -->
<!-- /* calculation, I will convert the yearly interest rate into a */ -->
<!-- /* monthly amount, then divide the loan amount by the PV of $1 */ -->
<!-- /* using the annuity formula to figure out the monthly payment. */ -->
<!-- /******************************************************************/ -->
function doCalculateMonthlyPayment(form)
{
 var dMonthlyInterest = parseFloat(form.loaninterest.value) / (12*100);
 var dTerm = parseInt(form.loanterm.value);
 var dLoanAmount = parseFloat(form.loanamount.value);

 var dMoPmt = dLoanAmount / ((1/dMonthlyInterest) - 
 (1/(dMonthlyInterest * 
 Math.pow(dMonthlyInterest+1, dTerm))));
 
 // Round it to nearest cent...
 dMoPmt = roundToCents(dMoPmt);
 form.loanpayment.value = "" + dMoPmt;
} 

<!-- /******************************************************************/ -->
<!-- /* roundToCents() - Rounds a float to the nearest penny. */ -->
<!-- /******************************************************************/ -->
function roundToCents(dFloat)
{ 
 dFloat *= 100;
 dFloat = Math.round(dFloat);
 return (dFloat / 100);
}

<!-- /******************************************************************/ -->
<!-- /* fieldsValid() - Ensure that fields are in a valid format. */ -->
<!-- /******************************************************************/ -->
function fieldsValid(form, bLoanAmountCalculation)
{
 var bReturn = true;

 if (form.loanamount.value.length > 0 &&
 isNaN(form.loanamount.value) &&
 bLoanAmountCalculation == false) {
 alert("Por favor, solo ingrese numeros y el punto decimal. No use comas."); 
 form.loanamount.focus();
 bReturn = false;
 }
 else if (form.loaninterest.value.length > 0 &&
 isNaN(form.loaninterest.value)) {
 alert("La tasa de interés debe ser un numero.");
 form.loaninterest.focus();
 bReturn = false;
 }

 else if (form.loanpayment.value.length > 0 &&
 isNaN(form.loanpayment.value) &&
 bLoanAmountCalculation == true) {
 alert("Por favor, solo ingrese numeros y el punto decimal. No use comas.");
 form.loanpayment.focus();
 bReturn = false;
 }

 return bReturn;
}
 
<!-- /******************************************************************/ -->
<!-- /* fieldsFilled() - Checks to see that 3 items are filled. */ -->
<!-- /******************************************************************/ -->
function fieldsFilled(form)
{
 var iFieldsFilled = 0;

 if (form.loanamount.value.length > 0)
 iFieldsFilled++;
 if (parseInt(form.loanterm.value) > 0) 
 iFieldsFilled++;
 if (form.loaninterest.value.length > 0)
 iFieldsFilled++;
 if (form.loanpayment.value.length > 0)
 iFieldsFilled++;

 if (iFieldsFilled == 3) 
 return true;
 else
 alert("Debe ingresar 3 campos para hacer el calculo.");

 return false;
}

<!-- /******************************************************************/ -->
<!-- /* Interest Rate Calculation
<!-- /* Reversed engineered by CEO Corvette Hunt
<!-- /******************************************************************/ -->

		function doGetInterest(form) {

 var n = parseInt(form.loanterm.value);
 var a = parseFloat(form.loanamount.value);
 var m = parseFloat(form.loanpayment.value);


		var target=a/m;
		var p=0;
		do {
		p+=0.1;
		var acc=0;
		var base = 1 + p/1200;
		for (i=1;i<=n;i++) 
			{ acc += Math.pow(base,-i); }
}		while (target<acc);
p-=0.1;

 // Round it to nearest cent...
 p = roundToCents(p);
 form.loaninterest.value = "" + p;

	}

<!-- /******************************************************************/ -->
<!-- /* Monthly Terms Calculation
<!-- /* Reversed engineered by CEO Corvette Hunt
<!-- /******************************************************************/ -->

			function doGetTerm(form) {

 var a = parseFloat(form.loanamount.value);
 var m = parseFloat(form.loanpayment.value);
 var p = parseFloat(form.loaninterest.value) / (12*100);


		var target=a/m;

		var acc=0;
		var base = 1 + p/1200;
		var i=0;
		do {
		i++;
		acc += Math.pow(base,-i); 
}		while (target>acc);

 // Round it...
 i++;
 form.loanterm.value = "" + i;

	}
<!-- /******************************************************************/ -->
<!-- /* Improved by CEO Corvette Hunt - Checks for ANY of the variables missing 
<!-- /* and calculates it accordingly. */ -->
<!-- /******************************************************************/ -->

function docalcs()
{

 var form = document.fincalc;

 if (fieldsValid(form, true)) {
 if (fieldsFilled(form, true)) {
 if (form.loanterm.value.length == 0) {
 doGetTerm(form);
 }
 else if (form.loaninterest.value.length == 0) {
 doGetInterest(form);
 }
 else if (form.loanpayment.value.length == 0) {
 doCalculateMonthlyPayment(form);
 } 
 else if (form.loanamount.value.length == 0) {
 doCalculateLoanAmount(form);
 }

 getAmortization(form.loanamount.value,form.loanterm.value,form.loaninterest.value);
 
 }
}
}


