/* START applesearch object */

var applesearch;
if (!applesearch)	applesearch = {};

applesearch.init = function ()
{

		this.clearBtn = false;
		
}

// called when on user input - toggles clear fld btn
applesearch.onChange = function (fldID, btnID)
{
	// check whether to show delete button
	var fld = document.getElementById( fldID );
	var btn = document.getElementById( btnID );
	if (fld.value.length > 0 && !this.clearBtn)
	{
		btn.style.background = "transparent url('/wp-content/themes/editerat-v4/images/search-right.png') no-repeat bottom left";
		btn.style.cursor = 'pointer';
		btn.fldID = fldID; // btn remembers it's field
		btn.onclick = this.clearBtnClick;
		this.clearBtn = true;
	} else if (fld.value.length == 0 && this.clearBtn)
	{
		btn.style.background = "transparent url('/wp-content/themes/editerat-v4/images/search-right.png') no-repeat top left";
		btn.style.cursor = 'normal';
		btn.onclick = null;
		this.clearBtn = false;
	}
}


// clears field
applesearch.clearFld = function (fldID,btnID)
{
	var fld = document.getElementById( fldID );
	fld.value = "";
	this.onChange(fldID,btnID);
}

// called by btn.onclick event handler - calls clearFld for this button
applesearch.clearBtnClick = function ()
{
	applesearch.clearFld(this.fldID, this.id);
}

/* END applesearch object */