<div class="centering" style="width:85%;margin-top: 2%;">
	<div id='keterangan_saksi' style="border: 1px solid #ffffff;">

		<div class="cssTable" style="padding: 2px;background-color: white;">
        <table id='tableDetilPerkara' style="font-size:14px;">
			<col width="45%">
			<col width="55%">
				<tbody>
				<tr>
					<td style="padding:4px;background:white;font-size:16px;color:#111;" align="center" colspan="2"><strong><?php echo $namahalaman; ?></strong></td>
				</tr>
		</table>
		<div style="position:fix;">	
		<div style="float:left">
		    <input type="radio" name="penanya" id="hakim_penanya" value="1" checked> Hakim 
		    <span class="custom-dropdown custom-dropdown--emerald">
		        <select style='width:200px;'  name="hakim_id" id="hakim"  class="custom-dropdown__select custom-dropdown__select--white">                                
					<?php 
						echo "<option value='1'>Hakim Ketua</option>";
						for ($i=2; $i <= $jml_hakim ; $i++) { 						
							echo "<option value=".$i.">Hakim Anggota ".$i."</option>";
						}
					?>
		        </select>
		    </span><br>
		    <input type="radio" name="penanya" id="jaksa" value="6"> Penuntut Umum<br>
		    <input type="radio" name="penanya" id="pengacara" value="7"> Penasihat Hukum  <br>
  	  </div>
  	  
  	  <div style="float:right;margin-right:30%">
  	  	Bertanya kepada Terdakwa :
		    <span class="custom-dropdown custom-dropdown--emerald">
		        <select style='width:300px;'  name="terdakwa" id="terdakwa"  class="custom-dropdown__select custom-dropdown__select--white">                                
					<?php 
						if(!empty($terdakwa)){
							echo "<option value=''>--Pilih Terdakwa--</option>";
							foreach ($terdakwa->result() as $row) {
								echo "<option value=".$row->id.">".$row->nama."</option>";
							}
						}
					?>
		        </select>
		    </span>  	  		
		</div>
		</div>
		<div><br>
		<div id="divtanyajawab">
		<table id="tanyajawab" width="100%" style="overflow:auto;" class="table" border="1" cellpadding="0" cellspacing="0">
			<tr >
			<th width='5%'>No.</th><th width='5%'>Aksi</th><th width='45%'>Pertanyaan</th><th width='45%'>Jawaban</th>
			</tr>
		    <tr >
		    	<td height='30'><div id='data_id1' ketid1="">1</div></td>
		    	<td height='30'><div id='q_hapus1' contenteditable='false' class='hapus'></div></td>
		    	<td height='30'><div id='q_tanya1' contenteditable class='tanya'></div></td>
		    	<td height='30'><div id='q_jawab1' contenteditable class='jawab'></div></td>
		    	
		    </tr>

		</table>
		<div style="font-size:11px;color:red;">Pilih Terdakwa dan tekan Tombol TAB untuk memulai mengisi Tanya Jawab Terdakwa</div>
		</div>
		</div>
			<div style="text-align:center;"><input type="button" id="close_keterangan_saksi" value="Tutup" style="text-decoration:none" class="del_btn"></div>
		</div>
	</div>
	</div>
</div>

<script type="text/javascript">

<?php 
if($this->session->userdata('jenis_pengadilan')==1){
?>
    $('#close_keterangan_saksi').click(function(){
        window.open("<?php echo base_url('perkara_detil/'.$enc.'/4');?>","_self");    
    });
<?php
}else if($this->session->userdata('jenis_pengadilan')==2){
?>
    $('#close_keterangan_saksi').click(function(){
        window.open("<?php echo base_url('perkara_detil_mil/'.$enc.'/4');?>","_self");    
    });    
<?php
}else if($this->session->userdata('jenis_pengadilan')==3){
?>
    $('#close_keterangan_saksi').click(function(){
        window.open("<?php echo base_url('perkara_detil_tun/'.$enc.'/4');?>","_self");    
    });
<?php
}else if($this->session->userdata('jenis_pengadilan')==4){
?>
    $('#close_keterangan_saksi').click(function(){
        window.open("<?php echo base_url('perkara_detil_agama/'.$enc.'/4');?>","_self");    
    });        
<?php
}else{
?>
    $('#close_keterangan_saksi').closingFormWin();
<?php
}
?> 

