// Function to add more than one funtion in the onload event
function addLoadEvent(func){
    var oldonload = window.onload;
    if(typeof window.onload != 'function') window.onload = func;
    else window.onload = function() {
        oldonload();
        func();
    }
}

var maxRoom = 8;
var maxKids = 6;
var nbRoom;
function SetRoomList() 
{
    var childRoomSelect = new Array(maxRoom);
    roomList = $S('#w_RoomSelect').getElementsByTagName('select');
    nbRoom = roomList[0].selectedIndex + 1;
    $("w_PACS_RoomFirst").style.visibility = (nbRoom>1) ? "visible":"hidden";
    for (var i=1;i<=maxRoom;i++)
    {
        childRoomSelect[i-1] = $S('#w_PACS_ChildRoom'+i).getElementsByTagName('select');
    }
    for(var i=1; i<=maxRoom; i++){
        $("w_PACS_Room"+i).style.display = (i>nbRoom) ? "none" :"block";
        $('w_KidAge').style.display = (  childRoomSelect[0][0].selectedIndex !=0 || 
                                        (childRoomSelect[1][0].selectedIndex !=0 && nbRoom > 1) || 
                                        (childRoomSelect[2][0].selectedIndex !=0 && nbRoom > 2) || 
                                        (childRoomSelect[3][0].selectedIndex !=0 && nbRoom > 3) || 
                                        (childRoomSelect[4][0].selectedIndex !=0 && nbRoom > 4) || 
                                        (childRoomSelect[5][0].selectedIndex !=0 && nbRoom > 5) || 
                                        (childRoomSelect[6][0].selectedIndex !=0 && nbRoom > 6) || 
                                        (childRoomSelect[7][0].selectedIndex !=0 && nbRoom > 7)
                                       ) ? "block":"none";
        $('w_KidAge' + i).style.display = ((childRoomSelect[i-1][0].selectedIndex != 0) && (i<=nbRoom)) ? "block":"none";
        
        for(var j=1; j<=maxKids;j++)
        {
            if ($('w_Kid' + i + j) != null)
            {
                $('w_Kid' + i + j).style.display =(childRoomSelect[i-1][0].selectedIndex >= j) ? "block" :"none";
            }
        }
    }

	// Fixing 53045 - options "hidding" behind footer
	fix2ColHotelLayout();

}
function SetPCDisplay()
{
    var ele = $S('#w_Product_Choice').getElementsByTagName('input');
    if ($('w_City_Panel') != null && ele[0]!= null) {$('w_City_Panel').style.display = (ele[0].checked) ? "block" : "none";}
    if ($('w_Airport_Panel') != null && ele[1]!= null) {$('w_Airport_Panel').style.display = (ele[1].checked) ? "block" : "none";}
    if ($('w_Attraction_Panel') != null && ele[2]!= null) {$('w_Attraction_Panel').style.display = (ele[2].checked) ? "block" : "none";}
}

