window.onload = function() 
{
	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;
			}
		}

		var aContactForm = document.getElementById('ContactForm');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;

		var aTradeForm = document.getElementById('TradeForm');
		if (aTradeForm != null) aTradeForm.onsubmit = JSFnValidateTradeForm;

		var aHomeForm = document.getElementById('HomeForm');
		if (aHomeForm != null) aHomeForm.onsubmit = JSFnValidateHomeForm;
	}	
}

var aContactRequiredFields = new Array ("Name","Please enter your name to continue");
function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('Email');
	var aAddress = document.getElementById('address');
	var aTelephone = document.getElementById('Telephone');

	if ((aEmail != null) && (aAddress != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aAddress.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your address, telephone number or email address to continue.');
			return false;
		}
	}

	return JSFnValidateForm(aContactRequiredFields);
}

/* Validate the Trade Form: Fields 
var aTradeFormRequiredFields = new Array ("Courses","Please select the type fo course to continue",
									 	 "Tuition","Please select the type of tuition to continue",
									 	 "DurationType","Please select the type of duration to continue",
									 	 "Looking","Please select the qualification you are looking for to continue",
									 	 "Experience","Please select if you want hands on or technical info to continue",
									 	 "FullName","Please enter your name to continue",
									 	 "Telephone","Please enter your telephone number to continue");*/
var aTradeFormRequiredFields = new Array ("Courses","Please select the type fo course to continue");
/* Validate the Trade Form: Function */
function JSFnValidateTradeForm()
{
	return JSFnValidateForm(aTradeFormRequiredFields);
}

	/********************************/

/* Validate the Home Form: Fields 
var aHomeRequiredFields = new Array ("SpecificProject","Please select what you intend to work on to continue",
									 "ProjectType","Please enter the rpoject type to continue",
									 "CourseProvides","Please select what you want the course to provide to continue",
									 "DealBuilders","Please select if you are interested in dealing with builders to continue",
									 "TuitionType","Please select the type of tuition you would prefer to continue",
									 "DurationType2","Please select the duration you would prefer to continue",
									 "FullName2","Please enter your name to continue",
									 "Telephone2","Please enter your telephone number to continue");*/
var aHomeRequiredFields = new Array ("SpecificProject","Please select what you intend to work on to continue");
/* Validate the Home Form: Function */
function JSFnValidateHomeForm()
{
	return JSFnValidateForm(aHomeRequiredFields);
}

	/********************************/


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;
}
