minlend=0;

maxlend=0;

minrefund=0;

maxrefund=0;



function exitapp ()

	{

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

 	if (exitapplication == true)

 		{

  		window.status="Closing"

		parent.window.close();

 		}

	}



function changetomonthly (num,period)

	{

	num.value=parseInt(num.value/period.value);

	checknum (num);

	period.selectedIndex=2;

	}



function checknum (num)

	{

	validate (num);

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

	}



function validate(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=0;

	}

if (num.value == "") num.value=num.defaultValue;

}



function calculateold ()

	{

	totalinc=parseInt(document.bpform.grossincome.value, 10)+parseInt(document.bpform.grossincome2.value, 10)+parseInt(document.bpform.otherincome.value, 10)+parseInt(document.bpform.otherincome2.value, 10);

	totalexp=parseInt(document.bpform.otherloans.value, 10)+parseInt(document.bpform.livingexp.value, 10);

	uncommittedinc=parseInt(totalinc, 10)-parseInt(totalexp, 10);

	qualrate=8;

	periodrate=(qualrate/12)/100;

	repayments=document.bpform.term.value*12;

	mindsr=0.25;

	maxdsr=0.30;

	minlend=((uncommittedinc*mindsr)*(1-Math.pow(1+parseFloat(periodrate, 10),-repayments)))/periodrate;

	maxlend=((uncommittedinc*maxdsr)*(1-Math.pow(1+parseFloat(periodrate, 10),-repayments)))/periodrate;

	document.bpform.minlend.value=parseInt(minlend,10);

	document.bpform.maxlend.value=parseInt(maxlend,10);

	document.bpform.minrefund.value=parseInt(minrefund,10);

	document.bpform.maxrefund.value=parseInt(maxrefund,10);

	}



function calculate ()

	{

	repaymentfreq=12;

	loanterm=document.bpform.term.value;

	grossincome=document.bpform.grossincome.value;

	grossincome2=document.bpform.grossincome2.value;

	otherincome=document.bpform.otherincome.value;

	otherincome2=document.bpform.otherincome2.value;

	creditcardlimit=document.bpform.cardlimit.value;

	otherloans=document.bpform.otherloans.value;

	adults=document.bpform.adults.value;

	dependants=document.bpform.dependants.value;

	minlend=bank1();

	maxlend=bank1();

	if (bank2() > maxlend) maxlend = bank2();

	if (bank2() < minlend) minlend = bank2();

	if (bank3() > maxlend) maxlend = bank3();

	if (bank3() < minlend) minlend = bank3();

	if (bank4() > maxlend) maxlend = bank4();

	if (bank4() < minlend) minlend = bank4();

	if (bank5() > maxlend) maxlend = bank5();

	if (bank5() < minlend) minlend = bank5();

	if (bank6() > maxlend) maxlend = bank6();

	if (bank6() < minlend) minlend = bank6();

	document.bpform.minlend.value=parseInt(minlend,10);

	document.bpform.maxlend.value=parseInt(maxlend,10);

	document.bpform.minrefund.value=parseInt(minlend*0.00144,10);

	document.bpform.maxrefund.value=parseInt(maxlend*0.004,10);

	}
