<!-- 

var xmlDoc;
var xmlDocPoll;

function loadPoll(id)
{
	if (window.ActiveXObject)
	{
		xmlDocPoll=new ActiveXObject("Microsoft.XMLDOM");
		xmlDocPoll.async=false;
		xmlDocPoll.load("poll/poll.xml");

		checkPoll(id);

	}
	else if (document.implementation && document.implementation.createDocument)
	{
		xmlDocPoll=document.implementation.createDocument("","",null);
		xmlDocPoll.load("poll/poll.xml");
		xmlDocPoll.onload=function() {
		removeWhiteSpaceNodes();
		checkPoll(id); 
		}
	}
	else
	{
		alert('XML wordt niet ondersteund');
	}
}

function loadPollResults(id,edition,from,vote)
{
	if (window.ActiveXObject)
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load("poll/"+id+".xml");
		if (from=="checkFile")
		{
			getPollResult(id,edition);
		}
		if (from=="setVote")
		{
			setVote(id,edition,vote);
		}

	}
	else if (document.implementation && document.implementation.createDocument)
	{
		var file = "poll/"+id+".xml";
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.load(file);

		if (from=="checkFile")
		{
			xmlDoc.onload=function() { 
			removeWhiteSpaceNodesVote();
			getPollResult(id,edition); 
			}
		}
		if (from=="setVote")
		{
			xmlDoc.onload=function() {
				removeWhiteSpaceNodesVote();
				setVote(id,edition,vote); 
				}
			}
			
	}
	else
	{
		alert('XML wordt niet ondersteund');
	}
}

function checkCookie()
{
	var checkCookie = navigator.cookieEnabled;
	if (checkCookie == true)
	{
		return checkCookie;
	}
	else
	{ 
		return checkCookie;
	}
}

function checkPoll(id)
{
	var x = xmlDocPoll.getElementsByTagName('poll');
	var edition = "";
	for (i=0;i<x.length;i++)
	{
		if (x[i].attributes[0].value == id &&  x[i].childNodes[0].firstChild.nodeValue == "on")
		 {	
			edition = x[i].attributes[1].value; 
			if (checkCookie() == true)
			{
				getCookie(id,edition);
			}
			else 
			{
				checkFile(id,edition);				
			}
		
		}
	}
}


function getPoll(id,edition)
{
	var x = xmlDocPoll.getElementsByTagName('poll');
	var strPollOutput = "";
	var vote = "";

	for (i=0;i<x.length;i++)
	{
		if (x[i].attributes[0].value == id && x[i].childNodes[0].firstChild.nodeValue == "on")
		{	
			strPollOutput += "<div class=\"vote\">";
			strPollOutput += "<h3><span class=\"no-show\">Mini enquete</span></h3>";
			strPollOutput += "<div class=\"border\">";
			strPollOutput += "<p>";
			strPollOutput += x[i].childNodes[4].firstChild.nodeValue;
			strPollOutput += "</p><br /><table width=\"150px\">";
			for (j=5;j<parseFloat(x[i].childNodes[3].firstChild.nodeValue)+5;j++)
			{
				if (x[i].childNodes[j].firstChild.nodeValue != "")
				{
					vote = j-4;
					strPollOutput += "<tr><td valign=\"top\"><input type=\"radio\" name=\"rdVote\" onMouseUp=\"javascript:checkFile('"+id+"','"+edition+"','setVote','"+vote+"')\"></td>";
					strPollOutput += "<td>"+x[i].childNodes[j].firstChild.nodeValue+"</td></tr>";
				
				}
			}
			strPollOutput += "</table><br/>";
			strPollOutput += "</div>";
			strPollOutput += "</div>";
			strPollOutput += "<br/>&nbsp;";

		   
			document.getElementById('vote').innerHTML = strPollOutput;
			document.getElementById('vote').style.visibility = "visible";
		}
	}
}


