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
/**
 * Concatenates the values of a variable into an easily readable string
 * by Matt Hackett [scriptnode.com]
 * @param {Object} x The variable to debug
 * @param {Number} max The maximum number of recursions allowed (keep low, around 5 for HTML elements to prevent errors) [default: 10]
 * @param {String} sep The separator to use between [default: a single space ' ']
 * @param {Number} l The current level deep (amount of recursion). Do not use this parameter: it's for the function's own use
 */
function print_r(x, max, sep, l) {
	l = l || 0;
	max = max || 10;
	sep = sep || ' ';
	if (l > max) {
		return "[WARNING: Too much recursion]\n";
	}
	var
		i,
		r = '',
		t = typeof x,
		tab = '';
	if (x === null) {
		r += "(null)\n";
	} else if (t == 'object') {
		l++;
		for (i = 0; i < l; i++) {
			tab += sep;
		}
		if (x && x.length) {
			t = 'array';
		}
		r += '(' + t + ") :\n";
		for (i in x) {
			try {
				r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
			} catch(e) {
				return "[ERROR: " + e + "]\n";
			}
		}
	} else {
		if (t == 'string') {
			if (x == '') {
				x = '(empty)';
			}
		}
		r += '(' + t + ') ' + x + "\n";
	}
	return r;
};

function do_onComplete(responseTree, responseElements, responseHTML, responseJavaScript) {
   //	alert(responseHTML);

}


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();
    	// graag zorgen dat de pagina niet cached
        options.url
    }
	var myHTMLRequest = new Request.HTML(options);
//	myHTMLRequest.setHeader('Last-Modified','Sat, 1 Jan 2005 05:00:00 GMT');
//	myHTMLRequest.setHeader('X-Request','HTML');
	myHTMLRequest.get();
}

function do_ajax_HTML_post(options,formID) {
	var myHTMLRequest = new Request.HTML(options);
	myHTMLRequest.setHeader('Last-Modified','Sat, 1 Jan 2005 05:00:00 GMT');
//	myHTMLRequest.setHeader('X-Request','HTML');
	myHTMLRequest.post($(formID));

}


function toggleValue(id) {
	if(document.getElementById(id).checked==true)
		document.getElementById(id).checked = false;
	else
		document.getElementById(id).checked = true;
}
