function Validator(theForm)
{

	var strName = new String;
	
	// Validate the User Name field
	if (theForm.username.value == "")
		{
			alert("Please enter your desired User Name");
			theForm.username.focus();
			return (false);
		}

	if (theForm.username.value.length > 15)
		{
			alert("User Name is limited to a maximum length of 15");
			theForm.username.focus();
			return (false);
		}

	// Validate the Password field
	if (theForm.password.value == "")
		{
			alert("Please enter your assigned Patient Code");
			theForm.password.focus();
			return (false);
		}
	else
		{
			if (theForm.password.value.length < 4)
				{
					alert("A minimum length of 4 is required for your Patient Code");
					theForm.password.focus();
					return (false);
				}
		}
		

	if (isSpecVars(theForm.password.value) == false)
		{
			alert("Special Characters and Spaces are not allowed in the Patient Code field");
			theForm.password.focus();
			return (false);
		}
		
		
	// Validate the Verify Password field
	if (theForm.verify_password.value == "")
		{
			alert("Please Verify your Patient Code entered");
			theForm.verify_password.focus();
			return (false);
		}
	else
		{
			if (theForm.verify_password.value != theForm.password.value)
				{
					alert("The Patient Code and Verify Patient Code you entered did not match");
					theForm.verify_password.focus();
					return (false);
				}
		}

	// Validate the First Name field
	if (theForm.firstname.value == "")
		{
			alert("Please enter your First Name");
			theForm.firstname.focus();
			return (false);
		}
		
	// Validate the Last Name field
	if (theForm.lastname.value == "")
		{
			alert("Please enter your Last Name");
			theForm.lastname.focus();
			return (false);
		}
		
	// Validate the EMail Address field
	if (theForm.EmailAddress.value == "")
		{
			alert("Please a valid EMail Address");
			theForm.EmailAddress.focus();
			return (false);
		}
	else
		{
			if (isValidEmail(theForm.EmailAddress.value) == false)
				{
					alert("Please enter a valid EMail Address");
					theForm.EmailAddress.focus();
					return (false);
				}
		}

		
	// Validate the Address field
	if (theForm.Address.value == "")
		{
			alert("Please enter your Street Address");
			theForm.Address.focus();
			return (false);
		}
		
	// Validate the City field
	if (theForm.City.value == "")
		{
			alert("Please enter the name of your City");
			theForm.City.focus();
			return (false);
		}
	
	// Validate the State field
	if (theForm.State.value == "")
		{
			alert("Please enter the name of your State");
			theForm.State.focus();
			return (false);
		}

	if (theForm.PostalCodePlus.value.length > 0) 
		{
			if (theForm.PostalCodePlus.value.length != 4)
				{
					alert("Zipcode Plus must be 4-digits.");
					theForm.PostalCodePlus.focus();
					return (false);
				}
		}
		
	if (isNumeric(theForm.PostalCodePlus.value) == false)
		{
			alert("Numbers only allowed in Zipcode Plus.");
			theForm.PostalCodePlus.focus();
			return (false);
		}

	// Validate the Country field
	if (theForm.Country.value == "")
		{
			alert("Please enter your Country");
			theForm.Country.focus();
			return (false);
		}
	
	if (theForm.Country.value.length > 0)
		{
		var ucStr = new String;
		ucStr = theForm.Country.value.toUpperCase();
			if (ucStr == "USA" || ucStr == "US" || ucStr == "CANADA")
				{
					if (theForm.postalcode.value == "")
						{
							alert("You must enter your Postal Code");
							theForm.postalcode.focus();
							return (false);
						}
				}
		}
		
		
	if (theForm.Phone.value == "")
		{
			alert("Please enter your Phone Number");
			theForm.Phone.focus();
			return (false);
		}

	if (theForm.AddressType.options[0].selected)
		{
			alert("Please make a valid Address Type selection");
			theForm.AddressType.focus();
			return (false);
		}
	
	if (theForm.PhoneType.options[0].selected)
		{
			alert("Please make a valid Phone Type selection");
			theForm.PhoneType.focus();
			return (false);
		}

	return (true);
}


///////////////////////////////////////////////////////
// Function to check for a valid email address entered.
function isValidEmail(str) {
   return (str.indexOf("@") > 0);
//   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}


///////////////////////////////////////////////////////
// Function to check string for special vars.
function isSpecVars(str)
{
var iChars = "!@#$%^&*()-+=[]\\\';,./{}|\":<>? ";
  for (var i = 0; i < str.length; i++) {
  	if (iChars.indexOf(str.charAt(i)) != -1) {
  	return false;
  	}
  }
  
  return true;
}

///////////////////////////////////////////////////////
// Function to check string for special vars.
function isNumeric(str)
{
var iChars = "0123456789";
  for (var i = 0; i < str.length; i++) {
  	if (iChars.indexOf(str.charAt(i)) == -1) {
  	return false;
  	}
  }
  
  return true;
}
