<hr class="thick-line" style="clear:both;">
<div style="margin: 0 auto;top: 10%;margin-top: 1%;margin-bottom: 25px;">
	<div class="detil" style="background-color:white;border-color: white;margin-top:25px;width: 60%;margin: 0 auto;">
			<form id="frm_lalulintas" style="background:white;margin:0;" method="post" action="<?php echo base_url().'add_lalulintas/validateInput';?>">
				<table id="tableDetilPerkara" style="font-size:14px;">
					<col width="30%">
					<col width="70%">
					<tbody>
						<tr>
							<td style="color:white;">Tanggal Pendaftaran <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="hidden" id="previous" name="previous" value="<?php echo $previous; ?>">
								<input type="hidden" id="curr_date" name="curr_date" value="<?php echo $curr_date; ?>">
								<input type="text" id='tanggal_pelimpahan' class="datepicker" placeholder="tgl/bln/tahun" name='tanggal_pelimpahan' class="standard-input" maxlength="10">
							</td>
						</tr>
						<tr>
							<td style="color:white;">Tanggal Penetapan Hakim <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='tanggal_penetapan_hakim' class="datepicker" placeholder="tgl/bln/tahun" name='tanggal_penetapan_hakim' class="standard-input" maxlength="10">
							</td>
						</tr>
						<tr>
							<td style="color:white;">Nama Hakim <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px">
								<span class="custom-dropdown custom-dropdown--emerald" style="border:1px #ddd solid;  width:250px;">
								<select name="hakim" id="hakim" onchange="" style="width:250px;" class="custom-dropdown__select custom-dropdown__select--white">
									<option id="hakim" value="-1" selected> Pilih Hakim</option>
										<?php
											if($hakim_list!=''){
												if($hakim_list->num_rows>0){
													$id = '0';
								    				foreach ($hakim_list->result() as $row) {
								    					echo '<option value="'.$row->id.'|'.$row->nama_gelar.'">'.$this->templatehelper->standradnaming($row->nama_gelar).'</option>';
								    				}
								    			}
								    		}
										?>
										
								</select>
							</span>
							</td>
						</tr>
						<tr>
							<td style="color:white;">Tanggal Penunjukan Panitera <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='tanggal_penetapan_panitera' class="datepicker" placeholder="tgl/bln/tahun" name='tanggal_penetapan_panitera' class="standard-input" maxlength="10">
							</td>
						</tr>
						<tr>
							<td style="color:white;">Nama Panitera <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald"  style="border:1px #ddd solid;  width:250px;">
								<select name="panitera" id="panitera" onchange="" style="width:250px;" class="custom-dropdown__select custom-dropdown__select--white">
									<option id="panitera" value="-1" selected> Pilih Panitera</option>
										<?php
											if($panitera_list!=''){
												if($panitera_list->num_rows>0){
													$id = '0';
								    				foreach ($panitera_list->result() as $row) {
								    					echo '<option value="'.$row->id.'|'.$row->nama_gelar.'">'.$this->templatehelper->standradnaming($row->nama_gelar).'</option>';
								    				}
								    			}
								    		}
										?>
										
								</select>
							</span>
							</td>
						</tr>
						<tr>
							<td style="color:white;">Tanggal Penetapan Hari Sidang <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='tanggal_penetapan_sidang' class="datepicker" placeholder="tgl/bln/tahun" name='tanggal_penetapan_sidang' class="standard-input" maxlength="10">
							</td>
						</tr>
						<tr>
							<td style="color:white;">Tanggal Sidang <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='tanggal_sidang' class="datepicker" placeholder="tgl/bln/tahun" name='tanggal_sidang' class="standard-input" maxlength="10">
							</td>
						</tr>
						<tr>
							<td style="color:white;">Ruang Sidang <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald"  style="border:1px #ddd solid; width:250px;">
								<select name="ruang_sidang" id="ruang_sidang" onchange="" style="width:250px;" class="custom-dropdown__select custom-dropdown__select--white">
									<option id="ruang_sidang" value="-1" selected> Pilih Ruang Sidang</option>
										<?php
											if($ruangan_sidang!=''){
												if($ruangan_sidang->num_rows>0){
													foreach ($ruangan_sidang->result() as $row) {
								    					echo '<option value="'.$row->id.'|'.$row->nama.'">'.$this->templatehelper->standradnaming($row->nama).'</option>';
								    				}
								    			}
								    		}
										?>
								</select>
							</span>
							</td>
						</tr>
						<tr>
							<td style="color:white;">Kejaksaan Tinggi <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald"  style="border:1px #ddd solid; width:250px;">
								<select name="select_kejati" id="select_kejati" onchange="" style="width:250px;" class="custom-dropdown__select custom-dropdown__select--white">
									<option id="kejati" value="-1" selected> Pilih Kejaksaan Tinggi</option>
										<?php
											if($kejati_list!=''){
												if($kejati_list->num_rows>0){
													foreach ($kejati_list->result() as $row) {
								    					echo '<option id="kejati" value="'.$row->kode.'">'.$this->templatehelper->standradnaming($row->nama).'</option>';
								    				}
								    			}
								    		}
										?>
								</select>
							</span>
							</td>
						</tr>
						<tr>
							<td style="color:white;">Kejaksaan Negeri <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald"  style="border:1px #ddd solid; width:250px;">
								<select name="select_kejari" id="select_kejari" onchange="" style="width:250px;" class="custom-dropdown__select custom-dropdown__select--white" disabled>
									<option id="kejari" value="-1" selected> Pilih Kejaksaan Negeri</option>
										<?php
											if($kejari_list!=''){
												if($kejari_list->num_rows>0){
													foreach ($kejari_list->result() as $row) {
								    					echo '<option class="kejari" id="kejari_'.$row->kode_kejati.'" value="'.$row->kode_kejati.'.'.$row->kode_kejari.'">'.$this->templatehelper->standradnaming($row->nama_instansi).'</option>';
								    				}
								    			}
								    		}
										?>
								</select>
							</span>
							</td>
						</tr>
						<tr>
							<td style="color:white;">Ditilang Oleh <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<span class="custom-dropdown custom-dropdown--emerald"  style="border:1px #ddd solid;  width:250px;">
								<select name="tilang_oleh" id="tilang_oleh" onchange="" style="width:250px;" class="custom-dropdown__select custom-dropdown__select--white">
									<option value="-1" selected>Pilih</option>
									<option value="1">Polisi</option>
									<option value="2">Dinas Perhubungan</option>
									<option value="3">Lainnya</option>
								</select>
							</span>
							</td>
						</tr>
						<tr>
							<td style="color:white;">Jumlah Perkara <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="text" id='jumlah_perkara' name='jumlah_perkara'  onkeypress="return numbersonly(event)" class="standard-input" style="width:20%" maxlength="20"> Perkara
							</td>
						</tr>
						<tr style="color:white;">
							<td>Upload Data <font color="red">*</font></td>
							<td style="padding:0px;padding-left:5px;">
								<input type="file" id="import" name="import" class="standard-input" size="100" />
							</td>
						</tr>
						<tr>
							<td colspan="2" style="background:white;" align="center">
								<input type="button" id="kembali" value="Kembali" class="btn">
								<input type="submit" id="simpan" name="simpan" value="Simpan" class="btn">
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
$('#kembali').click(function(){
	window.open("<?php echo $previous;?>","_self");
});

