// Início Tela Consulta
//v2.0

subWin = null;

function con_asc(objeto) {
   alert('ok');
   var codigo;
   codigo = event.keyCode;
   alert(codigo);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

// Fim Tela Consulta

function setafocus(objeto) {
   objeto.focus();
}

function teclaenter(local) {
   var codigo;
   codigo = event.keyCode;
   if (codigo == 13) {
      event.keyCode = 0
      local.focus()
   }
}

function submete(form) {
   eval( "document."+form+".submit()" )
}

function keysubmete( form, key ) {
   var codigo;
   codigo = event.keyCode;
   if (codigo == key) {
      eval( "document."+form+".submit()" )
   }
}

function validasexo(objeto) {
   var sexo = objeto.value;
   if ( sexo == 'm' )
      objeto.value = 'M';
   else if ( sexo == 'f' )
      objeto.value = 'F';
   else if ( sexo != 'M' && sexo != 'F' ) {
      objeto.focus();
      objeto.select();
      alert("Atenção: digite M-Masculino ou F-Feminino!");
   }
}

function validaemail(objeto) {
        var email = objeto.value;
        var s = new String(email);
        var retorno = true;

        // Se o email for vazio, retorne verdadeiro.
        if (email == "") return true;
        // Validar se o e-mail inicia com o @
        if (email.substr(0,1) == "@"){
                retorno = false;
        }

        // { } ( ) < > [ ] | \ /
        if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0))
                retorno = false;
        // & * $ % ? ! ^ ~ ` ' "
        if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
                retorno = false;
        // , ; : = #
        if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
                retorno = false;
        // procura se existe apenas um @
        if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
                retorno = false;
        // verifica se tem pelo menos um ponto após o @
        if (s.lastIndexOf(".") < s.indexOf("@"))
                retorno = false;

        if (!retorno){
                objeto.focus();
                objeto.select();
                alert("Atenção: o seu Email está Incorreto!");
        }

        return retorno;
}

function LimpaFormatacaoCNPJ(objeto) {
        var novoCnpj;

        novoCnpj = objeto.value.replace(".","");
        novoCnpj = novoCnpj.replace(".","");
        novoCnpj = novoCnpj.replace("-","");
        novoCnpj = novoCnpj.replace("/","");

        return novoCnpj;
}

function habilitacampo(form,campo){
   for ( i=1; i <= form.elements.length - 1; i++ ) {
      if ( form.elements[i].name == 'nrconvenio' ) {
         if ( campo == "001" ) {
            form.elements[i].disabled = false
            form.elements[i].style.backgroundColor  = "#FFFFFF"
         } else {
            form.elements[i].disabled = true
            form.elements[i].style.backgroundColor  = "#DFDFDF"
         }
      }
   }
}

function formataHora(objeto) {
   var codigo;
   codigo = event.keyCode;
   if(codigo < 48 || codigo > 57){
      event.keyCode = 0;
   } else {
      tamanho = objeto.value.length;
      if(tamanho == 0 && (codigo > 50 )) {
         event.keyCode = 0;
//         return false;
      } else if(tamanho == 2) {
         objeto.value = objeto.value + ':';
      } else if (tamanho == 3 && (codigo > 53 )) {
         event.keyCode = 0;
      }
   }
}

function formataData(objeto) {
   var codigo;
   codigo = event.keyCode;
   if(codigo < 48 || codigo > 57){
      event.keyCode = 0;
      return false;
   }

   tamanho = objeto.value.length;
   if(tamanho == 2 || tamanho == 5)
     objeto.value = objeto.value + '/';
}

function formataMoeda(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 8 || whichCode == 46){
  fld.value = '';
  return false;
}
if (whichCode == 13) return false;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

function validaData(objeto) {
        var valor = objeto.value;
        var mValores = "312931303130313130313031"
        var retorno = false;
        var lastDate = 0

        if (valor == "")
           return true;
        if (valor.length < 10)
           retorno = false;
        if (valor.substr(6, 4) < 1900) {
                alert("O sistema não trabalha com ano inferior a 1900.")
                objeto.focus();
                objeto.select();
                return false;
        }

        dia  = parseInt(valor.substring(0,2),10)                // pega o dia
        mes  = parseInt(valor.substring(3,5),10)                  // pega o mês
        ano  = parseInt(valor.substring(6,10),10)                // pega o ano
        lastDate = mValores.substring((mes-1)*2, (mes-1)*2+2)

        if (valor.length < 8){
                retorno = false
        } else if ((valor.substring(2,3) != "/" ) || (valor.substring(5,6) != "/") ) {
                retorno = false
        } else if ( (isNaN(dia)) || (isNaN(mes)) || ( isNaN(ano)) ) {
                retorno = false
        } else if ( (mes > 12) || (mes <= 0) ){
                retorno = false
        } else if ( (dia > lastDate) || (dia <=0) ){
                retorno = false
        } else if (valor.substring(6,10) < 4){
                retorno = false
        } else {
                retorno = true
        }

        if (!retorno){
                objeto.focus();
                objeto.select();
                alert("Atenção: A data digitada está Inválida!")
        }

        return retorno;
}

