
function openDialog(url, handler)
{
	window.open(url, "_blank", "resizable=1, scrollbars=1, toolbar=0, status=0, location=0, menubar=0, width=600, height=600");
	this.selectHandler = handler;
}

function toggleDiv(id)
{
	var div = document.getElementById(id);
	if (div.style.display != "none") div.style.display = "none";
	else div.style.display = "block";
}

function getContainingElement(element, tagName)
{
	while ((element.parentNode != null) && (element.parentNode.tagName != tagName))
	{
		element = element.parentNode;
	}
	return element.parentNode;
}

function getContainedElement(element, tagName)
{
	for (var index in element.childNodes)
	{
		if (element.childNodes[index].tagName == tagName) return element.childNodes[index];
	}
	return null;
}

function hasClass(node, className)
{
  if (node.className == className) return true;
  var reg = new RegExp('(^| )'+ className +'($| )');
  if (reg.test(node.className)) return true;
  return false;
}

function getContainedElementByClass(element, name)
{
	for (var index in element.childNodes)
	{
		if (hasClass(element.childNodes[index], name))
		{
			return element.childNodes[index];
		}
		else
		{
			// Check child nodes
            for (var childIndex in element.childNodes[index].childNodes)
			{
				var ret = getContainedElementByClass(element.childNodes[index].childNodes[childIndex], name);
				if (ret != null) return ret;
			}
		}
	}
	return null;
}

function generateBio(name, div_id)
{
	var url = "http://api.freebase.com/api/service/mqlread";
	var query = "{\"query\":{\"name\":\"deus\",\"id\":null,\"type\":[]}}";
	var args = {"query":query};
	var data = doRequest("GET", url, args);
}

function absolutePosition(el)
{
	var sLeft = 0, sTop = 0;
	var isDiv = /^div$/i.test(el.tagName);
	if (isDiv && el.scrollLeft) sLeft = el.scrollLeft;
	if (isDiv && el.scrollTop) sTop = el.scrollTop;
	var r = { x: el.offsetLeft - sLeft, y: el.offsetTop - sTop };
	if (el.offsetParent)
	{
		var tmp = this.absolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};

function showPopup(anchorId, html)
{
	var anchor = document.getElementById(anchorId);
	var div = document.createElement("DIV");
	var titleBar = document.createElement("DIV");
	titleBar.style.textAlign = "right";
	var closeButton = document.createElement("IMG");
	closeButton.onclick = function() { div.parentNode.removeChild(div); };
	closeButton.src = "images/close_div.gif";
	titleBar.appendChild(closeButton);
	div.appendChild(titleBar);
	var body = document.createElement("DIV");
	div.appendChild(body);
	body.innerHTML = html;
	// get position of target textfield
	// position holding div below it
	var pos = absolutePosition(anchor);
	div.style.padding = "5px";
	div.style.position = "absolute";
	div.style.zIndex = "1";
	div.style.left = pos.x + "px";
	div.style.top = pos.y + "px";
    div.style.border = "1px solid #cccccc";
	div.style.backgroundColor = "#ffffff";

	document.getElementsByTagName("body")[0].appendChild(div);
}

function showPressPopup(anchorId)
{
	var html = "Deze persknipsels zijn geselecteerd uit de <a href='pressoverview.php'>muzikale persoverzichten</a> die we sinds 2003 opmaken.<br />Ze zijn opgesteld aan de hand van een beperkte, maar kwalitatieve lijst bronnen en op basis van inhoudelijke selectiecriteria.<br />We pretenderen dus met deze persknipsels <strong>geen totaaloverzicht</strong>. Alle knipsels zijn raadpleegbaar bij Muziekcentrum Vlaanderen op eenvoudige telefonische afspraak (02/504.90.90)";
	showPopup(anchorId, html);
}