var masterjeniskelamin=(function(){
	var hal=0;
	var jumlah=30;
	var idmasterjeniskelamin=0;
	return{
		caricanggih:function(){
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterjeniskelamin",
				ikdata: {0:"datacari01",1:1}
			};
			
			$.ajax({url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					mload.hd();
					if(e!=false){
						var boxcari;
						var obj=new Object;
						obj.proses=function(a){
							$("#cari").val(a);
							boxcari.tutup();
							document.getElementById("btcari").click();
						};
						var datacari={"data":e,"proses":obj}
						boxcari=caricanggih.buka(datacari);
					}
				}
			});
		},
		enter:function(e){
			if(e.which == 13 || e.keyCode == 13){
				masterjeniskelamin.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			masterjeniskelamin.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_masterjeniskelamin").html("");
			var loaderdatajeniskelamin=mload.loading({"el":"loader_data_jeniskelamin"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterjeniskelamin",
				ikdata: {0:"getTabel",1:hal,2:jumlah,3:cr}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					loaderdatajeniskelamin.tutup();
					//alert(JSON.stringify(e));
					if(e!=false && e.length>0){
						
						if(e.length>0 && e[0]['halaman']>0){
							var htm;
							for(var i=0;i<e[0]['halaman'];i++){
								htm+="<option value='"+(i+1)+"'>"+(i+1)+"</option>";
							}
							$("#hal_ke").html(htm);
							
						}
						$("#hal_ke").val(nohal);
						
						var datatb={
							box:"grid_masterjeniskelamin",
							data:e,
							lebarmin:"500px",
							trklik:{"data":"id","fungsi":"barisklik"},
							title:"kategori Menu",
							isi:[
									{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":hal,"jumlah":jumlah},
									{"col":"kode","judul":"Kode","tipe":"data","lebar":"60px"},
									{"col":"nama","judul":"Jenis Kelamin","tipe":"data"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"masterjeniskelamin"
						};
						tabel.multisub(datatb);
					}else{
						loaderdatajeniskelamin.pesan("BELUM ADA DATA MASTER JENIS KELAMIN");
					}
				}
			});
		},
		buat:function(a){
			document.location=lokal+"member/mod/masterjeniskelamin?id="+a+"&scrmenu="+modmenu.getmenuscr();
		},
		kembali:function(){
			document.location=lokal+"member/mod/masterjeniskelamin?scrmenu="+modmenu.getmenuscr();
		},
		edit:function(a){
			idmasterjeniskelamin=a;
		},
		simpan:function(){
			$("#loader_level_err").html("");
			var nm=$("#nama").val();
			var kd=$("#kode").val();
			var err="";
			if(nm=="") err+="Nama jenis kelamin belum diisi.</br>";
			if(kd=="") err+="Kode jenis kelamin belum diisi.</br>";
			
			if(err!=""){
				$("#loader_level_err").html(err);
				return;
			}
			var fg="inputmasterjeniskelamin";
			if(idmasterjeniskelamin>0){
				fg="editmasterjeniskelamin";
			}
			var loadersimpandata=mload.loader({"keterangan":"Proses simpan data.."});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterjeniskelamin",
				ikdata: {0:fg,nama:nm,kode:kd,id:idmasterjeniskelamin}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					
					if(e==1){
						masterjeniskelamin.kembali();
					}else{
						loadersimpandata.error([{"pesan":"Gagal simpan data"}]);
					}
				}
			});
		},
		hapus:function(a){
			if(a<=0) return;
			var ps={"pesan":"Yakin akan menghapus data jenis kelamin ini ??",
					"title":"Peringatan Hapus data"};
				
			var boxyesno=boxpesan.yesno(ps);
			boxyesno.proses.onclick=function(){
				
				boxyesno.tutup();
				var loadersimpandata=mload.loader({"keterangan":"Proses hapus data.."});
				var ik_data = {
					ajax: 1,
					mode: "mod",
					cl: "masterjeniskelamin",
					ikdata: {0:"hapusData",id:a}
				};
				
				$.ajax({
					url: lokal+"man.ajax.php",
					type: "POST",
					dataType: "json",
					async:true,
					data: ik_data,
					success: function(e){
						if(e!=false){
							loadersimpandata.error([{"pesan":"Berhasil"}]);
							masterjeniskelamin.load();
						}else{
							loadersimpandata.error([{"pesan":"Gagal hapus data"}]);
						}
					}
				});
			}
		}

	};
})();