if (window.attachEvent) window.attachEvent("onload", sfHover);
function sfHover()
{
    var sfEls = document.getElementById("navbar").getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++) 
    {                                   
        sfEls[i].onmouseover=function() 
        {
            this.className+=" hover";
        }
        
        sfEls[i].onmouseout=function() 
        {
            this.className=this.className.replace(new RegExp(" hover\\b"), "");
        }
    }
}

var oBridge;     
function getPrevQuote( sType, nId, sDo )
{       
    var oXML = new klib3.xml();
    oXML.onload = function()
    {
        onLoadQuotes( oXML.getData() );
    };
    oXML.request( "/rpc.php", "post", true, {command:"getquote",_format:"xml",type:sType,id:nId,sdo:sDo} );
}

function getNextQuote( sType, nId, sDo )
{   
    var oXML = new klib3.xml();
    oXML.onload = function()
    {
        onLoadQuotes( oXML.getData() );
    };
    oXML.request( "/rpc.php", "post", true, {command:"getquote",_format:"xml",type:sType,id:nId,sdo:sDo} );
}

function onLoadQuotes(oXML)
{
    var oStatus   = parseStatusResult( oXML );
        
    var oFeedback = document.getElementById( "getquote" );
    if ( oStatus )
    {
        if ( oFeedback )
        {
            oFeedback.className = "form" + ( oStatus.success ? "info" : "error" );
            oFeedback.innerHTML = oStatus.message;
        }
    }
}     

/** Default shizzle */

function getSiblingByName( oNode, sName )
{
    
    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;
}

function getNodeValue( oNode )
{
    if ( oNode )
    //alert(oNode.firstChild);
   //   textnode               cdata
        if ( oNode.nodeType == 3 || oNode.nodeType == 4 )
            return oNode.nodeValue;
        return arguments.callee( oNode.firstChild );
}

function parseStatusResult( oDataXML )
{                    
    if ( oDataXML )
    {
        var oReply = 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;
                
                
            var sMessage = getNodeValue( getSiblingByName( oReply.firstChild, "message" ) );
            
            var sContent = getNodeValue( getSiblingByName( oReply.firstChild, "content" ) );
            
            var bStatus  = sStatus == "OK";
            
            return {
                success:bStatus,
                status:sStatus,
                message:unescape( sMessage ),
                content:sContent
            };
        }
    }
    
    return false;
}




function toPasswordInput(id)
{
    /*document.getElementById(id).type = 'password'; */
    oFake = document.getElementById("textpassword");
    oPassword = document.getElementById("passwordinput");
    oFake.style.display = 'none';
    oPassword.style.display = 'block';
    oPassword.focus();
}

function highlightPart()
{

    var oInput = document.getElementById( 'partID' );
    var oDuration = document.getElementById( 'durationValue' );
    oBridge1.highlightPart( oInput.value != "" ? oInput.value : "<leeg>", oDuration.value );
    oBridge2.highlightPart( oInput.value != "" ? oInput.value : "<leeg>", oDuration.value );
}

function setPercentage()
{
    var oPart         = document.getElementById( 'setPercentageID' );
    var oPercentage    = document.getElementById( 'setPercentageValue' );
    oBridge.setPercentage( oPart.value, oPercentage.value  );
}

function toggleCheckbox( oElement )
{
    var sValue = oElement.name;
    if( sValue == "off" )
    {
        oElement.src = "/media/site/image/form/vinkje_on.png";
        oElement.name = "on"; 
        document.getElementById("agree").value = "1";  
    }
    else
    {
        oElement.src = "/media/site/image/form/vinkje.png";
        oElement.src = "/media/site/image/form/vinkje.png";
        oElement.name = "off";
        document.getElementById("agree").value = "";
    }   
}

function toggleCheckboxReason( oElement, sReason )
{
    var sValue = oElement.name;
    if( sValue == "off" )
    {
        oElement.src = "/media/site/image/form/vinkje_on.png";
        oElement.name = "on"; 
        document.getElementById(sReason).value = sReason;  
    }
    else
    {
        oElement.src = "/media/site/image/form/vinkje.png";
        oElement.src = "/media/site/image/form/vinkje.png";
        oElement.name = "off";
        document.getElementById(sReason).value = "";
    }   
}


function selectCat( oImage, iCatID, iImg)  //oDiv, iCatID, sColor, sDiv, iDiv 
{   
    //document.getElementById("partID").value = iCatID; 
//   / highlightPart();
    
    var aImage = document.getElementsByTagName( "img" );
    for ( var i = 0; i < aImage.length; ++i )
    {
        if ( aImage[ i ].className.match( /imgarchetype/ ) ) 
        {
            var aArchetype = aImage[ i ].id.split("_");
            if( aArchetype[0] == "right" )
                aImage[ i ].src = "/media/site/image/layout/item_"+aArchetype[1]+".gif";  
            else if( aArchetype[0] == "left" )
                aImage[ i ].src = "/media/site/image/layout/item_"+aArchetype[1]+"_off.gif";  
            
        }
    } 
  
    if( !oImage.id )
        var sArchetype = oImage.split("_");
    else
        var sArchetype = oImage.id.split("_");
    document.getElementById("left_"+sArchetype[1]).src = "/media/site/image/layout/item_"+sArchetype[1]+"_active.gif";
    document.getElementById("right_"+sArchetype[1]).src = "/media/site/image/layout/item_"+sArchetype[1]+"_active.gif";
    
    var iChosen = document.getElementById("left_"+sArchetype[1]).getAttribute("name");
    var iReal = document.getElementById("right_"+sArchetype[1]).getAttribute("name");
   
    handleResultText( sArchetype[1], iChosen, iReal );
}

