// +---------------------------+
// | Liste des modules chargés |
// +---------------------------+

var AL_Liste_librairie = new Array();

function AL_Definir_module_librairie(Nom,Version)
{
  this.Nom = Nom;
  this.Version = Version;
  return(this);
}

AL_Liste_librairie[AL_Liste_librairie.length]=new AL_Definir_module_librairie("ecran","V2.0");

// +-----------------------------+
// | Détection du navigateur Web |
// +-----------------------------+

var Ancien_opera = ((navigator.userAgent.indexOf("Opera/1")!=-1)||
                    (navigator.userAgent.indexOf("Opera/2")!=-1)||
                    (navigator.userAgent.indexOf("Opera/3")!=-1)||
                    (navigator.userAgent.indexOf("Opera/4")!=-1)||
                    (navigator.userAgent.indexOf("Opera/5")!=-1)||
                    (navigator.userAgent.indexOf("Opera/6")!=-1));

var Opera     = ((!Ancien_opera)&&
                 ((navigator.appName.indexOf("Opera")!=-1)||
                  (navigator.userAgent.indexOf("Opera")!=-1)));

var Compatible_internet = (((!Ancien_opera)&&
                            ((navigator.appName.indexOf("Explorer")!=-1)||
                             (navigator.userAgent.indexOf("MSIE")!=-1)))||(Opera));

var Ancien_netscape = ((navigator.appName.indexOf("Netscape")!=-1)&&
                       (navigator.userAgent.indexOf("Mozilla/4.7")!=-1));

var Compatible_mozilla = ((!Ancien_netscape)&&(!Ancien_opera)&&(!Opera)&&
                          ((navigator.appName.indexOf("Netscape")!=-1)||
                           (navigator.userAgent.indexOf("Mozilla/5.0")!=-1)));

var Navigateur_valide = (Compatible_internet || Compatible_mozilla);

// +----------------------------+
// | Gestion d'un ecran virtuel |
// +----------------------------+

function AL_Ecran_X(X)
{
  return(Math.floor((this.OX+X)*this.Coef_X));
}

function AL_Ecran_Y(Y)
{
  return(Math.floor((this.OY+Y)*this.Coef_Y));
}

function AL_Ecran_centre_X(Longueur)
{
  return(Math.floor((this.Ecran_longueur-Longueur*this.Coef_X)/2.));
}

function AL_Ecran_centre_Y(Largeur)
{
  return(Math.floor((this.Ecran_largeur-Largeur*this.Coef_Y)/2));
}

function AL_Ecran_ajuste_X(Longueur1,Largeur1,Longueur2,Largeur2)
{
  if ((Longueur1==0)||(Largeur1==0))
    return(0);
    
  var rx = Longueur2/Longueur1;
  var ry = Largeur2/Largeur1;

  if (rx>ry)
    return(ry*Longueur1);
    
  return(rx*Longueur1);
}

function AL_Ecran_ajuste_Y(Longueur1,Largeur1,Longueur2,Largeur2)
{
  if ((Longueur1==0)||(Largeur1==0))
    return(0);
    
  var rx = Longueur2/Longueur1;
  var ry = Largeur2/Largeur1;

  if (rx>ry)
    return(ry*Largeur1);
    
  return(rx*Largeur1);
}

function AL_Ecran_longueur(Longueur)
{
  return(Math.floor(Longueur*this.Coef_X));
}

function AL_Ecran_largeur(Largeur)
{
  return(Math.floor(Largeur*this.Coef_Y));
}

function AL_Ecran_police(Taille)
{
  var T=Math.floor(Taille*(this.Ecran_longueur/1024.));
  
  if (T<=0) T=1;
  if (T>8) T=8;
  
  return(T);
}

