//   -			-			-			-			-			BROWSERDETECTION & MISC

var isOpera   = (navigator.appName.indexOf("Opera")>-1  || (!window.showHelp && navigator.appName=="Microsoft Internet Explorer"));
var isIE      = (!isOpera && document.all  ) ? true : false;
var isNS6     = (!isOpera && !isIE&&$) ? true : false;
var isMac	  = navigator.platform.indexOf("Mac")>-1;

var blnOpenCloseDocument = true;

var lib_form_saving_prefix = "__FRM_save_";
var lib_form_saving_days = 365;
var lib_cookie_repl_sep = "__%__"; 			// vervanging voor ; in cookie waardes

var fader_zindex = 999998;
var lib_caption_height = 28;
var lib_std_shadow = "progid:DXImageTransform.Microsoft.Shadow(color='#888888',Direction=135,Strength=7)"

//  -			-			-			-			-			Quick functions

// 	$ replacement for document.getElementbyId
//
function $(id) {
	if (document.getElementById) {
		elt = document.getElementById(id);
	} else if (document.all) {
		elt = document.all[id];
	}
	return elt;
} 

function lib_getObj(id) { return $(id); }


//   -			-			-			-			-			EVENTS

function lib_event_get_key( evt ) {
	return (evt.charCode ? evt.charCode : (evt.keyCode ? evt.keyCode : (evt.which ? evt.which : (window.event ? window.event.keyCode : null) )));
}

// 	addEvent(window, "load", sortables_init);
//
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be removed");
	}
} 

//   -			-			-			-			-			ANTI-SPAM function
// let op : deze functie word aangeroepen vanuit ASP library code: niet wijzigen!
function lib_mail(u,d,s){
	document.write('<a href=\"mailto:'+u+'@'+d+(s=='' ? '' : '?subject='+s)+'\">')
}

//   -			-			-			-			-			FORMS


// 	use this in a keydown of a control to surpress any other characters than numbers
//	now supports the clipboard: please note that copying text is allowed this way
function lib_form_digitsonly (evt) {
	var charCode = lib_event_get_key( evt );
	var shift = evt ? evt.shiftKey : false;
	var ctrl  = evt ? evt.ctrlKey  : false;
 	return ( ctrl || (!shift) && ((charCode >= 48 && charCode <= 57)  || (charCode >= 96 && charCode <= 105) || charCode==190 || charCode==9 || charCode==8 || charCode==46 || charCode==37  || charCode==189) )
}

// 	use <textarea maxlength="40" onkeyup="return lib_form_check_maxlength(this)"></textarea>
//
function lib_form_check_maxlength(obj){
	var maxlen=obj.getAttribute?parseInt(obj.getAttribute("maxlength")) : 90;
	if (obj.getAttribute && obj.value.length>maxlen) obj.value=obj.value.substring(0,maxlen);
}

//	Key characters for a time field
//
function lib_form_timekey (evt) {
	var charCode = lib_event_get_key( evt );
	
	if (charCode==32) {
		// change into a : character (not supported in Mozilla
		if (window.event) window.event.keyCode = 58;
		return true;
	} else {
		// || (charCode >= 96 && charCode <= 105)
		return (charCode==58 || charCode==13 || (charCode >= 48 && charCode <= 57)  || charCode==190 || charCode==9 || charCode==8 || charCode==46 || charCode==37  || charCode==189) 
	}
}


// 	use this in a keydown of a control to surpress spaces
//
function lib_form_nospaces (evt) {
	var charCode = lib_event_get_key( evt );
	return (charCode != 32) 
}

// 	Indicates whether the content of a form has changed since loading it
// 
function lib_form_is_modified(oForm) {
	var el, opt, hasDefault, i = 0, j;
	while (el = oForm.elements[i++]) {
		switch (el.type) {
			case 'text' :
			case 'textarea' :
			case 'hidden' :
				if (!/^\s*$/.test(el.value) && el.value != el.defaultValue) return true;
				break;
			case 'checkbox' :
			case 'radio' :
				if (el.checked != el.defaultChecked) return true;
				break;
			case 'select-one' :
			case 'select-multiple' :
				j = 0, hasDefault = false;
				while (opt = el.options[j++])
					if (opt.defaultSelected) hasDefault = true;
				j = hasDefault ? 0 : 1;
				while (opt = el.options[j++]) 
					if (opt.selected != opt.defaultSelected) return true;
				break;
		}
	}
	return false;
}

