/**************************************************************************************
(C) www.dhtmlgoodies.com, March 2006

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland
****************************************************************************************/
	var txt_totalVotes = 'Total votes: ';

	var pollVotes = new Array();
	var pollVoteCounted = new Array();
	var totalVotes = new Array();

	function vote(pollId)
	{
		var myGlobalHandlers = {
			onCreate: function()
			{
				Form.disable('pollForm'+pollId);
			},
			onComplete: function()
			{
				if(Ajax.activeRequestCount == 0)
				{
					Form.enable('pollForm'+pollId);
				}
			}
		};
		Ajax.Responders.register(myGlobalHandlers);

		var params = Form.serialize($('pollForm'+pollId));
		var url = 'inc.vote.php';
		new Ajax.Request(
			url, 
			{
				asynchronous: true, 
				parameters: params,
				onComplete: showVoteResults,
				onFailure: reportError				
			});
	}
	
	function view(pollId)
	{
		var myGlobalHandlers = {
			onCreate: function()
			{
				Form.disable('pollForm'+pollId);
			},
			onComplete: function()
			{
				if(Ajax.activeRequestCount == 0)
				{
					Form.enable('pollForm'+pollId);
				}
			}
		};
		Ajax.Responders.register(myGlobalHandlers);

	 	var params = 'pollId='+pollId;
		var url = 'inc.vote.php';	 
		new Ajax.Request(
			url,
			{
				asynchronous: true,
				parameters: params,
				onComplete: showVoteResults,
				onFailure: reportError
			}); 
	}

	function showResponse(req)
	{
		showVoteResults(req);
	}

	function reportError(req)
	{
		alert('Sorry. There was an error.');
	}
	
	function showVoteResults(req)
	{
		var xml = req.responseText;

		var reg = new RegExp("^.*?<pollId>(.*?)<.*$","gi");
		var pollId = xml.replace(reg,'$1');

		preparePollResults(pollId);
		$('pollResults'+pollId).innerHTML = xml;
	}
		
	function preparePollResults(pollId)
	{
		document.getElementById('pollResults'+pollId).style.display='block';
		document.getElementById('pollArea'+pollId).style.display='none';	
	}

	function backToPoll(pollId)
	{
		document.getElementById('pollResults'+pollId).style.display='none';
		document.getElementById('pollArea'+pollId).style.display='block';	
	}