/*
<form id="ceForm" onsubmit="return false;" action="temp.php" >
<input type="file" name="f" value="value2">
<input type="checkbox" name="check" value="value2">
<input type="radio" name="radio1" value="r1" >
<input type="radio" name="radio1" value="r2" >
<input name="name1" value="value2">
<input name="name2" value="value1">
<input name="hidden" value="value1">
<input type="hidden" name="jxaction" value="1_<?= md5("alosdk#1") ?>">
<img src="images/tables/4_mini.jpg"  onclick="jx( 'temp.php' , 'POST' , formElements('ceForm') ,false); ">
<input type="image" src="images/tables/4_mini.jpg"  onclick="jx( 'temp.php' , 'POST' , formElements('ceForm') ,false); ">


<input type="button" value="go" onclick="document.getElementById('dd').innerHTML='Wait...'+this.form.action;jx( this.form.action, 'GET' , formElements(this.form) ,true); ">
</form>


*/
var AJAX = {
	
	XMLHttpRequest: function()
	{
		var req = false;
		
		if(window.XMLHttpRequest && !(window.ActiveXObject))
		{
			try
			{
				req = new XMLHttpRequest();
			}
			catch(e)
			{
				req = false;
			}

		}
		else if(window.ActiveXObject)
		{
			try
			{
				req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					req = false;
				}
			}
		}
		
		return(req);
	},
	
	Response: function(xmlobject)
	{
		this.status = xmlobject.status;
		this.statusText = xmlobject.statusText;
		this.responseText = xmlobject.responseText;
		this.responseXML = xmlobject.responseXML;
	},
	
	Request: function(url, options)
	{
		if (!isset(url))
		{
			return(false);
		}
		
		this.url = url;
		this.method = (isset(options.method)) ? options.method : 'GET';
		this.asynchronous = (isset(options.asynchronous) && typeof(options.asynchronous) == "boolean") ? options.asynchronous : true;
		this.contentType = (isset(options.contentType)) ? options.contentType : 'application/x-www-form-urlencoded';
		this.parameters = (isset(options.parameters)) ? options.parameters : '';
		
		if (typeof(this.parameters.join) != "Undefined")
		{
			this.parameters = this.parameters.join("&");
		}
		
		this.encoding = (isset(options.encoding)) ? options.encoding : 'iso-8859-1';
		
		this.callbacks = {};
		
		this.dispatch = function(event, parameter)
		{
			if (isset(this.callbacks[event]))
			{
				if (isset(parameter))
				{
					this.callbacks[event](parameter);
				}
				else
				{
					this.callbacks[event]();
				}
			}
		}
		
		this.handler = function()
		{
			switch(this.object.readyState)
			{
				case 3:
					this.dispatch('onLoading');
					break;
				
				case 4:
					this.dispatch('onComplete', new AJAX.Response(this.object));
					break;
			}
		}
		
		if (isset(options.onComplete))
		{
			this.callbacks['onComplete'] = options.onComplete;
		}
		
		if (isset(options.onFailure))
		{
			this.callbacks['onFailure'] = options.onFailure;
		}
		
		this.object = new AJAX.XMLHttpRequest();
		
		if (!this.object)
		{
			this.dispatch('onFailure');
			return false;
		}

		this.object.onreadystatechange = this.handler.bind(this);
		
		if (this.method == "GET")
		{
			this.object.open(this.method, this.url + "?" + this.parameters, this.asynchronous);
		}
		else
		{
			this.object.open(this.method, this.url, this.asynchronous);
			
		}
		
		this.object.setRequestHeader("Content-Encoding", this.encoding);
		this.object.setRequestHeader("Content-Type", this.contentType);
		
		if (this.method == "GET")
		{
			this.object.send("");
		}
		else
		{
			this.object.send(this.parameters);
		}
		
		if (!this.asynchronous)
		{
			this.response = new AJAX.Response(this.object);
		}
	}
	
}

function isset(check)
{
	return(typeof(check) != "undefined");
}

Function.prototype.bind = function()
{
	var __method = this;
	args = $A(arguments);
	object = args.shift();
	
	return function()
	{
		return __method.apply(object, args.concat($A(arguments)));
	}
}

var $A = Array.from = function(iterable)
{
	if (!iterable) return [];
	if (iterable.toArray)
	{
		return iterable.toArray();
	}
	else
	{
		var results = [];
		for (var i = 0, length = iterable.length; i < length; i++)
		{
			results.push(iterable[i]);
		}
		return results;
	}
}


//fonction sycrone
function file(fichier)
     {
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest(); 
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
     else 
          return(false); 
     xhr_object.open("GET", fichier, false); 
     xhr_object.send(null); 
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
     }


function translate(champ){
	eval(file( "translate.ajax.php?champ="+ champ +"" ));
	return dictionnaire;	
}


function formElements(formulaire){
if(document.getElementById(formulaire))
	formulaire=document.getElementById(formulaire);
str="";

for (var i = 0; i < formulaire.length; i++) {

	if (formulaire.elements[i].type != "checkbox" && formulaire.elements[i].type != "radio") {
		str += formulaire.elements[i].name + "=" + formulaire.elements[i].value + "&";
	}
	if (formulaire.elements[i].type == "checkbox") {
		
		str += formulaire.elements[i].name + "=" + formulaire.elements[i].checked + "&";
	}
	if (formulaire.elements[i].type == "radio") {
		if(formulaire.elements[i].checked)
			str += formulaire.elements[i].name + "=" + formulaire.elements[i].value+ "&";
	}
	
	
}			


return str;


}


function jx( FILE , METHOD , DATA, evaluer )
{
        if( METHOD == 'GET' && DATA != null )
        {
                FILE += '?' + DATA;
                DATA = null;
        }

        var httpRequestM = null;   

                if( window.XMLHttpRequest )
                {   // Firefox   
                    httpRequestM = new XMLHttpRequest();
                }
                        else if( window.ActiveXObject )
                {   // Internet Explorer   
                    httpRequestM = new ActiveXObject( "Microsoft.XMLHTTP" );
                }
                        else
                {   // XMLHttpRequest non supporté par le navigateur   
                    return "Votre navigateur ne supporte pas les objets XMLHTTPRequest...";
                }   

                        httpRequestM.open( METHOD , FILE , true );
                        httpRequestM.onreadystatechange = function()
                        {   
                                if( httpRequestM.readyState == 4 )
                                {
									 if(httpRequestM.status == 200){
                                        if(evaluer)
											eval(httpRequestM.responseText);
										else
											alert(httpRequestM.responseText);
                                		}
										else
											alert(httpRequestM.statusText);
								}
                        }
        
                if( METHOD  == 'POST' )   
                {
                        httpRequestM.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" );
                }

         httpRequestM.send( DATA );   
}