//	Save the content of all fields in a form to separate cookies (currently igoring hidden end password fields)
//
//	exclude fields by setting their class to lib_nosave 
//
function lib_form_save_content(frm) {
	var string;
	var blnStoreField;
	
	if (frm) {
		var n = frm.length;
		for (i = 0; i < n; i++) {
			try {
				var e = frm[i].name;
				if (e) {
					var e_clean=e;
					if (e_clean.substring(0,9).toLowerCase()=='required-')
						e_clean = e_clean.substring(9);
					blnStoreField = !frm[i].disabled && (frm[i].className.search(/lib_nosave/i)==-1);
					if (blnStoreField) {
						fieldValue  = frm[i].value;
						fieldType   = frm[i].type;
						string 		= "";

						if (fieldType == "radio") {
							for (x=0; x < frm.elements[e].length; x++) {
								if (frm.elements[e][x].checked) {string = frm.elements[e][x].value};
							}			
							if (i+1<frm.length) 
								while (frm[i].name && frm[i].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) i++;
							while (frm[i].name && frm[i].name.toLowerCase()!=e.toLowerCase()) i--;
						}
						if ((fieldType == "text") || (fieldType == "textarea")) {
							string = frm.elements[e].value;
						}
						if (fieldType == "select-one") {
							string = frm[i].options[frm[i].selectedIndex].text;
						}
						if (fieldType == "checkbox") {
							// store all other values of this checkbox in the same cookie
							if (i+1<frm.length) {
								while (frm[i].name && frm[i].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) {
									string = string + (frm[i].checked==true ? ((string=="" ? "" : ",") + frm[i].value) : "");	
									i++;
								}
								while (frm[i].name && frm[i].name.toLowerCase()!=e.toLowerCase()) i--;
							} else {
								string = frm[i].checked==true ? fieldValue : "";
							}
						}

						// also save empty values: this can be informational as well! , save them for a year
						if (fieldType!="hidden" && fieldType!="password" && fieldType!="select-multiple") {
							lib_createCookie(lib_form_saving_prefix + e_clean.toLowerCase(), string, lib_form_saving_days);
						}
					}
				}
			}
	        catch(err) {}		
		}
	}
}


//	TODO: Multiple selection listboxes
//	exclude fields by setting their class to lib_nosave 
//
function lib_form_load_content(frm) {
	var blnRestoreField;
	
	if (frm) {
		var n = frm.length;
		for (var i = 0; i < n; i++) {
			try {
				var e = frm[i].name;
				if (e) {
					var e_clean = e;
					if (e_clean.substring(0,9).toLowerCase()=='required-') 
						e_clean = e_clean.substring(9);
						
					blnRestoreField = !frm[i].disabled && (frm[i].className.search(/lib_nosave/i)==-1);

					if (blnRestoreField) {
						var fieldValue = lib_readCookie(lib_form_saving_prefix + e_clean.toLowerCase());
						if (fieldValue) {
							var fieldType  = frm[i].type.toLowerCase();

							if ((fieldType == "text") || (fieldType == "textarea")) {
								frm[i].value = fieldValue;
							}
							if (fieldType == "select-one") {
								lib_form_group_select(frm, e, fieldValue);
							}
							if (fieldType == "checkbox") {
								lib_form_setCheckbox(frm, e, fieldValue);
								if (i+1<frm.length) 
									while (frm[i+1] && frm[i+1].name && frm[i+1].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) i++;
							}
							if (fieldType == "radio") {
								lib_form_setRadio(frm, e, fieldValue)
								if (i+1<frm.length) 
									while (frm[i+1] && frm[i+1].name && frm[i+1].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) i++;
							}
						}
					}
				}
			}
	        catch(err) {}		
		}
	}
}

// 	Automatically sets the focus to the first possible form field
// 
function lib_form_autofocus() {
	var bFound = false;

	for (var f=0; f < document.forms.length; f++) {
		for(var i=0; i < document.forms[f].length; i++) {
		  if (document.forms[f][i].type != "hidden") {
			if (document.forms[f][i].disabled != true) {
				document.forms[f][i].focus();
				var bFound = true;
			}
		  }
		  if (bFound == true) break;
		}
	if (bFound == true) break;
	}
}

//	Sets the select field to the tip (like type your name here..)
//  
function lib_form_edit_select_tip(oControl, sDefault) {
	if (oControl.value!=sDefault) { oControl.select() } else { oControl.value='' }
}

//	Adds a number to a specified form field (for + and - button)
//
function lib_form_add_number(oForm, elt_name, nOffset) {
	var elt = oForm.elements[elt_name];
	if (elt) {
		var cur = parseInt(elt.value);
		if (isNaN(cur)) cur=0;
		var new_value = Math.max(0,cur + nOffset);
		oForm.elements[elt_name].value = (new_value==0 ? '' : new_value.toString());
	}
}

// 	Sets the value of a radio button
//
function lib_form_setRadio(oFrm, radio_name, new_value) {
	try {
		for (var y=0; y < oFrm.elements.length; y++) {
			if (oFrm.elements[y].name) {
				if (oFrm.elements[y].name.toLowerCase()==radio_name.toLowerCase()) {
					oFrm.elements[y].checked = (oFrm.elements[y].value==new_value);
				}
			}
		}
	}
	catch(e) {}
}

