
function fGoto(AjaxAction,DivHeader,dataAjaxSort,formName,CONF,idPaging){
	var txtpage = eval("document.getElementById('txtpage"+formName+idPaging+"').value");
	if(txtpage==""){txtpage=1;}
	var dataAjaxSort = dataAjaxSort + '&index='+txtpage;
	AjaxTable(AjaxAction, DivHeader, dataAjaxSort, formName,CONF);	
}


//function frmSearch(data,inputField,formName,title){
//	var dataAjax = data+"&inputField="+inputField+"&formName="+formName;
//	windows7('w_frmSearch', 'Form Search '+title, 'Assets/Images/icon-search.png', 'FrmSearch.php', dataAjax)	
//}

//function ClickSearch(formName,inputField,fIndexEdit){
//	var cb = eval("document."+formName);
//	var input = inputField.split(";");
//	var val = fIndexEdit.split("~");
//	for(var c=0;c<input.length;c++){
//		var ipt = eval('cb.'+input[c]);
//		ipt.value = val[c];
//	}
//	$("#w_frmSearch").fadeOut("slow",function () {
//		$(this).remove();
//  	});
//
//}
function SwitchMenu(obj,imgId,CONF){//alert(obj);
	var el = document.getElementById(obj);
	//var img = eval("document.getElementById('"+imgId+"')");	
	var trObj = $("#tr_"+obj).css("display");
	//if(el.style.display != "block"){ 
	if(trObj == "none"){ 
		//img.src = CONF+"images/icon/group-collapse.gif";
		el.style.display = "block";
		//img.title = "Collapse";
		$("#tr_"+obj).css("display","table-row"); //marker | table-row
		$("#tableData").css("border-collapse","separate");
	}else{
		//img.src = CONF+"images/icon/group-expand.gif";
		el.style.display = "none";
		//img.title = "Expand";
		$("#tableData").css("border-collapse","collapse");
		$("#tr_"+obj).css("display","none");
		/*$("#td_"+obj).css("border-bottom","#F00 4px solid");*/
	}
}

function AjaxShowDrillDown(varfiles, divID, data, tab, imgId, CONF){
	if (tab == "drill"){SwitchMenu(divID,imgId,CONF);}
	//$('#loading-wait').css("visibility","visible");
	//proses('Please Wait...');
	$("#"+divID).html('<img src=\"images/icon/loading.gif\" width=\"16\" height=\"16\" alt=\"loading\" /> Please wait ...');
	$.ajax({
		url: varfiles,
		data: data,
		success: function(html){
			$("#"+divID).html(html);
			//$('#loading-wait').css("visibility","hidden");
			//closedialog('proses');
			
		}
	});	
}



