// öffnet ein Pop-Under-Window, aber höchstens alle X Stunden eines, dank Cookie. Variante [C].

// Würfle Ziel-Seite aus, wie bei Variante [B]:
var PopunderSeite=new Array()
PopunderSeite[0]="http://www.eligo.ch/i317864.html"
// PopunderSeite[1]=...
// PopunderSeite[2]=...

var PopunderFensterEigenschaften="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"
// specify popunder window features. Set 1 to enable a particular feature, 0 to disable

var PopAlleXStunden="24 hours" //Ist das effizient ? wieso nicht nur die Zahl, und folglich 0 anstelle von "always" ?
// Control frequency of the pop up:
// "always", for every time page loads OR
// "x hours" for once per x hours, where x is an integer (ie: 12 hours)
// ((Alternative wäre noch: nur einmal je Browser Session. Siehe Variante [A]))

function LiesCookie(Name)
{
  var Suche = Name + "="
  var Resultat = ""
  if (document.cookie.length > 0)
  {
    offset = document.cookie.indexOf(Suche)
    if (offset != -1)
    { // if cookie exists
      offset += Suche.length 
      // set index of beginning of value //Bezieht sich das auf die obere oder untere Zeile ???
      end = document.cookie.indexOf(";", offset) 
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length
      Resultat=unescape(document.cookie.substring(offset, end))
    }
  }
  return Resultat
}
function resetcookie()
{
  var VerfallDatumUndZeit = new Date()
  VerfallDatumUndZeit.setHours(VerfallDatumUndZeit.getHours()-10)
  document.cookie = "tcpopunder=;path=/;expires=" + VerfallDatumUndZeit.toGMTString()
}
function LadenOderNicht()
{
  if (LiesCookie('tcpopunder')=='')
  {
    LadePopunder()
    var VerfallDatumUndZeit = new Date()
    VerfallDatumUndZeit.setHours(VerfallDatumUndZeit.getHours()+parseInt(PopAlleXStunden))
    document.cookie = "tcpopunder="+parseInt(PopAlleXStunden)+";path=/;expires=" + VerfallDatumUndZeit.toGMTString()
  }
}
function LadePopunder()
{
  var SiteNummer=Math.floor(Math.random()*(PopunderSeite.length))
  win2=window.open(PopunderSeite[SiteNummer],"",PopunderFensterEigenschaften)
  win2.blur()
  window.focus()
}
//MAIN:
if (PopAlleXStunden=="always")
{
  resetcookie()
  LadePopunder()
}
else
{
  if (LiesCookie('tcpopunder')!=parseInt(PopAlleXStunden))
  resetcookie()
  LadenOderNicht()
}