// fungsi untuk menghandle filter yang memiliki filter anak yang bergantung padanya
// filter akan post data bila terjadi onchange event
// sehingga filter anak akan berubah nilai-nilainya
function doChangeFilter() {
	document.forms[0].submit();
}

// fungsi untuk mengecek apakan inputan berupa angka atau bukan
function cekIsAngka(input, obj, text) {
	if (isNaN(input)) {
		alert("Field "+ text +" mohon isikan dengan angka");
	}
}

// fungsi konfirmasi berulang untuk memastikan penghapusan data
function doDel(linkDel){
	var isDel = confirm("Apakah yakin untuk dihapus?");
	if(isDel){
		window.location = linkDel;
	}
}

// fungsi konfirmasi berulang untuk memastikan penghapusan data, tapi jenisnya submit data
function submitCekDel(sync) {
	if (confirm("Apakah yakin untuk dihapus?")) {
		if (confirm("Data benar-benar akan dimusnahkan dari database, Anda yakin?")) {
			if (confirm("Ini konfirmasi terakhir bahwa Anda akan menghapus data selamanya dari database, Anda yakin?")) {
				document.getElementById("isDel").name = "del";
				document.getElementById("isDel").value = "del";

				document.getElementById("syncUid").value = sync;

				document.forms[0].submit();
			} 
		} 
	} 
}

function submitPosition(sync, direction) {
	document.getElementById("pos").name = "pos";
	document.getElementById("pos").value = direction;

	document.getElementById("syncUid").value = sync;

	document.forms[0].submit();
}

function cekAgregate(noElement) {
	if (document.getElementById("none_" + noElement).checked) {
		document.getElementById("sum_" + noElement).checked = false;
		document.getElementById("avg_" + noElement).checked = false;
		document.getElementById("max_" + noElement).checked = false;
		document.getElementById("min_" + noElement).checked = false;

		document.getElementById("sum_" + noElement).disabled = true;
		document.getElementById("avg_" + noElement).disabled = true;
		document.getElementById("max_" + noElement).disabled = true;
		document.getElementById("min_" + noElement).disabled = true;
	} else {
		document.getElementById("sum_" + noElement).disabled = false;
		document.getElementById("avg_" + noElement).disabled = false;
		document.getElementById("max_" + noElement).disabled = false;
		document.getElementById("min_" + noElement).disabled = false;
	}
}

var groupSpanHolder = "";

function showGroupSpan() {
	document.getElementById("groupSpan").innerHTML = groupSpanHolder;
	//document.getElementById("groupSpan").style.visibility = "visible";
	//alert("kentang");
}

function hideGroupSpan() {
	groupSpanHolder = document.getElementById("groupSpan").innerHTML;
	//document.getElementById("groupSpan").style.visibility = "hidden";
	document.getElementById("groupSpan").innerHTML = "";
}

// fungsi untuk menghapus kolom yang berlebih dari header tabel
function deleteColumn(tblId)
{
	var allRows = document.getElementById(tblId).rows;
	var jmlKolomOptimun = allRows[0].cells.length;
	for (var i=0; i<allRows.length; i++) {
		if (allRows[i].cells.length > jmlKolomOptimun) {
			allRows[i].deleteCell(-1);
		}
	}
}

// fungsi untuk export data
function doExport(tipeDoc, namaFile) {
	document.getElementById("exportDoc").value = document.getElementById("exportBlock").innerHTML;
	document.getElementById("tipeExport").value = tipeDoc;
	document.getElementById("expName").value = namaFile;

	document.FExport.submit();
}

// fungsi untuk export data
function printPrev(idTabel) {
	document.getElementById("exportDoc").value = document.getElementById("exportBlock").innerHTML;
	document.getElementById("tipeExport").value = "";
	document.getElementById("expName").value = idTabel;
	
	document.forms[1].action = 'DBGen_printPrev_main.php';
	document.forms[1].target = "_blank";
	document.forms[1].submit();

	//alert(document.forms[1].target);
}

//---------------------------------------------------------------------------------

