var var_cookieid = "";
var var_cookie_domain = "";
var var_cookie_path   = "/";

//==========================================
// Get cookie
//==========================================

function my_getcookie( name )
{
	cname = var_cookieid + name + '=';
	cpos  = document.cookie.indexOf( cname );
	
	if ( cpos != -1 )
	{
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);
		
		if (cend == -1)
			cend = document.cookie.length;
	
		return unescape( document.cookie.substring(cstart, cend) );
	}
	
	return null;
}

//==========================================
// Set cookie
//==========================================

function my_setcookie(name, value, sticky)
{
	expire = "";
	domain = "";
	path   = "/";
	
	if ( sticky )
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	
	if ( var_cookie_domain != "" )
		domain = '; domain=' + var_cookie_domain;
	
	if ( var_cookie_path != "" )
		path = var_cookie_path;
	
	document.cookie = var_cookieid + name + "=" + value + "; path=" + path + expire + domain + ';';
}

//==========================================
// Get element by id
//==========================================

function my_getbyid(id)
{
	itm = null;
	
	if (document.getElementById)
		itm = document.getElementById(id);

	else if (document.all)
		itm = document.all[id];

	else if (document.layers)
		itm = document.layers[id];

	
	return itm;
}


//==========================================
// Toggle category
//==========================================

function togglecategory(fid)
{
	saved = new Array();
	clean = new Array();
	
	//-----------------------------------
	// Get any saved info
	//-----------------------------------
	
	if (tmp = my_getcookie('collapseprefs'))
		saved = tmp.split(",");
	
	//-----------------------------------
	// Remove bit if exists
	//-----------------------------------
	
	for(i = 0 ; i < saved.length; i++)
	{
		if (saved[i] != fid && saved[i] != "")
			clean[clean.length] = saved[i];
	}
	
	//-----------------------------------
	// Add?
	//-----------------------------------
	
	if (my_getbyid('box_'+fid).style.display == "")
	{
		clean[clean.length] = fid;
		my_getbyid('box_'+fid).style.display = "none";
		my_getbyid('img_'+fid).src = my_getbyid('img_'+fid).src.replace('up','down');
	}
	else
	{
		my_getbyid('box_'+fid).style.display = "";
		my_getbyid('img_'+fid).src = my_getbyid('img_'+fid).src.replace('down','up');
	}
	
	my_setcookie('collapseprefs', clean.join(','), 1);
}


//==========================================
// Standaard functie waarmee verschillende 
// javascript functies bij laden aangeroepen
// worden.
//==========================================
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


//==========================================
// Openen van links in een nieuw browser venster 
//==========================================
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}



