var xmlHttp = createXmlHttpRequestObject(); 

function createXmlHttpRequestObject() 
{	
  var xmlHttp;
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}


function showres(id)
{
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    var url = 'index-ajax.php';
	var params = 'q=assets/snippets/poll/snip.php&res=' + id;

	xmlHttp.open("GET", url+"?"+params, true);  
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  }
  else
    setTimeout('showres(id)', 1000);
}


function vote(poll_id)
{
 var theGroup = document.poll_1.varp;
 for (i=0; i< theGroup.length; i++) {
     if (theGroup[i].checked) {
	 var varp1 = theGroup[i].value;
	// alert(varp1);
	 }
     }

  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    var url = 'index-ajax.php';
	var params = '?q=assets/snippets/poll/snip.php&poll_id='+poll_id+"&varp="+varp1;
		xmlHttp.open("GET", url+params, true);  
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  }
  else
    setTimeout('vote(id)', 1000);
}





function handleServerResponse() 
{
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200) 
    {
      Response = xmlHttp.responseText;
      document.getElementById("divMessage").innerHTML = 
                                            Response;
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}




