function FormataTexto(objeto) 

{ 

    var valor = objeto.value;     

    var LetrasArray = new Array(); 



    LetrasArray[1] = new Array(); 

    LetrasArray[2] = new Array(); 

     

    //Primeira Coluna : Letras Acentuadas e Símbolos 

    LetrasArray[1][1]='á'; 

    LetrasArray[1][2]='ã'; 

    LetrasArray[1][3]='à'; 

    LetrasArray[1][4]='â'; 

    LetrasArray[1][5]='ä'; 

    LetrasArray[1][6]='é'; 

    LetrasArray[1][7]='è'; 

    LetrasArray[1][8]='ê'; 

    LetrasArray[1][9]='ë'; 

    LetrasArray[1][10]='í'; 

    LetrasArray[1][11]='ì'; 

    LetrasArray[1][12]='î'; 

    LetrasArray[1][13]='ï'; 

    LetrasArray[1][14]='ó'; 

    LetrasArray[1][15]='õ'; 

    LetrasArray[1][16]='ò'; 

    LetrasArray[1][17]='ô'; 

    LetrasArray[1][18]='ö'; 

    LetrasArray[1][19]='ú'; 

    LetrasArray[1][20]='ù'; 

    LetrasArray[1][21]='û'; 

    LetrasArray[1][22]='ü'; 

    LetrasArray[1][23]='ç'; 

    LetrasArray[1][24]='Á'; 

    LetrasArray[1][25]='Ã'; 

    LetrasArray[1][26]='À'; 

    LetrasArray[1][27]='Â'; 

    LetrasArray[1][28]='Ä'; 

    LetrasArray[1][29]='É'; 

    LetrasArray[1][30]='È'; 

    LetrasArray[1][31]='Ê'; 

    LetrasArray[1][32]='Ë'; 

    LetrasArray[1][33]='Í'; 

    LetrasArray[1][34]='Ì'; 

    LetrasArray[1][35]='Î'; 

    LetrasArray[1][36]='Ï'; 

    LetrasArray[1][37]='Ó'; 

    LetrasArray[1][38]='Õ'; 

    LetrasArray[1][39]='Ò'; 

    LetrasArray[1][40]='Ô'; 

    LetrasArray[1][41]='Ö'; 

    LetrasArray[1][42]='Ú'; 

    LetrasArray[1][43]='Ù'; 

    LetrasArray[1][44]='Û'; 

    LetrasArray[1][45]='Ü'; 

    LetrasArray[1][46]='Ç'; 

    LetrasArray[1][47]='Ñ'; 

    LetrasArray[1][48]='ñ'; 

    LetrasArray[1][49]='~'; 

    LetrasArray[1][50]='^'; 

    LetrasArray[1][51]='´'; 

    LetrasArray[1][52]='`'; 

     

    //Segunda Coluna : Letras Equivalentes sem acentos 

    LetrasArray[2][1]='a'; 

    LetrasArray[2][2]='a'; 

    LetrasArray[2][3]='a'; 

    LetrasArray[2][4]='a'; 

    LetrasArray[2][5]='ä'; 

    LetrasArray[2][6]='e'; 

    LetrasArray[2][7]='e'; 

    LetrasArray[2][8]='e'; 

    LetrasArray[2][9]='e'; 

    LetrasArray[2][10]='i'; 

    LetrasArray[2][11]='i'; 

    LetrasArray[2][12]='i'; 

    LetrasArray[2][13]='i'; 

    LetrasArray[2][14]='o'; 

    LetrasArray[2][15]='o'; 

    LetrasArray[2][16]='o'; 

    LetrasArray[2][17]='o'; 

    LetrasArray[2][18]='o'; 

    LetrasArray[2][19]='u'; 

    LetrasArray[2][20]='u'; 

    LetrasArray[2][21]='u'; 

    LetrasArray[2][22]='u'; 

    LetrasArray[2][23]='c'; 

    LetrasArray[2][24]='A'; 

    LetrasArray[2][25]='A'; 

    LetrasArray[2][26]='A'; 

    LetrasArray[2][27]='A'; 

    LetrasArray[2][28]='Ä'; 

    LetrasArray[2][29]='E'; 

    LetrasArray[2][30]='E'; 

    LetrasArray[2][31]='E'; 

    LetrasArray[2][32]='E'; 

    LetrasArray[2][33]='I'; 

    LetrasArray[2][34]='I'; 

    LetrasArray[2][35]='I'; 

    LetrasArray[2][36]='I'; 

    LetrasArray[2][37]='O'; 

    LetrasArray[2][38]='O'; 

    LetrasArray[2][39]='O'; 

    LetrasArray[2][40]='O'; 

    LetrasArray[2][41]='O'; 

    LetrasArray[2][42]='U'; 

    LetrasArray[2][43]='U'; 

    LetrasArray[2][44]='U'; 

    LetrasArray[2][45]='U'; 

    LetrasArray[2][46]='C'; 

    LetrasArray[2][47]='N'; 

    LetrasArray[2][48]='n'; 

    LetrasArray[2][49]=''; 

    LetrasArray[2][50]=''; 

    LetrasArray[2][51]=''; 

    LetrasArray[2][52]=''; 



    temp = "" + valor + (String.fromCharCode(window.event.keyCode)); 



    for (i=1; i<=52 ; i++ ) 

    { 

        while (temp.indexOf((LetrasArray[1][i]))>-1) 

            { 

                pos= temp.indexOf((LetrasArray[1][i])); 

                temp = "" + (temp.substring(0, pos) + (LetrasArray[2][i]) + temp.substring((pos + (LetrasArray[1][i].length)), temp.length)); 

            } 

    } 

    if((window.event.keyCode) != 13) 

        { 

            objeto.value = (temp.toUpperCase()); 

            window.event.cancelBubble = true; 

            window.event.returnValue = false; 

        } 



} 





