    var manageCookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = cookies[i].replace( /^\s+|\s+$/g, "" );
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };

    var genAdRiverValues = function () {
        var adRiverCookieName = 'adRiverGenValues';
        var cookieVal = manageCookie(adRiverCookieName);
        
        var cookieDomain = 'tochka.net';
        var cookiePath = '/';

        var secondParts = new Array('s1', 's2', 's3');
        var date = new Date();
        var today = date.getUTCMonth().toString() + date.getUTCDate().toString();

        var firstPart = '';
        if(typeof cookieVal == 'string') {
            var split = cookieVal.split(/,/);

            var dayNMonthUTC = split[0];

            //start page visit count all over again if the cookie wasn't set today
            if(dayNMonthUTC == today) {
                firstPart = split[1];
            }
        }

        var newVal = '';
        switch(firstPart) {
            case 'p1':
                newVal = 'p2';
                break;

            case 'p2':
                newVal = 'p3';
                break;

            case 'p3':
            case 'p4':
                newVal = 'p4';
                break;

            default:
                newVal = 'p1';
        }

        var randIdx = Math.floor(Math.random() * 3);
        var secPart = secondParts[randIdx];

        var returnVal = newVal + ', ' + secPart;
        cookieVal = today + ',' + returnVal;
        manageCookie(adRiverCookieName, cookieVal, {expires: 0, path: cookiePath, domain: cookieDomain});

        return returnVal;
    }

    //prevent function from accidentaly executing more than once per page view
    if(!adRiverValsAlreadyGenerated) {
        var ar_bn1 = genAdRiverValues();
        var adRiverValsAlreadyGenerated = true;
    }




