function AJAX() {
	
	this.xhr_object    = null;
	this.response      = null;
	this.ready         = true;
	this.asynchronous  = true;
	this.autovalidate  = false;

	if(window.XMLHttpRequest) // Firefox
		this.xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		this.xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");


	this.indicatorFunction = null;

	this.setIndicatorFunction = function(func) {
		if(typeof(func) == "function") this.indicatorFunction = func;
	}

	this.callbackFunction = null;

	this.setCallbackFunction = function(func) {
		if(typeof(func) == "function") {
            this.callbackFunction = func;
            this.autovalidate     = true;
        }
	}

	this.setSynchronous = function() {
		this.asynchronous = false;
	}

	this.setAsynchronous = function() {
		this.asynchronous = true;
	}

	this.getFileGet = function(url, data) {
		return this.doRequest(url, "GET", data);
	}

	this.getFile = this.getFileGet;
	
	this.getFilePost = function(url, data) {
		return this.doRequest(url, "POST", data);
	}

	this.getFileHeader = function(url, header) {
		return this.doRequest(url, "HEAD", header);
	}

	this.doRequest = function(url, method, data) {
		if(!this.ready || !this.xhr_object) return false;

		function _getResponseHeader(headers, header_name) {
			var tmp = headers.split("\n");
			for(var i=0, n=tmp.length, t=[]; i<n-1; ++i) {
				t = tmp[i].split(": ");
				if(t[0].toLowerCase() == header_name.toLowerCase()) return t[1];
			}
			return "Header inconnu...";
		}

		if(this.indicatorFunction) this.indicatorFunction(true);
		this.ready = false;

		var obj = this;
		function onreadystatechangeFunction() {
			if(obj.xhr_object.readyState != 4) return;
			
			if(obj.indicatorFunction) obj.indicatorFunction(false);

			var all_headers = obj.xhr_object.getAllResponseHeaders();
			if(method == "HEAD") {
				obj.response = data ? _getResponseHeader(all_headers, data) : all_headers;
			}
			else {
				var content_type = _getResponseHeader(all_headers, "Content-Type");
				if (content_type != "Header inconnu..." && (new RegExp("^text/xml.*$", "gi")).test(content_type))
					obj.response = obj.xhr_object.responseXML;
				else
					obj.response = obj.xhr_object.responseText;
				if (obj.callbackFunction) {
                    obj.callbackFunction(obj.xhr_object.responseText);
                    if (obj.autovalidate) obj.validateRequest();
                }
			}
		}

		if(method == "GET" && typeof(data) != "undefined" && data != "") url += "?"+data;
		this.xhr_object.open(method, _AJAX_addDummyData(url), this.asynchronous);

		if(this.asynchronous)
			this.xhr_object.onreadystatechange = onreadystatechangeFunction;
		
		if(data) this.xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		else     data = null;
		this.xhr_object.send(data);

		if(!this.asynchronous)
			onreadystatechangeFunction();

		return true;
	}

	this.hasResponse = function() {
		return this.response != null;
	}

	this.getResponse = function() {
		return this.response;
	}

    this.setAutoValidate = function(flag) {
        this.autovalidate = flag;
    }

	this.validateRequest = function() {
		this.ready    = true;
		this.response = null;
	}

	this.cancelRequest = function() {
		this.xhr_object.abort();
		if(this.indicatorFunction) this.indicatorFunction(false);
		this.validateRequest();
	}
}

function _AJAX_addDummyData(str) {
	var t = new Date();
    if (str.indexOf("?") == -1) str += "?ajax_dummy=";
    else                        str += "&ajax_dummy=";
	return str+t.getTime();
}

var req = new AJAX();
req.setIndicatorFunction(switcharg);
req.setCallbackFunction(aff_infos);

function switcharg(){
	document.getElementById('in').innerHTML ='<div style="text-align:center;padding-top:110px"><img src="img/bigrotation2.gif" alt="Chargement ..."/></div>';
}

function get(id){
	if(req.ready == true){
		req.getFilePost("ajax_get.php", "act=" + id);
	}
}

function aff_infos(str){
	document.getElementById('in').innerHTML = str;
	if (isIE == 0) {
		mySlide.hide();
		mySlide.toggle();
	}
}

var req1 = new AJAX();
req1.setCallbackFunction(res_submit);

function envoi_check(){
	if(req1.ready == true){
		req1.getFilePost("ajax_env.php", "email="+escape(document.formulaire.email.value).replace(/\+/g,"%2B")+"&objet="+escape(document.formulaire.objet.value).replace(/\+/g,"%2B")+"&message="+escape(document.formulaire.message.value).replace(/\+/g,"%2B"));
	}
}

function res_submit(str){
	var retour = str.split("<|>");
	retour.pop();
	
	if(retour[0] == 0){
		document.getElementById('in').innerHTML = retour[1];
	}
	else if(retour[0] > 0){

		var items = retour[1].split("|");
		items.pop();
		
		for(var y=1;y<=3;y++){
			document.getElementById(y).style.border = "1px solid #CCCCCC";
			document.getElementById(y+'a').style.display = "none";
			document.getElementById(y+'b').style.display = "none";
		}
		
		for(var y=0;y<retour[0];y++){
			document.getElementById(items[y]).style.display = "block";
			document.getElementById(items[y].substring(0,1)).style.border = "1px solid #FF0000";
		}
		
	}
}
