﻿
function vote()
{
	document.getElementById('divView').removeChild(document.getElementById('buttons'));
	
	var radios = document.getElementById('divView').getElementsByTagName('input');
	
	for(i = 0; i < radios.length; i++)
	{
		if(radios[i].checked == true)
		{
			pollWork(radios[i].value);
		}
	}
}

function showResults()
{
	document.getElementById('divView').removeChild(document.getElementById('buttons'));
	pollWork('result');
}

function voteDeny()
{
	alert("You must be logged in to vote.");
}

function pollWork(arg)
{
	xmlHttp=GetXmlHttpObject2();
	
	if(xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url = "processing/pollViewAJAX.php";
	url = url + "?function=" + arg;
	url = url + "&sid=" + Math.random();

	xmlHttp.onreadystatechange=stateHasChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateHasChanged2()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById('pollDisplay').style.marginLeft = '5px';
		document.getElementById('pollDisplay').innerHTML=xmlHttp.responseText;
	} 
}

function GetXmlHttpObject2()
{
	var xmlHttp=null;
	
	try
	{
		// Firefox, Opera 8.0+, Safari
		
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}