function EhNumero(){
        var codigo;
        codigo = event.keyCode;
        //O Código 46 é correspondente ao ponto(.) usado para casas decimais.
        //O Código 58 é correspondente ao dois pontos(:) para campos Hora.
        if (codigo == 46 || codigo == 44)
           return true;

        if(codigo < 48 || codigo > 57){
           event.keyCode = 0;
        }
}
function abrejanela (pagina,x,y) {
  var floater= null
  floater =
  window.open(pagina,'vjanela','width='+x+',height='+y+',resizable=yes,status=0,scrollbars=1,location=no,directories=no,menubar=no,top=25,left=25')
  if (floater !=null) {
    if (floater.opener == null) {
          floater.opener = self
    }
    floater.location.href =pagina
  }
}

function FormataCNPJ(objeto) {
   if (((event.keyCode) > 47) && ((event.keyCode) < 58)) {
      var tecla, tamanho;
      tecla = event.keyCode;
      if (tecla != 8) {
         tamanho = objeto.value.length;
         if(tamanho == 2) {
            objeto.value = objeto.value + '.';
         } else if (tamanho == 6) {
            objeto.value = objeto.value + '.';
         } else if (tamanho == 10) {
            objeto.value = objeto.value + '/';
         } else if (tamanho == 15) {
            objeto.value = objeto.value + '-';
         }
      }
      return(true)
   } else
      return(false)
}

function FormataCPF(objeto) {
   if ((event.keyCode) > 31 && ((event.keyCode) < 48 || (event.keyCode) > 57))
  {
    event.keyCode = 0;
    return false
  }
  if (((event.keyCode) > 47) && ((event.keyCode) < 58)) {
      var tecla, tamanho;
      tecla = event.keyCode;
      if (tecla != 8){
         tamanho = objeto.value.length;
         if(tamanho == 3) {
            objeto.value = objeto.value + '.';
         } else if (tamanho == 7) {
            objeto.value = objeto.value + '.';
         } else if (tamanho == 11) {
            objeto.value = objeto.value + '-';
         }
      }
      return(true)
   } else
      return(false)
}
function validaCNPJ(objeto) {
   if ( objeto ) {
      var cnpj;
      cnpj = objeto.value;
      cnpj = cnpj.replace(".","");
      cnpj = cnpj.replace(".","");
      cnpj = cnpj.replace("-","");
      cnpj = cnpj.replace("/","");
      var Numero = cnpj.substring(0,12);
      var Digito = cnpj.substring(12,14);
      var CGC = Numero;
      var peso1 = '543298765432';
      var peso2 = '654329876543';
      var soma1 = 0;
      var soma2 = 0;
      var digito1 = 0;
      var digito2 = 0;
      var total = 0;
      total = Numero.length + Digito.length;
      // Se o CNPJ for todo zero.
      if (CGC == 0) {
         msgerrocnpj(objeto);
         return false;
      }
      if(Numero == "" && Digito == "") return true;
      // Para pergar a quantidade correta, pois o usuário pode ter preenchido
      // o CNPJ com 14 ou 15 números.
      if(total == 15)
         CGC = Numero.substr(1,12);

      if ((Numero.length < 12) || (Digito.length < 2))
       {
         msgerrocnpj(objeto);
         return false;
       }
      for (i = 1; i < 12 - Numero.length+1; i++) {
         CGC = eval("'" + CGC + "'")
      }

      for (i = 1; i < CGC.length+1; i++) {
         soma1 += CGC.substring(i, i-1) * peso1.substring(i, i-1);
      }

      soma1 %= 11;
      if (soma1  < 2) {
         digito1 = 0;
      } else {
         digito1 = 11 - soma1;
      }
      for (i = 1; i < CGC.length+1; i++) {
         soma2 += CGC.substring(i, i-1) * peso2.substring(i, i-1);
      }
      soma2 += digito1 * 2
      soma2 %= 11;

      if (soma2  < 2)
         digito2 = 0;
      else
         digito2 = 11 - soma2;

      if (eval("'" + digito1 + digito2 + "'") != Digito)
      {
         msgerrocnpj(objeto);
         return false;
      }
      else
         return true;
   } else
      return true;
}

