<script type="text/javascript">
$(document).ready(function() {
	cari_nomor();
	
	$("#txt_nama").focus();
			
	function cari_nomor(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "modul/customer/cari_nomor.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(data.nomor);
			}
		});
	}
	
	$("#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	nobank	= $("#txt_nobank").val();
		var	kontak  = $("#txt_kontak").val();
		
		var error = false;

		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/customer/simpan.php",
			data	: "kode="+kode+
					"&nama="+nama+
					"&alamat="+alamat+
					"&telepon="+telepon+
					"&fax="+fax+					
					"&nobank="+nobank+
					"&kontak="+kontak,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$(".input").val('');
				$(".input").val('');
				cari_nomor();
				$("#txt_nama").focus();
			}
		});
		}
	}
	
	$("#keluar").click(function(){
		document.location='?module=home';
	});
});
</script>

<?php
include '../../inc/inc.koneksi.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><select id='txt_nobank' class='input_header'>";
			$sql = mysql_query("SELECT * FROM akun_bb WHERE noakun BETWEEN '11111' AND '11119' ORDER BY noakun");
			while($r=mysql_fetch_array($sql)){
				$noakun = $r[noakun];
				echo "<option value='$noakun'>$noakun - $r[naakun]</option>";
			}
			echo "</select>
		</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>
	
	<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>";
?>