function selectCatNoText( oImage, iCatID, iImg)  //oDiv, iCatID, sColor, sDiv, iDiv 
{   
    var aImage = document.getElementsByTagName( "img" );
    for ( var i = 0; i < aImage.length; ++i )
    {
        if ( aImage[ i ].className.match( /imgarchetype/ ) ) 
        {               
            var aArchetype = aImage[ i ].id.split("_");
            
            aImgSrc = aImage[ i ].src.split("_");       
            //alert(aImgSrc[1]+"test" + aArchetype[1]);
            if( aImgSrc[2] != "active.gif" ) 
            {               
                if( aArchetype[0] == "right" )
                    aImage[ i ].src = "/media/site/image/layout/item_"+aArchetype[1]+".gif";  
                else if( aArchetype[0] == "left" )
                    aImage[ i ].src = "/media/site/image/layout/item_"+aArchetype[1]+"_off.gif";  
            }
        }
    } 
            
    if( !oImage.id )
        var sArchetype = oImage.split("_");
    else
        var sArchetype = oImage.id.split("_");
    
    var aSrcTemp = oImage.src.split("_");  
    
    if (aSrcTemp[2] != "active.gif")
    {                              
        
        var dLeft = document.getElementById("left_"+sArchetype[1]);
        var dRight = document.getElementById("right_"+sArchetype[1]);
    
        if( dLeft )
            dLeft.src = "/media/site/image/layout/item_"+sArchetype[1]+"_on.gif";
        if( dRight )
            dRight.src = "/media/site/image/layout/item_"+sArchetype[1]+"_on.gif";
        
    }     
}

function selectCatNoTextOut( oImage, iCatID, iImg)  //oDiv, iCatID, sColor, sDiv, iDiv 
{   
    if( !oImage.id )
        var sArchetype = oImage.split("_");
    else
        var sArchetype = oImage.id.split("_");
    
    var aSrcTemp = oImage.src.split("_");  
    
    if (aSrcTemp[2] != "active.gif")
    {    
        document.getElementById("left_"+sArchetype[1]).src = "/media/site/image/layout/item_"+sArchetype[1]+"_off.gif";
        document.getElementById("right_"+sArchetype[1]).src = "/media/site/image/layout/item_"+sArchetype[1]+".gif";
        
    }     
}

function selectCatBenchmark( oImage )  //oDiv, iCatID, sColor, sDiv, iDiv 
{   
   // document.getElementById("partID").value = iCatID; 
   // highlightPart();
    
    var aImage = document.getElementsByTagName( "img" );
    for ( var i = 0; i < aImage.length; ++i )
    {
        if ( aImage[ i ].className.match( /imgarchetype/ ) ) 
        {
            var aArchetype = aImage[ i ].id.split("_");
            if( aArchetype[0] == "right" )
                aImage[ i ].src = "media/site/image/layout/item_"+aArchetype[1]+".gif";  
            else if( aArchetype[0] == "left" )
                aImage[ i ].src = "media/site/image/layout/item_"+aArchetype[1]+"_off.gif";  
                
            //if( aArchetype[1] == "yourself" )
            //    aImage[ i ].src = "media/site/image/layout/item_"+aArchetype[1]+"_on.gif";   
        }
    } 
    
    //for( y=1;y<=5;y++ )
    //    document.getElementById("block_"+y).style.backgroundColor = "#f2f2f2";
            
    if( !oImage.id )
        var sArchetype = oImage.split("_");
    else
        var sArchetype = oImage.id.split("_");
    var dLeft = document.getElementById("left_"+sArchetype[1]);
    var dRight = document.getElementById("right_"+sArchetype[1]);
    
    if( dLeft )
        dLeft.src = "/media/site/image/layout/item_"+sArchetype[1]+"_on.gif";
    if( dRight )
        dRight.src = "/media/site/image/layout/item_"+sArchetype[1]+"_on.gif";
}

function selectCatBenchmarkOut( oImage )  //oDiv, iCatID, sColor, sDiv, iDiv 
{   
    if( !oImage.id )
        var sArchetype = oImage.split("_");
    else
        var sArchetype = oImage.id.split("_");
    var dLeft = document.getElementById("left_"+sArchetype[1]);
    var dRight = document.getElementById("right_"+sArchetype[1]);
    
    if( dLeft )
        dLeft.src = "/media/site/image/layout/item_"+sArchetype[1]+"_off.gif";
    if( dRight )
        dRight.src = "/media/site/image/layout/item_"+sArchetype[1]+".gif";
}

function handleResultText( sArchetype, iChosen, iReal )
{
    var oXML = new klib3.xml();
    oXML.onload = function()
    {
        onloadResultText( oXML.getData() );
    };
    oXML.request( "/rpc.php", "post", true, {command:"resulttext",_format:"xml",archetype:sArchetype,chosen:iChosen,real:iReal} );
}