//	Sets the values for a range of checkboxes
//
function lib_form_setCheckbox(oFrm, checkbox_name, new_values) {
	try {
		if (new_values) {
			var arr_values = lib_array_split(new_values);
			for (var x=0; x < oFrm.elements[checkbox_name].length; x++) {
				oFrm.elements[checkbox_name][x].checked = (lib_array_find(arr_values, oFrm.elements[checkbox_name][x].value) > -1);
			}
		}
	}
	catch(e) {}
}

// 	Finds a form field 
//
function lib_form_findfield(sName) {
	var fldObj = null;
	var the_frm;

	fldObj = $(sName);
	if (!fldObj) {
	  for (var f=0; f<=document.forms.length; f++) {
		the_frm = document.forms[f];
		try { 
			if (the_frm[sName]) return the_frm.elements[sName];
		} 
		catch(err) {}
	  }
	} 
	return fldObj;
}

//	Selects a value within a select box 
//
function lib_form_group_select(oFrm, sField, sSelectedValue){
	try {
		var fld = oFrm.elements[sField];
		for (t=0;t<fld.options.length;t++) {
			if (fld.options[t].text.toLowerCase() == sSelectedValue.toLowerCase()) {
				fld.selectedIndex=t;
			}
		}
	}
	catch(e) {}
} 



//	Validates an email address
//
function lib_form_valid_email(email){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return  (filter.test(email))
}


//   -			-			-			-			-			CONVERSIONS

// 	formats a number with the specified numer of  deimals
//
function lib_NumberFormat(num, decimalNum) { 
    if (isNaN(parseInt(num))) return "NaN";
	var tmpNumStr = ((num.toFixed(decimalNum)).toString()).replace(".",",") ;
	return (tmpNumStr);		// Return our formatted string!
}

//   -			-			-			-			-			CLIPBOARD

function lib_ClipboardCopy(s) {
	if(window.clipboardData && clipboardData.setData) {
		clipboardData.setData("Text", s);
	} else {
		alert ("Helaas, kopieren niet gelukt..");
	}
}

//   -			-			-			-			-			STYLESHEETS

//	This function will include a specified CSS if a rule is not present
//
function lib_css_include( cStyleName, sCSSName ) {
return;

	var bFound = false;
	var selectorText = cStyleName.toLowerCase();
	
	for (var i=0; i<document.styleSheets.length; i++) {
		var rules = document.styleSheets[i].cssRules ? document.styleSheets[i].cssRules : document.styleSheets[i].rules;
		for (var i=0; i<rules.length; i++) {
			if (rules[i].selectorText.toLowerCase() == selectorText) {
				bFound = true;
				break;
	        }
	    }
	}
	if (!bFound) {
		var headID = document.getElementsByTagName("head")[0];
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = sCSSName;
		headID.appendChild(cssNode);
	}
}

//   -			-			-			-			-			ALERTS

var ALERT_BUTTON_TEXT = "Ok";

if(window.alert) {
	window.modal_alert = window.alert;				// save original alert for situations in which the modality is really needed (just use modal_alert() instead of alert()
	window.alert = function(txt,title,icon) {
		lib_alertbox(txt,title,icon);
	}
}

//	alert box
//
function lib_alertbox(txt, title, icon) {
	var body_elt = document.getElementsByTagName("body")[0];
	
	if($("modalContainer")) return;
	
	lib_css_include('DIV#modalContainer','library/library.css');

	title = title ? title : 'Melding';
	icon  = icon  ? icon  : 'info';
    txt   = txt.replace( /\n/gi, "<br>");
	
	lib_screen_fade(true);

	// create the modalContainer div as a child of the BODY element
	var mObj = body_elt.appendChild(document.createElement("div"));
	mObj.id="alertBox";
	mObj.style.visibility='hidden';
	mObj.style.zIndex=fader_zindex+1;
	mObj.innerHTML=
		"<div id=lib_window_dialog class="+icon+">" +
			"<div class=lib_window_caption>" +
				"<a href=javascript:lib_alertbox_remove()><div class=lib_window_close></div></a>" + 
				"<div class=lib_window_caption_title>" + title + "</div>" + 
			"</div>" +
			"<p onClick=lib_alertbox_remove()>" + txt.replace(/\r\n/ig,"<br>") + "</p>" +
			"<div class=buttonbar onClick=lib_alertbox_remove()>" +
				"<a class=button href=javascript:lib_alertbox_remove()><div>" + ALERT_BUTTON_TEXT + "</div></a>" +
			"</div>" + 
		"</div>"
	lib_window_fixIE( mObj, false );
	
	Drag.init( $("alertBox") );
	window.setTimeout( "lib_alertbox_center()",0)
}

//	centers the alert box
//
function lib_alertbox_center() {
	var elt = $("alertBox");
	var outer_width  = elt.offsetWidth  + 2;
	var outer_height = elt.offsetHeight + lib_caption_height + 2;
	var win_left     = Math.round( Math.max(1, ( lib_window_width()  - (outer_width )) / 2));
	var win_top      = Math.round( Math.max(1, ( lib_window_height() - (outer_height)) / 2));
	elt.style.top=( (isIE ? lib_scrolltop() : 0 ) + win_top).toString()+"px";
	elt.style.left=win_left.toString()+"px";
	elt.style.visibility='visible';
	elt.style.display='block';
	lib_fade(elt, true, 5, 45, 100, "lib_alertbox_add_shadow");
}

