window.onload = function() 
{
	if (document.getElementById)
	{
		var aLogo = document.getElementById('logo');
		if (aLogo != null) 
		{
			aLogo.style.cursor = 'pointer';
			aLogo.onclick = GoHome;
		}

		var aLogo = document.getElementById('learnlogo');
		if (aLogo != null) 
		{
			aLogo.style.cursor = 'pointer';
			aLogo.onclick = LearnGoHome;
		}

		var aForm = document.getElementById('userdetailsform');
		if (aForm != null) aForm.onsubmit = UserDetailsCheck;
		
		var aForm = document.getElementById('diagnosticform');
		if (aForm != null) aForm.onsubmit = DiagnosticsCheck;

		var aLinks = document.getElementsByTagName("a");
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if (aLinks[aIndex].href.indexOf('images/5starmodel.jpg') != -1)
			{
				aLinks[aIndex].onclick = JSFnShow5StarModel;
			}
			else if (aLinks[aIndex].href.indexOf('casestudy1.php') != -1)
			{
				aLinks[aIndex].onclick = JSFnShowCaseStudy;
			}
			else if (aLinks[aIndex].href.indexOf('casestudy2.php') != -1)
			{
				aLinks[aIndex].onclick = JSFnShowCaseStudy;
			}
			else if (aLinks[aIndex].className == 'docdelete')
			{
				aLinks[aIndex].onclick = JSFnConfirmDeleteDoc;
			}
		}
		
		var aInputs = document.getElementsByTagName("input");
		for (aIndex = 0; aIndex < aInputs.length; aIndex++)
		{
			if (aInputs[aIndex].className == 'delforum') aInputs[aIndex].onclick = JSFnConfirmDeleteForum;
			else if (aInputs[aIndex].className == 'delreply') aInputs[aIndex].onclick = JSFnConfirmDeleteReply;			
			else if (aInputs[aIndex].id == 'removebutton') aInputs[aIndex].onclick = JSFnConfirmDelete;
			else if (aInputs[aIndex].id == 'removebutton2') aInputs[aIndex].onclick = JSFnConfirmDelete;
			else if (aInputs[aIndex].id == 'removebutton3') aInputs[aIndex].onclick = JSFnConfirmDelete;			
		}
	}	
}

function GoHome()
{
	window.location = 'index.php';
}

function LearnGoHome()
{
	window.location = '../index.php';
}

function UserDetailsCheck()
{
	var aEmail= document.getElementById('email');
	var aPassword = document.getElementById('password');
	var aCPassword = document.getElementById('cpassword');
	if (aEmail.value == '') 
	{
		alert('Error - you must provide a valid email address.');
		return false;
	}
	else if (aPassword.value != aCPassword.value) 
	{
		alert('Error - the password and confirm password entries are not the same.');
		return false;
	}
}

function DiagnosticsCheck()
{
	var aForm = document.getElementById('diagnosticform');
	var aRadios = aForm.getElementsByTagName("input");
	var aLastName = '';
	var aLastNameSelected = true;
	var aResult = true;
	for (aIndex = 0; aIndex < aRadios.length; aIndex++)
	{
		if (aRadios[aIndex].type == 'radio')
		{
			if (aLastName != aRadios[aIndex].name)
			{
				if (aLastNameSelected == false)
				{
					aResult = false;
				}
				aLastName = aRadios[aIndex].name;
				aLastNameSelected = false;
			}
			if (aRadios[aIndex].checked) aLastNameSelected = true;
		}
	}
	if (aLastNameSelected == false)
	{
		aResult = false;
	}
	
	if (aResult == false) alert("You must select a response for each of the questions - please try again");
	
	return aResult;
}

function JSFnShow5StarModel()
{
	aWindow = window.open(this.href, '5starwindow', 'width=850,height=800');
	aWindow.focus();
	return false;
}

function JSFnShowCaseStudy()
{
	aWindow = window.open(this.href, 'casestudy', 'width=550,height=400,scrollbars,top=200,left=200');
	aWindow.focus();
	return false;
}

function JSFnConfirmDeleteDoc()
{
	return confirm('Are you sure you wish to delete this document?');
}

function JSFnConfirmDeleteForum()
{
	return confirm('Are you sure you wish to delete this forum?');
}

function JSFnConfirmDeleteReply()
{
	return confirm('Are you sure you wish to delete this reply?');
}

function JSFnConfirmDelete()
{
	return confirm('Are you sure you wish to delete this item?');
}