// Menu over
function mOvr(src,clrOver) { 
 if (!src.contains(event.fromElement)) { 
 	src.style.cursor = 'hand'; src.bgColor = clrOver; 
 	}
 }

function mOut(src,clrIn) { 
 if (!src.contains(event.toElement)) { 
 	src.style.cursor = 'default'; src.bgColor = clrIn; 
 	}
 }
 
function mClk(src) { 
  if(event.srcElement.tagName=='TD') {
	src.children.tags('a')[0].click();
        }
 }




/********************************************************* 
*   Script que mostra em uma caixa flutuante, detalhes   * 
*  do registro onde mouse passar.                        * 
**********************************************************/ 

	function MostraDetalhe(Msg)
	{
		if (Msg==null)
                {
			document.getElementById("Container").style.visibility = "hidden"
		}
		else
                {
			document.getElementById("Container").style.visibility = "visible"
			document.getElementById("Mensagem").innerHTML =  Msg
			document.getElementById("Container").style.top  =  event.y+10
			document.getElementById("Container").style.left = event.x+10
		}
	}
	
	function MostraDetalhe2(Msg)
	{
		if (Msg==null)
                {
			document.getElementById("Container2").style.visibility = "hidden"
		}
		else
                {
			document.getElementById("Container2").style.visibility = "visible"
			document.getElementById("Mensagem2").innerHTML =  Msg
			document.getElementById("Container2").style.top  =  event.y+10
			document.getElementById("Container2").style.left = event.x+10
		}
	}




     function Verifica_Tamanho_Texto( Objeto , TamanhoMaximo , Contador ) 
     {
          Campo = eval(Objeto);

          if ( Campo.value.length > TamanhoMaximo ) 
          {
               Campo.value = Campo.value.substring( 0 , TamanhoMaximo );
          }

          // alert( (Contador!= null) );

          // Se o Campo contador estiver sendo passado então a função atualisa o conteudo do campo contado
          if (Contador!= null)
          {
               Contador.value = (TamanhoMaximo - Campo.value.length);
          }

     }


     function Limpa_Texto( Objeto )
     {
          Campo = eval(Objeto);

          Campo.value = "";  	
     }







     function FormataValorDecimal( Objeto , decimais ) 
     {
          Campo = eval(Objeto);

          var vr = Campo.value;
          vr = vr.replace( /[^0123456789]/g , '' );
          var tam = vr.length;
          // alert( vr );

          // var tecla = teclapres.keyCode;
          //if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
          //{
		  
                if ( tam <= decimais )
                { 
                   Campo.value = vr ; 
                }

                if ( tam > decimais )
                {

                   var y = 0;
                   var z = 0;
                   var x = new Array();
                   var str = vr.substr( 0, tam - decimais ) ; 
                   // alert( str );

                   for (var ct=str.length-1 ; ct>=0; ct--) 
                   {
                      y++;
                      if  ( y == 4 || y == 7 || y == 10 || y == 13 || y == 16 || y == 19 || y == 22 )
                      {
                         x[z]= "."; 
                         z++;
                      }

                      x[z]= str.charAt(ct); 
                      z++;
                   }

                   x.reverse();
                   str = x.join("");
				   // alert( str );

                   Campo.value =  str + "," + vr.substr( tam - decimais, tam );

                }

          //}

     }
	 
	 


     function FormataNumeroDecimais( Valor , decimais ) 
     {

          Campo = parseFloat(Valor) ;


          if ( decimais<=0 )
          {
             Multiplicador = 10 
          }
          else
          {
             Multiplicador = 10; 

             for (var ct=1 ; ct<decimais ; ct++) 
             {
                Multiplicador = Multiplicador * 10;
             }

          }

          // Campo = Math.abs( (Campo * Multiplicador) );
          Campo = parseInt( (Campo * Multiplicador) );
		  // alert(Campo);

          var vr = Campo.toString();
          vr = vr.replace( /[^0123456789]/g , '' );
          var tam = vr.length;
          // alert( vr );

		  
                if ( tam <= decimais )
                { 
                   // Campo.value = vr ; 
                   return( vr ); 
                }

                if ( tam > decimais )
                {

                   var y = 0;
                   var z = 0;
                   var x = new Array();
                   var str = vr.substr( 0, tam - decimais ) ; 
                   // alert( str );

                   for (var ct=str.length-1 ; ct>=0; ct--) 
                   {
                      y++;
                      if  (  ( ((y-1)%3) == 0 ) && y>1 )
                      {
                         x[z]= "."; 
                         z++;
                      }

                      x[z]= str.charAt(ct); 
                      z++;
                   }

                   x.reverse();
                   str = x.join(""); 
                   // alert( str );

                   // Campo.value =  str + "," + vr.substr( tam - decimais, tam );

                   return(  ( str + "," + vr.substr( tam - decimais, tam ) )  ); 

                }


     }








   function AbreJanela(URL)
   {
       msgWindow=window.open(URL,'ExibePopUP','toolbar=no,menubar=no,directories=no,location=no,status=no,scrollbars=no,resizable=no,top=50,left=60,width=650,height=500')
   }


    function AbreJanela2(URL,NomeJanela,X,Y)
    {
        msgWindow=window.open(URL,NomeJanela,'toolbar=no,menubar=no,directories=no,location=no,status=yes,scrollbars=yes,resizable=yes,top=5,left=20,width='+ X +',height='+ Y )
    }

    function AbreJanela3(URL,NomeJanela)
    {
        msgWindow=window.open(URL,NomeJanela)
    }

   function AbreJanela4(URL)
   {
       msgWindow=window.open(URL,'ExibePopUP','toolbar=no,menubar=no,directories=no,location=no,status=no,scrollbars=yes,resizable=yes,top=50,left=60,width=650,height=500')
   }




   function ConfirmaExclusaoRegistro(Msg,Url)
   {
       if ( confirm(Msg) )
       {
           window.location.href = (Url)
       }
   }


     function Refresh()
     {
          var hoje = new Date()
          var dia = hoje.getDate()
          var dias = hoje.getDay()
          var mes = hoje.getMonth()+1
          var ano = hoje.getYear()
          var hora = hoje.getHours()
          var minuto = hoje.getMinutes()
          var segundo = hoje.getSeconds()
 
          if (dia < 10)
               dia = "0" + dia
          if (mes < 10)
               mes = "0" + mes
          if (ano < 2000)
               ano = "19" + ano

          return (ano+mes+dia+hora+minuto+segundo+"")
     }


     function envia(formulario,destino)
     {
	  document.forms[formulario].proximo.value = destino
          document.forms[formulario].submit()
     }

     function EnviaForm(formulario)
     {
          document.forms[formulario].submit()
     }






