// ==================================================
// global vars
// ==================================================

var popupblockmsg = "A pop-up blocker is preventing a new window from opening.\nTo avoid blocking the next time, try any of these options:\n\n1. Press and hold the [CTRL] key as you click on a link to open a window.\n2. Reconfigure the pop-up blocker to allow pop-ups for this site.";

var is_initpage	= 0;			// flag die bijhoudt of functie initpage al is aangeroepen.
var is_showmenu	= 1;			// indien 1 dan toon menu, indien 0 dan verberg menu
var displaymenus= 1;			// deze onderdrukt evt. onload-menus-init

//var undotext;					// hierin wordt tekst opgeslagen voordat een TAG aan selectie wordt toegevoegd
//var undotobj;					// text-object waarvandaan / naartoe undotext komt en gaat

var regURL = new RegExp(/^(http\:\/\/)([a-z0-9\-]+\.){1,2}([a-z0-9\-])/);

var bbmx = bbmy = 0; 			// global mousepos vars voor oa. Help Mouseover
var mmchecktel, mmcheckid;

var mmevent 	= 0;			// pas als mmevent op 1 staat zullen de mouse-coords worden uitgelezen
var mmaway		= 0;			// pas als mmaway op 8 staat gaat helptext weer weg
var mymx, mymy;					// waar deze nou voor zijn... vergeten!

var tiditmmover	= 0;			// timer voor tonen / hiden van move-column/row layer

var blocksetx;					// hierin wordt straks de absolute pixelLeft waarde van content geplaatst
var blocksetw;					// komt breedte van pagina / blockset in

// window resizer vars (animeert het resizen van een window)

var rray 		= new Array(0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 0.9, 0.94, 0.97, 0.98, 0.99, 1);
var rtel 		= 0;
var rzid;

// browser detect

var is_mac		= navigator.platform.indexOf("Mac") != -1;
var is_win		= navigator.platform=="Win32";
var is_safari 	= navigator.userAgent.indexOf("Safari") != -1;
var is_opera 	= navigator.userAgent.indexOf("Opera") > -1;
var is_ie 		= navigator.userAgent.indexOf("MSIE") > 1 && !is_opera; //(navigator.userAgent.indexOf ("IE") != -1);
var is_mozilla	= navigator.userAgent.indexOf("Mozilla/5.") == 0 && !is_opera;
var is_gecko 	= /gecko/i.test(navigator.userAgent);
//var is_ie    	= /MSIE/.test(navigator.userAgent);

var treevis = 0;		// is de pagetree zichtbaar

// document afmetingen

var DBW, DBH;

// ==================================================
// misc functions
// ==================================================

function setDocsize() {
	if (is_safari) {
		DBW = document.innerWidth;
		DBH = document.innerHeight;
	} else if (is_mozilla) {
		DBW = window.innerWidth;
		DBH = window.innerHeight;
	} else {
		DBW = document.body.clientWidth;
		DBH = document.body.clientHeight;
	}
	//DBW = is_safari ? document.innerWidth : document.body.clientWidth;
	//DBH = is_safari ? document.innerHeight : document.body.clientHeight;
}

function centerElement(elid, xoff, yoff) {
	var dw = is_safari ? document.clientWidth : document.body.clientWidth;
	var dh = is_safari ? document.clientHeight : document.body.clientHeight;
	var ew = getElement(elid).offsetWidth;
	var eh = getElement(elid).offsetHeight;

	getElement(elid).style.left = (Math.round((dw-ew)/2)+xoff) + "px";
	getElement(elid).style.top  = (Math.round((dh-eh)/2)+yoff) + "px";
}

function posElement(id,pos,px) {
	// top, left, width, height
	if (is_mozilla) {
		if (pos == "left") { getElement(id).style.left = px + "px"; }
		else if (pos == "top") { getElement(id).style.top = px + "px"; }
		else if (pos == "width") { getElement(id).style.width = px + "px"; }
		else if (pos == "height") { getElement(id).style.height = px + "px"; }
	} else {
		if (pos == "left") { getElement(id).style.pixelLeft = px; }
		else if (pos == "top") { getElement(id).style.pixelTop = px; }
		else if (pos == "width") { getElement(id).style.pixelWidth = px; }
		else if (pos == "height") { getElement(id).style.pixelHeight = px; }
	}
}

function rnd(bot, top) {
	tmp = top - bot;
	tmp = Math.random() * tmp;
	return bot + tmp;
}

function ctime() {
	t 	= new Date();
	t2 	= t.getYear().toString()
		+ t.getMonth().toString()
		+ t.getDate().toString()
		+ t.getHours().toString()
		+ t.getMinutes().toString()
		+ t.getSeconds().toString();
	return t2;
}

// ==================================================
// centreer object
// ==================================================

function centerobject(obj,w,h,v) {
	tmpx = Math.round((document.body.clientWidth - w) / 2 + document.body.scrollLeft);
	tmpy = Math.round((document.body.clientHeight - h) / 2 + document.body.scrollTop);

	getElement(obj).style.pixelLeft = tmpx;
	getElement(obj).style.pixelTop = tmpy;

	if (v) getElement(obj).style.visibility = 'visible';
}

// ==================================================

function getElement(el) {
	return document.getElementById(el);
}

function setEl(objId, x, y, innerData) {
	if (x!=false) document.getElementById(objId).style.left = x+'px';
	if (y!=false) document.getElementById(objId).style.top = y+'px';
	if (innerData!=false) document.getElementById(objId).innerHTML = innerData;
}

// ==================================================

function go(url, cid) {
	if (url.substr(0,1) == "#") {
		// go('#cid392') -> jump to section within page
		location.href = location.href.toString().replace(/([^\x23])\x23(.+)/gi, "$1") + url;
	} else {
		if (typeof(pageid) == 'undefined') pageid = 0;
		location.href = "go.php?pid=" + pageid + "&cid=" + cid + "&url=" + check_url(url);
	}
}

function ngo(url, cid) {
	if (typeof(pageid) == 'undefined') pageid = 0;
	window.open("go.php?pid=" + pageid + "&cid=" + cid + "&url=" + check_url(url));
}

function mail(adr) {
	location.href = "mailto:" + adr;
}

function openmedia(tiepe, pw, ph, file) {
	mx		= (screen.availWidth - pw) / 2;
	my		= (screen.availHeight - ph) / 2;
	popobj 	= window.open('', 'win', 'scrollbars=auto, resizable=1, fullscreen=0, menubar=0, status=0, statusbar=0, left='+mx+', top='+my+', width='+pw+', height='+ph);
	if (popobj) {
		popobj.location.href = 'playmedia.php?w='+pw+'&h='+ph+'&type='+tiepe+'&file='+file;
		popobj.focus();
		return true;
	} else {
		alert(popupblockmsg);
	}
}

