// JavaScript Document

function ajaxInit() {
	
	var xmlhttp;
	
	try {
		xmlhttp = new XMLHttpRequest();
	} catch(ee) {
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				xmlhttp = false;
			}
		}
	}
	return xmlhttp;
}


//---------------CPF--------------------
	function valida_cpf(obj,erro){
		var cpf=obj.value;
		if(cpf.length==11){
			for(var i=0; i<cpf.length; i++){
				if(isNaN(cpf.charAt(i))==true){
					return false;
				}
			}
			cpf = obj.value=obj.value.substr(0,3)+"."+obj.value.substr(3,3)+"."+obj.value.substr(6,3)+"-"+obj.value.substr(9);
		}else if(cpf.length==14){
			obj.value=obj.value.substr(0,3)+"."+obj.value.substr(4,3)+"."+obj.value.substr(8,3)+"-"+obj.value.substr(12);
			cpf = obj.value;
		} else{
			return false;			
		}
		if (cpf.length<14 || cpf.charAt(3)!="." || cpf.charAt(7)!="." || cpf.charAt(11)!="-" || cpf=="000.000.000-00" || cpf=="111.111.111-11" || cpf=="222.222.222-22" || cpf=="333.333.333-33" || cpf=="444.444.444-44" || cpf=="555.555.555-55" || cpf=="666.666.666-66" || cpf=="777.777.777-77" || cpf=="888.888.888-88" || cpf=="999.999.999-99"){
			return false;
		} else {
		// Primeiro Calculo
		calculo1 = new Array(13)
			for (i=0; i<=13; i++){
				calculo1[i]=cpf.charAt(i);
			} 
			valor_cal=(calculo1[0]*10)+(calculo1[1]*9)+(calculo1[2]*8)+(calculo1[4]*7)+(calculo1[5]*6)+(calculo1[6]*5)+(calculo1[8]*4)+(calculo1[9]*3)+(calculo1[10]*2);
			valor_cal=valor_cal%11;
				if (valor_cal<2){
					valor_cal=0;
				} else {
					valor_cal=11-valor_cal;
				}
				
				
			// Segundo Calculo
			calculo2 = new Array(10)
			for (i=0; i<=10; i++){
				calculo2[i]=cpf.charAt(i);
			} 
			valor_cal2=(calculo2[0]*11)+(calculo2[1]*10)+(calculo2[2]*9)+(calculo2[4]*8)+(calculo2[5]*7)+(calculo2[6]*6)+(calculo2[8]*5)+(calculo2[9]*4)+(calculo2[10]*3)+(valor_cal*2);
			valor_cal2=valor_cal2%11;
			if (valor_cal2<2){
				valor_cal2=0;
			} else {
				valor_cal2=11-valor_cal2;
			}
			if (valor_cal == calculo1[12] && valor_cal2 == calculo1[13]){
				for(var i=0; i<cpf.length; i++){
					if(isNaN(cpf.charAt(i))==true && i!=3 && i!=7 && i!=11){
						return false;
					}
				}			
			} else {
				return false;
			}
		}
	}
	//---------------Final CPF--------------
	
	
	
	//------------Telefone------------------
	function valida_telefone(obj){
		var tel = obj.value;
		if(tel.length==10){
			for(var i=0; i<tel.length; i++){
				if(isNaN(tel.charAt(i))==true){
					return false;
				}
			}
			obj.value="("+obj.value.substr(0,2)+") "+obj.value.substr(2,4)+"-"+obj.value.substr(6);
			tel = obj.value;
		}else if(tel.length==14){
			obj.value="("+obj.value.substr(1,2)+") "+obj.value.substr(5,4)+"-"+obj.value.substr(10,4);
			tel = obj.value;
		} else{
			return false;			
		}
		if (tel.length<14 || tel.charAt(4)!=" " || tel.charAt(9)!="-" || tel.charAt(0)!="(" || tel.charAt(3)!=")"){
			return false;
		} else {
			for(var i=0; i<tel.length; i++){
				if(isNaN(tel.charAt(i))==true && i!=0 && i!=3 && i!=4 && i!=9){
					return false;
				}
			}
		}
	}
	//------------Final Telefone------------
	
	//------------Quantidade de Caracteres Números------------------
	function valida_length(obj, maior, menor){
		var campo = obj.value;
		if (campo.length<menor || campo.length>maior){
			return false;
		} else {
			return true;
		}
	}
	//------------Final Quantidade de Caracteres Números------------
	
	//---------Emal--------------------
	function valida_email(obj){
		var email = obj.value;
		obj.value=email.toLowerCase();
		email = obj.value;
		var comando = /^[a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9-]+\.[a-z0-9-]+(\.[a-z0-9-]+)*$/;
		var valida = comando.exec(email);
		if (!valida){
			return false;
		}
	}
	//-----------Final Email----------------


