function cReqAlter()
{
    this.kinder = 0;
    this.babies = 0;

    this.kinderalter = 2;
    this.recount_save = new Array();
    this.saveErw = 0;

    this.teilnehmer_removeAll = function()
    {
        for (var i=0; i < 100; i++)
        {
            var tn_alter = I("RT_GEBDATUM_" + (Number(this.saveErw) + Number(1) + Number(i)));
            if (tn_alter == null)
                break;

            this.recount_save[i] = tn_alter.value;
        }

        var insert = I("INSERT_ALTER");
        insert.innerHTML = "";
        this.kinder = 0;
        this.babies = 0;
    }
    
    this.teilnehmer_recount = function()
    {
        this.teilnehmer_removeAll();

        this.saveErw = I("ANZAHL_ERWACHSENE").value;

        var kind = I("ANZAHL_KINDER").value;
        var baby = I("ANZAHL_BABY").value;

        var anzahl = Number(kind) + Number(baby);

        if (anzahl == 0)
        {
            I("ALTERSEINGABE").style.display = "none";
            return;
        }
        else
        {
            I("ALTERSEINGABE").style.display = "";
        }

        for (var i = 0; i < kind; i++)
        {
            var alter = null;

            if (i < this.recount_save.length)
                alter = this.recount_save[i];

            this.teilnehmer_add("K", alter);
        }

        for (;i < anzahl; i++)
        {
            var alter = null;

            if (i < this.recount_save.length)
                alter = this.recount_save[i];

            this.teilnehmer_add("B", alter);
        }
    }

    this.teilnehmer_add = function(typ, alter)
    {
        if (typ == "E")
            return;

        var insert = I("INSERT_ALTER");

        if (typ == "K")
        {
            this.kinder++;
            var label = document.createTextNode(this.kinder + ". Kind: ");
            if (alter != null && alter <= this.kinderalter)
                alter = null;
        }
        else if (typ == "B")
        {
            this.babies++;
            var label = document.createTextNode(this.babies + ". Baby: ");
            if (alter != null && alter > this.kinderalter)
                alter = null;        
        }

        this.saveErw = I('ANZAHL_ERWACHSENE').value;

        var span = document.createElement("span");
        span.appendChild(label);
        var input = document.createElement("input");
        input.setAttribute("type", "text");
        input.setAttribute("size", "2");
        input.setAttribute("maxlength", "2");
        input.name = "RT_GEBDATUM_" + (Number(this.saveErw) + Number(this.kinder) + Number(this.babies));
        input.id = input.name;

        if (alter != null)
            input.value=alter;

        span.appendChild(input);

        insert.appendChild(span);
    }

}

