//<script>
<!-- 


function resetForm() // main job to clear any error messages in "Results" column
{
   var i;
   var Elements = document.getElementsByTagName('div');
   for (i=0;i<Elements.length;i++)
   {
      if (Elements.item(i).parentNode.id == "Results") // check the <tr> had id="Results"
         Elements.item(i).innerHTML = '';
   }
   return true;
}

function validateForm()
{
   var validateFlag;
   
   validateFlag = checkFirstNameField()&
	              checkLastNameField() &
	              checkAddressField() &
                  checkZipCodeField() &
				  checkCityField() &
				  checkCountryField() &
				  checkEmailField();
	 
	if (validateFlag)
	{
	   return true;
	}
	else
	{
	   return false;
	}  
}

function checkFirstNameField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('firstNameResults');
   
   var re = /[\w\s]{2,}/;
   if (re.test(Form.firstName.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter a first name</span>';
      return false;
   }
}


function checkLastNameField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('lastNameResults');
   
   var re = /[\w\s]{2,}/;
   if (re.test(Form.lastName.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter a last name</span>';
      return false;
   }
}

function checkAddressField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('addressResults');
   
   var re = /[\w\s\d]{2,}/;
   if (re.test(Form.address.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter an address</span>';
      return false;
   }
}

function checkZipCodeField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('zipCodeResults');
   
   var re = /[\w\s\d]{2,}/;
   if (re.test(Form.zipCode.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter a zip code</span>';
      return false;
   }
}

function checkCityField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('cityResults');
   
   var re = /[\w\s]{2,}/;
   if (re.test(Form.city.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter a city name</span>';
      return false;
   }
}

function checkCountryField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('countryResults');
   
   var re = /[\w\s]{2,}/;
   if (re.test(Form.country.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter a country name</span>';
      return false;
   }
}


function checkEmailField()
{
   var Form = document.getElementById('Registration');
   var ResultsArea = document.getElementById('emailAddressResults');
   if (checkEmailAddress(Form.emailAddress.value) )
   {
      ResultsArea.innerHTML = '';
      return true;
   }
   else
   {
	  ResultsArea.innerHTML = '<span class="formerror">You need to enter a valid E-Mail address</span>';
   }
}


function checkEmailAddress(Address)
	{
	   // This function controlls the checking of an email address. It is supplies
	   // as a parameter the Address to validate. If it is valid, the function returns
	   // true, otherwise false.
	   //
	   // first lets make sure we have one and only one @ in the string and split on it
	   var splitAddress = Address.split("@");  
	   if (splitAddress.length != 2)
	   {
	      return false;
	   }
	   if (checkNamePart(splitAddress[ 0 ]) && checkDomainPart(splitAddress[ 1 ]))
	   {
	      return true;
	   }
	   else 
	   {
	      return false;
	   }
	}
	
	function checkNamePart(Name)
	{
	   // the name can contain the characters a-z (upper or lower case) 0-9 . _ and -
	   // and must start with one of a-z (upper or lower case) or 0-9
	   
	   // Explanation of RegExp used below:
	   //   ^[0-9a-z]
	   //          This says look for at least one alphanumeric character at the 
	   //          beginning of the string (^ means beginning).
	   //    [0-9a-z\._-]*$
	   //          This bit says match any number of alphnumerics, the "." "-"
	   //          and "_" in any order up to the end of the string. 
	   var re = /^[0-9a-z][0-9a-z\._-]*$/i; 

	   if(re.test(Name))
	   {
	      return true;
	   }
	   else 
	   {
	      return false;
	   } 
	}
	
	function checkDomainPart(Domain)
	{
	   // The domain part must contain at least one dot
	   // The last part of the domain (the TLD) must be at least 2 alpha characters
	   // The rules for the next part (left of the last dot) vary according to the organisers of the TLD
	   //   but must be alpha numeric values contianing at least one alpha character
	 
	   // Explanation of RegExp used below:
	   //   ^([0-9a-z]{1,}\.)*?  
	   //          This says start at the beginning of the string and look for any number 
	   //          of alphanumerics followed by "." as many times as possible (* = o or more), but
	   //          not so many timeas that the following patterns can not be matched (? = not greed match).
	   //   ([0-9a-z]{2,}\.)
	   //          This bit says look for one pattern containing at least two alphanumeric characters
	   //          followed by a .
	   //   ([a-z]{2,})$
	   //          This last bit says match up to the end of the string (signified by the "$"), and
	   //          match two or more alpha characters.
	   var re = /^([0-9a-z]{1,}\.)*?([0-9a-z_-]{2,}\.)([a-z]{2,})$/i ///^([0-9a-z]{1,}\.)*?([0-9a-z]{2,}\.)([a-z]{2,})$/i
	
	   if(re.test(Domain))
	   {
	      return true;
	   }
	   else 
	   {
	      return false;
	   } 
	}

// -->

