var Axmlhttp=new XMLHttpRequest();

function poll()
{
	for (index=0; index < document.frmPoll.Option.length; index++) {
		if (document.frmPoll.Option[index].checked) {
			x = index + 1;
			eval('document.frmPoll.Option_' + x +"_Count.value = 1");	
		}
		else {
			x = index + 1;
			eval('document.frmPoll.Option_' + x +"_Count.value = 0");
		}			
	}
} 

//Get new posts after adding new discussion
function update_poll() {
	Axmlhttp=GetXmlHttpObject();
	if (Axmlhttp==null)  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	
	var op1 = 0;
	var op2 = 0;
	var op3 = 0;
	var op4 = 0;
	var op5 = 0;
	var op6 = 0;
	var op7 = 0;
	var op8 = 0;
	var op9 = 0;
	var op10 = 0;	
	
	if(document.getElementById("Option_1_Count")) {
		op1 = document.getElementById("Option_1_Count").value;
	}
	if(document.getElementById("Option_2_Count")) {
		op2 = document.getElementById("Option_2_Count").value;
	}
	if(document.getElementById("Option_3_Count")) {
		op3 = document.getElementById("Option_3_Count").value;
	}
	if(document.getElementById("Option_4_Count")) {
		op4 = document.getElementById("Option_4_Count").value;
	}
	if(document.getElementById("Option_5_Count")) {
		op5 = document.getElementById("Option_5_Count").value;
	}
	if(document.getElementById("Option_6_Count")) {
		op6 = document.getElementById("Option_6_Count").value;
	}
	if(document.getElementById("Option_7_Count")) {
		op7 = document.getElementById("Option_7_Count").value;
	}
	if(document.getElementById("Option_8_Count")) {
		op8 = document.getElementById("Option_8_Count").value;
	}
	if(document.getElementById("Option_9_Count")) {
		op9 = document.getElementById("Option_9_Count").value;
	}
	if(document.getElementById("Option_10_Count")) {
		op10 = document.getElementById("Option_10_Count").value;
	}
	
	x = document.getElementById('poll_question').height;
	document.getElementById('divVote').innerHTML = '<div align="center"><img src="Assets/loading1.gif" /></div>'; 
	document.getElementById('poll_question').height = x;
	
	var url="code_poll_result.php"; 
	url=url+"?op1="+op1+"&op2="+op2+"&op3="+op3+"&op4="+op4+"&op5="+op5+"&op6="+op6+"&op7="+op7+"&op8="+op8+"&op9="+op9+"&op10="+op10+"&sid="+Math.random();
	Axmlhttp.onreadystatechange=stateChanged_update_poll; 
	Axmlhttp.open("GET",url,true);
	Axmlhttp.send(null);
}

function stateChanged_update_poll() {
	if (Axmlhttp.readyState==4 && Axmlhttp.status == 200)  {
		document.getElementById('poll_result').innerHTML = Axmlhttp.responseText;	
		document.getElementById('poll_question').style.display = 'none';
		document.getElementById('poll_result').style.display = 'table-row';
	} 
}

function GetXmlHttpObject() {
	if (window.XMLHttpRequest)  {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

