// Javascript Library - Copyright Make IT Work (http://www.makeitwork.be)

// Usage: <script  language="javascript" src="scriptlib.js">

// The left() function doesn't exist, so we'll just create one...
function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

// The right() function doesn't exist, so we'll just create one...
function 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);
    }
}

// The replace() function doesn't exist, so we'll just create one...
function replace( str, from, to )
{
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}

// Pop-up window with picture
function ShowPicture(fotonaam, fhoogte, fbreedte, src, naam)
{
        naam=fotonaam;
		len=naam.length;
		naam=replace(replace(Left(naam,naam.length - 4),"-"," "),"_"," ");
		margin = 180; // margin you need for the menu + your OS menu bar
		reshoogte = screen.height; // user resolution height
		resbreedte = screen.width; // user resolution width
		if (fhoogte > (reshoogte-margin))
		{ hoogte = reshoogte-margin; breedte = (fbreedte/fhoogte)*hoogte; }
	    else { hoogte = fhoogte; breedte = fbreedte; } // if the resolution is way bigger than the pic size
		// alle parameters doorgeven aan de windowNavigator, navigatie info
		strUrl = "windowNavigator.php?fotonaam=" + fotonaam + "&src=" + src + "&breedte=" + breedte 
		+ "&hoogte=" + hoogte + "&naam=" + naam;
		foto = window.open(strUrl,'','menubar=no,toolbar=no');
		foto.resizeTo(breedte+15,hoogte+margin-50); // count 50 pixels for the OS menu bar
}

// Pop-up window
function open_me(url,w,h,name)
{
	w=w+15; h=h+15;
	window.open(url,name,'location=0,resizable=0,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=0,status=0,width='+w+',height='+h+',screenX='+(screen.width - w)/2+',screenY='+(screen.height - h)/2+',top='+(screen.height - h)/2+',left='+(screen.width - w)/2);
}

