

enddate="071231";
date="2005.3.3.16.30.57.0";
date1=date.split (".");
var start_date=new Date(date1[0],date1[1],date1[2]);
madate=start_date.getTime();
var exp = new Date();
var indreissigTagen = exp.getTime() + (30 * 24 * 60 * 60 * 1000);
exp.setTime(indreissigTagen);

function setCookie (value) {
    document.cookie = "NGCount=" + escape(value) + ";domain=.web.de;path=/;expires=" + exp.toGMTString();
}

function getCookie() {
    var cookie = document.cookie;
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf("NGCount=");
        if (offset != -1) {
            offset += 6;
            end = cookie.indexOf(";", offset);
            if (end == -1) end=cookie.length;
                setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}

var NGCount = getCookie();

if(NGCount == null) {
    newNGCount="X"+enddate+"1E"+adid+"X";
} else {
    var montab= NGCount.split("X");
    var newNGCount="";
    var found=0;
    var j=0;
    var found2=0;

    for (i=1;i< montab.length-1;i++){

        if (montab[i].length>8){
            var annee="20"+montab[i].substring(0,2);
            var end_date=new Date(annee,montab[i].substring(2,4),montab[i].substring(4,6));
            end_date=end_date.getTime();

            if ( end_date >= madate){
                found2=1;j+=1;

                if (montab[i].substring(8,montab[i].length) == adid) {
                    found=(parseInt(montab[i].substring(6,7))+1);
                    if (found>=2)
                        found=1;
                    montab[i]=enddate+ found+"E"+adid;
                }

                if (j==1) {
                    newNGCount += "X"+montab[i]+"X";
                } else {
                    newNGCount += montab[i]+"X";
                }
            }
        }
    }

    if (found==0 && found2==1) {
        newNGCount += enddate + "1E" + adid + "X";
        found=1;
    }

    if (found==0 && found2==0)  {
        newNGCount += "X"+enddate + "1E" + adid + "X";
    }
}

setCookie(newNGCount);
