<!--

// ------------------------------------------------------------------------------------------ //
// Função:    GoBack()
// Descrição: Fazer o "back" do browser
// Entrada:   Quantidade de janelas a retornar. Default: 1
// ------------------------------------------------------------------------------------------ //
function GoBack(Qtde)
{
	if (Qtde==null)
		Qtde=1;
	if (Qtde>0)
		Qtde *= (-1);
	history.go(Qtde);
}

// ------------------------------------------------------------------------------------------ //
// Função:    CheckAll()
// Descrição: Selecionar todos os checkbox da tela, exceto o corrente
// Entrara:   ctrl - referência ao controle corrente: (this)
//            QualF (opcional) - Qual o formulário
//			  VerC - Sai do loop quando encontrar um campo hidden
//			  acao - true=seleciona, false=limpa - utilizado em link, quando não exixtir o ctrl
// ------------------------------------------------------------------------------------------ //
function CheckAll(ctrl, QualF, VerC, acao)
{
	var TForm;
	QualF=CalcQualF(QualF);
	if ( QualF==-2 )
		return;
	else if ( QualF==-1 )
	{
		QualF=0
		TForm=document.forms.length;
	}
	else
		TForm=QualF+1;

	for ( var iForm=QualF; iForm < TForm; iForm++ )
	{
		for ( var i=0; i < document.forms[iForm].elements.length;i++ )
		{
			if ( document.forms[iForm].elements[i].type=="checkbox" )
			{	
				//caso exista o parâmetro acao, não utiliza o controle ctrl para checar
				if(acao!=""){
					document.forms[iForm].elements[i].checked=acao;
				}
				else{
					if ( document.forms[iForm].elements[i]!=ctrl )
						document.forms[iForm].elements[i].checked=ctrl.checked;				
				}			
			}			
			else if  (VerC == 1)
			{ 						
				if (document.forms[iForm].elements[i].type=="hidden")			
				{
					break;
				}
			}

		}
	}
}
// ------------------------------------------------------------------------------------------ //
// Função:    VerCheckAll()
// Descrição: Selecionar todos os checkbox da tela, exceto o corrente
// Entrara:   ctrl - referência ao controle corrente: (this)
//            QualT - nome do botão "Selecionar Todos"
//            QualF (opcional) - Qual o formulário
// ------------------------------------------------------------------------------------------ //
function VerCheckAll(ctrl, QualT, QualF)
{
	var TForm;
	
	QualF=CalcQualF(QualF);
	if ( QualF==-2 )
		return;
	else if ( QualF==-1 )
	{
		QualF=0
		TForm=document.forms.length;
	}
	else
		TForm=QualF+1;

	for ( var iForm=QualF; iForm < TForm; iForm++ )
	{
		var todos=true;
		for ( var i=0; ((i < document.forms[iForm].elements.length) && (todos));i++ )
		{
			if ( (document.forms[iForm].elements[i]==ctrl) && (ctrl.checked==false) )
				todos=false;
		    else if ( document.forms[iForm].elements[i].type=="checkbox" )
			{
				if ( document.forms[iForm].elements[i].name != QualT )
					if ( document.forms[iForm].elements[i].checked==false )
						todos=false;
			}
		}
		if ( typeof(document.forms[iForm].elements[QualT])=="object")
			document.forms[iForm].elements[QualT].checked=todos;
	}
	
}

// ------------------------------------------------------------------------------------------ //
// Acrescenta algumas propriedades aos controles:
// .Indice			: indica o índice na tela para o controle
// .IndiceAnterior	: indica o índice do controle anterior
// .IndicePosterior	: indica o índice para o controle posterior
// .Tam				: tamanho máximo para digitação
// .AutoSkip		: indica se pula para o próximo campo após completar o tamanho do campo
// .Tipo			: indica o tipo de dado
//						'D' -> só dígitos de 0(zero) a 9(nove)
//						'N' -> dígitos de 0(zero) a 9(nove), "."(ponto) e ","(vírgula)
//						'C' -> caracteres de 'a' até 'z' e de 'A' até 'Z'
//						'CPFCNPJ' -> permite formatação especial para CPF ou CNPJ
//						'CPF'     -> permite formatação especial para CPF
//						'CNPJ'    -> permite formatação especial para CNPJ
//						outro -> qualquer caracter entre ascii 32 e ascii 127
// .Saltar			: (reservado) indica o momento de saltar de campo
// ------------------------------------------------------------------------------------------ //

// Carrega índices para o próximo controle e controle anterior
function InicializarIndices()
{
	if (document.CargaInicial==null)
	{
		document.CargaInicial=false;		// Seta para só fazer uma vez por documento
		var ctrlAnterior=null;

		for ( var iForm=0; iForm < document.forms.length; iForm++ )
		{
			var IndAnt=0;
			for ( var i=0; i<document.forms[iForm].elements.length;i++)
			{
				var e=document.forms[iForm].elements[i];
				if ( e.type!="hidden" && e.type!="image" )		
				{
					if ( ctrlAnterior != null )
					{
						ctrlAnterior.IndicePosterior=i;
						ctrlAnterior.FormPosterior=iForm;
					}
					ctrlAnterior=e;
					e.Indice=i;
					e.Form=iForm;
					e.IndiceAnterior=IndAnt;
					if ( iForm==0 )
						e.FormAnterior=0;
					else
						e.FormAnterior=iForm-1;
				}
			}
		}
		//if ( ctrlAnterior!=null )
		//{
		//	ctrlAnterior.IndicePosterior=i-1;
		//}
	}
}

