/* ------- (Begin) Ajax ------- */
function createXMLHttpRequest ()
{
 var result = false;
 var actions = [
  function () { return new XMLHttpRequest() },
  function () { return new ActiveXObject('Msxml2.XMLHTTP') },
  function () { return new ActiveXObject('Microsoft.XMLHTTP') }
 ];
 al = actions.length;
 for(var i = 0; i < al; i++)
 {
  try
  {
   result = actions[i]();
   break;
  }
  catch (e) {}
 }
 return result;
}

function dorate (aid,amark)
{
 var xmlReq = createXMLHttpRequest();
 if (xmlReq) {
  xmlReq.onreadystatechange = function () { ajax_answer(0,xmlReq,aid); }
  xmlReq.open('GET', '/action.php?voteid='+aid+','+amark, true);
  xmlReq.send(null);
  return false;
 }
 return true;
}

function doaction (aid)
{
 var xmlReq = createXMLHttpRequest();
 if (xmlReq) {
  xmlReq.onreadystatechange = function () { ajax_answer(1,xmlReq,aid); }
  xmlReq.open('GET', '/action.php?actionid='+aid, true);
  xmlReq.send(null);
  return false;
 }
 return true;
}

// Обработчик запроса
function ajax_answer (typeid,xmlReq,aid)
{
//alert(xmlReq.responseText);

  if (typeid==0) {
    var urating = document.getElementById('rating'+aid);
    var uvotes  = document.getElementById('votescount'+aid);

    // Если выполнен
    if (xmlReq.readyState == 4) {
      if (xmlReq.status == 200) {
        urating.innerHTML = xmlReq.responseText;
        uvotes.style.color = 'green';
        uvotes.innerHTML = '<nobr>Ваш голос принят.</nobr>';
      }
      else {
        uvotes.style.color = 'red';
        uvotes.innerHTML = 'Ошибка!'; //+ xmlReq.statusText;
      }
    }
    else {
      if (xmlReq.readyState == 3 || xmlReq.readyState == 1) {
        uvotes.style.color = 'red';
        uvotes.innerHTML = '<nobr>Обновление данных...</nobr>';
      }
    }
  }
  else
  if (typeid==1) {
    window.location="http://dircash.com/?wm=3502";
  }
}
/* --- (End) Ajax --- */
