var max_width = 950;
var left_width = 300;
var top_height = 255;
var left_padding = 40;
var left_margin;
var userAgent = navigator.userAgent.toLowerCase();
var isInternetExplorer = (userAgent.indexOf('msie') > -1 && userAgent.indexOf('opera') == -1);

function center_content() {
  var elm;
  var elm_list = new Array('div', 'form', 'table');

  left_margin = Math.round((document.body.clientWidth - max_width) / 2) - left_padding;
  if (is_scrollbar_visible()) {
    if (isInternetExplorer) {
      if (-1 == userAgent.indexOf('msie 6')) {
        left_margin += get_scrollbar_width() / 2;
      }
    } else {
      left_margin += get_scrollbar_width() / 2;
    }
  }

  for (var i = 0; i < elm_list.length; i++) {
    for (var j = 0; j < document.getElementsByTagName(elm_list[i]).length; j++) {
      elm = document.getElementsByTagName(elm_list[i])[j];
      if ('fixiert' == elm.className) {
        elm.style.marginLeft = left_margin + 'px';
      } else {
        if ('inhalt' == elm.className) {
          elm.style.marginLeft = left_margin + left_width + 'px';
        }
      }
    }
  }

  document.getElementsByTagName('body')[0].style.backgroundPosition = left_margin + 'px';;
}


function get_scrollbar_width() {
  var x;
  var width_scrollbar;

  document.body.style.overflow = 'hidden';
  x = document.body.offsetWidth || document.body.clientWidth;
  document.body.style.overflow = 'scroll';

  width_scrollbar = x - (document.body.offsetWidth || document.body.clientWidth);
  if(!width_scrollbar) {
    width_scrollbar = document.body.offsetWidth - document.body.scrollWidth;
  }
  document.body.style.overflow = '';

  return Math.abs(width_scrollbar);
}


function is_scrollbar_visible() {
  var textHeight;
  var windowHeight;

  textHeight = document.getElementById('inhalt_id').offsetHeight;

  if (isInternetExplorer) {
    windowHeight = window.document.documentElement.clientHeight;
  } else {
    windowHeight = window.innerHeight;
  }

  return textHeight > (windowHeight - top_height) ? true : false;
}

