// JavaScript Document
function isblank(field_value)
		{
			var len=field_value.length;
			var i;
			for (i=0;i<len;++i)
				{
					if( field_value.charAt(i) != " " )
					return false ;

				}
			return true;
		}
function Addfields_borrow(formname)
		{
			var IncomeErrorMsg = document.getElementById("LbIncomeError");
			IncomeErrorMsg.innerHTML = "";
			var multErrorMsg = document.getElementById("LbmultError");
			multErrorMsg.innerHTML = "";
			var PartnerIncomeErrorMsg = document.getElementById("LbPartnerIncomeError");
			PartnerIncomeErrorMsg.innerHTML = "";
			var YourSavingsErrorMsg = document.getElementById("LbYourSavingsError");
			YourSavingsErrorMsg.innerHTML = ""; 
			var HomeSaleErrorMsg = document.getElementById("LbHomeSaleError");
			HomeSaleErrorMsg.innerHTML = "";
			var valid =  document.getElementById("isValid");
			valid.value = "true";
			
			
			var IncomeFld = document.getElementById("income");

			if ( isblank(document[formname].income.value))
			{
				document[formname].income.value = '0.00';
				document[formname].partnerincome.focus();
			}

			if ( isblank(document.BorrowingCalculator.partnerincome.value))
			{
				document[formname].partnerincome.value = '0.00';
				document[formname].mult.focus();
			}
			if ( isblank(document.BorrowingCalculator.yoursavings.value))
			{
				document[formname].yoursavings.value = '0.00';
				document[formname].homesale.focus();
			}
			if ( isblank(document.BorrowingCalculator.homesale.value))
			{
				document[formname].homesale.value = '0.00';
				document[formname].income.focus();
			}


			if ( isblank(document.BorrowingCalculator.mult.value))
			{
				document[formname].mult.value = '3.00';
				document[formname].yoursavings.focus();
			}
			if (isNaN(document[formname].mult.value) | document[formname].mult.value < 0 )
		 	{
				multErrorMsg.innerHTML = "Multiplier is not valid";
				valid.value = "false";	
				setTimeout(function(){document[formname].mult.focus()}, 10);
				
				return;
 			}



			if (isNaN(IncomeFld.value) | IncomeFld.value < 0 )
			{
				IncomeErrorMsg.innerHTML = "Income is not valid";
				var valid =  document.getElementById("isValid");
				valid.value = "false";	
				
				//Note focus only works with a timeout on firefox.
				setTimeout(function(){IncomeFld.focus()}, 10);
				
				return;
			}
			if (isNaN(document[formname].partnerincome.value) | document[formname].partnerincome.value < 0 )
			{
				PartnerIncomeErrorMsg.innerHTML = "Partner Income is not valid";
				var valid =  document.getElementById("isValid");
				valid.value = "false";	
				//Note focus only works with a timeout on firefox.
				setTimeout(function(){document[formname].partnerincome.focus()}, 10);
				
				return;
			}

			if ( document[formname].mult.value > 5 )
			{
				multErrorMsg.innerHTML = "Multiple should be less than 5";
				//Note focus only works with a timeout on firefox.
				setTimeout(function(){document[formname].mult.focus()}, 10);
				return;
			}
 			if (isNaN(document[formname].yoursavings.value) | document[formname].yoursavings.value < 0 )
 			{
				YourSavingsErrorMsg.innerHTML ="Savings is not valid";
				var valid =  document.getElementById("isValid");
				valid.value = "false";	
				setTimeout(function(){document[formname].yoursavings.focus()}, 10);
				return;
 			}

 			if (isNaN(document[formname].homesale.value) | document[formname].homesale.value < 0 | document[formname].homesale.value == "")
			{
				HomeSaleErrorMsg.innerHTML = "Home sale amount is not valid";
				var valid =  document.getElementById("isValid");
				valid.value = "false";	
				setTimeout(function(){document[formname].homesale.focus()}, 10);
				return;
 			}

 			document[formname].lender.value=parseFloat(document[formname].income.value)+
							   				parseFloat(document[formname].partnerincome.value);
			// borrow is run at server so we have to use prefix
			var borrowFld = document.getElementById("Borrowing_borrow"); 				   				
			borrowFld.value=parseFloat(document[formname].lender.value) *
							   				parseFloat(document[formname].mult.value);
			document[formname].total.value=parseFloat(borrowFld.value)+
							  			   parseFloat(document[formname].yoursavings.value)+
							   			   parseFloat(document[formname].homesale.value);

}
//-->

