YAHOO.util.Event.onContentReady("arrival", function () {

        function onButtonClick() {

            /*
                 Create a Calendar instance and render it into the body 
                 element of the Overlay.
            */

            var oCalendar = new YAHOO.widget.Calendar("buttoncalendar", oCalendarMenuArrival.body.id);

            oCalendar.render();



            /* 
                Subscribe to the Calendar instance's "changePage" event to 
                keep the Overlay visible when either the previous or next page
                controls are clicked.
            */

            oCalendar.changePageEvent.subscribe(function () {
                
                window.setTimeout(function () {

                    oCalendarMenuArrival.show();
                
                }, 0);
            
            });


            /*
                Subscribe to the Calendar instance's "select" event to 
                update the Button instance's label when the user
                selects a date.
            */

            oCalendar.selectEvent.subscribe(function (p_sType, p_aArgs) {

				var aDate,
					nDay,
					nMonth,
					nYear;

				if (p_aArgs) {
					
					aDate = p_aArgs[0][0];
					nDay = aDate[2];
					nMonth = aDate[1];
					nYear = aDate[0];

					oButtonArrival.set("label", (nDay + "/" + nMonth + "/" + nYear));


					// Sync the Calendar instance's selected date with the date form fields

					YAHOO.util.Dom.get("dayArrival").selectedIndex = (nDay - 1);
					YAHOO.util.Dom.get("monthArrival").selectedIndex = (nMonth - 1);
					YAHOO.util.Dom.get("yearArrival").value = nYear;

				}
				
				oCalendarMenuArrival.hide();
            
            });


            /*
                 Unsubscribe from the "click" event so that this code is 
                 only executed once
            */

            this.unsubscribe("click", onButtonClick);
        
        }


		var oDateFields = YAHOO.util.Dom.get("arrival");
		oDayField = YAHOO.util.Dom.get("dayArrival"),
			oMonthField = YAHOO.util.Dom.get("monthArrival"),
			oYearField = YAHOO.util.Dom.get("yearArrival");


		/*
			 Hide the form fields used for the date so that they can be replaced by the 
			 calendar button.
		*/

		
		oDayField.style.display = "none";
		oMonthField.style.display = "none";
		oYearField.style.display = "none";


        // Create a Overlay instance to house the Calendar instance

        var oCalendarMenuArrival = new YAHOO.widget.Overlay("calendarmenu", { visible: false });


        // Create a Button instance of type "menu"

        var oButtonArrival = new YAHOO.widget.Button({ 
                                        type: "menu", 
                                        id: "calendarpickerArrival", 
                                        label: "Choose A Date", 
                                        menu: oCalendarMenuArrival, 
                                        container: "arrival" });


		oButtonArrival.on("appendTo", function () {
		
			/*
				 Create an empty body element for the Overlay instance in order 
				 to reserve space to render the Calendar instance into.
			*/
	
			oCalendarMenuArrival.setBody("&#32;");
	
			oCalendarMenuArrival.body.id = "calendarcontainerArrival";
	
	
			// Render the Overlay instance into the Button's parent element
	
			oCalendarMenuArrival.render(this.get("container"));
		
		});


        /*
            Add a listener for the "click" event.  This listener will be
            used to defer the creation the Calendar instance until the 
            first time the Button's Overlay instance is requested to be displayed
            by the user.
        */        

        oButtonArrival.on("click", onButtonClick);
    
    });


























































    YAHOO.util.Event.onContentReady("departure", function () {

        function onButtonClick() {

            /*
                 Create a Calendar instance and render it into the body 
                 element of the Overlay.
            */

            var oCalendar = new YAHOO.widget.Calendar("buttoncalendar", oCalendarMenuDeparture.body.id);

            oCalendar.render();



            /* 
                Subscribe to the Calendar instance's "changePage" event to 
                keep the Overlay visible when either the previous or next page
                controls are clicked.
            */

            oCalendar.changePageEvent.subscribe(function () {
                
                window.setTimeout(function () {

                    oCalendarMenuDeparture.show();
                
                }, 0);
            
            });


            /*
                Subscribe to the Calendar instance's "select" event to 
                update the Button instance's label when the user
                selects a date.
            */

            oCalendar.selectEvent.subscribe(function (p_sType, p_aArgs) {

				var aDate,
					nDay,
					nMonth,
					nYear;

				if (p_aArgs) {
					
					aDate = p_aArgs[0][0];

					nDay = aDate[2];
					nMonth = aDate[1];
					nYear = aDate[0];

					oButtonDeparture.set("label", (nDay + "/" + nMonth + "/" + nYear));


					// Sync the Calendar instance's selected date with the date form fields

					YAHOO.util.Dom.get("dayDeparture").selectedIndex = (nDay - 1);
					YAHOO.util.Dom.get("monthDeparture").selectedIndex = (nMonth - 1);
					YAHOO.util.Dom.get("yearDeparture").value = nYear;

				}
				
				oCalendarMenuDeparture.hide();
            
            });


            /*
                 Unsubscribe from the "click" event so that this code is 
                 only executed once
            */

            this.unsubscribe("click", onButtonClick);
        
        }


		var oDateFields = YAHOO.util.Dom.get("departure");
			oDayField = YAHOO.util.Dom.get("dayDeparture"),
			oMonthField = YAHOO.util.Dom.get("monthDeparture"),
			oYearField = YAHOO.util.Dom.get("yearDeparture");


		/*
			 Hide the form fields used for the date so that they can be replaced by the 
			 calendar button.
		*/

		oDayField.style.display = "none";
		oMonthField.style.display = "none";
		oYearField.style.display = "none";


        // Create a Overlay instance to house the Calendar instance

        var oCalendarMenuDeparture = new YAHOO.widget.Overlay("calendarmenu", { visible: false });


        // Create a Button instance of type "menu"

        var oButtonDeparture = new YAHOO.widget.Button({ 
                                        type: "menu", 
                                        id: "calendarpickerDeparture", 
                                        label: "Choose A Date", 
                                        menu: oCalendarMenuDeparture, 
                                        container: "departure" });


		oButtonDeparture.on("appendTo", function () {
		
			/*
				 Create an empty body element for the Overlay instance in order 
				 to reserve space to render the Calendar instance into.
			*/
	
			oCalendarMenuDeparture.setBody("&#32;");
	
			oCalendarMenuDeparture.body.id = "calendarcontainer";
	
	
			// Render the Overlay instance into the Button's parent element
	
			oCalendarMenuDeparture.render(this.get("container"));
		
		});


        /*
            Add a listener for the "click" event.  This listener will be
            used to defer the creation the Calendar instance until the 
            first time the Button's Overlay instance is requested to be displayed
            by the user.
        */        

        oButtonDeparture.on("click", onButtonClick);
    
    });
