/*
  -----------------------------------------------
 START ---> LEFT MENU - POSITIONING
 The following is to keep the left menu in view
 -----------------------------------------------
 */
var lastX, lastY, currentX, currentY;
var footerOriginalPosition;

function recordbeginvalues()
{
    footerOriginalPosition = document.getElementById("cntFooter").offsetTop;
	if (document.getElementById&&!document.all)
	{
		lastY=window.pageYOffset;
		lastX=window.pageXOffset;
	}
	else
	{
		lastY=document.documentElement.scrollTop;
		lastX=document.documentElement.scrollLeft;
	}
//	startPolling();
}
/* 
 -----------------------------------------------
 startpolling is called in the load of the html body
 -----------------------------------------------
 */
function startPolling()
{
	recordbeginvalues();
	setInterval("poll()",500);
}
function poll()
{
	if (document.getElementById && !ie)
	{   // Voor niet ie wel DOM
		currentX=window.pageXOffset;
		currentY=window.pageYOffset;
	}
	else
	{   // Voor ie en geen DOM
		currentX=document.documentElement.scrollLeft;
		currentY=document.documentElement.scrollTop;
	}
	if (lastX!=currentX || lastY!=currentY)
	{
		//alert('The Page Was Scrolled\n lastX '+lastX+' currentX'+currentX+'\n lastY '+lastY+' currentY '+currentY);
		lastX=currentX;
 	    if (currentY > 210)
		{
			//alert('Start to move div');
			//alert('currentY=' + currentY);
    		moveDivTo(0,currentY - 210);
    		showDiv('cntKolomLinks');
			//alert('end to move div');
		}
		else
		{
			//alert('Start to move div to original position');
    		moveDivTo(0,0);
    		showDiv('cntKolomLinks');
			//alert('end to move div');
		}
		lastY=currentY;
	}

    //Uitgezet: Is waarschijnlijk niet meer nodig, wordt nu afgehandeld in css. 
    var kolomLinksHeight = document.getElementById("cntKolomLinks").offsetHeight;
    var cntContentHeight = document.getElementById("cntContent").offsetHeight;
    var footerHeight = document.getElementById("cntFooter").offsetHeight;
    var mainpanelHeight = document.getElementById("mainPanel").offsetHeight;
    var kolomRechtsHeight = document.getElementById("cntKolomRechts").offsetHeight;
 	var winHeight = findPageHeight();

	if (ie6)
	{ // Dit is voor linkerkolom en rechterkolom 
	    if ((kolomLinksHeight >= (winHeight - 220 - footerHeight)) || 
	    (mainpanelHeight > (winHeight - 220 - footerHeight)) ||
	    (kolomRechtsHeight > (winHeight - 220 - footerHeight)) )
	    {
		 	if ((kolomLinksHeight >= mainpanelHeight) && (kolomLinksHeight >= kolomRechtsHeight))
			{
			    //alert("links");
				moveFooterDivTo(0, 220 + kolomLinksHeight);
			}
			else if ((kolomRechtsHeight >= mainpanelHeight) && (kolomRechtsHeight >= kolomLinksHeight))
			{
			    //alert("rechts");
			    moveFooterDivTo(0, 220 + kolomRechtsHeight);
			}  
			else
			{
			    // ie method works with mainpanelHeight but not with Mozilla 
				moveFooterDivTo(0, 250 + mainpanelHeight);
			}
		}
	}
	else
	{
	    var useThisHeight = cntContentHeight;
		if ((kolomLinksHeight >= (winHeight - 220 - footerHeight)) || 
	    (useThisHeight > (winHeight - 230 - footerHeight)))
	    {
		 	if ( kolomLinksHeight > useThisHeight)
			{
				moveFooterDivTo(0, 220 + kolomLinksHeight);
			}
			else
			{
				moveFooterDivTo(0, 220 + useThisHeight);
			}
		}
	}
}


function moveFooterDivTo(x,y)
{
	myReference = getRefToDiv( 'cntFooter' );
	if( !myReference ) 
	{
	    alert('return = done nothing!'); 
		return; 
	}
    //alert('continue! - 1'); 
	if( myReference.style )
	{ 
        //alert('continue!- 2'); 
		myReference = myReference.style;
	}
	var noPx = document.childNodes ? 'px' : 0;
	myReference.left = x + noPx;
    myReference.top = y + noPx;
    //alert('myReference.top=' + myReference.top);
 	
}