// selObj.options[selObj.selectedIndex].value

function FmascTempoRealDt(ConteudoCampo)

{



if (((event.keyCode) > 47) && ((event.keyCode) < 58))

  {

   NumDig = ConteudoCampo.value;

   

   TamDig = NumDig.length;

   if (TamDig == 2)

      ConteudoCampo.value = NumDig.substr(0,2)+"/";

   else if (TamDig == 5)

      ConteudoCampo.value = NumDig.substr(0,5)+"/";

   else if (TamDig == 9)

       ConteudoCampo.value = NumDig.substr(0,10);



   return(true);}

else return(false)}





function MM_winpopup (url,nome,x,y,r,s) {

 pos_x = ((screen.availWidth/2)-(x/2));pos_y = ((screen.availHeight/2)-(y/2));

 window.open(url,nome,'toolbar=0,location=0,directories=0,sobrebar=0,scrollbars='+s+',resizable='+r+',status=0,top='+pos_y+',left='+pos_x+',width='+x+',height='+y+'');

}



function verificaEmail(email) {



  var arroba = false;

  var ponto = false;



   for (var i = 0; i < email.length; i++) {



		if (email.substring(i-1,i) == "@") {

		  arroba = true;

		}

	

		if (email.substring(i-1,i) == ".") {

		  ponto = true;

		}

	

   }

	

   if ((arroba == false) || (ponto == false)) {



	return false;



   }



   else {



	return true;



   }



}

function goUrl(target,win) {

	if(win) {

		parent[win].location = target;

	} else {

		window.location = target;

	}

}

function selTipo() {

	var f = document.forms.formulario;

	var l = f.elements('recaloc');

	var bol = (f.tipo.value == 'ADM') ? true : false;

	if(l) { 

		if(l.length>0) {

			for (i=0;i<l.length;i++) {

				l[i].disabled = bol;

			}

		} else {

			l.disabled = bol;

		}

	} 

}

function btnCancel(url) {

		window.self.location = url;

}

function exibir (id) {

	if(id) {

		nWin = window.open("exibir.php?id="+parseInt(id),'exibir','toolbar=0,location=0,directories=0,sobrebar=0,scrollbars=yes,resizable=yes,width=540,height=300');

		nWin.focus();

	}

}

function btnRemover (str) {

	var f = window.grid.document.forms.registro;

	if(f) {

		if(!str) {

			var str = 'Deseja realmente remover esses registros?';

		}

		if(confirm(str))

			f.submit();

	}

}

function btnAddAtividade () {

	var f = window.grid.document.forms.registro;

	if(f) {

		f.submit();

	}

}

function piscar(str,n) {

	var lbsts = window.top.lbsts;

	if(n) {

		lbsts.innerHTML = "";

		setTimeout("piscar('"+str+"',false)",700);

	} else {

		lbsts.innerHTML = str;	

		setTimeout("piscar('"+str+"',true)",700);

	}

}







function openWin( windowURL, windowName, windowFeatures ) { 

  return window.open( windowURL, windowName, windowFeatures ) ; 

}



function validar_indique() {

campo = new String();

campo = this.indique.DE.value;

if (campo.length == 0) { alert("Campo  < DE > vazio"); indique.DE.focus(); return false; }

if ( !campo.match("@") || !campo.match(".") ) { alert("Campo  < DE > invalido!!"); indique.DE.focus(); return false; } 

campo = this.indique.PARA.value;

if (campo.length == 0) { alert("Campo < PARA > vazio"); indique.PARA.focus(); return false; }

if ( !campo.match("@") || !campo.match(".") ) { alert("Campo  < PARA >  invalido!!"); indique.PARA.focus(); return false; } 

else  { 

url = 'indicar2.php?DE=' + indique.DE.value + '&PARA=' + indique.PARA.value;

window.open(url,'Indique','width=200,height=256,resizable=0,status=0,menubar=0,scrollbars=0' ) ; }

}



function SoDigito(cNumero) {



var cDigitos = "0123456789";

var digito   = "";

  	

    for (var i=0; i < cNumero.length; i++){;



      digito = cNumero.charAt(i);

	  

      if (cDigitos.indexOf(digito) = -1) {return false};

	  

    }

     form.submit();

}



function CriaArray (n) { 

this.length = n } 



Dados = new CriaArray(10);



function isDigit (c){

	return ((c >= "0") && (c <= "9") || (c=="-") || (c=="."))

}



function isAlpha (s){

var i;



 if (isEmpty(s))

    if (isInteger.arguments.length == 1) return defaultEmptyOK;

    else return (isInteger.arguments[1] == true);



 for (i = 0; i < s.length; i++)

 {

     var c = s.charAt(i);



     if ( isDigit(c) || c == "'") return false;

 }



 return true;

}



function isCaracterInvalid(theField, Conteudo, CampoObrig, msgErroCampoObrig, StringInvalida, msgErroStringInvalida ) {



   if ( (CampoObrig == 'N') && (isEmpty(Conteudo)) ) { 

      warnInvalid( theField, msgErroCampoObrig );

	  return true; 

   }

   

   if (!isEmpty(StringInvalida)) {       

      

       for (i = 0; i < Conteudo.length; i++) {       	          

         var c = Conteudo.charAt(i);

         if ( (StringInvalida.indexOf(c) != -1) || (c == "'") ) {

	        warnInvalid( theField, msgErroStringInvalida );

	        return true;

  		 }		

	   }     

	   return false;

  }

  

}



function isEmpty(s){

	return ((s == null) || (s.length == 0))

}



function comprim(s)	{

	if (s.length < 11)	return true;

}



function warnInvalid (theField, s){

	theField.focus()

	theField.select()

	alert(s)

	return false

}



