
function ajax(_action)
{
	this.destination = "index.php";
	this.datas_url = "&ajax_action="+_action+""; 
	this.datas = ''; 
	this.id;
	this.retour = new Array;
	this.valeur = null;
	this.xhr_object = null;
	this.append = false;
	this.prepend = false;
	this.elsCB = new Array;
}

ajax.prototype.setAjax = function()
{
	for(var i = 0; i < this.elsCB.length; i++)
	{
		var divides = this.elsCB[i].split(':');
		this.retour[divides[0]] = divides[1];
		
		switch(divides[2])
		{
			case 'onclick':
				document.getElementById(divides[0]).onclick = function() { eval(divides[3]); };
				break;
				
			case 'onchange':
				document.getElementById(divides[0]).onchange = function() { eval(divides[3]); };
				break;
		}
	}
}
ajax.prototype.start = function()
{
	if(window.XMLHttpRequest) 
	{
		this.xhr_object = new XMLHttpRequest(); 
		this.open();
	}
	else if(window.ActiveXObject) 
	{
		this.xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		this.open();
	}
	else 
	{ 
		this.valeur = 'Cette application n�cessite l\'utilisation de requ�te XMLHTTP , votre navigateur ne supporte pas ce type d\'action.'; 
		this.end();
	} 
}

ajax.prototype.open = function()
{
	this.xhr_object.open('POST', this.destination, true); 
	this.send();
}

ajax.prototype.send = function()
{
	this.xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
	this.xhr_object.send(this.datas+this.datas_url);
	this.recieve();
}

ajax.prototype.recieve = function()
{
	var object = this;
	var xhr = this.xhr_object;
	xhr.onreadystatechange = function() 
	{ 
		if(xhr.readyState == 4 && xhr.status == 200) 
		{ 
			object.valeur  = xhr.responseText; 
			object.end();
		} 
	} 	
}

ajax.prototype.end = function()
{
	if(this.append) document.getElementById(this.retour[this.id]).innerHTML = document.getElementById(this.retour[this.id]).innerHTML+this.valeur;
	if(this.prepend) document.getElementById(this.retour[this.id]).innerHTML = this.valeur+document.getElementById(this.retour[this.id]).innerHTML;
	if(!this.append && ! this.prepend) document.getElementById(this.retour[this.id]).innerHTML = this.valeur;
	
	this.completed();
}

ajax.prototype.completed = function()
{
//a surcharger
}