$(document).ready(function() {	
	$(document).on("focus",'#tanyajawab tr:last-child td:last-child',function() {
		//append the new row here.
		var table = $("#tanyajawab");
		var table_len = $('#tanyajawab tr').length;
		table.append("<tr>\
			<td height='30'><div id='data_id"+table_len+"' ketid"+table_len+"='' >"+table_len+"</div></td>\
			<td height='30'><div id='q_hapus"+table_len+"' ></div><a href='#' id='hapus' style='color:red'>Hapus</a></td>\
			<td height='30'><div id='q_tanya"+table_len+"' contenteditable class='tanya'></div></td>\
			<td height='30'><div id='q_jawab"+table_len+"' contenteditable class='jawab'></div></td>\
			</tr>");
	});

	$("#terdakwa,#hakim,#jaksa,#pengacara,#hakim_penanya").change(function () {
		var terdakwa = $('#terdakwa').val();
    	var penanya = $('input[name=penanya]:checked').val();
    	var hakim = $('#hakim').val();
    	var terdakwa = $('#terdakwa').val();
    	var enc = "<?php echo $enc;?>";
    	var sidang_id = "<?php echo $idjadwal;?>";
		var namahalaman = "<?php echo $namahalaman;?>";		
		$.post('<?php echo base_url()?>data_persidangan_c/show_tanya_jawab_terdakwa', {
			penanya:penanya,
			hakim:hakim,
			terdakwa:terdakwa,
			enc:enc,
			sidang_id:sidang_id,
			namahalaman:namahalaman
		}, function(response){
			var json = jQuery.parseJSON(response);
			events = '';
			if(json.st==1){
				$("#divtanyajawab").html(json.datatnyjawab);
				$('table#tanyajawab div').attr('contenteditable', true);
				$('table#tanyajawab tr:last td:last-child div').focus();				
			}else{
				$("#divtanyajawab").html(json.datatnyjawab);
			 	if(terdakwa>0){
			 		$('table#tanyajawab div').attr('contenteditable', true);
			 		$('table#tanyajawab tr:last td:nth-child(3) div').focus();
			 	}else{
			 		$('table#tanyajawab div').attr('contenteditable', false);
			 	}
			}		
		});


	});	

    $(document).on('blur',"div.jawab", function() {
    	var rowin = $(this).closest('tr').index();
    	var row_index = $('#tanyajawab tr').index()-1;
    	var tanya = $('#q_tanya'+rowin).html();
    	var jawab = $('#q_jawab'+rowin).html();
    	var penanya = $('input[name=penanya]:checked').val();
    	var hakim = $('#hakim').val();
    	var terdakwa = $('#terdakwa').val();
    	var enc = "<?php echo $enc;?>";
    	var sidang_id = "<?php echo $idjadwal;?>";
		var namahalaman = "<?php echo $namahalaman;?>";
    	var iddata = $('#data_id'+rowin).attr('ketid'+rowin);

		$.post('<?php echo base_url()?>data_persidangan_c/input_data_terdakwa', {
			tanya:tanya,
			jawab:jawab,
			penanya:penanya,
			hakim:hakim,
			terdakwa:terdakwa,
			enc:enc,
			sidang_id:sidang_id,
			data_id:iddata,
			namahalaman:namahalaman
		}, function(response){
		});
    });

	$(document).on('click','#hapus',function(){
    	var rowin = $(this).closest('tr').index();
    	var iddata = $('#data_id'+rowin).attr('ketid'+rowin);

    	var tanya = $('#q_tanya'+rowin).html();
    	var jawab = $('#q_jawab'+rowin).html();
    	var penanya = $('input[name=penanya]:checked').val();
    	var hakim = $('#hakim').val();
    	var terdakwa = $('#terdakwa').val();
    	var enc = "<?php echo $enc;?>";
    	var sidang_id = "<?php echo $idjadwal;?>";
		var namahalaman = "<?php echo $namahalaman;?>";		

		$.post('<?php echo base_url()?>data_persidangan_c/hapus_data_ket_terdakwa', {
			tanya:tanya,
			jawab:jawab,
			penanya:penanya,
			hakim:hakim,
			terdakwa:terdakwa,
			enc:enc,
			sidang_id:sidang_id,	
			data_id:iddata,
			namahalaman:namahalaman
		}, function(response){
			var json = jQuery.parseJSON(response);
			events = '';
			if(json.st==1){
				var terdakwa = $('#terdakwa').val();
		    	var penanya = $('input[name=penanya]:checked').val();
		    	var hakim = $('#hakim').val();
		    	var terdakwa = $('#terdakwa').val();
		    	var enc = "<?php echo $enc;?>";
		    	var sidang_id = "<?php echo $idjadwal;?>";	
				var namahalaman = "<?php echo $namahalaman;?>";						
				$.post('<?php echo base_url()?>data_persidangan_c/show_tanya_jawab_terdakwa', {
					penanya:penanya,
					hakim:hakim,
					terdakwa:terdakwa,
					enc:enc,
					sidang_id:sidang_id,
					namahalaman:namahalaman
				}, function(response){
					var json = jQuery.parseJSON(response);
					events = '';
					if(json.st==1){
						$("#divtanyajawab").html(json.datatnyjawab);
						$('table#tanyajawab div').attr('contenteditable', true);
						$('table#tanyajawab tr:last td:last-child div').focus();				
					}else{
						$("#divtanyajawab").html(json.datatnyjawab);
					 	if(terdakwa>0){
					 		$('table#tanyajawab div').attr('contenteditable', true);
					 		$('table#tanyajawab tr:last td:nth-child(3) div').focus();
					 	}else{
					 		$('table#tanyajawab div').attr('contenteditable', false);
					 	}
					}		
				});


			}		
		});
	    
	});

});


//
</script>