// JavaScript Document
function submitPalavraChave() {

	if (document.forms['form2'].chave.value.length < 3) {
		alert("A palavra chave deve conter no mínimo 3(três) caracteres.");
		document.forms['form2'].chave.focus();
	} else {
		document.forms['form2'].submit();
	}
}

function validaSubmit() {

	if (document.forms['form2'].chave.value.length < 3) {
		alert("A palavra chave deve conter no mínimo 3(três) caracteres.");
		document.forms['form2'].chave.focus();
		return false;
	} else {
		document.forms['form2'].submit();
		return true;
	}
}

function repeat() {
	alert("Desculpe, você não pode usar este mesmo formulário para mais de uma solicitação!\n Se desejar fazer outro pedido clique no menu ao lado em Solicitar Serviço");
}

function falhaPermissao() {
	alert("Serviço não pode ser captado via internet. Veja na ementa do serviço os locais de captação.");
}

function falhaOrgaoCaptador(){
	alert("Sua Unidade não tem permissão para captar este serviço.");
}

function sessaoExpirada() {
	alert("Sua sessão foi expirada!");
}

function exibeMsgAnonimo() {
	if (document.frmServico.anonimo.checked) {
		if (confirm("Esta opção não permite que a Prefeitura de Belo Horizonte o contate para informá-lo"
				+ " sobre o andamento e a conclusão do serviço a ser solicitado ou para obter esclarecimentos "
				+ "adicionais porventura necessários. Tem certeza que deseja a opção anônimo?")) {
			document.frmServico.verificaAnonimo.value = "1";
			document.frmServico.nat_cid[0].checked = false;
			document.frmServico.nat_cid[1].checked = false;
			document.frmServico.parametro.value = "";
			return true;
		} else {
			document.frmServico.anonimo.checked = false;
		}
	}
}
function exibeMsgSigilo() {
	
		alert("Solicitação de serviço captada de forma sigilosa só poderá ser acompanhada através" +
				" do número da solicitação de serviço, não sendo possível localizá-la através do CPF/CNPJ" +
				" e Seviço, ou ainda através do endereço da irregularidade. Os seus dados estão sendo mantidos" +
				" em sigilo para esta solicitação de serviço.");		
}

function falhaEmail(orgao) {
	alert("A solicitação foi gravada com sucesso! \nPorém não foi possível enviar o e-mail para o órgão executor: "
			+ orgao + "\nFavor comunicá-lo sobre esta solicitação");
}

function novaJanela() {

	window
			.open(
					"../Ctrl/CtrlSolicitacao?acao=9",
					"NovaJanela",
					"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=760,height=610");

}
function novaJanelaServico()

{

	window
			.open(
					"../Ctrl/CtrlSolicitacao?acao=10",
					"NovaJanela",
					"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=760,height=610");

}
function windowBloco() {
	window
			.open(
					"../Ctrl/CtrlSolicitacao?acao=18",
					"NovaJanela",
					"toolbar=yes,location=yes,directories=yes,	status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=760,height=500");
}

function redirectEmail() {
	// window.open("../Ctrl/CtrlSolicitacao?acao=12","NovaJanela","toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=500");
	document.location.href = '../Ctrl/CtrlSolicitacao?acao=12';
}

function limpaCampos() {
	
	if ((document.frmServico.forma_atendimento != null) &&
		(document.frmServico.forma_atendimento[0] != null) &&
			(document.frmServico.forma_atendimento[1] != null)){
		document.frmServico.forma_atendimento[0].checked = false;
		document.frmServico.forma_atendimento[1].checked = false;
	}
	
	if (document.frmServico.sigilo != null) {
		document.frmServico.sigilo.checked = false;
	}
	if (document.frmServico.nat_cid != null) {
		document.frmServico.nat_cid[0].checked = false;
		document.frmServico.nat_cid[1].checked = false;
	}
	document.frmServico.acao.value = "14";
	document.frmServico.submit();
}

function buscaPalavraChave() {
	document.form1.acao.value = "20";
	document.form1.submit();
}

function buscaGrupo() {
	document.form1.acao.value = "22";
	document.form1.submit();
}

function selecionaServicoLogado(numero) {
	document.form1.cod_ser.value = numero;
	document.form1.acao.value = "4";
	document.form1.submit();
}

function botaoAlterarSolicitacao() {
	document.frmServico.acao.value = "1";
	document.frmServico.operacao.value = "4";
	document.frmServico.submit();
}

