function OnlyNumbers(e) {
   var key;
   var keychar;
   var reg;

   if(window.event) {
      // for IE, e.keyCode or window.event.keyCode can be used
      key = e.keyCode; 
   }
   else if(e.which) {
	   // netscape
	   key = e.which; 
   }
   else {
	   // no event, so pass through
	   return true;
   }

   //tecla 8=tab
   //9 = enter???
   if(key==8) { 
      return 8; 
   }

   keychar = String.fromCharCode(key);
   reg = /\d/;
   return reg.test(keychar);
}

function Numbers2(e) {
   var key;
   var keychar;
   var reg;

   if(window.event) {
      // for IE, e.keyCode or window.event.keyCode can be used
      key = e.keyCode; 
   }
   else if(e.which) {
	   // netscape
	   key = e.which; 
   }
   else {
	   // no event, so pass through
	   return true;
   }

   //tecla 8=tab
   //9 = enter???
   if(key==8) { 
      return 8;
   }
   if(key==44) { 
      return 44;
   }

   keychar = String.fromCharCode(key);
   reg = /\d/;

   return reg.test(keychar);
}

function mascaraCPF(cpf,e) {
   var mycpf = '';
   tecla = OnlyNumbers(e);

   if (tecla==8) {
      return true;
   }
   if (tecla) {
      mycpf = mycpf + cpf.value;
      if (mycpf.length == 3) {
         mycpf = mycpf + '.';
         cpf.value = mycpf; }
      if (mycpf.length == 7) {
         mycpf = mycpf + '.';
         cpf.value = mycpf; }
      if (mycpf.length == 11) {
         mycpf = mycpf + '-';
         cpf.value = mycpf; }
      //if (mycpf.length == 14) { }
   }
   else {
      return false;
   }
}

function mascaraCNPJ(cnpj,e){
   var mycnpj = '';
   tecla = OnlyNumbers(e);

   if (tecla==8) {
      return true;
   }
   if (tecla) {
      mycnpj = mycnpj + cnpj.value;
      if (mycnpj.length == 2) {
         mycnpj = mycnpj + '.';
         cnpj.value = mycnpj; }
      if (mycnpj.length == 6) {
         mycnpj = mycnpj + '.';
         cnpj.value = mycnpj; }
      if (mycnpj.length == 10) {
         mycnpj = mycnpj + '/';
         cnpj.value = mycnpj; }
      if (mycnpj.length == 15) {
         mycnpj = mycnpj + '-';
         cnpj.value = mycnpj; }
      //if (mycnpj.length == 18) { }
   }
   else {
      return false;
   }
}

function mascaraCEP(cep,e){
   var mycep = '';
   tecla = OnlyNumbers(e);

   if (tecla==8) {
      return true;
   }
   if (tecla) {
      mycep = mycep + cep.value;
      if (mycep.length == 5) {
         mycep = mycep + '-';
         cep.value = mycep; }
      //if (mycep.length == 9) { }
   }
   else {
      return false;
   }
}

//function mascaraCPF(cpf,teclapres) {
//    var tecla = teclapres.keyCode;
//    var mycpf = '';
//    if (tecla >= 48 && tecla <= 57) {
//        if (tecla != 9 && tecla != 8){
//            mycpf = mycpf + cpf.value;
//            if (mycpf.length == 3) {
//                mycpf = mycpf + '.';
//                cpf.value = mycpf; }
//            if (mycpf.length == 7) {
//                mycpf = mycpf + '.';
//                cpf.value = mycpf; }
//            if (mycpf.length == 11) {
//                mycpf = mycpf + '-';
//                cpf.value = mycpf; }
//            if (mycpf.length == 14) { }
//        }
//    }
//    else {return false;}
//}
//function mascaraCNPJ(cnpj,teclapres){
//    var tecla = teclapres.keyCode;
//    var mycnpj = '';
//    if (tecla >= 48 && tecla <= 57) {
//        if (tecla != 9 && tecla != 8){
//            mycnpj = mycnpj + cnpj.value;
//            if (mycnpj.length == 2) {
//                mycnpj = mycnpj + '.';
//                cnpj.value = mycnpj; }
//            if (mycnpj.length == 6) {
//                mycnpj = mycnpj + '.';
//                cnpj.value = mycnpj; }
//            if (mycnpj.length == 10) {
//                mycnpj = mycnpj + '/';
//                cnpj.value = mycnpj; }
//            if (mycnpj.length == 15) {
//                mycnpj = mycnpj + '-';
//                cnpj.value = mycnpj; }
//            if (mycnpj.length == 18) { }
//        }
//    }
//    else {return false;}
//}
//function mascaraCEP(cep,teclapres){
//    var tecla = teclapres.keyCode;
//    var mycep = '';
//    if (tecla >= 48 && tecla <= 57) {
//        if (tecla != 9 && tecla != 8){
//            mycep = mycep + cep.value;
//            if (mycep.length == 5) {
//                mycep = mycep + '-';
//                cep.value = mycep; }
//            if (mycep.length == 9) { }
//        }
//    }
//    else {return false;}
//}
//function mascaraCEP2(cep,teclapres){
//   var tecla = teclapres.keyCode;
//   var vr = new String(cep.value);
//   vr = vr.replace("-", "");
//   tam = vr.length + 1 ;
//   if (tecla >= 48 && tecla <= 57) { //if (tecla != 9 && tecla != 8){
//      if (tam == 6) //if (tam > 5 && tam < 7)
//         cep.value = vr.substr(0, 5) + '-' + vr.substr(5, tam);
//   }
//   else { return false; }
//}
