
<hr class="thick-line" style="clear:both;">
<div style="padding:20px;"></div>
	<div class="detil" style="padding:10px;font-size:14px;margin-top:25px;width:45%;margin: 0 auto;border-color: #ddd;">
		<form id="frm_add_pidana" style="background:white;margin:0;" method="post" action="<?php echo base_url().'add_pidana/validateInput';?>">
			<table id="tableDetilPerkara" style="font-size:14px;">
				<col width="30%">
				<col width="70%">
				<tbody>
					<tr id="rw_generate">
						<td >Generate Nomor</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:70px;'>
								<select name="generate" id="generate" style='width:70px;' class="custom-dropdown__select custom-dropdown__select--white">
									<option value="1">Ya</option>
									<option value="0">Tidak</option>
								</select>
							</span>
						</td>
					</tr>
					<tr>
						<?php
						if ($idalurperkara<= 118){
							echo "<td>Tanggal Pelimpahan <font color='red'>*</font></td>";
						}else if($idalurperkara== 120){
							echo "<td>Tanggal Penerimaan <font color='red'>*</font></td>";
						}else{
							echo "<td>Tanggal Permohonan <font color='red'>*</font></td>";
						}
						?>
						<td style="padding:0px;padding-left:5px;">
							<input id="tgl_pendaftaran" name="tgl_pendaftaran" value="<?php echo date('d/m/Y');?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
						</td>
					</tr>
					<?php
					if ($idalurperkara != 119){
					?>
					<tr hidden>
						<td>Status Terdakwa <font color="red">*</font></td-->
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:150px;'>
								<?php
									$js="id='terdakwa_anak' class='custom-dropdown__select custom-dropdown__select--white' style='width:150px;'";
									if ($idalurperkara==118){
										$option=array('1'=>'Anak-anak');
										echo form_dropdown('terdakwa_anak', $option, '1', $js);
									}else{
										$option=array('0'=>'Dewasa');
										echo form_dropdown('terdakwa_anak', $option, '0', $js);
									}
								?>
							</span>
						</td>
					</tr>
					<?php
					}
					?>
					<tr id="rw_generate">
						<td >Klasifikasi Perkara</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:400px;'>
								<select style='width:400px;' name="klas_perkara" id="klas_perkara" class="custom-dropdown__select custom-dropdown__select--white">
									<option value="-1">Pilih Klasifikasi Perkara</option>
									<?php
									if($jenis_perkara!=''){
										if($jenis_perkara->num_rows>0){
											foreach ($jenis_perkara->result() as $row) {
												echo '<option value="'.$row->id.'">'.$row->nama.'</option>';
											}
										}
									}
									?>
								</select>
							</span>
						</td>
					</tr>
					<?php
					if($this->session->userdata('jenis_pengadilan')==2 OR $idalurperkara==120 ){
						?>
					<tr id="matra">
						<td >Matra</td>
						<td style="padding:0px;padding-left:5px;">
							<span class="custom-dropdown custom-dropdown--emerald" style='width:400px;'>
								<select style='width:400px;' name="matra" id="matra" class="custom-dropdown__select custom-dropdown__select--white">
									<option value="1">AD</option>
									<option value="2">AL</option>
									<option value="3">AU</option>
								</select>
							</span>
						</td>
					</tr>
					<?php };
					?>
					<tr>
						<td>Nomor Urut <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_urut' name='no_urut' value="<?php echo $no_urut;?>" class="standard-input" maxlength="10" readonly="readonly" style="width:50px;">
						</td>
					</tr>
					<tr id="rw_no_perkara_auto">
						<td>Nomor Perkara <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_perkara_auto' name='no_perkara_auto' value="<?php echo $no_perkara;?>" style="width:250px;"class="standard-input" maxlength="255" readonly="readonly">
							<input type="hidden" id="urutan" value="<?php echo $no_perkara;?>">
						</td>
					</tr>
					<tr id="rw_no_perkara_manual" disabled>
						<td>Nomor Perkara <font color="red">*</font></td>
						<td style="padding:0px;padding-left:5px;">
							<input type="text" id='no_urutan_manual' name='no_urutan_manual' value="<?php echo $no_urutan_perkara;?>" class="standard-input" maxlength="10" style="width:50px;">
							<input type="text" id='no_perkara_manual' name='no_perkara_manual' value="<?php echo $no_perkara_manual;?>" class="standard-input" maxlength="100" style="width:250px;">
						</td>
					</tr>
					<tr>
						<td style="background:white;padding:2px;"></td>
						<input type="hidden" id="enc" name="enc" value="<?php echo $enc;?>">
					</tr>
					<tr>
						<td colspan="3" style="background:white;" align="center">
							<input type="hidden" id="curr_date" value="<?php echo $current_date;?>">
							<input type="button" id="kembali" value="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">
