;(function($) {

/**
 * Selects an option by text
 *
 * @name     selectOptionsByText
 * @author   Mathias Bank (http://www.mathias-bank.de), original function
 * @author   Sam Collett (http://www.texotela.co.uk), addition of regular expression matching
 * @author   Christophe (version modifiée : recherche sur le texte au lieu de rechercher sur la valeur du champ option)
* @type     jQuery
 * @param    String|RegExp value  Which options should be selected
 * can be a string or regular expression
 * @param    Boolean clear  Clear existing selected options, default false
 * @example  $("#myselect").selectOptions("val1"); // with the text 'val1'
 * @example  $("#myselect").selectOptions(/^val/i); // with the text starting with 'val', case insensitive
 *
 */
$.fn.selectOptionsByText = function(text, clear)
{
    var v = text;
    var vT = typeof(text);
    var c = clear || false;
    // has to be a string or regular expression (object in IE, function in Firefox)
    if(vT != "string" && vT != "function" && vT != "object") return this;
    this.each(
        function()
        {
            if(this.nodeName.toLowerCase() != "select") return this;
            // get options
            var o = this.options;
            // get number of options
            var oL = o.length;
            for(var i = 0; i<oL; i++)
            {
                if(v.constructor == RegExp)
                {
                    if(o[i].text.match(v))
                    {
                        o[i].selected = true;
                    }
                    else if(c)
                    {
                        o[i].selected = false;
                    }
                }
                else
                {
                    if(o[i].text == v)
                    {
                        o[i].selected = true;
                    }
                    else if(c)
                    {
                        o[i].selected = false;
                    }
                }
            }
        }
    );
    return this;
};

})(jQuery);