function fluxoInexistente() {
	alert("Falha na tramitação \nNão existe órgão desta mesma regional cadastrado para executar esta primeira sequencia deste fluxo! \n Favor contactar o administrador:");
}

// ------------------------- FUNÇÕES SOLICITA ----------------------------------

function estadoNaoEncontrado() {
	alert("Sua pesquisa não retornou nenhum resultado.");
}

function validaSolicita() {

	if (document.frmServico.cod_ser.selectedIndex == "0") {
		alert("Favor escolher serviço.")
		document.frmServico.focus();
		return false;
	} else {
		document.frmServico.submit();
	}

}// fim validaSolicita
// ------------------------- FIM FUNÇÕES SOLICITA
// ----------------------------------

// ------------------------- FUNÇÕES ENDEREÇO SIOM
// ----------------------------------
function janela() {
	// document.frmDadosCidadao.ref_end_ate.value="";
	// document.frmDadosCidadao.complemento.value="";
	// vPosIniX=((screen.availWidth/2)-(700/2));
	// vPosIniY=((screen.availHeight/2)-(300/2));
	window
			.open(
					"../Ctrl/CtrlEndereco?acao=2",
					"",
					"toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=750,height=610");

}

function janela_i() {
	window
			.open(
					"../Ctrl/CtrlEndereco?acao=5",
					"",
					"toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=750,height=610");

}

function recebeSelecao() {
	// Recebe os vetores de nome e valor dos atributos selecionados
	var nome = arguments[0];
	var valor = arguments[1];

	// Procura no form corrente por atributos de mesmo nome. Se achar, atribui o
	// valor passado
	// do atributo ao atributo de mesmo nome no form.
	for ( var j = 0; j < nome.length; j++) {
		for ( var i = 0; i < document.forms[0].length; i++) {

			if (document.forms[0].elements[i].name == nome[j]) {
				document.forms[0].elements[i].value = valor[j];
				break;
			}
		}
	}
	document.frmServico.complemento.focus();
}

// -----------------------FIM FUNÇÕES ENDEREÇO SIOM
// ----------------------------------
// -----------------------FUNÇÕES PÁGINA
// CADASTRA_LOCAL.JSP----------------------------------
function carrega_campos_cadastrar() {
	document.frmServico.operacao.value = "1";
}

function valida_gravar() {// validar todos os campos exceto anônimo e
	// parâmetro
	document.frmServico.valida.value = "2";
}
function valida_consultar() {// validar campo parãmetro
	document.frmServico.valida.value = "3";

}

function validaCadastrar() {// validar campo parãmetro
	document.frmServico.valida.value = "4";
	document.frmServico.operacao.value = "1";
}
function validaGravar() {// validar campo parãmetro
	document.frmServico.valida.value = "5";
}
function cidadaoNaoEncontrado() {
	alert("CPF/CNPJ não cadastrado na base de dados. Verifique se você digitou corretamente.");
	document.frmServico.parametro.focus();
}

