<script type="text/javascript">
$(document).ready(function() {
	cari_nomor();
	$("#txt_nama").focus();

	function cari_nomor(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url	: "modul/supplier/cari_nomor.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
				tampil_data_detail();
			}
		});
	}
	
	$("#txt_nama").keyup(function() {
		var nama	= $("#txt_nama").val()
		
		$.ajax({
			type	: "POST",
			url	: "modul/supplier/cari.php",
			data	: "nama="+nama,
			dataType	: "json",
			success	: function(data){
				$("#txt_nama").val(data.nama);
				$("#akses").val(data.akses);				
			}
		});
	});
	
	$("#simpan").click(function(){
		simpan_data();
	});

	function simpan_data(){
		var	kode	= $("#txt_kode").val();
		var	nama	= $("#txt_nama").val();
		var	alamat  = $("#txt_alamat").val();
		var	telepon = $("#txt_telepon").val();
		var	fax	    = $("#txt_fax").val();
		var	bank	= $("#txt_bank").val();
		var	nomorac = $("#txt_nomorac").val();
		var	namaac  = $("#txt_namaac").val();
		var	kontak  = $("#txt_kontak").val();
		
		var error = false;
		
		alert('kode '+kode+' nama '+nama+' alamat '+alamat+' telp '+telepon+' fax '+fax+' bank '+bank+' noac '+nomorac+' naac '+namaac+' kont '+kontak);

		if(nama.length == 0){
			var error = true;
			alert("Maaf, Nama kabupaten tidak boleh kosong");
			$("#txt_nama").focus();
			return (false);
        }	 
		 
		if(error == false){
		$.ajax({
			type	: "POST",
			url	    : "modul/supplier/simpan.php",
			data	: "kode="+kode+
					"&nama="+nama+
					"&alamat="+alamat+
					"&telepon="+telepon+
					"&fax="+fax+					
					"&bank="+bank+
					"&nomorac="+nomorac+
					"&namaac="+namaac+
					"&kontak="+kontak,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$("#tampil_data").load('modul/supplier/tampil_data.php');
				cari_nomor();
				$(".input").val('');
				$(".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 Supplier</td>
		<td>:</td>
		<td><input type='text' name='txt_kode' id='txt_kode' size='4' lenght='4' value='$kode' class='input' readonly /></td>
	</tr>
	<tr>
		<td>Nama Supplier</td>
		<td>:</td>
		<td><input type='text' name='txt_nama' id='txt_nama'  size='30' lenght='30' class='input'></td>
	</tr>
	<tr>
		<td>Alamat</td>
		<td>:</td>
		<td><input type='text' name='txt_alamat' id='txt_alamat'  size='50' lenght='50' class='input'></td>
	</tr>
	<tr>
		<td>Telepon</td>
		<td>:</td>
		<td><input type='text' name='txt_telepon' id='txt_telepon' size='25' lenght='25' class='input'></td>
	</tr>
	<tr>
		<td>Faxcimile</td>
		<td>:</td>
		<td><input type='text' name='txt_fax' id='txt_fax'  size='15' lenght='15' class='input'></td>
	</tr>
	
	<tr>
		<td>Bank</td>
		<td>:</td>
		<td><input type='text' name='txt_bank' id='txt_bank' size='20' lenght='20' class='input'></td>
	</tr>	
	<tr>
		<td>Nomor Rekening</td>
		<td>:</td>
		<td><input type='text' name='txt_nomorac' id='txt_nomorac' size='20' lenght='20' class='input'></td>
	</tr>
	<tr>
		<td>Atas Nama</td>
		<td>:</td>
		<td><input type='text' name='txt_namaac' id='txt_namaac' size='30' lenght='30' class='input'></td>
	</tr>
	<tr>
		<td>Contact Person</td>
		<td>:</td>
		<td><input type='text' name='txt_kontak' id='txt_kontak' size='20' lenght='20' class='input'></td>
	</tr>
	
	<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>";
?>