function fmtMoney(value)
{

 var count;
 var order,n=0;

 for(count=1;count-1<value.length;count++)
{
  value = value.replace(",","");
 }

  value = value.replace(",","");

 result=""+Math.floor(value)+".";
 var cents=100*(value-Math.floor(value))+0.5;
 result += Math.floor(cents/10);
 result += Math.floor(cents%10);
 if (result=='NaN.NaNNaN') result = '0.00';

 order =
result.charAt(result.length-3)+result.charAt(result.length-2)+result.charAt(
result.length-1);

 
for(count=result.length-result.indexOf(".")+1;count-1<result.length;count++)
 {
   if(n>2)
   {
    order =   result.charAt(result.length-count) + ',' + order;
    n=1;
   }
   else
   {
    order =  '' + result.charAt(result.length-count) + order;
    n++;
   }
 }

 return order;
}







function fmtCPFCNPJ(value)
{

 var result='';

 if(value.length>10)
 {
  for(count=1;count-1<value.length;count++)
  {
    value = value.replace(" ","");
    value = value.replace("/","");
    value = value.replace(".","");
    value = value.replace("-","");
  } 

 if(value.length > 11)
  result = fmtCNPJ(value); 
 else
  result = fmtCPF(value)
 }
 return result;
 
}



function fmtCPF(value)
{
 var result='';
 if(value.length>8)
 {

  for(count=1;count-1<value.length;count++)
  {
    value = value.replace(" ","");
    value = value.replace("/","");
    value = value.replace(".","");
    value = value.replace("-","");
  } 


  for(i=value.length-1;i+1>0;i--)
  {
    result = value.charAt(i) + result;
    if(i==(value.length-2)) result = '-' + result;
		if(i==(value.length-5)) result = '.' + result;
		if(i==(value.length-8)) result = '.' + result;
  } 
 }
 return result;
}


