////////////////////////////////////////
// FONCTIONS XMLHTTPREQUEST
////////////////////////////////////////
var req;
var xmlUrl = "xml.php";
var startReq, endReq;
var loading = new Image();
	loading.src = "media/loading.gif";

function GnooCom(n)
{
	this.name = n;
	this.xmlUrl = "xml.php";
	this.req = false;
	this.param = "";	// paramêtres de la requête
	this.target = null; // div de destination
	///////////////////////////////
	// constructeur
	///////////////////////////////
	this.init = function()
	{
//		if(this.req)
//			this.req.abort();

		if(window.XMLHttpRequest)
		{
			try 
			{
				this.req = new XMLHttpRequest();
			} 
			catch(e)
			{
				this.req = false;
			}
			// branch for IE/Windows ActiveX version
		}
		else if(window.ActiveXObject)
		{
			try
			{
				this.req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try 
				{
					this.req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) 
				{
					this.req = false;
				}
			}
		}
		return this.req;
	}
	///////////////////////////////
	// chargement de XML
	///////////////////////////////
	this.loadXML = function(tg, r)
	{
		this.target = tg;
		/**
		 * 
		 */
		this.param = '';
		for(p in r)
			this.param += p+"="+r[p]+"&";
//		this.param = "act="+r['act']+"&game="+r["game"];
//		this.loaded[this.loaded.length] = {type:r["type"], target:tg};
		if(!this.req)
			this.init();
		if(this.req)
		{
			var tmp = document.getElementById(this.target);
			if(tmp)
			{
				tmp.innerHTML = '<div align="center" style="border: solid 0px red;text-align:center;"><img src="'+loading.src+'" border="0" align="center" /></div>';
				tmp.style.display = "block";
				tmp.style.visibility = "visible";
			}
//			this.req.abort();
			this.req.open("POST", this.xmlUrl, true);
			this.req.onreadystatechange = new Function("", this.name+".getXML();");
			this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.req.send(this.param);
		}
		return this.req;
	}
	///////////////////////////////
	// reception de XML
	///////////////////////////////
	this.getXML = function()
	{
		// only if req shows "loaded"
		if (this.req.readyState == 4) 
		{
			// only if "OK"
			if (this.req.status == 200) 
			{
				this.showData();
			}
			else
			{
				var tmp = document.getElementById(this.target);
				if(tmp)
				{
					tmp.innerHTML = '<div align="center" style="width:100%;border: solid 1px red;text-align:center;"><img src="'+loading.src+'" border="0" align="center" /></div>';
					tmp.style.display = "block";
					tmp.style.visibility = "visible";
				}
//				alert("There was a problem retrieving the XML data:\n"+this.req.statusText);
			}
		}
	}
	///////////////////////////////
	// affichage du résultat
	///////////////////////////////
	this.showData = function()
	{
		var tmp = document.getElementById(this.target);
		if(tmp)
		{
			tmp.innerHTML = this.req.responseText;
			tmp.style.display = "block";
			tmp.style.visibility = "visible";
		}
//		else
//			alert("destination inconnue");
	}
	///////////////////////////////
	// masquage du résultat
	///////////////////////////////
	this.hideData = function(tg)
	{
		var tmp = document.getElementById(tg);
		if(tmp)
		{
			tmp.innerHTML = "";
			tmp.style.display = "none";
			tmp.style.visibility = "hidden";
		}
//		else
//			alert("destination inconnue");
	}
	///////////////////////////////
	// annulation de la requête
	///////////////////////////////
	this.cancel = function()
	{
		if(this.req)
			this.req.abort();
	}
	///////////////////////////////
	return this;
///////////////////////////////
} // end class
///////////////////////////////

function askPwd(obj) {
	GC.loadXML('ccenterdata', {'act':'sendpwd', 'email':obj.form.elements['email'].value});
}
