/*
Validates email addresses. Usage:

		if (bademail(obj, 'FieldNameHere')){
			return false;
		}
*/

function bademail(obj, objname) {
	var i,strLen,atPos1,atPos2,periodPos1,periodPos2,strEnd2,strEnd3,testChar;
	//var illegalChars = ", *()<>;:\'\";
	var illegalChars = ", *()<>;:\'\"";
	trimall(obj);
	strLen = obj.value.length;
	atPos1 = obj.value.indexOf("@");
	if (atPos1 == -1) {
		alert(objname + " is missing the \'@\' character");
		obj.focus();
		return true;
	}
	if (atPos1 == 0) {
		alert(objname + " may not have \'@\' as the first character");
		obj.focus();
		return true;
	}
	if (atPos1 == strLen-1) {
		alert(objname + " may not have \'@\' as the last character");
		obj.focus();
		return true;
	}
	atPos2 = obj.value.indexOf("@",atPos1+1);
	if (atPos2 !=-1) {
		alert(objname + " may not have more than one \'@\' character");
		obj.focus();
		return true;
	}
	periodPos1 = obj.value.indexOf(".");
	if (periodPos1 == -1) {
		alert(objname + " must contain a \'.\' character");
		obj.focus();
		return true;
	}
 	if (periodPos1 == strLen-1) {
		alert(objname + " may not have \'.\' as the last character");
		obj.focus();
		return true;
	}
	if (periodPos1 == 0) {
		alert(objname + " may not have \'.\' as the first character");
		obj.focus();
		return true;
	}
	periodPos2 = obj.value.indexOf(".",atPos1+1);
	if (periodPos2 == atPos1+1) {
		alert(objname + " must have characters between \'@\' and \'.\'");
		obj.focus();
		return true;
	}
	for (i=0; i < illegalChars.length; i++) {
		if (obj.value.indexOf(illegalChars.charAt(i)) != -1) {
			alert(objname + " may not contain a \'" + illegalChars.charAt(i) + "\'");
			obj.focus();
			return true;
		}
	}
	return false;
}