function AutoPreFill( inputFieldId, preFillText, defaultColor )
{
	// Initialize vars
	if( typeof( defaultColor ) === 'undefined' ) {
		defaultColor = '#FFFFAA'
	}
	this.inputFieldId = inputFieldId;
	this.preFillText = preFillText;
	this.defaultColor = defaultColor;
}

AutoPreFill.prototype.init = function()
{
	if( $( this.inputFieldId ).value == '' || $( this.inputFieldId ).value == this.preFillText )
	{
		$( this.inputFieldId ).style.backgroundColor = this.defaultColor;
		$( this.inputFieldId ).style.color = '#888888';
		$( this.inputFieldId ).value = this.preFillText;
	}
	else
	{
		$( this.inputFieldId ).style.backgroundColor = '#FFFFFF';
		$( this.inputFieldId ).style.color = '#000000';
	}
}

// Input element was blurred, so fill in pre-fill input if input field is empty and make input yellow
AutoPreFill.prototype.blurEvent = function()
{
	if( $( this.inputFieldId ).value == '' )
	{
		$( this.inputFieldId ).value = this.preFillText;
		$( this.inputFieldId ).style.backgroundColor = this.defaultColor;
		$( this.inputFieldId ).style.color = '#888888';
	}
}

// Input element was focussed, so clear pre-fill input if exists any and restore original text color
AutoPreFill.prototype.focusEvent = function()
{
	if( $( this.inputFieldId ).value == this.preFillText )
	{
		$( this.inputFieldId ).value = '';
		$( this.inputFieldId ).style.backgroundColor = '#FFFFFF';
		$( this.inputFieldId ).style.color = '#000000';
	}
}

// Form was submitted. In case it contains the pre-fill text, it has to be cleared
AutoPreFill.prototype.submitEvent = function()
{
	if( $( this.inputFieldId ).value == this.preFillText )
	{
		$( this.inputFieldId ).value = '';
	}
}

