
  function ClassValidacao(){
     this.campos = document.getElementsByTagName("input");
	  //for(i=0;i<this.campos.length;i++){this.campos[i].tabindex=i}
     c=this
     for(i=0;i<this.campos.length;i++){
	     this.campos[i].tabindex=i;
        this.campos[i].onclick=function(){this.select();}
        this.campos[i].onkeydown = function(e){
           //debug('');
			  //showProps(this);
		  	  ascii=(document.all)?event.keyCode:e.keyCode;
			  if (this.mask){
			     if (c.verificaTecla(ascii)==false){
				     this.onkeypress=function(){return false;}
					  return false;
  		        }else{
				     this.onkeypress=function(){return true;}
				     if(c.valida(this,ascii)){
                    if (ascii == 13 || ascii == 40)c.nextfoco(this);
                    if (ascii == 38)c.prevfoco(this);
					  }
				  }
			  }else{
              if (ascii == 13 || ascii == 40)c.nextfoco(this);
              if (ascii == 38)c.prevfoco(this);
			  }
		  }
	  }
    //this.campos[0].focus();

	  return false;
  }
  ClassValidacao.prototype.verificaTecla = function(ascii){
	  //if ((ascii < 48 || ascii > 58) && (ascii < 96 || ascii > 105) && ascii!=8 && ascii!=46 && ascii!=13 && ascii!=38 && ascii!=40){return false} else {return true};     
	  if ((ascii >= 48 && ascii <= 58) || (ascii >= 96 && ascii <= 105) || ascii==8 || ascii==13 || ascii==35 || ascii==38 || ascii==40 || ascii==46 || ascii==123 || ascii==9){return true} else {return false};     
  }
  ClassValidacao.prototype.nextfoco = function(obj){
     if (obj.tabindex < this.campos.length-1)this.campos[(obj.tabindex + 1)].focus();
  }
  ClassValidacao.prototype.prevfoco = function(obj){
     if (obj.tabindex > 0)this.campos[(obj.tabindex - 1)].focus();
  }
  
  ClassValidacao.prototype.valida = function(obj,ascii){
      //alert(ascii)  											 
      if(ascii == 123)getCalend(obj.name);
		obj.maxLength=obj.mask.length;
		/*
		if (this.verificaTecla(ascii)==false){
			obj.onkeypress=function(){return false;}
			obj.onkeyup=function(){return false;}
			return false;
		}
		*/
		carac = obj.mask.split("");
		cnt=0;
		cnt2=0;
		cnt3=0;
		block=Array();

		for (i=0;i<carac.length;i++){
			cnt++;
			if (carac[i]!=9){
				block[cnt2]=Array();
				block[cnt2][0]=(cnt-1)+cnt3;
				block[cnt2][1]=carac[i];
				cnt3 = block[cnt2][0]+1;
				cnt=0;
				cnt2++
			}
		}

		if (obj.mask=="99/99/9999"){
		   for (i=0;i<block.length;i++){
			   if (obj.value.length==block[i][0] && ascii!=8 && ascii!=46){
				   obj.value=obj.value + block[i][1];
			   }
		   }
		}else{

//		   for (i=0;i<block.length;i++){
		   for (i=block.length-1;i>=0;i--){
			   if (obj.value.length==block[i][0] && ascii!=8 && ascii!=46){
				   obj.value=obj.value + block[i][1];
			   }
		   }
		}

		if (ascii==13 && obj.funcao!="")eval(obj.funcao);
		if (obj.value.length==obj.mask.length || obj.mask!="99/99/9999")return true;
		return false;
  }

   //ClassValidacao = new ClassSetFocus();

