﻿/********************************************************
Modulo de Funcoes Genericas utilizada pelo Educacional
*********************************************************/
   
   /* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mario Costa | */
function currencyFormat(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 == 13) return true; // Enter
if (whichCode == 8) return true; // Delete
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 ValidaHora(vHora)
{
sTamanho= vHora.value.replace( ':', '' );
sTamanho= sTamanho.replace( ':', '' );
//alert(sTamanho);
//alert(sTamanho.length);
if (sTamanho.length>0){
//alert(sTamanho.length);
if (sTamanho.length<6){
alert('Hora Inválida !')
vHora.focus();
vHora.select();
}
} 
tempo=vHora.value;
Hora=tempo.substr(0,2);
Minutos=tempo.substr(3,2);
Segundos=tempo.substr(6,2);
//alert(Hora+'-'+Minutos+'-'+Segundos);
if ((Hora>23)||(Minutos>59)||(Segundos>59))
{
alert('Hora inválida !');
vHora.focus();
vHora.select();
}

}
function FormataHora(vHora, vEvent) {
// Formata o CPF 999.999.999-99
// Chamada: onKeyUp='CPFFormat(this,event)' 
isNav4 = navigator.appName == 'Netscape' && navigator.appVersion < '5';
if (!isNav4) {
if ((vHora.value.length == 2 || vHora.value.length == 5 || vHora.value.length == 7) ) 
if (vEvent.keyCode != 46) // Del 
if (vEvent.keyCode != 8) // Back Space
{
//alert(vHora.value.length);
if (vHora.value.length==2)
vHora.value = vHora.value +':'
if (vHora.value.length==5)
vHora.value = vHora.value +':'

//vHora.value = vHora.value + ((vHora.value.length == 2|| vHora.value.length == 5)?':':':');
}
else
vHora.value = vHora.value.substr(0,vHora.value.length-1); 
}
else 
if (vHora.value.length ==6) 
//alert(vHora.value);
vHora.value = vHora.value.substr(0,2) + ':' + 
vHora.value.substr(2,2) + ':' + 
vHora.value.substr(5,2);

/*CPFFormat*/}
function hora_correta() {
campo = document.forms[0].fim.value;
if(campo.length == 0) {
campo = document.forms[0].fim.value = campo = document.forms[0].fim.value + '00:00:00';
}else if(campo.length < 3) {
campo = document.forms[0].fim.value = campo = document.forms[0].fim.value + ':00:00';
}else if(campo.length < 6) {
campo = document.forms[0].fim.value = campo = document.forms[0].fim.value + ':00';
}
}
// ----------------------------------------------
// Calcula o dígito em Módulo 10 do número dado.
// Os valores de entrada e saída são string.
// ----------------------------------------------
function CalculaDigitoMod10(Dado)
  {
  var i;
  var mult = 2;
  var soma = 0;
  var s = "";
 
  for (i=Dado.length-1; i>=0; i--)
    {
    s = (mult * parseInt(Dado.charAt(i))) + s;
    if (--mult<1)
      {
      mult = 2;
      }
    }
  for (i=0; i<s.length; i++)
    {
    soma = soma + parseInt(s.charAt(i));
    }
  soma = soma % 10;
  if (soma != 0)
    {
    soma = 10 - soma;
    }
  return soma.toString();
  }

                   function Redim() {
               
                      var IFR = document.getElementById('Conteudo');	
	                    //IFR.style.height = 700;
	                   // IFR.style.height = IFR.contentWindow.document.body.scrollHeight+40;
                        alert(parent.document.getElementById("Conteudo").height);
                        
                        // =IFR.contentWindow.document.body.scrollHeight+40;
                        alert(document.body.scrollHeight+40);
                        parent.document.getElementById("Conteudo").height=document.body.scrollHeight+40;
                   //window.frames
                     }
function redimensiona(teste)
{
alert(teste);
alert(window.parent.frames[0].document.body.scrollHeight)

var x1=window.parent.frames[0].document.getElementById(teste).height;
var x2=document.body.scrollHeight;
alert("total "+ x1 + x2);
//alert( window.parent.frames[0].document.getElementById(teste).height + document.body.scrollHeight+10);
window.parent.frames[0].document.getElementById(teste).height = window.parent.frames[0].document.getElementById(teste).height + document.body.scrollHeight+10;
//document.all[teste].height = document.frames[teste].document.body.scrollHeight+10;
}

