
/*************************************************************************

Name:	placeholder.js
Desc:	input field text that dissappears when it becomes focussed

*************************************************************************/



function PlaceholderJS(target, caption) {
	var parent = this;
	this.target = target;
	this.caption = caption;
	
	target.oldFocus = target.onfocus;
	target.oldBlur = target.onblur;
	
	EventListener.add(	target, 
						'onfocus', 
						function(e) {if (this.oldFocus != null) {this.oldFocus();} parent.select();}
					);
	EventListener.add(	target, 
						'onblur', 
						function(e) {if (this.oldBlur != null) {this.oldBlur();} parent.change();}
					);
	this.change();
	/**/
}


PlaceholderJS.prototype.isChanged = function() {
	return (this.target.value != this.caption);
}


PlaceholderJS.prototype.change = function() {
	if ((this.target.value == '') || (this.target.value == this.caption)) {
		this.target.value = this.caption;
		setStateSuffix(this.target, {disabled:true});
	} else {
		setStateSuffix(this.target);
	}
}

PlaceholderJS.prototype.select = function() {
	//if default text is in the field
	if (this.target.value == this.caption) {
		//clear it
		this.target.value = '';
		if (this.target.className == 'text_disabled') {
			this.target.className = 'text';
		}
	//if other text in the field
	} else {
		//select ALL text
		this.target.select();
	}
}
