function setupEvent (elem, eventType, handler)
{
	if (elem.attachEvent)
	{
		elem.attachEvent ('on' + eventType, handler)
	}

	if (elem.addEventListener)
	{
		elem.addEventListener (eventType, handler, false)
	}
}

function InputPlaceholderList (form, cssFilled, cssEmpty)
{
	var thisCopy = this
	
	this.Form = form
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty

	this.Items = new Array()
	setupEvent (this.Form, 'submit', function() {return thisCopy.onSubmit()})

	return this
}

InputPlaceholderList.prototype.addItem = function (input, value, cssFilled, cssEmpty)
{
    if (typeof cssFilled == 'undefined') cssFilled = this.CssFilled
    if (typeof cssEmpty == 'undefined') cssEmpty = this.CssEmpty
    this.Items[this.Items.length] = new InputPlaceholder (input, value, cssFilled, cssEmpty);

	return this
}

InputPlaceholderList.prototype.onSubmit = function()
{
    for (var i=0; i<this.Items.length; i++)
    {
        if (this.Items[i].Input.value == this.Items[i].Value)
            this.Items[i].Input.value = '';
    }
    return true
}


function InputPlaceholder (input, value, cssFilled, cssEmpty)
{
	var thisCopy = this
	
	this.Input = input
	this.Value = value
	this.SaveOriginal = (input.value == value)
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty

	setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()})
	setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()})
	setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()})

	if (input.value == '') this.onBlur();

	return this
} 

InputPlaceholder.prototype.onFocus = function()
{
	if (!this.SaveOriginal &&  this.Input.value == this.Value)
	{
		this.Input.value = ''
		//this.Input.className = this.CssFilled
	}
	else
	{
		//this.Input.className = ''
		//this.Input.className = this.cssEmpty
	}
}

InputPlaceholder.prototype.onKeyDown = function()
{
	this.Input.className = this.CssFilled
}

InputPlaceholder.prototype.onBlur = function()
{
	if (this.Input.value == '' || this.Input.value == this.Value)
	{
		this.Input.value = this.Value
		this.Input.className = this.CssEmpty
	}
	else
	{
		this.Input.className = this.CssFilled
	}
}
