<script type="text/javascript">
    var valuedatatable;
	
	$(document).ready(function(){
<!-- page script -->
        //$('.datatables').DataTable();
        $('.datetimepicker').datetimepicker({
            viewMode: 'months',
            format: 'DD-MM-YYYY'
        });
		
		
		$('#datatable_companylist').on('search.dt', function() {
    		valuedatatable = $('.dataTables_filter input').val();
    		//alert(valuedatatable);
		});
		
		/*
		 $('#datatable_companylist').dataTable( {
			"aoColumnDefs": [
			  		{ "bSearchable": false, "aTargets": [ 0] },
			  		{ "bSearchable": true, "aTargets": [ 1] },
			  		{ "bSearchable": false, "aTargets": [ 2] }
			] 
		});
		*/
		
		$('#datatable_companylist').DataTable( {
			"pageLength": 25,
			initComplete: function () {	
				var $table = $(this);			
				var $filter = $table.parents('.dataTables_wrapper').find('.dataTables_filter');
				
				$filter.find('input[type="search"]').attr('id','search_input');
			}
		});
	
		

    });
    
	function showDetail(me)
	{
		
		$('#companyID').val("");
		$('#companyName').val("");
		$('#companyAddress').val("");
		
    	$('#company_modal').modal('show');
		
	}
	
	function showDetail2(companyID, companyName)
	{
		
		$('#company_modal').modal('show');
		
		$('#companyID').val(companyID);
		$('#companyName').val(companyName);
		
		$('#companyAddress').val($('#companyAddress_' + companyID).text());
	}
	
	function deleteConfirm(companyID)
	{
		$('#deleteID').val(companyID);
		$('#delete_modal').modal('show');
		
	}
	
	function deleteCompany(){
	
		var companyID = $('#deleteID').val();
		//if (confirm("Are you sure?")) {
        
			$.ajax({
				type: "POST",
				url: "<?php echo base_url(); ?>company/deleteCompany",
				data: {
					'companyID' : companyID
				},
				dataType:'json',
				success: function(data){
					if(data.status == 'success'){
						
						location.reload();
						
					}
				}
			 });
		
		 //}
    	//return false;
	
	}
	
	function printcompany(){
		
		$('#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() ?>company/printCompany/" + search;
		
		$('#print_btn').attr('target','_blank');
		$('#print_btn').attr('href',url);
		return true;
	}
	
	
	
</script>

