var eksporxls=(function(){
	var boxekspor=null;
	var tokendata=null;
	return{
		mulai:function(a,ob){
			//alert('aa');
			if(a.length>0){
				var arrkol=Object.keys(a[0]);
				var datakol=[];
				for(var i=0;i<arrkol.length;i++){
					datakol.push({"nama":arrkol[i]});
				}
				
				var ps={"lebar":"500px","box":"box_kolom_ekspor","title":"Pilih kolom yang akan di ekspor","tinggimax":"fit"};
				boxekspor=boxpesan.win(ps);
				
				var datatb={
					box:"grid_kolom_ekspor",
					data:datakol,
					lebarmin:"400px",
					tbclass:"table_grid-2",
					trklik:{"data":"id","fungsi":"barisklik"},
					title:"kategori Menu",
					isi:[
							{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"50px","halaman":0,"jumlah":100},
							{"col":"nama","judul":"Nama Kolom","tipe":"data"},
							{"judul":"","tipe":"tpl","lebar":"40px","tpl":"bt_pilih_kolom_ekpor","align":"center"},
							
						],
					mod:"plg",
					module:"eksporxls"
				};
				
				var tbsub=tabel.multisub(datatb); 
				
				document.getElementById("bt_tutup_ekspor").onclick=function(){
					boxekspor.tutup();
					if(tokendata!=null && tokendata!=""){
						var ik_data = {ajax: 1,mode: "plg",cl: "eksporxls",
							ikdata: {0:"hapustoken",1:tokendata}};
						
						$.ajax({
							url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
							success: function(e){
								
							}
						});
					}
					
				};
				
				document.getElementById("bt_proses_cekall").onclick=function(){
					for(var i=0;i<datakol.length;i++){
						document.getElementById("bt_pilih_kolom_ekpor_"+tbsub.tabel()+"_"+i).checked =true;
					}
				};
				
				document.getElementById("bt_proses_uncekall").onclick=function(){
					for(var i=0;i<datakol.length;i++){
						document.getElementById("bt_pilih_kolom_ekpor_"+tbsub.tabel()+"_"+i).checked =false;
					}
				};
				
				document.getElementById("bt_proses_ekspor").onclick=function(){
					var datach=[];
					for(var i=0;i<datakol.length;i++){
						if(document.getElementById("bt_pilih_kolom_ekpor_"+tbsub.tabel()+"_"+i).checked){
							datach.push(datakol[i]['nama']);
						}
					}
					//alert(JSON.stringify(a)+" "+JSON.stringify(datach));
					
					mload.sh();
					var ik_data = {ajax: 1,mode: "plg",cl: "eksporxls",
						ikdata: {0:"exportxls",1:a,2:datach}};
					
					$.ajax({
						url: lokal+"man.ajax.php",type: "POST",dataType: "json",async:true,data: ik_data,
						success: function(e){
							mload.hd();
							if(e['token']!=null && e['token']!=""){
								boxekspor.tutup();
								tokendata=e['token'];
								ob.proses(tokendata);
							}
						}
					});
				};
			}
		}
	}
})();
