function newPopUp(newurl) 
{
	apopup = window.open(newurl,"Dados",'height=545,width=790,top=0,left=0,location=no,toolbar=no,menubar=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=yes');
}

function ValidaNumeros( )
{
	var checkOK = "0123456789";
	var allValid = true;
	var decPoints = 0;
	var checkStr = consultamun.Municipio.value;
	for (i = 0; i < checkStr.length; i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++) 
		{
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}
	}
	if (!allValid)
	{
		alert("Digite apenas Numeros para o campo CNPJ" );
		return (false);
	}
	return (true);
}

function VerificaNumeros(campo)
{
	var checkOK = "0123456789";
	var allValid = true;
	var decPoints = 0;
	var checkStr = campo.value;
	for (i = 0; i < checkStr.length; i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++) 
		{
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length-1)
			{
				allValid = false;
				break;
			}
		}
	}
	if (!allValid)
	{
		campo.value = campo.value.substring(0,checkStr.length-1);
		return (false);
	}
	return (true);
}

function CriaArray (n)
{
	this.length = n 
}


function escreveData()
{
	NomeDia = new CriaArray(7)
    
	NomeDia[0] = "Domingo"
	NomeDia[1] = "Segunda"
	NomeDia[2] = "Ter&ccedil;a"
	NomeDia[3] = "Quarta"
	NomeDia[4] = "Quinta"
	NomeDia[5] = "Sexta"
	NomeDia[6] = "S&aacute;bado"
	
	NomeMes = new CriaArray(12)

	NomeMes[0] = "janeiro"
	NomeMes[1] = "fevereiro"
	NomeMes[2] = "mar&ccedil;o"
	NomeMes[3] = "abril"
	NomeMes[4] = "maio"
	NomeMes[5] = "junho"
	NomeMes[6] = "julho"
	NomeMes[7] = "agosto"
	NomeMes[8] = "setembro"
	NomeMes[9] = "outubro"
	NomeMes[10] = "novembro"
	NomeMes[11] = "dezembro"
		
	// Captura Dados da Data 

	hoje = new Date()
	dia = hoje.getDate()
	dias = hoje.getDay()
	mes = hoje.getMonth()
	ano = hoje.getYear()
	if (dia < 10)
		dia = "0" + dia
	if (ano < 2000)
		ano = "19" + ano

	document.write (NomeDia[dias] + ", " + dia + " de " + NomeMes[mes] + " de " + ano+"&nbsp;&nbsp;")
}
	
function MascaraData(Campo)
{
	if ((event.keyCode > 47) && (event.keyCode < 58)) 
	{
		if (Campo.value.length == 2)
		{ 
			Campo.value += "/"; 
		}
		if (Campo.value.length == 5)
		{ 
			Campo.value += "/"; 
		}
	}
	else 
	{
		event.returnValue=false;
	}
}
/*
Esta função restringe os valores fornecidos a dígitos
A chamada deve ser feita através do evento ONKEYPRESS da seguinte maneira
onKeyPress="return Numerico();"
*/
function Numerico()
{
	if ((event.keyCode > 47) && (event.keyCode < 58))
	{
		return true;
	}
	else
	{
		return false;
	}
}

/*
Estas funções destinam-se a formatação de campos para valores monetários,
mascarando automaticamente os campos com pontos e vírgulas a chamada deve
ser feita através do evento ONKEYPRESS da seguinte maneira:
onKeyPress="if (!(FmascTempoReal(this))) return false;" onKeyDown="FtrataBackSpace(this)"
O evento ONKEYDOWN é para o tratamento do backspace para reformatação do campo.
*/
function MascaraBackSpaceValorMonetario( dado )
{
	NumDig = dado.value;
	TamDig = NumDig.length;
	TamDig--;
	Contador = 0;
	
	if ((TamDig >= 0) && (event.keyCode == 8))
	{
		numer = "";
		for (i = TamDig; (i >= 0); i--)
		{
			if ( (parseInt( NumDig.substr(i,1) ) >=0 ) && (parseInt(NumDig.substr(i, 1)) <= 9 ) )
			{
				Contador++;
				if ((Contador == 3) && ((TamDig -i) < 4))
				{
					numer = ","+numer;
					Contador = 0;
				}
				else {
					if ((Contador == 3) && ((numer.length) > 4))  
					{
						numer = "."+numer;
						Contador = 0;
					}
				}
				numer = NumDig.substr(i, 1)+numer;
			}
		}
		dado.value = numer;
	}
}

function MascaraValorMonetario(ConteudoCampo)
{
	NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
	maxtamanho = ConteudoCampo.maxlength;
	
//	if( not ( ( maxtamanho > 0 ) && ( maxtamanho < 20 ) ))
//	{
//		maxtamanho = 20;
//	}
//&& (TamDig < maxtamanho)
	if (((event.keyCode) > 47) && ((event.keyCode) < 58)  ) 
	{
		Contador = 0;

		if (TamDig > 1)
		{
			numer = "";
			for (i = TamDig; (i >= 0); i--)
			{
				if (( parseInt( NumDig.substr( i ,1 )) >= 0 ) && ( parseInt( NumDig.substr( i, 1 ))<= 9 ))
				{
					Contador++;
					if ((Contador == 2) && ((TamDig -i) < 3))
					{
						numer = "," + numer;
						Contador = 0;
					}
					else 
					{
						if (Contador == 3)
						{
							numer = "." + numer;
							Contador = 0;
						}
					}
					numer = NumDig.substr(i, 1) + numer;
				}
			}
			ConteudoCampo.value = numer;
		}
		return true;
	}
	else 
	{
		return false;
	}
}

