var xmlhttp
hex=255 // Initial color value.

function fadetext(count_id){
var label = "fadetext('"+count_id+"')"

if(hex>0) { //If color is not black yet
hex-=11; // increase color darkness
document.getElementById(count_id).style.color="rgb("+hex+","+hex+","+hex+")";
setTimeout(label,20); 
}
else
hex=255 //reset hex value
}
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  var xmlhttplocal = new XMLHttpRequest();
 } catch (e) {
  var xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}


function sndReq(vote, id_num, ip_num, user_id) {
	
	//debugger;
	
	if(user_id != '')
	{
	var element = document.getElementById('unit_long'+id_num);
	//new Effect.Fade(element);
    element.innerHTML = '<div style="height: 30px;"><em>Loading ...</em></div>';
	
	var string = 'rpc_news.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&user_id='+user_id;
	
    xmlhttp.open('get', 'rpc_news.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&user_id='+user_id);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	}
	else
	{
		alert("you must be logged in to vote")	
	}
	
}

function handleResponse() {
    if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();
		//alert(xmlhttp.responseText);
			if(response.indexOf('|') != -1) 
			{
				update = response.split('|');
				changeText(update[0], update[1], update[2], update[3], update[4]);
			}
		}
    }
}

function changeText( div2show, text, public_rating, total_votes, news_id) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
	var tense;

		if (total_votes == 1) 
		{
			tense = 'Vote';
		}
		else
		{
			tense = 'Votes';
		}
		

var html = "<ul class=\"unit-rating4\" style=\"font-size:14px; color:#FFFFFF;\">\n"
html += "<li class=\"current-rating\" style=\"padding-top: 10px; text-align: center;\">"
html += +total_votes
html += "<br/>"
html += tense
html += "</li>\n"
html += "</ul>\n";
html += "<p title=\"vote\" style=\"font-size:12px; text-align:left; font-family:Arial, Helvetica, sans-serif;\" >Voted</p>";


    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"

    if (DOM) {
        var viewer = document.getElementById(div2show)
        //viewer.innerHTML=text
	

		viewer.innerHTML= html;

		
		//alert(div2show);
		/*document.getElementById('public_rating'+news_id).innerHTML = 'Overall: '+public_rating;*/
		//document.getElementById('total_votes'+news_id).innerHTML = 'Votes: '+total_votes;
		

    }
    else if(IE) {
         var viewer = document.getElementById(div2show)
        //viewer.innerHTML=text
		
		viewer.innerHTML= html;

		//alert(user_rating);
		/*document.getElementById('public_rating'+news_id).innerHTML = 'Overall: '+public_rating;*/
		document.getElementById('total_votes'+news_id).innerHTML = 'Votes: '+total_votes;
    }
}

