<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>resources/css/jquery.autocomplete.css">
<script type="text/javascript" src="<?php echo base_url();?>resources/js/jquery.autocomplete.js"></script> 
<?php
$lang_tglput=($this->nativesession->getLangguage('tanggal_putusan'));
if($idalurperkara<100){
	$b_pendaftaran = 0;
	$b_atk = 0;
	if($biaya!=''){
		if($biaya->num_rows>0){
			foreach ($biaya->result() as $row) {
				if($row->id==62){
					$b_pendaftaran = round($row->jumlah);
				}elseif ($row->id==170) {
					$b_atk = round($row->jumlah);
				}
			}
		}
	}
}

?>
<hr class="thick-line" style="clear:both;">
<div style="padding:20px;"></div>
<div class="detil" style="font-size:14px;margin-top:25px;width: 65%;margin: 0 auto;border-color: #FFFFFF;">
	<form id="frm_add_perdata" style="background:white;margin:0;" method="post" action="<?php echo base_url().'add_perdata_banding/validateInput';?>">
		<table id="tableDetilPerkara" style="font-size:14px;">
			<col width="30%">
			<col width="50%">
			<col width="20%">
			<tbody>
				<tr>
					<td>Tanggal Permohonan<font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input id="tgl_pendaftaran" name="tgl_pendaftaran" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
					</td>
				</tr>
				<tr>
					<td>Nomor Perkara<font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" class="autocomplete" id='no_perkara' name='no_perkara' value="" size="50" placeholder="Ketik Nomor Perkara" style="padding: 7px 0;padding-left:4px;border: 1px solid; width: 250px;">
						<input type="button" id = "cari_perkara" value="Cari" style="padding: 7px 0;color:white;background: #7f8c8d;border: 0 none;  -webkit-border-radius: 0 0 0 0;width: 90px;">
					</td>
				</tr>
				<tr>
					<td>Tanggal Putusan<font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;"  colspan="2" id="tgl_putusan_pn"></td>
				</tr>
				<tr id="tr_pihak">
					<input type="hidden" id="tgl_beritahu" value="">
					<input type="hidden" id="date_put" value="">
					<td colspan="3" class="divider">PIHAK PEMOHON BANDING</td>
					<input type="hidden" id="enc_alur" name="enc_alur" value="<?php echo $enc_alur;?>">
					<input type="hidden" id="enc" name="enc" value="<?php echo (!empty($enc))? $enc:'';?>">
					<input type="hidden" id="enc_pemohon" name="enc_pemohon" value="<?php echo (!empty($enc_pemohon))? $enc_pemohon:'';?>">
					<input type="hidden" id="status" value="<?php echo $idalurperkara;?>">
				</tr>
				<tr class="lastpihak1" style="display:none;"></tr>
				<tr class="lastpihak2" style="display:none;"></tr>
				<tr class="lastpihak3" style="display:none;"></tr>
				<tr>
					<td >Pihak Diwakili<font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<span class="custom-dropdown custom-dropdown--emerald" style='width:80px;'>
							<select name="diwakilkan" id="diwakilkan" style="width:80px;" class="custom-dropdown__select custom-dropdown__select--white">
								<option value="0">Tidak</option>
								<option value="1">Ya</option>
							</select>
						</span>
					</td>
				</tr>
				<tr class ="tr_pemohon">
					<td colspan="3" class="divider">PEMOHON BANDING</td>
				</tr>
				<tr class ="tr_pemohon">
					<td>Nama Pemohon<font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='nama_pemohon' name='nama_pemohon' value="<?php echo (!empty($nama) ? $nama : '');?>" class="standard-input" maxlength="255" style="width:250px;" readonly="readonly">
						<input id="cari" type="button" onClick="popup_form('<?php echo base_url('pihak_list_up');?>')" value="Cari" style="padding: 7px 0;color:white;background: #7f8c8d;border: 0 none;  -webkit-border-radius: 0 0 0 0;width: 90px;">
					</td>
				</tr>
				<tr class ="tr_pemohon">
					<td>Pekerjaan Pemohon</td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='pekerjaan_pemohon' name='pekerjaan_pemohon' value="<?php echo (!empty($pekerjaan) ? $pekerjaan : '');?>" class="standard-input" maxlength="255" style="width:250px;" readonly="readonly">
					</td>
				</tr>
				<tr class ="tr_pemohon">
					<td>Alamat Pemohon</td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<textarea class="standard-input" id="alamat_pemohon" name = "alamat_pemohon"  style="width: 250px; height: 90px;resize: none;" readonly><?php echo (!empty($alamat) ? $alamat : '');?></textarea>
					</td>
				</tr>
				<tr id="tr_tgl_kuasa" class ="tr_pemohon">
					<td>Tanggal Surat Kuasa</td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input id="tgl_surat_kuasa" name="tgl_surat_kuasa" value="" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
					</td>
				</tr>
				<tr class ="tr_pemohon">
					<td>Nomor Surat Kuasa</td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='no_kuasa' name='no_kuasa' value="<?php echo (!empty($sex) ? $sex : '');?>" style="width:250px;" class="standard-input" maxlength="255">
					</td>
				</tr>
				<?php
				if($idalurperkara<100){
				?>
				<tr>
					<td colspan="3" class="divider">BIAYA PERKARA</td>
				</tr>
				<tr id="rw_prodeo">
					<td >Prodeo <font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<span class="custom-dropdown custom-dropdown--emerald" style='width:80px;'>
							<select name="prodeo" id="prodeo" style='width:80px;' class="custom-dropdown__select custom-dropdown__select--white">
								<option value="0">Tidak</option>
								<option value="1">Ya</option>
							</select>
						</span>
					</td>
				</tr>
				<tr id="rw_jenis_prodeo">
					<td >Jenis Prodeo <font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<span class="custom-dropdown custom-dropdown--emerald" style='width:150px;'>
							<select name="jenis_prodeo" style='width:150px;' id="jenis_prodeo" class="custom-dropdown__select custom-dropdown__select--white">									<option value="-1">Pilih Jenis Prodeo</option>
								<option value="2">DIPA</option>
								<option value="3">Murni</option>
							</select>
						</span>
					</td>
				</tr>
				<tr>
					<td style="background:white;padding:2px;"></td>
				</tr>
				<tr id="rw_ref_bank">
					<td>Nomor Referensi Bank</td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='no_ref' name='no_ref' value="" style="width:180px;" class="standard-input" maxlength="150">
					</td>
				</tr>
				<tr>
					<td>Panjar Perkara <font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='b_panjar' name='b_panjar' value="" data-a-sep="." data-a-dec="," style="width:180px;text-align:right;" class="standard-input" maxlength="20">
					</td>
				</tr>
				<tr id="tr_biaya_pendaftaran">
					<td>Biaya Pendaftaran <font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='b_pendaftaran' name='b_pendaftaran' data-a-sep="." data-a-dec="," value="<?php echo $b_pendaftaran;?>" style="width:150px;text-align:right;" class="standard-input" maxlength="10" readonly="readonly">
					</td>
				</tr>
				<tr id="tr_atk">
					<td>Alat Tulis Kantor <font color="red">*</font></td>
					<td style="padding:0px;padding-left:5px;" colspan="2">
						<input type="text" id='b_atk' name='b_atk' data-a-sep="." data-a-dec="," value="<?php echo $b_atk;?>" style="width:150px;text-align:right;" class="standard-input" maxlength="10" readonly="readonly">
					</td>
				</tr>
				<?php
				}
				?>
				<input type="hidden" id="curr_date" value="<?php echo $current_date;?>">
				<tr>
					<td colspan="3" style="background:white;" align="center">
						<input type="button" value="Kembali" id="kembali" class="btn">
						<input type="submit" id="simpan" value="Simpan" class="btn">
					</td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
