* name="xxx".....
* onkeypress="return Mascara(document.rcfDownload, 'str_cep', '99999-999', event);">
* Observação: As máscaras podem ser representadas
* como os exemplos abaixo:
* CEP -> 99999-999
* CPF -> 999.999.999-99
* CNPJ -> 99.999.999/9999-99
* C/C -> 999999-!
* Tel -> (99) 9999-9999
* Hora -> 99:99:99 ou 99:99
* Número -> R$ 15.000,00
* Formato do jeito que quiser usando e abusando dos exemplos acima.
***/
function Mascara(a, strField, sMask, s) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
objForm = document.forms[0];

if(document.all) { // Internet Explorer
nTecla = event.keyCode; }
else if(document.layers) { // Nestcape
nTecla = event.which;
}

if(nTecla == 39) return false;

sValue = objForm[strField].value;

// Limpa todos os caracteres de formataï¿½ï¿½o que
// jï¿½ estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ",", "" );
sValue = sValue.toString().replace( "$", "" );
sValue = sValue.toString().replace( "R", "" ); 
fldLen = sValue.length;
mskLen = sMask.length; // = 5

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"));
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "));
bolMask = bolMask || ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "$") || (sMask.charAt(i) == "R") || (sMask.charAt(i) == ","));

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}


// FUNCÕES PARA MOSTRAR E ESCONDER <TABLES>
//-----------------------------------------
function mostraTbl(tbl){
	tbl.style.display="block";
}
//if (form1)
function escondeTbl(tbl){
	tbl.style.display="none";
}


// FUNCÕES PARA VALIDAR CAMPOS DEPESQUISA DE ENTIDADES COMPONENTES
//-------------------------------------------------------------------
function validaFrmPesqEntComponentes(pag){
	if (frmGeral.cnpjPesq.value=="" && frmGeral.razaosocialPesq.value=="" && frmGeral.regancinePesq.value=="") {
		window.alert("Escolha e preencha uma forma de pesquisa.");
	} else {
		window.open("/protRegistro/jsp/cadastro/EntidadesEncontradas.jsp?pag="+pag+"","entidadesEncontradas","width=580,height=150");
	}	
}

function validaFrmPesqEntComponentes1(pag){
	if (frmCadDeEmp.cnpjPesq.value=="" && frmCadDeEmp.razaosocialPesq.value=="" && frmCadDeEmp.regancinePesq.value=="") {
		window.alert("Escolha e preencha uma forma de pesquisa.");
	} else {
		window.open("/protRegistro/jsp/cadastro/EntidadesEncontradas.jsp?pag="+pag+"","entidadesEncontradas","width=580,height=150");
	}	
}

function validaFrmPesqEntComponentes2(pag){
	if (frmGeralGrupo.cnpjPesq.value=="" && frmGeralGrupo.razaosocialPesq.value=="" && frmGeralGrupo.regancinePesq.value=="") {
		window.alert("Escolha e preencha uma forma de pesquisa.");
	} else {
		window.open("/protRegistro/jsp/cadastro/EntidadesEncontradas.jsp?pag="+pag+"","entidadesEncontradas","width=580,height=150");
	}	
}

function validaFrmPesqEntComponentesComplexo(pag){
	if (frmGeralGrupo.cnpjPesq.value=="" && frmGeralGrupo.razaosocialPesq.value=="" && frmGeralGrupo.regancinePesq.value=="") {
		window.alert("Escolha e preencha uma forma de pesquisa.");
	} else {
		window.open("/protRegistro/jsp/cadastro/EntidadesEncontradas.jsp?pag="+pag+"","entidadesEncontradas","width=580,height=150");
	}	
}


// FUNCÕES PARA VALIDAR FORMULÁRIOS DE PESQUISA
//-----------------------------------------------------
function validaFrmPesq() {
	if(frmGeral.cnpj.value=="" && frmGeral.outros.value=="") {
		window.alert("Preencha o campo de pesquisa.");
	} else if (frmGeral.situacaoControle.options.value==""){
		window.alert("Escolha uma situação.");
	} else {
		mostraTbl(tblResPesquisa);
		mostraTbl(tblRes1);
		mostraTbl(tblRes2);
		mostraTbl(tblRes3);
		mostraTbl(tblRes4);
	}
}

function validaFrmPesq1() {
	if(frmGeral.outros.value=="") {
		window.alert("Preencha o campo de pesquisa.");
	} else if (frmGeral.situacaoControle.options.value==""){
		window.alert("Escolha uma situação.");
	} else {
		mostraTbl(tblResPesquisa);
		mostraTbl(tblRes1);
		mostraTbl(tblRes2);
		mostraTbl(tblRes3);
		mostraTbl(tblRes4);
	}
}

function validaFrmPesq2() {
	if(frmGeral.cpf.value=="" && frmGeral.outros.value=="") {
		window.alert("Preencha o campo de pesquisa.");
	} else if (frmGeral.situacaoControle.options.value==""){
		window.alert("Escolha uma situação.");
	} else {
		mostraTbl(tblResPesquisa);
		mostraTbl(tblRes1);
		mostraTbl(tblRes2);
		mostraTbl(tblRes3);
		mostraTbl(tblRes4);
	}
}


// VALIDA E-MAIL
//-------------------------------------------------
function validaEmail(frm) {
	if (document.forms[frm].email.value == "") {
/*		alert("Digite seu e-mail.");
		document.forms[frm].email.focus();
		document.forms[frm].email.select();
*/
	} else {
		prim = document.forms[frm].email.value.indexOf("@")
		if(prim < 2) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("@",prim + 1) != -1) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf(".") < 1) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf(" ") != -1) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("zipmeil.com") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("hotmeil.com") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf(".@") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("@.") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf(".com.br.") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("/") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("[") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("]") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("(") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf(")") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
		if(document.forms[frm].email.value.indexOf("..") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email.focus();
			document.forms[frm].email.select();
			return false;
		}
	}
		return true;
}
function validaEmail1(frm) {
	if (document.forms[frm].email1.value == "") {
/*		alert("Digite seu e-mail.");
		document.forms[frm].email1.focus();
		document.forms[frm].email1.select();
*/
	} else {
		prim = document.forms[frm].email1.value.indexOf("@")
		if(prim < 2) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("@",prim + 1) != -1) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf(".") < 1) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf(" ") != -1) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("zipmeil.com") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("hotmeil.com") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf(".@") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("@.") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf(".com.br.") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("/") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("[") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("]") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("(") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf(")") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
		if(document.forms[frm].email1.value.indexOf("..") > 0) {
			alert("E-mail incorreto.");
			document.forms[frm].email1.focus();
			document.forms[frm].email1.select();
			return false;
		}
	}
		return true;
}


