window.onload = StandardOnLoad;

FSelectedServ = '';
FSelectedServObj = null;

function StandardOnLoad()
{
	if (document.getElementById)
	{	
		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 aCandidateForm = document.getElementById('CandidateForm');
		if (aCandidateForm != null) aCandidateForm.onsubmit = JSFnValidateCandidateForm;
		
		var aClientForm = document.getElementById('ClientForm');
		if (aClientForm != null) aClientForm.onsubmit = JSFnValidateClientForm;

		var aTestimonialForm = document.getElementById('TestimonialForm');
		if (aTestimonialForm != null) aTestimonialForm.onsubmit = JSFnValidateTestimonialForm;

		var aFriendForm = document.getElementById('FriendForm');
		if (aFriendForm != null) aFriendForm.onsubmit = JSFnValidateFriendForm;


		var aImage = document.getElementById('international');
		if (aImage != null) 
		{
			aImage.onmouseover = JSFnImageOver;
			aImage.onmouseout = JSFnImageOut;
		}

		var aImage = document.getElementById('candidates');
		if (aImage != null) 
		{
			aImage.onmouseover = JSFnImageOver;
			aImage.onmouseout = JSFnImageOut;
		}

		var aImage = document.getElementById('clients');
		if (aImage != null) 
		{
			aImage.onmouseover = JSFnImageOver;
			aImage.onmouseout = JSFnImageOut;
		}

		var aImage = document.getElementById('vacancies');
		if (aImage != null) 
		{
			aImage.onmouseover = JSFnImageOver;
			aImage.onmouseout = JSFnImageOut;
			aImage.onclick = JSFnOpenNewWindow;
		}

		var aImage = document.getElementById('projectlifecycle');
		if (aImage != null) 
		{
			aImage.onmouseover = JSFnImageOver;
			aImage.onmouseout = JSFnImageOut;
		}

		var aLinksTable = document.getElementById('linkstable');
		if (aLinksTable != null) 
		{
			var as = aLinksTable.getElementsByTagName("a");
			for(aIndex=0;aIndex<as.length;aIndex++)
			{
				as[aIndex].onclick=JSFnOpenNewWindow;
			}
		}
	}
}

function JSFnImageOver()
{
	var aImage = this.getElementsByTagName("img")[0];
 	if (aImage != null)	
	{	
	 	aThisImageName = aImage.src.substr(aImage.src.lastIndexOf('/'));
	 	aThisImageName = aThisImageName.replace('%20', '_');
	 	if (aThisImageName != FSelectedServ) 
		{
			aImage.src = aImage.src.replace('.gif', '_hover.gif');	
			aImage.src = aImage.src.replace('.jpg', '_hover.jpg');	
		}
	}
}

function JSFnImageOut()
{
	var aImage = this.getElementsByTagName("img")[0];
 	if (aImage != null)	
	{
	 	aThisImageName = aImage.src.substr(aImage.src.lastIndexOf('/'));
	 	aThisImageName = aThisImageName.replace('%20', '_');
		if (aThisImageName != FSelectedServ) 
		{
			aImage.src = aImage.src.replace('_hover.gif', '.gif');	
			aImage.src = aImage.src.replace('_hover.jpg', '.jpg');	
		}
	}
}


function JSFnOpenNewWindow()
{
	var aWindow = window.open(this.href, 'linkwindow', '')
	aWindow.focus();
	return false;
}

/******************************************************************************************************************************************/
var aClientRequiredFields = new Array ("FirstName","Please enter your first name to continue",
									  	  "Surname","Please enter your surname to continue",
									  	  "City","Please enter a city to continue",
									  	  "Country","Please enter a country to continue",
									  	  "DaytimePhone","Please enter a daytime phone number to continue",
									  	  "EmailAddress","Please enter your email address to continue",
									  	  "Company","Please enter your email address to continue");

function JSFnValidateClientForm()
{
	return JSFnValidateForm(aClientRequiredFields);
}
/******************************************************************************************************************************************/

/******************************************************************************************************************************************/
var aCandidateRequiredFields = new Array ("FirstName","Please enter your first name to continue",
									  	  "Surname","Please enter your surname to continue",
									  	  "City","Please enter a city to continue",
									  	  "Country","Please enter a country to continue",
									  	  "DaytimePhone","Please enter a daytime phone number to continue",
									  	  "EmailAddress","Please enter your email address to continue");
function JSFnValidateCandidateForm()
{
	return JSFnValidateForm(aCandidateRequiredFields);
}
/******************************************************************************************************************************************/

/******************************************************************************************************************************************/
var aFriendRequiredFields = new Array ("YourName","Please enter your name to continue",
									  	  "FriendsName","Please enter your friends name to continue",
									  	  "PositionSeeking","Please enter the position they are looking for to continue",
									  	  "EmailAddress","Please enter your email address to continue",
									  	  "FriendsEmailAddress","Please enter your friends email address to continue");
function JSFnValidateFriendForm()
{
	return JSFnValidateForm(aFriendRequiredFields);
}
/******************************************************************************************************************************************/

/******************************************************************************************************************************************/
var aTestimonialRequiredFields = new Array ("YourName","Please enter your name to continue");

function JSFnValidateTestimonialForm()
{
	return JSFnValidateForm(aTestimonialRequiredFields);
}
/******************************************************************************************************************************************/

var aContactRequiredFields = new Array ("firstname","Please enter your name to continue","surname","Please enter your surname to continue");

function JSFnValidateContactForm()
{
	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(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;
}