<!--

//------------------------------------------------------------------------------

// launchWin et findObjByName en version alpha
// faire findObjByTagName

//------------------------------------------------------------------------------

// En cas de souci avec ce fichier, vous pouvez m'envoyer un mail à
// aurelien@barbier-accary.info

// Rq: Il est conseillé d'inclure ce fichier en premier dans vos pages afin de
// corriger le problème de cache des vieux navigateurs Netscape

//------------------------------------------------------------------------------

// Ce fichier standards.js permet d'écrire un code simple gérant un grand nombre
// de navigateurs, y compris ceux qui ne respectent pas les standards du W3C en
// évitant d'avoir à tester à la main les navigateurs comme ceci :

// var IE4 = (document.all) ? true : false;
//  => IE version 4+
// var NN4 = (document.layers) ? true : false;
//  => Netscape Navigator 4.x
// var W3C = (document.getElementById) ? true : false;
//  => IE5+, Netscape 6+, Opera 5+, Konqueror 2.1+, Mozilla et Gecko

//------------------------------------------------------------------------------

// Les fonctions proposées ci-dessous permettent de gérer simplement les
// navigateurs suivants :
//  - Netscape Navigator 4.x
//  - IE version 4 (et supérieurs ; IE6 est compatible W3C)
//  - IE5+, Netscape 6+, Opera 5+, Konqueror 2.1+, Mozilla et autres
//    Mozilla/Gecko-based browsers (Firefox, Galeon, ...)

// Les différentes fonctions sont :
//  - findObjById(n,d)                         trouve un objet à partir de son identifiant
//  - findObjByName(n,d)                       trouve tous les objets (tableau) ayant un nom donné (rien de garantit l'unicité)
//  - findObjsByTagName(t,d)                   ?
//  - getStyleObject(o)                        renvoie le style d'un objet
//  - getStyleById(n,d)                        renvoie le style d'un objet déterminé par de son identifiant
//  - showHideLayersById()                     affiche/masque un ou des objet(s) déterminés par leur identifiant
//  - showHideLayersByName()                   affiche/masque un ou des objet(s) déterminés par leur nom
//  - moveLayersById()                         positionne un ou des objet(s) déterminés par leur identifiant
//  - moveLayersByName()                       positionne un ou des objet(s) déterminés par leur identifiant
//  - preloadImages()                          précharge une ou des image(s) pour en accélérer l'affichage lorsqu'il devient nécessaire
//  - swapImage()                              échange le contenu d'une ou plusieurs image(s) déterminées par leur identifiant
//  - launchwin(winurl, winname, winfeatures)  ouvre une nouvelle fenêtre
//  - goToURL()                                définit une redirection vers une nouvelle page

// Un exemple d'utilisation est donné pour chacune des fonctions

//------------------------------------------------------------------------------

document.writeln('<!-- Prevent caching in netscape. Very important cause'
               + ' netscape tends to mangle cached code -->');
document.writeln('<meta http-equiv="expires" content="0">');
document.writeln('<meta http-equiv="Pragma" content="no-cache">');

//------------------------------------------------------------------------------
function findObjById(n, d) //v4.01
{
  var p, i, x;
  if(!d)
    d = document;
  if((p=n.indexOf("?"))>0 && parent.frames.length)
  {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }

  if(!(x=d[n]) && d.all)
    x = d.all[n];
  for (i=0; !x && i<d.forms.length; i++)
    x = d.forms[i][n];
  for(i=0; !x && d.layers && i<d.layers.length; i++)
    x = findObjById(n,d.layers[i].document);
  if(!x && d.getElementById)
    x = d.getElementById(n);

  return x;
}

// Paramètres: 1 id + 1 scope optionnel
// findObjById('id')

//------------------------------------------------------------------------------

