function passo(valor){
	endereco = valor.split("/");
//	alert(endereco);
	
	switch (endereco[3]){
		
		case 'parte1.php':
		document.getElementById('passo0').style.opacity = '0.2';
		document.getElementById('passo0').style.filter = 'alpha(opacity=20)';
		document.getElementById('passo1').style.opacity = '';
		document.getElementById('passo1').style.filter = '';
		break;
		
		case 'parte2.php':
		document.getElementById('passo0').style.opacity = '0.2';
		document.getElementById('passo0').style.filter = 'alpha(opacity=20)';
		document.getElementById('passo2').style.opacity = '';
		document.getElementById('passo2').style.filter = '';
		break;
		
		case 'parte3.php':
		document.getElementById('passo0').style.opacity = '0.2';
		document.getElementById('passo0').style.filter = 'alpha(opacity=20)';
		document.getElementById('passo3').style.opacity = '';
		document.getElementById('passo3').style.filter = '';
		break;
	}

}

function infor()
{
	document.getElementById("informacao").innerHTML = 'A 2ª OPÇÃO DE CURSO É FACULTATIVA';
	if(document.getElementById("opcao_curso_um").value != '')
		document.getElementById("opcao_curso_dois").disabled = false;
	else{
		document.getElementById("opcao_curso_dois").value = '';
		document.getElementById("opcao_curso_dois").disabled = true;
	}
}

function vestibular()
{
	if(document.getElementById("enem").checked == true){
		document.getElementById("nm_nota").style.display = '';
		document.getElementById("nota").style.display = '';
		document.getElementById("not_ene").value = '';
	}
	else if (document.getElementById("vest").checked == true){
		document.getElementById("nm_nota").style.display = 'none';
		document.getElementById("nota").style.display = 'none';
		document.getElementById("not_ene").value = '';
	}
}

function necessidade(){
	if(document.getElementById("motora").checked == true)
		document.getElementById("motora").value = "1";
	else
		document.getElementById("motora").value = "0";
			
	if(document.getElementById("visual").checked == true)
		document.getElementById("visual").value = "1";
	else
		document.getElementById("visual").value = "0";
		
	if(document.getElementById("auditiva").checked == true)
		document.getElementById("auditiva").value = "1";
	else
		document.getElementById("auditiva").value = "0";
	
	Outranecessidade = document.getElementById("outra").checked;
		if (Outranecessidade == true){
		document.getElementById("deficiencia").style.display = '';
		document.getElementById("nm_def").style.display = '';
		document.getElementById("out_def").value = '';
	}
	else{
		document.getElementById("deficiencia").style.display = 'none';
		document.getElementById("nm_def").style.display = 'none';
		document.getElementById("out_def").value = '';
	}
}


function somente_numero(campo){
        var digits="0123456789"
        var campo_temp 
        for (var i=0;i<campo.value.length;i++){
          campo_temp=campo.value.substring(i,i+1)       
          if (digits.indexOf(campo_temp)==-1){
					campo.value = campo.value.substring(0,i);
					alert('Atenção: (digite apenas os números de seu cpf)');
                    break;
        }
	}
}

function VerificaCPF (cpf_temp) {
if (vercpf(cpf_temp)){
}
else{
errors="1";
		if (errors){
			alert('Atenção: verifique o CPF informado, o mesmo não é válido');
			return false;
		}
			document.retorno = (errors == '');
	}
}


function vercpf (cpf){
	if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
		return false;
	add = 0;
	for (i=0; i < 9; i ++)
		add += parseInt(cpf.charAt(i)) * (10 - i);
		rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(9)))
		return false;
		add = 0;
	for (i = 0; i < 10; i ++)
		add += parseInt(cpf.charAt(i)) * (11 - i);
		rev = 11 - (add % 11);
	if (rev == 10 || rev == 11)
		rev = 0;
	if (rev != parseInt(cpf.charAt(10)))
		return false;
		return true;
}

