window.onload = jsFnOnload;

function jsFnOnload()
{	
	if (document.getElementById)
	{	
	  	var news = document.getElementById("news");
 		
		if (news != null) 
		{
	  		JSFnTickerTape();
	  	}
	  	
		/* 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 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 aProspectusForm = document.getElementById('prospectusrequestform');
		if (aProspectusForm != null) aProspectusForm.onsubmit = JSFnValidateProspectusForm;

		var aFamilyDayForm = document.getElementById('familydayform');
		if (aFamilyDayForm != null) aFamilyDayForm.onsubmit = JSFnValidateFamilyDayForm;		
		
		var aFamilyDayWeekendForm = document.getElementById('familydayweekendform');
		if (aFamilyDayWeekendForm != null) aFamilyDayWeekendForm.onsubmit = JSFnValidateFamilyDayWeekendForm;

		var aCurriculumDayForm = document.getElementById('curriculumdayform');
		if (aCurriculumDayForm != null) aCurriculumDayForm.onsubmit = JSFnValidateCurriculumDayForm;
						
		var aImageZoom = document.getElementById('largeimage');
		if (aImageZoom != null) aImageZoom.onclick = JSFnImageZoom;
	}
	
}

function JSFnMenuLiOver()
{
	this.className = 'level1 hover';
}

function JSFnMenuLiOut()
{
	this.className = 'level1';
}

function JSFnMenuLiClick()
{
	window.location = this.childNodes[0].href;
	//alert(this.childNodes[0]);
}

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 aProspectusRequiredFields = new Array ("name","Please enter your name to continue","address","Please enter your address to continue","postcode","Please enter your postcode to continue");

function JSFnValidateProspectusForm()
{
	// alert(document.getElementById('wheredidyouhearaboutus').value);
	if(document.getElementById('wheredidyouhearaboutus').value == "0")
	{	
		alert("Please let us know how you found us.");
		return false;
	}
	
	/*var aEmail = document.getElementById('email');
	var aTelephone = document.getElementById('telephone');
	var aMobile = document.getElementById('mobile');
	if ((aEmail != null) && (aTelephone != null) && (aMobile != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == '') && (aMobile.value == ''))
		{
			alert('You must provide either your telephone/mobile number or email address to continue.');
			return false;
		}
	}*/
	return JSFnValidateForm(aProspectusRequiredFields);
}

function JSFnValidateFamilyDayForm()
{
	for (aIndex = 1; aIndex < 9; aIndex = aIndex + 1)
	{	
		var aFirstBreakoutSession = document.getElementById('firstbreakout' + aIndex);
		var aSecondBreakoutSession = document.getElementById('secondbreakout' + aIndex);
		var aName = document.getElementById('name' + aIndex);
		
		if(aName.value == '')
		{
			alert('Error, you have not filled in all of the Names.');
			return false;		
		}
		
		if(aFirstBreakoutSession.value == '')
		{
			alert('Error, you have not filled in all of your First Breakout Session choices.');
			return false;
		}
		
		if(aSecondBreakoutSession.value == '')
		{
			alert('Error, you have not filled in all of your Second Breakout Session choices.');
			return false;
		}
	}
}

function JSFnValidateCurriculumDayForm()
{
	for (aIndex = 1; aIndex < 3; aIndex = aIndex + 1)
	{	
		var aCurriculumDay = document.getElementById('curriculumday' + aIndex);
		var aName = document.getElementById('name' + aIndex);
		
		if(aName.value == '')
		{
			alert('Error, you have not filled in all of the Names.');
			return false;		
		}
		
		if(aCurriculumDay.value == '')
		{
			alert('Error, you have not filled in your Curriculum Day Choice.');
			return false;
		}
	}	
}

var aFamilyWeekendFormRequiredFields = new Array ("WhereDidYouHearAboutUs","Please let us know how you found us.");

function JSFnValidateFamilyDayWeekendForm()
{
	return JSFnValidateForm(aFamilyWeekendFormRequiredFields);
}

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 JSFnTickerTape()
{
		TICKER_CONTENT = document.getElementById("news").innerHTML;
		TICKER_RIGHTTOLEFT = false;
		TICKER_SPEED = 2;
		TICKER_PAUSED = false;
		TICKER_STYLE = "color:#7E644B;";
		
		ticker_start();
}

function ticker_start()
{
	var tickerSupported = false;
	TICKER_WIDTH = '358px';

	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1)
	{
		document.getElementById("news").innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%' style=\"padding: 0 500px 0 "+TICKER_WIDTH+"\"><TR><TD nowrap='nowrap'><SPAN style='"+ TICKER_STYLE +"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN></TD></TR></TABLE>";
		tickerSupported = true;
	}
	// IE
	if (navigator.userAgent.indexOf("MSIE")!=-1 || window.opera)
	{
		document.getElementById("news").innerHTML = "<DIV nowrap='nowrap' style='width:100%; padding: 0 500px 0 "+TICKER_WIDTH+"'><SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN></DIV>";
		tickerSupported = true;
	}
	if(!tickerSupported)
	{
		document.getElementById("news").outerHTML = "";
	}
	else
	{
		document.getElementById("news").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("news").scrollWidth - document.getElementById("news").offsetWidth : 0;
		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
		document.getElementById("news").style.display="block";
		TICKER_tick();
	}
	
}
		
function TICKER_tick()
{
	if(!TICKER_PAUSED) document.getElementById("news").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
	if(TICKER_RIGHTTOLEFT && document.getElementById("news").scrollLeft <= 0) document.getElementById("news").scrollLeft = document.getElementById("news").scrollWidth - document.getElementById("news").offsetWidth;
	if(!TICKER_RIGHTTOLEFT && document.getElementById("news").scrollLeft >= document.getElementById("news").scrollWidth - document.getElementById("news").offsetWidth) document.getElementById("news").scrollLeft = 0;
	window.setTimeout("TICKER_tick()", 30);
}