function ouvrirPopup (pFichier, pLargeur, pHauteur)
{
  var posX = (screen.width / 2) - (pLargeur / 2);
  var posY = (screen.height / 2) - (pHauteur / 2);
  wiwin=window.open(pFichier,"popup","width = " + pLargeur + ", height = " + pHauteur + ", left = " + posX + ", top = " + posY + ", resizable = 1, scrollbars= 1");
  if (self.focus) wiwin.focus();
}

function ChangeImageOver (objImg)
{
  intLongueur = objImg.src.length;
  objImg.src = objImg.src.substr(0,intLongueur-4)+"_over.gif";
}

function ChangeImageOut (objImg)
{
	intLongueur = objImg.src.length;
	objImg.src = objImg.src.substr(0,intLongueur-9)+".gif";
}

// AJAX
function getHTTPObject()
{
  var xmlhttp = false;

  if (typeof XMLHttpRequest != "undefined")  
  {  
    xmlhttp = new XMLHttpRequest();
  }
  
  if (!xmlhttp && typeof ActiveXObject != "undefined") 
  {   
    try 
    {   
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");   
    }
    catch (e1) 
    {   
      try 
      {   
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");   
      }
      catch (e2) 
      {   
        try 
        {   
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");   
        }
        catch (e3) 
        {   
          xmlhttp = false;   
        }   
      }   
    }   
  }   

  if(!xmlhttp && window.createRequest) 
  {
    try 
    {
      xmlhttp = window.createRequest();
    }
    catch (e) 
    {
      xmlhttp = false;
    }
  }  

  return xmlhttp;
}

function ajaxPOST(url, data, onCompleteFunction)
{
  var OAjax = null;
  OAjax = getHTTPObject();
  if (OAjax)
  {  
    OAjax.open('POST', url, true);
    OAjax.onreadystatechange = function()
    {
      if ((OAjax.readyState == 4) && (OAjax.status == 200))
      {
        if (document.getElementById) onCompleteFunction(OAjax.responseText);
      }
    }  
    OAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    OAjax.setRequestHeader('Content-Length', data.length);
    OAjax.setRequestHeader('Connection', 'close');
    OAjax.send(data);
    
    return OAjax;
  }  
  else
  {
    return false;
  }
}

function ajaxGET(url, onCompleteFunction)
{
  var OAjax = null;
  OAjax = getHTTPObject();
  if (OAjax)
  {  
    OAjax.open('GET', url, true);
    OAjax.onreadystatechange = function()
    {
      if ((OAjax.readyState == 4) && (OAjax.status == 200))
      {
        if (document.getElementById) onCompleteFunction(OAjax.responseText);
      }
    }  
    OAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    OAjax.setRequestHeader('Connection', 'close');
    OAjax.send(null);
    
    return OAjax;
  }  
  else
  {
    return false;
  }
}

/* Ajout d'une fonction au window.onload */
function addLoadEvent(func)
{
  var newfunc = (typeof func != 'function') ? function() {func;} : func;
 
  if (window.addEventListener)
    window.addEventListener('load', newfunc, false);
  else if (window.attachEvent)
    window.attachEvent('onload', newfunc);
}

/* Focus */
function set_focus(id_obj)
{
  if (document.getElementById(id_obj))
  {
    if (window == window.top)
    {
      document.getElementById(id_obj).focus();
    }
  }
}

/* Clignotage */
function transparent(opacity, obj_id)
{
  var obj = document.getElementById(obj_id);
  if (obj)
  {
    obj.style.opacity = (opacity / 100);
    obj.style.MozOpacity = (opacity / 100);
    obj.style.KhtmlOpacity = (opacity / 100);
    obj.style.filter = "alpha(opacity=" + opacity + ")";
  }  
} 

function clignotage(obj_id, millisec)
{
  var speed = ((millisec || 'ok') == 'ok') ? 4 : Math.round(millisec / 100);
  var timer = 0;

  for(i = 100; i >= 0; i--)
  {
    setTimeout("transparent(" + i + ",'" + obj_id + "')",(timer * speed));
    timer++;
  }
  for(i = 0; i <= 100; i++)
  {
    setTimeout("transparent(" + i + ",'" + obj_id + "')",(timer * speed));
    timer++;
  }
   
  setTimeout("clignotage('" + obj_id + "'," + millisec + ")",(timer * speed * 2)); 
}

function check_radio() 
{
  document.forms['frm_recherche_doc'].type_recherche[1].checked = true;
}

function Compter(target, max, nomchamp)
{
  StrLen = target.value.length

  if (StrLen > max )
  {
    target.value = target.value.substring(0,max);
    CharsLeft = max;
  }
  else
  {
    CharsLeft = max-StrLen;
  }

  nomchamp.value = CharsLeft;
}



