﻿
/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

function $A(v, o) { return ((typeof (o) == 'object' ? o : document).getElementById(v)); }
function $S(o) { return ((typeof (o) == 'object' ? o : $A(o)).style); }
function agent(v) { return (Math.max(navigator.userAgent.toLowerCase().indexOf(v), 0)); }
function abPos(o) { var o = (typeof (o) == 'object' ? o : $A(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 = {};

star.mouse = function(e, o) {
    if (star.stop || isNaN(star.stop)) {
        star.stop = 0;

        document.onmousemove = function(e) {
            var n = star.num;

            var p = abPos($A('star' + n)), x = XY(e), oX = x.X - p.X, oY = x.Y - p.Y; star.num = o.id.substr(4);

            if (oX < 1 || oX > 84 || oY < 0 || oY > 19) { star.stop = 1; star.revert(); }

            else {


                $S('starUser' + n).color = '#111';
                var tot = Math.ceil(oX / 84 * 5);
                $A('starUser' + n).innerHTML = tot;
                $S('starCur' + n).width = Math.round(tot * 84 / 5) + 'px';
                $A('starCur' + n).title = tot;

            }
        };
    }
};

star.update = function(e, o) {
    var n = star.num, v = parseInt(($A('starUser' + n).innerHTML / 5) * 100);

    n = o.id.substr(4);

    $A('starCur' + n).title = $A('starUser' + n).innerHTML;
    //    if (window.XMLHttpRequest)                 //  Objet de la fenêtre courant
    //    {
    //        req = new XMLHttpRequest();     //  Firefox, Safari, ...
    //    }
    //    else if (window.ActiveXObject)                    //  Version Active
    //    {
    //        req = new ActiveXObject("Microsoft.XMLHTTP");   // Internet Explorer 
    //    }

    //    req = new XMLHttpRequest(); req.open('GET', '/AJAX_Star_Vote.php?vote=' + (v / 100), false); req.send(null);
    document.formText.rate.value = v / 20;
};

star.revert = function() {
    var n = star.num, v = $A('starUser' + n).innerHTML;

    $S('starCur' + n).width = Math.round(v * 84 / 5) + 'px';
    $A('starUser' + n).innerHTML = (v > 0 ? v : '');
    $A('starUser' + n).style.color = '#888';

    document.onmousemove = '';

};

star.num = 0;
