jQuery.fn.filterlist = function(pattern,mode) {
	return this.each(function(){
		
		if(mode)
		{
			var j = 1;
			this.options[0].text = pattern;
		} else {
			var j = 0;
		}

		for (i=0; i < this.length; i++)
			this.options[i].selected = false;
		
		for (; j < this.length; j++)
		{
			// Check if we have a match
			if (this.options[j].text.toLowerCase().indexOf(pattern.toLowerCase())>=0 || this.options[j].value.toLowerCase().indexOf(pattern.toLowerCase())>=0)
			{
				this.options[j].selected = true;
				return false;
			}
		}
		if(mode)
			this.options[0].selected = true;
  });
};
