<?php
    $alur_perkara_id		= $perkara['0']['alur_perkara_id'];
    $jurusita_sebelumnya 	= array();
	$tanggal_sebelumnya 	= ''; 
	$jurusita_sebelumnya_id	= '';
    $keterangan 			= '';
    $i						= 0;
    if ($action=='edit'){
    	if (count($data_jurusita_detail)<>0){						    
    		foreach ($data_jurusita_detail as $row=>$val){
    			if ($val['aktif']=='Y'){
					if ($tanggal_sebelumnya===$val['tanggal_penetapan'] || $tanggal_sebelumnya===''){
					    $jurusita_sebelumnya[]=$val['jurusita_id']; 
					    $jurusita_sebelumnya_id.=$val['id'];
					    if ($i<>(count($data_jurusita_detail)-1)){
							$jurusita_sebelumnya_id.=',';
						}
					    
					    if ($keterangan!=''){
					    	$keterangan.= $val['keterangan'].' - ';
					    }else{
					    	$keterangan = $val['keterangan'];
					    }
					}else{
					    break;
					}
		    	}
		    	$i++;
    		}
    	}
    }
?>
<div class="centering" style="width:600px;margin-top: 1%;z-index:-100">
    <div id='jurusita' style="border: 1px solid #ffffff;">
		<div class="detil" style="padding: 2px;background-color: white;">
			<div style="font-size:14px;">     
            <?php
				if ($action=='add'){
					?>
					<form id="frm_juru_sita" class="removeformbottomspace" method="post" action="<?php echo base_url().'addJuruSita_c/f_validate_input_add';?>">
					<?php
				}else{
					?>
					<form id="frm_juru_sita" class="removeformbottomspace" method="post" action="<?php echo base_url().'addJuruSita_c/f_validate_input_edit';?>">
					<?php
				}
				?>
			<table id="tableDetilPerkara" style="font-size:14px;">
            	<col width="38%">
                <col width="62%">
                <tbody>
					<tr><td style="padding:4px;background:white;font-size:16px;color:#111;" align="center" colspan="2"><strong><?php echo $namahalaman; ?></strong></h3></td></tr> 
	               	<tr>
                    	<td id="first-child">Nomor Perkara</td>
                        <td>
                        	<span>
							    <?php
								print_r($perkara['0']['nomor_perkara']);
							    ?>
							    <input type="hidden" name='enc' value='<?php echo $enc;?>'>
							</span>
						</td>
                    </tr>
                    <tr>
                    <?php
					    if (intval($perkara['0']['alur_perkara_id'])>100){
						echo "<td id='first-child'>Tanggal Pelimpahan</td>";
					    }else{
						echo "<td id='first-child'>Tanggal Pendaftaran</td>";
					    }
					?>
                    	<td>
                        	<span>
						    <?php
							echo $this->tanggalhelper->convertDayDate($perkara['0']['tanggal_pendaftaran']);
						    ?>
							</span>
                        </td>
                    </tr>
                    <tr>
                    	<td id="first-child">Tanggal Penetapan Hakim</td>
                        <td>
                        	<span>
						    <?php
							echo $this->tanggalhelper->convertDayDate($perkara_penetapan['0']['penetapan_majelis_hakim']);
						    ?>
							</span>
                        </td>
                    </tr>
                    <tr>
                    	<td id="first-child">Majelis Hakim/Hakim</td>
                        <td>
                        <?php
						    if (trim($perkara_penetapan['0']['majelis_hakim_text'])==''){
							echo 'Belum Penetapan Majelis Hakim';
						    }else{
							echo $perkara_penetapan['0']['majelis_hakim_text'];
						    }
						?>
                        </td>
                    </tr>
                    <tr>
                    	<td id="first-child">Tanggal Penunjukan Panitera Pengganti</td>
                        <td>
                        	<span>
						    <?php
							echo $this->tanggalhelper->convertDayDate($perkara_penetapan['0']['penetapan_panitera_pengganti']);
						    ?>
							</span>
                        </td>
                    </tr>
                    <tr>
                    	<td id="first-child">Panitera Pengganti</td>
                        <td>
                        <?php
							echo $perkara_penetapan['0']['panitera_pengganti_text'];
						?>
                        </td>
                    </tr>
				    <tr>
				    	<td class="divider" colspan="2">Penunjukan Jurusita</td>
				    </tr>
				    <tr>
                        <td id="first-child">Tanggal Penunjukan Jurusita</td>
                        <td>
                        	<?php
                        		$val='';
                        		if ($perkara_penetapan[0]['penetapan_jurusita']!=''){
                        			$val = $this->tanggalhelper->convertToInputDate($perkara_penetapan[0]['penetapan_jurusita']);
                        		}
                        	?>
                        	<input id="tgl_penunjukan_juru_sita" name="tgl_penunjukan_juru_sita" value="<?php echo $val; ?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                       	</td>
                    </tr>
				    <tr>
						<td id="first-child">Jurusita</td>
						<td>
					    	<span class="custom-dropdown custom-dropdown--emerald" style="width:250px">
							<?php
						    	$js = 'id="juru_sita1" class="nama_jurusita custom-dropdown__select custom-dropdown__select--white" style="width:250px"';
						    	if(isset($arr_jurusita[0])){
						    		echo form_dropdown('juru_sita1', $data_juru_sita, $arr_jurusita[0], $js);	
						    	}else{
						    		echo form_dropdown('juru_sita1', $data_juru_sita, '', $js);
						    	}
						    	 ?>
					    	</span>
						</td>
				    </tr>
				    <tr>
						<td id="first-child">Jurusita Pengganti 2</td>
						<td>
					    	<span class="custom-dropdown custom-dropdown--emerald" style="width:250px">
							<?php
						    	$js = 'id="juru_sita2" class="nama_jurusita custom-dropdown__select custom-dropdown__select--white" style="width:250px"';
						    	if (isset($arr_jurusita[1])){
						    		echo form_dropdown('juru_sita2', $data_juru_sita, $arr_jurusita[1], $js);
						    	}else{
						    		echo form_dropdown('juru_sita2', $data_juru_sita, '', $js);
						    	}
						    	 ?>
					    	</span>
						</td>
				    </tr>
				    <tr>
						<td id="first-child">Jurusita Pengganti 3</td>
						<td>
					    	<span class="custom-dropdown custom-dropdown--emerald" style="width:250px">
							<?php
						    	$js = 'id="juru_sita3" class="nama_jurusita custom-dropdown__select custom-dropdown__select--white" style="width:250px"';
						    	if (isset($arr_jurusita[2])){
						    		echo form_dropdown('juru_sita3', $data_juru_sita, $arr_jurusita[2], $js);	
						    	}else{
						    		echo form_dropdown('juru_sita3', $data_juru_sita, '', $js);
						    	}

						    	 ?>
					    	</span>
						</td>
				    </tr>
                    <tr>
                    	<td id="first-child">Keterangan</td>
                        <td>
						<?php
							$js="{datatype: 'text', maxLength: 500, allowedChars: '', lettersCase: '', enterTab: false, enterSubmit: false, autoTab: true, selectOnFocus: true, watermark: '', watermarkClass: 'scFormObjectOddWm', maskChars: '(){}[].,;:-+/ '}
							cols='100' rows='2' id='keterangan' name='keterangan' style='width: 100%; height: 100px; resize: none; font-size:13px;' maxlength='500'";
							echo form_textarea('keterangan', $keterangan, $js); ?>
						</td>
                    </tr>
                    <tr>
                    	<td colspan="2" class="buttongroup">
                        	<input type="button" id='close_form_add_juru_sita' value="Kembali" class="btn">
                        	<?php
                        	if(!empty($perkara_penetapan[0]['penetapan_jurusita'])){
                        		echo '<input type="submit" id="hapus" value="Hapus" class="btn btn-danger" onclick="return false;">';
                            }
                            ?>
                            <input type="submit" id="simpan" value="Simpan" class="btn">
                            <input type="hidden" id="curr_date" value="<?php echo $current_date;?>">
                            <input type="hidden" name="jurusita_sebelumnya_id" value="<?php echo $jurusita_sebelumnya_id;?>">
							<input type="hidden" name="namahalaman" value="<?php echo $namahalaman;?>">
                        </td>
                    </tr>
                    <input type="hidden" id="refresh" class='detil_perkara_refresh' value="0">
            	</tbody>
         	</table>
     	</form>
        </div>
    </div>
