function liesCookie(name) {
     
     keks = document.cookie;
     posName = keks.indexOf("; " + name + "=");
    
     if (posName == -1) {

         if (keks.indexOf(name + "=") === 0){
           posName = 0;
         }
       else{
         return null;
       }
     
     }
     
    wertAnfang = keks.indexOf("=", posName)+1;
    wertEnde = keks.indexOf(";", posName+1);
     
    if (wertEnde == -1) {
      wertEnde = keks.length;
    }
     
    wert = keks.substring(wertAnfang, wertEnde);
    
    return unescape(wert);
    
}
  
  
function fixedGMTString(datum){     
     
   var damals=new Date(1970,0,1,12);
   
   if (damals.toGMTString().indexOf("02")>0) {
   
       datum.setTime(datum.getTime()-1000*60*60*24);
       
   } 
   
   return datum.toGMTString();
     
}
  
  
function schreibCookie(name,wert,verfall,pfad,dom,secure) {
   
   neuerKeks = name + "=" + escape(wert);
           
   if (verfall) {
     neuerKeks += "; expires=" + fixedGMTString(verfall);     
   }
   if (pfad) {
     neuerKeks += "; path=" + path;
   }
   if (dom) {
     neuerKeks += "; domain=" + dom;
   }
   if (secure) {
     neuerKeks += "; secure";
   }
   
   document.cookie = neuerKeks;
  
   //alert("new cookie set - expiration date:" +verfall);
   
}


function cookieSetzen(cookieName, cookieLifetime) {
   
   jetzt = new Date();

   // change lifetime in 3rd parameter 
  
   schreibCookie(cookieName, jetzt.getTime(), new Date(jetzt.getTime()+cookieLifetime));
   
}



function check_for_last_visit(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, cookieAvailValue, displayIfCookieNotAvail, cookieNotAvailValue){
  
  warda = liesCookie(cookieName);
  
  if ((warda)) {
        
     // Wenn der Cookie da ist, das entsprechende Date-Objekt erzeugen 
            
     wardaDatum = new Date(warda*1);

  }

  else {
     
      // Wenn kein Cookie gesetzt - setzen 

     cookieSetzen(cookieName, cookieLifetime);
     
      // und lightbox initialisieren
            
     lightbox_init(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, cookieAvailValue, displayIfCookieNotAvail, cookieNotAvailValue);
  
  }

}


// Cookie lesen

function lightbox_cookie_init(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, cookieAvailValue, displayIfCookieNotAvail, cookieNotAvailValue){

  if (show === true){
        
    // displayIfCookieAvail is SET and has value cookieAvailValue
    
    if ((displayIfCookieAvail !== "") && (displayIfCookieNotAvail === "")) {
            
      cookieNameAvail = liesCookie(displayIfCookieAvail);
      
      if ((cookieAvailValue === "" && cookieNameAvail !== "") || (cookieAvailValue !== "" && cookieNameAvail === cookieAvailValue)) {
        
        check_for_last_visit(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, cookieAvailValue, displayIfCookieNotAvail, cookieNotAvailValue);
        
      }      
      
    }
    
    
    // displayIfCookieNotAvail is not SET or SET and doesn't have value cookieNotAvailValue
    
    if ((displayIfCookieAvail === "") && (displayIfCookieNotAvail !== "")){
      
      cookieNameNotAvail = liesCookie(displayIfCookieNotAvail);
    
      if ((cookieNotAvailValue === "" && cookieNameNotAvail === null) || (cookieNameNotAvail !== "" && cookieNameNotAvail !== cookieNotAvailValue)){
        
        check_for_last_visit(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, cookieAvailValue, displayIfCookieNotAvail, cookieNotAvailValue);
        
      }
    
    }
    
    
    
    // displayIfCookieAvail is SET and displayIfCookieNotAvail is not SET
    
    if ((displayIfCookieAvail !== "") && (displayIfCookieNotAvail !== "")){
          
      cookieNameAvail = liesCookie(displayIfCookieAvail);      
      
      cookieNameNotAvail = liesCookie(displayIfCookieNotAvail);
        
      if (((cookieAvailValue === "" && cookieNameAvail !== "") || (cookieAvailValue !== "" && cookieNameAvail === cookieAvailValue)) &&
         ((cookieNotAvailValue === "" && cookieNameNotAvail === null) || (cookieNameNotAvail !== "" && cookieNameNotAvail !== cookieNotAvailValue))) {
                      
         check_for_last_visit(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, displayIfCookieNotAvail);
        
      }
      
    }  
    
    
    //  displayIfCookieAvail NOT SET und displayIfCookieNotAvail NOT SET
    
    if ((displayIfCookieAvail === "") && (displayIfCookieNotAvail === "")){
    
       check_for_last_visit(show, isSWF, width, height, path, url, target, track, viewtrack, nbotext, cookieName, cookieLifetime, displayIfCookieAvail, cookieAvailValue, displayIfCookieNotAvail, cookieAvailValue, cookieNotAvailValue, cookieNotAvailValue);
          
    }    
    
  } else {
    
    return;    
  
  }
  
}  