// FUNCÕES PARA VALIDAR FORMULÁRIOS DE EMPRESA NACIONAL
//-----------------------------------------------------
function validaFrmGeral(par) {

	emBranco="Campos em branco:"+('\n\n');
	
	if (frmGeral.cnpj.value==""){
		emBranco = emBranco+"- CNPJ"+('\n');
	}
	if (frmGeral.razao.value==""){
		emBranco = emBranco+"- Razão"+('\n');
	}
	if (frmGeral.nome.value==""){
		emBranco = emBranco+"- Nome Fantasia"+('\n');
	}
	if (frmGeral.data.value==""){
		emBranco = emBranco+"- Data de Constituição"+('\n');
	}
	if (frmGeral.situacao.options.value==""){
		emBranco = emBranco+"- Situação Comercial"+('\n');
	}
	if (frmGeral.telefone.value==""){
		emBranco = emBranco+"- Telefone"+('\n');
	}
	if (frmGeral.fax.value==""){
		emBranco = emBranco+"- Fax"+('\n');
	}
	if (frmGeral.email.value==""){
		emBranco = emBranco+"- E-mail"+('\n');
	}
	if (frmGeral.logradouro.value==""){
		emBranco = emBranco+"- Logradouro"+('\n');
	}
	if (frmGeral.bairro.value==""){
		emBranco = emBranco+"- Bairro"+('\n');
	}
	if (frmGeral.uf.options.value==""){
		emBranco = emBranco+"- Estado"+('\n');
	}
	if (frmGeral.municipio.value==""){
		emBranco = emBranco+"- Municipio"+('\n');
	}
	if (frmGeral.cep.value==""){
		emBranco = emBranco+"- Cep"+('\n');
	}
	if (frmGeral.atividadePrincipal.options.value==""){
		emBranco = emBranco+"- Atividade Principal"+('\n');
	}
	if (frmGeral.representanteLegal.value==""){
		emBranco = emBranco+"- Representante Legal"+('\n');
	}
	if (frmGeral.cpf.value==""){
		emBranco = emBranco+"- Cpf"+('\n');
	}
	if (frmGeral.cargo.value==""){
		emBranco = emBranco+"- Cargo"+('\n');
	}
	if (frmGeral.telefone1.value==""){
		emBranco = emBranco+"- Telefone do Representante"+('\n');
	}
	if (frmGeral.fax1.value==""){
		emBranco = emBranco+"- Fax do Representante"+('\n');
	}
	if (frmGeral.email1.value==""){
		emBranco = emBranco+"- E-mail do Representante"+('\n');
	}
	if (emBranco=="Campos em branco:"+('\n\n')){
	   if (window.confirm("Os dados serão gravados no banco de dados. Deseja prosseguir?")) {
		window.alert("Informações inseridas com sucesso.");
		if (par!=null){
			window.location.href="cadastroAtividades/cadastroAtividadesEmpresaNacNaoExibidora.jsp";
		} else {
			window.location.href="../inicio.jsp";
		}
	   }
	} else {
		window.alert(emBranco+('\n')+"* Preenchimento obrigatório.");
	}
}


// FUNÇÕES PARA VALIDAR FORMULÁRIOS DE EMPRESA GRUPO
//--------------------------------------------------
function validaFrmGeralGrupo(par) {

	emBranco="Campos em branco:"+('\n\n');
	
	if (frmGeralGrupo.nome.value==""){
		emBranco = emBranco+"- Nome Fantasia"+('\n');
	}
	if (frmGeralGrupo.data.value==""){
		emBranco = emBranco+"- Data de Constituição"+('\n');
	}
	if (frmGeralGrupo.situacao.options.value==""){
		emBranco = emBranco+"- Situação Comercial"+('\n');
	}
	if (frmGeralGrupo.telefone.value==""){
		emBranco = emBranco+"- Telefone"+('\n');
	}
	if (frmGeralGrupo.fax.value==""){
		emBranco = emBranco+"- Fax"+('\n');
	}
	if (frmGeralGrupo.email.value==""){
		emBranco = emBranco+"- E-mail"+('\n');
	}
	if (frmGeralGrupo.logradouro.value==""){
		emBranco = emBranco+"- Logradouro"+('\n');
	}
	if (frmGeralGrupo.bairro.value==""){
		emBranco = emBranco+"- Bairro"+('\n');
	}
	if (frmGeralGrupo.uf.options.value==""){
		emBranco = emBranco+"- Estado"+('\n');
	}
	if (frmGeralGrupo.municipio.value==""){
		emBranco = emBranco+"- Municipio"+('\n');
	}
	if (frmGeralGrupo.cep.value==""){
		emBranco = emBranco+"- Cep"+('\n');
	}
	if (frmGeralGrupo.atividadePrincipal.options.options.value==""){
		emBranco = emBranco+"- Atvidade Principal"+('\n');
	}
	if (frmGeralGrupo.representanteLegal.value==""){
		emBranco = emBranco+"- Representante Legal"+('\n');
	}
	if (frmGeralGrupo.cpf.value==""){
		emBranco = emBranco+"- Cpf"+('\n');
	}
	if (frmGeralGrupo.cargo.value==""){
		emBranco = emBranco+"- Cargo"+('\n');
	}
	if (frmGeralGrupo.telefone1.value==""){
		emBranco = emBranco+"- Telefone do Representante"+('\n');
	}
	if (frmGeralGrupo.fax1.value==""){
		emBranco = emBranco+"- Fax do Representante"+('\n');
	}
	if (frmGeralGrupo.email1.value==""){
		emBranco = emBranco+"- E-mail do Representante"+('\n');
	}
	if (emBranco=="Campos em branco:"+('\n')){
	   if (window.confirm("Os dados serão gravados no banco de dados. Deseja prosseguir?")) {
		window.alert("Informações inseridas com sucesso.");
		if (par!=null){
			window.location.href="cadastroAtividades/cadastroAtividadesEmpresaNacNaoExibidora.jsp";
		} else {
			window.location.href="../inicio.jsp";
		}
	   }
	} else {
		window.alert(emBranco+('\n')+"* Preenchimento obrigatório.");
	}
}