function check_url(url) {
	// check op http (niet helemaal safe: bijv. "news.thesignal.tv" zal ie niet als dusdanig herkennen
	if (url.substr(0,7).toLowerCase() != "http://") {
		if (url.substr(0,3).toLowerCase() == "www") url = "http://" + url;
	}

	// converteer naar url-encoded
	return urlenc(url);
	//return url;
}

// php-compatible url-encode (alle non-alphanumerieke tekens behalve de .)
// NB: escape() zou ook kunnen, echter deze functie werkt beter dan escape()
function urlenc(str) {
	var ret = "";
//alert('ok');
	for (i=0; i < str.length; i++) {
		c = (str.substr(i,1));	// neem 1 char vd string
		// indien char geen alfanumeriek of . teken is
		if (c.search(/[^0-9a-zA-Z\.]/g) != -1) {
			// neem ascii-code van char en converteer naar hexadecimaal en maak die string uppercase
			ret += "%" + c.charCodeAt(0).toString(16).toUpperCase();
		} else {
			ret += c;
		}
	}
	return ret;
}

// ==================================================
// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
// ==================================================

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);

   return output;
}

// ==================================================

function popwin(myurl) {
	pw	= 385;
	ph	= 530+16;
	mx	= window.top.imgx ? window.top.imgx : (screen.availWidth - pw) / 3;
	my	= window.top.imgy ? window.top.imgy : (screen.availHeight - ph) / 3;
	popobj = window.open(myurl, 'winimg', 'scrollbars=1, resizable=1, fullscreen=0, menubar=0, status=0, statusbar=0, left='+mx+', top='+my+', width='+pw+', height='+ph);
	if (popobj) {
		popobj.focus();
		popobj.resizeTo(pw,ph);
	} else {
		alert(popupblockmsg);
	}
}

function popprev(myurl) {
	mx	= Math.floor((screen.availWidth-100)/2);
	my	= Math.floor((screen.availHeight-100)/2);
	window.open(myurl, 'winprev', 'scrollbars=1, resizable=1, fullscreen=0, menubar=0, status=0, statusbar=0, left='+mx+', top='+my+', width=100, height=100');
}

function popfixed(myurl, w, h) {
	var mx	= Math.floor((screen.availWidth-w)/2);
	var my	= Math.floor((screen.availHeight-h)/2);
	window.open(myurl, 'winfixed', 'scrollbars=0, resizable=0, fullscreen=0, menubar=0, status=0, statusbar=0, left='+mx+', top='+my+', width='+w+', height='+h);
}

function popmanage(mywin, myurl, pw, ph) {
	pw	= Math.min(screen.availWidth, pw);	// 800 breed of maximaal mogelijke breedte van scherm
	ph	= Math.min(screen.availHeight, ph);	// idem voor hoogte maar dan met variabele hoogte
	mx	= (screen.availWidth - pw) / 2;
	my	= (screen.availHeight - ph) / 2;
	myurl += (myurl.indexOf("?") != -1 ? "&w=" : "?w=") + pw.toString();
	myurl += "&h=" + ph.toString();
	popobj = window.open(myurl, mywin, 'scrollbars=0, resizable=1, fullscreen=0, menubar=0, status=0, statusbar=0, left='+mx+', top='+my+', width='+pw+', height='+ph);
	if (popobj) {
		popobj.resizeTo(pw,ph);
		popobj.focus();
	} else {
		alert(popupblockmsg);
	}
}

function popgoscroll(mywin, myurl, pw, ph, mayscroll) {
	// houd breedte en hoogte binnen limieten van scherm-afmetingen
	// NB: ook procenten toegestaan, bijv. "75%"
	if (typeof(pw) == "string" && pw.indexOf("%") != -1) {
		pw = Math.floor(parseInt(pw.replace(/[^0-9]/gi, ""),10)/100 * screen.availWidth);
	} else {
		pw = Math.min(pw, screen.availWidth);
	}
	if (typeof(ph) == "string" && ph.indexOf("%") != -1) {
		ph = Math.floor(parseInt(ph.replace(/[^0-9]/gi, ""),10)/100 * screen.availHeight);
	} else {
		ph = Math.min(ph, screen.availHeight);
	}

	mx = Math.floor((screen.availWidth - pw) / 2);
	my = Math.floor((screen.availHeight - ph) / 2);
	popobj 	= window.open('', mywin, 'scrollbars='+mayscroll.toString()+', resizable=1, fullscreen=0, menubar=0, status=0, statusbar=0, left='+mx+', top='+my+', width='+pw+', height='+ph);
	if (popobj) {
		popobj.location.href = myurl;
		popobj.resizeTo(pw, ph);
		popobj.focus();
		return 1;
	} else {
		alert(popupblockmsg);
	}
}

function ipop(myurl, cid) {
	if (typeof(pageid) == 'undefined') pageid = 0;
	if (typeof(cid)=="string") cid = urlenc(cid);
	//popgoscroll('popimg', 'popup_imagepreview.php?nofilename=1&recenter=1&file=' + myurl + '&cid=' + cid, 50, 50, 1);
	popgoscroll('popimg', 'popup_imagepreview.php?nofilename=1&file='+myurl+'&cid='+cid+'&pid='+pageid, 50, 50, 1);
}

function apop(myurl) {
	// JS 23-apr-07: dirty trick om te checken of myurl al dan niet gecodeerd is mbv urlencode(base64_encode())
	// check op /, als deze er in zit dan kan myurl nog niet gecodeerd zijn
	if (myurl.indexOf('/') != -1) myurl = urlenc(encode64(myurl));

	// popgoscroll('articlebrowser', 'article.php?path=ere2006/022-031_edit_europe_alg&ct=1142336371', '100%', '75%', 0)
	popgoscroll('articlepop', "../articlebrowser/article.php?path="+myurl, '100%', '100%', 0);
}

function getscreenmeasures(mode, opts) {
	if (mode == "get") {
		// genereer string met GET-params
		// opts: factor-waarde (float) tussen 0 en 1, om schrerm-resolutie met factor te vermenigvulden
		opts = opts ? opts : 1;
		r = "screenx=" + Math.round(opts*screen.availWidth) + "&screeny=" + Math.round(opts*screen.availHeight);
	}
	return r;
}

// ================================================
//	Help functies 8 mei 2002
// ================================================

function getmouseXY() {
	if (is_ie) {
		bbmx	= window.event.clientX + document.body.scrollLeft;
		bbmy	= window.event.clientY + document.body.scrollTop;
	}
}

