SwxFormsNotEmptyValidator = SxCore.Class.create();
SxCore.Class.extend( SwxFormsNotEmptyValidator.prototype, {
	initialize: function(strValue)
	{
		this.m_strValue = String(strValue);
		this.m_strError = "";
		this.m_oDictionary = Swx.FrontEndLang.getModuleDictionary(SwxFormsNotEmptyValidator.GUID);
	},
	getPhrase: function(strName)
	{
		if ( !this.m_oDictionary )
			return "";
		return this.m_oDictionary.validationmsg[strName];
	},
	isEmpty: function()
	{
		return !this.m_strValue.length;
	},
	validate: function()
	{
		if ( this.isEmpty() )
		{
			this.m_strError = this.getPhrase("NotEmpty");
			return false;
		}

		return this.m_strValue;
	},
	getError: function()
	{
		return this.m_strError;
	}
});

SwxFormsEmailValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsEmailValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsEmailValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^[a-zA-Z][_a-zA-Z0-9]*\@[a-zA-Z][_a-zA-Z0-9\-]*(\.[a-zA-Z]{2,3}(\.[a-zA-Z]{1,2})?)$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("NotEmail");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsSingleWordValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsSingleWordValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsSingleWordValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^[_a-zA-Z][_a-zA-Z'\-]*([_a-zA-Z'\-]( )*)$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("NotSingleWord");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsMultipleWordValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsMultipleWordValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsMultipleWordValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^[_a-zA-Z][ _a-zA-Z'\-]*[_a-zA-Z'\-]$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("NotMultipleWord");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsAlphanumericStartWithLetterValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsAlphanumericStartWithLetterValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsAlphanumericStartWithLetterValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^[_a-zA-Z][ _a-zA-Z0-9\-\+]*[_a-zA-Z0-9\-\+]$/.test( this.m_strValue ) )
			return false;

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsAlphanumericValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsAlphanumericValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsAlphanumericValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^[_a-zA-Z0-9\-\+][ _a-zA-Z0-9\-\+]*[_a-zA-Z0-9\-\+]$/.test( this.m_strValue ) )
			return false;

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsNumericValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsNumericValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsNumericValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^((\-)?[0-9])([0-9]*(\.[0-9]*)?)$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("NotNumeric");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsZipCodeValidator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsZipCodeValidator.prototype, {
	validate: function()
	{
		if ( !SwxFormsZipCodeValidator.superClass.validate.call(this) )
			return false;
		if ( ! /^[0-9]([0-9]{4}(\-[0-9]{4})?)$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("NotZipCode");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsPassword312Validator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsPassword312Validator.prototype, {
	validate: function()
	{
		if ( ! /^[ a-zA-Z0-9_\-][ a-zA-Z0-9_\-]{2,11}$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("Not312Password");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

SwxFormsPassword812Validator = SxCore.Class.inherit(SwxFormsNotEmptyValidator);
SxCore.Class.extend( SwxFormsPassword812Validator.prototype, {
	validate: function()
	{
		if ( ! /^[ a-zA-Z0-9_\-][ a-zA-Z0-9_\-]{7,11}$/.test( this.m_strValue ) )
		{
			this.m_strError = this.getPhrase("Not812Password");
			return false;
		}

		// TODO:
		// Trim the string.
		return this.m_strValue;
	}
});

var g_oSwxFormsModuleValidators = [
	"SwxFormsNotEmptyValidator",
	"SwxFormsEmailValidator",
	"SwxFormsSingleWordValidator",
	"SwxFormsMultipleWordValidator",
	"SwxFormsAlphanumericStartWithLetterValidator",
	"SwxFormsAlphanumericValidator",
	"SwxFormsNumericValidator",
	"SwxFormsZipCodeValidator",
	"SwxFormsPassword312Validator",
	"SwxFormsPassword812Validator" ];

var g_oSwxFormsModuleError = "";

function swxFormsModule_Validate(nType, strValue)
{
	if ( nType<0 || nType>=g_oSwxFormsModuleValidators.length )
		return false;

	eval("var oValidator = new " + g_oSwxFormsModuleValidators[nType] + "()" );
	if ( !oValidator )
		return false;

	oValidator.m_strValue = strValue;
	var bResult = oValidator.validate();
	g_oSwxFormsModuleError = oValidator.getError();

	return bResult !== false;
}

function swxFormsModule_GetError()
{
	return g_oSwxFormsModuleError;
}