//==========================================
// pop-up voor nieuwsflitsen 
//==========================================
function openWin(url, name, theWidth, theHeight) {
	newwindow=window.open(url,name,'height='+theHeight+',width=' + theWidth+',scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}    
    

//==========================================
// nieuwsflitsen 
//==========================================    
function GetFlits() {
    if (!document.getElementsByTagName) return false;
    if (!document.getElementById) return false;
    if (!(document.getElementById("nieuwsflitsen") || document.getElementById("linkback"))) return false;
    var flitsen = document.getElementById("nieuwsflitsen");
    var links = flitsen.getElementsByTagName("a");
    for (var i=0; i<links.length; i++ ) {
        links[i].destination = links[i].getAttribute("href");
        if(links[i].parentNode.id == "linkback")
        {
            links[i].onclick = function() {
                this.href = "#";
                window.close();
                return false;
            }
            links[i].innerHTML = "sluiten";
        }
        else
        {   
            var tn = links[i].parentNode.tagName.toLowerCase();
            if(tn=='li')
            {
                links[i].onclick = function() {
                    return openWin(this.destination, "MacMinds", 400, 300);
                }
            }
            else
            {
                links[i].target = "_blank";
                links[i].setAttribute("target", "_blank");
            }
        }
   }
}


//==========================================
// aan te roepen functies bij het laden
// van de pagina
//========================================== 
addLoadEvent(GetFlits);
addLoadEvent(externalLinks);


/* From lightbox sourcecode */
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



/** 
	JavaScript Private Message Notifier

	@author http://www.macminds.net/profile.php?id=288
	@package MacMinds
	@modified Sun, 24 Jun 2007 17:00:09 +0200
**/

var mmNotify = {
	blockId: 'pmsnotification',
	backgroundObj: null,
	settingsSaved: false,
	speed: 1, /* 0.5, 1 or 2 are best choices */
	
	show: function( ){
		if( !mmNotify.backgroundObj ) mmNotify.createBackground( );
		setTimeout( "mmNotify.fadeIn( 0 );" , 100 );
	}, 
	
	hide: function( ){
		mmNotify.fadeOut( 6 );
	},
	
	createBackground: function( ){
		var pageSize = getPageSize( );
		
		mmNotify.backgroundObj = document.createElement( "div" );
		mmNotify.backgroundObj.style.display = 'none';
		mmNotify.backgroundObj.style.opacity = 0;
		mmNotify.backgroundObj.style.filter = "alpha(opacity=0)";
		mmNotify.backgroundObj.style.backgroundColor = "#000000";
		mmNotify.backgroundObj.style.position = "absolute";
		mmNotify.backgroundObj.style.top = "0px";
		mmNotify.backgroundObj.style.left = "0px";
		mmNotify.backgroundObj.style.height = pageSize[1] + "px";
		mmNotify.backgroundObj.style.width = "100%";
		mmNotify.backgroundObj.style.zIndex = 998;
		
		mmNotify.backgroundObj.onclick = function( e ){
			if( !e ) var e = window.event;
			
			mmNotify.handleButton( 'ignore' );
		}
		
		document.getElementById( mmNotify.blockId ).style.position = 'fixed';
		document.getElementById( mmNotify.blockId ).style.zIndex = 999;
		
		var blockObj = document.getElementById( mmNotify.blockId );
		
		document.body.appendChild( mmNotify.backgroundObj );
		document.body.appendChild( blockObj );
	}, 
	
	fadeIn: function( v )
	{
		mmNotify.backgroundObj.style.opacity = ( v / 10 );
		mmNotify.backgroundObj.style.filter = 'alpha(opacity=' + ( v / 10 ) + ')';
		mmNotify.backgroundObj.style.display = 'block';
		
		document.getElementById( mmNotify.blockId ).style.opacity = (10/6) * ( v / 10 );
		document.getElementById( mmNotify.blockId ).style.filter = 'alpha(opacity=' + Math.round( (10/6) * ( v / 10 ) ) + ')';
		document.getElementById( mmNotify.blockId ).style.display = 'block';

		if( v < 6 )
		{
			setTimeout( "mmNotify.fadeIn(" + (v+mmNotify.speed) + ");" , 20 );
		}
	},
	
	fadeOut: function( v )
	{
		mmNotify.backgroundObj.style.opacity = ( v / 10 );
		mmNotify.backgroundObj.style.filter = 'alpha(opacity=' + ( v / 10 ) + ')';
		mmNotify.backgroundObj.style.display = 'block';
		
		document.getElementById( mmNotify.blockId ).style.opacity = (10/6) * ( v / 10 );
		document.getElementById( mmNotify.blockId ).style.filter = 'alpha(opacity=' + Math.round( (10/6) * ( v / 10 ) ) + ')';
		document.getElementById( mmNotify.blockId ).style.display = 'block';

		if( v > 0 )
		{
			setTimeout( "mmNotify.fadeOut(" + (v-mmNotify.speed) + ");" , 20 );
		}else
		{
			mmNotify.backgroundObj.style.display = 'none';
			document.getElementById( mmNotify.blockId ).style.display = 'none';
		}
	}, 
	
	handleButton: function( s )
	{
		var checkbox = document.getElementById( 'always_ignore' );
		var uri = "notification.php?action=";
		var ignore = checkbox.checked ? "1" : "0";
		
		
		switch( s )
		{
			case 'inbox':
				uri = uri + "inbox&ignore=" + ignore;
				window.location.href = uri;
				break;
			case 'ignore':			
				uri = uri + "ignore&ignore=" + ignore;
				if( mmNotify.settingsSaved === false )
				{
					my_setcookie( "mm_ignore_notification" , "1" );
					Web.sendRequest( uri , [] , null );
					setTimeout( "mmNotify.hide( );" , 20 );
				}
				mmNotify.settingsSaved = true;
				return false;
				break;
				
			default:
				return false;
				break;
		}
	}
}


/** 
	JavaScript Web Library ('AJAX')

	@author http://www.macminds.net/profile.php?id=288
	@package MacMinds
	@modified Sun, 24 Jun 2007 17:05:09 +0200
**/

var Web = {
	queu: [],
	ondone: null,
	
	checkQueu: function( )
	{
		var buffer = null;
		var callback = null;
		
		for( var i = 0; i < Web.queu.length; i++ )
		{
			if( Web.queu[i][0].readyState == 4 )
			{
				buffer = Web.queu[i][0].responseXML;
				callback = Web.queu[i][1];
				Web.queu.splice( i , 1 ); 
				i--;
				
				if( callback ) callback( buffer );
			}
		}
	},
	
	addQueu: function( socket , callback )
	{
		Web.queu.push( [ socket , callback ] );
	},
	
	sendRequest: function( url , postvars , callback )
	{
		if( !postvars ) var postvars = [];
		postvars = postvars.join( "&" );
		
		var httpSocket = new XMLHttpRequest( );
		if( !httpSocket ) return false;
		
		httpSocket.open( "POST" , url , true );
		httpSocket.onreadystatechange = function(){ Web.checkQueu( ); }
		httpSocket.setRequestHeader( "If-Modified-Since" , "Sat, 1 Jan 2000 00:00:00 GMT" );
		httpSocket.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" );
		httpSocket.setRequestHeader( "Content-Length" , postvars.length );
		httpSocket.setRequestHeader( "Connection" , "close" );
		httpSocket.send( postvars );
		
		Web.addQueu( httpSocket , callback );
	}
}

if( !window.XMLHttpRequest )
{
	window.XMLHttpRequest = function( )
	{
		var Microsoft = ["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0"];
		
		for( var i = 0; i < Microsoft.length; i++ )
		{
			try
			{
				return new ActiveXObject( Microsoft[i] );
			}catch( e ){ }
		}
	}
}