//------Somente Números-----------------------		
function numeros(e){
	var tecla=new Number();
	if(window.event) {
		tecla = e.keyCode; 
	} else if(e.which) {
		tecla = e.which; 
	} else {
		return true;
	}
	
	if(((tecla < 48) || (tecla > 57)) && (tecla!=8)){
		return false;
	}
	
}
//-------------Final Somente Números----------------


//-------Pontuação Telefone-------------
	function traco_tel(obj, e){			
		var tecla=new Number();
		if(window.event) {
			tecla = e.keyCode;
		} else if(e.which) {
			tecla = e.which;
		} else {
			return true;
		}
		
		tel=obj.value;
		if (tel.length==2 && tel.charAt(0)!="(" && tecla!=8){
				obj.value="("+tel+") ";
		}
		
		if (tel.length==3 && tel.charAt(0)=="(" && tecla!=8){
				obj.value=tel+") ";
		}
		
		if (tel.length==9 && tecla!=8){
			obj.value=tel+"-";
		}
	}
//-------Final Pontuação Telefone-------------

//----------pontuação do CPF----------------------
function pontuacao_cpf(obj, e){
	var tecla=new Number();
	if(window.event) {
		tecla = e.keyCode;
	} else if(e.which) {
		tecla = e.which;
	} else {
		return true;
	}
	
	cpf=obj.value;
	if ((cpf.length==3 || cpf.length==7) && tecla!=8){
		obj.value=cpf+".";
	}
	if (cpf.length==11 && tecla!=8){
		obj.value=cpf+"-";
	}
}

//----------Final pontuação do CPF----------------------

//================================ Checa Radio =========================================

function check_radio(obj){
	var checked=0;
	for(var i=0; i<obj.length; i++){
		if (obj[i].checked==true){
			return obj[i].value;
			break;
		}
	}
	return false;
}

//================================ Final Checa Radio ====================================


//================================ Checa Radio =========================================

function uncheck_radio(obj){
	for(var i=0; i<obj.length; i++){
		obj[i].checked=false;
	}
}

//================================ Final Checa Radio ====================================

//===================================== Checa Vendedor ==============================================
function checa_indicador(obj){
	if(check_radio(obj)==1){
		document.getElementById('Indicador').style.display="block";
		//document.getElementById('pesqMidia').style.display="none";		
	} else {
		document.getElementById('Indicador').style.display="none";
		//document.getElementById('pesqMidia').style.display="block";				
	}
}
//===================================== Checa Vendedor ==============================================

//===================================== Checa Segmento ==============================================
function checa_segmento(obj){
	if(obj.value=="1" || obj.value=="8" || obj.value=="22" || obj.value=="2"){
		var lis=document.getElementById('cursos').getElementsByTagName("li");
		for(var i=0; i<lis.length; i++){
			lis[i].style.display="none";
		}
		document.getElementById(obj.value).style.display="block";
	}
}
//===================================== Checa Segmento ==============================================

//===================================== Checa Formulário ==============================================

function checar_cartao(obj){
	checa_indicador(document.form.opt_ind);
}