</div>
</div>

<script type="text/javascript">

$('.nama_jurusita').change(function(){
	if ($(this).val()!='0'){
		switch($(this).attr('id')) {
			case 'juru_sita1':
				if ($(this).val()===$('#juru_sita2').val() || $(this).val()===$('#juru_sita3').val()) {
					message_error_show('Tidak bisa memilih juru sita yang sama !');
					$(this).val('0');
				}
			break;
			case 'juru_sita2':
				if ($(this).val()==$('#juru_sita1').val() || $(this).val()==$('#juru_sita3').val()) {
					message_error_show('Tidak bisa memilih juru sita yang sama !');
					$(this).val('0');
				}
			break;
			case 'juru_sita3':
				if ($(this).val()==$('#juru_sita2').val() || $(this).val()==$('#juru_sita1').val()) {
					message_error_show('Tidak bisa memilih juru sita yang sama !');
					$(this).val('0');
				}
			break;
		}
	}
});

$('#frm_juru_sita').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#close_form_add_juru_sita',
	whenStatus:1,
	next_step:1
    });
$('#hapus').ButtonClickHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#close_form_add_juru_sita',
	whenStatus:1,
	actions:'<?php echo base_url("delete_jurusita")."/".$enc;?>',
	formName:'#frm_juru_sita',
	actionName:'Hapus Penunjukan'
});

<?php 
if($this->session->userdata('jenis_pengadilan')==1){
?>
    $('#close_form_add_juru_sita').click(function(){
        window.open("<?php echo base_url('perkara_detil/'.$enc.'/2');?>","_self");    
    });
<?php
}else if($this->session->userdata('jenis_pengadilan')==2){
?>
    $('#close_form_add_juru_sita').click(function(){
        window.open("<?php echo base_url('perkara_detil_mil/'.$enc.'/2');?>","_self");    
    });    
<?php
}else if($this->session->userdata('jenis_pengadilan')==3){
?>
    $('#close_form_add_juru_sita').click(function(){
        window.open("<?php echo base_url('perkara_detil_tun/'.$enc.'/2');?>","_self");    
    });
<?php
}else if($this->session->userdata('jenis_pengadilan')==4){
?>
    $('#close_form_add_juru_sita').click(function(){
        window.open("<?php echo base_url('perkara_detil_agama/'.$enc.'/2');?>","_self");    
    });        
<?php
}else{
?>
    $('#close_form_add_juru_sita').closingFormWin();
<?php
}
?>     
$('#tgl_penunjukan_juru_sita').datepicker({
		beforeShowDay: $.datepicker.noWeekends,
        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(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
			error = 0;
    	}
  	});
$('.datepicker').ValidateDateInput();
    
</script>