function validaCadastraLocal() {

	if (document.frmServico.valida.value != null) {
		if (document.frmServico.valida.value == "1"
				|| document.frmServico.valida.value == "5") {// verifica
			// todos os
			// campos

			if (document.frmServico.obs_ate.value == "") {
				alert("Favor informar detalhes sobre a solicitação.")
				document.frmServico.obs_ate.focus();
				return false;
			}
			if (document.frmServico.obs_ate.value == document.frmServico.valida_req_ser.value) {
				alert("Favor informar detalhes sobre a solicitação.")
				document.frmServico.obs_ate.focus();
				return false;
			}

			if (document.frmServico.verificaAnonimo.value == "1") {
				if (document.frmServico.valida.value != 3
						&& document.frmServico.anonimo.checked == false) {
					alert("Favor consultar cidadão ou cadastrar cidadão ou marcar anônimo.")
					return false;
				}
			} else {
				if (document.frmServico.cod_cid.value == null
						|| document.frmServico.cod_cid.value == "") {
					alert("Favor consultar cidadão ou cadastrar cidadão.")
					document.frmServico.parametro.focus();
					return false;
				}
			}

			if (document.frmServico.tipoLogradouro.value == "") {
				alert("Favor localizar o endereço.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}

			if (document.frmServico.nomeLogradouro.value == "") {
				alert("Favor localizar o endereço.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}
			if (document.frmServico.numEndereco.value == "") {
				alert("Favor digitar o número.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}
			if (document.frmServico.bairroEndereco.value == "") {
				alert("Favor localizar o endereço.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}
			if (document.frmServico.cidadeEndereco.value == "") {
				alert("Favor localizar o endereço.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}
			if (document.frmServico.numCep.value == "") {
				alert("Favor localizar o endereço.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}
			if (document.frmServico.codAdmRegional.value == "") {
				alert("Favor localizar o endereço.")
				document.frmServico.localizaEndereco.focus();
				return false;
			}
			if (document.frmServico.ref_end_ate.value == "") {
				alert("Favor informar uma referência do endereço.")
				document.frmServico.ref_end_ate.focus();
				return false;
			}
			if (document.frmServico.sigilo != null) {
				if ((document.frmServico.sigilo[0].checked == false)
						&& (document.frmServico.sigilo[1].checked == false)) {
					alert("Escolha se deseja ou não manter seus dados em sigilo.")
					return false;
				}
			}
			if (document.frmServico.forma_atendimento != null) {
				if (document.frmServico.forma_atendimento[0].checked == false
						&& document.frmServico.forma_atendimento[1].checked == false) {
					alert("Escolha a forma de atendimento desejada.")
					return false;
				}
			}

		}// fim verifica todos os campos

		// if(document.frmServico.valida.value=="2"){//verifica todos os campos
		// exceto campo anonimo e parametro
		else {
			if (document.frmServico.valida.value != "4") {// verifica todos os
				// campos
				if (document.frmServico.obs_ate.value == "") {
					alert("Favor informar detalhes sobre a solicitação.")
					document.frmServico.obs_ate.focus();
					return false;
				}

				if (document.frmServico.tipoLogradouro.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}

				if (document.frmServico.nomeLogradouro.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}
				if (document.frmServico.numEndereco.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}
				if (document.frmServico.bairroEndereco.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}
				if (document.frmServico.cidadeEndereco.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}
				if (document.frmServico.numCep.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}
				if (document.frmServico.codAdmRegional.value == "") {
					alert("Favor localizar o endereço.")
					document.frmServico.localizaEndereco.focus();
					return false;
				}
				if (document.frmServico.ref_end_ate.value == "") {
					alert("Favor informar uma referência do endereço.")
					document.frmServico.ref_end_ate.focus();
					return false;
				}
				// if (!document.frmServico.anonimo.checked){
				if (document.frmServico.sigilo != null) {
					if ((document.frmServico.sigilo[0].checked == false)
							&& (document.frmServico.sigilo[1].checked == false)) {
						alert("Escolha se deseja ou não manter seus dados em sigilo.")
						return false;
					}
				}
				if (document.frmServico.forma_atendimento != null) {
					if (document.frmServico.forma_atendimento[0].checked == false
							&& document.frmServico.forma_atendimento[1].checked == false) {
						alert("Escolha a forma de atendimento desejada.")
						return false;
					}
				}
			}// alert(document.frmServico.valida.value);

			// }
		}
	}
	// fim verifica todos os campos exceto anonimo

	// document.frmServico.submit();
}// fim function validaCampos

function teclaAtalhoCadastra() {
	var tecla = window.event.keyCode;
	// tecla F10
	if (tecla == 121) {
		if (validaCadastraLocal() != false) {
			document.frmServico.submit();
		}
		// return true;
	}
}// fim atalho pesquisa

function enderecoCidadao() {
	document.frmServico.tipoLogradouro.value = document.frmServico.tip_log_cid.value;
	document.frmServico.siglaTipoLogradouro.value = document.frmServico.tip_log_cid.value;
	document.frmServico.nomeLogradouro.value = document.frmServico.nom_log_cid.value;
	document.frmServico.numEndereco.value = document.frmServico.num_end_cid.value;
	document.frmServico.bairroEndereco.value = document.frmServico.bai_cid.value;
	document.frmServico.cidadeEndereco.value = "Belo Horizonte";
	document.frmServico.numCep.value = document.frmServico.cep_log_cid.value;
	document.frmServico.codAdmRegional.value = document.frmServico.reg_cid.value;
	document.frmServico.regionalEndereco.value = document.frmServico.regionalEnderecoCid.value;
	document.frmServico.ref_end_ate.value = document.frmServico.ref_end_ate_cid.value;
	document.frmServico.complemento.value = document.frmServico.com_end_cid.value;

}// fim enderecoCidadao

function campoInativo() {
	document.frmServico.localizaEndereco.focus();
}// fim campoInativo()

function campoInativoRef() {
	document.frmServico.ref_end_ate.focus();
}// fim campoInativo()

function validaConsultarCidadao() {
	if (document.frmServico.parametro.value == "") {
		alert("CPF/CNPJ não cadastrado na base de dados. Verifique se você digitou corretamente.");
		document.frmServico.parametro.focus();
		// document.frmServico.valida.value="1";
		return false;
	} else {
		// document.frmServico.valida.value="1";
		document.frmServico.operacao.value = "2";
		document.frmServico.submit();
	}
}

function contaRefEndAte(obj, event) {
	var str = obj.value;
	var Tecla = event.which;
	if (Tecla == null)
		Tecla = event.keyCode;
	if (document.frmServico.ref_end_ate.value.length > 150) {
		if (Tecla <= 258) {
			event.returnValue = false;
			return false;
		}
		event.returnValue = true;
		return true;
	}
}

function contaDetalhamento(obj, event) {
	var str = obj.value;
	var Tecla = event.which;
	if (Tecla == null)
		Tecla = event.keyCode;
	if (document.frmServico.obs_ate.value.length > 1900) {
		if (Tecla <= 258) {
			event.returnValue = false;
			return false;
		}
		event.returnValue = true;
		return true;
	}
}

function Validar(theCPF) {

	if (theCPF.value == "") {
		return (true);
	}
	if (((theCPF.value.length == 11) && (theCPF.value == 11111111111)
			|| (theCPF.value == 22222222222) || (theCPF.value == 33333333333)
			|| (theCPF.value == 44444444444) || (theCPF.value == 55555555555)
			|| (theCPF.value == 66666666666) || (theCPF.value == 77777777777)
			|| (theCPF.value == 88888888888) || (theCPF.value == 99999999999) || (theCPF.value == 00000000000))) {
		alert("CPF/CNPJ inválido.");
		theCPF.focus();
		return (false);
	}

	/*
	 * if (!((theCPF.value.length == 11) || (theCPF.value.length == 14))) {
	 * alert("CPF/CNPJ inválido."); theCPF.focus(); return (false); }
	 */
	if (theCPF.value.length < 11) {
		while (theCPF.value.length < 11) {
			theCPF.value = "0" + theCPF.value;
		}
	} else if ((theCPF.value.length > 11) && (theCPF.value.length < 14)) {
		while (theCPF.value.length < 14) {
			theCPF.value = "0" + theCPF.value;
		}
	}

	var checkOK = "0123456789";
	var checkStr = theCPF.value;
	var allValid = true;
	var allNum = "";
	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;
		}
		allNum += ch;
	}
	if (!allValid) {
		alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
		theCPF.focus();
		return (false);
	}

	var chkVal = allNum;
	var prsVal = parseFloat(allNum);
	if (chkVal != "" && !(prsVal > "0")) {
		alert("CPF zerado !");
		theCPF.focus();
		return (false);
	}

	if (theCPF.value.length == 11) {
		var tot = 0;

		for (i = 2; i <= 10; i++)
			tot += i * parseInt(checkStr.charAt(10 - i));

		if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9))) {
			alert("CPF/CNPJ inválido.");
			theCPF.focus();
			return (false);
		}

		tot = 0;

		for (i = 2; i <= 11; i++)
			tot += i * parseInt(checkStr.charAt(11 - i));

		if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10))) {
			alert("CPF/CNPJ inválido.");
			theCPF.focus();
			return (false);
		}
	} else {
		var tot = 0;
		var peso = 2;

		for (i = 0; i <= 11; i++) {
			tot += peso * parseInt(checkStr.charAt(11 - i));
			peso++;
			if (peso == 10) {
				peso = 2;
			}
		}

		if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12))) {
			alert("CPF/CNPJ inválido.");
			theCPF.focus();
			return false;
		}

		tot = 0;
		peso = 2;

		for (i = 0; i <= 12; i++) {
			tot += peso * parseInt(checkStr.charAt(12 - i));
			peso++;
			if (peso == 10) {
				peso = 2;
			}
		}

		if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13))) {
			alert("CPF/CNPJ inválido.");
			theCPF.focus();
			return (false);
		}
	}
	return (true);
}

