// Nicolas DEROUET
// Ajax Lite 1.01
// 08/02/2010 11:45

function Ajax(id, url)
{
	this.xhr = null;
	this.obj = document.getElementById(id);
	this.url = url;
	this.tim = 0;

	if (window.XMLHttpRequest) this.xhr = new XMLHttpRequest();
	else if (window.ActiveXObject) this.xhr = new ActiveXObject('Microsoft.XMLHTTP');
	else alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest');

	this.Periodic = function(value) { this.tim = value; }

	this.GET = function(para)
	{
		try {
			this.xhr.open('GET',this.url+'?'+para,false);
			this.xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.xhr.send(null);
		} catch(e) {}
		this.getData('get',para);
	}

	this.POST = function(para)
	{
		try {
			this.xhr.open('POST',this.url,false);
			this.xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			this.xhr.setRequestHeader('Content-length',para.length);
			this.xhr.setRequestHeader('Connection','close');
			this.xhr.send(para);
		} catch(e) {}
		this.getData('post',para);
	}

	this.getData = function(type,para)
	{
		var oThis = this; var timer = this.tim;
		try {
			if (this.xhr.readyState!=4 || this.xhr.status!=200) timer=5;
			else this.obj.innerHTML = this.xhr.responseText;
		} catch(e) { timer=5; }

		if (this.tim != 0)
		{
			if (type == 'get')
				setTimeout(function () { oThis.GET(para) },timer*1000);
			else
				setTimeout(function () { oThis.POST(para) },timer*1000);
		}
	}
}
