function digitoVerificador(cpf) {
	erro = new String;
	if (cpf.length < 11) {
		erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) {
		erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
	}
	if (cpf == "00000000000" || 
		cpf == "11111111111" || 
		cpf == "22222222222" || 
		cpf == "33333333333" || 
		cpf == "44444444444" || 
		cpf == "55555555555" || 
		cpf == "66666666666" || 
		cpf == "77777777777" || 
		cpf == "88888888888" || 
		cpf == "99999999999") {
		erro += "Número de CPF inválido"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i = 0; i < 11; i++) {
		a[i] = cpf.charAt(i);
		if (i < 9) {
			b += (a[i] * --c);
		}
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] * c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])) {
		erro += "Número de CPF inválido";
	}
	if (erro.length > 0) {
		alert(erro);
		return false;
	}
	return true;
}

function caseUp(id) {
	var valor = document.getElementById(id);
	valor.value = valor.value.toUpperCase();
}

function checaEmail(campo) {
	var campo = document.getElementById(campo);
	if (campo.value == "") {
	} 
	else {
		prim = campo.value.indexOf("@");
		if (prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if (campo.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if (campo.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if (campo.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("www") > 0) {
			alert("O e-mail informado não pode conter www.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf(",") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
		else if(campo.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			campo.focus();
			campo.select();
			return false;
		}
	}
	return true;
}

function showTeste(){

	alert('Teste de include arquivo script.js.  Arquivo incluido com sucesso. ');

}

function validarCampos() {
	
//	alert('Teste de include arquivo script.js.  Arquivo incluido com sucesso. ');
	
	var cpf          = document.getElementById('cpf');
	var nome         = document.getElementById('nome');
	var diaNasc      = document.getElementById('diaNasc');
	var mesNasc      = document.getElementById('mesNasc');
	var anoNasc      = document.getElementById('anoNasc');
	var sexo         = document.getElementById('sexo');
	var endereco     = document.getElementById('endereco');
	var bairro       = document.getElementById('bairro');
	var cidade       = document.getElementById('cidade');
	var uf           = document.getElementById('uf');
	var cep          = document.getElementById('cep');
	var email        = document.getElementById('email');
	var escolaridade = document.getElementById('escolaridade');
	var ocupacao     = document.getElementById('ocupacao');
	
	if (ehVazio(nome.value)) {
		alert("Campo obrigatório");
		nome.focus();
		return false;
	}
	else if (ehVazio(cpf.value)) {
		alert("Campo obrigatório");
		cpf.focus();
		return false;
	}
	else if (!digitoVerificador(cpf.value)) {
		cpf.focus();
		return false;
	}
	else if (ehVazio(diaNasc.value)) {
		alert("Campo obrigatório");
		diaNasc.focus();
		return false;
	}
	else if (ehVazio(mesNasc.value)) {
		alert("Campo obrigatório");
		mesNasc.focus();
		return false;
	}
	else if (ehVazio(anoNasc.value)) {
		alert("Campo obrigatório");
		anoNasc.focus();
		return false;
	}
	else if (ehVazio(sexo.value)) {
		alert("Campo obrigatório");
		sexo.focus();
		return false;
	}
	else if (ehVazio(endereco.value)) {
		alert("Campo obrigatório");
		endereco.focus();
		return false;
	}
	else if (ehVazio(bairro.value)) {
		alert("Campo obrigatório");
		bairro.focus();
		return false;
	}
	else if (ehVazio(cidade.value)) {
		alert("Campo obrigatório");
		cidade.focus();
		return false;
	}
	else if (ehVazio(uf.value)) {
		alert("Campo obrigatório");
		uf.focus();
		return false;
	}
	else if (ehVazio(cep.value)) {
		alert("Campo obrigatório");
		cep.focus();
		return false;
	}
	else if (!ehVazio(email.value) && !checaEmail(email)) {		
		email.focus();
		return false;
	}
	else if (ehVazio(escolaridade.value)) {
		alert("Campo obrigatório");
		escolaridade.focus();
		return false;
	}
	else if (ehVazio(ocupacao.value)) {
		alert("Campo obrigatório");
		ocupacao.focus();
		return false;
	}
	else {
		return true;
	}
}

function ehVazio(variavel) {
	if (variavel == null || variavel == "") {
		return true
	}
	return false
}


function verImpressao(pagina) {
window.open("includes/verImpressao.php?pagina="+pagina+"&botao=false","janela","resizable=1,width=500,height=500,scrollbars=YES");

}

function showstuff(boxid){
   document.getElementById(boxid).style.visibility="visible";
}

function hidestuff(boxid){
   document.getElementById(boxid).style.visibility="hidden";
}


// OPEN BROWSER WINDOW - IMPRESSAO DO CARTAO DE PROVA - CURSO RESPONSANBILIDADE
// FABIANO VIANA - 29/07/08

function goTo(){
var url = document.forms.popup.url.value;
window.open('/responsabilidade/textos/imp_cartao_model2.php?cpf_menu='+url,'wdetail','height=260,width=400');
return false;
}

