﻿	function updateSurveyResults(data)
	{
		eval(data);
		
		var html = "";
		var totalVotes = 0;
		
		for (var i = 0; i < results.length; i++)
		{
			totalVotes += results[i].votes;
			html = "<table><tr><td>";
			html += '<table cellspacing="0" cellpadding="0" border="0">';
			html += '	<tr>';
			html += '		<td width="2" align="left">';
			html += '			<img width="2" height="10" src="/images/survey_' + results[i].color + '_r.gif" /></td>';
			html += '		<td background="/images/survey_' + results[i].color + '_middle.gif" align="center" width="' + results[i].percent +'">';
			html += '		</td>';
			html += '		<td width="2" align="right">';
			html += '			<img width="2" height="10" src="/images/survey_' + results[i].color + '_l.gif" /></td>';
			html += '	</tr>';
			html += '</table>';
			html += '</td><td>';
			html += '		<span style="font-size: 10px; color: #ffffff; ">';
			html += '			' + results[i].percent + '%</span>';
			html += "</td></tr></table>";

			document.getElementById('surveyResults' + (i + 1)).innerHTML = html;
		}
		
		html = 'סה"כ מצביעים: ' + totalVotes
		document.getElementById('surveyResultsTotalVotes').innerHTML = html;


	}
	
	function showSurveyResults()
	{ 
		document.getElementById('surveyResults').style.display = '';
	}
	function showSurveyVoting()
	{ 
		document.getElementById('surveyVoting').style.display = '';
	}
	function hideSurveyResults()
	{ 
		document.getElementById('surveyResults').style.display = 'none';
	}
	function hideSurveyVoting()
	{ 
		document.getElementById('surveyVoting').style.display = 'none';
	}

	function surveyVote()
	{
		var id = document.getElementById('voteForm').id.value;
		
		var arr = document.getElementsByName('answer');
		
		var answer = 0;
		for (var i = 0; i < arr.length; i++)
		{
			if (arr[i].checked)
			{
				answer = i + 1;
			}
		}
		
		if (answer == 0)
		{ 
			alert('יש לבחור באחת האפשרויות');
		}
		else if (getCookie('survey_' + id) == null)
		{
			setCookie('survey_' + id, 'true', 7);
			document.getElementById('voteForm').answer.value = answer;
			document.getElementById('voteForm').submit();
		}
		else
			alert("ניתן להצביע רק פעם אחת");
	}