function validaCPF(objeto){
   var cpf;
   cpf = objeto.value;
   var fach = 1;
   var pdig = cpf.substring(0,1);
   var cdig;
   if (cpf.length == 14){
     cpf = cpf.replace(".","");
     cpf = cpf.replace(".","");
     cpf = cpf.replace("-","");
     cpf = cpf.replace("/","");
     for(i = 1; i < cpf.length ;i++)
     {
      cdig = cpf.substring(i,i+1);
      if( pdig == cdig )
      {
         fach=fach+1;
      }
     }
     if(fach == cpf.length)
     {
        msgerro(objeto);
        return false;
     }
     x = 0;
     soma = 0;
     dig1 = 0;
     dig2 = 0;
     texto = "";
     cpf1="";
     len = cpf.length; x = len -1;
     for (var i=0; i <= len - 3; i++)
     {
        y = cpf.substring(i,i+1);
        soma = soma + ( y * x);
        x = x - 1;
        texto = texto + y;
     }
     dig1 = 11 - (soma % 11);
     if (dig1 == 10)
        dig1=0;
     if (dig1 == 11)
        dig1=0;
     cpf1 = cpf.substring(0,len - 2) + dig1 ;
     x = 11; soma=0;
     for (var i=0; i <= len - 2; i++)
     {
        soma = soma + (cpf1.substring(i,i+1) * x);
        x = x - 1;
     }
     dig2= 11 - (soma % 11);
     if (dig2 == 10)
        dig2=0;
     if (dig2 == 11)
        dig2=0;
     if ((dig1 + "" + dig2) != cpf.substring(len,len-2))
     {
        msgerro(objeto);
        return false;
     }
   }
   else if (cpf != ""){
     msgerro(objeto);
     return false;
   }
}
function msgerrocnpj(objeto)
{
  objeto.focus();
  objeto.select();
  alert("Atenção: O CNPJ digitado está Inválido!")
}
function msgerro(objeto)
{
  objeto.focus();
  objeto.select();
  alert("Atenção: O CPF digitado está Inválido!")
}


function LimpaFormatacaoCNPJ(objeto)
{
   var novoCnpj;
   novoCnpj = objeto.value.replace(".","");
   novoCnpj = novoCnpj.replace(".","");
   novoCnpj = novoCnpj.replace("-","");
   novoCnpj = novoCnpj.replace("/","");
   return novoCnpj;
}

function LimpaFormatacaoCPF(objeto)
{
   novoCPF = objeto.value;
   novoCPF = novoCPF.replace( ".", "" );
   novoCPF = novoCPF.replace( ".", "" );
   novoCPF = novoCPF.replace( "-", "" );
   return novoCPF;
}
function masc_valor(ConteudoCampo)
{
if (((event.keyCode) > 47) && ((event.keyCode) < 58))
{
   NumDig = ConteudoCampo.value;
   TamDig = NumDig.length;
   Contador = 0;
   if (TamDig > 1)
   {
      numer = "";
      for (i = TamDig; (i >= 0); i--)
      {
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) {
             Contador++;
             if ((Contador == 2) && ((TamDig -i) < 4))
             {
               numer = ","+numer;
               Contador = 0;
             }
             else if (Contador == 3)
             {
               numer = "."+numer;
               Contador = 0;
             }
             numer = NumDig.substr(i, 1)+numer;
          }
      }
      ConteudoCampo.value = numer;
   };
   return(true)
}
else
return(false)
}

