/*
 * Public JavaScripts for SefeGallup.
 */

SefeGallup = 
{
	castVote : function(choiceId, locale)
	{
		GallupService.castVote(choiceId, locale, this.refreshGallup);
	},
	
	refreshGallup : function(gallup)
	{
		if (gallup)
		{
			var result = "<h2>" + gallup.question + "</h2>";
			result += "<ol class=\"gallup\" style=\"margin: 0;\">";
			
			var i = 0;
			for (i = 0; i < gallup.choices.length; i++)
			{
				var choice = gallup.choices[i];
				
				result += "<li><p>";
				result += "<img src=\"/pics/contentmanager/bar.gif\" + height=\"12\" width=\"" + choice.width + "\" /> &nbsp; <b>" + choice.percentage + " % &nbsp;</b>";
				result +=  choice.label + "</p></li>";
			}

			result += "</ol>";
			
			dwr.util.setValue("gallup", result, { escapeHtml:false } );
			
			jQuery.cookie(gallup.cookieName, gallup.cookieValue);
		}
	}
};

