var BOTTOM_PADDING = 40;


// Returns the height of the web page space
function windowHeight() {
		var winH;
	
		if (window.innerHeight) {
			winH=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			winH=document.documentElement.clientHeight;
		}
		else if (document.body) {
			winH=document.body.clientHeight;
		}

		return winH;
	}

// Function thanks to msdn.microsoft.com 
function getInternetExplorerVersion ()
	{
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).
	  var rv = -1; // Return value assumes failure.
	  if (navigator.appName == 'Microsoft Internet Explorer')
	  {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		  rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
}
	

// Sets the size of the three content columns
function setLayout () {
	var o1, o2, o3, t, footerHeight;
	
	o1 = document.getElementById("mainBody_left");
	o2 = document.getElementById("mainBody_center");
	o3 = document.getElementById("mainBody_right");
	t = document.getElementById("mainBody_title");
	h = document.getElementById("header");
	me = document.getElementById("menu");
	ma = document.getElementById("main");
	f = document.getElementById("footer");
	
	ieV = getInternetExplorerVersion();
	if(ieV <= 6 && ieV > 0) {
		o1.style.width="300px";
		o2.style.width="378px";
		o3.style.width="300px";
	
	}

	height = Math.max(o1.offsetHeight, o2.offsetHeight, o3.offsetHeight) + BOTTOM_PADDING;
	o1.style.height = height + 'px';
	o2.style.height = height + 'px';
	o3.style.height = height + 'px';
	
	
	ma.style.height = height + (t ? t.offsetHeight : 0) + 'px';
	footerHeight = windowHeight() - (h.offsetHeight + me.offsetHeight + ma.offsetHeight) ;
	f.style.height = (footerHeight < 80 ? 80 : footerHeight) + 'px';
	
}

function setHandlers () {
	document.getElementById("contact_submit").addEventListener('submit', validateFields, false);
}

function validateFields(e) {
	alertMessage="";
		contactForm = document.getElementById("contact_form");
		emailRegExp = new RegExp("^.+\@.+\..{2,3}[$|(\..{2}$)]");
		phoneRegExp = new RegExp("^.?[0-9][0-9 ]+[0-9]$");
	
	if(contactForm.name.value.length == 0) alertMessage+="- Please enter your name\n"; 
	if(contactForm.email.value.length + contactForm.phone.value.length == 0) alertMessage+="- Please enter either an email address or phone number\n";
	else {
		if(contactForm.phone.value.length > 0) alertMessage+=(phoneRegExp.test(contactForm.phone.value) ? "" : "- Please enter a correct phone number (eg +61 430 000 000, 9000 0000 or 97000000)\n");
		if(contactForm.email.value.length > 0) alertMessage+=(emailRegExp.test(contactForm.email.value) ? "" : "- Please enter a correct email address (eg john@hotmail.com or paul@bigpond.com.au)\n");
		}
	if(contactForm.enquiry.value.length == 0) alertMessage+="- Please enter an enquiry\n"; 
	if(alertMessage.length > 0) alert(alertMessage);
	
	return(alertMessage.length == 0);
	}
