var one_poll_Master = {
	/**
	 * Processes the poll vote in a way which will work from an iframe.
	 * 
	 * @param string container The poll container to update
	 * 
	 * @return void
	 */
	sendIframeVote : function (container)
	{
		var voteForm = YAHOO.util.Dom.getElementsByClassName(
			"pollVoteForm",
			"form",
			container
		);
		
		voteForm = voteForm[0];
		
		var params = '&display=1&vote=1';
		
		// Gather up the form arguments.
		for (var i=0; i<voteForm.elements.length; i++) {
			switch (voteForm.elements[i].type) {
				case "hidden":
					break;
				case "text":
					break;
				case "checkbox":
					if (!voteForm.elements[i].checked) {
						continue;
					}
					break;
				case "radio":
					if (!voteForm.elements[i].checked) {
						continue;
					}
					break;
				default:
					continue;
			}
			
			params += "&"+voteForm.elements[i].name + "=";
			params += voteForm.elements[i].value;
		}
		
		YAHOO.util.Connect.asyncRequest(
			'POST',
			'/iframes/poll_iframe.one',
			{
				success  : this.displayResults,
				argument : {"container": container}
			},
			params
		);
	},
	/**
	 * Processes a poll vote form and submits it using AJAX.
	 * 
	 * @param string container  the poll container to update
	 * @param int    width      The width to display the results
	 * @param int    height     The height to display the results
	 * 
	 * @return void
	 */
	sendVote : function(container, width, height)
	{
		var voteForm = YAHOO.util.Dom.getElementsByClassName("pollVoteForm", "form", container);
		voteForm = voteForm[0];
		
		var params = 'action=logPollVote&responseFormat=json&requestType=class';
		params += '&handlerName=one_ajax_poll_handler&display=1&heavyAjax=1';
		
		if (width) {
			params += '&width=' + width;
		}
		
		if (height) {
			params += '&height=' + height;
		}
		
		// Gather up the form arguments.
		for (var i=0; i<voteForm.elements.length; i++) {
			switch (voteForm.elements[i].type) {
				case "hidden":
					break;
				case "text":
					break;
				case "checkbox":
					if (!voteForm.elements[i].checked) {
						continue;
					}
					break;
				case "radio":
					if (!voteForm.elements[i].checked) {
						continue;
					}
					break;
				default:
					continue;
			}
			
			params += "&"+voteForm.elements[i].name + "=" + voteForm.elements[i].value;
		}
		
		YAHOO.util.Connect.asyncRequest(
			'POST',
			'/resources/ajax/_router.one',
			{
				success  : this.displayResults,
				argument : {"container": container}
			},
			params
		);
	},
	
	/**
	 * Method to handle a successful AJAX request. Replaces poll div's innerHTML
	 * with the request response.
	 * 
	 * @param o  the request response
	 */
	displayResults : function(o)
	{
		var results = YAHOO.lang.JSON.parse(o.responseText);
		
		YAHOO.util.Dom.get(o.argument['container']).innerHTML = results.msg;
		
		if (results.script) {
			eval(results.script);
		}
	},
	
	init : function(poll_id)
	{
		var params = 'action=displayPoll&responseFormat=json&requestType=class';
		params += '&handlerName=one_ajax_poll_handler&display=1&heavyAjax=1';
		params += '&poll_id=' + poll_id;
		
		YAHOO.util.Connect.asyncRequest(
			'POST',
			'/resources/ajax/_router.one',
			{
				success : one_poll_Master.display,
				failure : function(o) {},
				argument : {"poll_id" : poll_id}
			},
			params
		);
	},
	
	display : function (o)
	{
		var results = YAHOO.lang.JSON.parse(o.responseText);
		var dom = YAHOO.util.Dom.get('pollWrapper_' + o.argument['poll_id']);
		
		if (!dom) {
			return;
		}
		
		dom.innerHTML = results.buffer;
		
		if (results.script) {
			eval(results.script);
		}
	}
}