<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>
<?php
if ($data_pn_asal!='') {
	if($data_pn_asal->num_rows>0){
	   foreach ($data_pn_asal->result() as $row) {
		   	$enc_pn_asal=base64_encode($this->encrypt->encode($row->IDPN));
		   	$id_pn_asal=$row->IDPN;
		   	$pn_asal_text=$row->NamaPN;
		   	$kode_satker_asal=$row->kode_satker;
		   	if ($row->IDPN=='') {
		   		$enc_pn_asal='0';
		   	}
	   }
	}
}
?>
<div class="centering" style="margin-top: 1%;z-index:-100">
     <div id='delegasi' style="width:700;border: 1px solid #ffffff;">
        <div class="detil" style="width:660px;padding: 12px;background-color: white;">
		<form id="frm_add_delegasi_keluar" style="background:white;margin:0;border:1px solid #f8f8f8;padding:10px" method="post" enctype="multipart/form-data" action="<?php echo base_url().'manage_delegasi_perkara/simpan_data_umum';?>">
			<table id="tableDetilPerkara" style="background:#f8f8f8;font-size:14px;;">
				<col width="40%">
				<col width="50%">
                <tr>
                    <td colspan="2" style="padding:4px;background:white;font-size:16px;color:#111;" align="center"><strong><?php echo $judul;?></strong></td>
                </tr>
				<tbody>
					<tr>
						<td>Wilayah Tujuan<font color="red">*</font></td>
						<td>
							<span class="custom-dropdown custom-dropdown--emerald" style='width:320px;'>
								<select style='width:320px;' name="pt-tujuan" id="pt-tujuan" onchange="" class="custom-dropdown__select custom-dropdown__select--white">
									<option id="main-pt-tujuan" value="-1" selected> Pilih Pengadilan Tinggi <?php echo $pengadilannama;?></option>
									<?php
										if($list_pt!=''){
											if($list_pt->num_rows>0){
								    			foreach ($list_pt->result() as $row) {
								    				echo '<option value="'.$row->id.'" ';
								    				echo ($row->id == $idpt) ? 'selected' : ''; echo ' >'.$row->nama.'</option>';
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<td>Pengadilan <?php echo $pengadilannama;?> tujuan<font color="red">*</font></td>
						<td>
							<span class="custom-dropdown custom-dropdown--emerald" style='width:320px;'>
								<select style='width:320px;' name="pn-tujuan" id="pn-tujuan" class="custom-dropdown__select custom-dropdown__select--white" disabled>
									<option id="main-pn-tujuan" value="-1"> Pilih Nama Pengadilan</option>
									<?php
										if($list_pn!=''){
											if($list_pn->num_rows>0){
								    			foreach ($list_pn->result() as $row) {
								    				if ($row->id!=$id_pn_asal){
									    				echo '<option class= "pros" id="'.$row->pt_id.'" value="'. base64_encode($this->encrypt->encode($row->id)).'" ';
									    				echo ($row->id == $this->encrypt->decode(base64_decode($enc_pn_tujuan))) ? 'selected' : '';
									    				echo ($row->id == $this->encrypt->decode(base64_decode($enc_pn_asal))) ? 'disabled' : '';
									    				echo ' >'.$row->nama.'</option>';
									    			}
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<td>Jenis Delegasi<font color="red">*</font></td>
						<td>
							<span class="custom-dropdown custom-dropdown--emerald" style='width:320px;'>
								<select style='width:320px;' name="jenis-delegasi" id="jenis-delegasi" class="custom-dropdown__select custom-dropdown__select--white">
									<option id="main-jenis-delegasi" value="-1" selected>-- Pilih Jenis Delegasi -- </option>
									<?php
										if($jenis_delegasi!=''){
											if($jenis_delegasi->num_rows>0){	
								    			foreach ($jenis_delegasi->result() as $row) {
								    				echo '<option value="'. $row->id.'" '; 
								    				echo ($row->id == $id_jenis_delegasi) ? 'selected' : '';
								    				echo ' >'.$row->jenis_delegasi.'</option>';
								    			}
								    		}
								    	}
									?>
								</select>
							</span>
						</td>
					</tr>

					<tr style="font-size:14px;background: #f8f8f8">
						<td >Nomor Perkara<font color="red">*</font></td>
						<td>
							<input type="text" id='nomor_perkara' style='width:320px;' class='autocomplete standard-input' name='nomor_perkara' value="<?php echo $nomor_perkara;?>" placeholder="contoh : 123" class="standard-input" maxlength="150">
							<input type="button" id = "cari_perkara" value="Cari" style="padding: 7px 0;color:white;background: #7f8c8d;border: 0 none;  border-radius: 0 0 0 0;width: 50px;" hidden>
						</td>
					</tr>
					<tr id="tgl_sidang_tr" hidden>
						<td>Tanggal Sidang<font color="red">*</font></td>
						<td>
							<input id="tgl_sidang" name="tgl_sidang" value="<?php echo $tgl_sidang;?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
				</tbody>
			</table>
			<table id="tableDetilPerkara" style="font-size:14px;background: #f8f8f8">
				<col width="40%">
				<col width="50%">
				<tbody>
					<tr id="tanggal_pendaftaran_perkara_tr" hidden>
						<td>Tanggal Pendaftaran Perkara<font color="red">*</font></td>
						<td>
							<input type="text" id='tanggal_pendaftaran_perkara' name='tanggal_pendaftaran_perkara' style="width:320px;" placeholder="" class="standard-input" value="<?php echo $tanggal_pendaftaran_perkara;?>" readonly="readonly">
						</td>
					</tr>
					<tr id="jenis_perkara_tr" hidden>
						<td>Klasifikasi Perkara</td>
						<td >
							<input type="text" id='jenis_perkara' name='jenis_perkara' style="width:320px;" placeholder="" class="standard-input" value="<?php echo $jenis_perkara;?>" readonly="readonly">
						</td>
					</tr>

					<tr id="tr_pihak1" class="tr_pihak1" hidden>
						<td id="td_pihak" class="td_pihak"  colspan="2" style="background:#fff;border:1pxsolid #ddd;padding:0px;padding-top:5px;">
							<?php
							if (!empty($para_pihak)) {
								echo $para_pihak;
							}
							?>
						</td>
					</tr>
					<tr id="tr_pihak2" hidden>
						<td id="td_pihak" class="td_pihak"  colspan="2" style="background:#fff;border:1pxsolid #ddd">
							<?php
							if (!empty($para_pihak)) {
								echo $para_pihak;
							}
							?>
						</td>
					</tr>
					<tr id="tr_pihak3" hidden>
						<td id="td_pihak" class="td_pihak"  colspan="2" style="background:#fff;border:1pxsolid #ddd">
							<?php
							if (!empty($para_pihak)) {
								echo $para_pihak;
							}
							?>
						</td>
					</tr>
					<tr id="tr_pihak4" hidden>
						<td id="td_pihak" class="td_pihak"  colspan="2" style="background:#fff;border:1pxsolid #ddd">
							<?php
							if (!empty($para_pihak)) {
								echo $para_pihak;
							}
							?>
						</td>
					</tr>
						<input type="hidden" id="para_pihak" style="width:320px" name="para_pihak" value="<?php echo $para_pihak;?>">
					<tr>
						<td colspan="2" style="height:3px;background: #f8f8f8">
					</tr>
					</tbody>
			</table>
			<table id="tableDetilPerkara" class="tr_adaperkara" style="font-size:14px">
				<col width="40%">
				<col width="50%">
				<tbody>
					<tr>
						<td>Tanggal Permohonan Delegasi<font color="red">*</font></td>
						<td>
							<input id="tgl_delegasi" name="tgl_delegasi" value="<?php echo $tgl_delegasi;?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
					<tr>
						<td>Tanggal Surat<font color="red">*</font></td>
						<td>
							<input id="tgl_surat" name="tgl_surat" value="<?php echo $tgl_surat;?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
					<tr>
						<td >Nomor Surat<font color="red">*</font></td>
						<td>
							<input type="text" id='nomor_surat' name='nomor_surat' value="<?php echo $nomor_surat;?>" class="standard-input" maxlength="50"  style="width:320px;">
						</td>
					</tr>

					<tr>
						<td>Tanggal Pengiriman Berkas<font color="red">*</font></td>
						<td>
							<input id="tgl_pengiriman" name="tgl_pengiriman" value="<?php echo $tgl_pengiriman;?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
					<tr>
						<td>Tanggal Resi Pengiriman<font color="red">*</font></td>
						<td><input id="tgl_resi" name="tgl_resi" value="<?php echo $tgl_resi;?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun"></td>
					</tr>
					<tr>
						<td>Nomor Resi Pengiriman<font color="red">*</font></td>
						<td>
							<input type="text" id='nomor_resi' placeholder="" name='nomor_resi' value="<?php echo $nomor_resi;?>" class="standard-input" maxlength="50"  style="width:320px;">
						</td>
					</tr>

					<tr>
						<td>Biaya</font></td>
						<td id="biayaketerangan">
							Rp. <input type="text" id='biaya' name='biaya' value="<?php echo $biaya;?>" class="standard-input" maxlength="50"  style="width:250px;"><br>
						</td>
					</tr>
					<tr>
						<td >Catatan </td>
						<td>
							<textarea id="catatan" name="catatan" value="<?php echo $catatan;?>" rows="4" cols="38" class="standard-input" style="width: 320px; height: 70px;resize: none;"></textarea>
						</td>
					</tr>
				</tbody>
			</table>
			<table id="tableDetilPerkara" style="font-size:14px;;">
				<col width="40%">
				<col width="50%">
				<tbody>
					<tr>
						<td colspan="2" style="background:white;" align="center">
							<input id="kembali" type="button" onClick='' value="Kembali" class="btn kembali">
							<input type="submit" id="simpan_delegasi_keluar" value="Simpan" class="btn">
							<?php
								if ($edit=='edit') {
								echo '<input type="submit" id="hapus" value="Hapus" class="btn btn-danger" onclick="return false;">';
								}
							?>
						</td>
					</tr>
							<input type="hidden" id="enc_pn_tujuan" name="enc_pn_tujuan" value="<?php  echo $enc_pn_tujuan; ?>">
							<input type="hidden" id="pn_tujuan_text" name="pn_tujuan_text" value="<?php  echo $pn_tujuan_text;?>">
							<input type="hidden" id="id_jenis_delegasi" name="id_jenis_delegasi" value="<?php echo $id_jenis_delegasi;?>">
							<input type="hidden" id="enc_perkara" name="enc_perkara" value="<?php echo $enc_perkara;?>">
							<input type="hidden" id="enc_alur" name="idalur" value="<?php echo $enc_alur;?>">
							<input type="hidden" id="enc_delegasi" name="enc_delegasi" value="<?php  echo $enc_delegasi; ?>">
							<input type="hidden" id="enc_pn_asal" name="enc_pn_asal" value="<?php  echo $enc_pn_asal; ?>">
							<input type="hidden" id="pn_asal_text" name="pn_asal_text" value="<?php  echo  $pn_asal_text; ?>">
							<input type="hidden" id="kode_satker_asal" name="kode_satker_asal" value="<?php  echo $kode_satker_asal; ?>">
							<input type="hidden" id="enc_alur_perkara" name="alur_perkara_id" value="<?php  echo $enc_alur_perkara; ?>">
							<input type="hidden" id="is_edit" name="is_edit" value="<?php echo $edit;?>">
							<input type="hidden" id="kembali_hapus" name="kembali_hapus" onClick="kembali_kelist()">
							
				</tbody>
			</table>
		</form>
	</div>
</div>
</div>
<script src="<?php echo base_url();?>resources/js/autoNumeric.js"></script>
<script type='text/javascript' src='<?php echo base_url();?>resources/js/jquery.autocomplete.js'></script>
  
<script type="text/javascript">
$('#download').click(function(){
	var enc_delegasi=$('#enc_delegasi').val();
	var enc_pn_asal=$('#enc_pn_asal').val();
	var enc_pn_tujuan=$('#enc_pn_tujuan').val();
	window.open("<?php echo base_url()?>download/downloadFile/"+enc_delegasi+'/'+enc_pn_asal+'/'+enc_pn_tujuan);
	closeLoading();
});

$('.td_pihak').on('click', 'input', function (event) {
    var nilai=$(this).val();
	    if ($(this).is(":checked")) {
	        var group = "input:checkbox[name='" + $(this).attr("name") + "']";
			$(group).prop("checked", false);
			$(this).prop("checked", true);
			$('#para_pihak').val(nilai);
	    }
});

	
$( document ).ready(function() {
	var site = "<?php echo base_url();?>";
	$('.autocomplete').autocomplete({
	    serviceUrl: site+'manage_delegasi_perkara/auto_complete',
	    onSelect: function (suggestion) {
	       $('#cari_perkara').click();
	    }
	});
	$('#biaya').ForceNumericOnly();
    $('#biaya').autoNumeric('init', {mDec: '0'});


	$('#simpan_delegasi_keluar').hide();
	$('#tr_pihak').hide();
	

	if ($('#is_edit').val()=='edit') {
		$('.tr_adaperkara').show();
		$('#simpan_delegasi_keluar').show();

	}else{
		$('.tr_adaperkara').hide();
	}

    $( function() {
        $('#tgl_surat').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 tmp = $(this).val().split("/");
			var tmp2 = $('#tanggal_pendaftaran_perkara').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 sebelum tanggal pendaftaran';
				message_error_show_parent(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
    	}
    	});
    });

    $( function() {
        $('#tgl_delegasi').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 tmp = $(this).val().split("/");
			var tmp2 = $('#tanggal_pendaftaran_perkara').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 sebelum tanggal pendaftaran';
				message_error_show_parent(message);
				$(this).css("background-color", "red");
			}else{
				$(this).css("background-color", "#dedbdb");
			}
    	}
    	});
    });

    $( function() {
        $('#tgl_pengiriman').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 tmp = $(this).val().split("/");
				var tmp2 = $('#tgl_delegasi').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 sebelum tanggal permohonan delegasi';
					message_error_show_parent(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
	    	}
        });      
    });
    $( function() {
        $('#tgl_resi').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 tmp = $(this).val().split("/");
				var tmp2 = $('#tgl_delegasi').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 sebelum tanggal permohonan delegasi';
					message_error_show_parent(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
	    	}
        });      
    });
	$( function() {
	        $('#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 tmp = $(this).val().split("/");
				var tmp2 = $('#tanggal_pendaftaran_perkara').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 sebelum tanggal pendaftaran';
					message_error_show_parent(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
	    	}
	    	});    
	    });

    $('input,select').not('#simpan_delegasi_keluar').keypress(function(event) { return event.keyCode != 13; });  
});

