function checkApplication()
{
	hasErrors = false;
	errorMessage = "";
	companyType = "";
	checkElement("name");
	checkElement("company-name");
	checkElement("address-1");
	checkElement("city");
	checkElement("postcode");
	checkElement("email");
	checkElement("mtelephone");


	for(i = 0; i < document.application.type.length; i++)
	{
		if(document.application.type[i].checked)
		companyType = document.application.type[i].value;
	}

	if(companyType == "")
	{
		hasErrors = true;
		errorMessage += "Company Type must be entered.\n";
	}

	if(hasErrors)
	{
		alert(errorMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function checkCV()
{
	hasErrors = false;
	errorMessage = "";
	companyType = "";
	checkElement("first-name");
	checkElement("surname");
	checkElement("telephone");
	checkElement("mobile");
	checkElement("work-telephone");
	checkElement("email");
	checkElement("best-time");
	checkElement("address-1");
	checkElement("address-2");
	checkElement("city");
	checkElement("postcode");
	checkElement("location");
	checkElement("position");
	checkElement("salary");
	checkElement("referrer");
	
	var re = new RegExp('.doc|.rtf|.txt|.pdf');
	if( (!document.getElementById('file').value.match(re)) && (!document.getElementById('file').value == '') )
	{
		hasErrors = true;
		errorMessage += "Please upload your CV in one of the following formats: .doc, .rtf, .txt, .pdf.";
	}

	if(hasErrors)
	{
		alert(errorMessage);
		return false;
	}
	else
	{
		return true;
	}	
}

function checkVacancy()
{
	hasErrors = false;
	errorMessage = "";
	companyType = "";
	
	checkElement("first-name");
	checkElement("surname");
	checkElement("telephone");
	checkElement("email");
	checkElement("company");
	checkElement("position");
	checkElement("details");

	if(hasErrors)
	{
		alert(errorMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function checkContactForm()
{
	hasErrors = false;
	errorMessage = "";
	companyType = "";
	
	checkElement("name");
	checkElement("email");
	checkElement("message");

	if(hasErrors)
	{
		alert(errorMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function checkElement(element)
{
	if(document.getElementById(element).value == '')
	{
		hasErrors = true;
		element = element.ucfirst();
		element = element.replace("-", " ");
		errorMessage += element + " must be entered.\n";
	}
}

String.prototype.ucfirst = function()
{
	return this.charAt(0).toUpperCase() + this.substr(1);
}