<div id="popup_tambah_agenda_bas" class="centering" style="width:1000px;margin-top: 1%;">
	<div class="detil" style="padding: 2px;background-color: white;">
		<table id="tableDetilPerkara" style="font-size:14px;width:100%">
			<col width="20%">
			<col width="80%">
			<tr>
				<td colspan="2" class="header">Tambah Agenda <?php echo $no_urut; ?></td>
			</tr>
			<tr>
				<td>
					Agenda
				</td>
				<td>
					<span class="custom-dropdown custom-dropdown--emerald" style="width:200px">
						<?php 
						$options=array();
						foreach ($jenis_agenda as $row) {
							$options[$row['id']]=$row['nama'];
						}
						$js='id="sl_agenda" style="width:200px" class="custom-dropdown__select custom-dropdown__select--white"';
						echo form_dropdown('jenis_agenda', $options, 'large', $js);
						?>
					</span>
				</td>
			</tr>
			<tr>
				<td>Params</td>
				<td>
					<form id='parameter'>
					</form>
					<input type="hidden" id='generate' value="Generate" class="btn">
				</td>
			</tr>
			<tr>
				<td>Preview Redaksi</td>
				<td>
					<div id='preview_redaksi'></div>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="buttongroup">
					<input type="button" id='tutup_tambah' value="Kembali" class="btn">
					<input type="button" id='simpan_tambah' value="Simpan" class="btn">
				</td>
			</tr>
		</table>
	</div>
</div>
<script type="text/javascript">
var no_urut = <?php echo $no_urut; ?>;
var arr_text={}; 
$('#parameter').change(function(){
	$(this).find('.textarea').hide();
	$(this).find('.cke').hide();
	$('.isian').hide();
	var name_text=($(this).find('#text_'+$(this).children().children().val()).attr('name'));
	$('#cke_'+name_text).fadeIn();
	$(this).find('#lbl_isian_'+$(this).children().children().val()).show();
});
$('#parameter').find('#text_'+$(this).children().children().val()).show();
$('#parameter').find('#lbl_isian_'+$(this).children().children().val()).show();

