var masterstatus=(function(){
	var hal=0;
	var jumlah=30;
	var idmasterstatus=0;
	var boxcarimodule=null;
	var boxkode=null;
	return{
		init:function(a){
			$("#sl_kategori").val(a['idkategori']);
			
			masterstatus.load();
		},
		caricanggih:function(){
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				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){
				masterstatus.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			masterstatus.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val();
			var kat=$("#sl_kategori").val();
			
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_masterstatus").html("");
			var loaderdata=mload.loading({"el":"loader_data_status"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterstatus",
				ikdata: {0:"getTabel",1:hal,2:jumlah,3:cr,
					kategori:kat}
			};
			
			$.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){
						
						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_masterstatus",
							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":"id","judul":"ID/Kode","tipe":"tpl","tpl":"btkode","lebar":"60px"},
									{"col":"kategori","judul":"Kategori","tipe":"data","lebar":"110px"},
									{"col":"nama","judul":"Nama Status","tipe":"data"},
									{"align":"center","judul":"Module View","tipe":"tpl","tpl":"btjumlahview","lebar":"60px"},
									{"align":"center","judul":"Module Update","tipe":"tpl","tpl":"btjumlahmodule","lebar":"60px"},
									{"align":"center","judul":"Notif","tipe":"tpl","tpl":"btjumlahnotif","lebar":"60px"},
									{"align":"center","judul":"Edit","tipe":"tpl","tpl":"btjumlahedit","lebar":"60px"},
									{"align":"center","judul":"Hapus","tipe":"tpl","tpl":"btjumlahhapus","lebar":"60px"},
									{"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatus","lebar":"60px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"masterstatus"
						};
						tabel.multisub(datatb);
					}else{
						loaderdata.pesan("BELUM ADA DATA STATUS");
					}
				}
			});
		},
		buat:function(a,b,c,d){
			var idkategori=$("#sl_kategori").val();
			var idst=0;
			if(a>0) idst=tabel.gettabel(b).getdata(c,"id");
			
			document.location=lokal+"member/mod/masterstatus?idkat="+idkategori+"&id="+idst+"&scrmenu="+modmenu.getmenuscr();
		},
		kembali:function(){
			document.location=lokal+"member/mod/masterstatus?scrmenu="+modmenu.getmenuscr();
		},
		edit:function(a){
			idmasterstatus=a['id'];
			$("#sl_kategori").val(a['idkategori']);
			$("#idmasterstatus").focus();
		},
		simpan:function(){
			var nm=$("#nama").val();
			var idkategori=$("#sl_kategori").val();
			var idstatus=$("#idmasterstatus").val();
			var bg=$("#bg").val();
			var warna=$("#warna").val();
			var err="";
			if(nm=="") err+="Nama Status belum diisi.</br>";
			if(idkategori=="" || idkategori<=0) err+="Kategori Status belum dipilih.</br>";
			
			if(err!=""){
				var ps={"title":"Peringatan","pesan":err};
				boxpesan.peringatan(ps);
				return;
			}
			var fg="inputstatus";
			if(idmasterstatus>0){
				fg="editstatus";
			}
			var loadersimpan=mload.loader({"keterangan":"Proses simpan data status..."});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterstatus",
				ikdata: {0:fg,nama:nm,iddatamasterstatus:idstatus,
					idkategori:idkategori,
					bg:bg,warna:warna,
					id:idmasterstatus}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e==1){
						masterstatus.kembali();
					}else{
						loadersimpan.error([{"pesan":"Terjadi kesalahan simpan data"}]);
					}
				}
			});
		},
		hapus:function(a,b,c,d){
			if(tabel.gettabel(b).getdata(c,"id")<=0) return;
			var ps={"pesan":"Yakin akan menghapus data Master Status ini ??",
					"title":"Peringatan Hapus data"};
				
			var boxyesno=boxpesan.yesno(ps);
			boxyesno.proses.onclick=function(){
				boxyesno.tutup();
				var loaderhapusdata=mload.loader({"keterangan":"Proses hapus data status.."});
				var ik_data = {
					ajax: 1,
					mode: "mod",
					cl: "masterstatus",
					ikdata: {0:"hapusData",
						id:tabel.gettabel(b).getdata(c,"id")}
				};
				
				$.ajax({
					url: lokal+"man.ajax.php",
					type: "POST",
					dataType: "json",
					async:true,
					data: ik_data,
					success: function(e){
						if(e!=false){
							loaderhapusdata.error([{"pesan":"Berhasil"}]);
							masterstatus.load();
						}else{
							loaderhapusdata.error([{"pesan":"Gagal hapus data status"}]);
						}
					}
				});
			}
		},
		setstatus:function(a,b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"status")==1){
				st=0;
			}
			
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				ikdata: {0:"setStatus",status:st,
					id:tabel.gettabel(b).getdata(c,"id")}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e==1){
						if(st==1){
							d.className="mini_ok";
						}else{
							d.className="mini_dis";
						}
						tabel.gettabel(b).setdata(c,"status",st);
					}
				}
			});
		},
		
		bukamodule:function(a,b,c,d){
			var idtb=b+"_"+c;
            
            var htm="<div align='left' style='padding-top:10px;padding-bottom:10px;width:100%;'>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'><b>DAFTAR MODULE STATUS</b></div>";
            htm+="<div id='grid_lampiran_"+idtb+"'></div>";
            
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div align='left'>";
            htm+="<span class='btmerah medium' id='bt_hide_"+idtb+"'>TUTUP</span>&nbsp;&nbsp;";
            htm+="<span class='btkuning medium' id='bt_hapus_"+idtb+"'>HAPUS SEMUA</span>&nbsp;&nbsp;";
            htm+="<span class='bthijau medium' id='bt_input_"+idtb+"'>INPUT MODULE</span>&nbsp;&nbsp;";
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            //alert(b);
            
            if(tabel.gettabel(b)!=null){
                
                tabel.gettabel(b).maxim(obj,c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
                d.offsetParent.setAttribute("class","garis_kiri_td bghijau");
            };
            
            document.getElementById("bt_hide_"+idtb).onclick=function(){
                tabel.gettabel(b).minim(c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
            };
            document.getElementById("bt_hapus_"+idtb).onclick=function(){
                var ps={"pesan":"Yakin akan menghapus semua module akses edit dari status ini ??",
					"title":"Peringatan Hapus data"};
				
				var boxyesno=boxpesan.yesno(ps);
				boxyesno.proses.onclick=function(){
					var idstatus=tabel.gettabel(b).getdata(c,"id");
				 	mload.sh();
		            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
		                ikdata: {0:"hapusemuamodakses",idstatus:idstatus}
		            };
		            
		            $.ajax({
		                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
		                success: function(e){
		                    
		                    mload.hd();
		                    //alert(JSON.stringify(e));
		                    if(e==1){
		                        var jumlah=0;
		                        d.innerHTML=0;
		                        tabel.gettabel(b).setdata(c,"jumlah_module",0);
		                        masterstatus.bukamodule(idstatus,b,c,d);
		                        boxyesno.tutup();
		                    }else{
		                    	alert("Terjadi kesalahan!");
		                    }
		                }
		            });
				}
            };
            
            document.getElementById("bt_input_"+idtb).onclick=function(){
                var ps={"box":"box_cari_module",
						"judul":"Cari Module ","tinggimax":"fit","tinggi":"auto","lebar":"600px"};
				boxcarimodule=boxwin.load(ps);
				boxcarimodule.idstatus=a;
				boxcarimodule.tabel=b;
				boxcarimodule.baris=c;
				boxcarimodule.el=d;
				boxcarimodule.mode=1;
				boxcarimodule.arrpilih=[];
				boxcarimodule.buka();
				
				$("#loader_module").html("");
				masterstatus.loademodule();
				
            };
            
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"getmodulestatus",
                	idstatus:tabel.gettabel(b).getdata(c,"id")}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e!=false && e.length>0){
                        var datatb={
                            box:"grid_lampiran_"+idtb,
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            tabelpar:b,
                            barispar:c,
                            isi:[
                            		{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Module","tipe":"data"},
									{"judul":"","tipe":"data","tipe":"tpl","tpl":"bthapusmodule","lebar":"60px","align":"center"},
                                ],
                            mod:"mod",
                            module:"statussuratlevel"
                        };
                        tabel.multisub(datatb);
                    }else{
                    	$("#grid_lampiran_"+idtb).html("BELUM ADA DATA MODULE");
                    }
                }
            });
		},
		loademodule:function(){
			$("#hal_ke_module").val(0);
			masterstatus.loaddatamodule($("#hal_ke_module").val(),$("#jumlah_hal_module").val());
		},
		loadmodule:function(){
			masterstatus.loaddatamodule($("#hal_ke_module").val(),$("#jumlah_hal_module").val());
		},
		entermodule:function(e){
			if(e.which == 13 || e.keyCode == 13){
				masterstatus.loademodule();
			}
		},
		loaddatamodule:function(h,jm){
			
			$("#grid_data_module").html("");
			
			var cr=$("#cari_module").val();
			var posisiawal=(h-1)*jumlah;
			
			$("#hal_ke_module").html("<option value=\"1\">1</option>");
			
			var fg="getdatamoduleview";
			if(boxcarimodule.mode==1){
				fg="getdatamodule";
			}
			mload.sh("loader_module");
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				ikdata: {0:fg,halaman:h,jumlah:jm,cari:cr,idstatus:boxcarimodule.idstatus}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e!=false && e.hasOwnProperty("data")){
						var jumlahhalaman=e['totalhalaman'];
						if(jumlahhalaman>1){
							var htm;
							for(var i=0;i<jumlahhalaman;i++){
								htm+="<option value='"+(i+1)+"'>"+(i+1)+"</option>";
							}
							$("#hal_ke_module").html(htm);
							
						}
						$("#hal_ke_module").val(h);
						
						
						if((e['data']).length>0){
							var datatb={
								box:"grid_data_module",
								data:e['data'],
								lebarmin:"500px",
								trklik:{"data":"id","fungsi":"barisklik"},
								title:"kategori Menu",
								isi:[
									{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":posisiawal,"jumlah":jumlah},
									{"col":"nama","judul":"Nama module","tipe":"data"},
									{"align":"center","judul":"Pilih","tipe":"tpl","tpl":"btpilihmodule","lebar":"60px"},
								],
								mod:"mod",
								module:"masterstatus"
							};
							tabel.multisub(datatb);
						}else{
							$("#grid_data_module").html("Tidak ada data");
						}
						
					}
				}
			});
		},
		pilihdatamodule:function(a,b,c,d){
			var idtb=b+"_"+c;
            var attst=document.getElementById("btpilihmodule_"+idtb).getAttribute("stpilih");
            
            var st=0;
            if(attst==0){
                st=1;
                boxcarimodule.arrpilih.push(a);
                
                document.getElementById("btpilihmodule_"+idtb).className="bt_ya";
                document.getElementById("btpilihmodule_"+idtb).setAttribute("stpilih",1);
            }else{
                var index = kudus.getindexarr(a,boxcarimodule.arrpilih);
                if(index > -1)  {
                    boxcarimodule.arrpilih.splice(index, 1);
                }
                
                document.getElementById("btpilihmodule_"+idtb).className="bt_tidak";
                document.getElementById("btpilihmodule_"+idtb).setAttribute("stpilih",0);
            }
            
		},
		prosespilihmodule:function(){
			$("#loader_module").html("");
			if(boxcarimodule.arrpilih<=0) {
				$("#loader_module").html("Belum ada pilihan!");
				return;
			}
			mload.sh();
			var fg="inputmoduleview";
			if(boxcarimodule.mode==1){
				fg="inputmodule";
			}
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:fg,idstatus:boxcarimodule.idstatus,idmodule:boxcarimodule.arrpilih}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e==1){
                    	if(boxcarimodule.mode==0){
                    		var jumlah=parseInt(tabel.gettabel(boxcarimodule.tabel).getdata(boxcarimodule.baris,"jumlah_view"))+boxcarimodule.arrpilih.length;
                        
	                        boxcarimodule.el.innerHTML=jumlah;
	                        tabel.gettabel(boxcarimodule.tabel).setdata(boxcarimodule.baris,"jumlah_view",jumlah);
	                        masterstatus.bukamoduleview(boxcarimodule.idstatus,boxcarimodule.tabel,boxcarimodule.baris,boxcarimodule.el);
                    	}else if(boxcarimodule.mode==1){
                    		var jumlah=parseInt(tabel.gettabel(boxcarimodule.tabel).getdata(boxcarimodule.baris,"jumlah_module"))+boxcarimodule.arrpilih.length;
                        
	                        boxcarimodule.el.innerHTML=jumlah;
	                        tabel.gettabel(boxcarimodule.tabel).setdata(boxcarimodule.baris,"jumlah_module",jumlah);
	                        masterstatus.bukamodule(boxcarimodule.idstatus,boxcarimodule.tabel,boxcarimodule.baris,boxcarimodule.el);
                    	}
                    	masterstatus.batalpilihmodule();
                    }else{
                    	alert("Error");
                    }
                }
            });
		},
		batalpilihmodule:function(){
			if(boxcarimodule!=null) boxcarimodule.tutup();
			boxcarimodule=null;
		},
		hapusmodule:function(a,b,c,d){
			if(a<=0) return;
			var ps={"pesan":"Yakin akan menghapus data akses module dari status ini ??",
					"title":"Peringatan Hapus data"};
				
			var boxyesno=boxpesan.yesno(ps);
			boxyesno.proses.onclick=function(){
				
				var tbpar=tabel.gettabel(b).parrent;
				var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
				var idmodule=tabel.gettabel(b).getdata(c,"id");
				mload.sh();
	            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
	                ikdata: {0:"hapusmodule",idstatus:idstatus,idmodule:idmodule}
	            };
	            
	            $.ajax({
	                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
	                success: function(e){
	                    
	                    mload.hd();
	                    //alert(JSON.stringify(e));
	                    if(e==1){
	                    	boxyesno.tutup();
	                    	var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_module"))-1;
	                        
	                        var el=document.getElementById("btjumlahmodule_"+tbpar.tabel+"_"+tbpar.baris);
	                        el.innerHTML=jumlah;
	                        tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_module",jumlah);
	                        masterstatus.bukamodule(idstatus,tbpar.tabel,tbpar.baris,el);
	                    }else{
	                    	alert("Error");
	                    }
	                }
	            });
			}
		},
		bukanotifikasi:function(a,b,c,d){
			var idtb=b+"_"+c;
            
            var htm="<div align='left' style='padding-top:10px;padding-bottom:10px;width:100%;'>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'><b>DAFTAR LEVEL NOTIFIKASI</b></div>";
            htm+="<div id='grid_lampiran_"+idtb+"'></div>";
            
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div align='left'>";
            htm+="<span class='btmerah medium' id='bt_hide_"+idtb+"'>TUTUP</span>&nbsp;&nbsp;";
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            //alert(b);
            
            if(tabel.gettabel(b)!=null){
                
                tabel.gettabel(b).maxim(obj,c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
                d.offsetParent.setAttribute("class","garis_kiri_td bghijau");
            };
            
            document.getElementById("bt_hide_"+idtb).onclick=function(){
                tabel.gettabel(b).minim(c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
            };
            
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"getlevelnotifikasi",
                	idstatus:tabel.gettabel(b).getdata(c,"id")}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e!=false && e.length>0){
                        var datatb={
                            box:"grid_lampiran_"+idtb,
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            tabelpar:b,
                            barispar:c,
                            isi:[
                            		{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Level","tipe":"data"},
									{"judul":"","tipe":"data","tipe":"tpl","tpl":"btstatuslevel","lebar":"60px","align":"center"},
                                ],
                            mod:"mod",
                            module:"statussuratlevel"
                        };
                        tabel.multisub(datatb);
                    }else{
                    	$("#box_catatan_"+idtb).html("BELUM DATA LEVEL");
                    }
                }
            });
		},
		setaktiflevel:function(a,b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"status")==0){
				st=1;
			}
			var tbpar=tabel.gettabel(b).parrent;
			var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"setstatuslevel",status:st,idlevel:a,idstatus:idstatus}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e==1){
                    	var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_notifikasi"));
                        if(st==0){
                        	d.className="mini_dis";
                        	jumlah=jumlah-1;
                        }else if(st==1){
                        	d.className="mini_ok";
                        	jumlah=jumlah+1;
                        }
                        
                        var el=document.getElementById("btjumlahnotif_"+tbpar.tabel+"_"+tbpar.baris);
                        el.innerHTML=jumlah;
                        tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_notifikasi",jumlah);
                        tabel.gettabel(b).setdata(c,"status",st);
                    }else{
                    	alert("Error");
                    }
                }
            });
		},
		bukamoduleview:function(a,b,c,d){
			var idtb=b+"_"+c;
            
            var htm="<div align='left' style='padding-top:10px;padding-bottom:10px;width:100%;'>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'><b>DAFTAR MODULE STATUS VIEW</b></div>";
            htm+="<div id='grid_lampiran_"+idtb+"'></div>";
            
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div align='left'>";
            htm+="<span class='btmerah medium' id='bt_hide_"+idtb+"'>TUTUP</span>&nbsp;&nbsp;";
            htm+="<span class='btkuning medium' id='bt_hapus_"+idtb+"'>HAPUS SEMUA</span>&nbsp;&nbsp;";
            htm+="<span class='bthijau medium' id='bt_input_"+idtb+"'>INPUT MODULE</span>&nbsp;&nbsp;";
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            //alert(b);
            
            if(tabel.gettabel(b)!=null){
                
                tabel.gettabel(b).maxim(obj,c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
                d.offsetParent.setAttribute("class","garis_kiri_td bghijau");
            };
            
            document.getElementById("bt_hapus_"+idtb).onclick=function(){
                var ps={"pesan":"Yakin akan menghapus semua akses view module dari status ini ??",
					"title":"Peringatan Hapus data"};
				
				var boxyesno=boxpesan.yesno(ps);
				boxyesno.proses.onclick=function(){
					var idstatus=tabel.gettabel(b).getdata(c,"id");
				 	mload.sh();
		            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
		                ikdata: {0:"hapusemuaview",idstatus:idstatus}
		            };
		            
		            $.ajax({
		                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
		                success: function(e){
		                    
		                    mload.hd();
		                    //alert(JSON.stringify(e));
		                    if(e==1){
		                        var jumlah=0;
		                        d.innerHTML=0;
		                        tabel.gettabel(b).setdata(c,"jumlah_view",0);
		                        masterstatus.bukamoduleview(idstatus,b,c,d);
		                        boxyesno.tutup();
		                    }else{
		                    	alert("Terjadi kesalahan!");
		                    }
		                }
		            });
				}
            };
            document.getElementById("bt_hide_"+idtb).onclick=function(){
                tabel.gettabel(b).minim(c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
            };
            
            document.getElementById("bt_input_"+idtb).onclick=function(){
                var ps={"box":"box_cari_module",
						"judul":"Cari Module ","tinggimax":"fit","tinggi":"auto","lebar":"600px"};
				boxcarimodule=boxwin.load(ps);
				boxcarimodule.idstatus=a;
				boxcarimodule.tabel=b;
				boxcarimodule.baris=c;
				boxcarimodule.el=d;
				boxcarimodule.mode=0;
				boxcarimodule.arrpilih=[];
				boxcarimodule.buka();
				
				masterstatus.loademodule();
            };
            
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"getmodulestatusview",
                	idstatus:tabel.gettabel(b).getdata(c,"id")}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e!=false && e.length>0){
                        var datatb={
                            box:"grid_lampiran_"+idtb,
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            tabelpar:b,
                            barispar:c,
                            isi:[
                            		{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Module","tipe":"data"},
									{"judul":"","tipe":"data","tipe":"tpl","tpl":"bthapusmoduleview","lebar":"60px","align":"center"},
                                ],
                            mod:"mod",
                            module:"statussuratlevel"
                        };
                        tabel.multisub(datatb);
                    }else{
                    	$("#grid_lampiran_"+idtb).html("BELUM ADA DATA MODULE");
                    }
                }
            });
		},
		hapusmoduleview:function(a,b,c,d){
			if(a<=0) return;
			var ps={"pesan":"Yakin akan menghapus data akses module dari status View ini ??",
					"title":"Peringatan Hapus data"};
				
			var boxyesno=boxpesan.yesno(ps);
			boxyesno.proses.onclick=function(){
				
				var tbpar=tabel.gettabel(b).parrent;
				var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
				var idmodule=tabel.gettabel(b).getdata(c,"id");
				mload.sh();
	            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
	                ikdata: {0:"hapusmoduleview",idstatus:idstatus,idmodule:idmodule}
	            };
	            
	            $.ajax({
	                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
	                success: function(e){
	                    
	                    mload.hd();
	                    //alert(JSON.stringify(e));
	                    if(e==1){
	                    	boxyesno.tutup();
	                    	var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_view"))-1;
	                        
	                        var el=document.getElementById("btjumlahview_"+tbpar.tabel+"_"+tbpar.baris);
	                        el.innerHTML=jumlah;
	                        tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_view",jumlah);
	                        masterstatus.bukamoduleview(idstatus,tbpar.tabel,tbpar.baris,el);
	                    }else{
	                    	alert("Error");
	                    }
	                }
	            });
			}
		},
		hapusmoduleview:function(a,b,c,d){
			if(a<=0) return;
			var ps={"pesan":"Yakin akan menghapus data akses module dari status View ini ??",
					"title":"Peringatan Hapus data"};
				
			var boxyesno=boxpesan.yesno(ps);
			boxyesno.proses.onclick=function(){
				
				var tbpar=tabel.gettabel(b).parrent;
				var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
				var idmodule=tabel.gettabel(b).getdata(c,"id");
				mload.sh();
	            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
	                ikdata: {0:"hapusmoduleview",idstatus:idstatus,idmodule:idmodule}
	            };
	            
	            $.ajax({
	                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
	                success: function(e){
	                    
	                    mload.hd();
	                    //alert(JSON.stringify(e));
	                    if(e==1){
	                    	boxyesno.tutup();
	                    	var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_view"))-1;
	                        
	                        var el=document.getElementById("btjumlahview_"+tbpar.tabel+"_"+tbpar.baris);
	                        el.innerHTML=jumlah;
	                        tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_view",jumlah);
	                        masterstatus.bukamoduleview(idstatus,tbpar.tabel,tbpar.baris,el);
	                    }else{
	                    	alert("Error");
	                    }
	                }
	            });
			}
		},
		bukaedit:function(a,b,c,d){
			var idtb=b+"_"+c;
            
            var htm="<div align='left' style='padding-top:10px;padding-bottom:10px;width:100%;'>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'><b>STATUS EDIT AKSES LEVEL</b></div>";
            htm+="<div id='grid_lampiran_"+idtb+"'></div>";
            
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div align='left'>";
            htm+="<span class='btmerah medium' id='bt_hide_"+idtb+"'>TUTUP</span>&nbsp;&nbsp;";
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            //alert(b);
            
            if(tabel.gettabel(b)!=null){
                
                tabel.gettabel(b).maxim(obj,c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
                d.offsetParent.setAttribute("class","garis_kiri_td bghijau");
            };
            
            document.getElementById("bt_hide_"+idtb).onclick=function(){
                tabel.gettabel(b).minim(c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
            };
            
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"getstatusedit",
                	idstatus:tabel.gettabel(b).getdata(c,"id")}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e!=false && e.length>0){
                        var datatb={
                            box:"grid_lampiran_"+idtb,
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            tabelpar:b,
                            barispar:c,
                            isi:[
                            		{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Level","tipe":"data"},
									{"judul":"","tipe":"data","tipe":"tpl","tpl":"btstatusedit","lebar":"60px","align":"center"},
                                ],
                            mod:"mod",
                            module:"statussuratlevel"
                        };
                        tabel.multisub(datatb);
                    }else{
                    	$("#grid_lampiran_"+idtb).html("BELUM ADA DATA MODULE");
                    }
                }
            });
		},
		setstatusedit:function(b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"statusedit")==1){
				st=0;
			}
			var tbpar=tabel.gettabel(b).parrent;
			var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			var idlevel=tabel.gettabel(b).getdata(c,"id");
			var el=document.getElementById("btjumlahedit_"+tbpar.tabel+"_"+tbpar.baris);
			
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				ikdata: {0:"setStatusedit",status:st,idlevel:idlevel,idstatus:idstatus}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e==1){
						var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_edit"));
						if(st==1){
							d.className="mini_ok";
							jumlah=jumlah+1;
						}else{
							d.className="mini_dis";
							jumlah=jumlah-1;
						}
						el.innerHTML=jumlah;
						tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_edit",jumlah);
						tabel.gettabel(b).setdata(c,"statusedit",st);
					}
				}
			});
		},
		bukahapus:function(a,b,c,d){
			var idtb=b+"_"+c;
            
            var htm="<div align='left' style='padding-top:10px;padding-bottom:10px;width:100%;'>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'><b>STATUS HAPUS AKSES LEVEL</b></div>";
            htm+="<div id='grid_lampiran_"+idtb+"'></div>";
            
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div align='left'>";
            htm+="<span class='btmerah medium' id='bt_hide_"+idtb+"'>TUTUP</span>&nbsp;&nbsp;";
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            //alert(b);
            
            if(tabel.gettabel(b)!=null){
                
                tabel.gettabel(b).maxim(obj,c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
                d.offsetParent.setAttribute("class","garis_kiri_td bghijau");
            };
            
            document.getElementById("bt_hide_"+idtb).onclick=function(){
                tabel.gettabel(b).minim(c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
            };
            
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"getstatushapus",
                	idstatus:tabel.gettabel(b).getdata(c,"id")}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e!=false && e.length>0){
                        var datatb={
                            box:"grid_lampiran_"+idtb,
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            tabelpar:b,
                            barispar:c,
                            isi:[
                            		{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Level","tipe":"data"},
									{"judul":"","tipe":"data","tipe":"tpl","tpl":"btstatushapus","lebar":"60px","align":"center"},
                                ],
                            mod:"mod",
                            module:"statussuratlevel"
                        };
                        tabel.multisub(datatb);
                    }else{
                    	$("#grid_lampiran_"+idtb).html("BELUM ADA DATA MODULE");
                    }
                }
            });
		},
		setstatushapus:function(b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"statushapus")==1){
				st=0;
			}
			var tbpar=tabel.gettabel(b).parrent;
			var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			var idlevel=tabel.gettabel(b).getdata(c,"id");
			var el=document.getElementById("btjumlahhapus_"+tbpar.tabel+"_"+tbpar.baris);
			
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				ikdata: {0:"setStatushapus",status:st,idlevel:idlevel,idstatus:idstatus}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e==1){
						var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_hapus"));
						if(st==1){
							d.className="mini_ok";
							jumlah=jumlah+1;
						}else{
							d.className="mini_dis";
							jumlah=jumlah-1;
						}
						el.innerHTML=jumlah;
						tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_hapus",jumlah);
						tabel.gettabel(b).setdata(c,"statushapus",st);
					}
				}
			});
		},
		bukavalidasi:function(a,b,c,d){
			var idtb=b+"_"+c;
            
            var htm="<div align='left' style='padding-top:10px;padding-bottom:10px;width:100%;'>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'><b>STATUS VALIDASI AKSES LEVEL</b></div>";
            htm+="<div id='grid_lampiran_"+idtb+"'></div>";
            
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div align='left'>";
            htm+="<span class='btmerah medium' id='bt_hide_"+idtb+"'>TUTUP</span>&nbsp;&nbsp;";
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            //alert(b);
            
            if(tabel.gettabel(b)!=null){
                
                tabel.gettabel(b).maxim(obj,c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
                d.offsetParent.setAttribute("class","garis_kiri_td bghijau");
            };
            
            document.getElementById("bt_hide_"+idtb).onclick=function(){
                tabel.gettabel(b).minim(c);
                var trparr=d.offsetParent.parentNode;
                var tdarr=trparr.childNodes;
                for(var n=0;n<tdarr.length;n++){
                    tdarr[n].removeAttribute("class");
                    tdarr[n].setAttribute("class","garis_kiri_td");
                }
            };
            
            mload.sh();
            var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
                ikdata: {0:"getstatusvalidasi",idstatus:a}
            };
            
            $.ajax({
                url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
                success: function(e){
                    
                    mload.hd();
                    //alert(JSON.stringify(e));
                    if(e!=false && e.length>0){
                        var datatb={
                            box:"grid_lampiran_"+idtb,
                            data:e,
                            lebarmin:"500px",
                            trklik:{"data":"id","fungsi":"barisklik"},
                            title:"kategori Menu",
                            tabelpar:b,
                            barispar:c,
                            isi:[
                            		{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Level","tipe":"data"},
									{"judul":"","tipe":"data","tipe":"tpl","tpl":"btstatusvalidasi","lebar":"60px","align":"center"},
                                ],
                            mod:"mod",
                            module:"statussuratlevel"
                        };
                        tabel.multisub(datatb);
                    }else{
                    	$("#grid_lampiran_"+idtb).html("BELUM ADA DATA STATUS");
                    }
                }
            });
		},
		setstatusvalidasi:function(b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"statusvalidasi")==1){
				st=0;
			}
			var tbpar=tabel.gettabel(b).parrent;
			var idstatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			var idlevel=tabel.gettabel(b).getdata(c,"id");
			var el=document.getElementById("btjumlahvalidasi_"+tbpar.tabel+"_"+tbpar.baris);
			
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				ikdata: {0:"setStatusvalidasi",status:st,idlevel:idlevel,idstatus:idstatus}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e==1){
						var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_validasi"));
						if(st==1){
							d.className="mini_ok";
							jumlah=jumlah+1;
						}else{
							d.className="mini_dis";
							jumlah=jumlah-1;
						}
						el.innerHTML=jumlah;
						tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_validasi",jumlah);
						tabel.gettabel(b).setdata(c,"statusvalidasi",st);
					}
				}
			});
		},
		editkode:function(a,b,c,d){
			var ps={"box":"box_kode",
					"judul":"Update ID/Kode Status","tinggimax":"fit","tinggi":"auto","lebar":"500"};
			boxkode=boxwin.load(ps);
			boxkode.id=tabel.gettabel(b).getdata(c,"id");
			boxkode.tabel=b;
			boxkode.baris=c;
			boxkode.el=d;
			boxkode.buka();
			
			$("#kodestatus").val(tabel.gettabel(b).getdata(c,"id"));
		},
		simpankode:function(){
			$("#loader_kode").html("");
			var kode=$("#kodestatus").val();
			if(kode==""){
				$("#loader_kode").html("ID/Kode belum diisi!");
				return;
			}
			
			mload.sh("loader_kode");
			var ik_data = {ajax: 1,mode: "mod",cl: "masterstatus",
				ikdata: {0:"updateKode",
					id:boxkode.id,
					kode:kode}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e==1){
						boxkode.el.innerHTML=kode;
						tabel.gettabel(boxkode.tabel).setdata(boxkode.baris,"id",kode);
						masterstatus.batalkode();
					}
				}
			});
		},
		batalkode:function(){
			if(boxkode!=null) boxkode.tutup();
			boxkode=null;
		}
	};
})();