$(document).ready(function() 
{
            
            var dt = $('#messages_table').dataTable( 
            {
                "sAjaxSource": CI_ROOT+"message/getMessages",
                "bJQueryUI": true,
                "bProcessing": true,
                "bServerSide": true,
                "language":{
                            "sProcessing":   "Proceseaza...",
                            "sLengthMenu":   "Afiseaza _MENU_ inregistrari pe pagina",
                            "sZeroRecords":  "Nu am gasit nimic - ne pare rau",
                            "sInfo":         "Afisate de la _START_ la _END_ din _TOTAL_ inregistrari",
                            "sInfoEmpty":    "Afisate de la 0 la 0 din 0 inregistrari",
                            "sInfoFiltered": "(filtrate dintr-un total de _MAX_ inregistrari)",
                            "sInfoPostFix":  "",
                            "sSearch":       "Cauta:",
                            "sUrl":          "",
                            "oPaginate": {
                                "sFirst":    "Prima",
                                "sPrevious": "Precedenta",
                                "sNext":     "Urmatoarea",
                                "sLast":     "Ultima"
                            }
                        },
                "bFilter": true,
                "bLengthChange": true,
                "bInfo": true,
                "bSort": true,
                "fnServerParams": function (aoData) 
                {
                    var id = $("#mesaj").val();
                    aoData.push({"name" : "mesaj_select", "value" : id});
                }
            });

            $("#mesaj").change( function()
            {
                dt.fnDraw();
            }); 
            
                     
                               
});
function viewMessage(e)
{
    var dt = $('#messages_table').dataTable();
    var element = $(this).parent().parent()[0];
    var id      = $(this).parent().find("input").val();
    var row_id  = dt.fnGetPosition(element);
    //alert(id);
    
                
    $.post(CI_ROOT+"message/getTextMessage",{id:id},
        function (data)
        {
            var response = jQuery.parseJSON(data);
           
            if(response.success == 1)
            {
                //alert(response.aaData);
                $('#myModal').modal('show');
                $('#subiect_modal').val(response.aaData[0]);
                $('#mesaj_modal').val(response.aaData[1]);
                $('#data_modal').val(response.aaData[2]);
                dt.fnDraw();
                
            }
            else
            {
                alert('Could not save Student!');
            }

        });
    return false;
}
jQuery.fn.multiselect = function() {
    $(this).each(function() {
        var checkboxes = $(this).find("input:checkbox");
        checkboxes.each(function() {
            var checkbox = $(this);
            // Highlight pre-selected checkboxes
            if (checkbox.prop("checked"))
                checkbox.parent().addClass("multiselect-on");
 
            // Highlight checkboxes that the user selects
            checkbox.click(function() {
                if (checkbox.prop("checked"))
                    checkbox.parent().addClass("multiselect-on");
                else
                    checkbox.parent().removeClass("multiselect-on");
            });
        });
    });
};

$(function() {
     $(".multiselect").multiselect();
});


