function mtgIns()
	{
	
	if (document.forms[0].BestGuess.value > ""){
	if(document.forms[0].RentMonths.value >= document.forms[0].BestGuess.value *12){
	alert("The number of months that you rent before you buy must be less than the holding period of the property");
	document.forms[0].BestGuess.focus();
	}
	}
	
	if(document.forms[0].AppreciationRate.value == ""){
	document.forms[0].AppreciationRate.value = 0;
	}
	if((document.forms[0].DwnPmt2.value > "") && (document.forms[0].RentMonths.value > "") && (document.forms[0].SavingsRate.value > ""))
	{

b = parseFloat(document.forms[0].RentMonths.value);
c = parseFloat(document.forms[0].DwnPmt2.value)-parseFloat(document.forms[0].DwnPmt1.value);
window.status = c
d = parseFloat(document.forms[0].SavingsRate.value);
	x = c/Math.pow(1+d/1200,b);
	y = (1-Math.pow(1+(d/1200),-b))/(d/1200);
	y = Math.round((x/y*100)+0.499)/100;
	document.forms[0].MonthlySvgs.value = y;
	}
	
	if(document.forms[0].DwnPmt1.value > "")
	{
a = parseFloat(document.forms[0].AppreciationRate.value);
b = parseFloat(document.forms[0].RentMonths.value);

x = Math.pow(1+a/100,b/12);
appreciationamount = (x * parseFloat(document.forms[0].PurchasePrice1.value)) - parseFloat(document.forms[0].PurchasePrice1.value);

	document.forms[0].PurchasePrice2.value = Math.round(parseFloat(document.forms[0].PurchasePrice1.value)+ appreciationamount);
	
	//document.forms[0].DwnPmt2.value = parseFloat(document.forms[0].DwnPmt1.value) + parseFloat(document.forms[0].MoreDwnPmt.value);
	
	dwnpmtA = parseFloat(document.forms[0].DwnPmt1.value) / parseFloat(document.forms[0].PurchasePrice1.value)* 100;
	dwnpmtA = Math.round((dwnpmtA*100)+0.499)/100;
	
	dwnpmtB = parseFloat(document.forms[0].DwnPmt2.value) / parseFloat(document.forms[0].PurchasePrice2.value) * 100;
	dwnpmtB = Math.round((dwnpmtB*100)+0.499)/100;

document.forms[0].LoanAmt1.value = document.forms[0].PurchasePrice1.value - document.forms[0].DwnPmt1.value;

document.forms[0].LoanAmt2.value = parseFloat(document.forms[0].PurchasePrice2.value) - document.forms[0].DwnPmt2.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].DwnPmt2.value == ""){
document.forms[0].DwnPmt2.focus();
}

if (document.forms[0].DwnPmt2.value > ""){
h = document.forms[0].DwnPmt2.value/document.forms[0].PurchasePrice2.value;
	h = Math.round(h*1000)/1000;
	h = h*100;
document.forms[0].DwnPmtPct2.value = h + "%";
}

