
function GetXmlHttpObject(/*handler*/)
{ 
	var objXmlHttp=null;
	
	if (navigator.userAgent.indexOf("MSIE")>=0)	{ 
	var strName="Msxml2.XMLHTTP";
	if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
		strName="Microsoft.XMLHTTP";
	} 
	try	{ 
		objXmlHttp=new ActiveXObject(strName);
//		objXmlHttp.onreadystatechange=handler;
		return objXmlHttp;
	} 
	catch(e)	{ 
		alert("Error. Scripting for ActiveX might be disabled");
		return;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)	{
		objXmlHttp=new XMLHttpRequest();
//		objXmlHttp.onload=handler;
//		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 



var starGo='', starNum=0;
/* Create a new XMLHttpRequest object to talk to the Web server */
var req = false;

function $(v) { 
	return(document.getElementById(v)); 
}

function $S(v) { 
	return(document.getElementById(v).style); 
}

function agent(v) { 
	return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); 
}

function absPos(o) { 
	var r = {x:o.offsetLeft,y:o.offsetTop}; 
	
	if (o.offsetParent) { 
		var v=absPos(o.offsetParent); 
		r.x+=v.x; 
		r.y+=v.y; 
	}
	 
	return(r); 
} 

function getXPos(e) {
	return (agent('msie') ? event.clientX + document.body.scrollTop : e.pageX);
}

function getYPos(e) {
	return (agent('msie') ? event.clientY + document.body.scrollTop : e.pageY);
}

function starUpdate(e,o,id) { 
	if (($('starUser'+starNum).innerHTML) != 'Rating recorded!') {
	var v=parseInt($('starUser'+starNum).innerHTML); 
	starNum=o.id.substr(4);
	$('starCurr'+starNum).title=v; 
	req=GetXmlHttpObject(); 
	req.open('GET','set-rating.asp?id='+id+'&rating='+v,true); 
	req.onreadystatechange=updatePage;
	req.send(null); 
	}
}

function updatePage() {
  if (req.readyState == 4) {
    var response = req.responseText;
	// Update the page with the result from the server
    $('starUser'+starNum).innerHTML = 'Rating recorded!';
	$('rating'+starNum).innerHTML = response+'%';
	// Nullify the mousemove and mousedown handlers - beware - does this has side effects for the rest of the page? 
	document.onmousemove='';
  }
}

function starRevert() { 
	var value=parseInt($('starCurr'+starNum).title); 
	$S('starCurr'+starNum).width = Math.round( value * 84/100 ) + 'px'; 
	$('starUser'+starNum).innerHTML = (value > 0 ? Math.round(value) + '%' : ''); 
	$('starUser'+starNum).style.color = '#888'; 
	document.onmousemove=''; 
}

// When the page loads, set the star value
function starLoad(value){
	$S('starCurr'+starNum).width = Math.round( value * 84/100 ) + 'px'; 
}

function starCurr(e,o) {
	if (($('starUser'+starNum).innerHTML) != 'Rating recorded!') {

	function starMove(e) { 
		var p=absPos($('star'+starNum)); 
		starNum=o.id.substr(4);

		var eventX=getXPos(e)-p.x;
		var eventY=getYPos(e)-p.y;		
		
		if (eventX < 1 || eventX > 84 || eventY < 0 || eventY > 19) { 
			starGo=''; 
			starRevert(); 
		} 
		else { 
			$S('starCurr'+starNum).width=eventX+'px'; 
			$S('starUser'+starNum).color='#111'; 
			$('starUser'+starNum).innerHTML=Math.round(eventX/84*100)+'%'; 
		}
		
	}

	if (!starGo) { 
		starGo=1; 
		document.onmousemove=starMove; 
	}
	}
}

