<?php
function parse_day_to_year($vonis){
	$result = array();
	$month = (int)($vonis/30);
	$year = (int) ($month/12);
	$month = (int) ($month%12);
	$total = (int)($year*12*30+$month*30);
	$day = intval($vonis-$total);
	$result['year'] = $year;
	$result['month'] = $month;
	$result['day'] = $day;
	return $result;
}
?>
<script src="<?php echo base_url();?>resources/js/autoNumeric.js"></script>
<div class="centering" style="width:1024px;margin-top: 1%;">
	<div id='pihak_pilih' style="border: 1px solid #ffffff;">
		<div class="detil" style="padding: 2px;background-color: white;">
			<?php
			if($error==TRUE){
				if($error_message=='404'){
					show_404();
					exit();
				}else{
					echo "<h1>".$error_message."</h1>";
				}
				echo '<input type="button" id="close_form_putusan_diversi" value="Kembali" class="btn">';
			}
			?>
			<form id="frm_putusan_diversi" style="background:white;margin:0;" method="post" action="<?php echo base_url().'managePutusanAkhir/validateInputDiversi';?>">
				<table id='infoPerkara' style="font-size:14px;">
					<col width="15%">
					<col width="85%">
					<tbody>
						<tr>
							<td colspan="2" style="background-color: white;font-size:18px;text-align:center"><?php echo $namahalaman ?></td>						
						</tr>
						<tr>
							<td id="first-child">Tanggal Penetapan<font color="red">*</font></td>						
							<td>
								<input id="tgl_putusan" name="tgl_putusan" value="<?php echo (!empty($tanggal_putusan)? $tanggal_putusan:$sidang_terakhir);?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun" required>
							</td>
						</tr>						
						<tr>
							<td id="first-child" style="vertical-align:top;">Amar Penetapan<font color="red">*</font></td>						
							<td style="background:white;" id="amar_text">
								<?php echo $this->ckeditor->editor("amar",$amar);?>
							</td>
						</tr>						
						<tr>
							<td id="first-child">Keterangan</td>
							<td>
								<textarea class="standard-input" id="keterangan" name ="keterangan" style="width: 827px; height: 70px;resize: none;"><?php echo (!empty($keterangan) ? $keterangan : '');?></textarea>
							</td>
							
							<input type="hidden" id="curr_date" value="<?php echo $current_date;?>">
							<input type="hidden" id="enc" name="enc" value="<?php echo $enc;?>">
							<input type="hidden" id="enc_alur" name="enc_alur" value="<?php echo $enc_alur;?>">
							<input type="hidden" id="act" name="act" value="<?php echo $act;?>">
							<input type="hidden" id="tgl_lap_pkbapas" name="tgl_lap_pkbapas" value="<?php echo $detail_diversi->tgl_lap_pembimbing_masyarakat;?>">
							<input type="hidden" id="namahalaman" name="namahalaman" value="<?php echo $namahalaman;?>">
						</tr>
						<tr>
							<td colspan="2" style="background:white;border:0px;" align="center">
								<input type="button" id='close_form_putusan_diversi' value="Kembali" class="btn">
								<?php
								$act = $this->encrypt->decode(base64_decode($act));
								if($act=="diversi"){
									echo '<input type="submit" id="hapus" value="Hapus" class="btn btn-danger" onclick="return false;">';
								}
								?>
								<input type="submit" id="simpan" value="Simpan" class="btn">
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
// $('#close_form_putusan_diversi').closingFormWin();
$('#close_form_putusan_diversi').click(function(){
    window.open("<?php echo base_url('perkara_detil/'.$enc.'/10');?>","_self");    
});

$('#frm_putusan_diversi').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#close_form_putusan_diversi',
	whenStatus:1,
	isCKEdit:1,
	tdID:'amar_text',
	textID:'amar',
	next_step:1
});
$('#hapus').ButtonClickHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#close_form_putusan_diversi',
	whenStatus:1,
	actions:'<?php echo base_url()?>managePutusanAkhir/validateDelete',
	formName:'#frm_putusan_diversi',
	actionName:'Hapus Data'
});

$("#tgl_putusan").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("/");
		var tmp3 = $("#tgl_lap_pkbapas").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();
			/*$('#tgl_putusan').val('');*/
			error = 1
		}
		if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() < new Date(tmp3[0]+"-"+tmp3[1]+"-"+tmp3[2]+"T00:00:00").getTime())){
			message = "Tidak Dapat Memilih Kurang Dari Tanggal Laporan Pembimbing Kemasyarakatan ";
			/*$('#tgl_putusan').val('');*/
			error = 1
		}
		if(error==1){
			message_error_show(message);
			$(this).css("background-color", "red");
		}else{
			$(this).css("background-color", "#dedbdb");
		}
	}
});


$('.datepicker').ValidateDateInput();
function refreshDataPutusan(){
	openLoadingDialog();
	$("#popup_form").remove();
	popup_form('<?php echo base_url("add_putusan_akhir/".$enc."/diversi");?>')
	$("#popup_form").hide();
	closeLoading()
}
function doDelete(){
	var values = $('form').serializeArray();
	values = jQuery.param(values);
	var url = "<?php echo base_url('managePutusanAkhir/doDelete/');?>";
	$.post(url,values, function(json){
		closeLoading()
		if(json.st==1){
			message_show(json.msg);
		}else{
			message_error_show_parent(json.msg);
		}
	},'json');
}

$(document).ready(function() {
    $('#template_amar').change(function(){
    	$.post( "<?php echo base_url('managePutusanAkhir/getAmar');?>", { selected: $(this).val(), enc: "<?php echo $enc;?>" })
		.done(function( data ) {
		   	CKEDITOR.instances['amar'].setData(data); 
		});
    })

});
</script>