/* Contact us */



function init()
{
	var _form = document.getElementById("aspnetForm");
	if (_form != null)
	{
		_form.onsubmit = validate;
	}
}



function validate()
{
	var isValid = true;
	
	var _form = document.getElementById("aspnetForm");
	if (_form != null)
	{
		//required fields
		var firstName = document.getElementById("ctl00_primarygroupPlh_primaryPlh_firstNameTbx");
		var lastName = document.getElementById("ctl00_primarygroupPlh_primaryPlh_lastNameTbx");
		var job = document.getElementById("ctl00_primarygroupPlh_primaryPlh_jobTbx");
		var company = document.getElementById("ctl00_primarygroupPlh_primaryPlh_companyTbx");
		var industry = document.getElementById("ctl00_primarygroupPlh_primaryPlh_industryDdl");
		var email = document.getElementById("ctl00_primarygroupPlh_primaryPlh_emailTbx");
		var address1 = document.getElementById("ctl00_primarygroupPlh_primaryPlh_address1Tbx");
		var city = document.getElementById("ctl00_primarygroupPlh_primaryPlh_cityTbx");
		//var county = document.getElementById("ctl00_primarygroupPlh_primaryPlh_countyTbx");
		var postcode = document.getElementById("ctl00_primarygroupPlh_primaryPlh_postcodeTbx");
		var country = document.getElementById("ctl00_primarygroupPlh_primaryPlh_countryTbx");
		var tel = document.getElementById("ctl00_primarygroupPlh_primaryPlh_telTbx");
		
		if (firstName.value == "" 
			|| lastName.value == "" 
			|| job.value == "" 
			|| company.value == "" 
			|| industry.value == "" || industry.value == "0" 
			|| email.value == "" 
			|| address1.value == ""
			|| city.value == "" 
		//	|| county.value == "" 
			|| postcode.value == "" 
			|| country.value == "" 
			|| tel.value == ""
		)
		{
			isValid = false;
			
			//highlight fields
			if (firstName.value == "")
				if (firstName.className.indexOf("error") < 0)
					firstName.className += " error";
			if (lastName.value == "")
				if (lastName.className.indexOf("error") < 0)
					lastName.className += " error";
			if (job.value == "")
				if (job.className.indexOf("error") < 0)
					job.className += " error";
			if (company.value == "")
				if (company.className.indexOf("error") < 0)
					company.className += " error";
			if (industry.value == "" || industry.value == "0" )
				if (industry.className.indexOf("error") < 0)
					industry.className += " error";
			if (email.value == "")
				if (email.className.indexOf("error") < 0)
					email.className += " error";
			if (address1.value == "")
				if (address1.className.indexOf("error") < 0)
					address1.className += " error";
			if (city.value == "")
				if (city.className.indexOf("error") < 0)
					city.className += " error";
			/*if (county.value == "")
				if (county.className.indexOf("error") < 0)
					county.className += " error";*/
			if (postcode.value == "")
				if (postcode.className.indexOf("error") < 0)
					postcode.className += " error";
			if (country.value == "")
				if (country.className.indexOf("error") < 0)
					country.className += " error";
			if (tel.value == "")
				if (tel.className.indexOf("error") < 0)
					tel.className += " error";
			
			if (document.getElementById('generatederrormessage') == null && document.getElementById('generatedshowallmessage') == null)
			{
			
				//insert error message
				var _error = document.createElement('p');
				_error.setAttribute('id', 'generatederrormessage');
				_error.setAttribute('class', 'error');
				var _error_text = document.createTextNode("Please fill in the required fields.");
				_error.appendChild(_error_text);
				
				//insert link to show all fields
				_show_all = document.createElement('p');
				_show_all.setAttribute('id', 'generatedshowallmessage');
				_show_all.setAttribute('class', 'showall');
				_show_all_link = document.createElement('a');
				_show_all_link.setAttribute('href', '#');
				_show_all_link.onclick = show_all_fields;
				_show_all_link_text = document.createTextNode("Show all fields.");
				_show_all_link.appendChild(_show_all_link_text);
				_show_all.appendChild(_show_all_link);
				
				//attach to <form>
				_form.parentNode.insertBefore(_error, _form);
				_form.parentNode.insertBefore(_show_all, _form);
			
			}
			else
			{
				var generatederrormessage = document.getElementById("generatederrormessage");
				var generatedshowallmessage = document.getElementById("generatedshowallmessage");
				
				if (generatederrormessage != null)
				{
					generatederrormessage.className = generatederrormessage.className.replace("completed", "");
				}
				if (generatedshowallmessage != null)
				{
					generatedshowallmessage.className = generatedshowallmessage.className.replace("completed", "");
				}
			}
			
			//jump to form
			location.href = "#demoForm";
		}

		//required fields
		if (firstName.value != "")
			firstName.parentNode.className += " completed";
		if (lastName.value != "")
			lastName.parentNode.className += " completed";
		if (job.value != "")
			job.parentNode.className += " completed";
		if (company.value != "")
			company.parentNode.className += " completed";
		if (industry.value != "" && industry.value != "0" )
			industry.parentNode.className += " completed";
		if (email.value != "")
			email.parentNode.className += " completed";
		if (address1.value != "")
			address1.parentNode.className += " completed";
		if (city.value != "")
			city.parentNode.className += " completed";
		/*if (county.value != "")
			county.parentNode.className += " completed";*/
		if (postcode.value != "")
			postcode.parentNode.className += " completed";
		if (country.value != "")
			country.parentNode.className += " completed";
		if (tel.value != "")
			tel.parentNode.className += " completed";
		
		//optional fields
		var title = document.getElementById("ctl00_primarygroupPlh_primaryPlh_titleTbx");
		var address2 = document.getElementById("ctl00_primarygroupPlh_primaryPlh_address2Tbx");
		var address3 = document.getElementById("ctl00_primarygroupPlh_primaryPlh_address3Tbx");
		var county = document.getElementById("ctl00_primarygroupPlh_primaryPlh_countyTbx");
		var dataprotection = document.getElementById("dataprotection");
		
		title.parentNode.className += " completed";
		address2.parentNode.className += " completed";
		address3.parentNode.className += " completed";
		county.parentNode.className += " completed";
		dataprotection.className += " completed";
	
	}
	
	return isValid;
}