function onloadResultText( oXML )
{
    var oStatus   = parseStatusResult( oXML );
        
    var oFeedback = document.getElementById( "resulttext" );
    if ( oStatus )
    {
        if ( oFeedback )
        {
            oFeedback.className = "form" + ( oStatus.success ? "info" : "error" );
            oFeedback.innerHTML = oStatus.message;
        }
    }
}

function mouseOverCat( oDiv, sColor, sDiv )
{
    var currentDiv = oDiv.id.split("_");
    document.getElementById("type").value = currentDiv[1];   
    selCat = document.getElementById("type").value; 
    if ( selCat == "" )
    {         
        document.getElementById("choosen_"+currentDiv[1]).style.backgroundColor='#000000';
        document.getElementById("real_"+currentDiv[1]).style.backgroundColor='#000000';
    }
    else
    {      
        if (selCat != currentDiv[1]) 
        {
            document.getElementById("choosen_"+currentDiv[1]).style.backgroundColor='';
            document.getElementById("real_"+currentDiv[1]).style.backgroundColor='';
        }
    }
    
}

function showProgress()
{
    var iCurrentQuestion = document.getElementById("questionprogress").value;
    
    if( iCurrentQuestion != "" )
    {
        for( var i=1;i<= 30; i++ )
        {
            if( i == iCurrentQuestion )
            {
            
            } 
        }
    }
}  

function ImageCheck( oImage )
{
    // a = selected
    // b = over
    // c = standaard
    this._image    = oImage;
    this._selected = false;
    this._image.onmouseover = this.__mouseover;
    this._image.onmouseout  = this.__mouseout;
};
ImageCheck.prototype.__mouseover = function()
{
    this.src = this.src.replace( /_Off/, "_On" );
};
ImageCheck.prototype.__mouseout = function()
{
    this.src = this.src.replace( /_On/, "_Off" );
};

function initImageCheck()
{
    var aImage = document.getElementsByTagName( "img" );
    for ( var i = 0; i < aImage.length; ++i )
        if ( aImage[ i ].className.match( /menuitem/ ) )  
            new ImageCheck( aImage[ i ] );
}  

function shortNews( oDiv )
{
    // a = selected
    // b = over
    // c = standaard
    this._div    = oDiv;  
    this._div.onmouseover = this.__mouseover;
    this._div.onmouseout  = this.__mouseout;
};
shortNews.prototype.__mouseover = function()
{       
    var aImage = this.getElementsByTagName("img");
    for( var i = 0; i < aImage.length; ++i )
    {                         
        if ( aImage[ i ].className.match( /newsimage/ ) ) 
        {               
            this.style.backgroundColor = "#f8f8f8";
            this.style.color = "#b32020";
            aImage[ i ].src = aImage[ i ].src.replace( /_off/, "_on" ); 
        } 
        else if( aImage[ i ].className.match( /newsimagebig/ ) )
        {
            aImage[ i ].src = aImage[ i ].src.replace( /_on/, "_off" ); 
        } 
        /*
        else if( aImage[ i ].id == "aan")
            aImage[ i ].className = "imageoff";    
        else if( aImage[ i ].id == "aantwo")
            aImage[ i ].className = "imageoff";
        else if( aImage[ i ].id == "uit")
            aImage[ i ].className = "imageon";    
        else if( aImage[ i ].id == "uittwo")
            aImage[ i ].className = "imageon";
        else if( aImage[ i ].className == "imageon")
            aImage[ i ].className = 'imageoff';    
        else if( aImage[ i ].className == "imageoff")
            aImage[ i ].className = 'imageon';   
            */
               
    }                            
};
shortNews.prototype.__mouseout = function()
{   
    var aImage = this.getElementsByTagName("img");
    for( var i = 0; i < aImage.length; ++i )
    {         
        if ( aImage[ i ].className.match( /newsimage/ ) ) 
        {   
            this.style.backgroundColor = "#f2f2f2";
            this.style.color = "#5d5d5d"; 
            aImage[ i ].src = aImage[ i ].src.replace( /_on/, "_off" ); 
        }   
        else if( aImage[ i ].className.match( /newsimage/ ) )
        {
            aImage[ i ].src = aImage[ i ].src.replace( /_on/, "_off" ); 
        }   
        /*
        else if( aImage[ i ].id == "aan")
            aImage[ i ].className = "imageon";    
        else if( aImage[ i ].id == "aantwo")
            aImage[ i ].className = "imageon";  
        else if( aImage[ i ].id == "uit")
            aImage[ i ].className = "imageoff";    
        else if( aImage[ i ].id == "uittwo")
            aImage[ i ].className = "imageoff";            
            */                
    }                            
};

function shortNewsOptional( oDiv )
{
    // a = selected
    // b = over
    // c = standaard
    this._div    = oDiv;  
    this._div.onmouseover = this.__mouseover;
    this._div.onmouseout  = this.__mouseout;
};
shortNewsOptional.prototype.__mouseover = function()
{       
    var aImage = this.getElementsByTagName("img");
    for( var i = 0; i < aImage.length; ++i )
    {   
        
        if ( aImage[ i ].className.match( /newsimage/ ) ) 
        {   
            this.style.color = "#b32020";
            aImage[ i ].src = aImage[ i ].src.replace( /_off/, "_on" ); 
        } 
        else if( aImage[ i ].className.match( /newsimage/ ) )
        {
            aImage[ i ].src = aImage[ i ].src.replace( /_on/, "_off" ); 
        }                                    
    }                            
};
shortNewsOptional.prototype.__mouseout = function()
{   
    var aImage = this.getElementsByTagName("img");
    for( var i = 0; i < aImage.length; ++i )
    {         
        if ( aImage[ i ].className.match( /newsimage/ ) ) 
        {   
            this.style.color = "#5d5d5d"; 
            aImage[ i ].src = aImage[ i ].src.replace( /_on/, "_off" ); 
        }   
        else if( aImage[ i ].className.match( /newsimage/ ) )
        {
            aImage[ i ].src = aImage[ i ].src.replace( /_off/, "_on" ); 
        }                                  
    }                            
};




