function showFAQ(itemId)
{
	var faqObj = (document.getElementById(("faq" + itemId)));
	
	if(faqObj.style.visibility == "hidden")
	{
		faqObj.style.visibility = "visible";
		faqObj.style.overflow = 'auto';
		faqObj.style.height = '100%';
	}
	else
	{
		faqObj.style.visibility = "hidden";
		faqObj.style.overflow = 'hidden';
		faqObj.style.height = '0px';
	}
}

function showCMSButtonPanel(cms_object, height)
{
	cms_object.style.visibility = 'visible';
	cms_object.style.height     = height + 'px';
}

function hideCMSButtonPanel(cms_object)
{
	cms_object.style.visibility = 'hidden';
	cms_object.style.height     = '0px';
}

function combineColumns(item_id, nr_of_columns, column_name)
{
	var columns = document.getElementById(column_name);
	columns.value = "";
	
	for(var c = 1; c <= nr_of_columns; c++)
	{
		if(c > 1){ columns.value += "~"; }
		
		var column = document.getElementById("item_" + item_id + "_row_" + c);
		columns.value += column.value;
	}
}

function addTask(item_id)
{
	document.edit.action.value = 'add_task';
	document.edit.alias.value  = '<?php echo $this->alias; ?>';
	
	var t_user_id = document.getElementById(item_id + "#t_user_id");
	var t_task    = document.getElementById(item_id + "#t_task");
	
	document.edit.cmswhere.value = (item_id + ',' + t_user_id.options[t_user_id.selectedIndex].value + ',' + t_task.options[t_task.selectedIndex].value);
	
	document.edit.submit();
}

function refreshScreen()
{
	document.location.href = document.location.href;
}

document.dialog = new Array();

var tekst_obj_focus = null;

function popUp(url)
{
	var top  = ((screen.height - 700) / 2);
	var left = ((screen.width  - 400) / 2);
	
	//eventueel in midden plaatsen
	window.open(url, "", "height=700, width=400, top=" + top + ", left=" + left + ", scrollbars=auto");
}

function customPopUp(url, pop_h, pop_w)
{
	var top  = ((pop_h - 700) / 2);
	var left = ((pop_w  - 400) / 2);
	
	//eventueel in midden plaatsen
	window.open(url, "", "height=" + pop_h + ", width=" + pop_w + ", top=" + top + ", left=" + left + ", scrollbars=yes");
}

function popUpMax(url)
{
	var top  = 0;
	var left = 0;
	
	window.open(url, "", "height=" + screen.height + ", width=" + screen.width + ",top=" + top + ",left=" + left + ", scrollbars=yes");
}

function subscribe(event_id)
{
	$window_object = window.open('inschrijven.php?id=' + event_id, '', 'height=450,left=200,top=150,width=400;');
}

function textareaHeight(e) {
	if (!e) var e = window.event;
	var tg = (e.target) ? e.target : e.srcElement;
	var duObj = document.getElementById('dummytextarea');
	var taObjValue = tg.value.replace(/\n/g, "<br />&nbsp;");
	duObj.innerHTML = taObjValue;
	tg.style.height = duObj.offsetHeight+2+'px';
}

function alltextareaHeight() {
	var allta = document.getElementsByTagName("textarea");
	for (i = 0; i<allta.length; i++) {
		allta[i].onkeyup = textareaHeight;
		allta[i].onclick = textareaHeight;
		// do textareaHeight once as initialization (not really nice, should use the function for that. no time)
		var duObj = document.getElementById('dummytextarea');
		var taObjValue = allta[i].value.replace(/\n/g, "<br />&nbsp;");
		duObj.innerHTML = taObjValue;
		allta[i].style.height = duObj.offsetHeight+2+'px';
	}
}

function custom_dialog(titel, text, button_name, button_function, e) {
	// set position
	var dialogbox = document.getElementById('dialogbox'); var dialogbox_text = document.getElementById('db_text');
	if (e) {
		var posx = 0;
		var posy = 0;
		if (e.pageX || e.pageY)
		{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			posx = e.clientX + document.body.scrollLeft;
			posy = e.clientY + document.body.scrollTop;
		}
		// 'remember' dialog position in case of no user event triggered the dialog
		document.dialog['posx'] = posx;
		document.dialog['posy'] = posy;
	}
	else {
			posx = document.dialog['posx'];
			posy = document.dialog['posy'];
	}
	dialogbox.style.top = posy-60+'px';
	dialogbox.style.left = posx+30+'px';
	// END set position
	
	document.getElementById('button_cancel').onclick = function () {document.getElementById('dialogbox').style.display = 'none';}
	document.getElementById('db_titel').innerHTML = titel;
	document.getElementById('db_text').innerHTML = text;
	
	// Make button functional
	if (button_name) {
		document.getElementById('button_ok').innerHTML = button_name;
		// see if there are inputfields. If so, they must contain a value
		var inputfields = false;
		for (var itemi=0; itemi< dialogbox_text.childNodes.length; itemi++) {
			if(dialogbox_text.childNodes[itemi].tagName == 'INPUT') {
				
				// v- if inputfield, attach onchange anonymous function and set inputfields to true
				dialogbox_text.childNodes[itemi].onchange = function() {
					var emptyfields = false;
					for (var inputfieldi=0; inputfieldi< dialogbox_text.childNodes.length; inputfieldi++) {
						if(dialogbox_text.childNodes[inputfieldi].tagName == 'INPUT') {
							if (dialogbox_text.childNodes[inputfieldi].value == '')
								emptyfields = true;
						}
					}
					
					// no emptyfields, attach onclick event
					if (!emptyfields)
						document.getElementById('button_ok').onclick = button_function;
					else
						document.getElementById('button_ok').onclick = null;
				}
				// ^- END onchange anonymous function
				
				inputfields = true;
			}
		}
		// no inputfields, attach onclick event
		if (!inputfields)
			document.getElementById('button_ok').onclick = button_function;
		else
			document.getElementById('button_ok').onclick = null;
		document.getElementById('button_ok').className = 'button';
	}
	// END
	
	dialogbox.style.display = 'block';	
}