function valida_form()
{
	Nome = document.getElementById("nome");
	Dia_nas = document.getElementById("dia_nas");
	Mes_nas = document.getElementById("mes_nas");
	Ano_nas = document.getElementById("ano_nas");
	Dia_exp_rg = document.getElementById("dia_exp_rg");
	Mes_exp_rg = document.getElementById("mes_exp_rg");
	Ano_exp_rg = document.getElementById("ano_exp_rg");
	Sex = document.getElementById("sex");
	Naturalidade = document.getElementById("naturalidade");
	Uf_nascimento = document.getElementById("uf_nascimento");
	Rg = document.getElementById("rg");
	Org_exp = document.getElementById("org_exp");
	Email = document.getElementById("email");
	Tel_cel = document.getElementById("tel_cel").value.replace(/^\s*/, "");
	Tel_res = document.getElementById("tel_res").value.replace(/^\s*/, "");
	Endereco = document.getElementById("endereco");
	Bairro = document.getElementById("bairro");
//	Complemento = document.getElementById("complemento")
	Numero = document.getElementById("numero");
	Cidade = document.getElementById("cidade");
	Cep = document.getElementById("cep");
	Est_reside = document.getElementById("est_reside");
	Logradouro = document.getElementById("CodigoTipoLogradouro");
	Canhotodestro = document.getElementById("canhoto").checked;
	Destro = document.getElementById("destro").checked;
	Curso = document.getElementById("opcao_curso_um");
	Nota =	document.getElementById("not_ene");
	Outranecessidad = document.getElementById("outra").checked;
	Espanhol = document.getElementById("espanhol").checked;
	Ingles = document.getElementById("ingles").checked;
	
	Selecao_fac_uni = document.getElementById("selecao_fac_uni");

	x = 670;
	y = 550;
	posx = (screen.width/2)-(x/2);
 	posy = (screen.height/2)-(y/2);
	
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	
	nomes = new Array('NOME','DIA DO NASCIMENTO','MÊS DO NASCIMENTO','ANO DO NASCIMENTO','SEXO','NATURALIDADE','UF DO NASCIMENTO','RG','ORGÃO EXPEDIDOR','EMAIL','ENDEREÇO','BAIRRO','NÚMERO','CIDADE','CEP','ESTADO','LOGRADOURO','DIA EXPEDIÇÃO RG','MÊS EXPEDIÇÃO DO RG','ANO EXPEDIÇÃO RG','CURSO PRIMEIRA OPÇÃO');
	
	campo = new Array(Nome,Dia_nas,Mes_nas,Ano_nas,Sex,Naturalidade,Uf_nascimento,Rg,Org_exp,Email,Endereco,Bairro,Numero,Cidade,Cep,Est_reside,Logradouro,Dia_exp_rg,Mes_exp_rg,Ano_exp_rg,Curso);
	
	for(i=0;i<=campo.length-1;i++)
	{	
		if(campo[i].value.replace(/^\s*/, "") == '')
		{
			alert('Atenção: o campo "'+nomes[i]+'" está em branco ou com valor inválido, favor preenche-lo corretamente!');
			campo[i].focus();
			return false;
		}
	}
	
	if (Tel_cel.length == 0 || Tel_cel == '' || Tel_cel.length != 14){
		alert('Atenção: o telefone celular e de preechimento obrigatorio, favor preenche-lo corretamente.');
		return false
	}
	if(Outranecessidad == true && document.getElementById("out_def").value == ''){
		alert('Atenção: favor informar qual o seu outro tipo de necessidade especial.');
		document.getElementById("out_def").focus();
		return false;
	}
	if(Canhotodestro == false && Destro == false)
	{
		alert('Atenção: favor informar se você é canhoto ou destro.');
		return false
	}
	if (Email.value.replace(/^\s*/, "") == '' || Email.value.indexOf("@")== -1 || Email.value.indexOf(".")== -1 || Email.value.indexOf("..") > 0 || Email.value.indexOf(")") > 0 || Email.value.indexOf("(") > 0 || Email.value.indexOf("]") > 0 || Email.value.indexOf("[") > 0 || Email.value.indexOf("/") > 0 || Email.value.indexOf(".com.br.") > 0 || Email.value.indexOf("@.") > 0 || Email.value.indexOf(".@") > 0 || Email.value.indexOf("hotmeil.com") > 0 || Email.value.indexOf("zipmeil.com") > 0 || Email.value.indexOf(" ") != -1 || Email.value.indexOf(".") < 1)
	{
		alert('Atenção: campo email em branco, ou email inválido.');
		Email.focus();
		return false;
	}
	//if(document.getElementById("enem").checked == true && Nota.value.replace(/^\s*/, "") == '')
	//{
	//	alert('Atenção: informe seu nº de inscrição do ENEM para ser utilizado no vestibular');
	//	Nota.focus();
	//	return false;
	//}
	if(Ingles == false && Espanhol == false)
	{
		alert('Atenção: informe qual a sua opção de língua estrangeira');
		return false;
	}
	if(document.getElementById("enem").checked == false && document.getElementById("vest").checked == false){
		alert('Atenção: informe qual a sua modalidade de ingresso');
		return false;
	}
	
	document.frm_fic.submit;
}

