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;
			}
		}

		// Remove confirm
		var remove = document.getElementsByTagName("a");
 		if (remove != null) 
		{
			for(aremindex=0;aremindex<remove.length;aremindex++)
			{
				if(remove[aremindex].className=='rem')
				{
					remove[aremindex].onclick = JSFnRemoveClick;
				}
			}
		}
				
		// var menu = document.getElementById("topmenu");
		//  		if (menu != null) 
		// {
		// 	var lis = menu.getElementsByTagName("li");
		// 	for(aliindex=0;aliindex<lis.length;aliindex++)
		// 	{
		// 		if(lis[aliindex].className=='level1')
		// 		{
		// 			lis[aliindex].onclick = JSFnMenuLiClick;
		// 			
		// 			lis[aliindex].onmouseover = JSFnMenuLiOver;
		// 			lis[aliindex].onmouseout = JSFnMenuLiOut;
		// 		}
		// 	}
		// }	
		
		var menu = document.getElementById("mainmenu");
 		if (menu != null) 
		{
			var aLis = menu.getElementsByTagName("li");
			for(aLiIndex = 0; aLiIndex < aLis.length; aLiIndex++)
			{
				var aSubMenus = aLis[aLiIndex].getElementsByTagName("ul");
				if (aSubMenus.length > 0)
				{
					aLis[aLiIndex].onmouseover = JSFnMenuLiOver;
					aLis[aLiIndex].onmouseout = JSFnMenuLiOut;
				}
				else
				{
					aLis[aLiIndex].onmouseover = JSFnMenuLiHover;
					aLis[aLiIndex].onmouseout = JSFnMenuLiHoverOut;
				}
			}
		}
	
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		var aImageZoom = document.getElementById('largeimage');
		if (aImageZoom != null) aImageZoom.onclick = JSFnImageZoom;
		
		SetupMemberList();
	}
	
}

function JSFnMenuLiOver()
{
	this.className += ' hover';
	var aSubMenus = this.getElementsByTagName("ul");
	if (aSubMenus.length > 0) 
	{	
		aSubMenus[0].parentNode.style.display = 'block';
		aSubMenus[0].style.display = 'block';
		
	}
}

function JSFnMenuLiOut()
{
	this.className = this.className.substring(0, this.className.length - 6);
	var aSubMenus = this.getElementsByTagName("ul");
	if (aSubMenus.length > 0)
	{
		aSubMenus[0].parentNode.style.display = 'none';
		aSubMenus[0].style.display = 'none';
	}
}

function JSFnMenuLiHover()
{
	this.className += ' hover';
}

function JSFnMenuLiHoverOut()
{
	this.className = this.className.substring(0, this.className.length - 6);
}


function JSFnGoBack()
{
	history.go(-1);
}

function JSFnImageZoom()
{
	var aWindow = window.open(this.href, 'productbig', 'menubar=no, resizeable=no, toolbar=no, width=600px, height=600px')
	aWindow.focus();
	return false;
}

var aContactRequiredFields = new Array ("name","Please enter your 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;
}

function DisplayArbitratorApplicationBoxes(selectObj)
{
	var selectedvalue = selectObj.options[document.applicationform.ApplicationType.selectedIndex].value;
	
	if((selectedvalue == '2') || (selectedvalue == '3'))
	{
		document.getElementById('arbitratorsection').style.display = '';
	} else document.getElementById('arbitratorsection').style.display = 'none';
}

function SetupMemberList()
{
	aRightPage = document.getElementById('memberspage');
	if (aRightPage != null)
	{
		var aFirstMember = null; 

		var aNewSelect = document.createElement('select');
		aNewSelect.onchange = JumpToMember;
		aNewSelect.style.width = '96%';

		aMembers = document.getElementsByTagName("h3");
		for (aIndex = 0; aIndex < aMembers.length; aIndex++)
		{
			if (aMembers[aIndex].className == "membernameheader")
			{
				if (aIndex == 0) aFirstMember = aMembers[aIndex];
				var aNewOption = document.createElement('option');
				aNewOption.innerHTML = aMembers[aIndex].innerHTML;
				aNewOption.value = aIndex;
				aNewSelect.appendChild(aNewOption);
				aMembers[aIndex].id = 'member' + aIndex;
			}
		}

		var aNewP = document.createElement('p');
		aNewP.innerHTML = "To jump straight to a particular member's details simply select their name from the list below.";
		//var aNewHR = document.createElement('hr');

		aContent = document.getElementById('content');
		aContent.insertBefore(aNewP, aFirstMember);
		aContent.insertBefore(aNewSelect, aFirstMember);
		//aContent.insertBefore(aNewHR, aFirstMember);
	}
}

function JumpToMember()
{
	window.location = 'members.php#member' + this.value;
}