function masc_back(dado)
{
   NumDig = dado.value;
   TamDig = NumDig.length;
   TamDig--;
   Contador = 0;
   if ((TamDig >= 0) && (event.keyCode == 8))
   {
      numer = "";
      for (i = TamDig; (i >= 0); i--)
      {
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9)) {
             Contador++;
             /*alert(NumDig.substr(i, 1) + " Contador " + Contador+ " numer "+ numer+ " TamDig " +TamDig + " i " + i );*/
             if ((Contador == 4) && ((TamDig -i) < 5))
             {
                numer = ","+numer;
                Contador = 0;
             }
             else if ((Contador == 3) && ((numer.length) > 4))
             {
                numer = "."+numer;
                Contador = 0;
             }
             numer = NumDig.substr(i, 1)+numer;
          }
      }
      if (numer == "001")
         numer="";
         if ((numer.length) == 3 )
            numer= "0," + numer;
            dado.value = numer;
   }
}
function consultas(idprofissional,destList,profissionais)
{
   var codigo;
   var len;
   var valor;
   var found = false;
   codigo = event.keyCode;
   if ( codigo == 43 || codigo == 45 )
   {
      event.keyCode = 0;
      idprofissional.value = idprofissional.value.toUpperCase();
   }
   len = destList.length;
   if ( codigo == 43 )
   {
      if ( pro[idprofissional.value] )
      {
         for(var count = 0; count < len; count++)
         {
            if (destList.options[count] != null )
            {
               if (idprofissional.value == destList.options[count].value)
               {
                  found = true;
                  break;
               }
            }
         }
         if (found != true)
         {
            profissionais.value = profissionais.value+idprofissional.value+';';
            newOp = new Option();
            newOp.value = idprofissional.value;
            newOp.text = (len+1)+': '+idprofissional.value+' - '+pro[idprofissional.value];
            destList.options[len] = newOp;
         }
         else
            alert ( 'Esse Profissional já foi selecionado!' )
      }
      else
         alert ( 'Código de Profissional Inexistente!' )
      idprofissional.value = '';
   }
   else if (codigo == 45)
   {
      if ( pro[idprofissional.value] )
      {
         profissionais.value = '';
         for(var count = 0; count < len; count++)
         {
            if ( idprofissional.value == destList.options[count].value )
            {
               destList.options[count] = null;
               found = true;
               len--;
            }
            if ( count != len )
            {
               profissionais.value = profissionais.value+destList.options[count].value+';';
               if ( found == true )
               {
                  valor = destList.options[count].value;
                  destList.options[count].text = (count+1)+': '+valor+'-'+pro[valor];
               }
            }
         }
         if ( found != true )
            alert ( 'Esse Profissional não foi selecionado!' )
         idprofissional.value = '';
      }
      else
         alert ( 'Código de Profissional Inexistente!' )
   }
}
function montaprof (objeto)
{
   var codigo;
   for(var count = 1; cod[count]!=null; count++)
   {
      newOp = new Option();
      newOp.value = '';
      codigo = cod[count];
      newOp.text = cod[count]+' - '+pro[codigo];
      objeto.options[count] = newOp;
   }
}
function montaexa(objeto) {
   var ascii = event.keyCode;
   var tecla = String.fromCharCode(ascii)
   if ( (ascii >= 65 && ascii <= 90) || (ascii >= 97 && ascii <= 122) ) {
      len = objeto.length;
      while ( objeto.options[1] )
         objeto.options[1] = null
      for (var i=cod_exa.length-1; i>=1; i--) {
         exam = ds1_exa[cod_exa[i]]
         letra = exam.substr(0,1)
         if ( tecla.toUpperCase() == letra.toUpperCase() ) {
            newOp = new Option()
            newOp.value = cod_exa[i]
            newOp.text = cod_exa[i]+' - '+ds1_exa[cod_exa[i]]
            if ( ds2_exa[cod_exa[i]] )
               newOp.text = newOp.text+' - '+ds2_exa[cod_exa[i]]
            objeto.add( newOp, 1 )
         }
      }
   }
}
function preenche_descricao( objeto1, objeto2 ) {
   var codigo;
   codigo = objeto1.value;
   if ( codigo ) {
      if ( des[codigo] ) {
         objeto2.value = des[codigo];
      } else {
         objeto2.value = 'CÓDIGO DE PROCEDIMENTO NÃO CADASTRADO';
         objeto1.focus();
      }
   }
}
function selectall (objeto) {
   var len;
   len = objeto.length;
   for (var i = 0; i<=len; i++ ) {
      objeto.options[i].selected = true;
   }
}

function consulta_tab(consulta,palavra,lista){
   path = "consulta.php?con="+consulta+"&campo="+palavra.name+"&palavra="+palavra.value;
   lista.location.href = path;
   palavra.value = '';
}

function preenche(campo,valor) {
   eval("document.solicitacoes."+campo+".value='"+valor+"'")
}

function acumula(campo,valor) {
   var atual
   eval("atual=document.solicitacoes."+campo+".value")
   if ( atual != '' )
      valor = valor+", "+atual
   eval("document.solicitacoes."+campo+".value='"+valor+"'")
}

function deslogado() {
   alert('Você ainda não se identificou. Digite seu usuário e a sua senha, por favor.');
   parent.topo.login.USERID.focus();
}

function checkIt(evt)
{
  evt = (evt) ? evt : window.event
  var charCode = (evt.which) ? evt.which : evt.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57))
  {
    event.keyCode = 0;
    return false
  }
  return true
}

