﻿
function ShowSuccessMsg()
{
// To make sure receiving response data from server is completed
	if(XMLHTTP.readyState == 4)
{
//Valid Response is received
if(XMLHTTP.status == 200)
{
//success show hide here
document.getElementById("divOptions").className="displayNone"
document.getElementById("chartcont").className=""
__doPostBack('',document.getElementById("ctl00_cphMainContent_Poll1_frvPoll_txtPollResult").value+"|"+ document.getElementById("ctl00_cphMainContent_Poll1_frvPoll_txtPollQuestionaireId").value); 

}
else //something is wrong 
{
alert('Error has occured')
}
}
}
 
function CreateXMLHTTP()
{	
try	
{		
XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");	
}	
catch(e)	
{		
try		
{			
XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");		
} 		
catch(oc)		
{			
XMLHTTP = null;		
}	
}	//Creating object in Mozilla and Safari 	
if(!XMLHTTP && typeof XMLHttpRequest != "undefined") 	
{		XMLHTTP = new XMLHttpRequest();	
}
} 

function GetResults(id) 
{
var options = document.getElementsByTagName('input');
var arrayOfCheckBoxLabels= document.getElementsByTagName("label");
            
var err = "1";

for(i=0;i<options.length;i++)
{
var opt = options[i];
//alert(opt.id)
if(opt.checked)
{

document.getElementById("ctl00_cphMainContent_Poll1_frvPoll_txtPollResult").value = opt.value; 

 err="0"
} 
} 

if(err=="1")
{
alert('Please choose a Poll option');
}

if(err=="0")
{
//ajax call
 var requestUrl ="../AjaxCalls.aspx?action=RegitsterPollVote&PollResult=" + escape(document.getElementById("ctl00_cphMainContent_Poll1_frvPoll_txtPollResult").value) + "&QuestionaireId="+ document.getElementById("ctl00_cphMainContent_Poll1_frvPoll_txtPollQuestionaireId").value;


CreateXMLHTTP();	
// If browser supports XMLHTTPRequest object	
if(XMLHTTP)	
{	
//Setting the event handler for the response	

XMLHTTP.onreadystatechange = ShowSuccessMsg;	
	//Initializes the request object with GET (METHOD of posting), 		
	//Request URL and sets the request as asynchronous.		
	
	XMLHTTP.open("GET", requestUrl, true);		
	//Sends the request to server		
	XMLHTTP.send(null); 
}
}
}