// ======================== Valida Inscrição ===============================================
function valida_cartao(obj){
	var erro = 0
	var select_curso=0;
	var desc_erro = new Array();
	
	if (check_radio(obj.opt_ind)==1){
		if (valida_length(obj.nome_indicador,1200,4)==false){
			desc_erro[erro]="Digite o nome de seu Indicador corretamente!";
			erro = erro + 1;
		}
		
		if (check_radio(obj.tipo_indicador)==false){
			desc_erro[erro]="Selecione se seu indicador é Aluno ou Funcionário ou Professor.";
			erro = erro + 1;
		}
	}
	
	/* if (valida_cpf(obj.cpf)==false){
		desc_erro[erro]="Digite seu CPF Corretamente!";
		erro = erro + 1;
	}
	
	if(obj.segmento.value!="1" && obj.segmento.value!="8" && obj.segmento.value!="22" && obj.segmento.value!="2"){
		desc_erro[erro]="Escolha um segmento: Graduação ou Pós-graduação ou EJA/Supletivo ou CAS/ITS";
		erro = erro + 1;
		select_curso=1;
	} else {
		if(obj.segmento.value=="1" && obj.curso_graducao.value==""){
			desc_erro[erro]="Escolha algum curso de Graduação";
			erro = erro + 1;
		}
		
		if(obj.segmento.value=="8" && obj.curso_pos.value==""){
			desc_erro[erro]="Escolha algum curso de Pós-graduação";
			erro = erro + 1;
		}
		
		if(obj.segmento.value=="22" && obj.curso_eja.value==""){
			desc_erro[erro]="Escolha algum curso do Eja/Supletivo";
			erro = erro + 1;
		} 
		
		if(obj.segmento.value=="2" && obj.curso_cas.value=="") {
			desc_erro[erro]="Escolha algum curso do CAS/ITS";
			erro = erro + 1;
		}
	} */
	
	if (obj.curso.value==""){
		desc_erro[erro]="Escolha o Curso Desejado!";
		erro = erro + 1;
	}

		
	if (valida_length(obj.nome,1200,4)==false){
		desc_erro[erro]="Digite seu Nome Corretamente!";
		erro = erro + 1;
	}

/*	if (obj.Cpf.value==""){
		desc_erro[erro]="Preencha seu CPF!";
		erro = erro + 1;
	}
*/
	if (obj.telefone.value=="" && obj.tel_alt.value=="" && obj.celular.value==""){
		desc_erro[erro]="Preencha com no mínimo 2 telefones para contato!";
		erro = erro + 1;
	} else {
		var tel_contato=0;
		if (obj.telefone.value.length>0){
			if (valida_length(obj.telefone,14,8)==false){
				desc_erro[erro]="Digite seu Telefone corretamente!";
				erro = erro + 1;
			}else{
				tel_contato=tel_contato+1;
			}
		}
		
		if (obj.tel_alt.value.length>0){
			if (valida_length(obj.tel_alt,14,8)==false){
				desc_erro[erro]="Digite seu Celular corretamente!";
				erro = erro + 1;
			}else{
				tel_contato=tel_contato+1;
			}
		}
		
		if (obj.celular.value.length>0){
			if (valida_length(obj.celular,14,8)==false){
				desc_erro[erro]="Digite seu Celular corretamente!";
				erro = erro + 1;
			}else{
				tel_contato=tel_contato+1;
			}
		}
		
		if (tel_contato<2){
			desc_erro[erro]="Preencha com no mínimo 2 telefones para contato!";
			erro = erro + 1;
		}
	}
	
	if (valida_email(obj.email)==false){
		desc_erro[erro]="Digite seu E-mail corretamente!";
		erro = erro + 1;
	}
	
	if (erro>0){
		document.getElementById('erros').innerHTML="";
		document.getElementById('erros').style.display="block";
		var li = new Array();
		var total_erros = desc_erro.length;
		var elementos = document.form.elements;
		var lis = document.getElementById('erros').getElementsByTagName('li');
		for (var i=0; i<total_erros; i++){
			li[i] = document.createElement('li');
			li[i].appendChild(document.createTextNode(desc_erro[i]));
			document.getElementById('erros').appendChild(li[i]);
		}
		/*========================================================
		if(select_curso>0){
			var segmentos = document.createElement('div');
			segmentos.setAttribute("id","segmentos");
			var input=new Array(4);
			for (var a=0; a<input.length; a++){
				input[a] = document.createElement('input');
				input[a].setAttribute("name","segmentos");
				input[a].setAttribute("type","radio");
				input[a].setAttribute("style","margin-left:15px;");
				input[a].onclick=function (){
					document.form.segmento.value=this.value;
					checa_segmento(document.form.segmento);
				}
			}
			input[0].setAttribute("value","1");
			input[1].setAttribute("value","8");
			input[2].setAttribute("value","22");
			input[3].setAttribute("value","2");
			segmentos.appendChild(input[0])
			segmentos.appendChild(document.createTextNode("Graduação "));
			segmentos.appendChild(input[1]);
			segmentos.appendChild(document.createTextNode("Pós-graduação "));
			segmentos.appendChild(input[2]);
			segmentos.appendChild(document.createTextNode("EJA/Supletivo "));
			segmentos.appendChild(input[3]);
			segmentos.appendChild(document.createTextNode("CAS/ITS"));
			document.getElementById('erros').appendChild(segmentos);
		}
		========================================================================*/
		return false;
	}
}

