var defaultChildAges = [[0,1],[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]];
function updateAgeSelect(selectElement, ageArray){
    var currentItem = selectElement[selectElement.selectedIndex].value;
    selectElement.length=0;
    var i=0;
    for(var i=0; i<ageArray.length; i++){
        selectElement.options[selectElement.options.length]=new Option(ageArray[i] + " Years", ageArray[i]);
        if(currentItem==ageArray[i]){
            selectElement.selectedIndex=i;
        }
    }
}
function updateChildAges(childSelectName, infantSelectName, AgeTextCell, ageSelect, prefix,childAgesArray){
	alert(childSelectName + ' ' + infantSelectName + ' ' + AgeTextCell + ' ' + ageSelect + ' ' + prefix + ' ' + childAgesArray);
    if(childAgesArray==null){
        childAgesArray = defaultChildAges;
    }
    var childSelect = document.getElementById(prefix+childSelectName);
    var infantSelect = document.getElementById(prefix+infantSelectName);
    var childAgeHeading = document.getElementById(prefix+AgeTextCell);
	alert(prefix + ' ' + childSelectName + ' ' + infantSelectName + ' ' + childAgeHeading);
    if(childSelect!=null && infantSelect!=null){
        var childCount = (childSelect.value-0) + (infantSelect.value-0);
        if(childAgeHeading!=null){
            if(childCount>0){
                childAgeHeading.style.display="";
            } else {
                childAgeHeading.style.display="none";
            }
        }
        for(i=0; i<100; i++){
            var title = document.getElementById(prefix+"AgeTitle"+i);
            var select = document.getElementById(prefix+ageSelect+i);
            if(title==null && select==null) {break;}
            if(i<childCount){
                if(title!=null) title.style.display="";
                if(select!=null) select.style.display="";
                updateAgeSelect(select, i<(childSelect.value-0) ? childAgesArray[1] : childAgesArray[0]);            } else {
                if(title!=null) title.style.display="none";
                if(select!=null) select.style.display="none";
            }
        }
    }
}

