function gid(id) {
    return document.getElementById(id);
}

function addSmiley(text, id) {
	var txtarea = gid(id);
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function toggle3( targetId ){
  if (document.getElementById){
  		target1 = document.getElementById( targetId );
		if (target1.style.display == "none"){
			target1.style.display = "";
		} else {
			target1.style.display = "none";
		}
  	}
}

function setVisible( targetId ){
  if (document.getElementById){
  		target1 = gid( targetId );
		target1.style.display = "";
  	}
}

function setHidden( targetId ){
  if (document.getElementById){
  		target1 = gid( targetId );
		target1.style.display = "none";
  	}
}
/*
// Agrandir textarea
function biggerTextArea(id, nb=5) {
	gid(id).rows += nb;
}

// Diminue textarea
function smallerTextArea(id, nb=5) {
	gid(id).rows -= nb;
}
*/
// bascule de visibilité
function toggle( targetId ){
  if (document.getElementById){
  		target1 = document.getElementById( targetId );
  		img = document.getElementById( 'img_'+targetId );
		if (target1.style.display == "none"){
			target1.style.display = "";
			img.src = '/images/moins.png';
		} else {
			target1.style.display = "none";
			img.src = '/images/plus.png';
		}
  	}
}


// Ouvrir tout
function openAll(idArray)
{
	for(var i=0;i<idArray.length;i++) {
		target1 = document.getElementById( idArray[i] );
  		img = document.getElementById( 'img_'+idArray[i] );
  		target1.style.display = "";
		img.src = '/images/moins.png';
	}
}

// Ferme tout
function closeAll(idArray)
{
	for(var i=0;i<idArray.length;i++) {
		target1 = document.getElementById( idArray[i] );
  		img = document.getElementById( 'img_'+idArray[i] );
  		target1.style.display = "none";
		img.src = '/images/plus.png';
	}
}

// bascule de visibilité (Version 2 ids)
function toggle2( targetId ){
  if (document.getElementById){
  		target1 = document.getElementById( targetId+'1' );
  		target2 = document.getElementById( targetId+'2' );
  		img = document.getElementById( 'img_'+targetId );
		if (target1.style.display == "none"){
			target1.style.display = "";
			target2.style.display = "";
			img.src = '/images/moins.png';
		} else {
			target1.style.display = "none";
			target2.style.display = "none";
			img.src = '/images/plus.png';
		}
  	}
}


// Ouvrir tout (Version 2 ids)
function openAll2(idArray)
{
	for(var i=0;i<idArray.length;i++) {
		target1 = document.getElementById( idArray[i]+'1' );
		target2 = document.getElementById( idArray[i]+'2' );
  		img = document.getElementById( 'img_'+idArray[i] );
  		target1.style.display = "";
  		target2.style.display = "";
		img.src = '/images/moins.png';
	}
}

// Ferme tout (Version 2 ids)
function closeAll2(idArray)
{
	for(var i=0;i<idArray.length;i++) {
		target1 = document.getElementById( idArray[i]+'1' );
		target2 = document.getElementById( idArray[i]+'2' );
  		img = document.getElementById( 'img_'+idArray[i] );
  		target1.style.display = "none";
  		target2.style.display = "none";
		img.src = '/images/plus.png';
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - ( smooth scrolling between internal links ) - - - - - - - - - - - 
// http://www.sitepoint.com/article/scroll-smoothly-javascript
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// set vars
var ss_INTERVAL;
var ss_STEPS = 15;

function ss_fixAllLinks()
	{
	// grab all the links
	var allLinks = document.getElementsByTagName('a');
	
	// loop through all the links
	for (var i=0; i<allLinks.length; i++)
		{
		var lnk = allLinks[i];
		
		// check to see if there's a hash, and if the current url completely matches the one in the link
		if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) || ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search))
			{
			addEvent(lnk, 'click', smoothScroll);
			}
		}
	}