function initShortNews()
{
    var aDiv = document.getElementsByTagName( "div" );
    for ( var i = 0; i < aDiv.length; ++i )
        if ( aDiv[ i ].className.match( /shortnews/ ) )  
            new shortNews( aDiv[ i ] );      
}    

function initShortNewsResult()
{
    var aDiv = document.getElementsByTagName( "div" );
    for ( var i = 0; i < aDiv.length; ++i )
        if ( aDiv[ i ].className.match( /shortnewsresult/ ) )  
            new shortNewsOptional( aDiv[ i ] );      
} 

function initShortNewsOptional()
{
    var aDiv = document.getElementsByTagName( "div" );
    for ( var i = 0; i < aDiv.length; ++i )
        if ( aDiv[ i ].className.match( /shortnewsoptionalresult/ ) )  
            new shortNewsOptional( aDiv[ i ] );      
} 

function connectToCat( oDiv, sColor )
{
    var currentDiv = oDiv.id.split("_");   
    var nodeList = document.getElementById('benchmark').getElementsByTagName('div'); 
    for(var x=0;x<nodeList.length;x++) 
    {
        nodeList[x].style.backgroundColor = "#f8f8f8";
    }
    document.getElementById("choosen_"+currentDiv[1]).style.backgroundColor = "#"+sColor; 
    document.getElementById("real_"+currentDiv[1]).style.backgroundColor = "#"+sColor;     
} 

function Locator( oElement, oParent )
{
  this._element   = oElement;
  this.__construct( oParent );
};
Locator.prototype.__construct = function( oParent )
{
  this._getOffset( oParent );
};
Locator.prototype._getOffset = function( oParent )
{
  if ( typeof oParent != "object" )
    oParent = document.body;

  var oCurrent = this._element;
  this.x       = 0;
  this.y       = 0;

  do
  {
    this.x += oCurrent.offsetLeft;
    this.y += oCurrent.offsetTop;
  }
  while( oCurrent != oParent && ( oCurrent = oCurrent.offsetParent ) );
};





function MCP( sControl )
{
  this.__construct( sControl );
};

