function caroussel(el, n, pe) {
	if (pe && pe.stop) {
		pe.stop();
	}
	var link = $(el);
	var lecaroussel = link.up('div').down('.caroussel');
	var ledecalage = lecaroussel.down('.caroussel-item').getWidth();
	var lamarge = parseInt(lecaroussel.down('.caroussel-item').getStyle('margin-right'));
	if (lamarge != 0 && !isNaN(lamarge) && lamarge != undefined)
		ledecalage += lamarge;
	lamarge = parseInt(lecaroussel.down('.caroussel-item').getStyle('margin-left'));
	if (lamarge != 0 && !isNaN(lamarge) && lamarge != undefined)
		ledecalage += lamarge;
	new Effect.Move(lecaroussel.down('.caroussel-container'), {x: -ledecalage*(n-1), y: 0, duration: .5, mode: 'absolute'});
	link.siblings().invoke('removeClassName', 'selected');
	link.addClassName('selected');
	link.blur();
}

function checkMandatories() {
	var error = false;
	$$('.mandatory').each(function (iteration) {
		if (iteration.value == '') {
			error = true;
			iteration.setStyle({border: '1px solid #f00'});
		} else {
			iteration.setStyle({border: ''});
		}
	});
	if (error) {
		alert('Tous les champs obligatoires ne sont pas remplis.');
		return false;
	} else {
		return true;
	}
}

function refreshCheckedCount(container, el, strNone, strSingular, strPlural) {
	var count = 0;
	$(container).select('input[type=checkbox]').each(function(s) {
		if (s.checked) count++;
	});
	if(count == 0) $(el).innerHTML = strNone;
	else if(count == 1) $(el).innerHTML = strSingular;
	else $(el).innerHTML = count+' '+strPlural;
}


function doPrint() {
	if (window.print) window.print();
	else alert('Veuillez aller dans le menu Fichier de votre navigateur puis dans Imprimer.')
}
Event.observe(document, 'dom:loaded',
function () {
	if ($('content')) {
		var currFontSize = parseInt(Get_Cookie('contentFontSize'));
		if (!isNaN(currFontSize) && currFontSize != 0) {
			$('content').setStyle({fontSize: currFontSize+'px'});
			 Set_Cookie('contentFontSize', currFontSize, 30);
		}
	}
});


function changeFontSize(el, step) {
	el = $(el);
	var currFontSize = parseInt(Get_Cookie(el.id+'FontSize'));
	if (isNaN(currFontSize) || currFontSize == 0)
		currFontSize = 11;
	currFontSize += step;
	el.setStyle({fontSize: currFontSize+'px'});
	if (el.id) Set_Cookie(el.id+'FontSize', currFontSize, 30);
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				

function popup(name, loc, width, height) {
	win = window.open(loc, name, "width="+width+",height="+height); 
	win.focus();
}

Ajax.Replacer = Class.create(Ajax.Updater, {
  initialize: function($super, container, url, options) {
    options = options || { };
    options.onComplete = (options.onComplete ||
Prototype.emptyFunction)
      .wrap(function(proceed, transport, json) {
        $(container).replace(transport.responseText);
        proceed(transport, json);
      })
    $super(container, url, options);
  }

})

function ahah(container, params, replace) {
	var url = 'spip.php?action=ajax&'+params;
	if (replace) new Ajax.Replacer(container, url, {evalScripts: true});
	else new Ajax.Updater(container, url, {evalScripts: true});
}