<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.simplePagination.js"></script>
<div id="popup_pihak_list" class="centering" style="width:98%;margin-top: 1%;">
	<div style="border: 1px solid #ffffff;">
	<div class="detil" style="padding: 2px;background-color: white;">
	<div style="text-align:center;background-color:white;color:#5fb85c;border:2px solid #fff;margin:;font-size:20px;height:35px;"><span style="position: relative;top: 15%;transform: translateY(-15%);">REFERENSI PIHAK BERPERKARA</span></div>
	<hr class="thick-line" style="clear:both;">
	<div id="left">
		<?php
		$attributes = array('id' => 'form_search_pihak');
		echo form_open(base_url().'pihak_list/searchPage',$attributes);
		?>
		<span class="custom-dropdown custom-dropdown--emerald" style='width:130px;'>
			<select name="search_field" id="search_field" style='width:130px;' class="custom-dropdown__select custom-dropdown__select--white">
					<option value="0">Semua Kolom</option>
					<option value="1">Nama</option>
					<option value="2">Alamat</option>
					<option value="3">Tempat Lahir</option>
					<option value="4">Tanggal Lahir</option>
					<option value="5">Pekerjaan</option>
			</select>
		</span>
		<?php
		$attributes = array('name' => 'keyword_pihak', 'id' => 'search-box', 'type' => 'text','size' => '50','placeholder'=>"  Ketik kata kunci  ");
		echo form_input($attributes);
		$data = array(
			'enc' => "enc"
		);
		echo form_hidden($data);
		echo "<span>  </span>";
		$attributes = array('value' => 'Search', 'class' => 'btn', 'id' => 'search-btn1', 'type' => 'submit');
		echo form_submit($attributes);
		echo form_close('');
		?>
	</div>
	<div id="right" style="margin-top: 0px;margin-right: 6px;"><input type="button" id='addPihak' value="Tambah" class="btn">&nbsp;<input type="button" id='close_form_2nd' value="Kembali" class="del_btn"></div>
	<div id="pages" >
    	<div id="selector" style="padding: 4px 5px 5px 0;"></div>
    </div>
	<div class="cssTable">
		<table id="tablePerkaraAll">
			<col  width="5%" />
			<col  width="5%" />
			<col  width="3%" />
			<col  width="23%" />
			<col  width="25%" />
			<col  width="18%" />
			<col  width="10%" />
			<col  width="11%" />
        	<tbody>
				<tr>
					<td></td>
					<td></td>
					<td>No</td>
					<td onclick="sorting(1)">Nama</td>
					<td onclick="sorting(2)">Alamat</td>
					<td onclick="sorting(7)">Tempat/Tanggal Lahir</td>
					<td onclick="sorting(5)">Jenis Kelamin</td>
					<td onclick="sorting(6)">Pekerjaan</td>
				</tr>
				<?php
				if($pihak!=''){
					$i=$counter+1;
					if($pihak->num_rows>0){
						foreach ($pihak->result() as $row) {
							if($row->jenis_kelamin=='L'){
								$sex = 'Laki-Laki';
							}elseif ($row->jenis_kelamin=='P') {
								$sex = 'Perempuan';
							}else{
								$sex='';
							}
							$ttl = $row->tempat_lahir;
							if(!empty($row->tanggal_lahir)){
								$ttl .= ', ';
								$ttl .= $this->tanggalhelper->convertDate($row->tanggal_lahir);
							}							
							echo "<tr>";
							echo "<td style='text-align:center;'><a href='#' onClick='pilih(\"".base64_encode($this->encrypt->encode($row->id))."\")'>[Pilih]</a></td>";
							echo "<td style='text-align:center;'><a href='#' onClick='edit(\"".base64_encode($this->encrypt->encode($row->id))."\")'>[Edit]</a></td>";
							echo "<td>".$i."</td>";
							echo "<td style='text-overflow: ellipsis;white-space: nowrap;overflow: hidden;'>".$row->nama."</td>";
							echo "<td>".$row->alamat."</td>";
							echo "<td>".$ttl."</td>";
							echo "<td>".$sex."</td>";
							echo "<td>".$row->pekerjaan."</td>";
							echo "</tr>";
							$i++;
						}
					}
				}
				?>
			</tbody>
		</table>
	</div>
	<div id="pages_bottom" style="width:100%;padding-left:5px;padding-top:5px;">
    	<div id="selector_bottom"></div>
	</div>
	<div style="margin:bottom:5px;"></div>
