// -----------------------------------------------------------------------------------
//
//	defaultValue v1
//	by Giancarlo Gomez - http://www.fusedevelopments.com
//	Last Modification: 05.07.2009
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//  	- Free for use in both personal and commercial projects
//		- Attribution requires leaving author name, author link, and the license info intact.
//
// -----------------------------------------------------------------------------------

var defaultValue = Class.create({
	
	initialize: function(field,options){
		this.options = Object.extend({
			value : '',
			className : 'defaultValue'
		}, options || {});
		this.fieldID = field;
		this.field = $(field);
		Event.observe(this.field,'blur',this.onBlur.bind(this),false);
		Event.observe(this.field,'focus',this.onFocus.bind(this),false);
		this.showState('init for ' + field);
		this.onInit();
	},
	
	onInit: function(){
		
		if (this.field.value == '' || this.field.value.toUpperCase() == this.options['value'].toUpperCase()){
			
			$(this.fieldID).addClassName(this.options['className']);
			this.field.value =	this.options['value'];
		
		}
		
	},
	
	onBlur: function(){
		this.showState('blur occured');
		
		if (this.field.value == '' || this.field.value.toUpperCase() == this.options['value'].toUpperCase()){
			
			this.field.value =	this.options['value'];
			this.field.hasFocus = false;
			$(this.fieldID).addClassName(this.options['className']);
		
		}
	},
	
	onFocus: function(){
		this.showState('focus occured');
		
		// remove the default class name
		$(this.fieldID).removeClassName(this.options['className']);
		
		// if the current value = the default value clear it
		if (this.field.value == this.options['value']){
			this.field.value = '';
		}
		this.field.hasFocus = false;
		
	},
		
	showState: function(msg){
		//console.log(msg);
	}
	
});
