/*
	This script is used by registration.php to validate the contents of the form.
*/
function ValidateForm(theForm)
{
	// check for valid chars in password
	if(!isCharsInBag(theForm.Password.value,passwordChars))
	{
		alert("Sorry, but some of the characters you entered are not allowed in the password field" + "\n" + "Please only use the following characters: \n\n" + passwordChars);
		return false;
	}

	// Username
	if(!checkString(theForm.Username,'Username')){return false;}
	if(typeof(useEmailAsUsername) != 'undefined' && useEmailAsUsername != null && useEmailAsUsername == true)
	{
		if(FormatUsername() == false)
			return false;
	}
	
	//Verify Email Address
	if(typeof(useVerifyEmailAddress) != 'undefined' && useVerifyEmailAddress != null && useVerifyEmailAddress == true)
	{
		if(theForm.Username.value != theForm.ConfirmEmailAddress.value)
		{
			alert("Your email addresses do not match. Please check you have entered them correctly.");
			theForm.ConfirmEmailAddress.focus();
			return false;
		}	
	}

	// Password
	if(!checkString(theForm.Password,'Password')){return false;}

	// check passwords match
	if(theForm.Password.value != theForm.ConfirmPassword.value)
	{
		alert("Your passwords don't match, please enter them again.");
		theForm.Password.value='';
		theForm.ConfirmPassword.value='';
		theForm.Password.focus();
		return false;
	}
	
	//Check Password
	if(theForm.ConfirmPassword.value.length == 0)
	{
		alert("Please confirm your password.");
		theForm.ConfirmPassword.focus();
		return false;
	}	
	
	if(theForm.Password.value != txtConfirmPassword.value)
	{
		alert("Your passwords don't match, please enter them again.");
		txtPassword.value='';
		txtConfirmPassword.value='';
		txtPassword.focus();
		return false;
	}
	
	IncludedFields = theForm.PersonalDetails_Array.value;
		
	// Title
	if(IncludedFields.indexOf("Title")!=-1)
	{
	 if (theForm.Title.selectedIndex < 0)
	  {
	    alert("Please select one of the \"Title\" options.");
	    theForm.Title.focus();
	    return (false);
	  }
	
	  if (theForm.Title.selectedIndex == 0)
	  {
	    alert("The first \"Title\" option is not a valid selection.  Please choose one of the other options.");
	    theForm.Title.focus();
	    return (false);
	  }
	}	
	if(IncludedFields.indexOf("Firstname")!=-1)
	{
	   // FistName
	  if (theForm.Firstname.value == "")
	  {
	    alert("Please enter a value for the \"First Name\" field.");
	    theForm.Firstname.focus();
	    return (false);
	  }
	
	  if (theForm.Firstname.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"First Name\" field.");
	    theForm.Firstname.focus();
	    return (false);
	  }
	
	  if (theForm.Firstname.value.length > 25)
	  {
	    alert("Please enter at most 25 characters in the \"First Name\" field.");
	    theForm.Firstname.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("Surname")!=-1)
	{
	// Surname
	  if (theForm.Surname.value == "")
	  {
	    alert("Please enter a value for the \"Surname\" field.");
	    theForm.Surname.focus();
	    return (false);
	  }
	
	  if (theForm.Surname.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Surname\" field.");
	    theForm.Surname.focus();
	    return (false);
	  }
	
	  if (theForm.Surname.value.length > 25)
	  {
	    alert("Please enter at most 25 characters in the \"Surname\" field.");
	    theForm.Surname.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("Email")!=-1)
	{ 
	//Email
	  if (theForm.Email.value == "")
	  {
	    alert("Please enter a value for the \"Email Address\" field.");
	    theForm.Email.focus();
	    return (false);
	  }
	
	  if (theForm.Email.value.length < 5)
	  {
	    alert("Please enter at least 5 characters in the \"Email Address\" field.");
	    theForm.Email.focus();
	    return (false);
	  }
	
	  if (theForm.Email.value.length > 100)
	  {
	    alert("Please enter at most 100 characters in the \"Email Address\" field.");
	    theForm.Email.focus();
	    return (false);
	  }
	
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@._";
	  var checkStr = theForm.Email.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  
	  var i = 1;
	  var sLength = checkStr.length;
	  
	  // look for @
	  while ((i < sLength) && (checkStr.charAt(i) != "@"))
	  { i++;}
	  diff=sLength-i;
	  if(diff<1)
	  {
	     alert("You have not used an \"@\" symbol in your email address.Please use one.")
	     theForm.Email.focus();
	     return (false);
	  }
	  
	  // look for .
	  i = 1;
	  while ((i < sLength) && (checkStr.charAt(i) != "."))
	  { i++;}
	  diff=sLength-i;
	  if(diff<1)
	  {
	     alert("You have not used an \".\" symbol in your email address.Please use one.")
	     theForm.Email.focus();
	     return (false);
	  }
	  
	  if (!allValid)
	  {
	    alert("Please enter only letter, digit and \"@._\" characters in the \"Email Address\" field.");
	    theForm.Email.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("DOB")!=-1)
	{ 
	  //Date of Birth
	  if (theForm.DOBDay.value == "" || theForm.DOBMonth.value == "" || theForm.DOBYear.value == "")
	  {
	    alert("Please enter your date of birth.");
	    theForm.DOBDay.focus();
	    return (false);
	  }
	
	  if (!isDay(theForm.DOBDay.value))
	  {
	    alert("Please enter the day correctly.");
	    theForm.DOBDay.focus();
	    return (false);
	  }
	  
	  if (!isMonth(theForm.DOBMonth.value))
	  {
	    alert("Please enter the month correctly.");
	    theForm.DOBMonth.focus();
	    return (false);
	  }
	  
	  if (!isYear(theForm.DOBYear.value))
	  {
	    alert("Please enter the year correctly. The year should consist of 4 digits.");
	    theForm.DOBYear.focus();
	    return (false);
	  }
	  
	  //Check the Day is correct based on the month
	  var day = parseFloat(theForm.DOBDay.value);
	  var month = parseFloat(theForm.DOBMonth.value);
	  var year = parseFloat(theForm.DOBYear.value);
	  if(month == 2 && ((isLeapYear(year) && day > 29) || (!isLeapYear(year) && day > 28)))
	  {
	  	alert("Please enter a correct date for the month.");
	    	theForm.DOBDay.focus();
	    	return (false);	
	  }
	  else if((month == 4 || month==6 || month==9 || month == 11) && day > 30)
	  {
	  	alert("Please enter a correct date for the month.");
	    	theForm.DOBDay.focus();
	    	return (false);	
	  }
	  
	  //Check the Year is not in the future
	  var curYear = new Date().getFullYear();
	  if(year > curYear || year < (curYear - 150))
	  {
	  	alert("Please enter a valid year.");
	    	theForm.DOBYear.focus();
	    	return (false);
	  }
	  
	  //Check not greater than current date
	  var curDate = new Date();
	  var birthDate = new Date(year, month-1, day);
	  if(birthDate >= curDate)
	  {
	  	alert("Please enter a date that is less than the current date.");
	    	theForm.DOBDay.focus();
	    	return (false);
	  }
	}
	
	if(IncludedFields.indexOf("JobTitle")!=-1)
	{ 
	// JobTitle
	  if (theForm.JobTitle.value == "")
	  {
	    alert("Please enter a value for the \"Job Title\" field.");
	    theForm.JobTitle.focus();
	    return (false);
	  }
	
	  if (theForm.JobTitle.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Job Title\" field.");
	    theForm.JobTitle.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("Company")!=-1)
	{ 
	// Company
	  if (theForm.Company.value == "")
	  {
	    alert("Please enter a value for the \"Company\" field.");
	    theForm.Company.focus();
	    return (false);
	  }
	
	  if (theForm.Company.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Company\" field.");
	    theForm.Company.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("CompanyType")!=-1)
	{ 
	// CompanyType
	
	  if (theForm.CompanyType.selectedIndex < 0)
	  {
	    alert("Please select one of the \"Company Type\" options.");
	    theForm.CompanyType.focus();
	    return (false);
	  }
	
	  if (theForm.CompanyType.selectedIndex == 0)
	  {
	    alert("The first \"Company Type\" option is not a valid selection.  Please choose one of the other options.");
	    theForm.CompanyType.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("CompanyABN")!=-1)
	{ 
	// Company
	  if (theForm.CompanyABN.value == "")
	  {
	    alert("Please enter a value for the \"Company ABN\" field.");
	    theForm.CompanyABN.focus();
	    return (false);
	  }
	
	  if (theForm.CompanyABN.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Company ABN\" field.");
	    theForm.CompanyABN.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("AddressStreet")!=-1)
	{ 
	// Street Address
	  if (theForm.AddressStreet.value == "")
	  {
	    alert("Please enter a value for the \"Street Address\" field.");
	    theForm.AddressStreet.focus();
	    return (false);
	  }
	
	  if (theForm.AddressStreet.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Street Address\" field.");
	    theForm.AddressStreet.focus();
	    return (false);
	  }
	
	  if (theForm.AddressStreet.value.length > 50)
	  {
	    alert("Please enter at most 50 characters in the \"Street Address\" field.");
	    theForm.AddressStreet.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("AddressCity")!=-1)
	{ 
	// City
	  if (theForm.AddressCity.value == "")
	  {
	    alert("Please enter a value for the \"City\" field.");
	    theForm.AddressCity.focus();
	    return (false);
	  }
	
	  if (theForm.AddressCity.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"City\" field.");
	    theForm.AddressCity.focus();
	    return (false);
	  }
	
	  if (theForm.AddressCity.value.length > 50)
	  {
	    alert("Please enter at most 50 characters in the \"City\" field.");
	    theForm.AddressCity.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("AddressState")!=-1)
	{ 
	// State
	  if (theForm.AddressState.value == "")
	  {
	    alert("Please enter a value for the \"State\" field.");
	    theForm.AddressState.focus();
	    return (false);
	  }
	
	  if (theForm.AddressState.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"State\" field.");
	    theForm.State.focus();
	    return (false);
	  }
	
	  if (theForm.AddressState.value.length > 50)
	  {
	    alert("Please enter at most 50 characters in the \"State\" field.");
	    theForm.AddressState.focus();
	    return (false);
	  }  
	}
	
	if(IncludedFields.indexOf("AddressCountry")!=-1)
	{ 
	// Country
	
	  if (theForm.AddressCountry.selectedIndex < 0)
	  {
	    alert("Please select one of the \"Country\" options.");
	    theForm.AddressCountry.focus();
	    return (false);
	  }
	
	  if (theForm.AddressCountry.selectedIndex == 0)
	  {
	    alert("The first \"Country\" option is not a valid selection.  Please choose one of the other options.");
	    theForm.AddressCountry.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("AddressPostCode")!=-1)
	{ 
	// Postcode
	  if (theForm.AddressPostCode.value == "")
	  {
	    alert("Please enter a value for the \"Postcode\" field.");
	    theForm.AddressPostCode.focus();
	    return (false);
	  }
	
	  if (theForm.AddressPostCode.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Postcode\" field.");
	    theForm.AddressPostCode.focus();
	    return (false);
	  }
	
	  if (theForm.AddressPostCode.value.length > 50)
	  {
	    alert("Please enter at most 50 characters in the \"Postcode\" field.");
	    theForm.Postcode.focus();
	    return (false);
	  }  
	}
	
	if(IncludedFields.indexOf("PhoneHome")!=-1)
	{  
	// Telephone
	  if (theForm.PhoneHome.value == "")
	  {
	    alert("Please enter a value for the \"Telephone\" field.");
	    theForm.PhoneHome.focus();
	    return (false);
	  }
	
	  if (theForm.PhoneHome.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Telephone\" field.");
	    theForm.PhoneHome.focus();
	    return (false);
	  }
	
	  if (theForm.PhoneHome.value.length > 50)
	  {
	    alert("Please enter at most 50 characters in the \"Telephone\" field.");
	    theForm.PhoneHome.focus();
	    return (false);
	  }
	}
	
	if(theForm.PhoneHome && !RF_CheckGenericPhoneNumber(theForm.PhoneHome.value))
	{
		alert("Please enter at valid phone number.");
		theForm.PhoneHome.focus();
		return (false);
	}
	
	if(IncludedFields.indexOf("PhoneMobile")!=-1)
	{  
	// Mobile Phone
	  if (theForm.PhoneMobile.value == "")
	  {
	    alert("Please enter a value for the \"Mobile Phone\" field.");
	    theForm.PhoneMobile.focus();
	    return (false);
	  }
	
	  if (theForm.PhoneMobile.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Mobile Phone\" field.");
	    theForm.PhoneMobile.focus();
	    return (false);
	  }
	
	  if (theForm.PhoneMobile.value.length > 50)
	  {
	    alert("Please enter at most 50 characters in the \"Mobile Phone\" field.");
	    theForm.PhoneMobile.focus();
	    return (false);
	  }
	}
	
	if(theForm.PhoneMobile && !RF_CheckGenericPhoneNumber(theForm.PhoneMobile.value))
	{
		alert("Please enter at valid phone number.");
		theForm.PhoneMobile.focus();
		return (false);
	}
	
	if(IncludedFields.indexOf("AgeBracket")!=-1)
	{ 
	// AgeBracket
	
	  if (theForm.AgeBracket.selectedIndex < 0)
	  {
	    alert("Please select one of the \"Age Bracket\" options.");
	    theForm.AgeBracket.focus();
	    return (false);
	  }
	
	  if (theForm.AgeBracket.selectedIndex == 0)
	  {
	    alert("The first \"Age Bracket\" option is not a valid selection. Please choose one of the other options.");
	    theForm.AgeBracket.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("Gender")!=-1)
	{ 
	// Gender
	
	  if (theForm.Gender.selectedIndex < 0)
	  {
	    alert("Please select a gender.");
	    theForm.Gender.focus();
	    return (false);
	  }
	
	  if (theForm.Gender.selectedIndex == 0)
	  {
	    alert("The first \"Gender\" option is not a valid selection. Please choose one of the other options.");
	    theForm.Gender.focus();
	    return (false);
	  }
	}
	
	theForm.btnRegister.disabled = true;

	return true;
}