// Só permite que sejam digitados valores númericos para campos
// monetários, e aplica a máscara com 4 casas decimais.
function MascaraValorMonetario4casasdecimais(campo) {
	if(Numerico())
	 {
	NumDig = campo.value;
	TamDig = NumDig.length;
	maxtamanho = campo.maxlength;
	

	if (((event.keyCode) > 47) && ((event.keyCode) < 58)  ) 
	{
		Contador = 0;

		if (TamDig > 1)
		{
			numer = "";
			for (i = TamDig; (i >= 0); i--)
			{
				if (( parseInt( NumDig.substr( i ,1 )) >= 0 ) && ( parseInt( NumDig.substr( i, 1 ))<= 9 ))
				{
					Contador++;
					if ((Contador == 4) && ((TamDig -i) < 5))
					{
						numer = "," + numer;
						Contador = 0;
					}
					else 
					{
						if ((Contador == 3) && ((TamDig -i) > 5))
						{
							numer = "." + numer;
							Contador = 0;
						}
					}
					numer = NumDig.substr(i, 1) + numer;
				}
			}
			
			campo.value = numer;
		}
		return true;
	}
	else 
	{
		return false;
	}
	}
	 else
	 {
		campo.value = campo.value.substring(0,campo.value.length-1);
		alert('Digite apenas números para campos monetários!');
		
	}
}

function mascara_cnpj(campo) {
	if (campo.value.length == 2)
	{ campo.value += "."; }
	if (campo.value.length == 6)
	{ campo.value += "."; }
	if (campo.value.length == 10)
	{ campo.value += "/"; }
	if (campo.value.length == 15)
	{ campo.value += "-"; }
}

//Samuel 01/08/2001

function mascara_cpf(campo) {
	if (campo.value.length == 3)
	{ campo.value += "."; }
	if (campo.value.length == 7)
	{ campo.value += "."; }
	if (campo.value.length == 11)
	{ campo.value += "-"; }
}
//Fim Samuel

// Gustavo M. Gois
// Cria options para serem inseridos em uma lista
function insereOption(nomeLista, text, value) {
	var op = document.createElement("OPTION");
	op.text=text;
	op.value=value;
	nomeLista.add(op);
}
// Exclui todos os itens de uma lista
function excluiItensLista(lista) {
	
	var numItens = lista.length;
	for (i=numItens-1; i>=0; i--) {
		lista.remove(i);
	}
}
// Só permite que sejam digitados valores númericos para campos
// monetários, e aplica a máscara.
function trataValorMonetario(campo) {
	if(Numerico()) {
		MascaraValorMonetario(campo);
	} else {
		campo.value = campo.value.substring(0,campo.value.length-1);
		alert('Digite apenas números para campos monetários!');
	}
}
// Só permite que sejam digitados valores númericos para campos
// CEP, e aplica a máscara.
function trataCEP(campo) {
	if(Numerico()) {
		mascara_cep(campo);
	} else {
		campo.value = campo.value.substring(0,campo.value.length-1);
		alert('Digite apenas números para o CEP!');
	}
}
// Máscara para CEP
function mascara_cep(campo) {
	if (campo.value.length == 5) { 
		campo.value += "-"; 
	}
}

// Criado por Yamara, move linhas entre 2 select´s
function moveEntreListas(cmbOrigem,cmbDestino) {
	var id;
	destList = eval(cmbDestino);
	srcList = eval(cmbOrigem);
	var len = destList.length;
	for(var i = 0; i < srcList.length; i++) 
	{
		if ((srcList.options[i].value != null) && (srcList.options[i].selected)) {
		var found = false;
			for(var count = 0; count < len; count++) {
				if (destList.options[count] != null) {
					if (srcList.options[i].value == destList.options[count].value) {
						found = true;
						break;
  					}
				}
			}
			if (found != true) {
				destList.options[len] = new Option(srcList.options[i].text,srcList.options[i].value); 
				len++;
									
				if (srcList.options[i].value == 'ativo') {
					ativo.style.display = '';
				}
				if (srcList.options[i].value == 'inativo') {
					inativo.style.display = '';
				}
	
				if (srcList.options[i].value == 'pensionista') {
					pensionista.style.display = '';
				}
				if (srcList.options[i].value == 'dependente') {
					dependente.style.display = '';
				}
			}
		}
	}
	excluiLista(cmbDestino); 		
}
	
