/*
FORMS.JS
Author : Bruno Sabot
Website : http://www.brunosabot.com
Version : v0.1
Copyright : Bruno Sabot

Please don't delete legal mention and report every bugs and missing on the website.
*/

Form.PluginInfos = "[v0.1] Bruno Sabot (http://www.brunosabot.com)";
Form.FocusCreate = function(e) {
	e.elements._each(function (v) {
		Event.observe(v,'focus',function () { if (this.value==this.defaultValue) { this.value=''; } });
		Event.observe(v,'blur',function() { if (this.value=='') { this.value=this.defaultValue; } });
		if (e.onFocus) { Event.observe(v,'focus',e.onFocus); }
		if (e.onBlur) { Event.observe(v,'blur',e.onBlur); }
	});
};
Form.isBad = function (e) {
	if (!e.color) { e.color='#FF0000'; }
	if (!e.text) { e.text='Cette valeur n\'est pas correcte'; }
	if (!e.duration) { e.duration=2000; }
	var id=$(e.id);
	var ttext = id.value;
	var tcolor = id.style.backgroundColor;
	id.value = e.text;
	id.style.backgroundColor = e.color;
	window.setTimeout(function(text, color) {
		this.value=text;
		this.style.backgroundColor = color;
	}.bind(id, ttext, tcolor),e.duration);
};
Form.isDefault = function (e) {
	var a = Array();
	var res = false;
	e.elements._each(function (v) {
		if ($(v).value==$(v).defaultValue) {
			res|=true;
			if (e.onTrue) {e.onTrue(v);}
			else {a.push(v);}
		} else {
			res|=false;
			if (e.onFalse) {e.onFalse(v);}
		}
	});
	if (e.onEnd) { e.onEnd(res,a); }
	return a;
};