function mod(dividendo, divisor) {
	return Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor));
}

// gera digito verificador
function cpf(cpf) {
	if (cpf.value.length < 9) {
		while (cpf.value.length < 9) {
			cpf.value = "0" + cpf.value;
		}
	}

	var n1 = cpf.value.charAt(0);
	// alert ("n1: "+n1);
	var n2 = cpf.value.charAt(1);
	// alert ("n2: "+n2);
	var n3 = cpf.value.charAt(2);
	// alert ("n3: "+n3);
	var n4 = cpf.value.charAt(3);
	// alert ("n4: "+n4);
	var n5 = cpf.value.charAt(4);
	// alert ("n5: "+n5);
	var n6 = cpf.value.charAt(5);
	// alert ("n6: "+n6);
	var n7 = cpf.value.charAt(6);
	// alert ("n7: "+n7);
	var n8 = cpf.value.charAt(7);
	// alert ("n8: "+n8);
	var n9 = cpf.value.charAt(8);
	// alert ("n9: "+n9);

	var d1 = n9 * 2 + n8 * 3 + n7 * 4 + n6 * 5 + n5 * 6 + n4 * 7 + n3 * 8 + n2
			* 9 + n1 * 10;
	d1 = 11 - (mod(d1, 11));

	if (d1 >= 10)
		d1 = 0;
	var d2 = d1 * 2 + n9 * 3 + n8 * 4 + n7 * 5 + n6 * 6 + n5 * 7 + n4 * 8 + n3
			* 9 + n2 * 10 + n1 * 11;
	d2 = 11 - (mod(d2, 11));

	if (d2 >= 10)
		d2 = 0;
	retorno = '' + n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + d1 + d2;

	cpf.value = retorno;
}
// Inicio mascara cpf/cnpj
// ============================================================================================================
function mascaraTexto(evento, mascara) {
	var valor, i, j;
	if (document.all) // Internet Explorer
		campo = evento.srcElement;
	else
		// Nestcape, Mozzila
		campo = evento.target;
	campo.maxLength = mascara.length + 1;
	if (campo.value.charAt(0) == '0')
		valor = campo.value.substring(1, campo.value.length);
	else
		valor = campo.value;
	if (valor.length > mascara.length)
		valor = valor.substring(0, valor.length - 1);
	campo.value = "";
	for (j = valor.length, i = mascara.length; j > 0; --i) {
		while (--j >= 0 && (valor.charAt(j) < '0' || valor.charAt(j) > '9'))
			;
		if (j >= 0) {
			while (mascara.charAt(i) != '9')
				campo.value = mascara.charAt(i--) + campo.value;
			campo.value = valor.charAt(j) + campo.value;
		}
	}
	while (i >= 0) {
		while (mascara.charAt(i) != '9')
			campo.value = mascara.charAt(i--) + campo.value;
		campo.value = '0' + campo.value;
		i--;
	}
}
function testaDv() {
	if ((frmServico.nat_cid[0].checked == true)
			&& (frmServico.parametro.value.length > 15)) {
		alert("Entre com um CPF correto.");
		frmServico.parametro.focus();
		return false;
	} else if ((frmServico.nat_cid[1].checked == true)
			&& (frmServico.parametro.value.length > 19)) {
		alert("Entre com um CNPJ correto.");
		frmServico.parametro.focus();
		return false;
	} else {
		var i = 0;
		nCnpjCpf = frmServico.parametro.value;
		num = "";
		while (i < nCnpjCpf.length) {
			if (nCnpjCpf.charAt(i) != '.' && nCnpjCpf.charAt(i) != '-'
					&& nCnpjCpf.charAt(i) != '/')
				num += nCnpjCpf.charAt(i);
			i++;
		}
		if (parseFloat(num) == 0 || num == "") {
			alert("Preencha CPF/CNPJ");
			return false;
		}
		if (num.length == 11)
			return testeCpf(num);
		if (num.length == 14)
			return testeCnpj(num);
		alert("CPF/CNPJ incorreto");
		return false;
	}
}
function testeCpf(num) {
	var i, tot = 0;
	if (num == "00000000000" || num == "11111111111" || num == "22222222222"
			|| num == "33333333333" || num == "44444444444"
			|| num == "55555555555" || num == "66666666666"
			|| num == "77777777777" || num == "88888888888"
			|| num == "99999999999") {

		alert("CPF inválido.");
		return false;
	}
	for (i = 0; i <= 8; i++)
		tot += (i + 2) * parseInt(num.charAt(8 - i));
	dv1 = parseInt(num.charAt(9));
	if ((tot * 10 % 11 % 10) != dv1) {
		alert("CPF inválido.");
		return (false);
	}
	tot = 0;
	for (i = 0; i <= 9; i++)
		tot += (i + 2) * parseInt(num.charAt(9 - i));
	dv2 = parseInt(num.charAt(10));
	if ((tot * 10 % 11 % 10) != dv2) {
		alert("CPF inválido.");
		return false;
	}
	return true;
}
function testeCnpj(num) {
	var i, tot = 0;
	if (num == "11111111111111" || num == "22222222222222"
			|| num == "33333333333333" || num == "44444444444444"
			|| num == "55555555555555" || num == "66666666666666"
			|| num == "77777777777777" || num == "88888888888888"
			|| num == "99999999999999" || num == "00000000000000") {

		alert("CNPJ inválido.");
		return false;
	}

	for (i = 0; i <= 11; i++) {
		j = i + 2;
		if (j > 9)
			j -= 8;
		tot += j * parseInt(num.charAt(11 - i));
	}
	dv1 = parseInt(num.charAt(12));
	if ((tot * 10 % 11 % 10) != dv1) {
		alert("CNPJ inválido.");
		return false;
	}
	tot = 0;
	for (i = 0; i <= 12; i++)
		tot += (i > 7 ? i - 6 : i + 2) * parseInt(num.charAt(12 - i));
	dv2 = parseInt(num.charAt(13));
	if ((tot * 10 % 11 % 10) != dv2) {
		alert("CNPJ inválido.");
		return false;
	}
	return true;
}

