// JavaScript Document

//----------Begin of Calculator Functions----------------//

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function calculate(){
/*	- get user's input from FORM
  	- convert the annual rate to a monthly rate
   	- convert interest from a % to a decimal
   	- convert payment period from years to months
   	- compute the monthly payments */
	if(document.loan.method[document.loan.method.selectedIndex].value == '1'){
		var principal =
				document.loan.principal.value;
		var interest =
				document.loan.interest.value /100 /12;
		var payment =
				document.loan.years.value * 12;
		var x = Math.pow(1 + interest,payment);
		var months = (principal*x*interest) / (x-1);



		/*	check that the result is a finite number.
			If so display results */

		if ( !isNaN(months)
			&& (months != Number.POSITIVE_INFINITY)
			&& (months != Number.NEGATIVE_INFINITY) )
		 {document.loan.payment.value =
				rounding (months);
		  document.loan.total.value =
				rounding(months*payment);
		  document.loan.totalinterest.value =
				rounding((months*payment) - principal);
		 }		// EndofIf

		 // user's input invalid so display nothing.
		else
		 {document.loan.payment.value = "";
		  document.loan.total.value = "";
		  document.loan.totalinterest.value = "";
		 }		// EndofElse
	}else if(document.loan.method[document.loan.method.selectedIndex].value == '2'){
		var principal = document.loan.principal.value;
		document.loan.payment.value =  rounding(((document.loan.principal.value)*(document.loan.interest.value /100)) /12);

	}
}	// End Fn Calculate


// round to 2 decimal places function

function rounding(x) {
	return Math.round(x*100)/100;
}	
//End Fn rounding



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


//----------End of calculator-------------//

