var old = (window.onload) ? window.onload : function () {};
window.onload = function ()
{
	old();
	if (!document.getElementById) return;

	//add listener to "external" class a hrefs
	for(var i = 0; i < document.links.length; i++)
	{
		if(document.links[i].className == 'external')
		{
			document.links[i].onclick = newWindow;
		}				
	}
	try
	{
		document.getElementById('submitbutton').onclick = validateForm;
	}catch(e)
	{
	}
}

function newWindow()
{
	newWindow = window.open(this,"","")
	return false;
}

function bookingWindow()
{
	newWindow = window.open(this,"Booking form","resizable=yes,scrollbars=yes,width=280,height=400")
	return false;
}

function validateForm()
{
	var errormsg = "";
	var x = document.forms[0].elements;
	
	for (var i=0;i<x.length;i++)
	{
		if(x[i].className == 'required' && !x[i].value)
		{
			errormsg = errormsg + x[i].name + ",\n";
		}
	}
	
	var stremail = document.forms[0].emailaddress.value
	var emailchar = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!emailchar.test(stremail))
	{
		alert("Please enter a valid email address.");
		return false;
	}
	
	if(errormsg != "")
	{
		if(errormsg != "")
		{
			errormsg = errormsg + "are required fields.";
			alert(errormsg);
		}
		return false;	
	}
	else
	{
		return true;	
	}
}