/*
 *
 *    Тёма, ничего, что мы твой скрипт сп*здили?
 *
 */


function InputPlaceholder (input, value, cssFilled, cssEmpty, button, buttonsrc)
{
	var thisCopy = this
	
	this.Input = input
	this.Value = value
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty

	this.setupEvent (this.Input, 'focus', function() { return thisCopy.onFocus() })
	this.setupEvent (this.Input, 'blur',  function() { return thisCopy.onBlur() })

	this.onBlur();

	if(button) {
		this.Button = button
		this.ButtonGray = new Image();
		this.ButtonGray.src = buttonsrc
		this.ButtonActive = new Image();
		this.ButtonActive.src = button.src

		this.Button.src = this.ButtonGray.src
	}

	return this
}

InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler)
{
	if(elem.attachEvent) {
		elem.attachEvent ('on' + eventType, handler)
	}

	if(elem.addEventListener) {
		elem.addEventListener (eventType, handler, false)
	}
}

InputPlaceholder.prototype.onFocus = function()
{
	if(this.Input.value == this.Value) {
		this.Input.value = ''
		this.Input.className = this.CssFilled
		if(this.Button) {
			this.Button.src = this.ButtonActive.src
		}

	}
}


InputPlaceholder.prototype.onBlur = function()
{
	// Поле теряет фокус.
	// Если оно пустое или в нём стоит значение по умолчанию, то...

	if(this.Input.value == '' || this.Input.value == this.Value) {
		this.Input.value = this.Value
		this.Input.className = this.CssEmpty
		if(this.Button) {
			this.Button.src = this.ButtonGray.src
		}
	}/* else {
		this.Input.className = this.CssFilled
	}*/
}

