document.observe('dom:loaded', initQSearchForm);

function initQSearchForm(evt)
{
	new DefVal('q', 'Quick Search');
}

var DefVal = Class.create(
{
	initialize: function(fieldID, defaultVal) 
	{
		this.field = $(fieldID);
		this.fieldID = fieldID;
		this.defaultVal = defaultVal;
		
		this.isPasswordType = (this.field.type == 'password') ? true : false;
		if(Prototype.Browser.IE) this.isPasswordType = false;
		
		if(this.field.value == '') this.setDefVal();
		
		Event.observe(this.field, 'focus', this.fieldOnFocus.bindAsEventListener(this, true));
		Event.observe(this.field, 'blur', this.fieldOnBlur.bindAsEventListener(this, true));
		
	},
	clear: function() 
	{
		this.field.value = '';		
		if(this.isPasswordType) this.field.type = 'password';
	},
	setDefVal: function() 
	{
		this.field.value = this.defaultVal;
		if(this.isPasswordType) this.field.type = 'text';
	},
	isDefVal: function(){
		return (this.field.value.strip() == this.defaultVal);
	},
	fieldOnFocus: function()
	{
		if(this.isDefVal()) this.clear();
	},
	fieldOnBlur: function()
	{
		if(this.field.value.strip() == '') this.setDefVal();
	}
});