function set_poll(answers_cnt,url){
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
 
	var poll_id = document.getElementById('poll_id').value;
	i= 1;
	var selected_value = "false";
	
	while (i <= answers_cnt){
		var answer_inputID = 'answer'+i;
		//alert(document.getElementById(answer_inputID).checked)
		if (document.getElementById(answer_inputID).checked){
			selected_value = document.getElementById(answer_inputID).value;
		}
		i++;
	}
	
	var params = "poll_id="+poll_id+"&answers_cnt="+answers_cnt+"&selected_value="+selected_value;
	
	xmlHttp.open("POST",url,true)
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.onreadystatechange=stateChanged_poll
	xmlHttp.send(params)	
}

/*function set_poll(answers_cnt,url){
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
 
	var poll_id = document.getElementById('poll_id').value;
	i= 1;
	var selected_input = "false";
	
	while (i <= answers_cnt){
		var answer_inputID = 'answer'+i;
		//alert(document.getElementById(answer_inputID).checked)
		if (document.getElementById(answer_inputID).checked){
			//alert(i)
			selected_input = "nr"+i;
		}
		i++;
	}
	//alert(selected_input)
	//we need to manually escape the "+" sign because it is interpreted as " "
	//alert(selected_input)
	//if (selected_input){
		var params = "poll_id="+poll_id+"&answers_cnt="+answers_cnt+"&selected_input="+selected_input;
	//}else{
	//	var params = "poll_id="+poll_id+"&answers_cnt="+answers_cnt;
	//}
	//alert(params)
	xmlHttp.open("POST",url,true)
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.onreadystatechange=stateChanged_poll
	xmlHttp.send(params)	
}*/

function stateChanged_poll(){
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		
		str = xmlHttp.responseText;
		//alert(str)
	 	if(document.getElementById("box-poll")) {
			start_poll = str.indexOf('<!--%START_POLL%-->');
			end_poll = str.indexOf('<!--%END_POLL%-->');
			part_poll = str.slice(start_poll, end_poll);
			document.getElementById("box-poll").innerHTML=part_poll;
		}	 
				
	 	document.getElementById("div_poll_loader").style.display = "none";
	 	document.getElementById("div_poll").style.display = "block";
	 	
	 }else{
	 	document.getElementById("div_poll").style.display = "none";
	 	document.getElementById("div_poll_loader").style.display = "block";
	 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