function isInteger(s) {

var i;

 

 if (isEmpty(s))

  if (isInteger.arguments.length == 1) return defaultEmptyOK;

    else return (isInteger.arguments[1] == true);



 for (i = 0; i < s.length; i++)

 {

     // Check that current character is number.

     var c = s.charAt(i);

     if (!isDigit(c)) return false;

 }



 // All characters are numbers.

return true;

}



function isReal(s) {

var i;

 

 if (isEmpty(s))

  if (isInteger.arguments.length == 1) return defaultEmptyOK;

    else return (isInteger.arguments[1] == true);



 for (i = 0; i < s.length; i++)

 {

     alert(s);

     var c = s.charAt(i);

     if (!isDigit(c)) return false;

 }

 

return true;

}



function ValidaCPF(valor)

{

	var obj;

	obj = valor;

	var straux;

	var dv;

	var nro,cpfdv1,cpfdv2,dv;

	var txtGrupodv;

  //Internet Explorer

	if(parseInt(valor.length,10)==14)

	{

		straux = "" + obj.substring(0,3) +  obj.substring(4,7) + obj.substring(8,11);

		dv = obj.substring(12,14)

	}

	else

	{

		straux = obj.substring(0,9);

		dv = obj.substring(9,11)	

	}

	nro = 0;

	for(var i=0; i<9; i++)

	{

		nro = parseInt(nro,10) + parseInt(straux.charAt(i),10)*(10 - ((parseInt(i,10) + 1) -1));

	}

	cpfdv1 = (parseInt(nro,10)%11)

	if (parseInt(cpfdv1,10)!=0)

	{

		cpfdv1 = 11 - parseInt(cpfdv1,10);

		if (parseInt(cpfdv1,10)==10)

		{

			cpfdv1 = 0;

		}

	}

	straux = straux + cpfdv1;

	nro = 0;

	for(var i=0; i<10; i++)

	{

		nro = parseInt(nro,10) + parseInt(straux.charAt(i),10)*(11 - ((parseInt(i,10) + 1) -1));

	}

	cpfdv2 = (parseInt(nro,10)%11)

	if (parseInt(cpfdv2,10)!=0)

	{

		

		cpfdv2 = 11 - parseInt(cpfdv2,10);

		if (parseInt(cpfdv2,10)==10)

		{

			cpfdv2 = 0;

		}

	}

	txtGrupodv = "" + cpfdv1 + cpfdv2

	if (parseInt(txtGrupodv,10)!=parseInt(dv,10))

	{	

		return false;

	}

	return true;

}

//teste

function FormataCPF(Campo, teclapres)

{

	var tecla = teclapres.keyCode;

	

	var vr = new String(Campo.value);

	vr = vr.replace(".", "");

	vr = vr.replace(".", "");

	vr = vr.replace("-", "");



	tam = vr.length + 1;

	tamCon = vr.length;

	if (tamCon > 11 ) 

			ControleCNPJ(vr,Campo,teclapres);

	if (tecla != 9 && tecla != 8)

		{

		if (tam > 3 && tam < 7)

			Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);

		if (tam >= 7 && tam <10)

			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);

		if (tam >= 10 && tam < 12)

			Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);

		}

		

}

/////////////////////////////////////////////////////////////////

function ControleCPF (vr,Campo,teclapres){

	var CNPJ;

	tam = vr.length;

	if (tam > 11){ 

		FormataCNPJ(Campo,teclapres);

	}

	else{

		for(i=1;i<tam;i++){

			if (tam > 3 && tam < 7)

				CNPJ = vr.substr(0, 3) + '.' + vr.substr(3, tam);

			if (tam >= 7 && tam <10)

				CNPJ = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);

			if (tam >= 10 && tam < 12)

				CNPJ = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);

			}

	document.form.cnpj_cpf.value = CNPJ

	}

}





<!--

function Verifica_campo_CPF(campo) {

var CPF = campo.value; // Recebe o valor digitado no campo



// 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.value = '';

      campo.focus();

      return false;

   } 

}



function piscar(str,n) {

	var lbsts = window.top.lbsts;

	if(n) {

		lbsts.innerHTML = "";

		setTimeout("piscar('"+str+"',false)",700);

	} else {

		lbsts.innerHTML = str;	

		setTimeout("piscar('"+str+"',true)",700);

	}

}



/*******************************************************************

 *                                                                 *

 *   Basico.asp  -  Funções Básicas em JavaScript para uso Geral   *

 *                                                                 *

 *                  V1.5  -  Jan/2000                              *

 *                                                                 *

 *******************************************************************/



/*-----------------------------------------------------------------*

 | ContidoNoDominio    Retorna True se a String dada só contiver   |

 |                     caracteres do domínio dado                  |

 *-----------------------------------------------------------------*/

function ContidoNoDominio(StrDado, Dominio)

	{

	var i, j;

	

	if (StrDado == "") return false;

	

	for (i=0; i<StrDado.length; i++)

		{

		for (j=0; j<Dominio.length; j++)

			{

			if (StrDado.substr(i,1) == Dominio.substr(j,1)) break;

			}

		if (j >= Dominio.length) return false;

		}

	return true

	}

			

/*-----------------------------------------------------------------*

 | ContemDominio    Retorna True se a String dada contiver algum   |

 |                  caractere do domínio dado                      |

 *-----------------------------------------------------------------*/

function ContemDominio(StrDado, Dominio)

	{

	var i, j;

	

	if (StrDado != "")

		{

		for (i=0; i<StrDado.length; i++)

			{

			for (j=0; j<Dominio.length; j++)

				{

				if (StrDado.substr(i,1) == Dominio.substr(j,1)) return true;

				}

			}

		}

		

	return false;

	}

			

/*-----------------------------------------------------------------*

 | IsStrNum     Retorna True se a String dada só contiver números  |

 |                                                                 |

 *-----------------------------------------------------------------*/

function IsStrNum(Dado)

	{

	return ContidoNoDominio(Dado, " 0123456789");

	}

	

