var public_ja_consta = "#_public_ja_consta";
var public_erro = "#_public_erro";
var public_nao_consta = "#_public_nao_consta";

function AbrirAjax() {
	
	var xmlhttp;
	try {
		//Para o Internet Explorer
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e) {
	 try {
	  //Para o Internet Explorer
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(ex) {
	  try {
	   //Para todos os outros Browsers (FireFox,Opera, etc ...)
	   xmlhttp = new XMLHttpRequest();
	  }
	  catch(exc) {
	   alert("Seu navegador não tem recursos para uso de Ajax");
	   xmlhttp = null;
	  }
	 }
	}
	return xmlhttp;
}

function loadConteudo(arquivo, vidro){
		
	var Ajax = new AbrirAjax();
	Ajax.open('post', "/", true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	if (!vidro){
		
		Ajax.onreadystatechange = function(){
			if (Ajax.readyState == 1){
			document.getElementById('corpo').innerHTML = "<p><p><p><p><center><img src='/images/gerais/loading.gif' width='32' height='32' /></center>";	
			}
			if(Ajax.readyState == 4) document.getElementById('corpo').innerHTML = Ajax.responseText;		}
	}
	else{
		
		AbrirVidro();
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 4) VidroConteudo(Ajax.responseText);
		}		
	}
	
	var dados =	"acao=request" + 
				"&request=view" + 
				"&arquivo=" + arquivo;
		
	Ajax.send(dados);
}


function loadView(arquivo, elemento_destino_id, vidro){
		
	var Ajax = new AbrirAjax();
	Ajax.open('post', "/", true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	if (!vidro){
		
		Ajax.onreadystatechange = function(){
			if (Ajax.readyState == 1){
			document.getElementById(elemento_destino_id).innerHTML = "<p><p><p><p><center><img src='/images/gerais/loading.gif' width='32' height='32' /></center>";	
			}
			if(Ajax.readyState == 4) document.getElementById(elemento_destino_id).innerHTML = Ajax.responseText;		}
	}
	else{
		
		AbrirVidro();
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 4) VidroConteudo(Ajax.responseText);
		}		
	}
	
	var dados =	"acao=request" + 
				"&request=view" + 
				"&arquivo=" + arquivo;
		
	Ajax.send(dados);
}



function AbrirVidro(){
	
	var vidro = document.createElement("div");
	vidro.setAttribute('class', 'vidro');
	vidro.setAttribute('id', 'vidro');
	vidro.ondblclick = function (){ FecharVidro();};
	document.body.appendChild(vidro);
	
	var folha_moldura = document.createElement("div");
	folha_moldura.setAttribute('class', 'folha_moldura');
	folha_moldura.setAttribute('id', 'folha_moldura');
	folha_moldura.ondblclick = function (){ FecharVidro();};
	var folha_moldura = document.body.appendChild(folha_moldura);
	
	var folha_estrutura = document.createElement("div");
	folha_estrutura.setAttribute('class', 'folha_estrutura');
	folha_estrutura.setAttribute('id', 'folha_estrutura');
	folha_estrutura.ondblclick = function (){ FecharVidro();};
	var folha_estrutura = folha_moldura.appendChild(folha_estrutura);
	
	var folha_barra = document.createElement("div");
	folha_barra.setAttribute('class', 'folha_barra');
	folha_barra.setAttribute('id', 'folha_barra');
	folha_barra.innerHTML="<a onClick='FecharVidro()' style='cursor:pointer' title='Fechar'>[x]</a>";
	folha_estrutura.appendChild(folha_barra);
	
	var folha_conteudo = document.createElement("div");
	folha_conteudo.setAttribute('class', 'folha_conteudo');
	folha_conteudo.setAttribute('id', 'folha_conteudo');
	var folha_conteudo = folha_estrutura.appendChild(folha_conteudo);
	
	document.getElementById('folha_conteudo').innerHTML="<h3>processando...</h3>";
	var Imagem = document.createElement("img");
	Imagem.setAttribute("src", "/images/gerais/loading.gif");		
	document.getElementById('folha_conteudo').appendChild(Imagem);	
}