/*
 * function envia() { if (filtroProcessoForm.idOrgao.value == "") {
 * alert("preencha ORGÃO"); filtroProcessoForm.idOrgao.focus(); return false; }
 * if (!verCnpjCpf()) return false; if (!testaDv()) {
 * filtroProcessoForm.cnpjCpf.focus(); return false; } if
 * (filtroProcessoForm.idServico.value == ""){ alert("preecha SERVIÇO");
 * filtroProcessoForm.idServico.focus(); return false; } return true; }
 */
function verCnpjCpf() {
	if (frmServico.nat_cid[0].checked != true
			&& frmServico.nat_cid[1].checked != true) {
		alert("Marque um TIPO de PESSOA");
		frmServico.nat_cid[0].focus();
		return false;
	}
	return true;
}
function formataCPF(CPF) {
	if (CPF.value.length != 0) {
		with (CPF) {
			value = value.substr(0, 3) + '.' + value.substr(3, 3) + '.'
					+ value.substr(6, 3) + '-' + value.substr(9, 2);
		}
	} else {
		return;
	}

}
function formataCNPJ(CPF) {
	if (CPF.value.length != 0) {
		with (CPF) {
			value = value.substr(0, 2) + '.' + value.substr(2, 3) + '.'
					+ value.substr(5, 3) + '/' + value.substr(8, 4) + '-'
					+ value.substr(12, 2);
		}
	} else {
		return;
	}
}
function desmarcaCheck() {
	if (document.frmServico.anonimo.checked) {
		document.frmServico.anonimo.checked = false;
	}
}
// ============================================================================================================
// fim mascara cpf/cnpj

