/* Last Modified: 10/27/99 9:30am - mft */

/* ============================================================= */

var blnDebugEmail = false;

/* ============================================================= */

//Purpose: Check if a string is all alpha-numeric (or has "." or "_")
//Input: rstrTest: Any string
//Output: false if not alpha-numeric-email, true if it is alpha-numeric-email

function isAlphaNumEmail(rstrTest, rintType) {
	var blnValid = true;

	for (i = 0; i < rstrTest.length; i++) {
		if (blnDebugEmail) {
			alert(rstrTest.charAt(i));
		}
		if (!(((rstrTest.charAt(i) >= "a") && (rstrTest.charAt(i) <= "z")) || ((rstrTest.charAt(i) >= "A") && (rstrTest.charAt(i) <= "Z")) || ((rstrTest.charAt(i) >= 0) && (rstrTest.charAt(i) <= 9)) || (rstrTest.charAt(i) == ".") || (rstrTest.charAt(i) == "_") || (rstrTest.charAt(i) == "-"))) {
			if (!((rintType == 1) && (rstrTest.charAt(i) == "%"))) {
				blnValid = false;
			}
		}
	}

	if (blnDebugEmail) {
		if (blnValid) { alert("It is valid."); }
		else { alert("It is NOT valid."); }
	}
	return blnValid;
}

/* ============================================================= */

//Purpose: Check if a string is a valid email address
//Input: robjField: Any string
//Output: false if not a valid email address, true if it is a valid email address

function isValidEmail(robjField) {
	var blnValid = true;
	robjField.value += "";

	strName = robjField.value.substring(0, robjField.value.indexOf("@"));
	strDomain = robjField.value.substring(robjField.value.indexOf("@")+1, robjField.value.length);
	strDName = strDomain.substring(0, strDomain.indexOf("."));
	strDType = strDomain.substring(strDomain.indexOf(".")+1, strDomain.length);

	if (blnDebugEmail) {
		alert("Name: '" + strName + "'");
		alert("DName: '" + strDName + "'");
		alert("DType: '" + strDType + "'");
	}

	/* Check if the email address has all 3 parts */
	if ((strName.length < 1) || (strDName.length < 1) || (strDType.length < 1))
		{ blnValid = false; }

	/* Check if the 3 parts are all alpha-numeric (plus "." or "_" as well) */
	if ((!isAlphaNumEmail(strName,1)) || (!isAlphaNumEmail(strDName,2)) || (!isAlphaNumEmail(strDType,3)))
		{ blnValid = false; }

	if (blnValid) {
	   	return blnValid;
	} else {
		alert("Not a valid email address");
		robjField.focus();
	   	return blnValid;
	}
}

/* ============================================================= */