/*-----------------------------------------------------------------*

 | IsStrInt	    Retorna True se a String dada só contiver          |

 |              Caracteres para Número inteiro                     |

 *-----------------------------------------------------------------*/

function IsStrInt(Dado)

	{

	return ContidoNoDominio(Dado, " +-0123456789");

	}

			

/*-----------------------------------------------------------------*

 | IsStrFloat   Retorna True se a String dada só contiver          |

 |              Caracteres para Número em Ponto-Flutuante          |

 *-----------------------------------------------------------------*/

function IsStrFloat(Dado)

	{

	return ContidoNoDominio(Dado, " +-0123456789Ee,.");

	}



/*-----------------------------------------------------------------*

 | IsStrCurr    Retorna True se a String dada só contiver          |

 |              Caracteres para Número Currency                    |

 *-----------------------------------------------------------------*/

function IsStrCurr(Dado)

	{

	return ContidoNoDominio(Dado, " +-0123456789,.");

	}



/*-----------------------------------------------------------------*

 | IsStrData    Retorna True se a String dada for uma data válida  |

 |              no formato DD/MM/AAAA                              |

 *-----------------------------------------------------------------*/

function IsStrData(Dado)

	{

    var DiasMes = new Array(31,29,31,30,31,30,31,31,30,31,30,31);

    var Dia, Mes, Ano;

    var Result = false;



	// Pré-analisa o String:

	if (Dado != "")

		{

		if ((Dado.length == 10) && (Dado.substr(2,1) == "/") && (Dado.substr(5,1) == "/"))

			{

			// Levanta Campos:

			if (IsStrNum(Dado.substr(0,2))) Dia = Dado.substr(0,2);

			if (IsStrNum(Dado.substr(3,2))) Mes = Dado.substr(3,2);

			if (IsStrNum(Dado.substr(6,4))) Ano = Dado.substr(6,4);



			// Analisa Ano e Mês:

			if ((Ano > 0) && (Mes >= 1) && (Mes <= 12))

				{

				// Analisa Dia:

				if ((Dia >= 1) && (Dia <= DiasMes[Mes - 1]))

					{

					// Analisa os casos não-bissextos:

					if ((Mes == 2) && ((Ano%4 != 0) || (Ano%100 == 0) && (Ano%400 != 0)))

						{

						if (Dia <= 28) Result = true;

						}

					else

						{

						Result = true;

						}

					}

				}

			}

		}		

	return Result;

	}	



/*-----------------------------------------------------------------*

 | IsStrHora    Retorna True se a String dada for uma data válida  |

 |              no formato HH:MM ou HH:MM:SS                       |

 *-----------------------------------------------------------------*/

function IsStrHora(Dado)

	{

    var Hor, Min, Seg;

    var Result = false;



	// Pré-analisa o String:

	if (Dado != "")

		{

		if (((Dado.length == 5) || (Dado.length == 8)) && (Dado.substr(2,1) == ":"))

			{

			// Levanta Campos:

			if (IsStrNum(Dado.substr(0,2))) Hor = Dado.substr(0,2); else Hor = -1;

			if (IsStrNum(Dado.substr(3,2))) Min = Dado.substr(3,2); else Min = -1;



			// Analisa a Hora:

			if ((Hor >= 0) && (Hor <= 23))

				{

				// Analisa o Minuto:

				if ((Min >= 0) && (Min <= 59))

					{

					// Verifica se tem segundo:

					if (Dado.length == 8)

						{

						// Pré-analisa:

						if (Dado.substr(5,1) == ":")

							{

							// Levanta e verifica segundos:

							if (IsStrNum(Dado.substr(6,2))) Seg = Dado.substr(6,2); else Seg = -1;

							if ((Seg >= 0) && (Seg <= 59))

								{

								Result = true;

								}

							}

						}

					else

						{

						Result = true;

						}				

					}

				}

			}

		}

	return Result;

	}



/*-----------------------------------------------------------------*

 | SeparaNomeArq       Separa o Nome de Arquivo do Path completo   |

 |                                                                 |

 *-----------------------------------------------------------------*/

function SeparaNomeArq(PathDado)

	{

	var i

	

	if (PathDado.length == 0) return "";

	

	for (i=PathDado.length-1; i>=0; i--)

		{

		if (PathDado.substr(i,1) == "\\" || PathDado.substr(i,1) == ":")

			{

			return PathDado.substr(i + 1);

			}

		}

	return PathDado;				

	}



/*-----------------------------------------------------------------*

 | StrD      Acerta a String na Largura dada com                   |

 |           Alinhamento à Direita:                                |

 *-----------------------------------------------------------------*/

function StrD(Dado, Larg)

	{    

    var Result;

	var i;



    if (Dado.length >= Larg)             

        {

        Result = Dado.substr(Dado.length - Larg,Larg);             

		}

    else

		{

		Result = "";

		for (i=Larg-Dado.length; i>0; i--)

			{

			Result = Result + " ";

			}

        Result = Result + Dado;

		}

	return Result;

	}



/*-----------------------------------------------------------------*

 | StrE      Acerta a String na Largura dada com                   |

 |           Alinhamento à Esquerda:                               |

 *-----------------------------------------------------------------*/

function StrE(Dado, Larg)

	{    

    var Result;

	var i;



    if (Dado.length >= Larg)             

        {

        Result = Dado.substr(0,Larg);             

		}

    else

		{

		Result = Dado;

		for (i=Larg-Dado.length; i>0; i--)

			{

			Result = Result + " ";

			}

		}

	return Result;

	}



/*-----------------------------------------------------------------*

 | StrNum    Retorna o valor Numérico em String Dado,              |

 |           formatado na Largura dada:                            |

 *-----------------------------------------------------------------*/