function showbighelp(myhelptext, shw) {
	if (shw == 1 || shw == 3) {
		// prepare and hold item for showing
		mmevent=1;
		if (shw == 1) {
			// bij show=1: innertext
			getElement('bighcnt').innerText = myhelptext;
		} else {
			// bij show=3: innerHTML
			getElement('bighcnt').innerHTML = myhelptext;
		}
		clearTimeout(mmcheckid);
		mmcheckid = setTimeout("showbighelp(0,2)", 1000);
	} else if (shw == 2) {
		// show item
		var whlp = getElement('bighelp').offsetWidth; //style.pixelWidth;
		var xmax = Math.min(bbmx, document.body.clientWidth - whlp - 5);
		getElement('ibighelp').style.left		= Math.min(whlp - 2*10, Math.max(10, bbmx - xmax)) + 'px';
		getElement('bighelp').style.left		= xmax + 'px';
		getElement('bighelp').style.top			= Math.min(bbmy + 25, document.body.clientHeight - 10 + getyoff()) + 'px';
		getElement('bighelp').style.visibility	= 'visible';
	} else if (shw < 0) {
		// hide item with delay
		clearTimeout(mmcheckid);
		mmcheckid = setTimeout("showbighelp(0,0)", Math.abs(shw));
	} else {
		// hide item directly (shw=0)
		mmevent=0;
		clearTimeout(mmcheckid);
		getElement('bighelp').style.visibility 	= 'hidden';
	}
}

function hlp_show(myhelptext, myhelpshow) {
	if (myhelpshow == 1) {
		getElement('spanhelp').innerText = myhelptext;
		mmevent 	= 1;
		mymx 		= bbmx;
		mymy 		= bbmy;
		mmchecktel 	= 0;
		clearInterval(mmcheckid);
		mmcheckid 	= setInterval("hlp_mmwait()", 200);
	} else {
		mmaway		= 0;
		mmevent 	= 0;
		clearInterval(mmcheckid);
		getElement('tblhelp').style.visibility 	= 'hidden';
	}
}

function hlp_mmwait() {
	curmx = bbmx;
	curmy = bbmy;
	if (mmchecktel > 2) {
		curmx = Math.min(curmx, document.body.clientWidth - 100);	// zie helpsmall in main.css => 200 breed; staat op 100 ivm teveel naar linksgaan bij korte tekstjes
		curmy = Math.min(curmy + 20, document.body.clientHeight - 20 + getyoff());
		getElement('tblhelp').style.pixelLeft 	= curmx; 	// help-x-pos tov mousepointer, clipped
		getElement('tblhelp').style.pixelTop 	= curmy;	// help-y-pos tov mousepointer, clipped
		getElement('tblhelp').style.visibility 	= 'visible';
		clearInterval(mmcheckid);
		mmcheckid 	= setInterval("hlp_mmcheck()", 200);
	} else {
		if (Math.abs(curmx - mymx) < 2 || Math.abs(curmy - mymy) < 2) {
			mmchecktel++;
		} else {
			mmchecktel = 0;
		}
		mymx = curmx;
		mymy = curmy;
	}
}

function hlp_mmcheck() {
	curmx = bbmx;
	curmy = bbmy;
	if (Math.abs(curmx - mymx) > 5 || Math.abs(curmy - mymy) > 5 || mmaway > 15) {
		mmaway		= 0;
		mmevent 	= 0;
		getElement('tblhelp').style.visibility 	= 'hidden';
		clearInterval(mmcheckid);
	} else {
		mymx = curmx;
		mymy = curmy;
		mmaway++;
	}
}

// ==================================================
// Window resizer: heeft begx, begy, endx, endy nodig
// ==================================================

function winresize() {
	iray = 1 - rray[rtel];
	curw = begw * iray + finw * rray[rtel];
	curh = begh * iray + finh * rray[rtel];
	window.resizeTo(Math.floor(curw), Math.floor(curh));
	rtel++;
	if (rtel >= rray.length) clearInterval(rzid);
}

// ==================================================
// Misc functions
// ==================================================

function check_login(df) {
	if (typeof (hex_md5) == "undefined") return false;
	if (df.usr.value.length == 0) {
		alert("Please enter your username");
		df.usr.focus();
		return false;
	}
	if (df.pwd.value.length == 0) {
		alert("Please enter your password");
		df.pwd.focus();
		return false;
	}
	df.pwd.value = hex_md5(hex_md5(df.pwd.value) + df.tjek.value);
	df.clk.value = 'Checking...';
	df.clk.disabled = true;
	return true;
}

function getxoff() {
	if (is_safari) 	return window.pageXOffset;
	if (is_ie) 		return document.body.scrollLeft;
}

function getyoff() {
	if (is_safari) 	return window.pageYOffset;
	if (is_ie) 		return document.body.scrollTop;
}

function setxoff(xoff) {
	if (is_safari) 	window.pageXOffset = xoff;
	if (is_ie) 		document.body.scrollLeft = xoff;
}

function setyoff(yoff) {
	if (is_safari) 	window.pageYOffset = yoff;
	if (is_ie) 		document.body.scrollTop = yoff;
}

function div_invbgcol(obj, bgcol) {
	obj.style.backgroundColor = bgcol;
}

function div_highlight(obj, tcol, bcol) {
	obj.style.color = tcol;
	obj.style.backgroundColor = bcol;
}

function check(frm, fld, sw, dis, bas) {
	// JS 15-mar-08: IE has a bug not adding dynamically created field as named properties so we loop through the elements array
	// this SHITuation happens when you create a hidden input-field using createElement("INPUT") and then try to get its value using document.form.field.value!
	var objField = eval("document."+frm+"."+fld);
	if (typeof(objField) == 'undefined') {
		var objForm = eval("document."+frm);
		for(var i=0; i<objForm.elements.length; i++) {
			if (objForm.elements[i].name == fld) {
				objField = objForm.elements[i];
				break;
			}
		}
	}

	if (typeof(objField) == 'undefined') {
		alert("The field " + fld + " could not be found!");
		return;
	}

	if (sw) {
		// schakel om (change)
		tmpval = 1 - parseInt(objField.value, 10);
		objField.value = tmpval.toString();
		getElement('img'+fld).src = "gfx/chk" + (bas ? bas : "") + tmpval.toString() + (dis ? "dis" : "") + ".gif";
		return tmpval;
	} else {
		// pak huidige inputwaarde (init)
		getElement('img'+fld).src = "gfx/chk" + (bas ? bas : "") + objField.value + (dis ? "dis" : "") + ".gif";
		return parseInt(objField.value, 10);
	}
}

// zet / get waarde van document.veld - nodig omdat JS-dynamisch gegenereerde velden in f*cking IE niet kan benaderen zoals document.formname.fieldname.value
function formFieldGetSetValue(strForm, strField, mode, strValue) {
	// zoek veld
	var objForm = eval("document."+strForm);
	for(var i=0; i<objForm.elements.length; i++) {
		if (objForm.elements[i].name == strField) {
			var objField = objForm.elements[i];
			break;
		}
	}

	// doe wat met veld
	if (typeof(objField) == 'undefined') {
		if (mode == 'set') {
			objField.value = strValue;
		}
	}

	// retourneer inhoud van veld
	return objField.value;
}