// Criado por Yamara, exclui a linha selecionada de uma Select
function excluiLista(vObjeto) 
{
	var destList  = eval(vObjeto);
	var len = destList.options.length;
	for(var i = (len-1); i >= 0; i--) {
		if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
								
			if (destList.options[i].value == 'ativo') {
				ativo.style.display = 'none';
			}
			if (destList.options[i].value == 'inativo')	{
				inativo.style.display = 'none';
			}
	
			if (destList.options[i].value == 'pensionista')	{
				pensionista.style.display = 'none';
			}
			if (destList.options[i].value == 'dependente') {
				dependente.style.display = 'none';
			}
			destList.options[i] = null;
		}
	}
}

// Gois 15/07/2001
// Exclui todas as opções de um select
function excluiTodosLista(vObjeto) 
{
	var destList  = eval(vObjeto);
	var len = destList.options.length;
	for(var i = (len-1); i >= 0; i--) {
		destList.options[i] = null;
	}
}
// Gois 15/07/2001
// move todas as opções de um select para outro
function moveTodosEntreListas(cmbOrigem,cmbDestino) {
	var id;
	destList = eval(cmbDestino);
	srcList = eval(cmbOrigem);
	var len = destList.length;
	for(var i = 0; i < srcList.length; i++) 
	{
		var found = false;
		for(var count = 0; count < len; count++) {
			if (destList.options[count] != null) {
				if (srcList.options[i].value == destList.options[count].value) {
					found = true;
					break;
  				}
			}
		}
		if (found != true) {
			destList.options[len] = new Option(srcList.options[i].text,srcList.options[i].value); 
			len++;
									
		}
	}
	excluiLista(cmbDestino); 		
}

// Gois 07/12/2001
// Implementa um array em Javascript
function MeuArray(tamanho) {
	this.length = tamanho
	for(var i=0;i<tamanho;i++) {
		this[i]=""
	}
}
// Seleciona todas as opções de um combo box
function SelecionaLista(lista) {
	for(i=0;i<lista.length;i++) {
		lista.options[i].selected = true
	}
}

// Trata a quantidade maxima de caracteres nos campos monetarios
function LimitaNumDigitos(campo, tamMax) {
	var tmp, pos;
	tmp = campo.value;
	tmp = tmp.replace(",","");
	pos = tmp.indexOf(".");
	while(pos != -1) {
		tmp = tmp.replace(".","");
		pos = tmp.indexOf(".");
	}
	if (tmp.length >= tamMax + 2) {
		campo.value = campo.value.substring(0,campo.value.length-1);
	} else {
		if (!(MascaraValorMonetario(campo))) return false;
	}
}

function MascaraMesAno(Campo1)
{	
	if ((event.keyCode > 47) && (event.keyCode < 58)) 
	{
		if (Campo1.value.length == 2)
		{
			Campo1.value += "/"; 
		}
	}
	else 
	{				
		event.returnValue=false;
	}
}

function altotab(campo1,campo2)
{
	var versao = navigator.appVersion;
	var versaoReal = parseInt(versao.substring(22,26),10);
	if (versaoReal!=5)
	{
		if (campo1.value.length == (campo1.maxLength - 1))
		{	
			campo2.focus();
			if(campo2.type == "text")
			{
		 		campo2.select();
			}
		}
	}
	else
	{
		if (campo1.value.length == (campo1.maxLength))
		{
			campo2.focus();
			if(campo2.type == "text")
			{
		 		campo2.select();
			}
		}
	}
}

function MaskPercent(ConteudoCampo)
{
	NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
	//maxtamanho = ConteudoCampo.maxlength;

	if (((event.keyCode) > 47) && ((event.keyCode) < 58)  ) 
	{
		Contador = 0;
		if (TamDig >= 1 && TamDig < 9)
		{
			numer = "";
			for (i = TamDig; (i >= 0); i--)
			{
				if (( parseInt( NumDig.substr( i ,1 )) >= 0 ) && ( parseInt( NumDig.substr( i, 1 ))<= 9 ))
				{
					Contador++;
					
					if (TamDig < 6)
					{
						if ((Contador == 2) && ((TamDig -i) < 3))
						{
							numer = "," + numer;
							Contador = 0;
						}
					numer = NumDig.substr(i, 1) + numer;
					}
					else
					{
					return false;
					}
				
				}
			}
			ConteudoCampo.value = numer;
		}
		return true;
	}
	else 
	{
		return false;
	}
}

function MaskBackPercent(ConteudoCampo)
{
	NumDig = ConteudoCampo.value;
	TamDig = NumDig.length;
	//TamDig--;
	Contador = 0;
	
	if ((TamDig >= 0) && (event.keyCode == 8))
	{
		numer = "";
		for (i = TamDig; (i >= 0); i--)
		{
			if ( (parseInt( NumDig.substr(i,1) ) >=0 ) && (parseInt(NumDig.substr(i, 1)) <= 9 ) )
			{
				Contador++;
				if ((Contador == 5) && ((TamDig-i) = 5))
				{
					numer = "";
					Contador = 0;
				}
				numer = NumDig.substr(i, 1)+numer;
			}
		}
		ConteudoCampo.value = numer;
	}
}
