/* $Id$
 * Copyright (c) 2007 WorldTicket A/S
 * All rights reserved.
 * 
 * Generic rule where person types are:
 *    adult = 1
 *    child = 2
 *    infant = 3
 * Only one infant for each adults
 */
function GenericRule() {
        this.ADULT = arguments[0] -1 ;
        this.CHILD = arguments[1] - 1;
        this.INFANT = arguments[2] - 1;
}

GenericRule.prototype = new Rule();

GenericRule.prototype.apply = function() {
    this.applyAdult();
    this.applyChild();
    this.applyInfant();
}
GenericRule.prototype.applyAdult = function() {
    var adult = this.handlers[this.ADULT];
    adult.setMax(this.maxPerType(adult));
}
GenericRule.prototype.applyChild = function() {
    var adult = this.handlers[this.ADULT];
    var child = this.handlers[this.CHILD];
    var iAdults = parseInt(adult.getValue());
    child.setMax(iAdults >= 1 ? this.maxPerType(child) : 0);
}
GenericRule.prototype.applyInfant = function() {
    var adult = this.handlers[this.ADULT];
    var infant = this.handlers[this.INFANT];
    var iAdults = parseInt(adult.getValue());
    var iMaxInfants = this.maxPerType(infant);
    infant.setMax(iAdults >=  iMaxInfants ? iMaxInfants : iAdults);
}
GenericRule.prototype.maxPerType = function(handler) {
    return 10;
}
GenericRule.prototype.init = function() {
    for (var a = 0; a < this.handlers.length; a++) {
        this.handlers[a].setMax(this.maxPerType(this.handlers[a]));
    }

    this.apply()
}

