// rating_draw(,5,0); // preload the turned on+off star images var i1 = new Image(); i1.src = '/pictures/star_full.png'; var i2 = new Image(); i2.src = '/pictures/star_none.png'; // display this rating score function rating_set (id, max) { // turn on/off all imgs (assumedly stars) in this element var el = document.getElementById('rating_'+id); if (!el) { return false; } // do some error checking var is = el.getElementsByTagName('img'); var c = 0; for (var i = 0; i < is.length; i++) { is[i].src = '/pictures/star_'+(c < max ? 'full' : 'none')+'.png'; c++; } return false; } // send this rating as an ajax call function rating_submit (id, n) { sendAJAXrequest('/ajax/rating/' + id + '/' + n, function (data) { confirmajax_rating_submit(id, n, data); }); return false; } // handle the result response function confirmajax_rating_submit (id, n, data) { // get the response var el = document.getElementById('rating_'+id); var m = (data[0]['success'] > 0 ? 'Thank you for rating this video a '+n+'! Re-rate' : 'There was a problem submitting your rating!'); if (el) { el.innerHTML = m; }// else { alert(m); } } // draw/fill an element (div) with the specified number of stars (rating score) function rating_draw (id,max,cur) { // fill all the content into the space/element/div var el = document.getElementById('rating_'+id); if (el) { el.innerHTML = ''; // clear js req msg for (var n = 1; n <= max; n++) { // create the link which displays and submits star level var a = document.createElement('a'); // a.setAttribute('href', '#'); a.href = '#'; /* doesn't work in IE for who cares what reason a.setAttribute('onMouseOver', 'return rating_set('+id+','+n+')'); a.setAttribute('onClick', 'return rating_submit('+id+','+n+')'); a.setAttribute('onMouseOut', 'return rating_set('+id+',0)'); */ a.onmouseover = new Function ('return rating_set('+id+','+n+');'); a.onclick = new Function ('return rating_submit('+id+','+n+');'); a.onmouseout = new Function ('return rating_set('+id+',0);'); /* // these create closures which point to n surrounding the loop, not inside the loop // and therefore will all hold the same, final value that n has when the loop ends a.onmouseover = function () { return rating_set(id,n); }; a.onclick = function () { return rating_submit(id,n); }; a.onmouseout = function () { return rating_set(id,0); }; */ // create the actual star image for this level var i = document.createElement('img'); i.setAttribute('src', '/pictures/star_'+(n <= cur ? 'full' : 'none')+'.png'); // now add them to the element/space a.appendChild(i); el.appendChild(a); }} }