/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

function $(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $S(o) { return((typeof(o)=='object'?o:$(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(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.documentElement.scrollLeft,'Y':event.clientY+document.documentElement.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

star={};
starDevide=20; // 1
starUnits=""; // %
star_time="";
star_valide=false;
star.mouse=function(e,o) { 
	if(star.stop || isNaN(star.stop)) { 
		star.stop=0;
	    document.onmousemove=function(e) { 
	    	//alert("ok1");
	    	var n=star.num;
	    	n=o.id.substr(4); 
	    	
	    	var p=abPos($('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 {
	        	//oX=oX -(oX % starStep/2) + starStep/2;
	            if (!star_valide) {
		            $S('starCur'+n).width=oX+'px';
		            $S('starUser'+n).color='#111';
		            $('starUser'+n).innerHTML=Math.round(oX/84*100/starDevide)+ starUnits ;
		        }
	        }
	    };
	} 
};

star.update=function(e,o) { 
	var n=star.num; 
	n=o.id.substr(4); 
	
	var v=parseInt($('starUser'+n).innerHTML);
    
    URLLoad = '/Culinotheque/CoteAmour_MAJ.asp?id='+n+'&vote='+v
    if (document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument('', '', null);
		xmlDoc.load(URLLoad);
	// ActiveX pour Internet Explorer
	} else if (window.ActiveXObject) {
		try {
		  xmlDoc = new ActiveXObject('Msxml2.XMLDOM');
		} catch (e) {
		  xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
		}
		xmlDoc.async = false;
		xmlDoc.load(URLLoad);
	// à l'aide de lobjet XMLHTTPRequest
	} else if (window.XMLHttpRequest) {
		xmlDoc = new XMLHttpRequest();
		xmlDoc.overrideMimeType('text/xml');
		xmlDoc.open('GET',URLLoad, false);
		xmlDoc.send(null);
		if (this.xmlDoc.readyState == 4) xmlDoc = xmlDoc.responseXML;
	}
    
   // req=new XMLHttpRequest();
   //  req.open('GET','/Culinotheque/CoteAmour_MAJ.asp?id='+n+'&vote='+v,false);
   // req.send(null);
    
    //if (xmlDoc.status == 200) {
    	star_valide=true
    	$S('starCur'+n).width = '84px'
    	star_time = setTimeout ("star.clignote()",0);
    	$('starCur'+n).title=v;
    //} 
};

star.revert=function() { 
	star_valide=false;
	clearTimeout(star_time);
	
	var n=star.num;
	var v=parseInt($('starCur'+n).title);
	$S('starCur'+n).width=Math.round((v*starDevide)*84/100)+'px';
    $('starUser'+n).innerHTML=(v>=0?v+ starUnits :'');
    $('starUser'+n).style.color='#888';
    document.onmousemove='';
};

star.clignote=function() {
	var n=star.num;
	if ($S('starCur'+n).width == '84px') {
		$S('starCur'+n).width = '0px'
	} else {
		$S('starCur'+n).width = '84px'
	}
	star_time = setTimeout ("star.clignote()",500);
}

star.num=0;