var infantNumber= 0;
var childrenNumber = 0;
var childrenForm = 0;
var infantForm = 0;

function moreThanOneInfant(form){
    infantForm = document.forms['AvailRequester'].infants;
    infantNumber= infantForm.value;
    if(document.forms['AvailRequester'].children.selectedIndex>1){
        headerDisplay.style.visibility="visible";
        childrenDisplay.style.display="block";
        childrenDisplay.style.visibility="visible";
        showChildren(document.forms['AvailRequester'].children.selectedIndex-1);
    }

    var infTotal = infantForm.value;
    var max=6;
    if(0==infantForm.value){
        if(0==childrenForm.value){
            headerDisplay.style.display="none";
            showChildren(0);
        }
        showInfants(0);
        infantDisplay.style.display="none";
    }else{
        showInfants(infantNumber);
        if(headerDisplay.style.display=="none"){
            headerDisplay.style.visibility="hidden";
            headerDisplay.style.display="block";
        }
        headerDisplay.style.visibility="visible";

        infantDisplay.style.display="block";
        infantDisplay.style.visibility="visible";
    }
}

function moreThanOne(form){
    childrenForm = document.forms['AvailRequester'].children;
    childrenNumber= childrenForm.value;

    if(document.forms['AvailRequester'].infants.selectedIndex>1){
        headerDisplay.style.visibility="visible";
        infantDisplay.style.display="block";
        infantDisplay.style.visibility="visible";
        showInfants(document.forms['AvailRequester'].infants.selectedIndex-1);
    }

    var total=childrenForm.value;

    var max=6;
    if(0==childrenForm.value){
        if(0==infantForm.value){
            headerDisplay.style.display="none";
            showInfants(0);
        }
        showChildren(0);
        childrenDisplay.style.display="none";
    }else{
        showChildren(childrenNumber);

        if(headerDisplay.style.display=="none"){
            headerDisplay.style.visibility="hidden";
            headerDisplay.style.display="block";
        }
        childrenDisplay.style.display="block";
        childrenDisplay.style.visibility="visible";
        headerDisplay.style.visibility="visible";
    }
}

function showChildren(numberOfChildren){
    for(i=1; i<= numberOfChildren;i++){
        eval("showChildHeader"+i+".style.visibility='visible'");
        eval("showChild"+i+".style.visibility='visible'");
    }
    for(j=6; j > numberOfChildren; j--){
        var ptc=j-1;
        eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=0");
        eval("showChildHeader"+j+".style.visibility='hidden'");
        eval("showChild"+j+".style.visibility='hidden'");
    }
}

function showInfants(numberOfInfants){
    for(i=1; i<= numberOfInfants;i++){
        eval("showInfantHeader"+i+".style.visibility='visible'");
        eval("showInfant"+i+".style.visibility='visible'");
    }
    for(j=6; j > numberOfInfants; j--){
    var ptc=j+5;
        eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=0");
        eval("showInfantHeader"+j+".style.visibility='hidden'");
        eval("showInfant"+j+".style.visibility='hidden'");
        eval("showInfant"+j+".style.display='block'");
    }
}

function processInfants( inf, ins ) {
    var totalInfants = inf+ins;
    var ptc=5;
    while (totalInfants > -1) {
        //alert(totalInfants);
        //alert(ptc);

        if(inf>-1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=1");
            inf--;
        } else if(ins > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=2");
            ins--;
        }
        totalInfants = inf+ins;
        ptc++;
    }
}

function processChildren( c2, c3,c4, c5, c6, c7, c8, c9, c10, c11) {
    var totalChildren = -1;
    var ptc=0;

    if(c2>-1){
        totalChildren++;
    }
    if(c3>-1){
        totalChildren++;
    }
    if(c4>-1){
        totalChildren++;
    }
    if(c5>-1){
        totalChildren++;
    }
    if(c6>-1){
        totalChildren++;
    }
    if(c7>-1){
        totalChildren++;
    }
    if(c8>-1){
        totalChildren++;
    }
    if(c9>-1){
        totalChildren++;
    }
    if(c10>-1){
        totalChildren++;
    }

    if(c11>-1){
        totalChildren++;
    }

    while (totalChildren > -1) {
        if(c2 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=1");
            c2--;
        } else if(c3 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=2");
            c3--;
        }else if(c4 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=3");
            c4--;
        }else if(c5 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=4");
            c5--;
        }else if(c6 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=5");
            c6--;
        }else if(c7 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=6");
            c7--;
        }else if(c8 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=7");
            c8--;
        }else if(c9 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=8");
            c9--;
        }else if(c10 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=9");
            c10--;
        }else if(c11 > -1) {
            eval("document.forms['AvailRequester'].childPTC["+ptc+"].selectedIndex=10");
            c11--;
        }
        ptc++;

        totalChildren = -1;
        if(c2>-1){
            totalChildren++;
        }
        if(c3>-1){
            totalChildren++;
        }
        if(c4>-1){
            totalChildren++;
        }
        if(c5>-1){
            totalChildren++;
        }
        if(c6>-1){
            totalChildren++;
        }
        if(c7>-1){
            totalChildren++;
        }
        if(c8>-1){
            totalChildren++;
        }
        if(c9>-1){
            totalChildren++;
        }
        if(c10>-1){
            totalChildren++;
        }

        if(c11>-1){
            totalChildren++;
        }
    }
}

