// cookieHandler.js
//
// functions for geting, setting and checking cookies.
//
// April, 2010, Chip Moore

// Set cookie value associated with some cookie key.
function setCookie( ckey, cval, expiredays )
{
    var exdate = new Date();
    exdate.setDate( exdate.getDate() + expiredays );
    document.cookie = ckey + "=" + escape( cval ) +
        ( ( expiredays == null ) ? "" : ";expires=" + exdate.toGMTString() );
}

// Get value associated with some cookie key.
function getCookie( ckey )
{
    if ( document.cookie.length > 0 )
    {
        cstart = document.cookie.indexOf( ckey + "=" );
        if ( cstart != -1 )
        {
            // Strip off expiration date and key from cookie.
            cstart = cstart + ckey.length + 1;
            cend = document.cookie.indexOf( ";", cstart );
            if ( cend == -1 ) cend  = document.cookie.length;
            var cval = unescape( document.cookie.substring( cstart, cend ) );
            return cval;
        }
    }

    return "";
}

// Send cookie key to see if associated value exists.
function checkCookie( ckey )
{
    var cval = getCookie( ckey );
    if ( ( cval != null ) && ( cval != "" ) )
    {
        return true;
    }

    return false;
}