/******* Redimensiona Iframe ******/
function Redim_Iframe(){               
  var IFR =document.body.offsetHeight; 
 // alert(IFR);
  //alert( window.parent.document.getElementById("Conteudo").height);
    window.parent.document.getElementById("Conteudo").height =IFR+40;
}/** Redim_Iframe **/

/******** Calculo da Idade ********/
function calcular_idade(data,controle){ 

var data2=data.value ;
    //calculo a data de hoje 
    hoje=new Date() 
     

    //calculo a data que recebo 
    //descomponho a data em um array 
    var array_data = data2.split("/") 
    alert(array_data);
alert("1");
    //comprovo que o ano, mes, dia são corretos 
    var ano 
    ano = parseInt(array_data[2]); 

    var mes 
    mes = parseInt(array_data[1]); 

    var dia 
    dia = parseInt(array_data[0]); 

alert('2');


    //subtraio os anos das duas datas 
    idade=hoje.getYear()- ano - 1; //-1 porque ainda nao fez anos durante este ano 

    //se subtraio os meses e for menor que 0 entao nao cumpriu anos. Se for maior sim ja cumpriu 
    if (hoje.getMonth() + 1 - mes < 0) //+ 1 porque os meses comecam em 0 
       //return idade 
    if (hoje.getMonth() + 1 - mes > 0) 
       idade+1 

alert('3');

    //entao eh porque sao iguais. Vejo os dias 
    //se subtraio os dias e der menor que 0 entao nao cumpriu anos. Se der maior ou igual sim que já cumpriu 
    if (hoje.getUTCDate() - dia >= 0) 
       idade + 1 
alert(idade);
window.document.getElementById(controle).value=idade

//    return idade 
} 


/**************************************************************************
Função para simular um Tab quando for pressionado a tecla Enter
Exemplo: onKeyDown="TABEnter()"
Funciona em TEXT BOX,RADIO BUTTON, CHECK BOX e menu DROP-DOWN
**************************************************************************/
function TABEnter(oEvent){
  var oEvent = (oEvent)? oEvent : event;
  var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
  if(oEvent.keyCode==13)
    oEvent.keyCode = 9;
  if(oTarget.type=="text" && oEvent.keyCode==13)
    //return false;
    oEvent.keyCode = 9;
  if (oTarget.type=="radio" && oEvent.keyCode==13)
    oEvent.keyCode = 9;
}
function PreenchimentoObrigatório(texto)
{

}
function CentralizaJanela(Arquivo,NomeDaJanela,X,Y,scroll)
{
var PosVertical=(screen.height -Y)/2;
var PosHorizontal=(screen.width -X)/2;
if (scroll=='true')
window.open(Arquivo,NomeDaJanela,'Height='+Y+',Width='+X+',top='+PosVertical+',left='+PosHorizontal+',scrollbars=yes ')

if (scroll=='false')
window.open(Arquivo,NomeDaJanela,'Height='+Y+',Width='+X+',top='+PosVertical+',left='+PosHorizontal+',resizable=no')
}/* CentralizaJanela*/

function ValidaCPF(campo){


var CPF = campo.value; // Recebe o valor digitado no campo

CPF=CPF.replace(".","");
CPF=CPF.replace(".","");
CPF=CPF.replace("-","");


// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
}
   else{
       DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   }
   else {
        DIGITO[10] = 11 - DIGITO[10];
   }

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   if (DV != DV_INFORMADO) {
   alert("CPF Inválido  ! ");
   campo.focus();
      return false;
   } 
}

function ValidaCNPJ(NomeDoCampo)
{
var CNPJ=NomeDoCampo.value;
var Qtd=CNPJ.length;

CNPJ=CNPJ.replace(".","");
CNPJ=CNPJ.replace(".","");
CNPJ=CNPJ.replace("/","");
CNPJ=CNPJ.replace("-","");

if (Qtd<14 && Qtd>0)
  { 
 alert("Quantidade de dígitos de CNPJ inválido !!!!");
 NomeDoCampo.focus();
  return false;
  }
	
var Dg1=CNPJ.substr(12,1);
var Dg2=CNPJ.substr(13,1);
var a, i, d1,d2,j;

// *****************************
// * calcula o primeiro digito *
// *****************************
j=5;a=0;i=0;d1=0;
for(i=1;i<=12;i++)
  {
	a=a+(CNPJ.substr(i-1,1)*j);
	if (j>2) 
		{j=j-1}
	else
		{j=9}
  }
// fim do For

a=a%11

if (a>1)
  {d1=11-a}
else
  {d1=0}

// ****************************
// * calcula o segundo digito *
// ****************************
j=6;a=0;i=0;d2=0;
for(i=1;i<=13;i++)
  {
	a=a+(CNPJ.substr(i-1,1)*j);
	if (j>2) 
	  {j=j-1}
	else
 	  {j=9}
  }
// fim do For  

a=a%11

if (a>1)
  {d2=11-a}
else
  {d2=0}

if (d1==Dg1 && d2==Dg2)
  {return true}
else
	{
	 alert("CNPJ Inválido !!!");
 NomeDoCampo.focus();
return false
}	
}

function Formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
        src.value += texto.substring(0,1);
  }
}


/*

function CNPJFormat(vCNPJ, vEvent) {
// Formata o CPF 99.999.999/9999-99
// Chamada:  onKeyUp="CNPJFormat(this,event)" 
     if(vEvent.keyCode != 46)    // Del 
        if(vEvent.keyCode != 8){          // Back Space
         if(vCNPJ.value.length == 2) 
          vCNPJ.value = vCNPJ.value.substr(0,2) + "." ;
    
         if(vCNPJ.value.length == 6) 
            vCNPJ.value = vCNPJ.value.substr(0,6) + "." ;       
    
         if(vCNPJ.value.length == 10) 
            vCNPJ.value = vCNPJ.value.substr(0,10) + "/" ;       
       
         if(vCNPJ.value.length == 15) 
            vCNPJ.value = vCNPJ.value.substr(0,15) + "-" ;       
         }      

     

     
// *** CNPJFormat *** //}
/*
function FormataProcesso(vProcesso, vEvent) {
// Formata o Nr. do Processo 9.9999.9999-9
// Chamada:  onKeyUp="FormataProcesso(this,event)" 
  isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";

  if (!isNav4) {
    if ((vProcesso.value.length == 1 || vProcesso.value.length == 6 || vProcesso.value.length == 11)  ) 
      if (vEvent.keyCode != 46)    // Del 
        if (vEvent.keyCode != 8)   // Back Space
          vProcesso.value = vProcesso.value + ((vProcesso.value.length == 1 || vProcesso.value.length == 6)?".":"-");
        else
          vProcesso.value = vProcesso.value.substr(0,vProcesso.value.length-1);   
  }
  else 
    if (vProcesso.value.length == 11) 
      vProcesso.value = vProcesso.value.substr(0,1) + "." + 
                   vProcesso.value.substr(1,4) + "." + 
                   vProcesso.value.substr(5,4) + "-" + 
                   vProcesso.value.substr(10,1);

/ *** FormataProcesso*** /}

function CPFFormat(vCPF, vEvent) {
// Formata o CPF 999.999.999-99
// Chamada:  onKeyUp="CPFFormat(this,event)" 
  isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";

  if (!isNav4) {
    if ((vCPF.value.length == 3 || vCPF.value.length == 7 || vCPF.value.length == 11)  ) 
      if (vEvent.keyCode != 46)    // Del 
        if (vEvent.keyCode != 8)   // Back Space
          vCPF.value = vCPF.value + ((vCPF.value.length == 3 || vCPF.value.length == 7)?".":"-");
        else
          vCPF.value = vCPF.value.substr(0,vCPF.value.length-1);   
  }
  else 
    if (vCPF.value.length == 11) 
      vCPF.value = vCPF.value.substr(0,3) + "." + 
                   vCPF.value.substr(3,3) + "." + 
                   vCPF.value.substr(6,3) + "-" + 
                   vCPF.value.substr(9,2);

/ ***CPFFormat *** /}
/*
function DateCheck(vDate,vRequired) {
// Verifica de a data é válida
// Chamada: onBlur="DateCheck(this,false)"
  retorno = true;



  
  if (vDate.value.substr(1,1) == "/"){
      vDate.value='0' + vDate.value
  }
  
  if (vDate.value.substr(4,1) == "/"){
      vDate.value=vDate.value.substr(0,3)+ '0' + vDate.value.substr(3,6)
  }

   
  //'if (vDate.value.substr(5,1) != "/") retorno = false;
  
  aux = vDate.value;
  
  while (aux.search('/') != -1) 
    aux = aux.replace('/','');
  aux = LRTrim(aux);

  if (aux=='')
    vDate.value = '';
  else
    vDate.value = LRTrim(vDate.value);

  if (vRequired && (vDate.value == ''))  retorno=false;
  if (!vRequired && (vDate.value == '')) return;

  if (retorno) {
    if (navigator.appName == "Netscape" && navigator.appVersion < "5") {
      mDay   = vDate.value.substr(0,2);
      mMonth = vDate.value.substr(2,2);
      mYear  = vDate.value.substr(4,4);
    }
    else {
      mDay   = vDate.value.substr(0,2);
      mMonth = vDate.value.substr(3,2);
      mYear  = vDate.value.substr(6,4);
    }

    if (mYear.length == 2) {
      mToday = new Date();
      checkYear = mToday.getFullYear() + 50; 
      mCheckYear = '20' + mYear;
      mYear = ((mCheckYear >= checkYear) ? ('19' + mYear) : ('20' + mYear));
      vDate.value = mDay+strSeperator+mMonth+strSeperator+mYear;
    }
  }

  if (!retorno || !dataStrValida(mDay,mMonth,mYear)) {
    alert('Data inválida.');
    vDate.focus();
    vDate.select();
  }
/ *** DateCheck *** /}

function dataStrValida(vDia,vMes,vAno) {
// Verifica se a data "vDia"/"vMes"/"vAno" é válida .
  if (isNaN(vDia) || vDia.length < 2) return false;
  if (isNaN(vMes) || vMes.length < 2) return false;
  if (isNaN(vAno) || vAno.length < 2) return false;

  if (vMes < 1 || vMes > 12)
    return false;
  else
    if (vMes == 1 ||  vMes == 3 ||  vMes == 5  ||
        vMes == 7 ||  vMes == 8 ||  vMes == 10 || vMes == 12)
      diamax = 31;
    else
      if (vMes == 4 ||  vMes == 6 ||  vMes == 9 || vMes == 11)
        diamax = 30;
      else
        if ((vAno % 4) == 0)
          diamax = 29;
        else
          diamax = 28;

  if (vDia < 1 || vDia > diamax) return false;
  if (vAno < 1900 || vAno >2078)   return false;

  return true;
/ *** dataStrValida *** /}

 function LRTrim(str) {
  //remove os brancos do inicio e do fim de str
    while (str.length > 0 && str.charAt(0)==" ") str = str.substr(1,str.length);
    while (str.length > 0 && str.charAt(str.length-1)==" ") str = str.substr(0,str.length-1);
    return str;
  / *** LRTrim *** /}
  function DateFormat(vDate, vEvent) {
// Formata a data "DD/MM/YYYY"
// Chamada:  onKeyUp="DateFormat(this,event)" 
  isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";
  strSeperator = '/';

  if (!isNav4) {
    if ((vDate.value.length == 2 || vDate.value.length == 5)  ) 
      if (vEvent.keyCode != 46)    // Del 
        if (vEvent.keyCode != 8)   // Back Space
          vDate.value = vDate.value + strSeperator;   
        else
          vDate.value = vDate.value.substr(0,vDate.value.length-1);   
  }
  else 
    if (vDate.value.length == 8) 
      vDate.value = vDate.value.substr(0,2) + strSeperator + 
                    vDate.value.substr(2,2) + strSeperator + 
                    vDate.value.substr(4,4);

/ ***DateFormat*** /}
function ComparaData(dt1,dt2) {
if (ValData(dt2,false)==false) 
	{
	alert("Data Invalida !");
	dt2.focus();
	dt2.select();
	return false
	}
//ert(dt1);
//alert(dt2);

  // Retorna a data no formato "YYYYMMDD". Obs: Os parâmetros devem ser strings ex: dataStr('1','1','2000'))
  if (dt2.value<dt1.value)
  { 
  alert("DATA FINAL não pode ser menor que a DATA INICIAL !");
  //  if (dia.length == 1)  dia = '0' + dia;
//    if (mes.length == 1)  mes = '0' + mes;
dt2.focus();
    return false;
    }else {
    return true;
    }
  / *** dataStr *** /}
  
  function ValData(vDate,vRequired) {
// Verifica de a data é válida
// Chamada: onBlur="DateCheck(this,false)"
  retorno = true;



  
  if (vDate.value.substr(1,1) == "/"){
      vDate.value='0' + vDate.value
  }
  
  if (vDate.value.substr(4,1) == "/"){
      vDate.value=vDate.value.substr(0,3)+ '0' + vDate.value.substr(3,6)
  }

   
  //'if (vDate.value.substr(5,1) != "/") retorno = false;
  
  aux = vDate.value;
  
  while (aux.search('/') != -1) 
    aux = aux.replace('/','');
  aux = LRTrim(aux);

  if (aux=='')
    vDate.value = '';
  else
    vDate.value = LRTrim(vDate.value);

  if (vRequired && (vDate.value == ''))  retorno=false;
  if (!vRequired && (vDate.value == '')) return;

  if (retorno) {
    if (navigator.appName == "Netscape" && navigator.appVersion < "5") {
      mDay   = vDate.value.substr(0,2);
      mMonth = vDate.value.substr(2,2);
      mYear  = vDate.value.substr(4,4);
    }
    else {
      mDay   = vDate.value.substr(0,2);
      mMonth = vDate.value.substr(3,2);
      mYear  = vDate.value.substr(6,4);
    }

    if (mYear.length == 2) {
      mToday = new Date();
      checkYear = mToday.getFullYear() + 50; 
      mCheckYear = '20' + mYear;
      mYear = ((mCheckYear >= checkYear) ? ('19' + mYear) : ('20' + mYear));
      vDate.value = mDay+strSeperator+mMonth+strSeperator+mYear;
    }
  }

  if (!retorno || !dataStrValida(mDay,mMonth,mYear)) {
    alert('Data inválida.');
//    vDate.focus();
//    vDate.select();
return retorno
  }
// --- DateCheck ---
}
*/
function isNum( caractere )
{
	var strValidos = "0123456789"
	    if ( strValidos.indexOf( caractere ) == -1 )
		return false;
	return true;
}//---- IsNum() ----//

