var rootPath = '.';
var flashPath = 'flash/';
var imgPath = 'img/';

$(function(){
	$(".hulpmiddel div, .faqvraag div").hide();
	$(".hulpmiddel h3, .faqvraag h3").click(function(){
		$(this).next().toggle();
		$(this).toggleClass("opened");
	});
	
	$("#faqfilter span").click(function(){
		$("#faqfilter").data("clicked",$(this).text());
		$(this).toggleClass("actief").toggleClass("deactief");
		if($(this).hasClass("deactief")){
			$("."+$(this).text()).each(function(){
				var classnamen = $(this).attr("class").split(" ");
				classnamen.splice(classnamen.indexOf("faqvraag"),1);
				if(classnamen.length==1){
					$(this).hide();
				}else{
					classnamen.splice(classnamen.indexOf($("#faqfilter").data("clicked")),1);
					var tonen = false;
					for(var i=0;i<classnamen.length;i++){
						if($("#zetactief"+classnamen[i]).hasClass("actief")){
							tonen = true;
						}
					}
					if(!tonen){
						$(this).hide();
					}
				}
			});
		}
		if($(this).hasClass("actief")){
			$("."+$(this).text()).show();
		}
		$("#faqfilter").removeData();							
	});
	
	$(".openingstijduitzonderingen").each(function(){
		$(this).parent("td").mouseover(function(){
			$(this).find(".openingstijduitzonderingen").show();
			if($("#wrapper").height()-$(this).find(".openingstijduitzonderingen").offset().top<$(this).find(".openingstijduitzonderingencontent").height()){
				$(this).find(".openingstijduitzonderingen").addClass("bovenuitlijnen");
			}
		}).mouseout(function(){
			$(this).find(".openingstijduitzonderingen").hide();
		});
	});
});


var urlParams = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       urlParams[d(e[1])] = d(e[2]);
})();

// JavaScript Document

function emptyValue(elm, tekst){
	if(document.getElementById(elm).value==tekst){
		document.getElementById(elm).value="";
	}
}
function returnValue(elm, tekst){
	if(document.getElementById(elm).value==""){
		document.getElementById(elm).value=tekst;
	}
}

function popUp(link , width , height){
	window.open(link, 'venster', 'width=' + width + ',height=' + height + ',scrollbars=yes,toolbar=no,location=no,status=no,resize=no');
}

function expandAll(startDiv) {
	var divObj = document.getElementById(startDiv);
	if (divObj == "object") {
		for (var i=0;i<divObj.childNodes.length;i++) {
			if (divObj.childNodes[i].nodeName == "DIV" && divObj.childNodes[i].id.substr(0,6) == "folder") {
				toggleFolder(divObj.childNodes[i].id, document.getElementById("image" + divObj.childNodes[i].id.substr(6)));
				expandAll(divObj.childNodes[i].id);
			}
		}
	}
}

function closeAll(startDiv) {
	expandAll(startDiv);
	var divObj = document.getElementById(startDiv);
	for (var i=0;i<divObj.childNodes.length;i++) {
		if (divObj.childNodes[i].nodeName == "DIV" && divObj.childNodes[i].id.substr(0,6) == "folder") {
			toggleFolder(divObj.childNodes[i].id, document.getElementById("image" + divObj.childNodes[i].id.substr(6)));
			expandAll(divObj.childNodes[i].id);
		}
	}
}

function expandItem(theID, startDiv) {
	var divObj = document.getElementById(startDiv);
	var found = false;
	for (var i=0;i<divObj.childNodes.length;i++) {
		if (divObj.childNodes[i].nodeName == "DIV" && divObj.childNodes[i].id.substr(0,6) == "folder") {
			found = expandItem(theID, divObj.childNodes[i].id);
			if (divObj.childNodes[i].id == "folder" + theID) {
				// current element found
				toggleFolder(divObj.childNodes[i].id, document.getElementById("image" + divObj.childNodes[i].id.substr(6)));
				return true;
			}
			if (found) {
				toggleFolder(divObj.childNodes[i].id, document.getElementById("image" + divObj.childNodes[i].id.substr(6)));
				return true;
			}
		}
	}
	return found;
}

