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

function msgStatus(loading, msg) {
	var status = loading == true ? "<img src=\"/imagens/carregando.gif\" alt=\"carregando\" class=\"carregando\" />" + msg : msg;
	
	$.blockUI({ 
		message: status,
		centerY: 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: "/novo/cidades.php?uf=es",
			type: "get",
			success: function(resposta) {
				$("#cidade").html(resposta);
			}
		});
	}
);

$(document).ready(
	function() {
		/* PNGs */
		$(document).pngFix();
		/* FIM PNGs */
        
		/* 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, 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: "/novo/cidades.php?uf=" + estado,
						type: "get",
						success: function(resposta) {
							$("#cidade").html(resposta);
							$("#cidade").removeAttr("disabled");
						}
					});
				}
			}
		);
		/* FIM SELEÇÃO ESTADOS */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* CONTATO */
		$("#contato").submit(
			function() {
				var n = $("#nome");
				var e = $("#email");
				var t = $("#tel");
				var c = $("#cidade");
				var uf = $("#estado");
				var a = $("#assunto");
				var m = $("#msg");
				
				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(c.val() == "nulo") {
					alert("Selecione a cidade!");
					c.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(m.val() == "") {
					alert("Digite uma mensagem!");
					m.focus();
					return false;
				}
				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM CONTATO */
		
		/* @-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@-@- */
		
		/* CONTRATAR */
		$("#contratar").submit(
			function() {
				var n = $("#nome");
				var e = $("#email");
				var t = $("#tel");
                var ev = $("#evento");
                var ts = $("#tipo_show");
                var d = $("#data");
				var c = $("#cidade");
				var uf = $("#estado");
				
				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(ev.val() == "") {
					alert("Informe o nome do evento!");
					ev.focus();
					return false;
				}
                if(ts.val() == "nulo") {
					alert("Selecione o tipo do evento!");
					ts.focus();
					return false;
				}
                if(d.val() == "" || d.val() == "__/__/____") {
					alert("Informe a data do evento!");
					d.focus();
					return false;
				}
				if(c.val() == "nulo") {
					alert("Selecione a cidade!");
					c.focus();
					return false;
				}
				if(uf.val() == "nulo") {
					alert("Selecione o estado!");
					uf.focus();
					return false;
				}

				else {
					enviar($(this), $(this).attr("action"));
					return false;
				}
			}
		);
		/* FIM CONTRATAR */
	}
);