		// <![CDATA[  


		// An object that ties the two datePickers together 
		var bookingPod = window.bookingPod = {
				// Default departure cursor date : todays date + 7
				"OUTWARD_CURSOR"    : 1,
				// Default return cursor date : departure date + 7
				"RETURN_CURSOR"     : 1, 
				// Min days between departure and return dates      
				"MIN_DAYS_BETWEEN"  : 1,                     
				// Default messages
				"MESSAGES"          : { "MD1" : "", "MD2" : "" },
				// Maximum days ahead that a flight can be booked
				"MAX_DATE_LIMIT"    : 360,
				// Minimum days ahead that a flight can be booked
				"MIN_DATE_LIMIT"    : 0,
				
				
				createYYYYMMDDString: function(dt) {
						return dt ? dt.getFullYear() + String(dt.getMonth() + 1 < 10 ? "0" + (dt.getMonth() + 1) : dt.getMonth() + 1) + (dt.getDate() < 10 ? "0" + dt.getDate() : dt.getDate()) : "";                                                             
				},
				checkOutwardDate: function(cbObj) {              
						// Show the date 
						bookingPod.showEnglishDate(cbObj);                
						
						// An invalid or no outward date was entered
						if(!cbObj.date) {                                            
								// Set the default cursor dates on the return element
								var today       = new Date(),
									defaultOut  = new Date(today.getFullYear(), today.getMonth(), today.getDate() + bookingPod.OUTWARD_CURSOR),
									defaultRet  = new Date(defaultOut.getFullYear(), defaultOut.getMonth(), defaultOut.getDate() + bookingPod.RETURN_CURSOR),                                                                           
									rangeHigh   = new Date(today.getFullYear(), today.getMonth(), today.getDate() + bookingPod.MAX_DATE_LIMIT),                
									rangeLow    = new Date(today.getFullYear(), today.getMonth(), today.getDate() + bookingPod.MIN_DATE_LIMIT);                
								
								// Reset the outward default ranges        
								datePickerController.setRangeHigh("MD2", bookingPod.createYYYYMMDDString(rangeHigh));
								datePickerController.setRangeLow("MD2", bookingPod.createYYYYMMDDString(rangeLow));  
								 
								// Set the outward cursor to be the default value : today's date + OUTWARD_CURSOR     
								datePickerController.setCursorDate("MD1", bookingPod.createYYYYMMDDString(defaultOut)); 
														 
								// If no return date set then reset the cursor position to be today's date + OUTWARD_CURSOR + RETURN_CURSOR  
								if(!datePickerController.getSelectedDate("MD2")) {                                                                                                                                               
										datePickerController.setCursorDate("MD2", bookingPod.createYYYYMMDDString(defaultRet)); 
								};                                             
								
								return;
						};                                           
						
						// Set the rangeLow of the return to be the outward date + MIN_DAYS_BETWEEN                                               
						datePickerController.setRangeLow("MD2", bookingPod.createYYYYMMDDString(new Date(cbObj.yyyy, +cbObj.mm - 1, (+cbObj.dd + bookingPod.MIN_DAYS_BETWEEN), 5, 0, 0, 0)));  
						
						// If no valid return date set 
						if(!datePickerController.getSelectedDate("MD2")) {                         
								// Set the return date to be departure date + RETURN_CURSOR                        
								datePickerController.setSelectedDate("MD2", bookingPod.createYYYYMMDDString(new Date(cbObj.yyyy, +cbObj.mm - 1, (+cbObj.dd + bookingPod.RETURN_CURSOR), 5, 0, 0, 0)));  
						};
				},
				
				checkReturnDate: function(cbObj) {
						// Set the return cursor date if none set
						if(!cbObj.date) {                          
								var depDate     = datePickerController.getSelectedDate("MD1") || new Date();                                              
								// Set the outward cursor to be the default value : todays date + OUTWARD_CURSOR     
								datePickerController.setCursorDate("MD2", bookingPod.createYYYYMMDDString(new Date(depDate.getFullYear(), depDate.getMonth(), depDate.getDate() + bookingPod.RETURN_CURSOR)));                   
						}; 
						
						// Show the date                 
						bookingPod.showEnglishDate(cbObj);                
				},
				
				showEnglishDate : function(argObj) {                
						// Grab the span & get a more English-ised version of the selected date
						var spn = document.getElementById(argObj.id + "-EnglishDate"),
							formattedDate = !(argObj.date == null) ? datePickerController.printFormattedDate(argObj.date, "l-cc-sp-d-S-sp-F-sp-Y", false) || bookingPod.MESSAGES[argObj.id] : bookingPod.MESSAGES[argObj.id];
										
						while(spn.firstChild) spn.removeChild(spn.firstChild);
							  
						// Note: The 3rd argument to printFormattedDate is a Boolean value that 
						// instructs the script to use the imported locale (true) or not (false)
						// when creating the dates. In this case, I'm not using the imported locale
						// as I've used the "S" format mask, which returns the English ordinal
						// suffix for a date e.g. "st", "nd", "rd" or "th" and using an
						// imported locale would look strange if an English suffix was included        
						
						// Add a new text node containing our formatted date
						//spn.appendChild(document.createTextNode(formattedDate));
				}
		}

       
        var today       = new Date();        
                         
        document.getElementById("DD1").selectedIndex = today.getDate();
        
        var depElem = document.getElementById("MD1"),
            opts = depElem.options,
            dt = ((today.getMonth() + 1) < 10 ? "0" + (today.getMonth() + 1) : (today.getMonth() + 1)) + "" + today.getFullYear();
            
        for(var i = 0, opt; opt = opts[i]; i++) {
                if(opt.value == dt) {
                        opt.selected = true;
                        break;
                };
        }
        
        // Default options
        var opts = {                             
                splitDate:true, 
                staticPos:false,
                fillGrid:true,
                constrainSelection:false,                
                noTodayButton:true,
                rangeLow:bookingPod.createYYYYMMDDString(new Date(today.getFullYear(), today.getMonth(), today.getDate() + bookingPod.MIN_DATE_LIMIT)),
                rangeHigh:bookingPod.createYYYYMMDDString(new Date(today.getFullYear(), today.getMonth(), today.getDate() + bookingPod.MAX_DATE_LIMIT)),                       
                callbackFunctions:{"create":[bookingPod.checkReturnDate],"dateset":[bookingPod.checkReturnDate]},                                                   
                statusFormat:"l-cc-sp-d-S-sp-F-sp-Y"      
        };  
        
        // Create Slave first
        opts.formElements = { "MD2":"m-Y", "DD2":"j" };                        
        datePickerController.createDatePicker(opts);
        
        // Master second
        opts.formElements = { "MD1":"m-Y", "DD1":"j" };   
        opts.callbackFunctions = {"create":[bookingPod.checkOutwardDate],"dateset":[bookingPod.checkOutwardDate]};
                         
        datePickerController.createDatePicker(opts);
// ]]>