// Colocar o foco em determinado campo
function SetarFoco ( ind, QualF )
	{
	QualF=CalcQualF(QualF);
	
	if (ind == undefined) // Hb 13/05/2008
		ind = 0;
		
	
	if ( QualF==-2 )
		return;
	if ( QualF==-1 )
		QualF=0;
	InicializarIndices();
	
	if ( isNaN(ind) && document.forms[QualF].elements[ind].type!="hidden" && (!document.forms[QualF].elements[ind].disabled))
		document.forms[QualF].elements[ind].focus();
	else
		for (;ind<document.forms[QualF].elements.length;ind++)
			if ( document.forms[QualF].elements[ind].type!="hidden" && (!document.forms[QualF].elements[ind].disabled) )
				break;
		if ( ind<=document.forms[QualF].elements.length )
			document.forms[QualF].elements[ind].focus();
	}

// Limpar o conteúdo do(s) campo(s)
function LimparCampo ( ind, QualF )
	// Para -1, limpa todos os elementos
{

	QualF=CalcQualF(QualF);
	if ( QualF==-2 )
		return;
	if ( QualF==-1 )
		QualF=0;
	if (isNaN(ind))			// Limpa pelo nome
	{
		document.forms[QualF].elements[ind].value="";
	}
	else
	{
		var TForm;
		if ( QualF==-1 )
		{
			QualF=0;
			TForm=document.forms.length;
		}
		else
			TForm=QualF+1;
		var count=-1;
		var bFim=false;
		for ( var iForm = QualF; (!bFim && iForm < TForm); iForm++ )
		{
			for ( var i=0; (!bFim && i < document.forms[iForm].elements.length); i++ )
			{
				if ( document.forms[iForm].elements[i].type=="text" || document.forms[iForm].elements[i].type=="password" )
				{
					count++;
					if ((ind==-1) || (ind==count))
						document.forms[iForm].elements[i].value="";
					if ( ind==count )
						bFim=true;
				}
			}
		}
	}
}

// Verificar qual navegador
function QualNavegador() {
	var u = navigator.userAgent.toLowerCase();
	var s = navigator.appName;	
	if (u.indexOf('safari') != -1) {
		return "SA";	
	
	} else if (u.indexOf('firefox') != -1) {	
		return "FF";
	}		
	if (s == "Microsoft Internet Explorer") {
		return "IE";		
		
	} else if ( s == "Netscape" ) {
		return "NE";		
		
	} else {
		return "";	
	}
}

// Verificar qual a versão do navegador
function QualVersao() {
	var s = navigator.appVersion;
	if ( QualNavegador() == "IE" ) {
		var i = s.search("MSIE");
		s=s.substring(i+5);
		i=s.search(";");
		return s.substring(0,i);		
		
	} else if (QualNavegador() == 'FF') {
       		var u = navigator.userAgent.toLowerCase();
       		//Recuperar o numero da versao
		var firefoxVersionStr = u.substring(u.indexOf('firefox'));		
		//A string retornada tem o formato 1.n.n.n -> transforma em inteiro
		//Devolve as 2 primeiras posicoes
		return parseInt(firefoxVersionStr.replace(/\D/g, '').substring(0,2));
       		
	} else if ( QualNavegador() == "NE" ){
		if(navigator.userAgent.indexOf('Netscape/7.0')!= -1)return "7.0";		
		if(navigator.userAgent.indexOf('Netscape/7.1')!= -1)return "7.1";
		return parseInt(s.substring(0,1));
		
	} else {
		return 0;
	}
}

// Verificar se é Macintosh
function SeMac(){
	var s = navigator.appVersion;
	var v = s.search("Mac");  

	if (v!=-1){
		return "MAC";
	}
	return 0;
}

// Verificar se é Linux
function SeLinux() {
	if (navigator.userAgent.indexOf('Linux') != -1) { 
		return "Linux";
	}
		return 0;
}

