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

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

	function simpan_data(){
		var kode			= $("#txt_kode").val();
		var nama		= $("#txt_nama").val();
		var alamat 		= $("#txt_alamat").val();
		var nomorhp	= $("#txt_nomorhp").val();
		var error			= false;

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

<?php
echo "<input type='hidden' id='akses'>";
echo "<table>
	<tr>
		<td>Kode Salesman</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 Salesman</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_nama' id='txt_nama' size='50' lenght='60' class='input'></td>
	</tr>
	<tr>
		<td>Nomor HP</td>
		<td>:</td>
		<td><input type='text' name='txt_nomorhp' id='txt_nomorhp' size='30' lenght='30' 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>";
?>