	/*
	 * Turn on IE6 background caching
	 * http://extjs.com/forum/showthread.php?t=2476
	 */
	( function() {
	
	    /*Use Object Detection to detect IE6*/
	    var  m = document.uniqueID /*IE*/
	    && document.compatMode  /*>=IE6*/
	    && !window.XMLHttpRequest /*<=IE6*/
	    && document.execCommand;
	    
	    try{
	        if( !!m ){
	            m("BackgroundImageCache", false, true ) /* = IE6 only */ 
	        }
	        
	    }catch( oh ){};
	})();





	/*
	 * ASAD reminder frontend
	 */



	function ReminderEngine( aReminders, sOpenReminder )
	{
		this._reminders 		= aReminders ;
		this._states			= new Array() ;
		this.animation  		= new Mover() ;
		this.animation._mama	= this ;
		this.evaluate			= null ;
		this.interval			= null ;
		document.ReminderEngine = this ;
		this.init() ;
 
		
		if( sOpenReminder != '' )
			this.animation.toggle( sOpenReminder )  ;
		else
			this.animation.toggle( 'manual' )  ;
		
		
		this.open = false ;
	}
	
	ReminderEngine.prototype.init = function()
	{
		var oButton = null ;
		
		/* First we get the state of the reminders and other data */
		for( var t=0 ; t < this._reminders.length ; t++ )
		{
			if( document.getElementById( this._reminders[t] + 'button' ) )
			{
				/* is a reminder */
				oButton = document.getElementById( this._reminders[t] + 'button' ) ;
				this._states[t] = Number( oButton.className == "button_on" );
				
				/* Make clickable */
				oButton._parent = this ;
				oButton._id     = this._reminders[t] ;
				oButton.onclick = this.showForm ;
			}
			else
			{
				/* is part of other functionality */
				this._states[t] = -1 ;
				
				/* Commanded by another link */
				oButton = document.getElementById( this._reminders[t] + '_click' ) ;
				if( oButton )
				{
 
					oButton._parent = this ;
					oButton._id     = this._reminders[t] ;
					oButton.onclick = this.showForm ;
				}
			}
			/* This will set the last form as open */ 
			this.evaluate = this._reminders[t] ;
		}
		
		/* Set form submit button states */
		this.evaluateOffButtons() ;
		this.evaluateOnButtons() ;
		this.evaluateSubmitButtons();
		
		/* start validation. It will decide for itself if this is needed */
		this.interval  = setInterval( "document.ReminderEngine.validator() ;", 300  ) ;
		
 

	};
	
	ReminderEngine.prototype.evaluateOffButtons = function()
	{
		/* The state of the off-button in the form is dependend 
		 * of the state of the service
		 */
		
		var oButtonOff = null ;
		
		for( var t=0 ; t < this._reminders.length ; t++ )
		{
			oButtonOff = document.getElementById( "stop_"  + this._reminders[t] ) ;
			
			
			/* check, because it might be other functionality */
			if( !oButtonOff )
				continue ;
		
			/* always provide ref to this instance */ 
			oButtonOff._parent =  this ;
			oButtonOff._id	   =  this._reminders[t] ;
			
			/* take appropiate action by state */
			if( this._states[t] == 1 )
			{
				/* active services can be set to off */
				oButtonOff.onclick = this.setOff ;
				oButtonOff.className = 'formbutton' ;
			}
			if( this._states[t] == 0 )
			{
				/* Non active services cannot be set off, and so will be disabled */
				oButtonOff.onclick = function(){ return false ;} ;
				oButtonOff.className = 'formbutton_dis' ;
			}
		}
	};
	
	
	ReminderEngine.prototype.evaluateOnButtons = function()
	{
		/* The state of the on/off buttons in the form is dependend 
		 * of the state of the service.
		 * 
		 * It is commanded by the main button state
		 */
		var oButtonOn = null ;
		var oForm     = null ;
		
		for( var t=0 ; t < this._reminders.length ; t++ )
		{		
			oButtonOn  = document.getElementById( "start_" + this._reminders[t] ) ;
			
			/* Check */
			if( !oButtonOn )
				continue ;
			
			/* always provide ref to this instance */ 
			oButtonOn._parent 	= this ;
			oButtonOn._id 		= this._reminders[t] ;			
			
				
			if( this._states[t] == 1 )
			{
				oButtonOn.className = 'formbutton_dis' ;
				oButtonOn.onclick = function(){ return false ;} ;
			}
			if( this._states[t] == 0 )
			{
				oButtonOn.className = 'formbutton' ;
				oButtonOn.onclick = this.setOn ;
			}
 
		};
	};
	
	
	ReminderEngine.prototype.evaluateSubmitButtons = function()
	{
		/* The state of the on/off buttons in the form is dependend 
		 * of the state of the service.
		 * 
		 * It is commanded by the main button state
		 */
		var oButtonOn = null ;
		var oForm     = null ;
		
		for( var t=0 ; t < this._reminders.length ; t++ )
		{		
			oButtonOn  = document.getElementById( "submit_" + this._reminders[t] ) ;
			
			/* Check */
			if( !oButtonOn )
				continue ;
			
			/* always provide ref to this instance */ 
			oButtonOn._parent 	= this ;
			oButtonOn._id 		= this._reminders[t] ;			
			oButtonOn.className = 'submitbutton_dis' ;
			oButtonOn.onclick   = this.submit ;
		};
	};
	
	
	
	
	
	
	ReminderEngine.prototype.prepareposting = function( sId, bSetoff )
	{
		var oVariable = new Object() ;
		var oForm = document.getElementById( sId ) ;
		if( !bSetoff )
			bSetoff = false ;
		
		if( oForm  && !bSetoff )
		{
			var aInputs = oForm.getElementsByTagName( 'input' ) ;
			for( var t=0; t<aInputs.length; t++ )
				oVariable[ aInputs[t].name ] = aInputs[t].value ; 
			oVariable['command'] = 'save' ;
		}
		else
		{
			if( bSetoff )
				oVariable['command'] = 'toggleoff' ;
			else
				oVariable['command'] = 'toggleon' ;
		}
		oVariable['reminder'] = sId ;
		oVariable['_format'] = 'xml' ;
		return oVariable ;
	};

	
	ReminderEngine.prototype.prepareclassicposting = function( sId  )
	{
		var oVariable = new Object() ;
		var oForm = document.getElementById( sId ) ;

		var aInputs = oForm.getElementsByTagName( 'input' ) ;
		for( var t=0; t<aInputs.length; t++ )
		{
			if( aInputs[t].type == 'checkbox' ) 
				oVariable[ aInputs[t].name ] = Number(aInputs[t].checked ) ;
			else
				oVariable[ aInputs[t].name ] = aInputs[t].value ; 
		}
			
		var aTextareas = oForm.getElementsByTagName( 'textarea' ) ;	
		if( aTextareas.length )
			for( var x=0; x<aTextareas.length ; x++ )
				oVariable[ aTextareas[x].name ] = aTextareas[x].value ; 
		
		oVariable['command'] = sId ;
		oVariable['_format'] = 'xml' ;
		return oVariable ;
	};
	
	
	ReminderEngine.prototype.doPost = function( oVariable )
	{
		/* Time will defeat IE AJAX caching bug */
		var currentTime = new Date() ;
		oVariable['time'] = currentTime.getTime() ;
		oXml  = new Keen.xml() ;
		oXml._parent = this ;
		oXml.onload = this.processReply  ;
		oXml.get( '/rpc.php', true, oVariable ) ;	
		
	};
	
	
	
	/**
	 * Callbacks over here
	 * 
	 * @return
	 */
	
	ReminderEngine.prototype.processReply = function()
	{
		/* This is called from the scope of the Keen xml object */
		var oStatus = new Status( this ) ;
		if( oStatus.success )
		{
			for( var t=0 ; t< this._parent._reminders.length; t++ )
			{
				if( this._parent._reminders[t] == oStatus.content.reminder )
				{
					/* Reflect state in main button ( if there is one ...) */
					var oLargeButton = document.getElementById( oStatus.content.reminder + 'button' ) ;
					if( oLargeButton )
					{
						this._parent._states[t] = oStatus.content.rstatus ;
						document.getElementById( oStatus.content.reminder + 'button' ).className =
							( oStatus.content.rstatus == 1 ? 'button_on' : 'button' ) ;
						
						/* then we will change the state of the formbuttons as well */
						var oButtonOn  = document.getElementById( 'start_' + oStatus.content.reminder  ) ;
						var oButtonOff = document.getElementById( 'stop_' + oStatus.content.reminder  ) ;
						if( oStatus.content.rstatus == 1 )
						{
							/* active services can be set to off */
							oButtonOff.onclick = this._parent.setOff ;
							oButtonOff.className = 'formbutton' ;
							oButtonOn.onclick = function(){ return false ;} ;
							oButtonOn.className = 'formbutton_dis' ;	
						}
						else
						{
							/* inactive services can be set to on */
							oButtonOff.onclick = function(){ return false ;} ;
							oButtonOff.className = 'formbutton_dis' ;
							oButtonOn.onclick = this._parent.setOn ;
							oButtonOn.className = 'formbutton' ;
						}
					}
				}
			}
			/* If we have a classic formpost we might have a submitbutton */
			var oSubmitButton = document.getElementById( 'submit_' + oStatus.content.reminder ) ;
			if( oSubmitButton )
			{
				oSubmitButton.onclick = function(){ return false ;} ;
				oSubmitButton.className = 'submitbutton_dis' ;
			}
			
			/* The backend might want to tell u something ... */
			var oMessagefield = document.getElementById( 'feedback' + oStatus.content.reminder ) ;
			if( oMessagefield && oStatus.message  )
				oMessagefield.innerHTML = oStatus.message ;			
				
			/* redirects here */
			if ( oStatus.content && oStatus.content.redirect && oStatus.content.redirect.url && oStatus.content.redirect.url != "" )
			{
				var nTimeout = oStatus.content.redirect.timeout ? parseInt( oStatus.content.redirect.timeout ) : 1500;
				if ( nTimeout <= 0 )
					document.location = oStatus.content.redirect.url;
				else
					setTimeout( "document.location='" + oStatus.content.redirect.url + "';", nTimeout );
			}
			
		}
		else
		{
			/*error stuff */
			var oMessagefield = document.getElementById( 'feedback' + oStatus.content.reminder ) ;
			if( oMessagefield && oStatus.message )
				oMessagefield.innerHTML = oStatus.message ;
		}
		
		/* perhaps update */
		if( oStatus.content.activereminders && document.getElementById( 'activereminders' ) )
			document.getElementById( 'activereminders' ).innerHTML = oStatus.content.activereminders  ;
			
		/*perhaps open other panel? */
		if( oStatus.content && oStatus.content.shiftpanel )
			this._parent.animation.toggle( oStatus.content.shiftpanel ) ;
			
			
			
		/* perhaps callback */
		if ( oStatus.content && oStatus.content.callback && oStatus.content.callback  != "" )
			{
					eval( oStatus.content.callback ) ;
			}
		
	};

	
	
	
	
	ReminderEngine.prototype.showForm = function() 
	{
		/* This is called from the scope of a button */
		
		/* do trick */
		this._parent.animation.toggle( this._id ) ;
		return false ;
	};
	
	ReminderEngine.prototype.setOff = function()
	{
		/* This is called from the scope of a formbutton */
		this._parent.doPost( this._parent.prepareposting( this._id, true ) ) ;
		return false ;
	};
	
	ReminderEngine.prototype.setOn = function()
	{
		/* This is called from the scope of a formbutton */
		this._parent.doPost( this._parent.prepareposting( this._id, false  ) ) ;
		return false ;
	};

	ReminderEngine.prototype.submit = function()
	{
		/* This is called from the scope of a formbutton */
		this._parent.doPost( this._parent.prepareclassicposting( this._id ) ) ;
		return false ;
	}
	
	ReminderEngine.prototype.validator = function()
	{
		/* this is called from a global scope */
	
		var oParent = document.ReminderEngine ;
		
		/* is it something with a form ? */
		var oForm = document.getElementById( oParent.evaluate );
		
		/* If not, we dont care anymore */
		if( !oForm )
			return ;
		
		/* which button */
		var oButtonOn  = document.getElementById( "start_" + oParent.evaluate ) ;
		
		/* if not, we seek submit button because thats probably what we want */
		if( !oButtonOn )
			oButtonOn  = document.getElementById( "submit_" + oParent.evaluate ) ;
		
		oButtonOn._parent = this;
		/* use the specific evaluator for that */
		var nResult = null ;
		eval( "nResult = reminderValidator." + oParent.evaluate + "() ;" )  ;
		
		/* if is 1, we enable the on button */
		if( nResult == 1 )
		{
			oButtonOn.className = 'formbutton' ;
			oButtonOn.onclick = oParent.setOn ;			
		}
		
		/* if is 0, we disable */
		if( nResult == 0 )
		{
			oButtonOn.className = 'formbutton_dis' ;
			oButtonOn.onclick = function(){ return false ;} ;		
		}
		
		/* The next set is for normal submits */
		/* if is 11, we enable the on button */
		if( nResult == 11 )
		{
			oButtonOn.className = 'submitbutton' ;
			oButtonOn._id = oButtonOn.id.replace( "submit_", "" );
			oButtonOn.onclick = oParent.submit ;			
		}
		
		/* if is 10, we disable */
		if( nResult == 10 )
		{
			oButtonOn.className = 'submitbutton_dis' ;
			oButtonOn.onclick = function(){ return false ;} ;		
		}		
		
		/* if is 12, we only show the button disabled, trusting the evaluator has taken care of setting stuff */
		if( nResult == 12 )
		{
			oButtonOn.className = 'submitbutton_dis' ;	
		}			
		
		
		
		/* any other result will have no effect */
	};
	
	 
	
	
	
	
	
	
	
	
	
	
	
	
	
	 
	function Mover()
	{
		this._switch = null ;
 	};
		
	 
	Mover.prototype.toggle = function( sForm )
	{
		clearInterval( this._mama.interval );
		
		if( this._switch )
		{
			var oEl = document.getElementById( 'form_' + this._switch ); 
			if( oEl )
				oEl.style.display = 'none';
		}
		else
		{
			setMask(0.2) ;
			setTimeout( "setMask(0.4)", 50 ) ;
			setTimeout( "setMask(0.6)", 100 ) ;
		}
		
		var oEl = document.getElementById( 'form_' + sForm ); 
		if( !oEl )
			return;
		oEl.style.display = 'block';
 		this._switch = sForm ;
		this._mama.evaluate  = this._switch ;
		document.ReminderEngine.validator() ;
		document.ReminderEngine.validator() ;
		this._mama.interval  = setInterval( "document.ReminderEngine.validator() ;", 150 ) ;
	};
	
	
	Mover.prototype.close = function()
	{
		clearInterval( this._mama.interval );
		var oEl = document.getElementById( 'form_' + this._switch );
		if( !oEl )
			return;
		oEl.style.display = 'none';
		this._switch = null ;
		this._mama.evaluate = null ;
		setTimeout( "setMask(0.6)" , 50  ) ;
		setTimeout( "setMask(0.4)" , 100 ) ;
		setTimeout( "setMask(0.2)" , 150  ) ;
		setTimeout( "setMask(0)"   , 200 ) ;
	}
	
	
	/**
	* Set mask to opacity
	*/
	
	function setMask( nOpacity )
	{
		var oMask = document.getElementById( 'mask'  ) ;
		if( nOpacity == 0 )
			oMask.style.height = '0%' ;
		else
			oMask.style.height = '100%' ;
		oMask.style.opacity = nOpacity ;
		oMask.style.filter  = "alpha(opacity=" +  nOpacity*100 + ")" ;
	}
	
	
	
	
	
	
	
	
	
	
	
