<!--

// 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 isBusy;
var menuActive = false;
var childPanel = false; // Open?
var childrenActive = 0;

// -------------------------------------------------------------------------------

// VALIDATE INPUT

// Get dates (v1.0) - T. Nelson '07
function getDates() {

// Outbound
outDay = document.Search.LeavingDay.options.selectedIndex + 1; // Cannot use value after menu dynamically adjusts for days
var outMonthStr = document.getElementById('LeavingMonth').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.ReturningDay.options.selectedIndex + 1; // Cannot use value after menu dynamically adjusts for days
var inMonthStr = document.getElementById('ReturningMonth').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 departure 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 departure and return dates cannot be the same day.');
	return false;
} else if (inDate.getTime() < outDate.getTime()) {
	alert('Your return date cannot be before your departure 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.LeavingMonth.options.selectedIndex
	document.Search.ReturningMonth.options.selectedIndex = depMonth
	validDate('Returning');
	menuActive = true // Only run once
	}
}

// Submit form
function submitSearch() {
	
	// Check data
	var dataCheck = searchValidate();
	
	// If valid then submit
	if (dataCheck == true) {
		document.Search.submit();
	}
}

// -------------------------------------------------------------------------------

// DYNAMICALLY DISPLAY MENUS

// Where children are travelling get ages (v1.0) - T. Nelson '07
function childAges() {
// More than one child travelling?
children = document.Search.Children.options.selectedIndex;
// Is panel open?
if (childPanel == true) {
	// No children?
	if (children == 0) {
		// Slide panel up
		Effect.SlideUp('childAges',{duration:0.5});
		// Hide all menus
		setTimeout ('childHide()',1000);
		// Set active children to zero
		childrenActive = 0
		// Mark panel as closed
		childPanel = false;
	} else { // Has the number of children changed?
		if (children > childrenActive) { // Adding
			// Set transition type (appear)
			childToggle(children,0);
		} else if (children < childrenActive) { // Removing
			// Set transition type (disappear)
			childToggle(children,1);
		}
	}
// Panel is closed
} else {
	// More than zero children?
	if (children > 0) {
		// Show as many child menus as we need - no need to fade as the panel is hidden
		childShow(children);
		// Slide panel down
		Effect.SlideDown('childAges',{duration:0.5});
		// Set active children
		childrenActive = children;
		// Mark panel as open
		childPanel = true;
	}
}
}

function childHide() {
var i
for (i = 1; i <= 7; i++) {
var activeDiv
activeDiv = 'child' + i
document.getElementById(activeDiv).style.display = 'none';
}
}

function childShow(num) {
var i
for (i = 1; i <= num; i++) {
var activeDiv;
activeDiv = 'child' + i;
document.getElementById(activeDiv).style.display = 'block';
}
}

function childToggle(num,trans) {
// Currently showing
var i
var activeDiv
// Adding or removing?
if (trans == 0) { // Add
	for (i = childrenActive + 1; i <= num; i++) {
	// Show panels
	activeDiv = 'child' + i
	document.getElementById(activeDiv).style.display = 'block';
	//Effect.Appear(activeDiv,{duration:0.5});
	}
} else { // Remove
	for (i = num + 1; i <= childrenActive; i++) {
	// Hide panels
	activeDiv = 'child' + i
	document.getElementById(activeDiv).style.display = 'none';
	//Effect.Fade(activeDiv,{duration:0.5});
	}
}
childrenActive = num;
}

// -->