//----------------------------------------------------------------------------------------------------------------------------------------
// framework/javascript/common.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

var el = function (id) { return document.getElementById(id); }

//----------------------------------------------------------------------------------------------------------------------------------------

sprintfWrapper = {

	init : function () {

		if (typeof arguments == 'undefined') { return null; }
		if (arguments.length < 1) { return null; }
		if (typeof arguments[0] != 'string') { return null; }
		if (typeof RegExp == 'undefined') { return null; }

		var string = arguments[0];
		var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
		var matches = new Array();
		var strings = new Array();
		var convCount = 0;
		var stringPosStart = 0;
		var stringPosEnd = 0;
		var matchPosEnd = 0;
		var newString = '';
		var match = null;

		while (match = exp.exec(string)) {
			if (match[9]) { convCount += 1; }

			stringPosStart = matchPosEnd;
			stringPosEnd = exp.lastIndex - match[0].length;
			strings[strings.length] = string.substring(stringPosStart, stringPosEnd);

			matchPosEnd = exp.lastIndex;
			matches[matches.length] = {
				match: match[0],
				left: match[3] ? true : false,
				sign: match[4] || '',
				pad: match[5] || ' ',
				min: match[6] || 0,
				precision: match[8],
				code: match[9] || '%',
				negative: parseInt(arguments[convCount]) < 0 ? true : false,
				argument: String(arguments[convCount])
			};
		}
		strings[strings.length] = string.substring(matchPosEnd);

		if (matches.length == 0) { return string; }
		if ((arguments.length - 1) < convCount) { return null; }

		var code = null;
		var match = null;
		var i = null;

		for (i=0; i<matches.length; i++) {

			if (matches[i].code == '%') { substitution = '%' }
			else if (matches[i].code == 'b') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'c') {
				matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'd') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'f') {
				matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'o') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 's') {
				matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'x') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'X') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
				substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
			}
			else {
				substitution = matches[i].match;
			}

			newString += strings[i];
			newString += substitution;

		}
		newString += strings[i];

		return newString;

	},

	convert : function(match, nosign){
		if (nosign) {
			match.sign = '';
		} else {
			match.sign = match.negative ? '-' : match.sign;
		}
		var l = match.min - match.argument.length + 1 - match.sign.length;
		var pad = new Array(l < 0 ? 0 : l).join(match.pad);
		if (!match.left) {
			if (match.pad == '0' || nosign) {
				return match.sign + pad + match.argument;
			} else {
				return pad + match.sign + match.argument;
			}
		} else {
			if (match.pad == '0' || nosign) {
				return match.sign + match.argument + pad.replace(/0/g, ' ');
			} else {
				return match.sign + match.argument + pad;
			}
		}
	}
}

sprintf = sprintfWrapper.init;