// Setar o evento
// ------------------------------------------------------------------------------------------ //
// Função   : SetarEvento
// Descrição: Seta eventos para permitir verificação de digitação e salto de campo
// Entradas:  - ctrl: referência ao controle (this)
//            - Tam:  tamanho máximo do input
//            - Tipo: indica o tipo de campo para digitação
//            - AutoSkip: Indica se faz o "autoskip" ou não: default: true
//            - CasasDec: Somente para o tipo 'N'. Limita o número de casas decimais ( após a vírgula )
// ------------------------------------------------------------------------------------------ //
function SetarEvento(ctrl, Tam, Tipo, AutoSkip, CasasDec )
{
	// Filtra navegadores conhecidos
	var s = QualNavegador();
	if ( s.length==0 )
		return;
	if ( s=="IE" && QualVersao()>7 )
		return;
		
	/*	As linhas abaixo, foram comentadas para funcionar no NS 7.0	
	if ( s=="NE" && QualVersao()>4 )
		return;
	*/
		
	if (ctrl.onkeypressSet==null)
	{
		ctrl.onkeypressSet=true;
		
		if (AutoSkip==null)
			AutoSkip=true;
		if (Tipo!=null)
			Tipo.toUpperCase();
		else
			Tipo="";
		if ( CasasDec==null )
			CasasDec=-1;
		ctrl.Tam=Tam;
		ctrl.Tipo=Tipo;
		ctrl.AutoSkip=AutoSkip;
		ctrl.Saltar=false;
		ctrl.CasasDec=CasasDec;
		InicializarIndices();
		//alert(InicializarIndices());
		var txtFun="";
		if ( ctrl.onkeypress!= null )
			txtFun=ExtrairCodigo(ctrl.onkeypress);
		txtFun += ExtrairCodigo(ValidarTecla);
		var myFun = new Function("evnt", txtFun);
		ctrl.onkeypress=myFun;
		if (QualNavegador()=="IE" && QualVersao()>=5)
		{
			txtFun="";
			if ( ctrl.onkeyup != null )
				txtFun=ExtrairCodigo(ctrl.onkeyup);
			txtFun += ExtrairCodigo(SaltarCampo);
			myFun=new Function("ctrl", txtFun);
			ctrl.onkeyup=myFun;
		}
	}
}

function SaltarCampo(ctrl)
{
	if (ctrl==null)
		ctrl=this;
	if ( ctrl.AutoSkip && ctrl.Saltar)
		if (ctrl.Saltar)
		{
			ctrl.Saltar=false;
			if ( ctrl.IndicePosterior != null )
				SetarFoco(ctrl.IndicePosterior, ctrl.FormPosterior);
		}
}

