var req;
var nr;

function $Star(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $SStar(o) { return((typeof(o)=='object'?o:$Star(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$Star(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($Star('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 {

			$SStar('starCur'+n).width=oX+'px';
			$Star('starCur'+n).title=Math.round(oX/84*100);
			
		}
	};
} };

star.update=function(e,o,aid) { 

	var n=star.num, v=parseInt($Star('starCur'+n).title);
	
	req=GetXmlHttpObject();
	
	if (req==null){alert ("Browser does not support HTTP Request");return;}
	nr = n;
    if(req) {
		
		var url='/tools/update_vote.php';
				
		var params = params +'&id='+ aid +'&vote='+ (v);
		req.onreadystatechange=stateChangedVote;
		req.open("POST",url,true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", params.length);
		req.setRequestHeader("Connection", "close");
		req.send(params);
	}
		
	
	
};

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.xmlhttpDesc");
  }
return null;
}// JavaScript Document

function stateChangedVote()
{			
	if (req.readyState==4){
		document.getElementById("votenr" + nr).innerHTML=req.responseText;
	}
}

star.revert=function() { 

	var n=star.num; 
	var v;

	if((ob = $Star('saver'+n)) != null){
		
		v=parseInt(ob.title);
	
	
		if(v != null || v != ""){
			$SStar('starCur'+n).width=Math.round(v*84/100)+'px';
			$Star('starCur'+n).title=(v>0?Math.round(v)+'%':'');
		}
		document.onmousemove='';
	}
};

star.num=0;