// ==============================================
// postit-note functies
// NB: moeten hier blijven, niet naar notes.js verplaatsen!
// ==============================================

function notes_add(url,params) {
	//location.href = "insert_note.php?pageid="+pageid+"&redir="+escape(url);
	//alert("insert_note.php?"+params+"&redir="+escape(url));
	location.href = "insert_note.php?"+params+"&redir="+urlenc(url);
}

function notes_toggle(url, state) {
	//alert(url);
	//return;
	location.href = "writecookie_redir.php?cname="+escape("ws_notes")+"&cvalue="+state+"&redir="+escape(url);
}

function hlRow(obj, col) {
	while (obj.nodeName != 'TR' && obj.nodeName != 'HTML') obj = obj.parentNode;
	if (obj.nodeName == 'HTML') return;

	if (col.indexOf("url(") != -1) {
		// background image
		for (var i = 0; i < obj.childNodes.length; i++) if (obj.childNodes[i].tagName == 'TD') obj.childNodes[i].style.backgroundImage = col;
	} else {
		// background color
		for (var i = 0; i < obj.childNodes.length; i++) if (obj.childNodes[i].tagName == 'TD') obj.childNodes[i].style.backgroundColor = col;
	}

	return obj;
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function isUrl(s) {
	// werkt niet: /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	// werkt niet: /https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?/;
	var regexp = /^(ftp|http|https):\/\/([0-9a-z\-]{2,})\.([0-9a-z\-]{2,})(.{0,})$/i;
	return regexp.test(s);
}

function displayEl(id,i,base) {
	d = getElement(id).style.display;

	if (d == "none") {
		getElement(id).style.display = "block";
		if (i) getElement(i+id).src = "gfx/"+base+"1.gif";
		return 1;	// return "uitgeklapt"
	} else {
		getElement(id).style.display = "none";
		if (i) getElement(i+id).src = "gfx/"+base+"0.gif";
		return 0;	// return "ingeklapt"
	}
}

// initialiseer radiobuttons
// NB1: update slechts 1 button, namelijk degene die geselecteerd is
// NB2: dus zorg ervoor bij genereren HTML dat alle radiobuttons standaard UIT staan en roep vervolgens deze functie aan
// NB3: id's van radiobuttons hebben altijd het formaat 'img' + formfieldname + 'r' + indexnummer

function init_radio(frmName, inpName, arrVal) {
	val = eval("document." + frmName + "." + inpName + ".value");
	for (i=0; i<arrVal.length; i++) {
		if (arrVal[i] == val) getElement("img" + inpName + "r" + i).src = "gfx/rad1.gif";
	}
}

function change_radio(frmName, inpName, arrVal, idx, action) {
	//alert(idx);
	eval("document." + frmName + "." + inpName + ".value = '" + arrVal[idx] + "'");
	update_radio(frmName, inpName, idx);
	if (action) eval(action);
}

function update_radio(frmName, inpName, idx) {
	tel = 0;
	while (1) {
		objid = getElement("img" + inpName + "r" + tel.toString());
		if (objid) {
			if (tel == idx) {
				objid.src = "gfx/rad1.gif";
			} else {
				objid.src = "gfx/rad0.gif";
			}
		} else {
			break;
		}
		tel++;
	}
}

// compacte versie. JS 6-jun-08: nu ook mogelijk om value mee te sturen ipv index: zie selIdxOrVal
function swradio(selIdxOrVal, frm, fld, arrValues, imgBase) {
	// indien selIdxOrVal een string is, beschouw waarde dan als selected value ipv selected index van arrValues
	var valType = typeof(selIdxOrVal); // == 'string' ? 1 : 0;

	// loop door items
	for (var i=0; i<arrValues.length; i++) {
		if ((valType == 'string' && selIdxOrVal == arrValues[i]) || (valType == 'number' && selIdxOrVal == i)) {
			// waarde of index is gelijk aan huidige item: maak actief
			eval("document."+frm+"."+fld+".value = '"+arrValues[i]+"'");
			getElement('img'+fld+i.toString()).src = "gfx/"+imgBase+"1.gif";
		} else {
			getElement('img'+fld+i.toString()).src = getElement('img'+fld+i.toString()).src.replace(/^(.+)(0|1)(\.[0-9a-z]{3,4})$/i, '$10$3'); //"gfx/"+imgBase+"0.gif";
		}
	}
}

// cookie stuff
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie= name + "=" + escape(value.toString()) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

// toggle visibility van layer
function togglevisibility(id) {
	if (getElement(id).style.visibility == 'visible') {
		getElement(id).style.visibility	= 'hidden';
		return 0;
	} else {
		getElement(id).style.visibility	= 'visible';
		return 1;
	}
}

// show popup layer
function showpopuplayer(id, xoff, yoff, hideothers, forceshow) {

	var v = forceshow ? false : getElement(id).style.visibility;

	if (v == 'visible') {
		getElement(id).style.visibility	= 'hidden';
		return 0;
	} else {
		// LET OP: moet vanuit een event aangeroepen worden ivm positionering layer, niet vanuit een A HREF oid!!

		if (typeof(xoff) == 'object') {
			xoff = obj_curleft(xoff);
		} else {
			xoff = window.event.clientX + xoff;
		}

		if (typeof(yoff) == 'object') {
			yoff = obj_curtop(yoff) + yoff.offsetHeight + 1;
		} else {
			yoff = window.event.clientY + yoff + getyoff();
		}

		getElement(id).style.visibility	= 'visible';
		getElement(id).style.left	= xoff + 'px';
		getElement(id).style.top	= yoff + 'px';

		// verberg andere layers?
		if (hideothers) {
			var ids = new Array("grabnew", "grabexport", "grabshow", "grabart", "grabaddons", "grabpublish");
			for (var i=0; i<ids.length; i++) {
				if (ids[i] != id) getElement(ids[i]).style.visibility = 'hidden';
			}
		}

		return 1;
	}
}

// alternatief: plaats object adhv positie huidige object
// NB: extra feature die kijkt of element buiten beeld valt, zoja plaats dan in beeld
function showLayerRelative(srcObj, dstObj, dstXOff, dstYOff, forceShow) {
	if (dstObj.style.visibility == 'visible' && !forceShow) {
		dstObj.style.visibility = 'hidden';
	} else {
		var objBody = document.body;
		var ow = dstObj.offsetWidth;
		var oh = dstObj.offsetHeight;
		var ox = obj_curleft(srcObj)+dstXOff;
		var oy = obj_curtop(srcObj)+dstYOff;

		if (oy+oh > objBody.clientHeight+objBody.scrollTop) {
			oy = obj_curtop(srcObj)-oh+srcObj.offsetHeight-dstYOff;
		}

		if (ox+ow > objBody.clientWidth+objBody.scrollLeft) {
			ox = obj_curleft(srcObj)-ow+srcObj.offsetWidth-dstXOff;
		}

		dstObj.style.left = ox+'px';
		dstObj.style.top  = oy+'px';
		dstObj.style.visibility = 'visible';
	}
}

// ==============================================
// maak een kleur bijv. "#f08050" lichter of donkerder in factor (0.5 = donkerder, 1.5 = lichter)
// ==============================================

function colbrightness(srcCol, factor) {
	tmpR = Math.max(0, Math.min(255, Math.round(hexdec(srcCol.substr(1,2)) * factor)));
	tmpG = Math.max(0, Math.min(255, Math.round(hexdec(srcCol.substr(3,2)) * factor)));
	tmpB = Math.max(0, Math.min(255, Math.round(hexdec(srcCol.substr(5,2)) * factor)));
	return "#" + toHex(tmpR) + toHex(tmpG) + toHex(tmpB);
}

function colmix(colA, colB, balance) {
	tmpR = Math.round( hexdec(colA.substr(1,2)) * (1-balance) + hexdec(colB.substr(1,2)) * balance);
	tmpG = Math.round( hexdec(colA.substr(3,2)) * (1-balance) + hexdec(colB.substr(3,2)) * balance);
	tmpB = Math.round( hexdec(colA.substr(5,2)) * (1-balance) + hexdec(colB.substr(5,2)) * balance);
	return "#" + toHex(tmpR) + toHex(tmpG) + toHex(tmpB);
}

// ==============================================
// decimaal naar hexadecimaal conversie
// ==============================================

var hexval = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');

function toHex(i) {
	runningTotal = '';
	quotient = hexQuotient(i);
	remainder = eval(i + '-(' + quotient + '* 16)');
	runningTotal = hexval[remainder] + runningTotal;
	while( quotient >= 16) {
		savedQuotient = hexQuotient(quotient);
		remainder = eval(quotient + '-(' + savedQuotient + '* 16)');
		runningTotal = hexval[remainder] + runningTotal;
		quotient = savedQuotient;
	}
	return hexval[quotient] + runningTotal ;
}

function hexQuotient(i) {
	return Math.floor(eval(i +'/ 16'));
}

function valClip(val, lo, hi) {
	val = parseInt(val,10);
	val = isNaN(val) ? 0 : val;
	return Math.max(lo, Math.min(hi, parseInt(val, 10)));
}

function hexdec(i) {
  i = parseInt(i.toUpperCase(),16);
  return (isNaN(i) ? 0 : i);
}

function str2int(str) {
	if (typeof(str)=="string") {
		val = parseInt(str.replace(/[^0-9\-]/gi, ''),10);
		return isNaN(val) ? 0 : val;
	} else {
		return str;
	}
}

// ==============================================
// haal gedeelte uit string, bijv. "6,weg,5" => "6,5"
// ==============================================

function str_remove(str, rem, sep) {
	// str -> complete string
	// rem -> string to remove
	// sep -> seperator to also remove

	i = str.indexOf(rem);
	if (i == -1) return str;

	cuta = i;
	cutb = i;

	if (i != 0 && str.indexOf(sep, i-1) != -1) {
		// check of ervoor nog een "," staat
		cuta -=1;
	} else if (i+2 < str.length && str.indexOf(sep, i+1) != -1) {
		// check of erna nog een "," staat
		cutb +=1;
	}

	str = str.substr(0,cuta) + str.substr(cutb+rem.length);
	return str;
}

// test of waarde in array zit
// JS 26-jul-09: case-insensitive gemaakt
function inArray(arr, val) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i].toString().toLowerCase() == val.toString().toLowerCase()) return true;
	}
	return false;
}