// FUNCÕES PARA VALIDAR FORMULÁRIOS DE EMPRESA ESTRANGEIRA
//--------------------------------------------------------
function validaFrmEstr(par) {

	emBranco="Campos em branco:"+('\n\n');
	
	if (frmGeralEstr.razao.value==""){
		emBranco = emBranco+"- Razão Social"+('\n');
	}
	if (frmGeralEstr.nome.value==""){
		emBranco = emBranco+"- Nome Fantasia"+('\n');
	}
	if (frmGeralEstr.data.value==""){
		emBranco = emBranco+"- Data de Constituição"+('\n');
	}
	if (frmGeralEstr.telefone.value==""){
		emBranco = emBranco+"- Telefone"+('\n');
	}
	if (frmGeralEstr.fax.value==""){
		emBranco = emBranco+"- Fax"+('\n');
	}
	if (frmGeralEstr.email.value==""){
		emBranco = emBranco+"- E-mail"+('\n');
	}
	if (frmGeralEstr.cidade.value==""){
		emBranco = emBranco+"- Cidade"+('\n');
	}
	if (frmGeralEstr.pais.options.value==""){
		emBranco = emBranco+"- País"+('\n');
	}
	if (frmGeralEstr.cep.value==""){
		emBranco = emBranco+"- Cep"+('\n');
	}
	if (frmGeralEstr.nomeSocio.value==""){
		emBranco = emBranco+"- Nome do Sócio"+('\n');	
	}
	if (frmGeralEstr.logradouroSocio.value==""){
		emBranco = emBranco+"- Logradouro do Sócio"+('\n');
	}
	if (frmGeralEstr.cidadeSocio.value==""){
		emBranco = emBranco+"- Cidade do Sócio"+('\n');
	}
	if (frmGeralEstr.cep1.value==""){
		emBranco = emBranco+"- Cep do Sócio"+('\n');
	}
	if (frmGeralEstr.cidadeSocio.value==""){
		emBranco = emBranco+"- Fax do Sócio"+('\n');
	}
	if (frmGeralEstr.paisSocio.options.value==""){
		emBranco = emBranco+"- País do Sócio"+('\n');
	}
	if (frmGeralEstr.telefone1.value==""){
		emBranco = emBranco+"- Telefone do Sócio"+('\n');
	}
	if (frmGeralEstr.email1.value==""){
		emBranco = emBranco+"- E-mail do Sócio"+('\n');
	}	
	if (frmGeralEstr.razaoAtividade.value==""){
		emBranco = emBranco+"- Razão Social da Atividade"+('\n');
	}
	if (frmGeralEstr.cargoAtividade.value==""){
		emBranco = emBranco+"- Cargo da Atividade"+('\n');
	}
	if (frmGeralEstr.telefone2.value==""){
		emBranco = emBranco+"- Telefone da Atividade"+('\n');
	}
	if (frmGeralEstr.fax2.value==""){
		emBranco = emBranco+"- Fax da Atividade"+('\n');
	}
	if (frmGeralEstr.email2.value==""){
		emBranco = emBranco+"- E-mail da Atividade"+('\n');
	}
	if (emBranco=="Campos em branco:"+('\n')){
	   if (window.confirm("Os dados serão gravados no banco de dados. Deseja prosseguir?")) {
		window.alert("Informações inseridas com sucesso.");
		if (par!=null){
			window.location.href="cadastroAtividades/cadastroAtividadesEmpresaNacNaoExibidora.jsp";
		} else {
			window.location.href="../inicio.jsp";
		}
	   }
	} else {
		window.alert(emBranco+('\n')+"* Preenchimento obrigatório.");
	}
}


// FUNCÕES PARA VALIDAR FORMULÁRIOS DE CADASTRO DE EMPRESAS
//---------------------------------------------------------
function validaFrmCadOutrasAtiv() {

	emBranco="Campos em branco:"+('\n\n');

	if (frmCadOutrasAtiv.atividades.options.value==""){
		emBranco = emBranco+"- Atividade"+('\n');
	}
	if (frmCadOutrasAtiv.representanteLegal.value==""){
		emBranco = emBranco+"- Representante Legal"+('\n');
	}
	if (frmCadOutrasAtiv.cpf.value==""){
		emBranco = emBranco+"- CPF"+('\n');
	}
	if (frmCadOutrasAtiv.cargo.value==""){
		emBranco = emBranco+"- Cargo"+('\n');
	}
	if (frmCadOutrasAtiv.telefone.value==""){
		emBranco = emBranco+"- Telefone"+('\n');
	}
	if (frmCadOutrasAtiv.fax.value==""){
		emBranco = emBranco+"- Fax"+('\n');
	}
	if (frmCadOutrasAtiv.email.value==""){
		emBranco = emBranco+"- E-mail"+('\n');
	}
	if (emBranco=="Campos em branco:"+('\n\n')){
		window.alert("Nova atividade inserida com sucesso.");
		mostraTbl(tblAtCad);
		frmCadOutrasAtiv.representanteLegal.value="";
		frmCadOutrasAtiv.cpf.value="";
		frmCadOutrasAtiv.cargo.value="";
		frmCadOutrasAtiv.telefone.value="";
		frmCadOutrasAtiv.fax.value="";
		frmCadOutrasAtiv.email.value="";
	} else {
		window.alert(emBranco+('\n')+"* Preenchimento obrigatório.");
	}
}