</div>
</div>
</div>


<div id="popup_pihak" class="popup">
	<div style="margin: 0 auto;top: 50%;margin-top: 1%;margin-bottom: 25px;">

		<div style="border: 1px solid #ffffff;width: 35%;margin: 0 auto;">
		<div class="detil" style="padding: 2px;background-color: white;">
			<form id="frm_ref_pihak" style="background:white;margin:0;" method="post" action="<?php echo base_url().'pihak_list/validateInput';?>">
				<table id="tableDetilPerkara" class="pihak_list" style="font-size:14px;">
				<col width="40%">
				<col width="60%">
					<tbody>
						<tr>
							<td colspan="2" style='text-align:center;background:white;border:0px;font-size: 20px;color: #648C03;'>TAMBAH REFERENSI DATA PIHAK</td>
						</tr>
						<?php
						$idalurperkara = 0;
						if($idalurperkara<100){
						?>
							<tr>
								<td>Jenis Pihak <font color="red">*</font></td>
								<td style="padding:0px;padding-left:5px;">
									<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
										<select name="pihak_jenis_pihak" id="pihak_jenis_pihak" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
											<?php
											foreach ($list_jenis_pihak->result() as $row) {
												echo '<option value="'.$row->id.'" selected>'.$row->nama.'</option>';
											}
											?>
										</select>
									</span>
									<input type="hidden" id="act_frm_ref_pihak" name="act" value="">
								</td>
							</tr>
						<?php	
						}
						?>
						<tr>
							<td>Nama <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pihak_fullname' name='pihak_fullname' value="" class="standard-input" maxlength="500">
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Tempat Lahir <?php echo ($pihak_ke==1 || ($this->session->userdata('jenis_pengadilan')!=3))? '<font color="red">*</font>':'';?></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pihak_tempat_lahir' name='pihak_tempat_lahir' value="" class="standard-input" maxlength="50">
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Tanggal Lahir <?php echo ($pihak_ke==1 || ($this->session->userdata('jenis_pengadilan')!=3))? '<font color="red">*</font>':'';?></td>
							<td style="padding:0px;padding-left:5px;">
								<input id="pihak_tgl_lahir" name="pihak_tgl_lahir" value="<?php echo date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Umur <?php echo ($pihak_ke==1 || ($this->session->userdata('jenis_pengadilan')!=3))? '<font color="red">*</font>':'';?></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pihak_umur' name='pihak_umur' value="" class="standard-input" maxlength="2" style="width:50px;">
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Jenis Identitas</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_jenis_identitas" id="pihak_jenis_identitas" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="">Pilih Identitas</option>
										<option value="1">Kartu BPJS</option>
										<option value="2">Kartu Keluarga</option>
										<option value="3">Kartu Pelajar</option>
										<option value="4">KTP</option>
										<option value="5">Paspor</option>
										<option value="6">SIM</option>
										<option value="7">KTA</option>
									</select>
								</span>
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>No Identitas</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pihak_no_identitas' name='pihak_no_identitas' value="" class="standard-input" maxlength="50">
							</td>
						</tr>
						<tr>
							<td>No Telepon</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pihak_no_tlp' name='pihak_no_tlp' value="" class="standard-input" maxlength="50">
							</td>
						</tr>
						<tr>
							<td>Alamat Email</td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='pihak_email' name='pihak_email' value="" class="standard-input" maxlength="50">
							</td>
						</tr>
						<tr>
							<td>Alamat <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<textarea id="pihak_alamat" name="pihak_alamat" class="standard-input" maxlength="500" style="width: 245px; height: 70px;resize: none;"></textarea>
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Jenis Kelamin <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_jenis_kelamin" id="pihak_jenis_kelamin" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="">Pilih Jenis Kelamin</option>
										<option value="1">Laki Laki</option>
										<option value="2">Perempuan</option>
									</select>
								</span>
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Agama</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_agama" id="pihak_agama" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="">Pilih Agama</option>
										<?php
										if($agama!=''){
											if($agama->num_rows()>0){
												foreach ($agama->result() as $row) {
													echo '<option value="'.$row->id.'">'.$row->nama.'</option>';
												}
											}
										}
										?>
									</select>
								</span>
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Warga Negara <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_warga_negara" id="pihak_warga_negara" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<?php
										if($country!=''){
											if($country->num_rows()>0){
												foreach ($country->result() as $row) {
													$select = ($row->nama=='Indonesia')? 'selected':'';
													echo '<option value="'.$row->id.'" '.$select.'>'.$row->nama.'</option>';
												}
											}
										}
										?>
									</select>
								</span>
							</td>
						</tr>						
						<tr class="tr_perorangan">
							<td>Pekerjaan<font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<?php
								if($this->session->userdata('jenis_pengadilan')==2){
									?>
									<span class="custom-dropdown custom-dropdown--emerald">
										<select style='width:200px;' name="apakahtni" id="apakahtni" class="custom-dropdown__select custom-dropdown__select--white">
											<option value="1">Tentara Nasional Indonesia</option>
											<option value="2">Lain-Lain</option>
										</select>
									</span>
									<?php
								}elseif($this->session->userdata('jenis_pengadilan')==4){
									?>
									<span class="custom-dropdown custom-dropdown--emerald">
										<select style='width:200px;' name="apakahtni" id="apakahtni" class="custom-dropdown__select custom-dropdown__select--white">
											<option value="">Pilih Pekerjaan</option>
											<option value="4">Pegawai BUMN/BUMD</option>
											<option value="3">Pegawai Negeri Sipil</option>
											<option value="5">POLRI</option>
											<option value="1">Tentara Nasional Indonesia</option>
											<option value="2">Lain-Lain</option>
										</select>
									</span>
									<?php
								}else{
								?>
								<input type="text"  id='pihak_pekerjaan' name='pihak_pekerjaan' value="" class="standard-input" maxlength="255" placeholder="Isikan Pekerjaan Di Sini">
								<?php } ?>
							</td>
							<input type="hidden" id='keyword_pihak' name="keyword_pihak" value="<?php echo $keyword;?>">
						</tr>
						<?php 
						if($this->session->userdata('jenis_pengadilan')==2 OR $this->session->userdata('jenis_pengadilan')==4){
							?>
						<tr class="tr_perorangan" id='input_pihak_pekerjaan'>
							<td></td>
							<td>
								<input type="text"  id='pihak_pekerjaan' name='pihak_pekerjaan' value="" class="standard-input" maxlength="255" placeholder="Isikan Pekerjaan Di Sini">
							</td>
						</tr>
						<?php } ?>
						<tr class="tr_perorangan">
							<td>Berkebutuhan Khusus</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select style='width:200px;' name="pihak_difabel" id="pihak_difabel" class="custom-dropdown__select custom-dropdown__select--white">
										<option value="T"> Tidak</option>
										<option value="Y"> Ya</option>
									</select>
								</span>
							</td>
						</tr>
						<tr class="tr_perorangan">
							<td>Status Kawin <?php echo ($pihak_ke==1 || ($this->session->userdata('jenis_pengadilan')!=3))? '<font color="red">*</font>':'';?></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_status_kawin" id="pihak_status_kawin" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="">Pilih Status Kawin</option>
										<option value="1">Kawin</option>
										<option value="2">Belum Kawin</option>
										<option value="3">Duda</option>
										<option value="4">Janda</option>
									</select>
								</span>
							</td>
							<input type="hidden" id='pihak_id_frm_ref_pihak' name="pihak_id" value="">
						</tr>
						<tr class="tr_perorangan">
							<td>Pendidikan <?php echo ($pihak_ke==1 || ($this->session->userdata('jenis_pengadilan')!=3))? '<font color="red">*</font>':'';?></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_pendidikan" id="pihak_pendidikan" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="">Pilih Pendidikan</option>
										<?php
										if($pendidikan!=''){
											if($pendidikan->num_rows()>0){
												foreach ($pendidikan->result() as $row) {
													echo '<option value="'.$row->id.'">'.$row->nama.'</option>';
												}
											}
										}
										?>
									</select>
								</span>
							</td>
							
						</tr>
						<tr class="tr_perorangan">
							<td>Golongan Darah</td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald" style='width:200px;'>
									<select name="pihak_gol_darah" id="pihak_gol_darah" style='width:200px;' class="custom-dropdown__select custom-dropdown__select--white">
										<option value="">Pilih Golongan Darah</option>
										<option value="A">A</option>
										<option value="AB">AB</option>
										<option value="B">B</option>
										<option value="O">O</option>
									</select>
								</span>
							</td>
							<input type="hidden" id="curr_date" value="<?php echo $current_date;?>">
						</tr>
						<tr>
							<td>Keterangan</td>
							<td style="padding:0px;padding-left:5px;border:0px;">
								<textarea id="pihak_keterangan" name="pihak_keterangan" maxlength="255" class="standard-input" style="width: 245px; height: 70px;resize: none;"></textarea>
							</td>
						</tr>
						<tr>
							<td colspan="2" style="background:white;" align="center">
								<input type="button" id='back_pihak' value="Kembali" class="btn">
								<input type="submit" id="simpan_btn" value="Simpan" class="btn">
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>
</div>
<script type="text/javascript">
$('#close_form_2nd').<?php echo $popup==5?'closingForm5thWin':'closingForm2ndWin'; ?>();

