function mtgIns()
	{
	
	if(document.forms[0].DwnPmt1.value > "")
	{
	
	dwnpmtA = parseFloat(document.forms[0].DwnPmt1.value) / parseFloat(document.forms[0].PurchasePrice1.value)* 100;
	dwnpmtA = Math.round((dwnpmtA*100)+0.499)/100;
	
	
document.forms[0].LoanAmt1.value = document.forms[0].PurchasePrice1.value - document.forms[0].DwnPmt1.value;

g = document.forms[0].DwnPmt1.value/document.forms[0].PurchasePrice1.value;
	g = Math.round(g*1000)/1000;
	g = g*100;
document.forms[0].DwnPmtPct1.value = g + "%";


if ((document.forms[0].LoanAmt1.value > "")&&(document.forms[0].intrate1.value > "")){
f = parseFloat(document.forms[0].LoanAmt1.value)


m = parseFloat(document.forms[0].intrate1.value)


if(document.forms[0].loanterm1.selectedIndex == 0){
p = 30
}
if(document.forms[0].loanterm1.selectedIndex == 1){
p = 25
}
if(document.forms[0].loanterm1.selectedIndex == 2){
p = 20
}
if(document.forms[0].loanterm1.selectedIndex == 3){
p = 15
}
if(document.forms[0].loanterm1.selectedIndex == 4){
p = 10
}


	y = (1-Math.pow(1+(m/1200),-p*12))/(m/1200);
	y = Math.round((f/y*100)+0.499)/100;
	document.forms[0].PmtAmt1.value = y;
	
}
	
	if (document.forms[0].loanterm1.options.selectedIndex == 0){
		if ((dwnpmtA >= 3) && (dwnpmtA < 5)){
				document.forms[0].mtgInsPmt1.value = .96;
				}
		if ((dwnpmtA >= 5)&& (dwnpmtA < 10)) {
				document.forms[0].mtgInsPmt1.value = .78;
				}
		if ((dwnpmtA >= 10)&& (dwnpmtA < 15)){
				document.forms[0].mtgInsPmt1.value = .52;
				}
		if ((dwnpmtA >= 15)&& (dwnpmtA < 20)){
				document.forms[0].mtgInsPmt1.value = .32;
				}
		if (dwnpmtA >= 20) {
				document.forms[0].mtgInsPmt1.value = 0;
				}
	}

	if (document.forms[0].loanterm1.options.selectedIndex == 1) {
		if ((dwnpmtA >= 3) && (dwnpmtA < 5)) {
				document.forms[0].mtgInsPmt1.value = .85;
				}
		if ((dwnpmtA >= 5)&& (dwnpmtA < 10)) {
				document.forms[0].mtgInsPmt1.value = .67;
				}
		if ((dwnpmtA >= 10)&& (dwnpmtA < 15)){
				document.forms[0].mtgInsPmt1.value = .41;
				}
		if ((dwnpmtA >= 15)&& (dwnpmtA < 20)){
				document.forms[0].mtgInsPmt1.value = .21;
				}
		if (dwnpmtA >= 20) {
				document.forms[0].mtgInsPmt1.value = 0;
				}
	}
	
	if (document.forms[0].loanterm1.options.selectedIndex == 2) {
		if ((dwnpmtA >= 3) && (dwnpmtA < 5)) {
				document.forms[0].mtgInsPmt1.value = .80;
				}
		if ((dwnpmtA >= 5)&& (dwnpmtA < 10)) {
				document.forms[0].mtgInsPmt1.value = .56;
				}
		if ((dwnpmtA >= 10)&& (dwnpmtA < 15)){
				document.forms[0].mtgInsPmt1.value = .23;
				}
		if ((dwnpmtA >= 15)&& (dwnpmtA < 20)){
				document.forms[0].mtgInsPmt1.value = .19;
				}
		if (dwnpmtA >= 20) {
				document.forms[0].mtgInsPmt1.value = 0;
				}
	}
	
	if (document.forms[0].loanterm1.options.selectedIndex == 3) {
		if ((dwnpmtA >= 3) && (dwnpmtA < 5)) {
				document.forms[0].mtgInsPmt1.value = .80;
				}
		if ((dwnpmtA >= 5)&& (dwnpmtA < 10)) {
				document.forms[0].mtgInsPmt1.value = .56;
				}
		if ((dwnpmtA >= 10)&& (dwnpmtA < 15)){
				document.forms[0].mtgInsPmt1.value = .23;
				}
		if ((dwnpmtA >= 15)&& (dwnpmtA < 20)){
				document.forms[0].mtgInsPmt1.value = .19;
				}
		if (dwnpmtA >= 20) {
				document.forms[0].mtgInsPmt1.value = 0;
				}
	}
	

	

		if (dwnpmtA < 3){
	alert("Private mortgage insurance ordinarily is not available on loans with less than 3% down. The user should expect to pay a higher interest rate on the Buy Now Loan instead.");
document.forms[0].mtgInsPmt1.value = 0;
			}

	k = parseFloat(document.forms[0].LoanAmt1.value)*parseFloat(document.forms[0].mtgInsPmt1.value)/1200;
	k = Math.round((k*100)+0.499)/100;
	document.forms[0].mtgInsPmtAmt1.value = k;
	}
	}

function format(expr,decplaces){
	var str = "" + Math.round(eval(expr)*Math.pow(10,decplaces))
	while (str.length <= decplaces){
		str = "0" + str
		}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "" + str.substring(decpoint,str.length);
	}
	
function dollarize(expr){
	return "$" + format(expr,0)
	}
