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

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

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

	this.dataType = d.dataType;
	
	this.precision = new ParserStyle(d.extStyle).items(extStyles.precision);
	if (this.precision == undefined) this.precision = 12;
	
	this.scale = new ParserStyle(d.extStyle).items(extStyles.scale);
	if (this.scale == undefined) this.scale = 2;
	
	this.onValidate = d.onValidate;
	this.beforeValidate = d.beforeValidate;
	this.afterValidate = d.afterValidate;
	
	this.getRegExp = getNumericRegExp;
	this.doCheck = doCheckNumeric;
}

function getNumericRegExp()
{
	var s = '[+|-]{0,1}[\\d]{0,' + this.precision + '}';
	if (this.scale > 0)
	{
		s = s + '(\\.[\\d]{1,' + this.scale + '}|)';
	}
	return new RegExp(s);
}

function doCheckNumeric()
{
	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.dtNumeric;