function ValidateParentRegistrationForm(theForm)
{
	IncludedFields = "Firstname,Surname,EmailAddress";
	
	if(IncludedFields.indexOf("Firstname")!=-1)
	{
	   // FistName
	  if (theForm.Firstname.value == "")
	  {
	    alert("Please enter a value for the \"First Name\" field.");
	    theForm.Firstname.focus();
	    return (false);
	  }
	
	  if (theForm.Firstname.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"First Name\" field.");
	    theForm.Firstname.focus();
	    return (false);
	  }
	
	  if (theForm.Firstname.value.length > 25)
	  {
	    alert("Please enter at most 25 characters in the \"First Name\" field.");
	    theForm.Firstname.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("Surname")!=-1)
	{
	// Surname
	  if (theForm.Surname.value == "")
	  {
	    alert("Please enter a value for the \"Surname\" field.");
	    theForm.Surname.focus();
	    return (false);
	  }
	
	  if (theForm.Surname.value.length < 1)
	  {
	    alert("Please enter at least 1 characters in the \"Surname\" field.");
	    theForm.Surname.focus();
	    return (false);
	  }
	
	  if (theForm.Surname.value.length > 25)
	  {
	    alert("Please enter at most 25 characters in the \"Surname\" field.");
	    theForm.Surname.focus();
	    return (false);
	  }
	}
	
	if(IncludedFields.indexOf("EmailAddress")!=-1)
	{ 
	//Email
	  if (theForm.EmailAddress.value == "")
	  {
	    alert("Please enter a value for the \"Email Address\" field.");
	    theForm.EmailAddress.focus();
	    return (false);
	  }
	
	  if (theForm.EmailAddress.value.length < 5)
	  {
	    alert("Please enter at least 5 characters in the \"Email Address\" field.");
	    theForm.EmailAddress.focus();
	    return (false);
	  }
	
	  if (theForm.EmailAddress.value.length > 100)
	  {
	    alert("Please enter at most 100 characters in the \"Email Address\" field.");
	    theForm.EmailAddress.focus();
	    return (false);
	  }
	
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@._";
	  var checkStr = theForm.EmailAddress.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  
	  var i = 1;
	  var sLength = checkStr.length;
	  
	  // look for @
	  while ((i < sLength) && (checkStr.charAt(i) != "@"))
	  { i++;}
	  diff=sLength-i;
	  if(diff<1)
	  {
	     alert("You have not used an \"@\" symbol in your email address.Please use one.")
	     theForm.EmailAddress.focus();
	     return (false);
	  }
	  
	  // look for .
	  i = 1;
	  while ((i < sLength) && (checkStr.charAt(i) != "."))
	  { i++;}
	  diff=sLength-i;
	  if(diff<1)
	  {
	     alert("You have not used an \".\" symbol in your email address.Please use one.")
	     theForm.EmailAddress.focus();
	     return (false);
	  }
	  
	  if (!allValid)
	  {
	    alert("Please enter only letter, digit and \"@._\" characters in the \"Email Address\" field.");
	    theForm.EmailAddress.focus();
	    return (false);
	  }
	  
	  if(theForm.EmailAddress.value != theForm.ConfirmEmailAddress.value)
	  {
		alert("Your email addresses do not match. Please check you have entered them correctly.");
		theForm.ConfirmEmailAddress.focus();
		return false;
	  }
	}
	
	return true;
}

