// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

//  alert(foundObj);

  return foundObj;
}

// Affiche un DIV
function showObj(theObj)
{
	findObj(theObj).style.display='block';
}

// Cache un DIV
function hideObj(theObj)
{
	findObj(theObj).style.display='none';
}

// Retourne la position de la scroll bar en X
function getScrollX() {
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' ) {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  } else if( document.body && document.body.scrollLeft) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && document.documentElement.scrollLeft ) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

// Retourne la position de la scroll bar en Y
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}


function showObjFullSize(theObj)
{
	obj = findObj(theObj);	
	obj.style.display='block';
	obj.style.width = document.body.clientWidth + "px";
	obj.style.height = document.body.clientHeight + "px";
	obj.style.top = getScrollY() + "px";
	obj.style.left = getScrollX() + "px";
}
function showObjFullSizeBis(theObj)
{	
	setObjFullSize(theObj)	
	findObj(theObj).style.display='block';
}
function setObjFullSize(theObj)
{	/*
	var taille = f_taille_utile();
	var scr = f_scrollXY();
	var l = taille[0] + scr[0];
	var h = taille[1] + scr[1];
	*/
	var taille = f_taille_utile_totale();
	var l = taille[0];
	var h = taille[1];
	obj = findObj(theObj);	
	obj.style.width = l + "px";
	obj.style.height = h + "px";
	obj.style.top = "0 px";
	obj.style.left = "0 px";
}
function f_taille_utile() 
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } 
  else 
  if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } 
  else 
  if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
  
}
function f_scrollXY() {
  var scrOfX = 0, scrOfY = 0;
   if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else 
  if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else 
  if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function f_taille_utile_totale()
{
  var scrOfX = 0, scrOfY = 0;
   if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    scrOfY = document.body.clientHeight + window.scrollMaxY;
    scrOfX = document.body.clientWidth + window.scrollMaxX ;
  } else 
  if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
  {
    //DOM compliant
    scrOfY = document.body.scrollHeight;
    scrOfX = document.body.scrollWidth;
  } else 
  if( document.documentElement && ( document.documentElement.scrollWidth || document.documentElement.scrollHeight ) ) 
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollHeight;
    scrOfX = document.documentElement.scrollWidth;
  }
  return [ scrOfX, scrOfY ];
}
// Centre un DIV sur un document
function centerObj(theObj)
{
	obj = findObj(theObj);
	var divWidth = parseInt(obj.style.width);
	var divHeight = parseInt(obj.style.height);
    
	obj.style.left = Math.round((document.body.clientWidth - divWidth) / 2) + "px";
	obj.style.top = Math.round((document.body.clientHeight - divHeight) / 2) + "px";
}
function centerObjBis(theObj)
{
	//alert(theObj);
	obj = findObj(theObj);
	var divWidth = parseInt(obj.style.width);
	var divHeight = parseInt(obj.style.height);
	var taille = f_taille_utile();
	var scr = f_scrollXY();
	var l = taille[0] ;
	var h = taille[1] ;
	obj.style.left = Math.round(scr[0] + (l - divWidth) / 2) + "px";
	obj.style.top = Math.round(scr[1] + (h - divHeight) / 2) + "px";
}


// Charge un document avec les données XML
function loadXmlData(xmlObj, nodeName, tagName, propertyName)
{
	if (!propertyName) propertyName = "value";
	
	if (propertyName == "value")
	{
		if (xmlObj.getElementsByTagName(nodeName).length == 0 || xmlObj.getElementsByTagName(nodeName).item(0).firstChild == null)
			document.getElementById(tagName).value = "";
		else
			document.getElementById(tagName).value = xmlObj.getElementsByTagName(nodeName).item(0).firstChild.data;
	}
	if (propertyName == "label")
	{
		if (xmlObj.getElementsByTagName(nodeName).length == 0 || xmlObj.getElementsByTagName(nodeName).item(0).firstChild == null)
			document.getElementById(tagName).innerText = "";
		else
			document.getElementById(tagName).innerText = xmlObj.getElementsByTagName(nodeName).item(0).firstChild.data;
	}	
	else if (propertyName == "select")
	{
		objSel = document.getElementById(tagName);
		for(var i=0;i<objSel.options.length;i++)
		{
			if (xmlObj.getElementsByTagName(nodeName).item(0).firstChild != null && objSel.options[i].value == xmlObj.getElementsByTagName(nodeName).item(0).firstChild.data)
				objSel.options[i].selected = true;
			else
				objSel.options[i].selected = false;
		}
	}
}


function getXmlData(xmlObj, nodeName)
{
	if (xmlObj.getElementsByTagName(nodeName).length == 0 || xmlObj.getElementsByTagName(nodeName).item(0).firstChild == null)
		return null;
	else
		return xmlObj.getElementsByTagName(nodeName).item(0).firstChild.data;
}


// Sélectionne l'option select avec la valeur correspondante
function setSelectOption(selectObj, valeur)
{
	objSel = findObj(selectObj);
	for(var i=0;i<objSel.options.length;i++)
	{
		if (objSel.options[i].value == valeur)
			objSel.options[i].selected = true;
		else
			objSel.options[i].selected = false;
	}
}


// Retourne la valeur de l'option sélectionnée
function getSelectOption(selectObj)
{
	objSel = findObj(selectObj);
	return objSel.options[objSel.selectedIndex].value;
}
