function creaEstrellas (idusu, puntaje, theme){

for (i = 1; i<=10; i++){

    var estrella = document.createElement('img');
    estrella.id = 'e'+i;
    if (i <= puntaje)
        estrella.setAttribute('src', theme+'/images/star.png');
        else
           estrella.setAttribute('src', theme+'/images/stard.png');

    estrella.onclick = function(){votar(idusu, this.id, theme);};
    estrella.onmouseover = function(){pintaEstrella(this.id, theme);};
    estrella.setAttribute('alt', i+' puntos');
    estrella.setAttribute('height', '25px');
    estrella.setAttribute('width', '25px');
    // Añadimos el elemento LI a la lista UL
    var agrega = document.getElementById('estrellas');
    agrega.appendChild(estrella);

}

}

function pintaEstrella (punto, theme){

        punto = punto.split('e');
        punto = punto[1];
    
    
    for (i = 1; i<=10; i++){
    estrella = document.getElementById('e'+i);

    if (i <= punto)
        estrella.setAttribute('src', theme+'/images/star.png');
        else
           estrella.setAttribute('src', theme+'/images/stard.png');
    }    
    
}


function votar (idFoto, punto, theme){

    punto = punto.split('e');
    punto = punto[1];

    for (i = 1; i<=10; i++){
    var eliminar = document.getElementById('e'+i);
    var padre = eliminar.parentNode;
    padre.removeChild(eliminar);
    }



          random = num_random= parseInt (Math.random()*999999999999);
          var ajax=creaAjax();
          url = theme+"insertavoto.php?puntos="+punto+"&idFoto="+idFoto+"&r="+random;
          var capaContenedora = document.getElementById('estrellas');


         ajax.open ('GET', url, true);


        ajax.onreadystatechange=function() {
        if(ajax.readyState == 4) {
            if(ajax.status == 200) {
                capaContenedora.innerHTML=ajax.responseText;
                } else {
                capaContenedora.innerHTML = 'Hay errores en el servidor. Inténtelo más tarde, gracias.';
                }
            } else {
                   capaContenedora.innerHTML = "<div style=\"height:400px;\"><span  style=\"background:#002B84; color:#FFFFFF\">Enviando...</span></div>";
            }
        }



         ajax.send(null);
         return;

}

function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}