  var defaultDashboardColor  = 'blue';
  var lightBoxColors         = new Array('light-green', 'green', 'dark-green', 'orange-brown', 'red', 'light-purple', 'blue', 'light-blue');
  var lightBoxTypes          = new Array('small', 'medium', 'large', 'extralarge', 'login');

  /**
  * Return the current dashboard color
  *
  * @param void
  * @return string
  */
  function getDashBoardColor()
  {
    var elem = null;

    if (elem = document.getElementById('page'))
    {
      var className = elem.className;

      className = className.replace(/page-/, '');

      if (lightBoxColorExists(className))
        return className;
    }

    return defaultDashboardColor;
  }

  /**
  * Check if a certain lightbox color exists
  *
  * @param string color
  * @return boolean
  */
  function lightBoxColorExists(color)
  {
    if (color == null)
      return false;

    if (lightBoxColors)
    {
      var numLightBoxColors = lightBoxColors.length;

      for (i = 0; i <= numLightBoxColors; i++)
      {
        if (color == lightBoxColors[i])
          return true;

      }
    }

    return false;
  }

  /**
  * Check if a certain lightbox type exists
  *
  * @param string type
  * @return boolean
  */
  function lightBoxTypeExists(type)
  {
    if (type == null)
      return false;

    if (lightBoxTypes)
    {
      var numLightBoxTypes = lightBoxTypes.length;

      for (i = 0; i <= numLightBoxTypes; i++)
      {
        if (type == lightBoxTypes[i])
          return true;

      }
    }

    return false;
  }

  /**
  * Toggle the opacity layer
  *
  * @param string mode
  * @return boolean
  */
  function toggleOpacityLayer(mode)
  {
    var className         = 'hidden';
    var lightBoxOpacity   = null;

    if (mode == 'show')
      className           = 'visible';

    if (lightBoxOpacity = document.getElementById('lightbox-opacity'))
    {
      lightBoxOpacity.className     = className;

      return true;
    }

    return false;
  }

  /**
  * Toggle the lightbox on  or of
  *
  * @param string mode
  * @return boolean
  */
  function toggleLightBox(mode)
  {
    var className         = 'hidden';
    var lightBoxHolder    = null;

    if (mode == 'show')
      className           = 'visible';

    if (lightBoxHolder = document.getElementById('lightboxholder'))
    {
      if (lightBoxContent = document.getElementById('lightbox'))
      {
        if (mode != 'show')
          lightBoxContent.innerHTML     = '&nbsp;';

        lightBoxHolder.className      = className;

        return true;
      }
    }

    return false;
  }

  /**
  * Open a lightbox
  *
  * @param string url
  * @param string lightBoxType
  * @param string lightBoxColor
  * @param string list
  * @param string executeFunctions
  * @param string showInternalLoading
  * @return void
  */
  function openLightBox(url, lightBoxType, lightBoxColor, list, executeFunctions, showInternalLoading)
  {
    if (lightBoxColor == null)
      lightBoxColor = getDashBoardColor();

    if (lightBoxColor == null)
      lightBoxColor = defaultDashboardColor;

    if (lightBoxType == null)
      lightBoxType = 'large';

    if (executeFunctions == null)
      executeFunctions = '';

    // Check if the color defined actually exists
    if (!lightBoxColorExists(lightBoxColor))
      return;

      // Check if the type defined actually exists
    if (!lightBoxTypeExists(lightBoxType))
      return;

    if (lightBoxType == 'login')
    {
      // first check if the user is connected via https if not redirect to the secured part of the site
      var pageurl = new String(document.location);

      if (pageurl.indexOf('http://') != -1)
      {
        // change protocol
        myRegExp  = new RegExp("http://", "i");
        pageurl   = pageurl.replace(myRegExp, 'https://');

        // cleanup the url before adding the lightbox call
        myRegExp  = new RegExp("#", "g");
        pageurl   = pageurl.replace(myRegExp, '');

        // remove old lightbox references
        if (pageurl.indexOf('lb=') != -1)
          pageurl = pageurl.substring(0, pageurl.indexOf('&lb='))

        // check on a logof (uitloggen) url and remove when presend
        if (pageurl.indexOf('&url=uitloggen') != -1)
          pageurl = pageurl.substring(0, pageurl.indexOf('&url=uitloggen'))

        myRegExp  = new RegExp("logoff", "i");
        pageurl   = pageurl.replace(myRegExp, '');

        // get the right part of the lightbox url
        url = url.substring(url.indexOf('=')+1, url.length);

        // add the open lightbox part to the pageurl
        pageurl     += '&lb='+url;

        // redirect the site's main page
        window.top.document.location = pageurl;
        return;
      }
    }

    scrollToTop();

    // Close lightbox in case it is still opened
    closeLightBox();

    // Clear all old print data
    removeChildsFromElement('printcontentholder');

    // First set the lightbox settings
    if (lightBoxSettings = document.getElementById('lightbox-settings'))
    {
      // Set the type and color of the lightbox
      lightBoxSettings.className = lightBoxType + ' ' + lightBoxColor;

      // First check if the lightbox exists
      if (lightBox = document.getElementById('lightbox'))
      {
        if (showInternalLoading)
          executeFunctions += 'loadingLightBox(true);';

        if (toggleOpacityLayer('show'))
          placeContent(url, 'lightbox', list, executeFunctions);

      }
    }
  }

  /**
  * Size a lightbox
  *
  * @param void
  * @return void
  */
  function sizeLightBox()
  {
    var oplayer1 = document.getElementById('lightbox-opacity');
    var oplayer2 = document.getElementById('lightbox-opacity-bg');
    var lightboxLayer = document.getElementById('lightbox');
    var myHeight = 0;
    var newHeight = 0;

    if (!oplayer1 || !oplayer2 || !lightboxLayer)
      return;

    if (typeof(window.innerHeight) == 'number')
      myHeight = window.innerHeight; //Non-IE
    else if (document.documentElement && document.documentElement.clientHeight)
      myHeight = document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
    else if (document.body && document.body.clientHeight)
      myHeight = document.body.clientHeight; //IE 4 compatible

    if ((lightboxLayer.offsetHeight + 150) > document.body.offsetHeight)
      newHeight = lightboxLayer.offsetHeight + 150;
    else
      newHeight = document.body.scrollHeight + 80;

    if (newHeight > myHeight)
      oplayer1.style.height = newHeight + 'px';
    else
      oplayer1.style.height = myHeight + 'px';

    oplayer2.style.height = oplayer1.offsetHeight + 'px';

    // force the browser (IE) to parse the lightbox again so the multiselects will be visible again
    lightboxLayer.style.display = 'none';
    lightboxLayer.style.display = 'block';
  }

  /**
  * Close a lightbox
  *
  * @param void
  * @return void
  */
  function closeLightBox()
  {
    var parameters     = closeLightBox.arguments;
    var changeProtocol = (parameters[0]) ? parameters[0] : false;

    if (toggleLightBox('hide'))
    {
      if (toggleOpacityLayer('hide'))
      {
        window.onresize = null;

        scrollToTop();

        if (changeProtocol)
        {
          var pageurl = new String(document.location);

          if (pageurl.indexOf('https://') != -1)
          {
            // change protocol
            myRegExp  = new RegExp("https://", "i");
            pageurl   = pageurl.replace(myRegExp, 'http://');
            window.top.document.location = pageurl;
          }
        }
      }
    }
  }

  /**
  * Shows the loader of the lightbox
  *
  * @param boolean loading
  * @return void
  */
  function loadingLightBox(loading)
  {
    var elem = null;

    if (elem = document.getElementById('loading'))
    {
      if (loading == true)
        elem.className = 'visible';
      else
        elem.className = 'hidden';
    }
  }

  /**
  * Print the current lightbox
  *
  * @param string lightBoxContentContainerId
  * @param string printContentContainerId
  * @return boolean
  */
  function printLightBox(lightBoxContentContainerId, printContentContainerId)
  {
    if (lightBoxContentContainerId == null)
      lightBoxContentContainerId = 'lightbox';

    if (printContentContainerId == null)
      printContentContainerId = 'printcontentholder';

    lightBoxContent   = document.getElementById(lightBoxContentContainerId);
    printContent      = document.getElementById(printContentContainerId);

    // Kan de data niet uit de container halen, daar ie niet bestaat.
    if (lightBoxContent == null)
      return false;

    // Kan de data niet in de container plaatsen, daar ie niet bestaat.
    if (printContent == null)
      return false;

    // Makes sure the action iframes wont get printed out. Just give the iframe a  printstatus="false" as an attribute.
    var iframes   = null;
    var iframeId  = '';
    var i = 0;

    if (iframes = lightBoxContent.getElementsByTagName('iframe'))
    {
      if (iframes.length > 0)
      {
        for (i = 0; i < iframes.length; i++)
        {
          if (iframes[i].getAttribute('printstatus'))
          {
            if (iframeId = iframes[i].id)
            {
              if (iframeId != '')
              {
                var iframeContent = document.getElementById(iframeId);
                iframeContent.parentNode.removeChild(iframeContent);
              }
            }
          }
        }
      }
    }

    // remove old printboxes
    removeChildsFromElement(printContentContainerId);
    printContent.appendChild(lightBoxContent.cloneNode(true));

    window.print();
    return true;
  }