


// Copyright (c) NimbleCat, 2008

/*
* this object implements a button
* 
* */
// make sure that the required includes are there
 if (typeof NC == 'undefined') {
       alert("edithint.js requires the NC JavaScript framework");
 }
 
 if (typeof NC.widget == 'undefined') {
       alert("edithint.js requires the NC JavaScript framework");
 }
 
 /*
  * constructor
  */
  
  NC.widget.EditHint = function( id, query, hint) {
		var fnSuperClass = NC.widget.EditHint.superclass.constructor;
		fnSuperClass.call( this, id);
		this.el = document.getElementById( id);
		if (query == null || query.length == 0) {
			this.el.hint = hint;
			this.el.value = hint;
			this.el.hintShown = true;
		}
		else {
			this.el.hint = hint;
			this.el.value = query;
			this.el.hintShown = false;
		}
  }
  
  NC.lang.extend(NC.widget.EditHint, NC.widget.Element, 
  	{
		_blur: function( event)
		{
			var target = NC.core.Event.getEventTarget(event);
			var value = NC.util.Dom.getValue( target);
			if (value.length == 0) {
				target.value = target.hint;
				target.hintShown = true;
				NC.util.Dom.replaceClass( target, target.className, target.className + '-blur');
			}
		},
		
		_focus:function( event)
		{
			var target = NC.core.Event.getEventTarget(event);
			if (target.hintShown) {
				target.value = '';
				target.hintShown = false;
			}
			var i = target.className.indexOf(  '-blur');
			if ( i != -1) {
				var baseClass = target.className.substring( 0, i);
				NC.util.Dom.replaceClass( target, target.className , baseClass);
			}
		},

	  	init: function() {
            NC.widget.EditHint.superclass.init.call(this);
			this.addDomEvent(NC.core.EventType.Blur, this._blur, false);
			this.addDomEvent(NC.core.EventType.Focus, this._focus, false);
	  		return "init EditHint function";
	  	},


 		render:function() {
 			return "render";
 		},
		
		setHintShown: function( value) {
			this.el.hintShown = value;
			if (value == false) {
				var i = this.el.className.indexOf(  '-blur');
				if ( i != -1) {
					var baseClass = this.el.className.substring( 0, i);
					NC.util.Dom.replaceClass( this.el, this.el.className , baseClass);
				}
			}
		}
	  	
  	});
