/* $Id: Copyright (c) 2003 WorldTicket A/S

/*
 * RuleHandler.js
 *
 * Created on 2004/02/16, 11:37:19
 */

/** RuleHandler handles the dropdowns
 *
 * @author  Claus Brøndby Reimer / 2M business applications a|s
 */

function RuleHandler(dropdown) {
        this.dropdown = dropdown;
}


/** Set the maximun amount which can be choosed from this handler
 *
 * @param p_value the maximum amount which can be choosed from this dropdown.
 */

RuleHandler.prototype.setMax = function(p_value) {
    var value;
    var prevValue;

    maxValue = parseInt(p_value);

    if (this.dropdown.options.length > maxValue) {
        prevValue = this.dropdown.value;
        this.dropdown.options.length = maxValue + 1;

        if (prevValue > maxValue) {
             this.dropdown.options[maxValue].selected = true
        } else {
             this.dropdown.options[prevValue].selected = true
       }
    } else {
        for (var a = this.dropdown.options.length; a <= maxValue; a++) {
            this.dropdown.options[a] = new Option(a, a, false, false);
        }
    }
}


/** Gets the maximum amount which can be choosed from this dropdown.
 *
 *  @return the maximum amount which can be choosed from this dropdown.
 */

RuleHandler.prototype.getMax = function() {
    return this.dropdown.options.length;
}

RuleHandler.prototype.getValue = function() {
    return parseInt(this.dropdown.value);
}

