//   -			-			-			-			-			BROWSERDETECTION & MISC

var isOpera   = ( navigator.appName.indexOf("Opera")>-1  || (!window.showHelp && navigator.appName=="Microsoft Internet Explorer"));
var isNS4     = (!isOpera && document.layers) ? true : false;
var isIE      = (!isOpera && document.all   ) ? true : false;
var isIE4	  = (!isOpera && document.all && !document.getElementById ) ? true : false;
var isNS6     = (!isOpera && !isIE&&document.getElementById) ? 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

//   -			-			-			-			-			EVENTS

// 	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
// nieuw 20 juni 2007: "-" nu ook toegestaan (189)
function lib_form_digitsonly () {
	// 2 ranges: for normal keyboard and keypad..
	return ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode==190 || event.keyCode==9 || event.keyCode==8 || event.keyCode==46 || event.keyCode==37  || event.keyCode==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);
}

// 	use this in a keydown of a control to surpress spaces
//
function lib_form_nospaces () {
	return (event.keyCode != 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)
//	TODO: Multiple selection listboxes borchureaanvragen RINO : Divers doet het niet!
//
function lib_form_save_content( frm, sExclude ) {
	var n = frm.length;
	var string;
	var flds_arr;

	if (frm) {
		if (sExclude) flds_arr = sExclude.split(";");
		for (i = 0; i < n; i++) {
			try {
				e = frm[i].name;
				if (e) {
					var e_clean=e;
					if (e_clean.substring(0,9).toLowerCase()=='required-')
						e_clean = e_clean.substring(9);

					var blnStoreField = true;
					if (flds_arr) blnStoreField = !frm[i].disabled && ( lib_array_find(flds_arr, e_clean) == -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};
							}			
							// skip all other instances of this radiobutton
							if (i+1<frm.length) 
								while (frm[i].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) i++;
							// ga terug naar de laatste radiobox
							while (frm[i].name.toLowerCase()!=e.toLowerCase()) i--;

							// alert("RADIO " + e + " SAVING \r\n" + string);
						}
						if ((fieldType == "text") || (fieldType == "textarea") ) {
							string = frm.elements[e].value;
						}
						if (fieldType == "select-one") {
							string = frm[i].options[frm[i].selectedIndex].text;
//							alert("Saving " + string + " to field " + e);
						}
						if (fieldType == "checkbox") {
							// store all other values of this checkbox in the same cookie
							if (i+1<frm.length) {
								while (frm[i].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) {
									string = string + (frm[i].checked==true ? ( (string=="" ? "" : ",") + frm[i].value ) : "");	
									i++;
								}
								// ga terug naar de laatste checkbox
								while (frm[i].name.toLowerCase()!=e.toLowerCase()) i--;
							} else {
								string = frm[i].checked==true ? fieldValue : "";
							}
//							alert("CHECKBOX " + e + " SAVING \r\n" + string);
						}

						// 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);
//							alert("Storing value " + string + " for field " + e);					
						}
					}
				}
			}
	        catch(err) {}		
		}
	}
}


