
   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 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 );
       }
   }  

}




//  onKeyUp="FormataValor('e4',3,event);"

function FormataValor(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 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 CNPJ válido !");
            document.Form_Pesquisa.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;

}



// ===========================
// COMO CHAMAR A FUnÇÃO ABAIXO
// ===========================
// input align=left size=9 maxlength=9 name=CEP onKeyPress="Mascara('CEP', window.event.keyCode, 'document.Geral.CEP');" 
// input align=left size=10 maxlength=10 name=DATA onKeyPress="Mascara('DATA', window.event.keyCode, 'document.Geral.DATA');" 
// 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;
    }
  }

  // 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();
			}	
		}
	}
*/
}




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();
			}	
		}
	}
}








