function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Ajax Engine
function createXMLHttpRequest() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}
function AjaxRequestSetup()
{
	this.url = "";
	this.Method = "GET";
	this.returnType = "Text";
	this.ReturnFunction = function(XMLResponse) {alert(XMLResponse);};
	this.ErrorFunction = Global_CatchError;
	this.TimeOutFunction = Global_CatchTimeOut;
	this.ErrorGlobalText = "Une erreur est survenu : \nErreur {0}\n{1}";
	this.TimeOutGlobalText = "La ressource ne répond pas.\nDélai d'attente dépassé : {0} secondes ce sont écoulées";
	this.IsAsync = true;
	this.MAXIMUM_WAITING_TIME = 10000;
	this.Request = null;
	this.ForceUtf8 = false;
	this.CharSet = null;
}
var XmlRequestSetup = new AjaxRequestSetup();
var MAXIMUM_WAITING_TIME = XmlRequestSetup.MAXIMUM_WAITING_TIME;

function Global_CatchError(status, statusText)
{
	var txt = XmlRequestSetup.ErrorGlobalText.replace("{0}", status);
	txt = txt.replace("{1}", statusText);
	alert(txt);
}
function Global_CatchTimeOut(timeoutTime)
{
	var txt = XmlRequestSetup.TimeOutGlobalText.replace("{0}", parseInt(timeoutTime/60));
	alert(txt);
};
function XmlRequest() //url, Method, returnType, ReturnFunction, ErrorFunction, TimeOutFunction
{
	// initialisation via l'apelle de fonction (compatibility mode pour les vieilles procédure)
	if (arguments.length >= 1)
		XmlRequestSetup.url = arguments[0];
	if (arguments.length >= 2)
		XmlRequestSetup.Method = arguments[1];
	if (arguments.length >= 3)
		XmlRequestSetup.returnType = arguments[2];
	if (arguments.length >= 4)
		XmlRequestSetup.ReturnFunction = arguments[3];
	if (arguments.length >= 5)
		XmlRequestSetup.ErrorFunction = arguments[4];
	if (arguments.length >= 6)
		XmlRequestSetup.TimeOutFunction = arguments[5];
	
	// Début de la procédure
	var ajaxRequest = createXMLHttpRequest();
		ajaxRequest.open(XmlRequestSetup.Method, XmlRequestSetup.url, XmlRequestSetup.IsAsync);
		
		if (XmlRequestSetup.Request != null || XmlRequestSetup.ForceUtf8)
		{
			ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8;");
		}
		else if (XmlRequestSetup.CharSet != null)
		{
			ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; " + XmlRequestSetup.CharSet + ";");
		}
		
		if (XmlRequestSetup.IsAsync)
		{
			var requestTimer = setTimeout(function() { // Handle timeout situation, e.g. Retry or inform user.
				ajaxRequest.abort();
				XmlRequestSetup.TimeOutFunction(XmlRequestSetup.MAXIMUM_WAITING_TIME);
			}, XmlRequestSetup.MAXIMUM_WAITING_TIME);
		
			ajaxRequest.onreadystatechange = function() 
			{
				if (ajaxRequest.readyState != 4) {return;}
				clearTimeout(requestTimer);
				if (ajaxRequest.status != 200) // Handle error, e.g. Display error message on page
				{
					XmlRequestSetup.ErrorFunction(ajaxRequest.status, ajaxRequest.statusText);
					return;
				}
				
				var XMLResponse;
				if (XmlRequestSetup.returnType == "Text") // Handle response type, e.g. Text Or Xml
				{
					XMLResponse = ajaxRequest.responseText;
				}
				else
				{
					XMLResponse = ajaxRequest.responseXML;
				}
				XmlRequestSetup.ReturnFunction(XMLResponse);
			};
		}
		ajaxRequest.send(XmlRequestSetup.Request);
		if (!XmlRequestSetup.IsAsync)
		{
			if (ajaxRequest.status != 200) // Handle error, e.g. Display error message on page
			{
				XmlRequestSetup.ErrorFunction(ajaxRequest.status, ajaxRequest.statusText);
				return;
			}
			else
			{
				var XMLResponse;
				if (XmlRequestSetup.returnType == "Text") // Handle response type, e.g. Text Or Xml
				{
					XMLResponse = ajaxRequest.responseText;
				}
				else
				{
					XMLResponse = ajaxRequest.responseXML;
				}
				XmlRequestSetup.ReturnFunction(XMLResponse);
			}
		}

}