var forPihakKe = "<?php echo $forPihakKe?>";
$("#pihak_tgl_lahir").change(function() {
	var error = 0;
	var tmp = $(this).val().split("/");
	var tmp2 = $('#curr_date').val().split("/");
	dob = new Date(tmp[2],tmp[1],tmp[0]);
	var today = new Date(tmp2[2],tmp2[1],tmp2[0]);
	var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
	if(age<5 || age >100){
		message = 'Tanggal Lahir Tidak Valid. Silahkan Periksa Kembali';
		error = 1
	}
	if(error==1){
		message_error_show(message);
		$(this).css("background-color", "red");
	}else{
		$('#pihak_umur').val(age);
		$(this).css("background-color", "#dedbdb");
	}
	error = 0;
});

$("#pihak_umur").change(function() {
	var age = $('#pihak_umur').val();
	var error = 0;
	var tmp2 = $('#curr_date').val().split("/");
	var year = tmp2[2]-age;
	if(age<5 || age >100){
		message_error_show('Tanggal Lahir Tidak Valid. Silahkan Periksa Kembali');
		$(this).css("background-color", "red");
	}else{
		var tglLahir = tmp2[0]+'/'+tmp2[1]+'/'+year;
		$("#pihak_tgl_lahir").val(tglLahir)
		$(this).css("background-color", "#dedbdb");
	}
});