if ((document.forms[0].LoanAmt1.value > "")&&(document.forms[0].intrate1.value > "")){
f = parseFloat(document.forms[0].LoanAmt1.value)
g = parseFloat(document.forms[0].LoanAmt2.value)

m = parseFloat(document.forms[0].intrate1.value)
n = parseFloat(document.forms[0].intrate2.value)

if(document.forms[0].loanterm1.selectedIndex == 0){
p = 40
}
if(document.forms[0].loanterm1.selectedIndex == 1){
p = 30
}
if(document.forms[0].loanterm1.selectedIndex == 2){
p = 25
}
if(document.forms[0].loanterm1.selectedIndex == 3){
p = 20
}
if(document.forms[0].loanterm1.selectedIndex == 4){
p = 15
}
if(document.forms[0].loanterm1.selectedIndex == 5){
p = 10
}

if(document.forms[0].loanterm2.selectedIndex == 0){
q = 40
}
if(document.forms[0].loanterm2.selectedIndex == 1){
q = 30
}
if(document.forms[0].loanterm2.selectedIndex == 2){
q = 25
}
if(document.forms[0].loanterm2.selectedIndex == 3){
q = 20
}
if(document.forms[0].loanterm2.selectedIndex == 4){
q = 15
}
if(document.forms[0].loanterm2.selectedIndex == 5){
q = 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].intrate2.value > ""){
	y = (1-Math.pow(1+(n/1200),-q*12))/(n/1200);
	y = Math.round((g/y*100)+0.499)/100;
	document.forms[0].PmtAmt2.value = y;
	}
}
	
	if (document.forms[0].loanterm1.options.selectedIndex == 0){
		if ((dwnpmtA >= 0) && (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 >= 0) && (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 == 2) {
		if ((dwnpmtA >= 0) && (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 == 3) {
		if ((dwnpmtA >= 0) && (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 == 4) {
		if ((dwnpmtA >= 0) && (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].loanterm2.options.selectedIndex == 0){
		if ((dwnpmtB >= 0) && (dwnpmtB < 5)){
				document.forms[0].mtgInsPmt2.value = .96;
				}
		if ((dwnpmtB >= 5)&& (dwnpmtB < 10)) {
				document.forms[0].mtgInsPmt2.value = .78;
				}
		if ((dwnpmtB >= 10)&& (dwnpmtB < 15)){
				document.forms[0].mtgInsPmt2.value = .52;
				}
		if ((dwnpmtB >= 15)&& (dwnpmtB < 20)){
				document.forms[0].mtgInsPmt2.value = .32;
				}
		if (dwnpmtB >= 20) {
				document.forms[0].mtgInsPmt2.value = 0;
				}
	}
	
	if (document.forms[0].loanterm2.options.selectedIndex == 1){
		if ((dwnpmtB >= 0) && (dwnpmtB < 5)){
				document.forms[0].mtgInsPmt2.value = .96;
				}
		if ((dwnpmtB >= 5)&& (dwnpmtB < 10)) {
				document.forms[0].mtgInsPmt2.value = .78;
				}
		if ((dwnpmtB >= 10)&& (dwnpmtB < 15)){
				document.forms[0].mtgInsPmt2.value = .52;
				}
		if ((dwnpmtB >= 15)&& (dwnpmtB < 20)){
				document.forms[0].mtgInsPmt2.value = .32;
				}
		if (dwnpmtB >= 20) {
				document.forms[0].mtgInsPmt2.value = 0;
				}
	}

	if (document.forms[0].loanterm2.options.selectedIndex == 2) {
		if ((dwnpmtB >= 0) && (dwnpmtB < 5)) {
				document.forms[0].mtgInsPmt2.value = .85;
				}
		if ((dwnpmtB >= 5)&& (dwnpmtB < 10)) {
				document.forms[0].mtgInsPmt2.value = .67;
				}
		if ((dwnpmtB >= 10)&& (dwnpmtB < 15)){
				document.forms[0].mtgInsPmt2.value = .41;
				}
		if ((dwnpmtB >= 15)&& (dwnpmtB < 20)){
				document.forms[0].mtgInsPmt2.value = .21;
				}
		if (dwnpmtB >= 20) {
				document.forms[0].mtgInsPmt2.value = 0;
				}
	}
	
	if (document.forms[0].loanterm2.options.selectedIndex == 3) {
		if ((dwnpmtB >= 0) && (dwnpmtB < 5)) {
				document.forms[0].mtgInsPmt2.value = .80;
				}
		if ((dwnpmtB >= 5)&& (dwnpmtB < 10)) {
				document.forms[0].mtgInsPmt2.value = .56;
				}
		if ((dwnpmtB >= 10)&& (dwnpmtB < 15)){
				document.forms[0].mtgInsPmt2.value = .23;
				}
		if ((dwnpmtB >= 15)&& (dwnpmtB < 20)){
				document.forms[0].mtgInsPmt2.value = .19;
				}
		if (dwnpmtB >= 20) {
				document.forms[0].mtgInsPmt2.value = 0;
				}
	}
	
	if (document.forms[0].loanterm2.options.selectedIndex == 4) {
		if ((dwnpmtB >= 0) && (dwnpmtB < 5)) {
				document.forms[0].mtgInsPmt2.value = .80;
				}
		if ((dwnpmtB >= 5)&& (dwnpmtB < 10)) {
				document.forms[0].mtgInsPmt2.value = .56;
				}
		if ((dwnpmtB >= 10)&& (dwnpmtB < 15)){
				document.forms[0].mtgInsPmt2.value = .23;
				}
		if ((dwnpmtB >= 15)&& (dwnpmtB < 20)){
				document.forms[0].mtgInsPmt2.value = .19;
				}
		if (dwnpmtB >= 20) {
				document.forms[0].mtgInsPmt2.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;
	l = parseFloat(document.forms[0].LoanAmt2.value)*parseFloat(document.forms[0].mtgInsPmt2.value)/1200;
	l = Math.round((l*100)+0.499)/100;
	document.forms[0].mtgInsPmtAmt2.value = l;
	}
	}

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)
	}
