<?php error_reporting(E_ALL ^ E_NOTICE);
if(isset($list)){	
	$val=$list->row_array();
}
?>
<?php
$cekdup=($type=='New' ? ',ajax[ajaxcekcode]' : '');
?>
    
<div class="row">
	
    	<div class="box-content">
            <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  }?>
       <form id="form" method="post" enctype="multipart/form-data" action="<?php echo base_url($this->utama)?>/submit" class="form-horizontal formular" role="form">
		   
		   <?php echo form_hidden('id',isset($val['id']) ? $val['id'] : '')?>
			
		   
		   
		   <!--div class="form-group">
			   
			   <?php $nm_f="code";?>
			   <div class="col-sm-3">
				   <label for="<?php echo $nm_f?>">Code</label>
				   </div><div class="col-sm-9">
				   <input type="text" name="<?php echo $nm_f?>"  id="<?php echo $nm_f?>_master_brand" value="<?php echo $a= (isset($val[$nm_f]) ? $val[$nm_f] : '') ?>" class="col-sm-4 validate[required<?php echo $cekdup?>]">
			   </div>
		   </div-->
		   
		   <div class="form-group">
			   
			   <?php $nm_f="produk";?> 
			   <div class="col-sm-2">
				   <label for="<?php echo $nm_f?>">Produk</label>
				   </div><div class="col-sm-9">
                                   <?php echo form_dropdown($nm_f,$opt_produk,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="select2" onchange="cekisi()" id="'.$nm_f.'"'); ?>
			   </div>
		   </div>
		  
		   <!--div class="form-group">
			   
			   <?php $nm_f="activity";?> 
			   <div class="col-sm-2">
				   <label for="<?php echo $nm_f?>">Jenis Activity</label>
				   </div><div class="col-sm-9" id="activity_sales">
                                   <?php echo form_dropdown($nm_f,array(),(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="select2" onchange="" id="'.$nm_f.'"'); ?>
			   </div>
		   </div-->
		   <div id="activity_sales">
		   <!--div class="form-group">
			   
			   <?php $nm_f="target[]";?> 
			   <div class="col-sm-2">
				   <label for="<?php echo $nm_f?>">Target</label>
				   </div><div class="col-sm-9">
                                   <?php echo form_input($nm_f,(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="" onchange="" id="'.$nm_f.'"'); ?>
                                   <?php echo form_input("activity[]",(isset($val[$nm_f]) ? $val[$nm_f] : ''),'class="" onchange="" id="'.$nm_f.'" style="display:none"'); ?>
			   </div>
		   </div-->
                   </div>
		   <div class="form-group">
			   
                       <div class="col-sm-12"></div>
		   </div>
                   <div id="monthlys">
                   </div>
    		<div class="form-group">
            <button type="submit" class="btn pull-right">Submit</button>
            
             </div>
			 </form>
    	</div> 
    </div>
    </div>
</div>
<script>
    
    $(document).ready(function(e){
        $('.select2').css('width','200px').select2({matcher: function(params,data){
               return matchStart(params, data);
               }});
        cekisi();
        $("#form").validate({
            submitHandler: function(form) {
    form.submit();
  },
           ignore: [],      
            rules: {
                'title': {required:true},
                'tag': {required:true}
            }
            , 
            messages: {
                'title': 'Wajib diisi',
                'tag': 'Wajib diisi'
            }
            });
            $('#from').datepicker({
                //startDate: '-0m',
                 format: 'yyyy-mm-dd'
                //endDate: '+2d'
                 }).on('changeDate', function(ev){
                //$('#sDate1').text($('#datepicker').data('date'));
                //alert('ev');
                var from=$('#from').val();
                var abs=from.split('-');
                var maxDate =  new Date(abs[0], abs[1] +0, +0);
                var monthz=parseInt(maxDate.getMonth())+1;
                var end=abs[0]+'-'+monthz+'-'+maxDate.getDate();
               // alert(end);
                    $('#to').datepicker({
                        
                        format: 'yyyy-mm-dd',
                        //startDate: '-0m',
                        //endDate: abs[0]+'-'+abs[1]+'-31'
                        //endDate:'Apr 30 2017'
                        //stepMonths: 0,
                        endDate:end
                    });
                });
    });
    function cekisi(){
            //alert('ok');
            $('#monthlys').empty();
            $('#activity_sales').empty();
            var sales=$('#produk').val();
            var year=$('#year').val();
            if(sales){
                $('#activity_sales').load('<?php echo base_url().$this->utama?>/loadactivity',{s:sales},function(e){
                    
            });
            }
//        if(sales && year){
//            $('#monthlys').append('<img src="<?php echo base_url()?>assets/img/nowload.gif" width="30px" height="30px"/>');
//            $('#monthlys').load('<?php echo base_url()?>sales_plan/loadisi',{s:sales,y:year},function(e){
//            });
//        }
    }
</script>