// set variables
  var hbx_pagename = "";
  var hbx_seg_val = "";
  var hbx_belEH_agofid = "";
  
  var is_mac = window.navigator.platform == "MacPPC";
  var mac_ns = window.navigator.platform == "MacPPC" && navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) > "4";  
  var mac    = window.navigator.platform == "MacPPC" && navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) == "4";
  var mac_ie = window.navigator.platform == "MacPPC" && navigator.userAgent.match(/MSIE/i);
  var safari = window.navigator.platform == "MacPPC" && navigator.userAgent.match(/Safari/i);  
  var ie     = navigator.userAgent.match(/MSIE\s5.*/i);
  var ie5    = navigator.appVersion.match(/MSIE.+5\.0/i);
  var ie6    = navigator.userAgent.match(/MSIE\s6.*/i);
  var ie4    = navigator.userAgent.match(/MSIE\s4.*/i);
  var op     = navigator.userAgent.indexOf('Opera') != -1;
  var ns4    = navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) == "4";  
  var moz    = navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) > "4";
  var ns6    = navigator.userAgent.match(/Netscape6/i);
  var konq   = navigator.userAgent.match(/Konqueror/i);  
  var fustyUserAgent = mac_ie || ns4 || ns6 || mac;
  var timer  = null;

  if(mac_ie)
    document.writeln('<link rel="stylesheet" href="/css/GEOlino/ie_mac.css" type="text/css" media="screen" />');

// adtag flags
  var fullsize = 0;
  var LeaderBoard = 0;
  var promo = 0;
  var halfpage = 0;
  var contentad = 0;
  var skyscraper = 0;
  var textteaser = 0;
  var textcontent = 0;
  var popup = 0;


// detect flash 7 plugin or active-x
var usesActiveX = false;
var swf7 = false;
var swf8 = false;
var swf9 = false;

if (navigator.plugins.length != 0) {
  for (i=0; i<navigator.plugins.length; i++) {
    var plugDescr = navigator.plugins[i].description.toLowerCase();
    if ((plugDescr.indexOf('flash') != -1) && (plugDescr.indexOf('7.') != -1)) {
      swf7 = true;
    }
    if ((plugDescr.indexOf('flash') != -1) && (plugDescr.indexOf('8.') != -1)) {
      swf8 = true;
    }
    if ((plugDescr.indexOf('flash') != -1) && (plugDescr.indexOf('9.') != -1)) {
      swf9 = true;
    }
  }
} else {
  usesActiveX = true;
}

// #### resize layout for halfpage-integration ####
function resizeLayout() {
  document.getElementById("magNav").style.padding            = "0 0 3px 60px";
  document.getElementById("rubrikenAd").style.width          = "991px";
  document.getElementById("mainHeader").style.width          = "991px";
  if(ie5) document.getElementById("mainNav").style.width     = "991px"; 
  else    document.getElementById("mainNav").style.width     = "992px"; 
  document.getElementById("seperatorHalfpage").style.display = "block";
  document.getElementById("topNavHalfpage").style.display    = "block";
  document.getElementById("mainContent").style.width         = "993px";
  document.getElementById("right").style.width               = "336px";
  if(document.getElementById("issueBoxLarge")) 
    document.getElementById("issueBoxLarge").style.display   = "block";
  if(ie5) document.getElementById("footer").style.width      = "992px";
  else    document.getElementById("footer").style.width      = "991px";
  if (document.getElementById("floater")) document.getElementById("floater").style.display = "none";
  document.getElementById("gujSites").style.width            = "991px";
  document.getElementById("promoAd").style.display           = "inline";
  document.getElementById("promoAd").style.width             = "336px";
  document.getElementById("promoAd").style.margin            = "0 0 10px 0";
  if(document.getElementById('issueBox'))
    document.getElementById('issueBox').style.display        = "none";
}

function doAdStuff() { 

  // ======== Rubriken Ad ========
  if (!fustyUserAgent) {
    if(document.getElementById("bufferRubrikenAd") && (LeaderBoard || fullsize)) {
      var bufferRubrikenAd    = document.getElementById("bufferRubrikenAd");
      var rubrikenAdContainer = document.getElementById("rubrikenAd");
      rubrikenAdContainer.style.display = "block";
      while (bufferRubrikenAdChild = bufferRubrikenAd.firstChild) {
        if (bufferRubrikenAdChild.tagName && bufferRubrikenAdChild.tagName.toLowerCase() == "script") {
          bufferRubrikenAd.removeChild(bufferRubrikenAdChild);
        } else {
          if (LeaderBoard) rubrikenAdContainer.style.height = "90px";
            rubrikenAdContainer.appendChild(bufferRubrikenAdChild);
          }
        }
    }
    // ======== Content-Ad =======
    if(document.getElementById("contentAd") && !contentad) {
     document.getElementById("contentAd").style.display = "none";     
    }
    // ======== Promo/Halfpage Ad ========
    if((promo) && document.getElementById("promoAd")) {
      document.getElementById("promoAd").style.display = "block";
    }
    // ======== Text-Teaser rechte Spalte ========
    if(textcontent && document.getElementById("textAd")) {
      document.getElementById("textAd").style.display = "block";
    }
    // ======== Skyscraper ========
    if(document.getElementById("floater")) {
      if (LeaderBoard)   document.getElementById("floater").style.top = "130px";
      else if (fullsize) document.getElementById("floater").style.top = "100px";
    }
  }
}

