/*The following function creates an XMLHttpRequest object... */
function PollObject(PollType){

	var OptArr = new Array();
	var request_o; //declare the variable to hold the object.
	var i = 0;
	
	browser = BrowserDetect();
	
	if (browser == "Internet Explorer"){
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		request_o = new XMLHttpRequest();
	}

	function RefreshClient(div_id) {
		if (request_o.readyState == 4)
			document.getElementById(div_id).innerHTML = request_o.responseText;
		else
			document.getElementById(div_id).innerHTML = '<div class="ajax-loading">Verificare...</div>';
	}
	
	this.setResult = function(PollID,val) {
		if (PollType == 'single') {
			i = 0;
			OptArr[i++] = val;
		}
		if (PollType == 'multi') {
			ValFound = false;
			for (key in OptArr) {
				if (OptArr[key] == val) {
					OptArr[key] = null;
					ValFound = true;
				}
			}
			if (ValFound == false)
				OptArr[i++] = val;
		}
		document.getElementById('poll' + PollID).Options.value = OptArr;
	}
	
	this.ShowPoll = function(PollID) {
		request_o.open('get', '/polls/poll_request.php?Action=show-options&PollID=' + PollID + '&PollType=' + PollType);
		request_o.onreadystatechange = function() {RefreshClient('polldiv' + PollID);}
		request_o.send(null);
	}

	this.ViewResults = function(PollID) {
		request_o.open('get', '/polls/poll_request.php?Action=view-results&PollID=' + PollID + '&PollType=' + PollType);
		request_o.onreadystatechange = function() {RefreshClient('polldiv' + PollID);}
		request_o.send(null);
	}

	this.Vote = function(PollID,Options) {
		request_o.open('get', '/polls/poll_request.php?Action=vote&PollID=' + PollID + '&Options=' + Options + '&PollType=' + PollType);
		request_o.onreadystatechange = function() {RefreshClient('polldiv' + PollID);}
		request_o.send(null);
	}
}