function getPollResult(id,edition)
{
	var x = xmlDoc.getElementsByTagName('poll');
	var y = xmlDocPoll.getElementsByTagName('poll');
	var z = "";
	var antwoord1 = 0;
	var antwoord2 = 0;
	var antwoord3 = 0;
	var antwoord4 = 0;
	var antwoord5 = 0;
	var antwoord6 = 0;
	var antwoord7 = 0;
    var totaalStemmen = 0;
	var percentage1 = 0;
	var percentage2 = 0;
	var percentage3 = 0;
	var percentage4 = 0;
	var percentage5 = 0;
	var percentage6 = 0;
	var percentage7 = 0;
	var strPollOutput = "";

	for (i=0;i<x.length;i++)
	{
		if (x[i].attributes[0].nodeValue == id && x[i].attributes[1].nodeValue == edition)
		{
			
			for (j=0;j<x[i].childNodes.length;j++)
			{
				
				for (k=0;k<x[i].childNodes[j].childNodes.length;k++)
				{

					if (x[i].childNodes[j].childNodes[k].nodeName == "value")
					{

						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "1")
						{
							antwoord1 += 1;
						}
						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "2")
						{
							antwoord2 += 1;
						}
						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "3")
						{
							antwoord3 += 1;
						}
						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "4")
						{
							antwoord4 += 1;
						}
						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "5")
						{
							antwoord5 += 1;
						}
						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "6")
						{
							antwoord6 += 1;
						}
						if (x[i].childNodes[j].childNodes[k].firstChild.nodeValue == "7")
						{
							antwoord7 += 1;
						}
					}
				}
			}	
		}
	}
	
	totaalStemmen = antwoord1 + antwoord2 + antwoord3 + antwoord4 + antwoord5 + antwoord6 + antwoord7;	
	percentage1 = Math.round(100/totaalStemmen*antwoord1);
	percentage2 = Math.round(100/totaalStemmen*antwoord2);
	percentage3 = Math.round(100/totaalStemmen*antwoord3);
	percentage4 = Math.round(100/totaalStemmen*antwoord4);
	percentage5 = Math.round(100/totaalStemmen*antwoord5);
	percentage6 = Math.round(100/totaalStemmen*antwoord6);
	percentage7 = Math.round(100/totaalStemmen*antwoord7);

	for (i=0;i<y.length;i++)
	{

		if (y[i].attributes[0].value==id && y[i].attributes[1].value==edition)
		{	
			
			z = parseFloat(y[i].childNodes[3].firstChild.nodeValue);
			strPollOutput += "<div class=\"vote\">";
			strPollOutput += "<h3><span class=\"no-show\">Mini enquete</span></h3>";
			strPollOutput += "<div class=\"border\">";
			strPollOutput += "<p>";
			strPollOutput += y[i].childNodes[4].firstChild.nodeValue;
			strPollOutput += "<br /><br />";
			strPollOutput += "</p><table>";
			if (z>0) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage1*1.1)+"\"> &nbsp; "+percentage1+"%</td></tr>";
			strPollOutput += "<tr><td>";
			strPollOutput += y[i].childNodes[5].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			if (z>1) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage2*1.1)+"\"> &nbsp; "+percentage2+"%</td></tr>";
			strPollOutput += "<tr><td>";
			strPollOutput += y[i].childNodes[6].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			if (z>2) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage3*1.1)+"\"> &nbsp; "+percentage3+"%</td></tr>";
			strPollOutput += "<tr><td>";
			strPollOutput += y[i].childNodes[7].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			if (z>3) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage4*1.1)+"\"> &nbsp; "+percentage4+"%</td></tr>";
			strPollOutput += "<tr><td>";
			strPollOutput += y[i].childNodes[8].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			if (z>4) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage5*1.1)+"\"> &nbsp; "+percentage5+"%</td></tr>";
			strPollOutput += "<tr><td>";
			strPollOutput += y[i].childNodes[9].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			if (z>5) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage6*1.1)+"\"> &nbsp; "+percentage6+"%</td></tr>";
			strPollOutput += "<tr><td>";			
			strPollOutput += y[i].childNodes[10].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			if (z>6) {
			strPollOutput += "<tr><td valign=\"top\"><img src=\"poll/resultpx.gif\" align=\"left\" height=\"10\" width=\""+Math.round(percentage7*1.1)+"\"> &nbsp; "+percentage7+"%</td></tr>";
			strPollOutput += "<tr><td>";			
			strPollOutput += y[i].childNodes[11].firstChild.nodeValue;
			strPollOutput += "<br/>&nbsp;";
			strPollOutput += "</td></tr>";
			}
			strPollOutput += "</table>";
			strPollOutput += "<p>";
			strPollOutput += "<span class=\"persoon\"><a href=\""+y[i].childNodes[2].firstChild.nodeValue+"\">";
			strPollOutput += "Doorpraten met <br />"+y[i].childNodes[1].firstChild.nodeValue;
			strPollOutput += "</a></span>";
			strPollOutput += "</p><br/>";
			strPollOutput += "</div>";
			strPollOutput += "</div>";
			strPollOutput += "<br/>";

			document.getElementById('vote').innerHTML = strPollOutput;
			document.getElementById('vote').style.visibility = "visible";
		}
	}
}