// ======================== Final Valida Inscrição ===========================================

function anima_erros(){	
	animacao=1;
	var erros = document.getElementById('erros');
	var lightbox = document.getElementById('lightbox');
	var height_pg = document.body.offsetHeight;
	var width_pg = document.body.offsetWidth;
	lightbox.style.height=height_pg+"px";
	lightbox.style.width=width_pg+"px";
	lightbox.style.opacity=0;
	lightbox.style.filter="alpha(opacity=0)";
	lightbox.style.display="block";
	var i=0;
	var intervalo = window.setInterval(function (){
		if(i<=9){
			lightbox.style.opacity=i/10;
			lightbox.style.filter="alpha(opacity="+i*10+")";
			i++
		} else {    
			clearInterval(intervalo);
			var distancia = window.pageYOffset || document.documentElement.scrollTop;
			var h_tela=window.innerHeight || document.documentElement.clientHeight;
			document.getElementById('erros').style.display="block";
			var h_obj = document.getElementById('erros').offsetHeight;
			var recuo=h_obj/2;
			if(h_obj>=h_tela){
				recuo=(h_tela*50)/100;
			}
			h_final_obj=((((h_tela*50)/100)+distancia)-recuo);
			document.getElementById('erros').style.marginTop=h_final_obj+"px";
			if(h_final_obj+h_obj > height_pg){
				lightbox.style.height=(h_final_obj+h_obj)+"px";
			}
			animacao=0;
		}
		lightbox.onclick=function (){    
			clearInterval(intervalo);
			lightbox.style.display="none";
			document.getElementById('erros').style.display="none";
		}
	},40);
}

/*===================== Fechar Light =========================*/
		
function fechar(){
	document.getElementById('lightbox').style.display='none';
	document.getElementById('erros').style.display='none';
}

/*===================== Final Fechar Light =========================*/
//----------------------Loading------------------------------------

function loading(obj){
	document.getElementById(obj).innerHTML=""				
	var img=document.createElement('img');
	img.setAttribute('src','imagens/loading.gif');
	img.setAttribute('alt','Carregando Dados');
	document.getElementById(obj).appendChild(img);
}

