LocationSuggest = Class.create();
Object.extend( Object.extend(LocationSuggest.prototype, Autocompleter.Local.prototype), {
	selectEntry: function() {
		this.active = false;
	    this.updateElement(this.getCurrentEntry());
		var value = Element.collectTextNodesIgnoreClass(this.getCurrentEntry(), 'informal');
		// 		alert(value);
		var suggestLink = document.getElementsByClassName( 'location-suggest-tag' ).detect ( function( each, index ) {
			return each.innerHTML == value;
		})
		
		toggle_loc_on( suggestLink );
	}
});

function toggle_loc( loc_el ) {
	var list = $('special_location_list');
	var exists = false
	list.value = list.value.gsub( new RegExp(loc_el.innerHTML + '|, ' + loc_el.innerHTML, 'i'), function(val) {
		 									exists = true; return '';
										});
	if( !exists )
	{
		var stripped = list.value.strip();
		list.value += (stripped.length > 0 && stripped[stripped.length - 1] != ',' ? ', ' : '' ) + loc_el.innerHTML;
		toggle_loc_on( loc_el );
	}
	else
	{
		toggle_loc_off( loc_el );
	}
}

function toggle_loc_on( loc_el )
{
	Element.addClassName(loc_el, 'selected-tag');
}

function toggle_loc_off( loc_el )
{
	Element.removeClassName(loc_el, 'selected-tag')
}