function makeRequest() {
  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
     http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml'); // Фиксиране на някои проблеми
        }
  }
  else if (window.ActiveXObject) { // IE
       try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
  }
  if (!http_request) {
     alert('Възникна проблем при създаването на XMLHTTP връзка');
     return false;
  }
  return http_request;
}
function bitAJAX(selid) {
  var http_request = makeRequest();
  var rand_no = Math.random();
  var info = selid;
  var url = 'addfav.php?id=' + info;
  http_request.open('GET', url, true);
  http_request.onreadystatechange = function() { testResponse(http_request,info); };
  http_request.send(null);
}
function vote(selid,vote) {
  var http_request = makeRequest();
  var rand_no = Math.random();
  var info = selid + '&vote=' + vote;
  var url = 'addvote.php?id=' + info;
  http_request.open('GET', url, true);
  http_request.onreadystatechange = function() { testResponse_vote(http_request,selid); };
  http_request.send(null);
}

function testResponse(http_request,info) {
  if (http_request.readyState == 4 || http_request.readyState == 'complete') { // Проверка...
     if (http_request.status == 200) { // Втора проверка...

var selid = 'f' + info;
  var commss = http_request.responseText;
var colord = '#A5F059';
var texts = '+Любими';
if(commss == 2) {
colord = '#ff0000';
texts = '-Любими';
}
  document.getElementById(selid).innerHTML = texts;
  document.getElementById(selid).style.color = colord;



     }
     else {
        alert('Information Problem!');
     }
  }
}




function testResponse_vote(http_request,id) {
  if (http_request.readyState == 4 || http_request.readyState == 'complete') { // Проверка...
     if (http_request.status == 200) { // Втора проверка...

  var comms = http_request.responseText;
if(comms == 1 || comms == 2 || comms == 3 || comms == 4 || comms == 5) {
alert("Вашият глас беше успешно отчетен");
for(i = 1; i <= 5;i++) {
if(comms >= i) {
document.getElementById('star' + id + '_' + i).src="img/star.gif";
document.getElementById('star' + id + '_' + i).setAttribute("onmouseout","glasnormal(" + id + "," + comms + ");");
} else {
document.getElementById('star' + id + '_' + i).src="img/star_gray.gif";
document.getElementById('star' + id + '_' + i).setAttribute("onmouseout","glasnormal(" + id + "," + comms + ");");
}
}
}
if(comms == 6) {
alert("Вие вече сте гласували за този виц!");
}



     }
     else {
        alert('Information Problem!');
     }
  }
}