var suratmasuk=(function(){
	var hal=0;
	var jumlah=30;
	var idsuratmasuk=0;
	var idsurat=0;
	var editstatus=0;
	var boxuploaddokumen=null;
	var statusdisposisi=0;
	var jumlahreq=0;
	var datadokumen=[];
	var datadisposisi=[];
	var namalib="";
	var boxnamadisposisi=null;
	var boxjabatandisposisi=null;
	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: "suratmasuk",
				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){
				suratmasuk.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			suratmasuk.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_suratmasuk").html("");
			var loaderdata=mload.loading({"el":"loader_datasuratmasuk"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "suratmasuk",
				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_suratmasuk",
							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},
									{"align":"center","judul":"Tanggal","tipe":"data","col":"tanggal_surat","lebar":"90px"},
									{"col":"nama","judul":"Detail Surat","tipe":"tpl","tpl":"btdetailsurat"},
									{"align":"center","judul":"Catatan","tipe":"tpl","tpl":"btcatatan","lebar":"60px"},
									{"align":"center","judul":"Cetak","tipe":"tpl","tpl":"btcetak","lebar":"40px"},
									{"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatus","lebar":"210px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"suratmasuk"
						};
						tabel.multisub(datatb);
					}else{
						loaderdata.pesan("BELUM ADA DATA");
					}
				}
			});
		},
		buat:function(a){
			document.location=lokal+"member/mod/suratmasuk?id="+a+"&scrmenu="+modmenu.getmenuscr();
		},
		kembali:function(){
			document.location=lokal+"member/mod/suratmasuk?scrmenu="+modmenu.getmenuscr();
		},
		edit:function(a){
			idsuratmasuk=a['id'];
			idsurat=a['idsurat'];
			editstatus=a['editstatus'];
			
			statusdisposisi=a['statusdisposisi'];
			$("#sl_kategori").val(a['idkategori']);
			$("#sl_kategorijenis").val(a['idkategorijenissurat']);
			
			suratmasuk.katch(a['idjenissurat']);
			
			$("#tanggalsurat").datepicker({
                inline: true,
                dateFormat: 'dd/mm/yy'
            });
            
            $("#tanggalterima").datepicker({
                inline: true,
                dateFormat: 'dd/mm/yy'
            });
            
            var obj=new Object;
			var cbf=suratmasuk.reqcb(2);
			
			cbf.addCallbackToQueue(true, function() {
	            suratmasuk.getcatatansurat(idsurat);
	        });
	        cbf.addCallbackToQueue(true, function() {
	            suratmasuk.getdokumensurat(idsuratmasuk);
	        });
	        
		},
		katch:function(a){
			var idjenissurat=a || 0;
			var idkategori=$("#sl_kategori").val();
			
			var loaderdatajenis=mload.loading({"el":"sl_jenis"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "suratmasuk",
				ikdata: {0:"getjenissurat",
					idkategori:idkategori}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("data")){
						loaderdatajenis.tutup();
						if(e['data'].length>0){
							$("#sl_jenis").html(e['html']);
							$("#sl_jenis").val(idjenissurat);
							
							suratmasuk.getdisposisi();
						}else{
							loaderdatajenis.pesan("Tidak ada data");
						}
						
					}else{
						loaderdatajenis.pesan("Tidak ada data");
					}
				}
			});
		},
		getcatatansurat:function(a){
			$("#grid_catatan").html("");
			var loaderdatacatatan=mload.loading({"el":"grid_catatan"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "suratmasuk",
				ikdata: {0:"getcatatansurat",idsurat:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.length>0){
						var tabeldata={
							box:"grid_catatan",
							data:e,
							lebarmin:"500px",
							trklik:{"data":"id","fungsi":"barisklik"},
							title:"kategori Menu",
							tbclass:"table_grid",
							isi:[
									{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":1},
									{"judul":"Nama Pegawai","tipe":"data","col":"namapegawai","lebar":"250px"},
									{"col":"catatan","judul":"Catatan","tipe":"data"},
									
								],
							mod:"mod",
							module:"suratmasuk"
						};
						tabel.multisub(tabeldata);
						
					}else{
						loaderdatacatatan.pesan("Tidak ada catatan");
					}
				}
			});
		},
		getdokumensurat:function(a){
			datadokumen=[];
			$("#grid_dokumen").html("");
			var loaderdatadok=mload.loading({"el":"grid_dokumen"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "suratmasuk",
				ikdata: {0:"getdokumensurat",
					idsuratmasuk:a}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.length>0){
						loaderdatadok.tutup();
						for(var i=0;i<e.length;i++){
							datadokumen.push({
								"nama":e[i]['nama'],
								"iddokumen":e[i]['iddokumen'],
								"edit":editstatus,
								"statusdisposisi":statusdisposisi
							});
						}
						suratmasuk.tabeldokumen();
					}else{
						loaderdatadok.pesan("Tidak ada data dokumen");
					}
				}
			});
		},
		getdisposisi:function(){
			var idjenissurat=$("#sl_jenis").val();
			datadisposisi=[];
			$("#grid_disposisi").html("");
			$("#boxdisposisi").hide();
			var loaderdatadis=mload.loading({"el":"loader_disposisi"});
			
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "suratmasuk",
				ikdata: {0:"getdatadisposisi",
					idsurat:idsurat,
					idjenissurat:idjenissurat}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e!=false && e.hasOwnProperty("status")){
						loaderdatadis.tutup();
						datadisposisi=e['data'];
						if(datadisposisi.length>0){
							$("#boxdisposisi").show();
							$("#grid_disposisi").html(e['obj']);
							for(var i=0;i<datadisposisi.length;i++){
								if(editstatus==1) $("#boxtambahdis_"+i).show();
								$("#grid_manual_"+i).html("Tidak ada data");
								var datadis=datadisposisi[i];
								if(datadis.length>0){
									for(var n=0;n<datadis.length;n++){
										datadisposisi[i][n]['editstatus']=editstatus;
										var datajabatan=datadisposisi[i][n]['datajabatan'];
										for(var x=0;x<datajabatan.length;x++){
											datadisposisi[i][n]['datajabatan'][x]['editstatus']=editstatus;
											var datastatus=datadisposisi[i][n]['datajabatan'][x]['datastatus'];
											for(var y=0;y<datastatus.length;y++){
												datadisposisi[i][n]['datajabatan'][x]['datastatus'][y]['editstatus']=editstatus;
											}
										}
									}
								}
								suratmasuk.tabeldisposisi(i);
								
							}
						}
					}else{
						loaderdatadis.pesan("Tidak ada data");
					}
				}
			});
		},
		inputnamadisposisi:function(a){
			var ps={"box":"box_namadisposisi",
				"judul":"Input Disposisi",tinggi:"auto","lebar":"700"};
	
			boxnamadisposisi=boxwin.load(ps);
			boxnamadisposisi.group=a;
			boxnamadisposisi.buka();
			
			var urutan=datadisposisi[a].length+1;
			$("#urutan").val(urutan);
			$("#namadisposisi").val("");
		},
		simpannamadatadis:function(){
			$("#loader_namadisposisi").html("");
			var urutan=$("#urutan").val();
			var nomorgroup=boxnamadisposisi.group;
			var nama=$("#namadisposisi").val();
			
			var err="";
			if(urutan=="") err+="Urutan disposisi wajib diisi";
			if(nama=="") err+="Nama disposisi wajib diisi";
			
			if(err!=""){
				$("#loader_namadisposisi").html(err);
				return;
			}
			
			datadisposisi[nomorgroup].push(
				{
					"id":0,
					"urutan":urutan,
					"nomorgroup":nomorgroup,
					"nama":nama,
					"jumlah_jabatan":0,
					"editstatus":editstatus,
					"datajabatan":[]
				}
			);
			
			suratmasuk.tabeldisposisi(nomorgroup);
		},
		batalnamadatadis:function(){
			if(boxnamadisposisi!=null) boxnamadisposisi.tutup();
			boxnamadisposisi=null;
		},
		bukajabatan:function(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>DATA JABATAN DISPOSISI </b></div>";
            htm+="<div id='loader_sub_"+idtb+"'></div>";
            htm+="<div id='grid_sub_"+idtb+"'>TIDAK ADA DATA</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;";
            if(editstatus==1){
	            htm+="<span class='bthijau medium' id='bt_input_"+idtb+"'>INPUT 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");
                }
            };
            
            var nomorgroup=tabel.gettabel(b).getdata(c,"nomorgroup");
            if(editstatus==1){
            	document.getElementById("bt_input_"+idtb).onclick=function(){
	            	var ps={"box":"box_jabatandisposisi",
						"judul":"Input Jabatan Disposisi",tinggi:"auto","lebar":"700"};
			
					boxjabatandisposisi=boxwin.load(ps);
					boxjabatandisposisi.nomorgroup=nomorgroup;
					boxjabatandisposisi.tabel=b;
					boxjabatandisposisi.baris=c;
					boxjabatandisposisi.el=d;
					boxjabatandisposisi.buka();
					
					suratmasuk.getjabatan();
	            };
            }
            
            var datajabatan=datadisposisi[nomorgroup][c]['datajabatan'];
            
            if(datajabatan.length>0){
            	var tabeldata={
					box:"grid_sub_"+idtb,
					data:datajabatan,
					lebarmin:"500px",
					trklik:{"data":"id","fungsi":"barisklik"},
					title:"kategori Menu",
					tbclass:"table_grid-1",
					tabelpar:b,
					barispar:c,
					isi:[
							{"judul":"Mode Jabatan","tipe":"tpl","tpl":"btmodejabatan","lebar":"120px"},
							{"judul":"Jabatan","tipe":"tpl","tpl":"btjabatan"},
							{"align":"center","judul":"View","tipe":"tpl","tpl":"btviewjab","lebar":"60px"},
							{"align":"center","judul":"Edit","tipe":"tpl","tpl":"bteditjab","lebar":"60px"},
							{"align":"center","judul":"Hapus","tipe":"tpl","tpl":"bthapusjab","lebar":"60px"},
							{"align":"center","judul":"Status","tipe":"tpl","tpl":"btjumlahstatus","lebar":"70px"},
							{"align":"center","judul":"","tipe":"tpl","tpl":"bteditjabatan","lebar":"70px"},
						],
					mod:"mod",
					module:"suratmasuk"
				};
				tabel.multisub(tabeldata);
            }
		},
		
		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: "suratmasuk",
				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 modejabatan=$("#sl_modejabatan").val();
			var idjabatan=$("#sl_jabatan").val();
			var jabatanstruk="";
			var jabatanfung="";
			if(modejabatan==1) jabatanstruk=kudus.selecttext("sl_jabatan");
			if(modejabatan==2) jabatanfung=kudus.selecttext("sl_jabatan");
			var err="";
			if(idjabatan=="" || parseInt(idjabatan)<=0) err+="Jabatan Disposisi belum diisi.</br>";
			
			if(err!=""){
				$("#loader_jabatan").html(err);
				return;
			}
			var idx=boxjabatandisposisi.baris;
			var nomorgroup=boxjabatandisposisi.nomorgroup;
			datadisposisi[nomorgroup][idx]['datajabatan'].push(
				{
					"id":0,
					"modejabatan":modejabatan,
					"idjabatan":idjabatan,
					"jabatanstruk":jabatanstruk,
					"jabatanfung":jabatanfung,
					"edit":0,
					"view":0,
					"hapus":0,
					"jumlah_status":0,
					"datastatus":[],
					"editstatus":editstatus
				}
			);
			
			var jumlah=parseInt(tabel.gettabel(boxjabatandisposisi.tabel).getdata(boxjabatandisposisi.baris,"jumlah_jabatan"))+1;
			boxjabatandisposisi.el.innerHTML=jumlah;
			tabel.gettabel(boxjabatandisposisi.tabel).setdata(boxjabatandisposisi.baris,"jumlah_jabatan",jumlah);
			
			suratmasuk.bukajabatan(boxjabatandisposisi.tabel,boxjabatandisposisi.baris,boxjabatandisposisi.el);
			suratmasuk.bataldatadisjbt();
		},
		hapusdisposisi:function(b,c,d){
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data disposisi ini ?? ",
				proses:function(){
					boxyesno.tutup();
					var nomorgroup=tabel.gettabel(b).getdata(c,"nomorgroup");
					datadisposisi[nomorgroup].splice(c,1);
					suratmasuk.tabeldisposisi(nomorgroup);
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		hapusdisposisijabatan:function(b,c,d){
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data jabatan disposisi ini ?? ",
				proses:function(){
					boxyesno.tutup();
					var tbpar=tabel.gettabel(b).parrent;
					var el=document.getElementById("btjumlahjabatan_"+tbpar.tabel+"_"+tbpar.baris);
					var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_jabatan"))-1;
					el.innerHTML=jumlah;
					tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_jabatan",jumlah);
					
					var nomorgroup=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nomorgroup");
					datadisposisi[nomorgroup][tbpar.baris]['datajabatan'].splice(c,1);
					suratmasuk.bukajabatan(tbpar.tabel,tbpar.baris,el);
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		bataldatadisjbt:function(){
			if(boxjabatandisposisi!=null) boxjabatandisposisi.tutup();
			boxjabatandisposisi=null;
		},
		tabeldisposisi:function(a){
			$("#grid_manual_"+a).html("Tidak ada data");
			var datadis=datadisposisi[a];
			
			if(datadis.length>0){
				var tabeldata={
					box:"grid_manual_"+a,
					data:datadis,
					lebarmin:"500px",
					trklik:{"data":"id","fungsi":"barisklik"},
					title:"kategori Menu",
					tbclass:"table_grid",
					isi:[
							{"judul":"Urutan","tipe":"data","col":"urutan","lebar":60},
							{"judul":"Nama","tipe":"data","col":"nama"},
							{"align":"center","judul":"Jabatan","tipe":"tpl","tpl":"btjumlahjabatan","lebar":"70px"},
							{"align":"center","judul":"","tipe":"tpl","tpl":"bteditnamadisposisi","lebar":"70px"},
						],
					mod:"mod",
					module:"suratmasuk"
				};
				tabel.multisub(tabeldata);
			}
			
			suratmasuk.batalnamadatadis();
		},
		setviewjab:function(b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"view")==0) st=1;
			d.className="mini_dis";
			if(st==1) d.className="mini_ok";
			
			tabel.gettabel(b).setdata(c,"view",st);
			var tbpar=tabel.gettabel(b).parrent;
			var nomorgroup=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nomorgroup");
			datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['view']=st;
		},
		seteditjab:function(b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"edit")==0) st=1;
			d.className="mini_dis";
			if(st==1) d.className="mini_ok";
			
			tabel.gettabel(b).setdata(c,"edit",st);
			var tbpar=tabel.gettabel(b).parrent;
			var nomorgroup=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nomorgroup");
			datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['edit']=st;
		},
		sethapusjab:function(b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"hapus")==0) st=1;
			d.className="mini_dis";
			if(st==1) d.className="mini_ok";
			
			tabel.gettabel(b).setdata(c,"hapus",st);
			var tbpar=tabel.gettabel(b).parrent;
			var nomorgroup=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nomorgroup");
			datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['hapus']=st;
		},
		bukastatus:function(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>DATA AKSES STATUS JABATAN</b></div>";
            htm+="<div id='loader_sub_"+idtb+"'></div>";
            htm+="<div id='grid_sub_"+idtb+"'>TIDAK ADA DATA</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;";
            if(editstatus==1){
	            htm+="<span class='bthijau medium' id='bt_input_"+idtb+"'>INPUT AKSES STATUS</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");
                }
            };
            var tbpar=tabel.gettabel(b).parrent;
            var nomorgroup=tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"nomorgroup");
            var datastatus=datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['datastatus'];
            
            if(editstatus==1){
            	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){
							for(var i=0;i<datastatus.length;i++){
								datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['datastatus'].push({
									"idstatus":datastatus[i]['id'],
									"namastatus":datastatus[i]['nama'],
									"editstatus":editstatus
								})
							}
							var jumlahstatus=parseInt(datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['jumlah_status'])+datastatus.length;
							datadisposisi[nomorgroup][tbpar.baris]['datajabatan'][c]['jumlah_status']=jumlahstatus;
							d.innerHTML=jumlahstatus;
							tabel.gettabel(b).setdata(c,"jumlah_status",jumlahstatus);
							suratmasuk.bukastatus(b,c,d);
						}
					};
					
					pilihstatus.bukastus(obj);
	            };
            }
            
            
            if(datastatus.length>0){
            	var tabeldata={
					box:"grid_sub_"+idtb,
					data:datastatus,
					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},
							{"judul":"Nama Status","tipe":"data","col":"namastatus"},
							{"align":"center","judul":"","tipe":"tpl","tpl":"bteditstatus","lebar":"70px"},
						],
					mod:"mod",
					module:"suratmasuk"
				};
				tabel.multisub(tabeldata);
            }
		},
		hapusstatusjabatan:function(b,c,d){
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data akses status jabatan disposisi ini ?? ",
				proses:function(){
					boxyesno.tutup();
					var tbpar=tabel.gettabel(b).parrent;
					var tbparmain=tabel.gettabel(tbpar.tabel).parrent;
					
					var el=document.getElementById("btjumlahstatus_"+tbpar.tabel+"_"+tbpar.baris);
					var jumlah=parseInt(tabel.gettabel(tbpar.tabel).getdata(tbpar.baris,"jumlah_status"))-1;
					el.innerHTML=jumlah;
					tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_status",jumlah);
					
					var nomorgroup=tabel.gettabel(tbparmain.tabel).getdata(tbparmain.baris,"nomorgroup");
					datadisposisi[nomorgroup][tbparmain.baris]['datajabatan'][tbpar.baris]['datastatus'].splice(c,1);
					suratmasuk.bukastatus(tbpar.tabel,tbpar.baris,el);
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		inputdokumen:function(){
			var ps={"box":"box_upload_dok",
				"judul":"Upload Dokumen Surat",tinggi:"auto","lebar":"800"};
	
			boxuploaddokumen=boxwin.load(ps);
			boxuploaddokumen.id=0;
			boxuploaddokumen.iddokumen=0;
			boxuploaddokumen.tabel=0;
			boxuploaddokumen.baris=0;
			boxuploaddokumen.el=null;
			boxuploaddokumen.buka();
			
			$("#loader_upload").html("");
			$("#namadokumen").val("");
			$("#upload_dokumen").html("");
			
			upload.tambahupload("upload_dokumen",suratmasuk.objupload("UPLOAD DOKUMEN SURAT","tidak"));
		},
		simpandokumen:function(){
			$("#loader_upload").html("");
			var err="";
			var namadok=$("#namadokumen").val();
			if(namadok=="") err+="Nama dokumen belum diisi!<br/>";
			if(boxuploaddokumen.iddokumen<=0) err+="Dokumen belum diupload!<br/>";
			if(err!=""){
				$("#loader_upload").html(err);
				return;
			}
			
			datadokumen.push({
				"nama":namadok,
				"iddokumen":boxuploaddokumen.iddokumen,
				"edit":editstatus,
				"statusdisposisi":statusdisposisi
			});
			
			suratmasuk.tabeldokumen();
			suratmasuk.batalsimpan();
		},
		batalsimpan:function(){
			if(boxuploaddokumen!=null) boxuploaddokumen.tutup();
			boxuploaddokumen=null;
		},
		hapusdokumen:function(b,c,d){
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data dokumen surat masuk ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					datadokumen.splice(c,1);
					suratmasuk.tabeldokumen();
					loaderhapus.tutup();
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		tabeldokumen:function(){
			$("#grid_dokumen").html("Tidak ada data!");
			
			if(datadokumen.length>0){
				var tabeldata={
					box:"grid_dokumen",
					data:datadokumen,
					lebarmin:"500px",
					trklik:{"data":"id","fungsi":"barisklik"},
					title:"kategori Menu",
					tbclass:"table_grid",
					isi:[
							{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
							{"judul":"Nama Dokumen","tipe":"data","col":"nama"},
							{"align":"center","judul":"Dok","tipe":"tpl","tpl":"btdokumen","lebar":"70px"},
							{"align":"center","judul":"","tipe":"tpl","tpl":"bteditdokumen","lebar":"70px"},
						],
					mod:"mod",
					module:"suratmasuk"
				};
				tabel.multisub(tabeldata);
			}
		},
		simpan:function(a){
			var submitdata=a || 0;
			
			$("#loader_suratmasuk").html("");
			var idkategori=$("#sl_kategori").val();
			var idjenissurat=$("#sl_jenis").val();
			var idkategorijenis=$("#sl_kategorijenis").val();
			var nomor=$("#nomor").val();
			var tanggalsurat=$("#tanggalsurat").val();
			var tanggalterima=$("#tanggalterima").val();
			var pengirim=$("#pengirim").val();
			var alamatpengirim=$("#alamatpengirim").val();
			var tujuan=$("#tujuan").val();
			var keperluan=$("#keperluan").val();
			var keterangan=$("#keterangan").val();
			
			var err="";
			if(nomor=="") err+="Nomor surat belum diisi.</br>";
			if(tanggalsurat=="") err+="Tanggal surat belum diisi.</br>";
			if(tanggalterima=="") err+="Tanggal terima surat belum diisi.</br>";
			if(pengirim=="") err+="Pengirim surat belum diisi.</br>";
			if(tujuan=="") err+="Tujuan surat belum diisi.</br>";
			if(keperluan=="") err+="Keperluan surat belum diisi.</br>";
			
			if(err!=""){
				$("#loader_suratmasuk").html(err);
				return;
			}
			var fg="inputsuratmasuk";
			if(idsuratmasuk>0){
				fg="editsuratmasuk";
			}
			
			var loadersimpan=mload.loader({"keterangan":"Proses simpan data"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "suratmasuk",
				ikdata: {0:fg,
					idkategori:idkategori,
					idjenissurat:idjenissurat,
					idkategorijenis:idkategorijenis,
					nomor:nomor,
					tanggalsurat:tanggalsurat,
					tanggalterima:tanggalterima,
					pengirim:pengirim,
					alamatpengirim:alamatpengirim,
					keperluan:keperluan,
					tujuan:tujuan,
					keterangan:keterangan,
					datadisposisi:datadisposisi,
					datadokumen:datadokumen,
					submitdata:submitdata,
					id:idsuratmasuk}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					if(e.hasOwnProperty("status")){
						if(e['status']==1){
							suratmasuk.kembali();
						}else{
							loadersimpan.error(e['pesan']);
						}
					}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 surat masuk ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "suratmasuk",
						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 && e.hasOwnProperty("status")){
								if(e['status']==1){
									loaderhapus.error([{"pesan":"Berhasil"}]);
									suratmasuk.load();
								}else{
									loaderhapus.error(e['pesan']);
								}
								
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		lihatcatatan: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>CATATAN </b></div>";
            htm+="<select id=\"jumlah_hal_"+idtb+"\" class=\"slkecil\" onchange=\"suratmasuk.loaddatacttpe("+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=\"suratmasuk.loaddatactt("+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+="</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");
                }
            };
            
            suratmasuk.loaddatactt(b,c);
		},
		loaddatactte:function(b,c){
			var idtb=b+"_"+c;
			$("#hal_ke_"+idtb).val(0);
			suratmasuk.loaddatactt(b,c);
		},
		loaddatactt:function(b,c){
			var idtb=b+"_"+c;
			var idsurat=tabel.gettabel(b).getdata(c,"idsurat");
			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: "suratmasuk",
				ikdata: {0:"getdataCatatan",
					halaman:hal,jumlah:jumlah,
					idsurat:idsurat}
			};
			
			$.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:[
										{"align":"center","judul":"Tanggal","tipe":"data","col":"tanggal","lebar":"140px","format":"tanggal"},
										{"judul":"Nama Pegawai","tipe":"data","col":"namapegawai","lebar":"120px"},
										{"col":"catatan","judul":"Catatan","tipe":"data"},
									],
								mod:"mod",
								module:"suratmasuk"
							};
							tabel.multisub(tabeldata);
						}else{
							loaderdatasub.pesan("TIDAK ADA DATA");
						}
					}
				}
			});
		},
		initcetak:function(a,b,c,d){
			var status=tabel.gettabel(b).getdata(c,"status");
			var statusdisposisi=tabel.gettabel(b).getdata(c,"statusdisposisi");
			if(status!=28 || statusdisposisi!=1) return;
			var jenissurat=tabel.gettabel(b).getdata(c,"jenissurat");
			//var namapegawai=tabel.gettabel(b).getdata(c,"namapegawai");
			var lib=tabel.gettabel(b).getdata(c,"lib");
			var idsurat=tabel.gettabel(b).getdata(c,"idsurat");
			
			var datajs={
				"jenissurat":jenissurat,
				//"namapegawai":namapegawai,
				"lib":lib,
				"idsurat":idsurat
			};
			
			suratmasuk.cetaksurat(datajs);
		},
		cetaksurat:function(a){
			var jenissurat=a['jenissurat'];
			//var namapegawai=a['namapegawai'];
			var namalib=a['lib'];
			
			var judulsurat="Cetak "+jenissurat;
			//if(namapegawai!="") judulsurat+=" "+namapegawai; 
			var obj={
				"judul":judulsurat,
				"lib":namalib,
				"data":{"idsurat":a['idsurat']}
			};
			cetak.cetaksample(obj);
		},
		lihatdokumen:function(a){
			var iddok=a;
			if(iddok<=0) return;
			var myWindow = window.open(lokal+"service.php?pos=suratmasuk&mode=mod&fl=download&id="+iddok, "", "left=100,top=50,width=800, height=600");
		},
		objupload:function(a,b){
			var nama=a || "PILIH FILE UNTUK UPLOAD DOKUMEN SK";
			var prev=b || "tidak";
			
			var disabled="tidak";
			if(editstatus==0) disabled="ya";
			
			var obp=new Object;
			obp.proses=function(dataupload){
				boxuploaddokumen.iddokumen=dataupload.id;
				var filelama=dataupload.nama
				$("#upload_dokumen").html("");
				upload.tambahupload("upload_dokumen",suratmasuk.objupload(filelama,"ya"));
			};
			
			obp.hapus=function(a){
				
			};
			obp.lihat=function(a){
				suratmasuk.lihatdokumen(boxuploaddokumen.iddokumen);
			};
			
			obp.pilihfile=function(a){
				boxuploaddokumen.iddokumen=0;
			};
			
			var dtpost={"jenis":13};
			var obj={"tautan":lokal+"service.php?pos=suratmasuk&mode=mod&fl=upload",
				"status":lokal+"service.php?pos=suratmasuk&mode=mod&fl=progres",
				"tutup":"tidak","finish":obp,disupload:disabled,
				"data":dtpost,"namafile":nama,"preview":prev};
			return obj;
		},
	};
})();