$('.tr_perorangan').show();
$("#pihak_jenis_pihak").change(function() {
	if($(this).val()!=1){
		$('#frm_ref_pihak .tr_perorangan').hide();
	}else{
		$('#frm_ref_pihak .tr_perorangan').show();
	}
});	
$("#addPihak").click(function() {
	clearAll();
	$('.pihak_list #pihak_jenis_pihak').val(1);
	$(".pihak_list #pihak_jenis_pihak").change();
	$('#popup_pihak_list').fadeOut();
	$('#popup_pihak').fadeIn();
	$('#edit_btn').hide();
	//$('#act').val('add');
	$('#act_frm_ref_pihak').val('add');
    $("body").css({overflow: 'hidden'});
	<?php
	if($this->session->userdata('jenis_pengadilan')==2){
	?>
		$('#input_pihak_pekerjaan').hide();
		$('#apakahtni').val('1');
	<?php }elseif($this->session->userdata('jenis_pengadilan')==4){
	?>
		$('#input_pihak_pekerjaan').hide();
		$('#apakahtni').val('');
	<?php } ?>
});

$("#back_pihak").click(function() {
	$('#popup_pihak_list').fadeIn();
	$('#popup_pihak').fadeOut();
    $("body").css({overflow: 'hidden'});
    if($("#refresh").val()==1){
    	refreshPihakList();
    }
    //$("#refresh").remove();
});


