var InputPlaceholder = function(input, value, cssEmpty){

	var eThis = this;
	
	eThis.Input = input;
	eThis.Value = value;
	eThis.SaveOriginal = (input.value == value);
	eThis.CssEmpty = cssEmpty;

	eThis.setupEvent(eThis.Input, "focus", function(){return eThis.onFocus();});
	eThis.setupEvent(eThis.Input, "blur",  function(){return eThis.onBlur();});
	eThis.setupEvent(eThis.Input, "keydown", function(){return eThis.onKeyDown();});

	if (input.value == "")
		eThis.onBlur();

	return eThis;
}

InputPlaceholder.prototype = {

	setupEvent : function(elem, eventType, handler){

		if (elem.attachEvent)
			elem.attachEvent("on" + eventType, handler);

		if (elem.addEventListener)
			elem.addEventListener(eventType, handler, false);
	},

	onFocus : function(){

		if (!this.SaveOriginal && this.Input.value == this.Value){

			this.Input.value = "";

		} else {

			this.Input.className = this.Input.className.replace(" empty", "");
		}
	},

	onKeyDown : function(){

		this.Input.className = this.Input.className.replace(" empty", "");
	},

	onBlur : function(){

		if (this.Input.value == "" || this.Input.value == this.Value){

			this.Input.value = this.Value;

			this.Input.className = this.Input.className + " " + this.CssEmpty;

		} else {

			this.Input.className = this.Input.className.replace(" empty", "");
		}
	}
}
