// Validation script for BRAVO Registration

function validateForm()
{
	
	$error = 0;

	if(document.registration.terms.checked == false)
	{
		$error = 1;
		$message = "Please read and accept the terms and conditions";
	}
	
	if(document.registration.interest.checked == false)
	{
		$error = 1;
		$message = "Please accept the payment option";
	}
	
	if(document.registration.paymentPlanFull.checked == false)
	{
		$error = 1;
		$message = "Please accept the required payment option by ticking the payment option box";
	}
	
	if(document.registration.supplyingPromotionalMaterial_0.checked == true)
	{
		if(document.registration.sizeOfMaterial.value == "")
		{
			$error = 1;
			$message = "You have selected Yes for promotional material, please give information on the size of the material."
		}
	}
	
	if(document.registration.exhibitorRate.checked == false)
	{
		$error = 1;
		$message = "Please accept the exhibitor rate charge by ticking the exhibitor rate box";
	}
	
	if(document.registration.country.value == "")
	{
		$error = 1;
		$message = "Please enter your country";
	}
	
	if(document.registration.postcode.value == "")
	{
		$error = 1;
		$message = "Please enter your postcode";
	}
	
	if(document.registration.county.value == "")
	{
		$error = 1;
		$message = "Please enter your county";
	}
	
	if(document.registration.city.value == "")
	{
		$error = 1;
		$message = "Please enter your town / city";
	}
	
	if(document.registration.address1.value == "")
	{
		$error = 1;
		$message = "Please enter your address";
	}
	
	if(document.registration.telephone.value == "")
	{
		$error = 1;
		$message = "Please enter your daytime contact telephone number";
	}
	
	// Is this a valid email
	if(validateEmail(document.registration.email.value) == false)
	{
		$error = 1;
		$message = "Please enter a valid email address";
	}
	
	if(document.registration.email.value == "")
	{
		$error = 1;
		$message = "Please enter your email address";
	}
	
	if(document.registration.surname.value == "")
	{
		$error = 1;
		$message = "Please enter your surname";
	}
	
	if(document.registration.firstname.value == "")
	{
		$error = 1;
		$message = "Please enter your first name";
	}
	
	if($error == 1)
	{
		alert($message);
		return false;
	}
	else
	{
		document.registration.submit();	
	}

}

function validateDelegate()
{
	
	$error = 0;

	
	if(document.registration.terms.checked == false)
	{
		$error = 1;
		$message = "Please read and accept the terms and conditions";
	}
	
	if(document.registration.bravoMember_0.checked == true)
	{
		if(document.registration.renewalCost.checked == false)
		{
			$error = 1;
			$message = "As an existing member you will need to renew your membership. Please tick the renewal cost box.";
		}
	}
	
	if(document.registration.bravoMember_1.checked == true)
	{
		if(document.registration.renewalCost.checked == true)
		{
			$error = 1;
			$message = "If you are not an existing member and do not need to renew, pleas untick the renewal box.";
		}
	}
	
	if(document.registration.country.value == "")
	{
		$error = 1;
		$message = "Please enter your country";
	}
	
	if(document.registration.postcode.value == "")
	{
		$error = 1;
		$message = "Please enter your postcode";
	}
	
	if(document.registration.county.value == "")
	{
		$error = 1;
		$message = "Please enter your county";
	}
	
	if(document.registration.city.value == "")
	{
		$error = 1;
		$message = "Please enter your town / city";
	}
	
	if(document.registration.address1.value == "")
	{
		$error = 1;
		$message = "Please enter your address";
	}
	
	if(document.registration.telephone.value == "")
	{
		$error = 1;
		$message = "Please enter your daytime contact telephone number";
	}
	
	// Is this a valid email
	if(validateEmail(document.registration.email.value) == false)
	{
		$error = 1;
		$message = "Please enter a valid email address";
	}
	
	if(document.registration.email.value == "")
	{
		$error = 1;
		$message = "Please enter your email address";
	}
	
	if(document.registration.surname.value == "")
	{
		$error = 1;
		$message = "Please enter your surname";
	}
	
	if(document.registration.firstname.value == "")
	{
		$error = 1;
		$message = "Please enter your first name";
	}
	
	if($error == 1)
	{
		alert($message);
		return false;
	}
	else
	{
		document.registration.submit();	
	}

}

function validateEmail(str) 
{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		{
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    return false
		}

		if (str.indexOf(at,(lat+1))!=-1)
		{
		    return false
		}

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    return false
		 }

 		 return true					
}

function selectNonResidential()
{
	document.registration.nonResidential.checked = true;
	document.registration.occupancy_0.checked = false;
	document.registration.occupancy_1.checked = false;
}

function selectResidential()
{
	
	document.registration.residential.checked = true;
	document.registration.occupancy_0.checked = true;
	document.registration.saturdayNonResidential.checked = false;
	document.registration.sundayNonResidential.checked = false;
}

function selectDoubleResidential()
{
	document.registration.residential.checked = true;
	document.registration.occupancy_1.checked = true;
	document.registration.saturdayNonResidential.checked = false;
	document.registration.sundayNonResidential.checked = false;
}