// FUNCÕES PARA VALIDAR FORMULÁRIOS DE CADASTRO DE EMPRESAS
//---------------------------------------------------------
function validaFrmCadEmpre(par) {

	emBranco="Campos em branco:"+('\n\n');
	
	if (frmCadDeEmp.cnpj.value==""){
		emBranco = emBranco+"- CNPJ"+('\n');
	}
	if (frmCadDeEmp.razao.value==""){
		emBranco = emBranco+"- Razão"+('\n');
	}
	if (frmCadDeEmp.data.value==""){
		emBranco = emBranco+"- Data de Constituição"+('\n');
	}
	if (frmCadDeEmp.telefone.value==""){
		emBranco = emBranco+"- Telefone"+('\n');
	}
	if (frmCadDeEmp.fax.value==""){
		emBranco = emBranco+"- Fax"+('\n');
	}
	if (frmCadDeEmp.email.value==""){
		emBranco = emBranco+"- E-mail"+('\n');
	}
	if (frmCadDeEmp.logradouro.value==""){
		emBranco = emBranco+"- Logradouro"+('\n');
	}
	if (frmCadDeEmp.complemento.value==""){
		emBranco = emBranco+"- Complemento"+('\n');
	}
	if (frmCadDeEmp.bairro.value==""){
		emBranco = emBranco+"- Bairro"+('\n');
	}
	if (frmCadDeEmp.uf.options.value==""){
		emBranco = emBranco+"- Estado"+('\n');
	}
	if (frmCadDeEmp.municipio.value==""){
		emBranco = emBranco+"- Municipio"+('\n');
	}
	if (frmCadDeEmp.cep.value==""){
		emBranco = emBranco+"- Cep"+('\n');
	}
	if (frmCadDeEmp.atividadePrincipal.options.value==""){
		emBranco = emBranco+"- Atvidade Principal"+('\n');
	}
	if (frmCadDeEmp.representanteLegal.value==""){
		emBranco = emBranco+"- Representante Legal"+('\n');
	}
	if (frmCadDeEmp.cpf.value==""){
		emBranco = emBranco+"- Cpf do Representante Legal"+('\n');
	}
	if (frmCadDeEmp.cargo.value==""){
		emBranco = emBranco+"- Cargo do Representante Legal"+('\n');
	}
	if (frmCadDeEmp.telefone1.value==""){
		emBranco = emBranco+"- Telefone do Representante Legal"+('\n');
	}
	if (frmCadDeEmp.fax1.value==""){
		emBranco = emBranco+"- Fax do Representante Legal"+('\n');
	}
	if (frmCadDeEmp.email1.value==""){
		emBranco = emBranco+"- E-mail do Representante Legal"+('\n');
	}	
	if (emBranco=="Campos em branco:"+('\n\n')){
	   if (window.confirm("Os dados serão gravados no banco de dados. Deseja prosseguir?")) {
		window.alert("Informações inseridas com sucesso.");
		if (par!=null){
			window.location.href="cadastroAtividades/cadastroAtividadesEmpresaNacNaoExibidora.jsp";
		} else {
			window.location.href="../inicio.jsp";
		}
	   }
	} else {
		window.alert(emBranco+('\n')+"* Preenchimento obrigatório.");
	}
}


// FUNCÕES PARA VALIDAR FORMULÁRIOS DE PRODUTOR AUDIOVISUAL
//--------------------------------------------------------
function validaFrmCadProAudVis() {

	emBranco="Campos em branco:"+('\n\n');
	
	if (frmCadProAudVis.cpf.value==""){
		emBranco = emBranco+"- CPF"+('\n');
	}
	if (frmCadProAudVis.rg.value==""){
		emBranco = emBranco+"- RG"+('\n');
	}
	if (frmCadProAudVis.orgaoEmissorRg.value==""){
		emBranco = emBranco+"- Orgão Emissor"+('\n');
	}
	if (frmCadProAudVis.ufRg.options.value==""){
		emBranco = emBranco+"- Estado do RG"+('\n');
	}
	if (frmCadProAudVis.nome.value==""){
		emBranco = emBranco+"- Nome Completo"+('\n');
	}
	if (frmCadProAudVis.telefone.value==""){
		emBranco = emBranco+"- Telefone"+('\n');
	}
	if (frmCadProAudVis.fax.value==""){
		emBranco = emBranco+"- Fax"+('\n');
	}
	if (frmCadProAudVis.email.value==""){
		emBranco = emBranco+"- E-mail"+('\n');
	}
	if (frmCadProAudVis.cep.value==""){
		emBranco = emBranco+"- Cep"+('\n');
	}
	if (frmCadProAudVis.ufEndereco.options.value==""){
		emBranco = emBranco+"- Estado do Endereço"+('\n');
	}
	if (frmCadProAudVis.logradouro.value==""){
		emBranco = emBranco+"- Logradouro"+('\n');
	}
	if (emBranco=="Campos em branco:"+('\n\n')){
	   if (window.confirm("Os dados serão gravados no banco de dados. Deseja prosseguir?")) {
		window.alert("Informações inseridas com sucesso.");
		window.location.href="../inicio.jsp";
	   }
	} else {
		window.alert(emBranco+('\n')+"* Preenchimento obrigatório.");
	}
}


// FUNÇÕES PARA VALIDAR CNPJ
//--------------------------------------------
function TESTACNPJ(campo)
{
  if(VerifyCNPJ(campo.value) == 1)
  {
    return true
  }
  else
  {
    alert("CNPJ inválido!");
    campo.value="";
    campo.focus();
  }
  return;
}


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);
  }
 }



// VALIDA CPF
// --------------------------------------------------------------
function limpaCPF(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 validaCPF(frm){ 
	var i; 
	s = document.forms[frm].cpf.value; 
	s = limpaCPF(s)
	if (s=="11111111111") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="22222222222") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="33333333333") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="44444444444") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="55555555555") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="66666666666") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="77777777777") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="88888888888") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="99999999999") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	if (s=="00000000000") {
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	}
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++) 
	{ 
		d1 += c.charAt(i)*(10-i); 
	} 
/*	if (d1 == 0){ 
		alert("CPF Inválido");
		document.forms[frm].cpf.value="";
		return false; 
	} 
*/
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) 
	{ 
		alert("CPF Inválido");
		document.forms[frm].cpf.value=""; 
		return false; 
	} 

	d1 *= 2; 
	for (i = 0; i < 9; i++) 
	{ 
		d1 += c.charAt(i)*(11-i); 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) 
	{ 
		alert("CPF Inválido");
		document.forms[frm].cpf.value=""; 
		return false; 
	} 

		return true; 
}