// Fazer o salto de campo
function ValidarTecla (evnt)
{

	var tk;
    var c;
	// Recebe a tela pressionada
	tk = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
    c=String.fromCharCode(tk);
	c=c.toUpperCase();
	
	// -- Este trecho faz com que o <Enter> tenha a função de <Tab>, mas acho inviável, pois não é possível
	//       colocar o foco em campos do Tipo "image", e, neste caso, nunca seria possível fazer a submissão
	//       do formulário
	// if ( tk == 13 )
	// {
	//	this.Saltar=true;
	//	SaltarCampo(this);
	//	return false;
	// }
	
	// Só aceita teclas alfanuméricas. Não aceita teclas de controle
    if ( tk < 32 )
		return true;
	if ( tk > 127 )
		return false;
	//if (this.value.length==this.Tam)
	//	return false;

	switch ( this.Tipo )
	{
	case "D":
		if ( c<"0" || c>"9" )
			return false;
		break;
	case "N":
		if ( (this.CasasDec==0) && (c==',') )
			return false;
		if ( (c<"0" || c>"9") && (c!="." && c!=",") )
			return false;
		if ( (c==",") && ((this.value.search(",")>-1) || (this.value.length==0)) )
			return false;
		if ( (c==".") && ( (this.value.length==0) || (this.value.search(",")!=-1) || (Conta(this.value,'.')==0 && this.value.length>3) ) )
			return false;
		if ( (c==",") && ( this.value.indexOf('.')!=-1 && this.value.length-this.value.lastIndexOf('.') != 4 ) )
				return false;
		if ( (c==".") && (this.value.length-this.value.lastIndexOf('.') != 4) )
		{
			if  (!((this.value.length < 3) && (this.value.indexOf('.')==-1)))
				return false;
		}
		if ( this.value.indexOf(',')==-1 )
		{
			j=this.value.lastIndexOf(".");
			if ( (j!=-1) && this.value.length>j+3 )
			{
				if ( (c!=',') && (c!='.') )
					return false;
			}
		}
		if ( (this.CasasDec > 0) && (this.value.indexOf(',')>-1) && (this.value.length==this.value.indexOf(',')+1+this.CasasDec) )
			return false;
		break;
	case "C":
		if ( c<"A" || c>"Z" )
			return false;
		break;
	case "CNPJ":
	case "CPF":
	case "CPFCNPJ":
		var bComFormato=true;
		var sTipo=this.Tipo;
		if ( this.value.indexOf(".")==-1 && this.value.indexOf("-")==-1 && this.value.indexOf("/")==-1 && this.value.length==3 && c!="." && c!="-" && c!="/")
			bComFormato=false;
		else if ( this.value.indexOf(".")==-1 && this.value.indexOf("-")==-1 && this.value.indexOf("/")==-1 && this.value.length>3 )
			bComFormato=false;
		if ( (c<"0" || c>"9") && (!bComFormato) )
			return false;
		if ( bComFormato )
		{
			if  ( (c<"0" || c>"9") && (c!="." && c!="-") )
			{
				if ( this.Tipo.indexOf("CNPJ")==-1 )
					return false;
				else if ( c!= "/" )
					return false;
			}
			
			if ( (c=="-") && (this.value.indexOf("-")!=-1) )
				return false;
			if ( (c=="/") && (this.value.indexOf("/")!=-1) )
				return false;
		}
		if ( this.value.indexOf(".")==-1 && this.value.indexOf("-")==-1 && this.value.indexOf("/")==-1 && this.value.length==3 && c!="." && c!="-" && c!="/")
			bComFormato=false;
		if ( bComFormato )
		{
			sTipo="";
			if ( c=='.' )
			{
				if ( this.value.length < 2 )
					return false;
				else if ( (i=this.value.indexOf('.')) != -1 )
					if ( this.value.length-i != 4 )
						return false;
			}
			if ( (this.value.length == 2) && (c=='.') )
				if ( this.Tipo.indexOf("CNPJ")==-1 )
					return false;
				else
					sTipo="CNPJ";
			if (sTipo=="" )
			{
				if ( this.Tipo=="CNPJ" )
					sTipo="CNPJ";
				else if ( this.Tipo=="CPF" )
					sTipo="CPF";
				if ( (this.value.indexOf("/")!=-1) || (this.value.indexOf('.')==2) )
					sTipo="CNPJ";
				else if ( this.value.indexOf("-")!=-1 )
					sTipo="CPF";
			}
			if ( sTipo=="CPF" && c=="/" )
				return false;
			// Limita os dígitos após o "-"
			
			if ( this.value.indexOf("-")!=-1 && ( (this.value.indexOf("-")+3==this.value.length) || c=='.') )
				return false;
			var qtdpto=Conta(this.value,".");
			if ( qtdpto==2 && c=="." )
				return false;
			//if ( qtdpto<2 && (c=="-" || c=="/") )
			//	return false;
			if ( c!="." )
			{
				// Limita máximo de dígitos após a barra "/"
				if ( sTipo=="CNPJ" && c=="-" && this.value.lastIndexOf("/")+5 != this.value.length )
					return false;
				var interpto=0;
				if ( this.value.indexOf("/")==-1 && this.value.indexOf("-")==-1 )
					interpto=3;
				// Tem que ter 3 números entre cada ponto
				var j=this.value.lastIndexOf(".");
				var i=this.value.length;
				var qtdcar=this.value.length-this.value.lastIndexOf(".");
				if ( (j!=-1) && ((qtdcar-1)<=interpto) )
				{
					if ( qtdcar==4 && c!="-" && c!="/")
						return false;
					else if ( qtdcar<4 && (c<"0" || c>"9") )
						return false;
				}
				if ( this.value.indexOf("/") != -1 )
				{
					// Tem que ter 4 dígitos após o "/"
					if ( this.value.lastIndexOf("/")+5 == this.value.length && c!="-")
						return false;
				}
			}
		}
		break;
		
	case "DEC":
		if ( (this.CasasDec==0) && (c==',') )
			return false;
		if ( (c<"0" || c>"9") && (c!=",") )
			return false;
		if ( (c==",") && ((this.value.search(",")>-1) || (this.value.length==0)) )
			return false;
		if ( (this.CasasDec > 0) && (this.value.indexOf(',')>-1) && (this.value.length==this.value.indexOf(',')+1+this.CasasDec) )
			return false;
		break;
	
	case "ALERT":
		if ( c<"A" || c>"Z" )
		{
			alert("A senha de efetivação passou a ser codificada. \nPara mais detalhes, clique sobre o link \"Saiba mais\", ao lado do campo de senha.");  
			return false;
		}
		break;

	case "ALERTLOGIN":
		if ((c<"0" || c>"9") || (c<"A" || c>"Z"))
		{
			alert("A senha de login deverá ser preenchida com a utilização do Teclado Virtual. \nPara mais detalhes, clique sobre o link \"Saiba mais\".");  
			return false;
		}
		break;
		
	default:
		break;
	}

	//verifica se o tamanho do campo, coincide com o solicitado para saltar	
	// se for NS7.0, Safari não decrementa		
	if ((QualNavegador()=="NE" && QualVersao()=="7.0") || QualNavegador()=="SA")	
		this.Saltar=(this.value.length==this.Tam);	
	else
		this.Saltar=(this.value.length==this.Tam-1);	
	
	
	if ( !this.Saltar )
	{
		if ( this.Tipo.indexOf("CPF")!=-1 || this.Tipo.indexOf("CNPJ")!=-1 )
		{
			if ( bComFormato )
			{
				 // Com formatação: para salto, verifica preenchimento de 2 dígitos de controle
				if ( this.value.indexOf("-") != -1 )
				{
					if ( !this.Saltar && this.value.indexOf("-")+2 == this.value.length )
						this.Saltar=true;
				}
			}
			else
			{
				// Sem formatação: para salto, verifica tamanho máximo de digitação (CPF:11 / CNPJ: 15)
				if ( this.Tipo=="CPF" && this.value.length==10 )
					this.Saltar=true;
				else if ( this.value.length==14 )
					this.Saltar=true;
			}
		}
		else if ( this.Tipo=='N' && this.CasasDec>0 && (this.value.indexOf(',')!=-1) && (this.value.indexOf(',')+this.CasasDec==this.value.length) )
			this.Saltar=true;
	}
	
	if ( ((QualNavegador()=="IE") && QualVersao()<5) || (QualNavegador()!="IE") )
		SaltarCampo(this);

	return true;
}


