<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.barang tr:even").addClass("stripe1");
        $("#theList.barang tr:odd").addClass("stripe2");

		$("#theList.barang tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function pilih(ID){
		var kode = ID;
		var tkas  	= $("#txt_kas").val();
		var tpiut 	= $("#txt_piut").val();
		var tutdg 	= $("#txt_utdg").val();
		var tutbg 	= $("#txt_utbg").val();
				
		if(kode==tkas){
			alert('Maaf, kode '+kode+' adalah akun Kas Besar, tidak bisa dibuat Buku Pembantu karena  dipakai untuk transaksi Kas.')
			return (false);
		}
			
		$.ajax({
			type	: "POST",
			url		: "modul/akun_bp/cari_bb.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nobb").val(kode);
				$("#txt_nabb").val(data.nabb);
				$("#txt_kode").val(data.tkode);
				$("#txt_tahun").val(data.ttahun);
				$("#form_cari_bb").dialog('close');
				cari_nomor();
			}
		});
	}
	
	function cari_nomor(){
		var kode = $("#txt_nobb").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/akun_bp/cari_nomor.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_noakun").val(data.nomor);
				$("#txt_noakun").focus();
			}
		});
	}
</script>

<?php
include '../../inc/inc.koneksi.php';
$cari = $_GET['cari'];

echo "<table id='theList' class='barang' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Akun</th>
			<th>D/K</th>
			<th>Ambil</th>
		</tr>";
		
		if (!empty($cari)){
			$sql	= "SELECT * FROM akun_bb WHERE (naakun LIKE '%$cari%' OR noakun LIKE '%$cari%') AND level='2' ORDER by noakun";		
		}
		else{
			$sql	= "SELECT * FROM akun_bb WHERE level='2' ORDER by noakun";
		}
				
		$query = mysql_query($sql);
		$jml_data = mysql_num_rows($query);
		$no=1;
		while($r_data=mysql_fetch_array($query)){
			echo "<tr>
					<td align='center'>$no</td>
					<td>$r_data[noakun]</td>
					<td>$r_data[naakun]</td>
					<td>$r_data[kode]</td>
					<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r_data[noakun]')\">
					<img src='icon/download.gif' border='0' id='tambah_data' title='Pilih' width='12' height='12' >
					</a>					
					</td>
					</tr>";
			$no++;
		}
		
	echo "</table>";
?>
