//Javascript Document

function ConsisteLogin(){
		with(document.frmAutentica){
				if (user.value==""){
					alert("Você deve preencher o campo USUÁRIO!");
					user.focus();
					return false;
				} else {
					if (password.value==""){
						alert("Você deve preencher o campo SENHA!");
						password.focus();
						return false;
					} else {
						if (cod_cliente.value==""){
							alert("Você deve selecionar o campo CLIENTE!");
							cod_cliente.focus();
							return false;
						} else {
							if (cod_cliente.value.length<4){
								alert("Código deve conter quatro dígitos!");
								cod_cliente.value='';
								cod_cliente.focus();
								return false;
							} else {
								return true;
							}
						}
					}
				}
		}
}

function chkCpf (valor) {

 

 strcpf = valor;

 str_aux = "";

 

 for (i = 0; i <= strcpf.length - 1; i++)

   if ((strcpf.charAt(i)).match(/\d/)) 

     str_aux += strcpf.charAt(i);

   else if (!(strcpf.charAt(i)).match(/[\.\-]/)) {

     alert ("O campo CPF apresenta caracteres inválidos !!!");
     return false;

   }

 

 if (str_aux.length != 11) {

   alert ("O campo CPF deve conter 11 dígitos !!!");

   return false;

 }

 if (str_aux == "00000000000" || str_aux == "11111111111" || str_aux == "22222222222" || str_aux == "33333333333" || str_aux == "44444444444" || str_aux == "55555555555" || str_aux == "66666666666" || str_aux == "77777777777" || str_aux == "88888888888" || str_aux == "99999999999"){
	alert("Número de CPF inválido!!!");
	return false;	
 }

 soma1 = soma2 = 0;

 for (i = 0; i <= 8; i++) {

   soma1 += str_aux.charAt(i) * (10-i);

   soma2 += str_aux.charAt(i) * (11-i);

 }

 d1 = ((soma1 * 10) % 11) % 10;

 d2 = (((soma2 + (d1 * 2)) * 10) % 11) % 10;

 if ((d1 != str_aux.charAt(9)) || (d2 != str_aux.charAt(10))) {

   alert ("O CPF digitado é inválido !!!");

   return false;

 }



 return true;

}

function ConsisteCPF_Manifestacao(valor){
		if (chkCpf(valor)){
			return true;
		} else {
			document.cad_manifestacao.cpf.value = '';
			return false;
		}
}

function Cad_Manifestacao(){
	with(document.cad_manifestacao){
		cadastrar.value = "Cadastrando manifestação...";
		cadastrar.disabled = true;
		limpar.disabled = true;
		if (nome.value == ""){
			alert("Você deve preencher o campo NOME!");
			nome.focus();
			cadastrar.value = "Cadastrar";
		    cadastrar.disabled = false;
    		limpar.disabled = false;
			return false;
		} else {
			if (endereco.value == ""){
				alert("Você deve preencher o campo ENDEREÇO!");
				endereco.focus();
				cadastrar.value = "Cadastrar";
			    cadastrar.disabled = false;
    			limpar.disabled = false;
				return false;
			} else {
				if (cidade.value == ""){
					alert("Você deve preencher o campo CIDADE!");
					cidade.focus();
					cadastrar.value = "Cadastrar";
				    cadastrar.disabled = false;
	    			limpar.disabled = false;
					return false;
				} else {
					if (telefone1.value == ""){
						alert("Você deve preencher o campo TELEFONE 1!");
						telefone1.focus();
						cadastrar.value = "Cadastrar";
					    cadastrar.disabled = false;
		    			limpar.disabled = false;
						return false;
					} else {
						if (descricao.value == ""){
									alert("Você deve preencher a MANIFESTAÇÃO!");
									descricao.focus();
									cadastrar.value = "Cadastrar";
								    cadastrar.disabled = false;
				    				limpar.disabled = false;
									return false;
								} else {
									if (confirmSelecionaCad()){
									if (confirm("Você confirma os dados?")){
										return true;
									} else {
										cadastrar.value = "Cadastrar";
									    cadastrar.disabled = false;
					    				limpar.disabled = false;
										return false;
									}
									} else {
										cadastrar.value = "Cadastrar";
							 			cadastrar.disabled = false;
    									limpar.disabled = false;
										return false;
									}
								}
							} else {
								cadastrar.value = "Cadastrar";
							    cadastrar.disabled = false;
    							limpar.disabled = false;
								return false;
							}
						}
					}
				
			}
		}
	}


function confirmSelecionaCad(){
		with(document.cad_manifestacao){
			if (tp_manifestacao.value=="Selecione..."){
				alert("Você deve selecionar um TIPO DE MANIFESTAÇÃO!");
				return false;
			} else {
				if (area_responsavel.value=="Selecione..."){
					alert("Você deve selecionar uma ÁREA RESPONSÁVEL!");
					return false;
				} else {
					if (tp_problema.value=="Selecione..."){
						alert("Você deve selecionar um TIPO DE PROBLEMA!");
						return false;
					} else {
						if (prioridade.value=="Selecione..."){
							alert("Você deve selecionar uma PRIORIDADE!");
							return false;
						} else {
							return true;
						}
					}
				}
			}
		}
}

function Resposta_Manif(){
	with(document.res_manifestacao){
		if (solucionada.checked==false){
			if (descricao.value==""){
				alert("Você deve preencher o campo RESPOSTA!");
				descricao.focus();
				return false;
			}
		}
	}
}

function showLevelResposta(show){
	var ie=navigator.appName.toLowerCase().indexOf("microsoft")>=0;
	var tabela = document.getElementById(show);
	if ( tabela.style.display == "none") {
		document.all.fechar_registro.style.display = "none";
		document.all.reencaminhar.style.display = "none";
		tabela.style.display = (ie)? "block" : "table-row";
	} else {
		tabela.style.display = "none";
	}
}

function showLevelManif(show){
	var ie=navigator.appName.toLowerCase().indexOf("microsoft")>=0;
	var tabela = document.getElementById(show);
	if ( tabela.style.display == "none") {
		document.all.fechar_registro.style.display = "none";
		//document.all.reencaminhar.style.display = "none";
		tabela.style.display = (ie)? "block" : "table-row";
	} else {
		tabela.style.display = "none";
	}
}
				