var hide_timer=null;
var hide_obj=null;
var cur_menu=null;

function cleantime() {
	clearTimeout(hide_timer);
	hide_timer=null;
}


function showPull(id,target)
{
	cleantime();
	if(cur_menu!=null && cur_menu!=id) hide_now();

	cur_menu=id;
	locobj=document.getElementById(id);
	x=locobj.offsetLeft;
	y=locobj.offsetTop;
	obj=document.getElementById(target);
	obj.style.top=y+18+'px';
	obj.style.left=x-15+'px';
	obj.style.visibility='visible';
}

function hide_now() {
	cleantime();
	if(hide_obj!=null) {
		hide_obj.style.visibility='hidden';
		hide_obj=null;
	}
}

function hidePull(id)
{
	hide_obj=document.getElementById(id);
	hide_timer=setTimeout('hide_now()',240);
}

function changeClass(target,cssClass)
{
	obj = document.getElementById(target);
	obj.className=cssClass;
}


function isEnter(event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) return true;
}

function limitText(limitField, limitCount) {
	var limitNum = document.getElementById(limitField).getAttribute('maxLength');
	if (document.getElementById(limitField).value.length > limitNum) {
		document.getElementById(limitField).value = document.getElementById(limitField).value.substring(0, limitNum);
	} else {
		var o=document.getElementById(limitCount);
		if(o!=null) {
			setTimeout(function() {
				o.innerHTML= limitNum - document.getElementById(limitField).value.length;
			}, 50);
		}
	}
}

function URLDecode(encoded)
{
	// Replace + with ' '
	// Replace %xx with equivalent character
	// Put [ERROR] in output if %xx is invalid.
	var HEXCHARS = "0123456789ABCDEFabcdef";
	var plaintext = "";
	var i = 0;
	while (i < encoded.length) {
	var ch = encoded.charAt(i);
	if (ch == "+") {
		plaintext += " ";
		i++;
	} else if (ch == "%") {
		if (i < (encoded.length-2)
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
			plaintext += ch;
			i++;
		}
	} // while
	return plaintext;
};


// AJAX CALLS
function do_ajax_HTML(options) {
	// 	voor param's zie:
	//	http://docs.mootools.net/Request/Request.HTML
	// 	if(options.params!=null) {
	// 	hier nog wat checks!
	// options.method='get';
	// options.complete=do_onComplete;
	if (options['cache']!=true) {
		var i=options['url'].indexOf('?',0)+options['url'].indexOf('&',0); // komt er een & of ? voor?
		if (i>-2){
			options['url']=options['url']+'&';
		} else options['url']=options['url']+'?';
		options['url']=options['url']+'randcachevar='+(new Date()).getTime();
		options.url
	}
	var myHTMLRequest = new Request.HTML(options);
	myHTMLRequest.setHeader('X-Request','text/xhtml');
	myHTMLRequest.get();
}

function do_ajax_HTML_post(options,formID) {
	var myHTMLRequest = new Request.HTML(options);
	myHTMLRequest.post($(formID));
}