function IBF_getID(idname) {
	if (idname=='') return null; 
  	if (document.getElementById) {
    	return document.getElementById(idname);
	} else if (document.all) {
    	return document.all(idname);
	} else {
		return null;
	}
}
function IBF_getComputedStyle(elm) {
	var retStyle=null;
	if (elm!=null) {
		if (typeof elm.currentStyle!='undefined') {
			retStyle = elm.currentStyle;
		} else {
			retStyle = document.defaultView.getComputedStyle(elm,null);
		}
	}
	return retStyle;
}
function IBF_getPosition(idname) {
	// get position from idname and put into object.top, .left, .width, .height
	var id=IBF_getID(idname);
	var arr=[];
	if (id!=null) {
		var style=IBF_getComputedStyle(id);
		arr.top=style.top.replace('px','');
		arr.left=style.left.replace('px','');
		arr.width=style.width.replace('px','');
		arr.height=style.height.replace('px','');
	} else {
		arr=null;
	}
	return arr;
}
function IBF_getH() {
	// get height of browser mainwindow
	var y;
	if (self.innerHeight) {// all except Explorer
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		y = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		y = document.body.clientHeight;
	}
	return y;
}
function IBF_getW() {
	// get width of browser mainwindow
	var x;
	if (self.innerWidth) {// all except Explorer
		x = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		x = document.body.clientWidth;
	}
	return x;
}    
function IBF_forceAvailSize() {
	// force full window for browser screen
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	} else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight || top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}
function IBF_showselects(disp) {
	if (document.all && !is_ie7up) {
		var sels = document.all.tags('SELECT');
		if (sels != null) {
			for (i=0;i<sels.length; i++) {
				if (sels[i].id!='metahmenunothide') { sels[i].style.visibility = (disp=='none')?'hidden':'visible'; }
			}
		}
	}
}
function IBF_attachEvent(target, eventtype, functionref) {
	// W3C event model attach event
	if (target==null) target = document;
	if (typeof target.addEventListener!='undefined') {
		// always applied during bubble
		target.addEventListener(eventtype, functionref, false);
	} else {
		if (typeof target.attachEvent!='undefined') {
			target.attachEvent('on'+eventtype, functionref);
		} else {
			eventtype = 'on'+eventtype;
			if (typeof target[eventtype]=='function') {
				var oldlistener = target[eventtype];
				target[eventtype] = function() {
					oldlisterner();
					return functionref();
				}
			} else {
				target[eventtype] = functionref;
			}
		}
	}
}
function IBF_detachEvent(target, eventtype, functionref) {
	// W3C event model delete event
	if (target==null) target = document;
	if (typeof target.removeEventListener!='undefined') {
		// always applied during bubble
		target.removeEventListener(eventtype, functionref, false);
	} else {
		if (typeof target.detachEvent!='undefined') {
			target.detachEvent('on'+eventtype, functionref);
		} else {
			target['on'+eventtype] = null;
		}
	}	
}
function IBF_stopEvent(event) {
	if (typeof event.stopPropagation!='undefined') {
		event.stopPropagation();
	} else {
		event.cancelBubble = true;
	}
}
function IBF_getTarget(event) {
	// getTarget from event (none textNode=3)
	var targetElm=null;
	if (typeof event.target!='undefined') {
		targetElm = event.target;
	} else {
		targetElm = event.srcElement;
	}
	while (targetElm.nodeType==3 && targetElm.parentNode!=null) {
		targetElm = targetElm.parentNode;
	}
	return targetElm;
}
var IBF_movediv = {
	newx: 0,
	newy: 0,
	divname: '',
	cover: null,
	loading: null,
	trdiv: null,
	init: function(divname) {
		this.offsetx=this.offsety=this.curx=this.cury=0;
		this.divname=divname;
		if (divname!='') {
			var div = IBF_getID(this.divname);
			if (div!=null) div.onmousemove=null;
		}
	},
	savePosition: function(saveFunction) {
		this.saveFunction = saveFunction;
	},
	showMoving: function() {
		var main = IBF_getID(this.divname);
		if (main!=null) {
			this.cover = IBF_dimmer.topDocument.createElement('div');
			main.appendChild(this.cover);
			IBF_dimmer.resetStyles(this.cover) ;
			IBF_dimmer.setElementStyles(this.cover,
			{
			'position' : 'absolute',
			'zIndex' : 20,
			'cursor' : 'move',
			'top' : '0px',
			'left' : '0px',
			'backgroundColor' : '#FFFFFF'
			} ) ;
			IBF_dimmer.setOpacity(this.cover,0.7) ;
			IBF_dimmer.setElementStyles( this.cover,
			{
			'width' : Math.max( main.scrollWidth,
			main.clientWidth) - 1 + 'px',
			'height' : Math.max( main.scrollHeight,
			main.clientHeight) - 1 + 'px'
			});
			IBF_attachEvent(this.cover,'click',IBF_movediv.onclick);
			this.loading = IBF_dimmer.topDocument.createElement('div');
			main.appendChild(this.loading);
			IBF_dimmer.resetStyles(this.loading) ;
			IBF_dimmer.setElementStyles(this.loading,
			{
			'position' : 'absolute',
			'zIndex' : 32,
			'left' : (Math.max( main.scrollWidth,main.clientWidth) / 2) - 150 + 'px',
			'top' : (Math.max( main.scrollHeight,main.clientHeight) / 2) - 80 + 'px',
			'backgroundColor' : '#FFFFFF',
			'color' : 'black',
			'border' : '1px solid black',
			'padding' : '2px',
			'width' : '300px',
			'height' : '80px'
			});
			this.loading.innerHTML = 'Verplaatsen van de popup...<br /><br />Beweeg de muis voor het verplaatsen.<br />Klik opnieuw om te stoppen en de positie te bewaren.';
			IBF_attachEvent(this.loading,'click',IBF_movediv.onclick);
		}
	},
	hideMoving: function() {
		var main = IBF_getID(this.divname);
		if (main!=null) {
			if (this.cover!=null) main.removeChild(this.cover);
			if (this.loading!=null) main.removeChild(this.loading);
			this.cover=this.loading=null;
		}
	},
	reset: function() {
		var div = IBF_getID(this.divname);
		if (div!=null) {
			div.onmousemove=null;
			if (this.cover!=null) div.removeChild(this.cover);
			if (this.loading!=null) div.removeChild(this.loading);
			this.cover=this.loading=null;
		}
		if (this.trdiv!=null) {
			this.trdiv.style.cursor = 'pointer';
		}
		this.divname='';
		this.trdiv=null;
		this.offsetx=this.offsety=this.curx=this.cury=0;
		this.saveFunction='';
	},
	onclick: function() {
		var argv=IBF_movediv.onclick.arguments, argc=argv.length;
		var trdiv=((argc>0)?argv[0]:null);
		var divname=((argc>1)?argv[1]:'');
		var saveFunction=((argc>2)?argv[2]:'');
		if (IBF_movediv.divname=='' && divname!='') {
			IBF_movediv.offsetx=IBF_movediv.offsety=IBF_movediv.curx=IBF_movediv.cury=0;
			if (saveFunction!='') IBF_movediv.saveFunction = saveFunction;
			IBF_movediv.divname=divname;
			var div = IBF_getID(IBF_movediv.divname);
			if (div!=null && div.style.display!='none') {
				IBF_attachEvent(null,'mousemove',IBF_movediv.onmousemove);
				//window.onmousemove=IBF_movediv.onmousemove;
				//div.onmousemove=IBF_movediv.onmousemove;
				IBF_movediv.trdiv = trdiv;
				trdiv.style.cursor = 'move';
				IBF_movediv.showMoving();
			}
		} else {
			if (typeof IBF_movediv.saveFunction!='undefined') {
				eval(IBF_movediv.saveFunction+'('+IBF_movediv.newx+','+IBF_movediv.newy+');');
				window.status='Saved position';
			} else {
				window.status='';
			}
			IBF_movediv.hideMoving();
			IBF_movediv.reset();
		}
	},
	onmousedown: function(divname) {
		var saveFunction = (arguments.length>1)?arguments[1]:'';
		this.offsetx=this.offsety=this.curx=this.cury=0;
		if (saveFunction!='') this.saveFunction = saveFunction;
		this.divname=divname;
		var div = IBF_getID(this.divname);
		IBF_attachEvent(null,'mousemove',IBF_movediv.onmousemove);
		//div.onmousemove=IBF_movediv.onmousemove;
	},
	onmousemove: function(evt) {
		evt = (evt) ? evt : ((event) ? event : null);
		if (typeof evt.pageX!='undefined' && typeof evt.x!='undefined') {
			cursorx = evt.pageX;
			cursory = evt.pageY;
		} else {
			cursorx = evt.clientX;
			cursory = evt.clientY;
		}
		var div = IBF_getID(IBF_movediv.divname);
		if (div!=null) {
			if (IBF_movediv.offsetx==0) {
				IBF_movediv.offsetx=cursorx;IBF_movediv.offsety=cursory;
				style=IBF_getComputedStyle(div);
				IBF_movediv.curx = parseInt(style.left.replace('px',''));
				IBF_movediv.cury = parseInt(style.top.replace('px',''));
			}
			IBF_movediv.newx = IBF_movediv.curx + (cursorx - IBF_movediv.offsetx);
			IBF_movediv.newy = IBF_movediv.cury + (cursory - IBF_movediv.offsety);
			div.style.left = IBF_movediv.newx + 'px';
			div.style.top = IBF_movediv.newy + 'px';
			window.status='Move '+IBF_movediv.divname+' to ('+IBF_movediv.newx+', '+IBF_movediv.newy+')   ';
		}
		IBF_stopEvent(evt);
	},
	onmouseup: function() {
		if (typeof this.saveFunction!='undefined') {
			eval(this.saveFunction+'('+IBF_movediv.newx+','+IBF_movediv.newy+');');
			window.status='Saved position';
		} else {
			window.status='';
		}
		this.init('');
	},
	onmouseout: function() {
		window.status='';
		this.init('');
	}
}
function IBF_parseInt(pValue) {
	var t = parseInt(pValue);
	return ((isNaN(t)) ? 0 : t);
}
var IBF_cookie = {
	read: function (name) {
		var nameEQ = name + "=";
		var value = null;
		try {
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) {
					value = c.substring(nameEQ.length,c.length);
					break;
				}
			}
		}
		catch (e) {
			value=null;
			//alert('IBF_cookie.read; cookies disabled');
		}
		return value;
	},
	write: function (name,value,days) {
		var expires = '';
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = '; expires='+date.toGMTString();
		}
		try {
			document.cookie = name+'='+value+expires+'; path=/';
		} 
		catch (e) {
			// nothing
			//alert('IBF_cookie.Write; cookies disabled');
		}
	},
	remove: function (name) {
		this.write(name,'',-1);
	},
	setPosition: function (div,cookiename) {
		
		var style=IBF_getComputedStyle(div);
		var width=IBF_parseInt(style.width.replace('px',''));
		var curX=IBF_parseInt(style.left.replace('px',''));
		var curY=IBF_parseInt(style.top.replace('px',''));

		var lastpos=this.read(cookiename);
		
		if (lastpos!=null && lastpos!='') {
			var lastxy=lastpos.split('-');
			if (lastxy.length>0) {
				curX = IBF_parseInt(lastxy[0]);
				curY = IBF_parseInt(lastxy[1]);
			}
		}

		// scherm hoogte en breedte
		var h=IBF_getH(), w=IBF_getW();

		// LEFT positie
		if (curX+width+20 > w) {
			div.style.left = w - width - 20;
		} else {
			div.style.left = curX;
		}

		// TOP positie
		var popheight = h - curY - 30;
		if (popheight < 200) {
			popheight = 200;
			div.style.top = curY - popheight;
		} else {
			div.style.top = curY;
		}
	}
}
var IBF_dimmer = {
	usercoverevent: null,
	init: function() {
		this.cover=null;
		this.topWindow = window;		
		// 2008/7/28/Gs: huidige window is topWindow; niet frame erbij halen, want dan problemen in IE6
		if (!is_ie || is_ie7up) {
			var parent;
			try {
				 parent = this.topWindow.parent;
			}
			catch (e) {	
				 parent = null;			
			}			
			//this.topWindow = window.parent ;
			while ( parent!=null && parent!=this.topWindow ) {
				try
				{
					if ( this.topWindow.parent.document.domain != document.domain )
					break ;
					if ( this.topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 )
					break ;
				}
				catch ( e )
				{
					break ;
				}
				try {
					 parent = this.topWindow.parent;
				}
				catch (e) {	
					 parent = null;			
				}			
				if (parent!=null) this.topWindow = parent;
			}
		}
		this.topDocument = this.topWindow.document;
	},
	addOwndiv: function(div) {
		this.topDocument.body.appendChild(div);
	},
	delOwndiv: function(div) {
		this.topDocument.body.removeChild(div);
	},
	setUsercoverevent: function(userfunc) {
		this.usercoverevent=userfunc;
	},
	resetStyles: function(element) {
		element.style.cssText = 'margin:0;' +
		'padding:0;' +
		'border:0;' +
		'background-color:transparent;' +
		'background-image:none;' ;
	},
	setElementStyles: function( element, styleDict ) {
		var style = element.style ;
		for ( var styleName in styleDict )
		style[ styleName ] = styleDict[ styleName ] ;
	},
	setOpacity: function( element, opacity ) {
		if (is_ie) {
			opacity = Math.round( opacity * 100 ) ;
			element.style.filter = ( opacity > 100 ? '' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')' ) ;
		} else {
			element.style.opacity = opacity ;
		}
	},
	resizeHandler: function() {
		// TO-DO: works not for making smaller, just for making larger
		if (!this.cover) return ;
		var relElement = this.topDocument.body;
		this.setElementStyles( this.cover,
		{
		'width' : Math.max( relElement.scrollWidth,
		relElement.clientWidth,
		this.topDocument.scrollWidth || 0 ) - 1 + 'px',
		'height' : Math.max( relElement.scrollHeight,
		relElement.clientHeight,
		this.topDocument.scrollHeight || 0 ) - 1 + 'px'
		} ) ;
	},
	/**
	* Retrieve the correct "empty iframe" URL for the current browser, which
	* causes the minimum fuzz (e.g. security warnings in HTTPS, DNS error in
	* IE5.5, etc.) for that browser, making the iframe ready to DOM use whithout
	* having to loading an external file.
	*/
	getVoidUrl: function() {
		if (is_ie) {
			if (is_ie7up || !is_ie6)
			return "" ;					// IE7+ / IE5.5
			else
			return "javascript: '';" ;	// IE6+
		}
		return "javascript: void(0);" ;		// All other browsers.
	},
	/**
	* Dim door een layer met een bepaalde doorzichtigheid over het scherm te leggen
	*/
	showCover: function() {
		if (this.cover==null) {
			// Setup the DIV that will be used to cover.
			this.cover = this.topDocument.createElement( 'div' ) ;
			this.resetStyles( this.cover ) ;
			this.setElementStyles( this.cover,
			{
			'position' : 'absolute',
			'zIndex' : 20,
			'top' : '0px',
			'left' : '0px',
			'overflow' : 'hidden',
			'backgroundColor' : '#000000'
			} ) ;
			this.setOpacity(this.cover,0.4) ;
			// We need to manually adjust the this.cover size on resize.
			this.resizeHandler() ;
			if (this.usercoverevent!=null) IBF_attachEvent(this.cover,'click',this.usercoverevent);
		}
		this.topDocument.body.appendChild(this.cover);
	},
	hideCover: function() {
		//this.cover.parentNode.removeChild(this.cover);
		if (this.cover!=null) this.topDocument.body.removeChild(this.cover);
	}
}
IBF_dimmer.init();
function IBF_showHide(idname,show) {
	var div = IBF_getID(idname);
	if (div!=null) {
		div.style.display = ((show)?'block':'none');
	}
}
var IBF_validator = {
	isDate: function (dateStr) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
			var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
			var matchArray = dateStr.match(datePat); // is the format ok?
			if (matchArray == null) {
				return false;
			}
			year = matchArray[1];
			month = matchArray[3]; 
			day = matchArray[5];
		} else {
			day = matchArray[1];
			month = matchArray[3];
			year = matchArray[5];
		}
		if (month < 1 || month > 12) { // check month range
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				return false;
			}
		}
		return true; // date is valid
	},
	isEmail: function(emailStr) {
		emailStr=emailStr.replace(/^\s+/,'').replace(/\s+$/,'');
		if (emailStr!='') {
			if (emailStr.indexOf(" ") != -1)
			return false;
			else if (emailStr.indexOf("@") == -1)
			return false;
			else if (emailStr.indexOf("@") == 0)
			return false;
			else if (emailStr.indexOf("@") == (emailStr.length-1))
			return false;
			var arrayString = emailStr.split("@");
			if (arrayString[1].indexOf(".") == -1)
				return false;
			else if (arrayString[1].indexOf(".") == 0)
				return false;
			else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
				return false;
			}
		}
		return true;
	},
	isNumber: function(number) {
		var t = parseInt(number);
		return (!isNaN(t));
	},
	isPostcode: function(postcode) {
		// NL postcode)
		result = /^\d{4}[\s-]?[a-zA-Z]{2}/.test(postcode);
		return result;
	},
	isMobile: function(mobile) {
		if (!IBF_validator.isNumber(mobile)) {
			return false;
		}
		// NL mobiel nummer (!)
		result = /(\+31|0)6\d{8}/.test(mobile);
		return result;
	}
}
var IBF_callserver = {
	cbdata: '',
	cbfunc: '',
	cbsession: '',
	setup: function(cbfunc,cbsession) {
		this.cbfunc=cbfunc;
		this.cbsession=cbsession;
	},
	callback: function(pmode,pkey) {
		var head = document.getElementsByTagName('head').item(0);
		script = document.createElement('script');
		var src = 'callback.php?cb='+this.cbfunc;
		src += '&md='+pmode;
		src += '&ik='+escape(pkey);
		if (this.cbsession!='') src += '&'+this.cbsession;
		src += '&dt='+escape(this.cbdata);
		src += '&rd='+escape(Math.random() * 1000);
		script.src = src;
		script.type = 'text/javascript';
		script.defer = false;
		script.id = 'ibfcallserver';
		void(head.appendChild(script));
	},
	elmvalue: function(elm) {
		var val='';
		alert('elm.type'+elm.type);
		if (elm.type=='CHECKBOX') {
			val = (elm.checked)?'y':'n';
		} else {
			val = elm.value;			
		}
		return val;
	},
	setData: function(cbdata) {
		this.cbdata=cbdata;
	},
	form2data: function(prefix) {
		this.data='';
		var i=0;
		var div=IBF_getID(prefix+i);
		this.cbdata = '';
		while (div!=null) {
			val = this.elmvalue(div);
			this.cbdata += div.name+'='+val+';';
			i += 1;
			div=IBF_getID('peveld'+i);
		}
	}
}
var IBF_callback = {
	cbget: '',
	cbsession: '',
	setup: function(cbget,cbsession) {
		this.cbget=cbget;
		this.cbsession=cbsession;
	},
	callback: function() {
		var head = document.getElementsByTagName('head').item(0);
		script = document.createElement('script');
		var src = 'callback.php?cb='+this.cbget;
		if (this.cbsession!='') src += '&'+this.cbsession;
		src += '&rd='+escape(Math.random() * 1000);
		script.src = src;
		script.type = 'text/javascript';
		script.defer = false;
		script.id = 'ibfcallback';
		void(head.appendChild(script));
	},
	showProgress: function() {
		IBF_dimmer.topDocument.body.style.cursor = 'progress';
	},
	hideProgress: function() {
		IBF_dimmer.topDocument.body.style.cursor = 'default';
	}
}
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();
// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
var is_ie7up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6);