//	Voor Internet Explorer : schaduw toevoegen (blur breaks this) !
//
function lib_alertbox_add_shadow() {
	if (isIE) {
		var elt = $("alertBox");		
		elt.style.filter=lib_std_shadow;
	}
}

// 	removes the custom alert from the DOM
//
function lib_alertbox_remove() {
	var a = $("alertBox");
	if (a) document.getElementsByTagName("body")[0].removeChild(a);
	lib_screen_fade(false);
}

//	retrieves the scroll top
//
function lib_scrolltop() {
	if (document.body.scrollTop>0) {
		return document.body.scrollTop;	// most likely IE7
	} else {
		return document.getElementsByTagName("html")[0].scrollTop;
	}
}

//   -			-			-			-			-			WINDOWS

//  Old-school popup
//
function lib_OpenPopupCentered(adres, naam, win_width, win_height, title) {
	var left   = (screen.width  - win_width)/2;
	var top    = (screen.height - win_height)/2;
	var params = 'width='+win_width+', height='+win_height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	newwin=window.open(adres,naam, params);
	if (window.focus) {newwin.focus()}
	return false;	
}

var lib_win_counter = 0;

// 	Open a centered DIV
// 
function lib_OpenWindowCentered(adres, naam, win_width, win_height, title) {
	lib_win_counter++;
	
	if (lib_win_counter==1){
		lib_css_include('DIV.lib_window_container','library/library.css')
		lib_screen_fade(true);
	}
	if (document.body) {
		var outer_width  = win_width  ;
		var outer_height = win_height + lib_caption_height;
		var win_left     = Math.round( Math.max(1, ( lib_window_width()  - (outer_width )) / 2) );
		var win_top      = Math.round( Math.max(1, ( lib_window_height() - (outer_height)) / 2) );
		
		var mObj = document.getElementsByTagName("body")[0].appendChild(document.createElement("div"));
		mObj.id="__lib_win" + lib_win_counter.toString();
		mObj.className="lib_window_container";
		mObj.style.top    = (( isIE ? lib_scrolltop() : 0 ) + win_top).toString()+"px";
		mObj.style.left   = win_left.toString()+"px";
		mObj.style.width  = outer_width+"px";
		mObj.style.height = outer_height + "px";
		mObj.style.zIndex = fader_zindex+1;
		mObj.style.visibility = 'hidden';	// fade will show it gradually
		mObj.style.position = 'fixed';
		mObj.innerHTML = "<div class=lib_window_dialog><div class=lib_window_caption>" + 
			"<a href=javascript:lib_OpenWindowCenteredClose()><div class=lib_window_close></div></a>" + 
			(title ? ("<div class=lib_window_caption_title>" + title + "</div>") : "") + "</div>" + 
			"<iframe id=__lib_win_iframe_" + lib_win_counter.toString() + " style=\"width:"+win_width.toString()+"px;height:"+win_height.toString()+"px\" frameborder=0 src=\'"+adres+"\'></iframe></div>";
			
		lib_window_fixIE( mObj, false );
			
		Drag.init(mObj);
		
		lib_fade(mObj,true,5,45,100,"lib_centered_window_add_shadow");
	}
}

//	Voor Internet Explorer : schaduw toevoegen (blur breaks this) !
//
function lib_centered_window_add_shadow() {
	if (isIE) {
		var elt = $("__lib_win" + lib_win_counter.toString());		
		elt.style.filter=lib_std_shadow;
	}
}


//	Fixes the position:fixed bug in IE
//
function lib_window_fixIE( divObj, bFullHeight ) {
	if (isIE) {
		if (bFullHeight) {
			divObj.style.height = document.body.scrollHeight + "px";
		}
		divObj.style.position = "absolute";	
	}
}

// 	TODO bug: closes the last opened window
//
function lib_OpenWindowCenteredClose() {
	var lw = $("__lib_win" + lib_win_counter.toString());
	
	if (!lw) {
		lw = window.parent.lib_OpenWindowCenteredClose();
	} else {
		if (lw) {
			lw.parentNode.removeChild(lw);
			lib_win_counter--;
			if (lib_win_counter==0) lib_screen_fade(false);
		}
	}
}

