function chars_remain(obj)
{
    //alert(obj.id);
    var length = 100 - $('#'+obj.id).val().length;
    $('#chars_'+obj.id).html(length);
}

function show_days(obj, day_select_id)
{
    if($('#'+obj.id).val() == '') return;
    
    $.post('my.php',
    {
        date: $('#'+obj.id).val(),
        aj_get_days: true,
        id: obj.id,
        day_id: day_select_id
    },
    function(data)
    {
        //alert(data);
        //prefix various months selects with months_ and days_
        $('#month_select_id').val(obj.id);
        //$('#day_select_id').val(obj.id);

        //alert($('#month_select_id').val());
        //alert($('#day_select_id').val());
        $('#days_span_'+day_select_id).html('<br /><br /><b>You may also choose a specific day of the month.  Leave this option blank to view stats for a whole month.</b><br />'+data);
    }
    );
}

function update_day_select_id(obj)
{
    $('#day_select_id').val(obj.id);
}

function check_impressions(month_a, month_b)
{
    //alert($('#month_select_id').val());
    //alert($('#day_select_id').val());
    if($('#'+month_a).val() == '' || $('#'+month_b).val() == '')
    {
            alert('Please choose a month from each of the drop down boxes.');
            return false;
    }
    else
    {
        $('#imp_graph_loader').html('<img src="images/graph_loader.gif" style="border:0px;" /><b>Loading Graph...</b>');
        
        $.post($('#url').val(),
        {
            json: true,
            month_a: $('#'+month_a).val(),
            month_b: $('#'+month_b).val(),
            imp_day_a: $('#imp_day_a').val(),
            imp_day_b: $('#imp_day_b').val(),
            user_id: $('#user_id').val(),
            check_impressions: true
        },
        function(data)
        {
            //alert(data);
            var json = new Object;
            json = JSON.parse(data);

            //table view html...
            //$('#table_view').html(json.table_view);

            // Create our data table.
            var g = new google.visualization.DataTable();

            for(var ix = 0; ix < json.columns.length; ix++)
            {
                g.addColumn('number', json.columns[ix]);
            }

            g.addRows(json.rows.length);

            for(var y = 0; y < json.rows.length; y++)
            {
                for(var iy = 0; iy < json.rows[y].length; iy++)
                {
                    g.setValue(y,iy,parseInt(json.rows[y][iy]));
                }
            }

            // Instantiate and draw our chart, passing in some options.
            var chart = new google.visualization.ColumnChart(document.getElementById('imp_compare_graph'));
            chart.draw(g, {width: 900,
                height: 600,
                title: json.graph_title,
                legend: "right",
                fontSize: 13,
                fontName: "Arial",
                chartArea: {left: 75, width: 600},
                hAxis: {title: "Impression Count Comparison"}});

             $('#imp_graph_loader').html('');

        });
    }
    return false;

}


function check_clicks(month_a, month_b)
{
    //alert($('#month_select_id').val());
    //alert($('#day_select_id').val());
    if($('#'+month_a).val() == '' || $('#'+month_b).val() == '')
    {
            alert('Please choose a month from each of the drop down boxes.');
            return false;
    }
    else
    {
        $('#cli_graph_loader').html('<img src="images/graph_loader.gif" style="border:0px;" /><b>Loading Graph...</b>');

        $.post($('#url').val(),
        {
            json: true,
            month_a: $('#'+month_a).val(),
            month_b: $('#'+month_b).val(),
            cli_day_a: $('#cli_day_a').val(),
            cli_day_b: $('#cli_day_b').val(),
            user_id: $('#user_id').val(),
            check_clicks: true
        },
        function(data)
        {
            //alert(data);
            var json = new Object;
            json = JSON.parse(data);

            //table view html...
            //$('#table_view').html(json.table_view);

            // Create our data table.
            var g = new google.visualization.DataTable();

            for(var ix = 0; ix < json.columns.length; ix++)
            {
                g.addColumn('number', json.columns[ix]);
            }

            g.addRows(json.rows.length);

            for(var y = 0; y < json.rows.length; y++)
            {
                for(var iy = 0; iy < json.rows[y].length; iy++)
                {
                    g.setValue(y,iy,parseInt(json.rows[y][iy]));
                }
            }

            // Instantiate and draw our chart, passing in some options.
            var chart = new google.visualization.ColumnChart(document.getElementById('cli_compare_graph'));
            chart.draw(g, {width: 900,
                height: 600,
                title: json.graph_title,
                legend: "right",
                fontSize: 13,
                fontName: "Arial",
                chartArea: {left: 50, width: 650},
                hAxis: {title: "Click Count Comparison"}});

             $('#cli_graph_loader').html('');

        });
    }
    return false;

}



function check_current()
{
    //alert($('#stat_form').serialize());

    //alert('here');
    if($('#cur_month_a').val() == '')
    {
            alert('Please choose a month from the drop down box.');
            return false;
    }
    else
    {
        $('#cur_graph_loader').html('<img src="images/graph_loader.gif" style="border:0px;" /><b>Loading Data...</b>');

    //    var month_id = $('#cur_month_a').val();
    //    var day_id = $('#dcur_month_a').val();
    //    alert(month_id);
    //    alert(day_id);
        $.post($('#url').val(),
        {
            json: true,
            month_select: $('#cur_month_a').val(),
            day_select: $('#cur_day_a').val(),
            check_current: true,
            user_id: $('#user_id').val()
        },
        function(data)
        {
            //alert(data);
            var json = new Object;
            json = JSON.parse(data);

            //table view html...
            $('#table_view').html(json.table_view);
            $('#cur_graph_loader').html('');

//            // Create our data table.
//            var g = new google.visualization.DataTable();
//
//            for(var ix = 0; ix < json.columns.length; ix++)
//            {
//                g.addColumn('number', json.columns[ix]);
//            }
//
//            g.addRows(json.rows.length);
//
//            for(var y = 0; y < json.rows.length; y++)
//            {
//                for(var iy = 0; iy < json.rows[y].length; iy++)
//                {
//                    g.setValue(y,iy,parseInt(json.rows[y][iy]));
//                }
//            }
//
//            // Instantiate and draw our chart, passing in some options.
//            var chart = new google.visualization.ColumnChart(document.getElementById('cur_compare_graph'));
//            chart.draw(g, {width: 800,
//                height: 600,
//                title: json.graph_title,
//                legend: "bottom"});

             

        });
    }
    return false;
}
