function JSON () {
    this.responsedata = {};
    var that = this;
    this.cache = [];
    
    this.jsoneval = function ( responseText ) {
        eval(responseText);
        if( responsedata ) {
            that.responsedata = responsedata;
        }
    }
    
    this.get = function ( params, myfunction ) {
        if( that.cache[params] ) {
            that.responsedata = that.cache[params];
            myfunction();
        } else {
            new ajax( '/exec/json.php', {
                postBody: 'get=1&' + params, 
                onComplete: function ( res ) {
                    that.jsoneval( res.responseText )
                    that.cache[params] = that.responsedata;
                    myfunction();
                }
            });
        }
    }
}
JSON.prototype = new Base();

var now_date = new Date();
var weekday = now_date.getDay();
if( parseInt( weekday ) == 0 ) {
    weekday = 7;
}
    weekday = weekday - 1;
var now_type = 0;
var now_sport = 0;
var json = new JSON();  

function listTvProgram( s_weekday, s_type, linkobj ) {
    if ( weekday == s_weekday && now_type == s_type )
        return false;
    var q = 'for=tv&weekday=' + s_weekday + '&type=' + (s_type);
    json.get( q, function() {

        _( 'time_' + weekday + '_' + now_type ).style.fontWeight = 'normal';
        _( 'time_' + weekday + '_' + now_type ).style.cursor     = '';
        _( 'time_' + weekday + '_' + now_type ).style.color      = '';

        weekday = s_weekday;
        now_type = s_type;
        _( 'time_' + weekday + '_' + now_type ).style.fontWeight = 'bold';
        _( 'time_' + weekday + '_' + now_type ).style.cursor     = 'default';
        _( 'time_' + weekday + '_' + now_type ).style.color      = '#20201E';

        var block = _('tv_block_' + parseInt(weekday+1)).getElementsByTagName('table')[0];
        var tbody = block.getElementsByTagName('tbody')[0]
        if( json.Browser.IE ) {
            for ( ; 0 < tbody.rows.length; ) tbody.deleteRow(0); 
        } else {
            tbody.innerHTML = '';   
        }
        i = 1;
        for(key in json.responsedata.data[0]) {
            tr = tbody.insertRow(-1);
            tr.className = ( ( i % 2 ) == 0 ) ? "" : "bg_light_gray";
            td = tr.insertCell(0);
            td.innerHTML = json.responsedata.data[0][key][0].tvtime;
            td = tr.insertCell(1);
            td.innerHTML = json.responsedata.data[0][key][0].channel;
            td = tr.insertCell(2);
            td.innerHTML = json.responsedata.data[0][key][0].program;
            i++;
        }
            
    });
    return false;
}

function listResult( s_sport, linkobj ) {
    if ( now_sport == s_sport )
        return false;
    var q = 'for=calendar&type=' + (s_sport);
    json.get( q, function() {
        _( 'result_0_' + now_sport ).style.fontWeight = 'normal';
        now_sport = s_sport;
        _( 'result_0_' + now_sport ).style.fontWeight = 'bold';
        var block = _('calendar_block_0').getElementsByTagName('table')[0];
        var tbody = block.getElementsByTagName('tbody')[0]
        if( json.Browser.IE ) {
            for ( ; 0 < tbody.rows.length; ) tbody.deleteRow(0); 
        } else {
            tbody.innerHTML = '';   
        }
        i = 1;
        for(key in json.responsedata.data[0]) {
            tr = tbody.insertRow(-1);
            tr.className = ( ( i % 2 ) == 0 ) ? "" : "bg_light_gray";
            td = tr.insertCell(0);
            td.innerHTML = json.responsedata.data[0][key][0].section_id;
            td = tr.insertCell(1);
            td.innerHTML = json.responsedata.data[0][key][0].name;
            td = tr.insertCell(2);
            td.innerHTML = json.responsedata.data[0][key][0].result;
            i++;
        }
            
    });
    return false;
}