﻿function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

    document.cookie = curCookie;
    
    return;
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name;// + "=";
    var begin = dc.indexOf("; " + prefix);
    var cookie;

    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
        begin += 2;
        
    var end = document.cookie.indexOf(";", begin);
    
    if (end == -1)
        end = dc.length;
        
    cookie = unescape(dc.substring(begin + prefix.length + 1, end));
    
    if (cookie == ';')
        cookie = '';
    
    return cookie;
}

function initializeCookies()
{
	if( getCookie( STATUS_COOKIE ) == null )
		setCookie(STATUS_COOKIE, '', '', '/', '', '');
    
    if( oPUBINFO.PublicationType.features.bookmarks )
    {
		if( getCookie( BOOKMARK_COOKIE ) == null )
			setCookie(BOOKMARK_COOKIE, '', '', '/', '', '');
    }
    if( oPUBINFO.PublicationType.features.shoppinglist )
	{
		if( getCookie( LIST_COOKIE ) == null )
			setCookie(LIST_COOKIE, '', '', '/', '', '');
	}
}

