if(navigator.appName.indexOf("Microsoft")!=-1){
 	if(navigator.userAgent.indexOf('Opera')== -1) isIE=true;
	else isIE=false;
}
else isIE=false;

var collapseDirty=false;
var expandDirty=false;

//alert('test');

function validate(inputObj,waarden){
	if(inputObj.value.length>0){
		var value = inputObj.value;
		var validValues = waarden.split(",");
		if(in_array(value,validValues)){
			return true;
		}else{
			alert("Geen geldige waarde ingevoerd");
			inputObj.value="";
			return false;
		}
	}
}

function checkall(obj,idPart){
	if (typeof(idPart) == 'undefined') idPart='';
	l=idPart.length;

	var i;
	cInput=document.getElementsByTagName('INPUT');
	for (i=0; i<cInput.length;i++){
		if (cInput[i].type=='checkbox' && cInput[i].id.substring(0,l)==idPart){
			cInput[i].checked = obj.checked;
		}
	}
}

function chk(ID){
	obj=document.getElementById("chkbox_db["+ID+"]");
    if (obj.value == 1) chk_off(ID);
    else chk_on(ID);
	chkbelow(ID);
	chkabove(ID);
}

function chkabove(ID){
	var state_sum=0;
	PID=en[ID];
	oTR=document.getElementById("d:" + PID);
	if(isObject(oTR)){
		obj=oTR.getElementsByTagName("INPUT");
		for (i=0;i<obj.length;i++){
			enid=obj[i].id.substring(0,obj[i].id.length-1).split('[')[1];
			state_sum+=parseInt(document.getElementById("chkbox_db["+enid+"]").value);
		}
		state_avg=state_sum/obj.length;
		if (state_avg==1) chk_on(PID);
		else if(state_avg==0)chk_off(PID);
		else chk_half(PID);
		chkabove(PID);

	}
}

function chkbelow(ID) {
	oTR=document.getElementById("d:" + ID);
	if(isObject(oTR)){
		state=document.getElementById("chkbox_db["+ID+"]").value;
		obj=oTR.getElementsByTagName("INPUT");
		for (i=0;i<obj.length;i++){
			enid=obj[i].id.substring(0,obj[i].id.length-1).split('[')[1];
			if(state==1) chk_on(enid);
			else chk_off(enid);
		}
	}
}

function chk_flip(ID){
	imgobj=document.getElementById("chkbox["+ID+"]");
	if(imgobj.className=="chkOn") imgobj.className="chkOff";
	else imgobj.className="chkOn";
}

function chk_half(ID){
	document.getElementById("chkbox["+ID+"]").src= IMG_CHK_HALF;
	document.getElementById("chkbox_db["+ID+"]").value = 0;
}

function chk_off(ID){
	document.getElementById("chkbox["+ID+"]").src= IMG_CHK_OFF;
	if (document.getElementById("chkbox_db["+ID+"]").value != 0) chk_flip(ID);
	document.getElementById("chkbox_db["+ID+"]").value = 0;
}

function chk_on(ID){
	document.getElementById("chkbox["+ID+"]").src= IMG_CHK_ON;
	if (document.getElementById("chkbox_db["+ID+"]").value != 1) chk_flip(ID);
	document.getElementById("chkbox_db["+ID+"]").value = 1;
}

function clickParent(obj){
	obj.parentNode.click();
}

function collapse(ID){
    document.images["i:" + ID].src = IMG_PLUS;
    document.getElementById("d:" + ID).style.display = "none";
}

function expand(ID){
    document.images["i:" + ID].src = IMG_MINUS;
    document.getElementById("d:" + ID).style.display = "";
}

function flip_style(ID){
	if (ID.style.backgroundColor=='') ID.style.backgroundColor='#0098E1';
	else ID.style.backgroundColor='';
}

function popup(url){
	window.open(url,'popup','height=400,width=600,status=no,toolbar=no,menubar=no,scrollbars=1,resizable=1,location=no');
}

function popup_help(){
	window.open('../algemeen/Help.php?url='+window.location.pathname,'help','height=400,width=490,status=no,toolbar=no,menubar=no,scrollbars=1,resizable=1,location=no');
}

function open_popup(obj){
	obj.style.display='block';
	start_timer(obj);
}

