<!--
var OPT_ID		= 0;
var OPT_TITLE	= 1;
var OPT_VOTES	= 2;
var POLCOD		= 3;
var votedID;

var hide = 1;
var fade = 1;
var is_open;

function sendemail(item)
{
	return false;
}

function highlightQuery()
{
	try
	{
		var keys = window.top.keys;
 		
		if (keys != null && keys != "")
	   	{
	           var words = keys.split(" ");
	
	        for (var w = 0; w < words.length; w++) 
	           {
				try {if (words[w] != "") highlightword(words[w]);} catch(e){}
	           }
	
			window.top.keys = "";
	   	}
  	}
  	catch(e){}
}

function highlightword(word)
{
	try
	{
	    var text	= document.body.createTextRange();  
	    var ci		= 0;
    	var maxi 	= word.length * 2;
	
	    while (text.findText(word) && ci < maxi)
    	{
       		try
       		{
       			text.pasteHTML("<span class=\"highlight\">" + text.text + "</span>");
       			text.moveStart("character", (-word.length)+1);
            }
       		catch(e){}
       
       		ci++;
    	}
	}
	catch(e){}
}

function setThumbNailEvents()
{
	var imgs 			= document.getElementsByTagName("img");
	var l				= imgs.length;
	var img;
	
	for (var i = 0; i < l; i++)
	{
		img				= imgs[i];
		
		if (img.className == "THUMBNAIL") img.onclick = thumbNailClick;			
	}
}

function thumbNailClick(e)
{
	try 
	{
		var item;

		if (IE) item = window.event.srcElement;
		else 	item = e.target;

		var url		= item.src.replace("&thumbnail=true", "");
		
		specificThumbNailClick(escape(url));
	} 
	catch (e) {}
}

function findFrame(w, frStr)
{
	var result = null;
  	var i = 0;
 
  	while (i < w.frames.length && result == null)
  	{
   		if (w.frames[i].name != null && w.frames[i].name == frStr) 	result = w.frames[i];
    	else 														result = findFrame(w.frames[i], frStr);
    
    	i = i + 1;
  	}
 
 	return result;
}

var b1 = false;
var b2 = false;

function checkNavigators(frame1, frame2)
{
	timeOut 		= timeOut + 1;
	
	if (frame1 != null && navitmcod1_cmsnavitm_unid != null)
	{
		f1 			= findFrame(top, frame1);
						
		try 
		{
			if (!b1)
			{
				b1 	= f1.activate(navitmcod1_cmsnavitm_unid);
			}
		} 
		catch(e) 
		{
			if (timeOut<40) {setTimeout("checkNavigators('" + frame1 + "', null)",300)};
		}
	}
	
	if (frame2 != null && navitmcod2_cmsnavitm_unid != null)
	{
		f2			= findFrame(top, frame2);
		
		try 
		{
			if (!b2)
			{
				b2 = f2.activate(navitmcod2_cmsnavitm_unid);
			}
		}
		catch(e) 
		{
			if (timeOut<40) {setTimeout("checkNavigators(null,'" + frame2 + "')",300)};
		}
	}
	
}

function checkFrameStructure(frame, i)
{
	if (i < arFr.length)
	{
		if (frame.frames[arFr[i]] != null) checkFrameStructure(frame.frames[arFr[i]], i + 1);
		else 	
		{
			try 
			{
				correctFrameStructure(frame, arFr[i], uniqueid);
			} 
			catch(e){} 
		}
	}
}

function formProcess(event)
{
	event.preventDefault();

	var polcod = event.target.id;

	var id = $("input[@name=\"vote\"]:checked").attr("value");
	id = id.replace("vote", "");

	$("#" + polcod + "-container").fadeOut("slow",function()
	{
		$(this).empty();

		votedID = id;
		$.getJSON("/PollServlet?vote=yes&polcod=" + polcod + "&id=" + id, loadResults);

		$.cookie(polcod, polcod, {expires: 365});
	});
}

