/**********************************************************
 *
 * Datei: popup.js
 * Datum: 07.11.03
 * Autor: J. Strübig
 * e-Mail: jstruebig@web.de
 *
 *
 * Funktion: popup(url, width, height [, close, anzahl])
 *
 * Öffnet ein Popupfenster in einer bestimmten Größe
 * und schliesst es automatisch nach einem angegebenem Intervall
 *
 * Parameter:
 *
 * url:    url die im Popup angeziegt werden soll
 * width:  Breite des Popupfenster
 * height: Höhe des Popupfenster
 * close:  Zeit in Sekunden bis das popup automatisch schließt [optional]
 * anzahl: wie oft das Popup angezeigt werden soll [optional]
 *
 ***********************************************************/

var gueltigkeit = 360;    // wieviele Tage das Popup Gültig ist.
var popupName = 'popup';  // Der Name des Popups.

function popup(url, width, height, close, anzahl)
{
    // popup nur anzahl mal öffnen (wenn anzahl angegeben wurde)
    if(anzahl)
    {
         var x = getCookie(popupName);
         if(x > anzahl) return;
         setCookie(popupName, ++x, gueltigkeit);
    }
    var param = new Array();

    if(width) param[param.length] = 'width=' + width;
    if(height) param[param.length] = 'height=' + height;

    _WIN_ = window.open(url, popupName, param.join(','));
    _WIN_.focus();
    if(close) window.setTimeout('closePopup()', close * 1000 );
}

function closePopup()
{
    if(!_WIN_ || typeof _WIN_.close == 'undefined') return;
    _WIN_.close();
    self.focus();
}
var _WIN_ = null;

///////////////////////////////////////////////////////////
// Cookie Funktionen
function getCookie(name)
{
    var c = new Object();
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen)
    {
         var endstr = document.cookie.indexOf (";", i);
         if (endstr == -1) endstr = document.cookie.length;

         var v = unescape(document.cookie.substring(i, endstr));
         var key = v.substring(0, v.indexOf("=", 0));
         var val = v.substring(v.indexOf("=") + 1);

         c[key] = val;

         i = endstr + 2; // Leerzeichen nach ; überspringen
    }
    if(name) return c[name] ? c[name] : null;
    return c;
}
function setCookie(name, value, days)
{
        if(!days) days = 1;
        var ms = 86400000 * days;
        var expire = new Date();
        expire.setTime(expire.getTime() + ms);
        document.cookie =
        name + "=" + escape(value)
        +  "; expires=" + expire.toGMTString()
        + ";"
        ;
}
