// JavaScript Document
var xmlHttp;
var grating = 0;
var currentrating = 0;

function rate(rating, id)
{ 	 
	grating = rating;	
	currentrating = id;
	var url="updaterating.php?sid=" + Math.random() + "&id=" + id + "&rating=" + rating;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);	
} 
function stateChanged() 
{ 
	/*if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//document.getElementById("txtHint").innerHTML=""
		if (xmlHttp.responseText == "1") {
			document.getElementById("imageBox"+boxnum).style.borderColor = "#b8e1b8";
			document.getElementById("imageBox"+boxnum).style.backgroundColor = "#efffef";
			//change picture to remove picture
			document.images["imgaction"+boxnum].src="bin/btn/redremove.gif"
		}
		if (xmlHttp.responseText == "-1") {
			document.getElementById("imageBox"+boxnum).style.borderColor = "#d4d4d4";
			document.getElementById("imageBox"+boxnum).style.backgroundColor = "#ffffff";
			//change to add picture
			document.images["imgaction"+boxnum].src="bin/btn/addtogroup.gif"
		}
	} */
	var newgrating = parseInt(grating) * 16;
	if (xmlHttp.responseText != 3) {
		document.getElementById('rating'+currentrating).style.width = newgrating+'px';	
		
		if (xmlHttp.responseText != 2) {
			var votes = document.getElementById('votes'+currentrating);
			var newvotes = document.createTextNode(parseInt(votes.innerHTML) + 1);
			
			if (parseInt(votes.innerHTML) == 0) {
				var rtext = document.getElementById('rtext'+currentrating);
				var rtextnew = document.createTextNode("Rating");

				rtext.removeChild(rtext.lastChild);							
				rtext.appendChild(rtextnew);
				
				delete rtext;
				delete rtextnew;
			}

			votes.removeChild(votes.lastChild);							
			votes.appendChild(newvotes);
			
			delete votes;
			delete newvotes;
		}
		
	} else {
		alert('You must login to rate alert services!');
		window.location = 'login.php' + returnLink;
	}
} 

function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("You must use Internet Explorer or Firefox") 
		return 
	}
	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
	}
} 
