window.onload = function() 
{
	if (document.getElementById)
	{
		var productimage = document.getElementById("ProductImage");
		if (productimage != null)
		{
				productimage.onclick = JSFnImageNewWindow;
		}

		var aProductLinks = document.getElementsByTagName("a");
		for (aProductIndex = 0; aProductIndex < aProductLinks.length; aProductIndex++)
		{
			if (aProductLinks[aProductIndex].className == 'picturelink') aProductLinks[aProductIndex].onclick = JSFnImageNewWindow;
		}

		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;

		//CollapseExpandProductRange();
	}
}

function JSFnImageNewWindow()
{
	window.open(this.href, 'image','width=620px,height=600px,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no');
	return false;
}

var aContactRequiredFields = new Array ("firstname","Please enter your first name to continue",
					 				    "surname","Please enter your surname to continue");
function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('email');
	var aAddress = document.getElementById('address');
	var aTelephone = document.getElementById('phone');
	var aFax = document.getElementById('fax');
	if ((aEmail != null) && (aAddress != null) && (aTelephone != null) && (aFax != null))
	{
		if ((aEmail.value == '') && (aAddress.value == '') && (aTelephone.value == '') && (aFax.value == ''))
		{
			alert('You must provide either your address, telephone/fax 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;
}

/*function CollapseExpandProductRange()
{
	aRightCol = document.getElementById('rightcolumn');
	if (aRightCol != null)
	{
		var aULs = aRightCol.getElementsByTagName("ul");
		for (aULIndex = 0; aULIndex < aULs.length; aULIndex++)
		{
			aULs[aULIndex].style.display = 'none';
		}

		var aH3s = aRightCol.getElementsByTagName("h3");
		for (aH3Index = 0; aH3Index < aH3s.length; aH3Index++)
		{
			aH3s[aH3Index].style.cursor = 'pointer';
			aH3s[aH3Index].onclick = DetermineProductRange;
		}
	}
}*/

function DetermineProductRange()
{
	aRightCol = document.getElementById('rightcolumn');
	if (aRightCol != null)
	{
		var aH3s = aRightCol.getElementsByTagName("h3");
		for (aH3Index = 0; aH3Index < aH3s.length; aH3Index++)
		{
			if (aH3s[aH3Index] == this) ShowProductRange(aH3Index);
		}
	}
}

function ShowProductRange(aIndex)
{
	aRightCol = document.getElementById('rightcolumn');
	if (aRightCol != null)
	{
		var aULs = aRightCol.getElementsByTagName("ul");
		for (aULIndex = 0; aULIndex < aULs.length; aULIndex++)
		{
			if (aULIndex == aIndex) aULs[aULIndex].style.display = 'block';
			else aULs[aULIndex].style.display = 'none';
		}
	}
}