function ValidateBuildingProjectRegistration(theForm)
{
	if(ValidateForm(theForm) == true)
	{
		theForm.btnRegister.disabled = false;
		
		if (theForm.BuildingRolesID.selectedIndex < 0 || theForm.BuildingRolesID.selectedIndex == 0)
		{
			alert("Please select role.");
			theForm.BuildingRolesID.focus();
			return false;
		}
		
		if(theForm.BuildingRolesID.options[theForm.BuildingRolesID.selectedIndex].innerHTML == "Contractor")
		{
			if (theForm.CompanyName.value == "")
			{
				alert("Please enter a value for the \"Company Name\" field.");
				theForm.CompanyName.focus();
				return (false);
			}
			
			var idProjectBuildingContractor = document.getElementById('idProjectBuildingContractor');
			if (idProjectBuildingContractor.selectedIndex < 0 || idProjectBuildingContractor.selectedIndex == 0)
			{
				alert("Please select a contractor.");
				idProjectBuildingContractor.focus();
				return false;
			}
		}
		else if(theForm.BuildingRolesID.options[theForm.BuildingRolesID.selectedIndex].innerHTML == "Employee")
		{
			if (theForm.BuildingContractorID.selectedIndex < 0 || theForm.BuildingContractorID.selectedIndex == 0)
			{
				alert("Please select a contractor.");
				theForm.BuildingContractorID.focus();
				return false;
			}
			
			if (theForm.InductionCode.value == "")
			{
				alert("Please enter a value for the \"Induction Code\" field.");
				theForm.InductionCode.focus();
				return (false);
			}
			
			if (theForm.InductionCode.value.length > 6 || !isCharsInBag(theForm.InductionCode.value,"0123456789"))
			{
				alert("The \"Induction Code\" must be made of numbers and be less than or equal to 6 characters.");
				theForm.InductionCode.focus();
				return (false);
			}
			
			if (theForm.ChildProtectionDeclaration.value == "")
			{
				alert("Please enter a value for the \"Child Protection Declaration\" field.");
				theForm.ChildProtectionDeclaration.focus();
				return (false);
			}
			
			if (theForm.ChildProtectionDeclaration.value.length > 6 || !isCharsInBag(theForm.ChildProtectionDeclaration.value,"0123456789"))
			{
				alert("The \"Child Protection Declaration\" must be made of numbers and be less than or equal to 6 characters.");
				theForm.ChildProtectionDeclaration.focus();
				return (false);
			}
			
			if (theForm.TradeProfession && theForm.TradeProfession.value == "")
			{
				alert("Please enter a value for the \"Trade Profession\" field.");
				theForm.TradeProfession.focus();
				return (false);
			}
			
			if (theForm.Postcode.value == "")
			{
				alert("Please enter a value for the \"Post code\" field.");
				theForm.Postcode.focus();
				return (false);
			}
		}
		
		theForm.btnRegister.disabled = true;

		return true;
	}
	
	return false;
}