function VidroConteudo(conteudo){
	
	if (document.getElementById('folha_conteudo')){
		document.getElementById('folha_conteudo').innerHTML=conteudo;
	}
	else alert('Erro. Vidro não encontrado.');
}

function FecharVidro(){
	
	document.body.removeChild(document.getElementById('vidro'));
	document.body.removeChild(document.getElementById('folha_moldura'));
}

function processar_length(field, countfield, maxlimit) {
	
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
	else 
	countfield.value = maxlimit - field.value.length;
}

function submit_msg(unidade){
	
	if (!document.getElementById('assunto').value){
		
		alert('Selecione o assunto');
		document.getElementById('assunto').focus();
		return;	
	}
	if (!document.getElementById('nome').value){
		
		alert('Informe seu nome');
		document.getElementById('nome').focus();
		return;	
	}
	if (!document.getElementById('telefone').value){
		
		alert('Informe seu telefone');
		document.getElementById('telefone').focus();
		return;	
	}
	if (!document.getElementById('email').value){
		
		alert('Informe seu e-mail');
		document.getElementById('email').focus();
		return;	
	}
	
	if (document.getElementById('texto').length > 500){
		
		alert('A mensagem não pode possuir mais de 500 caracteres');
		return;	
	}
	
	if (document.getElementById('texto').value < 1){
		
		alert('Sem mensagem');
		document.getElementById('texto').focus();
		return;	
	}
	
	var assunto = document.getElementById('assunto').value;
	var nome 	= document.getElementById('nome').value;
	var telefone = document.getElementById('telefone').value;
	var email 	= document.getElementById('email').value;
	var msg		= document.getElementById('texto').value;
	
	var Ajax = new AbrirAjax();
	Ajax.open('post', '/', true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	Ajax.onreadystatechange = function () {
		
		if (Ajax.readyState == 1){
			
			AbrirVidro();
		}
		
		if (Ajax.readyState == 4){
						
			if(Ajax.responseText == public_erro){
				alert("Houve um erro na requisição. Mensagem não enviada. Contacte o suporte.");
				FecharVidro();
				return;
			}
			
			alert("Mensagem enviada com sucesso");
			loadConteudo('/unidades/feap/Contato.php', false);
			FecharVidro();
			return;
		}
	}
	
	var info =  "acao=save" +
				"&target=mensagem" +
				"&dado=mensagem" +
				"&unidade=" + unidade +
				"&assunto=" + assunto +
				"&nome=" + nome +
				"&telefone=" + telefone +
				"&email=" + email +
				"&msg=" + msg;
	
	Ajax.send(info);


}

function tratar_duplo_clique(){
	
	if(document.getElementById('clicked')){
	
		if (document.getElementById('clicked').value == '1'){
			setTimeout("document.getElementById('clicked').value = '0'", 1500);
			return false;
		}
		else {
			document.getElementById('clicked').value = '1';
			setTimeout("document.getElementById('clicked').value = '0'", 1500);
			return true;
		}
	}
}

function loadUnidade(arquivo, vidro){
		
	var Ajax = new AbrirAjax();
	Ajax.open('post', "/", true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	if (!vidro){
		
		Ajax.onreadystatechange = function(){
			if (Ajax.readyState == 1){	
			}
			
			if(Ajax.readyState == 4){
				document.getElementById('unidade_div').innerHTML = Ajax.responseText;
			}
		}
	}
	else{
		
		AbrirVidro();
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 4) VidroConteudo(Ajax.responseText);
		}		
	}
	
	var dados =	"acao=request" + 
				"&request=view" + 
				"&arquivo=" + arquivo;
		
	Ajax.send(dados);
}