$(this).change(function(e) {
    var val = $('#'+e.target.id).val()	
	    if(e.target.id=='pt-tujuan'){
	    	$("#pn-tujuan").val('-1');
	    	var pt_tujuan = $('#pt-tujuan').val()
	    	$('#pn-tujuan').prop('disabled', false)
	    	$('.pros').show();
	    	$('.pros').not('#'+pt_tujuan).hide();
	    	$('#main-pt-tujuan').hide();
	    }
	    if(e.target.id=='pn-tujuan'){
	    	var enc_pn_tujuan = $("#pn-tujuan option:selected").val()
	    	var enc_pn_asal=$('#enc_pn_asal').val()
	    	var nama_pn_tujuan = $("#pn-tujuan option:selected").text()
	    	
	    	$('#enc_pn_tujuan').val(enc_pn_tujuan);
	    	$('#pn_tujuan_text').val(nama_pn_tujuan);
	    }
});

$("#jenis-delegasi").change(function() {
	var id_jenis_delegasi = $("#jenis-delegasi option:selected").val();
	$('#id_jenis_delegasi').val(id_jenis_delegasi);
	if (id_jenis_delegasi=='1') {
		$('#tgl_sidang_tr').show();
	}else{
		$('#tgl_sidang_tr').hide();
		$('#tgl_sidang').val('');
	}

});