//---------------------------------------
// persiapan qoute holder
//----------------------------------------
document.write ("<div id='divQuote' class='div-style' style='background-color:transparent'>"+
				"<table id='Table_01' width='121' height='87' border='0' cellpadding='0' cellspacing='0'>"+
					"<tr>"+
						"<td colspan='3'>"+
							"<img src='images/quote_01.png' width='121' height='17' alt=''></td>"+
					"</tr>"+
					"<tr>"+
						"<td><img src='images/quote_02.png' width='18' height='43' alt=''></td>"+
						"<td background='images/quote_03.jpg' width='88' height='43' align='center' style='color:black'><span id='quote'></span></td>"+
						"<td><img src='images/quote_04.gif' width='15' height='43' alt=''></td>"+
					"</tr>"+
					"<tr>"+
						"<td colspan='3'><img src='images/quote_05.png' width='121' height='27' alt=''></td>"+
					"</tr>"+
				"</table></div>");


var	_fixedX = 300 // x position (-1 if to appear below control)
var	_fixedY = 70 // y position (-1 if to appear below control)

var	_ie=document.all
var	_dom=document.getElementById
var	_ns4=document.layers
var	_crossobj
var _objContent

function initQuote()	{
	if (!_ns4) {
		_crossobj=(_dom)?document.getElementById("divQuote").style : _ie? document.all.divQuote : document.divQuote
		_objContent = (_dom)?document.getElementById("quote").style : _ie? document.all.quote : document.quote
	}
}

//fungsi untuk menampilkan quote
function showQuote(ctl, text) {
	var	leftpos=-400
	var	toppos=30

	initQuote();

	aTag = ctl;
	do {
		aTag = aTag.offsetParent;
		leftpos	+= aTag.offsetLeft;
		toppos += aTag.offsetTop;
	} while(aTag.tagName!="BODY");

	_crossobj.left	= _fixedX==-1 ? ctl.offsetLeft	+ leftpos :	 ctl.offsetLeft	+ leftpos + _fixedX
	_crossobj.top	= _fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	ctl.offsetTop +	toppos -111
	_crossobj.visibility=(_dom||_ie)? "visible" : "show"

	document.getElementById("quote").innerHTML  = text;
}

function hideQuote() {
	_crossobj.visibility=(_dom||_ie)? "hidden" : "hidden";
	document.getElementById("quote").innerHTML  = "";
}

function __ClipBoard(text) {
	//holdtext.innerText = text;
	//Copied = holdtext.createTextRange();
	//Copied.execCommand("RemoveFormat");
	//Copied.execCommand("Copy");
	window.clipboardData.setData("Text",text);
}

function ClipBoard(text2copy) {
	if (window.clipboardData) {
		window.clipboardData.setData("Text",text2copy);
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
}	


var newwindow = null;

function popCek(url) {
	if (newwindow == null) {
		newwindow=window.open(url,'name','width=700,height=420,scrollbars');
	} else {
		newwindow.focus();
	}
	return false;
}


//@var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
var sql_box_locked = false;

//@var array holds elements which content should only selected once
var only_once_elements = new Array();

// selects the content of a given object, f.e. a textarea
// @param   object  element     element of which the content will be selected
// @param   var     lock        variable which holds the lock for this element
//                              or true, if no lock exists
// @param   boolean only_once   if true this is only done once
//                              f.e. only on first focus
//------------------------------------------------------------------------------
function selectContent( element, lock, only_once ) {
	if ( only_once && only_once_elements[element.name] ) {
		return;
	}
	only_once_elements[element.name] = true;

	if ( lock  ) {
		return;
	}
	element.select();
}

function insertValueQuery(objTextArea, text2inserted) {
	var myQuery = opener.document.getElementById(objTextArea);

	sql_box_locked = true;
	
	//IE support
	if (document.selection) {
		myQuery.focus();
		sel = opener.document.selection.createRange();
		sel.text = text2inserted;
		//opener.document.forms[0].insert.focus();
		
	}
	//MOZILLA/NETSCAPE support
	else if (myQuery.selectionStart || myQuery.selectionStart == "0") {
		var startPos	= myQuery.selectionStart;
		var endPos		= myQuery.selectionEnd;
		var chaineSql	= myQuery.value;

		myQuery.value = chaineSql.substring(0, startPos) + text2inserted + chaineSql.substring(endPos, chaineSql.length);

	} else {
		myQuery.value += text2inserted;

	}

	sql_box_locked = false;

}


function numbersonly(myfield, e, dec) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;
  keychar = String.fromCharCode(key);

  // control keys
  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;

  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;

  // decimal point jump
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  } else
    return false;
}

function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return (true)
	} else {
		return (false)
	}		
}