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 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></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>';		
		}
				
		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);
			}				
		}
				
		var aQA = document.getElementById('questions');
		if (aQA != null)
		{
			aPs = aQA.getElementsByTagName("p");
			for (aIndex = 0; aIndex < aPs.length; aIndex++)
			{
				if (aPs[aIndex].className == 'question')
				{
					aPs[aIndex].onclick = JSFnDisplayAnswer; 
					aPs[aIndex].style.cursor = 'pointer'; 
				}
			}				
		}

		var aContent = document.getElementById('content');
		if (aContent != null)
		{
			aLinks = aContent.getElementsByTagName("a");
			for (aIndex = 0; aIndex < aLinks.length; aIndex++)
			{
//				if (aLinks[aIndex].href.indexOf('http://www.') != -1)
				if (aLinks[aIndex].href.indexOf('http://www.bluelinemedia') != -1)
				{
					aLinks[aIndex].target = '_blank'; 
				}
			}				
		}
	}
}


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 JSFnDisplayGalleryImage()
{	
	jsFnChangeImage('galleryimage',this.href);
	return false;
}

$aImagePosition = 0;

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);				
	}
}

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);				
	}
}

function JSFnDisplayAnswer()
{
	var aQA = document.getElementById('questions');
	if (aQA != null)
	{
		aPs = aQA.getElementsByTagName("p");
		for (aIndex = 0; aIndex < aPs.length; aIndex++)
		{
			if (aPs[aIndex] == this)
			{
				if(aPs[aIndex+1].style.display == 'block')
				{
					aPs[aIndex+1].style.display = 'none';
				}
				else
				{
					aPs[aIndex+1].style.display = 'block';
				}				
			}			
		}				
	}
}