function fmtCNPJ(value)
{
  var result = '';
  var count,n=0;
 if(value.length>10)
 {
 
 for(count=1;count-1<value.length;count++)
 {
  value = value.replace(" ","");
  value = value.replace("-","");
  value = value.replace("/","");
  value = value.replace(".","");
 }

  result = "/" + value.charAt(value.length-6) + value.charAt(value.length-5)
+ value.charAt(value.length-4) + value.charAt(value.length-3) + "-" +
value.charAt(value.length-2) + value.charAt(value.length-1);

 for(count=7;count-1<value.length;count++)
 {
   if(n>2)
   {
    result =   value.charAt(value.length-count) + '.' + result;
    n=1;
   }
   else
   {
    result =  '' + value.charAt(value.length-count) + result;
    n++;
   }
 }
 }
 return result;
}



function fmtCEP(value)
{

 var result='';

 if(value.length>7)
 {

    for(count=1;count-1<value.length;count++)
    {
      value = value.replace(" ","");
      value = value.replace("/","");
      value = value.replace(".","");
      value = value.replace("-","");
    } 

    for(i=value.length-1;i+1>0;i--)
    {
      result = value.charAt(i) + result;
      if(i==(value.length-3)) result = '-' + result;
    } 


 } 
 else 
 {

   result='00000-000';

 }

 return result;

}







  //  OnKeyUp="FormataCNPJ('f1', 'f2', event);"

  function FormataCNPJ(Formulario, Campo, TeclaPres) 
  { 
    var tecla = TeclaPres.keyCode; 
    var strCampo; 
    var vr; 
    var tam; 
    var TamanhoMaximo = 14; 
  
    eval("strCampo = document." + Formulario + "." + Campo); 
  
    vr = strCampo.value; 
    vr = vr.replace("/", ""); 
    vr = vr.replace("/", ""); 
    vr = vr.replace("/", ""); 
    vr = vr.replace(",", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    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 < TamanhoMaximo && 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) 
      { 
        strCampo.value = vr; 
      } 
       if ((tam > 2) && (tam <= 6)) 
       { 
         strCampo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam); 
       } 
       if ((tam >= 7) && (tam <= 9)) 
       { 
         strCampo.value = vr.substr(0, tam - 6) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
      } 
       if ((tam >= 10) && (tam <= 12)) 
       { 
         strCampo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
      } 
       if ((tam >= 13) && (tam <= 14)) 
       { 
         strCampo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
      } 
       if ((tam >= 15) && (tam <= 17)) 
       { 
         strCampo.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); 
      } 
    } 

  } 





//  onKeyPress="FormataCpf('txtCPF',11,event);"

