<!--- Hied from tired old browsers
// Steves mortgage calculator starts here:-
function restore(){
	document.mortcalc.myresults.value=document.mortcalc.backUp.value;
}

function recalcnow(){
	var totalVal;
	var endVal;
	var chop;
	var ammount = new Array(5);
	totalVal=0;
	
	for (var i=0; i<ammount.length; i++){
		ammount[i]=eval("document.mortcalc.ammount"+(i+1)+".value");
	}
	for (var p=0; p<ammount.length; p++){
		if (ammount[p]=="" || ammount[p]==null){
			ammount[p]=0;
		} else {
			if (!isNaN(ammount[p])){
				ammount[p]=parseFloat(ammount[p]);
				
			}else{
				temp = FixText(ammount[p]);
				if (isNaN(temp)){
					temp="";
					eval("document.mortcalc.ammount"+(p+1)+".value = temp");
				}else{
					eval("document.mortcalc.ammount"+(p+1)+".value = temp");
					recalcnow();
				}
				alert("Please only use numbers");
				return false;
		}
	}
	}
	for (var y=0;y<ammount.length;y++){
		totalVal += ammount[y];
	}
	totalVal = totalVal*6;
	if (totalVal>0){
		if (totalVal>1000000){
			totalVal=1000000;
		}
		totalVal+= ""; 
		endVal = commify(totalVal);
		chop = endVal.indexOf('.');
		endVal = endVal.substr(0,chop);
	} else {
		endVal=0;
	}
	document.mortcalc.myresults.value="£"+endVal;
	document.mortcalc.backUp.value="£"+endVal;
}

//--------------------------------------------------------------------------------------------------------------------

function remortgageBackup(){
	document.loan.savingsTxt.value=document.loan.monthlybackup.value;
	document.loan.savingsYearly.value=document.loan.annualbackup.value;
	document.loan.newpayment.value=document.loan.newpaymentbackup.value;
	document.loan.oldpayment.value=document.loan.oldpaymentbackup.value;
	document.loan.newloan.value=document.loan.newloanbackup.value;
}

function FixText(StrVal) {
 RgExVal = new RegExp ("[^0-9]+")
 strFixedText = StrVal.replace(RgExVal, "")
 while (strFixedText.match(RgExVal) != null) {
  strFixedText = strFixedText.replace(RgExVal, "")
 } return parseFloat(strFixedText);
}

