var caricanggih=(function(){
	var tabelcari=null;
	var dtbok=null;
	var jenis=null;
	var dtdata=null;
	var dtkunci=null;
	var boxcari=null;
	var datacari=null;
	return{
		buka:function(a){
			var objcari=new Object;
			var ps={"lebar":"500","box":"box_cari","judul":"Pencarian canggih","tinggi":"auto"};
			boxcari=boxwin.load(ps);
			boxcari.buka();
			
			var Obj=a['proses'];
			var e=a['data'];
			dtbok=e['alias'];
			dtdata=e['kolom'];
			dtkunci=e['kunci'];
			jenis=e['jenis'];
			datacari=[];
			for(var i=0;i<dtbok.length;i++){
				if(jenis[dtkunci[i]]!=null){
					datacari.push({"alias":dtbok[i],"jenis":jenis[dtkunci[i]]['jenis']});
				}else{
					datacari.push({"alias":dtbok[i],"jenis":"text"});
				}
			}
			
			var datatb={
				box:"grid_cari",
				data:datacari,
				lebarmin:"300px",
				trklik:{"data":"id","fungsi":"barisklik"},
				title:"kategori Menu",
				isi:[
						{"col":"","judul":"No","tipe":"urut","align":"center","lebar":"30px","halaman":0,"jumlah":100},
						{"col":"alias","judul":"Kata Kunci","tipe":"data"},
						{"judul":"Kata Pencarian","tipe":"tpl","tpl":"bt_plg_jeniscari","lebar":"240px"},
					],
				mod:"plg",
				module:"caricanggih"
			};
			tabelcari=tabel.multisub(datatb);
			
			document.getElementById("bt_tutup_cari").onclick=function(){
				boxcari.tutup();
			};
			
			document.getElementById("bt_bersih_cari").onclick=function(){
				for(var i=0;i<dtbok.length;i++){
					$("#bt_plg_jeniscari_"+tabelcari.tabel()+"_"+i).html("");
					var jeniscari=datacari[i]['jenis'];
					
					(function(a,b){
						document.getElementById("bt_plg_jeniscari_"+tabelcari.tabel()+"_"+i).onclick=function(){
							caricanggih.klik(a,b,this);
						};
					})(jeniscari,i);
				}
			};
			
			document.getElementById("bt_proses_cari").onclick=function(){
				var caritxt="";
				var n=0;
				for(var i=0;i<dtbok.length;i++){
					if(document.getElementById("val_datacari_"+i)!=null){
						if(n==0){
							caritxt+=dtkunci[i]+"="+document.getElementById("val_datacari_"+i).value;
						}else{
							caritxt+="&"+dtkunci[i]+"="+document.getElementById("val_datacari_"+i).value;
						}
						n++;
					}
				};
				Obj.proses(caritxt);
			};
			
			objcari.tutup=function(){
				boxcari.tutup();
			};
			
			return objcari;
		},
		klik:function(a,b,c){
			var datalama=c.innerHTML;
			c.onclick="";
			if(a=="text"){
				c.innerHTML="<input style='width:220px;' id='val_datacari_"+b+"'/>";
			}else if(a=="dropdown"){
				var objdata=jenis[dtkunci[b]]['data'];
				var objkey=Object.keys(jenis[dtkunci[b]]['data']);
				
				var slcari=document.createElement("select");
				slcari.id="val_datacari_"+b;
				
				slcari.setAttribute("style","width:233px");
				var htm="";
				for(var i=0;i<objkey.length;i++){
					htm+="<option value='"+objdata[objkey[i]]+"'>"+objkey[i]+"</option>";
					slcari.onchange=function(){
						if(slcari.value==1000){
							c.innerHTML=datalama;
							c.onclick=function(){
								caricanggih.klik(a,b,c);
							};
						}
					};
				}
				htm+="<option value='1000'>TUTUP</option>";
				slcari.innerHTML=htm;
				c.innerHTML="";
				c.appendChild(slcari);
			}else if(a=="tanggal"){
				c.innerHTML="<input style='width:220px' id='val_datacari_"+b+"'/>";
				$("#val_datacari_"+b).datepicker({
					inline:true,
					dateFormat:"dd/mm/yy"
				});
			}else if(a=="umur"){
				c.innerHTML="<input style='width:220px;' id='val_datacari_"+b+"'/>";
			}else if(a=="custom"){
				c.innerHTML="<input style='width:220px;' id='val_datacari_"+b+"'/>";
			}
		},
		batal:function(a){
			var docel=document.getElementById("bt_plg_jeniscari_"+tabelcari.tabel()+"_"+a);
			docel.innerHTML="";
			
			
			
		}
	};
})();