function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	    if (unicode!=8){ 
	        if (unicode<48||unicode>57) 
	        return false
	    }
}
$('form').on('submit', uploadFiles);

function uploadFiles(event){
	openLoadingDialog()
	event.stopPropagation();
    event.preventDefault();
    var formData = new FormData($(this)[0]);
    var file = $(':file')[0].files[0];
	if($(':file').val()!=''){
		if(file.type!='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' && file.type!='application/vnd.ms-excel'){
			closeLoading()
			message_error_show('File Format E-Document Tidak Diizinkan. System Hanya Mengizinkan File dengan Format: Ms. Excel');
			event.preventDefault();
			return;
		}
		$.ajax({
			url: "<?php echo base_url('add_lalulintas/uploadFileExcel');?>",
			type: 'POST',
			dataType: "json",
			xhr: function() {
				var myXhr = $.ajaxSettings.xhr();
				if(myXhr.upload){
					myXhr.upload.addEventListener('progress',progressHandlingFunction, false); 
				}
				return myXhr;
			},
			success: function (jsonup) {
				if (jsonup.st==0) {
					status = 0;
					message_error_show(jsonup.msg);
					event.preventDefault();
					return;
				}else if (jsonup.st==1){
					var values = $('form').serializeArray();
					values = jQuery.param(values);
					$.post($('form').attr('action'),values, function(json){
						closeLoading()
						if(json.st==1){
							$('<div id="popup_msg" class="popup"><div class="centering"><table class="pesan"><tr style="background-color: #5FB85C;"><td align="center" style="padding:5px;" id="test">Pesan</td><td id="tutup_windows" class="tutup_windows" align="center" style="padding:5px;" width="50">tutup</td></tr><tr><td style="padding:5px;" colspan="2"><div id="pesan-container"></div></td></tr></table></div></div>').appendTo( "body" );
							$('#tutup_windows').closingDiv({
		                        clicked:1,
		                        btnClicked:'#kembali',
		                        whenStatus:1,
		                        st:1
		                    });
							$('#pesan-container').html(json.msg);
							$('#popup_msg').show();
						}
						else{
							status = 0;
							message_error_show(json.msg);
							event.preventDefault();
							return;
						}
					},'json');
				}
			},
			data: formData,
			cache: false,
			contentType: false,
			processData: false
		});
	}
}

