<?php
if ((isset($detjsidang)) and (!empty($detjsidang)) and ($detjsidang!='')){
	foreach ($detjsidang as $row){
?>
<script src="<?php echo base_url();?>resources/js/jquery.ui.timepicker.js"></script>
<div class="centering" style="width:790px;margin-top: 1%;">
<div id='tunda_jadwal_sidang' style="border: 1px solid #ffffff;">
	<div class="detil" style="padding: 2px;background-color: white;">
		<form id="frm_tunda_jadwal_sidang" style="background:white;margin:0;" method="post" action="<?php echo base_url().'jadwal_sidang_c/validateTunda';?>">
			<table id="tableDetilPerkara" style="font-size:14px;">
					<tr>
						<td colspan="2" style="padding:4px;background:white;font-size:16px;color:#111;" align="center"><strong><?php echo $namahalaman; ?></strong></td>
					</tr>
					<tr>
						<td colspan="2" class="divider">Informasi Jadwal Sidang Sebelumnya</td>
					</tr>
				<col width="20%">
				<col width="80%">
				<tbody>
					<tr>
						<td>Tanggal</td>
						<td><?php 
							echo $this->tanggalhelper->convertDayDate($row->tanggal_sidang);
							echo "<input type='hidden' name='tglsidangsblm' id='tglsidangsblm' value='$row->tanggal_sidang'>";
							?>
						</td>
					</tr>
					<tr>
						<td>Jam Pelaksanaan<span style="color:red">*</span></td>
						<td>
							<input id="jammulaisblm" name="jammulaisblm" class="timepicker" maxlength="4" placeholder="HH:mm" value="<?php echo substr($row->jam_sidang,0,5); ?>" required>&nbsp;s/d&nbsp;
							<input id='jamselesaisblm' name='jamselesaisblm' class='timepicker' maxlength='4' placeholder='HH:mm' value="<?php echo substr($row->sampai_jam,0,5); ?>" required>
						</td>
					</tr>
					<tr>
						<td>Agenda<span style="color:red">*</span></td>
						<td style="padding:0px;padding-left:5px;">
						<textarea name="agendasblm" id="agendasblm" maxlength="500" class="standard-input" style="margin: 0px; width: 610px; height: 80px;resize: none;" required><?php echo "$row->agenda";?></textarea>
						</td>
					</tr>
					<tr>
						<td>Dihadiri Oleh</td>
						<td>
							<span class="custom-dropdown custom-dropdown--emerald" style="width:200px">
							<select name="dihadiri_olehsblm" id="dihadiri_olehsblm" style="width:200px" class="custom-dropdown__select custom-dropdown__select--white">
							<option value="1" <?php echo ($row->dihadiri_oleh==1)? 'selected':''; ?> >Semua Pihak</option>
							<option value="2" <?php echo ($row->dihadiri_oleh==2)? 'selected':''; ?>><?php echo $this->nativesession->getStatusPihak(10,$id_alur_perkara,1);?> Saja</option>
							<?php 
							if($id_alur_perkara<100 OR $id_alur_perkara==119){
								echo '<option value="3"';
								echo ($row->dihadiri_oleh==3)? 'selected':'';
								echo '>';echo $this->nativesession->getStatusPihak(10,$id_alur_perkara,2); echo ' Saja</option>';
								$result = $this->db->query("SELECT id FROM perkara_pihak3 WHERE perkara_id=".$row->perkara_id);
								if($result->num_rows>0){
									echo '<option value="5"';
									echo ($row->dihadiri_oleh==5)? 'selected':''; 
									echo '>Pihak Intervensi Saja</option>';

									echo '<option value="7"';
									echo ($row->dihadiri_oleh==7)? 'selected':''; 
									echo '>Penggugat dan Intervensi</option>';

									echo '<option value="8"';
									echo ($row->dihadiri_oleh==8)? 'selected':''; 
									echo '>Tergugat dan Intervensi</option>';

									echo '<option value="9"';
									echo ($row->dihadiri_oleh==9)? 'selected':''; 
									echo '>Penggugat dan Tergugat</option>';
							 	}
							}
							$arr_alur = array(111,112,113,115,116,117,118);
							if(in_array($id_alur_perkara, $arr_alur)){ 
								echo '<option value="6"';
								echo ($row->dihadiri_oleh==6)? 'selected':''; 
								echo '>PU Tidak Bisa Menghadirkan Terdakwa</option>';
							}	
							?>
							<option value="4" <?php echo ($row->dihadiri_oleh==4)? 'selected':''; ?>>Para Pihak Tidak Hadir</option>
							</select>
							</span>
						</td>
					</tr>
					<tr>
						<td>Sifat Sidang</td>
						<td>
							<input type="radio" name="form_pelaksanaan" value="Y" <?php echo ($row->sifat_sidang=='Y') ? "checked" : '';?> ><strong>Terbuka</strong>
							<input type="radio" name="form_pelaksanaan" value="T" <?php echo ($row->sifat_sidang=='T') ? "checked" : '';?> ><strong>Tertutup</strong>
						</td>
					</tr>
					<?php if ($id_alur_perkara!=9){ ?>
					<tr>
						<td>Sidang Keliling</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style="width:80px">
							<select name="sidang_kelilingsblm" id="sidang_kelilingsblm" style="width:80px" class="custom-dropdown__select custom-dropdown__select--white">
							<option value="T" <?php echo ($row->sidang_keliling=='T')? 'selected' :'' ?>>Tidak</option>
							<?php if ($id_alur_perkara!=119){ ?>
							<option value="Y" <?php echo ($row->sidang_keliling=='Y')? 'selected' :'' ?>>Ya</option>
							<?php } ?>
							</select>
							</span>
						</td>
					</tr>
					<?php } ?>
					<tr class="row_ruangansblm">
						<td>Ruangan</td>
								<td style="background:white;">
								<?php
								if ($ruangansidang!=''){
									?>
									<span class="custom-dropdown custom-dropdown--emerald" style="width:200px">
										<select name="ruangansblm" id="ruangansblm" style="width:200px" class="custom-dropdown__select custom-dropdown__select--white">
											<?php
											foreach ($ruangansidang as $rowrs){
												$id=$rowrs->id;
												$ruangan=$rowrs->nama;
												$data_ruangan=$id."|".$ruangan;
												if ($rowrs->id==$row->ruangan_id){
													echo "<option selected value='$data_ruangan' >$rowrs->nama</option>";
												}
												else{
													echo "<option value='$data_ruangan'>$rowrs->nama</option>";
												}
												
											}
											?>
										</select>
									</span>
									<?php
									}else{echo "<span style='color:red;font-weight:bold'>Referensi Ruangan Sidang Belum Terisi</span>";}
									?>
								</td>
					</tr>			
					<tr>
						<td>Alasan Penundaan<span style="color:red">*</span></td>
						<td style="padding:0px;padding-left:5px;">
							<textarea name="alasan_tunda" id="alasan_tunda" maxlength="500" class="standard-input" style="margin: 0px; width: 610px; height: 80px;resize: none;" placeholder="Uraikan Alasan Penundaan Sidang Sebelumnya" required><?php echo (!empty($row->alasan_ditunda) ? $row->alasan_ditunda : ''); ?></textarea>
						</td>
					</tr>
					<tr>
						<td valign="top" style="vertical-align:top">Keterangan</td>
						<td style="padding:0px;padding-left:5px;">
						<textarea name="keterangan" id="keterangan" maxlength="500" class="standard-input" style="margin: 0px; width: 610px; height: 80px;resize: none;" placeholder="Tuliskan keterangan persidangan"></textarea>
						</td>
						<input type="hidden" id='curr_date' value="<?php echo $curr_date;?>">
					</tr>

					<tr>
						<td colspan="2" class="divider">Jadwal Sidang Berikutnya</td>
					</tr>

					<tr>
						<td>Tanggal<span style="color:red">*</span></td>
						<td><input type="text" id="tgl_sidang" name="tgl_sidang" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun" required></td>
					</tr>
					<tr>
						<td>Jam Pelaksanaan<span style="color:red">*</span></td>
						<td>
                       		<input id="jammulai" name="jammulai" class="timepicker" maxlength="4" placeholder="HH:mm" required>
						</td>
					</tr>
					<tr>
						<td>Agenda<span style="color:red">*</span></td>
						<td style="padding:0px;padding-left:5px;">
							<textarea name="agenda" id="agenda" maxlength="500" class="standard-input" style="margin: 0px; width: 610px; height: 80px;resize: none;" placeholder="Tuliskan agenda sidang dengan lengkap dan jelas" required></textarea>
						</td>
					</tr>
					<?php if ($id_alur_perkara!=9){ ?>
					<tr>
						<td>Sidang Keliling</td>
						<td>
							<span class="custom-dropdown custom-dropdown--emerald" style="width:70px">
								<select name="sidang_keliling" id="sidang_keliling" style="width:70px" class="custom-dropdown__select custom-dropdown__select--white">
									<option value="T">Tidak</option>
									<option value="Y">Ya</option>
								</select>
							</span>
						</td>
					</tr>
					<?php } ?>
					<tr class="row_ruangan">
						<td valign="top" style="vertical-align:top">Ruangan</td>
						<td style="">
								<?php
								if ($ruangansidang!=''){
									?>
							<span class="custom-dropdown custom-dropdown--emerald" style="width:170px">
								<select name="ruangan" id="ruangan" style="width:170px"  class="custom-dropdown__select custom-dropdown__select--white">
									<option>Ditentukan Kemudian</option>
									<?php
									foreach ($ruangansidang as $rowrs){ 
										$id=$rowrs->id;
										$ruangan=$rowrs->nama;
										$data_ruangan=$id."|".$ruangan;
										echo "<option value='$data_ruangan'>$rowrs->nama</option>";
									}
									?>
								</select>
							</span>
									<?php
									}else{echo "<span style='color:red;font-weight:bold'>Referensi Ruangan Sidang Belum Terisi</span>";}
									?>
						</td>
					</tr>					
					<tr>
						<td colspan="2" class="buttongroup">
							<input type="hidden" name="encjadwalsidang" id="encjadwalsidang" value="<?php echo base64_encode($this->encrypt->encode($row->id)); ?>">
							<input type="hidden" name="enc" id="enc" value="<?php echo base64_encode($this->encrypt->encode($row->perkara_id)); ?>">
							<input type="hidden" name="namahalaman" id="namahalaman" value="<?php echo $namahalaman; ?>">
							<input type="button" id='close_tunda_jadwal_sidang' value="Kembali" class="btn">
							<input type="submit" id="simpan" value="Simpan" class="btn">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
</div>
<?php
}
}
?>
<script type="text/javascript">
<?php if($row->sidang_keliling=='Y'){ ?>
$("tr.row_ruangansblm").hide();
<?php } ?>

