



var Chart = function()
{
	Chart.inst = this;
	this.tip = new Object();
	//this.tip['options'] = '<b>Tip:</b> You can turn the Forecast and Revision on/off.';
	this.tip['scrolling'] = '<b>Tip:</b> You can zoom in/out using your mouse wheel.';
	this.tip['dragging'] = '<b>Tip:</b> You can drag the chart or sub-chart.';
	
}

Chart.inst = null;
Chart.prototype.tip = null;
Chart.prototype.chart = null;

Chart.getInst = function()
{
	if (Chart.inst == null)
		Chart.inst = new Chart();
		
	return Chart.inst;
}

Chart.prototype.getUsedTips = function()
{
	var used_tips = fetch_cookie('used_tips');
	
	if (used_tips == null)
		used_tips = new Array();
	else
		used_tips = used_tips.split(',');
		
	return used_tips;
}

Chart.prototype.showTip = function(event_id)
{
	var used_tips = this.getUsedTips();
	
	if (used_tips.length < count(this.tip))
	{	
		var available_tips = [];
		
		for (var tip in this.tip)
		{
			if (PHP.in_array(tip, used_tips, false) == -1)
			{
				available_tips.push(this.tip[tip]);
			}
			
		}
		
		var tip_container = fetch_object('chart_tip_' + event_id);		
		tip_container.innerHTML = available_tips[Math.floor(Math.random() * available_tips.length)];
	}
	
}

Chart.prototype.removeTip = function(tip)
{
	var used_tips = this.getUsedTips();
	
	if (PHP.in_array(tip, used_tips, false) == -1)
	{
		used_tips.push(tip);
		var new_cookie_val = implode(',', used_tips);
		
		var expires = new Date();
		expires.setDate(expires.getDate() + 365); //in a year

		set_cookie('used_tips', new_cookie_val, expires);
	}	
}

function count( mixed_var, mode ) {
    // Count the number of elements in a variable (usually an array)  
    // 
    // version: 812.316
    // discuss at: http://phpjs.org/functions/count
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Waldo Malqui Silva
    // *     example 1: count([[0,0],[0,-4]], 'COUNT_RECURSIVE');
    // *     returns 1: 6
    // *     example 2: count({'one' : [1,2,3,4,5]}, 'COUNT_RECURSIVE');
    // *     returns 2: 6
    var key, cnt = 0;

    if( mode == 'COUNT_RECURSIVE' ) mode = 1;
    if( mode != 1 ) mode = 0;

    for (key in mixed_var){
        cnt++;
        if( mode==1 && mixed_var[key] && (mixed_var[key].constructor === Array || mixed_var[key].constructor === Object) ){
            cnt += count(mixed_var[key], 1);
        }
    }

    return cnt;
}

function implode( glue, pieces ) {
    // Joins array elements placing glue string between items and return one string  
    // 
    // version: 812.316
    // discuss at: http://phpjs.org/functions/implode
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'
    return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}