function loadCurso(arquivo, vidro){
		
	var Ajax = new AbrirAjax();
	Ajax.open('post', "/", true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	if (!vidro){
		
		Ajax.onreadystatechange = function(){
			if (Ajax.readyState == 1){
				AbrirVidro();	
			}
			
			if(Ajax.readyState == 4)
				FecharVidro();
				document.getElementById('curso_div').innerHTML = Ajax.responseText;
		}
	}
	else{
		
		AbrirVidro();
		Ajax.onreadystatechange = function(){
			if(Ajax.readyState == 4) VidroConteudo(Ajax.responseText);
		}		
	}
	
	var dados =	"acao=request" + 
				"&request=view" + 
				"&arquivo=" + arquivo;
		
	Ajax.send(dados);
}

///////////////////////////////////////////////////////////////////
///////  VESTIBULAR ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

function vest_zerar_status_opcao(elemento, opcao_selecionada){
	
	var child_lenght = elemento.childNodes.length;
	var count = 0;	
	
	if (elemento.value == opcao_selecionada) elemento.selectedIndex = 0;
	
	while (count <= child_lenght){
		
		if(elemento.childNodes[count].value){
			
			if((elemento.childNodes[count].value == opcao_selecionada) && (elemento.childNodes[count].value > 0))
				elemento.childNodes[count].style.display='none';				
			
			else
				elemento.childNodes[count].style.display='block';
		}
		count++;
	}
}

function processar_opcao(elemento){
	
	var opcao_selecionada = elemento.value;
	
	var elemento_opcao_1 = document.getElementById('curso_opcao_1');
	var elemento_opcao_2 = document.getElementById('curso_opcao_2');
	var elemento_opcao_3 = document.getElementById('curso_opcao_3');
	
	if(elemento == elemento_opcao_1) vest_zerar_status_opcao(elemento_opcao_2, opcao_selecionada);
	
	if(elemento == elemento_opcao_2) vest_zerar_status_opcao(elemento_opcao_3, opcao_selecionada);
	
	if(elemento == elemento_opcao_3) vest_zerar_status_opcao(elemento_opcao_1, opcao_selecionada);
}

function save_vest_inscricao(){
	
	if(tratar_duplo_clique() == false){
		alert('Clique apenas uma vez');
		return;
	}
	
	if (!document.getElementById('curso_opcao_1').value){
		alert('Escolha a primeira opção de curso');
		document.getElementById('curso_opcao_1').focus();
		return;
	}
	
	if((document.getElementById('curso_opcao_3').value) && (!document.getElementById('curso_opcao_2').value)){
		alert('Escolha a segunda opção de curso');
		document.getElementById('curso_opcao_2').focus();
		return;
	}
	
	if(!document.getElementById('lingua').value || document.getElementById('lingua').value == null){
		alert('Selecione a opção de Língua Estrangeira!');
		document.getElementById('lingua').focus();
		return;
	}
	
	if(document.getElementById('prenome').value == '' || document.getElementById('prenome').value == null){
		document.getElementById('prenome').focus();
		alert('O campo Prenome é obrigatório!');
		return;
	}
	
	if(document.getElementById('sobrenome').value == ''  || document.getElementById('sobrenome').value == null){
		document.getElementById('sobrenome').focus();
		alert('O campo Sobrenome é obrigatório!');
		return;
	}
	
	if(document.getElementById('cpf').value == ''  || document.getElementById('cpf').value == null){
		document.getElementById('cpf').focus();	
		alert('O campo CPF é obrigatório!');
		return;
	}
	
	if(document.getElementById('cpf').value.length != 11){
		document.getElementById('cpf').focus();	
		alert('O campo CPF deve conter 11 dígitos!');
		return;
	}	
	
	if(document.getElementById('naturalidade').value == '' || document.getElementById('naturalidade').value == null){
		document.getElementById('naturalidade').focus();	
		alert('O campo Naturalidade é obrigatório!');
		return;
	}
	
	if(document.getElementById('nascimento_dia').value == '' || document.getElementById('nascimento_dia').value == null){
		document.getElementById('nascimento_dia').focus();
		alert('O campo Dia de Nascimento é obrigatório!');
		return;
	}
	
	if(document.getElementById('nascimento_dia').value.length != 2){
		document.getElementById('nascimento_dia').focus();
		alert('O campo Dia de Nascimento deve conter 2 dígitos!');
		return;
	}
	
	if(document.getElementById('nascimento_mes').value == ''  || document.getElementById('nascimento_mes').value == null){
		document.getElementById('nascimento_mes').focus();
		alert('O campo Mês de Nascimento é obrigatório!');
	return;
	}

	if(document.getElementById('nascimento_mes').value.length != 2){
		document.getElementById('nascimento_mes').focus();
		alert('O campo Mês de Nascimento deve conter 2 dígitos!');
		return;
	}
	
	if(document.getElementById('nascimento_ano').value == ''  || document.getElementById('nascimento_ano').value == null){
		document.getElementById('nascimento_ano').focus();
		alert('O campo Ano de Nascimento é obrigatório!');
		return;
	}

	if(document.getElementById('nascimento_ano').value.length != 4){
		document.getElementById('nascimento_ano').focus();
		alert('O campo Ano de Nascimento deve conter 4 dígitos!');
		return;
	}

	if(document.getElementById('profissao').value == '' || document.getElementById('profissao').value == null){
		document.getElementById('profissao').focus();
		alert('O campo Profissão é obrigatório!');
		return;
	}
	
	if(document.getElementById('nacionalidade').value == '' || document.getElementById('nacionalidade').value == null){
		document.getElementById('nacionalidade').focus();
		alert('O campo Nacionalidade é obrigatório!');
		return;
	}
	
	if(document.getElementById('renda').value == '' || document.getElementById('renda').value == null){
		document.getElementById('renda').focus();
		alert('O campo Renda Familiar é obrigatório!');
		return;
	}
	
	if(document.getElementById('mae').value == '' || document.getElementById('mae').value == null){
		document.getElementById('mae').focus();
		alert('O campo Nome da Mãe é obrigatório!');
		return;
	}
	
	if(document.getElementById('rg_numero').value == '' || document.getElementById('rg_numero').value == null){
		document.getElementById('rg_numero').focus();
		alert('O campo RG(Número) é obrigatório!');
		return;
	}
	
	if(document.getElementById('rg_emissor').value == '' || document.getElementById('rg_emissor').value == null){
		document.getElementById('rg_emissor').focus();
		alert('O campo RG(Órgão Emissor) é obrigatório!');
		return;
	}
	
	if(document.getElementById('rg_emissao_dia').value == '' || document.getElementById('rg_emissao_dia').value == null){
		document.getElementById('rg_emissao_dia').focus();
		alert('O campo RG(Data de Emissão) é obrigatório!');
		return;
	}

	if(document.getElementById('rg_emissao_dia').value.length != 2){
		document.getElementById('rg_emissao_dia').focus();
		alert('O campo RG (Data de Emissão) deve conter 2 dígitos!');
		return;
	}
	
	if(document.getElementById('rg_emissao_dia').value > 31){
		document.getElementById('rg_emissao_dia').focus();
		alert('O campo RG (Data de Emissão) não pode conter valores acima de 31!');
		return;
	}	

	if(document.getElementById('rg_emissao_mes').value == '' || document.getElementById('rg_emissao_mes').value == null){
		document.getElementById('rg_emissao_mes').focus();
		alert('O campo RG(Data de Emissão) é obrigatório!');
		document.getElementById('rg_emissao_mes').focus();
		return;
	}

	if(document.getElementById('rg_emissao_mes').value.length != 2){
		document.getElementById('rg_emissao_mes').focus();
		alert('O campo RG (Data de Emissão) deve conter 2 dígitos!');
		return;
	}
	
	if(document.getElementById('rg_emissao_mes').value.length != 2){
		document.getElementById('rg_emissao_mes').focus();
		alert('O campo RG (emissão) deve conter 2 dígitos!');
		return;
	}	

	if(document.getElementById('rg_emissao_ano').value == '' || document.getElementById('rg_emissao_ano').value == null){
		document.getElementById('rg_emissao_ano').focus();
		alert('O campo RG(Data de Emissão) é obrigatório!');
		return;
	}

	if(document.getElementById('rg_emissao_ano').value.length != 4){
		document.getElementById('rg_emissao_ano').focus();
		alert('O campo RG (Data de Emissão) deve conter 4 dígitos!');
		return;
	}
	
	if(document.getElementById('logradouro').value == '' || document.getElementById('logradouro').value == null){
		document.getElementById('logradouro').focus();
		alert('O campo Logradouro é obrigatório!');
		return;
	}
	
	if(document.getElementById('numero').value == '' || document.getElementById('numero').value == null){
		document.getElementById('numero').focus();
		alert('O campo Número é obrigatório!');
		return;
	}
	
	if(document.getElementById('bairro').value == '' || document.getElementById('bairro').value == null){
		document.getElementById('bairro').focus();
		alert('O campo Bairro é obrigatório!');
		return;
	}
	
	if(document.getElementById('cidade').value == '' || document.getElementById('cidade').value == null){
		document.getElementById('cidade').focus();
		alert('O campo Cidade é obrigatório!');
		return;
	}
	
	if(document.getElementById('cep').value == ''  || document.getElementById('cep').value == null){
		document.getElementById('cep').focus();
		alert('O campo CEP é obrigatório!');
		return;
	}
	
	if(document.getElementById('cep').value.length != 8){
		document.getElementById('cep').focus();
		alert('O campo CEP deve conter 8 dígitos!');
		return;
	}	
	
	if(document.getElementById('estado').value == '' || document.getElementById('estado').value == null){
		document.getElementById('estado').focus();
		alert('O campo Estado é obrigatório!');
		return;
	}
	
	if(document.getElementById('pais').value == '' || document.getElementById('pais').value == null){
		document.getElementById('pais').focus();
		alert('O campo País é obrigatório!');
		return;
	}
	if(document.getElementById('email').value == '' ||
		document.getElementById('email').value == null  ||
		document.getElementById('email').value == 'undefined'){
		
		document.getElementById('email').focus();
		alert('O campo E-Mail é obrigatório!');
		return;
	}
	if(document.getElementById('telefone').value == '' || document.getElementById('telefone').value == null){
		document.getElementById('telefone').focus();
		alert('O campo Telefone é obrigatório!');
		return;
	}
	
	var pai = document.getElementById('pai').value;
	var complemento = document.getElementById('complemento').value;
	var rg_validade_dia = document.getElementById('rg_validade_dia').value;
	var rg_validade_mes = document.getElementById('rg_validade_mes').value;	
	var rg_validade_ano = document.getElementById('rg_validade_ano').value;
	
	var curso_2 = document.getElementById('curso_opcao_2').value;
	var curso_3 = document.getElementById('curso_opcao_3').value;
	
	if(rg_validade_dia){
		
		if(document.getElementById('rg_validade_dia').value.length != 2){
			document.getElementById('rg_validade_dia').focus();
			alert('O campo RG (validade) deve conter 2 dígitos!');
			return;
		}
		
		if(document.getElementById('rg_validade_dia').value > 31){
			document.getElementById('rg_validade_dia').focus();
			alert('O campo RG (validade) não pode ter valor acima de 31!');
			return;
		}
		
		if(document.getElementById('rg_validade_mes').value.length != 2){
			document.getElementById('rg_validade_mes').focus();
			alert('O campo RG (validade) deve conter 2 dígitos!');
			return;
		}
		
		if(document.getElementById('rg_validade_mes').value > 12){
			document.getElementById('rg_validade_mes').focus();
			alert('O campo RG (validade) não pode conter valor acima de 12!');
			return;
		}
		
		if(document.getElementById('rg_validade_ano').value.length != 4){
			document.getElementById('rg_validade_ano').focus();
			alert('O campo RG (validade) deve conter 4 dígitos!');
			return;
		}
		
	}
					
	var Ajax = new AbrirAjax();
	Ajax.open('post', '/', true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	Ajax.onreadystatechange = function () {
		
		if (Ajax.readyState == 1){
			
			AbrirVidro();
		}
		
		if (Ajax.readyState == 4){
			
			if(Ajax.responseText == public_erro){
				alert("Houve um erro na requisição. Inscrição não realizada. Contacte o suporte.");
				FecharVidro();
				return;
			}
			
			if(Ajax.responseText == public_ja_consta){
				alert("Inscrição deste CPF já realizada.");
				FecharVidro();
				return;
			}
			
			FecharVidro();
			document.getElementById('body').innerHTML = Ajax.responseText;
			return;
		}
	}
	
	var info =  "acao=save" +
				"&controller=controllerVestibular.php" +
				"&target=vestibular" +
				"&dado=inscricao" +
				"&curso_1=" + document.getElementById('curso_opcao_1').value +
				"&lingua=" + document.getElementById('lingua').value +
				"&prenome=" + document.getElementById('prenome').value +
				"&sobrenome=" + document.getElementById('sobrenome').value +
				"&sexo=" + document.getElementById('sexo').value +
				"&estado_civil=" + document.getElementById('estado_civil').value +
				"&cpf=" + document.getElementById('cpf').value +
				"&naturalidade=" + document.getElementById('naturalidade').value +
				"&nascimento_dia=" + document.getElementById('nascimento_dia').value +
				"&nascimento_mes=" + document.getElementById('nascimento_mes').value +
				"&nascimento_ano=" + document.getElementById('nascimento_ano').value +
				"&profissao=" + document.getElementById('profissao').value +
				"&mae=" + document.getElementById('mae').value +
				"&rg_numero=" + document.getElementById('rg_numero').value +
				"&rg_emissor=" + document.getElementById('rg_emissor').value +
				"&rg_emissao_dia=" + document.getElementById('rg_emissao_dia').value +
				"&rg_emissao_mes=" + document.getElementById('rg_emissao_mes').value +
				"&rg_emissao_ano=" + document.getElementById('rg_emissao_ano').value +
				"&logradouro=" + document.getElementById('logradouro').value +
				"&numero=" + document.getElementById('numero').value +
				"&bairro=" + document.getElementById('bairro').value +
				"&cidade=" + document.getElementById('cidade').value +
				"&cep=" + document.getElementById('cep').value +
				"&estado=" + document.getElementById('estado').value +
				"&pais=" + document.getElementById('pais').value +
				"&renda=" + document.getElementById('renda').value +
				"&nacionalidade=" + document.getElementById('nacionalidade').value +
				"&email=" + document.getElementById('email').value +
				"&telefone=" + document.getElementById('telefone').value;

	if(curso_2) info +="&curso_2=" + curso_2;	
	if(curso_3) info +="&curso_3=" + curso_3;
	if(pai) info +="&pai=" + pai;
	if(complemento) info +="&complemento=" + complemento;
	if(rg_validade_dia) info +="&rg_validade_dia=" + rg_validade_dia;
	if(rg_validade_mes) info +="&rg_validade_mes=" + rg_validade_mes;
	if(rg_validade_ano) info +="&rg_validade_ano=" + rg_validade_ano;
	
	Ajax.send(info);
}

function formata_int(elemento){
	
	string = elemento.value
	tamanho = string.length;
	novaString = "";
	
	for (count = 0; count<tamanho; count++){
		
		if ((string.substring(count, count+1) == '0') ||
		   (string.substring(count, count+1) == '1') ||
		   (string.substring(count, count+1) == '2') ||
		   (string.substring(count, count+1) == '3') ||
		   (string.substring(count, count+1) == '4') ||
		   (string.substring(count, count+1) == '5') ||
		   (string.substring(count, count+1) == '6') ||
		   (string.substring(count, count+1) == '7') ||
		   (string.substring(count, count+1) == '8') ||
		   (string.substring(count, count+1) == '9')){
			
			novaString += string.substring(count, count+1);
		}
	}
	
	elemento.value = novaString;
}

function requestComprovanteInscrição(){

	// CPF //////////////////////////////
	
	if(document.getElementById('cpf').value == ''){
		document.getElementById('cpf').focus();
		alert('O campo CPF é obrigatório');
		return;
	}
	
	if(document.getElementById('cpf').value.length != 11){
		document.getElementById('cpf').focus();
		alert('O campo CPF deve conter 11 dígitos');
		return;
	}

	// DIA //////////////////////////////
	
	if(document.getElementById('nascimento_dia').value == ''){
		document.getElementById('nascimento_dia').focus();
		alert('O campo DIA é obrigatório');
		return;
	}

	if(document.getElementById('nascimento_dia').value.length != 2){
		document.getElementById('nascimento_dia').focus();
		alert('O campo DIA deve conter 2 dígitos!');
		return;
	}
	
	if(document.getElementById('nascimento_dia').value > 31){
		document.getElementById('nascimento_dia').focus();
		alert('O campo DIA não pode conter valores acima de 31!');
		return;
	}	

	// MÊS //////////////////////////////

	if(document.getElementById('nascimento_mes').value == ''){
		document.getElementById('nascimento_mes').focus();
		alert('O campo MÊS é obrigatório!');
		return;
	}

	if(document.getElementById('nascimento_mes').value > 12){
		document.getElementById('nascimento_mes').focus();
		alert('O campo MÊS não suporta valores acima de 12!');
		return;
	}
	
	if(document.getElementById('nascimento_mes').value.length != 2){
		document.getElementById('nascimento_mes').focus();
		alert('O campo MÊS deve conter 2 dígitos!');
		return;
	}	

	// ANO //////////////////////////////

	if(document.getElementById('nascimento_ano').value.length != 4){
		document.getElementById('nascimento_ano').focus();
		alert('O campo ANO deve conter 4 dígitos!');
		return;
	}

	if(document.getElementById('nascimento_ano').value == ''){
		document.getElementById('nascimento_ano').focus();
		alert('O campo ANO é obrigatório');
		return;
	}
	
	//////////////////////////////////////////
	
	var cpf = document.getElementById('cpf').value;
	var nascimento_dia = document.getElementById('nascimento_dia').value;
	var nascimento_mes = document.getElementById('nascimento_mes').value;
	var nascimento_ano = document.getElementById('nascimento_ano').value;
	
	var nascimento = nascimento_ano + nascimento_mes + nascimento_dia;
	
	var Ajax = new AbrirAjax();
	Ajax.open('post', '/', true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	Ajax.onreadystatechange = function () {
		
		if (Ajax.readyState == 1){
			
			AbrirVidro();
		}
		
		if (Ajax.readyState == 4){
			
			if(Ajax.responseText == public_erro){
				alert("Houve um erro na requisição. Inscrição não realizada. Contacte o suporte.");
				FecharVidro();
				return;
			}
			
			if(Ajax.responseText == '#_empty'){
				alert("Nenhuma inscição encontrada");
				FecharVidro();
				return;
			}
			
			if(Ajax.responseText == '#_inconsistente'){
				alert("Dados inconsistentes. Favor contactar o suporte.");
				FecharVidro();
				return;
			}
			
			FecharVidro();
			document.getElementById('body').innerHTML = Ajax.responseText;
			return;
		}
	}
	
	var info =  "acao=load" +
				"&controller=controllerVestibular.php" +
				"&target=vestibular" +
				"&dado=comprovante" +
				"&cpf=" + cpf +
				"&nascimento=" + nascimento;
				
	Ajax.send(info);
}

function vest_acesso_restrito(){
	
	if(document.getElementById('login').value == ''){
		document.getElementById('login').focus();
		alert('Informe seu login');
		return;
	}

	if(document.getElementById('pass').value == ''){
		document.getElementById('pass').focus();
		alert('Informe sua senha');
		return;
	}	 
	
	var Ajax = new AbrirAjax();
	Ajax.open('post', '/', true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	Ajax.onreadystatechange = function () {
		
		if (Ajax.readyState == 1){
			
			AbrirVidro();
		}
		
		if (Ajax.readyState == 4){
			
			if(Ajax.responseText == public_erro){
				FecharVidro();
				alert("Houve um erro na requisição. Contacte o suporte.");
				return;
			}
			
			if(Ajax.responseText == public_nao_consta){
				FecharVidro();
				alert("Dados não conferem. Cetifique-se que digitou corretamente.");
				return;
			}

			FecharVidro();
			
			window.location = "";
			return;
		}
	}
	
	var info =  "controller=controllerVestibular.php" +
				"&acao=login" +
				"&login=" + document.getElementById('login').value +
				"&pass=" + document.getElementById('pass').value;
				
	Ajax.send(info);	
}

function sair(){
	
	var Ajax = new AbrirAjax();
	Ajax.open('post', '#', true);
	Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	Ajax.setRequestHeader('encoding','UTF-8');
	Ajax.onreadystatechange = function () {
		
		if (Ajax.readyState == 4){
						
			if(Ajax.responseText == public_erro){
				alert("Houve um erro na requisição. Mensagem não enviada. Contacte o suporte.");
				FecharVidro();
				return;
			}
			
			window.location=window.location;
			return;
		}
	}
	
	var info =  "acao=logout";
	
	Ajax.send(info);	
	
}