/************************************************************************************************************
	@fileoverview
	This file provides functions related to polls functionality.

************************************************************************************************************/

var pollResponseBeingProcessed = -1;
var pollResponseAction = "";

/* ======= AJAX methods ======= */
function processPollResponse_SendRequest(action, pollId, pollOption, pollComment, verify) {
	//alert("Send Request [" + pollId + "], action=[" + action + "]");

	if (pollId==null || pollOption==null) {
		alert("Please select one from the available options and then submit your response.");
		return false;
	}
	
	if (pollResponseBeingProcessed != -1) {
		alert("The system has already saved your response.");
		return false;
	}
	
	document.getElementById("div_process_pollResponse_response_" + pollId).innerHTML = "<font style='color:blue;'>Please wait..</font>";
	
	makeAjaxRequest("poll-response-submit.html", "action=" + action + "&pollId=" + pollId 
		+ "&pollOption=" + pollOption + "&pollComment=" + pollComment + "&verify=" + urlEncode(verify), 
		processPollResponse_ResponseReceived_Success,
		processPollResponse_ResponseReceived_Error);

	pollResponseBeingProcessed = pollId;
	pollResponseAction = action;
}

function processPollResponse_ResponseReceived_Success(response) {
	//alert("Response Received = Success: [" + response + "]");

	document.getElementById("div_process_pollResponse_response_" + pollResponseBeingProcessed).innerHTML = response;
	//document.getElementById("cmd_submit_pollResponse").style.display = 'none';

	//pollResponseBeingProcessed = -1; -- commented to avoid multiple responses submitted in a row..
	pollResponseAction = "";
}

function processPollResponse_ResponseReceived_Error() {
	//alert("Response Received = Error: [" + response + "]");

	document.getElementById("div_process_pollResponse_response_" + pollResponseBeingProcessed).innerHTML = "<font style='color:red;'>"
							+ "There was an error in processing your response." 
							+ "<br/>Please <a href='javascript: window.location.reload();'>reload</a> this page and try again</font>";
	//document.getElementById("cmd_submit_pollResponse").style.display = 'none';
	
	//pollResponseBeingProcessed = -1;  -- commented to avoid multiple responses submitted in a row..
	pollResponseAction = "";
}
/* ======= AJAX methods ======= */