$('.datepicker').ValidateDateInput();

$( document ).ready(function() {
	$(this).change(function(e) {
		var val = $('#'+e.target.id).val();
	    if(e.target.id=='select_kejati') {
			 var jenis_kejati = $('#select_kejati').val();
			 $('#select_kejari').prop('disabled', false);
			 $("#select_kejari").val('-1');
			 $("#select_kejari").focus();
    	     $('.kejari').show();
	    	 $('.kejari').not('#kejari_'+jenis_kejati).hide();
		}
		if(e.target.id=='select_kejari') {
			 var pt_id = $('#select_kejari').val();
		}
	});


    $( function() {
        $('#tanggal_pelimpahan').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(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.';
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}
        });


		$('#tanggal_penetapan_hakim').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(message);
            		return;
            	}
				
				var tmp = $('#tanggal_penetapan_hakim').val().split("/");
				var tmp2 = $('#tanggal_pelimpahan').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 Kurang dari Tanggal Pendaftaran.';
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}
        });

		$('#tanggal_penetapan_panitera').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(message);
            		return;
            	}
				
				var tmp = $('#tanggal_penetapan_panitera').val().split("/");
				var tmp2 = $('#tanggal_pelimpahan').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 Kurang dari Tanggal Pendaftaran.';
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}
        });


		$('#tanggal_penetapan_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 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(message);
            		return;
            	}
				
				var tmp = $('#tanggal_penetapan_sidang').val().split("/");
				var tmp2 = $('#tanggal_pelimpahan').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 Kurang dari Tanggal Pendaftaran.';
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}
        });

		$('#tanggal_penetapan_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 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(message);
            		return;
            	}
				
				var tmp = $('#tanggal_penetapan_sidang').val().split("/");
				var tmp2 = $('#tanggal_pelimpahan').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 Kurang dari Tanggal Pendaftaran.';
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}
        });

		$('#tanggal_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 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(message);
            		return;
            	}
				
				var tmp = $('#tanggal_sidang').val().split("/");
				var tmp2 = $('#tanggal_penetapan_sidang').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 Kurang dari Tanggal Penetapan Persidangan.';
					message_error_show(message);
					$(this).css("background-color", "red");
				}else{
					$(this).css("background-color", "#dedbdb");
				}
			}
        });
		
    $('input,select').not('#simpan').keypress(function(event) { return event.keyCode != 13; });
    });
});


$('#frm_lalulintas').on('click', '#simpan', function(event) {
	if($('#tanggal_pelimpahan').val()==''){
		message_error_show('Tanggal Pendaftaran Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#tanggal_penetapan_hakim').val()==''){
		message_error_show('Tanggal Penetapan Hakim Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#hakim').val()=='-1'){
		message_error_show('Pilih Hakim');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#tanggal_penetapan_panitera').val()==''){
		message_error_show('Tanggal Penunjukan Panitera Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#panitera').val()=='-1'){
		message_error_show('Pilih Panitera');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#tanggal_penetapan_sidang').val()==''){
		message_error_show('Tanggal Penetapan Hari Sidang Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#tanggal_sidang').val()==''){
		message_error_show('Tanggal Sidang Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#ruang_sidang').val()=='-1'){
		message_error_show('Pilih Ruang Sidang');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#select_kejari').val()=='-1'){
		message_error_show('Pilih Kejaksaan Negeri');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#tilang_oleh').val()=='-1'){
		message_error_show('Pilih Ditilang Oleh');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#jumlah_perkara').val()==''){
		message_error_show('Jumlah Perkara Kosong');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}

	if($('#import').val()==''){
		message_error_show('Pilih File Excel');
		$(this).css("background-color", "red");
		event.preventDefault();
		return;
	}
});
</script>