<!-- Add this function to your existing script  -->
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Dustin Diaz :: http://www.dustindiaz.com/ */

function ltrim(s) {
    return s.replace(/^\s+/, '');
}

function rtrim(s) {
    return s.replace(/\s+$/, '');
}

function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}
function $() 
	{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) 
		{
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
		}
	return elements;
	}

// ........................................................



function DemanderConfirmation(t)
	{
	if (t!='' && t!='undefined' && t!=undefined)
	var agree=confirm(''+t);
	else
	var agree=confirm("Etes vous sur ?");
	
	if (agree)
		return true ;
	else
		return false ;
	}

function TrouverPos(AObject)
	{
	var posX = 0, posY = 0;
	do
		{
		posX += AObject.offsetLeft;
		posY += AObject.offsetTop;
		AObject = AObject.offsetParent;
		}
	while( AObject != null );

	var pos = [];
	pos['X'] = posX;
	pos['Y'] = posY;

	return pos;
	}


function getTaillePage(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function changecss(theClass,element,value)
	{
	//documentation for this script at http://www.shawnolson.net/a/503/
	var cssRules;
	var modifOk;
	modifOk=0;
	if (document.all)
		{
		cssRules = 'rules';
		}
	else if (document.getElementById)
		{
		cssRules = 'cssRules';
		}
	//try {
	for (var S = 0; S < document.styleSheets.length; S++)
		{
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
			{
			if (document.styleSheets[S][cssRules][R].selectorText == theClass)
				{
				document.styleSheets[S][cssRules][R].style[element] = value;
				modifOk=1;
				}
			}
		}
	//}
	//catch(err)
	//{
		//alert(''+err.description +'\n' + document.styleSheets[S].id)
	//}
	if (modifOk==0) alert(element+' non trouvé :(');
	}

function showSelects()
	{
	var elements = document.getElementsByTagName("select");
	for (i=0;i< elements.length;i++)
		{
		if (elements[i].title!='wasvisible')
		elements[i].style.visibility='';
		}
	}

function hideSelects()
	{
	var elements = document.getElementsByTagName("select");
	for (i=0;i< elements.length;i++)
		{
		if (elements[i].style.visibility!='hidden')
			{
			//alert(elements[i].style.visibility);
			elements[i].style.visibility='hidden';
			}
		else
			{
				//alert(elements[i].name+':'+elements[i].style.visibility);
			elements[i].title='wasvisible';
			}
		}
	}
function ie6()
	{
	if (typeof document.body.style.maxHeight != "undefined") {
	  return(false);// IE 7, mozilla, safari, opera 9
	} else {
	  return(true);// IE6, et versions antérieures
	}		
		
	}
	
	
function setCookie(name, value, duree) 
	{
	var aujourdhui = new Date() ;		
	var expdate = new Date() ;
	 //plus an an ŕ partir d'aujourdh'ui le cookie ne s'efface jamais
	expdate.setTime( aujourdhui.getTime() + ( duree*24*60*60*1000 ) )

	var curCookie = name + "=" + escape(value) +
	 ((expdate) ? "; expires=" + expdate.toGMTString() : "") ;
	document.cookie = curCookie;
	}	
	
function ShowHide(x)
	{
	if ($(x).style.display=='')
		$(x).style.display = 'none';
	else
		$(x).style.display = '';
	}
function Opacifie(i)
	{
	var x = $(i).style;
	if (ie6())
		x.filter = 'alpha(opacity=100)';
	else
		x.opacity = '1';
	return true;
	}
function SetOpacite(i,o)
	{
	var x = $(i).style;
	if (ie6())
		x.filter = 'alpha(opacity='+(100*o)+')';
	else
		x.opacity = o;
	return true;
	}