function populateAdultsDropDown()
{
    if(document.bookForm !=null)
    {
            if (document.getElementById("room") != null)
            {
                //Getting the room occupancy number from the room drop down list
                dropdown = document.bookForm.room;
                dropdownAdults = document.bookForm.adults;

                if (dropdown.options[dropdown.selectedIndex].id !="")
                {
					idDropDownAdults = dropdownAdults.options[dropdownAdults.selectedIndex].id;
                    textDropDown = dropdown.options[dropdown.selectedIndex].id;
                    textDropDown = textDropDown.substring(textDropDown.indexOf("_")+1,textDropDown.indexOf("_")+2);

                    removeAllOptions(document.bookForm.adults);
                    
                    var i;
                    for(i=1;i<=textDropDown;i++)
                    {
                        if (i == idDropDownAdults)
						{
							addOption(document.bookForm.adults,i,i,i, true);
						}
						else
						{
							addOption(document.bookForm.adults,i,i,i, false);
						}
                    }
                }
            }
      }
}


function removeAllOptions(selectbox)
{
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
        selectbox.options[i] = null;
    }
}


function addOption(selectbox,text,value,id, selectedBool)
{
    var optn = document.createElement("OPTION");
    optn.id = id;
    optn.text = text;
    optn.value = value;
    if(selectedBool)
    {
        optn.selected = true;
    }
    selectbox.options.add(optn);
}


var myNewlist = new Array();
function backUpRooms()
{
    if(document.bookForm !=null)
    {
        if (document.getElementById("room") != null)
        {
            //backing up the values of the drop down list for the first time
             mydropDown = document.bookForm.room;
             
             for (n=0;n<mydropDown.length;n++){
              myNewlist[myNewlist.length] = mydropDown[n].value + ", " + mydropDown[n].text + "?" + mydropDown[n].id;
            } 
        }
    }
}

function onRoomChange()
{
    adultDropDown = document.bookForm.adults;
    selectdAdultId = adultDropDown.options[adultDropDown.selectedIndex].id;

 
    roomDropDown = document.bookForm.room;
    selectdRoomIdOriginal = roomDropDown.options[roomDropDown.selectedIndex].id;

    selectdRoomId = selectdRoomIdOriginal.substring(selectdRoomIdOriginal.indexOf("_")+1, selectdRoomIdOriginal.length);
    
    removeAllOptions(roomDropDown);

     for (i=0;i<myNewlist.length;i++)
    {
  
        myParsString = myNewlist[i];
        myParsString = myParsString.substring(myParsString.indexOf("_")+1,myParsString.length);

        if(selectdAdultId<=myParsString)
        {
       
            roomId = myNewlist[i];
            roomId = roomId.substring(roomId.indexOf("?")+1,roomId.length);
        
            roomName = myNewlist[i];
            roomName = roomName.substring(roomName.indexOf(",")+1,roomName.indexOf("?"));
            
            roomValue = myNewlist[i];
            roomValue = roomValue.substring(0,roomValue.indexOf(","));
            
            if(roomId == selectdRoomIdOriginal)
            {
                addOption(roomDropDown, roomName, roomValue, roomId, true);
            }
            else
            {
                addOption(roomDropDown, roomName, roomValue, roomId, false);
            }
            
        }
    } 

    
}

function checkInvalidDateStart(ddl)
{
    dropDownMonth = document.bookForm.startmonth;
    dropDownDay = document.bookForm.startday;
    dropDownYear = document.bookForm.startyear;
    
    dimDay = dropDownDay.options[dropDownDay.selectedIndex].value;
    dimMonth = dropDownMonth.options[dropDownMonth.selectedIndex].value;
    dimYear = dropDownYear.options[dropDownYear.selectedIndex].value;
    
    if (dimYear/4 == parseInt(dimYear/4))
		monthLength[1] = 29;

	if (dimDay > monthLength[dimMonth-1])
	{
	    ddl.selectedIndex = ddl.selectedIndex-1;
	    checkInvalidDateStart(ddl);
		return false;
    }

	monthLength[1] = 28;

}
function checkInvalidDateEnd(ddl)
{
    dropDownMonth = document.bookForm.endmonth;
    dropDownDay = document.bookForm.endday;
    dropDownYear = document.bookForm.endyear;
    
    dimDay = dropDownDay.options[dropDownDay.selectedIndex].value;
    dimMonth = dropDownMonth.options[dropDownMonth.selectedIndex].value;
    dimYear = dropDownYear.options[dropDownYear.selectedIndex].value;
    
    if (dimYear/4 == parseInt(dimYear/4))
		monthLength[1] = 29;

	if (dimDay > monthLength[dimMonth-1])
	{
	    ddl.selectedIndex = ddl.selectedIndex-1;
	    checkInvalidDateEnd(ddl);
		return false;
    }

	monthLength[1] = 28;

}

var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);








