function FormataValor(campo,tammax,teclapres)
{
 var tecla = teclapres.keyCode;
 vr = campo.value;
 vr = vr.replace( "/", "" );
 vr = vr.replace( "/", "" );
 vr = vr.replace( ",", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 tam = vr.length;

 if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

 if (tecla == 8 ){        tam = tam - 1 ; }

 if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
 {
  if ( tam <= 2 )
  {
   campo.value = vr ;
  }
  if ( (tam > 2) && (tam <= 5) )
  {
   campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ;
  }
  if ( (tam >= 6) && (tam <= 8) )
  {
   campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
  if ( (tam >= 9) && (tam <= 11) )
  {
   campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
  }
  if ( (tam >= 12) && (tam <= 14) )
  {
   campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8,  3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
  }
  if ( (tam >= 15) && (tam <= 17) )
  {
   campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;
  }
 }
}

function mascara_cep (objeto)
{
  campo = eval (objeto);
  separador = '-';
  conjunto1 = 5;
  if (campo.value.length == conjunto1)
  {
    campo.value = campo.value + separador;
  }
}

function mascara_cnpj(campo, teclapres)
{

 tecla = teclapres.keyCode;

 vr = new String(campo.value);
 vr = vr.replace(".", "");
 vr = vr.replace(".", "");
 vr = vr.replace("/", "");
 vr = vr.replace("-", "");

 tam = vr.length + 1 ;

 if (tecla != 9 && tecla != 8)
 {
  if (tam > 2 && tam < 6)
   campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
   if (tam >= 6 && tam < 9)
    campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
   if (tam >= 9 && tam < 13)
    campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
   if (tam >= 13 && tam < 15)
    campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
 }
}

function verifica_cnpj(valor)
{
  aux1 = 0;
  aux2 = 0;
  aux3 = 1;
  aux4 = 0;
  for (i=0;i<valor.length-2;i++)
  {
    if ((valor.substr(i,1) != "/") && (valor.substr(i,1) != "-") && (valor.substr(i,1) != "."))
    {
      (aux3 < 5) ? aux4 = 6-aux3 : aux4 = 14-aux3;
      aux1 = aux1+(valor.substr(i,1)*aux4);
      (aux3 < 6) ? aux4 = 7-aux3 : aux4 = 15-aux3;
      aux2 = aux2+(valor.substr(i,1)*aux4);
      aux3++;
    }
  }
  resto = aux1-((Math.floor(aux1/11))*11);
  (resto < 2) ? dig1=0 : dig1=11-resto;
  aux2 = aux2+(2*dig1);
  resto = aux2-((Math.floor(aux2/11))*11);
  (resto < 2) ? dig2=0 : dig2=11-resto;
  aux = dig1+" "+dig2;
  aux = aux.substr(0,1)+aux.substr(2,1);
  if (aux != valor.substr(valor.length-2))
    return false;
  else
    if (valor == "99.999.999/9999-62")
      return false;
    else
      return true;
}



function mascara_data(data)
{
  var mydata = '';
  mydata = mydata + data;
  if (mydata.length == 2)
  {
    mydata = mydata + '/';
  }
  if (mydata.length == 5)
  {
    mydata = mydata + '/';
  }
  return mydata;
}

function mascara_data2(campo, evento)
{
  var tecla = evento.keyCode;
  vr  = campo.value;
  vr  = vr.replace( "/", "" );
  vr  = vr.replace( "/", "" );
  tam = vr.length + 1;

  if ((tecla >= 96 && tecla <= 105 ) || (evento.type == 'blur'))
  {
    if (tam > 2 && tam < 5)
      campo.value = vr.substr(0, tam - 2) + '/' + vr.substr(tam - 2, tam);
    if (tam >= 5 && tam <= 11)
      campo.value = vr.substr(0, 2) + '/' + vr.substr(2, 2) + '/' + vr.substr(4, 4);
  }
}

function ver_data(data, ano_ini, ano_fim)
{
  erro  = false;
  meses = new Array (31,28,31,30,31,30,31,31,30,31,30,31);

  if (data.length <10)
   erro = true;
  else
  {
    if ((data.substr(2,1) != "/") && (data.substr(5,1) != "/"))
    {
      erro = true;
    }
    else
    {
      d = parseFloat(data.substr(0,2));
      m = parseFloat(data.substr(3,2));
      a = parseFloat(data.substr(6,4));
      if (((d>0) && (d<32)) && ((m>0) && (m<13)) && ((a>=ano_ini) && (a<=ano_fim)))
      {
        if (m==2)
        {
          if (a%4==0)
          {
            if ((d<1) || (d>29))
              erro = true;
          }
          else
          {
            if ((d<1) || (d>meses[m-1]))
              erro = true;
          }
        }
        else
        {
          if ((d<1) || (d>meses[m-1]))
            erro = true;
        }
      }
      else
        erro = true;
    }
  }
  return (!erro);
}


function trim(str)
{
  return str.replace(/^\s*|\s*$/g,"");
}

function checa_email(email)
{
  aux = trim(email)
  aux_pos = aux.indexOf("@");
  aux_pos2 = aux.indexOf(" ");
  if ((aux_pos <= 1) || (aux == '') || (aux_pos2 > 0))
    return false
  else
    return true;
}


function mascara_cpf(campo, teclapres)
{

 tecla = teclapres.keyCode;

 vr = new String(campo.value);
 vr = vr.replace(".", "");
 vr = vr.replace(".", "");
 vr = vr.replace("/", "");
 vr = vr.replace("-", "");

 tam = vr.length + 1 ;

 if (tecla != 9 && tecla != 8)
 {
  if (tam > 3 && tam < 7)
   campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
   if (tam >= 7 && tam < 10)
    campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
   if (tam >= 10 && tam < 14)
    campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
 }
}

function verifica_cpf(valor)
{
 erro = 0;
 aux1 = 0;
 aux2 = 0;
 aux3 = 1;
 for (i=0;i<valor.length-2;i++)
 {
  if ((valor.substr(i,1) != "/") && (valor.substr(i,1) != "-") && (valor.substr(i,1) != "."))
  {
   aux1 = aux1+(11-aux3)*valor.substr(i,1);
   aux2 = aux2+(12-aux3)*valor.substr(i,1);
   aux3++;
  }
 }
 resto = aux1-((Math.floor(aux1/11))*11);
 (resto < 2) ? dig1=0 : dig1=11-resto;
 aux2 = aux2+(2*dig1);
 resto = aux2-((Math.floor(aux2/11))*11);
 (resto < 2) ? dig2=0 : dig2=11-resto;
 aux = dig1+" "+dig2;
 aux = aux.substr(0,1)+aux.substr(2,1);
 if (aux != valor.substr(valor.length-2))
  return false;
 else
  if ((valor == "000.000.000-00") || (valor == "111.111.111-11") || (valor == "222.222.222-22") ||
  (valor == "333.333.333-33") || (valor == "444.444.444-44") || (valor == "555.555.555-55") ||
  (valor == "666.666.666-66") || (valor == "777.777.777-77") || (valor == "888.888.888-88") ||
  (valor == "999.999.999-99"))
   return false;
  else
   return true;
}

function verifica_email(email)
{
 if (email.indexOf("@") < 3)
  return false;
 else
  return true;
}

function so_numero(campo, evento)
{
 if (campo.length ==0)
  campo.value=0;
 var key;
 var keychar;
 if (window.event)
  key = window.event.keyCode;
 else
  if (evento)
   key = evento.which;
  else
   return true;
 keychar = String.fromCharCode(key);
 if ((key==null) || (key==0) || (key==8) || (key==9)|| (key==13)|| (key==27) )
  return true;
 else
  if ((("0123456789").indexOf(keychar) > -1))
   return true;
  else
   return false;
}

function MostrarData() {
  Hoje = new Date()
  Data = Hoje.getDate()
  Dia = Hoje.getDay()
  Mes = Hoje.getMonth()
  Ano = Hoje.getYear()
  //
  if (Data<10) {
    Data = "0" + Data
  }
  var sNavegador = navigator.appName;
  if (sNavegador == "Microsoft Internet Explorer")
  {
    if (Ano < 2000) {
      Ano = "19" + Ano
    }
  }
  else
  {
    Ano = Ano + 1900;
  }
  //
  NomeDia = new Array(7)
  NomeDia[0] = "Domingo"
  NomeDia[1] = "Segunda-feira"
  NomeDia[2] = "Terça-feira"
  NomeDia[3] = "Quarta-feira"
  NomeDia[4] = "Quinta-feira"
  NomeDia[5] = "Sexta-feira"
  NomeDia[6] = "Sábado"
  //
  NomeMes = new Array(12)
  NomeMes[0] = "Janeiro"
  NomeMes[1] = "Fevereiro"
  NomeMes[2] = "Março"
  NomeMes[3] = "Abril"
  NomeMes[4] = "Maio"
  NomeMes[5] = "Junho"
  NomeMes[6] = "Julho"
  NomeMes[7] = "Agosto"
  NomeMes[8] = "Setembro"
  NomeMes[9] = "Outubro"
  NomeMes[10] = "Novembro"
  NomeMes[11] = "Dezembro"
  //
  document.write (Data + " " + NomeMes[Mes] + " " + Ano)
}
