function iescroll (){
		document.getElementById("popup").style.position = "absolute";		
		window.onscroll = function()
		{
				//compatible avec certains doctypes
				var scrollTop = document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;
				document.getElementById("popup").style.top = (scrollTop + hautfen) + "px";

		}
}

function Close_popup(){
	document.getElementById('popup').style.display='none';
	if (isIE == 0) document.getElementById('popup_fond').style.display='none';
}

function switcharg(rep){  
	if(document.getElementById){
        if (isIE == 1) var elt=document.getElementById('chargement');
		else var elt=document.getElementById('chargement2');
        if(rep == true){ 
                elt.style.display = "block";
        }
        else{
                elt.style.display = "none";
        }
    }
}

function popup(titre,contenu){  
	if(document.getElementById){
		var obj = document.getElementById('popup');
		obj.style.top = hautfen + "px";
		obj.style.left = leftfen + "px";
		obj.style.display = "block";
		if (isIE == 0) document.getElementById('popup_fond').style.display = "block";
		//fade(0);
		document.getElementById('popup_titre').innerHTML = titre;
		document.getElementById('popup_contenu').innerHTML = contenu;
	}
	if (isIE == 1){
		var scrollTop = document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop;
		document.getElementById("popup").style.top = (scrollTop + hautfen) + "px";
	}
}

function init_popup(){

	if (document.documentElement)
	{
		hautfen = (document.documentElement.clientHeight);
		leftfen = (document.documentElement.clientWidth);
	}
	else
	{
		hautfen = (window.innerHeight);
		leftfen = (window.innerWidth);
	}

	if(hautfen<500) hautfen = parseInt(hautfen/5);
	else hautfen = parseInt(hautfen/3);
	leftfen = (leftfen / 2) - 200

	if (typeof document.body.style.maxHeight != "undefined") {
	isIE=0;// IE 7, mozilla, safari, opera 9
	}else {
	isIE=1;// IE6, et versions antérieures
	}

	if (isIE == 1) iescroll();

}

var req_login = new AJAX();
req_login.setIndicatorFunction(switcharg);
req_login.setCallbackFunction(login_submit);

function login_check(){
	document.getElementById('errlogin').style.display = "";
	req_login.getFilePost("ajax_login.php", "email="+escape(document.login.email.value).replace(/\+/g,"%2B")+"&mp="+escape(document.login.mp.value).replace(/\+/g,"%2B"));
}

function login_submit(res_check){
	if(res_check == 'true'){	
		document.location.reload();
	}
	else {
		document.getElementById('errlogin').style.display = "block";
	}
	 
}


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

	if (typeof XMLHttpRequest == "undefined")
	  XMLHttpRequest = function() {
		try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {};
		try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {};
		try { return new ActiveXObject("Msxml2.XMLHTTP"); }     catch(e) {};
		try { return new ActiveXObject("Microsoft.XMLHTTP"); }  catch(e) {};
	 
		throw alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	  };
	this.xhr_object = new 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 {
					if(obj.xhr_object.status != 200 && obj.xhr_object.status != 304) alert("Une erreur " + obj.xhr_object.status + " est survenue, le serveur a detecté un problème dans les données transmises. Modifiez vos données ou bien contactez nous via la page contact si vous pensez que ces données sont correctes."); 
					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();
}
