var managlevel=(function(){
	var hal=0;
	var jumlah=30;
	var idlevel=0;
	return{
		caricanggih:function(){
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "managlevel",
				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){
				managlevel.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			managlevel.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_managlevel").html("");
			var loaderdata=mload.loading({"el":"loader_data_level"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "managlevel",
				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){
					
					loaderdata.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_managlevel",
							data:e,
							lebarmin:"500px",
							trklik:{"data":"id","fungsi":"barisklik"},
							title:"kategori Menu",
							isi:[
									
									{"col":"id","judul":"ID/Kode Level","tipe":"data","lebar":"80px"},
									{"col":"nama","judul":"Level","tipe":"data"},
									{"align":"center","judul":"Pegawai BDK","tipe":"tpl","tpl":"btpegawai","lebar":"40px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
								],
							mod:"mod",
							module:"managlevel"
						};
						tabel.multisub(datatb);
					}else{
						loaderdata.pesan("BELUM ADA DATA LEVEL");
					}
				}
			});
		},
		buat:function(a){
			var scrmenu=modmenu.getmenuscr();
			document.location=lokal+"member/mod/managlevel?id="+a+"&scrmenu="+scrmenu;
		},
		kembali:function(){
			var scrmenu=modmenu.getmenuscr();
			document.location=lokal+"member/mod/managlevel?scrmenu="+scrmenu;
		},
		edit:function(a){
			idlevel=a;
			$("#box_error_loader").html("");
		},
		simpan:function(){
			$("#loader_err_level").html("");
			var nm=$("#nama").val();
			var idlv=$("#idlevel").val();
			
			var err="";
			if(nm=="") err+="Nama Level belum diisi.</br>";
			if(idlv=="") err+="Id Level belum diisi.</br>";
			if(err!=""){
				$("#loader_err_level").html(err);
				return;
			}
			
			var fg="inputLevel";
			if(idlevel>0){
				fg="editLevel";
			}
			var loadersimpan=mload.loader({"keterangan":"Proses simpan data level ..."});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "managlevel",
				ikdata: {0:fg,nama:nm,id:idlevel,idlevel:idlv}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e==1){
						managlevel.kembali();
					}else{
						loadersimpan.error([{"pesan":"Gagal simpan data"}]);
					}
				}
			});
		},
		hapus:function(a){
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data level ini ?? ",
				proses:function(){
					boxyesno.tutup();
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data level ..."});
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "managlevel",
						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==1){
								loaderhapus.error([{"pesan":"Simpan data level berhasil"}]);
								managlevel.load();
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		setpeserta:function(a,b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"peserta")==0){
				st=1;
			}
			
			var loadersetpeserta=mload.loader({"keterangan":"Proses update peserta ..."});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "managlevel",
				ikdata: {0:"setpeserta",
					id:a,status:st}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					
					if(e==1){
						loadersetpeserta.tutup();
						var elps=document.getElementById("btpegawai_"+b+"_"+c);
						elps.className="mini_dis";
						d.className="mini_dis";
						if(st==1){
							d.className="mini_ok";
						}
						tabel.gettabel(b).setdata(c,"peserta",st);
						tabel.gettabel(b).setdata(c,"pegawai",0);
					}else{
						loadersetpeserta.error([{"pesan":"Gagal proses update peserta"}]);
					}
				}
			});
		},
		setpegawai:function(a,b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"pegawai")==0){
				st=1;
			}
			
			var loadersetpegawai=mload.loader({"keterangan":"Proses update pegawai ..."});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "managlevel",
				ikdata: {0:"setpegawai",
					id:a,status:st}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					
					if(e==1){
						loadersetpegawai.tutup();
						d.className="mini_dis";
						if(st==1){
							d.className="mini_ok";
						}
						tabel.gettabel(b).setdata(c,"pegawai",st);
						
					}else{
						loadersetpegawai.error([{"pesan":"Gagal proses update pegawai"}]);
					}
				}
			});
		},
		
	};
})();