﻿(function ($) {

    $.fn.addOptions = function (items) {
        var add = function (el, item) {
            var option = document.createElement("option");
            option.value = item[0], option.text = item[1];
            el.options[el.options.length] = option;
        }

        this.each(function () {
            if (this.nodeName.toLowerCase() != "select") return;

            for (var i = 0, n = items.length; i < n; ++i) {
                add(this, items[i]);
            }

        });

        return this;
    }

    $.fn.selectOption = function (value) {
        this.each(
		function () {
		    if (this.nodeName.toLowerCase() != "select") return this;
		    var os = this.options;
		    for (var i = 0, n = os.length; i < n; i++) {
		        os[i].selected = (os[i].value == value);
		    }
		}
	);
        return this;
    };

})(jQuery);