﻿function mascara_TextBoXCodigoUniodonto(cod, e)
     {
       var mycod= '';
       mycod = cod.value;
       var digits = "0123456789 ."
       var teste = false;
       var tecla = (window.event) ? event.keyCode : e.which;

       
       for (var i = 0; i < digits.length; i++) {

           var num = digits.substr(i, 1)


           if (String.fromCharCode(tecla) == num) {

               teste = true;
               break;
           }

       }

       if (teste == false)
           return false;

       if (tecla == 46 & mycod.length != 6)
           return false;

       if (tecla == 32 & (mycod.length >6 || mycod.length <4 ) )
           return false;
      
       if (mycod.length == 3 & mycod=='024') {

          mycod = mycod + '.';
          cod.value = mycod;
      }
        if (mycod.length == 4 & mycod!='024.') {
          mycod = mycod + '.';
          cod.value = mycod;
      }
      if (mycod.length == 9 & mycod.substr(0, 4) != '024.') {
          if (mycod.substr(8, 1) != ".") {
              mycod = mycod + '.';
          }
          cod.value = mycod;
      }
      if (mycod.length == 7 & mycod.substr(0, 4) == '024.') {

          if (mycod.substr(6, 1) != ".") {
              mycod = mycod + '.';
          }
          cod.value = mycod;
      }
      if (mycod.length == 16 & mycod.substr(0, 4) != '024.') {
          mycod = mycod + '-';
          cod.value = mycod;
      }
      if (mycod.length == 13 & mycod.substr(0, 4) == '024.' && mycod.lastIndexOf(".") == 6) {
          mycod = mycod + '-';
          cod.value = mycod
          //cod.value = mycod;
      }

      if (mycod.length == 14 & mycod.substr(0, 4) == '024.' && mycod.lastIndexOf(".") == 7) {
          
          mycod = mycod + '-';
          cod.value = mycod.replace(" ", "")
          //cod.value = mycod;
      }


      if (mycod.length == 17 && mycod.substr(0, 4) == '024.') {
          
          return false;
      }
      if (mycod.length == 20 && mycod.substr(0, 4) == '0037') {

          return false;
      }

      if (mycod.length == 19 && mycod.substr(0, 4) != '0037' ) {
          
          return false;
      }
      if (mycod.length == 16 && mycod.substr(0, 3) == '024'&& mycod.lastIndexOf(".")==6) {
          // 
          return false;
      }


     }