function StrNum(Dado, Larg)

  {

  var Result, sDado, i;



  sDado = Dado.toString();

  if (sDado.length >= Larg)       

    {

    Result = sDado.substr(sDado.length - Larg,Larg);       

    }

  else

    {

    Result = "";

    for (i=Larg-sDado.length; i>0; i--)

      {

      Result = Result + "0";

      }

    Result = Result + sDado.toString();

    }

  return Result;

  }



/*-----------------------------------------------------------------*

 | PassaDominio        Retorna a String dada, somente com os       |

 |                     caracteres do domínio dado                  |

 *-----------------------------------------------------------------*/

function PassaDominio(StrDado, Dominio)

	{

	var i, j, c;

	var Result;

	

	Result = "";

	for (i=0; i<StrDado.length; i++)

		{

		c = StrDado.substr(i,1);

		for (j=0; j<Dominio.length; j++)

			{

			if (c == Dominio.substr(j,1)) break;

			}

		if (j < Dominio.length)

			{

			Result = Result + c;

			}

		}

	return Result;

}



			

/*-----------------------------------------------------------------*

 | BloqueiaDominio     Retorna a String dada retirando os          |

 |                     caracteres do domínio dado                  |

 *-----------------------------------------------------------------*/

function BloqueiaDominio(StrDado, Dominio)

	{

	var i, j;

	

	Result = "";

	for (i=0; i<StrDado.length; i++)

		{

		c = StrDado.substr(i,1);

		for (j=0; j<Dominio.length; j++)

			{

			if (c == Dominio.substr(j,1)) break;

			}

		if (j >= Dominio.length)

			{

			Result = Result + c;

			}

		}

	return Result;

	}



/*******************************************************************

 *  Funções de Filtro para uso com Text-Boxes:                     *

 *  Utilize-as sob os eventos OnKeyUp e OnChange simultaneamente.  *

 *******************************************************************/



function FiltroNum(Objeto)

	{

	Objeto.value = PassaDominio(Objeto.value, "0123456789");

	}

	

function FiltroInt(Objeto)

	{

	Objeto.value = PassaDominio(Objeto.value, "0123456789+-");

	}

			

function FiltroCurr(Objeto)

	{

	Objeto.value = PassaDominio(Objeto.value, "0123456789+-,.");

	}



function FiltroFloat(Objeto)

	{

	Objeto.value = PassaDominio(Objeto.value, "0123456789+-Ee,.");

	}



function FiltroData(Objeto)

	{

	Objeto.value = PassaDominio(Objeto.value, "0123456789/");

	}



function FiltroHora(Objeto)

	{

	Objeto.value = PassaDominio(Objeto.value, "0123456789:");

	}



function FiltroUp(Objeto)

	{

	Objeto.value = Objeto.value.toUpperCase();

	}







//limita tamanho para textarea

//-----------------------------------------------------------------------

function fMaxTamCampo(TamMax,ValCampo)

{	

	Campo = ValCampo.value

	TamanhoCampo = Campo.length

	if (TamanhoCampo > TamMax)

		{ 	

		ValorCampo = Campo.substring(0,TamMax)	

		ValCampo.value = ValorCampo		

		alert("O limite máximo do campo é de " +TamMax+ " caracteres.")

	}	

}

//-----------------------------------------------------------------------





function ValidaEMail(EMail)

  {

  if (EMail.indexOf("@") < 0) return false;

  if (EMail.indexOf(".") < 0) return false;

  if (ContemDominio(EMail, " ;,:/$!#%^&*()+[]{}|\\~`'\"")) return false;

  return true;

  }



/*-----------------------------------------------------------------*

 | isNumber		  Retorna True se o String dada for um número      |

 |                com casas decimais dadas.                        |

 *-----------------------------------------------------------------*/

function isNumber(sNumero, iDecimais)

  {

  var bRet

  var i

  bRet = true

  if (iDecimais > 0)

    {

    if (sNumero.length < iDecimais + 2 || (sNumero.indexOf(".", 0) == -1 && sNumero.indexOf(",", 0) == -1))

      bRet = false

    }

  if (bRet)

    {

    i = 0

    while(i < sNumero.length && bRet)

      {

      if (iDecimais > 0)

        {

        if (i == sNumero.length - (iDecimais + 1))

          {

          if (sNumero.charAt(i) != "." && sNumero.charAt(i) != ",")

            bRet = false

          }

        else

          {

          if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")

            bRet = false

          }

        }

      else

        {

        if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")

          bRet = false

        }

      i++

      }

    }

  return bRet

  }



/*

 Nome........: FmtData

 Descricao...: Insere a máscara de data no campo

 Paramentros.: Dado

 Retorno.....: Retorna o conteúdo formatado em dd/mm/yyyy, não permitindo a digitação

               de caracteres alfa 

*/



function FmtData_old(Dado)

  {

   	var Result = Dado;



	 	for (i=1; i<=Dado.length; i++)

		{			

			if (i == 2)

			{	

				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, i);

			}

			if (i >= 4)

			{

				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2) + "/" + Dado.substr(4, 4);

			}

		}

   return Result;

  }



function FmtData(Dado)

  {

  var Result = Dado;

  var l = Dado.length;



  if((l > 2) && (l < 5))

    {

	Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2);

    }

  if(l >= 5)

    {

	Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 2) + "/" + Dado.substr(4, 4);

	}

  return Result;

  }





/*

 Nome........: FmtDataMesAno

 Descricao...: Insere a máscara de data no campo

 Paramentros.: Dado

 Retorno.....: Retorna o conteúdo formatado em mm/yyyy, não permitindo a digitação

               de caracteres alfa 

*/

function FmtDataMesAno(Dado)

  {

   	var Result = Dado;



	 	for (i=1; i<=Dado.length; i++)

		{			

			if (i == 2)

			{	

				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, i);

			}

			if (i > 2)

			{

				Result = Dado.substr(0, 2) + "/" + Dado.substr(2, 4);

			}

		}

   return Result;

  }

  

  /*

 Nome........: FmtHora

 Descricao...: Insere a máscara de hora no campo

 Paramentros.: Dado

 Retorno.....: Retorna o conteúdo formatado em hh:mm, não permitindo a digitação

               de caracteres alfa 

*/



