/*
[05/12/2006] - Version 2.0
  1.- Afip.Cuit
  2.- Afip.Descripcion
  3.- Afip.Fecha
  4.- Afip.Year
  5.- Afip.Email
*/
 
function Afip() {
    this.objeto  = null;
    this.valor   = null;    
    this.pattern = null;    
    this.version = "2.0";
 }    
   
Afip.prototype.Cuit = function (parameter) {   
	this.objeto = document.getElementById(parameter);    
	this.valor = trim(this.objeto.value).toString();
    this.pattern = /^[0-9]+$/;
   	    	
	/* Nulo */
	if (this.valor == "")
    {      
        alert("Debe ingresar un valor para la C.U.I.T.");
		this.objeto.select();
		return (false);    
    }		
           
    /* Numerico */
	if(!this.pattern.test(this.valor))
    { 
        alert("El número de la C.U.I.T. debe ser un dato numérico válido."); 
        this.valor = "";
		this.objeto.select();
        return (false);
    }					    	
   
    /* Longuitud */
    if (this.valor.length < 11 || this.valor.length > 11)
    { 
		alert("El número de la C.U.I.T. debe contener como mínimo 11 dígitos."); 		        
        this.valor = "";
		this.objeto.select();
		return (false);
    } 
           	
    return (true);
}
  
Afip.prototype.Descripcion = function (parameter) {   
	this.objeto = document.getElementById(parameter);    	
	this.valor = trim(this.objeto.value).toString();
    this.pattern = /^[a-zA-Z0-9-_\s-,-.]+$/;    
   	
   	/* Nulo */	  	
    if (this.valor == "")
    { 
        alert("Debe ingresar un valor."); 
        this.objeto.focus(); 
        return (false); 
    }		
    
    /* Alfanumerico */
	if(!this.pattern.test(this.valor))
    { 
        alert("El valor ingresado es inválido."); 
        this.objeto.value=""; 
        this.objeto.focus(); 
        return (false); 
    }					    	
    	
    return (true);    
}


Afip.prototype.Fecha = function (parameter) {   
	this.objeto = document.getElementById(parameter);    
	this.valor = trim(this.objeto.value).toString();
    this.pattern = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
    
	/* Nulo */
	if (this.valor == "")
    {      
        alert("Debe ingresar un valor para la fecha.");         
		this.objeto.select();
		return (false);    
    }	

    /* Formato dd/mm/yyyy */
	if(!this.pattern.test(this.valor))
    { 
        alert("El formato de la fecha ingresada es inválido."); 
        this.valor = "";
		this.objeto.select();
        return (false);
    }	   
    				    
    return (true);		  
}


Afip.prototype.Year = function (parameter) {   
	this.objeto = document.getElementById(parameter);    
	this.valor = trim(this.objeto.value).toString();
    this.pattern = /^[0-9]+$/;
    
	/* Nulo */
	if (this.valor == "")
    {      
        alert("Debe ingresar un valor para el año.");         
		this.objeto.select();
		return (false);    
    }	

    /* Numerico */
	if(!this.pattern.test(this.valor))
    { 
        alert("El año debe ser un dato numérico válido."); 
        this.valor = "";
		this.objeto.select();
        return (false);
    }	
    
    /* Longuitud */
    if (this.valor.length < 4)
    { 
		alert("El año debe contener como mínimo 4 dígitos."); 		        
        this.valor = "";
		this.objeto.select();
		return (false);
    } 
        

	/* Mayor a 1900 */
	if (left(this.valor, 2) < "19")
    { 
		alert("El año debe ser mayor a 1900."); 		        
        this.valor = "";
		this.objeto.select();
		return (false);
    } 

    return (true);		  
}


Afip.prototype.Email = function (parameter) {   
	this.objeto = document.getElementById(parameter);    
	this.valor = trim(this.objeto.value).toString();
    this.pattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    
	/* Nulo */
	if (this.valor == "")
    {      
        alert("Debe ingresar un valor para el email.");         
		this.objeto.select();
		return (false);    
    }	

    /* Alfanumerico */
	if(!this.pattern.test(this.valor))
    { 
        alert("El email ingresado es inválido."); 
        this.valor = "";
		this.objeto.select();
        return (false);
    }	
        
    return (true);		  
}
