function obtener_votacion(id_noticia, dominio, id_div){
	var lectorXML = new LectorXML('/votacion/pixel_votos.php?codigo='+id_noticia+'&dominio='+dominio);
	var xml = lectorXML.xml;
	pintarResultados(xml, id_div);
}

function votar(id_noticia, dominio, voto, id_div){
	//modificado 16/04/08 puede haber 2 noticias en una pagina, se añade id, para paginas antiguas se deja sin id
	if (document.getElementById('votacion'+id_div)!=null){
		document.getElementById('votacion'+id_div).className="inv";
	}else{
		if (document.getElementById('votacion')!=null) document.getElementById('votacion').className="inv";
	}
	if (document.getElementById('enviandoVotacion'+id_div)!=null){
		document.getElementById('enviandoVotacion'+id_div).className="";
	}else{
		if (document.getElementById('enviandoVotacion')!=null) document.getElementById('enviandoVotacion').className="";
	}
	//hacemos la petición
	var lectorXML = new LectorXML('/votacion/pixel_vota.php?codigo='+id_noticia+'&dominio='+dominio+'&voto='+voto);
	//recogemos datos y pintamos
	var xml = lectorXML.xml;
	pintarResultados(xml, id_div);
	
	if (document.getElementById('enviandoVotacion'+id_div)!=null){
		document.getElementById('enviandoVotacion'+id_div).className="inv";
	}else{
		if (document.getElementById('enviandoVotacion')!=null) document.getElementById('enviandoVotacion').className="inv";
	}
	if (document.getElementById('votacion'+id_div)!=null){
		document.getElementById('votacion'+id_div).className="";
	}else{
		if (document.getElementById('votacion')!=null) document.getElementById('votacion').className="";
	}
	if (document.getElementById('votacionEnviada'+id_div)!=null){
		document.getElementById('votacionEnviada'+id_div).className="";
	}else{
		if (document.getElementById('votacionEnviada')!=null) document.getElementById('votacionEnviada').className="";
	}
	//Deshabilitamos el envio de votos
	for (i=1;i<=5;i++){
		if (document.getElementById('ref'+id_div+i)!=null){
			document.getElementById('ref'+id_div+i).onclick=nada;
		}else{
			document.getElementById('ref'+i).onclick=nada;
		}
	}
}

//función para que una vez se haya realizado la votación, no se pueda votar
function nada(){
return false;
//nada
}

//Recoge los datos y pinta las estrellas y el numero de votos
function pintarResultados(xml, id_div){
	if (xml!=null){
		xmldoc = xmlParse(xml);
		if (xmldoc!=null && xmldoc.getElementsByTagName("RESULTADO")[0]!=null){
			// Obtiene los datos del XML
			var valoracionEnviada=xmldoc.getElementsByTagName("ENVIADA")[0].firstChild.nodeValue;;
			var valoracionMedia=xmldoc.getElementsByTagName("MEDIA")[0].firstChild.nodeValue;
			var numeroVotos=xmldoc.getElementsByTagName("NUMEROVOTOS")[0].firstChild.nodeValue;
			if (document.getElementById('star'+id_div+'99')!=null){
				document.getElementById('star'+id_div+'99').src="http://media.vtelevision.es/img/stars_" + valoracionMedia + ".gif";
			}else{
				for (i=1;i<=5;i++){
					if (valoracionMedia>=i){
						if (document.getElementById('star'+id_div+i)!=null){
                            getObject('star'+id_div+i).className="on";
						}else{
							if (document.getElementById('star'+i)!=null) document.getElementById('star'+i).className="on";
						}
					}else{
						if (document.getElementById('star'+id_div+i)!=null){
                            getObject('star'+id_div+i).className="";
						}else{
							if (document.getElementById('star'+i)!=null) document.getElementById('star'+i).className="";
						}
					}
				}
			}
			if (document.getElementById('numeroVotos'+id_div)!=null){
				document.getElementById('numeroVotos'+id_div).innerHTML=numeroVotos+"<span> votos</span>";
			}else{
				if (document.getElementById('numeroVotos')!=null) document.getElementById('numeroVotos').innerHTML=numeroVotos+"<span> votos</span>";
			}
		}
	}
}