function custom_dialog_hide() {
	document.getElementById('dialogbox').style.display = 'none';	
	document.getElementById('button_ok').innerHTML = '';
	document.getElementById('button_ok').onclick = null;
	document.getElementById('button_ok').className = null;
}

function do_inschrijven(e) {
	var questions = new Array(); var answers = new Array(); var qai = 0;

	// check to see if there's input elements
	for (var itemi=0; itemi<document.getElementById('db_text').childNodes.length; itemi++) {
		// if element = input, collect the data
		if(document.getElementById('db_text').childNodes[itemi].tagName == 'INPUT'){
			questions[qai]	= document.getElementById('db_text').childNodes[itemi].previousSibling.innerHTML// collect questions (caution, expects this format)
			answers[qai]	= document.getElementById('db_text').childNodes[itemi].value;	// collect entered value
			qai++;
		}
	}
	// end
	
	// ajax email 
	email(document.dialog['uid'], document.dialog['etitel']);
	// ajax insert
	insert('cms_inschrijving', document.dialog['uid']+','+document.dialog['eid'], questions, answers);
	document.getElementById('inschrijven'+document.dialog['objid']).innerHTML = 
		'<span class="ghost" title="U bent reeds ingeschreven voor dit evenement">inschrijven</span>';
	custom_dialog_hide();
}


function inschrijven (uid, eid, etitel, objid, q, e) {
if (uid) {
	var html='';
	document.dialog['uid'] = uid; document.dialog['eid'] = eid; document.dialog['etitel'] = etitel; document.dialog['objid'] = objid;
	// construct questions html
	for (var i=0; i<q.length; i++){
		if (q[i].length > 0)
			html += '<div class="question">'+q[i]+'?</div><input type="text" name="q['+i+']" />';
	}
	if (html)
		html = 'Beantwoord alstublieft de volgende vraag(en):<br />'+html+'<br />';
	custom_dialog('INSCHRIJVEN EVENEMENT', 
		'Weet u zeker dat u zich wilt inschrijven voor het evenement: <br /><br /><strong>'+etitel+'</strong><br /><br />'+html, 'INSCHRIJVEN&nbsp;>', do_inschrijven, e); 
}
else
	custom_dialog('U bent niet ingelogd', '', '', '', e);
}



// for mouseover fileupload in cms.

function getElementsByClassName(tagname, classname) {
	var elem = document.getElementsByTagName(tagname);
	var returnelem = new Array();
	for (var i=0; i< elem.length; i++) {
		if (elem[i].className == classname)
			returnelem[returnelem.length] = elem[i]
	}
	return returnelem;
}

function mouseoverFileUploads() {
	var FUelem = getElementsByClassName('div', 'photolist');
	var FUelem2 = getElementsByClassName('div', 'photolist big');
	for (var i=0; i< FUelem2.length; i++) {
		FUelem[FUelem.length] = FUelem2[i];
	}
	for (var i=0; i< FUelem.length; i++) {
		FUelem[i].onmouseover = function () {
			this.getElementsByTagName('input')[0].style.display = 'block';
		}
		FUelem[i].onmouseout = function () {
			this.getElementsByTagName('input')[0].style.display = 'none';
		}
	}
}



// sitemap

function isIE50 () {
	if (navigator.appVersion.indexOf("MSIE 5.0") != -1)
		return true;
	else
		return false;
}

function getStyle(x,styleProp)
{
	if (window.getComputedStyle)
		var y = eval('window.getComputedStyle(x,null).' + styleProp);
	else if (x.currentStyle)
		var y = eval('x.currentStyle.' + styleProp);
	return y;
}

function adjustHeights() {
	if (isIE50()) return;
	var blockboxheight = 0;
	var blockboxcount = 0;
	if(document.getElementById('content') != null)
	{
		for (var i = 0; i < document.getElementById('content').childNodes.length; i++) {
			if (document.getElementById('content').childNodes[i].nodeType == 1) {
				if (document.getElementById('content').childNodes[i].className == 'block2') {
					blockboxcount++;
					//alert(document.getElementById('content').childNodes[i].offsetHeight);
					if (blockboxheight > document.getElementById('content').childNodes[i].offsetHeight){
						currPaddingTop = getStyle(document.getElementById('content').childNodes[i],'paddingTop');
						currPaddingTop = Number(currPaddingTop.replace('px', ''));
						document.getElementById('content').childNodes[i].style.height = blockboxheight-currPaddingTop+'px';
						blockboxheight = 0;
					}
					else {
						if (blockboxcount % 2) {		// first column
							document.getElementById('content').childNodes[i].style.marginRight = '10px';
							blockboxheight = document.getElementById('content').childNodes[i].offsetHeight;
						}
						else
							blockboxheight = 0;
					}
				}
			}
		}
	}
}