$('#frm_ref_pihak').SubmitHandling({
	refresh:'1',
	setRefresh:1,
	divRef:'#pihak_pilih',
	clicked:1,
	btnClicked:'#back_pihak',
	whenStatus:1
});

function clearAll(){
	$('#popup_pihak :input').not('.btn').not('#curr_date').val('');
	$('#popup_pihak .hidden').hide();
	$('#pihak_jenis_pihak').val(1);
	$('#pihak_warga_negara').val(98);
}

function pilih(val){
	var status='<?php echo $isorangtuawali;?>';
	if(val==""){
		message_show("Error <br/> Refresh Browser Anda");
		return;
	}
	openLoadingDialog();

	if(status==2){
		var enc_id = '<?php echo $enc_id;?>';
		var enc_anak = '<?php echo $enc_anak;?>';
		var jenis_pihak = '<?php echo $jenis_pihak;?>';
		var status = 1;
		$.post('<?php echo base_url()?>pihak_list/addOrtu', {
			val:val,
			enc_anak:enc_anak,
			jenis_pihak:jenis_pihak,
			enc_id:enc_id
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				message_show(json.msg);
				status = json.st;
				return;
			});
		if(status==0){
			return;
		}
		refreshOrtuList(jenis_pihak);
	}
	$.post('<?php echo base_url()?>pihak_list/fetchPihak', {
		val:val
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.isLengkap==0){
			message_error_show("Data Pihak Tidak Lengkap, Data "+json.notFill+" Tidak Ada. Silahkan Lengkapi terlebih dahulu. Klik Edit.");
			return;
		}else if(json.st==1){
			<?php
			if ($this->session->userdata('jenis_pengadilan')==2){
			?>
				if (json.pekerjaan=='Tentara Nasional Indonesia'){
					$('.militer').show();
				}else{
					$('.militer').hide();
				}
			<?php
			}elseif ($this->session->userdata('jenis_pengadilan')==4){
			?>
				if (json.pekerjaan=='Tentara Nasional Indonesia' || json.pekerjaan=='Pegawai Negeri Sipil' || json.pekerjaan=='Pegawai BUMN/BUMD' || json.pekerjaan=='POLRI'){
					$('.militer').show();
				}else{
					$('.militer').hide();
				}
			<?php
			}
			?>

			if(json.IDJenisPihak>1){
				$('.tr_perorangan').hide();
			}else{
				$('.tr_perorangan').show();
			};
			if(json.IDJenisPihak==1){
				if(forPihakKe!=1 && forPihakKe==3){
					if(json.enc_pihak=="" || json.jenisPihak=="" || json.nama=="" || json.sex=="" || json.wargaNegara=="" || json.alamat=="" || json.pekerjaan=="" || json.statusKawin==""){
						message_error_show("Data Pihak Tidak Lengkap, Data "+json.notFill+" Tidak Ada. Silahkan Lengkapi terlebih dahulu. Klik Edit.");
						return;
					}else{
						fillForm(json);
						$('#close_form_2nd').click();
					}
				}else if(json.enc_pihak=="" || json.jenisPihak=="" || json.nama=="" || json.sex=="" || json.wargaNegara=="" || json.alamat=="" || json.pekerjaan==""){
					message_error_show("Data Pihak Tidak Lengkap, Data "+json.notFill+" Tidak Ada. Silahkan Lengkapi terlebih dahulu. Klik Edit.");
					return;
				}else{
					fillForm(json);
					$('#close_form_2nd').click();
				}
			}else{
				fillForm(json);
				$('#close_form_2nd').click();
			}
		}else if(json.st==0){
			message_error_show(json.msg);
		}
	});
}

