var mensagem = '';
var clickUmaVez = 0;
$(function(){
    $(".mapa-reservas a").easyTooltip({
        tooltipId: "easyTooltip2",
        content: mensagem
    });
});
 function bindConfirmaButton(){  
    $(".confirmaCancelamento").each(function(){
        $(this).bind('click', function(){
            if(clickUmaVez == 0){
                inputChecked = $(this);
                $("#confirmation").dialog("open");
                clickUmaVez = 1;
                return false;
            }
        });
    });
}
var inputChecked = '';
var hasOnClickEvent = 0;
var onclick = null;

$(document).ready(function(){
    bindConfirmaButton();
    $("#confirmation").dialog({
        autoOpen: false,
        bgiframe: true,
        height: 140,
        modal: true,
        buttons: {
            Cancelar: function() {
                $(this).dialog('close');
                inputChecked.attr('checked', '');
            },
            Ok: function() {
                if(hasOnClickEvent==0){
                    inputChecked.attr('checked', 'checked');
                }else{
                    inputChecked.attr('checked', false);
                    eval(onclick);
                }
                $(this).dialog('close');
            }
        }

    });
});

/*
 * JS que cuida da área de reservas
 */
 $(function(){
    $('.select-reservas').each(function(){
        $(this).find(".newList a").click(function(){
             switch($(this).html()){
                case '1º Andar':
                    $('.andar-1').show();
                    $('.andar-2').hide();
                break;
                case '2º Andar':
                    $('.andar-2').show();
                    $('.andar-1').hide();
                break;
                default:
                    var evento = $('.troca-evento').val();
                    window.location=baseUrl+"/reservas/"+evento;
                break;
            }
        });
    });
 });
 $(function(){
       $('.sel-mesas').each(function(){
       $(this).bind('click', function(){
            var mesa = $(this).attr('rel');

            $('#mesaR').val(mesa);
            var existeMesaLivre = $('#mesaR').serialize();


            var text = $('#mesaR option:selected').text();
            //alert(existeMesaLivre);
            if(existeMesaLivre == 'mesaR=0' ){
                text = 'Reservado';
            }

            $('#mesaR-element .selectedTxt').html(text);
            return false;
        })
    })
 })
