/*
general functions
Copyright (c) 2003-2010 Ylab, www.ylab.nl
*/
var debugging = true;

//window.onerror = reportError;
function reportError(msg, url, line){
	window.status = line + ": " + msg;
	return true;
}
var loadFunctions = new Array();
function addLoadFunction(f)  {loadFunctions[loadFunctions.length] = new Function(f);}
window.onload   = function() {for (var i=0; i<loadFunctions.length; i++){loadFunctions[i]();}}

//Set focus on first input element
function setFirstFieldFocus(container){
	if(container.tagName == "FORM"){
		var list = container.elements;
	}
	else{
		var list = container.getElementsByTagName("input");
	}
	for (var i=0; i< list.length; i++){
		try {
			if (list[i].type == "button"){continue;}
			list[i].focus();
			if(list[i].select){list[i].select();}
			break;
		}
		catch (exception){}
	}
}

//enable or disable elements and their children
function setEnabled(on){
	for (var i=1; i<arguments.length; i++){
		var obj = document.getElementById(arguments[i]);
		if (obj){
			obj.disabled = !on;
			if (obj.hasChildNodes()){
				for (var j=0; j<obj.childNodes.length; j++){
					if (obj.childNodes[j].nodeType == 1){setEnabled(on, obj.childNodes[j]);}
				}
			}
		}
	}
}

function getCookie(name){
	//Function to return the value of the cookie specified by "name".
	//returns: String object containing the cookie value, or null if the cookie does not exist.

	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
	function getCookieVal(offset){
		//Internal function to return the decoded value of a cookie
		var endstr = document.cookie.indexOf (";", offset);

		if (endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
}

function setCookie(name, value){
	//Function to create or update a cookie for calling document.
	document.cookie = name + "=" + escape (value);
}
//DEBUGGING
function devAlert(){
	if (!debugging){return;}
	var code = "Deze functie is nog niet geïmplementeerd.\n";
	for(var i=0; i < arguments.length; i++) {
		code += arguments[i] + "\n";
	}
	alert(code);
}

function debugAlert(){
	if (!debugging){return;}
	var code = "";
	for(var i=0; i < arguments.length; i++) {
		code += arguments[i] + "\n";
	}
	window.status = code;
	code += '\nKlik op Annuleren om verdere meldingen te onderdrukken.';
	debugging = confirm(code);
}
function debugConfirm(){
	if (!debugging){return;}
	var code = "";
	for(var i=0; i < arguments.length; i++) {
		code += arguments[i] + "\n";
	}
	window.status = code;
	return confirm(code);
}

if(!Array.prototype.push){
	Array.prototype.push = function(){
		for(var i=0; i<arguments.length; i++){
			this[this.length] = arguments[i];
		}
		return this.length;
	}
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
