var baseurl = '/SITE/';

function confirmacao(a, b) {
    $confirma = confirm(a);
    if ($confirma) {
        location.href = b
    } else {
        alert('Ufa! Que susto heim...');
        return false
    }
}
function reloadPagina(a) {
    setTimeout(function () {
        window.location.reload()
    }, a)
}
function respostaAjax(a) {
    $("div.blockMsg").html(a);
    $("div.blockMsg").append($("<a href='javascript:void(null)' class='fechar-barra'>X</a>"));
    $('a.fechar-barra').click($.unblockUI)
}
function votar(b, c) {
    $('#status-enquete').empty().text('Registrando... aguarde!').fadeIn();
    updateEnquete = true;
    var d = {
        url: c,
        type: "post",
        success: function (a) {
            $('#status-enquete').empty().html(a);
            if (updateEnquete) {
                setTimeout(function () {
                    $('#enquete').slideUp()
                }, 2000);
                setTimeout(function () {
                    $('#enquete').empty().load('resultado.php?inc=ajax').slideDown()
                }, 3000)
						                setTimeout(function () {
                    $('#status-enquete').empty().load('resultado.php?inc=ajax').fadeOut()
                }, 3000)
            }
        }
    };
    $(b).ajaxSubmit(d)
}



function msgStatus(a, b) {
    var c = a == true ? '<img src="http://www.guiadoagito.com.br/n1/loader.gif" alt="carregando" class="carregando" />' + b : b;
    $.blockUI({
        message: c,
        centerY: false,
        showOverlay: false,
        overlayCSS: {
            cursor: "auto"
        },
        css: {
            width: '100%',
            padding: '20px',
            textAlign: 'left',
            left: 0,
            top: 0,
            color: '#000',
            border: 'none',
            borderBottom: 'solid 1px #999',
            background: '#f5f5f5',
            cursor: 'auto'
        }
    })
}
function cadastrar(b, c) {
    msgStatus(true, "Cadastrando , aguarde...");
    cortar = false;
    corBarraTopo = null;
    var d = {
        url: c,
        type: "post",
        success: function (a) {
            respostaAjax(a);
            if (cortar) {
                setTimeout(function () {
                    location.href = baseurl + 'organizadores/area-preview-cartaz/' + eid
                }, 1500)
            }
            if (corBarraTopo == 'red') {
                $("div.blockMsg").css("background", "#F78083")
            } else {
                $("div.blockMsg").css("background", "#D8FF62")
            }
        }
    };
    $(b).ajaxSubmit(d)
}
function atualizar(b, c) {
    msgStatus(true, "Atualizando, aguarde...");
    update = false;
    cortar = false;
    evento_destaque = false;
    corBarraTopo = null;
    var d = {
        url: c,
        type: "post",
        success: function (a) {
            respostaAjax(a);
            if (update) {
                reloadPagina(2000)
            }
            if (cortar) {
                setTimeout(function () {
                    window.location.href = baseurl + 'organizadores/area-preview-cartaz/' + eid
                }, 1500)
            }
            if (evento_destaque) {
                setTimeout(function () {
                    window.location.href = baseurl + 'organizadores/area-destaque-cartaz/' + eid
                }, 1500)
            }
            if (corBarraTopo == 'red') {
                $("div.blockMsg").css("background", "#ffff99")
            } else {
                $("div.blockMsg").css("background", "#E9FFA6")
            }
        }
    };
    $(b).ajaxSubmit(d)
}
function enviar(b, c) {
    msgStatus(true, "Enviando, aguarde...");
    corBarraTopo = null;
    update = false;
    var d = {
        url: c,
        type: "post",
        success: function (a) {
            respostaAjax(a);
            if (update) {
                reloadPagina(2000)
            }
            if (corBarraTopo == 'red') {
                $("div.blockMsg").css("background", "#ffff99")
            } else {
                $("div.blockMsg").css("background", "#E9FFA6")
            }
        }
    };
    $(b).ajaxSubmit(d)
}
function buscar(b) { 
	msgStatus(true, "Buscando , aguarde...");
    function urlencode(a) {
        a = escape(a);
        a = a.replace('+', '%2B');
        a = a.replace('%20', '+');
        a = a.replace('*', '%2A');
        a = a.replace('/', '%2F');
        a = a.replace('@', '%40');
        return a
    }  

            enviar($(this), $(this).attr("action"));
			            return true

}


