<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());
		CariDatacustomer();
	});
	
	function CariDatacustomer(){
		var kode = $("#kode").val()
		$.ajax({
			type	: 'POST',
			url		: "<?php echo site_url(); ?>/ref_json/InfoCustomer",
			data	: "kode="+kode,
			cache	: false,
			dataType : "json",
			success	: function(data){
				$("#nama_customer").val(data.nama_customer);
				$("#jk").val(data.jk);
				$("#telp").val(data.telp);
				$("#tempat_lahir").val(data.tempat_lahir);
				$("#tgl_lahir").val(data.tgl_lahir);
				$("#alamat").val(data.alamat);
			}
		});
	}
	
	$("#simpan").click(function(){
		var kode			= $("#kode").val();
		var nama_customer	= $("#nama_customer").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_customer.length==0){
			$.messager.show({
				title:'Info',
				msg:'Maaf, Nama customer tidak boleh kosong', 
				timeout:2000,
				showType:'show'
			});
			$("#nama_customer").focus();
			return false();
		}
		$.ajax({
			type	: 'POST',
			url		: "<?php echo site_url(); ?>/customer/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 Pelanggan</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 Pelanggan</td>
    <td>:</td>
    <td><input type="text" name="nama_customer" id="nama_customer"  size="50" maxlength="50" class="easyui-validatebox" data-options="required:true,validType:'length[3,10]'" value="<?php echo $nama_customer;?>"/></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>
</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/customer/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/customer/">
    <button type="button" name="kembali" id="kembali" class="easyui-linkbutton" data-options="iconCls:'icon-back'">KEMBALI</button>
    </a>
    </td>
</tr>
</table>  
</fieldset>   
</form>