$("#sidang_keliling").change(function(){
    if($(this).val()=="T")
    $("tr.row_ruangan").show();
    else $("tr.row_ruangan").hide();
});

$("#sidang_kelilingsblm").change(function(){
    if($(this).val()=="T")
    $("tr.row_ruangansblm").show();
    else $("tr.row_ruangansblm").hide();
});

$('#jammulai').timepicker({});

$('#jammulaisblm').timepicker({
    onSelect: function(dateText, inst){
	var jammulai=$('#jammulaisblm').val()
	var jamselesai=$('#jamselesaisblm').val()
        if (jamselesai <= jammulai) {
        	alert ("Jam Selesai Sidang Tidak Boleh Sama Atau Kurang Dari Jam Mulai Sidang");
		}
    }
});

$('#jamselesaisblm').timepicker({
    onSelect: function(dateText, inst){
	var jammulai=$('#jammulaisblm').val()
	var jamselesai=$('#jamselesaisblm').val()
        if (jamselesai <= jammulai) {
        	alert ("Jam Selesai Sidang Tidak Boleh Sama Atau Kurang Dari Jam Mulai Sidang");
		}
    }
});

$('#frm_tunda_jadwal_sidang').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#close_tunda_jadwal_sidang',
	whenStatus:1,
	next_step:1
});
<?php 
if($this->session->userdata('jenis_pengadilan')==1){
?>
    $('#close_tunda_jadwal_sidang').click(function(){
        window.open("<?php echo base_url('perkara_detil/'.$enc.'/4');?>","_self");    
    });
<?php
}else if($this->session->userdata('jenis_pengadilan')==2){
?>
    $('#close_tunda_jadwal_sidang').click(function(){
        window.open("<?php echo base_url('perkara_detil_mil/'.$enc.'/4');?>","_self");    
    });    
<?php
}else if($this->session->userdata('jenis_pengadilan')==3){
?>
    $('#close_tunda_jadwal_sidang').click(function(){
        window.open("<?php echo base_url('perkara_detil_tun/'.$enc.'/4');?>","_self");    
    });
<?php
}else if($this->session->userdata('jenis_pengadilan')==4){
?>
    $('#close_tunda_jadwal_sidang').click(function(){
        window.open("<?php echo base_url('perkara_detil_agama/'.$enc.'/4');?>","_self");    
    });        
<?php
}else{
?>
    $('#close_tunda_jadwal_sidang').closingFormWin();
<?php
}
?> 
// $('#close_tunda_jadwal_sidang').closingFormWin();
$('#tgl_sidang').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 tanggal_sidang = $('#tglsidangsblm').val();
				var tmp3 = tanggal_sidang.split("-");
				// fix zeno
				var jammulaisblm = $('#jammulaisblm').val();
				var jammulai = $('#jammulai').val();
				if (!jammulai){
					jammulai = "00:00";
				}
				var tunda = new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T"+jammulai+":00").getTime();
				var sidang = new Date(tanggal_sidang+"T"+jammulaisblm+":00").getTime();
				if(tunda <= sidang){
					message = 'Tidak Dapat Memilih Tanggal Sebelum Atau Tepat Pada Tanggal Sidang Sebelumnya';
					error = 1
				}
				// end fix

				dob = new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00");
				var tglDaftar = new Date($('#tglPendaftaran').val());
				var age = Math.floor((tglDaftar-dob) / (365.25 * 24 * 60 * 60 * 1000));
				if(age >1){
					message = 'Tanggal Tidak Valid. Silahkan Periksa Kembali';
					error = 1
				}
				if(error==1){
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
				error = 0;
        	}
        	
      	});
$('#tgl_sidang').ValidateDateInput();
</script>