<!--

// GLOBAL VARIABLES

var outDate = new Date();
var inDate = new Date();
var now = new Date(); // Date now
var duration = '';
var oneDay=1000*60*60*24; // Set 1 day in milliseconds
var req;
var params;
var outDay;
var outMonth;
var outYear;
var duration;
var menuActive = false;
var locationActive = false;

// -------------------------------------------------------------------------------

// VALIDATE INPUT

// Get dates (v1.0) - T. Nelson '07
function getDates() {

// Outbound
outDay = document.Search.PickupDay.options.selectedIndex + 1; // Cannot use value after menu dynamically adjusts for days
var outMonthStr = document.getElementById('PickupMonth').value;
var outMonthLength = parseInt(Len(outMonthStr))

if (outMonthLength == 6) {
		outMonth = (parseInt(Left(outMonthStr,1))-1); // Before October
	}
	else {
		outMonth = (parseInt(Left(outMonthStr,2))-1); // After October
}
	
outYear = parseInt(Right(outMonthStr,4));

outDate.setFullYear(outYear,outMonth,outDay)

// Inbound
var inDay = document.Search.DropoffDay.options.selectedIndex + 1; // Cannot use value after menu dynamically adjusts for days
var inMonthStr = document.getElementById('DropoffMonth').value;
var inMonthLength = parseInt(Len(inMonthStr))

if (inMonthLength == 6) {
		inMonth = (parseInt(Left(inMonthStr,1))-1); // Before October
	}
	else {
		inMonth = (parseInt(Left(inMonthStr,2))-1); // After October
}

var inYear = parseInt(Right(inMonthStr,4));

inDate.setFullYear(inYear,inMonth,inDay)
	
// Calculate millisecond difference between the two dates, and convert to days
duration = Math.ceil((inDate.getTime()-outDate.getTime())/(oneDay))

}

// Valid dates (v1.0) - T. Nelson '07
window.dbIE  = document.all ? true : false; // IE 4+
window.dbDOM = (document.getElementById && ! document.all) ? true : false; // All other browsers

function limitList(listObj,length) { // Limit drop menu
   var list = listObj
   if (length<(list.selectedIndex+1)) { // Reduce current selected index to new length
      list.selectedIndex=length-1; 
   }
   if (window.dbIE || window.dbDOM) { // All browsers
      if (list.options.length<length) {
         for (var i=list.options.length+1; i<=length; i++) { 
             var oOption = document.createElement('OPTION');
             if (window.dbIE) { // IE
                list.options.add(oOption);
                oOption.innerText = i;
                oOption.Value = i;
             } else if (window.dbDOM) { // Mozilla      
                oOption.text = ' '+i;
                oOption.Value = i;
                list.add(oOption,null);
             }
          }
      } 
	  else if (list.options.length>length) {
         for (var i=list.options.length; i>=length; i--) { 
             list.remove(i);
         }               
      }
  }
}

function validDate(menu) { // Set 'Day' drop menu based on month and year selected

var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31); // Days in the month

var dayMenu = menu + 'Day'
var monthMenu = menu + 'Month'

var day = parseInt(document.getElementById(dayMenu).value); 
var monthStr = document.getElementById(monthMenu).value;

// Check length of string and get month
var monthStrLength = parseInt(Len(monthStr))

if (monthStrLength == 6) {
		month = parseInt(Left(monthStr,1)); // Before October
	} 
	else {
		month = parseInt(Left(monthStr,2)); // After October
}

var year = parseInt(Right(monthStr,4));

if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { // Leap year so adjust Feb days to 29
	monthLength[1] = 29;
}

var objDay = document.getElementById(dayMenu) // Set 'Day' menu object

var listLength = monthLength[month-1] // Adjust 'Day' menu
limitList(objDay,listLength);
}

// Future dates (v1.1) - T. Nelson '06
function futureDate() {

// Get dates
getDates();
	
// Check departure date is in the future	
if (now.getTime() > outDate.getTime()) {
	alert('Your pick up date cannot be in the past.');
	return false;
}

// Check flight type, duration and return date
if (duration == 0) { // Duration is greater than zero
	alert('Your pick up and drop off dates cannot be the same day.');
	return false;
} else if (inDate.getTime() < outDate.getTime()) {
	alert('Your drop off date cannot be before your pick up date.');
	return false;
}

return true;
}

// Validate form submission (v1.0) - T. Nelson '06
function searchValidate() {
return futureDate();
return true;
}

// If second date menu is toggled first then don't change first menu 
function dateChanged() {
	menuActive = true
}

// On the first menu change jump the month forward to help out
function matchDate() {
if (menuActive == false) {
	var depMonth = document.Search.PickupMonth.options.selectedIndex
	document.Search.DropoffMonth.options.selectedIndex = depMonth
	validDate('Dropoff');
	menuActive = true // Only run once
	}
}

// If second location menu is toggled first then don't change first menu 
function locationChanged() {
	locationActive = true
}

// On the first menu change jump the month forward to help out
function matchLocation() {
if (locationActive == false) {
	var pickupLocation = document.Search.Pickup.options.selectedIndex
	document.Search.Dropoff.options.selectedIndex = pickupLocation
	locationActive = true // Only run once
	}
}

// Submit form
function submitSearch() {
	
	// Check data
	var dataCheck = searchValidate();
	
	// If valid then submit
	if (dataCheck == true) {
		alert('You are now leaving Disneyworld.co.uk');
		document.Search.submit();
	}
}

// Fire layout function on page load - CAR ONLY
function carHire() {
// Set departure date 'Day' menu length based on month
validDate('Pickup');
// Set departure date 'Day' menu length based on month
validDate('Dropoff');
}

// -->