function getWindowHeight()
{
  if (typeof(document.documentElement) != 'undefined')
  {
    return document.documentElement.clientHeight;
  }
  else if (typeof(document.body) != 'undefined')
  {
    return document.body.clientHeight;
  }
  else
  {
    return window.innerHeight;
  }
}

function getWindowWidth()
{
  if (typeof(document.documentElement) != 'undefined')
  {
    return document.documentElement.clientWidth;
  }
  else if (typeof(document.body) != 'undefined')
  {
    return document.body.clientWidth;
  }
  else
  {
    return window.innerWidth;
  }
}

function fixPageHeight(offset)
{
  var wh = getWindowHeight();
  var ch = $('wrapper').offsetHeight;
  var sh = document.documentElement.scrollHeight;
  if (typeof(document.body.scrollHeight) != 'undefined' && document.body.scrollHeight >= sh)
  {
    sh = document.body.scrollHeight;
  }

  if (wh < 560 || sh > wh)
  {
    return;
  }

  if (wh >= ch)
  {
    $('content_wrapper').style.height = (wh - offset) + 'px';
  }
}

function toggleCollapse(elementName, containerElementName, hiddenFormTagName)
{
  containerElement = $(containerElementName);
  element = $(elementName);

  if (element)
  {
    eval('var status = ' + elementName + 'Collapsing;');
    if (status === true)
    {
      new Effect.Parallel(
        [
          new Effect.SlideDown(element, {sync: true}),
          new Effect.Appear(element, {sync: true})
        ],
        {duration: 1.0, fps: 35}
      );

      if (containerElement)
      {
        containerElement.update('[-]');
      }

      if (hiddenFormTagName)
      {
        $(hiddenFormTagName).value = 'true';
      }

      eval(elementName + 'Collapsing = false;');
    }
    else if (status === false)
    {
      new Effect.Parallel(
        [
          new Effect.SlideUp(element, {sync: true}),
          new Effect.Fade(element, {sync: true})
        ],
        {duration: 1.0, fps: 35}
      );

      if (containerElement)
      {
        containerElement.update('[+]');
      }

      if (hiddenFormTagName)
      {
        $(hiddenFormTagName).value = '';
      }

      eval(elementName + 'Collapsing = true;');
    }
  }
}
