/*
  FILE: functions.js JavaScript
  Created by Pieter Bruining
*/

var info = '';
var hideLayer = '';

// Dummy Function for HREF
function voidClick()
{
}

function changeRowColor(theRow, newColor)
{
  theRow.style.backgroundColor = newColor;
}

function changeThisColor(theThis, newColor)
{
  theThis.style.backgroundColor = newColor;
}

function changeCellColor(theCell, newColor)
{
  theCell.style.backgroundColor = newColor;
}

function changeFirstAndLastOfRowColor(theRow, newColor, last)
{
  theRow.cells[0].style.backgroundColor = newColor;
  theRow.cells[last].style.backgroundColor = newColor;
}

function changeFromToCellColor(theCell, Startx, Starty, Stopx, Stopy, newColor)
{
  var table = theCell.parentNode.parentNode;
  var starty = new Number(Starty);
  var startx = new Number(Startx);
  var stopy = new Number(Stopy);
  var stopx = new Number(Stopx);
  
  theCell.style.backgroundColor = newColor;

  if ((starty == 0)|| (startx == 0))
  {
    return;
  }
  
  if (starty > stopy)
  {
    return;
  }  
  
  var x,y;
  for (x=startx;x<=stopx;x++)
  {
    table.rows[starty].cells[x].style.backgroundColor = newColor;
  }
  for (x=startx;x<=stopx;x++)
  {
    table.rows[stopy].cells[x].style.backgroundColor = newColor;
  }

  return;
  
  for (y=starty;y<=stopy;y++)
  {
    for (x=startx;x<=stopx;x++)
    {
      table.rows[y].cells[x].style.backgroundColor = newColor;
    }
  }
}

function popup(url, options)
{
  try
  {
    document.popper.close();
  } catch (error)
  {
  }
  document.popper = open(url, 'popup', options);
  document.popper.focus();
}

function cleanup()
{
  try
  {
    document.popper.close();
  } catch (error)
  {
  }
}

function frameload(param)
{
  parent.hidden.location = './frameload.php?' + param;
}

function totalOffsetLeft(item)
{
  var r = 0;
  while (item)
  {
    r += item.offsetLeft;
    item = item.offsetParent
  }
  
  return r;
}

function totalOffsetTop(item)
{
  var r = 0;
  while (item)
  {
    r += item.offsetTop;
    item = item.offsetParent
  }
  
  return r;
}

function showMaxPages(maxpages, link, align)
{
  mouseElement = maxpages;
  
  maxpages.style.top = totalOffsetTop(link)+link.offsetHeight;
  switch (align)
  {
    case "LEFT":
    {
      maxpages.style.left = totalOffsetLeft(link) + 'px';
    } break;
    case "RIGHT":
    {
      maxpages.style.left = (totalOffsetLeft(link) + (link.offsetWidth) - (maxpages.offsetWidth)) + 'px';
    } break;
    default:
    {
      maxpages.style.left = (totalOffsetLeft(link) + (link.offsetWidth/2) - (maxpages.offsetWidth/2)) + 'px';
    }
  }
  
  hideLayer = '';
  maxpages.style.visibility = 'visible';
}

function hideMaxPages(maxpages)
{
  hideLayer = maxpages;
}

function checkHideLayer()
{
  if (hideLayer != '')
  {
    if (!mouseOverElement(hideLayer))
    {
      hideLayer.style.visibility = 'hidden';
    }
  }
}

function mouseOverElement(e)
{
  var mx = getMouseX();
  var my = getMouseY();
  var top = totalOffsetTop(e);
  var left = totalOffsetLeft(e);
  
  var n = 5;
  
  if (!(((top+n) < my) && (my < (top+e.offsetHeight-n))))
  {
    return false;
  }
  
  if (!(((left+n) < mx) && (mx < (left+e.offsetWidth-n))))
  {
    return false;
  }
  
  return true;
}

function showMenu(maxpages, link)
{
  maxpages.style.top = (totalOffsetTop(link)+link.offsetHeight) + 'px';
  maxpages.style.left = totalOffsetLeft(link) + 'px';
  maxpages.style.visibility = 'visible';
}

function hideMenu(maxpages)
{
  maxpages.style.visibility = 'hidden';
}

function areYouSure()
{
  return confirm('Weet u dit zeker..?');
}

// Javascript to remember the mouse position..

if (document.layers)
{ // Netscape
  document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove = captureMousePosition;
} else if (document.all)
{ // Internet Explorer
  document.onmousemove = captureMousePosition;
} else if (document.getElementById)
{ // Netcsape 6
  document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e)
{
  if (document.layers)
  {
    xMousePos = e.pageX;
    yMousePos = e.pageY;
    xMousePosMax = window.innerWidth+window.pageXOffset;
    yMousePosMax = window.innerHeight+window.pageYOffset;
  } else if (document.all)
  {
    xMousePos = window.event.x+document.body.scrollLeft;
    yMousePos = window.event.y+document.body.scrollTop;
    xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
    yMousePosMax = document.body.clientHeight+document.body.scrollTop;
  } else if (document.getElementById)
  {
    // Netscape 6 behaves the same as Netscape 4 in this regard
    xMousePos = e.pageX;
    yMousePos = e.pageY;
    xMousePosMax = window.innerWidth+window.pageXOffset;
    yMousePosMax = window.innerHeight+window.pageYOffset;
  }
  
  checkHideLayer();
  checkHidePopup();
}

function getMouseX()
{
  return xMousePos;
}

function getMouseY()
{
  return yMousePos;
}

function onmousewheel(event)
{
  var scrollbars = this.getTemplate("layout").getContent("scrollbars");
  var delta = scrollbars.element().offsetHeight * event.wheelDelta/480;
  scrollbars.element().scrollTop -= delta;
}

//obj.setEvent("onmousewheel", onmousewheel);



/************************************************************************************/
/* Popups */

var activePopup = '';
var activePopupElem = '';

function showPopup(id, elem)
{
  var popup = document.getElementById(id);
  
  popup.style.top = (totalOffsetTop(elem) + elem.offsetHeight) + 'px';
  popup.style.left = (totalOffsetLeft(elem) + (elem.offsetWidth / 2) - (popup.offsetWidth / 2)) + 'px';
  popup.style.visibility = "visible";
  
  activePopup = popup;
  activePopupElem = elem;
}

function checkHidePopup()
{
  var hide = false;
  
  if (activePopup == '')
  {
    return;
  }
  
  if (!mouseInElem(activePopup) && !mouseInElem(activePopupElem))
  {
    activePopup.style.visibility = 'hidden';
    activePopup = '';
    activePopupElem = '';
  }
}

function mouseInElem(elem)
{
  if (xMousePos < totalOffsetLeft(elem) || xMousePos > (totalOffsetLeft(elem) + elem.offsetWidth))
  {
    return false;
  }
  
  if (yMousePos < totalOffsetTop(elem) || yMousePos > (totalOffsetTop(elem) + elem.offsetHeight))
  {
    return false;
  }
  
  return true;
}

/************************************************************************************/
/* Us Twadde Thus js*/

function mouseOut(elem)
{
  elem.className = elem.className.replace(/_hover$/, '');
}

function mouseOver(elem)
{
  elem.className = elem.className + '_hover';
}

/************************************************************************************/

