/**
 * $Id$
 * @version $Revision$ $Date$
 * @author Søren Ejsing (SEJ) / 2M business applications a|s
 * Copyright 2005 WorldTicket A/S
 */

/**
 * Rules For Flyglinjen
 * Person type id and code:
 *      Adult = 1
 *      UM = 2
 *      Child = 3
 *      Infant = 4
 *      Student = 5
 *      Pensioner = 6
 * Only one infant for each adults
 * UM travels alone
 * @author  Søren Ejsing / 2M business applications a|s
 */
function FlyglinjenRule() {
        this.ADULT = arguments[0] -1 ;
        this.UM = arguments[1] -1 ;
        this.CHILD = arguments[2] - 1;
        this.INFANT = arguments[3] - 1;
        this.STUDENT = arguments[4] - 1 ;
        this.PENSIONER = arguments[5] - 1 ;
}

FlyglinjenRule.prototype = new Rule();

FlyglinjenRule.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 student = this.handlers[this.STUDENT];
    var pensioner = this.handlers[this.PENSIONER];

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

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

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

    this.apply()
}

