				function initPage ()
				{
					f = document.forms["monthly"];
					calcAmount (f.dep_percent, f.prop_price, f.dep_amt);
				}

				function switchDeposit (on, off)
				{
					if (on.style) {
						on.style.background = "#ffffff";
					}
					if (off.style) {
						off.style.background = "#cccccc";
					}
					return;
				}

				function recalculate_Amount()
				{
					f = document.forms["monthly"];
					if (isNaN(f.prop_price.value))
					{
						alert("Please enter a valid property price");
						return false;
					}
					else
					{
						if ((!isNaN(f.dep_amt.value))&&(f.dep_amt.value!=""))
						{
							return calcPercent (f.dep_amt, f.prop_price, f.dep_percent);
						}
					}
				}

				function calcPercent (amt, prp, per)
				{

					if ((amt.value == "")&&(per.value == ""))
					{
						alert("Please enter a valid deposit amount/percentage");
						return false;
					}
					else
					{
						if (amt.value != "")
						{
							if (isNaN(amt.value))
							{
								alert("Please enter a valid deposit amount");
								return false;
							}
							else
							{
								var x = (amt.value / prp.value) * 100;
								per.value = (Math.round (x * 100) / 100);
								subtractDeposit (amt.value, prp.value, per.value);
								return;
							}
						}
					}
				}

				function calcAmount (per, prp, amt)
				{
					if ((amt.value == "")&&(per.value == ""))
					{
						alert("Please enter a valid deposit amount/percentage");
						return false;
					}
					else
					{
						var pv = Trim(per.value).replace("%","");				
						if (pv != "")
						{
							if (isNaN(pv))
							{
								alert("Please enter a valid percentage");
								return false;
							}
							else
							{
								var number = parseFloat(pv);
								per.value=(Math.round(number*100)/100); 
								var x = (per.value / 100) * prp.value;
								amt.value = (Math.round (x * 100) / 100);
								subtractDeposit (amt.value, prp.value, per.value);
								return true;
							}
						}
					}
				}


				function subtractDeposit (dep, prp, per)
				{
					if(isNaN(prp))
					{
						alert("Please enter a valid property price");
						return false;
					}
					if(isNaN(dep))
					{
						alert("Please enter a valid deposit amount");
						return false;
					}

					myLoanAmount = prp - dep;

					if (myLoanAmount > 0)
					{
						document.monthly.loan_amt.value = (prp - dep);
						return;
					}
					else
					{
						alert("The deposit is greater than the purchase price.");
						document.monthly.loan_amt.value = "";
						document.monthly.dep_amt.value = "";
						document.monthly.dep_percent.value = "";
						document.monthly.prop_price.focus();
						return true;
					}
				}

				function LTrim(str)
				{
					var whitespace = new String(" \t\n\r");
					var s = new String(str);
					if (whitespace.indexOf(s.charAt(0)) != -1) {
						var j=0, i = s.length;
						while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
								j++;
						s = s.substring(j, i);
					}
					return s;
				}

				function RTrim(str)
				{
					var whitespace = new String(" \t\n\r");
					var s = new String(str);
					if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
						var i = s.length - 1;       // Get length of string
						while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
								i--;
						s = s.substring(0, i+1);
					}
					return s;
				}

				function Trim(str)
				{
					return RTrim(LTrim(str));
				}

				function getMonthlyPayment (f)
				{
					if (f.dep_amt.value == "");

					var loan_amt = Trim(f.loan_amt.value);
					if(isNaN(loan_amt))
					{
						alert("Please enter a valid loan amount");
						return false;
					}
					var repay_term = Trim(f.repay_term.value);
					if(isNaN(repay_term))
					{
						alert("Please enter a valid repayment term");
						return false;
					}
					var dep = Trim(f.dep_amt.value);
					if(isNaN(dep))
					{
						alert("Please enter a valid deposit amount");
						return false;
					}
					var int_rate = Trim(f.int_rate.value).replace("%","");
					if(isNaN(int_rate))
					{
						alert("Please enter a valid interest rate");
						return false;
					}

					f.loan_amt.value=loan_amt;
					f.repay_term.value=repay_term;
					f.dep_amt.value=dep;
					f.int_rate.value=int_rate;

					if((!f.dep_amt.value)&&(f.dep_percent.value))
					{
						if (calcAmount(f.dep_percent, f.prop_price, f.dep_amt)) {
							return getMonthlyPayment(f);
						}
						else {
							return false;
						}
					}
					var out = "";
					out += (dep == "")?"\t- Please enter a deposit amount/percentage.\n":"";
					out += (loan_amt == "")?"\t- Please enter a loan amount.\n":"";
					out += (repay_term == "")?"\t- Please enter a repayment term.\n":"";
					out += (int_rate < 0.001)?"\t- Please set an interest rate higher than 0.001%.\n":"";
					out += (int_rate > 25)?"\t- Please set an interest rate lower than 25%.\n":"";
					out += (repay_term < 1)?"\t- Please set the repayment term to one year or more.\n":"";
					out += (repay_term > 50)?"\t- Please set the repayment term to less than 51 years.\n":"";
					if (out != "")
					{
						sendMessage ("Before we can calculate your repayments...", out, 50);
						return;
					}
					else
					{
						var temp_rate = (int_rate.indexOf ("%") == -1)?int_rate:stripPercent(int_rate);
						f.mon_cost.value = doMonthlyFormula (loan_amt, temp_rate, repay_term, f.mort_type.options[f.mort_type.selectedIndex].value);
						return;
					}
				}

				function stripPercent (str)
				{
					var out = str.substring (0, str.length - 1);
					return (out);
				}

				function doMonthlyFormula (loan, int_rate, rep_term, mort_type)
				{

					
					var numerator = loan * int_rate / 1200;
					var result = 0;

					if (mort_type == 0)
					{
						//alert ("Repayment Mort");
						with (Math)
						{
							var denominator = 1 - 1 / (pow (1 + int_rate / 1200, rep_term * 12));
						}
						result = numerator / denominator;
					}
					else
					{
						result = numerator;
					}

					if (result == 0) result = "";
					return (Math.round (result * 100) / 100);
				}

				function getMaxBorrow (f)
				{
					alert ("getMaxBorrow func");
					var main_sal = f.main_sal.value;
					var main_freq = f.main_freq.options[f.main_freq.selectedIndex].value;
					var part_sal = f.part_sal.value;
					var part_freq = f.part_freq.options[f.part_freq.selectedIndex].value;
					var joint = false;
					if (main_sal == "")
					{
						f.amount.value = "0.00";
						sendMessage ("In order to calculate this figure...", "\t- Please enter your salary.\n", 50);
						return;
					}
					else
					{
						if (part_sal != "")
						{
							joint = true;
						}
						f.amount.value = doMaxFormula (main_sal, main_freq, part_sal, part_freq, joint);
						return;
					}
				}

				function doMaxFormula (ms, mf, ps, pf, j)
				{
					alert ("doMaxFormula func");
					var s_mult = 3.5;
					var j_multA =2.7;
					var j_multB = 3.5;
					var result = 0;

					if (ps == "")
					{
						// Single salary
						result = (s_mult * (ms * mf));
					}
					else
					{
						var resA = 0;
						var resB = 0;
						resA = (j_multA * ((ms * mf) + (ps * pf)));
						resB = ((j_multB * (ms * mf)) + (ps * pf));
						result = (resA > resB)?resA:resB;
					}
					return (Math.round (result * 100) / 100);
				}

				function sendMessage (Title, out, width)
				{
				
					var divide = "";
					for (i = 0; i < width; i++)
					{
						divide += "_";
					}
					var top = divide + "\n\n" + Title + "\n\n";
					var bottom = "\n" + divide + "\n\nClick OK to continue.\n";
					alert (top + out + bottom);
					return;
				}

				function redirectOpener (url)
				{
					var w = window.opener;
					w.location = url;
					return false;
				}

				function closeWindow()
				{
					close();
				}