function XmlRequestStandAlone(AjaxRequestSetupObject)
{	
	// Début de la procédure
	var ajaxRequest = createXMLHttpRequest();
		ajaxRequest.open(AjaxRequestSetupObject.Method, AjaxRequestSetupObject.url, AjaxRequestSetupObject.IsAsync);
		
		if (AjaxRequestSetupObject.Request != null || AjaxRequestSetupObject.ForceUtf8)
		{
			ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8;");
		}
		else if (AjaxRequestSetupObject.CharSet != null)
		{
			ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; " + AjaxRequestSetupObject.CharSet + ";");
		}
		
		if (AjaxRequestSetupObject.IsAsync)
		{
			var requestTimer = setTimeout(function() { // Handle timeout situation, e.g. Retry or inform user.
				ajaxRequest.abort();
				AjaxRequestSetupObject.TimeOutFunction(AjaxRequestSetupObject.MAXIMUM_WAITING_TIME);
			}, AjaxRequestSetupObject.MAXIMUM_WAITING_TIME);
		
			ajaxRequest.onreadystatechange = function() 
			{
				if (ajaxRequest.readyState != 4) {return;}
				clearTimeout(requestTimer);
				if (ajaxRequest.status != 200) // Handle error, e.g. Display error message on page
				{
					AjaxRequestSetupObject.ErrorFunction(ajaxRequest.status, ajaxRequest.statusText);
					return;
				}
				
				var XMLResponse;
				if (AjaxRequestSetupObject.returnType == "Text") // Handle response type, e.g. Text Or Xml
				{
					XMLResponse = ajaxRequest.responseText;
				}
				else
				{
					XMLResponse = ajaxRequest.responseXML;
				}
				AjaxRequestSetupObject.ReturnFunction(XMLResponse);
			};
		}
		ajaxRequest.send(AjaxRequestSetupObject.Request);
		if (!AjaxRequestSetupObject.IsAsync)
		{
			if (ajaxRequest.status != 200) // Handle error, e.g. Display error message on page
			{
				AjaxRequestSetupObject.ErrorFunction(ajaxRequest.status, ajaxRequest.statusText);
				return;
			}
			else
			{
				var XMLResponse;
				if (AjaxRequestSetupObject.returnType == "Text") // Handle response type, e.g. Text Or Xml
				{
					XMLResponse = ajaxRequest.responseText;
				}
				else
				{
					XMLResponse = ajaxRequest.responseXML;
				}
				AjaxRequestSetupObject.ReturnFunction(XMLResponse);
			}
		}
}

function XmlDom(xml, async) 
{
	var doc;
	// code for IE
	if (window.ActiveXObject)
	{
		doc = new ActiveXObject("Microsoft.XMLDOM");
		doc.async = async;
		doc.loadXML(xml);
	}
	// code for Mozilla, Firefox, Opera, etc.
	else
	{
		var parser = new DOMParser();
		doc = parser.parseFromString(xml, "text/xml");
	}
	return doc;
}

