var loadFunctions = new Array();
var popupNumber = 1;

// Stocker les scripts à lancer au chargement
function addLoadFunction(Obj) { 
	loadFunctions[loadFunctions.length] = Obj; 
}

// Permet de cocher / décocher toutes les cases d'un formulaire
function checkAll(formName, elementName, isChecked)
{
	var checkForm = document.forms[formName].elements[elementName];
	var count = checkForm.length;

	if (count) {
		for (var i = 0; i < count; i++)
			checkForm[i].checked = isChecked;
	}
	else
    	checkForm.checked = isChecked;
}

// Désactive l'ensemble d'un formulaire
function disableForm(formId) {
	var oForm = document.getElementById(formId);

	for(var i = 0; i < oForm.length; i++)
		oForm.elements[i].disabled = true;
}

// Affiche ou masque un element
function displayElement(element, displayed) {
	if(document.getElementById && document.getElementById(element))
		document.getElementById(element).style.display = (displayed) ? "block" : "none";
}

function displayDiv(element, displayed) {
	displayElement(element, displayed);
}

// Vérifier si une chaine est un nombre ( séparateur # autorisé )
function isNumeric(num) {
	var exp = new RegExp("^[0-9-#]*$","g");
	return exp.test(num);
}

// Affiche une fenêtre popup
function popup(page, width, height) {
	if(width == null)
		width = 1000;
	if(height == null)
		height = 600;

	window.open(page, "popup_" + popupNumber, config='height=' + height + ', width=' + width + ', toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no, left=' + ((screen.width - width) / 2) + ', top=0');
	popupNumber++;
}

// Equivalent de rtrim() de php
function rtrim(str, charlist) {
    charlist = !charlist ? ' \\s\u00A0' : (charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    var re = new RegExp('[' + charlist + ']+$', 'g');
    return (str + '').replace(re, '');
}

// Execution des scripts au chargement de la page 
window.onload = function() { 
	for(i = 0; i < loadFunctions.length; i++) 
		loadFunctions[i]();
}