MCP.prototype.__construct = function( sControl )
{
    
  this._control  = document.getElementById( sControl );
  this._canvas   = new Keen.animation( this._control );
  this._position = new Object();
  var aLink      = this._control.getElementsByTagName( "a" );
  
  for ( var i = 0; i < aLink.length; ++i )
  {
    if ( aLink[ i ].className.match( /locator/ ) ) //  placement identifiers
    {
        this._position[ aLink[ i ].name ] = new Locator( aLink[ i ].parentNode, this._control );
    }
    else if ( aLink[ i ].href.match( /#[a-zA-Z0-9]+/ ) ) //  named references
    {
      aLink[ i ]._parent = this;
      aLink[ i ].onclick = this.__clickhandle;
    }
  }
};

MCP.prototype.__clickhandle = function()
{
  if (this.href.substr((this.href.length-2), (this.href.length)) == '31')
  {
    new StoreAnswer( this );
    document.location.href='/test/';
  }
  else
  {
    this._parent.focus( this.href.match( /#([a-zA-Z0-9]+)/ )[ 1 ] );
    new StoreAnswer( this );
    var qId = this.href.substr((this.href.length-2), (this.href.length));
    if (isNaN(qId))
    {
      qId = this.href.substr((this.href.length-1), (this.href.length));
    }
    if (qId !='a')
    {
        document.getElementById('status_icon'+qId).src='/media/site/image/layout/progress_on.gif';
    }
  }
   return false;
};
MCP.prototype.focus = function( sSection )
{
  if (sSection == 'questioncodeintermezzo_dillema')
  {
    document.getElementById('dillemmaheader').style.display='block';
    document.getElementById('sliderheader').style.display='none';
    document.getElementById('progress_bar').style.display='none';
  }
  else if (sSection == 'questioncodeslider')
  {
    document.getElementById('dillemmaheader').style.display='none';
    document.getElementById('sliderheader').style.display='block';
    document.getElementById('progress_bar').style.display='none';
  }
  else
  {
    document.getElementById('dillemmaheader').style.display='none';
    document.getElementById('sliderheader').style.display='none';
    document.getElementById('progress_bar').style.display='block';
  }
  this._canvas.slide( 0, -this._position[ sSection ].y, Keen.movement.smooth, 15 )
};

function StoreAnswer( oLink )
{
  var aInput  = oLink.parentNode.parentNode.getElementsByTagName( "input" );
  //            A     DIV.button DIV.page   INPUT
  if ( aInput.length == 1 )
  {
  
   this._input = aInput[ 0 ];
   this._input.value = oLink.id;
   
   this.store( this._input );
  }
  else
  {
    for ( var i = 0; i < aInput.length; ++i )
      if ( aInput[ i ].className.match( /newslider/ ) && aInput[ i ].value != "" )
      {
        this._input = aInput[ i ];
        this.store( this._input );
        break;
      }
  }
  //this.store( this._input );
};
StoreAnswer.prototype.store = function( oInput )
{   
  if (oInput )
  {
    var oXML = new Keen.xml();
    oXML.request( "/rpc.php", "post", true, {command:"surveysave",_format:"xml",question:oInput.name,answer:oInput.value} );
  }
};

function hasClass( oElement, sClassName )
{
    if ( typeof oElement.className != "string" || oElement.className == "" )
        return false;

    var aClass = oElement.className.toString().split( " " );
    for ( var i = 0; i < aClass.length; ++i )
        if ( aClass[ i ] == sClassName )
            return true;
    return false;
}

function initSliders()
{
    var aInput = document.getElementsByTagName( "input" );
    for ( var i = 0; i < aInput.length; ++i )
        if ( aInput[ i ].className == "newslider" )
        {
            var oSlider = aInput[ i ].nextSibling;
            while ( oSlider.nodeType != 1 && !hasClass( oSlider, "slider" ) && oSlider.nextSibling )
                oSlider = oSlider.nextSibling;
            if ( oSlider.nodeType == 1 && hasClass( oSlider, "slider" ) )
                new Slider( oSlider, aInput[ i ] );
        }
}

/*
function Slider( oContainer, oInput )
{
    this._container = oContainer;
    this._input     = oInput;
    this.init();
};
Slider.prototype.init = function()
{
    var aChild = this._container.getElementsByTagName( "div" );
    for ( var i = 0; i < aChild.length; ++i )
    {
        switch( aChild[ i ].className.toLowerCase() )
        {
            case "sliderpane":
                this._pane = new klib3.animation( aChild[ i ] );
//                this._pane.attachMethod( "mousedownHandler", this.__onmousedown );
//                this._pane.attachMethod( "mouseupHandler", this.__onmouseup );
//                this._pane.attachEvent( "mousedown", "mousedownHandler" );
//                this._pane.attachEvent( "mouseup", "mouseupHandler" );
//                this._pane._master = this;

this._pane._object.onmousedown = this.__onmousedown;
this._pane._object.onmouseup   = this.__onmouseup;
this._pane._object._master     = this;

                break;
            case "slidercatch":
//                this._back = new klib3.dynamic( aChild[ i ] );
//                this._back.attachMethod( "mousemoveHandler", this.__onmousemove );
//                this._back.attachMethod( "mouseupHandler", this.__onmouseup );
//                this._back.attachMethod( "mouseoutHandler", this.__onmouseout );
//                this._back.attachMethod( "mouseoverHandler", this.__onmouseover );
//                this._back.attachMethod( "mouseclickHandler", this.__onmouseclick );
//                this._back.attachEvent( "mousemove", "mousemoveHandler" );
//                this._back.attachEvent( "mouseup", "mouseupHandler" );
//                this._back.attachEvent( "mouseout", "mouseoutHandler" );
//                this._back.attachEvent( "mouseover", "mouseoverHandler" );
//                this._back.attachEvent( "click", "mouseclickHandler" );
//                this._back._master = this;

this._back._object.onmousemove  = this.__onmousemove;
this._back._object.onmouseup    = this.__onmouseup;
this._back._object.onmouseout   = this.__onmouseout;
this._back._object.onmouseover  = this.__onmouseover;
this._back._object.onmouseclick = this.__onmouseclick;
this._back._object._master      = this;

                break;
        }
    }

    var aInput = this._input.parentNode.getElementsByTagName( "input" );
    for ( var i = 0; i < aInput.length; ++i )
        if ( aInput[ i ].type == "hidden" && aInput[ i ].name.indexOf( "__" ) > 0 )
        {
            var sAttribute = aInput[ i ].name.substr( aInput[ i ].name.indexOf( "__" ) + 2, 3 );
            if ( sAttribute && aInput[ i ].value != "" )
                this[ "_" + sAttribute + "value" ] = parseInt( aInput[ i ].value );
        }

    this._main = new klib3.dynamic( this._container );
    this._main._master = this;

    this._margin = ( this._back._width - this._main._width ) / 2;

    if ( typeof this._minvalue != "number" )
        this._minvalue = 0;
    if ( typeof this._maxvalue != "number" )
        this._maxvalue = 100;

    this.setSliderToValue();
};
Slider.prototype.__onmousedown = function( e ) // the scope of execution of this event lies inside the this._back property
{
    this._master.mousedown( e );

    if ( document.onselectstart ) // prevent text selection for IE specific
        document.onselectstart = function () { return false; };
    return false; // prevent text selections for browsers
};
Slider.prototype.__onmouseup = function( e ) // the scope of execution of this event lies inside the this._pane or this._back property
{
    this._master.mouseup( e );
};
Slider.prototype.__onmousemove = function( e ) // the scope of execution of this event lies inside the this._back property
{
    this._master.mousemove( e );
};
Slider.prototype.__onmouseout = function( e ) // the scope of execution of this event lies inside the this._back property
{
    this._master.mouseout( e );
};
Slider.prototype.__onmouseover = function( e ) // the scope of execution of this event lies inside the this._back property
{
    this._master.mouseover( e );    
};
Slider.prototype.__onmouseclick = function( e ) // the scope of execution of this event lies inside the this._back property
{
    this._master.mouseclick( e );    
};

Slider.prototype.mouseclick = function( e )
{
    var nX = ( this.getMouseOffset( e ) ).x - this._margin;
    if ( nX < 0 )
        nX = 0;
    else if ( nX > this._main._width )
        nX = this._main._width;
    this._pane.slide( nX, this._pane._y, klib3.movement.smooth, 5 );

    var nValue        = Math.round( ( 100 / this._main._width ) * this._pane._x );
    this._input.value = this._minvalue + Math.round( ( ( this._maxvalue - this._minvalue ) / 100 ) * nValue );
//    this._input.value = Math.round( ( 100 / this._main._width ) * nX );

    if ( this._main._object.className.indexOf( "answered" ) < 0 )
        this._main._object.className += " answered";
};
Slider.prototype.mouseout = function( e )
{
    this._hover = false;
    if ( this._dragging )
        this.setSliderToValue();
};
Slider.prototype.mouseover = function( e )
{
    this._hover = true;
};
Slider.prototype.mousedown = function( e )
{
    this._back.setStyle( "z-index", 10 ); // put the event catcher in front of the pane
    this._pane.setStyle( "z-index", 0 );  // ^^
    this._main._object.className += " dragging"; // put the special hand cursor on the entire object by setting the className

    this._hover        = true;
    document._master   = this;
    document.onmouseup = this.__onmouseup;

    this._dragging = true;
};
Slider.prototype.mouseup = function( e )
{
    document.onmouseup = null;

    if ( !this._hover )
    {
        this._dragging = false;
    }
    else if ( this._dragging )
    {
        this._dragging    = false;
        this._hover       = false;
        var nValue        = Math.round( ( 100 / this._main._width ) * this._pane._x );

        var nValue        = Math.round( ( 100 / this._main._width ) * this._pane._x );
        this._input.value = this._minvalue + Math.round( ( ( this._maxvalue - this._minvalue ) / 100 ) * nValue );
//        this._input.value = this._minvalue + Math.round( ( ( this._maxvalue - this._minvalue ) / 100 ) * nValue );

        if ( this._main._object.className.indexOf( "answered" ) < 0 )
            this._main._object.className += " answered";
    }

    if ( this._main._object.className.indexOf( "dragging" ) >= 0 )
        this._main._object.className = this._main._object.className.replace( /dragging/gi, "" );

    this._back.setStyle( "z-index", 0 );  // restore the 'natural' order of the event catcher and the pane
    this._pane.setStyle( "z-index", 10 ); // ^^
};
Slider.prototype.mousemove = function( e, bSlide )
{
    if ( this._dragging )
    {
        var nX = ( this.getMouseOffset( e ) ).x - this._margin;
        if ( nX < 0 )
            nX = 0;
        else if ( nX > this._main._width )
            nX = this._main._width;
        if ( typeof bSlide == "boolean" && bSlide )
            this._pane.slide( nX, this._pane._y, klib3.movement.smooth, 5 );
        else
            this._pane.move( nX, this._pane._y );
    }
};
Slider.prototype.getMouseOffset = function( e )
{
    return {
        x:( e && e.layerX ? e.layerX : window.event.offsetX ),
        y:( e && e.layerY ? e.layerY : window.event.offsetY )
    };

};

Slider.prototype.setSliderToValue = function()
{
    var nValue = parseInt( this._input.value );

    if ( isNaN( nValue ) )
        nValue = ( this._minvalue + this._maxvalue ) / 2;
    else if ( nValue > this._maxvalue )
        nValue = this._maxvalue;
    else if ( nValue < this._minvalue )
        nValue =  this._minvalue;
    this._input.value = nValue;

    nValue = Math.round( ( 100 / ( this._maxvalue - this._minvalue ) ) * ( nValue - this._minvalue ) );
    this._pane.slide( ( this._main._width / 100 ) * parseInt( nValue ), this._pane._y, klib3.movement.smooth, 5 );
};
Slider.prototype.preventSelection = function()
{
};
Slider.prototype.allowSelection = function()
{
};
*/
function toggleCustomRadio( oImage )
{
    //  Haal de input op die bij de image hoort (op id gelijkenis)
    var oInput   = document.getElementById( oImage.id.replace( /[a-z0-9]+_image/i, "input" ) );
    
    //  Welke waarde gaan we zetten?
    var aValue   = oImage.id.match( /[a-z0-9]+_([a-z0-9]+)_[a-z0-9]+/i );
    var sValue   = "";
    if ( aValue.length > 1 )
        sValue = aValue[ 1 ];

    //  Reset de huidige selectie (if any)
    if ( oInput.value != "" )
    {           
        var x = oImage.id.replace( new RegExp( sValue ), oInput.value );
        var oCurrentImage = document.getElementById( oImage.id.replace( new RegExp( sValue ), oInput.value ) );
        oCurrentImage.src = oCurrentImage.src.replace( /_on/, "_off" );
    }

    //  Keer de huidige input value om
    oInput.value = sValue;

    //  Vervang de afbeelding aan de hand van de nieuwe input value
    oImage.src = oImage.src.replace( oInput.value == sValue ? /_off/ : /_on/, oInput.value == sValue ? "_on" : "_off" );
}

function toggleCustomRadioByLabel( oLabel )
{
    
   var oDiv = oLabel.parentNode;
   var oImage=oDiv.getElementsByTagName("IMG")[0];
   
   toggleCustomRadio( oImage );
    
}

function handleBenchmarkForm( )
{
    var sGender = document.getElementById("gender").value;
    var iAge = document.getElementById("age").value;
    var sJob = document.getElementById("job").value;
    
    var oXML = new klib3.xml();
    oXML.onload = function()
    {
        onLoadBenchmark( oXML.getData() );
    };
    oXML.request( "/rpc.php", "post", true, {command:"benchmarkform",_format:"xml",gender:sGender,age:iAge,job:sJob} );
}

function onloadBenchmarkForm( sGender, iAge, sJob )
{
    var oXML = new klib3.xml();
    oXML.onload = function()
    {
        onLoadBenchmark( oXML.getData() );
    };
    oXML.request( "/rpc.php", "post", true, {command:"benchmarkform",_format:"xml",gender:sGender,age:iAge,job:sJob} );
}

function onLoadBenchmark(oXML)
{
    var oStatus   = parseStatusResult( oXML );
        
    var oFeedback = document.getElementById( "benchmarkcontent" );
    if ( oStatus )
    {
        if ( oFeedback )
        {
            oFeedback.className = "form" + ( oStatus.success ? "info" : "error" );
            oFeedback.innerHTML = oStatus.message;
			//writeBenchmarkPie(oStatus.content);
        }
    }
}

function handleStopTips( iCat )
{
    
    var oXML = new klib3.xml();
    oXML.onload = function()
    {
        onLoadStopTips( oXML.getData() );
    };
    oXML.request( "/rpc.php", "post", true, {command:"stop5form",_format:"xml",catid:iCat} );
}

function onLoadStopTips(oXML)
{
    var oStatus   = parseStatusResult( oXML );
        
    var oFeedback = document.getElementById( "stop5content" );
    if ( oStatus )
    {
        if ( oFeedback )
        {
            oFeedback.className = "form" + ( oStatus.success ? "info" : "error" );
            oFeedback.innerHTML = oStatus.message;
        }
    }
}

function getSiblingByName( oNode, sName )
{
    
    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;
}

function getNodeValue( oNode )
{
    if ( oNode )
    //alert(oNode.firstChild);
   //   textnode               cdata
        if ( oNode.nodeType == 3 || oNode.nodeType == 4 )
            return oNode.nodeValue;
        return arguments.callee( oNode.firstChild );
}

function parseStatusResult( oDataXML )
{                    
    if ( oDataXML )
    {
        var oReply = 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;
                
                
            var sMessage = getNodeValue( getSiblingByName( oReply.firstChild, "message" ) );
            
            var sContent = getNodeValue( getSiblingByName( oReply.firstChild, "content" ) );
            
            var bStatus  = sStatus == "OK";
            
            return {
                success:bStatus,
                status:sStatus,
                message:unescape( sMessage ),
                content:sContent
            };
        }
    }
    
    return false;
}



function checkPersonaldataForm()
{
    var geb_day = document.getElementById('geb_day');
    var geb_month = document.getElementById('geb_month');
    var geb_year = document.getElementById('geb_year');
    var job = document.getElementById('job');
    if (geb_year.value == 'none' || geb_month.value == 'none' || geb_day.value == 'none' || job.value == 'none')
    {
        document.getElementById('personaldata_submit_active').style.display='none';
        document.getElementById('personaldata_submit_disabled').style.display='block';
    }
    else
    {
        document.getElementById('personaldata_submit_active').style.display='block';
        document.getElementById('personaldata_submit_disabled').style.display='none';
    }
    
}

function handleNotChosenForm()
{
    var not1 = document.getElementById('nietgekozen1reason_input');
    var not2 = document.getElementById('nietgekozen2reason_input');
    var not3 = document.getElementById('nietgekozen3reason_input');
    
    if (not1.value == '' || not2.value == '' || not3.value == '')
    {
       document.getElementById('notchosen_enabled').style.display='none';
       document.getElementById('notchosen_disabled').style.display='block';
    }
    else
    {
       document.getElementById('notchosen_enabled').style.display='block';
       document.getElementById('notchosen_disabled').style.display='none';
    }
}

function writeBenchmarkPie(id)
{                         
	var so = new SWFObject( "/media/site/flash/PieChart.swf", "PieChart1", "230", "230", "9,0,0,0", "#FFFFFF" );
    so.addParam( "quality", "high" );
	so.addParam( "wmode", "transparent" );  
    so.addVariable( "id", "1" ); 
    so.write( "firstflash" );
    
    var so = new SWFObject( "/media/site/flash/PieChart.swf", "PieChart2", "230", "230", "9,0,0,0", "#FFFFFF" );
    so.addParam( "quality", "high" ); 
    so.addParam( "wmode", "transparent" );  
    so.addVariable( "id", ""+id+""  ); 
    so.write( "secondflash" );
    
	oBridge1 = new FlashBridge( "PieChart1" );
	oBridge2 = new FlashBridge( "PieChart2" );
}

function activateNext()
{
    document.getElementById("nextbtnoff").style.display = 'none';
    oElement = document.getElementById("questioncode1");
    oElement.style.display = 'block';
    //throbber_hide();
}

function Slider( sElement, iMinvalue, iMaxvalue )
{

    this.pressed        = false;
    this.element        = document.getElementById(sElement);
    this.element.width    = this.element.offsetWidth;
    this.element.pos    = this.getElementPosition( this.element );

    this.formelement            = document.createElement("input");
    this.formelement.type        = "hidden";
    this.formelement.name        = sElement;
    this.formelement.value        = iMaxvalue/2;
    this.formelement.className  ='newslider';
    this.element.appendChild(this.formelement);
    this.slider                    = document.createElement("div");
    this.slider.className        = "slider";
    this.slider.width            = 64;
    this.element.appendChild(this.slider);
    
    this.slidercatch            = document.createElement("div");
    this.slidercatch.className    = "slidercatch";
    this.element.appendChild(this.slidercatch);

    this.slidercatch.onmousemove    = this.slide;
    //this.slider.onmouseout = this.out;
    this.slidercatch.onmouseout        = this.out;
    this.slidercatch.onmousedown    = this.press;
    this.slidercatch.onmouseup        = this.release;
    this.slidercatch.onmouseover    = this.hover;
    this.slidercatch.onselectstart    = function(){return false;};
    this.slidercatch._parent        = this;

    this.minvalue    = iMinvalue;
    this.maxvalue    = iMaxvalue;
    this.pixelvalue = (this.maxvalue - this.minvalue) / this.element.width;

    this.rightbound = this.element.width - this.slider.width;
}

Slider.prototype.slide = function slide( e )
{
    if(!this._parent)
        this._parent = this;
    if(this._parent.pressed)
    {
        e = e ? e : window.event;
        var aPos = this._parent.getCursorPosition(e,this._parent.element);
        this._parent.slider.style.left = aPos[0]-(this._parent.slider.width/2)+"px";

        if(this._parent.slider.style.left)
        {
            if(parseInt(this._parent.slider.style.left) < 0)
                this._parent.slider.style.left = "0px";        
            if(parseInt(this._parent.slider.style.left) > this._parent.rightbound)
                this._parent.slider.style.left = this._parent.rightbound+"px";    
        }
    }
}

Slider.prototype.press = function press( e )
{
    this._parent.pressed = true;
    this._parent.slide( e );
    return false;
}

Slider.prototype.release = function release( e )
{
    this._parent.setValue( e );
    this._parent.pressed = false;
}

Slider.prototype.hover = function hover( e )
{
    this._parent.slider.className = "slider sliderhover";
}

Slider.prototype.setValue = function setValue( e )
{
    var aPos = this.getCursorPosition(e,this.element);    
    this.formelement.value = Math.round( this.minvalue + (aPos[0]*this.pixelvalue) );
    if( this.formelement.value < this.minvalue )
        this.formelement.value = this.minvalue;
    if( this.formelement.value > this.maxvalue )
        this.formelement.value = this.maxvalue;    
}

Slider.prototype.getCursorPosition = function getCursorPosition( e, oElement )
{
    e        = e ? e : window.event;
    aPos    = this.element.pos;  
    aCoords    = new Array(0,0);

    if(isNaN(window.scrollX))
    aCoords = new Array(e.clientX + 
              document.documentElement.scrollLeft + 
              document.body.scrollLeft - aPos[0], 
              e.clientY + 
              document.documentElement.scrollTop + 
              document.body.scrollTop - aPos[1]);
    else
    aCoords = new Array(e.clientX + window.scrollX - aPos[0], 
              e.clientY + window.scrollY - aPos[1]);

    return aCoords;
}
Slider.prototype.getElementPosition = function getElementPosition( oElement ) 
{
    aPosition = new Array(0,0);
    if (oElement.offsetParent)
    {
        do 
        {
            aPosition[0] += oElement.offsetLeft;
            aPosition[1] += oElement.offsetTop;
        } 
        while (oElement = oElement.offsetParent);
    }
    return aPosition;
}

Slider.prototype.out = function out( e )
{
    this._parent.slider.className = "slider";
    if(this._parent.pressed)
        this._parent.setValue( e );
    this._parent.pressed = false;
}


function initSlideShow()
{
      window.addEvent('domready', function(){
        var data = {
          'header_0.jpg': { caption: '' }, 
          'header_1.jpg': { caption: '' }, 
          'header_2.jpg': { caption: '' }, 
          'header_3.jpg': { caption: '' }, 
          'header_4.jpg': { caption: '' },
          'header_5.jpg': { caption: '' }, 
          'header_6.jpg': { caption: '' }, 
          'header_7.jpg': { caption: '' }, 
          'header_8.jpg': { caption: '' }, 
          'header_9.jpg': { caption: '' }
        };
        var myShow = new Slideshow('headerimage', data, { loader:false, captions: false, controller: false, height: 165, hu: '/media/site/image/header/', width: 386});
      });
}

function showSub(what) 
{
    var left  = 'subnavleft_'+what; 
    var right = 'subnavright_'+what; 
    
    document.getElementById(left).className='subleft';
    document.getElementById(right).className='subright';
}

function hideSub(what) 
{
    var left  = 'subnavleft_'+what; 
    var right = 'subnavright_'+what; 
    
    document.getElementById(left).className='subleft_off';
    document.getElementById(right).className='subright_off';
}

