<style>
    textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"] {
    background-color: #ffffff;
    border: 1px solid #4c8fbd;
    border-radius: 5px !important;
    box-shadow: none !important;
    color: #858585;
    font-family: inherit;
    font-size: 14px;
    padding: 5px 4px 6px;
    transition-duration: 0.1s;
}
    </style>


<br/><?php if($this->session->flashdata('message')){?>
<div class="col-sm-12" style="padding-left:0px!important; margin-top: 20px;">  <div class="alert alert-info"><?php echo $this->session->flashdata('message');?></div></div><?php  }?>
<?php
error_reporting(0);
 echo $js_grid; ?>
<!--input type="button" value="Tambah" onclick="window.location = '<?//= base_url() ?>index.php/ms_con/add'"/-->
<script type="text/javascript">
var _base_url = '<?php echo  base_url() ?>';
var controller = '<?php echo $this->utama?>/';
function del(id) { 
  i = confirm('Hapus : ' + id + ' ?');
  if (i) {
    window.location = _base_url + controller + 'delete/' + id;
  }
}
//$('.flex1').flexigrid({height:'auto',width:'auto',striped:false});

function edit(id) {
  window.location = _base_url + controller + 'input/' + id;
}

function detail(id) {
  window.location = _base_url + controller + 'form/' + id;
}
function btn(com,grid)
{
    if (com == 'add' ) {
		window.location = _base_url + controller + 'form/';
    }
	
    if (com == 'select' )
    {
		$('.bDiv tbody tr',grid).addClass('trSelected');
    }

    if (com == 'deselect')
    {
		$('.bDiv tbody tr',grid).removeClass('trSelected');
    }
	if(com=='edit'){
		if($('.trSelected',grid).length==1){ 
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
		//var items = $('.trSelected',grid);
 		 window.location = _base_url + controller + 'form/' + $('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', '.trSelected',grid).text();
			} else {
				return false;
			} 
	}
        if(com=='pengiriman'){
		if($('.trSelected',grid).length==1){ 
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
		//var items = $('.trSelected',grid);
 		 window.location = _base_url + controller + 'pengiriman/' + $('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', '.trSelected',grid).text();
			} else {
				return false;
			} 
	}
	if (com=='delete')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Delete ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
					itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+",";
					}
					  	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/deletec");?>",
					   data: "items="+itemlist,
					   success: function(data){
					   	$('#flex1').flexReload();
						//alert(data);
						if(data=='ok'){
						alert('Sukses!');}
						else{
							alert('Failed to Delete Data');
						}
					   }
					});
				}
			} else {
				return false;
			} 
      }       
	if (com=='export to xls')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Export ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
                                        var maxxx=items.length-1;
                                        if(i==maxxx){ var azz='';}
					else{
                                        var azz='%';
                                        }
                                           itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+azz;
					}
					  window.location = '<?php echo site_url($this->utama."/render_xls");?>/'+itemlist;	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/to_xls");?>",
					   data: "items="+itemlist,
					   success: function(data){
                                               
                                $("body").append("<iframe src='<?php echo site_url($this->utama."/to_xls");?>' style='display: none;' ></iframe>");
					   	//$('#flex1').flexReload(); 
						//alert(data);
//						if(data=='ok'){
//						alert('Sukses!');}
//						else{
//							alert('Failed to Delete Data');
//						}
					   }
					});
				}
			} else {
				return false;
			} 
      }  
      if (com=='cetak p.o')
    {
        var abbr = [];
    	$('.hDiv th', flex).each( function(index){
            abbr[index] = $(this).attr('abbr');
  	});
        
           if($('.trSelected',grid).length>0){
                        if($('.trSelected',grid).length==1){
                            window.location = '<?php echo site_url($this->utama."/suratpo");?>/'+$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', '.trSelected',grid).text()+'/true';
                        }
			   
			} else {
				return false;
			} 
      }
      if (com=='export to pdf')
    {
           if($('.trSelected',grid).length>0){
			   if(confirm('Export ' + $('.trSelected',grid).length + ' items?')){
		        var flex = $(grid).closest('.flexigrid');
    			var abbr = [];
    				$('.hDiv th', flex).each( function(index){
       			 abbr[index] = $(this).attr('abbr');
  				  });
    	
   				 $('.res').html('');//div.res - area for display result
		            var items = $('.trSelected',grid);
		            var itemlist ='';
		        	for(i=0;i<items.length;i++){ 
					//itemlist+=items[i].id+",";
					//var iteming=$('td:"no_reg" >div', items[i]).text();
                                        var maxxx=items.length-1;
                                        if(i==maxxx){ var azz='';}
					else{
                                        var azz='%';
                                        }
                                           itemlist+=$('td:nth-child('+ (1+$.inArray('idnya',abbr)) +')>div', items[i]).text()+azz;
					}
					  window.location = '<?php echo site_url($this->utama."/render_pdf");?>/'+itemlist;	
					$.ajax({
					   type: "POST",
					   url: "<?php echo site_url($this->utama."/to_xls");?>",
					   data: "items="+itemlist,
					   success: function(data){
                                               
                                $("body").append("<iframe src='<?php echo site_url($this->utama."/to_xls");?>' style='display: none;' ></iframe>");
					   	//$('#flex1').flexReload(); 
						//alert(data);
//						if(data=='ok'){
//						alert('Sukses!');}
//						else{
//							alert('Failed to Delete Data');
//						}
					   }
					});
				}
			} else {
				return false;
			} 
      }    
}
setInterval("$('#flex1').flexReload()",50000 );

function removeParam(key, sourceURL) {
    var rtn = sourceURL.split("?")[0],
        param,
        params_arr = [],
        queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
    if (queryString !== "") {
        params_arr = queryString.split("&");
        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
            param = params_arr[i].split("=")[0];
            if (param === key) {
                params_arr.splice(i, 1);
            }
        }
        rtn = rtn + "" + params_arr.join("&");
    }
    return rtn;
} 
function filter(){
    var divisi=$('#divisinya').val();
    var grup=$('#grupnya').val();
    $.post('<?php echo base_url()?>load/gantidivisidashboard',{d:divisi,g:grup},function(e){
                var abc = $(".tab-pane.fade.in.active").attr("id");
                var winz=window.location.href;
                var res=removeParam('activer',winz);
   window.location.href = res + "?activer="+abc;

    });
}
function gantiindivisi(){
    
    var dz=$('#divisinya').val();
    $('#grupingnya').load('<?php echo base_url()?>load/grup/',{dz:dz});
    
    }
function gantidivisi(val){
    $.post('<?php echo base_url()?>load/gantidivisidashboard',{d:val},function(e){
                var abc = $(".tab-pane.fade.in.active").attr("id");
                var winz=window.location.href;
                var res=removeParam('activer',winz);
   window.location.href = res + "?activer="+abc;

    });
}
</script>
<div class="col-sm-12" style="padding-left:0px!important; margin-top: 20px;">
<div class="layout-grid">
	<table id="flex1" style="display:none; "></table>
</div>
</div>