function smoothScroll(e)
	{
	var target;
	// checks with event model to use
	if (window.event)
		{
		// ie
		target = window.event.srcElement;
		}
	else if (e)
		{
		// other
		target = e.target;
		}
	else return;
	
	// strip off the hash
	var anchor = target.hash.substr(1);
	// grab all the anchors on the page
	var destinationLink = document.getElementById(anchor);
	// if none found, exit
	if (!destinationLink) return true;
	
	// find position of destination link
	var destx = destinationLink.offsetLeft; 
	var desty = destinationLink.offsetTop;
	var thisNode = destinationLink;
	// loop up through offsetParent until we hit the document body, as IE requires
	while (thisNode.offsetParent && (thisNode.offsetParent != document.body))
		{
		thisNode = thisNode.offsetParent;
		destx += thisNode.offsetLeft;
		desty += thisNode.offsetTop;
		}
	
	// clear the interval timer (why here?)
	clearInterval(ss_INTERVAL);
	
	// get current y-position
	var cypos = ss_getCurrentYPos();
	
	// calculate the step sizes
	var ss_stepsize = parseInt((desty-cypos)/ss_STEPS);
	
	// run the scroll
	ss_INTERVAL = setInterval('ss_scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
	
	// stop the browser handling the event as normal and opening the link
	// kills the bubble
	if (window.event)
		{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		}
	if (e && e.preventDefault && e.stopPropagation)
		{
		// hmmm, safari gets inside here, but then fails to stop the event, and so a 'jump' rather than a 'scroll' takes place. I can't figure it out...
		e.preventDefault();
		e.stopPropagation();
		}
	return true;
	}

function ss_scrollWindow(scramount, dest, anchor)
	{
	var wascypos = ss_getCurrentYPos();
	var isAbove = (wascypos < dest);
	window.scrollTo(0,wascypos + scramount);
	var iscypos = ss_getCurrentYPos();
	var isAboveNow = (iscypos < dest);
	// if finished cancel timer and jump anchor so url is correct
	if ((isAbove != isAboveNow) || (wascypos == iscypos))
		{
		window.scrollTo(0,dest);
		clearInterval(ss_INTERVAL);
		location.hash = anchor;
		}
	}

function ss_getCurrentYPos()
	{
	// ie5 and ie5.5
	if (document.body && document.body.scrollTop)
	return document.body.scrollTop;
	// ie6
	if (document.documentElement && document.documentElement.scrollTop)
	return document.documentElement.scrollTop;
	// netscape etc
	if (window.pageYOffset)
	return window.pageYOffset;
	return 0;
	}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 06/13/04 ---------------------------------------------------------

tooltip = {
	name : "tooltipDiv",
	name2 : "tooltipDivInner",
	offsetX : 20,
	offsetY : -10,
	tip : null
};
tooltip.init = function () {
	if (!document.getElementById) return;
	
	// It would be nice to be able to generate the tooltip div, 
	// but when using document.createElement Explorer5/MacOS9, 
	// the tooltip div becomes 100% of the window height.
	// Therefore, we have to use document.getElementById to access
	// a div that is already in the body.
	
	// this.tip = document.createElement ("div");
	// this.tip.setAttribute ("id", this.name);
	// document.body.appendChild (this.tip);
	
	this.tip = document.getElementById (this.name);
	this.tipInner = document.getElementById (this.name2);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
	
	var a;
	var anchors = document.getElementsByTagName ("a");
	for (var i = 0; i < anchors.length; i ++) {
		a = anchors[i];
		if (a.className == "tooltip") {
			a.onmouseover = function () {tooltip.show (this.title)};
			a.onmouseout = function () {tooltip.hide ()};
		}
	}
};
tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {// Explorer
	
		// Explorer5 contains the documentElement object but it's empty, 
		// so we must check if the scrollLeft property is available.
		
		// If Explorer6 is in Quirks mode, the documentElement properties 
		// will still be defined, but they will contain the number 0.
		
		// If Explorer6 is in Standards compliant mode, the document.body 
		// properties will still be defined, but they will contain the number 0.
		
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {// Mozilla
		x = evt.pageX;
		y = evt.pageY;
	}
	// If the style property value is not a string containing the unit measurement,
	// browsers in standard compliant mode will not set the property.
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
};
tooltip.show = function (text) {
	if (!this.tip) return;
	this.tipInner.innerHTML = text;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "visible";
	this.tip.style.display = "block";
};
tooltip.hide = function () {
	if (!this.tip) return;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "hidden";
	this.tip.style.display = "none";
	this.tipInner.innerHTML = "";
};



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


function addEvent(obj, evType, fn)
	{
	if (obj.addEventListener)
		{
		obj.addEventListener(evType, fn, false); 
		return true;
		}
	else if (obj.attachEvent)
		{
		var r = obj.attachEvent('on'+evType, fn);
		return r;
		}
	else
		{
		return false;
		}
	}


// run all the onload scripts
function runScripts()
	{
	ss_fixAllLinks();
	tooltip.init ();
	}
	
window.onload = runScripts;