
function clientcacheaddcache(type)
{
    w = crawltotop();

    if (w.clientcache != null)
    {
        if (w.clientcache[type] == null)
        {
            w.clientcache[type] = new Object();
        }
    }
}

function clientcachedeletecache(type)
{
    w = crawltotop();

    if (w.clientcache != null)
    {
        if (w.clientcache[type] != null)
        {
            w.clientcache[type] = null;
        }
    }
}

function clientcachebuildindex(charset, id)
{
    if (charset == "iso-8859-1" || charset == "us-ascii")
    {
        charset = "";
    }

    index = charset + ':' + id;

    return index;
}

function clientcacheadd(type, index, element, value)
{
    var obj;

    w = crawltotop();

    if (w.clientcache != null)
    {
        if (w.clientcache[type] != null)
        {
            obj = w.clientcache[type][index];

            if (obj == null)
            {
                obj = new Object();

                now = new Date();
                obj.datestamp = now.getTime();

                obj.init = true;
            }

            obj[element] = value;

            w.clientcache[type][index] = obj;
        }
    }
}

function clientcacheget(type, index, maxage)
{
    var obj;

    value = null;

    w = crawltotop();

    if (w.clientcache != null)
    {
        if (w.clientcache[type] != null)
        {
            obj = w.clientcache[type][index];

            if (obj != null && obj.init)
            {
                now = new Date().getTime();

                datestamp = obj.datestamp;

                diff = now - datestamp;
                diff = diff / 1000;

                if (maxage == 0 || diff < maxage)
                {
                    value = obj;
                }
                else
                {
                    clientcacheremove(type, index);
                }
            }
        }
    }

    return value;
}

function clientcacheremove(type, index)
{
    var obj;

    w = crawltotop();

    if (w.clientcache != null)
    {
        if (w.clientcache[type] != null)
        {
            obj = w.clientcache[type][index];

            if (obj != null)
            {
                obj.init = false;

                w.clientcache[type][index] = null;

                obj = null;
            }
        }
    }
}

function clientcachepurge(type, maxage)
{
    if (maxage != 0)
    {
        w = crawltotop();

        if (w.clientcache != null)
        {
            if (w.clientcache[type] != null)
            {
                a = w.clientcache[type];

                for (index in a)
                {
                    obj = clientcacheget(type, index, maxage);
                }
            }
        }

        command = 'clientcachepurge("' + type + '", ' + maxage + ')';

        setTimeout(command, maxage * 1000);
    }
}
