// geen observer(dom:loaded) meer, zie Mantis 8440.
//var initApplications = function (){

// ###################################################################
// ## FAQ (AUTOMATED UNOBTRUSIVE)									##
// ###################################################################
var execFAQ = function()
{
$$("div.question-container").each(function(el){
	var current = null;
	
	el.immediateDescendants("div").each(function(row){
		var button = $(row).down(".js-faq-question");
		var panel = $(row).down(".js-faq-answer").hide();
		if(button) {
			button.href = "javascript:void(0)";
			
			button.observe("click",function(e){
				e.stop();
				panel.show();
				button.addClassName("active");
				if(current)
				{
					current.button.removeClassName("active");
					current.panel.hide();
				};
				current = {
					button : button,
					panel : panel
				};
			});
		}
	});
});
};
execFAQ();
$(document).observe("dom:loaded",execFAQ)
	
// ###################################################################
// ## FORMVALIDATOR (AUTOMATED UNOBTRUSIVE)							##
// ###################################################################
var execFormValidator = function()
{
	var formToolTip = new NetEffect.AltToolTip({
		"style" : {
			"border" : "1px solid #cecece",
			"fontWeight" : "bold"
		}
	});
	
	var preloadAttentionImg = new Image();
	preloadAttentionImg.src = (contextPath||"")+"/docroot/images/attentie_red_ico.gif";
	
	$$("form.js-validator").each(function(o){
		// Validator object
		o.validator = new NetEffect.FormValidator(o);
		// Custom Validator handlers
		
		
		// onValid
		o.validator.observe("valid",function(e){
			
			if(e.field.attentionImg) {
				e.field.parentNode.removeChild(e.field.attentionImg);
				e.field.attentionImg = null;
			}
			
		});
		
		// onAllValid
		o.validator.observe("allvalid",function(e){
			
			o.validator.formObj.getInputs("text").each(function(obj,i){
				
				if(String(obj.value).empty())
					obj.value = "unknown";
				
			});
			
			o.validator.formObj.getElementsBySelector("input[type=text], textarea").each(function(obj,i){
				
				if(String(obj.value).empty())
					obj.value = "unknown";
				
			});
			
		});
		
		
		// onInvalid
		o.validator.observe("invalid",function(e){
			if(!e.field.attentionImg) {
				e.field.attentionImg = document.createElement("img");
				e.field.attentionImg.src = preloadAttentionImg.src;
				e.field.attentionImg = $(e.field.parentNode.insertBefore(e.field.attentionImg,e.field));
				if(e.field.hasClassName("js-validate-radio")){
					e.field.attentionImg.setStyle({
						"position" : "relative",
						"margin" : "3px 0 0 0px",
						"float" : "left",
						"zIndex" : "10",
						"width" : "16px",
						"height" : "15px"
					});
				} else {
					e.field.attentionImg.setStyle({
						"position" : "relative",
						"margin" : "3px 0 0 -22px",
						"float" : "left",
						"zIndex" : "10",
						"width" : "16px",
						"height" : "15px"
					});
				}
				// set alt texts for formToolTip object
				if(e.field.hasClassName("js-validate-string"))
					e.field.attentionImg.alt = "Vul hier alleen tekst in.";
				if(e.field.hasClassName("js-validate-number"))
					e.field.attentionImg.alt = "Vul hier alleen getallen in.";
				if(e.field.hasClassName("js-validate-email"))
					e.field.attentionImg.alt = "Vul hier een geldig e-mail adres in.";
				if(e.field.hasClassName("js-validate-select"))
					e.field.attentionImg.alt = "Selecteer <b>minimaal</b> 1 optie.";
				if(e.field.hasClassName("js-validate-radio"))
					e.field.attentionImg.alt = "Maak hier verplicht een keuze.";
				if(e.field.hasClassName("js-validate-notempty"))
					e.field.attentionImg.alt = "Vul dit verplichte veld in.";
				if(e.field.hasClassName("js-validate-phonenumber"))
					e.field.attentionImg.alt = "Vul hier uw telefoonnummer in.";
				// Bind events to the formToolTip object
				$(e.field.attentionImg).observe("mouseover",formToolTip.showTip.bindAsEventListener(formToolTip));
				$(e.field.attentionImg).observe("mouseout",formToolTip.hideTip.bindAsEventListener(formToolTip));
			}
		});
		// onValidateField
		o.validator.observe("fieldvalidated",function(e){
			if(!$(e.field.parentNode).visible() && !e.field.isValid) {
				if(e.field.attentionImg) {
					e.field.parentNode.removeChild(e.field.attentionImg);
					e.field.attentionImg = null;
				}
				e.validator.errors -=1;
			}
		});
		// onDone
		o.validator.observe("done",function(e){});
	});
};
execFormValidator();
//$(document).observe("dom:loaded",execFormValidator);

// ###################################################################
// ## PRINT (AUTOMATED UNOBTRUSIVE)									##
// ###################################################################
var execPrint = function()
{
	$$("a.print").each(function(o){
		o.observe("click",function(){
			window.print();
			return false;
		});
	});
};
execPrint();
//$(document).observe("dom:loaded",execPrint)

// ###################################################################
// ## TEKSTGROOTTE (AUTOMATED UNOBTRUSIVE)							##
// ###################################################################
var execTekstGrootte = function()
{
	$$("div.tekstgrootte").each(function(el){
		var fls = ["2_1","2_2","2_3"];
		var reStr = fls.join("|");
		var re = new RegExp("("+reStr+")\.css");
		
		var cssSheet = $$("head link").find(function(ss){
			return re.test(ss.href);
		});

		var switchSize = function(el){
			current.removeClassName("active");
			current = el.addClassName("active");
			new Ajax.Request(el.href);
		};
		
		var current = el.down("a.active");
		
		el.down("a.small").observe("click",function(e){
			e.stop();
			cssSheet.href = cssSheet.href.replace(re,fls[0]+".css");
			switchSize(this);
		});
		
		el.down("a.middle").observe("click",function(e){
			e.stop();
			cssSheet.href = cssSheet.href.replace(re,fls[1]+".css");
			switchSize(this);
		});
		
		el.down("a.large").observe("click",function(e){
			e.stop();
			cssSheet.href = cssSheet.href.replace(re,fls[2]+".css");
			switchSize(this);			
		});
	});
};
execTekstGrootte();
//$(document).observe("dom:loaded",execTekstGrootte);
