
function showBlock(obj)
{
 obj.style.zIndex = 12;
 obj.childNodes.item(1).style.display = 'block';
}
//------------------------------------------
function hideBlock(obj)
{
 obj.style.zIndex = 0;
 obj.childNodes.item(1).style.display = 'none';
}
//---------------------------------------------
function loadPNG(obj)
{
if( obj.runtimeStyle && obj.src.match( /\.png$/ ) ){
                    obj.runtimeStyle.filter
                        = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='
                        + obj.src
                        + ', sizingMethod=scale)';
                   obj.src = '/0.gif';
                }

}
//----------------------------------------------------------------------
var xmlHttp = createXmlHttpRequest();
var aid = 0,qid_;

function createXmlHttpRequest()
{
var xmlHttp = false;
 if(window.ActiveXObject)
   {
      xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.4.0");
   }
 else xmlHttp = new XMLHttpRequest();

 if (!xmlHttp)  alert("No");
 else return xmlHttp;
}
//--------------------------------------------------
function setAnswer(obj)
{
 aid = obj.value;
}
//--------------------------------------------------
function doVote(qid)
{
if (aid==0)
 {
  alert("Вариант не выбран");
  return false;
 }

qid_ = qid;

if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
   {
     xmlHttp.open("GET","/vote.php?qid="+qid + "&aid=" + aid,true);
     xmlHttp.onreadystatechange = handleVote;
     xmlHttp.send(null);
   }
}
//-----------------------------------------------------------
function handleVote()
{
   if (xmlHttp.readyState == 4)
    {
      if (xmlHttp.status==200)
        {
         xmlResponse = xmlHttp.responseText;

         if (xmlResponse=='yes')
               alert("Ваш голос принят");

         if (xmlResponse=='no')
               alert("Вы уже голосовали в данном опросе");
         
        showResults(qid_);
 
        }
      else alert(xmlHttp.statusText);
    }
}
//------------------------------------------------------
function showResults(qid)
{

if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
   {
     xmlHttp.open("GET","/results.php?qid="+qid,true);
     xmlHttp.onreadystatechange = handleResults;
     xmlHttp.send(null);
   }
}
//-----------------------------------------------------------
function handleResults()
{
   if (xmlHttp.readyState == 4)
    {
      if (xmlHttp.status==200)
        {
         xmlResponse = xmlHttp.responseXML;
         xmlDocumentElement = xmlResponse.documentElement;

  options = xmlDocumentElement.firstChild.getElementsByTagName('options');


list = "";

 for(i=0;i<options.length;i++)
  {
    optval = options.item(i).getElementsByTagName('opval').item(0).firstChild.data;
    opttxt = options.item(i).getElementsByTagName('optxt').item(0).firstChild.data;
    list+="<p>" + optval + " - " + opttxt + "</p>";
  }



  

        document.getElementById('votetopdiv').innerHTML = list; 

        }
      else alert(xmlHttp.statusText);
    }
}