// zoek waarde in array en retourneer index
// JS 26-jul-09: case-insensitive gemaakt
function arrval2idx(arr, val, notfound) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i].toLowerCase() == val.toLowerCase()) return i;
	}
	return notfound;
}

// zoek een waarde in de selbox lijst en retourneer diens index of 0 indien niet gevonden
function selboxval2idx(selobj, val) {
	for (var i=0; i<selobj.options.length; i++) {
		if (selobj.options[i].value == val) {
			return i;
		}
	}
	return 0;
}

// zoek in selectbox een waarde op en selecteer deze
function selboxset(selobj, val, noWarnings) {
	for (var i=0; i<selobj.options.length; i++) {
		if (selobj.options[i].value == val) {
			selobj.selectedIndex = i;
			return i;
		}
	}
	if (noWarnings != 1) {
		alert("Warning: selectbox '"+selobj.name+"' could not be set to option with value '" + val + "'.\n\nSource: "+location.href);
	}
	return 0;
}

// zoek in selectbox een label (text) op en selecteer deze
function selboxsetbylabel(selobj, val) {
	for (i=0; i<selobj.options.length; i++) {
		if (selobj.options[i].text.toLowerCase() == val.toLowerCase()) {
			selobj.selectedIndex = i;
			return i;
		}
	}
	return 0;
}

function dumpforms() {
	dw = window.open("");
	dw.focus();
	dw.document.write("<html><body>");
	if (document.forms.length != 0) {
		for (i = 0; i < document.forms.length; i++) {
			klojo = document.forms[i];
			dw.document.write("<div style='font-size:14px; font-weight:bold; background:#e0e0e0; margin: 10px 0px 10px 0px;'>" + klojo.name + "</div>");

			for (j = 0; j < klojo.elements.length; j++) {
				objel = klojo.elements[j];
				dw.document.write("<xmp style='font-family: andale mono, courier new; font-size: 10px; margin: 0px 0px 0px 0px;'>"
					+ objel.name + ".........................".substr(0,20-objel.name.length) + ": "
					+ objel.value + "</xmp>");
			}
		}
	}
	dw.document.write("</body></html>");
}

// valideer tijdveld in formaat HH:MM bijv. 23:12
function chktime(obj) {
	v = obj.value.replace(/[^0-9]/gi, "");
	if (isNaN(v) || v.length == 0) {
		obj.value = "12:00";
	}
	v = "0000" + v;
	v = v.substr(v.length-4,4);
	h = "00" + Math.min(23, parseInt(v.substr(0,2),10)).toString();
	m = "00" + Math.min(59, parseInt(v.substr(2,2),10)).toString();

	obj.value = h.substr(h.length-2,2) + ":" + m.substr(m.length-2,2);
}

function objDisplay(objid) {
	t = getElement(objid).style.display;
	if (t == 'none') {
		getElement(objid).style.display = "block";
		t = 1;
	} else {
		getElement(objid).style.display = "none";
		t = 0;
	}
	return t;
}

