<script type="text/javascript">
    var valuedatatable;
	
	$(document).ready(function(){
<!-- page script -->
        //$('.datatables').DataTable();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD-MM-YYYY'
        });
		
		
		$('#datatable_votelist').on('search.dt', function() {
    		valuedatatable = $('.dataTables_filter input').val();
    		//alert(valuedatatable);
		});
		
		
		 $('#datatable_votelist').dataTable( {
			"aoColumnDefs": [
			  		{ "bSearchable": false, "aTargets": [ 0] },
			  		{ "bSearchable": true, "aTargets": [ 1] },
					{ "bSearchable": true, "aTargets": [ 2] },
			  		{ "bSearchable": false, "aTargets": [ 3] },
			  		{ "bSearchable": false, "aTargets": [ 4] },
			   		{ "bSearchable": false, "aTargets": [ 5] }
			] 
		});
		

    });
    
	function showDetail(me)
	{
		
		$('#positionID').val("");
		$('#positionName').val("");
		$('#elected').val("");
		$('#ordering').val("");
		
    	$('#position_modal').modal('show');
		
	}
	
	function showDetail2(positionID, positionName, elected, ordering)
	{
		
		$('#position_modal').modal('show');
		
		$('#positionID').val(positionID);
		$('#positionName').val(positionName);
		$('#elected').val(elected);
		$('#ordering').val(ordering);
		
	}
	
	
	
	
	function deleteConfirm(me)
	{
		$('#delete_modal').modal('show');
		
	}
	
	function deleteVote(){
		
		var userID = Array();
		var count = 0;
	
		$.each($("#datatable_votelist").dataTable().fnGetNodes(), function(index,value) {

          		if($(this).find("td:eq(5) input:checked").val()) {

          			userID[count] = $(this).find("td:eq(6)").text();
					
					count++;
        	
				}
				
				
			
		});
	
		
			//alert(userID);
		
		$('#delete_modal').modal('hide');
		openLoader();
		$.ajax({
			type: "POST",
			url: "<?php echo base_url(); ?>vote/deleteVote",
			data: {
				'userID' : userID
			},
			dataType:'json',
			success: function(data){
				if(data.status == 'success') window.location.reload();
				closeLoader();
			}
		});
	
	}
	
	function printvote(){
			
		$('#print_btn').attr('href','javascript:void(0);');
		
		var search = $.trim($('#search_input').val());				
				search = (search !== "") ? search.replace(' ','%20') : 'all';
		
		var url = "<?php echo base_url() ?>vote/printVote/" + search;
		
		$('#print_btn').attr('target','_blank');
		$('#print_btn').attr('href',url);
		return true;
		
	}
	
	function isNumberKey(evt){
    	var charCode = (evt.which) ? evt.which : event.keyCode
    	if (charCode > 31 && (charCode < 48 || charCode > 57)){
			return false;
		}
		else{
			return true;
		}
	}
	
	function select_or_unselect_all(me) {
		var oTable = $('#datatable_votelist').dataTable();
        if ($(me).is(':checked')) {
            $(oTable.fnGetNodes()).find(':checkbox').prop('checked', true);
            $('.delete').prop('disabled', false);
        } else {
            $(oTable.fnGetNodes()).find(':checkbox').prop('checked', false);
            $('.delete').prop('disabled', true);
        }
    }
	
	function enabled_or_disabled_delete_btn(me) {
		if ($(me).is(':checked')) {
            $('.delete').prop('disabled', false);
        } else {
            var oTable = $('#datatable_votelist').dataTable();
            $(oTable.fnGetNodes()).find('input[type=checkbox] :checked');
            var notfind = true;
            $(oTable.fnGetNodes()).find(':checkbox:checked').each(function() {
                $('.delete').prop('disabled', false);
                notfind = false;
				return true;
            });
            if (notfind) {
                 $('.delete').prop('disabled', true);
            }
        }
    }
	
	
	function viewvote(userID, me){			
		$(me).attr('href','javascript:void(0);');
		
		var url = "<?php echo base_url() ?>vote/viewVote/" + userID;
		
		$(me).attr('target','_blank');
		$(me).attr('href',url);
		return true;
	}
	
</script>



