function startAjax() {
   
   var url = "Ajax1.asp?xml="+xml;
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
   }
   req.open("GET", url, true);
   req.onreadystatechange = callback;
   req.send(null);
}

function callback() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            parseMessage(req.responseXML);
            //alert(req.responseXML);
        }
    }
}

function parseMessage(righe) {
	    
	for(var i=1; i<=numSezioni;i++)
	{
    var sezione = righe.getElementsByTagName("candidato"+i)[0]; //sezione XML
    //alert(sezione.nodeName);
    updateValoriPartito(sezione,i);
	}
 // updateTotali(righe);
}

/**
* Aggoirna i voti dei partiti
*/
function updateValoriPartito(sezione,numSezione) 
  {    
    var rawHtmlSezione = document.getElementById("candidato"+numSezione);
    
    for(i = inizioCol; i<=numPartiti+inizioCol-1;i++)
    {
      var xmlPartito = sezione.getElementsByTagName("sezione"+(i-inizioCol+1))[0].firstChild;
      var htmlPartito = getPartitoInSezione(rawHtmlSezione,i); //Elemento TD
      voto = document.createTextNode(xmlPartito.nodeValue);
      htmlPartito.replaceChild(voto,htmlPartito.firstChild) //Aggiorna il voto nella cella
    }
  }

/**
* Recupera l'elemento TD dell'iesimo partito all'interno di una sezione 
*/
function getPartitoInSezione(sezione,index)
{
  if(window.ActiveXObject)
      partito = sezione.firstChild.nextSibling;
      
  else 
      partito = sezione.firstChild.nextSibling.nextSibling;
      
  if(index==1)
     return partito;
  if(index==0){
     if(window.ActiveXObject)
      return sezione.firstChild;
      else
      return sezione.firstChild.nextSibling;
   }
  for(var i=2; i<=index;i++)
  {
    partito= partito.nextSibling;
  }
    
  return partito;
}

function setTheInterval()
{
  startAjax(); //decommentare per dati finali
   
 //  setInterval('startAjax()',5000); //decommentare per dati parziali
}
