var selectedChoice;
var animDiv;
var opacityValue;

function selectChoice(id)
{
	selectedChoice = id;
}

function getXmlHttpObject()
{
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return false;
			}
		}
	}
	return xmlHttp;
}
function addVote()
{
	pollId = document.getElementById("pollId");
	pollId = pollId.value;
	if(selectedChoice && pollId) {
		xmlHttp = getXmlHttpObject();
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState==4) {
				readPollAjax();
			}
		}
		button = document.getElementById("vote");
		button.style.display = 'none';
		rnd = Math.random ( ) * 1000000;
		xmlHttp.open("GET", pollBaseUrl+"/index.php?op=addVote&choice="+selectedChoice+"&pollId="+pollId+"&r="+rnd, true);
		xmlHttp.send(null);
	}
}

function readPollAjax()
{
	xmlHttp = getXmlHttpObject();
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState==4) {
			div = document.getElementById("crystalPoll");
			div.innerHTML = xmlHttp.responseText;
		}
	}
	rnd = Math.random ( ) * 1000000;
	xmlHttp.open("GET", pollBaseUrl+"/index.php?op=readPoll&rr="+rnd, true);
	xmlHttp.send(null);
}