//================================Lightbox==================================
function lightbox(obj){	
	animacao=1;
	if(!document.getElementById('lightbox')){
		var lightbox = document.createElement('div');
		lightbox.setAttribute('id','lightbox');	
		document.body.insertBefore(lightbox, document.getElementById('principal'));
	} else {
		var lightbox = document.getElementById('lightbox');
	}
	var height_pg = document.body.offsetHeight;
	var width_pg = document.body.offsetWidth;
	if(height_pg<(window.innerHeight || document.documentElement.clientHeight)){
		var height_pg = window.innerHeight || document.documentElement.clientHeight;
		var width_pg = window.innerWidth || document.documentElement.clientWidth;
	}
	lightbox.style.height=height_pg+"px";
	lightbox.style.width=width_pg+"px";
	lightbox.style.opacity=0;
	lightbox.style.filter="alpha(opacity=0)";
	lightbox.style.display="block";
	var i=0;
	var intervalo = window.setInterval(function (){
		if(i<=9){
			lightbox.style.opacity=i/10;
			lightbox.style.filter="alpha(opacity="+i*10+")";
			i++
		} else {    
			clearInterval(intervalo);
			var distancia = window.pageYOffset || document.documentElement.scrollTop;
			var h_tela=window.innerHeight || document.documentElement.clientHeight;
			document.getElementById(obj).style.display="block";
			var h_obj = document.getElementById(obj).offsetHeight;
			var recuo=h_obj/2;
			if(h_obj>=h_tela){
				recuo=(h_tela*50)/100;
			}
			h_final_obj=((((h_tela*50)/100)+distancia)-recuo);
			document.getElementById(obj).style.marginTop=h_final_obj+"px";
			if(h_final_obj+h_obj > height_pg){
				lightbox.style.height=(h_final_obj+h_obj)+"px";
			}
			animacao=0;
		}
		lightbox.onclick=function (){    
			clearInterval(intervalo);
			fecha_lightbox(obj)
		}
	},40);
}

//===================== Final Lightbox =========================

function fecha_lightbox(obj){
	document.getElementById("lightbox").style.display="none";
	document.getElementById(obj).style.display="none";
}


//=================== VALIDA ENQUETE ==========================
function valida_enquete(form, segmento){
	if (animacao==0){
		ajax=ajaxInit();
		ajax.open('GET','valida-enquete.php?modelo_frente='+valor_radio_selecionado(form.modelo_frente)+'&modelo_verso='+valor_radio_selecionado(form.modelo_verso)+'&cor='+valor_radio_selecionado(form.cor)+'&segmento='+segmento,true);
		ajax.onreadystatechange=function(){		
			if(ajax.readyState == 1){
				loading('resultado_enquete');
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200){					
					document.getElementById('resultado_enquete').innerHTML=ajax.responseText;
				}
			}
			anima_obj('resultado_enquete');
		}
		ajax.send(null);
	}
	return false;
}
		
//================ FINAL VALIDA ENQUETE =======================

//----------------------Loading------------------------------------

function loading(obj){
	document.getElementById(obj).innerHTML=""				
	var img=document.createElement('img');
	img.setAttribute('src','imagens/loading.gif');
	img.setAttribute('alt','Carregando Dados');
	document.getElementById(obj).appendChild(img);
}

//----------------------Final Loading------------------------------------


//================================ Anima Objeto =========================================
animacao=0;
function anima_obj(obj){
	animacao=1;
	var resultado = document.getElementById(obj);
	resultado.style.filter="alpha(opacity="+0+")";
	resultado.style.opacity=0;
	resultado.style.display="block";
	
	var distancia = window.pageYOffset || document.documentElement.scrollTop;
	var h_tela=window.innerHeight || document.documentElement.clientHeight;
	var h_obj = document.getElementById(obj).offsetHeight;
	var recuo=h_obj/2;
	if(h_obj>=h_tela){
		recuo=(h_tela*50)/100;
	}
	h_final_obj=((((h_tela*50)/100)+distancia)-recuo);
	document.getElementById(obj).style.top=h_final_obj+"px";
	
	var h_resultado = resultado.offsetHeight;
	var novo_h=0;
	var mostra_resultado = setInterval(function () {
		if (navigator.appName=='Microsoft Internet Explorer'){
			var opacidade=resultado.style.filter;
			if(opacidade==undefined || opacidade==''){
				resultado.style.filter="alpha(opacity=0)";
				opacidade=0;
			} else {
				opacidade=parseInt(opacidade.substr(opacidade.substr(0,14).length, (opacidade.length-opacidade.substr(0,14).length)-1))/10;
			}
		}else{
			var opacidade=resultado.style.opacity;
			if(opacidade==undefined || opacidade==''){
			resultado.style.opacity=0;
			}
			opacidade=opacidade*10;
		}
		if(opacidade<=8){
			resultado.style.filter="alpha(opacity="+(novo_h*10)+")";
			resultado.style.opacity=novo_h/10;
		} else {
			animacao=0;
			clearInterval(mostra_resultado);
		}
		novo_h++
	}, 40);
}
//================================ Final Anima Objeto =========================================


