/**
 * @author leonardomelendez
 */

                var currentTime = new Date();
				var todayString = (currentTime.getMonth()+1) + "/" + (currentTime.getDate()) + "/" + currentTime.getFullYear();
				var todayString_plus_2 = (currentTime.getMonth()+1) + "/" + (currentTime.getDate()+2) + "/" + currentTime.getFullYear();
				
 
    YAHOO.util.Event.onDOMReady(function(){

        var Event = YAHOO.util.Event,
            Dom = YAHOO.util.Dom,
            dialog1,dialog2,
            calendar1,calendar2;

        var showBtn1 = Dom.get("pickup");

        Event.on(showBtn1, "click", function() {

            // Lazy Dialog Creation - Wait to create the Dialog, and setup document click listeners, until the first time the button is clicked.
            if (!dialog1) {

                // Hide Calendar if we click anywhere in the document other than the calendar
                Event.on(document, "click", function(e) {
                    var el = Event.getTarget(e);
                    var dialogEl = dialog1.element;
                    if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn1 && !Dom.isAncestor(showBtn1, el)) {
                        dialog1.hide();
                    }
                });

                function resetHandler() {
                    // Reset the current calendar page to the select date, or 
                    // to today if nothing is selected.
                    var selDates = calendar1.getSelectedDates();
                    var resetDate;
        
                    if (selDates.length > 0) {
                        resetDate = selDates[0];
                    } else {
                        resetDate = calendar1.today;
                    }
        
                    calendar1.cfg.setProperty("pagedate", resetDate);
                    calendar1.render();
                }
        
                function closeHandler() {
                    dialog1.hide();
                }

                dialog1 = new YAHOO.widget.Dialog("container1", {
                    //visible:false,
                    context:["pickup", "tl", "bl"],
                    //buttons:[ {text:"Reset", handler: resetHandler, isDefault:true}, {text:"Close", handler: closeHandler}],
                    draggable:false,
                    close:true
                });
				
                //dialog1.setHeader('Select pick-up date:');
                dialog1.setBody('<div id="cal1"></div>');
                dialog1.render(document.body);

                dialog1.showEvent.subscribe(function() {
                    if (YAHOO.env.ua.ie) {
                        // Since we're hiding the table using yui-overlay-hidden, we 
                        // want to let the dialog know that the content size has changed, when
                        // shown
                        dialog1.fireEvent("changeContent");
                    }
                });
            }

            
			
			// Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
            if (!calendar1) {

				
				calendar1 = new YAHOO.widget.CalendarGroup("cal1", { pages:2, mindate: todayString, selected: todayString,
                    iframe:false,          // Turn iframe off, since container has iframe support.
                    hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
                });
                calendar1.render();

                calendar1.selectEvent.subscribe(function() {
                    if (calendar1.getSelectedDates().length > 0) {

                        var selDate = calendar1.getSelectedDates()[0];

                        // Pretty Date Output, using Calendar's Locale values: Friday, 8 February 2008
                        //var wStr = calendar1.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];
                        //var mStr = calendar1.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
						var mStr = selDate.getMonth() + 1;
						var dStr = selDate.getDate();
                        var yStr = selDate.getFullYear();
						        
                        Dom.get("pickup").value = mStr + "/" + dStr + "/" + yStr;
                    } else {
                        Dom.get("pickup").value = "";
                    }
                    dialog1.hide();
                });

                calendar1.renderEvent.subscribe(function() {
                    // Tell Dialog it's contents have changed, which allows 
                    // container to redraw the underlay (for IE6/Safari2)
                    dialog1.fireEvent("changeContent");
                });
            }

            var seldate = calendar1.getSelectedDates();

            if (seldate.length > 0) {
                // Set the pagedate to show the selected date if it exists
                calendar1.cfg.setProperty("pagedate", seldate[0]);
                calendar1.render();
            }
			dialog1.show();	
        });
		//------
		
		
		var showBtn2 = Dom.get("dropoff");

        Event.on(showBtn2, "click", function() {

            // Lazy Dialog Creation - Wait to create the Dialog, and setup document click listeners, until the first time the button is clicked.
            if (!dialog2) {

                // Hide Calendar if we click anywhere in the document other than the calendar
                Event.on(document, "click", function(e) {
                    var el = Event.getTarget(e);
                    var dialogEl = dialog2.element;
                    if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn2 && !Dom.isAncestor(showBtn2, el)) {
                        dialog2.hide();
                    }
                });

                function resetHandler() {
                    // Reset the current calendar page to the select date, or 
                    // to today if nothing is selected.
                    var selDates = calendar2.getSelectedDates();
                    var resetDate;
        
                    if (selDates.length > 0) {
                        resetDate = selDates[0];
                    } else {
                        resetDate = calendar2.today;
                    }
        
                    calendar2.cfg.setProperty("pagedate", resetDate);
                    calendar2.render();
                }
        
                function closeHandler() {
                    dialog2.hide();
                }

                dialog2 = new YAHOO.widget.Dialog("container2", {
                    //visible:false,
                    context:["dropoff", "tl", "bl"],
                    //buttons:[ {text:"Reset", handler: resetHandler, isDefault:true}, {text:"Close", handler: closeHandler}],
                    draggable:false,
                    close:true
                });
				
                //dialog2.setHeader('Select drop-off date:');
                dialog2.setBody('<div id="cal2"></div>');
                dialog2.render(document.body);

                dialog2.showEvent.subscribe(function() {
                    if (YAHOO.env.ua.ie) {
                        // Since we're hiding the table using yui-overlay-hidden, we 
                        // want to let the dialog know that the content size has changed, when
                        // shown
                        dialog2 .fireEvent("changeContent");
                    }
                });
            }

            
			
			// Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
            if (!calendar2) {

                calendar2 = new YAHOO.widget.CalendarGroup("cal2", { pages:2, mindate: todayString_plus_2, selected: todayString,
                    iframe:false,          // Turn iframe off, since container has iframe support.
                    hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
                });
                calendar2.render();

                calendar2.selectEvent.subscribe(function() {
                    if (calendar2.getSelectedDates().length > 0) {

                        var selDate = calendar2.getSelectedDates()[0];

                        // Pretty Date Output, using Calendar's Locale values: Friday, 8 February 2008
                        //var wStr = calendar2.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];
                        //var mStr = calendar2.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
						var mStr = selDate.getMonth() + 1;
						var dStr = selDate.getDate();
                        var yStr = selDate.getFullYear();
        
                        Dom.get("dropoff").value = mStr + "/" + dStr + "/" + yStr;
                    } else {
                        Dom.get("dropoff").value = "";
                    }
                    dialog2.hide();
                });

                calendar2.renderEvent.subscribe(function() {
                    // Tell Dialog it's contents have changed, which allows 
                    // container to redraw the underlay (for IE6/Safari2)
                    dialog2.fireEvent("changeContent");
                });
            }

            var seldate = calendar2.getSelectedDates();

            if (seldate.length > 0) {
                // Set the pagedate to show the selected date if it exists
                calendar2.cfg.setProperty("pagedate", seldate[0]);
                calendar2.render();
            }
			dialog2.show();	
        });
		//------
		
		
    });
