function setCookie(name, value, expire)
{
  document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

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));
   }
  }
 return null;
}

function register( nom, valeur )
{
  var today = new Date();
  var expires = new Date();
  expires.setTime(today.getTime() + 1000*60*60*24);
  setCookie(nom, valeur, expires);
}

function testCookie()
{
  register( "test", 0 );
  return( getCookie("test") );
}


// affiche tous les thumbnails d'une galerie
function thumbnails()
{
  for( n=0; n<galerie[ng].length; n++ )
  {
    if( n%6 == 0 ) document.write( "<tr>" );
    ligne = "<td align=\"center\"><a href=\"agrandissement.htm\" onClick=\"register( 'numerooeuvre', " + n + " )\"><img src=\"images/" + galerie[ng][n][1] + "_small.jpg\" border=\"0\" width=\"80\" height=\"80\" hspace=\"10\"></a></td>";
    document.write(ligne);
    if( (n+1)%6 == 0 )
    {
      document.write( "</tr><tr>" );
      for(k=n-5;k<=n;k++)
      {
        ligne = "<td align=\"center\">" + galerie[ng][k][0] + "</td>";
        document.write(ligne);
      }
      document.write( "</tr>" );
    }
  }
  if( n%6 != 0 )
  {
    document.write( "</tr><tr>" );
    nn = n - n%6;
    for(k=nn;k<n;k++)
    {
      ligne = "<td align=\"center\">" + galerie[ng][k][0] + "</td>";
      document.write(ligne);
    }
    document.write( "</tr>" );
  }

}




// affiche un agrandissement
function affiche_image()
{
  ligne = "<img src=\"images/" + galerie[ng][no][1] + ".jpg\" border=\"1\" hspace=\"0\"";
  if( galerie[ng][no][5] != null ) ligne = ligne + " width=\"" + galerie[ng][no][5] + "\" height=\"" + galerie[ng][no][6] + "\"";
  ligne = ligne +">";
  document.write(ligne);
}

function affiche_image2()
{
  ligne = "<img src=\"images/" + oeuvre[num][1] + ".jpg\" border=\"" + oeuvre[num][5] + "\" hspace=\"0\"";
  if( oeuvre[num][5] != null ) ligne = ligne + " width=\"" + oeuvre[num][6] + "\" height=\"" + oeuvre[num][7] + "\"";
  ligne = ligne +">";
  document.write(ligne);
}


// affiche texte accompagnateur
function affiche_texte()
{
// trouver le moyen d'utiliser un fichier par texte (0001.js) qui ne contiendrait qu'une simple variable


// si la variable ou le fichier n'ont pas encore été créés, n'affiche rien
  if( texte_acc[ng][no] == undefined ) return;

var colonne_switch=0;

  texte_acc[ng][no] = insertion( texte_acc[ng][no], "<p>" + texte_acc[ng][no].charAt(0), 0 );
  for(n=0;n<texte_acc[ng][no].length;n++)
  {
    if( texte_acc[ng][no].charAt(n) == "*" )
    {
      if( n > texte_acc[ng][no].length/2 && colonne_switch == 0 )
      {
        texte_acc[ng][no] = insertion( texte_acc[ng][no], "</p></td><td valign=\"top\" width=\"50%\"><p>", n );
        colonne_switch = 1;
      }
      else
        texte_acc[ng][no] = insertion( texte_acc[ng][no], "</p><p>", n );
    }
    if( texte_acc[ng][no].charAt(n) == "à" )  texte_acc[ng][no] = insertion( texte_acc[ng][no], "&agrave;", n );
    if( texte_acc[ng][no].charAt(n) == "ù" )  texte_acc[ng][no] = insertion( texte_acc[ng][no], "&ugrave;", n );
    if( texte_acc[ng][no].charAt(n) == "è" )  texte_acc[ng][no] = insertion( texte_acc[ng][no], "&egrave;", n );
    if( texte_acc[ng][no].charAt(n) == "â" )  texte_acc[ng][no] = insertion( texte_acc[ng][no], "&acirc;", n );
    if( texte_acc[ng][no].charAt(n) == "ê" )  texte_acc[ng][no] = insertion( texte_acc[ng][no], "&ecirc;", n );
    if( texte_acc[ng][no].charAt(n) == "û" )  texte_acc[ng][no] = insertion( texte_acc[ng][no], "&ucirc;", n );
  }
  texte_acc[ng][no] = insertion( texte_acc[ng][no], "</p>", texte_acc[ng][no].length );

  document.write( texte_acc[ng][no] );

}


// remplace le caractère en position p par chaine2 dans chaine1
function insertion( chaine1, chaine2, p )
{
  lc = chaine1.length;
  chaine = chaine1.substring(0,p) + chaine2 + chaine1.substring(p+1,lc);
  return chaine;
}