function CheckUnCheck(QualCtrl, QualInd, QualF, Checked)
{
	QualF=CalcQualF(QualF);
	var ctrl;
	
	if ( QualF==-2 )
		return;
	if ( QualF==-1 )
		QualF=0;
	if ( document.forms[0].elements[QualCtrl].length>0 )
	{
		if ( !(isNaN(QualInd)) )
			ctrl=document.forms[QualF].elements[QualCtrl][QualInd];
	}
	else
		ctrl=document.forms[QualF].elements[QualCtrl];
	if ( (ctrl!=null) && (ctrl.type=="radio" || ctrl.type=="checkbox") )
		ctrl.checked=Checked;
}


function Check(QualCtrl, QualInd, QualF)
{
	CheckUnCheck(QualCtrl, QualInd, QualF, true);
}

function UnCheck(QualCtrl, QualInd, QualF)
{
	CheckUnCheck(QualCtrl, QualInd, QualF, false);
}


// Funções de uso comum


// ------------------------------------------------------------------------------------------ //
// Função:    CalcQualF()
// Descrição: Utilização interna
// Entrada:   QualF
// ------------------------------------------------------------------------------------------ //
function CalcQualF(QualF)
{
	if ( QualF==null )
	{

		if ( document.forms.length==0 )
			QualF=-2;
			
		else
			QualF=-1;
	}
	else if ( isNaN(QualF) )
	{
		for ( var i=0; i < document.forms.length; i++ )
		{
			if ( document.forms[i].name==QualF )
			{
				QualF=i;
				break;
			}
		}
		if ( i == document.forms.length )
			QualF=-2;
	}

	return QualF;
}

// ------------------------------------------------------------------------------------------ //
// Função:    Conta()
// Descrição: Calcular a quantidade de ocorrências de um caracter em uma string
// Entrada:   texto, car
// ------------------------------------------------------------------------------------------ //
function Conta(texto, car)
{
	var count = 0;
	var pos = texto.indexOf(car);
	while ( pos != -1 ) 
	{ 
		count++;
		pos = texto.indexOf(car,pos+1);
	}
	return count;
}

function ExtrairCodigo(funct)
{
	var sfunct=funct.toString();
	var s = sfunct.substr(sfunct.indexOf('{')+1);
	s = s.substring(1,s.lastIndexOf('}')-1);
	return s;
}

// ------------------------------------------------------------------------------------------ //
// Função:    Tecla()
// Descrição: Permite somente a entrada de números
// Entrara:   e  - Tecla digitada
// ------------------------------------------------------------------------------------------ //

function Tecla(e)
{
	if(document.all) // Internet Explorer
	var tecla = event.keyCode;

	else if(document.layers) // Nestcape
	var tecla = e.which;

	if(tecla > 47 && tecla < 58) // numeros de 0 a 9
	return true;
	else
{
	if (tecla != 8) // backspace
	return false;
	else
	return true;
}

}

// ------------------------------------------------------------------------------------------ //
// Função:    MandaFoco()
// Descrição: Manda o foco para o campo especificado na chamada da função
// Entrara:   ctrl - referência ao controle corrente: (this)
//			  Tam  - Tamanho do campo 
//            QualC- Qual campo será enviado o foco
// ------------------------------------------------------------------------------------------ //

function MandaFoco(ctrl, Tam, QualC)
{	
	if (ctrl.value.length >= Tam)
	{
	eval('document.forms[0].' + QualC + '.focus()');
	}
}

// ------------------------------------------------------------------------------------------ //
// Função:	FormataCPF()
// Descrição:	Criar mascara no input do campo CPF
// ------------------------------------------------------------------------------------------ //

function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres)
{
 var wTecla, wVr, wTam;
 wTecla = pTeclaPres.keyCode;
 wVr = pForm[pCampo].value;
 wVr = wVr.toString().replace( "-", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( ".", "" );
 wVr = wVr.toString().replace( "/", "" );
 wTam = wVr.length ;

 if (wTam < pTamMax && wTecla != 8) { 
    wTam = wVr.length + 1 ; 
 }

 if (wTecla == 8 ) { 
    wTam = wTam - 1 ; 
 }
   
 if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
  if ( wTam <= 2 ){
    pForm[pCampo].value = wVr ;
  }
  if (wTam > pPosTraco && wTam <= pTamMax) {
        wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
  }
  if ( wTam == pTamMax){
        wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
  }
  pForm[pCampo].value = wVr;
 
 }

}

function Limpa(valor)
{
	campo = valor;
	full = campo.value;

	if (full == "Nº DO DOCUMENTO")
	{
		campo.value = '';
		campo.focus();
	}

}
// ------------------------------------------------------------------------------------------ //
// Função:    enviaForm()
// Descrição: submit no formulário
// Entrara:   form  - nome do formulário
// ------------------------------------------------------------------------------------------ //
function enviaForm(form){			
	eval("document."+form+".submit()");
}	

