window.onload = jsFnOnload;

function jsFnOnload()
{
	if (document.getElementById)
	{	
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		var aEmailFriendForm = document.getElementById('emailfriendform');
		if (aEmailFriendForm != null) aEmailFriendForm.onsubmit = JSFnValidateEmailFriendForm;
		
		var aUserLoginForm = document.getElementById('UserLoginForm');
		if (aUserLoginForm != null) aUserLoginForm.onsubmit = JSFnValidateUserLoginForm;
		
		var aCallMeBackForm = document.getElementById('CallMeBack');
		if (aCallMeBackForm != null) aCallMeBackForm.onsubmit = JSFnValidateCallMeBackForm;
		
		var aVacancyForm = document.getElementById('vacancyform');
		if (aVacancyForm != null) aVacancyForm.onsubmit = JSFnValidateVacancyForm;
		
		var aSubmitCVForm = document.getElementById('SubmitCV');
		if (aSubmitCVForm != null) aSubmitCVForm.onsubmit = JSFnValidateSubmitCVForm;
		
		var aUserForm = document.getElementById('UserRegistrationForm');
		if (aUserForm != null) aUserForm.onsubmit = JSFnValidateUserForm;
		
		var aImageZoom = document.getElementById('vacancylink');
		if (aImageZoom != null) aImageZoom.onclick = JSFnImageZoom;
		
	 	if(document.getElementById("tickertape")) JSFnTickerTape();	
	 	if(document.getElementById("homepagedivisions")) JSFnActivateHomeLinks();	
	}
	
}
/************************************************************************************************************************************/
/* User Required Fields */
var aUserRequiredFields = new Array ("Candidate_Forename","Please enter your first name to continue",
									 "Candidate_Surname","Please enter a surname to continue",
									 "Candidate_Email","Please enter an email address to continue",
									 "Candidate_Password","Please enter a password to continue",
									 "PasswordRepeat","Please repeat password to continue");

/* User Form Validation */
function JSFnValidateUserForm()
{
	if (this.Candidate_Password.value.length < 6)
	{
		alert("Please enter at least 6 characters in the \"Password\" field.");
		this.Candidate_Password.focus();
		return (false);
	}
	
	// check if both password fields are the same
	if (this.Candidate_Password.value != this.PasswordRepeat.value)
	{
		alert("The two passwords are not the same.");
		this.PasswordRepeat.focus();
		return (false);
	}
	
	return JSFnValidateForm(aUserRequiredFields);
}
/************************************************************************************************************************************/
/* User Login Required Fields */
var aUserLoginRequiredFields = new Array ("username","Please enter your email address to continue",
									   	  "pss","Please enter your password to continue");
/* User Login Form Validation */
function JSFnValidateUserLoginForm()
{
	return JSFnValidateForm(aUserLoginRequiredFields);
}
/************************************************************************************************************************************/

/* Email Friend Required Fields */
var aEmailFriendRequiredFields = new Array ("FriendsName","Please enter your friends name to continue",
									   	  "FriendsEmailAddress","Please enter your friends email address to continue");
/* Email Friend Form Validation */
function JSFnValidateEmailFriendForm()
{
	return JSFnValidateForm(aEmailFriendRequiredFields);
}
/************************************************************************************************************************************/
/* Call Me Back Required Fields */
var aCallMeBackRequiredFields = new Array ("FirstName","Please enter your first name to continue",
									   	  "Surname","Please enter your surname to continue",
									   	  "TelephoneNumber","Please enter your telephone no. to continue");
/* Call Me Back Form Validation */
function JSFnValidateCallMeBackForm()
{
	return JSFnValidateForm(aCallMeBackRequiredFields);
}
/************************************************************************************************************************************/
/* Submit CV Required Fields */
var aSubmitCVRequiredFields = new Array ("FirstName","Please enter your first name to continue",
									   "Surname","Please enter your surname to continue",
									   "TelephoneNo","Please enter your telephone number to continue",
									   "EmailAddress","Please enter your email address to continue",
									   "AttachedDocument","Please attach your CV to continue");
/* Submit CV Form Validation */
function JSFnValidateSubmitCVForm()
{
	return JSFnValidateForm(aSubmitCVRequiredFields);
}
/************************************************************************************************************************************/
/* Place vacancy Required Fields */
var aVacancyRequiredFields = new Array ("FullName","Please enter your name to continue",
									   "Position","Please enter a position to continue",
									   "Company","Please enter a company to continue",
									   "Address","Please enter an address to continue",
									   "TelephoneNo","Please enter a telephone no. to continue",
									   "EmailAddress","Please enter an email address to continue",
									   "JobDescription","Please enter a job description to continue");
