var jenispengadaan=(function(){
	var hal=0;
	var jumlah=30;
	var iddatajenispengadaan=0;
	return{
		caricanggih:function(){
			mload.sh();
			var ik_data = {ajax: 1,mode: "mod",cl: "jenispengadaan",
				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){
				jenispengadaan.loade();
			}
		},
		loade:function(){
			$("#hal_ke").val(0);
			jenispengadaan.load();
		},
		load:function(){
			var nohal=$("#hal_ke").val()
			jumlah=$("#jumlah_hal").val();
			hal=(nohal-1)*jumlah;
			var cr=$("#cari").val();
			
			$("#grid_jenispengadaan").html("");
			mload.sh();
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "jenispengadaan",
				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){
					
					mload.hd();
					//alert(JSON.stringify(e));
					if(e!=false){
						
						if(e.length>0 && e[0]['halaman']>0){
							var htm;
							for(var i=0;i<e[0]['halaman'];i++){
								htm+="<option value='"+(i+1)+"'>"+(i+1)+"</option>";
							}
							$("#hal_ke").html(htm);
							
						}
						$("#hal_ke").val(nohal);
						
						var datatb={
							box:"grid_jenispengadaan",
							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":"kode","judul":"Kode","tipe":"data","lebar":"80px"},
									{"col":"nama","judul":"Nama Jenis Pengadaan","tipe":"data"},
									{"align":"center","judul":"Status","tipe":"tpl","tpl":"btstatus","lebar":"60px"},
									{"align":"center","judul":"","tipe":"tpl","tpl":"btedit","lebar":"60px"},
									
								],
							mod:"mod",
							module:"jenispengadaan"
						};
						tabel.multisub(datatb);
					}
				}
			});
		},
		buat:function(a){
			document.location=lokal+"member/mod/jenispengadaan?id="+a;
		},
		kembali:function(){
			document.location=lokal+"member/mod/jenispengadaan";
		},
		edit:function(a){
			iddatajenispengadaan=a;
		},
		simpan:function(){
			$("#box_error_simpan").html("");
			var nama=$("#nama").val();
			var kode=$("#kode").val();
			
			
			var err="";
			if(nama=="") err+="Nama Jenis Pengadaan belum diisi.</br>";
			if(kode=="") err+="Kode jenis Pengadaan belum diisi.</br>";
			if(err!=""){
				$("#box_error_simpan").html(err);
				return;
			}
			var fg="inputjenispengadaan";
			if(iddatajenispengadaan>0){
				fg="editjenispengadaan";
			}
			mload.sh();
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "jenispengadaan",
				ikdata: {0:fg,nama:nama,kode:kode,id:iddatajenispengadaan}
			};
			
			$.ajax({
				url: lokal+"man.ajax.php",
				type: "POST",
				dataType: "json",
				async:true,
				data: ik_data,
				success: function(e){
					
					mload.hd();
					if(e==1){
						document.location=lokal+"member/mod/jenispengadaan";
					}
				}
			});
		},
		hapus:function(a){
			if(a<=0) return;
			var boxyesno=null;
			var databox={
				judul:"Yakin akan menghapus data jenis pengadaan ini ?? ",
				proses:function(){
					mload.sh();
					var ik_data = {
						ajax: 1,
						mode: "mod",
						cl: "jenispengadaan",
						ikdata: {0:"hapusData",id:a}
					};
					
					$.ajax({
						url: lokal+"man.ajax.php",
						type: "POST",
						dataType: "json",
						async:true,
						data: ik_data,
						success: function(e){
							mload.hd();
							if(e==1){
								jenispengadaan.load();
								boxyesno.tutup();
								
							}
						}
					});
				}
			};
			boxyesno=boxwin.yesno(databox);
			boxyesno.buka();
			
		},
		setstatus:function(a,b,c,d){
			var st=0;
			if(tabel.gettabel(b).getdata(c,"status")==0){
				st=1;
			}
			
			mload.sh();
			var ik_data = {
				ajax: 1,
				mode: "mod",
				cl: "jenispengadaan",
				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){
					mload.hd();
					if(e==1){
						d.className="mini_dis";
						if(st==1){
							d.className="mini_ok";
						}
						
						tabel.gettabel(b).setdata(c,"status",st);
					}
				}
			});
		}
	};
})();