var FIDParagraphs = new Array('website_address', 2, 'blueM', 6, 'yellowC', 5, 'greenF', 4, 'about_gallery', 2, 'for_clients', 1, 'news', 3)

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;
			}
		}	
		
		/* Apply front page pop ups */
		var aIndexContent = document.getElementById('indexcontent');
		if (aIndexContent != null)
		{
			HideParagraphs();
			aIndexContent.style.display = 'block';
		}	
		
		for (aIndex = 0; aIndex < FIDParagraphs.length; aIndex+=2)
		{
			var aID = document.getElementById(FIDParagraphs[aIndex]);
			if (aID != null)
			{
				aID.onmouseout = HideParagraphs;
				switch(FIDParagraphs[aIndex + 1])
				{
					case 1:
						aID.onmouseover = ShowParagraph1;
						break    
					case 2:
						aID.onmouseover = ShowParagraph2;
						break    
					case 3:
						aID.onmouseover = ShowParagraph3;
						break    
					case 4:
						aID.onmouseover = ShowParagraph4;
						break    
					case 5:
						aID.onmouseover = ShowParagraph5;
						break    
					default:
						aID.onmouseover = ShowParagraph6;
				}
			}
		}
		
		// Apply form checking
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		var aFreelanceForm = document.getElementById('freelanceform');
		if (aFreelanceForm != null) aFreelanceForm.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 aJobForm = document.getElementById('jobform');
		if (aJobForm != null) aJobForm.onsubmit = JSFnValidateApplyForm;	
			
		var aSendJobForm = document.getElementById('sendjobform');
		if (aSendJobForm != null) aSendJobForm.onsubmit = JSFnValidateSendJobForm;	
	}
}

function HideParagraphs()
{
	var aIndexContent = document.getElementById('indexcontent');
	if (aIndexContent != null)
	{
		var aIndexParas = aIndexContent.getElementsByTagName('p');
		for (aIndex = 0; aIndex < aIndexParas.length; aIndex++)
		{				
			aIndexParas[aIndex].style.display = 'none';
		}
	}	
}

function ShowParagraph(aParaToShow, aLeft, aTop)
{
	var aIndexContent = document.getElementById('indexcontent');
	if (aIndexContent != null)
	{
		var aIndexParas = aIndexContent.getElementsByTagName('p');
		aIndexParas[(aParaToShow - 1)].style.display = 'block';
		aIndexParas[(aParaToShow - 1)].style.left = aLeft;
		aIndexParas[(aParaToShow - 1)].style.top = aTop;
		aIndexParas[(aParaToShow - 1)].style.zIndex = '1000';
	}	
}

function ShowParagraph1()
{
	ShowParagraph(1, '600px', '135px');
}

function ShowParagraph2()
{
	ShowParagraph(2, '465px', '60px');
}

function ShowParagraph3()
{
	ShowParagraph(3, '470px', '195px');
}

function ShowParagraph4()
{
	ShowParagraph(4, '180px', '35px');
}

function ShowParagraph5()
{
	ShowParagraph(5, '350px', '310px');
}

function ShowParagraph6()
{
	ShowParagraph(6, '245px', '20px');
}

function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
	while(1) 
	{
	  curleft += obj.offsetLeft;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.x)
	curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
	while(1)
	{
	  curtop += obj.offsetTop;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.y)
	curtop += obj.y;
return curtop;
}


var aContactRequiredFields = new Array ("name","Please enter your name to continue");
function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('email');
	var aMobile = document.getElementById('mobile');
	var aTelephone = document.getElementById('telephone');
	if ((aEmail != null) && (aMobile != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aMobile.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your telephone/mobile number or email address to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aContactRequiredFields);
}


var aCandidateRequiredFields = new Array ("Name","Please enter your name to continue",
										  "CandidateName","Please enter the name of the candidate you are referring to continue");
function JSFnValidateCandidateForm()
{
	var aEmail = document.getElementById('Email');
	var aTelephone = document.getElementById('Telephone');
	var aCandidateEmail = document.getElementById('CandidateEmail');
	var aCandidateTelephone = document.getElementById('CandidateTelephone');
	
	if ((aEmail != null) && (aTelephone != null) && (aCandidateEmail != null) && (aCandidateTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your telephone number or email address to continue.');
			return false;
		}
		else if ((aCandidateEmail.value == '') && (aCandidateTelephone.value == ''))
		{
			alert('You must provide either the telephone number or email address of the candidate you are referring to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aCandidateRequiredFields);
}

var aClientRequiredFields = new Array ("Name","Please enter your name to continue",
									   "Contact","Please enter some contact details to continue");
function JSFnValidateClientForm()
{
	return JSFnValidateForm(aClientRequiredFields);
}

var aSendJobRequiredFields = new Array ("email","Please enter a valid email address to continue");
function JSFnValidateSendJobForm()
{
	return JSFnValidateForm(aSendJobRequiredFields);
}

var aApplyRequiredFields = new Array ("Name","Please enter your first name to continue",
									  "Surname","Please enter your surname to continue");
function JSFnValidateApplyForm()
{
	var aEmail = document.getElementById('EmailAddress');
	var aMobile = document.getElementById('Mobile');
	var aTelephone = document.getElementById('Telephone');
	if ((aEmail != null) && (aMobile != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aMobile.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your telephone/mobile number or email address to continue.');
			return false;
		}
		else if (   (isNaN(aMobile.value.replace(/ /g, '')))
				 || (isNaN(aTelephone.value.replace(/ /g, ''))))
		{
			alert('You must only enter numerical information as your telephone/mobile number in order to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aApplyRequiredFields);
}


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;
}
