// ==================================================
// global vars
// ==================================================

var regURL = new RegExp(/^(http\:\/\/)([a-z0-9\-]+\.){1,2}([a-z0-9\-])/);

// 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_ipad		= navigator.userAgent.indexOf("iPad") != -1;
var is_iphone	= navigator.userAgent.indexOf("iPhone") != -1;

// document afmetingen
var DBW, DBH;

// ==================================================
// misc functions
// ==================================================

function setDocsize(debug) {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		DBW = window.innerWidth;
		DBH = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		DBW = document.documentElement.clientWidth;
		DBH = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		DBW = document.body.clientWidth;
		DBH = document.body.clientHeight;
	}

	if (debug) top.document.title = 'document width: ' + DBW + ' x ' + DBH;
}


function getDocScrollSize() {
    var d = document;

    var w = Math.max(
        Math.max(d.body.scrollWidth, d.documentElement.scrollWidth),
        Math.max(d.body.offsetWidth, d.documentElement.offsetWidth),
        Math.max(d.body.clientWidth, d.documentElement.clientWidth)
    );

    var h = Math.max(
        Math.max(d.body.scrollHeight, d.documentElement.scrollHeight),
        Math.max(d.body.offsetHeight, d.documentElement.offsetHeight),
        Math.max(d.body.clientHeight, d.documentElement.clientHeight)
    );

    return new Array(w,h);
}


function getScrollPosition() {
	var XPos = (document.all) ? document.body.scrollLeft : window.pageXOffset;
	var YPos = (document.all) ? document.body.scrollTop : window.pageYOffset;
	return new Array(XPos, YPos);
}


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 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 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 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"
	}
}

// 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;
	}
}

// ==============================================
// 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) {
	if (colA.match(/^(rgb)/i)) {
		colA = colA.replace(/[^0-9,]/g, '').split(',');
	} else {
		colA = new Array(hexdec(colA.substr(1,2)), hexdec(colA.substr(3,2)), hexdec(colA.substr(5,2)));
	}

	if (colB.match(/^(rgb)/i)) {
		colB = colB.replace(/[^0-9,]/g, '').split(',');
	} else {
		colB = new Array(hexdec(colB.substr(1,2)), hexdec(colB.substr(3,2)), hexdec(colB.substr(5,2)));
	}

	var tmpR = Math.round( colA[0] * (1-balance) + colB[0] * balance);
	var tmpG = Math.round( colA[1] * (1-balance) + colB[1] * balance);
	var tmpB = Math.round( colA[2] * (1-balance) + colB[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;
}

// 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=");
}

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 (var q=0; q<haystack.length; q++) if (needle == haystack[q]) return true;
	return false;
}

// 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;
	}
}

// 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);
}

// stel transparantie van item in
function zetOpacity(obj, percentOpacity) {
	percentOpacity = Math.round(percentOpacity);

	if(typeof(obj.style.opacity)=='string') { obj.style.opacity=percentOpacity/100; }
	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; }
}

// 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);
}

//

function addEvent2( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent2( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function getElementsByClassName(classname, node) {

	//alert(classname);

	if (!node) {
		node = document.getElementsByTagName('body')[0];
	}

	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName('*');

	for (var i = 0, j = els.length; i < j; i++) {
		if ( re.test(els[i].className) ) {
			a.push(els[i]);
		}
	}

	return a;
}


function getElementsByRegExpId(p_regexp, p_element, p_tagName) {
	p_element = p_element === undefined ? document : p_element;
	p_tagName = p_tagName === undefined ? '*' : p_tagName;
	var v_return = [];
	var v_inc = 0;
	for(var v_i = 0, v_il = p_element.getElementsByTagName(p_tagName).length; v_i < v_il; v_i++) {
		if(p_element.getElementsByTagName(p_tagName).item(v_i).id && p_element.getElementsByTagName(p_tagName).item(v_i).id.match(p_regexp)) {
			v_return[v_inc] = p_element.getElementsByTagName(p_tagName).item(v_i);
			v_inc++;
		}
	}
	return v_return;
}