function CheckEmptyTag(obj)
{
	if(obj != null && obj.length > 0 && obj[0].hasChildNodes())
		return obj[0].firstChild.nodeValue;
	else
		return "";
}

function ClearYear()
{
	if(dtmYear.value=="Year")
	{
		dtmYear.value="";
	}
}

function isLeapYear(year)
{
	return ((year%4 == 0) && (year%100 != 0 || year%400 == 0));
}

function FormatUsername()
{
	if(typeof(useEmailAsUsername) != 'undefined' && useEmailAsUsername != null && useEmailAsUsername == true)
	{
		//Email
		if (txtUsername.value.length > 0)
		{
			if (txtUsername.value.length < 5)
			{
				alert("Please enter at least 5 characters in the \"Email Address\" field.");
				txtUsername.focus();
				return (false);
			}
			
			if (txtUsername.value.length > 128)
			{
				alert("Please enter at most 128 characters in the \"Email Address\" field.");
				txtUsername.focus();
				return (false);
			}
		
			var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@._";
			var checkStr = txtUsername.value;
			var allValid = true;
			for (i = 0;  i < checkStr.length;  i++)
			{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkOK.length;  j++)
					if (ch == checkOK.charAt(j))
						break;
				if (j == checkOK.length)
				{
					allValid = false;
					break;
				}
			}
			
			var i = 1;
			var sLength = checkStr.length;
			
			// look for @
			while ((i < sLength) && (checkStr.charAt(i) != "@"))
			{ i++;}
			diff=sLength-i;
			if(diff<1)
			{
				alert("You have not used an \"@\" symbol in the \"Email Address\". Please use one.")
				txtUsername.focus();
				return (false);
			}
			
			// look for .
			i = 1;
			while ((i < sLength) && (checkStr.charAt(i) != "."))
			{ i++;}
			diff=sLength-i;
			if(diff<1)
			{
				alert("You have not used an \".\" symbol in the \"Email Address\". Please use one.")
				txtUsername.focus();
				return (false);
			}
			
			if (!allValid)
			{
				alert("Please enter only letter, digit and \"@._\" characters in the \"Email Address\" field.");
				txtUsername.focus();
				return (false);
			}
		}
	}
	else
	{
		txtUsername.value = stripCharsNotInBag(txtUsername.value,lowercaseLetters + uppercaseLetters + digits);
	}
	
	return true;
}

var txtUsername = getElement("txtUsername");
var txtPassword = getElement("txtPassword");
var txtConfirmPassword = getElement("txtConfirmPassword");
if(txtUsername)
	txtUsername.focus();

//LinkEvent("btnRegister","click",ValidateForm);
//LinkEvent("dtmYear","focus",ClearYear);
//LinkEvent("txtUsername","blur",FormatUsername);

