/*
************************************************
**  Augustin de Pr�ville <augustin AT fidesio DOT com>,
**	
**  COPYRIGHT FIDESIO - REUTILISATION INTERDITE SANS AUTORISION
**
**	Pour Fidesio  <info AT fidesio DOT com>
**
************************************************
*/

function auto_mod()
{
	var oAjax = new ajax('automoderation.php');
	oAjax.setVar('auto_moderation','auto_moderation');
	oAjax.setVar('value', $('auto_moderation').value);
	oAjax.onFinish = function() { document.getElementById('auto_message').innerHTML = this.sReturn; };
	oAjax.run();
}

function change_region(select){
    var region = new ajax('region.php');
    region.setVar('id_country', select.value);
    alert(select.value);
    
    region.onFinish = function() { document.getElementById('region_id').innerHTML = this.sReturn; };
    region.run();
}

function change(var_menu, niveau, step, type)
{
	var menu = new ajax('cat.php');
	if(type == 1)
		menu.setVar('order', '1');
	else if(type == 2)
		{
		menu.setVar('order', '2');
		}
	menu.setVar('menu', var_menu.value);
	menu.setVar('niveau', niveau + 1);
	if(step == 1)
	{
		menu.setVar('cat', 'category');
		menu.onFinish = function() { document.getElementById('niveau' + niveau).innerHTML = this.sReturn; } ;
	}
	if(step == 2)
	{
		if(type == 1)
			menu.setVar('cat', 'interactivity');
		else if(type == 2)
			{
			menu.setVar('cat', 'activity');
			menu.setVar('c_step', '3');
			}
		menu.onFinish = function() { document.getElementById('level').innerHTML = this.sReturn;};
	}
	if(step == 3)
	{
		menu.setVar('cat', 'interactivity');
		menu.onFinish = function() { document.getElementById('niveau' + niveau).innerHTML = this.sReturn; };
		if(document.getElementById('actselect' + (niveau-2)) != null)
			document.getElementById('actselect' + (niveau-2)).name = 'actselect' + (niveau-1);
	}
	menu.run();
}





function ajax(sFile)
{

	this.create = function(sFile)
	{
		if (sFile) this.sFile = sFile; else this.sFile = '';
		this.sMethod = 'POST';
		this.sUrl = '';
		this.sReturn = '';

		this.onFinish = function() { };

		this.isEncodeURI = true;

		this.oXmlhttp = false;
		
		try { this.oXmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e)
		{
			try { this.oXmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (err)
			{
				this.oXmlhttp = null;
			}
		}

		if(!this.oXmlhttp && typeof XMLHttpRequest != "undefined")
			this.oXmlhttp = new XMLHttpRequest();
	
		if (!this.oXmlhttp)
			this.isOk = false;
		else
			this.isOk = true;
	};

/*
*****************************************************
**
**
*****************************************************
*/

	this.setVar = function(name, value)
	{
		
		if (this.sUrl.length < 3)
			this.sUrl = name + "=" + value;
		else
			this.sUrl += "&" + name + "=" + value;
	};

/*
*****************************************************
**
**
*****************************************************
*/

	this.encVar = function(name, value)
	{
		return encodeURIComponent(name) + "=" + encodeURIComponent(value);
	};

/*
*****************************************************
**
**
*****************************************************
*/

	this.encodeURL	= function(sUrl)
	{
		if (!sUrl) return '';
	
		var	aVar = sUrl.split('&');
		
		for (i = 0; i < aVar.length; i++)
		{
			var	aUrl = aVar[i].split('=');

			if (aUrl[0].indexOf('amp;') != -1)
				aUrl[0] = aUrl[0].substring(4);
				
			aVar[i] = this.encVar(aUrl[0],aUrl[1]);
		}
		return aVar.join('&');
	};

/*
*****************************************************
**
**
*****************************************************
*/		
	
	this.run = function(sUrlString)
	{
		if(!this.isOk) return;

		this.aStatus = new Array(2);

		if (sUrlString)
		{ 
			if (this.sUrl.length)
				this.sUrl = this.sURL + "&" + sUrlString;
			else
				this.sUrl = sUrlString; 
		}

		if (this.isEncodeURI)
		{
			this.sUrl = this.encodeURL(this.sUrl);
			this.setVar("rand", new Date().getTime());
		}

/*
******************************************************************************************
*/
/*
******************************************************************************************
*/

		
		if (this.oXmlhttp)
		{
			var self = this;

			if (this.sMethod == 'GET')
				this.oXmlhttp.open(this.sMethod,  this.sFile + "?" + this.sUrl, true);
			else
				this.oXmlhttp.open(this.sMethod, this.sFile, true);

			if (this.sMethod == 'POST')
			{
  				try { this.oXmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded') }
				catch (e) {}
			}

			this.oXmlhttp.send(this.sUrl);
			this.oXmlhttp.onreadystatechange = function()
			{
				switch (self.oXmlhttp.readyState)
				{
					case 1:	case 2:	case 3:	break;
					case 4:
							self.sReturn = self.oXmlhttp.responseText;
							self.sReturnXML = self.oXmlhttp.responseXML;
							self.aStatus[0] = self.oXmlhttp.status;
							self.aStatus[1] = self.oXmlhttp.statusText;
							self.onFinish();
							self.sUrl = '';
					break;
				}
			};
		}
	};

/*
*****************************************************
**
**
*****************************************************
*/

	this.create(sFile);
}