//FUNÇÃO PARA VALIDA CEP
//---------------------------------
function validaCEP(frm){
	if (document.forms[frm].cep.value.length<8){
		alert("CEP Inválido.");
		document.forms[frm].cep.value="";
		return false; 
	}
}

function validaCEP1(frm){
	if (document.forms[frm].cep1.value.length<4){
		alert("CEP Inválido.");
		document.forms[frm].cep1.value="";
//		return false; 
	}
}


// FUNCAO PARA CONFIRMAR CANCELAMENTO DE CADASTRO DE ATIVIDADE
// --------------------------------------------------------------------------

function confirmaCancelamento(frm){
	if (confirm("Deseja cancelar o cadastramento dessa atividade?")){
		document.forms[frm].reset();
	}
}


// FUNCAO PARA VALIDAR DATA
// ----------------------------------------------------------------
function validaData(){
if (document.forms[0].data.value.length < 10){
	document.forms[0].data.value="";
	alert("Data inválida.");
}

dia = document.forms[0].data.value.substring(0,2);
mes = document.forms[0].data.value.substring(3,5);
ano = document.forms[0].data.value.substring(6);

  var v_dia;
  var v_mes;
  var v_ano;
  v_dia = dia;
  v_mes = mes;
  v_ano = ano;
  
  if (v_dia.length < 2)
  {
	return(false);
  }
  if (v_mes.length < 2)
  {
	return(false);
  }
  if (v_ano.length < 4)
  {
	return(false);
  }
  if (((v_ano < 1900) || (v_ano > 2079)) && (v_ano.length != 0))
  {
	document.forms[0].data.value="";
	alert("Data inválida.");
	return(false);
  }
  if (v_dia > 31)
  {
	document.forms[0].data.value="";
	alert("Data inválida.");
	return(false);
  }
  if (v_mes > 12)
  {
	document.forms[0].data.value="";
	alert("Data inválida.");
	return(false);
  }
  if (v_dia == "31") 
  {
	if ((v_mes == "04") || (v_mes == "06") || (v_mes == "09") || (v_mes == "11"))
	{
	    return(false);
	}
  }

  if (v_mes == "02")
  {
	if (!(v_ano%4)) 
	{
	    if (v_dia > 29)
	    {
		document.forms[0].data.value="";
		alert("Data inválida.");
		return(false);
	    }
	}
	else if (v_dia > 28)
	{
		document.forms[0].data.value="";
		alert("Data inválida.");
		return(false);
	}
  }
  
  //o -if- abaixo testa se algum campo foi preenchido e outro deixado em branco deixando a data incompleta

  if (((v_dia != "") || (v_mes != "") || (v_ano != "")) && ((v_dia == "") || (v_mes == "") || (v_ano == "")))
  {
	return(false);
  }
  return(true);
}

//FUNÇÃO PARA VALIDA A PAGINA INDEX
//---------------------------------
/*function validaAtividade() {
	if (frmAtividadesEmpresa.atividade.options.value=="1"){
		 window.location.href="cadastroEmpresaNacNaoExibidora.jsp";
	} else if (frmAtividadesEmpresa.atividade.options.value=="3"){
		 window.location.href="cadEmpresaEstrangeira.jsp";
	} else if (frmAtividadesEmpresa.atividade.options.value=="2"){
		 window.location.href="cadastroEmpresaExibidoraGrupo.jsp";
	}
}
*/

/*//FUNÇÃO PARA VALIDA A PAGINA OUTRAS ATIVIDADES
//---------------------------------------------
function confirmar() {
	if(confirm('Deseja Cadastrar outra atividade')) {
		window.alert("Dados inseridos com sucesso.");
		window.location.reload();
	}		
	else{			
		window.location.href="escolheRamoAtividade.jsp?tipoEntidade=3";
	} 
   }
*/

/*
//FUNÇÃO PARA VALIDA DADOS CADASTRO DA EMPRESA
//----------------------------------------------------------
function confirmarCadastroFisico() {
	if(confirm('Deseja Cadastrar outra atividade?')) {
		window.alert("Dados inseridos com sucesso.");
		window.location.href="controlaPessoaFisica.jsp";
	}		
	else{			
		window.location.href="../../index.htm";
	} 
   }
*/

/*
//FUNÇÃO PARA VALIDA DADOS CADASTRAIS DA EMPRESA
//--------------------------------------------------
function confirmarCadastro() {
	if(confirm('Deseja Cadastrar outra atividade')) {
		window.alert("Dados inseridos com sucesso.");
		window.location.href="controlaEmpresaNacNaoExibidora.jsp";
	}		
	else{			
		window.location.href="index.htm";
	} 
   }
*/

/*
//FUNÇÃO PARA VALIDA DADOS CADSTRAIS DA EMPRESA ESTRANGEIRA
//---------------------------------
function confirmarCadastroEstr() {
	if(confirm('Deseja Cadastrar outra atividade')) {
		window.alert("Dados inseridos com sucesso.");
		window.location.href="controlaEmpresaEstrangeira.jsp";
	}		
	else{			
		window.location.href="index.htm";
	} 
   }
*/


//FUNÇÕES PARA O SISTEMA DE CPB 
//-----------------------------------------------------

function ComfirmacaoCPB(){

		if(confirm("Deseja Enviar certificado de CPB?.")) {
		window.open("/cpb/jsp/EmisaoCPB.jsp","emissaoCPB","width=590,height=150");
		}
		
		
}

function ListaCesionarios(){		
  		window.open("/cpb/jsp/manutencao/listaCessionarios.jsp","listaCessionarios","width=590,height=210");
		
}

function validaPagina(){
		if(confirm("Deseja Salvar Alteração?")) {
		alert("Dados Alterados com Sucesso.")
		window.location.reload();
		}
}

function confirmaInclusao() {
		if(confirm('Confirma cadastro de Produtor Estrangeiro')) { 
		window.alert("Dados inseridos com sucesso.");
		window.location.reload();
		}
}