//	TODO: Multiple selection listboxes
//	 speciffy sExclude without the required prefix!
//
function lib_form_load_content( frm, sExclude ) {
	var n = frm.length;
	var flds_arr;
	
	if (frm) {
		if (sExclude) flds_arr = sExclude.split(";");	
		for (i = 0; i < n; i++) {
			try {
				e = frm[i].name;
				if (e) {
					var e_clean = e;
					if (e_clean.substring(0,9).toLowerCase()=='required-') 
						e_clean = e_clean.substring(9);
						
					var blnRestoreField = true;
					if (flds_arr) blnRestoreField = !frm[i].disabled && ( lib_array_find(flds_arr, e_clean) == -1 );
					
					if (blnRestoreField) {
						var fieldValue = lib_readCookie( lib_form_saving_prefix + e_clean.toLowerCase() );
						if (fieldValue!=null) {

							var fieldType  = frm[i].type.toLowerCase();
//							alert("restoring :" + fieldValue + " in type of field " + fieldType);

							if ((fieldType == "text") || (fieldType == "textarea")) {
//								alert(fieldType.toUpperCase() + " " + e + " RESTORING \r\n " + fieldValue);
								frm[i].value = fieldValue;
							}
							if (fieldType == "select-one") {
								lib_form_group_select( frm, e, fieldValue);
//								alert("Setting field " + e + " to value " + fieldValue);
							}
							if (fieldType == "checkbox") {
//								alert("CHECKBOX " + e + " RESTORING \r\n " + fieldValue);
								lib_form_setCheckbox(frm, e, fieldValue);
								// skip other instances ot the checkbox
								if (i+1<frm.length) 
									while (frm[i+1].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) i++;
							}
							if (fieldType == "radio") {
//								alert("RADIO " + e + " RESTORING \r\n " + fieldValue);
								lib_form_setRadio(frm, e, fieldValue)
								// skip other instances ot the radiobutton
								if (i+1<frm.length) 
									while (frm[i+1].name.toLowerCase()==e.toLowerCase() && i+1<frm.length) i++;
							}
//						} else {
	//					  alert("NULL value for field :" + e);
						}
//					} else {
//						alert("Skipping field :" + e);
					}
				}
			}
	        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=''
	}
}

// 	Sets the value of a radio button
//
function lib_form_setRadio(oFrm, radio_name, new_value) {
	try {	
//		alert("Setting radio " + rad_name + " to " + new_value);
		for (var x=0; x < oFrm.elements[radio_name].length; x++) {
			oFrm.elements[radio_name][x].checked = (oFrm.elements[radio_name][x].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) {
//			alert("Setting checkbox " + checkbox_name + " to " + 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 = document.getElementById( sName );
	// for mozilla: the field may be in a form, try to get the handle there
	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){
	var fld = oFrm.elements[sField];
	for (t=0;t<fld.options.length;t++) {
		if ( fld.options[t].text.toLowerCase() == sSelectedValue.toLowerCase() ) {
//			alert( "setting "+sField+" to " + t.toString());
			fld.selectedIndex=t;
		}
	}
} 


//   -			-			-			-			-			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..");
	}
}

//   -			-			-			-			-			WINDOWS

//
// 	Open a centered window, save the opener and set the focus
// 
function lib_OpenWindowCentered( adres, naam, win_width, win_height, optional_full_win) {
	var sParam = "resizable=no, toolbar=no, menubar=no" 
	if (isIE) {
		var win_left   = Math.max(1,(screen.width  - win_width )/2);
		var win_top    = Math.max(1,(screen.height - win_height)/2);
	} else {
		var win_left   = Math.max(1,(lib_screen_width()  - win_width )/2);
		var win_top    = Math.max(1,(lib_screen_height() - win_height)/2);
	}
	if (optional_full_win != null) {
		if (optional_full_win=true) {
			sParam = "resizable=yes, toolbar=yes, menubar=yes, scrollbars=yes "
		} 
	}
	var w=window.open(adres, naam, sParam + ", status=no, center=yes, width="+win_width.toString()+", height=" + win_height.toString()+", top=" + win_top.toString()+", left=" + win_left.toString());
	if (w) {
		w.opener = window;
		if (w.focus) w.focus();
	} else {
		// TODO IE only: perhaps a popup blocker is preventing opening a new window, try using an iframe (note: this requires other code for closing the window!)
		if (document.body) {
			win_left   = Math.max(1,(document.body.clientWidth  - win_width )/2);
			win_top    = Math.max(1,(document.body.clientHeight - win_height)/2);
			document.body.innerHTML = document.body.innerHTML + "<iframe style=\"z-index:9999;position:absolute;top:"+win_top.toString()+"px;left:"+win_left.toString()+"px;width:"+win_width.toString()+"px;height:"+win_height.toString()+"px;border:1px solid black;filter:progid:DXImageTransform.Microsoft.Shadow(color='#333333',Direction=135,Strength=5)\" src=\'"+adres+"\'></iframe>";
		}
	}
	return w
}

//
// Open a centered window showing an image
//
// TODO use for images as well!
// 
function lib_OpenWindowCenteredClose() {
	if (top.location==window.location) {
		// normal popup window
		window.close();
	} else {
		// iframe popup simulation, resize to nothing!
		window.resizeTo(0,0);
	}
}

//
// Open a centered window showing an image
// 
// TODO use OpenWindow and Close method here!
// 
function lib_window_ImageZoom( imagepath, optional_height, optional_width, optional_full_win ) {
	var sParam = "resizable=no, toolbar=no, menubar=no," 
	var win_width  = 800;
	var win_height = 600;

	if (optional_height != null && optional_height != 0) win_height = optional_height;
	if (optional_width  != null && optional_width  != 0) win_width  = optional_width;

	if (isIE) {
		var win_left   = Math.max(1,(screen.width  - win_width )/2);
		var win_top    = Math.max(1,(screen.height - win_height)/2);
	} else {
		win_height += 24;
		var win_left   = Math.max(1,(lib_screen_width()  - win_width )/2);
		var win_top    = Math.max(1,(lib_screen_height() - win_height)/2);
	}
	if (optional_full_win != null) {
		if (optional_full_win=true) sParam = "resizable=yes, toolbar=yes, menubar=yes, scrollbars=yes "
	}

	// TODO mozilla heeft scrollbars!
	strContent =  
	"<script language='javascript'>"+
	"function fitPic() {"+
	"if (window.innerWidth){"+
	"  iWidth=window.innerWidth;"+
	"  iHeight=window.innerHeight-24;"+
	"}else{"+
	"  iWidth=document.body.clientWidth;"+
	"  iHeight=document.body.clientHeight;"+
	"}"+
	"iWidth = document.images[0].width - iWidth;"+
	"iHeight = document.images[0].height - iHeight;"+
	"window.resizeBy(iWidth, iHeight);"+
	"};</script><BODY bgColor=#ffffff style=margin:0px marginheight=0 marginwidth=0 onload=fitPic()><TITLE>" + imagepath + "</TITLE><table cellpadding=0 cellspacing=0 height=100% width=100% ><tr><td align=center><A href=javascript:window.close() title=Sluit><img src='" + imagepath + "' border=0></A></td></tr></table>";

	var w = window.open("", 'zoom', sParam + ", status=no, center=yes, width="+win_width.toString()+", height="+win_height.toString()+", top=" + win_top.toString()+", left=" + win_left.toString());
	while(w.document == null){x++}; 
	with (w.document) {
		open();
		write( strContent );
		close();
	}
	if (w.focus) w.focus(); 
}

//   -			-			-			-			-			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=document.getElementById(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 = "";
	var ck = name+"="+value.replace(";",lib_cookie_repl_sep)+expires+"; path=/";
	document.cookie = ck;
}

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).replace(lib_cookie_repl_sep,";");
	}
	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
