var WatermarkField = function( field, emptyFieldText ) {
	this.field = YAHOO.util.Dom.get( field );
	this.emptyFieldText = emptyFieldText;
	
	// Initialize the watermarked object
	this.init();
}

WatermarkField.prototype = {
	init : function() {
		// If the input field wasn't set correctly in the constructor (i.e., was not found), throw an error and return
		if( !this.field ) { 
			throw new Error( "Watermark field not found." ); 
			return;
		}
		
		// Assign focus and blur handlers
		YAHOO.util.Event.addListener( this.field, 'focus', this.handleFocus, this, true );
		YAHOO.util.Event.addListener( this.field, 'blur', this.handleBlur, this, true );
		
		this.handleBlur();	// Run the handleBlur method immediately to set the initial "empty field text"
	},
	
	handleFocus : function() {
		// On focus, clear the text if what's in there is the "empty field text"
		if( this.field.value == this.emptyFieldText ) {
			this.field.value = "";
			this.field.style.color = "black";
		}
	},
	
	handleBlur : function() {
		// On blur, if the textfield is empty, fill it with the "empty field text"
		if( this.field.value == "" ) {
			this.field.value = this.emptyFieldText;
			this.field.style.color = "gray";
		}
	},
	
	blur : function() {
		this.field.blur();
	},
	
	getField : function() {
		return this.field;
	},
	
	clear : function() {
		this.field.value = "";
		this.handleBlur();
	}
}