//Verifica campo Numerico


        function checaCampoNum(objEvent)
        {
          var isNS4 = (navigator.appName=="Netscape")?1:0;
          var iKeyCode;
          if (!isNS4){
                iKeyCode = objEvent.keyCode;
          }else{
                iKeyCode = objEvent.which;
          }

              if(iKeyCode>=48 && iKeyCode<=57 || iKeyCode ==8 || iKeyCode ==9 || iKeyCode ==13){

                 return true;
              }else{

                 return false;
              }

}

//Função MAXLENGHT para os TEXTAREA

function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit);
    alert( 'Quantidade máxima de caracteres permitida:  ' + maxlimit);
    alterou = true;
    return false;
  }
  else
  {
   if(countfield != null){
    countfield.value = maxlimit - field.value.length;
   }
  }
}

//Funcao para verificar numerico

var tecla;
function isNumber(e)
{
    
    var isNS4 = (navigator.appName=="Netscape")?1:0;
    if (!isNS4){
      tecla = e.keyCode;	
    }else{
      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;
  }

}

//Funcao para validade CPF

   function verifyCPF(cpf){
     if (cpf.value==""){
       return false;
     }
     if (cpf.value.length!=14){
       alert("CPF Inválido!");
       return false;
       cpf.value="";
       cpf.focus = false;
     }
     else{
         cpfvalue="";  
         for(i=0;i<cpf.value.length;i++){
            if (cpf.value.charAt(i)!='.' && cpf.value.charAt(i)!='-'){
               cpfvalue=cpfvalue+cpf.value.charAt(i);
            }
         }
         if (!verificarCPF(cpfvalue)){
            cpf.value="";
            cpf.focus = false;
            return false;
         }else{
            return true;
         }
     }
   }
   
   	function removeFormatacaoCpfCnpj(cnpjCpf) {
		if (cnpjCpf.value != '') {
			cpfvalue = '';
			
	        for (i = 0; i < cnpjCpf.value.length; i++) {
	            if (cnpjCpf.value.charAt(i) != '.' && cnpjCpf.value.charAt(i) != '-'){
	               cpfvalue = cpfvalue + cnpjCpf.value.charAt(i);
	            }
	        }
	        cnpjCpf.value = cpfvalue;
	    }
	}
   
   function validateCPF(cpf, mensagem){
     if (cpf.value==""){
       return false;
     }
     if (cpf.value.length!=14){
       alert(mensagem);
       return false;
       cpf.value="";
       cpf.focus();
     } else{
         cpfvalue="";  
         for(i=0;i<cpf.value.length;i++){
            if (cpf.value.charAt(i)!='.' && cpf.value.charAt(i)!='-'){
               cpfvalue=cpfvalue+cpf.value.charAt(i);
            }
         }
		 var TUDO_0 = (cpfvalue == '00000000000');
	     var TUDO_1 = (cpfvalue == '11111111111'); 
	     var TUDO_2 = (cpfvalue == '22222222222');
	     var TUDO_3 = (cpfvalue == '33333333333');
	     var TUDO_4 = (cpfvalue == '44444444444');
	     var TUDO_5 = (cpfvalue == '55555555555');
	     var TUDO_6 = (cpfvalue == '66666666666');
	     var TUDO_7 = (cpfvalue == '77777777777');
	     var TUDO_8 = (cpfvalue == '88888888888');
	     var TUDO_9 = (cpfvalue == '99999999999');
         
         if (TUDO_0 || TUDO_1 || TUDO_2 || TUDO_3 || TUDO_4 || 
         	 TUDO_5 || TUDO_6 || TUDO_7 || TUDO_8 || TUDO_9) {
	         alert(mensagem);
	         cpf.value="";
	         cpf.focus();
	         return false;
         }
         if (!verificarCPF(cpfvalue)){
            cpf.value="";
            cpf.focus();
            return false;
         }else{
            return true;
         }
     }
   }

  
   
function verificarCPF(c){
var i; 
s = c;
var c = s.substr(0,9); 
var dv = s.substr(9,2); 
var d1 = 0; 
var v = false;
for (i = 0; i < 9; i++) 
{ 
d1 += c.charAt(i)*(10-i); 
} 
if (d1 == 0){ 
alert("CPF Inválido!")
v = true; 
return false; 
} 
d1 = 11 - (d1 % 11); 
if (d1 > 9) d1 = 0; 
if (dv.charAt(0) != d1) 
{ 
alert("CPF Inválido!") 
v = true;
return false; 
} 

d1 *= 2; 
for (i = 0; i < 9; i++) 
{ 
d1 += c.charAt(i)*(11-i); 
} 
d1 = 11 - (d1 % 11); 
if (d1 > 9) d1 = 0; 
if (dv.charAt(1) != d1) 
{ 
alert("CPF Inválido!") 
v = true;
return false; 
} 
if (!v) {
//alert(c + "\nCPF VÃ¡lido") ;
return true;
}
}

function formataCPF(cpf)
{
    if (cpf.value.length == 3) {
        cpf.value = cpf.value + '.';
    }
    if (cpf.value.length==7) {
        cpf.value=cpf.value + '.';
    }
    if (cpf.value.length == 11) {
        cpf.value = cpf.value + '-';
    }
    if (cpf.value.length == 14) {
    }
}

function formataCPF_OnExit( cpf )
{
  tam = cpf.value.length;

  if (tam > 3 && tam < 6)
  {
    cpf.value = cpf.value.substr(0,3) + '.' + cpf.value.substr(3,tam);
  }
  else if (tam >= 6 && tam < 9)
  {
    cpf.value = cpf.value.substr(0,3) + '.' + cpf.value.substr(3,3) + '.' + cpf.value.substr(6,tam-6);
  }
  else if (tam >= 9 && tam <= 11)
  {
    cpf.value = cpf.value.substr(0,3) + '.' + cpf.value.substr(3,3) + '.' + cpf.value.substr(6,3) + '-' + cpf.value.substr(9,tam-9);
  }
}

//Mascara de Telefone

