// for Internet Explorer (using conditional comments)
var ie_inited = false;
/*@cc_on @*/
/*@if (@_win32)
ie_inited = true;
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
  if (this.readyState == "complete") {
    init(); // call the onload handler
  }
};
/*@end @*/
if(!ie_inited){
	if (/WebKit/i.test(navigator.userAgent)) { // sniff
		var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				clearInterval(_timer);
				init(); // call the onload handler
			}
		}, 10);
	}else if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	}else{
		window.onload = init
	}
}

var initList = initList || new Array();
function init(){
	for(var i=0; i<initList.length; i++){
		initList[i]();
	} 
}



var infoBulle;

initList.push(
	function(){
		infoBulle=document.createElement("div");
		infoBulle.setAttribute("id", "infoBulle");
		document.getElementsByTagName("body")[0].appendChild(infoBulle);
	});

function mel(str){
	 location.href = 'mailto:' + str.replace('/', '@');
}
function getElementsByClass(searchClass,node,tag) {
	node = node || document.getElementsByTagName("body")[0];
	tag = tag || "*";
	var classElements = new Array();
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");
	for (ii = 0, j = 0; ii < elsLen; ii++) {
		 if ( pattern.test(els[ii] .className) ) {
		 	classElements[j] = els[ii];
		 	j++;
		}
	}
	return classElements;
}




function makeHandler(txt){
		return function(evt){
			var x;
			var y;
			if (document.all) {
				  x=event.clientX+document.documentElement.scrollLeft; 
				  y=event.clientY+document.documentElement.scrollTop;
			 } else {
				  x=evt.pageX; 
				  y=evt.pageY; 
			  }
			showBulle(x, y, txt);
			if(evt){
				evt.stopPropagation();
				evt.preventDefault();
			}else if(event){
				event.cancelBubble =true;
			}
			return false;
		};
	}
	
	function showBulle(x,y,texte) {
		var xOffset=15;
		var yOffset=15;
		var bulle = document.getElementById("infoBulle");
		bulle.innerHTML = texte;
		var w = getWidth(bulle);
		if( (x + xOffset - scrollX() + w) > windowWidth() ){
			x -= w;
			x -= xOffset;
		}else{
			x += xOffset
		}
		var h = getHeight(bulle);
		//Sous ie la valeur getHeight est incorrecte, on tente une approximation
		if(isNaN(h)){
			//on estime une ligne à 50 caractères
			h = Math.floor(16*(texte.length/50))
			//on ajoute une ligne par balise br
			var brs =  texte.match(/<br\s*\/?>/gi)
			if(brs) h+=brs.length;
		}
		if((y + yOffset -scrollY() + h) > windowHeight()){
			y = (windowHeight() + scrollY() - h - yOffset);
		}else{
			y += yOffset;
		}
	    bulle.style.left = x + "px";
	    bulle.style.top = y + "px";
	    bulle.style.visibility="visible";
	    return false;
	}
	
	function hideBulle() {
		document.getElementById("infoBulle").style.visibility="hidden";
	}
	
	// Find the height of the viewport
function windowHeight() {
	// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
	var de = document.documentElement;
	// If the innerHeight of the browser is available, use that
	return self.innerHeight ||
		// Otherwise, try to get the height off of the root node
		( de && de.clientHeight ) ||
		// Finally, try to get the height off of the body element
		document.body.clientHeight;
}

// Find the width of the viewport
function windowWidth() {
	// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
	var de = document.documentElement;
	// If the innerWidth of the browser is available, use that
	return self.innerWidth ||
		// Otherwise, try to get the width off of the root node
		( de && de.clientWidth ) ||
		// Finally, try to get the width off of the body element
		document.body.clientWidth;
}

// A function for determining how far horizontally the browser is scrolled
function scrollX() {
	// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
	var de = document.documentElement;
	// If the pageXOffset of the browser is available, use that
	return self.pageXOffset ||
		// Otherwise, try to get the scroll left off of the root node
		( de && de.scrollLeft ) ||
		// Finally, try to get the scroll left off of the body element
		document.body.scrollLeft;
}

// A function for determining how far vertically the browser is scrolled
function scrollY() {
	// A shortcut, in case we're using Internet Explorer 6 in Strict Mode
	var de = document.documentElement;
	// If the pageYOffset of the browser is available, use that
	return self.pageYOffset ||
		// Otherwise, try to get the scroll top off of the root node
		( de && de.scrollTop ) ||
		// Finally, try to get the scroll top off of the body element
		document.body.scrollTop;
}

// Get a style property (name) of a specific element (elem)
function getStyle( elem, name ) {
	// If the property exists in style[], then it's been set
	// recently (and is current)
	if (elem.style[name])
		return elem.style[name];
	// Otherwise, try to use IE's method
	else if (elem.currentStyle)
		return elem.currentStyle[name];
	// Or the W3C's method, if it exists
	else if (document.defaultView && 
		document.defaultView.getComputedStyle) {
		// It uses the traditional 'text-align' style of rule writing,
		// instead of textAlign
		name = name.replace(/([A-Z])/g,"-$1");
		name = name.toLowerCase();
		// Get the style object and get the value of the property (if it exists)
		var s = document.defaultView.getComputedStyle(elem,"");
		return s && s.getPropertyValue(name);
		// Otherwise, we're using some other browser
	} else
	return null;
}
function getHeight( elem ) {
	// Gets the computed CSS value and parses out a usable number
	return parseInt( getStyle( elem, 'height' ) );
}

// Get the actual width (using the computed CSS) of an element
function getWidth( elem ) {
	// Gets the computed CSS value and parses out a usable number
	return parseInt( getStyle( elem, 'width' ) );
}

// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)
function getXMLHTTP() {
	var xhr = null;
	if (window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if (window.ActiveXObject) { // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	} else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}
	return xhr;
}