function fillForm(json){
	$('#enc_pihak').val(json.enc_pihak);
	$('#jenis_pihak').val(json.jenisPihak);
	$('#fullname').val(json.nama);
	$('#tempat_lahir').val(json.tempatLahir);
	$('#tgl_lahir').val(json.tglLahir);
	$('#umur').val(json.umur);
	$('#jenis_kelamin').val(json.sex);
	$('#warga_negara').val(json.wargaNegara);
	$('#alamat').val(json.alamat);
	$('#pekerjaan').val(json.pekerjaan);
	$('#pendidikan').val(json.pendidikan);
	$('#keterangan').val(json.keterangan);
	$('#statusKawin').val(json.statusKawin);
	$('#difabel').val(json.difabel);
	$('#nrp').val(json.nip_nrp)
	$('#pangkat').val(json.pangkat)
	$('#jabatan').val(json.jabatan)
	$('#kesatuan').val(json.kesatuan)
}
function edit(val){
	if(val==""){
		message_error_show("Error <br/> Refresh Browser Anda");
		return;
	}
	openLoadingDialog()
	$.post('<?php echo base_url()?>pihak_list/fetchPihak', {
		val:val
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#pihak_id_frm_ref_pihak').val(json.enc_pihak);
			$('.pihak_list #pihak_jenis_pihak').val(json.IDJenisPihak);
			$('#pihak_fullname').val(json.nama);
			$('#pihak_tempat_lahir').val(json.tempatLahir);
			$('#pihak_tgl_lahir').val(json.tglLahir);
			$('#pihak_umur').val(json.umur);
			$('#pihak_jenis_kelamin').val(json.IDSex);
			$('#pihak_warga_negara').val(json.IDWargaNegara);
			$('#pihak_alamat').val(json.alamat);
			$('#pihak_pekerjaan').val(json.pekerjaan);
			$('#pihak_pendidikan').val(json.IDPendidikan);
			$('#pihak_keterangan').val(json.keterangan);
			$('#pihak_no_tlp').val(json.noTlp);
			$('#pihak_jenis_identitas').val(json.jenisIdentitas);
			$('#pihak_no_identitas').val(json.noIdentitas);
			$('#pihak_gol_darah').val(json.golDarah);
			$('#pihak_agama').val(json.IDAgama);
			$('#pihak_email').val(json.email);
			$('#pihak_status_kawin').val(json.IDStatusKawin);
			$('#popup_pihak_list').fadeOut();
			$('#popup_pihak').fadeIn();
			$('#pihak_jenis_pihak').val(json.IDJenisPihak)
			<?php
			if($this->session->userdata('jenis_pengadilan')==2){
			?>			
				if ($('#pihak_pekerjaan').val()=="Tentara Nasional Indonesia"){
						$('#input_pihak_pekerjaan').hide();
						$('#apakahtni').val('1');
				}else{
					$('#input_pihak_pekerjaan').show();
					$('#apakahtni').val('2');
				};
			<?php 
			}elseif($this->session->userdata('jenis_pengadilan')==4){?>
				switch(json.pekerjaan) {
					case "Tentara Nasional Indonesia":
						$('#input_pihak_pekerjaan').hide();
						$('#apakahtni').val('1');
						$('#pihak_pekerjaan').val('');
						break;
					case "Pegawai Negeri Sipil":
						$('#input_pihak_pekerjaan').hide();
						$('#apakahtni').val('3');
						$('#pihak_pekerjaan').val('');
						break;
					case "Pegawai BUMN/BUMD":
						$('#input_pihak_pekerjaan').hide();
						$('#apakahtni').val('4');
						$('#pihak_pekerjaan').val('');
						break;
					case "POLRI":
						$('#input_pihak_pekerjaan').hide();
						$('#apakahtni').val('5');
						$('#pihak_pekerjaan').val('');
						break;
					default:
						$('#apakahtni').val('2');
						$('#input_pihak_pekerjaan').show();
						break;
				}
			<?php
			} ?>
			
			if(json.IDJenisPihak!=1){
				$('#frm_ref_pihak .tr_perorangan').hide();

			}else{
				$('#frm_ref_pihak .tr_perorangan').show();
			}
			if(json.difabel=='Ya'){
				$('#pihak_difabel').val('Y');
			}else{
				$('#pihak_difabel').val('T');
			}
			$('#edit_btn').show();
			$('#act_frm_ref_pihak').val('updt');
			$("body").css({overflow: 'hidden'});
		}else if(json.st==0){
			message_error_show(json.msg);
		}
	});
	
}
$('#form_search_pihak').submit(function(event){
	openLoadingDialog()
    $.post($(this).attr('action'),$(this).serialize(), function(json){
    	closeLoading()
    	if(json.st==1){
    		refreshPihakList()
    	}else{
    		message_error_show("Error, Tutup Browser anda kemudian login kembali");
    	}
    	event.preventDefault()
	},'json');
	event.preventDefault()
});