function swapPanel(toPanel){ 
//alert(toPanel);    
        var holidayElement = document.getElementById("holidaySearch");
        var flightElement = document.getElementById("flightSearch");
        var hotelElement = document.getElementById("hotelSearch");
        var packageElement = document.getElementById("sabsbox");
        var holidayForm = document.getElementById("holidaysDO");
        var holidayResorts = document.getElementById("holidayResorts");
        var holidayAd = document.getElementById("holidays");
        var flightAd = document.getElementById("flights");
        var hotelAd = document.getElementById("hotels");
        var packageAd = document.getElementById("holidays");
        var longAd = document.getElementById("worldwide");
        var cityAd = document.getElementById("citybreaks");
        var skiAd = document.getElementById("ski");
		holidayResorts.options.length=0;

    	holidayElement.style.display="none";
    	flightElement.style.display="none";
    	hotelElement.style.display="none";
    	packageElement.style.display="none";
		holidayResorts.options[0]=new Option("Loading", "Loading", true, false);
    	holidayAd.style.display="none";
    	flightAd.style.display="none";
    	hotelAd.style.display="none";
    	packageAd.style.display="none";
    	longAd.style.display="none";
    	cityAd.style.display="none";
    	skiAd.style.display="none";
		
		if (toPanel=="holidaySearch") {
        	holidayElement.style.display="block";
        	holidayAd.style.display="block";
			holidayForm.action="/Limerick/holiday/Search.do";
			htmlData('/Limerick/common/DropListData.do', 'selectName=flightAdults&selectName=flightChildren&selectName=flightInfants&selectName=flightSeniors&selectName=flightDepartureDateDay&selectName=flightDepartureDateMonth&selectName=flightReturnDateDay&selectName=flightReturnDateMonth&selectName=flightDepartureOutLocations&selectName=flightDestinationOutLocations&selectName=flightDepartureInLocations&selectName=flightDestinationInLocations&selectName=hotelAdults&selectName=hotelChildren&selectName=hotelInfants&selectName=hotelSeniors&selectName=hotelCheckInDateDay&selectName=hotelCheckInDateMonth&selectName=hotelDuration&selectName=hotelResorts&selectName=holidayAdults&selectName=holidayChildren&selectName=holidayInfants&selectName=holidaySeniors&selectName=holidayCheckInDateDay&selectName=holidayCheckInDateMonth&selectName=holidayDuration&selectName=holidayDepartureOutLocations&selectName=holidayResorts');
			stateChanged();
		} else  if (toPanel=="flightSearch") {
        	flightElement.style.display="block";
        	flightAd.style.display="block";
			new AlltriaAjax.AutoComplete("destinationOutLocation", function() {return "/Limerick/flights/AirportSearch.do?pattern=" + this.text.value;}, { minChars: 3 });
			stateChanged();
		} else  if (toPanel=="hotelSearch") {
        	hotelElement.style.display="block";
        	hotelAd.style.display="block";
		} else  if (toPanel=="packageSearch") {
    		packageElement.style.display="block";
        	holidayAd.style.display="block";
		} else  if (toPanel=="citySearch") {
	    	holidayElement.style.display="block";
        	cityAd.style.display="block";
			holidayForm.action="/CityBreaks/holiday/Search.do";
			htmlData('/CityBreaks/common/DropListData.do', 'selectName=flightAdults&selectName=flightChildren&selectName=flightInfants&selectName=flightSeniors&selectName=flightDepartureDateDay&selectName=flightDepartureDateMonth&selectName=flightReturnDateDay&selectName=flightReturnDateMonth&selectName=flightDepartureOutLocations&selectName=flightDestinationOutLocations&selectName=flightDepartureInLocations&selectName=flightDestinationInLocations&selectName=hotelAdults&selectName=hotelChildren&selectName=hotelInfants&selectName=hotelSeniors&selectName=hotelCheckInDateDay&selectName=hotelCheckInDateMonth&selectName=hotelDuration&selectName=hotelResorts&selectName=holidayAdults&selectName=holidayChildren&selectName=holidayInfants&selectName=holidaySeniors&selectName=holidayCheckInDateDay&selectName=holidayCheckInDateMonth&selectName=holidayDuration&selectName=holidayDepartureOutLocations&selectName=holidayResorts');
			stateChanged();
		} else  if (toPanel=="worldSearch") {
	    	holidayElement.style.display="block";
        	longAd.style.display="block";
			holidayForm.action="/LongHaul/holiday/Search.do";
			htmlData('/LongHaul/common/DropListData.do', 'selectName=flightAdults&selectName=flightChildren&selectName=flightInfants&selectName=flightSeniors&selectName=flightDepartureDateDay&selectName=flightDepartureDateMonth&selectName=flightReturnDateDay&selectName=flightReturnDateMonth&selectName=flightDepartureOutLocations&selectName=flightDestinationOutLocations&selectName=flightDepartureInLocations&selectName=flightDestinationInLocations&selectName=hotelAdults&selectName=hotelChildren&selectName=hotelInfants&selectName=hotelSeniors&selectName=hotelCheckInDateDay&selectName=hotelCheckInDateMonth&selectName=hotelDuration&selectName=hotelResorts&selectName=holidayAdults&selectName=holidayChildren&selectName=holidayInfants&selectName=holidaySeniors&selectName=holidayCheckInDateDay&selectName=holidayCheckInDateMonth&selectName=holidayDuration&selectName=holidayDepartureOutLocations&selectName=holidayResorts');
		} else  if (toPanel=="skiSearch") {
		   	holidayElement.style.display="block";
        	skiAd.style.display="block";
			holidayForm.action="/Ski/holiday/Search.do";
			htmlData('/Ski/common/DropListData.do', 'selectName=flightAdults&selectName=flightChildren&selectName=flightInfants&selectName=flightSeniors&selectName=flightDepartureDateDay&selectName=flightDepartureDateMonth&selectName=flightReturnDateDay&selectName=flightReturnDateMonth&selectName=flightDepartureOutLocations&selectName=flightDestinationOutLocations&selectName=flightDepartureInLocations&selectName=flightDestinationInLocations&selectName=hotelAdults&selectName=hotelChildren&selectName=hotelInfants&selectName=hotelSeniors&selectName=hotelCheckInDateDay&selectName=hotelCheckInDateMonth&selectName=hotelDuration&selectName=hotelResorts&selectName=holidayAdults&selectName=holidayChildren&selectName=holidayInfants&selectName=holidaySeniors&selectName=holidayCheckInDateDay&selectName=holidayCheckInDateMonth&selectName=holidayDuration&selectName=holidayDepartureOutLocations&selectName=holidayResorts');
			stateChanged();
		}
		return false;
    }