//Contador TextArea Referencia do Endereço
var limiteRefEnd = 200;

function somaRefEnd() {

	var mais_um = eval(document.frmServico.ref_end_ate.value.length - 1);
	mais_um++;

	if (document.frmServico.ref_end_ate.value.length > limiteRefEnd) {
		document.frmServico.ref_end_ate.value = '';
		document.frmServico.ref_end_ate.value = valor_limite;
		alert("Você deve digitar no máximo " + limiteRefEnd + " caracteres");
	} else {
		document.frmServico.exibeRefEnd.value = '';
		document.frmServico.exibeRefEnd.value = eval(mais_um);
		valor_limite = document.frmServico.ref_end_ate.value;
		document.frmServico.exibeRefEnd2.value = '';
		document.frmServico.exibeRefEnd2.value = (limiteRefEnd - mais_um);
	}

	document.frmServico.ref_end_ate.focus();
}
//Contador TextArea Detalhamento Solicitação
var limiteDetalhamento = 2000;

function somaDetalhamento() {

	var mais_um = eval(document.frmServico.obs_ate.value.length - 1);
	mais_um++;

	if (document.frmServico.obs_ate.value.length > limiteDetalhamento) {
		document.frmServico.obs_ate.value = '';
		document.frmServico.obs_ate.value = valor_limite;
		alert("Você deve digitar no máximo " + limiteDetalhamento + " caracteres");
	} else {
		document.frmServico.exibeDet.value = '';
		document.frmServico.exibeDet.value = eval(mais_um);
		valor_limite = document.frmServico.obs_ate.value;
		document.frmServico.exibeDet2.value = '';
		document.frmServico.exibeDet2.value = (limiteDetalhamento - mais_um);
	}

	document.frmServico.obs_ate.focus();
}