/* Submit CV Form Validation */
function JSFnValidateVacancyForm()
{
	return JSFnValidateForm(aVacancyRequiredFields);
}
/*****************************************************************************************************************************/
var aContactRequiredFields = new Array ("FullName","Please enter your full name to continue");

function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('EmailAddress');
	var aTelephone = document.getElementById('TelephoneNo');
	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 JSFnActivateHomeLinks()
{
	aHomeUL = document.getElementById("homepagedivisions");
	if(aHomeUL != null)
	{
		aHomeLi = aHomeUL.getElementsByTagName('li');
		for(aIndex=0; aIndex<aHomeLi.length; aIndex++)
		{
			aHomeLi[aIndex].onmouseover = JSFnDeactivateOtherHomeLinks;
			aHomeLi[aIndex].onmouseout = JSFnResetOtherHomeLinks;
		}
	}
}

function JSFnDeactivateOtherHomeLinks()
{
	aHomeUL = document.getElementById("homepagedivisions");
	if(aHomeUL != null)
	{
		aHomeLi = aHomeUL.getElementsByTagName('li');
		for(aIndex=0; aIndex<aHomeLi.length; aIndex++)
		{
			if(aHomeLi[aIndex].childNodes[0] != this.childNodes[0]) 
			{
				aHomeLi[aIndex].childNodes[0].childNodes[0].style.clip = 'rect(159px 177px 318px 0px)';
				aHomeLi[aIndex].childNodes[0].childNodes[0].style.top = '-159px';

			}
		}
	}
}

function JSFnResetOtherHomeLinks()
{
	aHomeUL = document.getElementById("homepagedivisions");
	if(aHomeUL != null)
	{
		aHomeLi = aHomeUL.getElementsByTagName('li');
		for(aIndex=0; aIndex<aHomeLi.length; aIndex++)
		{
			aHomeLi[aIndex].childNodes[0].childNodes[0].style.clip = 'rect(0px 177px 159px 0px)';
			aHomeLi[aIndex].childNodes[0].childNodes[0].style.top = '0px';
		}
	}
}
/**************************************************************************************************************************************/

/* Ticker Tape */
function JSFnTickerTape()
{
		TICKER_CONTENT = document.getElementById("tickertape").innerHTML;
		TICKER_RIGHTTOLEFT = false;
		TICKER_SPEED = 3;
		TICKER_PAUSED = false;
		TICKER_STYLE = "color:#fff;";
		
		ticker_start();
}
/**************************************************************************************************************************************/

function ticker_start()
{
	var tickerSupported = false;
	TICKER_WIDTH = '200px';//document.getElementById("testimonials").style.width;
	//var img = "<img src=\"images/spacer.gif\" width=" + TICKER_WIDTH + " height=0>";

	// Firefox
	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1)
	{
		document.getElementById("tickertape").innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%' style=\"padding: 0 700px\"><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("tickertape").innerHTML = "<DIV nowrap='nowrap' style='width:100%; padding: 0 700px;'><SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN></DIV>";
		tickerSupported = true;
	}
	if(!tickerSupported)
	{
		document.getElementById("tickertape").outerHTML = "";
	}
	else
	{
		document.getElementById("tickertape").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("tickertape").scrollWidth - document.getElementById("tickertape").offsetWidth : 0;
		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
		document.getElementById("tickertape").style.display="block";
		TICKER_tick();
	}
	
}
/**************************************************************************************************************************************/		

function TICKER_tick()
{
	if(!TICKER_PAUSED) document.getElementById("tickertape").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
	if(TICKER_RIGHTTOLEFT && document.getElementById("tickertape").scrollLeft <= 0) document.getElementById("tickertape").scrollLeft = document.getElementById("tickertape").scrollWidth - document.getElementById("tickertape").offsetWidth;
	if(!TICKER_RIGHTTOLEFT && document.getElementById("tickertape").scrollLeft >= document.getElementById("tickertape").scrollWidth - document.getElementById("tickertape").offsetWidth) document.getElementById("tickertape").scrollLeft = 0;
	window.setTimeout("TICKER_tick()", 30);
}
/**************************************************************************************************************************************/