// ------------------------------------------------------------------------------------------ //
// Função   : Formata
// ------------------------------------------------------------------------------------------ //
function Formata(campo,tammax,teclapres,decimal) { 
  var tecla = teclapres.keyCode; 
  vr 	    = Limpar(campo.value,"0123456789"); 
  tam	    = vr.length; 
  dec	    = decimal 


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 <= dec ){
   campo.value = vr;
 } 

 if( (tam > dec) && (tam <= 5) ){ 
   campo.value = vr.substr( 0, tam - 2 ) + "." + vr.substr( tam - dec, tam );
 } 

 if( (tam >= 6) && (tam <= 8) ){  
   campo.value = vr.substr( 0, tam - 5 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ); 
 } 

 if( (tam >= 9) && (tam <= 11) ){ 
   campo.value = vr.substr( 0, tam - 8 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam ) ; 
 }
 
 if( (tam >= 12) && (tam <= 14) ){ 
    campo.value = vr.substr( 0, tam - 11 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - dec, tam );
 }
 
  if ( (tam >= 15) && (tam <= 17) ){  
    campo.value = vr.substr( 0, tam - 14 ) + "" + vr.substr( tam - 14, 3 ) + "" + vr.substr( tam - 11, 3 ) + "" + vr.substr( tam - 8, 3 ) + "" + vr.substr( tam - 5, 3 ) + "." + vr.substr( tam - 2, tam );
  } 
 } 
} 

// ------------------------------------------------------------------------------------------ //
// Função   : trataBlocoValor
// ------------------------------------------------------------------------------------------ //

function saltaUltimoBloco(objeto, evento, proximo) {
	
	var tecla = window.event ? evento.keyCode : evento.which;

	if (objeto.value.length >= objeto.maxLength && ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105))) {
		proximo.focus();
		proximo.select();
	}

	if (tecla == 86) {
		proximo.focus();
		proximo.select();
	}

	if (tecla == 9) {
		proximo.focus();
		proximo.select();
	}
}


//retira espaços da string
function lTrim(str){
	var resul;
	resul = "";
	for (var i=0; i < str.length; i++) { 
		if (str.substr(i,1)!=' ')
			resul = resul + str.substr(i,1);
	}
	return resul;
}

function trataBlocoValor(objeto, destinoDia, destinoMes, destinoAno, destinoValor) { 
	var a, b, c, d;
    var day, month, year;
    var data, valor;
	var notData, notValor;
	var naoPreenche;
	var aux;

	// Inicializa variaveis
	naoPreenche = 0;
	notData = 0;
	notValor = 0;
	destinoDia.value = "";
	destinoMes.value = "";
	destinoAno.value = "";
	destinoValor.value = "";
	
	// Verifica se o bloco foi preenchido completamente
	aux = objeto;
	aux = lTrim(aux.value);	// Retira os espaços
        if (aux.length != 14) {
		naoPreenche = 1;
	} 
	// Verifica se o bloco é diferente de zeros
	aux = aux * 1;
        if (aux == 0) {
		naoPreenche = 1;
	} 
	
	// Verifica se a data é diferente de zero
	aux = objeto.value.substr( 0, 4 );
	aux = lTrim(aux);	// Retira os espaços
        if ((aux  * 1) == 0) {
		notData = 1;
	} 
	
	// Verifica se o valor é diferente de zero
	aux = objeto.value.substr( 4, 10 );
	aux = lTrim(aux);	// Retira os espaços
        if ((aux  * 1) == 0) {
		notValor = 1;
	} 
	
	// Preenche a data e o valor apenas se todo o bloco tiver sido preenchido	
	if (naoPreenche != 1) {		

		if (notData != 1){
			data = objeto.value.substr(0, 4) * 1;
			a = data + 35710 + 68569 + 2415019;
			b = toInteger(( 4 * a ) / 146097);
			a = a - toInteger(( 146097 * b + 3 ) / 4);
			c = toInteger(( 4000 * ( a + 1 ) ) / 1461001);
			a = a - toInteger(( 1461 * c ) / 4) + 31;
			d = toInteger(( 80 * a) / 2447);
			day = (a - toInteger(( 2447 * d ) / 80));
			a = toInteger(d / 11);
			month = (d + 2 - ( 12 * a ));
			year = (100 * ( b - 49 ) + c + a);
	
			destinoDia.value = padLeft(day, 2);                   
			destinoMes.value = padLeft(month, 2);
			destinoAno.value = year;
		}

		if (notValor != 1){	
			valor = (objeto.value.substring(4) * 1) + "";

			if (valor.length == 1) {
				valor = "00" + valor;
			}

			if (valor.length == 2) {
				valor = "0" + valor;
			}

			destinoValor.value = valor.substr(0, valor.length - 2) + "," + valor.substring(valor.length - 2);
		}

	}
}

//-------------------------------------------------------------------------------


         function toInteger(value) {
            return Math.floor(value);
         }

         function padLeft(value, size) {
            return value < 10 ? "0" + value : value;
         }
