// JavaScript Document for getting the content for the nav submenu

function pollVote(poll){
	document.getElementById('pollError_success').style.display = 'none';
	document.getElementById('pollError_error').style.display = 'none';
	createAjaxObj();
	var selectedChoice = '';
	var loc = siteRoot;
	loc += 'includes/ajax/processing_scripts/process-poll-vote.php';
	loc += '?action=vote';
	//determine what option was chosen and for what poll
	var pollChoices = document.poll_form.pollAnswers;
	var choiceLength = pollChoices.length;
	for(i=0; i<choiceLength; i++){
		if(pollChoices[i].checked == true){
			selectedChoice = pollChoices[i].value;
			break;
		}
	}
	var pollNbr = document.poll_form.pollNbr.value;
	if(selectedChoice != ''){
		loc += '&choice='+selectedChoice;
		loc += '&pollNbr='+pollNbr;
		request.open("GET",loc);
		request.send(null);
		request.onreadystatechange = function(){
			if(request.readyState == 4 && request.status == 200){
				if(request.responseText == 'success'){
					document.getElementById('pollError_success').style.display = 'block';
					document.getElementById('pollError_error').style.display = 'none';
					setHeight()
					//check to see if the poll was the results page or not
					if(poll == 'ResultsPage'){
						loc = siteRoot;
						loc += 'includes/ajax/processing_scripts/process-poll-vote.php';
						loc += '?update=yes';
						request.open("GET",loc);
						request.send(null);
						request.onreadystatechange = function(){
							if(request.readyState == 4 && request.status == 200){
								document.getElementById('currentPoll_results').innerHTML = request.responseText;
							}
						}
					}					
				}else{
					document.getElementById('pollError_success').style.display = 'none';
					document.getElementById('pollError_error').style.display = 'block';
					setHeight()
				}
			}
		}
	}
}
