/*<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />*/ 
/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

function $G(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $S(o) { return((typeof(o)=='object'?o:$G(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$G(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={};
vglob = 0;
wglob = 0;

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($G('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('starCur'+n).width=oX+'px';
			$S('starUser'+n).color='#111';
			$G('starUser'+n).innerHTML=Math.round((oX/84*5)*10)/10;
		}
							};
	 } 
};

star.update=function(e,o)
 { 

 	var n=star.num, v=parseFloat($G('starUser'+n).innerHTML);
		
	
	n=o.id.substr(4); 
	$G('starCur'+n).title=v;//v;

	//req=new XMLHttpRequest(); 
	req = createXMLHttp(); //создает xMLhttp
	
	url = '/AJAX_Star_Vote.php?num='+n+'&vote='+v;
	req.open('GET',url,true); 
	req.onreadystatechange = updatePage;
	req.send(null);    


};

function updatePage() {
//alert(req.readyState);
  if (req.readyState == 4)
   { 		
   		if (req.status == 200)
		{
		//document.write(req.responseText);
		//resp = req.responseText;
		//alert('asa');
		//alert(req.responseText);
		var reg=/Вы уже голосовали/
		if	(reg.test(req.responseText) )
		{
		n=star.num;
		$G('starUser'+n).innerHTML = vglob;
		$G('starCur'+n).title =vglob;
		$S('starCur'+n).width = wglob;
		alert(req.responseText);
		}
		else
		{
		n=star.num;
		$G('starUser'+n).innerHTML=req.responseText;
		$G('starCur'+n).title=req.responseText;
		$S('starCur'+n).width=Math.round(req.responseText*84/5)+'px';
		alert('Ваш голос учтен! Спасибо');	
		}
		//r = $('starCur'+n).title;
		//alert('Ваш голос учтен! Спасибо');	
		
		}
        
   }
}



    //var response = xmlHttp.responseText;
   // document.write = response;
  // alert("asdasd");

star.revert=function() { var n=star.num, v=parseFloat($G('starCur'+n).title);
	vglob = v;
	$S('starCur'+n).width=Math.round(v*84/5)+'px';
	wglob = $S('starCur'+n).width;
	$G('starUser'+n).innerHTML=(v>0?(v):'');
	$G('starUser'+n).style.color='#888';
	
	document.onmousemove='';

};

star.num=0;