var lib_scroll_steps       = 20.0;                 

// 	scrolls until the desired scrolltop position is reached
//
function lib_div_scroller( sDiv, iStep, iSpeed, iScrollTopDesired ) {
	var elt = document.getElementById( 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_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_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 = document.getElementById( 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) {
    		            scrollHeight = iHeight/lib_scroll_steps;
                        lib_div_scroller( sDiv, scrollHeight, 20, elt.scrollTop + iHeight);
     		        } else {
     		            // omklap naar het begin!
     		            if (lib_scroll_auto_wrap) elt.scrollTop = 0;
     		        }
     		    } else {
	                // moving up
	                if (elt.scrollTop>0) {
		                scrollHeight = iHeight/lib_scroll_steps;
 		                lib_div_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 = document.getElementById( 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) {
	            scrollHeight = iHeight/lib_scroll_steps;
	            lib_div_scroller( sDiv, scrollHeight, 20, elt.scrollTop + iHeight)
	        } else {
	            if (lib_scroll_manual_wrap) elt.scrollTop=0;
	    	}
	    } else {
	        // moving up
        	if (elt.scrollTop>0) {
            	scrollHeight = iHeight/lib_scroll_steps;
            	lib_div_scroller( sDiv, scrollHeight, 20, Math.max(elt.scrollTop + iHeight, 0));
        	} else {
        	    if (lib_scroll_manual_wrap) elt.scrollTop = elt.scrollHeight + iHeight;
	    	}
	    }
	}
}

// 	als div hoger dan de aangegeven maximale hoogte, maak de div scrollable 
//
function lib_div_makescrollable( divname, maxheight ) {
	var d = document.getElementById(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

function lib_screen_height ( ) {
	if (isIE) {
		return document.body.offsetHeight;
	} else {
		return window.innerHeight;
	}
}

function lib_screen_width ( ) {
	if (isIE) {
		return document.body.offsetWidth;
	} else {
		return window.innerWidth;
	}
}

function lib_top_screen_height ( ) {
	if (isIE) {
		return top.window.document.body.offsetHeight;
	} else {
		return top.window.innerHeight;
	}
}


// can also be used for layers, fields etc...
function lib_getObj(id) {
	return layer_get(id);
}


//   -			-			-			-			-			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') + ";";
	sRetval +=  (bAbsolute ? 'position:absolute;' : '');
	if (isNS4&&!bAbsolute) sRetval += 'left:0px;top:0px;';
	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_get(sName) {
	if (document.getElementById) {
		return document.getElementById(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 (document.getElementById) {
		var x = document.getElementById(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)
// 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 ) {
    var ifr = document.getElementById( 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 = document.getElementById( 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 = document.getElementById( 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.indexOf(';')!=-1) {
		return stringvalue.split(";");
	} else {
		return stringvalue.split(",");
	}
}

//   -			-			-			-			-			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; }
}