var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
	xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function queryCEP(cep){

	if(cep.length!=9){
		alert('Atenção: favor preencher todos os números do cep');
		return false
	}

	url = "pesquisa_endereco.php?cep="+cep
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = xmlHttpHandler
	xmlHttp.send(null);
	
}

function xmlHttpHandler(){
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			fillCEP(xmlHttp.responseText);
		}
	}
}

function fillCEP(content){
dl = document.getElementById("CodigoTipoLogradouro");	
de = document.getElementById("endereco");
db = document.getElementById("bairro");
dc = document.getElementById("cidade");
ce = document.getElementById("est_reside");

		if (content=="NÃO ENCONTRADO")
		{
			alert('Atenção: cep não encontrado, favor verificar se o mesmo foi digitado corretamente. Informe um Cep válido, caso o problema continue informe os dados manualmente nos campos abaixo.');
			
			dl.value = "";
			de.value = "";
			db.value = "";
			dc.value = "";
			ce.value = "";
			document.getElementById("cep").focus();
			return false
		}
		else
		{
			separador = "|*|"
			dados = content.split(separador)
	
			i = dados[0];
			j = dados[1];
			k = dados[2];
			l = dados[3];
			m = dados[4];
			
			dl.value = i.toUpperCase();
			de.value = j;
			db.value = k;
			dc.value = l;
			ce.value = m;
		}
}

function telefone(formato,keypress)
{
	if (formato=='TelefoneResidencial' || formato=='TelefoneCelular' || formato=='TelefoneComercial' || formato=='Cep')
	{
	separador1 = '(';
	separador2 = ') ';
	separador3 = '-';
	conjunto1 = 0;
	conjunto2 = 3;
	conjunto3 = 9;
	conjunto4 = 5;

	switch(formato){
	case 'TelefoneResidencial':
       	if (document.getElementById("tel_res").value.length == conjunto1){
        document.getElementById("tel_res").value = document.getElementById("tel_res").value + separador1;
        }
        if (document.getElementById("tel_res").value.length == conjunto2){
        document.getElementById("tel_res").value = document.getElementById("tel_res").value + separador2;
        }
        if (document.getElementById("tel_res").value.length == conjunto3){
        document.getElementById("tel_res").value = document.getElementById("tel_res").value + separador3;
		}
	break;
	case 'TelefoneCelular':
       	if (document.getElementById("tel_cel").value.length == conjunto1){
        document.getElementById("tel_cel").value = document.getElementById("tel_cel").value + separador1;
        }
        if (document.getElementById("tel_cel").value.length == conjunto2){
        document.getElementById("tel_cel").value = document.getElementById("tel_cel").value + separador2;
        }
        if (document.getElementById("tel_cel").value.length == conjunto3){
        document.getElementById("tel_cel").value = document.getElementById("tel_cel").value + separador3;
		}
	break;
	case 'TelefoneComercial':
       	if (document.getElementById("tel_com").value.length == conjunto1){
        document.getElementById("tel_com").value = document.getElementById("tel_com").value + separador1;
        }
        if (document.getElementById("tel_com").value.length == conjunto2){
        document.getElementById("tel_com").value = document.getElementById("tel_com").value + separador2;
        }
        if (document.getElementById("tel_com").value.length == conjunto3){
        document.getElementById("tel_com").value = document.getElementById("tel_com").value + separador3;
		}
	break;
	case 'Cep':
       	if (document.getElementById("cep").value.length == conjunto4){
        document.getElementById("cep").value = document.getElementById("cep").value + separador3;
        }
	break;
	}
}
}
