var ns4 = (document.layers)? true:false;	  //NS 4
var Op = (navigator.userAgent.toLowerCase().indexOf('opera') > -1 && document.createTextNode);  // Opera 7
var ie4 = ((document.all)? true:false)&&!Op;	  //IE 4
var dom = (document.getElementById)? true:false;	  //DOM

function getXhr(){
	var getxhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
		getxhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
		try {
			getxhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			getxhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		getxhr = false; 
	} 
	return getxhr
}
function ajax (){
	if ( window == this || !this.constructeur )
		return new ajax;
	return this.constructeur(arguments[0]);
}
ajax.prototype= {
	readyfunc : Array(),
	tobj : Array(),
	constructeur : function (){
		this.arguments = arguments[0];
		this.o = getXhr();
		this.methode = 'POST';
		this.FileName = '';
		this.data = '';
		this.asynchrone = true;
		this.readyState = 0;
		for(var i=0;i<5;i++){this.readyfunc[i] = new Function();}
		this.ready();
		this.onend = null;
	},
	ready : function(){//on ne peut établir cette étape dans le constructeur, pour une raison inconnue (problème de référence de l'objet this)
		var _parent = this;
		_parent.o.onreadystatechange = function(){
			try{
				if(_parent.o.readyState==1)
					_parent.time = Date.parse(new Date());
				if(typeof _parent.readyfunc[_parent.o.readyState] =='function')
				{
					//alert(_parent.o.readyState+'  '+_parent.readyfunc[_parent.o.readyState])
					_parent.readyfunc[_parent.o.readyState](_parent);
				}
				if(_parent.o.readyState==4){
					eval(_parent.onend);
				}
				//cette ligne devrait éviter la répétition d'une fonction lors du mauvais changement d'indice d'un fonction, mais plante pour les grosses fonctions
				//_parent.readyfunc[_parent.o.readyState] = '';
			}catch(e){
				//alert(e)
			};
			//0 non initialisée
    		//1 l'ouverture de la connexion avec le serveur vient de se faire (open())
    		//2 envoi de la requête au serveur (send())
    		//3 le serveur est entrain d'envoyer les donnés
    		//4 terminée, toutes les données sont disponibles
		}
	},
	c: function(){
		this.constructeur();
	},
	executer : function (){
		this.o.open(this.methode,this.FileName,this.asynchrone);
		if( this.methode == 'POST' )
			this.o.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.o.send( this.data );
	},
	e : function(){
		this.executer()
	},
	s : function(){
		this.executer()
	},
	setAsynchrone : function(a){
		this.asynchrone = a;
	},
	A : function(a){
		this.asynchrone = a;
	},
	setData : function(a){
		this.data = a;
	},
	d: function(a){
		this.data = a;
	},
	setFileName: function(a){
		this.FileName = a;
	},
	f : function(a){
		this.FileName = a;
	},
	setFunction: function(nb,func){
		this.readyfunc[nb] = func;
	},
	F : function(nb,func){
		this.readyfunc[nb] = func;
	},
	setMethode : function(a){
		this.methode = a;
	},
	m : function(a){
		this.methode = a;
	},
	addObjet: function(a){
		this.tobj.push(a);
	},
	setObjet: function(a){
		this.tobj = Array(a);
	},
	videObjet: function(){
		this.tobj = Array();
	}
}

function maj_(param,val){eval(param+'=val');}//on peut se poser des questions sur la raison d'être de cette fonction
function cr(a){return document.createElement(a);}
function setEvent(obj,a,b){
//obj est l'objet sur lequel appliquer l'eventHandler
//a est le type d'event à mettre
//b est son contenu
	temp = a.replace(/on/,'');
	function toto(){eval(b);}
		//obj.attachEvent(onEvent,fonction);
		//obj.addEventListener(Event,fonction,false);
		//obj.removeEventListener(Event,fonction,false);
		//retirer les écouteurs d'événements attachés à cet objet auparavant
	if(false)//document.addEventListener)
	{
		obj.addEventListener(temp,toto,false);
	}
	else if(false)//document.attachEvent)
	{
		obj.attachEvent(a.toLowerCase(),toto);
	}
	else try{
			eval("obj."+a.toLowerCase()+" = toto;");
		}catch(e){obj.setAttribute(a,b);}
}

//function addEvent
//function removeEvent



function appartab(a,b){
//fonction retournant si un élément appartient à un tableau
//a est le tableau
//b est la valeur
	if(typeof a =='object'&&a.length!=undefined)
	{
		for(ap_i=0;ap_i<a.length;ap_i++)
		{
			if(a[ap_i]==b)
				return [true,ap_i];
		}
	}
	return [false]
}

function getElementsByClass(class_class,class_objet){
	getElementsByClass_tab = Array();
	allTags=(class_objet==undefined)?document.getElementsByTagName('*'):class_objet.getElementsByTagName('*');
	for(getElementsByClass_i=0;getElementsByClass_i<allTags.length;getElementsByClass_i++)
	{
		if(allTags[getElementsByClass_i].className==class_class)
		{
			getElementsByClass_tab[getElementsByClass_tab.length]=allTags[getElementsByClass_i];
		}
	}
	return getElementsByClass_tab;
}
function setStyle(a,b)
{
	if(ie4)
	{
		b = b.replace(/position:[ ]*fixed/,'position:absolute');
		a.style.setAttribute('cssText',b);
	}
	else
		a.setAttribute('style',b);
}
function addStyle(a,b)
{
	var c = getStyle(a);
	if(c.charAt(c.length-1)!=';')c += ';'
	if(b.charAt(b.length-1)!=';')b += ';'
	setStyle(a,c+b);
}
function getStyle(a)
{
	if(ie4)
		return a.style.getAttribute('cssText');
	return a.getAttribute('style');
}
function rendre_transparent(img){
	var imgName = img.src.toUpperCase()
	var arVersion = navigator.appVersion.split("MSIE" )
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters) && (imgName.substring(imgName.length-3, imgName.length) == 	"PNG" ))
	{
		//addStyle(img,"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"" + img.src + "\", sizingMethod=\"scale\" );");
		var imgID = (img.id) ? "id='" + img.id + "' " : ""
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
		if (img.align == "left") imgStyle = "float:left;" + imgStyle
		if (img.align == "right") imgStyle = "float:right;" + imgStyle
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		imgEvents = Array("onblur","onclick","ondblclick","onfocus","onkeydown","onkeypress","onkeyup","onload","onmousedown","onmousemove","onmouseout","onmouseover","onmouseup");
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\" ";
		for(var i=0;i<imgEvents.length;i++)
		{
			//alert("if (img."+imgEvents[i]+") strNewHTML+=' "+imgEvents[i]+" = '+img."+imgEvents[i]+";")
			eval("if (img."+imgEvents[i]+") strNewHTML+=' "+imgEvents[i]+" ='+img."+imgEvents[i]+"+' ';");
		}
		strNewHTML += "></span>" 
		//alert(strNewHTML)
		img.outerHTML = strNewHTML
	}
}