function FormataCpf(campo,tammax,teclapres) 
{
   var tecla = teclapres.keyCode;

   // vr = document.form[campo].value;
   vr = event.srcElement.value;
   vr = vr.replace( "/", "" );
   vr = vr.replace( "/", "" );
   vr = vr.replace( ",", "" );
   vr = vr.replace( ".", "" );
   vr = vr.replace( ".", "" );
   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 )
       { 
          event.srcElement.value = vr; 
       }

       if ( (tam > 2) && (tam <= 5) )
       {
          event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ); 
       }

       if ( (tam >= 6) && (tam <= 8) )
       {
          event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ); 
       }
  
       if ( (tam >= 9) && (tam <= 11) )
       {
          event.srcElement.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) )
       {
          event.srcElement.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) )
       {
          event.srcElement.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 Valida_CPF_CNPJ_OLDDDD( vlr , empresa )
{
   if ( vlr!="" )
   {

      if ( empresa ) // Pessoa jurídica
      {
         if ( ! vCicCgc( vlr , true ) )
         {
            alert("O Número de CNPJ informado não é válido !");
            document.FORMULARIO.CPF_CNPJ.focus();
         } 
      }
      else
      {
         if ( ! vCicCgc( vlr , false ) )
         {
            alert("Número de CPF informado não é válido !");
            document.FORMULARIO.CPF_CNPJ.focus();
         }
      }

   }

   return (null);

}



function Valida_CPF_CNPJ( vlr )
{


   if ( vlr!="" )
   {


      if ( ! vCicCgc( vlr , true ) )
      {

         if ( ! vCicCgc( vlr , false ) )
         {
            alert("O Número fornecido não é um CPF/CNPJ válido !");
            document.FORMULARIO.CPF_CNPJ.focus();
         }

      } 


   }

   return (null);


}







/*
Eu estou criando uma série de rotinas de verificacao de CIC e CGC em JavaScript, pois julgo mais interessante mante-la em 
lado cliente, pois fica dispensavel postar os dados para o web server para obter-se a validacao, e mantem a 
compatibiliadde com navegadores bixados, como o netscape.
Por outro lado, abre espaco para "fussadores", entao recomendo q alem de manter a rotina do lado cliente, crie a mesma 
rodando do lado servidor. Protecao excessiva nunca eh demais.
*/

/*
Verificação de CIC / CGC
Devem ser passados como parametros:
campo = valor a ser pesquisado
empresa = se true, verifica CGC, senao CPF
*/
function vCicCgc( vlr, empresa )
{
var intNumero, intMais, i, intResto, strCampo, strCaracter, strConf;
var intDig1, intDig2, dblDivisao, rt, intSoma, intSoma1, intSoma2, intInteiro;
var lngSoma, lngInteiro, strCGC; // somente para o caso de CGC

vlr = SoNumero( vlr );

if ( empresa ) // Pessoa jurídica
{
vlr = TransCGC( vlr );
intSoma = 0;
intSoma1 = 0;
intSoma2 = 0;
intNumero = 0;
intMais = 0;
strCGC = vlr.substr( vlr.length-7, 4 );
strCampo = vlr.substr( 4, 4 );
strCampo += strCGC;

for ( i=1; i<9; i++ )
{
strCaracter = strCampo.substr( strCampo.length - i );
intNumero = strCaracter.substr( 0, 1 );
intMais = intNumero * ( i+1 );
intSoma1 += intMais;
}
strCampo = vlr.substr( 0, 4 );
for ( i=1; i<5; i++ )
{
strCaracter = strCampo.substr( strCampo.length - i );
intNumero = strCaracter.substr( 0, 1 );
intMais = intNumero * ( i+1 );
intSoma2 += intMais;
}
intSoma = intSoma1 + intSoma2;
dblDivisao = intSoma / 11;
intInteiro = parseInt( dblDivisao ) * 11;
intResto = intSoma - intInteiro;
intDig1 = ( intResto == 0 || intResto == 1 ) ? 0 : 11 - intResto;

intSoma = 0;
intSoma1 = 0;
intSoma2 = 0;
intNumero = 0;
intMais = 0;
strCGC = vlr.substr( vlr.length-7, 4 );
strCampo = vlr.substr( 5, 3 );
strCampo += ( strCGC + intDig1 );

for ( i=1; i<9; i++ )
{
strCaracter = strCampo.substr( strCampo.length - i );
intNumero = strCaracter.substr( 0, 1 );
intMais = intNumero * ( i+1 );
intSoma1 += intMais;
}
strCampo = vlr.substr( 0, 5 );
for ( i=1; i<6; i++ )
{
strCaracter = strCampo.substr( strCampo.length - i );
intNumero = strCaracter.substr( 0, 1 );
intMais = intNumero * ( i+1 );
intSoma2 += intMais;
}
intSoma = intSoma1 + intSoma2;
dblDivisao = intSoma / 11;
intInteiro = parseInt( dblDivisao ) * 11;
intResto = intSoma - intInteiro;
intDig2 = ( intResto == 0 || intResto == 1 ) ? 0 : 11 - intResto;

strConf = intDig1.toString() + intDig2.toString();
rt = ( strConf == vlr.substr( vlr.length - 2 ) );
}
else // Pessoa física
{
lngSoma = 0;
intNumero = 0;
intMais = 0;
strCampo = vlr.substr( 0, 9 );

for ( i=1; i<10; i++ )
{
strCaracter = strCampo.substr( strCampo.length - i );
intNumero = parseInt( strCaracter.substr( 0, 1 ) );
intMais = intNumero * ( i+1 );
lngSoma += intMais;
}
dblDivisao = lngSoma / 11;
lngInteiro = parseInt( dblDivisao ) * 11;
intResto = lngSoma - lngInteiro;
intDig1 = ( intResto == 0 || intResto == 1 ) ? 0 : 11 - intResto;
strCampo += intDig1;
lngSoma = 0;
intNumero = 0;
intMais = 0;
for ( i=1; i<11; i++ )
{
strCaracter = strCampo.substr( strCampo.length - i );
intNumero = parseInt( strCaracter.substr( 0, 1 ) );
intMais = intNumero * ( i+1 );
lngSoma += intMais;
}
dblDivisao = lngSoma / 11;
lngInteiro = parseInt( dblDivisao ) * 11;
intResto = lngSoma - lngInteiro;
intDig2 = ( intResto == 0 || intResto == 1 ) ? 0 : 11 - intResto;
strCampo += intDig2;
strConf = intDig1.toString() + intDig2.toString();

rt = ( strConf == vlr.substr( vlr.length - 2 ) );
}
return rt;
}


// Transforma o CGC para a rotina corretamente, os numeros devem ser filtrados antes
function TransCGC( vlr )
{
var x, y, z;
x = vlr.substr( 0, 8 ); y = vlr.substr( 8, 4 ); z = vlr.substr( 12, 2 );
return ( x + '/' + y + '-' + z );
}

/*
Retira todas as letras e outros caracteres de uma string devolvendo
apenas numeros 
*/
function SoNumero( v )
{
var x, ret;
ret = '';
for ( x=0; x<=v.length; x++ )
ret += v.substr( x, 1 ) >= '0' && v.substr( x, 1 ) <= '9' ? v.substr( x, 1 ) : '';
return ( ret );
} 


// onKeyUp="Javascript:this.value=fmtCEP(this.value);"  22450-221

function FormataCEP(value)
{
 var result='';
 if(value.length > 7)
 {

  for(count=1;count-1<value.length;count++)
  {
    value = value.replace(" ","");
    value = value.replace("/","");
    value = value.replace(".","");
    value = value.replace("-","");
  } 

  for(i=value.length-1;i+1>0;i--)
  {
    result = value.charAt(i) + result;
    if(i==(value.length-3)) result = '-' + result;
  } 

 } // else result='00000-000';

 return result;

}



// =====================
//  FUNÇÃO DE IMPRESSÃO 
// =====================

/*
This script is written by Eric (Webcrawl@usa.net)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

//  Como chamar a Função de Impressão
//  ---------------------------------
//  SCRIPT Language="Javascript"
//  var NS = (navigator.appName == "Netscape");
//  var VERSION = parseInt(navigator.appVersion);
//  if (VERSION > 3) 
//  {
//      document.write('<form><input type=button value="Imprimir" name="Print" onClick="printit()"></form>');        
//  }
//  script

function printit()
{  
   if (NS) 
   {
      window.print() ;  
   } 
   else 
   {
      var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
   }
}






// =============================
// COMO CHAMAR AS FUnÇÕES ABAIXO
// =============================
// input align=left size=9 maxlength=9 name=CEP onKeyPress="Mascara('CEP', window.event.keyCode, this );" 
// input align=left size=10 maxlength=10 name=DATA onKeyPress="Mascara('DATA', window.event.keyCode, this );" 
// input align=left size=10 maxlength=12 name=DATA2 onKeyPress="Mascara('DATA2', window.event.keyCode, this );" 
// input  type=text  Name="dt_controle" onKeyPress="Mascara('DATA', window.event.keyCode, this );"    size=10  Maxlength=10   
// input align=left size=9 maxlength=9 name=TELEFONE onKeyPress="Mascara('TELEFONE', window.event.keyCode, 'document.Geral.TELEFONE');" 

function Mascara (formato, keypress, objeto)
{
  campo = eval (objeto);

  // CEP
  if (formato=='CEP')
  {
    separador = '-'; 
    conjunto1 = 5;
    if (campo.value.length == conjunto1)
    {
       campo.value = campo.value + separador;
    }
  }

  // DATA
  if (formato=='DATA')
  {
    separador = '/'; 
    conjunto1 = 2;
    conjunto2 = 5;
    if (campo.value.length == conjunto1)
    {
      campo.value = campo.value + separador;
    }
    if (campo.value.length == conjunto2)
    {
      campo.value = campo.value + separador;
    }
  }
  
  // DATA2
  if (formato=='DATA2')
  {
    separador = '/'; 
    conjunto1 = 2;
    conjunto2 = 7;
    if (campo.value.length == conjunto1)
    {
      campo.value = campo.value + separador;
    }
    if (campo.value.length == conjunto2)
    {
      campo.value = campo.value + separador;
    }
  }

  // TELEFONE
  if (formato=='TELEFONE')
  {
    separador = '-'; 
    conjunto1 = 4;
    if (campo.value.length == conjunto1)
    {
      campo.value = campo.value + separador;
    }
  }


}





function FormataData(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.FORMULARIO[campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.FORMULARIO[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.FORMULARIO[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
/*	
	for (var ct = 0; ct < document.FORMULARIO.elements.length; ct++) {
		if (document.FORMULARIO.elements[ct].name == document.FORMULARIO.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.FORMULARIO[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
*/
}




