function linkStuff() {
if (!document.getElementById || !document.getElementsByTagName) return;
var theNode = document.getElementById("sectionLinks");
if (theNode) {
var anchors = theNode.getElementsByTagName("a");
for (var i=0; i<anchors .length; i++) {
var anchor = anchors[i];
anchor.innerHTML+= " &#8250;";
}
}
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors .length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
anchor.target = "_blank";
anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
}
}
}
window.onload = linkStuff;

//Mortgage calculators
var answer;
function calc_deposit() {
	var theForm = document.getElementById("calcdeposit");
	theForm.needAmount.value = (theForm.needprice.value / 100) * theForm.depositreq.value;
	if (isNaN(theForm.needAmount.value)){
		alert('Please insert only figures');
		theForm.needAmount.value="";
	};
}

function calc_deposit_size() {
	var theForm = document.getElementById("calcdepositsize");
	theForm.affordAmount.value = Math.round((theForm.affordcash.value / theForm.affordprice.value ) * 100);
	if (isNaN(theForm.affordAmount.value)){
		alert('Please insert only figures');
		theForm.affordAmount.value="";
	};
}

function calc_repay_compute() {
	var theForm = document.getElementById("mort_repay_calc");
	if (isNaN(theForm.rate.value) || isNaN(theForm.loanAmount.value) || isNaN(theForm.term.value) ) {
		alert('Please insert only numbers');
	} else {
		var int_per_year = (Number(theForm.rate.value)/100)+1;
		var comp_int = Math.pow( Number(int_per_year), Number(theForm.term.value) ) ;
		var total = Number(theForm.loanAmount.value) * Number(comp_int);
		var proportion_of_total = Number(theForm.rate.value) / 100 / (Number(comp_int) - 1);
		var gross_pa = Number(proportion_of_total) * Number(total);
		var gross_pm = gross_pa / 12;
		var int_only_pa = Number(theForm.loanAmount.value) * Number(theForm.rate.value) / 100;
		var int_only_pm = Number(theForm.loanAmount.value) * Number(theForm.rate.value) / 100 /12;
		document.getElementById('gross_pa').innerHTML = Math.round(gross_pa*100)/100;
		document.getElementById('gross_pm').innerHTML = Math.round(gross_pm*100)/100;
		document.getElementById('int_only_pa').innerHTML = Math.round(int_only_pa*100)/100;
		document.getElementById('int_only_pm').innerHTML = Math.round(int_only_pm*100)/100;
		
		document.getElementById('diff_pm').innerHTML =
		Math.round((document.getElementById('gross_pm').innerHTML  - document.getElementById('int_only_pm').innerHTML)*100)/100;
		
		document.getElementById('diff_pa').innerHTML =
		Math.round((document.getElementById('gross_pa').innerHTML - document.getElementById('int_only_pa').innerHTML)*100)/100;
	}
}

function calc_mort_loan() {
	var theForm = document.getElementById("mort_loan_calc");
	theForm.borrowAmount.value = (theForm.mainSal.value*theForm.mainMultiple.value) + (theForm.secSal.value*theForm.secMultiple.value);
	if(isNaN(theForm.borrowAmount.value)){
		theForm.borrowAmount.value="Error: please insert only numbers";
	}
	return false;
}

