/*
 * psudoclase para validar formulario atravez de expreciones
 * regulares
 * JFcoDiaz
 * wariodiaz@gmail.com
* @fcoDiaz
*
 **/

function obj(id){
      return (document.getElementById(id))?document.getElementById(id):undefined;
   }

function validator(){
    this.objetos=new Array();
    this.add = function(IdObj,strPropiedad,strMensajeError,filtro){
        if(obj(IdObj)==undefined){
            alert(IdObj+" No Existe");
        }
        this.objetos[this.objetos.length]={
            'obj':obj(IdObj),
            'propiedad':strPropiedad,
            'mensaje':strMensajeError,
            'filtro':filtro
        }
    }
    this.onError=function(obj){
        alert(obj.mensaje);
    }
    this.onOk=function(){};
    this.test = function(){
        for(var i in this.objetos){
            var otem=this.objetos[i]
            if(!otem.filtro.test(otem.obj[otem.propiedad])){
                this.onError(otem);
                try{
                    otem.obj.focus();
                }catch(e){}
                return false;
            }
        }
        this.onOk();
        return true;
    }
} 