// #### adjust length of the right col ####
function adjustRightCol() {
  if(document.getElementById("left") && document.getElementById("right")) {
    var left  = document.getElementById("left").offsetHeight;
    var right = document.getElementById("right").offsetHeight;
    if (left > right) {
      document.getElementById("right").style.height = (left - 20) + "px";
      right = document.getElementById("right").offsetHeight;
    } else {
      document.getElementById("right").style.margin = "15px 0 10px 0";
    }
  }
}

// popup functions
  function execSubmit(formular,fenstername,fsize) {
    var fenster = window.open("",fenstername,fsize);
    document [formular].submit();
  }

  function submitWindow(formular,fenster){
    if ((window.name == "_blank")||(window.name == "")||(window.name == "_new")) {
      window.name = "blank_source";
    }
    if (window.name == fenster) {
      window.name = fenster + "_suche";
    }
    document.forms[formular].elements["destination"].value = window.name;
    execSubmit(formular,fenster,"width=637,height=650,scrollbars=yes,resizable=yes,status=no,menubar=no,location=no,left=0,top=0");
  }

  function submitQuery(formular){
    var service = document.forms[formular].service.options[document.forms[formular].service.options.selectedIndex].value;
    var query   = document.forms[formular].elements["q"].value;

    switch(service){
      case "register":
        blank_window("http://www.geo.de/GEO/static/registersuche/results.html?START=1&JBEGIN=&TEXT=" + query,"register");
        break;
      case "forum":
        blank_window("http://www.geo.de/GEO/static/forum/dosearch.php?Words=" + query + "&Cat=1,2,3&Forum=All_Forums&Match=And&Old=allposts&Limit=25","forum");
        break;
      case "shop":
        //blank_window("http://www.geowebshop.de/onlineabo/servlet/ServletR?page=PageArtikelSuchen&site=geo&suchbegriff=" + query,"shop");
        open_search("http://www.geo.de/GEO/static/lucene/suche/do/search?service=geowebshop&q=" + query,"637","650");
        break;
      case "geo":
        open_search("http://www.geo.de/GEO/static/lucene/suche/do/search?service=geo&q=" + query,"637","650");
    }
  }

  function submitHeaderQuery(formular){
    var query   = document.searchHeaderForm.query.value;
    open_search("http://www.geo.de/GEO/static/lucene/suche/do/search?service=geo&q=" + query,"637","650");
  }

// various popup-functions
  function openWindow(page,breite,hoehe,name){
    var popup = window.open(page,name,"width=" + breite + ",height=" + hoehe + ",scrollbars=no,resizable=yes,menubar=no,locationbar=no");
    popup.focus();
  }
  
  function printView(page){
    var popup = window.open(page,"print","width=620,height=600,scrollbars=yes,resizable=no,menubar=yes,locationbar=no,toolbar=no,left=0,top=0");
    popup.focus();
  }

  function openEcard(page,name){
    popup = window.open(page,name,"width=678,height=720,scrollbars=yes,resizable=yes,menubar=no,locationbar=no,toolbar=no,left=0,top=0");
    popup.focus();
  }

  function openChat(page){
    if (screen.width <= 800) var popup = window.open(page,"chat","width=780,height=545,scrollbars=no,resizable=no,menubar=no,locationbar=no,toolbar=no,statusbar=yes,left=0,top=0");
    else var popup = window.open(page,"chat","width=800,height=712,scrollbars=yes,resizable=no,menubar=no,locationbar=no,toolbar=no,statusbar=yes,left=0,top=0");
    popup.focus();
  }
function open_no_resize(page,breite,hoehe,name){
		popup = window.open(page,name,"width=" + breite + ",height=" + hoehe + ",resizable=no,toolbar=no,scrollbars=no,menubar=no,locationbar=no");		
		popup.focus();		
	}
  function sendArticle(headline){
    var url  = window.location.href;
    var link = url.replace(/\?.*/,"");
    window.location.href = 'mailto:?subject=GEOlino.de Linktipp: ' + headline + '&body=%0A' + link;
  }

// set GEO.de homepage
  function startseite() {
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
      document.links[0].style.behavior='url(#default#homepage)';
      document.links[0].setHomePage('http://www.geolino.de');
    } else window.open("/_components/GEOlino/sidebar/startseite/set_startpage.html","Anleitunge","width=470,height=600");
  }
  
