$.fn.extend(
{
	select_option : function(v){
		this.each(
			function()
			{
				var o = this.options;
				var oL = o.length;
				for(var i = 0; i<oL; i++)
				{
					if(o[i].value == v)
					{
						o[i].selected = true;
					}
				}
			}
		);
		return this;
	},
	addOption:function(){
	  	var add = function(el, v, t, sO)
	  	{
	  		var option = document.createElement("option");
	  		option.value = v, option.text = t;
	  		var o = el.options;
	  		var oL = o.length;
	  		if(!el.cache)
	  		{
	  			el.cache = {};
	  			for(var i = 0; i < oL; i++)
	  			{
	  				el.cache[o[i].value] = i;
	  			}
	  		}
	  		if(typeof el.cache[v] == "undefined") el.cache[v] = oL;
	  		el.options[el.cache[v]] = option;
	  		if(sO)
	  		{
	  			option.selected = true;
	  		}
	  	};
	  	
	  	var a = arguments;
	  	if(a.length == 0) return this;
	  	var sO = true;
	  	var m = false;
	  	var items, v, t;
	  	if(typeof(a[0]) == "object")
	  	{
	  		m = true;
	  		items = a[0];
	  	}
	  	if(a.length >= 2)
	  	{
	  		if(typeof(a[1]) == "boolean") sO = a[1];
	  		else if(typeof(a[2]) == "boolean") sO = a[2];
	  		if(!m)
	  		{
	  			v = a[0];
	  			t = a[1];
	  		}
	  	}
		this.each(
			function()
			{
				if(this.nodeName.toLowerCase() != "select") return;
				if(m)
				{
					for(var item in items)
					{
						add(this, item, items[item], sO);
					}
				}
				else
				{
					add(this, v, t, sO);
				}
			}
		);
		return this;
	},
	removeOption:function()
	{
		var a = arguments;
		if(a.length == 0) return this;
		var ta = typeof(a[0]);
		var v, index;
		if(ta == "string" || ta == "object" || ta == "function" ) v = a[0];
		else if(ta == "number") index = a[0];
		else return this;
		this.each(
			function()
			{
				if(this.nodeName.toLowerCase() != "select") return;
				if(this.cache) this.cache = null;
				var remove = false;
				var o = this.options;
				if(!!v)
				{
					var oL = o.length;
					for(var i=oL-1; i>=0; i--)
					{
						if(v.constructor == RegExp)
						{
							if(o[i].value.match(v))
							{
								remove = true;
							}
						}
						else if(o[i].value == v)
						{
							remove = true;
						}
						if(remove && a[1] === true) remove = o[i].selected;
						if(remove)
						{
							o[i] = null;
						}
						remove = false;
					}
				}
				else
				{
					if(a[1] === true)
					{
						remove = o[index].selected;
					}
					else
					{
						remove = true;
					}
					if(remove)
					{
						this.remove(index);
					}
				}
			}
		);
		return this;
	}
})