//================================ Valor do Radio Selecionado =========================================
function valor_radio_selecionado(obj){
	for(var i=0; i<obj.length; i++){
		if (obj[i].checked==true){
			return obj[i].value;
			break;
		}
	}
}
//================================ Final Valo do Radio Selecionado =========================================

//================================ Mostra Resultado da Enquete =====================================

function resultado_enquete(obj, segmento){
	ajax=ajaxInit();
	ajax.open('GET','resultado-enquete.php?segmento='+segmento,true);
	ajax.onreadystatechange=function(){		
		if(ajax.readyState == 1){
			loading(obj);
		}
		if(ajax.readyState == 4){
			if(ajax.status == 200){					
				document.getElementById(obj).innerHTML=ajax.responseText;
			}
		}
		anima_obj(obj);
	}
	ajax.send(null);
}

//================================ Final Mostra Resultado da Enquete =====================================



//================================ Fechar Objetos ===========================================
	function none_obj(obj){
		document.getElementById(obj).style.display="none";
	}
//================================ Final Fechar Objetos ===========================================

//================================ Valores Cursos ============================================

function valores_cursos(pagina){
	ajax=ajaxInit();
	ajax.open('GET',pagina,true);
	ajax.onreadystatechange=function(){
		if(ajax.readyState == 4){
			if(ajax.status == 200){
				lightbox("conteudo_mostrar");
				document.getElementById("conteudo_mostrar").innerHTML=ajax.responseText;
			}
		}
	}
	ajax.send(null);
}


//======================== CARREGA TURNO ================================

function carrega_curso(obj){
	var curso = obj.value;
	var idAnoSem = curso.split('-');
	curso = idAnoSem[0];
	var periodo = idAnoSem[1];
	var segmento = document.form.segmentoCurso.value
	document.getElementById("linha_curso").style.display="none";
	document.getElementById("linha_turno").style.display="none";
	document.getElementById("linha_entrada_turno").style.display="none";
	//alert(curso);
	ajax=ajaxInit();
	//alert('carrega-turno.php?tipo=curso&curso='+curso+'&periodo='+periodo+'&segmento='+segmento);
	ajax.open('GET','carrega-turno.php?tipo=curso&curso='+curso+'&periodo='+periodo+'&segmento='+segmento,true);
	ajax.onreadystatechange=function(){
		if(ajax.readyState == 1){
			//
		}
		if(ajax.readyState == 4){
			if(ajax.status == 200){
				var linha_curso = document.getElementById("linha_curso");
				var label = linha_curso.getElementsByTagName("label");
				//alert(document.form.anoSem.value);
				label[0].innerHTML = "";
					//alert(ajax.responseText);
				if (ajax.responseText.indexOf('NENHUM CURSO')>0){
					linha_curso.style.display="none";
				} else {
					linha_curso.style.display="block";
					var seta = document.createElement('img');
					seta.setAttribute("alt","Curso");
					seta.setAttribute("title","Curso");
					seta.src = "imagens/setaDados.jpg";
					label[0].appendChild(seta);
					label[0].appendChild(document.createTextNode("Curso:"));
					var select_curso = document.createElement('select');
					select_curso.setAttribute('name','curso');
					select_curso.className = "inputDados";
					select_curso.style.margin = "8px";
					select_curso.onchange = function(){
						 carrega_turno(this, periodo);
					}
					label[0].appendChild(select_curso);
					select_curso.innerHTML = ajax.responseText;
				}
			}
		}
	}
	ajax.send(null)
}


//===================== FINAL CARREGA TURNO =============================

//======================== CARREGA TURNO ================================