// -------------------------------------------------------
// meet hoeveel tekens zijn ingetikt
// -------------------------------------------------------

var tid_update;

// start meten (oude methode: voor elk veld een apart status-element)
function start_update(formname, fieldname, defcharlen) {
	clearInterval(tid_update);
	tid_update = setInterval("trigger_update('"+formname+"', '"+fieldname+"', false, 'status"+fieldname+"', "+defcharlen+")", 1000);
}

// start meten (nieuwe methode)
function start_update_new(formname, fieldname, objwordsid, objcharsid, defcharlen) {
	// JS 12-oct-08: check of MAXLENGTH is gezet voor input-field, zoja gebruik deze instelling dan ipv de aangeleverde defcharlen
	var fieldmaxlen = eval('document.'+formname+'.'+fieldname+'.maxLength');
	if (typeof(fieldmaxlen) != 'undefined') defcharlen = fieldmaxlen;

	clearInterval(tid_update);
	trigger_update(formname,fieldname,objwordsid,objcharsid,defcharlen);
	tid_update = setInterval("trigger_update('"+formname+"','"+fieldname+"','"+objwordsid+"','"+objcharsid+"',"+defcharlen+")", 1000);
}

// update metingen aantal tekens
function trigger_update(formname, fieldname, objwordsid, objcharsid, defcharlen) {
	//alert('formname: '+formname+'\nfieldname: '+fieldname+'\nobjwordsid: '+objwordsid+'\nobjcharsid: '+objcharsid+'\ndefcharlen:'+defcharlen);

	// indien de variabele 'fieldMaxLen' niet is gedefinieerd, zet deze dan alsnog
	if ( eval("typeof("+fieldname+"MaxLen)") == "undefined" ) eval("var "+fieldname+"MaxLen = " + defcharlen);

	var l = eval(fieldname + "MaxLen");
	var d = eval("document."+formname+"."+fieldname);
	if (l < d.value.length) {
		d.value = d.value.substr(0,l);
		alert("You have reached the maximum length for this field.");
	}
	var w = d.value.replace(/[\r\n\.\:\;\,\!\?]/g, " ");
	w = trim(w.replace(/\s\s+/g, " "));
	w = w.replace(/[^\s]/g, "");

	// indien objwordsid is gezet: bereken aantal reeds geplaatste woorden
	//if (objcharsid) getElement(objcharsid).innerHTML = l - d.value.length;
	if (objwordsid && objwordsid.length) getElement(objwordsid).innerHTML = (!w.length && !d.value.length) ? 0 : w.length+1;

	// indien objcharsid is gezet: bereken aantal resterende tekens
	// JS 12-oct-08: formatteer duizendtallen als 12.384
	//if (objcharsid) getElement(objcharsid).innerHTML = (l-d.value.length) + '/' + l;
	if (objcharsid && objcharsid.length) getElement(objcharsid).innerHTML = (l-d.value.length).toString().replace(/^([0-9]+)([0-9]{3})$/, "$1.$2"); // + '/' + l;

	// % tekens over
	//if (objcharsid) getElement(objcharsid).innerHTML = 100 - Math.round(d.value.length/l * 100);
}

// stop meten
function stop_update() {
	clearInterval(tid_update);
}

// -------------------------------------------------------

function format_seconds(seconds) {
	m = "00" + Math.floor(seconds/60).toString();
	s = "00" + (seconds % 60).toString();
	return m.substr(m.length-2,2) + ":" + s.substr(s.length-2,2);
}

// vervang de ct-parameter in een url-string
function url_refresh(str) {
	ctbeg = str.indexOf("ct=");
	if (ctbeg != -1) {
		ctend = str.indexOf("&", ctbeg);
		if (ctend != -1) {
			return str.substr(0,ctbeg) + "ct=" + ctime() + str.substr(ctend);
		} else {
			return str.substr(0,ctbeg) + "ct=" + ctime();
		}
	} else {
		return str + (str.indexOf("?") == -1 ? "?" : "&") + "ct=" + ctime();
	}
	//return str.indexOf("ct=");
}

// kopieer veld van veld x naar veld y
// indien force = true kopieer dan altijd
function copyfield(formname, src, dst, force) {
	src = eval("document."+formname+"."+src);
	dst = eval("document."+formname+"."+dst);

	//	alert(src.nodeName);

	// filter enters eruit
	src.value = src.value.replace(/[\r\n]/gi, "");

	// kopieer bron- naar doelveld
	if (force == 1 || dst.value.replace(/ /gi, "").length == 0) {
		dst.value = src.value;
	}
}

function human2unix(y,m,d,h,i,s) {
	d = new Date(Date.UTC(y,m-1,d,h,i,s));
	return d.getTime() / 1000.0;
}

function unix2human(timestamp, arrMonthNames, addTime) {
	var t  = new Date(timestamp * 1000);
	var t2 =
		+ t.getDate().toString() + " "
		+ arrMonthNames[t.getMonth()] + " "
		+ t.getYear().toString();

	if (addTime) {
		t2 += " " + t.getHours().toString() + ':' + t.getMinutes().toString();
	}

	return t2;
}

function unixstamp() {
	d = new Date();
	return d.getTime() / 1000.0;
}

// retourneer true indien needle in array haystack voorkomt, anders false
function in_array(needle, haystack) {
	if (!haystack.length) return false;
	for (q=0; q<haystack.length; q++) if (needle == haystack[q]) return true;
	return false;
}

// bij aanroep, focust browser op volgende inputfield tov van huidige field
function focusnext(objField) {
	objParent = objField;

	// ga net zolang omhoog totdat we bij het <FORM> object uitkomen
	while (objParent.nodeName != "FORM" && objParent.nodeName != "HTML") objParent = objParent.parentNode;

	// breek hele procedure af indien we op top van DOM tree staan
	if (objParent.nodeName == 'HTML') return;

	// loop door alle fields in form
	for (i = 0; i < objParent.elements.length; i++) {
		// indien huidige field in form gevonden is, pak dan volgende field en focus hierop
		if (objParent.elements[i].name == objField.name) {
			j=i+1; if (j>=objParent.elements.length) j=0;
			objParent.elements[j].focus();
			break;
		}
	}
}

