window.onload = function() 
{
	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;
				}
		}
		
		var submenu = document.getElementById("wearli");
		if (submenu != null)
		{
				submenu.onmouseover = function() 
				{
					var submenulist = document.getElementById("wearsubmenu");
					if (submenulist != null) submenulist.className = 'showmenu';
				}

				submenu.onmouseout = function() 
				{
					var submenulist = document.getElementById("wearsubmenu");
					if (submenulist != null) submenulist.className = '';
				}
		}
		
		var submenu2 = document.getElementById("bristolli");
		if (submenu2 != null)
		{
				submenu2.onmouseover = function() 
				{
					var submenulist2 = document.getElementById("bristolsubmenu");
					if (submenulist2 != null) submenulist2.className = 'showmenu';
				}

				submenu2.onmouseout = function() 
				{
					var submenulist2 = document.getElementById("bristolsubmenu");
					if (submenulist2 != null) submenulist2.className = '';
				}
		}
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;

		var aGallerySpan = document.getElementById('galleryspan');
		if (aGallerySpan != null)
		{
			aGallerySpan.innerHTML = '<div id="displayimage"><img src="" alt="" id="galleryimage"></img><span id="gallerycaption"></span></div><div id="gallerybuttons"><img src="images/left.gif" alt="Previous Image" onclick="JSFnPrevious()" id="previous"></img>&nbsp; &nbsp;<img src="images/right.gif" alt="Next Image" onclick="JSFnNext()" id="next"></img></div>';		
/*			aGallerySpan.innerHTML = '<div id="displayimage"><img src="images/left.gif" alt="Previous Image" onclick="JSFnPrevious()" id="previous"></img><img src="images/right.gif" alt="Next Image" onclick="JSFnNext()" id="next"></img><img src="" alt="" id="galleryimage"></img></div>';		
	*/	}
				
		var aGallery = document.getElementById('gallery');
		if (aGallery != null)
		{
			aAs = aGallery.getElementsByTagName("a");
			for (aIndex = 0; aIndex < aAs.length; aIndex++)
			{
				aAs[aIndex].onclick = JSFnDisplayGalleryImage; 
				if (aIndex == 0) 
				{
					jsFnChangeImage('galleryimage',aAs[aIndex].href);
					jsFnChangeCaption('gallerycaption',aCaptionArray[aImagePosition]);
				}
			}				
		}
	}	
}


var aContactRequiredFields = new Array ("name","Please enter your name to continue");
function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('email');
	var aAddress = document.getElementById('address');
	var aTelephone = document.getElementById('telephone');
	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 jsFnChangeImage(aImageToChange, aImageToShow)
{
	if  (document.getElementById)
	{
		var aImage = document.getElementById(aImageToChange);
		aImage.src = aImageToShow;
	}
}

function jsFnChangeCaption(aImageToChange, aNewCaption)
{
	if  (document.getElementById)
	{
		var aCaption = document.getElementById(aImageToChange);
		aCaption.innerHTML = '<p>' + aNewCaption + '</p>';
	}
}

aImagePosition = 0;

function JSFnDisplayGalleryImage()
{	
	jsFnChangeImage('galleryimage',this.href);
	var aGallery = document.getElementById('gallery');
	if (aGallery != null)
	{
		aAs = aGallery.getElementsByTagName("a");
		for (aIndex = 0; aIndex < aAs.length; aIndex++)
		{
			if (aAs[aIndex].href == this.href) aImagePosition = aIndex;
		}
		jsFnChangeCaption('gallerycaption',aCaptionArray[aImagePosition]);
	}
	return false;
}

function JSFnPrevious()
{
	var aGallery = document.getElementById('gallery');
	if (aGallery != null)
	{
		aImagePosition--;
		aAs = aGallery.getElementsByTagName("a");
		if (aImagePosition == -1)
		{
			aImagePosition = aAs.length-1;
		}
		jsFnChangeImage('galleryimage',aAs[aImagePosition].href);
		jsFnChangeCaption('gallerycaption',aCaptionArray[aImagePosition]);				
	}
}

function JSFnNext()
{
	var aGallery = document.getElementById('gallery');
	if (aGallery != null)
	{
		aImagePosition++;
		aAs = aGallery.getElementsByTagName("a");
		if (aImagePosition == aAs.length)
		{
			aImagePosition = 0;
		}
		jsFnChangeImage('galleryimage',aAs[aImagePosition].href);
		jsFnChangeCaption('gallerycaption',aCaptionArray[aImagePosition]);				
	}
}
