<script type="text/javascript">
$(document).ready(function(){
	$(':input:not([type="submit"])').each(function() {
		$(this).focus(function() {
			$(this).addClass('hilite');
		}).blur(function() {
			$(this).removeClass('hilite');});
	});	
	$("#kode").focus();
	
	$("#tgl_lahir").datepicker({
			dateFormat:"dd-mm-yy"
    });
	
	$("#kode").keyup(function(e){
		var isi = $(e.target).val();
		$(e.target).val(isi.toUpperCase());
		CariDatapegawai();
	});
	
	function CariDatapegawai(){
		var kode = $("#kode").val()
		$.ajax({
			type	: 'POST',
			url		: "<?php echo site_url(); ?>/ref_json/Infopegawai",
			data	: "kode="+kode,
			cache	: false,
			dataType : "json",
			success	: function(data){
				$("#nama_supp").val(data.nama_pegawai);
				$("#alamat").val(data.alamat);
			}
		});
	}
	
	$("#simpan").click(function(){
		var kode			= $("#kode").val();
		var nama_pegawai	= $("#nama_pegawai").val();
		var jk				= $("#jk").val();
		var telp			= $("#telp").val();
		var tempat_lahir	= $("#tempat_lahir").val();
		var tgl_lahir		= $("#tgl_lahir").val();
		var alamat			= $("#alamat").val();
		
		var string = $("#form").serialize();
		
		if(kode.length==0){
			$.messager.show({
				title:'Info',
				msg:'Maaf, Kode tidak boleh kosong', 
				timeout:2000,
				showType:'show'
			});
			$("#kode").focus();
			return false();
		}
		if(nama_pegawai.length==0){
			$.messager.show({
				title:'Info',
				msg:'Maaf, Nama pegawai tidak boleh kosong', 
				timeout:2000,
				showType:'show'
			});
			$("#nama_pegawai").focus();
			return false();
		}
		$.ajax({
			type	: 'POST',
			url		: "<?php echo site_url(); ?>/pegawai/simpan",
			data	: string,
			cache	: false,
			success	: function(data){
				$.messager.show({
					title:'Info',
					msg:data, 
					timeout:2000,
					showType:'slide'
				});
				CariSimpanan();
			},
			error : function(xhr, teksStatus, kesalahan) {
				$.messager.show({
					title:'Info',
					msg: 'Server tidak merespon :'+kesalahan,
					timeout:2000,
					showType:'slide'
				});
			}
		});
		return false();		
	});
	
});	
</script>
<form name="form" id="form">
<fieldset class="atas">
<table width="100%">
<tr>    
	<td width="150">Kode Pegawai</td>
    <td width="5">:</td>
    <td><input type="text" name="kode" id="kode" size="20" maxlength="20" class="easyui-validatebox" data-options="required:true,validType:'length[3,10]'" value="<?php echo $kode;?>" /></td>
</tr>
<tr>    
	<td>Nama Pegawai</td>
    <td>:</td>
    <td><input type="text" name="nama_pegawai" id="nama_pegawai"  size="50" maxlength="50" class="easyui-validatebox" data-options="required:true,validType:'length[3,10]'" value="<?php echo $nama_pegawai;?>"/></td>
</tr>
<tr>    
	<td>Jk</td>
    <td>:</td>
    <td><select name="jk" id="jk">
      <?php 
		if(empty($jk)){
		?>
      <option value="">-PILIH-</option>
      <?php
		}
		foreach($l_jk->result() as $t){
			if($jk==$t->Value){
		?>
      <option value="<?php echo $t->Value;?>" selected="selected"><?php echo $t->Component;?></option>
      <?php }else { ?>
      <option value="<?php echo $t->Value;?>"><?php echo $t->Component;?></option>
      <?php }
		} ?>
    </select></td>
</tr>
<tr>
  <td>Telp</td>
  <td>:</td>
  <td><input type="text" name="telp" id="telp" size="20" maxlength="20" class="easyui-validatebox" data-options="required:true,validType:'length[3,10]'" value="<?php echo $telp;?>" /></td>
</tr>
<tr>
  <td>Tempat Lahir</td>
  <td>:</td>
  <td><input type="text" name="tempat_lahir" id="tempat_lahir" size="20" maxlength="20" class="easyui-validatebox" data-options="required:true,validType:'length[3,10]'" value="<?php echo $tempat_lahir;?>" /></td>
</tr>
<tr>
  <td>Tgl Lahir</td>
  <td>:</td>
  <td><input type="text" name="tgl_lahir" id="tgl_lahir" size="20" maxlength="20" class="easyui-validatebox" data-options="required:true,validType:'length[3,10]'" value="<?php echo $tgl_lahir;?>" /></td>
</tr>
<tr>
  <td>Alamat</td>
  <td>:</td>
  <td><input type="text" name="alamat" id="alamat"  size="80" maxlength="80" value="<?php echo $alamat;?>"/></td>
</tr>
<tr>
  <td>Bagian</td>
  <td>:</td>
  <td><input type="text" name="bagian" id="bagian"  size="80" maxlength="80" value="<?php echo $bagian;?>"/></td>
</tr>
</table>
</fieldset>
<fieldset class="bawah">
<table width="100%">
<tr>
	<td colspan="3" align="center">
    <button type="button" name="simpan" id="simpan" class="easyui-linkbutton" data-options="iconCls:'icon-save'">SIMPAN</button>
    <a href="<?php echo base_url();?>index.php/pegawai/tambah">
    <button type="button" name="tambah_data" id="tambah_data" class="easyui-linkbutton" data-options="iconCls:'icon-add'">TAMBAH</button>
    </a>
    <a href="<?php echo base_url();?>index.php/pegawai/">
    <button type="button" name="kembali" id="kembali" class="easyui-linkbutton" data-options="iconCls:'icon-back'">KEMBALI</button>
    </a>
    </td>
</tr>
</table>  
</fieldset>   
</form>