/* START applesearch object */
		
if (!applesearch)	var applesearch = {};

applesearch.init = function (fldID, btnID)
{
	
	// add applesearch css for non-safari, dom-capable browsers
	if ( navigator.userAgent.toLowerCase().indexOf('safari') < 0  && document.getElementById )
	{
		this.isSafari = false;
		this.clearBtn = false;
		this.placeholder = "Search...";
		// add style sheet if not safari
		var dummy = document.getElementById("dummy_css");
		
		if (dummy){	
			applesearch.baseurl = dummy.href.replace(/dummy.css/gi, "");
			dummy.href = applesearch.baseurl + "applesearch.css";
		}
		var fld = document.getElementById( fldID );
		var search_index = location.href.indexOf("?s=");
		if(search_index > 0){
			fld.value = unescape(location.href.substring(search_index+3).replace(/\+/gi," "));
			this.onChange(fldID, btnID);
		}
		else{	
			fld.value = this.placeholder;
			fld.style.color = "#888";
		}
	}
	else {
		this.isSafari = true;
		document.getElementById( fldID ).style.display = "block";
	}
}
// called when on user sets focus - toggles "Search..." text
applesearch.onFocus = function (fldID)
{
	if(this.isSafari) return;
	// check whether to show delete button
	var fld = document.getElementById( fldID );
	if (fld.value.length > 0 && fld.value == this.placeholder){
		fld.value = "";
		fld.style.color = "#000";
	}
	
}

// called when on user leaves focus - toggles "Search..." text
applesearch.onBlur = function (fldID)
{	
	if(this.isSafari) return;
	// check whether to show delete button
	var fld = document.getElementById( fldID );
	if (fld.value.length == 0){
		fld.value = this.placeholder;
		fld.style.color = "#888";
	}
}
// called when on user input - toggles clear fld btn
applesearch.onChange = function (fldID, btnID)
{
	if(this.isSafari) return;
	// 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('"+applesearch.baseurl+"images/srch_r_f2.gif') no-repeat top left";
		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('"+applesearch.baseurl+"images/srch_r.gif') no-repeat top left";
		btn.onclick = null;
		this.clearBtn = false;
		fld.focus();
	}
}


// 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 */
