function $(id)
{
    if (!id) 
    {
        return null;
    }
    
    var element = document.getElementById(id);
    
    if (!element && document.all) 
    {
        element = document.all[id];
    }
    
    return element;
}

function show(id)
{
    $(id).style.display = 'block';
}

function hide(id)
{
    $(id).style.display = 'none';
}

function toggle(id)
{
    $(id).style.display = $(id).style.display == 'block' ? 'none' : 'block';
}


function get_cookie_value (offset) 
{
    var endstr = document.cookie.indexOf (';', offset);
    if (endstr == -1) 
    {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

function get_cookie(name)
{
    var arg = name + '=';
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) 
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) 
        {
            return get_cookie_value(j);
        }
        i = document.cookie.indexOf(' ', i) + 1;
        if (i == 0) 
        {
            break;
        }
    }
    return null;
}

function set_cookie(name, value, expires, path, domain, secure) 
{
    document.cookie = name + '=' + escape (value) +
    ((expires) ? '; expires=' + expires.toGMTString() : '') +
    ((path) ? '; path=' + path : '') +
    ((domain) ? '; domain=' + domain : '') +
    ((secure) ? '; secure' : '');
}

function cookie_time(days)
{
    return new Date(new Date().getTime() + days * 24 * 60 * 60 * 1000);
}
 
function toggle_day_graph(url)
{
    hide('nightgraph');
    show('daygraph')
    
    ct = cookie_time(365);
    
    if ($('daygraph').style.display != 'none')
    {
        if ($('daygraph').innerHTML == '')
        {
            $('daygraph').innerHTML = url;
        }        
        
        $('a_day').style.color = '#ff1482';
        $('a_night').style.color = '#003399';
//        show('closegraph');
        set_cookie('graph', 'day', ct, '/');
    }
    else
    {
        $('a_day').style.color = '#003399';
//        hide('closegraph');
        set_cookie('graph', 'none', ct, '/');
    }
}

function toggle_night_graph()
{
    hide('daygraph');
    show('nightgraph')
    
    ct = cookie_time(365);

    if ($('nightgraph').style.display != 'none')
    {
        if ($('nightgraph').innerHTML == '')
        {
            $('nightgraph').innerHTML = url;
        }
        
        $('a_night').style.color = '#ff1482';
        $('a_day').style.color = '#003399';
//        show('closegraph');
        set_cookie('graph', 'night', ct, '/');
    }
    else
    {
//        hide('closegraph');
        $('a_night').style.color = '#003399';
        set_cookie('graph', 'none', ct, '/');
    }

}
