// repayment types
// 0 - interest only
// 1 - normal repayment

function calculateRepayments(){
		loan = parseInt(document.calcform.loan.value);
		rate = document.calcform.rate.value;
		mtype = document.calcform.mortgagetype.selectedIndex; 
		
		if (!parseInt(loan) > 0){
			alert("Please enter a value for the loan. Must be whole pounds.");
			return false;
		}

		if (!parseInt(rate) > 0 | isNaN(rate)){
			alert("Please enter an interest rate.");
			return false;
		}

		term = parseInt(document.calcform.period.value);
		rate100 = (rate / 100)
		// (loan amount * decimal rate) / 12
		monthlyrepayments = ((loan * rate100) / 12);
		
		if (mtype == 0) { 
			monthlyrepayments = (Math.round(monthlyrepayments * 100)) / 100;
			document.calcform.answer.value = monthlyrepayments;
			return false; 
		} else if (mtype == 1) { // Full Repayment 
			var topline = (loan * rate * 12);
			var midline = Math.pow((1+(rate/1200)), (-term * 12));
			midline = (100 * 12 * (1 - midline));
			var answer = ((topline / midline) / 12);
			answer = (Math.round(answer * 100)) / 100;
			document.calcform.answer.value = answer; 
		}		
	return false;			
}

function calculateRange(){
		income1 = parseInt(document.rangeform.income1.value);
		income2 = parseInt(document.rangeform.income2.value);
		
		
		if(isNaN(income1)){
			income1 = 0;
		}
		
		if(isNaN(income2)){
			income2 = 0;
		}
		
		totalincome = (income1 + income2 );
		low = totalincome * 4;
		
		high = totalincome * 3.5;
		
		document.rangeform.low.value = low;
		document.rangeform.high.value = high;
		
		return false;
	}
