function byId(id) {
	return document.getElementById(id);
}

function supprimer(lien) {
	if (confirm("Confirmer la suppression.")) document.location.href = lien;
	else document.location.href = '#';	
}

function popup(lien, pLargeur, pHauteur) {
	var posX = (screen.width / 2) - (pLargeur / 2);
	var posY = (screen.height / 2) - (pHauteur / 2);
	window.open(lien,"popup","width = " + pLargeur + ", height = " + pHauteur + ", left = " + posX + ", top = " + posY + ", resizable=yes, location=no, menubar=no, status=no");
}

function Reporter(id, cible) {
	var choix = byId(id).value;
	window.opener.byId(cible).value = choix;
}

function invertAll(headerfield, checkform, mask)
{
	for (var i = 0; i < checkform.length; i++)
	{
		if (typeof(checkform[i].name) == "undefined" || (typeof(mask) != "undefined" && checkform[i].name.substr(0, mask.length) != mask))
			continue;

		if (!checkform[i].disabled)
			checkform[i].checked = headerfield.checked;
	}
}

/*Slide latéral*/
function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}

function positionElement(id)
{
	var pX = 0;
	do {
		pX += id.offsetLeft;
	} while ( id = id.offsetParent )
	return pX;
}

function go2Page(to, size)
{
	if (moveScroll == true) return;
	new clScroller(pageView, to, size);
}

function clScroller(from, to, size)
{
	moveScroll = true;
	pageView = to;
	this.from = byId(from);
	this.to = byId(to);
	this.divMain = byId('main');
	
	fromPosition = positionElement(this.from);
	toPosition = positionElement(this.to);
	
	byId('contener').style.height = size+'px';
	byId('frame').style.height = size+'px';
	
	if (this.to.scrollHeight < size)
	this.toHeight = size+'px'; else
	this.toHeight = this.to.scrollHeight+'px';
	
	this.start = this.divMain.scrollLeft;
	this.change = toPosition - fromPosition;
	this.frames = 25;
	this.scrollCycle(0);
}
clScroller.prototype.scrollCycle = function(currentFrame)
{
	if ( currentFrame > this.frames )
	{
		moveScroll = false;
		byId('contener').style.height = this.toHeight;
		byId('frame').style.height = this.toHeight;
		return;
	}
	
	scrollToPosition = sineInOut(currentFrame, this.start, this.change, this.frames);
	this.divMain.scrollLeft = scrollToPosition;
	currentFrame++;
	
	var self = this;
	setTimeout(function() { self.scrollCycle(currentFrame); }, 15);
}