function showDiv(divID_as_a_string) {
  //get a reference as above ...
  myReference = getRefToDiv(divID_as_a_string);
  if( !myReference ) {
    window.alert('Nothing works in this browser');
    return; //don't go any further
  }
  //alert("1");
  //now we have a reference to it
  if( myReference.style ) {
    //alert("2");
    //DOM & proprietary DOM
    myReference.style.visibility = 'visible';
  } else {
    //alert("3");
    //layers syntax
    myReference.visibility = 'show';
  }
}

function getRefToDiv(divID,oDoc) {
   if( !oDoc ) 
   { 
   		oDoc = document;
   }
   if( document.layers )
   {
       if( oDoc.layers[divID] )
       {
        	return oDoc.layers[divID]; 
       } 
       else
       {
           //repeatedly run through all child layers
           for( var x = 0, y; !y && x < oDoc.layers.length; x++ )
           {
               //on success, return that layer, else return nothing
               y = getRefToDiv(divID,oDoc.layers[x].document);
           }
           return y;
       }
   }
   if( document.getElementById ) 
   {
       return document.getElementById(divID);
   }
   if( document.all )
   {
       return document.all[divID];
   }
   return false;
}

function findPageHeight()
{
    var winWidth, winHeight; 
	var d=document;
	if (typeof window.innerWidth!='undefined')
	{
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	}
	else if ( d.documentElement
	&& typeof d.documentElement.clientWidth!='undefined'
	&& d.documentElement.clientWidth!=0 )
	{
		winWidth = d.documentElement.clientWidth;
		winHeight = d.documentElement.clientHeight;
	} 
	else if ( d.body
	&& typeof d.body.clientWidth!='undefined') 
	{
		winWidth = d.body.clientWidth;
		winHeight = d.body.clientHeight;
	}
	//alert('winWidth: ' + winWidth
	//+ '\nwinHeight: ' + winHeight);
	return winHeight;
}


function moveDivTo(x,y)
{// Move de linkerkolom - voor het scrollen van de linker kolom.
	myReferenceLinkerKolom = getRefToDiv( 'cntKolomLinks' );
	if( !myReferenceLinkerKolom ) 
	{
	    alert('return = done nothing!'); 
		return; 
	}
    //alert('continue! - 1'); 
	if( myReferenceLinkerKolom.style )
	{ 
        //alert('continue!- 2'); 
		myReferenceLinkerKolom = myReferenceLinkerKolom.style;
	}
	var noPx = document.childNodes ? 'px' : 0;
	//alert("noPx=" + noPx);
	myReferenceLinkerKolom.left = x + noPx;
    //myReferenceLinkerKolom.top = y + noPx;
    
 	var winHeight = findPageHeight();
 	//alert('winHeight=' + winHeight);
	if (
		   (
		   ((document.getElementById("cntKolomLinks").offsetHeight) <= (document.getElementById("cntFooter").offsetTop)) 
		   && ((document.getElementById("cntKolomLinks").offsetHeight) < (winHeight - 210))
		   && ((document.getElementById("cntKolomLinks").offsetHeight) > (document.getElementById("cntKolomRechts").offsetHeight))  
		   )
		   ||
		   (
		   ((document.getElementById("cntKolomRechts").offsetHeight) <= (document.getElementById("cntFooter").offsetTop))
           && ((document.getElementById("cntKolomLinks").offsetHeight) <= (document.getElementById("cntKolomRechts").offsetHeight))
           )  
	   )
	{
	    //alert('if myReferenceLinkerKolom.top=' + myReferenceLinkerKolom.top);
	    myReferenceLinkerKolom.top = y + noPx;
	}
	else
	{
        //alert('else myReferenceLinkerKolom.top=' + myReferenceLinkerKolom.top);
	    myReferenceLinkerKolom.top = 0;
	}
 	
}
/* 
-----------------------------------------------
 END ---> LEFT MENU - POSITIONING
 The previous is to keep the left menu in view
 -----------------------------------------------
 */