<script src="<?php echo base_url();?>resources/js/autoNumeric.js"></script>
<script type="text/javascript">
	var site = "<?php echo base_url();?>";
	var alur_perkara = '<?php echo $idalurperkara; ?>';
    $(function(){
        $('.autocomplete').autocomplete({
            serviceUrl: site+'cari_komplit/cari/'+alur_perkara,
            onSelect: function (suggestion) {
               $('#search-btn1').click();
            }
        });
    });
</script>
<script type="text/javascript">
function refreshPihakList(){
	$("#popup_form").remove();
	popup_form('<?php echo base_url("pihak_list_up");?>')
}
$("#cari_perkara").click(function() {
	openLoadingDialog()
	$.post('<?php echo base_url()?>add_perdata_banding/fetchData', {
		val:$('#no_perkara').val(),
		enc_alur:'<?php echo $enc_alur;?>',
		tglDaftar:$('#tgl_pendaftaran').val()
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('.tr_pihak1').remove();
			$('.tr_pihak2').remove();
			$('.tr_pihak3').remove();
			$('.tr_pihak4').remove();

			$('#tr_pihak').after(json.pihakPertama);
			$('.lastpihak1').after(json.pihakKedua);
			if(json.pihakKetiga!=''){
				$('.lastpihak2').after(json.pihakKetiga);
			}
			if(json.pihakKeempat!='' && json.pihakKetiga!=''){
				$('.lastpihak3').after(json.pihakKeempat);
			}
			if(json.pihakKeempat!='' && json.pihakKetiga==''){
				$('.lastpihak2').after(json.pihakKeempat);
			}
			$('#tgl_putusan_pn').text(json.tglPutusanPN);
			$('#tgl_beritahu').val(json.tgl_pemberitahuan);
			$('#date_put').val(json.tglPutusan);			
			$('#enc').val(json.enc);
			$('#enc_alur').val(json.enc_alur);
			if(json.isBanding){
				$('#tr_biaya_pendaftaran').hide();
				$('#tr_atk').hide();
			}
			if(json.stTgl==0){
				message_error_show_parent(json.stTglMsg);
			}
		}else if(json.st==0){
			message_error_show_parent(json.msg);
			return
		}
	});
});



