function getStyle(oElm, strCssRule) {
  var strValue = "";
  if (document.defaultView && document.defaultView.getComputedStyle) {
    strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
  } else if (oElm.currentStyle) {
    strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
      return
      p1.toUpperCase();
    });
    strValue = oElm.currentStyle[strCssRule];
  }
  return strValue;
}

function resizeDiv() {
  // Inline oder externes CSS
  var ad_sky = document.getElementById('skyscraper');
  var ad_sky_inner = document.getElementById('skyscraper_inner');
  var ad_lboard = document.getElementById('werbung_oben');
  var ad_lboard_inner = document.getElementById('werbung_oben_inner');
  var min_width = ad_sky.offsetWidth;
  var sky_left = (ad_sky.style.left == "") ? getStyle(ad_sky, "left") : ad_sky.style.left;
  // Sky-DIV dynamisch anpassen
  if (window.innerWidth) {
    // Firefox und Konsorten
    var test_scrollbar = (window.innerHeight <= document.body.scrollHeight) ? 17 : 0;
    ad_sky.style.width = (window.innerWidth - sky_left.substr(0, sky_left.length - 2) < min_width) ? min_width - test_scrollbar + "px" : window.innerWidth - sky_left.substr(0, sky_left.length - 2) - test_scrollbar + "px";
    ad_sky.style.height = document.body.scrollHeight + "px";
    ad_sky_inner.onmouseover = function() {
      ad_sky.onclick = "";
    };
    ad_sky_inner.onmouseout = function() {
      ad_sky.onclick = function() {
        window.open(adclick, '');
      }
    }
    ad_lboard_inner.onmouseover = function() {
      ad_lboard.onclick = "";
    };
    ad_lboard_inner.onmouseout = function() {
      ad_lboard.onclick = function() {
        window.open(adclick, '');
      }
    }
  } else if (document.documentElement && document.documentElement.clientWidth) {
    // IE Standard
    ad_sky.style.width = (document.documentElement.clientWidth - sky_left.substr(0, sky_left.length - 2) < min_width) ? min_width + "px" : document.documentElement.clientWidth - sky_left.substr(0, sky_left.length - 2) + "px";
    ad_sky.style.height = document.body.scrollHeight + "px";
  } else {
    // Quirks Mode
    ad_sky.style.width = (document.body.clientWidth - sky_left.substr(0, sky_left.length - 2) < min_width) ? min_width + "px" : document.body.clientWidth - sky_left.substr(0, sky_left.length - 2) + "px";
    ad_sky.style.height = document.body.scrollHeight + "px";
  }
}

function checkWallpaper() {
  if (typeof (adtype) != 'undefined') {
    if (adtype == 'wallpaper') {
      // Schiebe Skyscraper rechtsbündig an Leaderboard
      document.getElementById("werbung_oben").style.left = '137px';
      if (document.getElementById("skyscraper") != null) {
        document.getElementById("skyscraper").style.top = '3px';
        document.getElementById("skyscraper").style.left = '865px';
		// document.getElementById("skyscraper").style.width = '100%';
      }
      if (document.getElementById("skyscraper_detail") != null) {
        document.getElementById("skyscraper_detail").style.top = '3px';
        document.getElementById("skyscraper_detail").style.left = '865px';
		// document.getElementById("skyscraper_detail").style.width = '100%';
      }
      document.getElementById("werbungkopf").style.height = '80px';
    }
    if (adtype == 'expwallpaper') {
      // Schiebe Sky rechts unter das Leaderboard
      //alert("test2");
      document.getElementById("werbung_oben").style.left = '297px';
	  // document.getElementById("werbung_oben").style.width = '100%';
      if (document.getElementById("skyscraper") != null) {
        document.getElementById("skyscraper").style.top = '93px';
        document.getElementById("skyscraper").style.left = '865px';
		// document.getElementById("skyscraper").style.width = '100%';
      }
      if (document.getElementById("skyscraper_detail") != null) {
        document.getElementById("skyscraper_detail").style.top = '93px';
        document.getElementById("skyscraper_detail").style.left = '865px';
		// document.getElementById("skyscraper_detail").style.width = '100%';
	  }
    }
  }
  if (typeof (bgcolor) != 'undefined' && bgcolor != null) {
    // Färbe mögliche Bereiche ein
    document.getElementsByTagName("body")[0].style.backgroundColor = bgcolor;
    document.getElementById("header").style.backgroundColor = bgcolor;
  }
  if (typeof (bgimage) != 'undefined' && bgimage != null) {
    document.getElementsByTagName("body")[0].style.backgroundImage = 'url(' + bgimage + ')';
    document.getElementsByTagName("body")[0].style.backgroundRepeat = 'repeat';
  }
  if (typeof (adclick) != 'undefined' && adclick != null) {
    // Verlinke bei Klick auf Hintergrund auf adclick
    //alert("Test:"+adclick);
    //test = ;
    // document.getElementsByTagName("body")[0].onclick= function(){location.href = adclick;};
    // document.getElementById("center_start").onclick= function(){location.href = false;};
    // document.body.onclick = function(e){if (e.target == document.body) {location.href = adclick;}};
    /*
	document.body.onclick = function (e) {  
		console.log(e.target);
      if (e.target == document.body) {
        location.href = adclick;
      }	
	};
	*/
	
	var ad_lboard = document.getElementById('werbung_oben');
	var ad_lboard_inner = document.getElementById('werbung_oben_inner');
	ad_lboard.style.cursor = "pointer";
	ad_lboard.onclick = function() {
		window.open(adclick, '');
	}
	var ad_sky = document.getElementById('skyscraper');
	var ad_sky_inner = document.getElementById('skyscraper_inner');
	ad_sky_inner.style.width = ad_sky.offsetWidth + "px";
	ad_sky_inner.style.height = ad_sky.offsetHeight + "px";
	ad_sky.style.cursor = "pointer";
	ad_sky.onclick = function() {
		window.open(adclick, '');
	}
	resizeDiv();
	
    if (typeof (bMR) == 'undefined' || bMR == null) {
      document.getElementById("werbung_mitte").style.display = 'block';
      document.getElementById("werbung_mitte").style.width = '520px';
      document.getElementById("werbung_mitte").style.textalign = 'center';
    }
    if (document.getElementById('werbung_oben').offsetHeight > 100) {
      document.getElementById("header1").style.height = '200px';
      document.getElementById("skyscraper").style.top = '230px';
      //document.getElementById("werbung_oben").style.display='block';
    }
  }
}
