function MortgageFormCalc() {
	if (document.MortgageForm.InterestRate.value == "" || document.MortgageForm.LoanAmount.value == "" || document.MortgageForm.Term.value == "" ) {
		// if user has not completed all fields
		alert('Please complete all fields');
		document.MortgageForm.Capital_pa.value = "";
		document.MortgageForm.Capital_pm.value = "";
		document.MortgageForm.IntOnly_pa.value = "";
		document.MortgageForm.IntOnly_pm.value = "";
		
	} else if (isNaN(document.MortgageForm.InterestRate.value) || isNaN(document.MortgageForm.LoanAmount.value) || isNaN(document.MortgageForm.Term.value) ) {
		// if user has entered text into a field
		alert('Please enter a valid amount');
		document.MortgageForm.Capital_pa.value = "";
		document.MortgageForm.Capital_pm.value = "";
		document.MortgageForm.IntOnly_pa.value = "";
		document.MortgageForm.IntOnly_pm.value = "";
	}else{
		var IntPerAnnum = (Number(document.MortgageForm.InterestRate.value)/100)+1;
		var CompundInterest = Math.pow( Number(IntPerAnnum), Number(document.MortgageForm.Term.value) );
		var Total = Number(document.MortgageForm.LoanAmount.value) * Number(CompundInterest);
		var PropOfTotal = Number(document.MortgageForm.InterestRate.value) / 100 / (Number(CompundInterest) - 1);
		var Capital_pa = Number(PropOfTotal) * Number(Total);
		var Capital_pm = Capital_pa / 12;
		var IntOnly_pa = Number(document.MortgageForm.LoanAmount.value) * Number(document.MortgageForm.InterestRate.value) / 100;
		var IntOnly_pm = Number(document.MortgageForm.LoanAmount.value) * Number(document.MortgageForm.InterestRate.value) / 100 /12;

		// calculate capital and interest only mortgages
		document.MortgageForm.Capital_pa.value = Math.round(Capital_pa*100)/100;
		document.MortgageForm.Capital_pm.value = Math.round(Capital_pm*100)/100;
		document.MortgageForm.IntOnly_pa.value = Math.round(IntOnly_pa*100)/100;
		document.MortgageForm.IntOnly_pm.value = Math.round(IntOnly_pm*100)/100;

		// calculate differences between capital and interest only mortgages
		document.MortgageForm.Difference_pm.value = Math.round((document.MortgageForm.Capital_pm.value - document.MortgageForm.IntOnly_pm.value)*100)/100;
		document.MortgageForm.Difference_pa.value = Math.round((document.MortgageForm.Capital_pa.value - document.MortgageForm.IntOnly_pa.value)*100)/100;
	}

}