
function indicar(url) {
    $('#aspnetForm').removeValidate().validate({
        rules: {
            'indiq_nome': 'required',
            'indiq_email': 'required email',
            'indiq_emailTo': 'required email'
        }
    });
    if ($('#aspnetForm').valid()) {
        $("#ajaxIndiqLoader").show();
        $("#btnIndique").hide();

        $.ajax({
            type: "POST",
            url: "ajax/indicar/",
            dataType: "json",
            data: {
                url: url,
                nome: $('#indiq_nome').val(),
                email: $('#indiq_email').val(),
                emailTo: $('#indiq_emailTo').val()
            },
            complete: function(request, status) {
                $("#ajaxIndiqLoader").hide();
            },
            success: function(data, status, request) {
                if (data.success) {
                    $('#indiq_nome').val('');
                    $('#indiq_email').val('');
                    $('#indiq_emailTo').val('');
                    $.mensagem(data.message);
                }
                $("#btnIndique").show();
            }
        });
    }
    return false;
}



function votar(clientID, idEnquete) {
    $("#btnVotar" + clientID).hide();
    $("#ajaxLoader" + clientID).show();
    var idResposta = $("input[name=enq_" + idEnquete + "]:checked").val();

    $.ajax({
        type: "POST",
        url: "ajax/votar/",
        dataType: "json",
        data: {
            idEnquete: idEnquete,
            idResposta: idResposta
        },
        complete: function(request, status) {
            $("#ajaxLoader" + clientID).hide();
            $("#btnVotar" + clientID).show();
        },
        success: function(data, status, request) {
            $("#spnMsg" + clientID).show();
            $("#spnMsg" + clientID).html(data.message);
            if (data.success) {
                //montarRespostas(clientID, data.data);
            }
        }
    });
}
function exibirRespostas(clientID, idEnquete) {
    $.ajax({
        type: "POST",
        url: "ajax/exibirRespostas/",
        dataType: "json",
        data: {
            idEnquete: idEnquete
        },
        complete: function(request, status) {
        },
        success: function(data, status, request) {
            montarRespostas(clientID, data.data);
        }
    });
}
function montarRespostas(clientID, data) {
    $("#dvEnquete" + clientID).hide();
    var votos = "";
    var tplVotos = "<p>{resposta} - <strong>{porcentagem}%</strong><br /><small>({nVotos} voto(s))</small></p>";


    $.each(data, function() {
        var item = '';
        item = tplVotos.replace('{resposta}', this.resposta)
                                .replace('{porcentagem}', this.porcentagem)
                                .replace('{nVotos}', this.nVotos);
        votos += item;
    });

    votos += '<a href="javascript:void(0);" onclick="enqueteVoltar(\'' + clientID + '\');" style="margin-top: 10px;margin-left: 10px;" class="acesso bulletSeta">Voltar</a>';
    
    $("#dvVotos" + clientID).html(votos);
    $("#dvVotos" + clientID).show();
}
function enqueteVoltar(clientID) {
    $("#dvVotos" + clientID).hide();
    $("#dvEnquete" + clientID).show();
}
