
var voteurl = "voteit.php"; // The server-side script

function handleHttpResponse() {

  if (http.readyState == 4) {
    results = http.responseText.split("|");
    id = results[0];
    votes = results[1];
    type = results[2];
    message = results[3];

    if (id+0)
    {
      if (votes)
      { 
        curr=votes;
        if (curr>0)
        { curr='<font color="#007700">+' + curr + '</font>';}
        else if (curr<0)
        { curr='<font color="#770000">' + curr + '</font>';}
        else
        { curr='<font color="#007700">+' + curr + '</font>';}

        document.getElementById('v' + id).innerHTML = curr;
      }
      document.getElementById('m' + id).innerHTML = message;

      // Set cookie to avoid voting twice
      var cookieName = 'votes';
      votes=readCookie('votes');

      if (!votes) { votes='--';}
      if (votes.length>3900)
      { votes=votes.substring(3500); }

      var cookieValue = votes + type + id + type;
      var today = new Date();
      var expire = new Date();
      var nDays=7;
      expire.setTime(today.getTime() + 3600000*24*nDays);
      document.cookie = cookieName+'='+escape(cookieValue) + ';expires='+expire.toGMTString() +';path=/';
      //alert(votes);

    }
  }

}

function prate(id,type,curr)
{
  if (curr>0)
  { curr='<font color="#007700">+' + curr + '</font>';}
  else if (curr<0)
  { curr='<font color="#770000">' + curr + '</font>';}
  else
  { curr='';}

  votes=readCookie('votes');
  if (!votes) {votes='';}


  if (votes.indexOf(type+id+type)<=0)
  {
    // votestr=' <a href="javascript:void(0);" onclick="voteit('+id+',1);"><img width=14 id="u'+id+'" border=0 src="basis/up.png"></a> <a href="javascript:void(0);" onclick="voteit('+id+',0);"><img width=14 id="d'+id+'" border=0 src="basis/down.png"></a> '; 
    votestr=' <a href="javascript:void(0);" onclick="voteit('+id+',1,\''+type+'\');"><img width=14 id="u'+id+'" border=0 src="basis/up.png"></a> '; 
  }
  else
  {
   // votestr=' <img width=14 id="u'+id+'" border=0 src="basis/up0.png"> <img width=14 id="d'+id+'" border=0 src="basis/down0.png"> '; 
    votestr=' <img width=14 id="u'+id+'" border=0 src="basis/up0.png"> '; 
  }

  var printit= votestr + ' <span class="voted" id="v'+id+'">'+curr+'</span><span class="vmessage" id="m'+id+'"></span>';
  document.write(printit);
}


function voteit(id,state,type) {
  document.getElementById('u' + id).src = "basis/up0.png";
  // document.getElementById('d' + id).src = "basis/down0.png";
  http.open("GET", voteurl + '?id=' + id + '&t=' + type, true); 
  http.onreadystatechange = handleHttpResponse; 
  http.send(null);
}


function getHTTPObject() {
  var xmlhttp;
  /*@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;
    }
  }
  return xmlhttp;
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


var http = getHTTPObject(); // We create the HTTP Object

// Set initial cookie
     var cookieName = 'voting';
     var cookieValue = 'voting';
     var today = new Date();
     var expire = new Date();
     var nDays=30;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+'='+escape(cookieValue) + ';expires='+expire.toGMTString()+';path=/';

// preload images
tmppic= new Image(14,14); 
tmppic.src="basis/up0.png"; 
//tmppic2= new Image(14,14); 
//tmppic2.src="basis/down0.png"; 