function ObjWorker()
{
	var obj = document.getElementById(ObjWorker.arguments[0]);
	if (obj != null)
	{
		if (ObjWorker.arguments[1] == "write")
		{
			obj.innerHTML = ObjWorker.arguments[2];
		}
		else if (ObjWorker.arguments[1] == "append")
		{
			obj.innerHTML = obj.innerHTML + ObjWorker.arguments[2];
		}
		else if (ObjWorker.arguments[1] == "get")
		{
			return eval("obj." + ObjWorker.arguments[2]);
		}
		else if (ObjWorker.arguments[1] == "set")
		{
			eval("obj." + ObjWorker.arguments[2] + "=" + ObjWorker.arguments[3]);
		}
		else
		{
			obj.style.display = ObjWorker.arguments[1];
		}
	}
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();

function triggerCookie(){
	this.imageTrue = "/shared/images/bool_true.gif";
	this.imageFalse = "/shared/images/bool_false.gif";
	this.label = "Trigger le cookie!";
	
	this.trigger = function(sender, name, value, days){
		if(Cookies[name] && Cookies[name]!="clearedcookie"){
			Cookies.create(name, "clearedcookie", days);
			sender.style.backgroundImage="url("+this.imageFalse+")";
		}else{
			Cookies.create(name, value, days);
			sender.style.backgroundImage="url("+this.imageTrue+")";
		}
	}
	this.init = function(name, value, days){ //onclick="ccGUID.trigger(this,'ccGUID','X',2);"
		document.write('<a id="btn_' + name + '" href="javascript:;" class="triggerCookie">' + this.label + '</a>');
		var holder = document.getElementById('btn_' + name);
		holder.onclick = function(){
			window[name].trigger(holder, name, value, days);	
		}
		holder.style.backgroundImage = (Cookies[name] && Cookies[name]!="clearedcookie") ? "url("+this.imageTrue+")" : "url("+this.imageFalse+")";
	}
}

// Example:
// var b = new BrowserInfo();
// alert(b.version); 
var b = new BrowserInfo();
function BrowserInfo()
{
  this.name = navigator.appName;
  this.codename = navigator.appCodeName;
  this.version = navigator.appVersion.substring(0,4);
  this.platform = navigator.platform;
  this.javaEnabled = navigator.javaEnabled();
  this.screenWidth = screen.width;
  this.screenHeight = screen.height;
}

//	
//	Count Down dans le panel des boutton de Gestion Live
//	
var InactivityCounter_div, InactivityCounter
var GLOBAL_TIME = 1200;
var MaxSec = GLOBAL_TIME;

//
//<div id="InactivityCounter"></div>
//
function InactivityCounter_Load()
{
	setTimeout(function()
		{
			if (MaxSec == GLOBAL_TIME)
			{
				MaxSec = 1140;
				InactivityCounter_div = document.getElementById("InactivityCounter");
				InactivityCounter = setInterval(InactivityCounter_Update,1000)
			}
		}, 1000);
}

function InactivityCounter_Update()
{
	var Min = Math.floor(MaxSec/60);
	var Sec = (MaxSec % 60);
	if ((MaxSec % 60) == 0) {
		Sec = "00";
	} else if ((MaxSec % 60) < 10) {
		Sec = "0" + (MaxSec % 60);
	}
	
	MaxSec--
	if (MaxSec < 0)
	{
		clearInterval(InactivityCounter);
		InactivityCounter_div.innerHTML = "<span class=\"clock_ex\">Session Expirée !</span>";
	}
	else
	{
		InactivityCounter_div.innerHTML = Min + ":" + Sec;
	}
}
function IsIE()
{
	return ("Microsoft Internet Explorer" == b.name);
}
function IsNumeric(val)
{
	var myNumRegex = new RegExp("^[0-9]+$")
	return myNumRegex.test(val);
}


/*** Open Dialog ***/
setTimeout(function() {
	if (window["InnovaEditor"] == undefined)
	{
		window["modelessDialogShow"] = function(url,width,height)
		{
			if (window["windowOpen"] == undefined)
			{
				if (IsIE())
				{
					window.showModelessDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;");
				}
				else
				{
					left = (screen.width-width)/2;
					top = (screen.height-height)/2;
					window.open(url, "dependent=yes,width="+width+",height="+height+",left="+left+",top="+top);
				}
			}
			else
			{
				windowOpen(url,width,height);
			}
		}
		
		window["modalDialogShow"] = function(url,width,height)
		{
			if (window["windowOpen"] == undefined)
			{
				if (IsIE())
				{
					window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;maximize:1");
				}
				else
				{
					left = (screen.width-width)/2;
					top = (screen.height-height)/2;
					window.open(url, "dependent=yes,width="+width+",height="+height+",left="+left+",top="+top);
				}
			}
			else
			{
				windowOpen(url,width,height);
			}
		}
	}
}, 500);

function OpenAspxUploaderPopUp(URL)
{
	var width = 425;
	var height = 150;
	var left = (screen.width-width)/2
	var top = (screen.height-height)/2
	window.open(URL, 'AspxUploaderPopUp', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'')
}


function FontSize()
{
	this.minSize = 8;
	this.maxSize = 20;
	this.incrementation = 2;
	this.defaultSize = 10;
	this.modifyChildNodes = false;
	this.Unit = "px";
	this.modifyChildNodesFunction = function(myID, local_fontSize)
	{
		var TheBox = document.getElementById(myID);
		LoopDirectChild(local_fontSize, TheBox);
	};
}
var FontSizeSetting = new FontSize();
function LoopDirectChild(local_fontSize, obj)
{
	var i = 0;
	for (i=0;i<obj.childNodes.length;i++)
	{
		try
		{
			obj.childNodes[i].style.fontSize = local_fontSize + FontSizeSetting.Unit;
		}
		catch (e)
		{
		}
		if (obj.childNodes[i].hasChildNodes())
		{
			LoopDirectChild(local_fontSize, obj.childNodes[i])
		}
	}
}
function setFaceSize(myID,local_fontSize) {
	obj = document.getElementById(myID);
	obj.style.fontSize = local_fontSize + FontSizeSetting.Unit;
	if (FontSizeSetting.modifyChildNodes)
	{
		FontSizeSetting.modifyChildNodesFunction(myID, local_fontSize);
	}
}

function FontLarger(myID) {
	if (myID == "") {
		myID = "txt";
	}
	obj = document.getElementById(myID);
	var local_fontSize = obj.style.fontSize;
	if (local_fontSize == "") {
		local_fontSize = FontSizeSetting.defaultSize;
	} else {
		local_fontSize = local_fontSize.replace(FontSizeSetting.Unit, "");
	}
	local_fontSize = Math.floor(local_fontSize);
	if (local_fontSize < FontSizeSetting.maxSize) {
		local_fontSize += FontSizeSetting.incrementation;
		setFaceSize(myID,local_fontSize);
	}
}
	
function FontSmaler(myID) {
	if (myID == "") {
		myID = "txt";
	}
	obj = document.getElementById(myID);
	var local_fontSize = obj.style.fontSize;
	if (local_fontSize == "") {
		local_fontSize = FontSizeSetting.defaultSize;
	} else {
		local_fontSize = local_fontSize.replace(FontSizeSetting.Unit,"");
	}
	local_fontSize = Math.floor(local_fontSize);
	if (local_fontSize > FontSizeSetting.minSize) {
		local_fontSize -= FontSizeSetting.incrementation
		setFaceSize(myID,local_fontSize);
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var PagingPopUpWin = 0;
function PagingPopUpWindow() {
	var popupName = "PagingPopUpWin";
	var URLStr = arguments[0]
	var left = arguments[1]
	var top = arguments[2]
	var width = arguments[3]
	var height = arguments[4]
	if (arguments.length == 6) {popupName = arguments[5]}
	
	if (left == 'mid') {
		left = (screen.width-width)/2
	}
	if (top == 'mid') {
		top = (screen.height-height)/2
	}
	if(PagingPopUpWin) {
		if(!PagingPopUpWin.closed) PagingPopUpWin.close();
	}
	PagingPopUpWin = open(URLStr, popupName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function PrintMe(id) {
	if (id == "")
		id = "printid_"
	PagingPopUpWindow("/pages/print.asp?a=htmlgrab&id=" + id, 'mid', 'mid', 700, 550, "PRINTPAGE");
}

//####################################
//#####		   FORM FOCUS		 #####
//####################################
	var elem = 0;
	function formFocus() {
		try {
			if (document.forms[0].elements[elem].type == "button" || document.forms[0].elements[elem].type == "checkbox" || document.forms[0].elements[elem].type == "hidden" || (document.forms[0].elements[elem].type == "select-one" && document.forms[0].elements[elem].id == "inpList") ) {
				elem += 1;
				formFocus();
			} else {
				document.forms[0].elements[elem].focus();
			}
		} catch (e) {
			//alert(e.description)
		}
	}

	function OMconfirm(msg,url) {
		if ( confirm( msg ) ) {
			location = url;
		}
	}

	function countRest(obj,id) {
		try {
			if (obj.value.length > 255) {
				obj.value = Left(obj.value,255);
			}
			TheDiv = document.getElementById(id);
			TheDiv.innerHTML = 255 - obj.value.length;
		} catch (e) {
			alert(e.description)
		}
	}
	function Left(str, n){
		if (n <= 0)
			return "";
		else if (n > String(str).length)
			return str;
		else
			return String(str).substring(0,n);
	}
	function Right(str, n){
		if (n <= 0)
		   return "";
		else if (n > String(str).length)
		   return str;
		else {
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
	}
	
	function ShowLayer(layerId) {
		var eventslayer = document.getElementById(layerId);
		if (IE) {
			eventslayer.style.display = "block";
			popUp(event, layerId);
		} else {
			if (eventslayer.style.display == "block") {
				eventslayer.style.display = "none";
				eventslayer.style.visibility = "hidden";
				eventslayer.style.top = "-1000px";
				eventslayer.style.left = "-1000px";
			} else {
				eventslayer.style.display = "block";
				eventslayer.style.visibility = "visible";
				if (global_X < 0) {global_X=0;}
				eventslayer.style.left = (global_X + 20) + "px"
				if (global_Y < 0) {global_Y=0;}
				eventslayer.style.top = global_Y + "px"
			}
		}
		return true
	}
	
	function ClassChanger(obj)
	{
		var className = String(obj.className);
	   
		if (className.substring(className.length - 4, className.length) == "Over")
			obj.className = className.substring(0,className.length - 4);
		else
			obj.className += "Over";
	}
	
	function FormatNumber(number, decimal)
	{
		var multiple = Math.pow(10, decimal);
		var String_Number = String(Math.round(number*multiple)/multiple);
		String_Number = FormatNumberEndingZero(String_Number, decimal);
		return String_Number;
	}
	function FormatNumberEndingZero(number, decimal)
	{
		var tmp = number.replace(",", ".");
		var index = tmp.indexOf(".");
		
		if (index == -1)
		{
			tmp += ".";
			for (var iZero = 0; iZero < decimal; iZero++)
			{
				tmp += "0";
			}
		}
		else
		{
			var current_decimal = tmp.substring(index+1);			
			while (current_decimal.length < decimal)
			{
				tmp += "0";
				current_decimal = tmp.substr(index, tmp.length - index);
			}
		}
		return tmp;
	}
	
	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function ValidateChar(sender, charLen)
	{
		charLen = charLen - 1;
		if (sender.value.length >= charLen)
		{
			sender.value = sender.value.substring(0, charLen);
		}
	}

/*
Ajax True / False Updater
*/
	var ActifUpdater = function()
	{
		this.TableName = null;
		this.ConnectionString = null;
		this.idField = null;
		this.idType = null;
		this.actifField = null;
		this.imageActif = null;
		this.imageInactif = null;
		this.imageAltActif = null;
		this.imageAltInactif = null;
		this.ReturnFunction = AfficherGalerieReturn;
		
		this.url = "/gestion/pages/ActifUpdater.asp";
	}
	var Updater = new ActifUpdater();
	
	function AfficherGalerie(imgId, id)
	{
		XmlRequestSetup.ReturnFunction = Updater.ReturnFunction;
		XmlRequestSetup.url = Updater.url + "?id=" + id + 
							  "&idField=" + Updater.idField + 
							  "&actifField=" + Updater.actifField + 
							  "&ConnectionString=" + Updater.ConnectionString + 
							  "&TableName=" + Updater.TableName + 
							  "&imgId=" + imgId;
		if (Updater.idType != null)
			XmlRequestSetup.url += "&idType=" + Updater.idType
		
		//location = XmlRequestSetup.url;
		XmlRequest();
	}
	
	function AfficherGalerieReturn(XMLResponse)
	{
		var ReturnValues = XMLResponse.split("|");
		
		var SwitchValue = ReturnValues[0];
		
		switch (SwitchValue)
		{
			case "04" :
				alert(ReturnValues[1]);
				break;
			case "01" : 
				var imgId = ReturnValues[1];
				var img = document.getElementById(imgId);
				
				var inactifValue = document.getElementById("inactifValue");
				var count = null;
				if (inactifValue != null && inactifValue != undefined)
				{
					count = parseInt(inactifValue.innerHTML);
				}
				
				if (img.src.indexOf(Updater.imageActif) > -1)
				{
					img.src = Updater.imageInactif;
					img.alt = Updater.imageAltInactif;
					
					if (count != null)
						inactifValue.innerHTML = ++count;
				}
				else
				{
					img.src = Updater.imageActif;
					img.alt = Updater.imageAltActif;
					
					if (count != null)
						inactifValue.innerHTML = --count;
				}
				img.parentNode.title = img.alt;
				break;
			case "02" : 
				alert("Une erreur est survenu : \n" + ReturnValues[1]);
				break;
			case "03" : 
				alert("Vous n'avez pas accès à cette fonctionalité...");
				break;
			default : 
				alert("Une réponse de type inconu à été reçu...");
		}
	}

function omHsrc(el,hsrc){
	var src = el.src;
	el.src=hsrc;
	el.onmouseout = function(){this.src=src;}
}

function omTrOver(el,hcName){
	var cName = el.className;
	el.className=hcName;
	el.onmouseout = function(){this.className=cName;}
}

function attachCss(sheet)
{
	var head = document.getElementsByTagName("HEAD")[0];
	var myLink = document.createElement("link");
	myLink.setAttribute("rel", "stylesheet");
	myLink.setAttribute("type", "text/css");
	myLink.setAttribute("href", sheet);
	head.appendChild(myLink);
}

function removeCss(sheet)
{
	var head = document.getElementsByTagName("HEAD")[0];
	var links = document.getElementsByTagName("link");
	
	for (var i = 0; i < links.length; i++)
		if (links[i].getAttribute("href") == sheet)
			links[i].parentNode.removeChild(links[i]);
}

/*
Dynamicly include JavaScript
*/
function include_js(file) {
	var html_doc = document.getElementsByTagName('head')[0];
	js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', file);
	html_doc.appendChild(js);
	
	// This will load the javascript for Safari, but it won't
	// let us know when it's been loaded.  The following will.
	if(/WebKit|Khtml/i.test(navigator.userAgent)) {
		var iframe = document.createElement('iframe');
		iframe.style.display = 'none';
		iframe.setAttribute('src',file);
		document.getElementsByTagName('body').item(0).appendChild(iframe);
		// Fires in Saf
		iframe.onload = function() {
			jsLoaded();
		}
	}    
	// Fires in IE, also modified the test to cover both states
	js.onreadystatechange = function () {
		if (/complete|loaded/.test(js.readyState)) {
			jsLoaded();
		}
	}
	// Fires in FF
	js.onload = function () {
		jsLoaded();
	}
	return false;
}

function jsLoaded() {  }

function addJsLoadedEvent(func) {
	var oldJsLoadedEvent = jsLoaded;
	if (typeof jsLoaded != 'function') {
		jsLoaded = func;
	} else {
		jsLoaded = function() {
			oldJsLoadedEvent();
			func();
		}
	}
}

function moveNext(sender, maxLength, nextObjId)
{
	if (sender.value.length >= maxLength)
		document.getElementById(nextObjId).focus();
}

function OmAutoComplete(obj)
{
	/* Public Variables */
	this.enabled = true;
	this.searchBox = obj;
	this.mainBoxClass = "OmAutoComplete";
	this.focusOnChange = true;
	this.closeButtonClass = "OmAutoCompleteClose";
	this.closeButtonText = "<img src='/shared/images/autocomplete_close.gif' />";
	
	/* Private Variables */
	var itemCount = 0;
	
	var helpBox = document.createElement("DIV");
		helpBox.style.position = "absolute";
		helpBox.style.display = "none";
	
	var helpBoxHolder = document.createElement("DIV");
		helpBoxHolder.position = "relative";
		helpBoxHolder.appendChild(helpBox);
		
	this.searchBox.parentNode.appendChild(helpBoxHolder);
		
	/* Public Methods */
	this.trigger = function(KeyWordArray)
	{
		if (this.enabled)
		{
			
			helpBox.className = this.mainBoxClass;
			if (document.all)
				helpBox.className += " " + this.mainBoxClass + "IE";
			else
				helpBox.className += " " + this.mainBoxClass + "FF";
			// TODO : ajouter une class pour safari...
			
			helpBox.innerHTML = "";
			itemCount = 0;
			
			this.addCloseButton();
			
			var re = new RegExp("^" + this.searchBox.value, "i");
			for (var i = 0; i < KeyWordArray.length; i++)
			{
				if (re.test(KeyWordArray[i]))
				{
					this.addItem(KeyWordArray[i]);
					itemCount++;
				}
			}
			
			if (itemCount > 0)
				this.showHelper();
			else
				this.hideHelper()
		}
		else
		{
			this.hideHelper()
		}
	}
	
	this.showHelper = function()
	{
		helpBox.style.display = "block";
	}
	
	this.hideHelper = function()
	{
		helpBox.style.display = "none";
	}
	
	this.addItem = function(text)
	{
		var currentObject = this;
		
		var span = document.createElement("SPAN");
			span.innerHTML = text;
			
		var a = document.createElement("A");
			a.href = "javascript:;"
			a.onclick = function()
			{
				currentObject.searchBox.value = text;
				currentObject.hideHelper();
				
				if (currentObject.focusOnChange)
					currentObject.searchBox.focus();
			}
			a.appendChild(span);
			
		var div = document.createElement("DIV");
			div.appendChild(a);
			
		helpBox.appendChild(div);
	}
	
	this.addCloseButton = function()
	{
		var currentObject = this;
		
		var span = document.createElement("SPAN");
			span.innerHTML = this.closeButtonText;
		
		var a = document.createElement("A");
			a.href = "javascript:;"
			a.onclick = function()
			{
				currentObject.hideHelper();
			}
			a.appendChild(span);
		
		var CloseBox = document.createElement("DIV");
			CloseBox.className = this.closeButtonClass;
			CloseBox.appendChild(a);
		
		helpBox.appendChild(CloseBox);
	}
}

// addEvent(obj, func, e)
function addEventX(obj, func, e)
{
	var eventName = String("on" + e);
	var oldFunc = obj[eventName];
	if (typeof obj[eventName] != 'function') 
	{
		obj[eventName] = func;
	} 
	else 
	{
		obj[eventName] = function() 
		{
			oldFunc();
			func();
		}
	}
}

function SiteMaping(finalp,startp,cols,divEnd){
	var plan = document.getElementById(finalp);
	plan.innerHTML = "";
	
	for(i=0;i<cols;i++){
		var div = document.createElement("div");
		var ul = document.createElement("ul");
		var del = document.createElement("del");
		ul.id = "ul"+i;
		del.innerHTML = "&nbsp;";
		plan.appendChild(div);
		div.appendChild(ul);
		div.appendChild(del);
	}
	
	var oldplan = document.getElementById(startp);
	var boxes = oldplan.getElementsByTagName("LI");
	
	var bcount=0;
	for(i=0;i<boxes.length;i++){
		if(boxes[i].parentNode.id==startp){
			el = document.getElementById("ul"+bcount); 
			el.innerHTML += "<li>" + boxes[i].innerHTML + "</" + "li>";
			bcount++;
			if(bcount==cols) bcount=0;
		}
	}
	plan.innerHTML += divEnd;
	oldplan.style.display="none";
}

// PM's color picker -----------------------------------------------
	function init_pm_colorpick(el,inpID){
		var parent = el.parentNode;
		var divs = parent.getElementsByTagName("div");
		var init = true;
		for(i=0;i<divs.length;i++){
			if(divs[i].className=="pmpicker"){
				init = false;
				divs[i].style.display="";
			}
		}
		if(init){
			var left = el.offsetLeft;
			var mdiv =  document.createElement("div");
			var pcontent = parent.innerHTML;
			parent.innerHTML = "";
			parent.appendChild(mdiv);
			mdiv.style.position="relative";
			mdiv.innerHTML = pcontent;
			var hdiv =  document.createElement("div");
			mdiv.appendChild(hdiv);
			hdiv.className = "pmpicker";
			hdiv.style.left = (left-2)+"px";
			hdiv.onmouseout = function(){hdiv.style.display="none";};
			hdiv.onmouseover = function(){hdiv.style.display="";};
			buildPmColors(hdiv,inpID);
		}
	}
	
	var colors = new Array("#000000","#000033","#000066","#000099","#0000CC","#0000FF",
		"#003300","#003333","#003366","#003399","#0033CC","#0033FF",
		"#006600","#006633","#006666","#006699","#0066CC","#0066FF",
		"#009900","#009933","#009966","#009999","#0099CC","#0099FF",
		"#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF",
		"#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC","#00FFFF",
		"#330000","#330033","#330066","#330099","#3300CC","#3300FF",
		"#333300","#333333","#333366","#333399","#3333CC","#3333FF",
		"#336600","#336633","#336666","#336699","#3366CC","#3366FF",
		"#339900","#339933","#339966","#339999","#3399CC","#3399FF",
		"#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF",
		"#33FF00","#33FF33","#33FF66","#33FF99","#33FFCC","#33FFFF",
		"#660000","#660033","#660066","#660099","#6600CC","#6600FF",
		"#663300","#663333","#663366","#663399","#6633CC","#6633FF",
		"#666600","#666633","#666666","#666699","#6666CC","#6666FF",
		"#669900","#669933","#669966","#669999","#6699CC","#6699FF",
		"#66CC00","#66CC33","#66CC66","#66CC99","#66CCCC","#66CCFF",
		"#66FF00","#66FF33","#66FF66","#66FF99","#66FFCC","#66FFFF",
		"#990000","#990033","#990066","#990099","#9900CC","#9900FF",
		"#993300","#993333","#993366","#993399","#9933CC","#9933FF",
		"#996600","#996633","#996666","#996699","#9966CC","#9966FF",
		"#999900","#999933","#999966","#999999","#9999CC","#9999FF",
		"#99CC00","#99CC33","#99CC66","#99CC99","#99CCCC","#99CCFF",
		"#99FF00","#99FF33","#99FF66","#99FF99","#99FFCC","#99FFFF",
		"#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF",
		"#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF",
		"#CC6600","#CC6633","#CC6666","#CC6699","#CC66CC","#CC66FF",
		"#CC9900","#CC9933","#CC9966","#CC9999","#CC99CC","#CC99FF",
		"#CCCC00","#CCCC33","#CCCC66","#CCCC99","#CCCCCC","#CCCCFF",
		"#CCFF00","#CCFF33","#CCFF66","#CCFF99","#CCFFCC","#CCFFFF",
		"#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF",
		"#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF",
		"#FF6600","#FF6633","#FF6666","#FF6699","#FF66CC","#FF66FF",
		"#FF9900","#FF9933","#FF9966","#FF9999","#FF99CC","#FF99FF",
		"#FFCC00","#FFCC33","#FFCC66","#FFCC99","#FFCCCC","#FFCCFF",
		"#FFFF00","#FFFF33","#FFFF66","#FFFF99","#FFFFCC","#FFFFFF");
		
	var grays = new Array("#000000","#696969","#808080","#A9A9A9","#C0C0C0","#D3D3D3","#DCDCDC","#F5F5F5","#FFFFFF");
	
	function buildPmColors(cholder,inpID){
		for(i=0;i<colors.length;i++){
			buildPmColorDiv(cholder,colors[i],inpID);
		}
		var grayh =  document.createElement("div");
		cholder.appendChild(grayh);
		grayh.style.clear="left";
		for(i=0;i<grays.length;i++){
			buildPmColorDiv(grayh,grays[i],inpID);
		}
	}
	
	function buildPmColorDiv(appender,hex,inpID){
		var color =  document.createElement("div");
		appender.appendChild(color);
		color.className = "pmcolor";
		color.style.backgroundColor = hex;
		color.onmouseover = function(){
			this.style.borderColor="#000000";
		};
		color.onmouseout = function(){
			this.style.borderColor="#FFFFFF";
		};
		color.onclick = function(){
			if(getPmPreview(inpID)) getPmPreview(inpID).style.backgroundColor=this.style.backgroundColor;
			document.getElementById(inpID).value = hex.replace("#","");
		};
	}
	
	function getPmPreview(inpID){
		var parent = document.getElementById(inpID).parentNode;
		var inps = parent.getElementsByTagName("input");
		for(i=0;i<inps.length;i++){
			if(inps[i].className.indexOf("preview")>-1) return inps[i];
		}
	}
	
	function changePmColor(el){
		if(getPmPreview(el.id)) getPmPreview(el.id).style.backgroundColor="#"+el.value;
	}
// PM's color picker -- END ----------------------------------------

function maillink(el,needle){
	var findc = el.href.indexOf('courrielleur/');
	if(findc!=-1){
		var courriel = el.href.substr(findc+13,el.href.length);
		el.href = "mailto:"+courriel.replace(needle,"@");
	}
}

function OM_FlashCanPlay(MM_contentVersion){
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
			}
		return MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
	   && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</' + 'SCR' + 'IPT\> \n');
		return false;
	}
}

function NumericTextBoxValidation(sender)
{
	if ( !sender.value.match(/^([0-9]+)$/) )
		 sender.value = "0";
}

// Une class Queue, First In, First Out
function Queue()
{
	var innerQueue = new Array();
	var Count = 0;
	var Cursor = -1;
	
	this.enQueue = function(Target)
	{
		Count++;
		innerQueue.push(Target);
	}
	
	this.deQueue = function()
	{
		// Get l'item a renvoyer
		Count--;
		var cItem = innerQueue[++Cursor]
		
		return cItem;
	}
	
	this.getNextItem = function()
	{
		return innerQueue[Cursor+1];
	}
	
	this.getCount = function()
	{
		return Count;
	}
	
	this.isEmpty = function()
	{
		return (this.getCount() == 0);
	}
	
}

function LoadingScreen(){
	if(document.getElementById("FireLoadClick")){
		if(document.all) myLightbox = new Lightbox();
		myLightbox.start(document.getElementById("FireLoadClick"));

		/*var holderimg = document.getElementById("imageContainer");
		var monimage = document.getElementById("lightboxImage");
		var imglink = document.createElement("a");
			imglink.setAttribute('id','newlink');
			imglink.setAttribute('href','javascript:;');
			imglink.style.display = "block";
			
			document.getElementById("hoverNav").style.width = "0px";
			document.getElementById("hoverNav").style.height = "0px";
			document.getElementById("hoverNav").style.background = "#000000";
			document.getElementById("hoverNav").style.display = "none";
			holderimg.removeChild(monimage);
			holderimg.appendChild(imglink);
			imglink.appendChild(monimage);*/
	}
}

function safeCourriel(mailStr){
	mailStr = mailStr.replace(/ª/g,"@");
	mailStr = mailStr.replace(/·/g,".");
	window.location = "mailto:"+mailStr;
}


function ParseAspError(responseText)
{
	var expressionsToRemove = new Array();
	expressionsToRemove.push("<p>");
	expressionsToRemove.push("<font face=\"Arial\" size=2>");
	expressionsToRemove.push("\n");
	expressionsToRemove.push("\r");
	
	var tmp = responseText;
	for(var i = 0; i < expressionsToRemove.length; i++)
	{
		while (tmp.indexOf(expressionsToRemove[i]) > 0)
			tmp = tmp.replace(expressionsToRemove[i], "");
	}
	var values = tmp.split("</font>");
	
	return { 
		name: values[0].trim(), 
		description: values[2]
	};
}