function CalculateAgain(o){
	document.getElementById("pnlAmount").style.display = "none";
	o.salary1.value = "";
	o.salary2.value = "";
	o.salary1.focus();
}

function Test_this(thisPg)
{
	if (thisPg.salary2.value.length > 0 && isNaN(thisPg.salary2.value))
	{
		alert("If you wish to provide your Partners salary, please provide a valid amount");
		thisPg.salary2.focus();
		return false;
	}
	
	if (thisPg.salary1.value.length == 0 || isNumeric(thisPg.salary1.value))
	{
		alert("Please enter a valid amount for your salary");
		thisPg.salary1.focus();
		return (false);
	}
	else
	{
		var iAmount = 0;
		var s = thisPg.salary1.value;
		var r = '';
		for (i=0; i < s.length; i++)
		{
			if (s.charAt(i) != ',')
			{
				r += s.charAt(i);
			}
		}
		var salary1 = r;

		if (thisPg.salary2.value == "")
		{
			iAmount = salary1*4.5;
		}
		else
		{
			var s = thisPg.salary2.value;
			var r = '';
			for (i=0; i < s.length; i++)
			{
				if (s.charAt(i) != ',')
				{
					r += s.charAt(i);
				}
			}
			var salary2 = r;
			iAmount = (parseInt(salary1) + parseInt(salary2))*4.5;
			//thisPg.amount.value = (parseInt(salary1) + parseInt(salary2))*3.5;
		}
		document.getElementById("txtAmount").innerHTML = formatCurrency(iAmount);
		document.getElementById("pnlAmount").style.display = "block";
		return (true);
	}
}

function isNumeric(sValue){
	
			var s = sValue;
			var r = '';
			for (i=0; i < s.length; i++)
			{
				if (s.charAt(i) != ',')
				{
					r += s.charAt(i);
				}
			}
			var salary2 = r;
			if (isNaN(r)){
				return true;
			}else{
				return false;
			}

}

function Reset_this(thisPg)
{
	thisPg.salary1.style.visibility='visible';
	thisPg.salary2.style.visibility='visible';
	thisPg.calculate.style.visibility='visible';
	thisPg.txt1.style.visibility='visible';
	thisPg.txt2.style.visibility='visible';
	thisPg.reset.style.visibility='hidden';
	thisPg.result.style.overflow='hidden';
	thisPg.result.style.width='1';
}

function Show_this(thisPg)
{
	thisPg.salary1.style.visibility='hidden';
	thisPg.salary2.style.visibility='hidden';
	thisPg.calculate.style.visibility='hidden';
	thisPg.txt1.style.visibility='hidden';
	thisPg.txt2.style.visibility='hidden';
	thisPg.reset.style.visibility='visible';
	thisPg.result.style.overflow='visible';
	thisPg.result.style.width='100%';
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '' + num + '.' + cents);
}