function carrega_turno(obj, periodo){
	var curso = obj.value;
	//alert(curso);
	ajax=ajaxInit();
	ajax.open('GET','carrega-turno.php?tipo=turno&curso='+curso+'&periodo='+periodo,true);
	ajax.onreadystatechange=function(){
		if(ajax.readyState == 1){
			//
		}
		if(ajax.readyState == 4){
			if(ajax.status == 200){
				var linha_turno = document.getElementById("linha_turno");
				var label = linha_turno.getElementsByTagName("label");
				label[0].innerHTML = "";
				if (ajax.responseText.indexOf('NENHUM TURNO ENCONTRADO')>0){
					linha_turno.style.display="none";
				} else {
					linha_turno.style.display="block";
					var seta = document.createElement('img');
					seta.setAttribute("alt","Turno");
					seta.setAttribute("title","Turno");
					seta.src = "imagens/setaDados.jpg";
					label[0].appendChild(seta);
					label[0].appendChild(document.createTextNode("Turno:"));
					var select_turno = document.createElement('select');
					select_turno.setAttribute('name','turno');
					select_turno.className = "inputDados";
					select_turno.style.margin = "8px";
					select_turno.onchange = function(){
						carrega_entrada_turno(this, periodo);
					}
					label[0].appendChild(select_turno);
					select_turno.innerHTML = ajax.responseText;
				}
			}
		}
	}
	ajax.send(null)
}


//===================== FINAL CARREGA TURNO =============================

//======================== CARREGA HORÁRIO TURNO ================================

function carrega_entrada_turno(obj, periodo){
	var curso = document.form.curso.value;
	var turno = obj.value;
	ajax=ajaxInit();
	ajax.open('GET','carrega-turno.php?tipo=entrada&turno='+turno+'&curso='+curso+'&periodo='+periodo,true);				
	ajax.onreadystatechange=function(){
		if(ajax.readyState == 1){
			//
		}
		if(ajax.readyState == 4){
			if(ajax.status == 200){
				var entrada_turno = document.getElementById("linha_entrada_turno");
				var label = entrada_turno.getElementsByTagName("label");
				label[0].innerHTML = "";
				//alert(ajax.responseText);
				if (ajax.responseText.indexOf('NENHUMA ENTRADA ENCONTRADA')>0){
					entrada_turno.style.display="none";
				} else {
					entrada_turno.style.display="block";
					var seta = document.createElement('img');
					seta.setAttribute("alt","Entrada do Turnos");
					seta.setAttribute("title","Entrada do Turnos");
					seta.src = "imagens/setaDados.jpg";
					label[0].appendChild(seta);
					label[0].appendChild(document.createTextNode("Entrada do Turnos:"));
					var select_turno = document.createElement('select');
					select_turno.setAttribute('name','entrada_turno');
					select_turno.className = "inputDados";
					select_turno.style.margin = "8px";
					label[0].appendChild(select_turno);
					select_turno.innerHTML = ajax.responseText;
					//document.getElementById("linha_entrada_turno").innerHTML = ajax.responseText;
				}
			}
		}
	}
	ajax.send(null)
}


//===================== FINAL CARREGA HORÁRIO TURNO =============================



//======================= BUSCA CEP =========================================

function busca_cep(obj){
	var cep = obj.value;
	if (cep.length==8){
		ajax=ajaxInit();
		ajax.open('GET','busca-cep.php?cep='+cep,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState == 1){
				//
			}
			if(ajax.readyState == 4){
				if(ajax.status == 200){
					var result = ajax.responseText.split(";");
					if(result[0]==1){
						document.form.uf.value = result[2];
						document.form.endereco.value = result[5]+" "+result[6];
						document.form.bairro.value = result[4];
						document.form.cidade.value = result[3];
					}
					/*if (ajax.responseText.indexOf('NENHUMA ENTRADA ENCONTRADA')>0){
						document.getElementById("linha_entrada_turno").style.display="none";
					} else {
						document.getElementById("linha_entrada_turno").style.display="block";
						document.form.entrada_turno.innerHTML=ajax.responseText;
						//document.getElementById("linha_entrada_turno").innerHTML = ajax.responseText;
					}*/
				}
			}
		}
		ajax.send(null)
	}
}


//==================== FINAL BUSCA CEP ======================================
