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.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

star1={};
voted_stars = {};

star1.mouse=function(e,o,percrevert,schedaID) { 
	
	if(star1.stop || isNaN(star1.stop)) { 
		
		star1.stop=0;

		document.onmousemove=function(e) { 
			
			var n=star1.num;
		
			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) { 
				
				star1.stop=1; 
								
				star1.revert(percrevert, schedaID); 
				
			}	else {
				
				$S('starCur'+n).width=oX+'px';
				$S('starUser'+n).color='#000';
				$('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';
				
			}
		};
	} 
};

star1.update=function(e,o,schedaID,userid,usernick,tiposcheda,percrevert) { 
		
	var n=star1.num, v=parseInt($('starUser'+n).innerHTML);

	n=o.id.substr(4); 
	
	$('starCur'+n).title='grazie per aver votato!';

	req=new XMLHttpRequest();
	
	//"action="+tipo+"&id="+attr+"&autoreid="+attr1+"&autorenick="+attr2+"&voto="+attr3
	
	req.open("POST","/ajax.php?action=salva&id="+schedaID+"&autoreid="+userid+"&autorenick="+usernick+"&voto="+(Math.round(v/100*5*2)/2),false); 
	
	req.send(null);
	
	if (req.readyState == 4) { 
			
		if (req.status == 200) { 
			
			if (req.responseText == 1) {
				
				document.getElementById("testoVoto"+schedaID).innerHTML = "Grazie per aver votato!";
			
			} else {
			
				document.getElementById("testoVoto"+schedaID).innerHTML = "Si prega di riprovare!";
			
			}
		}			
	}
		  
};

star1.revert=function(percrevert, schedaID) {
	
//		var n=star1.num;
//////	
//	var v=parseInt($('starCur'+n).title);
////
//	//starwidth = (percrevert == 0) ? parseInt($('starUser'+n).innerHTML) : percrevert;
		
		//document.getElementById("starCur"+schedaID).width=Math.round(100*84/100)+'px';
		
	$S('starCur'+n).width=Math.round(v*84/100)+'px';
		
	alert(Math.round(100*84/100)+'px');	
		
	//$S('starCur'+n).width=starwidth;
	
//	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
//	$('starUser'+n).style.color='#888';
//	
	//$('starUser'+n).onmousemove='';

};

star1.num=0;