function AL_Definir_ecran(X,Y,Max_X,Max_Y)
{
  if ((Max_X==0)||(Max_Y==0))
    return(null);
    
  if (!Navigateur_valide)
    return(null);

  this.Ecran_longueur=window.screen.width;
  this.Ecran_largeur=window.screen.height;

  this.Document_longueur=this.Ecran_longueur;
  this.Document_largeur=this.Ecran_largeur;
  
  if (Compatible_internet)
  {
    if (document.body)
    {
      this.Document_longueur=document.body.clientWidth;
      this.Document_largeur=document.body.clientHeight;
    }
  }
  else if (Compatible_mozilla)
  {
    if (document.defaultView)
    {
      this.Document_longueur=document.defaultView.innerWidth;
      this.Document_largeur=document.defaultView.innerHeight;
    }
    else if (document.body)
    {
      if (document.body.clientWidth>0)
      {
        this.Document_longueur=document.body.clientWidth;
        this.Document_largeur=document.body.clientHeight;
      }
      else
      {
        this.Document_longueur=document.body.offsetWidth;
        this.Document_largeur=document.body.offsetHeight;
      }
    }
  }
  
  if (Max_X==null)
    this.Max_X=this.Ecran_longueur;
  else
    this.Max_X=Max_X;
    
  if (Max_Y==null)
    this.Max_Y=this.Ecran_largeur;
  else
    this.Max_Y=Max_Y;
    
  this.OX=X;
  this.OY=Y;
  
  this.Coef_X=this.Document_longueur/this.Max_X;
  this.Coef_Y=this.Document_largeur/this.Max_Y;
  
  this.X=AL_Ecran_X;
  this.Y=AL_Ecran_Y;
  this.Centre_X=AL_Ecran_centre_X;
  this.Centre_Y=AL_Ecran_centre_Y;
  this.Ajuste_X=AL_Ecran_ajuste_X;
  this.Ajuste_Y=AL_Ecran_ajuste_Y;
  this.Longueur=AL_Ecran_longueur;
  this.Largeur=AL_Ecran_largeur;
  this.Police=AL_Ecran_police;
  
  return(this); 
}

function AL_Tester_navigateur(Max_X_supporte,Max_Y_supporte,Max_X_conseille,Max_Y_conseille)
{
  var Ecran=AL_Definir_ecran(0,0,null,null);

  document.write("<CENTER><B><I>");
  document.write("("+navigator.appName+" - "+navigator.userAgent+")<br>");
  if (Ancien_opera)
  {
    document.write("Ce site n'est plus maintenu pour votre version d'Opera");
    document.write("<br>Veuillez vous munir d'une version plus récente ...");
  }
  else if (Ancien_netscape)
  {
    document.write("Ce site n'est plus maintenu pour votre version de Netscape");
    document.write("<br>Veuillez vous munir d'une version plus récente ...");
  }
  else if (Compatible_mozilla)
    document.write("Ce site a été testé avec votre navigateur comme compatible Mozilla (Netscape 6+)");
  else if (Compatible_internet)
    document.write("Ce site a été testé avec votre navigateur comme compatible Internet Explorer 4+");
  else
  {
    document.write("Ce site n'a pas été testé pour votre navigateur<br>");
    document.write("ATTENTION : vous rencontrerez quelques difficultés lors de votre visite ..");
  }
  
  if ((!Max_X_conseille)||(!Max_Y_conseille))
  {
    document.write("</I></B></CENTER>");
    return;
  }

  if (Navigateur_valide)
  {
    if (((Ecran.Max_X<Max_X_supporte)||(Ecran.Max_Y<Max_Y_supporte))&&
        (Max_X_supporte)&&(Max_Y_supporte))
    {
      document.write("<br>Votre affichage ("+Ecran.Max_X+"x"+Ecran.Max_Y+") n'est pas conseillé");
      document.write("<br>Je vous conseille de passer en "+Max_X_conseille+"x"+Max_Y_conseille+
                     " (supporte "+Max_X_supporte+"x"+Max_Y_supporte+")");
    }
    else if ((Ecran.Max_X<Max_X_conseille)||(Ecran.Max_Y<Max_Y_conseille))
    {
      document.write("<br>Votre affichage ("+Ecran.Max_X+"x"+Ecran.Max_Y+") est supporté");
      document.write("<br>Je vous conseille de passer en "+Max_X_conseille+"x"+Max_Y_conseille);
    }
    else
    {
      document.write("<br>Votre affichage est optimal");
    }
  }
  else
  {
    document.write("<br>Impossible de déterminer la résolution de votre écran");
    document.write("<br>Affichage conseillé "+Max_X_conseille+"x"+Max_Y_conseille);

    if ((Max_X_supporte)&&(Max_Y_supporte))
      document.write(" (supporté "+Max_X_supporte+"x"+Max_Y_supporte+")");
  }

  document.write("</I></B></CENTER>");
}
