function setSwitches() {
    nbr = document.getElementById('nb_enfant').value;
    GenererEnfant(nbr, 'txt_enfants');
    var switchs = getElementsByClass('switch');
    for (var j=0;j<switchs.length;j++) {
        if(switchs[j].value == 'oui') {
            addEvent(switchs[j],'click',Affiche);
        }
        if(switchs[j].value == 'non') {
            if(switchs[j].checked == true) {
            
                    var matches, aff;
                    if (matches = switchs[j].className.match(/\s?txt_(\w+)\s?/)) {
                        aff = $('txt_' + matches[1]);
                        aff.style.display = 'none';
                    }
            }
            addEvent(switchs[j],'click',Masque);
        }
    }
}
function Affiche(e) {
    var matches, obj, aff;
    var evt = getStandardEvent(e);
    obj = evt.target;
    if (matches = obj.className.match(/\s?txt_(\w+)\s?/)) {
        aff = $('txt_' + matches[1]);
        aff.style.display = 'block';
    }

    //evt.preventDefault();
    //return false;
}
function Masque(e){
    var matches, obj, aff;
    var evt = getStandardEvent(e);
    obj = evt.target;
    if (matches = obj.className.match(/\s?txt_(\w+)\s?/)) {
        aff = $('txt_' + matches[1]);
        aff.style.display = 'none';
    }
    //evt.preventDefault();
    //return false;
}

function GenererEnfant(nbr, id, values) {
    // nombre de champs maxi
    var MAXCOUNT = 7;
    
    if (nbr <= 0) {
        document.getElementById(id).innerHTML = '';
        return;
    } else if (nbr > MAXCOUNT) {
        nbr = MAXCOUNT;
    }
    
    if (!values) {
        var values=new Array(MAXCOUNT);
    }
    
    var txt = '<label>Âges de vos enfants</label>';
    for (i=0; i<nbr; i++) {       
        txt += '<input type="text" size="3" maxlength="2" name="enfant[' + (i+1) + ']" value="' +
               (values[i] > 0 ? values[i] : '') + '" /> ';
    }
    document.getElementById(id).innerHTML = txt;
}
addEvent(window,'load',setSwitches);
