function checkHorizScroll() {
  // dont do it if print view
  /*
  mainNav = document.getElementById('mainNav');
  if (mainNav.currentStyle) {
    mainNavDisplay = mainNav.currentStyle['display'];
  } else if (window.getComputedStyle) {
    mainNavDisplay = window.getComputedStyle(mainNav, '').getPropertyValue("display");
  }
  
  if(mainNavDisplay == 'none') {
    return true;
  }
  */
  
  var windowWidth = Element.clientWidth ? Element.clientWidth : document.body.clientWidth;
  var dynamicStyle = '';
  
  if(!document.getElementById('horizscroll_css')) {
    document.getElementById('main').innerHTML += '<div id="horizscroll_css"></div>';
  }
  
  if(windowWidth < 1000) {
    dynamicStyle = 'body { overflow-x:auto; } #main {left:0px !important; margin-left:0px !important;}';
    //document.body.style.overflowX = 'auto';
    //document.getElementById('main').style.left="0px";
    //document.getElementById('main').style.marginLeft="0px";
    
  } else {
    dynamicStyle = 'body { overflow-x:hidden;} #main {left:50% !important; margin: auto auto 15px -510px !important;}';
    //document.body.style.overflowX = 'hidden';
    //document.getElementById('main').style.left = '50%';
    //document.getElementById('main').style.margin = 'auto auto 15px -510px';
  }
  try {
    document.getElementById('horizscroll_css').innerHTML += '<style type="text/css" media="screen">' + dynamicStyle + '</style>';
  }catch(e){}
}

function checkHorizScrollIE() {
  // dont do it if print view
  /*mainNav = document.getElementById('mainNav');
  if (mainNav.currentStyle) {
    mainNavDisplay = mainNav.currentStyle['display'];
  } else if (window.getComputedStyle) {
    mainNavDisplay = window.getComputedStyle(mainNav, '').getPropertyValue("display");
  }
  if(mainNavDisplay == 'none') {
    return true;
  }*/
  
  var windowWidth = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
  var dynamicStyle = '';
  
  // ie 7
  if (window.XMLHttpRequest) {
    if(windowWidth < 1000) {
      dynamicStyle = 'body { overflow-x:visible; } #main {left:0px !important; margin-left:0px !important;}';
      //document.body.style.overflowX = 'visible';
      //document.getElementById('main').style.left="0px";
      //document.getElementById('main').style.marginLeft="0px";
    } else {
      dynamicStyle = 'body { overflow-x:hidden;} #main {left:50% !important; margin: auto auto 15px -510px !important;}';
      //document.body.style.overflowX = 'hidden';
      //document.getElementById('main').style.left = '50%';
      //document.getElementById('main').style.margin = 'auto auto 15px -510px';
    }
  // ie6
  } else {
    if(windowWidth < 1000) {
      dynamicStyle = 'body { overflow-x:scroll; } #main {left:0px !important; margin-left:0px !important;}';
      //document.body.style.overflowX = 'scroll';
      //document.getElementById('main').style.left="0px";
      //document.getElementById('main').style.marginLeft="0px";
    } else {
      dynamicStyle = 'body { overflow-x:visible;} #main {left:50% !important; margin: auto auto 15px -510px !important;}';
      //document.body.style.overflowX = 'visible';
      //document.getElementById('main').style.left = '50%';
      //document.getElementById('main').style.margin = 'auto auto 15px -510px';
    }
  }
  //document.getElementById('horizscroll_css').innerHTML = '<style type="text/css" media="screen">' + dynamicStyle + '</style>';
  document.getElementById('horizscroll_css').innerHTML += '<style type="text/css" media="screen">' + dynamicStyle + '</style>';
  try {
    /** This actually should get the IE version and then set the right css file */
    var rv = -1;
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
    
    if(rv > -1) {
      if(rv == 7) {
        if(windowWidth < 1000) {
          document.links["ie7css"].href = 'fileadmin/template_new/css/custom/ie7_fix.css';
        }else {
          document.links["ie7css"].href = 'fileadmin/template_new/css/custom/ie7_scroll.css';
        }
      }
    }
  }catch(e) { }
  
  /*
  if(document.getElementById('rightCol').offsetHeight > document.getElementById('midCol').offsetHeight) {
    document.getElementById('midCol').style.height = (document.getElementById('rightCol').offsetHeight + 200) + 'px';
  }*/
}

initCheckScroll = function(){
  checkHorizScrollIE();
  window.onresize = checkHorizScrollIE;
}

if (window.attachEvent) {
  window.attachEvent("onload", initCheckScroll);
} else {
	if (!navigator.userAgent.toLowerCase().match('chrome')){
		  window.addEventListener("resize", checkHorizScroll, false);
		  window.addEventListener("load", checkHorizScroll, false);
	}

}


