function showErg(pollid) {
	var pollAnswerVal = $('input:radio[name=pollAnswerID]:checked').val();//Getting the value of a selected radio element.
	if ($('input:radio[name=pollAnswerID]:checked').length) {
		$.ajax({  
			type: "POST",  
			url: "/poll/inc/functions.php",  
			data: { pollAnswerID: pollAnswerVal, action: "vote" },
			success: function(theResponse) { 
				//the functions.php returns a response like "1|13|#ffcc00-2|32|#00ff00-3|18|#cc0000-63" which the first number is the answerID, second is the points it has and third is the color for that answer's graph. The last number is the sum of all points for easilt calculating percentages.
				if (theResponse == "voted") { 
					$("#pollMessage").html("Sie haben schon abgestimmt!");
				} else {
					var numberOfAnswers 		= (theResponse).split("-").length-2;//calculate the number of answers
					var splittedResponse 		= (theResponse).split("-");
					var pollAnswerTotalPoints 	= splittedResponse[numberOfAnswers+1];

					for (i=0;i<=numberOfAnswers;i++)
					{
						var splittedAnswer 		= (splittedResponse[i]).split("|");
						var pollAnswerID 		= (splittedAnswer[0]);
						var pollAnswerPoints 	= (splittedAnswer[1]);
						var pollAnswerColor 	= (splittedAnswer[2]);
						var pollPercentage		= (100 * pollAnswerPoints / pollAnswerTotalPoints);
						$(".pollChart" + pollAnswerID).css("background-color",pollAnswerColor);
						$(".pollChart" + pollAnswerID).animate({width:pollPercentage + "%"});
						$("#pollAnswer" + pollAnswerID).html("<br>(" + Math.round(pollPercentage,2) + "% - " + pollAnswerPoints + " Stimmen)");
						$("#pollRadioButton" + pollAnswerID).attr("disabled", "disabled"); //disable the radio buttons
					}
					$("#pollSubmit").hide();
					$("#pollResults").hide();
					$("#pollShow").show();
					$("#pollMessage").html("&nbsp;");
				}
			}  
		});  
		return false; 


	
	} else {
		$("#pollMessage").html("Bitte eine Antwort auswählen.");
		return false;
	}

}

function showResults(pollid) {

	$.ajax({  
		type: "POST",  
		url: "/poll/inc/functions.php",  
		data: { action: "results", pollid: pollid },
		success: function(theResponse) { 
			//the functions.php returns a response like "1|13|#ffcc00-2|32|#00ff00-3|18|#cc0000-63" which the first number is the answerID, second is the points it has and third is the color for that answer's graph. The last number is the sum of all points for easilt calculating percentages.
				var numberOfAnswers 		= (theResponse).split("-").length-2;//calculate the number of answers
				var splittedResponse 		= (theResponse).split("-");
				var pollAnswerTotalPoints 	= splittedResponse[numberOfAnswers+1];

				for (i=0;i<=numberOfAnswers;i++)
				{
					var splittedAnswer 		= (splittedResponse[i]).split("|");
					var pollAnswerID 		= (splittedAnswer[0]);
					var pollAnswerPoints 	= (splittedAnswer[1]);			
					var pollAnswerColor 	= (splittedAnswer[2]);
					var pollPercentage		= (100 * pollAnswerPoints / pollAnswerTotalPoints);

					pollPercentage = Math.round(pollPercentage,2);
					if (isNaN(pollPercentage)) {
						pollPercentage = 0;
					}
					
					$(".pollChart" + pollAnswerID).css("background-color",pollAnswerColor);
					$(".pollChart" + pollAnswerID).animate({width:pollPercentage + "%"});
					$("#pollAnswer" + pollAnswerID).html("<br/>(" + pollPercentage + "% - " + pollAnswerPoints + " Stimmen)");
					$("#pollRadioButton" + pollAnswerID).attr("disabled", "disabled"); //disable the radio buttons
				}
				$("#pollSubmit").hide();
				$("#pollResults").hide();
				$("#pollShow").show();
				$("#pollMessage").html("&nbsp;");
		}  
	});  
	return false; 

}

function showPoll(pollid) {

	$.ajax({  
		type: "POST",  
		url: "/poll/inc/functions.php",  
		data: { action: "show" , pollid: pollid },
		success: function(theResponse) { 
			$("#pollWrap").html(theResponse);
			$("#pollShow").hide();
			$("#pollMessage").html("&nbsp;");
		}  
	});  
	return false; 

}
