/********************************************************************
 Fichier contenant les fonctions de gestion des formulaires
*********************************************************************/

function initialisation() {
	initAllSubmitInput();
	initHiddenJsInput();
}

function initHiddenJsInput() {
	var collection = document.getElementsByTagName("input");
	for (var i=0;i<collection.length;i++) {
		if(collection[i].attributes["type"].nodeValue == "hidden") {
			var nameValue = collection[i].attributes["name"].nodeValue;
			if(nameValue.search(/^.*[Jj][Ss][Aa]ctivated.*$/) != -1) {
			collection[i].attributes["value"].nodeValue = 'true';
			}
		}
	}
}

function initAllSubmitInput() {
	var collection = document.getElementsByTagName("input");
	for (var i=0;i<collection.length;i++) {
		if(collection[i].attributes["type"].nodeValue == "submit" || collection[i].attributes["type"].nodeValue == "button") {
			var valueContent = collection[i].attributes["value"].nodeValue;

			/* On supprime les occurences de <code CMSid=""></code> sur le dev, afin de clarifier l'affichage */
			var newValue = valueContent.replace(/^<code.+>(.+)<\/code>$/,"$1");
			collection[i].attributes["value"].nodeValue = newValue;

			/* On set les evenements pour gerer le rollover au niveau du style */
			collection[i].onmouseover = rollItSubmitInput;
			collection[i].onmouseout = rollItSubmitInput;
		}
	}
}
		
function rollItSubmitInput() {
	if(this.className.indexOf('_hover') != -1) {
		this.className = this.className.replace(/^(.+)(_hover)$/,"$1"); 
	} else {
		this.className = this.className + '_hover';
	}
}

window.onload = initialisation;

/********************************************************************
 LES FONCTIONS PRESENTENT CI DESSOUS SONT DEPRECATED
*********************************************************************/
var  tabElt = new Array(0);
/* fonction d'initialisation a appeler avant toutes choses*/
/* @DEPRECATED: utiliser la fonction $() de pceTools */
function InitTableauEltForm() {
	var nbEltForm = document.forms[0].length;
	tabElt = new Array(nbEltForm);
	for (i=0; i<nbEltForm; i++){
		tabElt[document.forms[0].elements[i].name] = i;
	} 
}

/* fonction de recherche d'un indice*/
/* @DEPRECATED: utiliser la fonction $() de pceTools */
function RechercherIndiceElt(nomEltForm) {
	var indiceElt = nomEltForm;
	if(tabElt.length==0)
		InitTableauEltForm();
	if (tabElt) {
		var num = tabElt[nomEltForm];
		if (isNaN(num) == false) /* Est-ce un nombre ?*/
			indiceElt = num
      	}
	return indiceElt;      
}

/* @DEPRECATED: utiliser la fonction $() de pceTools */
function getElement(name, delta, total) {
	if (!delta && !total) {
		delta = 0;
		total = 1;
	}
	return document.forms[0].elements[RechercherIndiceElt(name) - total + delta + 1];
}

/* @DEPRECATED: utiliser la fonction $() de pceTools */
function getElementForm(name, formId) {
	return document.forms[formId].elements[RechercherIndiceElt(name)];
}

/* @DEPRECATED: utiliser la fonction $() de pceTools */
function getDiv(divId) {
	if (document.getElementById) {
		return document.getElementById(divId);
	} else if (document.all) {
		return document.all[divId];
	} else if (document.layers)	{
		return document.layers[divId];
	}
}