function show_all_fields()
{
	var _form = document.getElementById("aspnetForm");
	if (_form != null)
	{
		//required fields
		var firstName = document.getElementById("ctl00_primarygroupPlh_primaryPlh_firstNameTbx");
		var lastName = document.getElementById("ctl00_primarygroupPlh_primaryPlh_lastNameTbx");
		var job = document.getElementById("ctl00_primarygroupPlh_primaryPlh_jobTbx");
		var company = document.getElementById("ctl00_primarygroupPlh_primaryPlh_companyTbx");
		var industry = document.getElementById("ctl00_primarygroupPlh_primaryPlh_industryDdl");
		var email = document.getElementById("ctl00_primarygroupPlh_primaryPlh_emailTbx");
		var address1 = document.getElementById("ctl00_primarygroupPlh_primaryPlh_address1Tbx");
		var city = document.getElementById("ctl00_primarygroupPlh_primaryPlh_cityTbx");
		//var county = document.getElementById("ctl00_primarygroupPlh_primaryPlh_countyTbx");
		var postcode = document.getElementById("ctl00_primarygroupPlh_primaryPlh_postcodeTbx");
		var country = document.getElementById("ctl00_primarygroupPlh_primaryPlh_countryTbx");
		var tel = document.getElementById("ctl00_primarygroupPlh_primaryPlh_telTbx");
		
		firstName.parentNode.className = firstName.parentNode.className.replace("completed", "");
		lastName.parentNode.className = lastName.parentNode.className.replace("completed", "");
		job.parentNode.className = job.parentNode.className.replace("completed", "");
		company.parentNode.className = company.parentNode.className.replace("completed", "");
		industry.parentNode.className = industry.parentNode.className.replace("completed", "");
		email.parentNode.className = email.parentNode.className.replace("completed", "");
		address1.parentNode.className = address1.parentNode.className.replace("completed", "");
		city.parentNode.className = city.parentNode.className.replace("completed", "");
		//county.parentNode.className = county.parentNode.className.replace("completed", "");
		postcode.parentNode.className = postcode.parentNode.className.replace("completed", "");
		country.parentNode.className = country.parentNode.className.replace("completed", "");
		tel.parentNode.className = tel.parentNode.className.replace("completed", "");
		
		//optional fields
		var title = document.getElementById("ctl00_primarygroupPlh_primaryPlh_titleTbx");
		var address2 = document.getElementById("ctl00_primarygroupPlh_primaryPlh_address2Tbx");
		var address3 = document.getElementById("ctl00_primarygroupPlh_primaryPlh_address3Tbx");
		var county = document.getElementById("ctl00_primarygroupPlh_primaryPlh_countyTbx");
		var dataprotection = document.getElementById("dataprotection");
		
		title.parentNode.className = title.parentNode.className.replace("completed", "");
		address2.parentNode.className = address2.parentNode.className.replace("completed", "");
		address3.parentNode.className = address3.parentNode.className.replace("completed", "");
		county.parentNode.className = address3.parentNode.className.replace("completed", "");
		dataprotection.className = dataprotection.parentNode.className.replace("completed", "");
		
		//hide link to show all fields
		var generatedshowallmessage = document.getElementById("generatedshowallmessage");
		generatedshowallmessage.className = " completed";
	}
	
	return false;
}



if (window.addEventListener)
{
	window.addEventListener('load',init,false)
}
else if (window.attachEvent)
{
	window.attachEvent('onload',init)
}
