// Fonction pour Ajax

var timer = null;
	   
function getXMLHTTP()
{
    var xhr=null;
 
    if (window.XMLHttpRequest) // Firefox et autres.
	{
	     xhr = new XMLHttpRequest();
		 
	}
    
    else if (window.ActiveXObject) // Internet Explorer.
    {
         try
         {
             xhr = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e)
         {
                try
                {
                       xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e1)
                {
                     xhr = null;
                }
         }
     }
     else
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
   return xhr;
}
 
// Div refresh.
 
function getDiv1(MyDiv, MyUrl) { 
 
var xmlhttp1 = null;  
	 
	var mondiv1 = document.getElementById(MyDiv); 
		 
	if (!mondiv1) { 
  		
		return 1; 
		
  	} 
  
    if (xmlhttp1 && xmlhttp1.readyState != 0) { 
        xmlhttp1.abort(); 
	} 
  
	xmlhttp1 = getXMLHTTP(); 
  
    if (xmlhttp1) { 
  
		xmlhttp1.open("GET", MyUrl, true);  
  
     	/* on définit ce qui doit se passer quand la page répondra */ 
      	 
      	xmlhttp1.onreadystatechange = function() { 
      		 
      		if (xmlhttp1.readyState == 4 && xmlhttp1.responseText != '') /* 4 : état "complete" */ {
		    var out = xmlhttp1.responseText;
			//alert (out.indexOf('<div id="horaires">'));
			out = out.substring(out.indexOf('<div id="horaires">')+19, out.length);
			out = out.substring(0, out.indexOf('</div>ENDHORAIRE'));
			mondiv1.innerHTML = out; 
	
      		}
		} 
      	 
      	xmlhttp1.send(null); 
     } 
}
 
function rafraichir()
{		

  getDiv1('horaires', 'index.php?id=46');
  setTimeout("rafraichir()", 30000);
  switchRefresh("stop");
  
}
function rafraichirNL()
{		
  getDiv1('horaires', 'index.php?id=46&L=1');
  setTimeout("rafraichirNL()", 30000);
  switchRefresh("start");
  
}function rafraichirEN()
{		
  getDiv1('horaires', 'index.php?id=46&L=2');
  setTimeout("rafraichirEN()", 30000);
  switchRefresh("start");
  
}
function stopRefresh()
{
  if(timer != null)
  {
    clearTimeout(timer);
    timer = null;
  }
  switchRefresh("start");
}
function switchRefresh(disp)
{
  stop = document.getElementById('horaires_stop');
  start = document.getElementById('horaires_start');
  if(!stop || !start) return;
   
  if(disp == "stop")
  {
    stop.style.display = "inline";
    start.style.display = "none";
  }
  else
  {
    stop.style.display = "none";
    start.style.display = "inline";
  }
}

