$("#rateYo").rateYo({
    fullStar: true
}).on("rateyo.set", function (e, data) {
    $('input[name=classificacao]').val(data.rating);
});

$('.send-pesquisa').click(function()
{
    var error = false;
    for(var i=1;i<5;i++)
    {
        var missing = true;
        $('input[name^="resp_'+i+'"]:checked').each(function(index){
            if(!($(this).val() == 'Outros' && $('textarea[name^="resp_'+i+'"]').val() == ''))
            {
                missing = false;
            }
        });
        if(missing == true)
        {
            error = missing;
            $('.required').eq(i-1).addClass('required-red');
        }
        else
        {
            $('.required').eq(i-1).removeClass('required-red');
        }
    }
    if($('input[name=classificacao]').val() == "")
    {
        error = true;
        $('.required:last').addClass('required-red');
    }
    else
    {
        $('.required').eq(i-1).removeClass('required-red');
    }
    
    if(error == true)
    {
        showModal('Erro ao Concluir Pesquisa', 'Por favor responda todas as perguntas.', 'danger');
    }
    else
    {
        $('form[name=pesquisaForm]').submit();
    }
});

$(window).load(function()
{
    
    if($('.showModal').length)
    {
        var title = $('.showModal').data('title');
        var content = $('.showModal').data('content');
        var classe = $('.showModal').data('class');
        showModal(title, content, classe);
    }
})


$('input').on('ifChanged', function(e){
    if(e.target.value == 'Outros')
    {
        if(e.target.checked)
        {
           $(this).parents('.form-group').next().find('textarea').removeAttr('disabled');
        }
        else
        {
           $(this).parents('.form-group').next().find('textarea').prop("disabled", true);;
        }
    }
});