<!--

			function toggle() {
				if (BTYPE == COOP) {
						document.getElementById("maint_common_label").innerHTML = "Maintenance";
						document.o_taxes = document.getElementById("div_taxes").innerHTML;
						document.getElementById("div_taxes").innerHTML = document.getElementById("div_shares").innerHTML;
						document.o_taxes = document.getElementById("div_taxes").innerHTML;
						document.getElementById("div_taxes").innerHTML = "";
				} else {
						document.getElementById("maint_common_label").innerHTML = "Common Charges";
						if (document.o_taxes) document.getElementById("div_taxes").innerHTML = document.o_taxes;
						document.getElementById("div_shares").style.display = "none";
						if (document.o_taxes) document.getElementById("div_taxes").innerHTML = document.o_taxes;
						document.getElementById("div_shares").style.display = "none";
				}
			}

			function calcSalePrice(obj) {
					str = calcMortgageTax(obj);
						if (!str) 
							return calcMansionTax(obj);
						else
							return str;
			}

			function calcMansionTax(obj) {
				if (parseInt(stonum(obj.value)) >= 1000000) {
					pct = .01;
				} else {
					pct = 0;
				}
				tax = parseFloat(stonum(obj.value) * pct);			
				document.getElementById("bf_mansion_tax").value = cent(tax);
				index = returnInputIndex("bf_mansion_tax");
				if (index > -1) {
					Inputs[index].setValue(document.getElementById("bf_mansion_tax").value);
				} 

				//recalculate();
			}

			function calcMortgageTax(obj) {
				mort_total = parseFloat(stonum(document.getElementById("bf_sale_price").value) -  stonum(document.getElementById("bf_cash_down").value));
				if (BTYPE == CONDO) {
						if (parseInt(stonum(mort_total)) > 500000) {
							pct = .01875;
						} else {
							pct = .0175;
						}
						tax = parseFloat(stonum(mort_total) * pct);			
						document.getElementById("bf_mortgage_tax").value = cent(tax);
					index = returnInputIndex("bf_mortgage_tax");
					if (index > -1) {
						Inputs[index].setValue(tax);
					}
				}


				//recalculate();
			}

			function calcClosing() {
				sale_price = document.getElementById("bf_sale_price");
				finance = document.getElementById("bf_mrtg_payoff_amt");

					sp = new String(sale_price.value);
					f = new String(finance.value);
					
					if (sp != "" && f != "") {
						cash_down = returnPercent(100 - parseFloat(stonum(f)),parseFloat(stonum(sp))); 
						document.getElementById("bf_cash_down").value = cent(cash_down);
					}

						index = returnInputIndex("bf_cash_down");
						
						if (index > -1) {
							Inputs[index].setValue(document.getElementById("bf_cash_down").value);
						} else {
							obj.value = document.o;
						}
			}

			
			function calcShortTerm() {
				MC = new MortgageCalculator(
					stonum(document.getElementById("bf_sale_price").value), 
					stonum(document.getElementById("bf_interest_rate").value),
					stonum(document.getElementById("bf_mrtg_payoff_years").value),
					100 - parseInt(stonum(document.getElementById("bf_mrtg_payoff_amt").value))
				);

				monthInterest = MC.getMonthlyInterest();
				document.getElementById("bf_short_term_interest").value = cent(monthInterest);

						index = returnInputIndex("bf_short_term_interest");
						
						if (index > -1) {
							Inputs[index].setValue(document.getElementById("bf_short_term_interest").value);
						} else {
							obj.value = document.o;
						}

				//recalculate();
			}

			function calcInterest(obj) {
				return (checkDecimals(obj));
				//recalculate();
			}

			function calcFinancing(obj) {
				if (obj.value != ""  && !parseInt(obj.value)) {
					alert("Please enter a whole number for the percent");
				}
				//recalculate();
			}

			function calcMansion(obj) {
					if (checkDecimals(obj)) {
						if (parseInt(obj.value) > 500000) {
							pct = .001875;
						} else {
							pct = .00175;
						}
						tax = parseFloat(document.getElementById("bf_sale_price").value * pct);			
						document.getElementById("bf_mortgage_tax").value = cent(tax);
					}
				//recalculate();
			}

			function calcMortgage(obj) {
				if (checkDecimals(obj)) {
					//calcShortTerm();
					//recalculate();			
				}
			}

			function calcMaintenance(obj) {
				return checkDecimals(obj); 
				//recalculate();
			}

			function checkTaxes(obj) {
				if (checkDecimals(obj)) {
					cent(obj.value);
				}
				//recalculate();
			}

			function calcBrokersFee() {
				amount = parseFloat(stonum(document.getElementById("bf_sale_price").value) * (stonum(document.getElementById("bf_mrtg_payoff_amt").value / 100)));
				if (parseFloat(stonum(document.getElementById("sf_brokers_fee_pct").value)) % .5 == 0) {
					fee = parseFloat(amount * (parseFloat(document.getElementById("sf_brokers_fee_pct").value) / 100));
					document.getElementById("bf_mortgage_fee_points").value = cent(fee);
						index = returnInputIndex("bf_mortgage_fee_points");
						if (index > -1) {
							Inputs[index].setValue(cent(fee));
						} else {
							obj.value = cent(document.o);
						}

				} else {
					return "Mortgage Brokers Fee: Please enter 1/2 increment amounts starting from 1";
				}

			}
			
			function calcTitle(obj) {
				if (BTYPE == CONDO) {
					pct = getTitlePercent(parseFloat(stonum(obj.value))).getPercent();
					min = getTitlePercent(parseFloat(stonum(obj.value))).getMin();
					if (parseFloat(pct) > 0) {
						document.getElementById("bf_title_insurance").value = cent(calcTitlePercent(stonum(obj.value), min, pct) + 299);
						tmp = cent(calcTitlePercent(stonum(obj.value), min, pct) + 299);
					} else {
						document.getElementById("bf_title_insurance").value = cent(299);
						tmp = cent(299);
					}


						index = returnInputIndex("bf_title_insurance");
						if (index > -1) {
							Inputs[index].setValue(tmp);
						} else {
							obj.value = cent(document.o);
						}

				}


			}

			function calcTitlePercent(total, min, pct) {
				if (BTYPE == CONDO) {
					tmp = 0;
					diff = Math.round(total - min);
					num = diff / 1000;
					
					if (num > 0) {
						for (i = 0; i < num; i++) {
							tmp = parseFloat(pct) + tmp;
						}
					}
					return tmp;
				}			
			}

			function TitleElement(min, max, pct) {
				this.min = stonum(min);
				this.max = stonum(max);
				this.percent = pct;
				this.isIn = isInTE;
				this.getPercent = getPercentTE;
				this.getMin = getMinTE;

			}

					function isInTE(total) {
						total = stonum(total);
						if (parseInt(total) >= parseInt(this.min) && parseInt(total) <= parseInt(this.max))
							return true;
						else if (this.max == "-1" && total > this.min)
							return true;
						return false;
					}
	
					function getPercentTE() {
						return parseFloat(this.percent);
					}

					function getMinTE() {
						return parseFloat(this.min);
					}


			function getTitlePercent(total) {
				var chart = new Array();
				chart[0] = new TitleElement("35,001","50,000","6.61");
				chart[1] = new TitleElement("50,001","100,000","4.10");
				chart[2] = new TitleElement("100,001","500,000","3.31");
				chart[3] = new TitleElement("500,001","1,000,000","2.96");
				chart[4] = new TitleElement("1,000,001","5,000,000","2.71");
				chart[5] = new TitleElement("5,000,001","10,000,000","2.47");
				chart[6] = new TitleElement("10,000,001","15,000,000","2.31");
				chart[7] = new TitleElement("15,000,001","-1","2.07");		
				for (i = 0; i < chart.length; i++) {
					if (chart[i].isIn(total))
						return chart[i];
				}
				return 0;
			}
			
			function recalculate() {
			var str = "";
			var total = 0;

				var str = "";
				str = calcSalePrice(document.getElementById("bf_sale_price"));	
				calcClosing();	
				str = calcMansionTax(document.getElementById("bf_sale_price"));	
				str = calcMortgageTax(document.getElementById("bf_sale_price"));
				str = calcBrokersFee();
				calcTitle(document.getElementById("bf_sale_price"));
				//calcShortTerm();
	
				//----- Final Tally
		
				for (i = 0; i < Inputs.length; i++) {
					if (MM_findObj(Inputs[i].getName())) {
						if (parseFloat(Inputs[i].getValue()) &&  Inputs[i].getName() != "bf_cash_down") {
							str += Inputs[i].getName() + ":" + Inputs[i].getValue() + "\n";
							//re = "/,/";
							total += parseFloat(stonum(Inputs[i].getValue()));
							//if (document.getElementById()) total += parseFloat(stonum());
						} else {
							total += 0;
						}
					}
				}

				//alert(str);
				setTotals(total, getSalePrice());
				return false;//for form submit
			}

			function getSalePrice() {
				return cent(stonum(document.getElementById("bf_sale_price").value));
			}

			function downPercent(total, portion) {
				return (total / portion) / 100;
			}
			
			function setTotals(total_closing, sale_price) {
				MC = new MortgageCalculator(
					stonum(document.getElementById("bf_sale_price").value), 
					stonum(document.getElementById("bf_interest_rate").value),
					stonum(document.getElementById("bf_mrtg_payoff_years").value),
					stonum(100 - parseInt(document.getElementById("bf_mrtg_payoff_amt").value))
				);

				monthlyMortgage = MC.getMonthlyPayment();
				document.getElementById("bf_total_closing_costs").value = cent(total_closing);
				//alert(cent(parseFloat(stonum(document.getElementById("bf_total_maintenance").value))) + ", " +  monthlyMortgage)	
				if (parseInt(document.getElementById("bf_cash_down").value) > 0) {
					if (BTYPE == COOP) {
						//alert(parseFloat(parseFloat(stonum(document.getElementById("bf_cash_down").value)) + parseFloat(stonum(total_closing))));
						cd = parseFloat(stonum(document.getElementById("bf_cash_down").value));
						tc = parseFloat(stonum(total_closing));
						document.getElementById("bf_cash_down_total").value = document.getElementById("bf_cash_down").value;
						document.getElementById("bf_total_funds").value = cent(parseFloat(cd + tc));
						document.getElementById("bf_total_maintenance").value = (document.getElementById("bf_maintenance_chg").value) ? cent(stonum(document.getElementById("bf_maintenance_chg").value)) : cent(0);
						document.getElementById("bf_monthly_mortgage_payment").value = cent(monthlyMortgage);
						document.getElementById("bf_total_monthly_payment").value = cent(parseFloat(stonum(document.getElementById("bf_total_maintenance").value)) + monthlyMortgage);
					} else {
						cd = parseFloat(stonum(document.getElementById("bf_cash_down").value));
						tc = parseFloat(stonum(total_closing));
						document.getElementById("bf_cash_down_total").value = document.getElementById("bf_cash_down").value;
						document.getElementById("bf_total_funds").value = cent(parseFloat(cd + tc));
						document.getElementById("bf_common_and_taxes").value = cent(parseFloat(stonum(document.getElementById("bf_maintenance_chg").value)) + parseFloat(stonum(document.getElementById("bf_taxes").value)));
						document.getElementById("bf_monthly_mortgage_payment").value = cent(monthlyMortgage);
						document.getElementById("bf_total_monthly_payment").value = cent(parseFloat(stonum(document.getElementById("bf_common_and_taxes").value)) + monthlyMortgage);
					}
				}
			}

			function focusfield(obj) {
				if (parseInt(obj.value) == 0) obj.value = "";
			}	

			function blurfield(obj) {

				if (obj.name == "bf_mrtg_payoff_amt") {

				} else if (obj.name == "bf_mrtg_payoff_years") {

				} else {

				/*
				if (obj.name == "bf_mortgage_fee_points") {
					calcBrokersFee();
				}

				if (obj.name == "bf_mortgage_fee_points") {
					calcBrokersFee();
				}
				*/
				
					document.o = obj.value;
					if (!obj.value) {
						obj.value = parseFloat(0);
					} else {
						if (checkDecimals(obj)) {
							index = returnInputIndex(obj.name);
							if (index > -1) {
								Inputs[index].setValue(obj.value);
							} else {
								obj.value = cent(document.o);
							}
							//recalculate();
						}
					}
				}
			}

			function returnPercent(percent, number) {
				return parseFloat(number * (percent / 100));
			}


			function returnInputIndex(name) {
				for (var i in Inputs) {
					if (Inputs[i].getName() == name) {
						return i;
					}
				}
				return -1;
			}
			
			
			function showCOOP() {
			var str = "";
				for (i = 0; i < Inputs.length; i++) {
					if (parseInt(Inputs[i].getBuildingType()) != parseInt(ALL)) {
						 if (parseInt(Inputs[i].getBuildingType()) == parseInt(COOP)) Inputs[i].enable(); else Inputs[i].disable();
					}
				}
				document.getElementById("maint_common_label").innerHTML = "Maintenance";
				document.o_taxes = document.getElementById("div_taxes").innerHTML;
				document.getElementById("div_taxes").innerHTML = "";

				/*
				for (i = 0; i < Inputs.length; i++) 
					str += (parseInt(Inputs[i].getBuildingType()) == parseInt(COOP)) ? Inputs[i].getName() + "\n" : "";
				alert(str);
				*/
			}
			
			function showCONDO() {
			var str = "";
				for (i = 0; i < Inputs.length; i++) {
					if (parseInt(Inputs[i].getBuildingType()) != parseInt(ALL)) {
						 if (parseInt(Inputs[i].getBuildingType()) == parseInt(CONDO)) Inputs[i].enable(); else Inputs[i].disable();
					}
				}
				document.getElementById("maint_common_label").innerHTML = "Common Charges";
				if (document.o_taxes) document.getElementById("div_taxes").innerHTML = document.o_taxes;
				document.getElementById("div_shares").style.display = "none";
			}

			function rightAlign (field, size) {
				size = field.size ? field.size : size ? size : 10;
				var v = field.value;
				while (v.length < size) {
					v = ' ' + v;
				}
				field.value = v;
			}

function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
	if (pK == 13) {
		recalculate();
	}
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
//-->