function FmtHora(Dado)

  {

   	var Result = Dado;



	 	for (i = 1; i <= Dado.length; i++)

		{



			if (i >= 3)

			{

				Result = Dado.substr(0, 2) + ":" + Dado.substr(2, 2);

			}

		}

   return Result;

  }

  

var bPula = true; 

  

function fAtuPulaBlur()

{

	bPula = false;	

}

function fAtuPulaKeyPress()

{

	bPula = true;

	return;

}





function fPulaCampo(campo1,campo2,iTam,tpcampo)

	{

		if(bPula)

		{

			

			if (tpcampo == "data")

				{

			    	Filtro(campo1,'data');

				}

				if (tpcampo == "hora")

				{

			    	Filtro(campo1,'hora');

				}

			if (campo1.value.length >= iTam)

			{ 

				campo2.focus(); 

			}

				

		}

		

		return;

		

	}





/*-----------------------------------------------------------------*

 | CalculaDigitoMod11(Dado, NumDig, LimMult)					   |

 |    Retorna o(s) NumDig Dígitos de Controle Módulo 11 do	   	   |

 |	  Dado, limitando o Valor de Multiplicação em LimMult:         |

 |		    													   |

 |		    Números Comuns::   			iDigSaida	 iCod          |

 |			  CGC					  	  2			   9		   |

 |   		  CPF					  	  2			  12		   |

 |			  C/C,Age - CAIXA			  1 		   9           |

 |			  habitação/bloqueto		  1 		   9           |

 *-----------------------------------------------------------------*/

function CalculaDigitoMod11(Dado, NumDig, LimMult)

  {

  var Mult, Soma, i, n;

    

  for(n=1; n<=NumDig; n++)

    {

    Soma = 0;

    Mult = 2;

    for(i=Dado.length-1; i>=0; i--)

      {

      Soma += (Mult * parseInt(Dado.charAt(i)));

      if(++Mult > LimMult) Mult = 2;

      }

    Dado += ((Soma * 10) % 11) % 10;

    }

  return Dado.substr(Dado.length-NumDig, NumDig);

  }



function CalculaDigitoMod10(sValor)

{

 mult = 2

 soma = 0

 str = new String()

 sValor = sZapDummy(sValor)



 for (t=sValor.length;t>=1;t--)

 {

 str = (mult*parseInt(sMid(sValor,t,1))) + str

 mult--

 if (mult<1) mult = 2

 }



 for (t=1;t<=str.length;t++)

 soma = soma + parseInt(sMid(str,t,1))

 soma = soma % 10

 if (soma != 0)

   soma = 10 - soma

 str = soma   //casting

 return str

}





function Mod10(valor)

{

  val = valor.substring( 0 , valor.length - 1 )

  dig = valor.substring( valor.length - 1 , valor.length )

  str = new String

  fator = 2

  soma = 0

  for(i = val.length; i > 0; i--)

  {

  str = fator * parseInt(val.substring(i, i - 1)) + str

  fator--

  if(fator < 1) fator = 2

  }

  for(i = 0; i < str.length; i++) soma = soma + parseInt(str.charAt(i))

  soma = soma % 10

  if(soma != 0) soma = 10 - soma

  str = soma //aqui existe uma espécie de "casting" (conversão)

  return str == dig

}







function isBissexto(iAno)

{

  var bRet

  bRet = false

  if (iAno % 4 == 0 && (iAno % 100 !=0 || iAno % 400 ==0 ))

    bRet = true

  return bRet

}





function isDate(sData)

{

  var bRet

  var i

  bRet = true

  if (sData.length != 10)

    bRet = false

  if (bRet)

  {

    i = 0

    while (i < sData.length && bRet)

    {

      if (i == 2 || i == 5)

      {

        if (sData.charAt(i) != "/")

          bRet = false

      }

      else

      {

        if (!isNumber(sData.charAt(i), 0))

          bRet = false

      }

      i++

    }

  }

  if (bRet)

  {

    iDia = parseInt(sData.substring(0, 2), 10)

    iMes = parseInt(sData.substring(3, 5), 10)

    iAno = parseInt(sData.substring(6, 10), 10)

    if (iMes < 1 || iMes > 12)

      bRet = false

    if (iAno < 1)

      bRet = false

  }

  if (bRet)

  {

    if (iMes == 1 || iMes == 3 || iMes == 5 || iMes == 7 || iMes == 8 || iMes == 10 || iMes == 12)

    {

      if (iDia < 1 || iDia > 31)

        bRet = false

    }

    if (iMes == 2)

    {

      if (isBissexto(iAno))

      {

        if (iDia < 1 || iDia > 29)

          bRet = false

      }

      else

      {

        if (iDia < 1 || iDia > 28)

          bRet = false

      }

    }

    if (iMes == 4 || iMes == 6 || iMes == 9 || iMes == 11)

    {

      if (iDia < 1 || iDia > 30)

        bRet = false

    }

  }

  return bRet

}





function sRight(sExpressao,iNumeros)

{

  if (sExpressao.length >= iNumeros ) return sExpressao.substring(sExpressao.length - iNumeros,sExpressao.length)

}



function sLeft(sExpressao,iNumeros)

{

  if (sExpressao.length >= iNumeros ) return sExpressao.substring(0,iNumeros)

}



function sMid(sExpressao,iNumeros,iTamanho)

{

  var aux = new String()

  if ((sExpressao.length >= iNumeros) && (iNumeros >=0) && (iTamanho > 0))

  {

    iNumeros--

    aux = sExpressao.substring(iNumeros,iNumeros+iTamanho)

  }

    return aux

}



