window.onload = jsFnOnload;

function jsFnOnload()
{
	if (document.getElementById)
	{		  
		/* Associate logo's onclick event with home page */
		var logo = document.getElementById("logo");
 		if (logo != null) {
			logo.onclick = function() {
				window.location = 'index.php';
				return false;
			}
		}
		
		aLinks = document.getElementsByTagName("a");		
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if (aLinks[aIndex].href.indexOf('leoni') == -1)
			{
				aLinks[aIndex].target = '_blank';
			}
			else if (aLinks[aIndex].href.indexOf('large_map.gif') != -1)
			{
				aLinks[aIndex].onclick = JSFnMapPopUp;
			}
		} 
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
	}
}

function JSFnMapPopUp()
{
	aWindow = window.open(this.href, 'testing', 'height=520,width=520, resizable');
	aWindow.focus();
	return false;
}

var aContactRequiredFields = new Array ("firstname","Please enter your first name to continue",
										"lastname","Please enter your last name to continue");
function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('email');
	var aTelephone = document.getElementById('telephone');
	if ((aEmail != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your telephone number or email address to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aContactRequiredFields);
}

function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if  (   (   (currElement.type == 'text')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'password')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'checkbox')
				     && (currElement.checked == false))
				 || (   (currElement.type == 'file')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'textarea')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'select-one')
				     && (currElement.value == '')))
			{
				alert(aRequiredFields[aIndex + 1]);
				return false;
			}
			else if (currElement.type == 'radio')
			{
				aIndex = aIndex + 2;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}