function validaTecla(campo, event)
{
	var BACKSPACE =  8;
	var key;
	var tecla;

	CheckTAB = true;
	if (navigator.appName.indexOf("Netscape") != -1)
		tecla = event.which;
	else
		tecla = event.keyCode;

	key = String.fromCharCode( tecla);

	if ( tecla == 13 )
		return false;
	if ( tecla == BACKSPACE )
		return true;
	return ( isNum(key));
}//----- validaTecla --------//

/*
//-----------------------------------------------
function CEPFormat(vCEP, vEvent) {
// Formata o CEP 99.999-999
// Chamada:  onKeyUp="CEPFormat(this,event)" 
//lert(vCEP.value)

  isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";

  if (!isNav4) {
    if ((vCEP.value.length == 2 || vCEP.value.length == 6)  ) 
      if (vEvent.keyCode != 46)    // Del 
        if (vEvent.keyCode != 8)   // Back Space
          vCEP.value = vCEP.value + ((vCEP.value.length == 2)?".":"-");
        else
          vCEP.value = vCEP.value.substr(0,vCEP.value.length-1);   
  }
  else 
  var cep
    cep=LRTrim(vCEP.value);  
    
    //alert (cep.length);
    if (cep.length == 8) 
      vCEP.value = vCEP.value.substr(0,2) + "." + 
                   vCEP.value.substr(2,3) + "-" + 
                   vCEP.value.substr(5,3);

}//--- CEPFormat ---
*/
function TiraMascaraCEP(campo)
{
	aux = campo.value.substring(0,5) + campo.value.substring(6,9);
	campo.value = aux;
}
function MascaraCEP(campo)

