function showHideCursos() {
	$('.cursos div.desc-curso').hide();
	$('.cursos li a').click(
    function() {
		var checkElement = $(this).next();
		if((checkElement.is('.cursos div.desc-curso')) && (checkElement.is(':visible'))) {
			return false;
		}
		if((checkElement.is('.cursos div.desc-curso')) && (!checkElement.is(':visible'))) {
			$('.cursos div.desc-curso:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
		}
	});
}

function respostaAjax(txt) {
	$("div.blockMsg").html(txt);
	$('div.blockOverlay').attr("title", "Clique para continuar").click($.unblockUI);
	$("div.blockOverlay").click(function() { $(this).removeAttr("title"); });
}

function aguarde() {
	$.blockUI({
		message: "Carregando...",
		overlayCSS: { background: "#fff", opacity: .8 },
		
		css: {
			background: "none",
			fontSize: "50px",
			color: "#333",
			width: "300px",
			padding: "10px",
			border: "none",
			top: "40%",
			left: "40%"
		}
	});
}

function votar(form, action, div, div2, url_resultado, eid) {
	aguarde();
	$("h3#titulo").text("Resultado parcial");
	var opcoes = {
		url: action,
		type: "post",
		success: function(resposta) {
			div.html(resposta);
			div2.load(url_resultado + "?eid=" + eid);
				
			setTimeout(
				function() {
					$.blockUI({
						message: $("#resultados-enquete"),
						
						css: {
							background: "#fff",
							textAlign: "left",
							width: "480px",
							padding: "5px",
							border: "none",
							top: ($(window).height() - $("#resultados-enquete").height()) / 2 + "px",
				            left: ($(window).width() - "480") / 2 + "px"
						}
					});
				},
				2000
			);
		}
	}
	$(form).ajaxSubmit(opcoes);
}

function parcial(url, eid, div) {	
	aguarde();
				
	div.empty().load(url + "?eid=" + eid);
    $("p#resposta-voto").empty();
	
	setTimeout(
		function() {
			$.blockUI({
				message: $("#resultados-enquete"),
				
				css: {
					background: "#fff",
					textAlign: "left",
					width: "480px",
					padding: "5px",
                    paddingBottom: "0",
					border: "none",
					top: ($(window).height() - $("#resultados-enquete").height()) / 2 + "px",
		            left: ($(window).width() - "480") / 2 + "px"
				}
			});
		},
		2000
	);
}

function msgStatus(loading, msg) {
	var status = loading == true ? "<img src=\"/holosv3/imagens/carregando.gif\" alt=\"carregando\" class=\"carregando\" />" + msg : msg;
	
	$.blockUI({ 
		message: status,
		centerY: false,
		showOverlay: false,
		overlayCSS: { cursor: "auto" },
		css: {
			padding: "10px", 
			width: "500px", 
			paddingTop: "13px",
			textAlign: "left", 
			left: ($(window).width() - 520) /2 + "px",
			top: 0,
			color: "#000", 
			border: "solid 1px #333",
			borderTop: "none",
			backgroundColor: "#fff", 
			cursor: "auto"
		}
	});
}

function cadastrar(form, action) {
	msgStatus(true, "Cadastrando, aguarde...");
					
	var opcoes = {
		url: action,
		type: "post",
		success: function(resposta) {
			respostaAjax(resposta);
		}
	};
	
	$(form).ajaxSubmit(opcoes);
}

function enviar(form, action) {
	msgStatus(true, "Enviando, aguarde...");
					
	var opcoes = {
		url: action,
		type: "post",
		success: function(resposta) {
			respostaAjax(resposta);
		}
	};
	
	$(form).ajaxSubmit(opcoes);
}

$(window).load(
	function() {
		$("#cidade option:first").text("Aguarde...");
		$.ajax({
			url: "/cidades.php?uf=es",
			type: "get",
			success: function(resposta) {
				$("#cidade").html(resposta);
			}
		});
		
		var divlogo = $("div.logo");
		var img = $("div.logo img");
		var imgs = img.length; 
		var i;
		
		for(i = 0; i <= imgs; i++) {
			divlogo.eq(i).css("top", "50%");
			divlogo.eq(i).css("margin-top", -(img.eq(i).height()/2));
		}
		
		/* SELECT CIDADE */
		$("select#cidade option:first").text("Aguarde...");
		$.ajax({
			url: "cidades.php?uf=es",
			type: "get",
			success: function(resposta) {
				$("select#cidade").html(resposta);
			}
		});
	}
);

$(document).ready(
	function() {
		/* PNGs */
		$(document).pngFix();
		/* FIM PNGs */
		
		//showHideCursos();
		
		/* FIM APLICAÇÃO DE ESTILOS */
		$("input[type=text], textarea, select").focus(
			function() {
				$(this).addClass("foco");
				$(this).prev("label").addClass("foco");
			}
		).blur(
			function() {
				$(this).removeClass("foco");
				$(this).prev("label").removeClass("foco");
			}
		);
		/* APLICAÇÃO DE ESTILOS */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* LINKS EXTERNOS */
		$("a[rel=externo], a.link-externo, area[rel=externo]").attr("target", "_blank");
		/* FIM LINKS EXTERNOS */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* LINKS TÍTULOS */
		$("a, area, img, input, textarea, select").livequery(
			function() {
				$(this).tooltip({
					track: true, 
					delay: 0, 
					showURL: false,
					fade: 250
				});
			}
		);
		/* FIM LINKS TÍTULOS */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* SELEÇÃO ESTADOS */
		$("#estado").change(
			function() {
				var estado = $(this).val();
				if(estado == "nulo") {
					alert("Selecione um estado!");
					$(this).focus();
					return false;
				}
				else {
					$("#cidade").attr("disabled", "disabled");
					$("#cidade option:selected").text("Aguarde...");
					$.ajax({
						url: "/holosv3/cidades.php?uf=" + estado,
						type: "get",
						success: function(resposta) {
							$("#cidade").html(resposta);
							$("#cidade").removeAttr("disabled");
						}
					});
				}
			}
		);
		/* FIM SELEÇÃO ESTADOS */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* ENQUETE */
		$("#votar").submit(
			function() {
				votar($(this), $(this).attr("action"), $("#resposta-voto"), $("#resultados"), "enquete/resultado.php", $("input[name='eid']").val());
				return false;
			}
		);
		
		$("input#parcial").click( 
			function() {
				parcial("enquete/resultado.php", $("input[name='eid']").val(), $("#resultados"), false);
				return false;
			}
		);
		
		$("a#fechar-enquete").livequery("click", 
			function() {
				$.unblockUI();
				return false;
			}
		);
		/* FIM ENQUETE */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* FOTOS */		
		$("a.ampliar-foto").click(
			function() {
				var href = $(this).attr("href");
				$("img#foto-atual").fadeOut(300);
				setTimeout(function() {
				$("img#foto-atual").attr("src", href).hide();
									},300);
				setTimeout(function() {
				$("img#foto-atual").attr("src", href).fadeIn();
									},2000);
				$("a.foco").removeClass("foco");
				return false;
			}
		);
		/* FIM FOTOS */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* CADASTRO */
		$("#cad-informativo").submit(
			function() {
				var n = $("#inome");
				var e = $("#iemail");
				
				if(n.val() == "") {
					alert("Digite seu nome!");
					n.focus();
					return false;
				}
				if(e.val() == "") {
					alert("Digite seu e-mail!");
					e.focus();
					return false;
				}
				else {
					cadastrar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM CADASTRO */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* MATRÍCULA */		
		$("#pre-matricula").submit(
			function() {
				var un = $("#unidade");
				var n = $("#nome");
				var e = $("#email");
				var t = $("#tel");
				var city = $("#cidade");
				var uf = $("#estado");
				
				if(un.val() == "nulo") {
					alert("Seleciona a unidade que deseja contato!");
					un.focus();
					return false;
				}
				if(n.val() == "") {
					alert("Informe seu nome!");
					n.focus();
					return false;
				}
				if(e.val() == "") {
					alert("Informe seu e-mail!");
					e.focus();
					return false;
				}
				if(t.val() == "") {
					alert("Informe um telefone para contato!");
					t.focus();
					return false;
				}
				if(city.val() == "nulo") {
					alert("Selecione a cidade!");
					city.focus();
					return false;
				}
				if(uf.val() == "nulo") {
					alert("Selecione o estado!");
					uf.focus();
					return false;
				}
				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM MATRÍCULA */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* CONTATO */		
		$("#contato").submit(
			function() {
				var un = $("#unidade");
				var n = $("#nome");
				var e = $("#email");
				var t = $("#tel");
				var city = $("#cidade");
				var uf = $("#estado");
				var a = $("#assunto");
				var msg = $("#msg");
				
				if(un.val() == "nulo") {
					alert("Seleciona a unidade que deseja contato!");
					un.focus();
					return false;
				}
				if(n.val() == "") {
					alert("Informe seu nome!");
					n.focus();
					return false;
				}
				if(e.val() == "") {
					alert("Informe seu e-mail!");
					e.focus();
					return false;
				}
				if(t.val() == "") {
					alert("Informe um telefone para contato!");
					t.focus();
					return false;
				}
				if(city.val() == "nulo") {
					alert("Selecione a cidade!");
					city.focus();
					return false;
				}
				if(uf.val() == "nulo") {
					alert("Selecione o estado!");
					uf.focus();
					return false;
				}
				if(a.val() == "") {
					alert("Informe o assunto!");
					a.focus();
					return false;
				}
				if(msg.val() == "") {
					alert("Digite uma mensagem!");
					msg.focus();
					return false;
				}
				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM CONTATO */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* LOGIN */		
		$("#login-curriculum").submit(
			function() {
				var e = $("#email_login");
				var s = $("#senha_login");
				
				if(e.val() == "") {
					alert("Informe seu e-mail!");
					e.focus();
					return false;
				}
				if(s.val() == "") {
					alert("Informe sua senha!");
					s.focus();
					return false;
				}
				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM LOGIN */
		
		/* RECUPERAR SENHA */
		$("#reset-senha").submit(
			function() {
				var e = $("#email_reset");
				
				if(e.val() == "") {
					alert("Informe seu e-mail!");
					e.focus();
					return false;
				}
				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM RECUPERAR SENHA */
		
		/* ALTERAR SENHA */
		$("#alterar-senha").submit(
			function() {
				var s = $("#nova_senha");
				var cs = $("#cnova_senha");
				
				if(s.val() == "" || s.val() != cs.val()) {
					alert("Senhas incorretas!");
					s.val("");
					cs.val("");
					s.focus();
					return false;
				}
				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM ALTERAR SENHA */
	}
);
