
var request;
function createRequest() {
//  var request=null;
   try
     {
     // Firefox, Opera 8.0+, Safari
      request=new XMLHttpRequest();
      }
  catch (trymicrosoft)
    {
       // Internet Explorer
      try
       {
       request=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (eothermicrosoft)
      {
      try
        {
         request=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (failed)
        {
        alert("Your browser does not support AJAX!");
        request = null;
	    return false;
        }
      }
    }
 
   //alert(request);
      if (request == null)
      alert("Error creating request object");
}	

/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */
function STAR(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function STARS(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.documentElement.scrollLeft,'Y':event.clientY+document.documentElement.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }


star={};
star.num=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(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 {

            STARS('starCur'+n).width=oX+'px';
            STARS('starUser'+n).color='#111';
            STAR('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';
        }
    };
} };

star.update=function(e,o,table_name,table_id) { 
	var n=star.num, v=parseInt(STAR('starUser'+n).innerHTML);
	n=o.id.substr(4); STAR('starCur'+n).title=v;
	
	createRequest();
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
	request.open('GET','/ajaxrequest/submit_rating.php?table_id='+table_id+'&table_name='+table_name+'&vote='+((v/100)*5),true);
	request.setRequestHeader("Content-Type", contentType);
	request.onreadystatechange = ratingSubmit;
	request.send(null);	
	return false; 

};

star.revert=function() { var n=star.num, v=parseInt(STAR('starCur'+n).title);

    STARS('starCur'+n).width=Math.round(v*84/100)+'px';
    STAR('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
    STAR('starUser'+n).style.color='#888';
    
    document.onmousemove='';

};



function ratingSubmit(){
	if(request.readyState==4){
		if(request.responseText != 'false')
			document.getElementById('star').innerHTML = request.responseText;		
	}
}