$(function() {
    var totalPage = '<?php echo $total_rows; ?>';
    var page = '<?php echo $page_number;?>';
    $('#selector').pagination({
        items: totalPage,
        itemsOnPage: 50,
        displayedPages: 3,
        cssStyle: 'light-theme',
        currentPage:page,
        onPageClick: function(pageNumber){
        	openLoadingDialog()
        	$.post('<?php echo base_url()?>pihak_list/setPage', {
        		pageNumber:pageNumber,
        		keyword:$('#keyword_pihak').val()
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				if(json.st==1){
					refreshPihakList()
				}else{
					message_error_show("Error, Tutup Browser anda kemudian login kembali");
				}
			});
            
        	}
        });
    $('#selector_bottom').pagination({
        items: totalPage,
        itemsOnPage: 50,
        displayedPages: 3,
        cssStyle: 'light-theme',
        currentPage:page,
        onPageClick: function(pageNumber){
            openLoadingDialog()
        	$.post('<?php echo base_url()?>pihak_list/setPage', {
        		pageNumber:pageNumber,
        		keyword:$('#keyword_pihak').val()
			}, function(response){
				var json = jQuery.parseJSON(response);
				closeLoading()
				if(json.st==1){
					refreshPihakList()
				}else{
					message_error_show("Error, Tutup Browser anda kemudian login kembali");
				}
			});
            
        	}
        });
    $('#pihak_tgl_lahir').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            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]).getTime() > new Date(tmp2[2],tmp2[1],tmp2[0]).getTime())){
					message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
					error = 1
				}

				dob = new Date(tmp[2],tmp[1],tmp[0]);
				var today = new Date(tmp2[2],tmp2[1],tmp2[0]);
				var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
				if(age<5 || age >100){
					message = 'Tanggal Lahir 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;
        	}
      	});

    });

$('.datepicker').ValidateDateInput();
<?php
if($this->session->userdata('jenis_pengadilan')==2 OR $this->session->userdata('jenis_pengadilan')==4){
?>
	$('#apakahtni').change(function(){
		if($(this).val()!=2){
			$('#input_pihak_pekerjaan').hide();
		}else{
			$('#input_pihak_pekerjaan').show();
		}
	});
<?php
}
?>
</script>
