﻿function setValuesAccordingtoAdultsSelected(lstAdult, lstChild, lstInfant){

   lstAdult = document.getElementById(lstAdult);
   lstChild = document.getElementById(lstChild);
   lstInfant = document.getElementById(lstInfant);
   
    //get id of the selected option
    var SelectedItem  = lstAdult.selectedIndex;
    
    //get value at that particular id position
    var SelectedValue = lstAdult.options[SelectedItem].value;
       
    var MaxChildOptions = 0,
        MaxInfantOptions = 0;
                                     
    switch(SelectedValue)
    {
        case "1":
            MaxChildOptions = 6;
            MaxInfantOptions = 1;
            break;
            
        case "2":
            MaxChildOptions = 5;
            MaxInfantOptions = 2;
            break;
            
        case "3":
            MaxChildOptions = 4;
            MaxInfantOptions = 3;
            break;
            
        case "4":
            MaxChildOptions = 3;
            MaxInfantOptions = 4;
            break;
            
        case "5":
            MaxChildOptions = 2;
            MaxInfantOptions = 5;
            break;
            
        case "6":
            MaxChildOptions = 1;
            MaxInfantOptions = 6;
            break;
            
        case "7":
            MaxChildOptions = 0;
            MaxInfantOptions = 6;
            break;                                 
    }
    
    //populate select options;
    populateSelectValue(lstChild, MaxChildOptions);
    populateSelectValue(lstInfant, MaxInfantOptions);
  
}

function populateSelectValue(selectId, MaxValues){
    //remove all previouse values of the select             
    clearSelectOptions(selectId);
                
    for (i=0; i<=MaxValues; i++){
        createOptionBooking(selectId, i, i, i);
    }
}


function clearSelectOptions(selectId){
    //remove all previouse values of the select 
    optionLength = selectId.options.length;
              
    for (i=(optionLength - 1); i >=0 ; i--) { 
        selectId.options[i] = null;         
    }  
}
       
function createOptionBooking(selectId, optionIndex, optionValue, optionText) {
    if (selectId) {
        selectId.options[optionIndex] = new Option();
        selectId.options[optionIndex].value = optionValue;
        selectId.options[optionIndex].innerHTML = optionText;
    }
}     