function animateResults(polcod)
{
	$("#" + polcod + "-results div").each(function()
	{
		var percentage = $(this).next().text();
		$(this).css({width: "0%"}).animate({width: percentage}, "slow");
	});
}

function loadResults(data)
{
	var total_votes			= 0;
	var percent				= 0;
	var polcod				= "";

	for (id in data)
	{
		polcod				= data[id][POLCOD];
		total_votes			= total_votes+parseInt(data[id][OPT_VOTES]);
	}

	var results_html		= "<div id=\"" + polcod + "-results\"><h3>Resultaten</h3>\n<dl class=\"graph\">\n";
	for (id in data)
	{
		percent = Math.round((parseInt(data[id][OPT_VOTES]) / parseInt(total_votes)) * 100);
		if (isNaN(percent))
		{
			percent			= 0;
		}
		if (data[id][OPT_ID] !== votedID)
		{
			results_html	= results_html + "<dt class=\"bar-title\">" + data[id][OPT_TITLE] + "</dt><dd class=\"bar-container\"><div id=\"bar" + data[id][OPT_ID] + "\" style=\"width: 0%;\">&nbsp;</div><strong>" + percent + "%</strong></dd>\n";
	    }
	    else
	    {
			results_html	= results_html + "<dt class=\"bar-title\">" + data[id][OPT_TITLE] + "</dt><dd class=\"bar-container\"><div id=\"bar" + data[id][OPT_ID] + "\" style=\"width: 0%; background-color:#0066cc;\">&nbsp;</div><strong>" + percent + "%</strong></dd>\n";
		}
	}

	results_html			= results_html + "</dl></div><br clear=\"all\"/><p>Totaal aantal stemmen: " + total_votes + "</p>\n";

	$("#" + polcod + "-container").append(results_html).fadeIn("slow",function(){animateResults(polcod);});
}

function initFlowPlayer()
{
	$("a[title*=.flv]")
		.css({"display":"block"})
		.flowplayer
		(
			"/" + CONTEXTNAME + "/swf/cms/flowplayer-3.0.3.swf",
			{								 
				clip: {autoPlay: 		false,
					   autoBuffering:	true}
			}
		)
		.flowplayer().each (function() {this.load()});
}

function initProperties()
{
	var toggleproperties	= document.getElementById("toggleproperties");
	var pijltje				= document.getElementById("pijltje");
	if (mode == MODE_ADD) hide = 0; // In MODE_ADD altijd open zetten in init, anders dicht.
	is_open = (hide == 0); // true bij hide = 0 en false bij hide = 1

	if (toggleproperties)
	{
		animatedcollapse.addDiv("properties", "hide=" + hide + ", fade=" + fade);
		animatedcollapse.init();

		if (hide == 1)
		{
			pijltje.className = "collapsed";
		}
		else
		{
			pijltje.className = "expanded";
		}
	}
}

function toggleProperties()
{
	var pijltje				= document.getElementById("pijltje");

	if (is_open)
	{
		pijltje.className = "collapsed";
	}
	else
	{
		pijltje.className = "expanded";
	}
	animatedcollapse.toggle("properties");
	is_open = !is_open;
}

function setChanged()
{
	isChanged = true;
}

function checkvelden(formId)
{
	var b			= true;
	var tmp			= document.getElementsByTagName("input");		
	var i			= 0;
	var email		= document.getElementById("email").value;
	
	while (i < tmp.length && b)
	{			
		if (tmp[i].getAttribute("req") && tmp[i].getAttribute("req") == "true")
		{
			if (tmp[i].value == "") b = false;
		}			
		
		i	= i + 1;
	}
	
	if (!b)
	{
		alert("U dient alle velden correct in te vullen!");
		return false;
	}
	else
	{
		document.formId.submit();
		return true;
	}
}
//-->
