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

/**
 * PassengerChooser provides the logic which connects an arbitrary quantities
 * of dropdowns for relationship based on a Rule Object.
 *
 * @see Rule      
 * @author  Claus Br�ndby Reimer / 2M business applications a|s
 * @version $Revision$ / $Date$
 */

function PassengerChooser() {
    this.rule;
    this.ruleHandlers = new Array();
    this.dropdowns = arguments;
}


/** Sets the Rule Object which should do the validation of the dropdowns
 *
 * @param oRule a Rule Object
 */
 
PassengerChooser.prototype.setRule = function(oRule) {    
    this.rule = oRule;
    this.rule.setHandlers(this.ruleHandlers);

    for (var a = 0; a < this.dropdowns.length; a++) {
        var dropdown = this.dropdowns[a];   // type of dropdown: HTMLSelectELement
        if (dropdown == null) {
            alert("Error: persontype #" + (a+1) + " doesnt exist in portal.xml")
            continue;
        }
        this.ruleHandlers[a] = new RuleHandler(dropdown);
        dropdown.chooser = this;
        dropdown.onchange = function() {
            this.chooser.rule.apply();
        }
    }
    this.rule.init();
}

PassengerChooser.prototype.getNumPassengers = function() {
    var amount;

    amount = 0;
    for (var a = 0; a < this.ruleHandlers.length; a++) {
        amount += this.ruleHandlers[a].getValue();
    }

    return amount;
}