function setVote(id,edition,vote) 
{
var x = xmlDoc.getElementsByTagName('poll');
var newVote,newValue,newValueText,newDate,newDateText;
var d = new Date();
var pollFound = 0;

newValueText = vote;
newDateText = d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear();
for (i=0;i<x.length;i++)
  {
	if (x[i].attributes[0].value==id && x[i].attributes[1].value==edition)
	{
	  newVote=xmlDoc.createElement('vote');
  	  newValue=xmlDoc.createElement('value');
	  newDate=xmlDoc.createElement('date');
  	  newTextValue=xmlDoc.createTextNode(newValueText);
	  newDateValue=xmlDoc.createTextNode(newDateText);

	  newValue.appendChild(newTextValue);
	  newDate.appendChild(newDateValue);	
	  newVote.appendChild(newValue);
	  newVote.appendChild(newDate);
   	  newel=xmlDoc.createElement('edition');

	  x[i].appendChild(newVote);

	  pollFound = 1;
	}
  }

  if (pollFound==0)
  {
	createPoll(id,edition,newValueText);
  }	
  else 
  {
	processResult(returnNodeString(),id,edition);
  }
}

function createPoll(id,edition,vote)
{

	var newPoll,newId,newEdition;
	var x = xmlDoc.getElementsByTagName('polldata');

	for (i=0;i<x.length;i++ )
	{
		newPoll=xmlDoc.createElement('poll');
		x[i].appendChild(newPoll);
	}

	
	var y = xmlDoc.getElementsByTagName('poll');

	for (i=0;i<y.length;i++)
	{
		
		if (i==(y.length-1))
		{
			newId=xmlDoc.createAttribute("id");
			newId.value=id;
			y[i].setAttributeNode(newId);
			newEdition=xmlDoc.createAttribute("edition");
			newEdition.value=edition;
			y[i].setAttributeNode(newEdition);

		}
	}
		
	setVote(id,edition,vote);

}


function returnNodeString() 
{
	var xmlString;
	var y=xmlDoc.getElementsByTagName("poll");
	
	xmlString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
	xmlString += "<"+xmlDoc.documentElement.nodeName+">\n";

	for (i=0;i<y.length;i++)
	  {
		xmlString += "<"+y[i].nodeName+" id=\""+y[i].attributes[0].nodeValue+"\" edition=\""+y[i].attributes[1].nodeValue+"\">\n";
		
		for (j=0;j<y[i].childNodes.length;j++)
		{
			xmlString += "<"+y[i].childNodes[j].nodeName+">\n";

			for (k=0;k<y[i].childNodes[j].childNodes.length;k++)
			{
				if (y[i].childNodes[j].childNodes[k].nodeType!=3)
				{
				xmlString += "<"+y[i].childNodes[j].childNodes[k].nodeName+">";
				xmlString += ""+y[i].childNodes[j].childNodes[k].firstChild.nodeValue+"";
				xmlString += "</"+y[i].childNodes[j].childNodes[k].nodeName+">\n";
				}
			}
			xmlString += "</"+y[i].childNodes[j].nodeName+">\n";
		}
		xmlString += "</"+y[i].nodeName+">\n";
	  }
	  xmlString += "</"+xmlDoc.documentElement.nodeName+">";
	  return xmlString;
}


