<script type="text/javascript">
$(document).ready(function() {
	cari_nomor();
	$("#txt_nama").focus();
			
	function cari_nomor(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url	: "modul/pelanggan/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/pelanggan/cari.php",
			data	: "nama="+nama,
			dataType	: "json",
			success	: function(data){
				$("#txt_nama").val(data.nama);
				$("#akses").val(data.akses);				
			}
		});
	});
	
	$("#simpan").click(function(){
		simpan_data();
		return false;
	});

	function simpan_data(){
		var	kode	= $("#txt_kode").val();
		var	tnama	= $("#txt_nama").val();
		var	talamat= $("#txt_alamat").val();
		var	ttelepon= $("#txt_telepon").val();
		var	tfax		= $("#txt_fax").val();		
		var	tbank	= $("#txt_bank").val();
		var	nomorac= $("#txt_nomorac").val();
		var	namaac= $("#txt_namaac").val();
		var	tkontak= $("#txt_kontak").val();
		
		var error = false;

		if(tnama.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/pelanggan/simpan.php",
			data	: "kode="+kode+
					"&tnama="+tnama+
					"&talamat="+talamat+
					"&ttelepon="+ttelepon+
					"&tfax="+tfax+					
					"&tbank="+tbank+
					"&nomorac="+nomorac+
					"&namaac="+namaac+
					"&tkontak="+tkontak,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$("#tampil_data").load('modul/pelanggan/tampil_data.php');
				$("#akses").val(1);
				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 width='20%'>Kode Pelanggan</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 width='20%'>Nama Pelanggan</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>";
?>