	function fnCalc(){
		if (fnCheckData()){
		
			var ir=document.frmProp.txtir.value;
			ir = ir / 100;
			
			var mortval=document.frmProp.txtmort.value;
			var repay=document.frmProp.txtrepay.value;
			
			var calcresult = ((mortval*ir)/12) * (1/(1-(Math.pow(1/(1+ir),repay))));
			document.frmProp.txtansmonthly.value = roundval(calcresult,2);
			calcresult = ((mortval*0.1)/12) * (1 / (1-(Math.pow((1/1.1),repay))));
			calcresult = (mortval*ir)/12;
			document.frmProp.txtanswerir.value = roundval(calcresult,2);
			calcresult = (mortval*0.1)/12;
			
			
		}
	}
	
	function fnClearForm(){
		document.frmProp.txtansmonthly.value = "";
		document.frmProp.txtanswerir.value = "";
		document.frmProp.txtir.value = "";
		document.frmProp.txtmort.value = "";
		document.frmProp.txtrepay.value = "";
	}
	
	//Check Data is Valid before Proceeding 
	function fnCheckData() {
		if (document.frmProp.txtmort.value==''){
			document.frmProp.txtmort.focus();
			alert("You must enter a required mortgage");
			return false;
		}
		if (document.frmProp.txtmort.value>5000000){
			document.frmProp.txtmort.focus();
			alert("The largest mortgage possible is £5 million");
			return false;
		}
		if (document.frmProp.txtmort.value<1000){
			document.frmProp.txtmort.focus();
			alert("The smallest mortgage possible is £1000");
			return false;
		}
		if (document.frmProp.txtrepay.value==''){
			document.frmProp.txtrepay.focus();
			alert("You must enter a repayment period");
			return false;
		}
		if (document.frmProp.txtrepay.value>30){
			document.frmProp.txtrepay.focus();
			alert("The longest repayment period is 30 years");
			return false;
		}
		if (document.frmProp.txtrepay.value<5){
			document.frmProp.txtrepay.focus();
			alert("The smallest repayment period is 5 years");
			return false;
		}
		if (document.frmProp.txtir.value==''){
			document.frmProp.txtir.focus();
			alert("You must enter an interest rate");
			return false;
		}
		if (document.frmProp.txtir.value>20){
			document.frmProp.txtir.focus();
			alert("The highest interest rate is 20%");
			return false;
		}
		if (document.frmProp.txtir.value<1){
			document.frmProp.txtir.focus();
			alert("The lowest interest rate is 1%");
			return false;
		}
		
		return true;
	}

	
	
	function roundval(number,X) {
		X = (!X ? 2 : X);
		return Math.floor(number*Math.pow(10,X))/Math.pow(10,X);
	}