function remortgage(){
	var borrow = new Array(6);
	var payment = new Array(6);
	var oldMonthly=0, newMonthly=0, oldTotal=0, newTotal=0, newSavings=0, borrowPass=0;
	var paymentPass=0, annualSavings=0, newSavingsStr, annualSavingsStr, showSavings=0;
	var chop1, chop2, newMonthlyStr, oldTotalStr, oldMonthlyStr,temp
	var rate = document.loan.rate.value;
	// Get the entered figures from the form
	for (var i=0; i<borrow.length; i++){
		borrow[i]=eval("document.loan.borrow"+(i+1)+".value");
		payment[i]=eval("document.loan.payment"+(i+1)+".value");
	}
	// Check the contents of the arrays
	for (var p=0; p<borrow.length; p++){
		if (borrow[p]=="" || borrow[p]==null){
			borrow[p]=0;
		} else {
			if (!isNaN(borrow[p])){
				borrow[p]=parseFloat(borrow[p]);
				borrowPass=1;
			}else{
				temp = FixText(borrow[p]);
				if (isNaN(temp)){
					temp="";
					eval("document.loan.borrow"+(p+1)+".value = temp");
				}else{
					eval("document.loan.borrow"+(p+1)+".value = temp");
					remortgage();
				}
				alert("Please only use numbers");
				return false;
		}
		}
		
		if (payment[p]=="" || payment[p]==null){
			payment[p]=0;
		} else {
			if (!isNaN(payment[p])){
				payment[p]=parseFloat(payment[p]);
				paymentPass=1;
			}else{
				temp = FixText(payment[p]);
				if (isNaN(temp)){
					temp="";
					eval("document.loan.payment"+(p+1)+".value = temp");
				}else{
					eval("document.loan.payment"+(p+1)+".value = temp");
					remortgage();
				}
				alert("Please only use numbers");
				return false;
		}
		}
	}
	
	// Build there old monthly payment total
	for (var r=0; r<payment.length; r++){
		oldMonthly+=parseInt(payment[r]);
		oldMonthlyStr = oldMonthly+'';
		oldMonthlyStr = commify(oldMonthlyStr);
		chop1 = oldMonthlyStr.indexOf('.');
		oldMonthlyStr = oldMonthlyStr.substr(0,chop1);
		document.loan.oldpayment.value="£"+oldMonthlyStr;
		document.loan.oldpaymentbackup.value="£"+oldMonthlyStr;
	}

	// Build new loan ammount
	for (var w=0; w<borrow.length; w++){
		oldTotal+=parseInt(borrow[w]);
		oldTotalStr = oldTotal+"";
		oldTotalStr = commify(oldTotalStr);
		chop1 = oldTotalStr.indexOf('.');
		oldTotalStr = oldTotalStr.substr(0,chop1);
		document.loan.newloan.value="£"+oldTotalStr;
		document.loan.newloanbackup.value="£"+oldTotalStr;
	}
	
	//Calculate savings
	if(borrowPass==1 && paymentPass==1){
		newMonthly = parseInt(oldTotal*rate/12);
		newMonthlyStr = newMonthly+"";
		newMonthlyStr = commify(newMonthlyStr);
		chop1 = newMonthlyStr.indexOf('.');
		newMonthlyStr = newMonthlyStr.substr(0,chop1);
		document.loan.newpayment.value="£"+newMonthlyStr;
		document.loan.newpaymentbackup.value="£"+newMonthlyStr;
	}
	
	//Calculate monthly savings
	newSavings = parseInt(oldMonthly - newMonthly);
	
		newSavingsStr = newSavings+"";
		newSavingsStr = commify(newSavingsStr);
		chop2 = newSavingsStr.indexOf('.');
		newSavingsStr = newSavingsStr.substr(0,chop2);
		if (oldMonthly>0 && newSavings>0){
			document.loan.savingsTxt.value = "£"+newSavingsStr;
			document.loan.monthlybackup.value = "£"+newSavingsStr;
		} else {
			document.loan.savingsTxt.value = "£"+0;
		}
		
	//Calculate annual savings
		annualSavings	=	newSavings*12;
		annualSavingsStr = annualSavings+"";
		annualSavingsStr = commify(annualSavingsStr);
		chop2 = annualSavingsStr.indexOf('.');
		annualSavingsStr = annualSavingsStr.substr(0,chop2);
		if (oldMonthly>0 && annualSavings>0){
			document.loan.savingsYearly.value="£"+annualSavingsStr;
			document.loan.annualbackup.value="£"+annualSavingsStr;
		} else {
			document.loan.savingsYearly.value = "£"+0;
		}
	
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
function commify(sujon) {
var Num = sujon;
var newNum = "";
var newNum2 = "";
var count = 0;

//check for decimal number
if (Num.indexOf('.') != -1){ //number ends with a decimal point
if (Num.indexOf('.') == Num.length-1){
Num += "00";
}
if (Num.indexOf('.') == Num.length-2){ //number ends with a single digit
Num += "0";
}

var a = Num.split("."); 
Num = a[0]; //the part we will commify
var end = a[1] //the decimal place we will ignore and add back later
}
else {var end = "00";} 

//this loop actually adds the commas 
for (var k = Num.length-1; k >= 0; k--){
var oneChar = Num.charAt(k);
if (count == 3){
newNum += ",";
newNum += oneChar;
count = 1;
continue;
}
else {
newNum += oneChar;
count ++;
}
} //but now the string is reversed!

//re-reverse the string
for (var k = newNum.length-1; k >= 0; k--){
var oneChar = newNum.charAt(k);
newNum2 += oneChar;
}

// add dollar sign and decimal ending from above
newNum2 = newNum2 + "." + end;
return(newNum2);
}

function copyAddress(){
	if (document.mortgageform.sameAddress.checked==1){
		document.mortgageform.JointAppAdd1.value = document.mortgageform.App1AddressLine1.value;
		document.mortgageform.JointAppCity.value = document.mortgageform.App1City.value;
		document.mortgageform.JointAppCounty.value = document.mortgageform.App1County.value;
		document.mortgageform.JointAppPostcode.value = document.mortgageform.App1PostCode.value;
		document.mortgageform.JointAppCountry.value = document.mortgageform.App1Country.value;
	} else {
		document.mortgageform.JointAppAdd1.value = "";
		document.mortgageform.JointAppCity.value = "";
		document.mortgageform.JointAppCounty.value = "";
		document.mortgageform.JointAppPostcode.value = "";
		document.mortgageform.JointAppCountry.value = "";
	}
}

function instantAddress(){
	if (document.mortgageform.sameAddress.checked==1){
		document.mortgageform.JointAppAdd1.value = document.mortgageform.App1AddressLine1.value;
		document.mortgageform.JointAppCity.value = document.mortgageform.App1City.value;
		document.mortgageform.JointAppCounty.value = document.mortgageform.App1County.value;
		document.mortgageform.JointAppPostcode.value = document.mortgageform.App1PostCode.value;
		document.mortgageform.JointAppCountry.value = document.mortgageform.App1Country.value;
	}
}

function instantAddressApp1(){
	if (document.mortgageform.sameAddress.checked==1){
		document.mortgageform.App1AddressLine1.value = document.mortgageform.JointAppAdd1.value;
		document.mortgageform.App1City.value = document.mortgageform.JointAppCity.value;
		document.mortgageform.App1County.value = document.mortgageform.JointAppCounty.value;
		document.mortgageform.App1PostCode.value = document.mortgageform.JointAppPostcode.value;
		document.mortgageform.App1Country.value = document.mortgageform.JointAppCountry.value;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkCallBack(){
	if(document.form1.p1FullName.value==""){
		alert("Please enter your name");
		document.form1.p1FullName.focus();
		return false;
	}
	if(document.form1.p1Tel.value==""){
		alert("Please enter a contact number");
		document.form1.p1Tel.focus();
		return false;
	}
	return true;
}
//-->