function sZapDummy(sStringNum)

{

  var sAux = new String()

  for (t=1;t<=sStringNum.length;t++)

  if (!isNaN(parseInt(sMid(sStringNum,t,1))))

    sAux = sAux + sMid(sStringNum,t,1)

  return sAux

}



function Filtro(Objeto,tpCampo) {

    if (navigator.appName.substr(0,9) != "Microsoft") {

        return;

    }



    if (window.event.keyCode == 37 || window.event.keyCode == 8

            || window.event.keyCode == 36 || window.event.keyCode == 46

            || window.event.keyCode == 16 || window.event.keyCode == 9)

        return;



    if (window.event.keyCode == 111 || window.event.keyCode == 191) {

	    if (tpCampo == "data") {

		    if (Objeto.value.length == 3 || Objeto.value.length == 6) {

			    return;

		    }

		    if (Objeto.value.length == 4 || Objeto.value.length == 7) {

			    var newpos = Objeto.value.length - 1;

			    Objeto.value = Objeto.value.substring(0,newpos);

			    return;

		    }

	    }

    }



    if (window.event.keyCode == 39) {

	    if (tpCampo == "data") {

            if (Objeto.value.length == 2 || Objeto.value.length == 5) {

			    Objeto.value = Objeto.value + "/";

            }

        }

        return;

    }



	if (tpCampo == "orgaoEmissor") {

    	Objeto.value = PassaDominio(Objeto.value, "0123456789ABCDEFGHIJLMNOPQRSTUVXZabcdefghijlmnopqrstuvxz");

		Objeto.value = FmtLacre(Objeto.value);

		return;

	}



	Objeto.value = PassaDominio(Objeto.value, "0123456789");

	if (tpCampo == "data") {

		Objeto.value = FmtData(Objeto.value);

	}

	if (tpCampo == "DataMesAno") {

		Objeto.value = FmtDataMesAno(Objeto.value);

	}

	if (tpCampo == "valor") {	

		Objeto.value = FmtCurr(Objeto.value);

	}

	if (tpCampo == "hora") {	

		Objeto.value = FmtHora(Objeto.value);

	}

	if (tpCampo == "lacre") {	

		Objeto.value = FmtLacre(Objeto.value);

	}

}



function FmtLacre(Dado)

{

	var Result, i;



	Dado = TiraTracos(Dado);



	if (Dado.length > 2)

	{

		Result = "-" + Dado.substr(Dado.length-2, 2);

		Result = Dado.substr(0, Dado.length-2) + Result;

	}

	else

	{

		Result = Dado;

	}

	return Result;

}

  

function FmtCurr(Dado)

  {



  var Result, i;

  

  if (Dado.length > 2)

    {

    Result = "," + Dado.substr(Dado.length-2, 2);

    for (i=5; i<=Dado.length; i+=3)

      {

      Result = Dado.substr(Dado.length-i, 3) + Result;

      if (Dado.length > i) Result = "." + Result;

      }

    Result = Dado.substr(0, Dado.length-i+3) + Result;

    }

  else

    {

    Result = Dado;

    }

  return Result;

}



function TiraPontos (NumeroFormatado)

{

    var s

    s  = NumeroFormatado.split (".");

    return s.join("");

}



function TiraVirgula (NumeroFormatado)

{

    var s

    s  = NumeroFormatado.split (",");

    return s.join("");

}



function TiraTracos (NumeroFormatado)

{

    var s

    s  = NumeroFormatado.split ("-");

    return s.join("");

}



function printit()

{  

	window.print();

}



function FiltraTexto(Dado) {

	var r = ''

	var asc1 = new String()

	var asc2 = new String()

	asc1 = 'áàãäâÁÀÃÄÂéèêëÉÈÊËìíîïÌÍÎÏòóôõöÒÓÔÕÖùúûüÙÚÛÜýÝçÇñÑ'

	asc2 = 'AAAAAAAAAAEEEEEEEEIIIIIIIIOOOOOOOOOOUUUUUUUUYYCCNN'

	for(i=0;i<=Dado.length-1;i++)

	    {

		c = Dado.charAt(i)

		for(j=0;j<=asc1.length-1;j++)

		if(Dado.charAt(i) == asc1.charAt(j))

			c = asc2.charAt(j)

			if((c<'0' || c>'9') && (c<'A' || c>'Z') && (c<'a' || c>'z') && (c != ' ') && (c != ',') && (c != '.') && (c != '/'))

			{

			return "";

			}

			r = r + c

		}

	return r.toUpperCase();

}



/* --------------------------------------------------------

	Nome: gfunCalcCEI

	Descricao: Verifica se o nro do CEI eh valido

	Parametros: Numero do CEI sem Formatacao

-------------------------------------------------------- */ 



function gfunCalcCEI(strCei) 

{

	var numLen;

	var strChar;

	var numSomat;

	var strAux;

	var strCharAux;

	var strSomat;

	var numLenumSomat;

	var numAux;

	var numDigit;



	numLen = strCei.length;



	//Verifica se o tamanho do CEI eh de 12 posicoes

	if	(numLen != 12) 

	{

		return false;

	}



	// Calcula o digito verificador

	strAux = "74185216374"

	numSomat = 0;

	for (i = 0; i < 11; i++) 

	{

		strChar = strCei.charAt(i)

		strCharAux = strAux.charAt(i)

		numSomat += (eval(strChar)) * (eval(strCharAux));

	}

	strSomat = numSomat + "";

	numLenumSomat = strSomat.length;

	numAux = parseInt(strSomat.charAt(numLenumSomat - 1)) + parseInt(strSomat.charAt(numLenumSomat - 2));

	

	if	((numAux >= 11) && (numAux <= 18))

		numDigit = 20 - numAux;

	else

		if	(numAux == 10)

			numDigit = 1;

		else

			numDigit = 10 - numAux;

	

	if (numDigit == 10) 

	{

	   numDigit = 1

	}



	//	Condicao para atender ao SFG. Aceitar o digito informado (0 ou 1), mesmo que o

	//	resultado do calculo seja igual a 1

	

	if ((strCei.charAt(11) < "2")) 

	{

	 if ((numDigit == 0) || (numDigit == 1)) 

	 {

		numDigit = eval(strCei.charAt(11));

		return true;

	 }

	}

	

	// Fim-condicao

	if	(eval(strCei.charAt(11)) != numDigit) 

	{

		return false;

	}



	return true;

}