function buscar2(b) { 
	msgStatus(true, "Cadastrando , aguarde...");
    function urlencode(a) {
        a = escape(a);
        a = a.replace('+', '%2B');
        a = a.replace('%20', '+');
        a = a.replace('*', '%2A');
        a = a.replace('/', '%2F');
        a = a.replace('@', '%40');
        return a
    }  

            enviar($(this), $(this).attr("action"));
			            return true

}
function alignMiddleImgBanda() {
    var a = $("#bandas div.banda div.bg-foto img");
    var b = a.length;
    var i;
    for (i = 0; i <= b; i++) {
        a.eq(i).css("top", "46%");
        a.eq(i).css("margin-top", -(a.eq(i).height() / 2))
    }
}
$(window).load(function () {
    $("select#cidade:not('.edicao') option:first").text("Aguarde...=[");
    $.ajax({
        url:'includes/cidades.php?uf=26',
        type: "get",
        success: function (a) {
            $("select#cidade:not('.edicao')").html(a)
        }
    });
    alignMiddleImgBanda()
});
$(document).ready(function () {
    $(document).pngFix();
    $("input[type=text], input[type=password], textarea, select").focus(function () {
        $(this).addClass("foco");
        $(this).prev("label").addClass("foco")
    }).blur(function () {
        $(this).removeClass("foco");
        $(this).prev("label").removeClass("foco")
    });
    $("input[type=text], textarea").each(function () {
        if ($(this).attr('value') != '') {
            $(this).val() == $(this).attr('value')
        } else {
            $(this).val($(this).attr('defaultVal'));
            if ($(this).val() == $(this).attr('defaultVal')) {
                $(this).css('color', '#ccc')
            } else {
                $(this).css('color', '#000')
            }
        }
    });
    $('input[type=text], textarea').focus(function () {
        if ($(this).attr('name') == 'sitebanda' || $(this).attr('name') == 'site_organizador') {
            if (($(this).val() == 'http://' || $(this).val() == $(this).attr('defaultVal'))) {
                $(this).val('http://');
                $(this).css('color', '#000')
            }
        } else if ($(this).attr('name') == 'twitter') {
            if ($(this).val() == 'http://www.twitter.com/' || $(this).val() == $(this).attr('defaultVal')) {
                $(this).val('http://www.twitter.com/');
                $(this).css('color', '#000')
            }
        } else {
            if ($(this).val() == $(this).attr('defaultVal') || $(this).val() == '') {
                $(this).val('');
                $(this).css('color', '#000')
            }
        }
    }).blur(function () {
        if ($(this).val() == 'http://' || $(this).val() == 'http://www.twitter.com/') {
            $(this).val($(this).attr('defaultVal'));
            $(this).css('color', '#ccc')
        }
    });
    $("a[rel=externo], a.link-externo, area[rel=externo]").attr("target", "_blank");
    $("a:not('div.calendario a'), area, input, textarea, select").livequery(function () {
        $(this).tooltip({
            track: true,
            delay: 0,
            showURL: false,
            fade: 250
        })
    });
    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();
    $("ul.tabs li").live("click", function () {
        if ($(this).attr("class") == "active") {
            return false
        } else {
            $("ul.tabs li").removeClass("active");
            $(this).addClass("active");
            $(".tab_content").hide();
            var a = $(this).find("a").attr("href");
            $(a).fadeIn();
            return false
        }
    });
    $("#data, .data").focus(function () {
        var a = new Date();
        var b = a.getFullYear();
        $(this).calendario({
            target: $(this),
            minDate: "01/01/" + b,
            maxDate: "31/12/" + (b + 1),
            top: 0,
            left: 90
        })
    });
    $("#estado").change(function () {
        var b = $(this).val();
        if (b == "nulo") {
            alert("Selecione um estado!");
            $(this).focus();
            return false
        } else {
            $("#cidade").attr("disabled", "disabled");
            $("#cidade option:selected").text("Aguarde... =]");
            $.ajax({
                url:"includes/cidades.php?uf=" + b,
                type: "get",
                success: function (a) {
                    $("#cidade").html(a);
                    $("#cidade").removeAttr("disabled")
                }
            })
        }
    });
    $("form#busca").submit(function () {

        $tag = $('#campobusca');
        if ($tag.val() == '' || $tag.val() == $tag.attr('defaultVal')) {
            alert("Digite o que deseje buscar!");
            $tag.focus();
            return false
        } else {
				msgStatus(true, "Cadastrando , aguarde...");

        enviar($(this), $(this).attr('action'));
		            return false

        }
    });

	    $("form#busca2").submit(function () {

        $tag = $('#campobusca2');
        if ($tag.val() == '' || $tag.val() == $tag.attr('defaultVal2')) {
            alert("Digite o que deseje buscar!");
            $tag.focus();
            return false
        } else {
				msgStatus(true, "Cadastrando , aguarde...");

        enviar($(this), $(this).attr('action'));
		            return false

        }
    });
    $("form#votar").submit(function () {
        votar($(this), $(this).attr('action'));
        return false
    });  
		
		$("form#adicionar-evento").submit(function () {
        cadastrar($(this), $(this).attr('action'));
        return false
    });




    $("button#parcial").click(function () {
        parcial($(this), $(this).attr('action'));
        return false
    });
    $('a.ampliar-foto').click(function () {
        var b = $('div.foto');
        var c = $(this).attr("href");
        b.stop().animate({
            opacity: 0
        }, 300, function () {
            b.empty().text('Carregando a foto...').animate({
                opacity: 1
            });
            $.get('http://www.guiadoagito.com.br/includes/foto.php', {
                foto: c
            }, function (a) {
                b.html(a).animate({
                    opacity: 1
                })
            });
            $('a.foco').removeClass('foco')
        });
        return false
    });
    $("#cadastro-usuario").submit(function () {
        $nome = $("#nome");
        $email = $("#email");
        $senha = $("#senha");
        $csenha = $("#csenha");
        $captcha = $("#captcha");
        if ($nome.val() == "") {
            alert("Informe seu nome!");
            $nome.focus();
            return false
        }
        if ($email.val() == "") {
            alert("Informe seu e-mail!");
            $email.focus();
            return false
        }
        if ($senha.val() == "" || $senha.val() != $csenha.val()) {
            alert("Senhas incorretas!");
            $senha.val("");
            $csenha.val("");
            $senha.focus();
            return false
        }
        if ($captcha.val() == "") {
            alert("Informe a resposta da pergunta anti-spam!");
            $captcha.focus();
            return false
        } else {
            cadastrar($(this), $(this).attr("action"));
            return false
        }
    });



	    $("#star").submit(function () {
        $r1 = $("#r1");
        $id = $("#valor");
        
       
      
            cadastrar($(this), $(this).attr("action"));
            return false
      
    });
    $("a#alterar-foto").toggle(function () {
        $(this).text('Deixar esta mesmo!');
        $('p.campo-foto').show()
    }, function () {
        $(this).text('Alterar foto');
        $('p.campo-foto').hide()
    });
    $("#editar-usuario").submit(function () {
        $nome = $("#nome");
        $email = $("#email");
        $senha = $("#senha");
        $csenha = $("#csenha");
        if ($nome.val() == "") {
            alert("Informe seu nome!");
            $nome.focus();
            return false
        }
        if ($email.val() == "") {
            alert("Informe seu e-mail!");
            $email.focus();
            return false
        }
        if ($senha.val() != $csenha.val()) {
            alert("Senhas incorretas!");
            $senha.val("");
            $csenha.val("");
            $senha.focus();
            return false
        } else {
            atualizar($(this), $(this).attr("action"));
            return false
        }
    });
    $("#cadastro-organizador").submit(function () {
        $empresa = $("#empresa");
        $nome = $("#nome");
        $email = $("#email");
        $senha = $("#senha");
        $csenha = $("#csenha");
        $captcha = $("#captcha");
        if ($empresa.val() == "") {
            alert("Informe o nome de sua empresa/marca!");
            $empresa.focus();
            return false
        }
        if ($nome.val() == "") {
            alert("Informe seu nome!");
            $nome.focus();
            return false
        }
        if ($email.val() == "") {
            alert("Informe seu e-mail!");
            $email.focus();
            return false
        }
        if ($senha.val() == "" || $senha.val() != $csenha.val()) {
            alert("Senhas incorretas!");
            $senha.val("");
            $csenha.val("");
            $senha.focus();
            return false
        }
        if ($captcha.val() == "") {
            alert("Informe a resposta da pergunta anti-spam!");
            $captcha.focus();
            return false
        } else {
            cadastrar($(this), $(this).attr("action"));
            return false
        }
    });
    $("a#alterar-logo").toggle(function () {
        $(this).text('Deixar esta mesmo!');
        $('p.campo-foto').show()
    }, function () {
        $(this).text('Alterar imagem');
        $('p.campo-foto').hide()
    });
    $("#editar-organizador").submit(function () {
        $empresa = $("#empresa");
        $nome = $("#nome");
        $email = $("#email");
        $senha = $("#senha");
        $csenha = $("#csenha");
        if ($empresa.val() == "") {
            alert("Informe o nome da empresa!");
            $empresa.focus();
            return false
        }
        if ($nome.val() == "") {
            alert("Informe seu nome!");
            $nome.focus();
            return false
        }
        if ($email.val() == "") {
            alert("Informe seu e-mail!");
            $email.focus();
            return false
        } else {
            atualizar($(this), $(this).attr("action"));
            return false
        }
    });
    $("button#cortar").click(function () {
        var b = $("input[name=tipo]").val();
        var c = $("img.area-" + b + "-cartaz").attr("alt");
        var d = $("img.area-" + b + "-cartaz").attr("id");
        if ($x1 == null && $x2 == null && $y1 == null && $y2 == null) {
            var e = confirm("Deseja realmente usar a seleção atual?\n Clique em \"OK\" para confirmar esta seleção.\n Clique em \"Cancelar para\" criar uma nova seleção.");
            if (e) {
                if (b == "preview") {
                    var f = $("img.area-preview-cartaz");
                    $x1 = (f.width() - 134) / 2;
                    $x2 = ((f.width() - 134) / 2) + 134;
                    $y1 = (f.height() - 84) / 2;
                    $y2 = ((f.height() - 84) / 2) + 84;
                    $w = 134;
                    $h = 84
                } else {
                    var f = $("img.area-destaque-cartaz");
                    $x1 = (f.width() - 460) / 2;
                    $x2 = ((f.width() - 460) / 2) + 460;
                    $y1 = (f.height() - 270) / 2;
                    $y2 = ((f.height() - 270) / 2) + 270;
                    $w = 460;
                    $h = 270
                }
                msgStatus(true, "Aguarde...");
                $.ajax({
                    url: baseurl + "_acesso/organizadores/cortar.php",
                    type: "post",
                    data: "tipo=" + b + "&eid=" + d + "&foto=" + c + "&xi=" + $x1 + "&yi=" + $y1 + "&largura=" + $w + "&altura=" + $h,
                    success: function (a) {
                        respostaAjax(a)
                    }
                })
            }
        } else {
            msgStatus(true, "Aguarde...");
            $.ajax({
                url: baseurl + "_acesso/organizadores/cortar.php",
                type: "post",
                data: "tipo=" + b + "&eid=" + d + "&foto=" + c + "&xi=" + $x1 + "&yi=" + $y1 + "&largura=" + $w + "&altura=" + $h,
                success: function (a) {
                    respostaAjax(a)
                }
            })
        }
        return false
    });
    $("button#cancelar").click(function () {
        location.href = baseurl + "organizadores/meus-eventos";
        return false
    });


					$("form#adicionar-promocao").submit(function () {
						      $e = $("#evento");
        $di = $("#datai");
        $df = $("#dataf");
        $uf = $("#estado");
        $c = $("#cidade");
        $g = $("#mail");
        $qtd = $("#qtd");
        $i = $("#cartaz");
        if ($e.val() == "") {
            alert("Informe o nome da Promocao!");
            $e.focus();
            return false
        }
			
		if ($di.val() == "") {
            alert("Informe a data de inicio da Promocao!");
            $di.focus();
            return false
        }
        if ($df.val() == "") {
            alert("Informe a data do final da Promocao!");
            $df.focus();
            return false
        }   
			
  
			
			        if ($qtd.val() == "") {
            alert("Informe uma quantidade de sorteados!");
            $qtd.focus();
            return false
        } 
        if ($uf.val() == "nulo") {
            alert("Selecione o estado!");
            $uf.focus();
            return false
        }
        if ($c.val() == "nulo") {
            alert("Selecione a cidade!");
            $c.focus();
            return false
        }     
			
		if ($g.val() == "") {
            alert("Informe um email para informar Promocao!");
            $g.focus();
            return false
        }
        if ($i.val() == "") {
            alert("Selecione uma imagem!");
            $i.focus();
            return false
        } else {
            cadastrar($(this), $(this).attr("action"));
            return false

        }
			

    });

	    $("#adicionar-evento").livequery("submit", function () {
        tinyMCE.triggerSave();
        $e = $("#evento");
        $d = $("#data");
        $uf = $("#estado");
        $c = $("#cidade");
        $i = $("#cartaz");
        if ($e.val() == "") {
            alert("Informe o nome do evento!");
            $e.focus();
            return false
        }
        if ($d.val() == "") {
            alert("Informe a data do evento!");
            $d.focus();
            return false
        }
        if ($uf.val() == "nulo") {
            alert("Selecione o estado!");
            $uf.focus();
            return false
        }
        if ($c.val() == "nulo") {
            alert("Selecione a cidade!");
            $c.focus();
            return false
        }
        if ($i.val() == "") {
            alert("Selecione uma imagem!");
            $i.focus();
            return false
        } else {
            cadastrar($(this), $(this).attr("action"));
            return false
        }
    });
    $("#alterar-cartaz").toggle(function () {
        $(this).text("Deixar este mesmo!");
        $("input#cartaz").show();
        $("p.com-check").hide();
        $("p.com-check input[type=checkbox]").each(function () {
            this.checked = false
        })
    }, function () {
        $(this).text("Alterar cartaz");
        $("input#cartaz").val("").hide();
        $("p.com-check").show()
    });
    $("#editar-evento").submit(function () {
        tinyMCE.triggerSave();
        var e = $("#evento");
        var d = $("#data");
        var a = $("#estado");
        var c = $("#cidade");
        $captcha = $("#captcha");
        if (e.val() == "") {
            alert("Informe o nome do evento!");
            e.focus();
            return false
        }
        if (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 (a.val() == "nulo") {
            alert("Selecione o estado!");
            a.focus();
            return false
        }
        if ($captcha.val() == "") {
            alert("Informe a resposta da pergunta anti-spam!");
            $captcha.focus();
            return false
        } else {
            atualizar($(this), $(this).attr("action"));
            return false
        }
    });
    $("#excluir-eventos-selecionados").click(function () {
        var a = $("input[type=checkbox]:checked").length;
        if (a == 0) {
            alert("Selecione ao menos um evento!");
            return false
        } else {
            var b = confirm("Deseja realmente excluir os eventos selecionados?");
            if (b) {
                exclusao = false;
                excluirSelecionados($(this).attr("href"));
                return false
            } else {
                return false
            }
        }
    });
    $(".excluir-evento").click(function () {
        $("tr#" + $(this).attr("id")).addClass("marcado");
        var a = confirm("Deseja realmente excluir este evento?");
        if (a) {
            exclusao = false;
            excluir($(this), $(this).attr("href"));
            return false
        } else {
            $("tr#" + $(this).attr("id")).removeClass("marcado");
            return false
        }
    });
    $("#cadastro-banda").submit(function () {
        $n = $("#nome");
        $g = $("#genero");
        $logo = $("#imagem");
        $r = $("#responsavel");
        $er = $("#emailr");
        if ($n.val() == "") {
            alert("Informe o nome do artista!");
            $n.focus();
            return false
        }
        if ($g.val() == "nulo") {
            alert("Selecione o estilo musical do artista!");
            $g.focus();
            return false
        }
        if ($logo.val() == "") {
            alert("Selecione uma imagem/logotipo!");
            $logo.focus();
            return false
        }
        if ($r.val() == "") {
            alert("Informe o nome do responsável pelo artista!");
            $r.focus();
            return false
        }
        if ($er.val() == "") {
            alert("Informe o e-mail do responsável pelo artista!");
            $er.focus();
            return false
        } else {
            cadastrar($(this), $(this).attr("action"));
            return false
        }
    });
    $("#divulgar-evento").submit(function () {
        tinyMCE.triggerSave();
        var e = $("#evento");
        var d = $("#data");
        var a = $("#estado");
        var c = $("#cidade");
        var i = $("#cartaz");
        var n = $("#nome");
        $captcha = $("#captcha");
        if (e.val() == "") {
            alert("Informe o nome do evento!");
            e.focus();
            return false
        }
        if (d.val() == "") {
            alert("Informe a data do evento!");
            d.focus();
            return false
        }
        if (a.val() == "nulo") {
            alert("Selecione o estado!");
            a.focus();
            return false
        }
        if (c.val() == "nulo") {
            alert("Selecione a cidade!");
            c.focus();
            return false
        }
        if (i.val() == "") {
            alert("Selecione uma imagem!");
            i.focus();
            return false
        }
        if (n.val() == "") {
            alert("Informe seu nome!");
            n.focus();
            return false
        }
        if ($captcha.val() == "") {
            alert("Informe a resposta da pergunta anti-spam!");
            $captcha.focus();
            return false
        } else {
            cadastrar($(this), $(this).attr("action"));
            return false
        }
    });
    $("#comentar-evento").submit(function () {
        $msg = $("#comentario");
        $captcha = $("#captcha");
        if ($msg.val() == "") {
            alert("Digite uma mensagem!");
            $msg.focus();
            return false
        }
        if ($captcha.val() == "") {
            alert("Informe a resposta da pergunta anti-spam!");
            $captcha.focus();
            return false
        } else {
            enviar($(this), $(this).attr("action"));
            return false
        }
    });
    $("#contato").submit(function () {
        $nome = $("#nome");
        $email = $("#email");
        $estado = $("#estado");
        $assunto = $("#assunto");
        $msg = $("#msg");
        $captcha = $("#captcha");
        if ($nome.val() == "") {
            alert("Informe seu nome!");
            $nome.focus();
            return false
        }
        if ($email.val() == "") {
            alert("Informe seu e-mail!");
            $email.focus();
            return false
        }
        if ($estado.val() == "nulo") {
            alert("Selecione o estado!");
            $estado.focus();
            return false
        }
        if ($assunto.val() == "") {
            alert("Informe o assunto!");
            $assunto.focus();
            return false
        }
        if ($msg.val() == "") {
            alert("Digite uma mensagem!");
            $msg.focus();
            return false
        }
        if ($captcha.val() == "") {
            alert("Informe a resposta da pergunta anti-spam!");
            $captcha.focus();
            return false
        } else {
            enviar($(this), $(this).attr("action"));
            return false
        }
    })
});