/////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function AjaxTable(varfiles, divID, data, formName, CONF){
		$.ajax({
			url: varfiles,
			data: data,
			beforeSend: function(){jloadings();},
			complete: function(){Clearjloadings();},				
			success: function(html){
				$("#"+divID).html(html);
			}
		});	
	}

	function CheckAll(formName){
		if(formName==""){alert('FormName not defined');return false;}
		var cb = eval('document.'+formName);
		var length = cb.checkPanel.length;
		if(length>0){
			for(var a=0;a<eval(length);a++){
				if(cb.checkbox.checked==true){
					cb.checkPanel[a].checked=true;
				}
				else{
					cb.checkPanel[a].checked=false;
				}
			}
		}
		else{
			if(cb.checkbox.checked==true){
				cb.checkPanel.checked=true;
			}
			else{
				cb.checkPanel.checked=false;
			}
		}
	}

	function SearchTable(varfiles, divID, formName){
		jloadings();
		var values = $("#"+formName).serialize();
		$.ajax({
			url: varfiles,
			data: "index=1&"+values,
			success: function(html){
				$("#"+divID).html(html);
				Clearjloadings();
			}
		});	
		return false;
	}

	function getdata(varfiles, divID, data){
		$("#"+divID).html('<img src=\"img/icon/indicator_arrows.gif\" width=\"16\" height=\"16\" alt=\"loading\" />');
		$.ajax({
			url: varfiles,
			data: data,
			success: function(html){
				$("#"+divID).html(html);
			}
		});	
		return false;
	}

	function getFile(varfiles, divID, data){
		jloadings();
		$.ajax({
			url: varfiles,
			data: data,
			success: function(html){
				$("#"+divID).html(html);
				Clearjloadings();
			}
		});	
		return false;
	}

	function ShowPopUp(url,data,width,height){
		$("#text_dialog").html('<img src=\"images/loader.gif\" alt=\"loading...\" /> Loading ...');
		$.ajax({
			url: url,
			data: data,
			success: function(html){
				$("#text_dialog").html(html);
			}
		});
		$('#dialog').dialogr('option', 'width', width );
		$('#dialog').dialogr('option', 'height', height );
		$('#dialog').dialogr('option', 'resizable', true );
		$('#dialog').dialogr('option', 'modal', false );
		$('#dialog').dialogr('option', 'buttons', false);
		$('#dialog').dialogr('option', 'maximized', true );
		$('#dialog').dialogr('option', 'minimized', true );
		$('#dialog').dialogr('open');
	}
	
	function CheckPanel(formName){
		var cb = eval('document.'+formName);
		if(cb.zzSizeData.value == 'kosong'){
			Alert('No record found.');
			var fCheckPanel = "undefined";
			return fCheckPanel;
		}
		
		var dataCheck = "";
		var length = cb.checkPanel.length;
		if(length>0){
			for(var a=0;a<eval(length);a++){
				if(cb.checkPanel[a].checked==true){
					dataCheck += cb.checkPanel[a].value + "|";
				}
			}
		}
		else{
			if(cb.checkPanel.checked==true){
				dataCheck += cb.checkPanel.value + "|";
			}
		}
		if(dataCheck!=""){
			return dataCheck;
		}
		else{
			Alert('Please choose data.');
		}
	}
	
	function saveFormTblNews(form,act){
		var cb = eval('document.'+form);	
		var text = CKEDITOR.instances.text.getData();
		var text_en = CKEDITOR.instances.text_en.getData();
		var msg = "";
		
		if(!GiveMeAnError("#title")){
			msg += "&raquo; Judul Berita <br>";	
		}
		if(!GiveMeAnError("#author")){
			msg += "&raquo; Penulis <br>";	
		}
		if(!GiveMeAnError("#prolog")){
			msg += "&raquo; Prolog <br>";	
		}
		if(text==""){
			msg += "&raquo; Isi Berita <br>";	
		}
		if(msg.length>0){
			var message = "<b>Error</b>, Please fill this input : <br>" + msg;	
			Alert(message);
		}
		else{
			jloadings();
			var values = $("#"+form).serialize();
			$.post("mod/modulpos.php?"+values,{what:form,text:text,text_en:text_en} ,function(data){
				if(data=='failed'){
					Clearjloadings();
					Alert(data);
				}else{
					Clearjloadings();
					document.location = 'index.php?act='+act;					
				}
			});
			return false;
		
		}
		return false;
	}
	
	function saveFormTblEvent(form,act){
		var cb = eval('document.'+form);	
		var text = CKEDITOR.instances.text.getData();
		var text_en = CKEDITOR.instances.text_en.getData();
		var msg = "";
		
		if(!GiveMeAnError("#title")){
			msg += "&raquo; Judul Event <br>";	
		}
		if(!GiveMeAnError("#author")){
			msg += "&raquo; Penulis <br>";	
		}
		if(!GiveMeAnError("#prolog")){
			msg += "&raquo; Prolog <br>";	
		}
		if(text==""){
			msg += "&raquo; Isi Event <br>";	
		}
		if(msg.length>0){
			var message = "<b>Error</b>, Please fill this input : <br>" + msg;	
			Alert(message);
		}
		else{
			jloadings();
			var values = $("#"+form).serialize();
			$.post("mod/modulpos.php?"+values,{what:form,text:text,text_en:text_en} ,function(data){
				//alert(data);
				if(data=='failed'){
					Clearjloadings();
					Alert(data);
				}else{
					Clearjloadings();
					document.location = 'index.php?act='+act;					
				}
			});
			return false;
		
		}
		return false;
	}
	
	function saveFormTbl(form,act){
		  var a=0;	
		  $('#'+form+' .required').each(function(n,element){
				if ($(element).val()=='') {  
					a = a+1;
					$("#"+element.id).css("border","1px solid red");
				}else{
					$("#"+element.id).css("border","");
				}  
				/*if(element.id=="EMAIL"){
					
				}*/
		  });  
		 
		/*if (isValidEmail(email) == false)
		{
			alert('Please enter a valid email address');
			return false;	
		}  */
		if(a>0){
			Alert(a +'&nbsp;Field must have a value');
			return false;
		}else{
			jloadings();
			var values = $("#"+form).serialize();
			$.post("mod/modulpos.php?"+values,{what:form} ,function(data){
				//alert(data);
				if(data=='failed'){
					Clearjloadings();
					Alert(data);
				}else{
					Clearjloadings();
					if(strpos(data,'|')){
						var e = data.split('|');
						url    = e[1];
						width  = e[2];
						height = e[3];
						popDialog(url,':: EDII - All about e-business solutions ::',width,height,true);
					}else{
						document.location = 'index.php?act='+act;
					}
				}
			});
			return false;
		}
	}
	
	function strpos (haystack, needle) {
	    var i = (haystack).indexOf(needle, 0);
    	return i === -1 ? false : i;
	}
	
	function deleteTbl(file,form,index,divID){
		if(index==""){
			index=1;
		}
		var list = eval("document."+form);
		if(list.zzSizeData.value == "kosong"){
			Alert("Cannot process.");
			return false;
		}
		var dataCheck = CheckPanel(form);
		if(typeof(dataCheck)!="undefined"){
			var explode = dataCheck.split("|");
			var data = 'index='+index+'&action=delete&dataAjax='+dataCheck;
			jConfirm('Are you sure want to delete?', ":: EDII - All about e-business solutions ::", 
				 function(r) {
					if(r==true){
						 AjaxTable(file,divID,data,form);
						return true;
					}else if(r==false){
						return false;
					}
				 }
			);
			
		}
	}
	
	function editTblAjax(url,divID,form){
		var dataCheck = "";
		dataCheck = CheckPanel(form);
		if(dataCheck!="undefined"){
			var explode = dataCheck.split("|");
			if(explode.length>2){
				Alert('Please choose only one data.');	
			}
			else{
				var data = 'dataAjax='+dataCheck+'&act=edit';
				AjaxTable(url, divID, data, form, '');
			}
		}else{
			Alert('No record found');		
		}
	}
	
	function editTbl(url,title,width, height, modal,form){
		var dataCheck = "";
		dataCheck = CheckPanel(form);
		if(dataCheck!="undefined"){
			var explode = dataCheck.split("|");
			if(explode.length>2){
				Alert('Please choose only one data.');	
			}
			else{
				popDialog(url+'?dataAjax='+dataCheck+'&act=edit',title,width, height,modal);
			}
		}else{
			Alert('No record found');		
		}
	}
	
	function uploadfile(folder,element){
		$("#"+element).css("display","none");
		$("#Uploads").html('<img src=\"img/icon/progressbar.gif\" width=\"100\" height=\"9\" alt=\"loading\" />');
		$.ajaxFileUpload({
			url:'mod/getUpload.php?folder='+folder+'&element='+element,
			secureuri:false,
			fileElementId:element,
			dataType:'json',
			success:function(data, status){
				//alert(data.error);
				if(typeof(data.error)!='undefined'){
					if(data.error!=''){
						ShowvalidBox('#Uploads',data.error);	
					}else{
						$("#"+element).replaceWith('<div id='+element+'></div');
						ShowvalidBox('#Uploads',data.msg);	
					}
				}
			},
			error: function(data, status, e){
				ShowErrorBox('#Uploads',e);	
			}
		})
	}
	
	function deleteFupload(filename,element){
		$.ajax({
			url: 'mod/modulpos.php?what=delfupload&filename='+filename,
			beforeSend: function(){
					$("#Uploads").html('<img src=\"img/icon/progressbar.gif\" width=\"100\" height=\"9\" alt=\"loading\" />');
				},			
			success: function(data){
				if(data=='gagal'){
					Alert("Can not delete file");
				}else{
					ClearvalidBox('#Uploads','');
					$('#Uploads').html('');	
					$("#"+element).replaceWith('<input type="file" name="newsimage" id="newsimage" size="30" ><script>$("input[name=newsimage]").change(function(){uploadfile("news","newsimage");});</script>');
					
				}
			}	
		});	
	}
	
	function addFupload(element){
		$("#"+element).replaceWith('<input type="file" name="newsimage" id="newsimage" size="30" ></span><script>$("input[name=newsimage]").change(function(){uploadfile("news","newsimage");});</script>');
	}
	
	function AjaxTablePopUp(idvPopUp, varfiles, data, title, width, height, dataPerPage, idvTr){
		popDialog(varfiles+'?'+data,title,width, height,true);
		for(var a=1;a<=dataPerPage;a++){
			var over = $("#tr"+a).hasClass("over");	
			if((over) && (a!=idvTr)){
				$("#tr"+a).removeClass("over");	
			}
		}
		
	}

	function fpublishTbl(file,divID,data,form,checkid){
		var cb = eval('document.'+form+'.'+checkid);
		if(cb.checked==true){
			var P = "P";
		}else{
			var P = "";	
		}
		jConfirm('Are you sure want to Process?', ":: EDII - All about e-business solutions ::", 
			 function(r) {
				if(r==true){
					$.ajax({
							url: file,
							data: data+'&action=publish&publish='+P,
							beforeSend: function(){jloadings();},
							complete: function(){Clearjloadings();},				
							success: function(html){
								$("#"+divID).html(html);
							}
						});	
					return true;
				}else if(r==false){
					return false;
				}
			 }
		);
	}
	
	function fbreakingTbl(file,divID,data,form){
		jConfirm('Are you sure want to Process?', ":: EDII - All about e-business solutions ::", 
			 function(r) {
				if(r==true){
					$.ajax({
							url: file,
							data: data+'&action=breaking',
							beforeSend: function(){jloadings();},
							complete: function(){Clearjloadings();},				
							success: function(html){
								$("#"+divID).html(html);
							}
						});	
					return true;
				}else if(r==false){
					return false;
				}
			 }
		);
	}
	