function valorKey(evt)
{
  evt = (evt) ? evt : window.event
  var charCode = (evt.which) ? evt.which : evt.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57))
  {
    // não é numero e não é 44 virgula
    if (charCode != 44) {
        event.keyCode = 0;
        return false
    }
  }
  return true
}
function validaANO(objeto)
{
  if ( objeto.value.length > 0 && objeto.value < 1900 )
  {
      objeto.focus();
      objeto.select();
      alert("Ano deve ser Maior que 1900");
      return false;
  }
}
function abre_relat(filtro,nome_relat,formula)
{
  url= 'http://db/relatorios/relat_rpt.asp?filtro='+filtro+'&nome_relat='+nome_relat+formula
  features = 'menubar=no,directories=no,toolbar=no,scrollbars=no,status=no,location=no,resizable=yes,width=791,height=544,left=0,top=0';
  window.open(url,"",features);
}

function chama_calendar(tipo)
{
  url = "../inc/calendar.php?tipo_campo="+tipo
  features = 'menubar=no,directories=no,toolbar=no,scrollbars=no,status=no,location=no,resizable=no,width=220,height=205,left=300,top=150';
  subWin=window.open(url,"",features);
}

function fecha_subjanela() {
  if (subWin != null && subWin.open) subWin.close();
}

function des_aspas()
{
  if (event.keyCode == 34 || event.keyCode == 39 || event.keyCode == 92 )
    {
      event.keyCode = 0;
      return false
    }
}

function pesq_nuc(nomeform)
{
  var url = "../pvl/frmPVL_Pesquisa_Nucleo.php?nomeform="+nomeform;
  var features = 'scrollbars=no,status=no,location=no,resizable=no,width=720,height=420,left=30,top=30';
  subWin=window.open(url,"",features);
}

function pesq_aluno(nomeform)
{
  var url = "../pvl/frmPVL_Pesquisa_Aluno.php?nomeform="+nomeform;
  var features = 'scrollbars=no,status=no,location=no,resizable=no,width=720,height=420,left=30,top=30';
  subWin=window.open(url,"",features);
}

function mov_titulo(objeto)
{
   pos=document.all.grid.scrollTop
   document.all.tab1.style.top=pos
   document.all.tab1.style.left=1
   document.all.tab1.style.position="absolute"
   if (pos==0){
     document.all.tab1.style.position="relative"
	 document.all.tab1.style.left=0
   }
}

function abre_subjanela(pagina,w,h,l,t)
{
  var url = pagina;
  var features = 'scrollbars=no,status=no,location=no,resizable=no,width='+w+',height='+h+',left='+l+',top='+t;
  subWin=window.open(url,"",features);
}

function abre_subjanela2(pagina,w,h,l,t)
{
  var url = pagina;
  var features = 'scrollbars=yes,status=no,location=no,resizable=no,width='+w+',height='+h+',left='+l+',top='+t;
  subWin=window.open(url,"",features);
}

function faixa_etaria(idade)
{
  if (idade < 15)
      return 0;
  else if(idade <= 19)
      return 1;
  else if(idade <= 24)
      return 2;
  else if(idade <= 29)
      return 3;
  else if(idade <= 39)
      return 4;
  else if(idade <= 49)
      return 5;
  else if(idade <= 59)
      return 6;
  else if(idade > 59)
      return 7;

}

function finaliza()
{
  retconf=false
  retconf=confirm('Você Deseja Finalizar o Sistema')
  if (retconf==true)
  {
    parent.location.href="modulo2.php?finaliza=ok"
    parent.close();
  }
}

function telainicial(link)
{
  window.open('http://educ_032/aula/'+link,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=791,height=544,top=0,left=0');
}

function expandIE(imagem,camada) {

   //whichIm = event.srcElement;

   if (camada.style.display == "none") {
      camada.style.display = "block";
      imagem.src = "img/menos.gif";
   } else {
      camada.style.display = "none";
      imagem.src = "img/mais.gif";
   }
   window.event.cancelBubble = true ;
}
function val_orgao_processo(objeto)
{
    if  ( objeto.value > 0 && ( objeto.value < 1700  ||  objeto.value > 1799 ))
    {
        alterna_telas("dados_gerais");
        alert('Orgão Invalido ou não informado! VALORES PERMITIDOS: 1700 a 1799');
        document.all.orgao_processo.focus();
        return;
    }
}

function Limpar(valor, validos) {
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}


function FormataValor(campo,tammax,teclapres) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
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 ) ;}
}

}
