/* $Id: ParserEMail.js,v 1.1 2004/08/24 15:08:07 jane Exp $ */

function EMailParser(d, value, e)
{
	if ((typeof(d) != 'object') || (d.constructor != ElementDescriptor))
	{
		throw ('EMailParser:\n' + 'DefMsgErrInvalidDescriptor');
	}
	if (d.dataType != valueTypes.dtEMail)
	{
		throw ('EMailParser:\n' + DefMsgErrDataTypeUnsupported + '\n' + d.dataType);
	}

	this.descriptor = d;
	this.value = value;
	this.element = e;

	this.dataType = d.dataType;

	this.onValidate = d.onValidate;
	this.beforeValidate = d.beforeValidate;
	this.afterValidate = d.afterValidate;
	
	this.getRegExp = getEMailRegExp;
	this.doCheck = doCheckEMail;
}

function getEMailRegExp()
{
	return new RegExp('[\\S]{1,}[\\@]{1}[\\S]{1,}[\\.]{1}[\\S]{1,}');
}

function doCheckEMail()
{
	var result = parserResults.Incorrect;
	if (this.beforeValidate) eval(this.beforeValidate);
	if (checkExp(this.value, this.getRegExp())) result = parserResults.Correct;
	if ((result == parserResults.Correct) && (this.onValidate)) eval(this.onValidate);
	if (this.afterValidate) eval(this.afterValidate);
	return result;
}

vSupportedDT[vSupportedDT.length] = valueTypes.dtEMail;
