function EnterPollChoice(pollId, resultXslSheet) {

	var ver;	
	// set the cookie 
	SetCookie('poll_' + pollId, 'yes', 365, '/', '');

	// post an answer
	ver = PostPollAnswer(pollId);

	// show the results
	ShowResults(ver, resultXslSheet, pollId);
	
	GetElement('poll_result_' + pollId).style.display = 'block';
	if(GetElement('poll_question_' + pollId).style.display == 'block')
		GetElement('poll_question_' + pollId).style.display = 'none';
}

function PostPollAnswer(pollId) {

	var ver = 0;
	var req = false;
	
	// this is only done in IE:
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
		req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			ver = 1;
			}
			catch (e2){
			req = false;
			}
		}
	@end
	@*/
	
	// otherwise mozilla:
	if (!req && typeof XMLHttpRequest != 'undefined') {
		req = new XMLHttpRequest();
		ver = 2;
	}
	
	// get the answer id
	var answerId = GetSelectedRadioValue(document.forms['frmPoll' + pollId].radChoice);

	
	if (answerId > 0)
	{
		//alert("pollId=" + pollId + ", answer=" + answerId);
		// send the post to the web service
		req.open("POST", "/poll_service/Poll.asmx/SubmitChoice", false);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send("pollId=" + pollId + "&answer=" + answerId);
	}
	
	return ver;

}

function ShowResults(ver, resultXslSheet, pollId) {
	if (ver == 0 || ver == 1)
	{
		if (ver == 0)
			GetResultsIe(new ActiveXObject("Microsoft.XMLDOM"), new ActiveXObject("Microsoft.XMLDOM"), resultXslSheet, pollId);
		else
			GetResultsIe(new ActiveXObject("Microsoft.XMLDOM"), new ActiveXObject("Microsoft.XMLDOM"), resultXslSheet, pollId);
	}
	else
	{
		GetResultsMoz(resultXslSheet, pollId);
	}
}

function GetResultsIe(xmlDom, xslDom, resultXslSheet, pollId)
{
	// Load XML 
	xmlDom.async = false;
	xmlDom.load("/poll_service/PollResults.aspx?pollid=" + pollId);

	// Load XSL
	xslDom.async = false;
	xslDom.load(resultXslSheet);

	// Transform
	GetElement('poll_result_' + pollId).innerHTML = xmlDom.transformNode(xslDom);
}

function GetResultsMoz(resultXslSheet, pollId) {
	try{
		var xslStylesheet;
		var xsltProcessor = new XSLTProcessor();   
		var xmlDoc;

		// load the xslt file
		var xslRequest = new XMLHttpRequest();
		xslRequest.open("GET", resultXslSheet, false);
		xslRequest.send(null);

		xslStylesheet = xslRequest.responseXML;
		xsltProcessor.importStylesheet(xslStylesheet);

		// load the xml file
		xmlRequest = new XMLHttpRequest();
		xmlRequest.open("GET", "/poll_service/PollResults.aspx?pollid=" + pollId, false);
		xmlRequest.send(null);

		xmlDoc = xmlRequest.responseXML;

		var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
		GetElement('poll_result_' + pollId).innerHTML = "";
		GetElement('poll_result_' + pollId).appendChild(fragment);
	}
	catch(e){
	}
}