function formatTel(tel){
    if (tel.value.length == 1) {
        tel.value="("+tel.value;
    }
    if (tel.value.length==3){
        tel.value=tel.value+')'; 
    }
    
     if (tel.value.length==4){
        tel.value=tel.value+' '; 
    }
    
    if (tel.value.length == 9) {
        tel.value=tel.value+'-';
    }
}

//Mascara de Telefone

function mascaraTEL(e,tel){
   var retorno=isNumber(e);
   if (retorno && tecla!=8){
     //formatTel(tel);
   }
   return retorno;
   
}

function mascaraCPF_OnExit( campo )
{
  formataCPF_OnExit( campo );
  return true;
}

//Mascara de CPF

function mascaraCPF(e,cpf){
   var retorno=isNumber(e);
   if (retorno && tecla!=8){
     formataCPF(cpf);
   }
   return retorno;
}

//Mascara de data

function formartDATA(data){
    if (data.value.length == 2 || data.value.length==5) {
        data.value = data.value + '/';
    }
 } 
 
function mascaraDATA(e,data){
   var retorno=isNumber(e);
   if (retorno && tecla!=8){
     formartDATA(data);
   }
   return retorno;
}

function getValueWithoutSymbols( campo )
{
  var vr = new String( campo.value );
  
  vr = vr.replace(".", "");
  vr = vr.replace(".", "");
  vr = vr.replace("/", "");
  vr = vr.replace("-", "");
  
  return vr;
}

function efetivarMascara( tam, campo, vr )
{
  if (tam > 2 && tam < 6)
     campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
  
  if (tam >= 6 && tam < 9)
     campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
  
  if (tam >= 9 && tam < 13)
     campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
  
  if (tam >= 13 && tam < 15)
     campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
}

function formataCNPJ_OnExit( campo )
{  
  var valor = getValueWithoutSymbols( campo );
  
  if ( valor.length < 14 )
  {
    tam = valor.length + 1 ;
  }
  else
  {
    tam = valor.length;
  }
  
  efetivarMascara( tam, campo, valor );
  
  return true;
}
  
//Mascara de CNPJ
function formataCNPJ(Campo, teclapres)
{
  if (isNumber(teclapres))
  {
    var tecla = teclapres.keyCode;
   
    var vr = getValueWithoutSymbols( Campo );

    tam = vr.length + 1 ;
   
    if (tecla != 9 && tecla != 8)
    {
      efetivarMascara( tam, Campo, vr );
    }
  }
  else
  {
    return false;
  }
}

function rtrim(mvar)
{
  if (mvar.substring(mvar.length-1,mvar.length)==" ") mvar = rtrim(mvar.substring(0,mvar.length-1));
  return mvar;
}

function ltrim(mvar)
{
    if (mvar.substring(0,1)== " ") mvar = ltrim(mvar.substring(1,mvar.length));
    return mvar;
}

function trim(mvar)
{
   return rtrim(ltrim(mvar));
}

var primeiraTecla = false;
var shift = false;

function formatarValor(valor,tammax,pattern,teclapres) {
	var tecla = teclapres.keyCode;

	if(tecla == 16){
		shift = true
	}

	if(!shift){
	if(primeiraTecla && ((tecla>=48 && tecla<=57) || (tecla>=96 && tecla<=105) || tecla==8 || tecla==46)){
			valor.value = '';
			primeiraTecla = false;
	}

	if(pattern.indexOf("%")>-1){
		pattern = pattern.substr(0,pattern.length-2);
	}
	numCasasDecimais = pattern.replace(".", "").length-1

	valorSemFormato = valor.value;
	valorSemFormato = replaceAll(valorSemFormato, ",", "");
	valorSemFormato = replaceAll(valorSemFormato, ".", "");
	valorSemFormato = replaceAll(valorSemFormato, "%", "");

	do{
		esquerda = valorSemFormato.substr(0,1);
		if(esquerda == '0'){
			valorSemFormato = valorSemFormato.substr(1, valorSemFormato.length);
		}
	}while(esquerda == '0');

	if(valorSemFormato==0){
		valorSemFormato = ""
		valor.value = ""
	}

	tamanho = valorSemFormato.length;

	if (tecla == 46) {
		valor.value = valor.value;
	}

	if (tamanho < tammax && tecla != 8) {
		tamanho = valorSemFormato.length + 1;

	}if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) {
		if (tecla == 8) {
			tamanho = tamanho - 1;
		}

		if(numCasasDecimais>0){
			if (tamanho <= numCasasDecimais) {
				valor.value = valorSemFormato;
			}else if ((tamanho > numCasasDecimais) && (tamanho <= 3+numCasasDecimais)) {
				valor.value = valorSemFormato.substr(0, tamanho - numCasasDecimais) + ',' +
							valorSemFormato.substr(tamanho - numCasasDecimais, tamanho);

			}else if ((tamanho >= 4+numCasasDecimais) && (tamanho <= 6+numCasasDecimais)) {
				valor.value = valorSemFormato.substr(0, tamanho - 3 - numCasasDecimais) + '.' +
							valorSemFormato.substr(tamanho - 3 - numCasasDecimais, 3) + ',' +
							valorSemFormato.substr(tamanho - numCasasDecimais, tamanho);

			}else if ((tamanho >= 7+numCasasDecimais) && (tamanho <= 9+numCasasDecimais)) {
				valor.value = valorSemFormato.substr(0, tamanho - 6 - numCasasDecimais) + '.' +
							valorSemFormato.substr(tamanho - 6 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 3 - numCasasDecimais, 3) + ',' +
							valorSemFormato.substr(tamanho - numCasasDecimais, tamanho);

			}else if ((tamanho >= 10+numCasasDecimais) && (tamanho <= 12+numCasasDecimais)) {
				valor.value = valorSemFormato.substr(0, tamanho - 9 - numCasasDecimais) + '.' +
							valorSemFormato.substr(tamanho - 9 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 6 - numCasasDecimais, 3)  + '.' +
							valorSemFormato.substr(tamanho - 3 - numCasasDecimais, 3)  + ',' +
							valorSemFormato.substr(tamanho - numCasasDecimais, tamanho);

			}else if ((tamanho >= 13+numCasasDecimais) && (tamanho <= 15+numCasasDecimais)) {
				valor.value = valorSemFormato.substr(0, tamanho - 12 - numCasasDecimais) + '.' +
							valorSemFormato.substr(tamanho - 12 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 9 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 6 - numCasasDecimais, 3)  + '.' +
							valorSemFormato.substr(tamanho - 3 - numCasasDecimais, 3)  + ',' +
							valorSemFormato.substr(tamanho - numCasasDecimais, tamanho);
			}else if ((tamanho >= 16+numCasasDecimais) && (tamanho <= 18+numCasasDecimais)) {
				valor.value = valorSemFormato.substr(0, tamanho - 15 - numCasasDecimais) + '.' +
							valorSemFormato.substr(tamanho - 15 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 12 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 9 - numCasasDecimais, 3) + '.' +
							valorSemFormato.substr(tamanho - 6 - numCasasDecimais, 3)  + '.' +
							valorSemFormato.substr(tamanho - 3 - numCasasDecimais, 3)  + ',' +
							valorSemFormato.substr(tamanho - numCasasDecimais, tamanho);
			}
		}
		else{
			if ((tamanho > 0) && (tamanho <= 3)) {
				valor.value = valorSemFormato.substr(0, tamanho+1);

			}else if ((tamanho >= 4) && (tamanho <= 6)) {
				valor.value = valorSemFormato.substr(0, tamanho - 3) + '.' +
							valorSemFormato.substr(tamanho - 3, tamanho)

			}else if ((tamanho >= 7) && (tamanho <= 9)) {
				valor.value = valorSemFormato.substr(0, tamanho - 6) + '.' +
							valorSemFormato.substr(tamanho - 6, 3) + '.' +
							valorSemFormato.substr(tamanho - 3, tamanho)

			}else if ((tamanho >= 10) && (tamanho <= 12)) {
				valor.value = valorSemFormato.substr(0, tamanho - 9) + '.' +
							valorSemFormato.substr(tamanho - 9, 3) + '.' +
							valorSemFormato.substr(tamanho - 6, 3)  + '.' +
							valorSemFormato.substr(tamanho - 3, tamanho);

			}else if ((tamanho >= 13) && (tamanho <= 15)) {
				valor.value = valorSemFormato.substr(0, tamanho - 12) + '.' +
							valorSemFormato.substr(tamanho - 12, 3) + '.' +
							valorSemFormato.substr(tamanho - 9, 3) + '.' +
							valorSemFormato.substr(tamanho - 6, 3)  + '.' +
							valorSemFormato.substr(tamanho - 3, tamanho);
			}else if ((tamanho >= 16) && (tamanho <= 18)) {
				valor.value = valorSemFormato.substr(0, tamanho - 15) + '.' +
							valorSemFormato.substr(tamanho - 15, 3) + '.' +
							valorSemFormato.substr(tamanho - 12, 3) + '.' +
							valorSemFormato.substr(tamanho - 9, 3) + '.' +
							valorSemFormato.substr(tamanho - 6, 3)  + '.' +
							valorSemFormato.substr(tamanho - 3, tamanho);
			}
		}
	}
	}
}