/*--------------------------------------------

'nome...: Recarrega combo com valor informado

----------------------------------------------*/

function recCombo(campo,valor)

{

	for (i=0;i < eval(campo + '.options.length') ;i++)

	{

		if (eval(campo + '[i].value') == valor)

		{

			eval(campo + '.options[i].selected = true');

			break;

		}

	}

	return;

}



/*-----------------------------------------------------------------*

'nome...: RTRIM

 *-----------------------------------------------------------------*/

function RTrim(StrDado) {

    TemEspaco = true;



    sCampo = StrDado

	if (sCampo != "") {

        while (TemEspaco) {



            if (sCampo.substr(sCampo.length - 1,1) == ' ') {

                sCampo = sCampo.substr(0,sCampo.length - 1);

            }

            else {

                TemEspaco = false;

            }

        }

    }

	return sCampo;

}



var iTimerOtico;

var oldServOtico;

function SaibaMaisOtico() {

    oldServOtico = document.FormMenu.serv.value;

    document.FormMenu.serv.value = "LeituraOptica";

    TelaAjuda();

    iTimerOtico = window.setTimeout("atualizaSaibaMais()", 2000);

    document.FormMenu.serv.value = oldServOtico;

}



function atualizaSaibaMais() {

    document.FormMenu.serv.value = oldServOtico;

    window.clearTimeout(iTimerOtico);

}



function fPulaCampoOtico(nomeform,campo1,campo2,tam,tpcampo) {

    if (!eval('document.' + nomeform + '.chkLeitorOptico.checked')) {

        campo1 = eval('document.' + nomeform + '.' + campo1);

        campo2 = eval('document.' + nomeform + '.' + campo2);

        fPulaCampo(campo1,campo2,tam,tpcampo);

    }

    return;

}



function verificaAgend(nomeForm,dataAgend) {

    if (dataAgend != "") {

        nomeForm.rdoAgendamento[1].checked = true;

    }

}



function alteraAgend(nomeForm, dataAgend) {

    if (nomeForm.rdoAgendamento[1].checked) {

        dataAgend.disabled = false;

        dataAgend.focus();

    } else {

        dataAgend.value = "";

        dataAgend.disabled = true;

    }

}



function verificaBrowserImpressao() {

    if (navigator.appName.substr(0,9) != "Microsoft") {

	    window.print();

	    history.back();

    }

}



function imprimeDireto(nomeForm, uri) {

	if (navigator.appName.substr(0,9) == "Microsoft") {

		printHidden(uri);

    } else {

	    nomeForm.action=uri;

		nomeForm.submit();

	}

}



function imprimeTeste(nomeForm, uri) {

    nomeForm.action=uri;

	nomeForm.submit();

}



function focoProximoElemento(nomeForm, nomeCampo) {    

    for (i = 0; i < nomeForm.length-1; i++) {        

        if (nomeForm.elements[i].name == nomeCampo) {                        

            if ((nomeForm.elements[i+1].type != "hidden") 

                    && (nomeForm.elements[i+1].name != nomeCampo)) {                

                nomeForm.elements[i+1].focus();

                break;

            } else {

                nomeCampo = nomeForm.elements[i+1].name;

            }

        }

    }

}



function limpaCamposTxt(nomeForm) {

    for (i = 0; i < nomeForm.length; i++) {

        if (nomeForm.elements[i].type == "text") {

            nomeForm.elements[i].value = "";

        }

    }

}



/* Retorna o DV do IPTU (tipo="1") / ISS (tipo="0") */

function calculaDAC11A(numero, tipo) {

    var intPeso = 2;

    var intCalcula = 0;



    for (var intPosicao = (numero.length-1); intPosicao >= 0; intPosicao --) {

        // soma o produto das multiplicações do dígito pelo peso

        intCalcula += (intPeso * parseInt(numero.charAt(intPosicao), 10));

        intPeso ++;

        if (intPeso == 11) {

            intPeso = 1;

        }

    }

    

    // divide a soma dos produtos por 11

    intCalcula = intCalcula % 11;

    

    // monta retorno a partir de intCalcula

    if (intCalcula == 0) {

        return "0";

    } else if (intCalcula == 1) {

        return tipo;

    } else {

        return 11 - intCalcula;

    }

}



function CalculaDigitoMod1129(valor) {

    mult = 2;

    somaTotal = 0;

    for (j=valor.length;j>0;j--) {

        soma = (mult * parseInt(valor.substring(j,j-1),10));

        if (parseInt(soma,10) > 9) {

            soma = soma.toString();

            soma = parseInt(soma.substring(0,1),10)

                    + parseInt(soma.substring(1,2),10);

        }

        somaTotal = somaTotal + soma;

        mult++;

        if (mult > 9) mult = 2;

    }

    resto = somaTotal % 11;



    if (resto == 0 || resto == 1) {

        dig = 1;

    } else {

        dig = 11 - resto;

    }

    return dig;

}



function SomenteNumeros(KeyPress, Campo){

objField = eval(Campo);



var Letras = '01234567890';

if ((Letras.search(String.fromCharCode(KeyPress)) != -1) && (objField.value.length < 9)){

	if (objField.value.length == 5) objField.value = objField.value + "-";

}else 

	event.returnValue = false;

}












