// The VerifyUserName JavaScript function can be used to perform client-side 
// validation of a User Name. The function accepts Two (2) input parameters
//  - strUserNameDesc, txtUserNameObj. 
// 
// The strUserNameDesc parameter is the English description of the form 
// text username object (i.e. Your User Name). The txtUserNameObj parameter 
// is the form text UserName object (i.e. txtUserName).

// The function will return "true" when there are no errors and it will 
// return "false" when errors exist.  Additionally, the function will 
// display an "alert" as well as set focus to the form text
// e-mail object when errors exist.

//   Code Example: VerifyUserName("Account User Name", document.frmProtocol.txtUserName1)

function VerifyUserName(strUserNameDesc, txtUserNameObj) {
	var Reason  	 = strUserNameDesc + ' was entered incorrectly.  Please correct the following error(s):\n';
	var checkStr 	 = txtUserNameObj.value;
	var RC       	 = true;
	var InValidChars = 0;
	for (i = 0;  i < checkStr.length;  i++) {
		if (checkStr.charAt(i) == '@')
			InValidChars++;
		else if (checkStr.charAt(i) == ' ')
			InValidChars++;
		else if (checkStr.charAt(i) == ',')
			InValidChars++;
		else if (checkStr.charAt(i) == ':')
			InValidChars++;
		else if (checkStr.charAt(i) == ';')
			InValidChars++;
		else if (checkStr.charAt(i) == '/')
			InValidChars++;
		else if (checkStr.charAt(i) == '*')
			InValidChars++;
		else if (checkStr.charAt(i) == '?')
			InValidChars++;
		else if (checkStr.charAt(i) == '"')
			InValidChars++;
		else if (checkStr.charAt(i) == '>')
			InValidChars++;
		else if (checkStr.charAt(i) == '<')
			InValidChars++;
		else if (checkStr.charAt(i) == '|')
			InValidChars++;
		else if (checkStr.charAt(i) == '{')
			InValidChars++;
		else if (checkStr.charAt(i) == '}')
			InValidChars++;
		else if (checkStr.charAt(i) == '[')
			InValidChars++;
		else if (checkStr.charAt(i) == ']')
			InValidChars++;
		else if (checkStr.charAt(i) == '!')
			InValidChars++;
		else if (checkStr.charAt(i) == '#')
			InValidChars++;
		else if (checkStr.charAt(i) == '$')
			InValidChars++;
		else if (checkStr.charAt(i) == '%')
			InValidChars++;
		else if (checkStr.charAt(i) == '^')
			InValidChars++;
		else if (checkStr.charAt(i) == '&')
			InValidChars++;
		else if (checkStr.charAt(i) == '(')
			InValidChars++;
		else if (checkStr.charAt(i) == ')')
			InValidChars++;
		else if (checkStr.charAt(i) == '~')
			InValidChars++;
		else if (checkStr.charAt(i) == '`')
			InValidChars++;
		else if (checkStr.charAt(i) == '=')
			InValidChars++;
		else if (checkStr.charAt(i) == '+')
			InValidChars++;
		else if (checkStr.charAt(i) == '\'')			
			InValidChars++;
	}

	RL = Reason.length;
	
	if (InValidChars != 0)
		Reason += '\nYour User Name Contains Invalid Characters.\nPlease Limit Your User Name to Numbers (0-9), Letters (A-Z), and Under Scores(_).\n \n Example User Names Include (John_Doe01, Joanne2, Lisa_Smith4, etc.)';

	if (RL != Reason.length) {
		alert(Reason);
		txtUserNameObj.focus();
		txtUserNameObj.select();
		RC = false;
	}
	else
		RC = true;
	return(RC);
}