//tracking for flash and dhtml applications
function flashInteractionTracking (application, action, clicktarget){	
	 if(typeof urchinTracker == "function") {
	urchinTracker(action+"="+clicktarget);
	}
	//google analytics neu
	pageTracker._trackPageview(application);
	pageTracker._trackEvent(application, action, clicktarget);
	var IVW = "http://geo.ivwbox.de/cgi-bin/ivw/CP/"+agof_id+";"+ivw_id+",,"+application+",";
  
  // Site Catalyst
  if((typeof s != "undefined") && (s != null)) {
    savehier = s.hier1;
    saveprop7 = s.prop7;    

    if (application.match(/schiebepuzzle/)) {
      application = application.replace(/_\d{4,5}/g, "");
    }
    
    //s.prop7 = application;
    s.prop7 = "interaktion-spiele";
    s.hier1 = s.hier1 + ","+application;
    
    s.referrer=window.location.protocol+"//"+document.location.host+document.location.pathname;
    void(s.t());
    s.prop7 = saveprop7;
    s.hier1 = savehier;
  }
  
  if(!document.getElementById("pixel_container")) {
    var pc = document.createElement('div');  
    pc.setAttribute('id', 'pixel_container');
    $('body').append(pc);
  }
  
  document.getElementById("pixel_container").innerHTML = "<img src='"+IVW+"?r=noref&amp;d="+(Math.random()*100000)+"' width='1' height='1' alt='' \/><br \/>";
  
  
}

// global cookie function
function setCookie (name, string, expires){	
  document.cookie = name+"="+string+"; expires="+expires;
}


// display or hide the reportBox for  article comments
  function reportComment(warn_comment, comment_nr, pv, comments_pv) {
    var report_box    = document.getElementById("report"+comment_nr);
    var report_button = document.getElementById("button"+comment_nr);
    var comment_box   = document.getElementById("commentBox"+comment_nr);
    
    if(report_box) {
      comment_box.removeChild(report_box);
      report_button.style.display = "block";
    } else {
      report_button.style.display = "none";
      comment_content = comment_box.innerHTML;
      report_content = '<div class="reportBox" id="report'+comment_nr+'"><form name="notify_form'+comment_nr+'" id="notify_form'+comment_nr+'" action="#comments" method="post"><input type="hidden" name="comment_id" value="'+comment_nr+'" /><input type="hidden" name="com" value="notify" /><input type="hidden" name="p" value="'+pv+'" /><input type="hidden" name="pageview" value="'+comments_pv+'" /><strong>Beitrag mit bedenklichem Inhalt melden</strong><div class="close" title="Box schlie&szlig;en" onclick="reportComment(\''+warn_comment+'\',\''+comment_nr+'\',\''+pv+'\');">[x]</div><br class="clearFloat" /><br />Grund der Meldung (mindestens 10 Zeichen): <p id="errorMessage'+comment_nr+'" style="color:red"></p><input type="text" style="margin-left: 0px;width:350px; font-size:10px;" name="reportReason" maxlength="50" value="" onfocus="if (this.value == \'Eingabe von mindestens 10 Zeichen\') this.value=\'\'" /><br /><br /><img src="/images/GEO/kommentar/beitrag_melden.gif" width="92" height="19" onclick="checkReportComment(0, '+comment_nr+', 0, 0)" alt="Beitrag melden!" title="Beitrag melden!"/> </form></div>';
      comment_box.innerHTML = comment_content+report_content;
    }
  }
  
  function checkReportComment(warn_comment, comment_nr, pv, comments_pv) {
	
	textlaenge = document.getElementById("notify_form"+comment_nr).reportReason.value
	textlaenge = textlaenge.length;
	if (textlaenge < 10)
	document.getElementById("errorMessage"+comment_nr).innerHTML = "Bitte geben Sie mindestens 10 Zeichen ein!";
	
	else
	//document.getElementById("errorMessage"+comment_nr).innerHTML = "alright";
	document.getElementById("notify_form"+comment_nr).submit();
	
  }

  
  /* 2007-08-03 js (spiegel.julia@guj.de) 
  	Zaehlt, wie viele Zeichen schon ins Textfeld eingegeben wurden, und gibt einen Status darueber aus. 
	Ausserdem eine Fehlermeldung, wenn es mehr als 1000 Zeichen sind */
	function count_textarea(text)
	{
		
		if (text.length >= 1000)
		{
			document.getElementById("form-error-msg_comment_text").innerHTML = "<strong style=\"color:red\">Sie haben die maximale Textl&auml;nge von 1000 Zeichen erreicht!<strong>";
			document.getElementById("form-comment-text-counter").innerHTML = "";
			document.getElementById("mitteilung").value = document.getElementById("mitteilung").value.substring(0,1000);
		}
		
		else
		{
			document.getElementById("form-comment-text-counter").innerHTML = "Noch "+(1000 - text.length) + " Zeichen frei";
			document.getElementById("form-error-msg_comment_text").innerHTML = "";
		}
		
	}