// charge le résumé de l'étape en AJAX
function ajaxLoadIndex()
{
  //alert('ajaxLoadIndex');
  var xhr = getXHR();
  xhr.onreadystatechange = function() { ajaxDisplayIndex(xhr); };
  var strUrl = url2008AustralieIndexLoad;
  xhr.open('GET', strUrl, true);
  xhr.send(null);
}

// affiche le résumé de l'étape
function ajaxDisplayIndex(xhr)
{
  //alert('ajaxDisplayEtape');
  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;
    //alert(items.length);
  	if (items.length >= 7)
  	{
  	  cleanChild('index_date');
  	  div = document.getElementById('index_date');
  	  
  	  nodeStrong = document.createElement('strong');
  	  nodeText = document.createTextNode(items.item(2).firstChild.nodeValue);
  	  nodeStrong.appendChild(nodeText);
  	  div.appendChild(nodeStrong);
  	  
  	  cleanChild('index_link');
  	  div = document.getElementById('index_link');
  	  
  	  nodeA = createANode('etape.php?id_etape=' + items.item(0).firstChild.nodeValue);
  	  addAttribute(nodeA, 'class', 'texte_gras');
  	  nodeA.style.color = '#983c3d';
  	  nodeText = document.createTextNode(items.item(3).firstChild.nodeValue);
  	  nodeA.appendChild(nodeText);
  	  div.appendChild(nodeA);

  	  cleanChild('index_etape');
  	  span = document.getElementById('index_etape');

      nodeEm = document.createElement('em');
	    nodeEm.innerHTML = items.item(4).firstChild.nodeValue + '<br/>';
  	  span.appendChild(nodeEm);
  	  
  	  cleanChild('index_resume');
  	  img = document.getElementById('guillemets');
  	  span = document.getElementById('index_resume');

      if (items.item(5).firstChild.nodeValue != '')
      {
    	  span.innerHTML = items.item(5).firstChild.nodeValue + '...';
    	  nodeA = createANode('etape.php?id_etape=' + items.item(0).firstChild.nodeValue);
    	  nodeA.style.color = '#983c3d';
    	  nodeText = document.createTextNode('(suite + photos)');
    	  nodeA.appendChild(nodeText);
    	  span.appendChild(nodeA);
    	  
    	  img.style.display = 'inline-block';
    	  pngFix(img);
    	}
    	else
  	  {
    	  br = document.createElement('br');
    	  span.appendChild(br);
    	  nodeA = createANode('etape.php?id_etape=' + items.item(0).firstChild.nodeValue);
    	  nodeA.style.color = '#983c3d';
    	  nodeText = document.createTextNode('Consulter la page d\'étape');
    	  nodeA.appendChild(nodeText);
    	  span.appendChild(nodeA);
    	  
    	  img.style.display = 'none';
  	  }

      img = document.getElementById('index_photo');
      img.src = 'images/' + items.item(6).firstChild.nodeValue;
      pngFix(img);
      
      for (i=1; i<32; i++)
      {
        if (i < 10)
          td = document.getElementById('index_calendrier_0'+i);
        else
          td = document.getElementById('index_calendrier_'+i);
          
        if (td != null)
        {
          if (i == items.item(1).firstChild.nodeValue)
          {
            var pos = getPos(td);
            div = document.getElementById('jour');
            div.style.left = (pos[0]+1) + 'px';
            div.style.top = (pos[1]+1) + 'px';
            div.innerHTML = i;
            div.style.display = 'block';

            if (i >= 18 && i <= 26)
            {
              div.style.color = '#983c3d';
            }
            else if (i >= 2 && i <= 15)
            {
              div.style.color = '#3c3e93';
            }
            else
            {
              div.style.color = '#3c9a3c';
            }
          }
          else
          {
          }
        }
      }
      
      div = document.getElementById('voiture');
      img = document.getElementById('voiture_img');
      
      if (items.length == 9)
      {
        div.style.display = 'block';
        div.style.top = items.item(7).firstChild.nodeValue + 'px';
        div.style.left = items.item(8).firstChild.nodeValue + 'px';
        div.style.width = '20px';
        div.style.height = '20px';

        if ((items.item(0).firstChild.nodeValue >= 4 && items.item(0).firstChild.nodeValue <= 10) || items.item(0).firstChild.nodeValue == 16 || (items.item(0).firstChild.nodeValue >= 18 && items.item(0).firstChild.nodeValue <= 24))
        {
          img.src = 'images/index_voiture_car.png';
        }
        else if (items.item(0).firstChild.nodeValue >= 11 && items.item(0).firstChild.nodeValue <= 12)
        {
          img.src = 'images/index_voiture_plane.png';
        }
        else if (items.item(0).firstChild.nodeValue >= 13 && items.item(0).firstChild.nodeValue <= 15)
        {
          img.src = 'images/index_voiture_4x4.png';
        }
        else if (items.item(0).firstChild.nodeValue >= 25 && items.item(0).firstChild.nodeValue <= 27)
        {
          img.src = 'images/index_voiture_bus.png';
        }
        else if (items.item(0).firstChild.nodeValue == 17)
        {
          img.src = 'images/index_voiture_boat.png';
        }
        pngFix(img);
      }
      else
      {
        div.style.display = 'none';
      }
    }
  }
}

function onClickJour(jour)
{
  //alert('onClickJour(' + jour + ')');
  var xhr = getXHR();
  xhr.onreadystatechange = function() { ajaxDisplayIndex(xhr); };
  var strUrl = url2008AustralieIndexLoad;
  strUrl += '?jour=' + jour;
  xhr.open('GET', strUrl, true);
  xhr.send(null);

}
