// JavaScript Document

function popUp(theURL, name, w, h) {
	var windowName = name;
	var features = "status=yes,scrollbars=yes,resizable=yes,width="+w+",height="+h+"";
	var newWindow = window.open("", windowName, features);
	newWindow.focus();
	newWindow.location = theURL;
}

function buildEmail(user , form) {
	//var user ="property"
	var at = "@";
	var domain = "realbayside.com.au";
	
	recipientAddress = user + at + domain;
	//alert(recipientAddress);
	
	if (form == "n") {
		document.write('<a href=mailto:' + recipientAddress + '>' + recipientAddress + '</a>');
	} 
	
	if (form == "y") {
		document.baysideForm.recipient.value = recipientAddress;
	}
		
}

function computeForm(form) { 

	var payment=0;
	var payment12=0;
	ir=1+(form.ir.value/100);
	ir=Math.pow(ir,(1/12));
	term=form.term.value*12;
	mortgage=form.mortgage.value;
	var x=0;
	
	x=Math.pow(ir,term);
	ir12=Math.pow(1.12,(1/12));
	x12=Math.pow(ir12,term);
	
	if(x==1){payment=mortgage/term
	}else
	{ 
	payment=((mortgage*x)*(1-ir))/(1-x)
	}
	payment12=((mortgage*x12)*(1-ir12))/(1-x12);
	
	form.payment.value=Math.round(payment*100)/100;
}


function validate(form) { 
	if (form.mortgage.value == "") {
		alert("You will need to enter an amount you wish to borrow");
		form.mortgage.focus();
		return false;
	}
	if (form.term.value == "") {
		alert("You need to enter the term of the loan in years");
		form.term.focus();
		return false;
	}
	if (form.ir.value == "") {
		alert("You need to enter the Interest rate you will be paying the loan at");
		form.ir.focus();
		return false;
	}
}