function findObjByName(n, d) //v4.01
// un peu foireux si plusieurs objets de même nom pour un vieux navigateur
{
  var p, i, x;
  if(!d)
    d = document;
  if((p=n.indexOf("?"))>0 && parent.frames.length)
  {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if(!x && d.getElementsByName){
    x = d.getElementsByName(n);
  }
  if(!x && !(x=d[n]) && d.all){
  	
    x = d.all[n];}
  for (i=0; !x && i<d.forms.length; i++){
    x = d.forms[i][n];}
  for(i=0; !x && d.layers && i<d.layers.length; i++) // ne cherche plus les autres si au moins un trouvé :-(
    {x = findObjByName(n,d.layers[i].document);}

  if (!x && (x=findObjById(n,d))){
  	
    x = new Array(x);}

  return x;
}

// Paramètres: 1 name + 1 scope optionnel
// findObjByName('name')

//------------------------------------------------------------------------------

function findObjsByTagName(t, d) //v4.01
{
  if(!d)
    d = document;

  var objs = d.getElementsByTagName(t);
  
  return objs;
}

//------------------------------------------------------------------------------

function getStyleObject(obj) //v1.0
{
  if (obj && obj.style)
    return obj.style;
  return obj;
}

//------------------------------------------------------------------------------

function getStyleById(n, d) //v1.0
{
  return getStyleObject(findObjById(n, d));
}

//------------------------------------------------------------------------------

function showHideLayersById() //v6.0
{
  var i, p, v, obj, args=showHideLayersById.arguments;
  for (i=0; i<(args.length-1); i+=2)
    if ((obj=findObjById(args[i])) != null)
    {
      if (obj.style)
        obj = obj.style;
      v = args[i+1];
      obj.visibility = (v=='show') ? 'visible' : (v=='hide')?'hidden':v;
    }
}

// Paramètres: 2 données par objet: id, 'hide' ou 'show'
// showHideLayersById('id1','hide', 'id2','show', ...);

//------------------------------------------------------------------------------

function showHideLayersByName() //v6.0
{
  var i, p, v, obj, args=showHideLayersByName.arguments;
  for (i=0; i<(args.length-1); i+=2)
  {
    objs=findObjByName(args[i]);
    for(var j=0;j<objs.length;j++)
      if ((obj=objs[j]) != null)
      {
        if (obj.style)
          obj = obj.style;
        v = args[i+1];
        obj.visibility = (v=='show') ? 'visible' : (v=='hide')?'hidden':v;
      }
  }
}

// Paramètres: 2 données par objet: name, 'hide' ou 'show'
// showHideLayersByName('name1','hide', 'name2','show', ...);

//------------------------------------------------------------------------------

function moveLayersById() //v6.0
{
  var i, p, v, obj, args=moveLayersById.arguments;
  for (i=0; i<(args.length-2); i+=3)
    if ((obj=findObjById(args[i])) != null)
    {
      if (obj.style)
        obj = obj.style;
      obj.left = args[i+1];
      obj.top = args[i+2];
    }
}

// Paramètres: 3 données par objet: id, left, top
// moveLayersById('id1','20px','150px', 'id2','70px','150px', ...);

//------------------------------------------------------------------------------

function moveLayersByName() //v6.0
{
  var i, p, v, obj, args=moveLayersByName.arguments;
  for (i=0; i<(args.length-1); i+=2)
  {
    objs=findObjByName(args[i]);
    for(var j=0;j<objs.length;j++)
      if ((obj=objs[j]) != null)
      {
        if (obj.style)
          obj = obj.style;
        obj.left = args[i+1];
        obj.top = args[i+2];
      }
  }
}

// Paramètres: 3 données par objet: name, left, top
// moveLayersByName('name1','20px','150px', 'name2','70px','150px', ...);

//------------------------------------------------------------------------------

function preloadImages() //v3.0
{
  var d=document;
  if(d.images)
  {
    if(!d.p)
      d.p = new Array();
    var i, j=d.p.length, a=preloadImages.arguments;
    for(i=0; i<a.length; i++)
      if (a[i].indexOf("#") != 0)
      {
        d.p[j] = new Image;
        d.p[j++].src = a[i];
      }
  }
}

// Paramètres: suite d'adresses d'images
// <body onLoad="preloadImages('ima1.gif','ima2.jpg',...,'imaN.png')">
// Attention, en XHTML on écrit onload et pas onLoad

//------------------------------------------------------------------------------

function swapImage() //v3.0
{
  var i, x, a=swapImage.arguments;
  for(i=0; i<(a.length-2); i+=3)
    if ((x=findObjById(a[i])) != null)
    {
      x.src = a[i+1];
	  if (a[i+2] != '')
        x.alt = a[i+2];
    }
}

// Paramètres: 3 données par image: id, src, alt
// swapImage('id1','images/monima1.png','monima1', 'id2','images/monima2.jpg','monima2', ...);

//------------------------------------------------------------------------------

function launchwin(winurl, winname, winfeatures)
{
  var newwin;
  //This launches a new window and then
  //focuses it if window.focus() is supported.
  newwin = window.open(winurl, winname, winfeatures);
  /*if (javascript_version > 1.0)
  {
    //delay a bit here because IE4 encounters errors
    //when trying to focus a recently opened window
    setTimeout('newwin.focus();', 250);
  }*/
  return newwin;
}

// Paramètres:
// 

//------------------------------------------------------------------------------

function goToURL() //v3.0
{
  var i, args=goToURL.arguments;
  document.returnValue = false;
  for (i=0; i<(args.length-1); i+=2)
    eval(args[i]+".location='"+args[i+1]+"'");
}

// Paramètres:
// <a href="javascript:;"
//    onClick="goToURL('parent','/index.html');return document.returnValue">
// ...</a>
// Attention, en XHTML on écrit onclick et pas onClick

//------------------------------------------------------------------------------

//-->

