var http;
var http_state = true;
var title_graph;
var response = "";
var ref;
var calendar_div;


function createRequestObject()
{
	var ro;
	
	if(window.ActiveXObject)
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		ro = new XMLHttpRequest();
	}
	return ro;
}




function handleResponse()
{
	if(http.readyState == 4)
	{
		if(http.status == 200)
		{
			var response = http.responseText;
			if (response == 'ERROR')
			{
				document.getElementById('graph').innerHTML = "";
			}
			else 
			{
				document.getElementById('graph').innerHTML = "";
				document.getElementById('graph').innerHTML = response;
				if (title_graph != "")
				{
					document.getElementById('graph_title').innerHTML = title_graph;
				}
			}
		}
		else
		{
			document.getElementById('graph').innerHTML = "ERROR";
			document.getElementById('graph_title').innerHTML = "ERROR";
		}
    }
}


function handleResponse2()
{
	if(http.readyState == 4)
	{
        response = http.responseText;
		ref.innerHTML = response;
    }
}


function handleResponse3()
{
	if(http.readyState == 4)
	{

        response = http.responseText;
		calendar_div.innerHTML = response;
    }
}

function handleResponse4()
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
		if (response == 'ERROR')
		{
			document.getElementById('graph').innerHTML = "";
		}
		else 
		{
			document.getElementById('graph').innerHTML = response;
		}
    }
}

function updateGraph(_url, _graph_title)
{
	if (_graph_title != "")
	{
		title_graph = "<font class='point'>. :</font> "+_graph_title+" <font class='point'>: .</font>";
	}
	else
	{
		title_graph = "";
	}
	http = createRequestObject();
	http.abort();
	_rnd = "&randid=" + Math.floor((new Date()).getTime() / 1000);
    http.open('get', _url+_rnd, true);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function updateGraph2(_url, _id)
{
	isIE = (document.all);
	isNN6 = (!isIE) && (document.getElementById);

	
	if (isIE) menu = document.all['menu' + _id]; 
	if (isNN6) menu = document.getElementById('menu' + _id); 
	
	if (isIE) img = document.all['imgz' + _id]; 
	if (isNN6) img = document.getElementById('imgz' + _id);
	
	if (isIE) ref = document.all['ref' + _id]; 
	if (isNN6) ref = document.getElementById('ref' + _id); 
	
	tmpstring = img.src;
	if(tmpstring.indexOf("img/plus.png") != -1)
	{
		img.src = "img/moins.png";
	}
	else
	{
		img.src = "img/plus.png";
	}
	if (menu.style.display == "none")
	{
		menu.style.display = "";
		_tmp_loading = "";
		_tmp_loading += "<table align='center' cellpadding='0' cellspacing='0' width='600'>";
			_tmp_loading += "<tr valign='middle' height='50'>";
				_tmp_loading += "<td style='background-color: #1f5ac6;' width='1'></td>";
				_tmp_loading += "<td align='center' height='50' style='background-color: rgb(255, 255, 255);' width='598'>";
					_tmp_loading += "<img src='../design/loading.gif' border='0'>";
				_tmp_loading += "</td>";
				_tmp_loading += "<td style='background-color: #1f5ac6;' width='1'></td>";
			_tmp_loading += "</tr>";
		_tmp_loading += "</table>";
		ref.innerHTML = _tmp_loading;
		
		http = createRequestObject();
		http.abort();
		_rnd = "&randid=" + Math.floor((new Date()).getTime() / 1000);
		http.open('get', _url+_rnd);
		http.onreadystatechange = handleResponse2;
		http.send(null);
	}
	else
	{ 
		menu.style.display = "none";
		ref.innerHTML = "";
	}
}

function updateGraph3(_url)
{ 
	_tmp_loading = "<br>";
	_tmp_loading += "<table align='center' cellpadding='0' cellspacing='0' width='600'>";
		_tmp_loading += "<tr align='center' height='20'>";
			_tmp_loading += "<td class='td_style_title' colspan='3' align='center' height='20'><font class='point'>. :</font> Chargement des donn&eacute;es graphiques <font class='point'>: .</font></td>";
		_tmp_loading += "</tr>";
		_tmp_loading += "<tr valign='middle'>";
			_tmp_loading += "<td style='background-color: #1f5ac6;' width='1'></td>";
			_tmp_loading += "<td align='center' height='275' style='background-color: rgb(255, 255, 255);' width='598'>";
				_tmp_loading += "<img src='../design/loading.gif' border='0'>";
			_tmp_loading += "</td>";
			_tmp_loading += "<td style='background-color: #1f5ac6;' width='1'></td>";
		_tmp_loading += "</tr>";
		_tmp_loading += "<tr align='center' height='20'>";
			_tmp_loading += "<td class='td_style_title_2' colspan='3' align='center' height='20'></td>";
		_tmp_loading += "</tr>";
	_tmp_loading += "</table>";
	
	_tmp_loading += "<br>";
	
	_tmp_loading += "<table align='center' cellpadding='0' cellspacing='0' width='600'>";
		_tmp_loading += "<tr align='center' height='20'>";
			_tmp_loading += "<td class='td_style_title' colspan='3' align='center' height='20'><font class='point'>. :</font> Chargement des donn&eacute;s d&eacute;taill&eacute;es <font class='point'>: .</font></td>";
		_tmp_loading += "</tr>";
		_tmp_loading += "<tr valign='middle' height='275'>";
			_tmp_loading += "<td style='background-color: #1f5ac6;' width='1'></td>";
			_tmp_loading += "<td align='center' style='background-color: rgb(255, 255, 255);' width='598'>";
				_tmp_loading += "<img src='../design/loading.gif' border='0'>";
			_tmp_loading += "</td>";
			_tmp_loading += "<td style='background-color: #1f5ac6;' width='1'></td>";
		_tmp_loading += "</tr>";
		_tmp_loading += "<tr align='center' height='20'>";
			_tmp_loading += "<td class='td_style_title_2' colspan='3' align='center' height='20'></td>";
		_tmp_loading += "</tr>";
	_tmp_loading += "</table>";
	document.getElementById('graph').innerHTML = _tmp_loading;
	http = createRequestObject();
	http.abort();
    _rnd = "&randid=" + Math.floor((new Date()).getTime() / 1000);
	http.open('get', _url+_rnd);
    http.onreadystatechange = handleResponse4;
    http.send(null);
}



function updateCalendar(_url)
{
	isIE = (document.all)
	isNN6 = (!isIE) && (document.getElementById) 


	if (isIE)  calendar_div = document.all['calendar']; 
	if (isNN6) calendar_div = document.getElementById('calendar'); 
	
	http = createRequestObject();
	http.abort();
    _rnd = "&randid=" + Math.floor((new Date()).getTime() / 1000);
	http.open('get', _url+_rnd);
    http.onreadystatechange = handleResponse3;
    http.send(null);
}