//  onKeyUp="FormataValor('e4',3,event);"

function FormataValorXXX(campo,tammax,teclapres) 
{
   var tecla = teclapres.keyCode;

   // vr = document.form[campo].value;
   vr = event.srcElement.value;
   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 > tammax)  )
       {
          event.srcElement.value = vr.substr( 0, tammax ) + ',' + vr.substr( tammax , tam ); 
       }

   }  

}



function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.FORMULARIO[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 ){ 
	 		document.FORMULARIO[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.FORMULARIO[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.FORMULARIO[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.FORMULARIO[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) ){
	 		document.FORMULARIO[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) ){
	 		document.FORMULARIO[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 ) ;}
	}
		
	for (var ct = 0; ct < document.FORMULARIO.elements.length; ct++) {
		if (document.FORMULARIO.elements[ct].name == document.FORMULARIO.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.FORMULARIO.elements[ct+1] && document.FORMULARIO.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
}






function FormataValorDecimal_ComERRO(campo,tammax,decimais,teclapres) 
{

	var tecla = teclapres.keyCode;
	vr = document.FORMULARIO[campo].value;
	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 <= decimais )
                { 
                   document.FORMULARIO[campo].value = vr ; 
                }


                if ( tam > decimais && tam <= tammax )
                {

				   var y = 0;
				   var z = 0;
                   var x = new Array();
                   var str = vr.substr( 0, tam - decimais ) ; 
                   // alert( str.length );
                   // alert( vr.substr( 0, tam - decimais ) );
				   
                   for (var ct=str.length-1 ; ct>=0; ct--) 
                   {
                      y++;
                      if  ( y == 4 || y == 7 || y == 10 || y == 13 || y == 16 || y == 19 || y == 22 )
                      {
                         x[z]= "."; 
                         z++;
                      }

                      x[z]= str.charAt(ct); 
                      z++;
                   }

                   str = x.reverse();

				   // alert( x.toString() );

                   document.FORMULARIO[campo].value = "" + str + "," + vr.substr( tam - decimais, tam );

                   // alert( vr.substr( tam - decimais, tam ) );

                }


	}
		

	for (var ct = 0; ct < document.FORMULARIO.elements.length; ct++) {
		if (document.FORMULARIO.elements[ct].name == document.FORMULARIO.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.FORMULARIO.elements[ct+1] && document.FORMULARIO.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}


}



