<script type="text/javascript">
$(document).ready(function() {	
	$("#txt_nogol").click(function(){
		cari_nomor();
	});
	
	function cari_nomor(){
		var tnokel = $("#txt_nokel").val();
		
		if (tnokel.length==0){
			alert("Maaf, Kelompok belum dipilih.");
			$("#txt_nokel").focus();
			return (false);
		}
		
		$.ajax({
			type	: "POST",
			url	: "modul/gol_akun/cari_nomor.php",
			data	: "tnokel="+tnokel,
			dataType: "json",
			success	: function(data){
				$("#txt_nokel").val(tnokel);
				$("#txt_nogol").val(data.nomor);
				$("#txt_nagol").focus();
			}
		});
	}
	
	$("#txt_nama").keyup(function() {
		var nama	= $("#txt_nama").val()

		$.ajax({
			type	: "POST",
			url	: "modul/gol_akun/cari.php",
			data	: "nama="+nama,
			dataType	: "json",
			success	: function(data){
				$("#txt_nama").val(data.namadep);				
				$("#akses").val(data.akses);
			}
		});
	});
	
	$("#simpan").click(function(){
		simpan_data();
		return false;
	});

	function simpan_data(){
		var	tnokel	= $("#txt_nokel").val();
		var	tnogol	= $("#txt_nogol").val();
		var	tnagol	= $("#txt_nagol").val();
		var	tkode	= $(".radio_kode:checked").val();
		var 	cek_kode = $(".radio_kode:checked");
		var 	error 	= false;
		
		if(tnokel.length == 0){
			var error = true;
			alert("Maaf, Kelompok belum dipilih.");
			$("#txt_nokel").focus();
			return (false);
        }
		
		if(tnogol.length == 0){
			var error = true;
			alert("Maaf, Kode golongan tidak boleh kosong.");
			$("#txt_nogol").focus();
			return (false);
        }
		
		if(tnagol.length == 0){
			var error = true;
			alert("Maaf, Nama golongan tidak boleh kosong.");
			$("#txt_nagol").focus();
			return (false);
        }
		 
		if(cek_kode.length == 0){
			var error = true;
			alert("Maaf, Anda belum menentukan saldo normal.");
			$("#radio_kode").focus();
			return (false);
         }
		  
		if(error == false){
		$.ajax({
			type	: "POST",
			url	: "modul/gol_akun/simpan.php",
			data	: "tnogol="+tnogol+
					"&tnagol="+tnagol+
					"&tnokel="+tnokel+
					"&tkode="+tkode,
					
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$("#akses").val(1);
				$(".input").val('');
			}
		});
		}
		return false; 			
	}
	
	$("#keluar").click(function(){
		document.location='?module=home';
	});
});
</script>

<?php
echo "<input type='hidden' id='akses'>";
echo "<table>
	<tr>
		<td>Kelompok</td>
		<td>:</td>
		<td><select name='txt_nokel' id='txt_nokel' >
			<option value='' selected>-Pilih-</option>
			<option value='1'> 1 - AKTIVA</option>
			<option value='2'> 2 - HUTANG</option>
			<option value='3'> 3 - MODAL</option>
			<option value='4'> 4 - PENDAPATAN</option>
			<option value='5'> 5 - BIAYA</option>
			<option value='6'> 6 - NON USAHA</option>
			<option value='7'> 7 - IKHTISAR LABA RUGI</option>
			</select>
		</td>
	</tr>
	
	<tr>
		<td>Kode Golongan</td>
		<td>:</td>
		<td><input type='text' name='txt_nogol' id='txt_nogol' size='2' class='input'></td>
	</tr>
	<tr>
		<td>Nama Golongan</td>
		<td>:</td>
		<td><input type='text' name='txt_nagol' id='txt_nagol' size='30' class='input'></td>
	</tr>		
	</table>
	
	<table width='40%' align='left'>
	<tr>
		<td width='36.5%'>Saldo Normal</td>
		<td>:</td>
		<td><input type='radio' name='txt_kode' id='radio_kode' value='D' class='radio_kode'>DEBET</td>
		<td><input type='radio' name='txt_kode' id='radio_kode' value='K' class='radio_kode'>KREDIT</td>
	</tr>
	</table>
	
	<table width='100%'
	<tr>
		<td colspan='3' align='center'>
		<button name='simpan' id='simpan'>Simpan</button>
		<button name='keluar' id='keluar'>Keluar</button>
		</td>
	</tr>
	</table>";
?>