// ----------------------------------------------------------------------------------------------------------------------------------------

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };

    return sa ? s : s[0];
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function trim (str, charlist) {
    var whitespace, l = 0, i = 0;
    str += '';

    if (!charlist) {
        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }

    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }

    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }

    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function ltrim ( str, charlist ) {
    charlist = !charlist ? ' \s\xA0' : (charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    var re = new RegExp('^[' + charlist + ']+', 'g');
    return (str+'').replace(re, '');
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function rtrim ( str, charlist ) {
    charlist = !charlist ? ' \s\xA0' : (charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    var re = new RegExp('[' + charlist + ']+$', 'g');
    return (str+'').replace(re, '');
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function strpos( haystack, needle, offset){
    var i = (haystack+'').indexOf( needle, offset );
    return i===-1 ? false : i;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function substr( f_string, f_start, f_length ) {
    f_string += '';

    if(f_start < 0) {
        f_start += f_string.length;
    }

    if(f_length == undefined) {
        f_length = f_string.length;
    } else if(f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }

    if(f_length < f_start) {
        f_length = f_start;
    }

    return f_string.substring(f_start, f_length);
}

//----------------------------------------------------------------------------------------------------------------------------------------

function mktime() {
    var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;

    if (argc > 0){
        d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
    }
 
    var dateManip = {
        0: function(tt){ return d.setHours(tt); },
        1: function(tt){ return d.setMinutes(tt); },
        2: function(tt){ var set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
        3: function(tt){ var set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
        4: function(tt){ return d.setDate(tt+mb); },
        5: function(tt){ return d.setYear(tt+ma); }
    };
    
    for( i = 0; i < argc; i++ ){
        no = parseInt(argv[i]*1);
        if (isNaN(no)) {
            return false;
        } else {
            // arg is number, let's manipulate date object
            if(!dateManip[i](no)){
                // failed
                return false;
            }
        }
    }

    return Math.floor(d.getTime()/1000);
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/string.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function strPad(val) { return (!isNaN(val) && val.toString().length==1)?"0"+val:val; }

//----------------------------------------------------------------------------------------------------------------------------------------

function stripCharacter(words,character) {
	//documentation for this script at http://www.shawnolson.net/a/499/
	var spaces = words.length;

	for(var x = 1; x<spaces; ++x) { words = words.replace(character, ""); }
	return words;
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/html.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function changeObjCSS(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	var cssRules;
	if (document.all) { cssRules = 'rules'; }
	else if (el) { cssRules = 'cssRules'; }
	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function changeObjImageSize(objectId,newWidth,newHeight) {
	imgString = 'theImg = el("'+objectId+'")';

	eval(imgString);

	oldWidth = theImg.width;
	oldHeight = theImg.height;

	if(newWidth>0) { theImg.width = newWidth; }
	if(newHeight>0){ theImg.height = newHeight; }
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function changeObjColor(theObj,newColor){
	eval('var theObject = el("'+theObj+'")');

	if (theObject.style.backgroundColor==null) { theBG='white'; }
	else { theBG=theObject.style.backgroundColor; }

	if (theObject.style.color==null) { theColor='black'; }
	else { theColor=theObject.style.color; }

	//alert(theObject.style.color+' '+theObject.style.backgroundColor);
	switch(theColor){
		case newColor:
			switch(theBG){
				case 'white':
					theObject.style.color = 'black';
					break;

				case 'black':
					theObject.style.color = 'white';
					break;

				default:
					theObject.style.color = 'black';
					break;
	  		}

	  		break;

	  	default:
			theObject.style.color = newColor;
			break;
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/html.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function sortListObj(obj) {
	var lb=obj;
	arrTexts = new Array();

	for(i=0; i<lb.length; i++) { arrTexts[i] = lb.options[i].text; }

	arrTexts.sort();

	for(i=0; i<lb.length; i++)  {
  		lb.options[i].text = arrTexts[i];
  		lb.options[i].value = arrTexts[i];
	}

	lb.selectedIndex=0;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function sortList(element) {
	var obj=el(element);
	sortListObj(obj);
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function setOptionSelected(obj,value) {
	for(idx=0; idx<obj.options.length; idx++ ) {
		if ( obj.options[idx].value==value ) {
			obj.selectedIndex=idx;
			break;
		}
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function selectAll(CONTROL,value){
	for (var i = 0;i < CONTROL.length;i++) { CONTROL.options[i].selected = value; }
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function selectAllLBOptions(CONTROL) {
	selectAll(el(CONTROL),true);
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function removeAllOptions(obj) {
	var i;
	for (i=obj.length-1;i>=0;i--) { obj.remove(i); }
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function addOption(obj,text,value) {
	var objNew=document.createElement('option');
	objNew.text=text;
	objNew.value=value;

	try { obj.add(objNew,null); }
	catch(ex) { obj.add(objNew); }
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function compareOptionValues(a, b) {
	// Radix 10: for numeric values
	// Radix 36: for alphanumeric values

	var sA = parseInt( a.value, 36 );
	var sB = parseInt( b.value, 36 );

	return sA - sB;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function compareOptionText(a, b) {
	// Radix 10: for numeric values
	// Radix 36: for alphanumeric values

	var sA = parseInt( a.text, 36 );
	var sB = parseInt( b.text, 36 );

	return sA - sB;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function moveDualList( srcList, destList, moveAll ) {
	// Do nothing if nothing is selected
	if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )) { return; }

	newDestList = new Array( destList.options.length );

	var len = 0;

	for( len = 0; len < destList.options.length; len++ ) {
		if ( destList.options[ len ] != null ) {
		  newDestList[ len ] = new Option(
			destList.options[ len ].text,
			destList.options[ len ].value,
			destList.options[ len ].defaultSelected,
			destList.options[ len ].selected );
		}
	}

	for( var i = 0; i < srcList.options.length; i++ ) {
		if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ) {
			// Statements to perform if option is selected
			// Incorporate into new list
			newDestList[ len ] = new Option(
				srcList.options[i].text,
				srcList.options[i].value,
				srcList.options[i].defaultSelected,
				srcList.options[i].selected );
			len++;
			}
	}

	// Sort out the new destination list
	newDestList.sort( compareOptionValues );   // BY VALUES
	// newDestList.sort( compareOptionText );   // BY TEXT

	// Populate the destination with the items from the new array
	for ( var j = 0; j < newDestList.length; j++ ) {
		if ( newDestList[ j ] != null ) { destList.options[ j ] = newDestList[ j ]; }
	}

	// Erase source list selected elements
	for( var i = srcList.options.length - 1; i >= 0; i-- ) {
		if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ) {
		   // Erase Source
		   //srcList.options[i].value = "";
		   //srcList.options[i].text  = "";
		   srcList.options[i]       = null;
		}
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function deleteOption(theSel, theIndex) {
	var selLength = theSel.length;
	if(selLength>0) { theSel.options[theIndex] = null; }
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function copyOptions(theSelFrom, theSelTo) {
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;

	var i;

	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=selLength-1; i>=0; i--) {
		if(theSelFrom.options[i].selected) {
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			selectedCount++;
		}
	}

	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selectedCount-1; i>=0; i--) { addOption(theSelTo, selectedText[i], selectedValues[i]); }

	sortListObj(theSelTo);

	if(NS4) history.go(0);
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function moveOptionPositionInList(zxcid,zxcud) {
	// zxcud: -1,1,top,bottom
	var zxcsel=el(zxcid);
	var zxcmove=zxcsel.selectedIndex;

	if (zxcmove<0) return;

	var zxcoptary=[];

	for (var zxc0=0;zxc0<zxcsel.options.length;zxc0++) zxcoptary.push(zxcsel.options[zxc0]);

	var zxcsave=(zxcud=='top')?0:(zxcud=='bottom')?zxcoptary.length-1:zxcmove+zxcud;

	if (zxcsel.options[zxcsave]) {
		for (var zxc1=0;zxc1<zxcoptary.length;zxc1++) { zxcsel.appendChild((zxc1==zxcmove)?zxcoptary[zxcsave]:(zxc1==zxcsave)?zxcoptary[zxcmove]:zxcoptary[zxc1]); }
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function zxcSize(zxcobj,zxcsz) {
	if (typeof(zxcobj)=='string') zxcobj=el(zxcobj);
	zxcobj.size=(zxcobj.size==zxcsz)?1:zxcsz;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function deleteOptions(theSelFrom) {
	var selLength = theSelFrom.length;
	for(i=selLength-1; i>=0; i--) {
		if(theSelFrom.options[i].selected) { deleteOption(theSelFrom, i); }
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function moveOptions(theSelFrom, theSelTo) {
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;

	var i;

	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=selLength-1; i>=0; i--) {
		if(theSelFrom.options[i].selected) {
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			deleteOption(theSelFrom, i);
			selectedCount++;
		}
	}

	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selectedCount-1; i>=0; i--) { addOption(theSelTo, selectedText[i], selectedValues[i]); }

	//sortListObj(theSelTo);

	if(NS4) history.go(0);
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for (z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') { theForm[z].checked = theElement.checked; }
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function checkUncheckSome(controller,theElements) {
	//Programmed by Shawn Olson
	//Copyright (c) 2006
	//Permission to use this function provided that it always includes this credit text
	//  http://www.shawnolson.net
	//Find more JavaScripts at http://www.shawnolson.net/topics/Javascript/

	//theElements is an array of objects designated as a comma separated list of their IDs
	//If an element in theElements is not a checkbox, then it is assumed
	//that the function is recursive for that object and will check/uncheck
	//all checkboxes contained in that element

	var formElements = theElements.split(',');
	var theController = el(controller);

	for (var z=0; z<formElements.length;z++) {
		theItem = el(formElements[z]);

		if (theItem) {
			if (theItem.type) {
				if (theItem.type == 'checkbox' && theItem.id != theController.id) { theItem.checked = theController.checked; }
				else {
					var nextArray = '';
					for(var x=0;x <theItem.childNodes.length;x++){
						if(theItem.childNodes[x]) {
							if (theItem.childNodes[x].id) {
								nextArray += theItem.childNodes[x].id+',';
							}
						}
					}

					checkUncheckSome(controller,nextArray);
				}

			}
		}
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/window.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight;
	return window.undefined;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
	if (document.body) return document.body.clientWidth;
	return window.undefined;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function getCenterXPos(width) {
	left = (screen.width) ? (screen.width-width)/2 : 0;
	return left;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function getCenterYPos(height) {
	top = (screen.height) ? (screen.height-height)/2 : 0;
	return top;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function maximizeWindow() {
	// maximaliseer internet verkenner venster

	top.window.moveTo(0,0);
	if (document.all) { top.window.resizeTo(screen.availWidth,screen.availHeight); }
	else if (document.layers||el) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------

function openCenterWindow(url,width,height) {
	// open gecentreerd venster

	left = (screen.width) ? (screen.width-width)/2 : 0;
	top = (screen.height) ? (screen.height-height)/2 : 0;

	var theWin=
		window.open(url,'',
	  		"width="+width+","+
	  		"height="+height+","+
	  		"top="+top+","+
	  		"left="+left+","+
			"fullscreen=no,"+
			"menubar=no,"+
			"location=no,"+
			"status=no,"+
			"titlebar=no,"+
			"toolbar=no,"+
			"scrollbars=yes,"+
			"resizable=no,"+
			"directories=no,"+
			"copyhistory=no"
		);
}

//----------------------------------------------------------------------------------------------------------------------------------------

function refreshParent() {
	window.location.href=window.location.href;
	if (window.progressWindow) { window.progressWindow.close(); }
}

//----------------------------------------------------------------------------------------------------------------------------------------

function launchWin(inURL,inName,inW,inH) {
	var theW;
	var theH;
	var top=0;
	var left=0;

	if (inW == 0) { theW = screen.availWidth; }
	else {
		theW = inW;
		top = (screen.width-theW)/2;
	}

	if (inH == 0) { theH = screen.availHeight; }
	else {
		theH = inH;
		left = (screen.height-theH)/2;
	}

	var theWin = window.open(inURL,inName,"width=" + theW + ",height=" + theH + ",top=" + top + ",left=" + left + ",resizable=yes,scrollbars=yes");
}

//----------------------------------------------------------------------------------------------------------------------------------------

function findPosX(obj) {
	var top = 0, left = 0;

	var myTarget=obj;
	while(myTarget!= document.body) {
		top += myTarget.offsetTop;
		left += myTarget.offsetLeft;
		myTarget = myTarget.offsetParent;
	}

	return left;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function findPosY(obj) {
	var top = 0, left = 0;

	var myTarget=obj;
	while(myTarget!= document.body) {
		top += myTarget.offsetTop;
		left += myTarget.offsetLeft;
		myTarget = myTarget.offsetParent;
	}

	return top;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function grayOutScreen(vis, options) {
	var options = options || {};
	var zindex = options.zindex || 50;
	var opacity = options.opacity || 70;
	var opaque = (opacity / 100);
	var bgcolor = options.bgcolor || '#000000';
	var dark=document.getElementById('darkenScreenObject');
	if (!dark) {
	 var tbody = document.getElementsByTagName("body")[0];
	 var tnode = document.createElement('div');           // Create the layer.
	     tnode.style.position='absolute';                 // Position absolutely
	     tnode.style.top='0px';                           // In the top
	     tnode.style.left='0px';                          // Left corner of the page
	     tnode.style.overflow='hidden';                   // Try to avoid making scroll bars
	     tnode.style.display='none';                      // Start out Hidden
	     tnode.id='darkenScreenObject';                   // Name it so we can find it later
	 tbody.appendChild(tnode);                            // Add it to the web page
	 dark=document.getElementById('darkenScreenObject');  // Get the object.
	}
	if (vis) {
	 // Calculate the page width and height
	 if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
	     var pageWidth = document.body.scrollWidth+'px';
	
	     //alert(document.body.scrollHeight+'\n'+document.body.offsetWidth);
	
	     if (document.body.offsetWidth>=1024) {
	     	if (document.body.scrollHeight<=1024) var pageHeight = '100%';
	     	else var pageHeight = document.body.scrollHeight+"px";
	     }
	     else var pageHeight = document.body.scrollHeight+'px';
	 } else if( document.body.offsetWidth ) {
	   var pageWidth = document.body.offsetWidth+'px';
	   //var pageHeight = document.body.offsetHeight+'px';
	   var pageHeight = '100%';
	 } else {
	    var pageWidth='100%';
	    var pageHeight='100%';
	 }
	
	 //set the shader to cover the entire page and make it visible.
	 dark.style.opacity=opaque;
	 dark.style.MozOpacity=opaque;
	 dark.style.filter='alpha(opacity='+opacity+')';
	 dark.style.zIndex=zindex;
	 dark.style.backgroundColor=bgcolor;
	 dark.style.width= pageWidth;
	 dark.style.height= pageHeight;
	 dark.style.display='block';
	} else {
	  dark.style.display='none';
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/date.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function isLeapYear(Year) {
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) { return true; }
	else { return false; }
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function setDays(value,dayField,monthField,yearField) {
	var weekDayArray=new Array("ZO","MA","DI","WO","DO","VR","ZA");
	
	var obj=el(dayField);
	removeAllOptions(obj);
	
	var yearobj=el(yearField);
	var monthobj=el(monthField);
	var month=monthobj.value;
	
	if ((month==1) || (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) { days=31; }
	else if ((month==4) || (month==6) || (month==9) || (month==11)) { days=30; }
	else if ((month==2) && isLeapYear(yearobj.value)) { days=29; }
	else { days=28; }

	for (i=1;i<=days;i++) { 
		var today=new Date(yearobj.value,month-1,i);
		var weekDay=today.getDay();	
		addOption(obj,"["+weekDayArray[weekDay]+"] - "+strPad(i),i);
	}
	
	obj.value=value;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function setToday(dayField,monthField,yearField) {
	var today=new Date();
	var yearobj=el(yearField);
	var monthobj=el(monthField);
	var dayobj=el(dayField);
	
	yearobj.value=today.getYear();
	monthobj.value=today.getMonth()+1;
	dayobj.value=today.getDate();
	
	yearobj.focus();
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/field.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function trim(s){ while (s.substring(0,1) == ' ') { s = s.substring(1,s.length); } while (s.substring(s.length-1,s.length) == ' ') { s=s.substring(0,s.length-1); } return s; }

//----------------------------------------------------------------------------------------------------------------------------------------

function enableField(field) { el(field).disabled=false; }

//----------------------------------------------------------------------------------------------------------------------------------------

function disableField(field) { el(field).disabled=true; }

//----------------------------------------------------------------------------------------------------------------------------------------

function enableDisableField(field,state) { el(field).disabled=state; }

//----------------------------------------------------------------------------------------------------------------------------------------

function enableDisableGroup(formName,groupName,state) {
	for (var i=0; i<formName.elements.length; i++) {
		if (formName.elements[i].name == groupName) { formName.elements[i].disabled = state; }
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------

function enableGroup(formName,groupName) { enableDisableGroup(formName,groupName,true); }

//----------------------------------------------------------------------------------------------------------------------------------------

function disableGroup(formName,groupName) { enableDisableGroup(formName,groupName,false); }

//----------------------------------------------------------------------------------------------------------------------------------------

function changeObjVisibility(field,visiblestate) { el(field).style.visibility=visiblestate; }

//----------------------------------------------------------------------------------------------------------------------------------------

function field2UC(field) { convert2UpperCase(field); }

//----------------------------------------------------------------------------------------------------------------------------------------

function field2LC(field) { convert2LowerCase(field); }

//----------------------------------------------------------------------------------------------------------------------------------------

function resetField(field) { field.value=''; }

//----------------------------------------------------------------------------------------------------------------------------------------

function convert2LowerCase(field) { field.value=trim(field.value.toLowerCase()); }

//----------------------------------------------------------------------------------------------------------------------------------------

function convert2UpperCase(field) { field.value=trim(field.value.toUpperCase()); }

//----------------------------------------------------------------------------------------------------------------------------------------

function setFieldToUpperCase(){ for(var i=0;i<arguments.length;i++) { arguments[i].value = trim(arguments[i].value.toUpperCase()); } }

//----------------------------------------------------------------------------------------------------------------------------------------

function setFieldVisible(field) {
	var obj=el(field);
	obj.style.visibility='visible';
	obj.style.display='inline';
}

//----------------------------------------------------------------------------------------------------------------------------------------

function setFieldInvisible(field) {
	var obj=el(htmlObj);
	obj.style.visibility='hidden';
	obj.style.display='none';
}

//----------------------------------------------------------------------------------------------------------------------------------------

function showDIV(divObj) {
	if (divObj.style!=undefined && divObj!=null) {
		if (divObj.style.visibility!='visible') {
			divObj.style.visibility='visible';
			divObj.style.display='inline';
		}
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------

function hideDIV(divObj) {
	if (divObj.style!=undefined && divObj!=null) {
		if (divObj.style.visibility!='hidden') {
			divObj.style.visibility='hidden';
			divObj.style.display='none';
		}
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------

function insertAtCursor(obj, value) {
	//IE support
	if (document.selection) {
		obj.focus();
		sel = document.selection.createRange();
		sel.text = value;
	}
	else if (obj.selectionStart || obj.selectionStart == '0') {
		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
		obj.value = obj.value.substring(0, startPos)+ value+ obj.value.substring(endPos, obj.value.length);
	} else {
		obj.value += value;
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------

function getCheckedValue(radioObj) {
	if(!radioObj) return "";

	var radioLength = radioObj.length;

	if(radioLength == undefined) {
		if(radioObj.checked) return radioObj.value;
		else return "";
	}

	for (var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) { return radioObj[i].value; }
	}

	return "";
}

//----------------------------------------------------------------------------------------------------------------------------------------

function getCheckedIndex(radioObj) {
	if(!radioObj) return "";

	var radioLength = radioObj.length;

	if(radioLength == undefined) {
		if(radioObj.checked) return 0;
		else return "";
	}

	for (var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) { return i; }
	}

	return "";
}

//----------------------------------------------------------------------------------------------------------------------------------------
//framework/javascript/form.validation.funtions.js
//----------------------------------------------------------------------------------------------------------------------------------------

function isFormModified(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;
}

addEvent = function(o, e, f, s){
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e){
        try{
            (e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
            e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        }catch(f){}
        for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
    for(var i = (e = o["_on" + e] || []).length; i;)
        if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
            return delete e[i];
    return false;
};

MaskInput = function(f, m){
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[À-ÿ]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    	}

    	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        	addEvent(f, i, mask);
};

// ----------------------------------------------------------------------------------------------------------------------------------------

function checkZipcode(obj) {
	var zipcode=obj.value.toUpperCase();

	if (zipcode=='0000ZZ') {
		obj.value=zipcode;
		return true;
	}

	/*
	zipcode=zipcode.split(' ');
	zipcode=zipcode.join('');
	*/

	obj.value=zipcode;

	rExp = /^[1-9]\d{3} [A-Z]{2}$/;
	if (!rExp.exec(zipcode)) {
	  /*
		openAlertBox(
			"De ingevoerde Postcode komt niet overeen met het volgende formaat: "+
			"9999 ZZ.<br><br>"+
			"Probeer opnieuw en voer de postcode in het correcte formaat in.",
			"POSTCODE",300,100);
	  */

		alert(
			"De ingevoerde Postcode komt niet overeen met het volgende formaat\n\n"+
			"\t9999 ZZ\n\n"+
			"Probeer het opnieuw en voer de postcode in het correcte formaat in.");

		obj.focus();

		return false;
	}

	obj.value=zipcode;
	return true;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function checktNumberFormat(str) {
	str.value=trim(str.value);

	var num=new Number(str.value);
	num=num.toFixed(2);
	if (num=="NaN") {
		alert('Er is een onjuist bedrag ingevoerd. Het juiste invoer formaat is EUR 9.99');
		str.value='0.00';
	}
	else {
		str.value=num;
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function checkDate(obj) {
	var dateobj=trim(obj.value);

	if (dateobj=='') { return true; }
	else {
		if (dateobj.length<10) {
			/*
			openAlertBox(
				"De ingevoerde Datum komt niet overeen met het volgende formaat<br><br>DD-MM-JJJJ.<br><br>Voer een geldig Datum formaat in.",
				"DATUM",300,100);
			globalvar =obj;
			setTimeout("globalvar.focus()",250);
			*/

			alert("De ingevoerde Datum komt niet overeen met het volgende formaat\n\nDD-MM-JJJJ.\n\nVoer een geldig Datum formaat in.");
			obj.focus();
			return false;
		}
		return true;
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function checkPhoneNumber(obj,execSweepToggle) {
	var len=trim(obj.value).length;
	var phnumber=obj.value;

	_0900=false;
	if (phnumber.substr(0,4)=='0900') {
		maxLen=14; // 0900-8844 | 0900-123456789 (14)
		seppos=phnumber.search('-');
		if (seppos==4) {
			telstr=phnumber.substr(5);
			_0900=(telstr.length>=4);
		}
	}
	else {
		maxLen=11; // 1234 - 123456 (11)
	}

	if ( (!_0900) && (len<=10) || (len>maxLen) ) {
		/*
		openAlertBox(
			'Er is een onjuist Telefoonnummer ingevoerd.<br><br>'+
			'Telefoonnummer kan minimaal uit '+maxLen+' cijfers bestaan, het kengetal en het '+
			'telefoonnummer dienen gescheiden te zijn door het - teken<br><br>'+
			'Of als het gaat om 0900 nummers dan kunnen de volgende regels gehanteerd worden:<br><br>'+
			'0900-1234 of 0900-123456789',
			'Telefoonnummer',400,250);

		globalvar =obj;
		setTimeout("globalvar.focus()",250);
		*/
		alert(
			'Er is een onjuist Telefoonnummer ingevoerd.\n\n'+
			'Telefoonnummer kan minimaal uit '+maxLen+' cijfers bestaan, het kengetal en het '+
			'telefoonnummer dienen gescheiden te zijn door het - teken\n\n'+
			'Of als het gaat om 0900 nummers dan kunnen de volgende regels gehanteerd worden:\n\n'+
			'0900-1234 of 0900-123456789'
		);

		obj.focus();

		return false;
	}

	return true;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function elf_proef(bankrekeningnummer) {
	// verwijder alle tekens die geen cijfers zijn
	bankrekeningnummer=bankrekeningnummer.replace(/\D/, "");
	aantal_tekens=bankrekeningnummer.length;
	var som=0;

	// loop door de 9 cijfers met de 11 proef formule
	for (i=1; i<10; i++) {
		getal=bankrekeningnummer.charAt(i-1);
		som+=getal*(10-i);
	}

	// geef resultaat van check terug
	if (som % 11==0 && aantal_tekens==9) { return true }
	else { return false }
}

function checkAccountNumber(obj) {
	var rekeningnummer=obj.value;
	rekeningnummer=rekeningnummer.toUpperCase();

	if (rekeningnummer=='') { return true; }

	if (rekeningnummer.substring(0,1)=='P') { return true; }
	else {
		ok=(elf_proef(rekeningnummer));
		if (!ok) {
			/*
			openAlertBox(
				'Je hebt een ongeldig Bank rekeningnummer ingevoerd.<br><br>'+
				'Let op: Als je een (Post)giro nummer wilt invoeren, begin dit rekeningnummer dan met de letter P<br>'+
				'Voorbeeld: P12345','Bank- Gironummer',400,170);
			*/

			alert(
				'Je hebt een ongeldig Bank rekeningnummer ingevoerd.\n\n'+
				'Let op: Als je een (Post)giro nummer wilt invoeren, begin dit rekeningnummer dan met de letter P\n'+
				'Voorbeeld: P12345'
			)

			obj.focus();

			return false;
		}

		return true;
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function checkTextarea(obj,description) {
	if (obj.value=='') {
		/*
		openAlertBox(
			'Je bent vergeten het volgende veld in te vullen.<br><br><span class=padleft30px><b>'+description+'</b></span>',
			'VELD BEVAT GEEN WAARDE',300,120);
		*/

		alert(
			'Je bent vergeten het volgende veld in te vullen.\n\n'+
			'\t\t'+description+'\n'
		);

		obj.focus();
		return false;
	}

	return true;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function emailCheck(obj) {
	emailStr=obj.value;
	if (emailStr=='') return true;

	var checkTLD=0;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		if (emailStr!='') { alert("Email adres is niet correct ingevoerd."); }

		obj.focus();
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Het gebruikersnaam gedeelte (voor het @ teken) is niet correct gespeld.");
			return false;
   		}
	}

	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Het domein van het email adres bevat ongeldige tekens.");

			obj.focus();
			return false;
   		}
	}

	if (user.match(userPat)==null) {
		alert("De gebruikersnaam is ongeldig.");

		obj.focus();
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//openAlertBox("Doel IP adres is ongeldig.","EMAIL ADRES",300,100);
				alert("Doel IP adres is ongeldig.");

				obj.focus();
				return false;
   			}
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("De domeinnaam van het email adres is ongeldig.");

			obj.focus();
			return false;
   		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("Een email adres moet eindigen op een bekende domeinnaam of een tweeletterige land codering.");

		obj.focus();
		return false;
	}

	if (len<2) {
		alert("Het email adres bevat geen hostnaam.");

		obj.focus();
		return false;
	}
	return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function checkEmail(obj) {
	// setFieldToUpperCase(obj);
	if (obj.value!='') {
		var emailok=emailCheck(obj);
		return emailok;
	}
	else {
		return true;
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function setcolor(obj,percentage,prop){ obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)"; }
function showTextAreaCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;

	// trim the extra text
	if (charcnt > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	}

	else {
		// progress bar percentage
		var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
		el(counter).style.width =  parseInt(((fieldWidth*percentage)/100))+"px";
		el(counter).innerHTML="Limiet: "+percentage+"%"
		// color correction on style from CCFFF -> CC0000
		setcolor(el(counter),percentage,"background-color");
	}
}