<!--hide 



calcdone = "no";



function exitapp ()

	{

	var exitapplication= confirm("Exit the calculator?");

 	if (exitapplication == true)

 		{

  		window.status="Closing"

		parent.window.close();

 		}

	}



function checkfloat(num)

	{

	num.value=parseFloat(num.value, 10);

	if (num.value == 'NaN' || num.value == 'Nan' || num.value == 'nan' ) num.value = num.defaultValue;

	if (num.value < 5 || num.value > 20) {

		alert ("The interest rate must be between 5 and 20 percent");

		num.value = num.defaultValue;}

	}



function checknum (field, num)

	{

	if (calcdone == "yes"){

	alert ("The existing figures must be cleared to allow you to re-calculate");

	calculate();}

	else {

	validate (field, num);

	if (num.value != ""){

	switch (field)

		{	case "lterm":

			if (num.value < 1 || num.value > 30) {

			alert ("The loan term should be between 1 and 30 years.");

			num.value="";}

			else 

				if (document.rform.lamount.value != "" && document.rform.ramount.value != ""){

  				alert ("Please clear one of the other fields before entering a loan term.");

				num.value="";}

			break;

			case "lamount":

			if (document.rform.ramount.value != "" && document.rform.lterm.value != ""){

  			alert ("Please clear one of the other fields before entering a loan amount.");

			num.value="";}

			break;

			case "ramount":

			if (document.rform.lamount.value != "" && document.rform.lterm.value != ""){

  			alert ("Please clear one of the other fields before entering a repayment amount.");

			num.value="";}

			break;

			}

		if (num.value != "")

		num.value=parseInt(num.value, 10);

		}		

	}

}



function validate(field, num) {

var valid = "0123456789";

var ok = "yes";

var temp;

for (var i=0; i<num.value.length; i++) {

	tempchar = "" + num.value.substring(i, i+1);

	if (valid.indexOf(tempchar) == "-1") ok = "no";

	}

if (ok == "no") {

	alert("This is not a valid entry.\nPlease enter only whole numbers.");

	num.value="";

	}

}



function calculate ()

	{

		



	if (calcdone == "yes"){

		document.rform.intrate.value = document.rform.intrate.defaultValue;

		document.rform.rfrequency.selectedIndex = 2;

		document.rform.lamount.value = "";

		document.rform.ramount.value = "";

		document.rform.lterm.value = "";

		calcdone = "no";swdisc();}

	else {

	fieldsok = "no";

	prate = (parseFloat(document.rform.intrate.value, 10)/parseInt(document.rform.rfrequency.value,10))/100;



		if (document.rform.lamount.value != "" && document.rform.ramount.value != ""){

  		lamount=document.rform.lamount.value;

		ramount=document.rform.ramount.value;

		nrepayments=(Math.log(ramount/(ramount-parseFloat(lamount*prate))))/(Math.log(1+parseFloat(prate)))/document.rform.rfrequency.value;

			if (nrepayments > 35 || isNaN(nrepayments)){ 

			alert ("Based on the data entered, the term will be too large \n for our lenders to consider this loan.");

			// nrepayments=0 ;

			}

		document.rform.lterm.value = parseInt(nrepayments,10);

//		document.rform.lterm.value = parseInt(nrepayments/document.rform.rfrequency.value,10);

//		document.rform.lterm.value = (ramount/(ramount-parseFloat(lamount*prate)));

		fieldsok = "yes";

		calcdone = "yes";swdisc();}



		if (calcdone != "yes" && document.rform.lamount.value != "" && document.rform.lterm.value != ""){

  		lamount=document.rform.lamount.value;

		nrepayments=document.rform.lterm.value*document.rform.rfrequency.value;

		ramount=(lamount*(prate/(1-Math.pow(1+prate,-nrepayments))));

		document.rform.ramount.value=parseInt(ramount,10);

		fieldsok = "yes";

		calcdone = "yes";

		swdisc();}



		if (calcdone != "yes" && document.rform.ramount.value != "" && document.rform.lterm.value != ""){

		ramount=document.rform.ramount.value;

		nrepayments=document.rform.lterm.value*document.rform.rfrequency.value;

		lamount=(ramount*(1-Math.pow(1+prate,-nrepayments)))/prate;

		document.rform.lamount.value=parseInt(lamount,10);

		fieldsok = "yes";

		calcdone = "yes";swdisc();}



		if (fieldsok == "no")

		alert ("Not enough data entered, please enter values for 2 of the above fields.");

		} //End else statement.

	}

function swdisc(){	

var e=document.getElementById("d1");

		var f=document.getElementById("d2");

		e.style.display=(e.style.display=='none')?e.style.display='inline':e.style.display = 'none';

		f.style.display=(f.style.display=='none')?f.style.display='inline':f.style.display = 'none'; }

//--> 