// JavaScript Document

$(document).ready(function(){
	
	$(".cx, textarea").focus(function(){
		this.style.border = "1px solid #777";
	});
	
	$(".cx, textarea").blur(function(){
		this.style.border = "1px solid #DDD";
	});

	
	$("#requerimentoMatricula").submit(function(){
												
		
		var nome_aluno	                      = $("#nome_aluno").val();
		var idade_aluno	                      = $("#idade_aluno").val();
		var data_nascimento	                  = $("#data_nascimento").val();
		var naturalidade	                  = $("#naturalidade").val();
		var estado_nascimento	              = $("#estado_nascimento").val();
		var estado_civil	                  = $("#estado_civil").val();
		var rg_aluno	                      = $("#rg_aluno").val();
		var emissao_rg               	      = $("#emissao_rg").val();
		var cpf_aluno	                      = $("#cpf_aluno").val();
		var nome_pai	                      = $("#nome_pai").val();
		var profissao_pai                     = $("#profissao_pai").val();
		var nome_mae	                      = $("#nome_mae").val();
		var profissao_mae	                  = $("#profissao_mae").val();
		var endereco_residencial	          = $("#endereco_residencial").val();
		var numeroenderec_residencial	      = $("#numeroenderec_residencial").val();
		var complementoenderec_residencial    = $("#complementoenderec_residencial").val();
		var bairro_endereco	                  = $("#bairro_endereco").val();
		var cep_endereco	                  = $("#cep_endereco").val();
		var telefone_residencial	          = $("#telefone_residencial").val();
		var email_aluno         	          = $("#email_aluno").val();
		var referencia_nome	                  = $("#referencia_nome").val();
		var referencia_tel	                  = $("#referencia_tel").val();
		var trabalhando_sim_nao	              = document.requerimentoMatricula.trabalhando_sim_nao.checked;
		var nome_empresa	                  = $("#nome_empresa").val();
		var endereco_empresarial	          = $("#endereco_empresarial").val();
		var telefone_empresarial	          = $("#telefone_empresarial").val();
		var conhecimento_estabelecimento      = $("#conhecimento_estabelecimento").val();
		var ja_foi_aluno                      = $("#ja_foi_aluno").val();			
		//var visibilidade = document.Contato.visibilidade.checked;

		
		if(nome_aluno.length < 4){
			$("#nome_aluno").focus();
			return false;
		} else if(idade_aluno < 10){
			$("#idade_aluno").focus();
			return false;
		} else	if(data_nascimento.length < 10){
			$("#data_nascimento").focus();
			return false;
		} else	if(naturalidade.length < 2){
			$("#naturalidade").focus();
			return false;	
		} else	if(estado_nascimento.length < 2){
			$("#estado_nascimento").focus();
			return false;	
		} else	if(estado_civil.length < 5){
			$("#estado_civil").focus();
			return false;	
		} else	if(rg_aluno.length < 5){
			$("#rg_aluno").focus();
			return false;	
		} else	if(emissao_rg < 1){
			$("#emissao_rg").focus();
			return false;	
		} else	if(cpf_aluno < 1){
			$("#cpf_aluno").focus();
			return false;
		/*} else	if(nome_pai.lenght < 4){
			$("#nome_pai").focus();
			return false;
		} else	if(profissao_pai.length < 4){
			$("#profissao_pai").focus();
			return false;	*/  
		} else	if(nome_mae.length < 4){
			$("#nome_mae").focus();
			return false;	
		} else	if(profissao_mae.length < 4){
			$("#profissao_mae").focus();
			return false;	
		} else	if(endereco_residencial.length < 5){
			$("#endereco_residencial").focus();
			return false;	
		} else	if(numeroenderec_residencial.length < 1){
			$("#numeroenderec_residencial").focus();
			return false;		
		} else	if(bairro_endereco.length < 4){
			$("#bairro_endereco").focus();
			return false;
		/*} else	if(complementoenderec_residencial.length < 0){
			$("#complementoenderec_residencial").focus();
			return false; */
		} else	if(cep_endereco.length < 4){
			$("#cep_endereco").focus();
			return false;
		} else	if(telefone_residencial.length < 10){
			$("#telefone_residencial").focus();
			return false;
		} else	if(!checkMail(email_aluno) == true){
			$("#email_aluno").focus();
			return false;
		} else	if(referencia_nome.length < 4){
			$("#referencia_nome").focus();
			return false;
		} else	if(referencia_tel.length < 10){
			$("#referencia_tel").focus();
			return false;		
		} else	if(trabalhando_sim_nao == 1){
			alert(trabalhando_sim_nao);
			if(nome_empresa.length < 5){				
				$("#nome_empresa").focus();
				return false;
			} else	if(endereco_empresarial.length < 10){
				$("#endereco_empresarial").focus();
				return false;	
			} else	if(telefone_empresarial.length < 10){
				$("#telefone_empresarial").focus();
				return false;
			}
		} else {
			$.post("./gerar-requerimentos/gerar-requerimento-matricula.php",{nome_aluno:nome_aluno,idade_aluno:idade_aluno,data_nascimento:data_nascimento,naturalidade:naturalidade,estado_nascimento:estado_nascimento,estado_civil:estado_civil,rg_aluno:rg_aluno,emissao_rg:emissao_rg,cpf_aluno:cpf_aluno,nome_pai:nome_pai,profissao_pai:profissao_pai,nome_mae:nome_mae,profissao_mae:profissao_mae,endereco_residencial:endereco_residencial,numeroenderec_residencial:numeroenderec_residencial,complementoenderec_residencial:complementoenderec_residencial,bairro_endereco:bairro_endereco,cep_endereco:cep_endereco,telefone_residencial:telefone_residencial,email_aluno:email_aluno,referencia_nome:referencia_nome,referencia_tel:referencia_tel,trabalhando_sim_nao:trabalhando_sim_nao,nome_empresa:nome_empresa,endereco_empresarial:endereco_empresarial,telefone_empresarial:telefone_empresarial,conhecimento_estabelecimento:conhecimento_estabelecimento,ja_foi_aluno:ja_foi_aluno},function(data){

			//alert(data);
			location.href='sucesso.php?relatorioNumero='+data;	
			});
			return false;
		}
		
		
	});
	
});


