/****************************************************/
/* Trouve le navigateur courant.					*/
/****************************************************/
var ns4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4);
var ns5 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5);
var ie4 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4);
var ie5 = (navigator.appVersion.indexOf('MSIE 5')>0);
var ie6 = (navigator.appVersion.indexOf('MSIE 6')>0);
var ie7 = (navigator.appVersion.indexOf('MSIE 7')>0);
var ie8 = (navigator.appVersion.indexOf('MSIE 8')>0);
var ElById = document.getElementById;
var googleChrome=false;

if((ns5) && (navigator.appVersion.indexOf('Chrome')>0))
{
	ns5=false;
	ie4=true;	
	ie7=true;
	googleChrome=true;	
}

if(ns5)
{
	window.captureEvents(Event.Click);
	window.onclick=OnClick_NS5;
	event=new Object();
}

/****************************************************/
/* Détecte un click.								*/
/****************************************************/
function OnClick_NS5(e)
{
	if(ns5)window.event=e;
}

/****************************************************/
/* Trouve si une valeur est dans un objet.			*/
/****************************************************/
function IsInObject(Obj, val)
{
	var a;
	for(a=0;a<Obj.length;a++)
		if(Obj[a]==val)return true;
	return false;
}

/****************************************************/
/* Ecrit dans un élément (DIV ou Layer).			*/
/****************************************************/
function WriteInElem(ID_Name,Text)
{
	if(ns4)
	{
		var Layer = document.layers[ID_Name].document;
		Layer.write(Text);
		Layer.close();
		return;
	}
	if(ElById)
	{
		document.getElementById(ID_Name).innerHTML = Text;
		return;
	}
	if(ie4)
	{
		document.all(ID_Name).innerHTML = Text;
		return;
	}
}

/****************************************************/
/* Ecrit dans la barre de status.					*/
/****************************************************/
function SetStatus(Text)
{
	if(ns4 || ns5)window.statusbar=Text;
	if(ie4)window.status=Text;		
}

/****************************************************/
/* Ouvre un Popup.									*/
/****************************************************/
function PopUp(Name, SizeX, SizeY, Location)
{
	TmpTxt="resizable=yes,scrollbars=yes,location=no,menubar=no,width="+SizeX+",height="+SizeY;
	window.open(Location,Name,TmpTxt);
}

/****************************************************/
/* Change la couleur de fond d'une ligne de tableau	*/
/****************************************************/
function SetTrBgColor(Obj,zeColor)
{
	zeList=GetChildTag(Obj,"TD",new Array());
	for(a=0;a<zeList.length;a++)
	{
		if(zeList[a].parentNode==Obj)
			zeList[a].style.background=zeColor;
	}
}

/****************************************************/
/* Change la couleur de fond d'une ligne de tableau	*/
/****************************************************/
function GetChildTag(Obj,TagName,zeList)
{
	for(elem in Obj.childNodes)
	{
		zeObj=Obj.childNodes[elem];
		if(zeObj.tagName==TagName)zeList[zeList.length]=zeObj;
		if(zeObj.childNodes)zeList=GetChildTag(zeObj,TagName,zeList);
	}
	return zeList;
}

/****************************************/
/* SetCookie							*/
/****************************************/
function setCookie(name, value, expire, path) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
   + ((path == null) ? "" : ("; path=" + path));
}

/****************************************/
/* GetCookie							*/
/****************************************/
function getCookie(Name) {
   var search = Name + "=";
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search); 
      if (offset != -1) { // if cookie exists 
         offset += search.length; 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset);
         // set index of end of cookie value
         if (end == -1)
            end = document.cookie.length;
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}

/****************************************/
/* Renvoie la valeur d'un check list	*/
/****************************************/
function GetCheckValue(Obj)
{
	for(a=0;a<Obj.length;a++)
	{
		if(Obj[a].checked)return Obj[a].value;
	}
	return null;
}

/****************************************/
/* Change l'adresse.					*/
/****************************************/
function ChangeLoc(NewLoc)
{
	var zeLinks = document.body.getElementsByTagName("A");

	zeLink=zeLinks[0];
	zeLink.href=NewLoc;
	zeLink.target="_self";
	if(zeLink.click)
		zeLink.click();
	else
		window.location.href=NewLoc;
//		zeLink.onclick();
}

/****************************************************/
/* Resize un Div.									*/
/****************************************************/
function DivResize(DivName,ParentName,PaddingWidth,PaddingHeight)
{
	var Width,Height;

	if(!ElById)return;

	if(PaddingWidth>-50)
	{
		Width=document.getElementById(ParentName).clientWidth;
		document.getElementById(DivName).style.width=Width-PaddingWidth;
	}

	if(PaddingHeight>-50)
	{
		Height=document.getElementById(ParentName).clientHeight;
		document.getElementById(DivName).style.height=Height-PaddingHeight;
	}
}