$('#frm_add_delegasi_keluar').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#konten',
	clicked:1,
	btnClicked:'#kembali',
	whenStatus:1,
	actionName:'Simpan data'
});

$("#cari_perkara").click(function() {
	var val=$('#nomor_perkara').val();
	openLoadingDialog();
	$.post('<?php echo base_url()?>manage_delegasi_perkara/fetchDataPerkara', {
		val
	}, function(response){
		var json = jQuery.parseJSON(response);
		if(json.st==1){
			closeLoading();
			$('.tr_adaperkara').show();
			$('#tanggal_pendaftaran_perkara_tr').show();
			$('#jenis_perkara_tr').show();
			$('#enc_perkara').val(json.enc);
			$('#enc').val(json.enc);
			$('#alur_perkara_id').val(json.alur_perkara_id);
			$('.tr_chk_pihak').remove();
			$('.judul_tabel').remove();
			if (json.nama_pihak1!='') {
				$('#tr_pihak1').show();
				$('#td_pihak').append(json.nama_pihak1);
			}else{
				$('#tr_pihak1').hide();
			}
			$('.tr_pihak2').remove();
			if (json.nama_pihak2!='') {
				$('#tr_pihak2').show();
				$('#td_pihak').append(json.nama_pihak2);	
			}else{
				$('#tr_pihak2').hide();
			}
			$('.tr_pihak3').remove();
			if (json.nama_pihak3!='') {
				$('#tr_pihak3').show();
				$('#td_pihak').append(json.nama_pihak3);
			}else{
				$('#tr_pihak3').hide();
			}
			$('.tr_pihak4').remove();
			if (json.nama_pihak4!='') {
				$('#tr_pihak4').show();
				$('#td_pihak').append(json.nama_pihak4);
			}else{
				$('#tr_pihak4').hide();
			}

			$('#jenis_perkara').val(json.perkara_nama);
			$('#simpan_delegasi_keluar').show();
			$('#jenis_perkara').show();
			$('#tanggal_pendaftaran_perkara').val(json.tanggal_pendaftaran_perkara);
			$('#tgl_sidang').val(json.tgl_sidang);
			if (json.alur_perkara_id>110) {
				$('#biaya').prop('disabled', true);
				$('#biayaketerangan').append('');
			}else{
				$('#biaya').prop('disabled', false);
				$('#biayaketerangan').empty();
				$('#biayaketerangan').append('<font color="red">Untuk biaya silahkan lihat di web Pengadilan tujuan, atau hubungi Pengadilan Tujuan</font>');
			}
			
		}else if(json.st==0){
			$('#simpan_delegasi_keluar').hide();
			message_error_show_parent(json.msg);
			closeLoading();
			return
		}
	});
});

$('#kembali').click(function(event){
		location.reload();
});

$('#kembali_hapus').click(function(event){
		window.open('<?php echo base_url().'perkara_list_delegasi/type/'.base64_encode($this->encrypt->encode(2));?>','_self')
});


$('#hapus').ButtonClickHandling({
	refresh:'1',
	iddelegasi:$('#enc_delegasi').val(),
	setRefresh:0,
	divRef:'#konten',
	clicked:1,
	whenStatus:1,
	btnClicked:'#kembali_hapus',
	actions:'<?php echo base_url()?>manage_delegasi_perkara/validateDelete',
	formName:'#frm_add_delegasi_keluar',
	actionName:'Menghapus Data'
});

</script>