{
		aux = campo.value.substring(0,5) + '-' + campo.value.substring(5,8);
		if (aux=='-'){
		   aux='';
		}   
		campo.value = aux;
}
/*
function MascaraDinheiro2(campo2){
campo=campo2.value
t=Number(campo.length);
  if (t>0){
campo=campo2.value+"00";
t=Number(campo.length);
//alert(campo);
}
aux='';
for (a=0;a<=t;a++){
    aux = aux + campo.substring(a,a+1);
   
    if (t-a==3){
       aux = aux + campo.substring(a,a)+',';
    }  
    else{
        if ((t-a==6)||(t-a==9)||(t-a==12)){
           aux = aux + campo.substring(a,a)+'.';
        }   
    }    
  }
  //alert(aux);
  campo2.value = aux;
  
}*/
function MascaraDinheiro(campo){
t=Number(campo.value.length);
aux='';
for (a=0;a<=t;a++){
    aux = aux + campo.value.substring(a,a+1);
   
    if (t-a==3){
       aux = aux + campo.value.substring(a,a)+',';
    }  
    else{
        if ((t-a==6)||(t-a==9)||(t-a==12)){
           aux = aux + campo.value.substring(a,a)+'.';
        }   
    }    
  }
  campo.value = aux;
}
/*
function TiraMascaraDinheiro2(campo){
t=Number(campo.value.length);
aux='';
for (a=0;a<=t;a++){
    if (campo.value.substring(a,a+1)==','){
       a++
       }
    if (campo.value.substring(a,a+1)=='.'){
       a++
       }
    aux = aux + campo.value.substring(a,a+1);
  }
  //alert(aux);
  //alert(t);
  campo.value = aux.substring(0,aux.length-2);
  //  campo.value=campo.value.substring(0,t-3);
  campo.select();
}
*/
function TiraMascaraDinheiro(campo){
t=Number(campo.value.length);
aux='';
for (a=0;a<=t;a++){
    if (campo.value.substring(a,a+1)==','){
       a++
       }
    if (campo.value.substring(a,a+1)=='.'){
       a++
       }
    aux = aux + campo.value.substring(a,a+1);
  }
  campo.value = aux;
  campo.select();
}
//--------------------------------------------------
// Formata a data "DD/MM/YYYY" 
// Chamada:  OnKeyPress="FormataData(this,event)" 
//           txbData.Attributes.Add("OnKeyPress", "FormataData(this,event);")
 