// 	Open a centered window showing an image (usage : <a href="groteplaatje.jpg" onclick='lib_image_window_ImageZoom('groteplaatje.jpg');return false">)
// 
function lib_window_ImageZoom( imagepath, sTitle ) {
	var large_image = new Image();	
    large_image.onload = function () {
		lib_OpenWindowCentered ("about:blank", "", large_image.width, large_image.height, (sTitle ? sTitle : large_image.width>200?"Vergroot venster":"Beeld"));		
		var oIframe = document.getElementById("__lib_win_iframe_" + lib_win_counter);
		var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
		if (oDoc.document) oDoc = oDoc.document;
		oDoc.write(	"<HTML><BODY style='margin:0px;background-color:#ffffff'>"+
					"<img src='"+imagepath+"' onclick='javascript:window.parent.lib_OpenWindowCenteredClose()' alt='Sluit venster'>" + 
					"</BODY></HTML>" );
		oDoc.close();
	}
	large_image.onerror = function () {
		alert("error loading '" + imagepath +"'");
	}
	// should be placed below onload for IE
	large_image.src = imagepath;
}

//   -			-			-			-			-			IMAGES

// 	Generic function to switch images, requires names to end with '_on' or '_off' (followed by .gif or .jpg)
//
function img_onoff(id, blnActivate) {
    var img
    if (typeof (id) == 'string') {
        img = $(id);
    } else {
        img = id;
    } if (img) {
		var strNewImg=img.src;
		img.src = strNewImg.substring(0,strNewImg.lastIndexOf('_')+1)+(blnActivate?'on':'off')+img.src.substring(strNewImg.lastIndexOf('.')); 
	}
}

//   -			-			-			-			-			COOKIES