// ------------------------------------------------------------------------------------------ //
// Função   : Recebe
// ------------------------------------------------------------------------------------------ //

function Recebe(campoTela){
	 
	 eval("document.forms[0]."+campoTela+".checked = true");
 }

// ------------------------------------------------------------------------------------------ //
 // Função   : RadioLimpa
// ------------------------------------------------------------------------------------------ //

function RadioLimpa(campoLimpaDia, campoLimpaMes, campoLimpaAno){
	 


		eval("document.forms[0]."+campoLimpaDia+".value = '' ");
		eval("document.forms[0]."+campoLimpaMes+".value = '' ");
		eval("document.forms[0]."+campoLimpaAno+".value = '' ");

	
 }


// ------------------------------------------------------------------------------------------ //
// Função   : Limpar
// ------------------------------------------------------------------------------------------ //
function Limpar(valor, validos) { 
  // retira caracteres invalidos da string 
  var result = ""; 
  var aux; 
  for (var i=0; i < valor.length; i++) { 
   aux = validos.indexOf(valor.substring(i, i+1)); 
   if (aux>=0) { 
     result += aux; 
   } 
 } 
  return result; 
} 
// ------------------------------------------------------------------------------------------ //
// Função   : Retira
// ------------------------------------------------------------------------------------------ //

function Retira(campoDia, campoMes, campoAno,campoFoco){



	if(campoDia == ""){
    if(campoMes == ""){
    if(campoAno == ""){

		  eval("document.forms[0]."+campoFoco+".checked = true");
        }
	  }
	}
  }
// -------------------------------------------------------
// ´processaAcoesDataPagamento
// -------------------------------------------------------

function processaAcoesDataPagamento(objetoThis, radioHoje, radioAgendado, editDia, editMes, editAno, proximoElemento, evento) {
	var tecla = window.event ? evento.keyCode : evento.which;

  if(editDia != "" && editMes != ""){
	if (objetoThis == radioHoje) {
		editDia.value = "";
		editMes.value = "";
		editAno.value = "";
	} else {
		radioAgendado.checked = true;
		if (objetoThis == editDia && editDia.value.length >= editDia.maxLength && tecla >= 32) {
			editMes.focus();
			editMes.select();
		} else if (objetoThis == editMes && editMes.value.length >= editMes.maxLength && tecla >= 32) {
			editAno.focus();
			editAno.select();
		} else if (objetoThis == editAno && editAno.value.length >= editAno.maxLength && tecla >= 32) {
			proximoElemento.focus();
		}else if(tecla == 9){
			objetoThis.checked = true;
		}else if (objetoThis != radioAgendado && editDia.value.length + editMes.value.length + editAno.value.length == 0) {
			radioHoje.checked = true;
			radioHoje.focus();
		}
	}
  }
}

// ------------------------------------------------------------------------------------------ //
// Função   : FormataTotal
// ------------------------------------------------------------------------------------------ //
function FormataTotal(campo,tammax,decimal) { 
  vr 	    = Limpar(campo,"0123456789"); 
  tam	    = vr.length; 
  dec	    = decimal;
  

 if ( tam <= dec ){
   campo = vr;
 } 

 if( (tam > dec) && (tam <= 5) ){ 
   campo = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam );
 } 

 if( (tam >= 6) && (tam <= 8) ){  
   campo = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ); 
 } 

 if( (tam >= 9) && (tam <= 11) ){ 
   campo = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
 }
 
 if( (tam >= 12) && (tam <= 14) ){ 
    campo = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
 }
 
  if ( (tam >= 15) && (tam <= 17) ){  
    campo = 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 );
  } 

  return campo;
} 

//************************************************************************
//
//Função para desabilitar campo, dependendo da escolha no radio button
//
//************************************************************************

function desabilitaNasc(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
	 document.forms[0].NUMPASSAPORTE.value  = "";
	document.forms[0].PAISORIGEM.value = "";
	document.forms[0].NUMPASSAPORTE.disabled  = true;
	document.forms[0].PAISORIGEM.disabled  = true;

  }
}

function habilataNasc(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
	document.forms[0].NUMPASSAPORTE.disabled  = false;
	document.forms[0].PAISORIGEM.disabled  = false;
  }
}
 
function desabilitaEnd(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
	document.forms[0].OUTROENDERECO.value  = "";
	document.forms[0].ENDNUMERO.value  = "";
	document.forms[0].COMPLEMENTO.value  = "";
	document.forms[0].BAIRRO.value  = "";
	document.forms[0].CEP.value  = "";
	document.forms[0].CEPCOMPL.value  = "";
	document.forms[0].CIDADE.value  = "";
	document.forms[0].UFPORT.value  = "";

	document.forms[0].OUTROENDERECO.disabled  = true;
	document.forms[0].ENDNUMERO.disabled  = true;
	document.forms[0].COMPLEMENTO.disabled  = true;
	document.forms[0].BAIRRO.disabled  = true;
	document.forms[0].CEP.disabled  = true;
	document.forms[0].CEPCOMPL.disabled  = true;
	document.forms[0].CIDADE.disabled  = true;
	document.forms[0].UFPORT.disabled  = true;

  }
}