function createCookie(id,edition) {
	var name = "id"+id+"e"+edition;
	var days = 365;
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+id+"e"+edition+expires+"; path=/";

}


function getCookie(id,edition)
{
	var nameEQ = "id"+id+"e"+edition+"="+id+"e"+edition;
	var ca = document.cookie.split(';');
	ca = ca.toString();
	if (ca.indexOf(nameEQ)>-1)
	{
		loadPollResults(id,edition,'checkFile')
		//getPollResult(id,edition);
	}
	else
	{
		getPoll(id,edition);
	}
}


function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}


function processResult(xml,id,edition)
{
    createXMLHttpRequest();
    var url = "poll/processresults.asp";
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    xmlHttp.onreadystatechange = function() 
     {
	if (xmlHttp.readyState==4)
	{
		createCookie(id,edition);
		getPollResult(id,edition);
	}
    }
    xmlHttp.send("xml="+escape(xml)+"&id="+id);
}

function checkFile(id,edition,from,vote)
{

    createXMLHttpRequest();
    var url = "poll/checkFile.asp?file="+id;
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = function() 
     {
	if (xmlHttp.readyState==4)
	   {
		if (xmlHttp.responseText=="true")
		{
			if (from=="setVote")
			{
				
				busyLoading();
				loadPollResults(id,edition,from,vote);
			}
			else
			{	
				
				busyLoading();
				loadPollResults(id,edition,'checkFile');
			}

		}
		else
		{
		if (from=="setVote")
			{
				busyLoading();
				loadPollResults(id,edition,from,vote);
			}
	
		}	
	   }

      }
    xmlHttp.send(null);
}

function removeWhiteSpaceNodes()
{
	var x = xmlDocPoll.getElementsByTagName('poll');
	var xlength = x.length;
	for (i=0;i<xlength;i++)
	{
		var ylength = x[i].childNodes.length;
		for (j=0;j<ylength;j++)
		{
			if (x[i].childNodes[j].nodeType==3)
			{
				x[i].removeChild(x[i].childNodes[j]);
				ylength--;
			}
		}
	}
}

function removeWhiteSpaceNodesVote()
{
	var x = xmlDoc.getElementsByTagName('poll');
	var xlength = x.length;
	for (i=0;i<xlength;i++)
	{
		var ylength = x[i].childNodes.length;
		for (j=0;j<ylength;j++)
		{			

			if (x[i].childNodes[j].nodeType==3)
			{
				x[i].removeChild(x[i].childNodes[j]);
				ylength--;
			}
			else
			{
				var zlength = x[i].childNodes[j].childNodes.length;
				for (k=0;k<zlength;k++)
				{
			
					if (x[i].childNodes[j].childNodes[k].nodeType==3)
					{
						x[i].childNodes[j].removeChild(x[i].childNodes[j].childNodes[k]);
						zlength--;
					}
				}
			}
		}
	}
}

function busyLoading()
{
	
	var strPollOutput = "";

	strPollOutput += "<div class=\"vote\">";
	strPollOutput += "<h3><span class=\"no-show\">Mini enquete</span></h3>";
	strPollOutput += "<div class=\"border\">";
	strPollOutput += "<p>";
	strPollOutput += "Bezig met laden";
	strPollOutput += "</p>";
	strPollOutput += "</div>";
	strPollOutput += "</div>";
	strPollOutput += "<br/>&nbsp;";

	document.getElementById('vote').innerHTML = strPollOutput;
	document.getElementById('vote').style.visibility = "visible";

}
//-->