function vota (modo,numero,maximo) {
//Votaciones: maximo es el número máximo de items, 
//            cont es el número de votados.
  var el,iv,cont;
  var votos=new Array (maximo+1);
  
  for (iv=1; iv<=maximo; iv++) votos[iv]=0;
  cont=0;
  for (iv=1; iv<=maximo; iv++) {	
   el=document.getElementById (modo+"ch"+iv);
   if (el.checked) {
   	cont++;
   	votos[cont]=el.value;
   }	
  } 
  graba_votacion (modo,votos,cont);  
}

function graba_votacion (modo,votos,cont) {
  var ig,str;
 	
  str="ticket=5673&modo="+modo+"&cont="+cont;	
  for (ig=1; ig<=cont; ig++) {
   	str=str+"&voto"+ig+"="+votos[ig];
  }	
  //alert (str);
  sxmlhttpPost ("graba_votos.php",str,modo);
}

function sxmlhttpPost(strURL, strPOST, modo) {
/* Crea el objeto XHR y hace llamada AJAX a strURL con parámetros strPOST */
/* *********************** LLAMADAS SINCRONAS *************************** */

    var el, ell, res, str, ir, codigo, votos, porc;
	var xmlHttpReq = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, false);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.send(strPOST);
	str=self.xmlHttpReq.responseXML;
	//Aquí hay que actualizar la página con los resultados que devuelva
	//el xmlHttpReq.responseXML.
	for (ir=0; ir<str.getElementsByTagName ("item").length; ir++) {
	 elem=str.getElementsByTagName ("item")[ir];
	 codigo=elem.getElementsByTagName ("codigo")[0].firstChild.data;
	 votos=elem.getElementsByTagName ("votos")[0].firstChild.data;
	 porc=elem.getElementsByTagName ("porcentaje")[0].firstChild.data;
	 el=document.getElementById (modo+"p"+codigo);
	 ell=document.getElementById (modo+"pr"+codigo);
	 el.style.width=String(porc)+"%";
	 ell.style.width=String(100-porc)+"%";
	 el=document.getElementById (modo+"tp"+codigo);
     if (el.hasChildNodes()) el.removeChild(el.lastChild);
     el.appendChild(document.createTextNode(String(votos)+" ("+String(porc)+"%)")); 
	}  
}