$('#klas_perkara').change(function(e){
	generateNomorPerkara();
});
$('#matra').change(function(e){
	generateNomorPerkara();
});

function generateNomorPerkara(){
	openLoadingDialog()
	var val = $('#klas_perkara').val()
	var enc = $('#enc').val()
	var urutan = $('#urutan').val()
	var date = $('#tgl_pendaftaran').val()
	var matra='';
	if ($('#matra').length>0){
		matra = $('#matra :selected').val();	
	}
	$("#klas_perkara option[value='-1']").remove();
	$.post('<?php echo base_url()?>add_pidana/getFormat', {
		enc: enc,
		val:val,
		urutan:urutan,
		date:date, matra:matra
	}, function(response){
		var json = jQuery.parseJSON(response);
		if(json.st==1){
			$('#no_perkara_auto').val(json.msg)
			$('#no_perkara_manual').val(json.manual)
			$('#no_urut').val(json.nourutregister)
		}
		closeLoading()
	});
}
$('#generate').change(function(e){
	if($('#generate').val()==1){
		$('#rw_no_perkara_manual').hide();
		$('#rw_no_perkara_auto').show();
		$('#no_urut').prop('readonly', true);
		generateNomorPerkara();
	}else{
		$('#rw_no_perkara_auto').hide();
		$('#rw_no_perkara_manual').show();
		$('#no_urut').prop('readonly', false);
		generateNomorPerkara();
	}
});

$('#no_urutan_manual').change(function(e){
	isNomorPerkaraExsist();
});

$('#no_perkara_manual').change(function(e){
	isNomorPerkaraExsist();
});

$('#no_urut').change(function(e){
	isNomorPerkaraExsist();
});


function isNomorPerkaraExsist(){
	if($('#generate').val()==0){
		openLoadingDialog()
		$.post('<?php echo base_url()?>add_pidana/validateNomorPerkara', {
			urutan:$('#no_urutan_manual').val(),
			no_urut_register:$('#no_urut').val(),
			date:$('#tgl_pendaftaran').val(),
			no_manual:$('#no_perkara_manual').val(),
			enc:$('#enc').val()
		}, function(response){
			var json = jQuery.parseJSON(response);
			if(json.st==0){
				message_show(json.msg);
				$('#no_urutan_manual').css("background-color", "red");
				$('#no_perkara_manual').css("background-color", "red");
				$('#no_urut').css("background-color", "red");
			}else{
				$('#no_urutan_manual').css("background-color", "#dedbdb");
				$('#no_perkara_manual').css("background-color", "#dedbdb");
				$('#no_urut').css("background-color", "#dedbdb");
			}
			closeLoading()
		});
	}
}
$( document ).ready(function() {
    $('#rw_no_perkara_manual').hide();
    $('#frm_add_pidana').SubmitHandling({
        refresh:'1',
        setRefresh:1,
        divRef:'#frm_add_pidana',
        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.';
            		error = 1;
            	}
            	var oldVal_tmp = tgl.data('oldVal').substring(2)
				tgl.data('oldVal',  $(this).val() );
				
				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())){
					if(message!=''){
						message = message+'<br/>';
					}
					message = message+'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
					error = 1
				}

				if(error==1){
					message_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}

				if(oldVal_tmp==$(this).val().substring(2)){
					return;
				}else{
					generateNomorPerkara();
				}
				error = 0;

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

var tgl = $('#tgl_pendaftaran');
tgl.data('oldVal',  tgl.val() );

$('#kembali').click(function(){
	window.open("<?php echo $previous;?>","_self");
});
</script>
