
function clsValidator() 
{

	this.msgError="";		
	this.errorColor="";			
	this.error = false;			
	
	
	///////////////////////////////////////////////////////////
	function setEncabezado(head)	
	{
		this.head = head;
	}
	///////////////////////////////////////////////////////////

	function AgregarError() {
		this.error=true;
		this.msgError += "* "+arguments[0]+"\n";
		for (var i=1; i < arguments.length ; i++) 
		{
			document.getElementById(arguments[i]).style.backgroundColor=this.errorColor;
		}
	}
	///////////////////////////////////////////////////////////
	
	/*function EliminarError()
	{
		for (var i=0; i < arguments.length ; i++) 
		{
			document.all[arguments[i]].style.backgroundColor="";
		}
	}*/
	///////////////////////////////////////////////////////////
	
	function setErrorColor(color)
	{
		this.errorColor = color;
	}

	///////////////////////////////////////////////////////////
	
	function Vacio(field,msg) 
	{
		//this.EliminarError(field);
		if(document.getElementById(field)!=null)
		{
		if (document.getElementById(field).value.replace(/ /g, '') == "")
		{
			this.AgregarError(msg, field);
			document.getElementById(field).focus()
			return false
		}
		}
		return true
	}
	///////////////////////////////////////////////////////////
	
	function Email(field,msg) 
	{
		//this.EliminarError(field);
		var re  = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		if (!re.test(document.getElementById(field).value)) {
			this.AgregarError(msg, field);
			document.getElementById(field).focus()
			return false
		}
		return true
	}
	///////////////////////////////////////////////////////////
	
	function Fecha(day, month, year) 
	{
	
		this.EliminarError(field);
		var datePat = /^([0-9]{2})\/([0-9]{2})\/([0-9]{4})?$/;
		//var matchArray = document.getElementById(field).value.match(datePat);
		var ok = true;
		var bisisesto;

		/*if (matchArray == null) ok = false;
		else 
		{*/
			/*day = matchArray[1];
			month = matchArray[2];
			year = matchArray[3];*/

			if ((day < 1  || day > 31) || (month < 1 || month > 12) || (year < 1)) ok = false;
			if ((month ==2 || month == 4 || month == 6 || month ==9 || month ==11) && (day > 30)) ok = false;
			//if (month == 2) 
			//{
				bisiesto = (parseInt (year/4))*4
				if ((year != bisiesto) && (day > 28)) ok = false;
				if ((year == bisiesto) && (day > 29)) ok = false;
			//}
		//}
		if (ok) return true
		else
		{
			this.AgregarError(msg, field);
			return false;		
		}
	}
	///////////////////////////////////////////////////////////

	function Iguales(field1, field2, msg)
	{
		//this.EliminarError(field1,field2);
		if(document.getElementById(field1).value != document.getElementById(field2).value)
		{
			this.AgregarError(msg, field1, field2);
			return false
		}
		return true	
	}
	///////////////////////////////////////////////////////////
	
	function Longitud(field, operator, length, msg)
	{

		//this.EliminarError(field);
		if (operator == "=") operator = "==";
		if ( !(eval("document.getElementById(field).value.length "+operator+" length")) )
		{
			this.AgregarError(msg, field);
			return false
		}
		return true
	}
	///////////////////////////////////////////////////////////
	
	function Cantidad(field, operator, valor, msg)
	{

		this.EliminarError(field);
		if (operator == "=") operator = "==";
		if (eval("document.getElementById(field).value "+operator+" valor") )
		{
			this.AgregarError(msg, field);
			return false
		}
		return true
	}

	///////////////////////////////////////////////////////////
	function EsEntero(field,msg) 
	{
		//this.EliminarError(field);
		var cadena="";
		if(document.getElementById(field)!=null)
		{
		cadena = document.getElementById(field).value;
		
			if (isNaN(cadena))
			{
			  this.AgregarError(msg, field);
			  return false
			}
			else
			{
			     if(cadena.indexOf(",") >= 0 || cadena.indexOf(".") >= 0)
		         {
		            this.AgregarError(msg, field);
			        return false
		         }
			}
		}
		return true
	}
	
	///////////////////////////////////////////////////////////
	function EsDecimal(field,msg) 
	{
		//this.EliminarError(field);
		
		if(document.getElementById(field)!=null)
		
		if (isNaN(document.getElementById(field).value))
		{
			this.AgregarError(msg, field);
			return false
		}
		return true
	}
	///////////////////////////////////////////////////////////
	function Validar() 
	{
		return !this.error;
	}
	///////////////////////////////////////////////////////////

	function getErrors() 
	{	
		alert(this.head+"\n\n"+this.msgError);
	}
	///////////////////////////////////////////////////////////
    function Errores()
    {
        return this.msgError;
    }
    
	this.setEncabezado = setEncabezado;
	this.setErrorColor = setErrorColor;
	this.getErrors = getErrors;
	this.AgregarError = AgregarError;
	//this.EliminarError = EliminarError;
	this.Vacio = Vacio;
	this.Email = Email;
	this.Fecha = Fecha;
	this.Iguales = Iguales;
	this.Longitud = Longitud;
	this.Validar = Validar;
	this.Cantidad = Cantidad;
	this.EsEntero = EsEntero;
	this.EsDecimal = EsDecimal;
	this.Errores = Errores;
	
}
//////////////////////////////////////////////////////////////////

