<style type="text/css">
.autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; }
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
.autocomplete-selected { background: #BCFCA0;font-size: 12px; }
.autocomplete-suggestions strong { font-weight: normal;font-size: 14px; color: #525050;background-color:#BEECFF }
</style>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>resources/css/jquery.autocomplete.css">
<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.autocomplete.js"></script> 
<script src="<?php echo base_url();?>resources/js/autoNumeric.js"></script>
<hr class="thick-line" style="clear:both;">
<div style="padding:20px;"></div>
	<div class="detil" style="font-size:14px;margin-top:25px;width: 75%;margin: 0 auto;border-color: #FFFFFF;">
		<form id="frm_add_diversi" style="background:white;margin:0;" method="post" action="<?php echo base_url().'add_register_diversi/validateInput';?>">
			<table id="tableDetilPerkara" style="font-size:14px;" width="750px" >
				<col width="25%">
				<col width="75%">
				<tbody >
                        <tr><td colspan="2" class="divider"><strong>KESEPAKATAN DIVERSI</td></tr>
                        <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Tanggal Diterima Permohonan<font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_diterima_permohonan" name="tgl_diterima_permohonan" value="<?php echo $act=='edit' ? $this->templatehelper->convertKeTglDatepicker($tgl_diterima_permohonan):date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                            </td>
                        </tr>
                        <?php if($act!='edit'){?>
                        <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Generate Nomor</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <span class="custom-dropdown custom-dropdown--emerald" style="width:100px">
                                    <select name="generate" id="generate" style='width:100px;' class="custom-dropdown__select custom-dropdown__select--white">
                                        <option value="1">Ya</option>
                                        <option value="2">Tidak</option>
                                    </select>
                                </span>                             
                            </td>
                         </tr>
                         <?php } ?>
                        <tr>                            
                            <td bgcolor='#5FB85C'><font color='#fff'>Nomor Urut</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input type="text" id="no_urut_diversi" name="no_urut_diversi" value="<?php echo $act=='edit' ? $no_urut : $no_urut_diversi;?>" class="standard-input" style="width:60px;" readonly="true">
                            </td>
                        </tr>                         
                        <tr>                            
                            <td bgcolor='#5FB85C'><font color='#fff'>Nomor Diversi<font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input type="text" id="no_diversi" name="no_diversi" value="<?php echo $act=='edit' ? $no_diversi : $new_no_diversi;?>" class="standard-input" style="width:320px;" readonly="true">
                            </td>
                        </tr>
                        <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Diversi dimohonkan oleh<font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <span class="custom-dropdown custom-dropdown--emerald" style="width:250px">
                                    <select name="dimohonkan_oleh" id="dimohonkan_oleh" style='width:250px;' class="custom-dropdown__select custom-dropdown__select--white">
                                        <option value="0">- Pilih - </option>
                                        <option value="1" <?php echo $pemohon_diversi=='1'?'selected':'';?>>Penyidik</option>
                                        <option value="2" <?php echo $pemohon_diversi=='2'?'selected':'';?>>Penuntut</option>
                                        <?php if($act=='edit'){?>
                                        <option value="3" <?php echo $pemohon_diversi=='3'?'selected':'';?>>Hakim</option> -->
                                        <?php } ?>
                                    </select>
                                </span>                            	
                            </td>
                         </tr>
                        <tr id='tr_reg_penyidik'>                            
                            <td bgcolor='#5FB85C'><font color='#fff'>Nomor Register Penyidik<font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input type="text" id="no_reg_penyidik" name="no_reg_penyidik" value="<?php echo !empty($no_reg_penyidik)?$no_reg_penyidik:'';?>" class="standard-input" style="width:320px;" readonly="true">
                            </td>
                        </tr>
                        <tr id='tr_reg_pu'>                            
                            <td bgcolor='#5FB85C'><font color='#fff'>Nomor Register Penuntut</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input type="text" id="no_reg_penuntut" name="no_reg_penuntut" value="<?php echo !empty($no_reg_penuntut_umum)?$no_reg_penuntut_umum:'';?>" class="standard-input" style="width:320px;" readonly="true">
                            </td>
                        </tr>
                        <?php if($act=='edit'){?>
                        <tr>                            
                            <td bgcolor='#5FB85C'><font color='#fff'>Nomor Berita Acara</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input type="text" id="no_berita_acara" name="no_berita_acara" value="<?php echo !empty($no_berita_acara) ? $no_berita_acara : '';?>" class="standard-input" style="width:320px;">
                            </td>
                        </tr>
                        <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Tanggal Berita Acara<font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_berita_acara" name="tgl_berita_acara" value="<?php echo $act=='edit' && !empty($tgl_berita_acara) ? $this->templatehelper->convertKeTglDatepicker($tgl_berita_acara):date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                            </td>
                        </tr>
<!--                         <tr>                            
                            <td bgcolor='#5FB85C'><font color='#fff'>Pasal Sangakaan/Dakwaan</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <textarea id="pasal_sangkaan_dakwaan" name="pasal_sangkaan_dakwaan" class="" cols="100"><?php echo !empty($pasal_sangkaan_dakwaan) ? $pasal_sangkaan_dakwaan : '';?></textarea> 
                            </td>
                        </tr>
                         -->                        
<!--                         <tr>                            
    <td bgcolor='#5FB85C'><font color='#fff'>Pasal Sangakaan/Dakwaan</font></td>
    <td style="padding:0px;padding-left:5px;">
        <textarea id="pasal_sangkaan_dakwaan" name="pasal_sangkaan_dakwaan" class="" cols="100"><?php echo !empty($pasal_sangkaan_dakwaan) ? $pasal_sangkaan_dakwaan : '';?></textarea> 
    </td>
</tr> -->
                        <tr>
                            <td valign="top" style="vertical-align:top">Pasal Sangkaan/Dakwaan<font color="red">*</font></td>
                            <td style="background:white;" id="pasal_sangkaan_dakwaan_text">
                                <?php echo $this->ckeditor->editor("pasal_sangkaan_dakwaan",$pasal_sangkaan_dakwaan);?>
                            </td>
                        </tr>
                         <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Tanggal Kesepakatan Diversi<font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_kesepakatan_diversi" name="tgl_kesepakatan_diversi" value="<?php echo $act=='edit' && !empty($tgl_kesepakatan_diversi) ? $this->templatehelper->convertKeTglDatepicker($tgl_kesepakatan_diversi):date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                            </td>
                        </tr>
                        <tr>
                            <td valign="top" style="vertical-align:top">Isi Kesepakatan Diversi<font color="red">*</font></td>
                            <td style="background:white;" id="isi_kesepakatan_diversi_text">
                                <?php echo $this->ckeditor->editor("isi_kesepakatan_diversi",$isi_kesepakatan_diversi);?>
                            </td>
                        </tr>
                         <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Tanggal Penetapan KPN <font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_penetapan_kpn" name="tgl_penetapan_kpn" value="<?php echo $act=='edit' && !empty($tgl_penetapan_kpn) ? $this->templatehelper->convertKeTglDatepicker($tgl_penetapan_kpn):date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                            </td>
                        </tr>
                         <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Tanggal Pengiriman Penetapan KPN <font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_pengiriman_penetapan_kpn" name="tgl_pengiriman_penetapan_kpn" value="<?php echo $act=='edit' && !empty($tgl_pengiriman_penetapan_kpn) ? $this->templatehelper->convertKeTglDatepicker($tgl_pengiriman_penetapan_kpn):date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                            </td>
                        </tr>
                        <tr>
                            <td valign="top" style="vertical-align:top">Amar Penetapan Diversi<font color="red">*</font></td>
                            <td style="background:white;" id="amar_text">
                                <?php echo $this->ckeditor->editor("amar",$amar);?>
                            </td>
                        </tr>
                         <tr>
                            <td bgcolor='#5FB85C'><font color='#fff'>Tanggal Pelaksanaan Isi Diversi <font color="red">*</font></td>
                            <td style="padding:0px;padding-left:5px;">
                                <input id="tgl_pelaksanan_isi_diversi" name="tgl_pelaksanan_isi_diversi" value="<?php echo $act=='edit' && !empty($tgl_pelaksanan_isi_diversi) ? $this->templatehelper->convertKeTglDatepicker($tgl_pelaksanan_isi_diversi):date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                            </td>
                        </tr>                        
                        <?php } ?>

<!--                         <tr id='tr_no_perkara'>                            
    <td bgcolor='#5FB85C'><font color='#fff'>Nomor Perkara SPPA</font></td>
    <td style="padding:0px;padding-left:5px;">
        <input type="text" id="no_perkara" name="no_perkara" value="" class="autocomplete standard-input" style="width:320px;" readonly="true">
        <input type="button" id="cariPerkara" value="Cari" class="btn" style="padding: 5px 15px;">
        <input type="hidden" id="perkara_id" name="perkara_id" value="" class="standard-input" style="width:320px;" readonly="true">
    </td>
</tr>
<tr id='perkara_anak'>                            
    <td bgcolor='#5FB85C'><font color='#fff'>Info Perkara</td>
    <td><div id='info_perkara'></div></td>
</tr>                            
 -->
                        <tr>
                            <td colspan="2" style="background:white;" align="center">
                            <?php
                            
                            ?>
                            <input type="hidden" id="curr_date" name="curr_date" value="<?php echo $tgl_sekarang;?>">
                            <input type="hidden" id="enc" name="enc" value="<?php echo $id;?>">
                            <input type="hidden" id="act" name="act" value="<?php echo $act;?>">
                            <input type="button" id="kembali" value="Kembali" class="btn">
                            <?php
                            //if($this->authorization->isAuthorized('hakim_pn_edit',$AuthorizationForm)){
                            ?>
                            
                                <input type="submit" id="simpan" value="Simpan" class="btn">
                            <?php
                            //}
                            ?>
                        </td>
                        </tr>

				</tbody>
			</table>
		</form>
	</div>
    <?php //echo $previous;?>
<script type='text/javascript' src='<?php echo base_url();?>resources/js/jquery.autocomplete.js'></script>
<script type="text/javascript">
    var site = "<?php echo base_url();?>";
    var alur_perkara = 18;
    $(function(){
    $('.autocomplete').autocomplete({
        serviceUrl: site+'add_register_diversi/auto_complete',
        onSelect: function (suggestion) {
           $('#cariPerkara').click();
        }
    });
    });
</script>
<script type="text/javascript">

$('#tr_reg_penyidik').hide();
$('#tr_reg_pu').hide();
$('#tr_no_perkara').hide();
$('#perkara_anak').hide();
var pemohon_diversi = "<?php echo $pemohon_diversi;?>";
var act = "<?php echo $act;?>";
if(pemohon_diversi==1 && act=='edit'){
        $('#tr_reg_penyidik').show();
        $('#no_reg_penyidik').attr('readonly', false);
}else if(pemohon_diversi==2 && act=='edit'){
        $('#tr_reg_pu').show();
        $('#no_reg_penuntut').attr('readonly', false);    
}
$('#dimohonkan_oleh').change(function(e){
    var pemohon = $(this).find(":checked").val();
    if(pemohon==1){
        $('#tr_reg_penyidik').show();
        $('#no_reg_penyidik').attr('readonly', false);
        $('#tr_reg_pu').hide();
/*        $('#tr_no_perkara').hide();
        $('#perkara_anak').hide();*/
    }else if(pemohon==2){
        $('#tr_reg_penyidik').hide();
        $('#tr_reg_pu').show();
        $('#no_reg_penuntut').attr('readonly', false);
/*        $('#tr_no_perkara').hide();        
        $('#perkara_anak').hide();*/
    }else if(pemohon==3){
        $('#tr_reg_penyidik').hide();
        $('#tr_reg_pu').hide();
/*        $('#tr_no_perkara').show();
        $('#no_perkara').attr('readonly', false);        */
    }else{
        $('#tr_reg_penyidik').hide();
        $('#tr_reg_pu').hide();
/*        $('#tr_no_perkara').hide();                */
    }
});

/*$('#cariPerkara').click(function(e){
    openLoadingDialog()
    var no_perkara = $('#no_perkara').val()
    $.post('<?php echo base_url()?>add_register_diversi/get_info_perkara_sppa', {
        no_perkara:no_perkara,
    }, function(response){
        var json = jQuery.parseJSON(response);
        if(json.st==1){
            $('#perkara_anak').show();
            $('#perkara_id').val(json.perkara_id);
            $('#info_perkara').html(json.info_sppa);
        }else if(json.st==0){
            message_show(json.msg);
        }
        closeLoading()
    });

});*/

$('#generate').change(function(e){
    if($('#generate').val()==1){
        $('#no_urut_diversi').attr('readonly', true);
        $('#no_diversi').attr('readonly', true);
        get_nomor_diversi();
    }else{
        $('#no_urut_diversi').attr('readonly', false);
        $('#no_diversi').attr('readonly', false);
    }        
});

function get_nomor_diversi(){
    openLoadingDialog()
    var val = $('#generate').val()
    $.post('<?php echo base_url()?>add_register_diversi/get_nomor_perkara_diversi', {
        val:val,
    }, function(response){
        var json = jQuery.parseJSON(response);
        if(json.st==1){
            $('#no_urut_diversi').val(json.no_urut_diversi)
            $('#no_diversi').val(json.new_no_diversi)
        }
        closeLoading()
    });
}


$('#kembali').click(function(){
    window.open("<?php echo $previous;?>","_self");
});


$('#tgl_diterima_permohonan,#tgl_berita_acara,#tgl_kesepakatan_diversi,#tgl_pengiriman_penetapan_kpn,#tgl_penetapan_kpn,#tgl_pelaksanan_isi_diversi').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            beforeShowDay:$.datepicker.noWeekends,
            onSelect: function(dateText, inst) {
                var error = 0;
                var tmp = $(this).val().split("/");
                var tmp2 = $('#curr_date').val().split("/");
                if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
                    message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
                    error = 1
                }

                if(error==1){
                    message_error_show_parent(message);
                    $(this).css("background-color", "red");
                }else{
                    $(this).css("background-color", "#dedbdb");
                }
                error = 0;
            }
});


$('.datepicker').ValidateDateInput();
if(act=='edit'){
    $('#frm_add_diversi').SubmitHandling({
            refresh:'1',
            setRefresh:1,
            divRef:'#frm_add_diversi',
            clicked:1,
            btnClicked:'#kembali',
            whenStatus:1,
            isCKEdit:1,
            tdID:'pasal_sangkaan_dakwaan_text,isi_kesepakatan_diversi_text,amar_text',
            textID:'pasal_sangkaan_dakwaan,isi_kesepakatan_diversi,amar'
        });
}else{
    $('#frm_add_diversi').SubmitHandling({
            refresh:'1',
            setRefresh:1,
            divRef:'#frm_add_diversi',
            clicked:1,
            btnClicked:'#kembali',
            whenStatus:1,
        });    
}
</script>