 /* AJAX Star Rating : v1.0.3 : 2008/05/06 */ /* http://www.nofunc.com/AJAX_Star_Rating/ */ var anchoRating = 128; var ajax_yaRemoteRating = ''; function $rating(v, o) { return ((typeof (o) == 'object' ? o : document).getElementById(v)); } function $S(o) { return ((typeof (o) == 'object' ? o : $rating(o)).style); } function agent(v) { return (Math.max(navigator.userAgent.toLowerCase().indexOf(v), 0)); } function abPos(o) { var o = (typeof (o) == 'object' ? o : $rating(o)), z = { X: 0, Y: 0 }; while (o != null) { z.X += o.offsetLeft; z.Y += o.offsetTop; o = o.offsetParent; }; return (z); } function XY(e, v) { var o = agent('msie') ? { 'X': event.clientX + document.body.scrollLeft, 'Y': event.clientY + document.body.scrollTop} : { 'X': e.pageX, 'Y': e.pageY }; return (v ? o[v] : o); } star = {}; function round1(n) { try { n = Math.round(n * 100) / 100; if (n < 0) n -= 0.01; else n += 0.01; n += ''; return n.substring(0, n.indexOf('.') + 2); } catch (e) { return n + ' - ' + e.description; } } star.mouse = function (e, o, ncampo) { if (star.stop || isNaN(star.stop)) { star.stop = 0; star.num = ncampo; document.onmousemove = function (e) { try { var n = star.num; var p = abPos($rating('star' + n)), x = XY(e), oX = x.X - p.X, oY = x.Y - p.Y; if (oX < 1 || oX > anchoRating || oY < 0 || oY > 19) { star.stop = 1; star.revert(n); } else { $S('starCur' + n).width = oX + 'px'; $S('starUser' + n).color = '#111'; $rating('starUser' + n).innerHTML = round1(oX / anchoRating * 10) + ' puntos'; } } catch (e) { } }; } }; star.update = function (e, o, ncampo, fRemote, valID) { try { var n = star.num, v = parseInt(parseFloat($rating('starUser' + n).innerHTML) * 10); n = o.id.substr(4); $rating('starCur' + n).title = v; updateRatingAjax(ncampo, v, fRemote, valID) } catch (e) { alert('errupd' + e.description) } }; function updateRatingAjax(nCampo, valor, fRemote, valorID) { try { var zdiv = 'ratingAjax_' + nCampo; var httpGetDatos = getHTTPObject(); if (httpGetDatos.readyState == 4 || httpGetDatos.readyState == 0) { esperando(zdiv); httpGetDatos.open("GET", '/es/comun/rating_r.asp?fx=RAJAX&n=' + fRemote + '&i=' + valorID + '&v=' + valor + '&rand=' + Math.floor(Math.random() * 1000000), true); httpGetDatos.onreadystatechange = function () { var results; try { if (httpGetDatos.readyState == 4) { results = httpGetDatos.responseText; runResultadoAjax(zdiv, results); } } catch (e) { } }; httpGetDatos.send(null); } } catch (e) { alert('erajx:' + e.description); } } function getRatingAjax(nCampo, fRemote, valorID) { try { var yaRemote; yaRemote = ajax_yaRemoteRating.search(':' + nCampo + ':'); ajax_yaRemoteRating += ':' + nCampo + ':'; if (yaRemote < 0) { var zdiv = 'ratingAjax_' + nCampo; var httpGetDatos = getHTTPObject(); if (httpGetDatos.readyState == 4 || httpGetDatos.readyState == 0) { httpGetDatos.open("GET", '/es/comun/rating_r.asp?fx=RAJAXV&n=' + fRemote + '&i=' + valorID + '&rand=' + Math.floor(Math.random() * 1000000), true); httpGetDatos.onreadystatechange = function () { var results; try { if (httpGetDatos.readyState == 4) { results = httpGetDatos.responseText; runResultadoAjax(zdiv, results); } } catch (e) { } }; httpGetDatos.send(null); } } } catch (e) { alert('erajx:' + e.description); } } star.revert = function (campo) { var n = campo, v = parseInt($rating('starCur' + n).title); v = parseInt($rating(n).value); $S('starCur' + n).width = Math.round(v * anchoRating / 100) + 'px'; $rating('starUser' + n).innerHTML = (v > 0 ? round1(v / 10) + '' : '') + ' puntos'; $rating('starUser' + n).style.color = '#888'; document.onmousemove = ''; };