$('#frm_add_perdata').on('click', '#kembali', function(event) {
	window.open('<?php echo $history;?>','_self')
});

$('#frm_add_perdata').on('click', '#simpan', function(event) {
	if($('#tgl_pendaftaran').val()==''){
		message_error_show_parent('Tanggal Permohonan Banding Masih Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}
	var tmp = $('#tgl_pendaftaran').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();
		message_error_show_parent(message);
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}else{
		$(this).css("background-color", "#dedbdb");
	}
	var checked = 0;
	var urutan ='';
	$('input[type=checkbox]').each(function () {
		var pihakName = $(this).attr('nama_pihak');
    	if($(this).is(":checked")){
    		checked = 1;
    		var inputName = $(this).attr('identify');
    		if($('#'+inputName).val()==-1){
    			message_error_show_parent('Urutan Pembanding '+pihakName+', Masih Belum dipilih. Silahkan Pilih Urutan Pembanding.')
    			event.preventDefault();
				return;
    		}
    		if($('#'+inputName).val()==1){
    			urutan =1;
    		}
    	}
	});
	if(checked==0){
		message_error_show_parent('Pemohon Banding Belum Dipilih');
		event.preventDefault();
		return;
	}

	if(urutan==0){
		message_error_show_parent('Periksa Kembali Urutan Pembanding');
		event.preventDefault();
		return;
	}
	if($('#diwakilkan').val()==1 && ($('#nama_pihak').val()=='' || $('#enc_pemohon').val()=='')){
		message_error_show_parent('Pilih Pihak Yang Mewakili. Jika tidak diwakilkan Silahkan Pilih Pihak Diwakili = Tidak.');
		event.preventDefault();
		return;
	}
});
$('#frm_add_perdata').on('click', '.checkbox_status', function() {
	var pihakStatus = $(this).attr('id');
	if($(this).is(":checked")) {
		if($('#status').val()<100){
			if($(this).attr('status')=='ck_pihak1'){
				$("input[status='ck_pihak2']:checkbox").prop('checked', false);
				$('.ck_pihak2').hide();
				$("input[status='ck_pihak3']:checkbox").prop('checked', false);
				$('.ck_pihak3').hide();
				$("input[status='ck_pihak4']:checkbox").prop('checked', false);
				$('.ck_pihak4').hide();
			}else if($(this).attr('status')=='ck_pihak2'){
				$("input[status='ck_pihak1']:checkbox").prop('checked', false);
				$('.ck_pihak1').hide();
				$("input[status='ck_pihak3']:checkbox").prop('checked', false);
				$('.ck_pihak3').hide();
				$("input[status='ck_pihak4']:checkbox").prop('checked', false);
				$('.ck_pihak4').hide();
			}else if($(this).attr('status')=='ck_pihak3'){
				$("input[status='ck_pihak1']:checkbox").prop('checked', false);
				$('.ck_pihak1').hide();
				$("input[status='ck_pihak2']:checkbox").prop('checked', false);
				$('.ck_pihak2').hide();
				$("input[status='ck_pihak4']:checkbox").prop('checked', false);
				$('.ck_pihak4').hide();
			}else if($(this).attr('status')=='ck_pihak4'){
				$("input[status='ck_pihak1']:checkbox").prop('checked', false);
				$('.ck_pihak1').hide();
				$("input[status='ck_pihak2']:checkbox").prop('checked', false);
				$('.ck_pihak2').hide();
				$("input[status='ck_pihak3']:checkbox").prop('checked', false);
				$('.ck_pihak3').hide();
			}
			$('#pihak_'+$(this).attr('id')).fadeToggle("slow");
		}else{
			$("input:checkbox").not($(this)).prop('checked', false);
			$('#pihak_'+$(this).attr('id')).fadeToggle("slow");
			$('#'+$(this).attr('identify')).val(1);
			$('#'+$(this).attr('identify')).prop('disabled', true);
			$('.ck_pihak1').not($('#pihak_'+$(this).attr('id'))).hide();
			$('.ck_pihak2').not($('#pihak_'+$(this).attr('id'))).hide();
			fetchDataPemohon($(this).attr('value'));
		}
	}else{
		$('#pihak_'+$(this).attr('id')).hide();
	}
});

function fetchDataPemohon(enc){
	openLoadingDialog()
	$.post('<?php echo base_url()?>add_perdata_banding/fetchDataPemohon', {
		enc:enc
	}, function(response){
		var json = jQuery.parseJSON(response);
		closeLoading()
		if(json.st==1){
			$('#nama_pemohon').val(json.nama);
			$('#enc_pemohon').val(json.enc_pihak);
			$('#alamat_pemohon').val(json.alamat);
			$('#pekerjaan_pemohon').val(json.pekerjaan);
		}else if(json.st==0){
			message_error_show_parent(json.msg);
			return
		}
	});
}
$('#frm_add_perdata').on('change', '.pembanding', function(){
	var idpilih = $(this).attr('id');
	var valpilih = $(this).attr('value');
	$( ".pembanding" ).each(function(index) {
		if($(this).attr('id')!=idpilih){
			if(valpilih==$(this).attr('value')){
				$(this).val(-1);
			}
		}
	});
	if(valpilih==1){
		fetchDataPemohon($(this).attr('pihak'));
	}
});

$('#frm_add_perdata').on('change', '#diwakilkan', function(){
	if($(this).attr('value')==1){
		$('#cari').show();
	}else{
		$('#cari').hide();
	}
});

$('#prodeo').change(function(e){
	if($('#prodeo').val()==0){
		$('#rw_jenis_prodeo').hide();
		$('#prodeo').show();
		$('#rw_ref_bank').show();
	}else{
		$('#rw_jenis_prodeo').show();
		$('#rw_ref_bank').hide();

	}
});

$('#jenis_prodeo').change(function(e){
	openLoadingDialog()
	if($('#jenis_prodeo').val()==3){
		b_panjar_tmp = $('#b_panjar').val();
		b_pendaftaran_tmp = $('#b_pendaftaran').val();
		b_atk_tmp = $('#b_atk').val();
		$('#b_panjar').val('0');
		$('#b_pendaftaran').val('0');
		$('#b_atk').val('0');
	}else{
		if(b_panjar_tmp==''){
			b_panjar_tmp = $('#b_panjar').val();
		}
		$('#b_panjar').val(b_panjar_tmp);
		$('#b_pendaftaran').val(b_pendaftaran_tmp);
		$('#b_atk').val(b_atk_tmp);
	}
	closeLoading()
});

$( document ).ready(function() {
    $('#rw_no_perkara_manual').hide();
    $('#rw_jenis_prodeo').hide();
    $('#b_pendaftaran').autoNumeric('init', {mDec: '0'});
    $('#b_pendaftaran').ForceNumericOnly();
    $('#b_atk').autoNumeric('init', {mDec: '0'});
    $('#b_atk').ForceNumericOnly();
    $('#b_panjar').autoNumeric('init', {mDec: '0'});
    $('#b_panjar').ForceNumericOnly();
    //$('.tr_pemohon').hide();

    $('#frm_add_perdata').SubmitHandling({
		refresh:'1',
		setRefresh:1,
		divRef:'#frm_add_perdata',
		clicked:1,
		btnClicked:'#kembali',
		whenStatus:1
	});
    $( function() {
        $('#tgl_pendaftaran').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 date = $(this).datepicker('getDate');
            	var dayOfWeek = weekday[date.getDay()];
            	var error = 0;
            	var message ='';
            	if(dayOfWeek=='Sunday' || dayOfWeek=='Saturday'){
            		message ='Tidak Dapat Memilih diluar Hari Kerja.';
            		message_error_show_parent(message);
            		return;
            	}
				
				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();
					message_error_show_parent(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}

				if($('#tgl_beritahu').val()!=''){
					var date = new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00");
					var tmp2 = $('#tgl_beritahu').val().split("/");
					var today = new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00");
					var dayDiff = Math.ceil((date-today) / (1000 * 60 * 60 * 24));
					if(dayDiff>15){
						message_error_show_parent('Permohonan Banding Telah Melebihi 14 Hari dari Tgl Pemberitahuan kepada Pihak ('+$('#tgl_beritahu').val()+'). Mohon Untuk Melihat kembali permohonan yang diajukan untuk menjadi catatan.');
					}
				}else if($('#date_put').val()!=''){
					var date = new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00");
					var tmp2 = $('#date_put').val().split("/");
					var today = new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00");
					var dayDiff = Math.ceil((date-today) / (1000 * 60 * 60 * 24));
					if(dayDiff>15){
						message_error_show_parent('Permohonan Banding Telah Melebihi 14 Hari dari Tgl Putusan ('+$('#date_put').val()+'). Mohon Untuk Melihat kembali permohonan yang diajukan untuk menjadi catatan.');
					}
				}
			}
        });
		$('#tgl_surat_kuasa').datepicker({
            inline: true,
            showOtherMonths: true,
            dateFormat: 'dd/mm/yy',
            dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
            onSelect: function(dateText, inst) {
            	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();
					message_error_show_parent(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
        	}
      	});

    });
    $('input,select').not('#simpan').keypress(function(event) { return event.keyCode != 13; });
    $('.datepicker').ValidateDateInput();
});
var b_panjar_tmp = $('#b_panjar').val();
	var b_pendaftaran_tmp = $('#b_pendaftaran').val();
	var b_atk_tmp = $('#b_atk').val();
</script>