function showLoading(){
	//maak een loading div
  	var loadingDiv = document.createElement("div");
  	loadingDiv.setAttribute("id","loading");
	loadingDiv.className="Loading";
	loadingDiv.setAttribute("onclick","return false;");
	
	//stop daarin een weer een div voor een plaatje
	var loadingImg = document.createElement("div");
  	loadingImg.setAttribute("id","loadingGif");
  	loadingDiv.appendChild(loadingImg);

	//voeg de loading div toe aan body
	objBody=document.getElementsByTagName("body")[0];
	objBody.appendChild(loadingDiv);
		
	//plaats de div op de juiste plek
	documentHeight=document.body.clientHeight;
	scrollTop=document.body.scrollTop;        
	loadingImg.style.top=scrollTop+300;
	loadingDiv.style.height=documentHeight+scrollTop;
	loadingDiv.style.display="block";
}

function saveTreeCookie(){
	//bewaar de status van de boom in 
	tree="";
    rowsObj=document.getElementsByTagName("tr");
	for(n=0;n<rowsObj.length;n++){
		if (rowsObj[n].id.substring(0,2)=='d:' && rowsObj[n].style.display != "none"){
			ID=rowsObj[n].id.substring(2);
			tree=tree+","+ID
		}
	}
	createCookie(Node,tree,1);
	//alert(tree);
}

function tover(objID){
	Obj=document.getElementById('content'+objID);
	aObj=document.getElementById('a'+objID);

	if (Obj.style.display=='none'){
		if(isObject(aObj)) aObj.innerHTML='<< minder';
		Obj.style.display='';
	}else{
		if(isObject(aObj)) aObj.innerHTML='meer >>';
		Obj.style.display='none';
	}
}


function t(ID){
    if (document.getElementById("d:"+ID).style.display == "none") expand(ID);
    else if (document.getElementById("d:"+ID).style.display == "") collapse(ID);
	saveTreeCookie();
}

function t_all(){
    rowsObj=document.getElementsByTagName("tr");
	if(tonen==1){
		var toon= collapse;
		tonen=0;
	}
	else {
		var toon = expand;
		tonen=1;
	}
	//alert(rowsObj.length);
	tree="";
	for(n=0;n<rowsObj.length;n++){
		if (rowsObj[n].id.substring(0,2)=='d:'){
			ID=rowsObj[n].id.substring(2);
			toon(ID);
			if(tonen==1){
				tree=tree+","+ID
			}
		}
	}
	//stop de visible status in cookie
	createCookie(Node,tree,1);
}

function t_lid(radio_obj){
	if(radio_obj.value=='nee'){
		document.getElementById("geenlid").style.display='';
		document.getElementById("wellid").style.display='none';
	}
	else{
		document.getElementById("geenlid").style.display='none';
		document.getElementById("wellid").style.display='';
	}
}


//------------- algemene functions ------------------------//

function isAlien(a) {
   return isObject(a) && typeof(a).constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof(a) == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof(a) == 'function';
}
function isNull(a) {
    return a === null;
}
function isNumber(a) {
    return typeof(a) == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof(a) == 'object') || isFunction(a);
}
function isString(a) {
    return typeof(a) == 'string';
}
function isUndefined(a) {
    return typeof(a) == 'undefined';
} 

function in_array(stringToSearch, arrayToSearch) {
            for (s = 0; s < arrayToSearch.length; s++) {
                        thisEntry = arrayToSearch[s].toString();
                        if (thisEntry == stringToSearch) {
                                   return true;
                        }
            }
            return false;
}


function createCookie(name,value,days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function dumpProperties(obj, obj_name) { 
	var result = "";
 	for (i in obj){
		result += obj_name + "." + i + " = " + obj[i] + "<br>";
	}
	//alert(result);
 	var dump  = window.open("dump","_blank");
 	dump.document.write(result);
 }


//------------- start algemene functies voor het starten van init ------------------------//

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof(window.onload) != 'function') {
    window.onload = func;
  } 
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
	  func();
	}
  }
}

addLoadEvent(
  function() {
	// quit if this function has already been called
	if (arguments.callee.done) return;
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	//draai init(). Is vrij in te vullen op elke pagina. Let er wel op. Deze file moet na de codecharge javascript worden toegevoegd.

	if ( typeof(init) == 'function'){
		init();
	}	
  }
);




//------------- einde algemene functies voor het starten van init ------------------------//