// Pop-up window with scroll bar
function open_me_scroll(url,w,h,name)
{
	w=w+15; h=h+15;
	window.open(url,name,'location=0,resizable=0,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h+',screenX='+(screen.width - w)/2+',screenY='+(screen.height - h)/2+',top='+(screen.height - h)/2+',left='+(screen.width - w)/2);
}
function open_me2(url,w,h)
{
	w=w+15; h=h+15;
	window.open(url,'popwin2','location=0,resizable=0,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=0,status=0,width='+w+',height='+h+',screenX='+(screen.width - w)/2+',screenY='+(screen.height - h)/2+',top='+(screen.height - h)/2+',left='+(screen.width - w)/2);
}

// Pop-up window with scroll bar
function open_me_scroll2(url,w,h)
{
	w=w+15; h=h+15;
	window.open(url,'popwin2','location=0,resizable=0,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h+',screenX='+(screen.width - w)/2+',screenY='+(screen.height - h)/2+',top='+(screen.height - h)/2+',left='+(screen.width - w)/2);
}

function open_me3(url,w,h)
{
	w=w+15; h=h+15;
	window.open(url,'popwin3','location=0,resizable=0,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=0,status=0,width='+w+',height='+h+',screenX='+(screen.width - w)/2+',screenY='+(screen.height - h)/2+',top='+(screen.height - h)/2+',left='+(screen.width - w)/2);
}

// Pop-up window with scroll bar
function open_me_scroll3(url,w,h)
{
	w=w+15; h=h+15;
	window.open(url,'popwin3','location=0,resizable=0,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0,width='+w+',height='+h+',screenX='+(screen.width - w)/2+',screenY='+(screen.height - h)/2+',top='+(screen.height - h)/2+',left='+(screen.width - w)/2);
}


// Limit size of textarea
// HTML code needed:
// <form name="form1">
// <textarea name="textfield" onkeydown="textCounter(textfield,form1.remLen,100);" onkeyup="textCounter(form1.textfield,form1.remLen,100);">Hello</textarea>
// <input name="remLen" type="text" value="100" size="3" maxlength="3" readonly="readonly"> remaining characters...
// </form>
function textCounter(field, countfield, maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
else 
	countfield.value = maxlimit - field.value.length;
}

// Age calculator
// HTML code needed:
// Stef is <script>calculate(17,9,1970)</ script> oud...

// needed for calculate()
function y2k(number)
{
	return (number < 1000) ? number + 1900 : number;
}

function calculate(day,month,year)
{		
	var today = new Date();
	var thisYear = y2k(today.getYear());
	var thisMonth = today.getMonth()+1;
	var thisDay = today.getDate();
	var yearsold = thisYear - year, monthsold = 0, daysold = 0, string = '';

    if (thisMonth >= month) monthsold = thisMonth - month;
    else { yearsold--; monthsold = thisMonth + 12 - month; }

    if (thisDay >= day)daysold = thisDay - day;
    else {
        if (monthsold > 0) monthsold--;
        else { yearsold--; monthsold+=11; }
        daysold = thisDay + 31 - day;
    }

    if (yearsold > 0) // toon dan enkel maanden & dagen
	{
		string = yearsold + ' jaar';
	}
	else // anders enkel jaren
	{
		if (monthsold > 0) {string += monthsold + ' maand ';}
		if (daysold > 0) {
			string += ' en ' + daysold + ' dag';
			if (daysold > 1) string += 'en';        
		}
	}
    document.write(string);
}

// Pop-up Divs
function toggleDiv(id,flagit)
{
	if (flagit=="1")
	{
		if (document.layers) document.layers[''+id+''].visibility = "show"
		else if (document.all) document.all[''+id+''].style.visibility = "visible"
			 else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
    }
	else
		if (flagit=="0")
		{
		if (document.layers) document.layers[''+id+''].visibility = "hide"
			else if (document.all) document.all[''+id+''].style.visibility = "hidden"
		   	     else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
}

// Expand/collapse a DIV
// HTML code needed:
// <div id="hiddentext" style="display:none;">
// This is hidden text</div>
// <a href="javascript:void(null);" onclick="expand('hiddentext', this);">
// <img src="/lib-pics/icon-sq-plus.gif" border="0" align="absmiddle"></a>

function expand(thistag, tag)
{
	styleObj=document.getElementById(thistag).style;
	if (styleObj.display=='none')
	{
		styleObj.display='';
		tag.innerHTML = "<img src='/lib-pics/icon-sq-min.gif' align=absmiddle border=0>";
	}
	else {
		styleObj.display='none';
		tag.innerHTML = "<img src='/lib-pics/icon-sq-plus.gif' align=absmiddle border=0>";
	}
}


function RTEsubmitForm()
{
	updateRTE('rte1');
	return true;
}

function DeleteWithConfirmation(deletepage_url,field_name,field_value,messagetext)
{ //v1.0 - Deletes a record with confirmation
  if (confirm(messagetext)==1){
    location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
  }
}

function DeleteWithConfirmationQuick(deletepage_url,messagetext)
{ //v1.0 - Deletes a record with confirmation
  if (confirm(messagetext)==1){
    location.href = eval('\"'+deletepage_url+'\"');
  }
}

// Title: Timestamp picker
// Description: See the demo at url
// URL: http://us.geocities.com/tspicker/
// Script featured on: http://javascriptkit.com/script/script2/timestamp.shtml
// Version: 1.0
// Date: 12-05-2001 (mm-dd-yyyy)
// Author: Denis Gritcyuk <denis@softcomplex.com>; <tspicker@yahoo.com>
// Notes: Permission given to use this script in any kind of applications if
//    header lines are left unchanged. Feel free to contact the author
//    for feature requests and/or donations

function show_calendar(str_target, str_datetime) {
	var arr_months = ["January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December"];
	var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
	var n_weekstart = 1; // day week starts from (normally 0 or 1)

	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));

	var dt_prev_month = new Date(dt_datetime);
	dt_prev_month.setMonth(dt_datetime.getMonth()-1);
	var dt_next_month = new Date(dt_datetime);
	dt_next_month.setMonth(dt_datetime.getMonth()+1);
	var dt_firstday = new Date(dt_datetime);
	dt_firstday.setDate(1);
	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);
	var dt_lastday = new Date(dt_next_month);
	dt_lastday.setDate(0);
	
	// html generation (feel free to tune it for your particular application)
	// print calendar header
	var str_buffer = new String (
		"<html>\n"+
		"<head>\n"+
		"	<title>Calendar</title>\n"+
		"</head>\n"+
		"<body bgcolor=\"White\">\n"+
		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+
		"<tr><td bgcolor=\"#4682B4\">\n"+
		"<div class='calendar'>"+
		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+
		"<tr>\n	<td bgcolor=\"#4682B4\"><a href=\"javascript:window.opener.show_calendar('"+
		str_target+"', '"+ dt2dtstr(dt_prev_month)+"');\">"+
		"<img src=\"/pics/prev.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"previous month\"></a></td>\n"+
		"	<td bgcolor=\"#4682B4\" colspan=\"5\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"
		+arr_months[dt_datetime.getMonth()]+" "+dt_datetime.getFullYear()+"</font></td>\n"+
		"	<td bgcolor=\"#4682B4\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('"
		+str_target+"', '"+dt2dtstr(dt_next_month)+"');\">"+
		"<img src=\"/pics/next.gif\" width=\"16\" height=\"16\" border=\"0\""+
		" alt=\"next month\"></a></td>\n</tr>\n"
	);

	var dt_current_day = new Date(dt_firstday);
	// print weekdays titles
	str_buffer += "<tr>\n";
	for (var n=0; n<7; n++)
		str_buffer += "	<td bgcolor=\"#87CEFA\">"+
		"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
		week_days[(n_weekstart+n)%7]+"</font></td>\n";
	// print calendar table
	str_buffer += "</tr>\n";
	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||
		dt_current_day.getMonth() == dt_firstday.getMonth()) {
		// print row heder
		str_buffer += "<tr>\n";
		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {
				if (dt_current_day.getDate() == dt_datetime.getDate() &&
					dt_current_day.getMonth() == dt_datetime.getMonth())
					// print current day
					str_buffer += "	<td bgcolor=\"#FFB6C1\" align=\"right\">";
				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
					// weekend days
					str_buffer += "	<td bgcolor=\"#DBEAF5\" align=\"right\">";
				else
					// print working days of current month
					str_buffer += "	<td bgcolor=\"white\" align=\"right\">";

				if (dt_current_day.getMonth() == dt_datetime.getMonth())
					// print days of current month
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";
				else 
					// print days of other months
					str_buffer += "<a href=\"javascript:window.opener."+str_target+
					".value='"+dt2dtstr(dt_current_day)+"'; window.close();\">"+
					"<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";
				str_buffer += dt_current_day.getDate()+"</font></a></td>\n";
				dt_current_day.setDate(dt_current_day.getDate()+1);
		}
		// print row footer
		str_buffer += "</tr>\n";
	}	
		str_buffer += "</table>\n" +
		"</div>" +
		"</tr>\n</td>\n</table>\n" +		
		"</body>\n" +
		"</html>\n";

	var vWinCal = window.open("", "Calendar", 
		"width=200,height=190,status=no,resizable=yes,top=200,left=200");
	vWinCal.opener = self;
	var calc_doc = vWinCal.document;
	calc_doc.write (str_buffer);
	calc_doc.close();
}
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function str2dt (str_datetime) {
	var re_date = /^(\d+)-(\d+)-(\d+)$/;
	if (!re_date.exec(str_datetime))
		return alert("Invalid Datetime format: "+ str_datetime);
	return (new Date (RegExp.$1, RegExp.$2-1, RegExp.$3, RegExp.$4, RegExp.$5, RegExp.$6));
}
function dt2dtstr (dt_datetime) {
	return (new String (
			dt_datetime.getFullYear()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getDate()));
}
function dt2tmstr (dt_datetime) {
	return (new String (
			dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- "'+nm+'" moet een geldig e-mail addres zijn.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- "'+nm+'" moet een nummer zijn.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- "'+nm+'" moet een nummer tussen '+min+' en '+max+' zijn.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- "'+nm+'" is een verplicht veld.\n'; }
  } if (errors) alert('Corrigeer de volgende fouten:\n\n'+errors+'\n\n');
  document.MM_returnValue = (errors == '');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ltrim(str){
	return str.replace(/^\s+/, '');
}
function rtrim(str) {
	return str.replace(/\s+$/, '');
}
function alltrim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

function filterDubbeleSpaties(str)
{
	return str.replace(/\s\s+/,' ');
}

function filterLidwoorden(sText)
{
	var reBadWords = /^ |^LES |^DE |^THE |^HET |^EEN /gi;
	return filterDubbeleSpaties(alltrim(sText.replace(reBadWords, function (sMatch) {return sMatch.replace(/./g, ""); })));
}
// used to check if variable is set. Usage: if(checkVar(yy)){do something}
function checkVar(what)
{
	return Boolean(typeof what != 'undefined' && what)
}
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}		

function MM_jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// Calculate window's width and heigth

var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;	
}
//alert( 'Width = ' + myWidth + ' Height = ' + myHeight );



// MAIL-SPAM-BLOCKER
// Usage:
// Browse to http://www.myvasco.com/msb/
// Then, put the link into your code (e.g)
// <a href="javascript:msb('your generated code')">mailto:list[AT SIGN]themission[DOT]be?subject=subscribe</a>

function ch1(x){var yy=2;var z=0;var xx="";for(var y=0;y<x.length;y++){z=x.charCodeAt(y);xx+=String.fromCharCode(z-yy);}return xx;}function msb(x){location.href=ch1(x);}
// ==================================================================

// Press Enter key to submit form
function checkEnter(e){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.forms[0].submit() //submit the form
return false
}
else{
return true
}

}


function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	

