/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

var _Captcha = {
	id : 'captcha',
	sc : 'security_code',
	chkField : function (e) {
		var label = _Form.getLabelFor(_Captcha.sc);
		var value = _Form.getValue(_Captcha.sc);
//console.log(label+' : '+value);		
		if (_Form.chkFieldEmpty(label,_Captcha.sc,value))
			return false;
		if (_Form.chkFieldLengthMax(label,_Captcha.sc,value,20))
			return false;
		if (!_Form.chkFieldMatch(label,_Captcha.sc,value,'a-zA-Z0-9'))
			return false;
		return true;
	},
	chg : function () {
		$(_Captcha.id).src='/mod/captcha/captcha.php?'+(new Date()).getTime();
	},
	reset : function () {
		$(_Captcha.sc).value = '';
	},
	init : function () {
		if ($(_Captcha.sc))	
			Event.observe($(_Captcha.sc),'change',_Captcha.chkField);
	}
};

Event.observe(window,'load',_Captcha.init);

