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",
	"SwxFormsCodeCaptchaValidator" 
	 ];

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;
}

/*========================================
 * LIMIT LINE
 * Modify by: Mario Sánchez
 */

function reloadCaptchaImage(oInputID, src){
	img = document.getElementById(oInputID); 	
	img.src = src; 			
}
				
//Gets the browser specific XmlHttpRequest Object 
function getXmlHttpRequestObject() {
	 if (window.XMLHttpRequest) {
	    return new XMLHttpRequest(); //Mozilla, Safari ...
	 } else if (window.ActiveXObject) {
	    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	 } else {
	    //Display our error message
	    alert("Your browser doesn\'t support the XmlHttpRequest object.");
	 }
}

function isCodeValid(oID, url, codLang){
	
	var oObject = document.getElementById("f_"+oID);
	var oContentMessage = document.getElementById("df_" + oID);
	var oValue = oObject.value;
	var strUrl = url + "source/verify_captcha.php";
	oLang = {"es":"Código Inválido","en":"Invalid Code"};
	
	
	oObject.style.backgroundColor = "#fff";
	var receiveReq = getXmlHttpRequestObject();
		receiveReq.open("POST", strUrl, false);
	   	/*receiveReq.onreadystatechange = function(){};*/
	   	
   		receiveReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');										
   		receiveReq.send("strCode=" + oValue);
   		var result = 0;
   		if (receiveReq.readyState == 4 && receiveReq.status == 200) {
			result = receiveReq.responseText;
		}
		
		if(result==0){
			oObject.style.backgroundColor = "#FF6666";			
			oContentMessage.innerHTML = oLang[codLang] + "<br><br>";

		}else{
			oObject.style.backgroundColor = "none";			
		}
				
		return result;
}






