var masterdisposisi=(function(){
	var hal=0;
	var jumlah=30;
	var idmasterdisposisi=0;
	var boxdatadisposisi=null;
	var boxjabatandisposisi=null;
	var boxjabatanstatus=null;
	var jumlahreq=0;
	return{
		reqcb:function(jumlah){
			var requestcb = new reqcb({
			    jumlahReq: jumlah
			});
			return requestcb;
		},
		caricanggih:function(){
			var loadercari=mload.loader({"keterangan":"Proses ...."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"datacari01",1:1}
			};
			
			$.ajax({url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					loadercari.tutup();
					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){
				masterdisposisi.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			masterdisposisi.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_masterdisposisi").html("");
			var loaderdata=mload.loading({"el":"loader_datamasterdisposisi"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				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_masterdisposisi",
							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":"jenissurat","judul":"Jenis Surat","tipe":"data","lebar":"130px"},
									{"col":"nama","judul":"Nama Disposisi","tipe":"data"},
									{"align":"center","judul":"Jml. Disposisi","tipe":"tpl","tpl":"btjumlahdis","lebar":"60px"},
									{"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatus","lebar":"60px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"masterdisposisi"
						};
						tabel.multisub(datatb);
					}else{
						loaderdata.pesan("BELUM ADA DATA");
					}
				}
			});
		},
		buat:function(a){
			document.location=lokal+"member/mod/masterdisposisi?id="+a+"&scrmenu="+modmenu.getmenuscr();
		},
		kembali:function(){
			document.location=lokal+"member/mod/masterdisposisi?scrmenu="+modmenu.getmenuscr();
		},
		edit:function(a){
			idmasterdisposisi=a['id'];
			$("#sj_jenissurat").val(a['idjenissurat']);
		},
		simpan:function(){
			$("#loader_masterdisposisi").html("");
			var nm=$("#nama").val();
			var idjenissurat=$("#sj_jenissurat").val();
			
			var err="";
			if(nm=="") err+="Nama Disposisi belum diisi.</br>";
			
			if(err!=""){
				$("#loader_masterdisposisi").html(err);
				return;
			}
			var fg="inputmasterdisposisi";
			if(idmasterdisposisi>0){
				fg="editmasterdisposisi";
			}
			
			var loadersimpan=mload.loader({"keterangan":"Proses simpan data"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:fg,nama:nm,
					idjenissurat:idjenissurat,
					id:idmasterdisposisi}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e==1){
						masterdisposisi.kembali();
					}else{
						loadersimpan.error([{"pesan":"Gagal proses simpan data"}]);
					}
				}
			});
		},
		hapus:function(a){
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data disposisi ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "masterdisposisi",
						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":"Berhasil"}]);
								masterdisposisi.load();
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		setstatus:function(a,b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"status")==1){
				st=0;
			}
			
			var loaderstatus=mload.loader({"keterangan":"Proses update status.."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"setStatus",status:st,id:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					
					if(e==1){
						loaderstatus.tutup();
						if(st==1){
							d.className="mini_ok";
						}else{
							d.className="mini_dis";
						}
						tabel.gettabel(b).setdata(c,"status",st)
					}else{
						loaderstatus.error([{"pesan":"Gagal update status"}]);
					}
				}
			});
		},
		bukadis:function(a,b,c,d){
			var namadis=(tabel.gettabel(b).getdata(c,"nama")).toUpperCase();
			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>DATA DISPOSISI \""+namadis+"\"</b></div>";
            htm+="<select id=\"jumlah_hal_"+idtb+"\" class=\"slkecil\" onchange=\"masterdisposisi.loaddatadispe("+b+","+c+")\">";
            htm+="<option value=\"30\">30</option>";
            htm+="<option value=\"50\">50</option>";
            htm+="<option value=\"100\">100</option>";
            htm+="</select>";
            htm+="&nbsp;&nbsp;Hal <select id=\"hal_ke_"+idtb+"\" class=\"slkecil\" onchange=\"masterdisposisi.loaddatadisp("+b+","+c+")\"><option value=\"1\">1</option></select>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div id='loader_sub_"+idtb+"'></div>";
            htm+="<div id='grid_sub_"+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='bthijau medium' id='bt_input_"+idtb+"'>INPUT DATA DISPOSISI</span>";
            
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            
            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_input_"+idtb).onclick=function(){
            	jumlahreq=0;
            	var iddisposisi=tabel.gettabel(b).getdata(c,"id");
            	var idkategorisurat=tabel.gettabel(b).getdata(c,"idkategori");
                var ps={"box":"box_datadisposisi",
					"judul":"Input Data Disposisi "+namadis,tinggi:"auto","lebar":"700"};
		
				boxdatadisposisi=boxwin.load(ps);
				boxdatadisposisi.id=0;
				boxdatadisposisi.iddisposisi=iddisposisi;
				boxdatadisposisi.tabel=b;
				boxdatadisposisi.baris=c;
				boxdatadisposisi.el=d;
				boxdatadisposisi.buka();
				
				$("#loader_sub").html("");
				$("#nama").html("");
				$("#keterangan").val("");
				$("#urutan").val("");
				
				var htm="<option value='0'>Sesuai Jabatan</option>";
				if(idkategorisurat==1){
					htm+="<option value='1'>Atasan Yang Mengajukan</option>";
				}
				htm+="<option value='2'>Manual Disposisi</option>";
				
				$("#sl_mode").html(htm);
				
				var obj=new Object;
				var cbf=masterdisposisi.reqcb(1);
				
				cbf.addCallbackToQueue(true, function() {
		            masterdisposisi.geturutan(iddisposisi);
		        });
            };
            
			masterdisposisi.loaddatadisp(b,c);
		},
		loaddatadispe:function(b,c){
			var idtb=b+"_"+c;
			$("#hal_ke_"+idtb).val(0);
			masterdisposisi.loaddatadisp(b,c);
		},
		loaddatadisp:function(b,c){
			var idtb=b+"_"+c;
			var iddisposisi=tabel.gettabel(b).getdata(c,"id");
			var loaderdatasub=mload.loading({"el":"loader_sub_"+idtb});
			var hal=$("#hal_ke_"+idtb).val();
			var jumlah=$("#jumlah_hal_"+idtb).val();
			var posisiawal=(hal-1)*jumlah;
			
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:"getdatadisposisi",
					halaman:hal,jumlah:jumlah,
					iddisposisi:iddisposisi}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("data")){
						loaderdatasub.tutup();
						var data=e['data'];
						var jumlahhalaman=e['totalhalaman'];
						if(data.length>0){
							var htm="";
							for(var i=0;i<jumlahhalaman;i++){
								htm+="<option value=\""+(i+1)+"\">"+(i+1)+"</option>";
							}
							$("#hal_ke_"+idtb).html(htm);
							$("#hal_ke_"+idtb).val(hal);
							
							var tabeldata={
								box:"grid_sub_"+idtb,
								data:data,
								lebarmin:"500px",
								trklik:{"data":"id","fungsi":"barisklik"},
								title:"kategori Menu",
								tbclass:"table_grid-1",
								tabelpar:b,
                            	barispar:c,
								isi:[
										//{"col":"id","judul":"ID","tipe":"data","align":"center","lebar":"50px"},
										{"align":"center","judul":"Urutan","tipe":"data","col":"urutan","lebar":"60px"},
										{"align":"center","judul":"Mode","tipe":"tpl","tpl":"btmodedis","lebar":"130px"},
										{"col":"nama","judul":"Nama","tipe":"data"},
										{"align":"center","judul":"Jumlah Jabatan","tipe":"tpl","tpl":"btjumlahjabatan","lebar":"60px"},
										{"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatussub","lebar":"60px"},
										{"align":"center","judul":"","tipe":"tpl","tpl":"bteditsub","lebar":"60px"},
									],
								mod:"mod",
								module:"masterdisposisi"
							};
							tabel.multisub(tabeldata);
						}else{
							loaderdatasub.pesan("TIDAK ADA DATA");
						}
					}
				}
			});
		},
		editsub:function(a,b,c,d){
			var tbpar=tabel.gettabel(b).parrent;
			var mode=tabel.gettabel(b).getdata(c,"mode");
			var idkategorisurat=tabel.gettabel(b).getdata(c,"idkategori");
			var iddisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			var namadis=(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nama")).toUpperCase();
            var el=document.getElementById("btjumlahdis_"+tbpar.tabel+"_"+tbpar.baris);
            
            var ps={"box":"box_datadisposisi",
				"judul":"Edit Data Disposisi "+namadis,tinggi:"auto","lebar":"700"};
	
			boxdatadisposisi=boxwin.load(ps);
			boxdatadisposisi.id=a;
			boxdatadisposisi.iddisposisi=iddisposisi;
			boxdatadisposisi.tabel=tbpar.tabel;
			boxdatadisposisi.baris=tbpar.baris;
			boxdatadisposisi.el=el;
			boxdatadisposisi.buka();
			
			$("#loader_sub").html("");
			$("#nama").val(tabel.gettabel(b).getdata(c,"nama"));
			$("#keterangan").val(tabel.gettabel(b).getdata(c,"keterangan"));
			$("#urutan").val(tabel.gettabel(b).getdata(c,"urutan"));
			
			var htm="<option value='0'>Sesuai Jabatan</option>";
			if(idkategorisurat==1){
				htm+="<option value='1'>Atasan Yang Mengajukan</option>";
			}
			$("#sl_mode").html(htm);
			$("#sl_mode").val(mode);
		},
		bataldatadis:function(){
			if(boxdatadisposisi!=null) boxdatadisposisi.tutup();
			boxdatadisposisi=null;
		},
		geturutan:function(a){
			$("#loader_urutan").html("");
			$("#urutan").hide();
			var loaderstatus=mload.loading({"el":"loader_urutan"});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"geturutan",
					iddisposisi:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					$("#urutan").show();
					loaderstatus.tutup();	
					if(e!=false && e>0){
						$("#urutan").val(e);
					}else{
						$("#urutan").val(1);
					}
				}
			});
		},
		
		inputdatadis:function(){
			$("#loader_sub").html("");
			var keterangan=$("#keterangan").val();
			var urutan=$("#urutan").val();
			var nama=$("#nama").val();
			var mode=$("#sl_mode").val();
			
			var err="";
			if(urutan=="" || parseInt(urutan)<=0) err+="Urutan Disposisi belum diisi.</br>";
			if(nama=="") err+="Nama status belum diisi.</br>";
			
			if(err!=""){
				$("#loader_sub").html(err);
				return;
			}
			var fg="inputdatadisposisi";
			if(boxdatadisposisi.id>0){
				fg="editdatadisposisi";
			}
			
			var loadersimpandatadis=mload.loader({"keterangan":"Proses simpan data"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:fg,urutan:urutan,
					mode:mode,
					keterangan:keterangan,
					nama:nama,
					iddisposisi:boxdatadisposisi.iddisposisi,
					id:boxdatadisposisi.id}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("status")){
						if(e['status']==1){
							loadersimpandatadis.tutup();
							if(boxdatadisposisi.id<=0){
								var jumlahdis=parseInt(tabel.gettabel(boxdatadisposisi.tabel).getdata(boxdatadisposisi.baris,"jumlah_disposisi"))+1;
								boxdatadisposisi.el.innerHTML=jumlahdis;
								tabel.gettabel(boxdatadisposisi.tabel).setdata(boxdatadisposisi.baris,"jumlah_disposisi",jumlahdis);
							}
							
							var iddisposisi=boxdatadisposisi.iddisposisi;
							masterdisposisi.bukadis(iddisposisi,boxdatadisposisi.tabel,boxdatadisposisi.baris,boxdatadisposisi.el);
							masterdisposisi.bataldatadis();
						}else{
							loadersimpandatadis.error(e['pesan']);
						}
						
					}else{
						loadersimpandatadis.error([{"pesan":"Gagal proses simpan data"}]);
					}
				}
			});
		},
		setstatussub:function(a,b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"status")==1){
				st=0;
			}
			
			var loaderstatus=mload.loader({"keterangan":"Proses update status.."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"setStatussub",
					status:st,id:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					
					if(e==1){
						loaderstatus.tutup();
						if(st==1){
							d.className="mini_ok";
						}else{
							d.className="mini_dis";
						}
						tabel.gettabel(b).setdata(c,"status",st)
					}else{
						loaderstatus.error([{"pesan":"Gagal update status"}]);
					}
				}
			});
		},
		hapussub:function(a,b,c,d){
			var tbpar=tabel.gettabel(b).parrent;
			var iddisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data urutan status data disposisi ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "masterdisposisi",
						ikdata: {0:"hapusDatastatusdis",id:a}
					};
					
					$.ajax({
						url: lokal+"man.ajax.php",
						type: "POST",
						dataType: "json",
						async:true,
						data: ik_data,
						success: function(e){
							if(e==1){
								loaderhapus.tutup();
								var el=document.getElementById("btjumlahdis_"+tbpar.tabel+"_"+tbpar.baris);
								var jumlahdis=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_disposisi"))-1;
								el.innerHTML=jumlahdis;
								tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_disposisi",jumlahdis);
								masterdisposisi.bukadis(iddisposisi,tbpar.tabel,tbpar.baris,el);
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		bukajabatandis:function(a,b,c,d){
			if(tabel.gettabel(b).getdata(c,"mode")==2) return;
			
			var tbpar=tabel.gettabel(b).parrent;
			var namadis=(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nama")).toUpperCase();
			var namastatus=(tabel.gettabel(b).getdata(c,"nama")).toUpperCase();
			var iddisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
        	var idsubdisposisi=tabel.gettabel(b).getdata(c,"id");
            
			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>DATA JABATAN DISPOSISI \""+namadis+"\" STATUS \""+namastatus+"\"</b></div>";
            htm+="<select id=\"jumlah_hal_"+idtb+"\" class=\"slkecil\" onchange=\"masterdisposisi.loaddatajbte("+b+","+c+")\">";
            htm+="<option value=\"30\">30</option>";
            htm+="<option value=\"50\">50</option>";
            htm+="<option value=\"100\">100</option>";
            htm+="</select>";
            htm+="&nbsp;&nbsp;Hal <select id=\"hal_ke_"+idtb+"\" class=\"slkecil\" onchange=\"masterdisposisi.loaddatajbt("+b+","+c+")\"><option value=\"1\">1</option></select>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div id='loader_sub_"+idtb+"'></div>";
            htm+="<div id='grid_sub_"+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='bthijau medium' id='bt_input_"+idtb+"'>INPUT DATA JABATAN DISPOSISI</span>";
            
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            
            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_input_"+idtb).onclick=function(){
            	jumlahreq=0;
            	
                var ps={"box":"box_jabatandisposisi",
					"judul":"Input Data Jabatan Status "+namastatus,tinggi:"auto","lebar":"700"};
		
				boxjabatandisposisi=boxwin.load(ps);
				boxjabatandisposisi.id=0;
				boxjabatandisposisi.iddisposisi=iddisposisi;
				boxjabatandisposisi.idsubdisposisi=idsubdisposisi;
				boxjabatandisposisi.tabel=b;
				boxjabatandisposisi.baris=c;
				boxjabatandisposisi.el=d;
				boxjabatandisposisi.buka();
				
				$("#loader_jabatan").html("");
				$("#sl_modejabatan").val(1);
				$("#sl_jabatan").html("");
				
				$("#ttlnamajabatan").html("Jabatan Struktural");
				
				var obj=new Object;
				var cbf=masterdisposisi.reqcb(1);
				
				cbf.addCallbackToQueue(true, function() {
		            masterdisposisi.getjabatan(0);
		        });
				
            };
            
			masterdisposisi.loaddatajbt(b,c);
		},
		loaddatajbte:function(b,c){
			var idtb=b+"_"+c;
			$("#hal_ke_"+idtb).val(0);
			masterdisposisi.loaddatajbt(b,c);
		},
		loaddatajbt:function(b,c){
			var idtb=b+"_"+c;
			var tbpar=tabel.gettabel(b).parrent;
			var iddisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
        	var idsubdisposisi=tabel.gettabel(b).getdata(c,"id");
        	
			var loaderdatasub=mload.loading({"el":"loader_sub_"+idtb});
			var hal=$("#hal_ke_"+idtb).val();
			var jumlah=$("#jumlah_hal_"+idtb).val();
			var posisiawal=(hal-1)*jumlah;
			
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:"getjabatandisposisi",
					halaman:hal,jumlah:jumlah,
					iddisposisi:iddisposisi,
					idsubdisposisi:idsubdisposisi}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("data")){
						loaderdatasub.tutup();
						var data=e['data'];
						var jumlahhalaman=e['totalhalaman'];
						if(data.length>0){
							var htm="";
							for(var i=0;i<jumlahhalaman;i++){
								htm+="<option value=\""+(i+1)+"\">"+(i+1)+"</option>";
							}
							$("#hal_ke_"+idtb).html(htm);
							$("#hal_ke_"+idtb).val(hal);
							
							var tabeldata={
								box:"grid_sub_"+idtb,
								data:data,
								lebarmin:"500px",
								trklik:{"data":"id","fungsi":"barisklik"},
								title:"kategori Menu",
								tbclass:"table_grid-2",
								tabelpar:b,
                            	barispar:c,
								isi:[
										{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":hal,"jumlah":jumlah},
										{"col":"namajabatan","judul":"Mode Jabatan","tipe":"tpl","tpl":"btmodejabatan","lebar":"100px"},
										{"col":"namajabatan","judul":"Jabatan","tipe":"data"},
										{"align":"center","judul":"View","tipe":"tpl","tpl":"btjabatanview","lebar":"60px"},
										{"align":"center","judul":"Edit","tipe":"tpl","tpl":"btjabatanedit","lebar":"60px"},
										{"align":"center","judul":"Hapus","tipe":"tpl","tpl":"btjabatanhapus","lebar":"60px"},
										{"align":"center","judul":"Juml. Status","tipe":"tpl","tpl":"btjumlahstatus","lebar":"60px"},
										{"align":"center","judul":"","tipe":"tpl","tpl":"bteditjabatan","lebar":"60px"},
									],
								mod:"mod",
								module:"masterdisposisi"
							};
							tabel.multisub(tabeldata);
						}else{
							loaderdatasub.pesan("TIDAK ADA DATA");
						}
					}
				}
			});
		},
		editjabatan:function(a,b,c,d){
			var tbpar=tabel.gettabel(b).parrent;
			var tbparb=tabel.gettabel(tbpar.tabel).parrent;
			var namadis=(tabel.gettabel(tbparb.tabel).getdata(tbparb.baris,"nama")).toUpperCase();
			var namastatus=(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nama")).toUpperCase();
			var iddisposisi=tabel.gettabel(tbparb.tabel).getdata(tbparb.baris,"id");
        	var idsubdisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
        	var el=document.getElementById("btjumlahjabatan_"+tbpar.tabel+"_"+tbpar.baris);
			jumlahreq=0;
            	
            var ps={"box":"box_jabatandisposisi",
				"judul":"Edit Data Jabatan Status "+namastatus,tinggi:"auto","lebar":"700"};
	
			boxjabatandisposisi=boxwin.load(ps);
			boxjabatandisposisi.id=a;
			boxjabatandisposisi.iddisposisi=iddisposisi;
			boxjabatandisposisi.idsubdisposisi=idsubdisposisi;
			boxjabatandisposisi.tabel=tbpar.tabel;
			boxjabatandisposisi.baris=tbpar.baris;
			boxjabatandisposisi.el=el;
			boxjabatandisposisi.buka();
			
			var mode=tabel.gettabel(b).getdata(c,"mode");
			$("#loader_jabatan").html("");
			$("#sl_modejabatan").val(mode);
			$("#sl_jabatan").html("");
			
			var ttljb="Jabatan Struktural";
			if(mode==2) ttljb="Jabatan Fungsional";
			$("#ttlnamajabatan").html(ttljb);
			
			var obj=new Object;
			var cbf=masterdisposisi.reqcb(1);
			
			cbf.addCallbackToQueue(true, function() {
	            masterdisposisi.getjabatan(tabel.gettabel(b).getdata(c,"idjabatan"));
	        });
		},
		hapusjabatan:function(a,b,c,d){
			var tbpar=tabel.gettabel(b).parrent;
			var tbparb=tabel.gettabel(tbpar.tabel).parrent;
			var iddisposisi=tabel.gettabel(tbparb.tabel).getdata(tbparb.baris,"id");
			var idsubdisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data jabatan pada status disposisi ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "masterdisposisi",
						ikdata: {0:"hapusDatajabatandis",id:a}
					};
					
					$.ajax({
						url: lokal+"man.ajax.php",
						type: "POST",
						dataType: "json",
						async:true,
						data: ik_data,
						success: function(e){
							if(e==1){
								loaderhapus.tutup();
								var el=document.getElementById("btjumlahjabatan_"+tbpar.tabel+"_"+tbpar.baris);
								var jumlahjab=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_jabatan"))-1;
								el.innerHTML=jumlahjab;
								tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_jabatan",jumlahjab);
								masterdisposisi.bukajabatandis(idsubdisposisi,tbpar.tabel,tbpar.baris,el);
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		bataldatadisjbt:function(){
			if(boxjabatandisposisi!=null) boxjabatandisposisi.tutup();
			boxjabatandisposisi=null;
		},
		getjabatan:function(a){
			var idjabatan=a || 0;
			var mode=$("#sl_modejabatan").val();
			var namattl="Jabatan Struktural";
			if(mode==2) namattl="Jabatan Fungsional";
			
			$("#ttlnamajabatan").html(namattl);
			
			var loaderjabatan=mload.loading({"el":"sl_jabatan"});
			var fg="getdatajabatanstr";
			if(mode==2) fg="getjabatanfung";
			
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:fg}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					$("#sl_jabatan").html("");
					if(e!=false && e.length>0){
						var htm="";
						for(var i=0;i<e.length;i++){
							htm+="<option value='"+e[i]['id']+"'>"+e[i]['nama']+"</option>";
						}
						$("#sl_jabatan").html(htm);
						$("#sl_jabatan").val(idjabatan);
					}
				}
			});
		},
		inputdatadisjbt:function(){
			$("#loader_jabatan").html("");
			var mode=$("#sl_modejabatan").val();
			var idjabatan=$("#sl_jabatan").val();
			var err="";
			if(idjabatan=="" || parseInt(idjabatan)<=0) err+="Jabatan Disposisi belum diisi.</br>";
			
			if(err!=""){
				$("#loader_jabatan").html(err);
				return;
			}
			var fg="inputjabatandisposisi";
			if(boxjabatandisposisi.id>0){
				fg="editjabatandisposisi";
			}
			
			var loadersimpandatajbt=mload.loader({"keterangan":"Proses simpan data ...."});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:fg,idjabatan:idjabatan,
					mode:mode,
					iddisposisi:boxjabatandisposisi.iddisposisi,
					idsubdisposisi:boxjabatandisposisi.idsubdisposisi,
					id:boxjabatandisposisi.id}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("status")){
						if(e['status']==1){
							loadersimpandatajbt.tutup();
							if(boxjabatandisposisi.id<=0){
								var jumlahdis=parseInt(tabel.gettabel(boxjabatandisposisi.tabel).getdata(boxjabatandisposisi.baris,"jumlah_jabatan"))+1;
								boxjabatandisposisi.el.innerHTML=jumlahdis;
								tabel.gettabel(boxjabatandisposisi.tabel).setdata(boxjabatandisposisi.baris,"jumlah_jabatan",jumlahdis);
							}
							
							var iddisposisi=boxjabatandisposisi.iddisposisi;
							var idsubdisposisi=boxjabatandisposisi.idsubdisposisi;
							masterdisposisi.bukajabatandis(idsubdisposisi,boxjabatandisposisi.tabel,boxjabatandisposisi.baris,boxjabatandisposisi.el);
							masterdisposisi.bataldatadisjbt();
						}else{
							loadersimpandatajbt.error(e['pesan']);
						}
						
					}else{
						loadersimpandatajbt.error([{"pesan":"Gagal proses simpan data"}]);
					}
				}
			});
		},
		setstatusview:function(a,b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"view")==1){
				st=0;
			}
			
			var loaderstatus=mload.loader({"keterangan":"Proses update status.."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"setStatusview",
					status:st,id:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					
					if(e==1){
						loaderstatus.tutup();
						if(st==1){
							d.className="mini_ok";
						}else{
							d.className="mini_dis";
						}
						tabel.gettabel(b).setdata(c,"view",st)
					}else{
						loaderstatus.error([{"pesan":"Gagal update status"}]);
					}
				}
			});
		},
		setstatusedit:function(a,b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"edit")==1){
				st=0;
			}
			
			var loaderstatus=mload.loader({"keterangan":"Proses update status.."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"setStatusedit",
					status:st,id:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					
					if(e==1){
						loaderstatus.tutup();
						if(st==1){
							d.className="mini_ok";
							tabel.gettabel(b).setdata(c,"edit",st);
						}else{
							//d.className="mini_dis";
							var tbpar=tabel.gettabel(b).parrent;
							var iddisposisi=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
							var el=document.getElementById("btjumlahjabatan_"+tbpar.tabel+"_"+tbpar.baris);
							masterdisposisi.bukajabatandis(iddisposisi,tbpar.tabel,tbpar.baris,el);
						}
						
					}else{
						loaderstatus.error([{"pesan":"Gagal update status"}]);
					}
				}
			});
		},
		setstatushapus:function(a,b,c,d){
			var st=1;
			if(tabel.gettabel(b).getdata(c,"hapus")==1){
				st=0;
			}
			
			var loaderstatus=mload.loader({"keterangan":"Proses update status.."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"setStatushapus",
					status:st,id:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					
					
					if(e==1){
						loaderstatus.tutup();
						if(st==1){
							d.className="mini_ok";
						}else{
							d.className="mini_dis";
						}
						tabel.gettabel(b).setdata(c,"hapus",st)
					}else{
						loaderstatus.error([{"pesan":"Gagal update status"}]);
					}
				}
			});
		},
		bukastatus:function(a,b,c,d){
			var edit=tabel.gettabel(b).getdata(c,"edit");
			if(edit!=1){
				alert("Mode edit tidak aktif! Menu ini hanya untuk mode edit set aktif");
				return;
			}
			
			var tbpar=tabel.gettabel(b).parrent;
			var namadis=(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nama")).toUpperCase();
			var namajabatan=(tabel.gettabel(b).getdata(c,"namajabatan")).toUpperCase();
			var iddisposisistatus=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
        	var idstatusjabatan=tabel.gettabel(b).getdata(c,"id");
            
			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>DATA STATUS DISPOSISI \""+namadis+"\" JABATAN \""+namajabatan+"\"</b></div>";
            htm+="<select id=\"jumlah_hal_"+idtb+"\" class=\"slkecil\" onchange=\"masterdisposisi.loaddatajbste("+b+","+c+")\">";
            htm+="<option value=\"30\">30</option>";
            htm+="<option value=\"50\">50</option>";
            htm+="<option value=\"100\">100</option>";
            htm+="</select>";
            htm+="&nbsp;&nbsp;Hal <select id=\"hal_ke_"+idtb+"\" class=\"slkecil\" onchange=\"masterdisposisi.loaddatajbst("+b+","+c+")\"><option value=\"1\">1</option></select>";
            htm+="<div style='margin-top:10px;margin-bottom:10px;'>";
            htm+="<div id='loader_sub_"+idtb+"'></div>";
            htm+="<div id='grid_sub_"+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='bthijau medium' id='bt_input_"+idtb+"'>INPUT DATA STATUS EDIT</span>";
            
            htm+="</div>";
            htm+="</div>";
            
            htm+="</div>";
            var obj=new Object;
            obj.html=htm;
            
            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_input_"+idtb).onclick=function(){
            	var obj=new Object;
				obj['judul']="Pilih Status Edit";
				obj['modepilih']="multi";
				obj.pilih=function(a){
					var datastatus=a;
					var cari=false;
					if(datastatus.length>0){
						var dataid=[];
						for(var i=0;i<datastatus.length;i++){
							dataid.push(datastatus[i]['id']);
						}
						
						masterdisposisi.updatedatastatus(datastatus,idstatusjabatan,b,c,d);
					}
				};
				
				pilihstatus.bukastus(obj);
				
            };
            masterdisposisi.loaddatajbst(b,c);
		},
		loaddatajbste:function(b,c){
			var idtb=b+"_"+c;
			$("#hal_ke_"+idtb).val(0);
			masterdisposisi.loaddatajbst(b,c);
		},
		loaddatajbst:function(b,c){
			var idtb=b+"_"+c;
			var idstatusjabatan=tabel.gettabel(b).getdata(c,"id");
			
			var loaderdatasub=mload.loading({"el":"loader_sub_"+idtb});
			var hal=$("#hal_ke_"+idtb).val();
			var jumlah=$("#jumlah_hal_"+idtb).val();
			var posisiawal=(hal-1)*jumlah;
			
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterdisposisi",
				ikdata: {0:"getjabatandisposisistatus",
					halaman:hal,jumlah:jumlah,
					idstatusjabatan:idstatusjabatan}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("data")){
						loaderdatasub.tutup();
						var data=e['data'];
						var jumlahhalaman=e['totalhalaman'];
						if(data.length>0){
							var htm="";
							for(var i=0;i<jumlahhalaman;i++){
								htm+="<option value=\""+(i+1)+"\">"+(i+1)+"</option>";
							}
							$("#hal_ke_"+idtb).html(htm);
							$("#hal_ke_"+idtb).val(hal);
							
							var tabeldata={
								box:"grid_sub_"+idtb,
								data:data,
								lebarmin:"500px",
								trklik:{"data":"id","fungsi":"barisklik"},
								title:"kategori Menu",
								tbclass:"table_grid-3",
								tabelpar:b,
                            	barispar:c,
								isi:[
										{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":hal,"jumlah":jumlah},
										{"col":"namastatus","judul":"Nama Status","tipe":"data"},
										{"align":"center","judul":"","tipe":"tpl","tpl":"bteditst","lebar":"60px"},
									],
								mod:"mod",
								module:"masterdisposisi"
							};
							tabel.multisub(tabeldata);
						}else{
							loaderdatasub.pesan("TIDAK ADA DATA");
						}
					}
				}
			});
		},
		updatedatastatus:function(datast,a,b,c,d){
			var loaderstatus=mload.loader({"keterangan":"Proses update data status.."});
			var ik_data = {ajax: 1,mode: "mod",cl: "masterdisposisi",
				ikdata: {0:"updatedatastatus",
					datastatus:datast,
					iddisposisijabatan:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("status")){
						if(e['status']==1){
							loaderstatus.tutup();
							var jumlahst=parseInt(tabel.gettabel(b).getdata(c,"jumlah_status"))+datast.length;
							tabel.gettabel(b).setdata(c,"jumlah_status",jumlahst);
							d.innerHTML=jumlahst;
							
							masterdisposisi.bukastatus(a,b,c,d);
						}else{
							loaderstatus.error(e['pesan']);
						}
					}else{
						loaderstatus.error([{"pesan":"Gagal update status"}]);
					}
				}
			});
		},
		hapusjabatanst:function(a,b,c,d){
			var tbpar=tabel.gettabel(b).parrent;
			var iddisposisijabatan=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"id");
			
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data status disposisi jabatan ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "masterdisposisi",
						ikdata: {0:"hapusDatadisposisistatus",
							id:a}
					};
					
					$.ajax({
						url: lokal+"man.ajax.php",
						type: "POST",
						dataType: "json",
						async:true,
						data: ik_data,
						success: function(e){
							if(e==1){
								loaderhapus.tutup();
								var el=document.getElementById("btjumlahstatus_"+tbpar.tabel+"_"+tbpar.baris);
								var jumlahst=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_status"))-1;
								el.innerHTML=jumlahst;
								tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_status",jumlahst);
								masterdisposisi.bukastatus(iddisposisijabatan,tbpar.tabel,tbpar.baris,el);
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		}
	};
})();