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

/*
 * DirektflygRule.java
 *
 * Created on 2005/05/30, 19:54:57
 */

/** Rules For Direkt Flyg
 * Person type id:
 *      Adult = 1
 *      Child = 2
 *      Infant = 3
 *      Accompanied adult = 4
 *      UM = 5
 *      Student = 6
 *      pension = 7
 
* Only one infant for each adults
 * UM travels alone
 * Only one Accompanied adult for each adults
 *
 * @author  Søren Ejsing / 2M business applications a|s
 */
function DirektflygRule() {
        this.ADULT = arguments[0] -1 ;
        this.CHILD = arguments[1] - 1;
        this.INFANT = arguments[2] - 1;
        this.ACCOMPANIEDADULT = arguments[3] - 1;
        this.UM = arguments[4] - 1 ;
        this.STUDENT = arguments[5] - 1 ;
        this.SENIOR = arguments[6] - 1 ;
}

DirektflygRule.prototype = new Rule();

DirektflygRule.prototype.apply = function() {
    var adult = this.handlers[this.ADULT];
    var um = this.handlers[this.UM];
    var child = this.handlers[this.CHILD];
    var infant = this.handlers[this.INFANT];
    var accompaniedAdult = this.handlers[this.ACCOMPANIEDADULT];
    var student = this.handlers[this.STUDENT];
    var senior = this.handlers[this.SENIOR];

    if (um.getValue() > 0) {
        adult.setMax(0);
        student.setMax(0);
        senior.setMax(0);
    }
    else {
        adult.setMax(10);
        student.setMax(10);
        senior.setMax(10);
    }

    var iAdults = adult.getValue() + student.getValue() + senior.getValue();
    child.setMax(parseInt(iAdults) >= 1 ? 10 : 0);
    infant.setMax((iAdults >= 10? 10: iAdults));
    accompaniedAdult.setMax(iAdults);
}

DirektflygRule.prototype.init = function() {
    for (var a = 0; a < this.handlers.length; a++) {
        this.handlers[a].setMax(10);
    }
    this.handlers[this.UM].setMax(3);

    this.apply()
}
