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

	function cari_nomor(){
		var no = 1;
				
		$.ajax({
			type	: "POST",
			url		: "modul/karyawan/cari_nomor.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#txt_nik").val(data.nomor);
				$("#txt_nama").focus();
			}
		});
	}
	
	$("#txt_kodejab").click(function(){
		var kode = $("#txt_kodejab").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/karyawan/cari_jab.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_jabatan").val(data.jabatan);				
			}
		});
	});
	
	$("#txt_kodejab").keyup(function(){
		var kode = $("#txt_kodejab").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/karyawan/cari_jab.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_jabatan").val(data.jabatan);				
			}
		});
	});
	
	$("#simpan").click(function(){
		simpan_data();
		return false;
	});

	function simpan_data(){
		var nik     = $("#txt_nik").val();
		var nama   	= $("#txt_nama").val();
		var tglmasuk= $("#txt_tglmasuk").val();
		var kodejab	= $("#txt_kodejab").val();
		var jabatan	= $("#txt_jabatan").val();		
		var alamat	= $("#txt_alamat").val();
		var tplahir = $("#txt_tplahir").val();
		var tglahir = $("#txt_tglahir").val();
		var pendid	= $("#txt_pendid").val();
		var sex   	= $("#txt_sex").val();
		var statkwn	= $("#txt_statkwn").val();
		var jmlanak	= $("#txt_jmlanak").val();
		var gapok  	= $("#txt_gapok").val();
		var umak	= $("#txt_umak").val();
		var tunjab	= $("#txt_tunjab").val();
				
		var error = false;

		if(nik.length == 0){
			var error = true;
			alert("Maaf, Nomor induk karyawan masih kosong. Klik tombol Tambah untuk memulai.");
			$("#tambah").focus();
			return (false);
        }
		
		if(nama.length == 0){
			var error = true;
			alert("Maaf, Nama karyawan tidak boleh kosong.");
			$("#txt_nama").focus();
			return (false);
        }
		
		if(kodejab.length == 0){
			var error = true;
			alert("Maaf, Kode jabatan tidak boleh kosong.");
			$("#txt_kodejab").focus();
			return (false);
        }
		
		if(gapok.length == 0){
			var error = true;
			alert("Maaf, Nomor gaji pokok tidak boleh kosong.");
			$("#txt_gapok").focus();
			return (false);
        }
		
		if(error == false){
		$.ajax({
			type	: "POST",
			url		: "modul/karyawan/simpan.php",
			datatype: "json",
			data	: "nik="+nik+
					"&nama="+nama+
					"&tglmasuk="+tglmasuk+
					"&kodejab="+kodejab+
					"&jabatan="+jabatan+
					"&alamat="+alamat+
					"&tplahir="+tplahir+
					"&tglahir="+tglahir+
					"&pendid="+pendid+
					"&sex="+sex+
					"&statkwn="+statkwn+
					"&jmlanak="+jmlanak+
					"&gapok="+gapok+
					"&umak="+umak+
					"&tunjab="+tunjab,
					
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#info").html(data);
				$("#tampil_data").load('modul/karyawan/tampil_data.php');
				$(".input").val('');
				$("#tambah").focus();
			}
		});
		}
		return false;
	}
	
	$("#keluar").click(function(){
		document.location='?module=home';
	});
});
</script>

<?php
include "../../inc/inc.koneksi.php";

echo "<table>
	<tr>
		<td>Nomor Induk Karyawan</td>
		<td>:</td>
		<td><input type='text' name='txt_nik' id='txt_nik' size='4' lenght='4' class='input' readonly /></td>
	</tr>
	<tr>
		<td>Nama karyawan</td>
		<td>:</td>
		<td><input type='text' name='txt_nama' id='txt_nama' size='30' lenght='30' class='input'></td>
	</tr>
	<tr>
		<td>Tanggal Masuk</td>
		<td>:</td>
		<td><input type='date' name='txt_tglmasuk' id='txt_tglmasuk' size='12' class='input'></td>
	</tr>
	<tr>
		<input type='txt' name='txt_jabatan' id='txt_jabatan' size='20' class='input' hidden/>
		<td>Jabatan</td>
		<td>:</td>
		<td><select name='txt_kodejab' id='txt_kodejab' >
			<option value='' selected>-Pilih-</option>";
		
			$sql	= "SELECT * FROM jabatan ";
			$query	= mysql_query($sql);
			while($r=mysql_fetch_array($query)){
				echo "<option value='$r[kode_jab]'>$r[kode_jab] - $r[nama_jab]</option>";
			}
			echo "</select>";
	    
echo "</td>
	</tr>
	<tr>
		<td>Alamat</td>
		<td>:</td>
		<td><input type='text' name='txt_alamat' id='txt_alamat' size='50' class='input'></td>		
	</tr>	
	<tr>
		<td>Tempat dan Tanggal Lahir</td>
		<td>:</td>
		<td>
			<input type='text' name='txt_tplahir' id='txt_tplahir' size='20' class='input'>
			<input type='date' name='txt_tglahir' id='txt_tglahir' size='10' class='input'>
		</td>
	</tr>
	<tr>
		<td>Pendidikan Terakhir</td>
		<td>:</td>
		<td><select name='txt_pendid' id='txt_pendid' >		
			<option value='' selected>-Pilih-</option>
			<option>SD</option>
			<option>SMP</option>
			<option>SMA</option>
			<option>AKADEMI/D3</option>
			<option>SARJANA</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>Jenis Kelamin</td>
		<td>:</td>
		<td><select name='txt_sex' id='txt_sex' >
			<option value='' selected>-Pilih-</option>
			<option>LAKI-LAKI</option>
			<option>PEREMPUAN</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>Status Kawin</td>
		<td>:</td>
		<td><select name='txt_statkwn' id='txt_statkwn' >
			<option value='' selected>-Pilih-</option>
			<option>KAWIN</option>
			<option>TIDAK KAWIN</option>
			<option>DUDA</option>
			<option>JANDA</option>
			</select>
		</td>
	</tr>	
	<tr>
		<td>Jumlah Anak</td>
		<td>:</td>
		<td><input type='text' name='txt_jmlanak' id='txt_jmlanak' size='4' class='input'></td>
	</tr>	
	<tr>
		<td>Gaji Pokok</td>
		<td>: Rp</td>
		<td><input type='text' name='txt_gapok' id='txt_gapok' size='10' length='10' class='input'></td>
	</tr>		
	<tr>
		<td>Uang Makan Harian</td>
		<td>: Rp</td>
		<td><input type='text' name='txt_umak' id='txt_umak' size='10' class='input'></td>
	</tr>
	<tr>
		<td>Tunjangan Jabatan</td>
		<td>: Rp</td>
		<td><input type='text' name='txt_tunjab' id='txt_tunjab' size='10' class='input' ></td>
	</tr>
	</table>
	
	<table width='100%'>
	<tr>
		<td colspan='3' align='center'>			
			<button name='simpan' id='simpan'>Simpan</botton>
			<button name='tambah' id='tambah'>Tambah</button>
			<button name='keluar' id='keluar'>Keluar</button>
		</td>
	</tr>
	</table>";
?>