function lib_createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function lib_readCookie(name) {
	var nameEQ = name + "=";
	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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function lib_eraseCookie(name) {
	lib_createCookie(name,"",-1);
}

//   -			-			-			-			-			SCROLLABLE DIV and scroll functions

// to avoid both auto and manual scroll
var LIB_SCROLL_MODE_AUTO   = "AUTO";
var LIB_SCROLL_MODE_MANUAL = "MANUAL";

var lib_scroll_started     = false;
var lib_scroll_mode        = LIB_SCROLL_MODE_AUTO;
var lib_scroll_manual_wrap = true;              // if in MANUAL mode, wrap position?
var lib_scroll_auto_wrap   = true;              // if in AUTO mode, wrap position? -> if false, wrapping is performed ONCE

// change this variable to change speed of scroll inside a step =>higher value = slower scroll
var lib_scroll_steps       = 20.0;                 

//
// 	scrolls until the desired scrolltop position is reached
//
function lib_div_internal_scroller(sDiv, iStep, iSpeed, iScrollTopDesired) {
	var elt = $(sDiv);
	
	if (elt) {
	    lib_scroll_started = true;
	    if (iStep>0) {
	        // move down
	        elt.scrollTop = Math.min(Math.round(elt.scrollTop + iStep, 0), iScrollTopDesired);
            if (elt.scrollTop < iScrollTopDesired) {
               window.setTimeout("lib_div_internal_scroller('" + sDiv + "'," + iStep.toString() + "," + iSpeed.toString() + "," + iScrollTopDesired.toString() + ")", iSpeed)  
            } else {
               lib_scroll_started = false;
            }
	    } else {
	        // move up
	        elt.scrollTop = Math.max(Math.round(elt.scrollTop + iStep, 0), iScrollTopDesired);
            if (elt.scrollTop > iScrollTopDesired) {
               window.setTimeout("lib_div_internal_scroller('" + sDiv + "'," + iStep.toString() + "," + iSpeed.toString() + "," + iScrollTopDesired.toString() + ")", iSpeed)
            } else {
               lib_scroll_started = false;
            }
	    }
    }
}

// if height is not specified, the element's height is assumed
// iHeight defines the step-height
// iSpeed defines the speed (pause) between steps!
function lib_div_autoscroll(sDiv, iHeight, iSpeed, bFromTimer) {
	
	if (lib_scroll_mode == LIB_SCROLL_MODE_AUTO) {
	
	    var elt = $(sDiv);
	    var scrollHeight = 0.0;
	    if (elt && lib_scroll_started==false) {
            if (iHeight==0) iHeight = elt.clientHeight;
            // first event is installing, don't do anything!
	        if (bFromTimer) { 
	            // moving down
	            if (iHeight>0) {
					if (elt.scrollTop + iHeight == elt.scrollHeight) {
						if (lib_scroll_auto_wrap) elt.scrollTop = 0;
					}
					if (elt.scrollTop + iHeight < elt.scrollHeight) {
						scrollHeight = iHeight/lib_scroll_steps;
						lib_div_internal_scroller(sDiv, scrollHeight, 20, elt.scrollTop + iHeight);
					}
     		    } else {
	                // moving up
	                if (elt.scrollTop>0) {
		                scrollHeight = iHeight/lib_scroll_steps;
 		                lib_div_internal_scroller(sDiv, scrollHeight, 20, Math.max(elt.scrollTop + iHeight, 0));
         	        } else {
                  		if (lib_scroll_auto_wrap) elt.scrollTop = elt.scrollHeight + iHeight;
 		            }
    		    }
    		}
	    }
	    window.setTimeout("lib_div_autoscroll('" + sDiv + "'," + iHeight.toString() + "," + iSpeed.toString() + ",true)", iSpeed);
	}
}


// 	in reactie op een scrollknop
//
function lib_div_manualscroll(sDiv, iHeight) {
	var elt = $(sDiv);
	var scrollHeight = 0.0;

	lib_scroll_mode = LIB_SCROLL_MODE_MANUAL;
	if (elt && lib_scroll_started==false) {
        // moving down
        if (iHeight>0) {
			if (elt.scrollTop + iHeight == elt.scrollHeight) {
	            if (lib_scroll_manual_wrap) elt.scrollTop=0;
			}
	        if (elt.scrollTop + iHeight < elt.scrollHeight) {
	            scrollHeight = iHeight/lib_scroll_steps;
	            lib_div_internal_scroller(sDiv, scrollHeight, 20, elt.scrollTop + iHeight)
	    	}
	    } else {
	        // moving up
        	if (elt.scrollTop>0) {
            	scrollHeight = iHeight/lib_scroll_steps;
            	lib_div_internal_scroller(sDiv, scrollHeight, 20, Math.max(elt.scrollTop + iHeight, 0));
        	} else {
        	    if (lib_scroll_manual_wrap) elt.scrollTop = elt.scrollHeight + iHeight;
	    	}
	    }
	}
}

//	
//	initialisatie lib_div_scroller ()
//
function lib_div_scroller(sContainerDiv, sItemDivClassName, iHeight, iScrollPause) {	
	// append first item to the end, to have a smooth scroll between the last and the first item
	if (cnt = $(sContainerDiv)) {
		var a = lib_DOM_getElementsByClass(sItemDivClassName,cnt);
		if (a) 
			cnt.appendChild(a[0].cloneNode(true));
	}
	lib_div_autoscroll(sContainerDiv, iHeight, iScrollPause, false);
}

//
// 	als div hoger dan de aangegeven maximale hoogte, maak de div scrollable 
//
function lib_div_makescrollable(divname, maxheight) {
	var d = $(divname);
	if (d){
		var d_s = d.style;
		if (d.offsetHeight>maxheight) {
			// create a new item inside the parent to create room
			if (document.createElement) {
				var spacer=document.createElement("<DIV id="+divname+"_spacer style=height:"+maxheight.toString()+"px></DIV>");
				d.parentElement.insertBefore(spacer);
				d_s.posHeight = maxheight;
				d_s.position  = "absolute";
				d_s.overflow  = "scroll";
				d_s.overflowX = "hidden";
			}
		}
	}
}

//   -			-			-			-			-			SCREEN METRICS

// returns the VISIBLE part of the window
//
function lib_window_height () {
	return isIE ? document.getElementsByTagName("html")[0].offsetHeight : window.innerHeight;
}

// returns the VISIBLE part of the window
//
function lib_window_width () {
	return isIE ? document.getElementsByTagName("html")[0].offsetWidth : window.innerWidth;
}

// returns the TOTAL height of the page
//
function lib_screen_height () {
	return isIE ? document.body.clientHeight : window.innerHeight;
}

// returns the TOTAL width of the page
//
function lib_screen_width () {
	return isIE ? document.body.clientWidth : window.innerWidth;
}

function lib_top_screen_height () {
	return isIE ? top.window.document.body.clientWidth : top.window.innerHeight;
}

//   -			-			-			-			-			SCREEN FADER

function lib_screen_fade( bOn ) {
    var fader_name = '__lib_fader';
    var fader = $(fader_name);

    lib_css_include('DIV.dialog_fader','library.css');
    if (!fader) {
        // create fader object
        fader = document.createElement('div');
        fader.setAttribute('id', fader_name);
        fader.className="dialog_fader";
        fader.style.zIndex=fader_zindex;
        lib_window_fixIE( fader, true );
        if (isIE) fader.style.position="";
        document.body.appendChild( fader );
    }
    fader.style.posHeight = (lib_window_height()).toString();
    fader.style.display = bOn ? 'block' : 'none';
}

//   -			-			-			-			-			LAYERS

function layer_style(bVisible, bAbsolute) {
	var sRetval 
	
	if (isIE || isNS6)
	   sRetval = 'display:' + (bVisible ?  'block' : 'none') + ";";  
	else 
	   sRetval = 'visibility:' + (bVisible ?  'visible' : 'hidden') + ";";
	sRetval += 'position:' + (bAbsolute ? 'absolute' : 'relative') + ";";
	return sRetval;
}


function layer_write_full(sName, bVisible, bAbsolute, sContent){
	if (blnOpenCloseDocument) document.open();
	document.write ("<DIV ID=\"" + sName + "\" style=\""+layer_style(bVisible, bAbsolute)+"\">"+sContent+"</DIV>");
	if (blnOpenCloseDocument) document.close();
}

function layer_set_visible(sName, bVisible) {
	var x = layer_get_style(sName);
	if (x) {
		if (isIE || isNS6)
			x.display = (bVisible ?  "block" : "none");
		else
			x.visibility = (bVisible) ? 'visible' : 'hidden';
	} 
}


function layer_toggle_class(sName, sClass, sClass2) {
	var x=layer_get(sName);
	if (x) x.className = (x.className.toLowerCase()==sClass.toLowerCase() ? sClass2 : sClass);
}

function layer_get(sName) {
	if ($) {
		return $(sName);
	} else if (document.all) {
		return document.all[sName];
	} else if (document.layers) {
		return document.layers[sName];
	} else return false;
}

// Documented not to work under Opera (not supported)
//
function layer_set_content(sName, sContent) {
	var x = layer_get(sName)
	
	if (document.layers) {
		with (x.document) {
			open();
			write("<P>"+sContent+"</P>");
			close();
		}
	} else 	x.innerHTML = sContent;
}

//
// NS4 not supported
//
function layer_set_color(sName, sColor) {
	var x=layer_get_style(sName);
	if (x) x.color = sColor;
}

//
// NS4 not supported
//
function layer_set_backcolor(sName, sColor) {
	var x=layer_get_style(sName);
	if (x) x.backgroundColor = sColor;
}

function layer_get_style(sName) {
	if ($) {
		var x = $(sName)
		if (x) return x.style;
	} else if (document.all) {
		var x = document.all[sName]
		if (x) return x.style;
	} else if (document.layers) {
		return document.layers[sName];
	} 
}

function lib_getAbsoluteOffsetTop(obj) {
    var top = obj.offsetTop;
    var parent = obj.offsetParent;
    while (parent != document.body) {
     	top += (parent.offsetTop - parent.scrollTop);
     	parent = parent.offsetParent;
    }
    return top;
}

function lib_getAbsoluteOffsetLeft(obj) {
    var left = obj.offsetLeft;
    var parent = obj.offsetParent;
    while (parent != document.body) {
     	left += (parent.offsetLeft - parent.scrollLeft);
     	parent = parent.offsetParent;
    }
    return left;
}

//   -			-			-			-			-			STRING FUNCTIONS

function lib_dropLeadingZeros(num)
{
	while (num.charAt(0) == "0") {
		newTerm = num.substring(1, num.length);
		num = newTerm;
	}
        
	if (num == "") num = "0";
	return num;
}

function lib_left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function lib_right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function lib_htmlencode(text)
{
    return text.replace(/&/g, '&amp').replace(/'/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

//   -			-			-			-			-			Custom control stuff 
// 
// for overlapping controls (comboboxes/objects) use an iframe to cover them (iframe shim) , only needed for IE6 and below
// idea taken from http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx 
// tip: from this point make sure the actual DIV measurements are known
function control_createshim(control_divname) {

	if (isIE) {
		if (lib_IEVersion()<=6) {
		    var ifr = $(control_divname + '__iframe');
			if (!ifr) {
		 	    var ifr = document.createElement('iframe');
			    if (typeof(ifr.innerHTML) != 'string') { return; }
			    ifr.id = control_divname + '__iframe';
			    ifr.style.position = 'absolute';
			    ifr.style.display = 'block';
			    ifr.src = "javascript:false;";
		        document.body.appendChild(ifr);
		    }

		    var ctrlDiv = $(control_divname);
			ifr.style.top = ctrlDiv.style.top;
		    ifr.style.left = ctrlDiv.style.left;
		    ifr.style.width = ctrlDiv.offsetWidth;
		    ifr.style.height = ctrlDiv.offsetHeight;
		    ifr.style.zIndex = ctrlDiv.style.zIndex - 1;
		    ifr.style.display = "block";
		}
	}
}

function control_deleteshim(control_divname) {
    var ifr = $(control_divname+'__iframe');
    if (ifr) document.body.removeChild(ifr);
}

//  	hack for Flash IE activate problem
//
function lib_activeX_activate() {
    var theObjects = document.getElementsByTagName("object"); 
    for (var i = 0; i < theObjects.length; i++) { 
        theObjects[i].outerHTML = theObjects[i].outerHTML; 
    }
}

// 	 Retrieves an array of DOM elements by Classname
//
function lib_DOM_getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if (node == null) node = document;
	if (tag == null) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// 	 Alternates row colors in a table (through TR classes)
//
function lib_table_alternate(className, TRClass1, TRClass2) { 
    if (className==null) className = "alternate";
    if (TRClass1==null) TRClass1 = "td1"
    if (TRClass2==null) TRClass2 = "td0"
    var tables = lib_DOM_getElementsByClass(className,document,"table");   
    for (var t=0; t<tables.length; t++) {
       var rows = tables[t].getElementsByTagName("tr");   
       for (var i = 0; i < rows.length; i++) rows[i].className = (i % 2 == 0) ? TRClass1 : TRClass2; 
    }
}

//	Searches a single dimension array for a value, returns -1 if not found, otherwise the index within the array
// 
function lib_array_find(arr, search_value) {
	var fld_num = 0;
	while (fld_num < arr.length) {
	  if (arr[fld_num].toLowerCase()==search_value.toLowerCase()) {
		 return fld_num;
	  }
	  fld_num+=1;
	}
	return -1;
}

//	Splits an string of values into an array
//
function lib_array_split(stringvalue) {
	if (stringvalue) {
		if (stringvalue.indexOf(';')!=-1) {
			return stringvalue.split(";");
		} else {
			return stringvalue.split(",");
		}
	}
}

function lib_IEVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}


// 	Drag object from www.youngpup.net
//
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top  ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};


///////////////////////////////////////////////////////////////////////
//     This fade library was designed by Erik Arvidsson for WebFX    //
//                                                                   //
//     For more info and examples see: http://webfx.eae.net          //
//     or contact Erik at http://webfx.eae.net/contact.html#erik     //
//                                                                   //
//     Feel free to use this code as lomg as this disclaimer is      //
//     intact.                                                       //
///////////////////////////////////////////////////////////////////////


var __fadeArray = new Array();    // Needed to keep track of wich elements are animating

//////////////////  fade  ////////////////////////////////////////////////////////////
//                                                                                  //
//   parameter: fadeIn                                                              //
// description: A boolean value. If true the element fades in, otherwise fades out  //
//              The steps and msec are optional. If not provided the default        //
//              values are used. Opacity is optional and specifies the start/end    //
//              opacity values. onfinish is used when the fadein/out has finished   // 
//              and is called (so pass in a function name)                          //
//////////////////////////////////////////////////////////////////////////////////////

function lib_fade ( el, fadeIn, steps, msec, opacity, onfinish) {
    if (steps    == null)  steps   = 4;
    if (msec     == null)  msec    = 25;
    if (opacity  == null)  opacity = 100;
    if (onfinish == null)  onfinish = '';

    if (el.fadeIndex == null) {
        el.fadeIndex = __fadeArray.length;
    }

    __fadeArray[el.fadeIndex] = el;

    if (el.style.visibility == "hidden") {
        el.style.display  = 'block';
        el.fadeStepNumber = 0;
    } else {
        el.fadeStepNumber = steps;
    }

    if (fadeIn) {
		lib_set_opacity( el, 0);
    } else {
		lib_set_opacity( el, opacity);
    }

    window.setTimeout("RepeatFade(" + fadeIn + "," + el.fadeIndex + "," + steps + "," + msec + ", " + opacity + ", '" + onfinish + "')", msec);
}

// Zet de opacity aan (behoudt de eventuele andere filters!
//
function lib_set_opacity( elt, opacity_percentage ) {
	var use_filter = elt.filters;
	
	if (use_filter) {
		if ( elt.style.filter.search(".Alpha")>-1 ) {
			elt.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity_percentage;
		} else {
			elt.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + opacity_percentage.toString() + ")";
		}
	}
	elt.style.MozOpacity = opacity_percentage / 100;
	elt.style.opacity = opacity_percentage / 100;
}

//////////////////////////////////////////////////////////////////////////////////////
//  Used to iterate the fading                                                      //
//////////////////////////////////////////////////////////////////////////////////////
function RepeatFade(fadeIn, index, steps, msec, opacity, onfinish)
{
    var el = __fadeArray[index];
    var c = el.fadeStepNumber;
    if (el.fadeTimer != null) {
        window.clearTimeout(el.fadeTimer);
    }

    if (c == 0 && !fadeIn) {            // Done fading out!
        el.style.visibility = "hidden"; // If the platform doesn't support filter it will hide anyway
        el.style.display    = "none"; // If the platform doesn't support filter it will hide anyway

        if (onfinish) {
            eval(onfinish + "()");
        }
        return;

    } else if (c == steps && fadeIn) {    // Done fading in!
		lib_set_opacity( el, opacity);
        el.style.visibility = "visible";

        if (onfinish) {
            eval(onfinish + "()");
        }
        return;

    } else {
        fadeIn ? c++ : c--;
        el.style.visibility = "visible";
		lib_set_opacity( el, opacity*c/steps);

        el.fadeStepNumber = c;
        el.fadeTimer = window.setTimeout("RepeatFade(" + fadeIn + "," + index + "," + steps + "," + msec + ", " + opacity + ", '" + onfinish + "' )", msec);
    }
}

//   -			-			-			-			-			Macromedia stuff, modified 
//
// to highlight menu-items
function changeto(e,highlightcolor){
  source=isIE ? event.srcElement : e.target
  if (source.tagName=="TR"||source.tagName=="TABLE")return
  while(source.tagName!="TD"&&source.tagName!="HTML")
  source=isNS6? source.parentNode : source.parentElement
  if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
  source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
  while (slave.parentNode)
  if ((slave = slave.parentNode) == master)
  return true;
  return false;
}

function changeback(e,originalcolor){
  if (isNS6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore")) return;
  source.style.backgroundColor=originalcolor
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
