/* 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.
*/

var BS_forms = {
	Author : "Bruno Sabot",
	Website : "http://www.brunosabot.com",
	Version : "0.1",
	Description : "BS_forms is a plugin of the prototype.js and scriptaculous.js Framework."
}

Form.FocusCreate = function (e) {
	if (e.elements=='*') {
		t = getElementsByTagName('input');
		
	}
	e.elements._each(function (v) {
		$(v).onfocus = function() {
			if (this.value==this.defaultValue) {
				this.value='';
			}
		}
		$(v).onblur = function() {
			if (this.value=='') {
				this.value=this.defaultValue;
			}
		}
	});
};

Form.isBad = function(e) {
	if (!e.color) { e.color='#FF0000'; }
	if (!e.text) { e.text='This is not a correct value'; }
	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);
	}
	return a;
}