/*
 * Status object for parsing replys from server into objects
 * 
 */	

	function Status( oXML )
	{
		if ( typeof oXML != "undefined" )
			this.init( oXML );
	}
	
	Status.prototype.init = function( oXML )
	{
		this.parseStatusResult( oXML.getData() );
	};
	
	Status.prototype.getNodeValue = function( oNode )
	{
		if ( oNode )
		{
			//   textnode               cdata
			if ( oNode.nodeType == 3 || oNode.nodeType == 4 )
				return oNode.nodeValue;
			return arguments.callee( oNode.firstChild );
		}
		return false;
	};
	
	Status.prototype.getSiblingByName = function ( oNode, sName )
	{
		if ( oNode )
		{
			while ( ( oNode.nodeType != 1 || ( oNode.nodeName && oNode.nodeName.toLowerCase() != sName.toLowerCase() ) ) && oNode.nextSibling )
				oNode = oNode.nextSibling;

			if ( oNode.nodeType == 1 && ( oNode.nodeName && oNode.nodeName.toLowerCase() == sName.toLowerCase() ) )
				return oNode;
		}
		return false;
	};
	
	Status.prototype.parseStatusResult = function( oDataXML )
	{
		if ( oDataXML )
		{
			var oReply = this.getSiblingByName( oDataXML.firstChild, "reply" );
			if ( oReply )
			{
				var sStatus = "error";
				if ( typeof oReply.attributes[ 0 ] != "undefined" && oReply.attributes[ 0 ].name.toLowerCase() == "status" )
					sStatus = oReply.attributes[ 0 ].value;
				this.success = sStatus == "OK";
				this.status  = sStatus;
				this.message = unescape( this.trim( this.getNodeValue( this.getSiblingByName( oReply.firstChild, "message" ) ) ) );
				this.content = this.xmlToObject( this.getSiblingByName( oReply.firstChild, "content" ) );
				return true;
			}
		}	
		return false;
	};
	
	Status.prototype.trim = function( s )
	{

		if ( typeof s == "string" )
		{
			for ( var i = 0; i < s.length; ++i )
				if ( s.charCodeAt( i ) > 32 )
					break;
			for ( var j = s.length - 1; j >= 0 ; --j )
				if ( s.charCodeAt( j ) > 32 )
					break;
			return s.substr( i, ( j + 1 ) - i );
		}
		return s;
	};
	
	Status.prototype.xmlToObject = function( oXML )
	{
		var oReturn = new Object();
		if ( oXML.childNodes && oXML.childNodes.length > 0 )
			for ( var i = 0; i < oXML.childNodes.length; ++i )
				if ( oXML.childNodes[ i ].nodeType == 3 || oXML.childNodes[ i ].nodeType == 4 )
					return unescape( oXML.childNodes[ i ].nodeValue );
				else
					oReturn[ oXML.childNodes[ i ].nodeName ] = arguments.callee( oXML.childNodes[ i ] );
		return oReturn;
	};


	/* cookie related wrapper functions */
	
	function cookie()
	{
		this.days = 300 ;
	}
	
	
	cookie.create = function( name, value  ) 
	{
		if ( this.days ) 
		{
			var date = new Date();
			date.setTime( date.getTime()+( this.days *24*60*60*1000 ) );
			var expires = "; expires=" + date.toGMTString();
		}
		else 
			var expires = "";
		document.cookie = name + "=" + value + expires + "; path=/";
	}

	cookie.read = function( name ) 
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return '';
	}
	
	 
	
	

	/* these are some functions for handling callbacks from server */
	
	function setClientMail( sProvider ) 
	{
		var oLinkcontainer = document.getElementById( "webclient" ) ;
		oLinkcontainer.innerHTML = "<br /><a target='_foo' class='webmaillink' href=" + sProvider + ">Naar je webmail</a>" ;
	}
	
	
	
	
	
	
	
	