<script type="text/javascript">
    $(document).ready(function () {
        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        $("#sub_all").click(function () {
            $('.sub_ele').attr('checked', this.checked);
        });
        $(".sub_ele").click(function () {
            if ($(".sub_ele").length == $(".sub_ele:checked").length) {
                $("#sub_all").attr("checked", "checked");
            } else {
                $("#sub_all").removeAttr("checked");
            }
        });

        $('.sub_edit').click(function (event) {
            $("#profesionales").load($(this).attr('href'), {idPaciente: '<?php echo $idPaciente?>', idLocalidad: '<?php echo $idLocalidad?>'});
            return false;
        });

        $('#sub_cancelar').click(function () {
            $("#profesionales").load("<?php echo base_url('admin/' . $dir . '/sub_index/' . $idPaciente . '/' . $idLocalidad) ?>");
        });

        $('#sub_restore').click(function () {
            var selectedItems = new Array();
            $("input[@name='sub_ele[]']:checked").each(function () {
                selectedItems.push($(this).val());
            });
            if (selectedItems.length > 0) {
                $("#profesionales").load("<?php echo base_url('admin/' . $dir . '/sub_restore/')?>", {
                    idPaciente: '<?php echo $idPaciente?>',
                    idLocalidad: '<?php echo $idLocalidad?>',
                    sub_ele: selectedItems
                });
                $(".close").click();
                return false;
            }
            else {
                $(".close").click();
            }
        });

    });
</script>

<div class="modal fade hide" id="myModal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h3>Eliminar</h3>
    </div>
    <div class="modal-body">
        <p>¿Desea restaurar los registros?</p>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">Cancelar</a>
        <a href="#" class="btn btn-primary" id="sub_restore">Aceptar</a>
    </div>
</div>

<div id="page-title" class="clearfix">
    <span style="font-size:24px;font-weight:bold;float:left;margin-top:5px;"><?php echo $dir3; ?></span>
    <div class="item-content" style="float:right;">
        <a href="#myModal" data-toggle="modal" class="btn btn-inverse">Restaurar</a>
        <button class="btn cancel" id="sub_cancelar">Cancelar</button>
    </div>
</div> <!-- /.page-title -->

<div class="row">
    <div class="span12">
        <div class="widget widget-table">
            <div class="widget-content">
                <div id="example_wrapper" class="dataTables_wrapper form-inline" role="grid">
                    <?php // if(isset($message)) echo $message;?>

                    <?php $this->load->view('partials/sub_table.php'); ?>

                </div>
            </div>
        </div>
    </div>
</div>	