﻿function AjaxObject()
{
	this.xhr_object = null;
	this.ReadyState = null;
	this.Status = null;
	this.SucceedFunction = null;
	this.FailedFunction = null;
	this.ContentType = null;
}

AjaxObject.prototype.Initialize = function()
{
	if (window.XMLHttpRequest) //MOZILLA
	{
		this.xhr_object = new XMLHttpRequest();
	}
	else
	{
		if (window.ActiveXObject) //IE7
		{
			try
			{
				this.xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try 
				{
					this.xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					this.xhr_object = false;
				}
			}
		}
	}
};

AjaxObject.prototype.Send = function(method, url, async, send)
{	
	// On ouvre la connexion et on passe les informations nécessaire à l'url
	this.xhr_object.open(method, url, async); 	
	var objAjax = this;
	this.xhr_object.onreadystatechange = function(){
			if(objAjax.xhr_object.readyState == 4)
			{
				if(objAjax.xhr_object.status == 200)
				{
					objAjax.SucceedFunction(objAjax.xhr_object.responseText, objAjax.xhr_object.responseXML);
				}
				else
				{
					objAjax.FailedFunction(objAjax.xhr_object.responseText, objAjax.xhr_object.responseXML);
				}
			}
		}
			
	if ( this.ContentType == null)
	{
		this.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
	}
		
	this.xhr_object.setRequestHeader("Content-Type", this.ContentType)
	this.xhr_object.send(send);
};

AjaxObject.prototype.RandomNumberForNoCache = function()
{
	return parseInt(Math.random()*99999999);
};
