//	File:		ValidateDetails.js
//	Purpose:	Validates personal details in MyAccount
//	Written:	12/12/01 - James Strath
//	Notes:		The email validation should remain as strict as the
//              regular expression in ApplicationConfig.

function ValidatePersonName(pstrName)
{
	// checks that a person's name follows conforms to this pattern:
	// has length and does not begin with a blank space
	// is made up of letters (can include hyphen and apostrophe)
	var bValid = true;
	if(pstrName.length == 0) return false;
	var posChar = pstrName.charAt(0);
	if(posChar == ' ' || posChar == '\t') return false;
	var strValidChars = "abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ-'";
	for (var i = 0; i < pstrName.length; i++)
	{
		posChar = pstrName.charAt(i);
		for (j = 0; j < strValidChars.length; j++)
		{				
			if (posChar == ' ')
			{
				break;
			}
			if (posChar == strValidChars.charAt(j))
			{
				break;
			}
		}
		if (j == strValidChars.length)
		{
			bValid = false;
			break;
		}							
	}						
	if (bValid == false)
	{			
		return false;
	}
	else
	{
	return true;
	}					
}

function ValidateEMail1(pstrEmail)
{
	// checks that the email address conforms to this pattern:
	// address string must be at least six characters long
	// an @ character must be preceded by at least one character
	// a . character must appear at least 1 character after the @ character
	// and at least 2 characters before the end of the string
	var bValid = true;
	var strValidLetters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
	var strLength = pstrEmail.length;
	if(strLength < 6)
		return false;
	//check @ pos
	var posAt = pstrEmail.indexOf('@');
	if(posAt < 1)
		return false;
	//check prefix
	var charBeforeAt = pstrEmail.charAt(posAt-1);
	for (intTextCount = 0; intTextCount < strValidLetters.length; intTextCount++)
	{
		if (charBeforeAt == strValidLetters.charAt(intTextCount))
			break;
		if ((intTextCount+1) == strValidLetters.length)
		{					
			bValid = false;
			break;
		}
	}
	if(bValid == false)
		return false;
	//check suffix
	var strSuffix = pstrEmail.substring(posAt,strLength);
	var posDot = strSuffix.indexOf('.');
	if(posDot < 3)
		return false;
	var posDot = strSuffix.lastIndexOf('.');
	if ((strSuffix.length - posDot) < 3)
		return false;

	//passed all tests					
	return true;				
}
