/**
 * Some useful form and form elements methods
 *
 * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
 */

/**
 * Class to easily extend and manipulate <select> elements
 *
 * @param select <select> element to decorate
 */
function Select(element) {
    this.element = element;
    this.options = element.options;
}

/**
 * Adds an option to the <select>
 *
 * @param Option option to add
 * @param integer placement
 */
Select.prototype.add = function(option, before) {
    this.element.add(option, before);
}

/**
 * Removes an option to the <select>
 *
 * @param integer option index to remore
 */
Select.prototype.remove = function(option) {
    this.element.remove(option);
}

/**
 * Updates a <select> box to have exactly "count" elements
 *
 * If the <select> has more elements, the ones at the end will be removed.
 * If the <select> doesn't have enough elements, it will be padded with
 * numeric value <options> elements.
 *
 * @param integer count of options the <select> element should have
 *
 * @return void
 */
Select.prototype.fillTo = function(count) {
    for (var i = this.options.length; i > count; --i) {
        this.remove(i - 1);
    }
    for (var i = this.options.length; i < count; ++i) {
        this.add(new Option(i + 1, i + 1));
    }
};
