// Fonctions javascripts communes

/****************************/
/*
<Type>	Fonction
<Categorie>
<Nom>	recupereElementsHTML
<NbParam>	1
<Param>
	monElement (string) 
</Param>
<Description>
	Permet de recuperer un tableau contenant tous les elements envoyés en parametre de la page.
	Ex : on souhaiterai recuperer tous les DIV de notre page HTML
</Description>
<Date Création>	02/06/2008
<Auteur Création>	STACHOWIAK Jérôme
<Modification>
</Modification> 
*/
/****************************/

function recupereElementsHTML(monElement) {
	if(monElement!= "") {
		var monTableau;
		monTableau=document.getElementsByTagName(monElement);
		return monTableau;
	}
	else
		return false;
}

/****************************/
/*
<Type>	Fonction
<Categorie>
<Nom>	siDivExist
<NbParam>	1
<Param>
	monDiv (string) 
</Param>
<Description>
	Permet de tester si un div est bien present dans la page
</Description>
<Date Création>	02/06/2008
<Auteur Création>	STACHOWIAK Jérôme
<Modification>
</Modification> 
*/
/****************************/

function siDivExist(monDiv) {
	if(monDiv!="") {
		monTableau = recupereElementsHTML("DIV");
		//on recherche dans le tableau
		for(i=0;i<monTableau.length;i++) {
			if(monTableau[i].id.length != 0) {
				if(monTableau[i].id == monDiv) {
					return true
				}
			}
		}
	}
	return false;
}

/****************************/
/*
<Type>	Fonction
<Categorie>
<Nom>	cacheDiv
<NbParam>	1
<Param>
	maChaine (string) 
</Param>
<Description>
	Permet de cacher un DIV a partir de son ID
</Description>
<Date Création>	02/06/2008
<Auteur Création>	STACHOWIAK Jérôme
<Modification>
</Modification> 
*/
/****************************/

function cacheDiv(maChaine) {
	if(maChaine!="") {
		if(siDivExist(maChaine) == true) {
			document.getElementById(maChaine).style.display = "none";
		}
	}
}

/****************************/
/*
<Type>	Fonction
<Categorie>
<Nom>	montreDiv
<NbParam>	1
<Param>
	maChaine (string) 
</Param>
<Description>
	Permet de montrer un DIV a partir de son ID
</Description>
<Date Création>	02/06/2008
<Auteur Création>	STACHOWIAK Jérôme
<Modification>
</Modification> 
*/
/****************************/

function montreDiv(maChaine) {
	if(maChaine!="") {
		//alert(maChaine);
		if(siDivExist(maChaine) == true) {
			//alert("ok");
			document.getElementById(maChaine).style.display = "block";
		}
	}
}

/****************************/
/*
<Type>	Fonction
<Categorie>
<Nom>	cutChaine
<NbParam>	2
<Param>
	maChaine (string) 
	nombre (int)
</Param>
<Description>
	Permet de couper une chaine de caractere, on recupere les x caracteres (definit par nombre) du debut de la chaine
</Description>
<Date Création>	02/06/2008
<Auteur Création>	STACHOWIAK Jérôme
<Modification>
</Modification> 
*/
/****************************/
function cutChaine(maChaine, nombre)
{
	if(maChaine!="") {
		if(maChaine.length > nombre) {
			return maChaine.substring(0 , nombre);
		}
		return maChaine;
	}
}

function PopupCentrer(page,largeur,hauteur,name) {
	var top=(screen.height-hauteur)/2;
  	var left=(screen.width-largeur)/2;
  	window.open(page, "name", "top="+top+",left="+left+",height="+hauteur+", width="+largeur+",toolbar=0, menubar=0, scrollbars=0, resizable=0, status=0, location=0");
}

function Left(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}
function Right(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
	{
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

/****************************/
/*
<Type>	Fonction
<Categorie>
<Nom>	text_limite
<NbParam>	3
<Param>
	zone (string) 
	max (int)
	compteur (string)
</Param>
<Description>
	Permet de compter les nombre de caractere dans un textarea est de limite a ce nombre
</Description>
<Date Création>	30/09/2008
<Auteur Création>	STACHOWIAK Jérôme
<Modification>
</Modification> 
*/
/****************************/
function text_limite(zone,maxi,compteur)
{	
	//Si on depasse le nombre de caracteres max on coupe la chaine 
	if(document.getElementById(zone).value.length>=maxi){
		document.getElementById(zone).value=document.getElementById(zone).value.substring(0,maxi);
	}
	//on insere dans le compteur le nombre de caractere restant a saisir
	document.getElementById(compteur).value = maxi - document.getElementById(zone).value.length;
}


function PopupCentrer(page,largeur,hauteur,options,name)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,name,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}