// charge les informations de la page en AJAX
function ajaxLoadPhotos()
{
  //alert('ajaxLoadPhotos');
  //alert(url2006UsaLoadPhotos);
  var xhr = getXHR();
  xhr.onreadystatechange = function() { ajaxDisplayPhotos(xhr); };
  xhr.open('GET', url2006UsaLoadPhotos, true);
  xhr.send(null);
}

function ajaxDisplayPhotos(xhr)
{
  //alert('ajaxDisplayPhotos');
  if(xhr.readyState == 4 && xhr.status == 200) // le serveur est disponible && la lecture du fichier XML a bien été effectuée
  {
    var docXML = xhr.responseXML.documentElement;
    var items = docXML.childNodes;

    var td_photos = document.getElementById('photos');

    var table = null;
    var border = null;
    var cellpadding = null;
    var cellspacing = null;
    //var class = null;
    var width = null;
    var tr = null;
    var td = null;
    var valign = null;
    var textNode = null;
    var b = null;
    var br = null;
    var img = null;
    var a = null;
    var href = null;
    var target = null;
    var iframe = null;
    var frameborder = null;
    var marginheight = null;
    var marginwidth = null;
    var height = null;

    table = document.createElement('table');

    border = document.createAttribute('border');
    border.nodeValue = 0;
    table.setAttributeNode(border);
    cellpadding = document.createAttribute('cellpadding');
    cellpadding.nodeValue = 0;
    table.setAttributeNode(cellpadding);
    cellspacing = document.createAttribute('cellspacing');
    cellspacing.nodeValue = 0;
    table.setAttributeNode(cellspacing);
    //class = document.createAttribute('class');
    //class.nodeValue = 'photos';
    //table.setAttributeNode(class);

    //alert(items.length);
    for (var i = 0; i < items.length; i++)
    {
      if (i % 2 == 0)
        tr = document.createElement('tr');

      td = document.createElement('td');
      //class = document.createAttribute('class');
      //class.nodeValue = 'photos_etape';
      //td.setAttributeNode(class);

      b = document.createElement('b');
      textNode = document.createTextNode(items.item(i).childNodes.item(1).firstChild.nodeValue);
      b.appendChild(textNode);
      td.appendChild(b);

      br = document.createElement('br');
      td.appendChild(br);

      img = document.createElement('img');
      src = document.createAttribute('src');
      src.nodeValue = 'images/' + items.item(i).childNodes.item(2).firstChild.nodeValue;
      img.setAttributeNode(src);
      td.appendChild(img);

      br = document.createElement('br');
      td.appendChild(br);

      iframe = document.createElement('iframe');
      frameborder = document.createAttribute('frameborder');
      frameborder.nodeValue = 0;
      iframe.setAttributeNode(frameborder);
      marginheight = document.createAttribute('marginheight');
      marginheight.nodeValue = 0;
      iframe.setAttributeNode(marginheight);
      marginwidth = document.createAttribute('marginwidth');
      marginwidth.nodeValue = 0;
      iframe.setAttributeNode(marginwidth);
      width = document.createAttribute('width');
      width.nodeValue = 400;
      iframe.setAttributeNode(width);
      height = document.createAttribute('height');
      height.nodeValue = 270;
      iframe.setAttributeNode(height);
      src = document.createAttribute('src');
      src.nodeValue = items.item(i).childNodes.item(3).firstChild.nodeValue;
      iframe.setAttributeNode(src);
      td.appendChild(iframe);

      br = document.createElement('br');
      td.appendChild(br);

      a = document.createElement('a');
      href = document.createAttribute('href');
      if (items.item(i).childNodes.item(0).firstChild.nodeValue < 10)
        href.nodeValue = 'photos/large/0' + items.item(i).childNodes.item(0).firstChild.nodeValue;
      else
        href.nodeValue = 'photos/large/' + items.item(i).childNodes.item(0).firstChild.nodeValue;
      a.setAttributeNode(href);
      target = document.createAttribute('target');
      target.nodeValue = '_blank';
      a.setAttributeNode(target);
      textNode = document.createTextNode('Cliquez ici pour visualiser cet album photos en plein écran');
      a.appendChild(textNode);
      td.appendChild(a);

      br = document.createElement('br');
      td.appendChild(br);

      a = document.createElement('a');
      href = document.createAttribute('href');
      href.nodeValue = 'etape.php?jour=' + items.item(i).childNodes.item(0).firstChild.nodeValue + '&carte=n&videos=n';
      a.setAttributeNode(href);
      textNode = document.createTextNode('Accédez au carnet de route de cette étape');
      a.appendChild(textNode);
      td.appendChild(a);

      tr.appendChild(td);
					
      if (i % 2 == 0)
        table.appendChild(tr);
    }

    td_photos.appendChild(table);
  }
  else
  {
  }
}

