<!--

	VerifiqueTAB=true;
	//passar campo e tamanho do campo
	//opcional pulo para quantos quer pular
	function Mostra(quem, tammax, pulo) {
		if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
			var i=0,j=0, indice=-1;
			for (i=0; i<document.forms.length; i++) {
				for (j=0; j<document.forms[i].elements.length; j++) {
					if (document.forms[i].elements[j].name == quem.name) {
						indice=i;
						break;
					}
				}
				if (indice != -1)
			         break;
			}
			for (i=0; i<=document.forms[indice].elements.length; i++) {
				if (document.forms[indice].elements[i].name == quem.name) {
					while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
							(i < document.forms[indice].elements.length) ) {
								i++;
					}
					document.forms[indice].elements[(i+1+pulo)].focus();
					VerifiqueTAB=false;
					break;
				}
			}
		}
	}

	function PararTAB(quem) {
		 VerifiqueTAB=false;
	}

	function ChecarTAB() {
		VerifiqueTAB=true;
	}
	
	function SetaFoco() {
		var i=0, j=0;
		for (j=0; j<document.forms.length; j++) {
			for (i=0; i<document.forms[j].elements.length; i++) {
				if (document.forms[j].elements[i].name == "FOCO") {
					document.forms[j].elements[i].focus();
					break;
				}
			}
		}
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0 
   window.open(theURL,winName,features);
}

// ------------------------------------------------------------------------------------------ //
// 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
// ------------------------------------------------------------------------------------------ //
//Estrada: VerC  -  Sai do loop  quando encontrar um campo hidden


function CheckAll(ctrl, QualF, VerC)
{
	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" )
			{
				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 ( QualF==-2 )
		return;
	if ( QualF==-1 )
		QualF=0;
	InicializarIndices();
	if ( isNaN(ind) && document.forms[QualF].elements[ind].type!="hidden" )
		document.forms[QualF].elements[ind].focus();
	else
		for (;ind<document.forms[QualF].elements.length;ind++)
			if ( document.forms[QualF].elements[ind].type!="hidden" )
				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 s = navigator.appName;
	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 parseInt(s.substring(0,i+1));
	}
	else if ( QualNavegador() == "NE" )
		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;
}

// 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()>6 )
		return;
	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 SetarEvento_Backsa(ctrl, Tam, Tipo, AutoSkip, CasasDec )
{
	// Filtra navegadores conhecidos
	var s = QualNavegador();
	if ( s.length==0 )
		return;
	if ( s=="IE" && QualVersao()>5 )
		return;
	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();
		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;
	}
	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()");
}	



function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

//To use one of these functions, just make a call and pass the radio button or check box object. For example, if you want to find out if at least one check box is selected and the check box field name is MyCheckBox, then write the following statements:

//var checkBoxArr = getSelectedCheckbox(document.forms[0].MyCheckBox);
//if (checkBoxArr.length == 0) { alert("No check boxes selected"); }


function soNumero(myfield, e, dec)
{
	var key;
	var keychar;
	if (dec == null) dec = "";
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
	    (key==9) || (key==13) || (key==27) )
	   return true;
	// numbers
	else if ((("0123456789" + dec).indexOf(keychar) > -1))
	   return true;
	// decimal point jump
	else
	   return false;
}
function mascaraData(objeto){
	campo = eval(objeto);

	separador = '/';
	conjunto1 = 2;
	conjunto2 = 5;

	if(campo.value.length == conjunto1) {
		campo.value = campo.value + separador;
	}
	if(campo.value.length == conjunto2) {
		campo.value = campo.value + separador;
	}
}
function checkDate(txtField) {
	 NumDig = 4;
	 valor = txtField.value;
     
	 if (valor.length > 0){
	     if (valor.charAt(2) != '/' || valor.charAt(5) != '/' || valor.length != 10){
	        alert('Formato de data inválido!\nFormato correto: DD/MM/AAAA!');
			txtField.select();
	        txtField.focus();
	        return false;        
	     }
	     else{
		     var Dia,Mes,Ano;
		     
			 Dia = (valor.charCodeAt(0) == 48)? parseInt(valor.substring(1,2)) : parseInt(valor.substring(0,2));
			 Mes = (valor.charCodeAt(3) == 48)? parseInt(valor.substring(4,5)) : parseInt(valor.substring(3,5));
		     Ano = parseInt(valor.substring(6,valor.length));
		     
			 var AnoBiss = ((Ano%4 == 0 && Ano%100 != 0) || Ano%400 == 0);
		
		     if ((Dia < 1 || Dia > 31 || isNaN(Dia)) || (Mes < 1 || Mes > 12 || isNaN(Mes)) || ((NumDig == 4 && Ano < 1900) || isNaN(Ano)) || (((Mes == 2 && AnoBiss && Dia > 29) || (Mes == 2 && !AnoBiss && Dia > 28)) || ((Mes == 4 || Mes == 6 || Mes == 9 || Mes == 11) && Dia > 30))){ 
		             alert('A data fornecida está incorreta!');
					 txtField.select();
                     txtField.focus();
		             return false;
		     }
		}
	}
}




function isEmail(str) { 
   // are regular expressions supported? 
   var supported = 0; 
   if (window.RegExp) { 
     var tempStr = "a"; 
     var tempReg = new RegExp(tempStr); 
     if (tempReg.test(tempStr)) supported = 1; 
   } 
   if (!supported)  
     return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); 
   var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)"); 
   var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); 
   return (!r1.test(str) && r2.test(str)); 
 }



//-->

