<script type="text/javascript">
    $(document).ready(function () {

		$("#list .orden").click(function()
		{
			$(window.location).attr('href', '<?php echo base_url(); ?>'+$(this).attr('rel'));
		});

		$("#per_page").change(function () {

			$("#per_page option:selected").each(function () {

				$(window.location).attr('href', '<?php echo site_url('admin/' . $dir . '/index/') . "/" . $this->session->userdata($dir . '_sort_by') . "/" . $this->session->userdata($dir . '_sort_order') . "/1/"; ?>'+$(this).val());

			});

		});


		// add multiple select / deselect functionality

		$("#all").click(function () {

			$('.ele').attr('checked', this.checked);

		});

		// if all checkbox are selected, check the selectall checkbox

		// and viceversa

		$(".ele").click(function(){
			if($(".ele").length == $(".ele:checked").length) {

				$("#all").attr("checked", "checked");

			} else {

				$("#all").removeAttr("checked");

			}
		});

		$('#nuevo').click(function()
		{
			$(window.location).attr('href', '<?php echo site_url('admin/' . $dir . '/edit/0') ?>');
		});

		$('#restore').click(function()
		{
			$(window.location).attr('href', '<?php echo site_url('admin/' . $dir . '/restaurar') ?>');
		});

		

		$("#breset").click(function()
		{
			$(window.location).attr('href', '<?php echo site_url('admin/' . $dir) ?>');
		});

		$("#csv").click(function () {
			$('#delete-form').attr('action', '<?php echo base_url('admin/' . $dir . '/exportarCSV/'); ?>');
			$('#delete-form').submit();
		});

		$('#atras').click(function()
		{
			$(window.location).attr('href', '<?php echo site_url('admin/' . $dir . '/index/') ?>');
		});

		var table = $('#list').DataTable({
	        "order": [[ 0, 'desc' ]],
			"pageLength": 25,
            "language": {
                "url": "//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json"
            }
        });
 
        $('#list tbody').on( 'click', 'tr', function () {
            if ( $(this).hasClass('selected') ) {
                $(this).removeClass('selected');
                id = table.$('tr.selected').data('id');
            }
            else {
                table.$('tr.selected').removeClass('selected');
                $(this).addClass('selected');
                id = table.$('tr.selected').data('id');
            }
        } );


     
        $('#eliminar').click( function () {
            table.row('.selected').remove().draw( false );

            $.ajax({
              type: "POST",
              url: "<?php echo base_url('admin/' . $dir . '/delete/'); ?>",
              data : {"ele": id}
            });

            $(".close").click();

        } );

        $('#restaurar').click( function () {
            table.row('.selected').remove().draw( false );

            $.ajax({
              type: "POST",
              url: "<?php echo base_url('admin/' . $dir . '/restore/'); ?>",
              data : {"ele": id}
            });

            $(".close").click();

        } );
	});
</script>