var IE6 = false, IE7 = false,
 FIREFOX2  = false, FIREFOX  = false,
 NETSCAPE7 = false, NETSCAPE = false, 
 OPERA9 = false, OPERA = false, 
 AUTRE = false;
var strChUserAgent = navigator.userAgent;
var intSplitStart = strChUserAgent.indexOf("(",0);
var intSplitEnd = strChUserAgent.indexOf(")",0);
var strChStart = strChUserAgent.substring(0,intSplitStart);
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
var strChEnd = strChUserAgent.substring(strChEnd);

if(strChMid.indexOf("MSIE 7") != -1)
 IE7 = true;
else if(strChMid.indexOf("MSIE 6") != -1)
 IE6 = true;
else if(strChEnd.indexOf("Firefox/2") != -1)
 FIREFOX2 = true;
else if(strChEnd.indexOf("Firefox") != -1)
 FIREFOX = true;
else if(strChEnd.indexOf("Netscape/7") != -1)
 NETSCAPE7 = true;
else if(strChEnd.indexOf("Netscape") != -1)
 NETSCAPE = true;
else if(strChStart.indexOf("Opera/9") != -1)
 OPERA9 = true;
else if(strChStart.indexOf("Opera") != -1)
 OPERA = true;
else
 AUTRE = true;

//Cette fonction permet de récupérer un Calque grace à son ID
function getIt(id){
    return document.getElementById(id);
}

//Cette fonction permet d'afficher le calque [ID]
function show(id){
	getIt(id).style.visibility = "visible";
   	getIt(id).style.display = "block";
}

//Cette fonction permet de cacher le calque [ID]
function hide(id){
	getIt(id).style.visibility = "hidden";
   	getIt(id).style.display = "none";
}

function bascule_visibilite(id){
 	if (getIt(id).style.visibility == "hidden")
		{show(id);}
	else
		{hide(id);}
}

//Accèpte en entrée aussi bien l'objet TR lui même, que son id.
function setBackgroundColor(theRow, thePointerColor)
{
	if (isString(theRow)) {theRow=getIt(theRow);}
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined')
    {
        return false;
    }
    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++)
    {
        theRow.cells[c].bgColor = thePointerColor;
    }
    return true;
}


/*
Cette fonction sert à vider le contenu d'une listbox
 */
function viderListeBox(oListe){
var intTaille=0;
	//Au cas où je récupère uniquement le nom de la liste, au lien de l'objet lui-même
	if(!isObject(oListe)) {oListe=getIt(oListe)}

	intTaille=oListe.length
	for (i=0;i<intTaille;i++)
	{
	   oListe.remove(0);
	}
}

/*
Cette fonction sert à positionner les valeurs d'une liste défilante
[strListe]=chaine de couple valeur:libellé;valeur:libellé....
*/
function remplirListeBox(oListe,strListe){
	var tabCouples = strListe.split(";");
	var tabOption;
	var oNewOption;

	//Au cas où je récupère uniquement le nom de la liste, au lien de l'objet lui-même
	if(!isObject(oListe)) {oListe=getIt(oListe)}

	viderListeBox(oListe);

	for (i=0;i<tabCouples.length;i++)
	{
       tabOption=tabCouples[i].split(":");
	   oNewOption = new Option(tabOption[1],tabOption[0],true,true);
	   oListe.options[i] = oNewOption;
	}
}


function string_remplace( text, stringToFind, stringRemplacement)
{
	var text = text.toString() ;
	var maReg = new RegExp( stringToFind, "gi") ;
	var resultat = text.replace( maReg, stringRemplacement ) ;
 
	return resultat ;
}


function bascule_image(id,strIMG1,strIMG2){

	if(getIt(id).src.indexOf(strIMG1)>0)
	{
		getIt(id).src=strIMG2;
	}
	else
	{
		getIt(id).src=strIMG1;
	}
}

/*ex: addListener(window, 'load', myFunction);*/
function addListener(element, event, listener, bubble){
	if(element.addEventListener)
	{
		if(typeof(bubble) == "undefined") bubble = false;
		element.addEventListener(event, listener, bubble);
	}
	else if(this.attachEvent)
	{
		element.attachEvent("on" + event, listener);
	}
}