// retourneer absolute top en left corner van relatief object
// handig voor positioneren absolute layers bij bijv. een input-object of span
function obj_curtop(obj) {
	actb_toreturn = 0;
	while(obj){
		actb_toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return actb_toreturn;
}

function obj_curleft(obj) {
	actb_toreturn = 0;
	while(obj){
		actb_toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return actb_toreturn;
}

// ------------------------------------------------------------
// loop door object en diens parentNodes (numlevels) heen om een property te vinden
// bijv. handig om breedte te vinden: obj_getstyle(getElement('object'), 'width', 2)
// ------------------------------------------------------------

function obj_getstyle(obj, prop, numlevels) {
	for(var i=0; i<numlevels; i++) {
		var meas = str2int(eval("obj.style."+prop));
		if(meas) {
			return meas;
			break;
		}
		obj = obj.parentNode;
	}
	return false;
}

// ------------------------------------------------------------
// muis-coordinaten
// bron: http://javascript.about.com/library/blmousepos.htm
// ------------------------------------------------------------

function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}

// ------------------------------------------------------------
// enable | disable fields in form
// ------------------------------------------------------------

function disable_fields(formname, mode) {
	f = eval("document."+formname);
	// loop door alle fields in form
	for (i = 0; i < f.elements.length; i++) {
		f.elements[i].disabled = mode;
	}
}

// ------------------------------------------------------------
// verwijder object en diens childs
// ------------------------------------------------------------

function obj_remove(obj) {
	// indien er kindjes in dit object zitten, verwijder die dan eerst
	if (obj.childNodes.length) {
		for (var i = 0; i < obj.childNodes.length; i++) {
			obj_remove(obj.childNodes[i]);
		}
	}
	// verwijder vervolgens het object zelf
	obj.parentNode.removeChild(obj);
}

// ------------------------------------------------------------
// geef basisnaam zonder pad terug
// ------------------------------------------------------------

function basename(filename) {
	return filename.replace(/^.+[\\\\\\/]/g, '');
}

function urlbase(url) {
	if (url == false) url = location.href;

	// http://127.0.0.0.1/bla/bla/bla/mediaman_settings.php?bla=1&b=3 -> mediaman_settings.php
	var urlpart = url.match(/^(http|https)\:\/\/.+\/(.+)$/);
	if (urlpart) url = urlpart[2];

	urlpart = url.match(/^([^\?]+)\?(.+)$/);
	if (urlpart) url = urlpart[1];

	return url;
}

// ------------------------------------------------------------
// zoek node (bijv. TEXTAREA) en retourneer object indien gevonden
// ------------------------------------------------------------

function findNode(obj, findNodeName, lvl) {
	if (lvl>20) {
		alert('Too many recursions: '+lvl);
		return;
	}
	if (obj.nodeType == 1 && obj.nodeName == findNodeName) {
		return obj;
	} else if (obj.nodeType == 1 && obj.childNodes.length) {
		for(var c=0; c<obj.childNodes.length; c++) {
			var objChild = findNode(obj.childNodes[c], findNodeName, lvl+1);
			if (objChild) return objChild;
		}
	} else {
		return false;
	}
}

// ------------------------------------------------------------
// zoek node op className en retourneer object indien gevonden
// ------------------------------------------------------------

function findNodeByClassName(obj, findClassName, lvl) {
	if (lvl>20) {
		alert('Too many recursions: '+lvl);
		return;
	}
	if (obj.nodeType == 1 && obj.className == findClassName) {
		return obj;
	} else if (obj.nodeType == 1 && obj.childNodes.length) {
		var objChild;
		for(var c=0; c<obj.childNodes.length; c++) {
			objChild = findNodeByClassName(obj.childNodes[c], findClassName, lvl+1);
			if (objChild) return objChild;
		}
	} else {
		return false;
	}
}

// ----------------------------------------------------------------
// zoek node via een regular expression op de id
// vb:	regExp = /^(ypos)[0-9]+$/gi
//		findNodeByRegExp(getElement('content'+imgCntId), regExp, 0)
// ----------------------------------------------------------------

function findNodeByRegExp(obj, regExp, lvl) {
	if (lvl>20) {
		alert('Too many recursions: '+lvl);
		return;
	}
	if (obj.nodeType == 1 && obj.id.length && regExp.test(obj.id)) {
		return obj;
	} else if (obj.nodeType == 1 && obj.childNodes.length) {
		for(var c=0; c<obj.childNodes.length; c++) {
			var objChild = findNodeByRegExp(obj.childNodes[c], regExp, lvl+1);
			if (objChild) return objChild;
		}
	} else {
		return false;
	}
}

// ----------------------------------------------------------------
// shift(): Removes the first element from an array and returns it
// usage: 	arrayObj.shift()
// ----------------------------------------------------------------

if(!Array.prototype.shift) {
	Array.prototype.shift = function(){
		firstElement = this[0];
		this.reverse();
		this.length = Math.max(this.length-1,0);
		this.reverse();
		return firstElement;
	}
}

// ----------------------------------------------------------------
// unshift():	Returns an array with specified elements inserted at the beginning
// usage: 		arrayObj.unshift([item1[, item2 [, . . . [, itemN]]]])
// ----------------------------------------------------------------

if(!Array.prototype.unshift) {
	Array.prototype.unshift = function(){
		this.reverse();
			for(var i=arguments.length-1; i>=0; i--) {
				this[this.length] = arguments[i];
			}
		this.reverse();
		return this.length;
	}
}

function toggleRadio(formName, fieldName) {
	var r = eval('document.'+formName+'.'+fieldName);
	r.checked = r.checked ? false : true;
	return r.checked;
}

function getRadioChecked(objRadio) {
	if (objRadio.length) {
		for(var i=0; i<objRadio.length; i++) {
			if (objRadio[i].checked) {
				return objRadio[i].value;
				break;
			}
		}
	}
	return false;
}

// make percentage, degrees or integer of a value
function validateinput(input, mode, minval, maxval) {
	if (mode == "percentage") {
		return Math.max(minval, Math.min(maxval, str2int(input))).toString() + "%";
	} else if (mode == "degrees") {
		return (str2int(input) % 360).toString() + "°";
	} else if (mode == "integer") {
		return Math.max(minval, Math.min(maxval, str2int(input)));
	} else if (mode == "float") {
		input = parseFloat(input.replace(/^0-9\-\./gi, ""));
		if (isNaN(input)) input = 0;
		return Math.max(minval, Math.min(maxval, input));
	}
}

// increase / decrease value of input
function incdecinput(formname, inputname, incvalue, mode, minval, maxval) {
	obj = eval("document."+formname+"."+inputname);
	obj.value = validateinput(
		str2int(obj.value)+incvalue,
		mode,
		minval,
		maxval
	);
}

// open help
function openHelp(ref) {
	if (!ref) ref = basename(location.href).replace(/^([^\?]+)(.*)/g, '$1');
	window.open('popup_help.php?ref='+urlenc(ref));
}

// check of window.opener bestaat en nog open is (retourneert true | false)
function checkOpener() {
	if (typeof(window.opener) == 'undefined' || window.opener.closed) {
		return false;
	} else {
		return true;
	}
}

// probeer een stukje code. indien dit een javascript error geeft, vang deze af
// vb: if (checkOpener()) tryCode('window.opener.focus()', 0)
function tryCode(code, showErrors) {
	try {
		eval(code);
	}
	catch(err) {
		if (showErrors) alert('Error: ' + err.description);
	}
}

// retourneer event bij een onclick ofzo, IE en FireFox compatible
// aanroep: getEvent(event)
// vb: onkeypress="if (getEvent(event).keyCode == 13) buildsearch(0);"
function getEvent(e) {
	if (!e) var e = window.event;
	return e;
	//if (e.keyCode) code = e.keyCode;
	//else if (e.which) code = e.which;
}

// voer een link uit van een <a href=''> element: geef ID van het object op en de link wordt uitgevoerd
function execLink(aObjectId) {
	var link = getElement(aObjectId).href;
	var isJS = link.match(/^(javascript\:)(.+)$/i);

	if (isJS) {
		// linkje is javascript-code!
		link = isJS[2];
		var isVoid = link.match(/^(void\()(.+)(\))$/i);
		if (isVoid) link = isVoid[2];

		// All characters encoded with the %xx hexadecimal form are replaced by their ASCII character set equivalents.
		link = unescape(link);

		eval(link);
	} else {
		location.href = link;
	}
	//alert(link);
}

// probeer window te herschalen zodat alles erin past zonder scrollbars. zet maxw / maxh op 0 om geen maximale breedte cq. hoogte af te dwingen
function winMagicResize(maxw, maxh) {

	var visibleWidth = is_safari ? document.clientWidth : document.body.clientWidth;	// breedte van inhoud
	var actualWidth = is_safari ? document.scrollWidth : document.body.scrollWidth;		// breedte van window

	var visibleHeight = is_safari ? document.clientHeight : document.body.clientHeight;	// hoogte van inhoud
	var actualHeight = is_safari ? document.scrollHeight : document.body.scrollHeight;	// hoogte van window

	// indien window-breedte ongelijk is aan inhoud van window, pas breedte dan aan aan breedte van inhoud
	if (actualWidth != visibleWidth || actualHeight != visibleHeight) {
		// check of het onderkant van window wel op scherm past als we zo gaan herschalen
		//var winRight = window.screenLeft + (actualWidth - visibleWidth);
		//var winBottom = window.screenTop + (actualHeight - visibleHeight);

		// herschaal
		window.resizeBy(
			actualWidth - visibleWidth,
			actualHeight - visibleHeight
		);
	}

	// bekijk de nieuwe afmetingen van de inhoud en kijk of deze de maximum breedte en/of hoogte overschreiden
	var newWidth = is_safari ? document.scrollWidth : document.body.scrollWidth;		// breedte van window
	var newHeight = is_safari ? document.scrollHeight : document.body.scrollHeight;		// hoogte van window

	//if ((maxw > 0 || maxh > 0) && (newWidth != maxw || newHeight != maxh)) {
	if ((maxw > 0 || maxh > 0) && (newWidth > maxw || newHeight > maxh)) {
		window.resizeBy(
			(maxw > 0 ? maxw - newWidth : 0),
			(maxh > 0 ? maxh - newHeight : 0)
		);
	}

	window.focus();
}

// laat een object blinken
// vb: objBlink('idvanobject', 'backgroundColor', '#d0e0ff', '#ffffff', 'init');
var arrBlink = new Array(1, 0.9, 0.5, 0.1, 0, 0.1, 0.5, 0.9, 1, 0.9, 0.5, 0.1, 0, 0.1, 0.5, 0.9, 1, 0.9, 0.5, 0.1, 0);
var tidBlink, curBlink;
function objBlink(objId, objStyle, colA, colB, mode) {
	if (mode == 'init') {
		//eval("obj.style."+objStyle+" = 'red'");

		curBlink = 0;
		clearInterval(tidBlink);
		tidBlink = setInterval("objBlink('"+objId+"', '"+objStyle+"', '"+colA+"', '"+colB+"', 'anim')", 40);

	} else if (mode == 'anim') {

		eval("getElement('"+objId+"').style."+objStyle+" = '"+colmix(colB, colA, arrBlink[curBlink])+"'");
		curBlink++;
		if (curBlink >= arrBlink.length) {
			clearInterval(tidBlink);
		}

	}
}

// stel transparantie van item in
function setOpacity(obj, percentOpacity) {
	if(typeof(obj.style.filter)=='string') { obj.style.filter='alpha(opacity:'+percentOpacity+')'; }
	if(typeof(obj.style.KHTMLOpacity)=='string') { obj.style.KHTMLOpacity=percentOpacity/100; }
	if(typeof(obj.style.MozOpacity)=='string') { obj.style.MozOpacity=percentOpacity/100; }
	if(typeof(obj.style.opacity)=='string') { obj.style.opacity=percentOpacity/100; }
}

// indien nodig, scroll naar item in beeld
function scrollObjectIntoView(obj) {

	// check Y-positie
	var topOfObject = obj.style.top.length ? str2int(obj.style.top) : obj_curtop(obj);
	var bottomOfObject = topOfObject + obj.offsetHeight;
	var bottomOfVisibleArea = document.body.clientHeight + getyoff();

	//alert(obj.style.top + ' / ' + bottomOfObject + ' : ' + bottomOfVisibleArea);

	if (bottomOfObject > bottomOfVisibleArea) {
		obj.scrollIntoView(false);
	}
}

// retourneer rechter-onderkant van een element (als kommagescheiden string)
function bottomRight(id) {
	var obj = getElement(id);

	// object niet gevonden?
	if (obj == null) {
		setDocsize();
		return (window.screenLeft + Math.round(DBW/2)) + ',' + (window.screenTop);
	}

	var rgt = obj_curleft(obj) + obj.offsetWidth + window.screenLeft;
	var bot = obj_curtop(obj) + obj.offsetHeight + window.screenTop;
	return rgt+','+bot;
}

// maak van alle woorden in een string de eerste letter een Hoofdletter
function ucwords(str) {
	var arrWords = str.split(' ');
	for (var i=0; i<arrWords.length; i++) {
		arrWords[i] = arrWords[i].substr(0,1).toUpperCase() + arrWords[i].substr(1,arrWords[i].length-1);
		//alert(arrWords[i]);
	}
	return arrWords.join(' ');
}

function clipText(str, treshold, abbr) {
	if (str.length>treshold) {
		if (!abbr) abbr = '...';
		str = str.substr(0,treshold) + abbr;
	}
	return str;
}

// converteer "dd-mm-yyyy" naar unix-versie
function date2unix(dat) {
	dat = dat.replace(/[^0-9]/gi, "");
	if (dat.length != 8) return false;
	y = dat.substr(4,4);
	m = dat.substr(2,2);
	d = dat.substr(0,2);
	return human2unix(y,m,d,0,0,0);
}

