<script type="text/javascript">
$(document).ready(function() {
	
	$("#mulai").click(function(){
		cari_nomor();
	});
	
	function cari_nomor(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url	    : "modul/st_group/cari_nomor.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
				$("#txt_nama").focus();
				tampil_data_detail();
			}
		});
	}
	
	$("#txt_nama").keyup(function() {
		var nama	= $("#txt_nama").val()

		$.ajax({
			type	: "POST",
			url		: "modul/st_group/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	kode	= $("#txt_kode").val();
		var	nama	= $("#txt_nama").val();				
		var 	error = false;
		
		if(nama.length == 0){
			var error = true;
			alert("Maaf, Nama kelompok tidak boleh kosong");
			$("#txt_nama").focus();
			return (false);
         }
		 		 
		if(error == false){
		$.ajax({
			type	: "POST",
			url	: "modul/st_group/simpan.php",
			data	: "kode="+kode+
					"&nama="+nama,				
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				cari_nomor();
				$(".input").val('');				
				$("#txt_nama").focus();				
			}
		});
		}
		return false; 			
	}
	
	$("#keluar").click(function(){
		document.location='?module=home';
	});
});
</script>

<?php
echo "<input type='hidden' id='akses'>";
echo "<table>
	<tr>
		<td>Kode Kelompok</td>
		<td>:</td>
		<td><input type='text' name='txt_kode' id='txt_kode'  size='8' lenght='8' value='$kode' class='input' readonly /></td>
	</tr>
	<tr>
		<td>Nama Kelompok</td>
		<td>:</td>
		<td><input type='text' name='txt_nama' id='txt_nama'  size='40' lenght='50' class='input'></td>
	</tr>	
	</table>
	
	<table width='100%'>
	<tr>
		<td colspan='3' align='center'>
			<button name='simpan' id='simpan'>Simpan</button>
			<button name='mulai' id='mulai'>Buat Data</button>
			<button name='keluar' id='keluar'>Keluar</button>
		</td>
	</tr>
	</table>";
?>