$('#generate').click(function(){
	arr_text={};
	var str = '';var name1='';var name=''; var isian='';
	if (($('#sl_agenda').val()!='6') && ($('#sl_agenda').val()!='107') && ($('#sl_agenda').val()!='108')){
		if ($('#parameter').children().length > 0){
			$( "#parameter select" ).each(function(){
				str+=($(this).attr('name')+'='+$(this).val())+'&';
				name=$(this).val();
			});	
			$( "#parameter textarea" ).each(function(){
				thisname=$(this).attr('name');
				alert(thisname);
				name1=thisname.split('_');
				name1=name1[1];
				if (name1==name){
					isian=CKEDITOR.instances[thisname].getData();
					arr_text[$(this).attr('name')]=isian;
				}
			});
		}else{
			alert('Data Kosong');
		}
	}
	<?php 
	if($this->session->userdata('jenis_pengadilan')==4){
	?>
		$.post( "<?php echo base_url('setting_bas_agama_c/get_preview'); ?>", { enc:'<?php echo $enc;?> ', param: str, agenda_id:$('#sl_agenda :selected').val(), no_urut:no_urut, isian:isian  }).done(function( data ) {
			$('#preview_redaksi').html(data);
		});
	<?php
	}else{
	?>
		$.post( "<?php echo base_url('setting_bas_c/get_preview'); ?>", { enc:'<?php echo $enc;?> ', param: str, agenda_id:$('#sl_agenda :selected').val(), no_urut:no_urut, isian:isian  }).done(function( data ) {
			$('#preview_redaksi').html(data);
		});
	<?php
	}
	?>
});
$("#sl_agenda").change(function() {
	if($(this).val()=='6' ){
		$('#preview_redaksi').append("<table class='cssTable' id='table_hasil_pemeriksaan_saksi'> <tr><td>No.</td><td>Sumber</td><td>Penanya</td><td>Pertanyaan</td><td>Jawaban</td><td>Keterangan</td><td></td></tr></table>");
		$('#generate').fadeOut();
	}else if($(this).val()=='7' ){
		$('#preview_redaksi').append("<table class='cssTable' id='table_hasil_pemeriksaan_terdakwa'> <tr><td>No.</td><td>Sumber</td><td>Penanya</td><td>Pertanyaan</td><td>Jawaban</td><td>Keterangan</td><td></td></tr></table>");
		$('#generate').fadeOut();
	}else if($(this).val()=='107' ){
		$('#preview_redaksi').append("<table class='cssTable' id='table_hasil_pemeriksaan_saksi_tun'> <tr><td>No.</td><td>Sumber</td><td>Penanya</td><td>Pertanyaan</td><td>Jawaban</td><td>Keterangan</td><td></td></tr></table>");
		$('#generate').fadeOut();
	}else if($(this).val()=='108' ){
		$('#preview_redaksi').append("<table class='cssTable' id='table_hasil_pemeriksaan_saksi_tun'> <tr><td>No.</td><td>Sumber</td><td>Penanya</td><td>Pertanyaan</td><td>Jawaban</td><td>Keterangan</td><td></td></tr></table>");
		$('#generate').fadeOut();
	}else{
		$('#table_hasil_pemeriksaan_saksi').remove();
		$('#table_hasil_pemeriksaan_terdakwa').remove();
		$('#generate').fadeIn();
	};
	$.post( '<?php echo base_url('setting_bas_c/get_agenda_param');?>', { 
		agenda_id: $('#sl_agenda').val() }).done(function( data ) {
    	$('#parameter').empty();
    	$(data).appendTo( "#parameter" );
    	if($("#sl_agenda").val()!='14' ){
    		$('#ckdiv').hide();
    	}
    	$('.options_ck').change(function(){
			$('#ckdiv').show();
		})
  	});
  	
});
$("#tutup_tambah").click(function() {
	$('#form_pop_2nd').fadeIn();
	$('#popup_form_3rd').empty();
	$('#popup_form_3rd').fadeOut();
});
$("#simpan_tambah").click(function() {
	$('#generate').click();
	var arr_opsi=[];
	var agenda_id=$('#sl_agenda :selected').val();
	$('#parameter .dynamic').each(function(){
		arr_opsi.push($(this).val());
	});
	$("#table_agenda").each(function () {
        var tds = '<tr><td><?php echo $no_urut; ?></td>';
        tds += '<td>';
        tds += $('#sl_agenda option:selected').text();
        tds += '</td><td hidden><label class="konten">';
        tds += $('#preview_redaksi').html()+'</label>';
        tds += '<input type="text" name="agenda_id[]" value="'+agenda_id+'">';
        if($('#sl_agenda').val()=='6' || $('#sl_agenda').val()=='107' || $('#sl_agenda').val()=='108'){
        	tds += '<input type="text" name="id[]" value="'+$('#saksi_agenda_id').val()+'">';
        }else if($('#sl_agenda').val()=='7'){
        	tds += '<input type="text" name="id[]" value="'+$('#terdakwa_agenda_id').val()+'">';
        }else{
        	if($('#sl_agenda').val()=='13'){
        		$('#parameter .fixed').each(function(){
					//arr_opsi.push($(this).val());
					tds += '<input type="text" name="'+$(this).attr('name')+'" value="'+$(this).val()+'">';
				});
        	}
	        for (i = 0; i < arr_opsi.length; i++) {
			    tds += '<input type="text" name="id[]" value="'+arr_opsi[i]+'">';
			}
			$.each(arr_text, function( index, value ) {
			  alert( index + ": " + value );
			  tds += '<textarea type="text" name="'+index+'" >'+value+'</textarea>';
			});	
        }
        tds += '</td><td>[<a ahref="" class="delete_agenda">hapus</a>]</td></tr>';
        if ($('tbody#bd_table_agenda', this).length > 0) {
            $('tbody#bd_table_agenda', this).append(tds);
        } else {
            $(this).append(tds);
        }
     });
	$('#form_pop_2nd').fadeIn();
	$('#popup_form_3rd').fadeOut();
	$('#popup_form_3rd').remove();
});

$(document).ready(function(){
	$('#sl_agenda').val(1).trigger('change');
})
</script>