<script type="text/javascript">
$(document).ready(function() {	
	$("#tambah").click(function(){
		cari_nomor();				
	});
	
	function cari_nomor(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "modul/jabatan/cari_nomor.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
				$("#txt_nama").focus();				
			}
		});
	}
	
	$("#txt_nama").keyup(function() {
		var nama	= $("#txt_nama").val()
		//var akses	= 1; //1 cari, 2 edit, 3 baru
		$.ajax({
			type	: "POST",
			url		: "modul/jabatan/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 jabatan tidak boleh kosong.");
		   $("#txt_nama").focus();
		   return (false);
         }	 
		  
		if(error == false){
		$.ajax({
			type	: "POST",
			url		: "modul/jabatan/simpan.php",
			data	: "kode="+kode+
					"&nama="+nama,					
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);				
				$(".input").val('');
				$("#tambah").focus();
			}
		});
		}
		return false; 			
	}
	
	$("#keluar").click(function(){
		document.location='?module=home';
	});
});
</script>

<?php
echo "<input type='hidden' id='akses'>";
echo "<table>
	<tr>
		<td>Kode Jabatan</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 Jabatan</td>
		<td>:</td>
		<td><input type='text' name='txt_nama' id='txt_nama' size='20' lenght='20' class='input'></td>
	</tr>	
	</table>
	
	<table width='100%'
	<tr>
		<td colspan='3' align='center'>
		<button name='simpan' id='simpan'>Simpan</button>
		<button name='tambah' id='tambah'>Tambah</button>		
		<button name='keluar' id='keluar'>Keluar</button>
		</td>
	</tr>
	</table>";
?>