function ProductChoiceEvent()
{
    // Top Radio Button Events
    var obj =$S('#w_Product_Choice');
    $S('#w_Product_Choice').getElementsByTagName('div').action({
        onclick: function() {
            var ele = $S('#w_Product_Choice').getElementsByTagName('input');
            $('w_City_Panel').style.display = (this.id=='HW_w_PC_w_Product_Choice1') ? "block":"none";
            $('w_Airport_Panel').style.display = (this.id=='HW_w_PC_w_Product_Choice2') ? "block":"none";
            $('w_Attraction_Panel').style.display = (this.id=='HW_w_PC_w_Product_Choice3') ? "block":"none";
            ele[0].checked = (this.id=='HW_w_PC_w_Product_Choice1') ? true:false;
            ele[1].checked = (this.id=='HW_w_PC_w_Product_Choice2') ? true:false;
            ele[2].checked = (this.id=='HW_w_PC_w_Product_Choice3') ? true:false;
        }
    });
    // Top panel Text box events.
    var ele1 = $S('#w_City_Other').getElementsByTagName('input');
    var ele2 = $S('#w_Airport_Panel').getElementsByTagName('input');
    var ele3 = $S('#w_Attraction_Panel').getElementsByTagName('input');
    
    if (ele1[1] != null && ele2[0] != null && ele3[0] != null) {
    ele1[1].onchange = function () { ele2[0].value = ele1[1].value; ele3[0].value = ele1[1].value;};
    ele2[0].onchange = function () { ele1[1].value = ele2[0].value; ele3[0].value = ele2[0].value;
    if($S('#w_City_Other').getElementsByTagName('input')[0] != null)
    {
        $S('#w_City_Other').getElementsByTagName('input')[0].checked = true;uncheckList();
    }
    };
    ele3[0].onchange = function () { ele1[1].value = ele3[0].value; ele2[0].value = ele3[0].value;
    if($S('#w_City_Other').getElementsByTagName('input')[0] != null)
    {
    $S('#w_City_Other').getElementsByTagName('input')[0].checked = true;uncheckList();
    }
    };
  }
    var isIE = false;
    if (navigator.appName.substring(0,3) == "Mic") isIE = true;
    $S('#w_City_Panel').getElementsByTagName('TD').action({
        onclick: function () { 
            if (isIE)
            {
                if (ele2[0] != null )
                {ele2[0].value = this.innerText;}
                if (ele3[0] != null )
                {ele3[0].value = this.innerText;}
            }
            else
            {
                if (ele2[0] != null)
                {ele2[0].value = this.textContent;}
                if (ele3[0] != null )
                {ele3[0].value = this.textContent;}
            }
        }
    });
    
    // City Radio Button Event
    var cityListInputs = $S('#w_City_Panel').getElementsByTagName("table").getElementsByTagName("input");
    var cityName = $S('#w_City_Other').getElementsByTagName("input");
    if(cityName[0]!=null){ cityName[1].onfocus = uncheckList; }
    if(cityName[1]!=null){ cityName[0].onclick = uncheckList; }
    cityListInputs.action({onclick: function(){cityName[0].checked = false}});

    function uncheckList(){
        cityListInputs.each(function(input){input.checked = false;})
        cityName[0].checked = true;
    }
    SetPCDisplay();
}

function RoomListEvent()
{
    // Room Number Events
    roomList = $S('#w_RoomSelect').getElementsByTagName('select');
    if (roomList[0]!=null) {roomList[0].onchange = SetRoomList};
    // Child Age Event (triggered by child number)
    var childRoomSelect = new Array(maxRoom);
    for (var i=1;i<=maxRoom;i++)
    {
        childRoomSelect[i-1] = $S('#w_PACS_ChildRoom'+i).getElementsByTagName('select');
    }
    childRoomSelect.each(function(select)
    {
        select.action({
            onchange: function()
            {
               var selected = this;
               for (var i=1;i<=maxRoom;i++)
               {
                    idRoom = selected.id.charAt(selected.id.length-1);
                    $('w_KidAge').style.display = (  childRoomSelect[0][0].selectedIndex !=0 || 
                                                    (childRoomSelect[1][0].selectedIndex !=0 && nbRoom > 1) || 
                                                    (childRoomSelect[2][0].selectedIndex !=0 && nbRoom > 2) || 
                                                    (childRoomSelect[3][0].selectedIndex !=0 && nbRoom > 3) || 
                                                    (childRoomSelect[4][0].selectedIndex !=0 && nbRoom > 4) || 
                                                    (childRoomSelect[5][0].selectedIndex !=0 && nbRoom > 5) || 
                                                    (childRoomSelect[6][0].selectedIndex !=0 && nbRoom > 6) || 
                                                    (childRoomSelect[7][0].selectedIndex !=0 && nbRoom > 7)
                                                   ) ? "block":"none";
                    $('w_KidAge' + idRoom).style.display = (selected.selectedIndex !=0) ? "block":"none";
                    for(var j=1; j<=maxKids;j++)
                    {
                        $('w_Kid' + idRoom + j).style.display =(j>selected.selectedIndex) ?"none" :"block";
                    }
                }
                // Fixing 53045 - options "hidding" behind footer
	            fix2ColHotelLayout();
            }
        });
    });
}


// Function that makes main col height same as a-col
function fix2ColHotelLayout() {
	var mcol = document.getElementById('l_2Col_MainCol');
    var container = document.getElementById('l_2Col_MainCol_Container');
	try {
		if((mcol.offsetHeight - 10) < container.offsetHeight) {
			mcol.style.height = container.offsetHeight + 20;
		}
	} catch(e) {
	}
	
}

addLoadEvent(fix2ColHotelLayout);