var masterpegawai=(function(){
	var hal=0;
	var jumlah=30;
	var idmasterpegawai=0;
	var boxlampiran=null;
	var boxdokumen=null;
	var datalampiran=[];
	var editstatus=1;
	var disabled="tidak";
	return{
		caricanggih:function(){
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "masterpegawai",
				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){
				masterpegawai.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			masterpegawai.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_masterpegawai").html("");
			var loaderdata=mload.loading({"el":"loader_datamasterpegawai"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterpegawai",
				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_masterpegawai",
							data:e,
							lebarmin:"500px",
							trklik:{"data":"id","fungsi":"barisklik"},
							title:"kategori Menu",
							isi:[
									{"col":"id","judul":"ID","tipe":"data","align":"center","lebar":"50px"},
									{"col":"nama","judul":"Detail Pegawai","tipe":"tpl","tpl":"btdetail"},
									{"col":"golongan","judul":"Gol.","tipe":"data","col":"golongan","lebar":"60px","align":"center"},
									{"align":"center","judul":"Lamp.","tipe":"tpl","tpl":"btjumlahlampiran","lebar":"60px"},
									{"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatus","lebar":"120px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"masterpegawai"
						};
						tabel.multisub(datatb);
					}else{
						loaderdata.pesan("BELUM ADA JABATAN");
					}
				}
			});
		},
		buat:function(a){
			document.location=lokal+"member/mod/masterpegawai?id="+a+"&scrmenu="+modmenu.getmenuscr();
		},
		kembali:function(){
			document.location=lokal+"member/mod/masterpegawai?scrmenu="+modmenu.getmenuscr();
		},
		edit:function(a){
			idmasterpegawai=a['id'];
			editstatus=a['editstatus'];
			disabled="ya";
			if(editstatus==1) disabled="tidak";
			$("#sl_jeniskelamin").val(a['idjeniskelamin']);
			$("#sl_golongan").val(a['idgolongan']);
			$("#sl_jabatanstr").val(a['idjabatanstruk']);
			$("#sl_jabatanfu").val(a['idjabatanfung']);
			$("#sl_propinsi").val(a['idpropinsi']);
			$("#sl_pendidikan").val(a['idpendidikan']);
			$("#sl_statusasn").val(a['statusasn']);
			
			$("#tanggallahir").datepicker({
                inline: true,
                dateFormat: 'dd/mm/yy'
            });
            $("#tanggalskawal").datepicker({
                inline: true,
                dateFormat: 'dd/mm/yy'
            });
			var idkota=a['idkota'];
			masterpegawai.propch(idkota);
			
			masterpegawai.getlampiran(idmasterpegawai);
			
		},
		propch:function(a){
			var idkota=0 || a;
			var idpropinsi=$("#sl_propinsi").val();
			var laoderprop=mload.loading({"el":"sl_kota"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterpegawai",
				ikdata: {0:"getdatakota",
					idpropinsi:idpropinsi}
			};
			
			$.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 htm="";
						for(var i=0;i<e.length;i++){
							htm+="<option value='"+e[i]['id']+"'>"+e[i]['kota']+"</option>";
						}
						
						$("#sl_kota").html(htm);
						$("#sl_kota").val(idkota);
					}else{
						laoderprop.pesan("Gagal");
					}
				}
			});
		},
		simpan:function(){
			$("#loader_masterpegawai").html("");
			var nm=$("#nama").val();
			var alamat=$("#alamat").val();
			var tempatlahir=$("#tempatlahir").val();
			var tanggallahir=$("#tanggallahir").val();
			var idjeniskelamin=$("#sl_jeniskelamin").val();
			var nip=$("#nip").val();
			var nohp=$("#nohp").val();
			var notelp=$("#notelp").val();
			var email=$("#email").val();
			var idpropinsi=$("#sl_propinsi").val();
			var idkota=$("#sl_kota").val();
			var idgolongan=$("#sl_golongan").val();
			var idjabatanstr=$("#sl_jabatanstr").val();
			var idjabatanfu=$("#sl_jabatanfu").val();
			var idpendidikan=$("#sl_pendidikan").val();
			var namasekolah=$("#namasekolah").val();
			var tanggalskawal=$("#tanggalskawal").val();
			var status=$("#sl_status").val();
			var statusasn=$("#sl_statusasn").val();
			var arrlampiran=datalampiran;
			
			var err="";
			if(nm=="") err+="Nama Pegawai belum diisi.</br>";
			//if(nip=="") err+="NIP Pegawai belum diisi.</br>";
			if(alamat=="") err+="Alamat Pegawai belum diisi.</br>";
			if(tempatlahir=="") err+="Tempat lahir Pegawai belum diisi.</br>";
			if(tanggallahir=="") err+="Tanggal lahir Pegawai belum diisi.</br>";
			if(tanggalskawal=="") err+="Tanggal SK Pengangkatan Pertama Pegawai belum diisi.</br>";
			if(nm=="") err+="Nama Pegawai belum diisi.</br>";
			if(idmasterpegawai>0) arrlampiran=[];
			
			if(err!=""){
				$("#loader_masterpegawai").html(err);
				return;
			}
			var fg="inputmasterpegawai";
			if(idmasterpegawai>0){
				fg="editmasterpegawai";
			}
			
			var loadersimpan=mload.loader({"keterangan":"Proses simpan data"});
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterpegawai",
				ikdata: {0:fg,nama:nm,
					nip:nip,
					alamat:alamat,tempatlahir:tempatlahir,
					tanggallahir:tanggallahir,
					idjeniskelamin:idjeniskelamin,
					nohp:nohp,notelp:notelp,
					email:email,
					idpropinsi:idpropinsi,
					idkota:idkota,
					idpendidikan:idpendidikan,
					idgolongan:idgolongan,
					idjabatanstruk:idjabatanstr,
					idjabatanfung:idjabatanfu,
					namasekolah:namasekolah,
					tanggalskawal:tanggalskawal,
					statusasn:statusasn,
					status:status,
					datalampiran:arrlampiran,
					id:idmasterpegawai}
			};
			
			$.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){
							masterpegawai.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 pegawai ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "masterpegawai",
						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"}]);
									masterpegawai.load();
								}else{
									loaderhapus.error(e['pesan']);
								}
								
							}else{
								loaderhapus.error([{"pesan":"Gagal hapus data"}]);
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		getlampiran:function(a){
			datalampiran=[];
			var loaderlampiran=mload.loading({"el":"grid_lampiran"});
			
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterpegawai",
				ikdata: {0:"getdatalampiran",idpegawai: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){
						loaderlampiran.tutup();
						for(var i=0;i<e.length;i++){
							e[i]['editstatus']=editstatus;
							var datadokumen=e[i]['datadokumen'];
							for(var n=0;n<datadokumen.length;n++){
								datadokumen[n]['editstatus']=editstatus;
							}
							e[i]['datadokumen']=datadokumen;
						}
						
						datalampiran=e;
						masterpegawai.tabellampiran();
					}else{
						loaderlampiran.pesan("Tidak ada data");
					}
				}
			});
		},
		tabellampiran:function(){
			$("#grid_lampiran").html("Tidak ada data");
			if(datalampiran.length>0){
				var datatb={
					box:"grid_lampiran",
					data:datalampiran,
					lebarmin:"500px",
					trklik:{"data":"id","fungsi":"barisklik"},
					title:"Data Dokumen",
					isi:[
							{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
							{"col":"nama","judul":"Nama Lampiran","tipe":"data"},
							{"align":"center","judul":"Dok.","tipe":"tpl","tpl":"btjumlahdokumen","lebar":"60px"},
							{"align":"center","judul":"","tipe":"tpl","tpl":"bteditlampiran","lebar":"70px"},
						],
					mod:"mod",
					module:"masterpegawai"
				};
				tabel.multisub(datatb);
			}
		},
		inputlampiran:function(){
			var ps={"box":"box_lampiran",
				"judul":"Input Lampiran Pegawai ",tinggi:"auto","lebar":"700"};
	
			boxlampiran=boxwin.load(ps);
			boxlampiran.idpegawai=idmasterpegawai;
			boxlampiran.id=0;
			boxlampiran.mode=0;
			boxlampiran.tabel=0;
			boxlampiran.baris=0;
			boxlampiran.buka();
			
			$("#namalampiran").val("");
			$("#loader_lampiran").html("");
		},
		editlampiran:function(b,c,d){
			var ps={"box":"box_lampiran",
				"judul":"Edit Lampiran Pegawai ",tinggi:"auto","lebar":"700"};
	
			boxlampiran=boxwin.load(ps);
			boxlampiran.idpegawai=idmasterpegawai;
			boxlampiran.id=tabel.gettabel(b).getdata(c,"id");
			boxlampiran.mode=1;
			boxlampiran.tabel=b;
			boxlampiran.baris=c;
			boxlampiran.buka();
			
			$("#namalampiran").val(tabel.gettabel(b).getdata(c,"nama"));
			$("#loader_lampiran").html("");
		},
		hapuslampiran:function(b,c,d){
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data lampiran pegawai ini ?? ",
				proses:function(){
					var loaderhapus=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					if(idmasterpegawai>0){
						var idlampiran=tabel.gettabel(b).getdata(c,"id");
						var loaderhapuslamp=mload.loader({"keterangan":"Proses hapus data"});
						var ik_data = {
							ajax: 1,
							mode: "mod",
							cl: "masterpegawai",
							ikdata: {0:"hapusdataLampiran",
								id:idlampiran}
						};
						
						$.ajax({
							url: lokal+"man.ajax.php",
							type: "POST",
							dataType: "json",
							async:true,
							data: ik_data,
							success: function(e){
								if(e!=false && e==1){
									loaderhapuslamp.tutup();
									masterpegawai.getlampiran(idmasterpegawai);
								}else{
									loadersimanlamp.error([{"pesan":"Terjadi kesalahan"}]);
								}
							}
						});
					}else{
						datalampiran.splice(c,1);
						loaderhapus.tutup();
						masterpegawai.tabellampiran();
					}
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
			
		},
		simpanlampiran:function(){
			$("#loader_lampiran").html("");
			var nama=$("#namalampiran").val();
			if(nama==""){
				$("#loader_lampiran").html("Nama lampiran belum diisi!");
				return;
			}
			
			if(idmasterpegawai>0){
				var loadersimanlamp=mload.loading({"el":"loader_lampiran"});
				var fgd="inputLampiran";
				if(boxlampiran.id>0) fgd="editLampiran";
	            var ik_data = {
					ajax: 1,
					mode: "mod",
					cl: "masterpegawai",
					ikdata: {0:fgd,
						idpegawai:boxlampiran.idpegawai,
						nama:nama,
						id:boxlampiran.id}
				};
				
				$.ajax({
					url: lokal+"man.ajax.php",
					type: "POST",
					dataType: "json",
					async:true,
					data: ik_data,
					success: function(e){
						if(e!=false && e==1){
							loadersimanlamp.tutup();
							masterpegawai.batallampiran();
							masterpegawai.getlampiran(idmasterpegawai);
						}else{
							loadersimanlamp.pesan("Terjadi kesalahan");
						}
					}
				});
			}else{
				if(boxlampiran.mode<=0){
					datalampiran.push({"id":0,
						"nama":nama,
						"jumlah_dokumen":0,
						"datadokumen":[],
						"editstatus":editstatus});
				}else{
					datalampiran[boxlampiran.baris]['nama']=nama;
				}
				masterpegawai.tabellampiran();
				masterpegawai.batallampiran();
			}
		},
		batallampiran:function(){
			if(boxlampiran!=null) boxlampiran.tutup();
			boxlampiran=null;
		},
		lhatlampiran: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>LAMPIRAN PEGAWAI </b></div>";
            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");
                }
            };
            
            var loadersub=mload.loading({"el":"loader_sub_"+idtb});
            var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterpegawai",
				ikdata: {0:"getdatalampiran",idpegawai: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){
						loadersub.tutup();
						var datatb={
							box:"grid_sub_"+idtb,
							data:e,
							lebarmin:"500px",
							trklik:{"data":"id","fungsi":"barisklik"},
							title:"Data Dokumen",
							isi:[
									{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Nama Lampiran","tipe":"data"},
									{"align":"center","judul":"Dok.","tipe":"tpl","tpl":"btjumlahdokumen","lebar":"60px"},
								],
							mod:"mod",
							module:"masterpegawai"
						};
						tabel.multisub(datatb);
						
					}else{
						loadersub.pesan("Tidak ada Lampiran");
					}
				}
			});
		},
		bukalampirandok: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>DOKUMEN</b></div>";
            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;";
            if(editstatus==1){
            	htm+="<span class='bthijau medium' id='bt_upload_"+idtb+"'>UPLOAD DOKUMEN</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");
                }
            };
            
            if(editstatus==1){
            	document.getElementById("bt_upload_"+idtb).onclick=function(){
	                var ps={"box":"boxwin_uploaddokumen",
						"judul":"Upload Dokumen ",tinggi:"auto","lebar":"700"};
			
					boxdokumen=boxwin.load(ps);
					boxdokumen.iddokumen=0;
					boxdokumen.idlampiran=tabel.gettabel(b).getdata(c,"id");
					boxdokumen.tabel=b;
					boxdokumen.baris=c;
					boxdokumen.buka();
					
					$("#namadokumen").val("");
					$("#loader_uploaddokumen").html("");
					$("#box_uploaddokumen").html("");
					upload.tambahupload("box_uploaddokumen",masterpegawai.objupload("PILIH FILE UNTUK UPLOAD DOKUMEN","tidak"));
	            };
            }
            var datadokumen=datalampiran[c]['datadokumen'];
            $("#grid_sub_"+idtb).html("Tidak ada dokumen!");
            if(datadokumen.length>0){
            	var datatb={
					box:"grid_sub_"+idtb,
					data:datadokumen,
					lebarmin:"500px",
					trklik:{"data":"id","fungsi":"barisklik"},
					title:"Data Dokumen",
					tabelpar:b,
                	barispar:c,
					isi:[
							{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
							{"col":"nama","judul":"Nama Dokumen","tipe":"data"},
							{"align":"center","judul":"Dok.","tipe":"tpl","tpl":"btdokumen","lebar":"60px"},
							{"align":"center","judul":"","tipe":"tpl","tpl":"bteditdokumen","lebar":"60px"},
						],
					mod:"mod",
					module:"masterpegawai"
				};
				tabel.multisub(datatb);
            }
		},
		simpanupload:function(){
			$("#loader_uploaddokumen").html("");
			var nama=$("#namadokumen").val();
			var err="";
			if(nama=="") err+="Nama dokumen harap diisi!<br/>";
			if(boxdokumen.iddokumen<=0) err+="File dokumen belum diupload!<br/>";
			if(err!=""){
				$("#loader_uploaddokumen").html(err);
				return;
			}
			
			if(idmasterpegawai>0){
				var loadersimpanupload=mload.loading({"el":"loader_uploaddokumen"});
				var ik_data = {
					ajax: 1,
					mode: "mod",
					cl: "masterpegawai",
					ikdata: {0:"inputDokumen",
						idlampiran:boxdokumen.idlampiran,
						iddokumen:boxdokumen.iddokumen,
						nama:nama}
				};
				
				$.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){
								loadersimpanupload.tutup();
								var datadokumen=datalampiran[boxdokumen.baris]['datadokumen'];
								datadokumen.push({
									"id":e['pesan'],
									"nama":nama,
									"iddokumen":boxdokumen.iddokumen,
									"editstatus":editstatus
								});
								datalampiran[boxdokumen.baris]['datadokumen']=datadokumen;
								var jumlahdok=datadokumen.length;
								var el=document.getElementById("btjumlahdokumen_"+boxdokumen.tabel+"_"+boxdokumen.baris);
								el.innerHTML=jumlahdok;
								tabel.gettabel(boxdokumen.tabel).setdata(boxdokumen.baris,"jumlah_dokumen",jumlahdok);
								
								masterpegawai.bukalampirandok(boxdokumen.tabel,boxdokumen.baris,el);
								masterpegawai.batalupload();
							}else{
								loadersimpanupload.pesan("Terjadi kesalahan");
							}
							
						}else{
							loadersimpanupload.pesan("Terjadi kesalahan");
						}
					}
				});
			}else{
				var datadokumen=datalampiran[boxdokumen.baris]['datadokumen'];
				datadokumen.push({
					"id":0,
					"nama":nama,
					"iddokumen":boxdokumen.iddokumen,
					"editstatus":editstatus
				});
				datalampiran[boxdokumen.baris]['datadokumen']=datadokumen;
				var el=document.getElementById("btjumlahdokumen_"+boxdokumen.tabel+"_"+boxdokumen.baris);
				var jumlahdok=datadokumen.length;
				var el=document.getElementById("btjumlahdokumen_"+boxdokumen.tabel+"_"+boxdokumen.baris);
				el.innerHTML=jumlahdok;
				tabel.gettabel(boxdokumen.tabel).setdata(boxdokumen.baris,"jumlah_dokumen",jumlahdok);
								
				masterpegawai.bukalampirandok(boxdokumen.tabel,boxdokumen.baris,el);
				masterpegawai.batalupload();
			}
		},
		batalupload:function(){
			if(boxdokumen!=null) boxdokumen.tutup();
			boxdokumen=null;
		},
		hapusdokumen:function(b,c,d){
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data dokumen lampiran pegawai ini ?? ",
				proses:function(){
					var loaderhapusdok=mload.loader({"keterangan":"Proses hapus data.."});
					boxyesno.tutup();
					if(idmasterpegawai>0){
						var iddata=tabel.gettabel(b).getdata(c,"id");
						var loaderhapusdok=mload.loader({"keterangan":"Proses hapus data"});
						var ik_data = {
							ajax: 1,
							mode: "mod",
							cl: "masterpegawai",
							ikdata: {0:"hapusdatadokumen",
								id:iddata}
						};
						
						$.ajax({
							url: lokal+"man.ajax.php",
							type: "POST",
							dataType: "json",
							async:true,
							data: ik_data,
							success: function(e){
								if(e!=false && e==1){
									loaderhapusdok.tutup();
									var tbpar=tabel.gettabel(b).parrent;
									var datadokumen=datalampiran[tbpar.baris]['datadokumen'];
									datadokumen.splice(c,1);
									datalampiran[tbpar.baris]['datadokumen']=datadokumen;
									
									var jumlahdokumen=datadokumen.length;
									var el=document.getElementById("btjumlahdokumen_"+tbpar.tabel+"_"+tbpar.baris);
									el.innerHTML=jumlahdokumen;
									tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_dokumen",jumlahdokumen);
									masterpegawai.bukalampirandok(tbpar.tabel,tbpar.baris,el);
							
								}else{
									loaderhapusdok.error([{"pesan":"Terjadi kesalahan"}]);
								}
							}
						});
					}else{
						loaderhapusdok.tutup();
						var tbpar=tabel.gettabel(b).parrent;
						var datadokumen=datalampiran[tbpar.baris]['datadokumen'];
						datadokumen.splice(c,1);
						datalampiran[tbpar.baris]['datadokumen']=datadokumen;
						
						var jumlahdokumen=datadokumen.length;
						var el=document.getElementById("btjumlahdokumen_"+tbpar.tabel+"_"+tbpar.baris);
						el.innerHTML=jumlahdokumen;
						tabel.gettabel(tbpar.tabel).setdata(tbpar.baris,"jumlah_dokumen",jumlahdokumen);
						masterpegawai.bukalampirandok(tbpar.tabel,tbpar.baris,el);
				
					}
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
		},
		lihatdatadokumen: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>DOKUMEN</b></div>";
            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");
                }
            };
            
            var loadersub=mload.loading({"el":"loader_sub_"+idtb});
            var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "masterpegawai",
				ikdata: {0:"getdatalampirandokumen",
					idlampiran: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){
						loadersub.tutup();
						var datatb={
							box:"grid_sub_"+idtb,
							data:e,
							lebarmin:"500px",
							trklik:{"data":"id","fungsi":"barisklik"},
							title:"Data Dokumen",
							tbclass:"table_grid-1",
							isi:[
									{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0},
									{"col":"nama","judul":"Nama Dokumen","tipe":"data"},
									{"align":"center","judul":"Dok.","tipe":"tpl","tpl":"btdokumen","lebar":"60px"},
								],
							mod:"mod",
							module:"masterpegawai"
						};
						tabel.multisub(datatb);
						
					}else{
						loadersub.pesan("Tidak ada Lampiran");
					}
				}
			});
		},
		lihatdokumen:function(a){
			var iddok=a;
			if(iddok<=0) return;
			var myWindow = window.open(lokal+"service.php?pos=masterpegawai&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";
			var prev=b || "tidak";
			
			var obp=new Object;
			obp.proses=function(dataupload){
				boxdokumen.iddokumen=dataupload.id;
				var filelama=dataupload.nama
				$("#box_uploaddokumen").html("");
				upload.tambahupload("box_uploaddokumen",masterpegawai.objupload(filelama,"ya"));
			};
			
			obp.hapus=function(a){
				
			};
			obp.lihat=function(a){
				masterpegawai.lihatdokumen(boxuploaddokumen.iddokumen);
			};
			
			obp.pilihfile=function(a){
				boxdokumen.iddokumen=0;
			};
			
			var dtpost={"jenis":12};
			var obj={"tautan":lokal+"service.php?pos=masterpegawai&mode=mod&fl=upload",
				"status":lokal+"service.php?pos=masterpegawai&mode=mod&fl=progres",
				"tutup":"tidak","finish":obp,disupload:disabled,
				"data":dtpost,"namafile":nama,"preview":prev};
			return obj;
		},
	};
})();