var FormBuilder_Validator = new Class({
	/**
	 * @param 	string		ID of the form.
	 * @param	object		Obj with:
	 * - language (string):	One of the WAF locale names:
	 * 		- en_us
	 *		- de_de
	 *		- nl_nl
	 */
	initialize: function(sFormID, oOpt) {
		// find the language.
		var lang_names = {
			"en_us":"en-US"
			,"nl_nl":"nl-NL"
			,"de_de":"de-DE"
		};
		var lang_name = lang_names[oOpt.language];
		if (!lang_name)
			lang_name = "nl-NL";
		
		MooTools.lang.setLanguage(lang_name);
		this.form_id = sFormID;
		this.setEvents();
	}
	
	,setEvents: function() {
		this.validator = new Form.Validator.Inline(this.form_id, {
			onFormValidate:this.validateForm
			,useTitles:true
		});
		
		// custom radio validation
		this.validator.add('radio_required',{
			errorMsg:"Dit veld is verplicht"
			,test:function(oEl) {
				var checked = false;
				oEl.getParent('li').getElements('input[type=radio]').each(function(oRadio){
					if(oRadio.get('checked'))
						checked = true;
				});
				return checked;
			}
		});
		
		// custom checkbox validation
		this.validator.add('checkbox_required',{
			errorMsg:"Dit veld is verplicht"
			,test:function(oEl) {
				var checked = false;
				oEl.getParent('li').getElements('input[type=checkbox]').each(function(oCB){
					if(oCB.get('checked'))
						checked = true;
				});
				return checked;
			}
		});
		
		// add a hidden captcha field, so the spam application must
		// have a JS-interpreter.
		var el = new Element('input', {"type":"hidden", "name":"captcha_check","value":"y"});
		el.injectInside($(this.form_id));
	}
	,validateForm:function(bPassed, oForm, oEv) {
		if(!bPassed) {
			oEv.stop();
		}
	}
});