function FormataData(vDate, vEvent) {
  isNav4 = navigator.appName == "Netscape" && navigator.appVersion < "5";
  strSeperator = '/';
  
  if (!isNav4) {
    if ((vDate.value.length == 2 || vDate.value.length == 5)  ) 
      if (vEvent.keyCode != 46)    // Del 
        if (vEvent.keyCode != 8)   // Back Space
          vDate.value = vDate.value + strSeperator;   
        else
          vDate.value = vDate.value.substr(0,vDate.value.length-1);   
  }
  else 
    if (vDate.value.length == 8) 
      vDate.value = vDate.value.substr(0,2) + strSeperator + 
                    vDate.value.substr(2,2) + strSeperator + 
                    vDate.value.substr(4,4);

}
//----------- ValidaData ------------------//
function ValidaData(vDate,vRequired) {
// Verifica de a data é válida
// Chamada: onBlur="ValidaData(this,false)"
  
  retorno = true;

  aux = vDate.value;

while (aux.search('/') != -1) 
       aux = aux.replace('/','');
      if (aux=='')
         vDate.value = '';
      else

         if (vRequired && (vDate.value == ''))  retorno=false;
         if (!vRequired && (vDate.value == '')) return;

         if (retorno) {
         if (navigator.appName == "Netscape" && navigator.appVersion < "5") {
            mDay   = vDate.value.substr(0,2);
            mMonth = vDate.value.substr(2,2);
            mYear  = vDate.value.substr(4,4);
         }
         else {
           mDay   = vDate.value.substr(0,2);
           mMonth = vDate.value.substr(3,2);
           mYear  = vDate.value.substr(6,4);
         }

         if (mYear.length == 2) {
            mToday = new Date();
           checkYear = mToday.getFullYear() + 50; 
           mCheckYear = '20' + mYear;
           mYear = ((mCheckYear >= checkYear) ? ('19' + mYear) : ('20' + mYear));
           vDate.value = mDay+strSeperator+mMonth+strSeperator+mYear;
         }
      }

      if (!retorno || !ValidaDMA(mDay,mMonth,mYear)) {
         alert('Data inválida.');
         vDate.focus();
         vDate.select();
      }
}// --- ValidaData ---


function ValidaDMA(vDia,vMes,vAno) {
// Verifica se a data "vDia"/"vMes"/"vAno" é válida .
  if (isNaN(vDia) || vDia.length < 2) return false;
  if (isNaN(vMes) || vMes.length < 2) return false;
  if (isNaN(vAno) || vAno.length < 2) return false;

  if (vMes < 1 || vMes > 12)
    return false;
  else
    if (vMes == 1 ||  vMes == 3 ||  vMes == 5  ||
        vMes == 7 ||  vMes == 8 ||  vMes == 10 || vMes == 12)
      diamax = 31;
    else
      if (vMes == 4 ||  vMes == 6 ||  vMes == 9 || vMes == 11)
        diamax = 30;
      else
        if ((vAno % 4) == 0)
          diamax = 29;
        else
          diamax = 28;

  if (vDia < 1 || vDia > diamax) return false;
  if (vAno < 1900 || vAno >2078)   return false;

  return true;
  
}//---- ValidaDMA --