function habilitaEnd(campo1){

 if("document.forms[0]."+ campo1 +".ckecked == true"){
	document.forms[0].OUTROENDERECO.disabled  = false;
	document.forms[0].ENDNUMERO.disabled  = false;
	document.forms[0].COMPLEMENTO.disabled  = false;
	document.forms[0].BAIRRO.disabled  = false;
	document.forms[0].CEP.disabled  = false;
	document.forms[0].CEPCOMPL.disabled  = false;
	document.forms[0].CIDADE.disabled  = false;
	document.forms[0].UFPORT.disabled  = false;
  }
}

function isNUMB(c) { 
	if((cx=c.indexOf(","))!=-1){ 
		c = c.substring(0,cx)+"."+c.substring(cx+1); 
	} 
	if((parseFloat(c) / c != 1)){ 
		if(parseFloat(c) * c == 0){ 
			return(1); 
		} 
		else{ 
			return(0); 
		} 
	} 
	else{ 
		return(1); 
	} 
} 

function LIMP(c){ 
	while((cx=c.indexOf("-"))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	while((cx=c.indexOf("/"))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	while((cx=c.indexOf(","))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	while((cx=c.indexOf("."))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	while((cx=c.indexOf("("))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	while((cx=c.indexOf(")"))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	while((cx=c.indexOf(" "))!=-1){ 
		c = c.substring(0,cx)+c.substring(cx+1); 
	} 
	return(c); 
} 

function VerifyCNPJ(CNPJ){ 
	CNPJ = LIMP(CNPJ); 
	if(isNUMB(CNPJ) != 1){ 
		return(0); 
	} 
	else{ 
		if(CNPJ == 0){ 
			return(0); 
		} 
		else{ 
			g=CNPJ.length-2; 
			if(RealTestaCNPJ(CNPJ,g) == 1){ 
				g=CNPJ.length-1; 
				if(RealTestaCNPJ(CNPJ,g) == 1){ 
					return(1); 
				} 
				else{ 
					return(0); 
				} 
			} 
			else{ 
				return(0); 
			} 
		} 
	} 
} 

function RealTestaCNPJ(CNPJ,g){ 
	var VerCNPJ=0; 
	var ind=2; 
	var tam; 

	for(f=g;f>0;f--){ 
		VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; 
		if(ind>8){ 
			ind=2; 
		} 
		else { 
			ind++; 
		} 
	} 

	VerCNPJ%=11; 
	if(VerCNPJ==0 || VerCNPJ==1){ 
		VerCNPJ=0; 
	} 
	else{ 
		VerCNPJ=11-VerCNPJ; 
	} 
	
	if(VerCNPJ!=parseInt(CNPJ.charAt(g))){ 
		return(0); 
	} 
	else{ 
		return(1); 
	} 
} 


function FormataCGC(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); 
		} 
	} 
} 

function validaCNPJ(){ 
	if(VerifyCNPJ(document.forms[0].CNPJ.value) == 1){ 
		alert("CNPJ válido!"); 
	} 
	else{ 
		alert("CNPJ não é válido!"); 
	} 
	document.forms[0].CNPJ.focus(); 
	return; 
}

function abrePopUp(caminho) {
	window.open(caminho,'',scrollbars='yes',resizable='yes',Left='162',top='151');
}

function controlaRadio(campoCheck, campoLimpa){
	campoCheck.checked = true;
	campoLimpa.value = "";
}

// Método WhatOS() acrescentado no RIE devido a necessidade do MPR
// BRW20087804001 - IB - Melhoria na instalação e atualização do Módulo de Proteção
// Ricardo Rufino dos Santos - 19/11/2008
function WhatOS() {
	var u = navigator.userAgent.toLowerCase();

	// Windows Vista
	if (u.indexOf("windows nt 6.0") != -1) {
		return "WIN_VISTA";
	}

	// Windows Server 2003; Windows XP x64 Edition
	if (u.indexOf("windows nt 5.2") != -1) {
		return "WIN_SRV_2003_OR_XP_X64";
	}

	// Windows XP
	if (u.indexOf("windows nt 5.1") != -1) {
		return "WIN_XP";
	}

	// Windows 2000, Service Pack 1 (SP1)
	if (u.indexOf("windows nt 5.01") != -1) {
		return "WIN_2000_SP1";
	}

	// Windows 2000
	if (u.indexOf("windows nt 5.0") != -1) {
		return "WIN_2000";
	}

	// Microsoft Windows NT 4.0
	if (u.indexOf("windows nt 4.0") != -1) {
		return "WIN_NT_4_0";
	}

	// Windows Millennium Edition (Windows Me)
	if (u.indexOf("win 9x 4.90") != -1) {
		return "WIN_ME";
	}

	// Windows 98
	if (u.indexOf("windows 98") != -1) {
		return "WIN_98";
	}

	// Windows 95
	if (u.indexOf("windows 95") != -1) {
		return "WIN_95";
	}

	// Windows CE
	if (u.indexOf("windows ce") != -1) {
		return "WIN_CE";
	}

	return "";
}
