function SetzeCookie(name, value){
  var argv    = SetzeCookie.arguments
  var argc    = SetzeCookie.arguments.length
  var expires = (argc > 2) ? argv[2] : null
  document.cookie = name + "=" + escape(value) + (expires ? ("; expires=" + expires.toGMTString()) : "")
}

function HoleCookieVal(offset){
  var endstr = document.cookie.indexOf(";", offset)
  if(endstr == -1) endstr = document.cookie.length
  return(unescape(document.cookie.substring(offset, endstr)))
}

function HoleCookie(name){
  var arg  = name + "="
  var alen = arg.length
  var clen = document.cookie.length
  var i    = 0
  while(i < clen)  {
    var j = i + alen
    if(document.cookie.substring(i, j) == arg)
      return(HoleCookieVal(j))
    i = document.cookie.indexOf(" ", i) + 1
    if(!i) break
  }
  return(null)
}

function Benutzer(){
  var UserName = HoleCookie("username")
  if(!UserName)  {
    //UserName = prompt("Gib doch bitte Deinen Vornamen an:", "")
    //if(!UserName)  UserName = "&quot;Unbekannter&quot;"
    //if(!UserName)  UserName = HoleCookie("username")
   if(!UserName)  UserName = "<form><input type=button value='Hier kannst Du Deinen Namen eintragen...' onClick='Benutzern();location.reload()'></form>"
  }
  var ThePath    = location.pathname ? location.pathname : "/"
  var TheDomain  = location.hostname
  var TheExpDate = new Date()
  TheExpDate.setTime(TheExpDate.getTime() + (30 * 24 * 3600 * 1000))
  SetzeCookie("username", UserName, TheExpDate, ThePath, TheDomain)
  return(UserName)
}

function Benutzern(){
  var UserName = HoleCookie("username")
  UserName = prompt("Gib doch bitte Deinen Vornamen an:", "")
  if(!UserName)  UserName = "Fremder"
  
  var ThePath    = location.pathname ? location.pathname : "/"
  var TheDomain  = location.hostname
  var TheExpDate = new Date()
  TheExpDate.setTime(TheExpDate.getTime() + (30 * 24 * 3600 * 1000))
  SetzeCookie("username", UserName, TheExpDate, ThePath, TheDomain)
  return(UserName)
}



function Besuche(){
  var AnzahlBesuche = HoleCookie("visits")
  if(!AnzahlBesuche)
    AnzahlBesuche = 1
  else
    AnzahlBesuche++
  var ThePath    = location.pathname ? location.pathname : "/"
  var TheDomain  = location.hostname
  var TheExpDate = new Date()
  TheExpDate.setTime(TheExpDate.getTime() + (30 * 24 * 3600 * 1000))
  SetzeCookie("visits", AnzahlBesuche, TheExpDate, ThePath, TheDomain)
  return(AnzahlBesuche)
}

function zBesuche(){
  return(HoleCookie("visits"))
}

function zScore(Prozent,em,anz){
  var AnzahlVersuche = HoleCookie("versuche")
  if(!AnzahlVersuche)
    AnzahlVersuche = 1
  else
    AnzahlVersuche++
  var Score = HoleCookie("score")
  var Erstesmal = HoleCookie("erstesmal")
  var Anzahl = HoleCookie("anzahl")
  
  if(!Score) { 
    Score = Prozent  
    Erstesmal = em
    Anzahl=anz
  }
  if (Score<Prozent) {
    Score = Prozent
    Erstesmal = em
    Anzahl=anz
  }
  var ThePath    = location.pathname ? location.pathname : "/"
  var TheDomain  = location.hostname
  var TheExpDate = new Date()
  TheExpDate.setTime(TheExpDate.getTime() + (30 * 24 * 3600 * 1000))
  SetzeCookie("score", Score, TheExpDate, ThePath, TheDomain)
  SetzeCookie("erstesmal", Erstesmal, TheExpDate, ThePath, TheDomain)  
  SetzeCookie("anzahl", Anzahl, TheExpDate, ThePath, TheDomain)
  SetzeCookie("versuche", AnzahlVersuche, TheExpDate, ThePath, TheDomain)
//  return(Score)
}

function hScore(){
  var Score = HoleCookie("score")
  if(!Score) {  Score = '0' }
  return(Score)
}

function hAnzahl(){
  var Score = HoleCookie("anzahl")
  if(!Score) {    Score = '0'  }
  return(Score)
}

function hErstesmal(){
  var Score = HoleCookie("erstesmal")
  if(!Score) {    Score = '0'  }
  return(Score)
}

function hVersuche(){
  var Score = HoleCookie("versuche")
  if(!Score) {    Score = '0'  }
  return(Score)
}