function replaceAll(sValue, strOld, strNew){
	var indexof = sValue.indexOf(strOld);

	while(indexof > -1){
		sValue = sValue.replace( strOld, strNew );
		indexof = sValue.indexOf(strOld);
	}
	return sValue;
}

function formatarDecimal(campo, pattern) {
	if(campo.value==''){
		campo.value = '0';
	}

	if(pattern.indexOf("%")>-1){
	pattern = pattern.substr(0,pattern.length-2);
	}
	numCasasDecimais = pattern.replace(".", "").length-1

	if(numCasasDecimais == 0){
		return;
	}
	if(numCasasDecimais == 1){
		if (campo.value.length == 1) {
			campo.value = '0,' + campo.value;
		}
	}
	if(numCasasDecimais == 2){
		if (campo.value.length == 2) {
			campo.value = '0,' + campo.value;
		}else if (campo.value.length == 1)  {
			campo.value = '0,0' + campo.value;
		}
	}
	if(numCasasDecimais == 3){
		if (campo.value.length == 3) {
			campo.value = '0,' + campo.value;
		}else if (campo.value.length == 2)  {
			campo.value = '0,0' + campo.value;
		}else if (campo.value.length == 1)  {
			campo.value = '0,00' + campo.value;
		}
	}
	if(numCasasDecimais == 4){
		if (campo.value.length == 4) {
			campo.value = '0,' + campo.value;
		}else if (campo.value.length == 3)  {
			campo.value = '0,0' + campo.value;
		}else if (campo.value.length == 2)  {
			campo.value = '0,00' + campo.value;
		}else if (campo.value.length == 1)  {
			campo.value = '0,000' + campo.value;
		}
	}
}

function testaShift(evt){
	var tecla = evt.keyCode;

	if(tecla == 16){
		shift = false;
	}
}
function filtrar(campo, tipo, evt){
	// tipo 1 = numerico
	// tipo 2 = alfabetico sem acentos
	// tipo 3 = email
    // tipo 4 =  conta
    // tipo 5 = tudo menos o enter
	var nTecla;
	evt = (evt) ? evt : (window.event) ? window.event : ""

	if(evt.which) {
		nTecla = evt.which;
	}else {
		nTecla = evt.keyCode;
	}

	switch(tipo)
	{
		case 1:
			if(nTecla>31 && (nTecla<48 || nTecla>57))
				return false;
				break;
		case 2:
			if(nTecla>31 && (nTecla<65 || nTecla>122) )
				return false;
				break;
	   case 3: 
	       if(!(nTecla==46 || nTecla==8 || nTecla==37 || nTecla==39 || (nTecla>=48 && nTecla<=57) || (nTecla>=64 && nTecla<=90) || (nTecla>=97 && nTecla<=122)))
				return false;
				break;
       case 4:
		   if(nTecla>31 && ((nTecla<48 || nTecla>57) && (nTecla!=120 && nTecla!=88 )))
		    	return false;
		  	    break;		  	    
	   case 5:
		   if(nTecla==13)
		   		return false;
		    	break;
	}

	return true;
}