function toggleFolder(id, imageNode) {
	var folder = document.getElementById(id);
	var l = imageNode.src.length;
	if (imageNode.src.substring(l-21,l)=="tree_folderclosed.png" || imageNode.src.substring(l-19,l)=="tree_folderopen.png") {
		imageNode = imageNode.previousSibling;
		l = imageNode.src.length;
	}
	if (folder == null) {
	} 
	else if (folder.style.display == "block")  {
		if (imageNode != null) {
			imageNode.nextSibling.src = imgPath+"sitemap/tree_folderclosed.png";
			if (imageNode.src.substring(l-14,l) == "tree_mnode.png") {
				imageNode.src = imgPath+"sitemap/tree_pnode.png";
			}
			else if (imageNode.src.substring(l-18,l) == "tree_mlastnode.png") {
				imageNode.src = imgPath+"sitemap/tree_plastnode.png";
			}
		}
		folder.style.display = "none";
	} 
	else {
		if (imageNode != null) {
			imageNode.nextSibling.src = imgPath+"sitemap/tree_folderopen.png";
			if (imageNode.src.substring(l-14,l) == "tree_pnode.png") {
				imageNode.src = imgPath+"sitemap/tree_mnode.png";
			}
			else if (imageNode.src.substring(l-18,l) == "tree_plastnode.png") {
				imageNode.src = imgPath+"sitemap/tree_mlastnode.png";
			}
		}
		folder.style.display = "block";
	}
	//updateRowColor();
}


function getObjectsByClassname(clsName) {
	var retVal = new Array();
	var elements = document.getElementsByTagName("*");
	
	for(var i = 0;i < elements.length;i++) {
		if(elements[i].className.indexOf(" ") >= 0) {
			classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++){
				if(classes[j] == clsName) {
					retVal.push(elements[i]);
				}
			}
		}
		else if(elements[i].className == clsName) {
			retVal.push(elements[i]);
		}
	}
	return retVal;
}


function RemoveClassName(objElement, strClass) {
	// if there is a class
	if ( objElement.className ) {
	
	   // the classes are just a space separated list, so first get the list
	   var arrList = objElement.className.split(' ');
	
	   // get uppercase class for comparison purposes
	   var strClassUpper = strClass.toUpperCase();
	
	   // find all instances and remove them
	   for ( var i = 0; i < arrList.length; i++ )
	      {
	
	      // if class found
	      if ( arrList[i].toUpperCase() == strClassUpper )
	         {
	
	         // remove array item
	         arrList.splice(i, 1);
	
	         // decrement loop counter as we have adjusted the array's contents
	         i--;
	
	         }
	
	      }
	
	   // assign modified class name attribute
	   objElement.className = arrList.join(' ');
	
	   }
	// if there was no class
	// there is nothing to remove
}

function AddClassName(objElement, strClass, blnMayAlreadyExist) {
	
	// if there is a class
	if ( objElement.className )
	   {
	
	   // the classes are just a space separated list, so first get the list
	   var arrList = objElement.className.split(' ');
	
	   // if the new class name may already exist in list
	   if ( blnMayAlreadyExist )
	      {
	
	      // get uppercase class for comparison purposes
	      var strClassUpper = strClass.toUpperCase();
	
	      // find all instances and remove them
	      for ( var i = 0; i < arrList.length; i++ )
	         {
	
	         // if class found
	         if ( arrList[i].toUpperCase() == strClassUpper )
	            {
	
	            // remove array item
	            arrList.splice(i, 1);
	
	            // decrement loop counter as we have adjusted the array's contents
	            i--;
	
	            }
	
	         }
	
	      }
	
	   // add the new class to end of list
	   arrList[arrList.length] = strClass;
	
	   // add the new class to beginning of list
	   //arrList.splice(0, 0, strClass);
	   
	   // assign modified class name attribute
	   objElement.className = arrList.join(' ');
	
	   }
	// if there was no class
	else
	   {
	
	   // assign modified class name attribute      
	   objElement.className = strClass;
	
	   }
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
  		if (x==c_name){
    		return unescape(y);
    	}
  	}
}

