function PopUp(ref)
{
	var strFeatures="toolbar=no,status=no,menubar=no,location=no"
	strFeatures=strFeatures+",scrollbars=yes,resizable=yes,height=520,width=600"

	newWin = window.open(ref,"TellObj",strFeatures);
       newWin.opener = top;
}

//Added dynamic protocal changing by Jeff Hirono on 2/6/2009
function newwindow(field) { 
var hostProtocol = (("https:" == document.location.protocol) ? "https://" : "http://");
window.open(hostProtocol+'www.montrosetravel.com/include/inc_php/AirportSearch.php?country=USA&field='+field,'mywindow','scrollbars=yes,width=550,height=485,left=200,top=120,screenX=200,screenY=120'); 
} 

function select_car_company()
{
  car_companies = document.getElementById('car_company');
  if (car_companies) {
    for (i = 0; i < car_companies.length; i++) {
      if (car_companies.options[i].value == '') {
        car_companies.options[i].selected = true;
        break;
      }
    }  
  }  
}

////

TRAVEL_DAYS_APART = 2;

//

/**********************************************************
General purpose/use JavaScript library file

**********************************************************/

function popupWindow(popupURL,height,width,windowName) {
	if (height == null) height=400;
	if (width == null) width=750;
	if (windowName == null) windowName='PopupWin';
	popupWin = window.open(popupURL, windowName,'height='+height+',width='+width+',scrollbars=yes,resizable=yes');
	popupWin.focus();
}

function popupWindowHW (popupURL,height,width) {
	//popupWin = window.open (popupURL,'PopupWin','height='+height+',width='+width+',scrollbars=yes,resizable=yes');
	//popupWin.focus ();
	popupWindow (popupURL,height,width);
}



///


// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
  var date=getDateFromFormat(val,format);
  if (date==0) { return false; }
  return true;
  }

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
  var d1=getDateFromFormat(date1,dateformat1);
  var d2=getDateFromFormat(date2,dateformat2);
  if (d1==0 || d2==0) {
    return -1;
  }
  else if (d1 > d2) {
    return 1;
  }
  return 0;
}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
  format=format+"";
  var result="";
  var i_format=0;
  var c="";
  var token="";
  var y=date.getYear()+"";
  var M=date.getMonth()+1;
  var d=date.getDate();
  var H=date.getHours();
  var m=date.getMinutes();
  var s=date.getSeconds();
  var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
  // Convert real date parts into formatted versions
  var value=new Object();
  if (y.length < 4) {y=""+(y-0+1900);}
  value["y"]=""+y;
  value["yyyy"]=y;
  value["yy"]=y.substring(2,4);
  value["M"]=M;
  value["MM"]=LZ(M);
  value["MMM"]=MONTH_NAMES[M-1];
  value["d"]=d;
  value["dd"]=LZ(d);
  value["H"]=H;
  value["HH"]=LZ(H);
  if (H==0){value["h"]=12;}
  else if (H>12){value["h"]=H-12;}
  else {value["h"]=H;}
  value["hh"]=LZ(value["h"]);
  if (H>11){value["K"]=H-12;} else {value["K"]=H;}
  value["k"]=H+1;
  value["KK"]=LZ(value["K"]);
  value["kk"]=LZ(value["k"]);
  if (H > 11) { value["a"]="PM"; }
  else { value["a"]="AM"; }
  value["m"]=m;
  value["mm"]=LZ(m);
  value["s"]=s;
  value["ss"]=LZ(s);
  while (i_format < format.length) {
    c=format.charAt(i_format);
    token="";
    while ((format.charAt(i_format)==c) && (i_format < format.length)) {
      token += format.charAt(i_format++);
      }
    if (value[token] != null) { result=result + value[token]; }
    else { result=result + token; }
    }
  return result;
}
  
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
  var digits="1234567890";
  for (var i=0; i < val.length; i++) {
    if (digits.indexOf(val.charAt(i))==-1) { return false; }
  }
  return true;
}

function _getInt(str,i,minlength,maxlength) {
  for (var x=maxlength; x>=minlength; x--) {
    var token=str.substring(i,i+x);
    if (token.length < minlength) { return null; }
    if (_isInteger(token)) { return token; }
  }
  return null;
}
  
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
  val=val+"";
  format=format+"";
  var i_val=0;
  var i_format=0;
  var c="";
  var token="";
  var token2="";
  var x,y;
  var now=new Date();
  var year=now.getYear();
  var month=now.getMonth()+1;
  var date=1;
  var hh=now.getHours();
  var mm=now.getMinutes();
  var ss=now.getSeconds();
  var ampm="";
  
  while (i_format < format.length) {
    // Get next token from format string
    c=format.charAt(i_format);
    token="";
    while ((format.charAt(i_format)==c) && (i_format < format.length)) {
      token += format.charAt(i_format++);
      }
    // Extract contents of value based on format token
    if (token=="yyyy" || token=="yy" || token=="y") {
      if (token=="yyyy") { x=4;y=4; }
      if (token=="yy")   { x=2;y=2; }
      if (token=="y")    { x=2;y=4; }
      year=_getInt(val,i_val,x,y);
      if (year==null) { return 0; }
      i_val += year.length;
      if (year.length==2) {
        if (year > 70) { year=1900+(year-0); }
        else { year=2000+(year-0); }
        }
      }
    else if (token=="MMM"){
      month=0;
      for (var i=0; i<MONTH_NAMES.length; i++) {
        var month_name=MONTH_NAMES[i];
        if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
          month=i+1;
          if (month>12) { month -= 12; }
          i_val += month_name.length;
          break;
          }
        }
      if ((month < 1)||(month>12)){return 0;}
      }
    else if (token=="MM"||token=="M") {
      month=_getInt(val,i_val,token.length,2);
      if(month==null||(month<1)||(month>12)){return 0;}
      i_val+=month.length;}
    else if (token=="dd"||token=="d") {
      date=_getInt(val,i_val,token.length,2);
      if(date==null||(date<1)||(date>31)){return 0;}
      i_val+=date.length;}
    else if (token=="hh"||token=="h") {
      hh=_getInt(val,i_val,token.length,2);
      if(hh==null||(hh<1)||(hh>12)){return 0;}
      i_val+=hh.length;}
    else if (token=="HH"||token=="H") {
      hh=_getInt(val,i_val,token.length,2);
      if(hh==null||(hh<0)||(hh>23)){return 0;}
      i_val+=hh.length;}
    else if (token=="KK"||token=="K") {
      hh=_getInt(val,i_val,token.length,2);
      if(hh==null||(hh<0)||(hh>11)){return 0;}
      i_val+=hh.length;}
    else if (token=="kk"||token=="k") {
      hh=_getInt(val,i_val,token.length,2);
      if(hh==null||(hh<1)||(hh>24)){return 0;}
      i_val+=hh.length;hh--;}
    else if (token=="mm"||token=="m") {
      mm=_getInt(val,i_val,token.length,2);
      if(mm==null||(mm<0)||(mm>59)){return 0;}
      i_val+=mm.length;}
    else if (token=="ss"||token=="s") {
      ss=_getInt(val,i_val,token.length,2);
      if(ss==null||(ss<0)||(ss>59)){return 0;}
      i_val+=ss.length;}
    else if (token=="a") {
      if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
      else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
      else {return 0;}
      i_val+=2;}
    else {
      if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
      else {i_val+=token.length;}
      }
    }
  // If there are any trailing characters left in the value, it doesn't match
  if (i_val != val.length) { return 0; }
  // Is date valid for month?
  if (month==2) {
    // Check for leap year
    if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
      if (date > 29){ return false; }
      }
    else { if (date > 28) { return false; } }
    }
  if ((month==4)||(month==6)||(month==9)||(month==11)) {
    if (date > 30) { return false; }
  }
  // Correct hours value
  if (hh<12 && ampm=="PM") { hh=hh-0+12; }
  else if (hh>11 && ampm=="AM") { hh-=12; }
  var newdate=new Date(year,month-1,date,hh,mm,ss);
  return newdate.getTime();
}
  
function setDaysInMonth(day, month, year) {
  var dd = new Date(year.value, month.value, 0);
  
  day.options.length = dd.getDate();
  for (i = 29; i <= day.options.length; i++) {
    day.options[i-1] = new Option(i,i);
  }
  return true;
} 

////

// Sets the z-index of the top most layer
var TOP_Z_INDEX = 10000;

// Function to determine whether the iframe needed is present or not.
function iframeHelperExists(iframeHelperId)
{
  return document.getElementById && document.getElementById(iframeHelperId);
}

// Function to init the iframe helpers
function initIframeHelpers()
{
}

// Function to hide iframe helper with the specified id
function hideIframeHelper(iframeHelperId)
{
  // Quick check to make sure that the iframe helper id is there.
  if (!iframeHelperExists(iframeHelperId)) {
    return false;
  }
  
  // Set the visibility and the z-index appropriately.
  document.getElementById(iframeHelperId).style.visibility  = 'hidden';
  document.getElementById(iframeHelperId).style.zIndex      = -1000;
}

// Function to show iframe helper with the specified id
function showIframeHelper(iframeHelperId, x, y, w, h)
{
  //alert('id:' + iframeHelperId + ' |x:' + x + ' |y:' + y + ' |w:' + w + ' | h:' + h );
  
  // Quick check to make sure that the iframe helper id is there.
  if (!iframeHelperExists(iframeHelperId)) {
    return false;
  }

// Set the location of the top corner of the iframe under the div.
  document.getElementById(iframeHelperId).style.left        = x;
  document.getElementById(iframeHelperId).style.top         = y;
  
  // Now set the width of the iframe under the div.
  if (isNaN(w)) {
    // alert('invalid width: "' + w + '"');
  }
  else {
    document.getElementById(iframeHelperId).style.width       = w + 'px';
  }
  
  // Now set the width of the iframe under the div.
  if (isNaN(h)) {
    // alert('invalid height: "' + w + '"');
  }
  else {
    document.getElementById(iframeHelperId).style.height      = h + 'px';
  }
  
  // Set the visibility and z-index behind the div.
  document.getElementById(iframeHelperId).style.zIndex      = 1;
  document.getElementById(iframeHelperId).style.visibility  = 'visible';
}

//

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/* 
AnchorPosition.js
Author: Matt Kruse
Last modified: 10/11/02

DESCRIPTION: These functions find the position of an <A> tag in a document,
so other elements can be positioned relative to it.

COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the 
Macintosh platform.

FUNCTIONS:
getAnchorPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor. Position is relative to the PAGE.

getAnchorWindowPosition(anchorname)
  Returns an Object() having .x and .y properties of the pixel coordinates
  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.

NOTES:

1) For popping up separate browser windows, use getAnchorWindowPosition. 
   Otherwise, use getAnchorPosition

2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the 
   anchor tag correctly. Do not do <A></A> with no space.
*/ 

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}


///

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

/* 
PopupWindow.js
Author: Matt Kruse
Last modified: 3/21/02

DESCRIPTION: This object allows you to easily and quickly popup a window
in a certain place. The window can either be a DIV or a separate browser
window.

COMPATABILITY: Works with Netscape 4.x, 6.x, IE 5.x on Windows. Some small
positioning errors - usually with Window positioning - occur on the 
Macintosh platform. Due to bugs in Netscape 4.x, populating the popup 
window with <STYLE> tags may cause errors.

USAGE:
// Create an object for a WINDOW popup
var win = new PopupWindow(); 

// Create an object for a DIV window using the DIV named 'mydiv'
var win = new PopupWindow('mydiv'); 

// Set the window to automatically hide itself when the user clicks 
// anywhere else on the page except the popup
win.autoHide(); 

// Show the window relative to the anchor name passed in
win.showPopup(anchorname);

// Hide the popup
win.hidePopup();

// Set the size of the popup window (only applies to WINDOW popups
win.setSize(width,height);

// Populate the contents of the popup window that will be shown. If you 
// change the contents while it is displayed, you will need to refresh()
win.populate(string);

// Refresh the contents of the popup
win.refresh();

// Specify how many pixels to the right of the anchor the popup will appear
win.offsetX = 50;

// Specify how many pixels below the anchor the popup will appear
win.offsetY = 100;

NOTES:
1) Requires the functions in AnchorPosition.js

2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

3) There must be at least a space between <A> </A> for IE5.5 to see the 
   anchor tag correctly. Do not do <A></A> with no space.

4) When a PopupWindow object is created, a handler for 'onmouseup' is
   attached to any event handler you may have already defined. Do NOT define
   an event handler for 'onmouseup' after you define a PopupWindow object or
   the autoHide() will not work correctly.
*/ 

// Set the position of the popup window based on the anchor
function PopupWindow_getXYPosition(anchorname) {
	var coordinates;
	if (this.type == "WINDOW") {
		coordinates = getAnchorWindowPosition(anchorname);
		}
	else {
		coordinates = getAnchorPosition(anchorname);
		}
	this.x = coordinates.x;
	this.y = coordinates.y;
	}
// Set width/height of DIV/popup window
function PopupWindow_setSize(width,height) {
	this.width = width;
	this.height = height;
	}
// Fill the window with contents
function PopupWindow_populate(contents) {
	this.contents = contents;
	this.populated = false;
	}
// Refresh the displayed contents of the popup
function PopupWindow_refresh() {
	if (this.divName != null) {
		// refresh the DIV object
		if (this.use_gebi) {
			document.getElementById(this.divName).innerHTML = this.contents;
			}
		else if (this.use_css) { 
			document.all[this.divName].innerHTML = this.contents;
			}
		else if (this.use_layers) { 
			var d = document.layers[this.divName]; 
			d.document.open();
			d.document.writeln(this.contents);
			d.document.close();
			}
		}
	else {
		if (this.popupWindow != null && !this.popupWindow.closed) {
			this.popupWindow.document.open();
			this.popupWindow.document.writeln(this.contents);
			this.popupWindow.document.close();
			this.popupWindow.focus();
			}
		}
	}
// Position and show the popup, relative to an anchor object
function PopupWindow_showPopup(anchorname) {
  this.getXYPosition(anchorname);
	this.x += this.offsetX;
	this.y += this.offsetY;
	if (!this.populated && (this.contents != "")) {
		this.populated = true;
		this.refresh();
  }
	if (this.divName != null) {
		// Show the DIV object
		if (this.use_gebi) {
			document.getElementById(this.divName).style.left = this.x;
			document.getElementById(this.divName).style.top = this.y;
			document.getElementById(this.divName).style.visibility = "visible";
			if (this.needIframeHelper()) {
			  document.getElementById(this.divName).style.zIndex = TOP_Z_INDEX;
			}
		}
		else if (this.use_css) {
			document.all[this.divName].style.left = this.x;
			document.all[this.divName].style.top = this.y;
			document.all[this.divName].style.visibility = "visible";
			if (this.needIframeHelper()) {
			  document.all[this.divName].style.zIndex = TOP_Z_INDEX;
			}
		}
		else if (this.use_layers) {
			document.layers[this.divName].left = this.x;
			document.layers[this.divName].top = this.y;
			document.layers[this.divName].visibility = "visible";
			if (this.needIframeHelper()) {
			  document.layers[this.divName].zIndex = TOP_Z_INDEX;
			}
		}
	  
	  if (this.needIframeHelper()) {
		  showIframeHelper(this.iframeId,this.x,this.y,this.width,this.height);
	  }
  }
	else {
		if (this.popupWindow == null || this.popupWindow.closed) {
			// If the popup window will go off-screen, move it so it doesn't
			if (screen && screen.availHeight) {
				if ((this.y + this.height) > screen.availHeight) {
					this.y = screen.availHeight - this.height;
					}
				}
			if (screen && screen.availWidth) {
				if ((this.x + this.width) > screen.availWidth) {
					this.x = screen.availWidth - this.width;
					}
				}
			this.popupWindow = window.open("about:blank","window_"+anchorname,"toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no,width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");
			}
		this.refresh();
		}
	}

// Hide the popup
function PopupWindow_hidePopup() {
	if (this.divName != null) {
		if (this.use_gebi && document.getElementById(this.divName)) {
            document.getElementById(this.divName).style.visibility = "hidden";
			}
		else if (this.use_css) {
			document.all[this.divName].style.visibility = "hidden";
			}
		else if (this.use_layers) {
			document.layers[this.divName].visibility = "hidden";
			}
		}
		if (this.needIframeHelper()) {
		  hideIframeHelper(this.iframeId);
	  }
	else {
		if (this.popupWindow && !this.popupWindow.closed) {
			this.popupWindow.close();
			this.popupWindow = null;
			}
		}
	}
// Pass an event and return whether or not it was the popup DIV that was clicked
function PopupWindow_isClicked(e) {
	if (this.divName != null) {
		if (this.use_layers) {
			var clickX = e.pageX;
			var clickY = e.pageY;
			var t = document.layers[this.divName];
			if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
				return true;
				}
			else { return false; }
			}
		else if (document.all) { // Need to hard-code this to trap IE for error-handling
			var t = window.event.srcElement;
			while (t.parentElement != null) {
				if (t.id==this.divName) {
					return true;
					}
				t = t.parentElement;
				}
			return false;
			}
		else if (this.use_gebi) {
		  if (!e) {
		    return false;
		    }
			var t = e.originalTarget;
			while (t.parentNode != null) {
				if (t.id==this.divName) {
					return true;
					}
				t = t.parentNode;
				}
			return false;
			}
		return false;
		}
	return false;
	}

// Check an onMouseDown event to see if we should hide
function PopupWindow_hideIfNotClicked(e) {
	if (this.autoHideEnabled && !this.isClicked(e)) {
		this.hidePopup();
		}
	}
// Call this to make the DIV disable automatically when mouse is clicked outside it
function PopupWindow_autoHide() {
	this.autoHideEnabled = true;
	}
// This global function checks all PopupWindow objects onmouseup to see if they should be hidden
function PopupWindow_hidePopupWindows(e) {
	for (var i=0; i<popupWindowObjects.length; i++) {
		if (popupWindowObjects[i] != null) {
			var p = popupWindowObjects[i];
			p.hideIfNotClicked(e);
			}
		}
	}
// Run this immediately to attach the event listener
function PopupWindow_attachListener() {
	if (document.layers) {
		document.captureEvents(Event.MOUSEUP);
		}
	window.popupWindowOldEventListener = document.onmouseup;
	if (window.popupWindowOldEventListener != null) {
		document.onmouseup = new Function("window.popupWindowOldEventListener(); PopupWindow_hidePopupWindows();");
		}
	else {
		document.onmouseup = PopupWindow_hidePopupWindows;
		}
	}
	
function PopupWindow_needIframeHelper()
{
  // alert(this.use_IframeHelper);
  if (this.use_IframeHelper != "undefined") {
    return this.use_IframeHelper;
  }
  
  // Show the iframe behind the div for IE browers
	var Opera = ((document.all)&&(navigator.userAgent.indexOf("Opera")!=-1)) ? true : false;
	var IE5   = !Opera && ((document.all)&&(navigator.userAgent.indexOf("MSIE 5.")!=-1)) ? true : false;
  var IE6   = !Opera && ((document.all)&&(navigator.userAgent.indexOf("MSIE 6.")!=-1)) ? true : false;
  this.use_IframeHelper = (IE5 || IE6) && this.iframeId.length && document.getElementById(this.iframeId);
  // alert("here:" + this.use_IframeHelper);
  
}

// CONSTRUCTOR for the PopupWindow object
// Pass it a DIV name to use a DHTML popup, otherwise will default to window popup
function PopupWindow() {
	if (!window.popupWindowIndex) { window.popupWindowIndex = 0; }
	if (!window.popupWindowObjects) { window.popupWindowObjects = new Array(); }
	if (!window.listenerAttached) {
		window.listenerAttached = true;
		PopupWindow_attachListener();
  }
	this.index = popupWindowIndex++;
	popupWindowObjects[this.index] = this;
	this.divName = null;
	this.popupWindow = null;
	this.width=0;
	this.height=0;
	this.populated = false;
	this.visible = false;
	this.autoHideEnabled = false;
	
	this.contents = "";
	if (arguments.length>0) {
		this.type="DIV";
		this.divName = arguments[0];
	}
	else {
		this.type="WINDOW";
	}
	this.use_gebi = false;
	this.use_css = false;
	this.use_layers = false;
	if (document.getElementById) { this.use_gebi = true; }
	else if (document.all) { this.use_css = true; }
	else if (document.layers) { this.use_layers = true; }
	else { this.type = "WINDOW"; }
	this.offsetX = 0;
	this.offsetY = 0;
	// Method mappings
	this.getXYPosition = PopupWindow_getXYPosition;
	this.populate = PopupWindow_populate;
	this.refresh = PopupWindow_refresh;
	this.showPopup = PopupWindow_showPopup;
	this.hidePopup = PopupWindow_hidePopup;
	this.setSize = PopupWindow_setSize;
	this.isClicked = PopupWindow_isClicked;
	this.autoHide = PopupWindow_autoHide;
	this.hideIfNotClicked = PopupWindow_hideIfNotClicked;
	this.needIframeHelper = PopupWindow_needIframeHelper;
	
	this.use_IframeHelper = "undefined"
	this.iframeId = "iframeHelper";  // id of the iframe to use behind the div.
}

//

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
// ===================================================================

// CONSTRUCTOR for the CalendarPopup Object
function CalendarPopup() {
  var c;
  if (arguments.length>0) {
    c = new PopupWindow(arguments[0]);
    c.setSize(164,185); // width,height
  }
  else {
    c = new PopupWindow();
    c.setSize(164,185);
  }  
  
  c.offsetX = -152;
  c.offsetY = 25;
  c.autoHide();
  // Calendar-specific properties
  c.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  c.monthAbbreviations = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  c.dayHeaders = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
  c.returnFunction = "CalendarPopup_tmpReturnFunction";
  c.returnMonthFunction = "CalendarPopup_tmpReturnMonthFunction";
  c.returnQuarterFunction = "CalendarPopup_tmpReturnQuarterFunction";
  c.returnYearFunction = "CalendarPopup_tmpReturnYearFunction";
  c.weekStartDay = 0;
  c.isShowYearNavigation = false;
  c.displayType = "date";
  c.disabledWeekDays = new Object();
  c.yearSelectStartOffset = 2;
  c.currentDate = null;
  c.todayText="Close";
  window.CalendarPopup_targetInput = null;
  window.CalendarPopup_dateFormat = "mm/dd/yyyy";
  // Method mappings
  c.setReturnFunction = CalendarPopup_setReturnFunction;
  c.setReturnMonthFunction = CalendarPopup_setReturnMonthFunction;
  c.setReturnQuarterFunction = CalendarPopup_setReturnQuarterFunction;
  c.setReturnYearFunction = CalendarPopup_setReturnYearFunction;
  c.setMonthNames = CalendarPopup_setMonthNames;
  c.setMonthAbbreviations = CalendarPopup_setMonthAbbreviations;
  c.setDayHeaders = CalendarPopup_setDayHeaders;
  c.setWeekStartDay = CalendarPopup_setWeekStartDay;
  c.setDisplayType = CalendarPopup_setDisplayType;
  c.setDisabledWeekDays = CalendarPopup_setDisabledWeekDays;
  c.setYearSelectStartOffset = CalendarPopup_setYearSelectStartOffset;
  c.setTodayText = CalendarPopup_setTodayText;
  c.showYearNavigation = CalendarPopup_showYearNavigation;
  c.showCalendar = CalendarPopup_showCalendar;
  c.hideCalendar = CalendarPopup_hideCalendar;
  c.getStyles = CalendarPopup_getStyles;
  c.refreshCalendar = CalendarPopup_refreshCalendar;
  c.getCalendar = CalendarPopup_getCalendar;
  c.select = CalendarPopup_select;
  c.isVisible = false;
  // Return the object
  return c;
}

// Temporary default functions to be called when items clicked, so no error is thrown
function CalendarPopup_tmpReturnFunction(y,m,d) {
  if (window.CalendarPopup_targetInput!=null) {
    var dt = new Date(y,m-1,d,0,0,0);
    window.CalendarPopup_targetInput.value = formatDate(dt,window.CalendarPopup_dateFormat);
  }
  else {
    alert('Use setReturnFunction() to define which function will get the clicked results!');
  }
}
function CalendarPopup_tmpReturnMonthFunction(y,m) {
  alert('Use setReturnMonthFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , month='+m);
}
function CalendarPopup_tmpReturnQuarterFunction(y,q) {
  alert('Use setReturnQuarterFunction() to define which function will get the clicked results!\nYou clicked: year='+y+' , quarter='+q);
}
function CalendarPopup_tmpReturnYearFunction(y) {
  alert('Use setReturnYearFunction() to define which function will get the clicked results!\nYou clicked: year='+y);
}

// Set the name of the functions to call to get the clicked item
function CalendarPopup_setReturnFunction(name)        { this.returnFunction = name; }
function CalendarPopup_setReturnMonthFunction(name)   { this.returnMonthFunction = name; }
function CalendarPopup_setReturnQuarterFunction(name) { this.returnQuarterFunction = name; }
function CalendarPopup_setReturnYearFunction(name)    { this.returnYearFunction = name; }

// Over-ride the built-in month names
function CalendarPopup_setMonthNames() {
  for (var i=0; i<arguments.length; i++) { this.monthNames[i] = arguments[i]; }
}

// Over-ride the built-in month abbreviations
function CalendarPopup_setMonthAbbreviations() {
  for (var i=0; i<arguments.length; i++) { this.monthAbbreviations[i] = arguments[i]; }
}

// Over-ride the built-in column headers for each day
function CalendarPopup_setDayHeaders() {
  for (var i=0; i<arguments.length; i++) { this.dayHeaders[i] = arguments[i]; }
}

// Set the day of the week (0-7) that the calendar display starts on
// This is for countries other than the US whose calendar displays start on Monday(1), for example
function CalendarPopup_setWeekStartDay(day) { this.weekStartDay = day; }

// Show next/last year navigation links
function CalendarPopup_showYearNavigation() { this.isShowYearNavigation = true; }

// Which type of calendar to display
function CalendarPopup_setDisplayType(type) {
  if (type!="date" && type!="week-end" && type!="month" && type!="quarter" && type!="year") {
    alert("Invalid display type! Must be one of: date,week-end,month,quarter,year");
    return false;
  }
  this.displayType=type;
}

// How many years back to start by default for year display
function CalendarPopup_setYearSelectStartOffset(num) { this.yearSelectStartOffset=num; }

// Set which weekdays should not be clickable
function CalendarPopup_setDisabledWeekDays() {
  this.disabledWeekDays = new Object();
  for (var i=0; i<arguments.length; i++) {
    this.disabledWeekDays[arguments[i]] = true;
  }
}

// Set the text to use for the "Today" link
function CalendarPopup_setTodayText(text) {
  this.todayText = text;
}

// Hide a calendar object
function CalendarPopup_hideCalendar() {
  if (arguments.length > 0) {
    window.popupWindowObjects[arguments[0]].isVisible = false; window.popupWindowObjects[arguments[0]].hidePopup();
  }
  else {
    this.isVisible = false; this.hidePopup();
  }
}

// Refresh the contents of the calendar display
function CalendarPopup_refreshCalendar(index) {
  var calObject = window.popupWindowObjects[index];
  today = new Date();

  if (arguments[2] < today.getFullYear() || (arguments[2] == today.getFullYear() && arguments[1] < eval(today.getMonth()+1))) {
    alert('You cannot select a date before today.');
    return;
  }

  if (arguments[2] > eval(today.getFullYear()+1) || (arguments[2] == eval(today.getFullYear()+1)) && arguments[1] > eval(today.getMonth()+1)) {
    alert('You cannot select a date more than one year in advance.');
    return;
  }

  if (arguments.length>1) {
    calObject.populate(calObject.getCalendar(arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]));
  }
  else {
    calObject.populate(calObject.getCalendar());
  }
  calObject.refresh();
}

// Populate the calendar and display it
function CalendarPopup_showCalendar(anchorname) {
  if (!this.isVisible) { this.isVisible = true; }
  this.populate(this.getCalendar());
  this.showPopup(anchorname);
}

// Simple method to interface popup calendar with a text-entry box
function CalendarPopup_select(inputobj, linkname, format) {
  if (!window.getDateFromFormat) {
    alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
    return;
  }
  if (this.displayType!="date"&&this.displayType!="week-end") {
    alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
    return;
  }
  if (inputobj.type!="text" && inputobj.type!="hidden" && inputobj.type!="textarea") {
    alert("calendar.select: Input object passed is not a valid form input object");
    window.CalendarPopup_targetInput=null;
    return;
  }
  window.CalendarPopup_targetInput = inputobj;
  if (inputobj.value!="") {
    var time = getDateFromFormat(inputobj.value,format);
    if (time==0) { this.currentDate=null; }
    else { this.currentDate=new Date(time); }
  }
  else { this.currentDate=null; }
  window.CalendarPopup_dateFormat = format;
  this.showCalendar(linkname);
}

// Get style block needed to display the calendar correctly
function CalendarPopup_getStyles() {

  var result = "";

result += "<STYLE>\n";
result +="TD.cal,TD.calday,TD.calmonth,TD.caltoday,A.textlink,";
result +=".disabledtextlink{font-family:verdana;font-size:11px;}\n";
result += "TD.cal{text-decoration:none;color:#FFFFFF;font-weight:bold;}\n";
result += "TD.calday{color:#FFFFFF;background-color:#339933;}\n";
result += "TD.calmonth{text-align:center;}\n";
result += "TD.cal2{text-align:center;color=#FFFFFF}\n";
result += "TD.caltoday{text-align:center;font-color=#FFFFFF;background-color:#FF9900;}\n";
result += "TD.textlink{text-decoration:none;}\n";
result += "A.textlink{text-decoration:none;height:15px;color:white;font-weight:bold;}\n";
result += ".disabledtextlink{height:20px;color:#FFFFFF;}\n";
result += "A.cal{text-decoration:none;color:#FFFFFF;}\n";
result += ".cal A:visited {text-decoration: none;color:#FFFFFF;}\n";
result += ".calmonth A:visited {text-decoration: none;color:#0066FF;}\n";
result += ".calthismonth A:visited {text-decoration: none;color:#FFFFFF;}\n";
result += ".caltoday A:visited {text-decoration: none;color:#FFFFFF;}\n";
result += ".calothermonth A:visited {text-decoration: none;color:#FFFFFF;}\n";
result += ".textlink A:visited {text-decoration: none;color:#FFFFFF;}\n";
result += "A.calthismonth{text-decoration:none;color:#0066FF;font-weight:bold;}\n";
result += "A.caltoday{text-decoration:none;color:#FFFFFF;background-color:#FF9900;font-weight:bold;}\n";
result += "A.calothermonth{text-decoration:none;color:#999999;}\n";
result += ".calnotclickable{color:#FFFFFF;}\n";
result += ".disabled{color:#D0D0D0;text-decoration:line-through;}\n";
result += "</STYLE>\n";
return result;

}

// Return a string containing all the calendar code to be displayed
function CalendarPopup_getCalendar() {
  var now = new Date();
  // Reference to window
  if (this.type == "WINDOW") { var windowref = "window.opener."; }
  else { var windowref = ""; }
  var result = "";
  // If POPUP, write entire HTML document
  if (this.type == "WINDOW") {
    result += "<HTML><HEAD><TITLE>Calendar</TITLE>"+this.getStyles()+"</HEAD><BODY MARGINWIDTH=0 MARGINHEIGHT=0 TOPMARGIN=0 RIGHTMARGIN=0 LEFTMARGIN=0>\n";
    result += '<CENTER><TABLE WIDTH=100% BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
  }
  else {
    result += '<TABLE WIDTH=160 BORDER=1 BORDERCOLOR=#0000FF CELLSPACING=0 CELLPADDING=0>\n';
    result += '<TR><TD ALIGN=CENTER>\n';
    result += '<CENTER>\n';
  }
  
  //Adding Shim Div
//  result += '<DIV style="display: block; z-index: 200; visibility: visible; width: 160px; position:relative; top:0px; text-align:left;"><IFRAME marginWidth="0" marginHeight="0" frameBorder="0" width="160" height="200" bordercolor="#000000"></IFRAME></DIV>';
//  result += '<div style="display: block; z-index: 201; visibility: visible; width: 160px; position:absolute; top:0px; text-align:left;">';

// Code for DATE display (default)
  // -------------------------------
  if (this.displayType=="date" || this.displayType=="week-end") {
    if (this.currentDate==null) { this.currentDate = now; }
    if (arguments.length > 0) { var month = arguments[0]; }
      else { var month = this.currentDate.getMonth()+1; }
    if (arguments.length > 1) { var year = arguments[1]; }
      else { var year = this.currentDate.getFullYear(); }
    var daysinmonth= new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
    if ( ( (year%4 == 0)&&(year%100 != 0) ) || (year%400 == 0) ) {
      daysinmonth[2] = 29;
    }
    var current_month = new Date(year,month-1,1);
    var display_year = year;
    var display_month = month;
    var display_date = 1;
    var weekday= current_month.getDay();
    var offset = 0;
    if (weekday >= this.weekStartDay) {
      offset = weekday - this.weekStartDay;
    }
    else {
      offset = 7-this.weekStartDay+weekday;
    }
    if (offset > 0) {
      display_month--;
      if (display_month < 1) { display_month = 12; display_year--; }
      display_date = daysinmonth[display_month]-offset+1;
    }
    var next_month = month+1;
    var next_month_year = year;
    if (next_month > 12) { next_month=1; next_month_year++; }
    var last_month = month-1;
    var last_month_year = year;
    if (last_month < 1) { last_month=12; last_month_year--; }
    var date_class;
    if (this.type!="WINDOW") {
      result += '<TABLE WIDTH=160 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=3>\n';
    }
    result += '<TR BGCOLOR="#0066FF">\n';
    var refresh = 'javascript:'+windowref+'CalendarPopup_refreshCalendar';
    if (this.isShowYearNavigation) {
      var td = '<TD BGCOLOR="#0066FF" CLASS="cal" ALIGN=CENTER VALIGN=MIDDLE ';
      result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+last_month+','+last_month_year+');">&lt;</A></B></TD>';
      result += td + ' WIDTH=58>'+this.monthNames[month-1]+'</TD>';
      result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+next_month+','+next_month_year+');">&gt;</A></B></TD>';
      result += td + ' WIDTH=10>&nbsp;</TD>';
      result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+month+','+(year-1)+');">&lt;</A></B></TD>';
      result += td + ' WIDTH=36>'+year+'</TD>';
      result += td + ' WIDTH=10><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+month+','+(year+1)+');">&gt;</A></B></TD>';
    }
    else {
      result += '  <TD height="20" CLASS="cal" WIDTH=20 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+last_month+','+last_month_year+');">&lt;&lt;</A></B></TD>\n';
      result += '  <TD  height="20" CLASS="cal" WIDTH=120 ALIGN=CENTER>'+this.monthNames[month-1]+' '+year+'</TD>\n';
      result += '  <TD height="20" CLASS="cal" WIDTH=20 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="'+refresh+'('+this.index+','+next_month+','+next_month_year+');">&gt;&gt;</A></B></TD>\n';
    }
    result += '</TR></TABLE>\n';
    result += '<TABLE WIDTH=160 BORDER=0 BORDERCOLOR=#000000 CELLSPACING=0 CELLPADDING=3 ALIGN=CENTER>\n';
    result += '<TR>\n';
    var td = '  <TD CLASS="calday" ALIGN=RIGHT WIDTH=14%  height="20">';
    for (var j=0; j<7; j++) {
      result += td+this.dayHeaders[(this.weekStartDay+j)%7]+'</TD>\n';
    }
    result += '</TR>\n';
    //result += '<TR><TD COLSPAN=7 ALIGN=CENTER><IMG SRC="http://www.montrosetravel.com/images/flights/line.gif" WIDTH=160 HEIGHT=1></TD></TR>\n';
    for (var row=1; row<=6; row++) {
      result += '<TR>\n';
      for (var col=1; col<=7; col++) {
        if (display_month == month) {
          date_class = "calthismonth";
        }
        else {
          date_class = "calothermonth";
        }
        if ((display_month == this.currentDate.getMonth()+1) && (display_date==this.currentDate.getDate()) && (display_year==this.currentDate.getFullYear())) {
          td_class="caltoday";
        }
        else {
          td_class="calmonth";
        }
        if (this.disabledWeekDays[col-1]) {
          date_class="calnotclickable";
          result += '  <TD CLASS="'+td_class+'"><SPAN CLASS="'+date_class+'">'+display_date+'</SPAN></TD>\n';
        }
        else {
          var selected_date = display_date;
          var selected_month = display_month;
          var selected_year = display_year;
          if (this.displayType=="week-end") {
            var d = new Date(selected_year,selected_month-1,selected_date,0,0,0,0);
            d.setDate(d.getDate() + (7-col));
            selected_year = d.getYear();
            if (selected_year < 1000) { selected_year += 1900; }
            selected_month = d.getMonth()+1;
            selected_date = d.getDate();
          }
          result += '  <TD CLASS="'+td_class+'"><A HREF="javascript:'+windowref+this.returnFunction+'('+selected_year+','+selected_month+','+selected_date+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+display_date+'</A></TD>\n';
        }
        display_date++;
        if (display_date > daysinmonth[display_month]) {
          display_date=1;
          display_month++;
        }
        if (display_month > 12) {
          display_month=1;
          display_year++;
        }
      }
      result += '</TR>';
    }
    var current_weekday = now.getDay();
    //result += '<TR><TD COLSPAN=7 ALIGN=CENTER><IMG SRC="http://www.montrosetravel.com/images/flights/line.gif" WIDTH=160 HEIGHT=1></TD></TR>\n';
    result += '<TR bgcolor="#0066FF">\n';
    result += '  <TD COLSPAN=7 ALIGN=CENTER  height="20" valign="bottom" CLASS="textlink">\n';
    if (this.disabledWeekDays[current_weekday+1]) {
      result += '    <SPAN CLASS="disabledtextlink">'+this.todayText+'</SPAN>\n';
    }
    else {
      result += '    <A CLASS="textlink" HREF="javascript:'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');">'+this.todayText+'</A>\n';
    }
    result += '    <BR>\n';
    result += '  </TD></TR></TABLE></CENTER></TD></TR></TABLE>\n';
  }

  // Code common for MONTH, QUARTER, YEAR
  // ------------------------------------
  if (this.displayType=="month" || this.displayType=="quarter" || this.displayType=="year") {
    if (arguments.length > 0) { var year = arguments[0]; }
    else {
      if (this.displayType=="year") {  var year = now.getFullYear()-this.yearSelectStartOffset; }
      else { var year = now.getFullYear(); }
    }
    if (this.displayType!="year" && this.isShowYearNavigation) {
      result += '<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
      result += '<TR BGCOLOR="#6699FF">\n';
      result += '  <TD BGCOLOR="#6699FF" CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year-1)+');">&lt;&lt;</A></B></TD>\n';
      result += '  <TD BGCOLOR="#6699FF" CLASS="cal" WIDTH=100 ALIGN=CENTER>'+year+'</TD>\n';
      result += '  <TD BGCOLOR="#6699FF" CLASS="cal" WIDTH=22 ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year+1)+');">&gt;&gt;</A></B></TD>\n';
      result += '</TR></TABLE>\n';
    }
  }

  // Code for MONTH display (default)
  // -------------------------------
  if (this.displayType=="month") {
    // If POPUP, write entire HTML document
    result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
    for (var i=0; i<4; i++) {
      result += '<TR>';
      for (var j=0; j<3; j++) {
        var monthindex = ((i*3)+j);
        result += '<TD WIDTH=33% ALIGN=CENTER><A CLASS="textlink" HREF="javascript:'+windowref+this.returnMonthFunction+'('+year+','+(monthindex+1)+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+this.monthAbbreviations[monthindex]+'</A></TD>';
      }
      result += '</TR>';
    }
    result += '</TABLE></CENTER></TD></TR></TABLE>\n';
  }

  // Code for QUARTER display (default)
  // ----------------------------------
  if (this.displayType=="quarter") {
    result += '<BR><TABLE WIDTH=120 BORDER=1 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n';
    for (var i=0; i<2; i++) {
      result += '<TR>';
      for (var j=0; j<2; j++) {
        var quarter = ((i*2)+j+1);
        result += '<TD WIDTH=50% ALIGN=CENTER><BR><A CLASS="textlink" HREF="javascript:'+windowref+this.returnQuarterFunction+'('+year+','+quarter+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">Q'+quarter+'</A><BR><BR></TD>';
      }
      result += '</TR>';
    }
    result += '</TABLE></CENTER></TD></TR></TABLE>\n';
  }

  // Code for YEAR display (default)
  // -------------------------------
  if (this.displayType=="year") {
    var yearColumnSize = 4;
    result += '<TABLE WIDTH=144 BORDER=0 BORDERWIDTH=0 CELLSPACING=0 CELLPADDING=0>\n';
    result += '<TR BGCOLOR="#6699FF">\n';
    result += '  <TD BGCOLOR="#6699FF" CLASS="cal" WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year-(yearColumnSize*2))+');">&lt;&lt;</A></B></TD>\n';
    result += '  <TD BGCOLOR="#6699FF" CLASS="cal" WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE><B><A CLASS="cal" HREF="javascript:'+windowref+'CalendarPopup_refreshCalendar('+this.index+','+(year+(yearColumnSize*2))+');">&gt;&gt;</A></B></TD>\n';
    result += '</TR></TABLE>\n';
    result += '<TABLE WIDTH=120 BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER>\n';
    for (var i=0; i<yearColumnSize; i++) {
      for (var j=0; j<2; j++) {
        var currentyear = year+(j*yearColumnSize)+i;
        result += '<TD WIDTH=50% ALIGN=CENTER><A CLASS="textlink" HREF="javascript:'+windowref+this.returnYearFunction+'('+currentyear+');'+windowref+'CalendarPopup_hideCalendar(\''+this.index+'\');" CLASS="'+date_class+'">'+currentyear+'</A></TD>';
      }
      result += '</TR>';
    }
    result += '</TABLE></CENTER></TD></TR></TABLE>\n';
  }
  
  // Common
  if (this.type == "WINDOW") {
    result += "</BODY></HTML>\n";
  }
  return result;
}

// custom site functions

function resetDays(selObjM, selObjD, selObjY, calObj) {
  if(!selObjM || !selObjD) {
    return;
  }

  month = selObjM.selectedIndex + 1;
  dayInd = selObjD.selectedIndex;
  if(selObjY == null || selObjY == 'null') {
    year = get_valid_year(month);
  }
  else {
    year = selObjY.options[selObjY.selectedIndex].value;
  }
  // clear day select
  daylength = selObjD.options.length
  for (i = daylength; i > 0; i--) {
    selObjD.options[i] = null;
  }
  // recreate day options
  var lastDay = getDaysInMonth(month, year);
  // confirm(lastDay);
  for (i = 1; i <= lastDay; i++) {
    selObjD.options[i-1] = new Option(i,i);
  }
  // set selected index
  if(dayInd < lastDay) {
    selObjD.selectedIndex = dayInd;
  }
  else {
    selObjD.selectedIndex = (lastDay - 1);
  }

  if (calObj != null) {
    calObj.currentDate = new Date(year, month - 1, selObjD.options[selObjD.selectedIndex].value);
  }

}

function getDaysInMonth(month, year)  {
    var days;
    // var month = calDate.getMonth()+1;
    // var year  = calDate.getFullYear();

    // RETURN 31 DAYS
    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
      month==10 || month==12)  {
      days=31;
    }
    // RETURN 30 DAYS
    else if (month==4 || month==6 || month==9 || month==11) {
      days=30;
    }
    // RETURN 29 DAYS
    else if (month==2)  {
      if (isLeapYear(year)) {
        days=29;
      }
      // RETURN 28 DAYS
      else {
        days=28;
      }
    }
    return (days);
}

// CHECK TO SEE IF YEAR IS A LEAP YEAR
function isLeapYear (Year) {
    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
        return (true);
    }
    else {
        return (false);
    }
}

function get_valid_year(valid_month, valid_day) {
  if (valid_day == null) {
    valid_day = 1;
  }

  var current_Date = new Date();
  current_month = current_Date.getMonth(); // + 1 -- Please don't increment this, see function updateTravelYear below for a fix to the 'All Months' year selection for cruises. Thanks, Everybody Else.
  current_day = current_Date.getDate();

  if(valid_month == 0 || valid_month == null) {
    valid_month = current_month;
  }

  if (current_month > valid_month || (current_month == valid_month && current_day > valid_day)) {
    valid_year = current_Date.getFullYear() + 1;
  } else {
    valid_year = current_Date.getFullYear();
  }

  return valid_year;
}

function update_travel_date (month1Obj, day1Obj, month2Obj, day2Obj, daysInBetween, year1Obj, year2Obj) {
  if (isNaN(daysInBetween)) {
    daysInBetween = 2;
  }
  
  // When is selected start date?
  day_value   = day1Obj.selectedIndex + 1;
  month_value = month1Obj.selectedIndex;
  if (!year1Obj) {
    year_value = get_valid_year (month_value, day_value);
  }
  else {
    year_value = year1Obj.options[year1Obj.selectedIndex].value;
  }
  
  // When is the selected end date?
  end_day_value   = day2Obj.selectedIndex + 1;
  end_month_value = month2Obj.selectedIndex;
  if (!year2Obj) {
    end_year_value = get_valid_year(end_month_value, end_day_value);
  }
  else {
    end_year_value = year2Obj.options[year2Obj.selectedIndex].value;
  }
  
  today      = new Date(year_value, month_value, day_value); // Not really today, just the start date.
  end_date   = new Date(end_year_value, end_month_value, end_day_value);
  // next_date represents the default end date based on TRAVEL_DAYS_APART
  next_date  = new Date(year_value, month_value, day_value + daysInBetween);
  
  // For cars, stop updating the end date if it is valid, just because the start date is chanaged.
  if (document.getElementById('pickup_city') && (end_date >= next_date) && (end_date > today)) {
    return true;
  }
  
  // Set new values, valid based on input.
  month2Obj.selectedIndex = next_date.getMonth();
  day2Obj.selectedIndex   = next_date.getDate() - 1;
  
  if (year2Obj) {
    for (i = 0; i < year2Obj.options.length; i++) {
      if (year2Obj.options[i].value == next_date.getFullYear()) {
        year2Obj.selectedIndex = i;
        break;
      }
    }
  }
}

function update_vacation_date (month1Obj, day1Obj, month2Obj, day2Obj) {
  day_value = day1Obj.selectedIndex + 1;
  month_value = month1Obj.selectedIndex;
  year_value = get_valid_year (month_value, day_value);

  today = new Date (year_value, month_value, day_value);

  next_date = new Date (year_value, month_value, day_value + 7);

  month2Obj.selectedIndex = next_date.getMonth();
  day2Obj.selectedIndex = next_date.getDate() - 1;
}


function updateTravelYear(monthObj,yearObj)
{
  month     = monthObj.selectedIndex;

  current_date = new Date();
  current_year = current_date.getFullYear();


  if (month > 0 ) {
    validYear = get_valid_year(month);
  }
  else {
    validYear = current_year;
  }

  for (i = 0; i < yearObj.options.length; i++) {
    if (yearObj.options[i].value == validYear) {
      yearObj.selectedIndex = i;
      break;
    }
  }
}


//

/* $Id: //php/release/www/js/div_magic.js#6 $ */

/**
 * showDiv
 *
 * show the specified div
 */
function showDiv(divNameToShow)
{
  if (document.getElementById) {
    /**
     * DOM3 = IE5, NS6
     */
    document.getElementById(divNameToShow).style.visibility = 'visible';
    document.getElementById(divNameToShow).style.display    = 'block';
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + divNameToShow + '.visibility="visible"');
      eval('document.' + divNameToShow + '.display="block"');
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + divNameToShow + '.style.visibility="visible"');
      eval('document.all.' + divNameToShow + '.style.display="block"');
    }
  }
}

/**
 * showSpan
 *
 * show the specified span
 */
function showSpan(spanNameToShow)
{
  if (document.getElementById) {
    /**
     * DOM3 = IE5, NS6
     */
    document.getElementById(spanNameToShow).style.visibility = 'visible';
    document.getElementById(spanNameToShow).style.display    = 'inline';
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + spanNameToShow + '.visibility="visible"');
      eval('document.' + spanNameToShow + '.display="inline"');
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + spanNameToShow + '.style.visibility="visible"');
      eval('document.all.' + spanNameToShow + '.style.display="inline"');
    }
  }
}

/**
 * showTableRow
 *
 * show the specific table row
 */
function showTableRow(tableRowNameToShow) 
{
  if (document.getElementById) {
    /**
     * DOM3 = IE5, NS6
     */
    document.getElementById(tableRowNameToShow).style.visibility = 'visible';
    document.getElementById(tableRowNameToShow).style.display    = '';
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + tableRowNameToShow + '.visibility="visible"');
      eval('document.' + tableRowNameToShow + '.display=""');
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + tableRowNameToShow + '.style.visibility="visible"');
      eval('document.all.' + tableRowNameToShow + '.style.display=""');
    }
  }
}

/**
 * hideDiv
 *
 * show the specified div
 */
function hideDiv(divNameToShow,doNotCollapse)
{
  if (doNotCollapse) {
    disp = 'block';
  }
  else {
    disp = 'none';
  }

  if (document.getElementById) {
    /**
     * DOM3 = IE5, NS6
     */
    document.getElementById(divNameToShow).style.visibility = 'hidden';
    document.getElementById(divNameToShow).style.display    = disp;
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + divNameToShow + '.visibility="hidden"');
      eval('document.' + divNameToShow + '.display="' + disp + '"');
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + divNameToShow + '.style.visibility="hidden"');
      eval('document.all.' + divNameToShow + '.style.display="' + disp + '"');
    }
  }
}

/**
 * hideSpan
 *
 * hide the specified Span
 */
function hideSpan(spanNameToHide)
{

  if (document.getElementById) {
/**
     * DOM3 = IE5, NS6
     */
    document.getElementById(spanNameToHide).style.visibility = 'hidden';
    document.getElementById(spanNameToHide).style.display    = 'inline';
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + spanNameToHide + '.visibility="hidden"');
      eval('document.' + spanNameToHide + '.display="inline"');
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + spanNameToHide + '.style.visibility="hidden"');
      eval('document.all.' + spanNameToShow + '.style.display="inline"');
    }
  }
}


/**
 * hideDiv
 *
 * hide the specified table row.
 */
function hideTableRow(tableRowNameToHide, doNotCollapse)
{
  if (doNotCollapse) {
    disp = '';
  }
  else {
    disp = 'none';
  }

  if (document.getElementById) {
    /**
     * DOM3 = IE5, NS6
     */
    document.getElementById(tableRowNameToHide).style.visibility = 'hidden';
    document.getElementById(tableRowNameToHide).style.display    = disp;
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + tableRowNameToHide + '.visibility="hidden"');
      eval('document.' + tableRowNameToHide + '.display="' + disp + '"');
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + tableRowNameToHide + '.style.visibility="hidden"');
      eval('document.all.' + tableRowNameToHide + '.style.display="' + disp + '"');
    }
  }
}


/**
 * hideDivs
 *
 * hides the specified ids
 */
function hideDivs()
{
  args = hideDivs.arguments;
  for (id = 0; id < args.length; id++) {
    if (!document.getElementById(args[id])) {
      //alert(args[id]);
      continue;
    }
    document.getElementById(args[id]).style.visibility = 'hidden';
    document.getElementById(args[id]).style.display    = 'none';
  }

  return args.length;
}


/**
 * unhideDiv
 *
 * Shows the first parameter, and hides the following params
 */
function unhideDiv(divNameToShow)
{
  if (document.getElementById) {
    /**
     * DOM3 = IE5, NS6
     */

    /**
     * Show the requested div
     */
    document.getElementById(divNameToShow).style.visibility = 'visible';
    document.getElementById(divNameToShow).style.display    = 'block';

    /**
     * Hide the rest of the divs
     * Start at 1 because 0 is for the divNameToShow
     */
    for (id = 1; id < unhideDiv.arguments.length; id++) {
      if (unhideDiv.arguments[id] != divNameToShow) {
        document.getElementById(unhideDiv.arguments[id]).style.visibility = 'hidden';
        document.getElementById(unhideDiv.arguments[id]).style.display    = 'none';
      }
    }
  }
  else {
    if (document.layers) {
      /**
       * NS4
       */
      eval('document.' + divNameToShow + '.visibility="visible"');
      eval('document.' + divNameToShow + '.display="block"');
      /**
       * Hide the rest of the divs
       * Start at 2 because 0 is for the function name and 1 for the divNameToShow
       */
      for (id = 2; id < unhideDiv.arguments.length; id++) {
        if (unhideDiv.arguments[id] != divNameToShow) {
          eval('document.' + unhideDiv.arguments[id] + '.visibility="hidden"');
          eval('document.' + unhideDiv.arguments[id] + '.display="none"');
        }
      }
    }
    else {
      /**
       * IE4
       */
      eval('document.all.' + divNameToShow + '.style.visibility="visible"');
      eval('document.all.' + divNameToShow + '.style.display="block"');
      /**
       * Hide the rest of the divs
       * Start at 1 because 0 is for the divNameToShow
       */
      for (id = 1; id < unhideDiv.arguments.length; id++) {
        if (unhideDiv.arguments[id] != divNameToShow) {
          eval('document.all.' + unhideDiv.arguments[id] + '.style.visibility="hidden"');
          eval('document.all.' + unhideDiv.arguments[id] + '.style.display="none"');
        }
      }
    }
  }
}

/**
 * switchVisibility
 *
 * Swaps the visibility of the specified DIV/LAYER.
 */
function switchVisibility(id, initialState)
{
  var state;
  if (document.getElementById) { // DOM3 = IE5, NS6
    state = document.getElementById(id).style.visibility;

    switch (state) {
      case 'visible':
        hideDiv(id);
        break;

      case 'hidden':
        showDiv(id);
        break;

      default:
        switch (initialState) {
          case 'visible':
            hideDiv(id);
            break;

          case 'hidden':
            showDiv(id);
            break;
        }
    }
  }
  else {
    if (document.layers) { // NS4
      eval('state = document.' + id + '.visibility');
    }
    else { // IE4
      eval('state = document.all.' + id + '.style.visibility');
    }
    if (state == "visible") {
      hideDiv(id);
    }
    else {
      showDiv(id);
    }
  }
}


/**
 * moveDiv
 *
 * Move the div to the specified x and y
 */
function moveDiv(divId,x,y)
{
  if (document.getElementById && document.getElementById(divId)) {
    divObj = document.getElementById(divId);

    // x is defined
    if (!isNaN(x)) {

      if (!isNaN(divObj.style.left)) {
        divObj.style.left = x;
      }
      else if (!isNaN(divObj.style.pixelLeft)) {
        divObj.style.pixelLeft = x;
      }
      else if (!isNaN(divObj.left)) {
        divObj.left = x;
      }
    }

    // y is defined
    if (!isNaN(y)) {
      if (!isNaN(divObj.style.top)) {
        divObj.style.top = y;
      }
      else if (!isNaN(divObj.style.pixelTop)) {
        divObj.style.pixelTop = y;
      }
      else if (!isNaN(divObj.top)) {
        divObj.top = y;
      }
    }
  }
  else if (document.layers) {
    eval('document.' + id + '.left = ' + x);
    eval('document.' + id + '.top = ' + y);
  }
  else if (document.all) {
    eval('document.all.' + id + '.style.left = ' + x);
    eval('document.all.' + id + '.style.top  = ' + x);
  }
}


/**
 * moveDivToCenter
 *
 * Moves a div to the center of the screen
 */
function moveDivToCenter(id,itemH,itemW)
{
  height  = getBrowserHeight();
  width   = getBrowserWidth();

  if (height <= 0 || width <= 0) {
    return;
  }

  centerH = Math.floor((height-itemH) / 2);
  centerW = Math.floor((width-itemW)  / 2);

  moveDiv(id,centerW,centerH)
}

function getBrowserHeight()
{
  if (typeof(window.innerHeight) == 'number') {
    return window.innerHeight;
  }

  if (document.documentElement && document.documentElement.clientHeight) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientHeight;
  }

  if (document.body && document.body.clientHeight) {
    //IE 4 compatible
    return document.body.clientHeight;
  }

  return 0;
}

function getBrowserWidth()
{
  if (typeof( window.innerWidth ) == 'number') {
    //Non-IE
    return window.innerWidth;
  }

  if (document.documentElement && document.documentElement.clientWidth) {
    //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientWidth;
  }

  if (document.body && document.body.clientWidth) {
    //IE 4 compatible
    return document.body.clientWidth;
  }

  return 0;
}

// Functions for IE to get position of an object
function getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}
function getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

function getCssObjXY(objID)
{
  // This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=getPageOffsetLeft(document.all[objID]);
		y=getPageOffsetTop(document.all[objID]);
		}
	else if (use_gebi) {
		var o=document.getElementById(objID);
		x=getPageOffsetLeft(o);
		y=getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=getPageOffsetLeft(document.all[objID]);
		y=getPageOffsetTop(document.all[objID]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==objID) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

function moveDivToAnchor(divID,anchorID,offsetX,offsetY)
{
  if (document.getElementById) {
    if (document.getElementById(divID)) {
      var divObj = document.getElementById(divID);
    }
    if (document.getElementById(anchorID)) {
      var anchorObj = document.getElementById(anchorID);
    }
  }

  if (isNaN(offsetX)) {
    offsetX = 0;
  }

  if (isNaN(offsetY)) {
    offsetY = 0;
  }

  coords = getCssObjXY(anchorObj.id);
  anchorObjX = coords.x
  anchorObjY = coords.y

  moveDiv(divID,anchorObjX + offsetX, anchorObjY + offsetY);
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";

function floatDiv(id, sx, sy)
{
  var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 10);
	}
	return el;
}


var FLOAT_DIV_OPENED = false;
function floatDivUntilOpened(id, sx, sy)
{
  var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
	  var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		if (!FLOAT_DIV_OPENED) {
	    this.sP(this.cx, this.cy);
	  }
		setTimeout(this.id + "_obj.flt()", 10);
	}
	return el;
}

//

var elementNameMonth = 'blank';
var elementNameDay   = 'blank';
var elementNameYear  = 'blank';

// Calendars in the main search -------------------------------
SEARCH_MAIN_FORM_NAME   = "search"
SEARCH_SIDE_FORM_NAME   = "sidesearch"

SEARCH_MAIN_FORM_OBJECT = "";
SEARCH_SIDE_FORM_OBJECT = "";

// Write out the calender popup stuff
document.write(CalendarPopup_getStyles());

var MAIN_START_CALENDAR     = new CalendarPopup("CalPopUp");
MAIN_START_CALENDAR.offsetX = 25;
MAIN_START_CALENDAR.offsetY = 0;
MAIN_START_CALENDAR.setReturnFunction("setMainStartDate");

var MAIN_END_CALENDAR       = new CalendarPopup("CalPopUp");
MAIN_END_CALENDAR.offsetX   = 25;
MAIN_END_CALENDAR.offsetY   = 0;
MAIN_END_CALENDAR.setReturnFunction("setMainEndDate");

var SEGMENT_DEPART_CALENDAR0 = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR0.offsetX = 25;
SEGMENT_DEPART_CALENDAR0.offsetY = 0;
SEGMENT_DEPART_CALENDAR0.setReturnFunction("setMainStartDate");

var SEGMENT_DEPART_CALENDAR1 = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR1.offsetX = 25;
SEGMENT_DEPART_CALENDAR1.offsetY = 0;
SEGMENT_DEPART_CALENDAR1.setReturnFunction("setMainStartDate");

var SEGMENT_DEPART_CALENDAR2 = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR2.offsetX = 25;
SEGMENT_DEPART_CALENDAR2.offsetY = 0;
SEGMENT_DEPART_CALENDAR2.setReturnFunction("setMainStartDate");

var SEGMENT_DEPART_CALENDAR3 = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR3.offsetX = 25;
SEGMENT_DEPART_CALENDAR3.offsetY = 0;
SEGMENT_DEPART_CALENDAR3.setReturnFunction("setMainStartDate");

var SEGMENT_DEPART_CALENDAR4 = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR4.offsetX = 25;
SEGMENT_DEPART_CALENDAR4.offsetY = 0;
SEGMENT_DEPART_CALENDAR4.setReturnFunction("setMainStartDate");

var SEGMENT_DEPART_CALENDAR5 = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR5.offsetX = 25;
SEGMENT_DEPART_CALENDAR5.offsetY = 0;
SEGMENT_DEPART_CALENDAR5.setReturnFunction("setMainStartDate");


var SEGMENT_ARRIVE_CALENDAR0 = new CalendarPopup("CalPopUp");
SEGMENT_ARRIVE_CALENDAR0.offsetX = 25;
SEGMENT_ARRIVE_CALENDAR0.offsetY = 0;
SEGMENT_ARRIVE_CALENDAR0.setReturnFunction("setMainStartDate");

var SEGMENT_ARRIVE_CALENDAR1 = new CalendarPopup("CalPopUp");
SEGMENT_ARRIVE_CALENDAR1.offsetX = 25;
SEGMENT_ARRIVE_CALENDAR1.offsetY = 0;
SEGMENT_ARRIVE_CALENDAR1.setReturnFunction("setMainStartDate");

var SEGMENT_ARRIVE_CALENDAR2 = new CalendarPopup("CalPopUp");
SEGMENT_ARRIVE_CALENDAR2.offsetX = 25;
SEGMENT_ARRIVE_CALENDAR2.offsetY = 0;
SEGMENT_ARRIVE_CALENDAR2.setReturnFunction("setMainStartDate");

var SEGMENT_ARRIVE_CALENDAR3 = new CalendarPopup("CalPopUp");
SEGMENT_ARRIVE_CALENDAR3.offsetX = 25;
SEGMENT_ARRIVE_CALENDAR3.offsetY = 0;
SEGMENT_ARRIVE_CALENDAR3.setReturnFunction("setMainStartDate");

var SEGMENT_ARRIVE_CALENDAR4 = new CalendarPopup("CalPopUp");
SEGMENT_ARRIVE_CALENDAR4.offsetX = 25;
SEGMENT_ARRIVE_CALENDAR4.offsetY = 0;
SEGMENT_ARRIVE_CALENDAR4.setReturnFunction("setMainStartDate");

var SEGMENT_ARRIVE_CALENDAR5 = new CalendarPopup("CalPopUp");
SEGMENT_ARRIVE_CALENDAR5.offsetX = 25;
SEGMENT_ARRIVE_CALENDAR5.offsetY = 0;
SEGMENT_ARRIVE_CALENDAR5.setReturnFunction("setMainStartDate");

var SEGMENT_DEPART_CALENDAR_DUMMY = new CalendarPopup("CalPopUp");
SEGMENT_DEPART_CALENDAR_DUMMY.offsetX = 25;
SEGMENT_DEPART_CALENDAR_DUMMY.offsetY = 0;
SEGMENT_DEPART_CALENDAR_DUMMY.setReturnFunction("setMainStartDate");

// Calendars in the side search  -------------------------------
var SIDE_START_CALENDAR     = new CalendarPopup("CalPopUp");
SIDE_START_CALENDAR.offsetX = 25;
SIDE_START_CALENDAR.offsetY = 0;
SIDE_START_CALENDAR.setReturnFunction("setSideStartDate");

var SIDE_END_CALENDAR       = new CalendarPopup("CalPopUp");
SIDE_END_CALENDAR.offsetX   = 25;
SIDE_END_CALENDAR.offsetY   = 0;
SIDE_END_CALENDAR.setReturnFunction("setSideEndDate");

var SIDE_SEGMENT_DEPART_CALENDAR0 = new CalendarPopup("CalPopUp");
SIDE_SEGMENT_DEPART_CALENDAR0.offsetX = 25;
SIDE_SEGMENT_DEPART_CALENDAR0.offsetY = 0;
SIDE_SEGMENT_DEPART_CALENDAR0.setReturnFunction("setSideStartDate");

var SIDE_SEGMENT_DEPART_CALENDAR1 = new CalendarPopup("CalPopUp");
SIDE_SEGMENT_DEPART_CALENDAR1.offsetX = 25;
SIDE_SEGMENT_DEPART_CALENDAR1.offsetY = 0;
SIDE_SEGMENT_DEPART_CALENDAR1.setReturnFunction("setSideStartDate");

var SIDE_SEGMENT_DEPART_CALENDAR2 = new CalendarPopup("CalPopUp");
SIDE_SEGMENT_DEPART_CALENDAR2.offsetX = 25;
SIDE_SEGMENT_DEPART_CALENDAR2.offsetY = 0;
SIDE_SEGMENT_DEPART_CALENDAR2.setReturnFunction("setSideStartDate");

var SIDE_SEGMENT_DEPART_CALENDAR3 = new CalendarPopup("CalPopUp");
SIDE_SEGMENT_DEPART_CALENDAR3.offsetX = 25;
SIDE_SEGMENT_DEPART_CALENDAR3.offsetY = 0;
SIDE_SEGMENT_DEPART_CALENDAR3.setReturnFunction("setSideStartDate");

var SIDE_SEGMENT_DEPART_CALENDAR_DUMMY = new CalendarPopup("CalPopUp");
SIDE_SEGMENT_DEPART_CALENDAR_DUMMY.offsetX = 25;
SIDE_SEGMENT_DEPART_CALENDAR_DUMMY.offsetY = 0;
SIDE_SEGMENT_DEPART_CALENDAR_DUMMY.setReturnFunction("setSideStartDate");


// --------------------------------------------------------------------
// Initialize the global form Objects, have to do this post document load.
// --------------------------------------------------------------------
function initSearchFormJS()
{
  if (SEARCH_MAIN_FORM_OBJECT == "") {
    SEARCH_MAIN_FORM_OBJECT = eval("document." + SEARCH_MAIN_FORM_NAME);
  }

  if (SEARCH_SIDE_FORM_OBJECT == "") {
    SEARCH_SIDE_FORM_OBJECT = eval("document." + SEARCH_SIDE_FORM_NAME);
  }
}

// --------------------------------------------------------------------
// Get the field for the starting date month
// --------------------------------------------------------------------
function getStartMonthObject(formObject)
{
  if (eval('formObject.'+elementNameMonth)) {
    return eval('formObject.'+elementNameMonth);
  }

  if (document.getElementById('CheckinMonth')) {
    // This is the hotel product
    return document.getElementById('CheckinMonth');
  }

  if (formObject.cruise_month) {
    return formObject.cruise_month;
  }

  if (formObject.pickup_month) {
    // This is car product.
    return formObject.pickup_month;
  }

  if (formObject.pickupMonth) {
    // This is car product.
    return formObject.pickupMonth;
  }

  if (formObject.depart_month) {
    // This is air product.
    return formObject.depart_month;
  }

  if (formObject.checkin_month) {
    // This is hotel product.
    return formObject.checkin_month;
  }
}

// --------------------------------------------------------------------
// Get the field for the starting date day
// --------------------------------------------------------------------
function getStartDayObject(formObject)
{
  if (eval('formObject.'+elementNameDay)) {
    return eval('formObject.'+elementNameDay);
  }

  if (document.getElementById('CheckinDay')) {
    // This is the hotel product
    return document.getElementById('CheckinDay');
  }

  if (formObject.pickup_day) {
    // This is car product.
    return formObject.pickup_day;
  }

  if (formObject.pickupDay) {
    // This is car product.
    return formObject.pickupDay;
  }

  if (formObject.depart_month) {
    // This is air product.
    return formObject.depart_day;
  }

  if (formObject.checkin_month) {
    // This is hotel product.
    return formObject.checkin_day;
  }

  return false;
}

// --------------------------------------------------------------------
// Get the field for the starting date year
// --------------------------------------------------------------------
function getStartYearObject(formObject)
{
  if (eval('formObject.'+elementNameYear)) {
    return eval('formObject.'+elementNameYear);
  }

  if (document.getElementById('CheckinYear')) {
    // This is the hotel product
    return document.getElementById('CheckinYear');
  }

  if (formObject.cruise_year) {
    return formObject.cruise_year;
  }

  if (formObject.pickup_year) {
    // This is car product.
    return formObject.pickup_year;
  }

  if (formObject.pickupYear) {
    // This is car product.
    return formObject.pickupYear;
  }

  if (formObject.depart_year) {
    // This is air product.
    return formObject.depart_year;
  }

  if (formObject.checkin_year) {
    // This is hotel product.
    return formObject.checkin_year;
  }
}

// --------------------------------------------------------------------
// Get the field for the ending date month
// --------------------------------------------------------------------
function getEndMonthObject(formObject)
{

  if (document.getElementById('CheckoutMonth')) {
    // This is the hotel product
    return document.getElementById('CheckoutMonth');
  }

  if (formObject.return_month) {
    // This is a car product
    return formObject.return_month;
  }

  if (formObject.returnMonth) {
    // This is a car product
    return formObject.returnMonth;
  }

  if (formObject.dest_month) {
    // This is a air product.
    return formObject.dest_month;
  }

  if (formObject.checkout_month) {
    // This is a hotel product.
    return formObject.checkout_month;
  }

  return false;
}

// --------------------------------------------------------------------
// Get the field for the ending date day
// --------------------------------------------------------------------
function getEndDayObject(formObject)
{

  if (document.getElementById('CheckoutDay')) {
    // This is the hotel product
    return document.getElementById('CheckoutDay');
  }

  if (formObject.return_month) {
    // This is a car product.
    return formObject.return_day;
  }

  if (formObject.returnMonth) {
    // This is a car product.
    return formObject.returnDay;
  }

  if (formObject.dest_month) {
    // This is a air product.
    return formObject.dest_day;
  }

  if (formObject.checkout_month) {
    // This is a hotel product.
    return formObject.checkout_day;
  }

  return false;
}

// --------------------------------------------------------------------
// Get the field for the ending date year
// --------------------------------------------------------------------
function getEndYearObject(formObject)
{

  if (document.getElementById('CheckoutYear')) {
    // This is the hotel product
    return document.getElementById('CheckoutYear');
  }

  if (formObject.return_year) {
    // This is a car product.
    return formObject.return_year;
  }

  if (formObject.returnYear) {
    // This is a car product.
    return formObject.returnYear;
  }

  if (formObject.dest_year) {
    // This is a air product.
    return formObject.dest_year;
  }

  if (formObject.checkout_year) {
    // This is a hotel product.
    return formObject.checkout_year;
  }

  return false;
}

// --------------------------------------------------------------------
// Set the start date, called from calendar
// --------------------------------------------------------------------
function setStartDate(formObject, y, m, d)
{
  var startMonthObject = getStartMonthObject(formObject);
  var startDayObject   = getStartDayObject(formObject);
  var startYearObject  = getStartYearObject(formObject);
  var endMonthObject   = getEndMonthObject(formObject);
  var endDayObject     = getEndDayObject(formObject);
  var endYearObject    = getEndYearObject(formObject);

  startMonthObject.selectedIndex = m - 1;
  updateStartCalendarDays(formObject);

  if (startDayObject) {
    startDayObject.selectedIndex   = d - 1;
  }

  if (startYearObject) {
    for (i = 0; i < startYearObject.options.length; i++) {
      if (startYearObject.options[i].value == y) {
        startYearObject.selectedIndex = i;
        break;
      }
    }
  }

  if (isMainSearchForm(formObject)) {
    MAIN_START_CALENDAR.currentDate=new Date(y, m -1, d);
  }

  if (isSideSearchForm(formObject)) {
    SIDE_START_CALENDAR.currentDate=new Date(y, m -1, d);
  }

  // Jump the end date according to TRAVEL_DAYS_APART from the start date
  update_travel_date(startMonthObject,startDayObject,endMonthObject,endDayObject,TRAVEL_DAYS_APART, startYearObject, endYearObject);

  // Update the calendar days based on the new end date.
  updateEndCalendarDays(formObject);

  if (elementNameMonth == 'dummyMonth') {
   formObject.segDepartMonth1.selectedIndex = formObject.dummyMonth.selectedIndex;
   formObject.segDepartDay1.selectedIndex   = formObject.dummyDay.selectedIndex;
   formObject.segDepartTime1.selectedIndex  = formObject.dummyTime.selectedIndex;
  }

  return true;
}

// --------------------------------------------------------------------
// Set the end date, called from calendar
// --------------------------------------------------------------------
function setEndDate(formObject, y, m, d)
{
  var endMonthObject   = getEndMonthObject(formObject);
  var endDayObject     = getEndDayObject(formObject);
  var endYearObject    = getEndYearObject(formObject);

  endMonthObject.selectedIndex = m - 1;
  updateEndCalendarDays(formObject);
  endDayObject.selectedIndex   = d - 1;
  if (endYearObject) {
    for (i = 0; i < endYearObject.options.length; i++) {
      if (endYearObject.options[i].value == y) {
        endYearObject.selectedIndex = i;
        break;
      }
    }
  }

  if (isMainSearchForm(formObject)) {
    MAIN_END_CALENDAR.currentDate=new Date(y, m -1, d);
  }

  if (isSideSearchForm(formObject)) {
    SIDE_END_CALENDAR.currentDate=new Date(y, m -1, d);
  }
}

// --------------------------------------------------------------------
// Assign the airport code to the appropriate field.
// --------------------------------------------------------------------
function aAssignAirportCode(aFormName,field,code) {
  airportField = eval("document." + aFormName + '.' + field);
  if (airportField) {
    airportField.value = code;
  }
}

// --------------------------------------------------------------------
// Called from Airport list page.
// --------------------------------------------------------------------
function assignAirportCode(field,code)
{
  initSearchFormJS();

  // We have to assign it to both, since we don't know where the airport code was chosen from.
  if (SEARCH_MAIN_FORM_OBJECT) {
    aAssignAirportCode(SEARCH_MAIN_FORM_NAME,field,code);
  }

  if (SEARCH_SIDE_FORM_OBJECT) {
    aAssignAirportCode(SEARCH_SIDE_FORM_NAME,field,code);
  }
}

// --------------------------------------------------------------------
// Abstract show calendar function
// --------------------------------------------------------------------
function aShowCalendar(formObject, calendarName, linkId, month, day, year)
{
  elementNameMonth = month;
  elementNameDay   = day;
  elementNameYear  = year;

  calObj = eval(calendarName);

  startMonthObject = getStartMonthObject(formObject);
  startDayObject   = getStartDayObject(formObject);
  startYearObject  = getStartYearObject(formObject);

  if (calendarName == 'MAIN_END_CALENDAR' || calendarName == 'SIDE_END_CALENDAR') {
    startMonthObject = getEndMonthObject(formObject);
    startDayObject   = getEndDayObject(formObject);
    startYearObject  = getEndYearObject(formObject);
  }

  startMonth = startMonthObject.selectedIndex;
  startDay   = startDayObject.selectedIndex + 1;

  if (!startYearObject) {
    startYear  = get_valid_year(startMonth, startDay); // declared in CalenderPopup.js
  }
  else {
    startYear = startYearObject.options[startYearObject.selectedIndex].value;
  }

  calObj.currentDate = new Date(startYear, startMonth, startDay);

  if (calObj.isVisible) {
    calObj.hideCalendar();
  }
  else {
    calObj.showCalendar(linkId);
  }

  return false;
}

// --------------------------------------------------------------------
// Set the depart date on the main search form
// --------------------------------------------------------------------
function setMainStartDate(y, m, d) {
  initSearchFormJS();

  if (SEARCH_MAIN_FORM_OBJECT) {
    setStartDate(SEARCH_MAIN_FORM_OBJECT,y,m,d);
  }
}

// --------------------------------------------------------------------
// Set the dest date on the main search form
// --------------------------------------------------------------------
function setMainEndDate(y, m, d) {
  initSearchFormJS();

  if (SEARCH_MAIN_FORM_OBJECT) {
    setEndDate(SEARCH_MAIN_FORM_OBJECT, y, m, d);
  }
}

// --------------------------------------------------------------------
// Set the depart date on the side search form
// --------------------------------------------------------------------
function setSideStartDate(y, m, d) {
  initSearchFormJS();

  if (SEARCH_SIDE_FORM_OBJECT) {
    setStartDate(SEARCH_SIDE_FORM_OBJECT,y,m,d);
  }
}

// --------------------------------------------------------------------
// Set the dest date on the side search form
// --------------------------------------------------------------------
function setSideEndDate(y, m, d) {
  initSearchFormJS();

  if (SEARCH_SIDE_FORM_OBJECT) {
    setEndDate(SEARCH_SIDE_FORM_OBJECT, y, m, d);
  }
}

// --------------------------------------------------------------------
// Switch the air flight type
// --------------------------------------------------------------------
function airSwitchFlightType(aForm, flightType, airIndexURL)
{
  aForm.flight_type.value = flightType;
  if (airIndexURL && airIndexURL.length) {
    aForm.action = airIndexURL;
    aForm.submit();
  }
}

// --------------------------------------------------------------------
// Check if the flight is round trip.
// --------------------------------------------------------------------
function isRoundTrip(aForm)
{
  // Make sure the flight_type field exists in the form.
  if (!aForm.flight_type) {
    return false;
  }

  // 0 means that it is a round trip flight
  if (aForm.flight_type.value == 0) {
    return true;
  }

  return false;
}

// --------------------------------------------------------------------
// Check if the flight is oneway.
// --------------------------------------------------------------------
function isOneWay(aForm)
{

  // Make sure the flight_type field exists in the form.
  if (!aForm.flight_type) {
    return false;
  }

  // 1 means that it is a oneway flight
  if (aForm.flight_type.value == 1) {
    return true;
  }

  return false;
}



// --------------------------------------------------------------------
// Determine whether or not it is the main search form
// --------------------------------------------------------------------
function isMainSearchForm(formObject)
{
  // Quick check on the formObject to see if it exists
  if (!formObject) {
    return false;
  }

  if (formObject.name == SEARCH_MAIN_FORM_NAME) {
    return true;
  }

  return false;
}

// --------------------------------------------------------------------
// Determine whether or not it is the side search form
// --------------------------------------------------------------------
function isSideSearchForm(formObject)
{
  // Quick check on the formObject to see if it exists
  if (!formObject) {
    return false;
  }

  if (formObject.name == SEARCH_SIDE_FORM_NAME) {
    return true;
  }

  return false;
}


// --------------------------------------------------------------------
// Get the starting calendar object based on the form we are in
// --------------------------------------------------------------------
function getStartCalendarObject(formObject)
{
  if (isMainSearchForm(formObject)) {
    return MAIN_START_CALENDAR;
  }

  if (isSideSearchForm(formObject)) {
    return SIDE_START_CALENDAR;
  }
}


// --------------------------------------------------------------------
// Get the ending calendar object based on the form we are in
// --------------------------------------------------------------------
function getEndCalendarObject(formObject)
{
   if (isMainSearchForm(formObject)) {
    return MAIN_END_CALENDAR
  }

  if (isSideSearchForm(formObject)) {
    return SIDE_END_CALENDAR;
  }
}

// --------------------------------------------------------------------
// Update the days of the start date months select drop down and the start
// calendar.
// --------------------------------------------------------------------
function updateStartCalendarDays(formObject, updateEnd, month, day)
{
  if (updateEnd == null && !document.getElementById('pickup_city')) {
    updateEnd = true;
  }
  else {
    updateEnd = false;
  }

  // Get the start date field objects
  startMonthObject = getStartMonthObject(formObject);
  startDayObject   = getStartDayObject(formObject);
  startYearObject  = getStartYearObject(formObject);

  if (!startYearObject) {
    startYearObject = null;
  }

  // Get the end date field objects
  endMonthObject   = getEndMonthObject(formObject);
  endDayObject     = getEndDayObject(formObject);
  endYearObject    = getEndYearObject(formObject);

  if (!endYearObject) {
    endYearObject = null;
  }

  // Reset the days on the start date and update the calendar
  resetDays(startMonthObject,startDayObject, startYearObject,getStartCalendarObject(formObject));

  // Update the end date based on the start date
  update_travel_date(startMonthObject,startDayObject,endMonthObject,endDayObject,TRAVEL_DAYS_APART, startYearObject, endYearObject);

  // Reset the days of the end date and update the calendar
  if (updateEnd) {
    updateEndCalendarDays(formObject);
  }

  return true;
}

// --------------------------------------------------------------------
// Update the days of the end date days select drop down and the start
// calendar.
// --------------------------------------------------------------------
function updateEndCalendarDays(formObject)
{
  // Get the start date field objects
  startMonthObject = getStartMonthObject(formObject);
  startDayObject   = getStartDayObject(formObject);

  // Get the end date field objects
  endMonthObject    = getEndMonthObject(formObject);
  endDayObject      = getEndDayObject(formObject);
  endYearObject     = getEndYearObject(formObject);

  endCalendarObject = getEndCalendarObject(formObject);

  endMonth = endMonthObject.selectedIndex;
  endDay   = endDayObject.selectedIndex + 1;

  if (!endYearObject) {
    endYear  = get_valid_year(endMonth,endDay); // declared in CalenderPopup.js
    endYearObject = null;
  }
  else {
    endYear  = endYearObject.options[endYearObject.selectedIndex].value;
  }

  // Reset the days on the start date.
  resetDays(endMonthObject,endDayObject, endYearObject);

  // Set the calendar to the current date.
  getEndCalendarObject(formObject).currentDate = new Date(endYear, endMonth, endDay);

  return true;
}

// --------------------------------------------------------------------
// Switch the air flight type accordingly, redirect if airIndexURL is
// defined
// --------------------------------------------------------------------
function airSwitchFlightType(formObject, flightType, airIndexURL)
{
  formObject.flight_type.value = flightType;
  if (airIndexURL && airIndexURL.length) {
    formObject.action = airIndexURL;
    formObject.submit();
  }
}

// --------------------------------------------------------------------
// Switch the air form to one-way
// --------------------------------------------------------------------
function airSearchShowOneWay(formObject)
{
  airSwitchFlightType(formObject,1);

  if (isMainSearchForm(formObject)) {
    hideDiv('mainSearchReturnDate');
  }

  if (isSideSearchForm(formObject)) {
    hideDiv('sideSearchReturnDate');
  }
}

// --------------------------------------------------------------------
// Switch the air form to round trip
// --------------------------------------------------------------------
function airSearchShowRoundTrip(formObject)
{
  airSwitchFlightType(formObject,0);

  if (isMainSearchForm(formObject)) {
    showDiv('mainSearchReturnDate');
  }

  if (isSideSearchForm(formObject)) {
    showDiv('sideSearchReturnDate');
  }
}

// --------------------------------------------------------------------
// Show the correct form based on the flightType passed in:
//   0 : roundtrip
//   1 : one-way
// --------------------------------------------------------------------
function updateAirSearchForm(formObject,flightType)
{
  if (flightType) {
    airSearchShowOneWay(formObject);
  }
  else {
    airSearchShowRoundTrip(formObject);
  }
}

// --------------------------------------------------------------------
// Checks the dates of travel upon submit
// --------------------------------------------------------------------
function checkTravelDates(formObject, no_days)
{
  currDate  = new Date();
  currMonth = currDate.getMonth();
  currYear  = currDate.getFullYear();

  // Get the start date field objects
  startMonthObject = getStartMonthObject(formObject);
  startDayObject   = getStartDayObject(formObject);

  endMonthObject   = getEndMonthObject(formObject);
  endDayObject     = getEndDayObject(formObject);

  // roundTrip = isRoundTrip(aForm);

  // Get the start dates
  startMonth = startMonthObject.selectedIndex
  startDay   = startDayObject.selectedIndex + 1;
  startYear  = get_valid_year(startMonth,startDay); // declared in CalenderPopup.js

  /*
  if (roundTrip) {
    month2 = aForm.dest_month.selectedIndex;
    day2 = aForm.dest_day.selectedIndex + 1;
    year2 = get_valid_year(month2, day2);
  }

  dateX = new Date(year1, month1, day1);

  if (roundTrip) {
    dateY = new Date(year2, month2, day2);
  }

  // Invalid date
  if (dateX.getTime() < currDate.getTime()) {
    message = message + "The departure date must be at least 1 day from today.\n";
    aForm.depart_day.focus();
    return false;
  }
  else if (roundTrip && dateY.getTime() < dateX.getTime()) {
    message = message + "The return date must be later than the departure date.\n";
    aForm.dest_day.focus();
    return false;
  }
  else if (no_days != null && dateX.getTime() > currDate.getTime() + (no_days * (1000 * 60 * 60 * 24))) {
    message = message + "The departure date must be earlier than "+ no_days +" days from now for bidding.\n";
    aForm.depart_day.focus();
  }
  */
  return true;
}

// --------------------------------------------------------------------
// Validate the search form
// --------------------------------------------------------------------
function validateSearchForm() {
	var message = '';
	var aFrom = document.search;
	var sel = aFrom.search_type.selectedIndex;

	switch(sel) {
		case 0: //city
			if (aFrom.hotel_city.value == '') {
				message = "Please enter a city.";
				aFrom.hotel_city.focus();
			}
		break;
		case 1: //Airport
			if (aFrom.hotel_city_code.value == '') {
				message = "Please enter an airport code.";
				aFrom.hotel_city_code.focus();
			}
		break;
		case 2: //Address
			if (aFrom.hotel_zipcode.value == '') {
				message = "Please enter a zip/postal code.";
				aFrom.hotel_zipcode.focus();
			}
			if (aFrom.hotel_city.value == '') {
				message = "Please enter a city.";
				aFrom.hotel_city.focus();
			}
			if (aFrom.hotel_address.value == '') {
				message = "Please enter an address.";
				aFrom.hotel_address.focus();
			}
		break;
		case 3: //Zip code
			if (aFrom.hotel_zipcode.value == '') {
				message = "Please enter a zip/postal code.";
				aFrom.hotel_zipcode.focus();
			}
		break;
	}

	checkTravelDates(document.search);

	if(message != '') {
		alert(message);
		return false;
	}
	if(window.loadSplash) loadSplash();
	return true;
}


function checkCruiseForm(formObj)
{
  if (checkField(formObj.DestinationID, "Please select a destination.")) {
    return true;
  }
  return false;
}

function checkCruiseLineForm(formObj)
{
  if (checkField(formObj.VendorID, "Please select a cruise line.")) {
    return true;
  }
  return false;
}


function validateForm(aForm)
{
  message = '';

  if(aForm.pickup_month) {
    checkDateCar(aForm);
  }
  else if(aForm.depart_month) {
    checkDateAir(aForm, TRAVEL_DAYS_APART);
  }
  else if(aForm.checkin_month) {
    checkDateHotel(aForm, TRAVEL_DAYS_APART);
  }

  if(message != '') {
    alert(message);
    return false;
  }

  if(window.loadSplash) loadSplash();

  return true;
}


/**
 * For car search forms.
 */
function checkDateCar(aForm)
{
  // Now
  initDate    = new Date();

  // Current date obj
  currMonth   = initDate.getMonth();
  currYear    = initDate.getFullYear();
  currDay     = initDate.getDate();
  currHour    = initDate.getHours();
  currDate    = new Date(currYear, currMonth, currDay, currHour, 0, 0, 0);

  // Pickup date obj
  if (aForm.elements['pickup_month'].type == 'select-one') {
    month1      = aForm.pickup_month.selectedIndex;
  }
  else {
    month1      = aForm.pickup_month.value - 1;
  }

  if (aForm.elements['pickup_day'].type == 'select-one') {
    day1        = aForm.pickup_day.selectedIndex + 1;
  }
  else {
    day1        = aForm.pickup_day.value;
  }

  if (aForm.elements['pickup_year']) {
    year1 = aForm.pickup_year.value;
  }
  else {
    year1     = get_valid_year(month1, day1);
  }

  hour1       = aForm.pickup_time.value;
  dateX       = new Date(year1, month1, day1, hour1, 0, 0, 0);

  // Return date obj
  if (aForm.elements['return_month'].type == 'select-one') {
    month2      = aForm.return_month.selectedIndex;
  }
  else {
    month2      = aForm.return_month.value - 1;
  }

  if (aForm.elements['return_day'].type == 'select-one') {
    day2        = aForm.return_day.selectedIndex + 1;
  }
  else {
    day2        = aForm.return_day.value;
  }

  if (aForm.elements['return_year']) {
    year2     = aForm.return_year.value;
  }
  else {
    year2     = get_valid_year(month2, day2);
  }

  hour2       = aForm.return_time.value;
  dateY       = new Date(year2, month2, day2, hour2, 0, 0, 0);

  // pieces of time in a day.
  var day_mseconds = (24 * 60 * 60 * 1000);

  // car search must be on or after this timestamp
  var min_time    = currDate.getTime() + (day_mseconds * CARMINDAYS);
  var minDate     = new Date(min_time);

  // Amount of lead time required by this site to book cars.
  var min_hours_warn = CARMINDAYS * 24;

  // Check Pickup city.
  if(aForm.elements['pickup_city'] && aForm.pickup_city.value == '') {
    message = message + "Pick up location can not be empty.\n";
    aForm.pickup_city.focus();
  }

  // Return city is an optional field, driven by config/gds for oneway rentals
  if (aForm.elements['return_city']) {
    // Set return city to the value of the pickup city by default
    if (aForm.return_city.value == '' && aForm.pickup_city.value != '') {
      setDefaultReturnCity(aForm.return_city);
    }
    // if a return city is available validate that a vendor has been selected, required for one way rentals.
    validateOneWay(aForm);
  }

  // Pickup date validation, before today?
  if (dateX.getTime() < currDate.getTime()) {
    message = message + "The pickup date and time must be later than the current date and time.\n";
    aForm.pickup_day.value   = minDate.getDate();
    aForm.pickup_month.value = minDate.getMonth() + 1;
    aForm.pickup_time.value  = minDate.getHours() + 1;
    if (aForm.elements['pickup_year']) {
      aForm.pickup_year.value  = minDate.getYear();
    }
    if (aForm.elements['pickup_day'].type != 'hidden') {
      aForm.pickup_day.focus();
    }
  }

  // Pickup date validation, check for min days?
  if (min_hours_warn > 0 && dateX.getTime() <= min_time) {
    message = message + "The pickup date and time must be at least ";
    message = message + min_hours_warn;
    message = message + " hours from now.\n";

    // write document min values for pickup time, day, month, year...
    aForm.pickup_day.value   = minDate.getDate();
    aForm.pickup_month.value = minDate.getMonth() + 1;
    aForm.pickup_time.value  = minDate.getHours() + 1;
    if (aForm.elements['pickup_year']) {
      aForm.pickup_year.value  = minDate.getYear();
    }
    if (aForm.elements['pickup_day'].type != 'hidden') {
      aForm.pickup_day.focus();
    }
  }

  // Return time is the same or sooner than pickup time
  if (dateY.getTime() <= dateX.getTime()) {
    // different year?
    if (year1 != year2) {
      message = message + "You have entered an invalid date range. Please check the dates and try again.\n";
    }
    else {
      message = message + "The return date must be later than the pickup date.\n";
    }

    if (aForm.elements['return_day'].type != 'hidden') {
      aForm.return_day.focus();
    }
  }

  return true;
}


/**
 * for car search forms, make sure that a vendor is selected when chosing a one way rental.
 */
function validateOneWay(form)
{
  // if there is a select list, find it's value and test, if not return true and continue.
  if (form.elements['car_company'].type == 'select-one') {
    var car_company_selected = form.elements['car_company'].value;
  }
  else {
    return true;
  }

  // test for an input field for return city, if it is different from the pickup city, force vendor selection (one-way).
  if (form.elements['return_city'].value) {
    if (form.elements['return_city'].value != form.elements['pickup_city'].value && car_company_selected == 0) {
      message = message + 'You must select a specific car company for one way rentals.\n';
      return false;
    }
  }

  return true;
}


/**
 * prefill return city when one way searches are available.
 */
function setDefaultReturnCity(form)
{
  if (form.elements['return_city']) {
    var pickup_city_value = form.pickup_city.value;

    if (form.return_city.value == '') {
      form.return_city.value = pickup_city_value;
    }

    return true;
  }

  return false;
}


/**
 * Air search forms
 */
function checkDateAir(aForm, no_days)
{
  currDate = new Date();
  currMonth = currDate.getMonth();
  currYear = currDate.getFullYear();

  roundTrip = isRoundTrip(aForm);

  month1 = aForm.depart_month.selectedIndex + 1;
  day1 = aForm.depart_day.selectedIndex + 1;
  year1 = get_valid_year(month1, day1);
  hour1 = aForm.depart_time.selectedIndex + 1;

  if (roundTrip) {
    month2 = aForm.dest_month.selectedIndex;
    day2 = aForm.dest_day.selectedIndex + 1;
    year2 = get_valid_year(month2, day2);
    hour2 = aForm.depart_time.selectedIndex + 1;
  }

  dateX = new Date(year1, month1, day1, hour1, 0, 0, 0);

  if (roundTrip) {
    dateY = new Date(year2, month2, day2, hour2, 0, 0, 0);
  }

  // Invalid date
  if (dateX.getTime() <= currDate.getTime()) {
    message = message + "The departure date must be after the current time.\n";
    aForm.depart_day.focus();
    return false;
  }
  else if (dateX.getTime() < (currDate.getTime() + (1000 * 60 * 60 * 24))) {
    message = message + "Same Day Travel or Travel within 24hrs not permitted.\n";
    aForm.depart_day.focus();
    return false;
  }
  else if (roundTrip && dateY.getTime() < dateX.getTime()) {
    message = message + "The return date must be later than the departure date.\n";
    aForm.dest_day.focus();
    return false;
  }
  /* Not sure why we have this so commenting out.
  else if (no_days != null && dateX.getTime() > currDate.getTime() + (no_days * (1000 * 60 * 60 * 24))) {
    alert(dateX.getTime() + ' > ' +  (no_days * (1000 * 60 * 60 * 24)));
    message = message + "The departure date must be earlier than 60 days from today.\n";
    aForm.depart_day.focus();
  }
  */
  return true;
}

function checkDateHotel(aForm, no_days)
{
  currDate = new Date();
  currMonth = currDate.getMonth();
  currYear = currDate.getFullYear();

  month1 = aForm.checkin_month.selectedIndex;
  day1 = aForm.checkin_day.selectedIndex + 1;
  year1 = get_valid_year(month1, day1);

  month2 = aForm.checkout_month.selectedIndex;
    day2 = aForm.checkout_day.selectedIndex + 1;
  year2 = get_valid_year(month2, day2);

  dateX = new Date(year1, month1, day1);
  dateY = new Date(year2, month2, day2);

  // Invalid date
  if (dateX.getTime() < currDate.getTime()) {
    message = message + "The departure date must be at least 1 day from today.\n";
    aForm.checkin_day.focus();
    return false;
  } else if (dateY.getTime() < dateX.getTime()) {
    message = message + "The return date must be later than the departure date.\n";
    aForm.checkout_day.focus();
    return false;
    }

//  else if (no_days != null && dateX.getTime() > currDate.getTime() + (no_days * (1000 * 60 * 60 * 24))) {
//  message = message + "The departure date must be earlier than "+ no_days +" days from now for bidding.\n";
//  aForm.checkin_day.focus();
//  }
//  return true;
}

// --------------------------------------------------------------------
// When using a map to search for a city, this will redirect the parent
// windown to the search page and close the popup window.
// --------------------------------------------------------------------
function search_redirect(url)
{
  opener.location=url;
  this.close();
}

function setPickupDate(y, m, d) {
  formObj = document.search;
  formObj.pickup_day.selectedIndex = d - 1;
  formObj.pickup_month.selectedIndex = m - 1;

  if (formObj.pickup_year) {
    for (i = 0; i < pickup_year.options.length; i++) {
      if (pickup_year.options[i].value == y) {
        pickup_year.selectedIndex = i;
        break;
      }
    }
  }

  return true;
}
function setReturnDate(y, m, d) {
  formObj = document.search;
  formObj.return_day.selectedIndex = d - 1;
  formObj.return_month.selectedIndex = m - 1;

  if (formObj.return_year) {
    for (i = 0; i < return_year.options.length; i++) {
      if (return_year.options[i].value == y) {
        return_year.selectedIndex = i;
        break;
      }
    }
  }

  return true;
}
//


function formbuttonClassNew(obj, new_style) {
    obj.className = new_style;
}
function blockClassNew(obj, new_style) {
    obj.className = new_style;
}
function disableSubmit(btn,form) {
  var submitMessage = "Processing...";
  btn.value = submitMessage;
  btn.disabled = true;
  form.submit();
  return false;
}
//





var optionsArray = new Array('hotel_chain',
                             'hotel_name',
                             'hotel_rating',
                             'hotel_amenities'
                             )

// Validate Date
function checkDate(aForm, no_days) {
    currDate = new Date();
    currMonth = currDate.getMonth();
    currYear = currDate.getFullYear();

    month1 = aForm.depart_month.selectedIndex;
    day1 = aForm.depart_day.selectedIndex + 1;
    year1 = get_valid_year(month1, day1);

    month2 = aForm.dest_month.selectedIndex;
      day2 = aForm.dest_day.selectedIndex + 1;
    year2 = get_valid_year(month2, day2);

    dateX = new Date(year1, month1, day1);
    dateY = new Date(year2, month2, day2);

    // Invalid date
    if (dateX.getTime() < currDate.getTime()) {
        message = message + "The departure date must be at least 1 day from today.\n";
        aForm.depart_day.focus();
        return false;
    } else if (dateY.getTime() < dateX.getTime()) {
        message = message + "The return date must be later than the departure date.\n";
        aForm.dest_day.focus();
        return false;
      } else if (no_days != null && dateX.getTime() > currDate.getTime() + (no_days * (1000 * 60 * 60 * 24))) {
        message = message + "The departure date must be earlier than "+ no_days +" days from now for bidding.\n";
        aForm.depart_day.focus();
    }
    return true;
}

function updateDates(currentObjectNum)
{
  formObj = document.search;

  switch (currentObjectNum) {
    case 0:
      update_travel_date(formObj.segDepartMonth0,formObj.segDepartDay0,formObj.segDepartMonth1,formObj.segDepartDay1,7);
      resetDays(formObj.segDepartMonth0,formObj.segDepartDay0,'null',formObj.SEGMENT_DEPART_CALENDAR0);
      update_travel_date(formObj.segDepartMonth0,formObj.segDepartDay0,formObj.dummyMonth,     formObj.dummyDay,     7);
      resetDays(formObj.dummyMonth     ,formObj.dummyDay     ,'null',formObj.SEGMENT_DEPART_CALENDAR_DUMMY);
    case 1:
      update_travel_date(formObj.segDepartMonth1,formObj.segDepartDay1,formObj.segDepartMonth2,formObj.segDepartDay2,7);
      resetDays(formObj.segDepartMonth1,formObj.segDepartDay1,'null',formObj.SEGMENT_DEPART_CALENDAR1);
    case 2:
      update_travel_date(formObj.segDepartMonth2,formObj.segDepartDay2,formObj.segDepartMonth3,formObj.segDepartDay3,7);
      resetDays(formObj.segDepartMonth2,formObj.segDepartDay2,'null',formObj.SEGMENT_DEPART_CALENDAR2);
      resetDays(formObj.segDepartMonth3,formObj.segDepartDay3,'null',formObj.SEGMENT_DEPART_CALENDAR3);
  }

  return;
}

function picksearch_type(form) 
{
  // var airportCodeObj = new String(form.hotel_airport_code.value);
  var addressObj = new String(form.hotel_address.value);
  var cityObj = new String(form.hotel_city.value);
  /*
  if (airportCodeObj != '') {
    form.search_type.selectedIndex = 2;
  }
  */
  // clearAddress();
  if (addressObj != '') {
    form.search_type.selectedIndex = 1;
  } 
  else {
    form.search_type.selectedIndex = 0;
    clearAddress();
  }
  return true;
}

function clearAddress() 
{
  document.getElementById('hotel_city').value = "";
  document.getElementById('hotel_address').value = "";
  document.getElementById('hotel_state').selectedIndex = 0;
  document.getElementById('hotel_country').selectedIndex = 0;
  return true;
}

function clearZipcode()
{  
  document.getElementById('hotel_zipcode').value = "";
  return true;
}  

function clearAirport()
{
  document.getElementById('hotel_city_code').value = "";
  return true;
}

function clearCity()
{
  document.getElementById('hotel_city').value = "";
  return true;
}

function switchShowDiv(selectObj)
{
  switch (selectObj.options.selectedIndex) {
    
    case 0: // by City
    default:
      // Hide 
      hideDiv('zipcode_title');
      hideDiv('address_title');
      hideDiv('airport_title');
      hideDiv('searchByAirport');
      hideDiv('searchByAddressStreet');
      hideDiv('searchByAddressZip');
      // Show 
      showSpan('city_title');
      showSpan('searchByAddress');
      showSpan('searchByAddressCity');
      showSpan('searchByAddressState');
      showSpan('searchByAddressCountry');
      changeCountry();
      // Clear
      clearAirport();
      break;

    case 1: // by Airport
      // Hide 
      hideDiv('zipcode_title');
      hideDiv('address_title');
      hideDiv('city_title');
      hideDiv('searchByAddress');
      // Show 
      showSpan('airport_title');
      showSpan('searchByAirport');
      // Clear
      clearAddress();
      clearZipcode();
      break;

    case 2: // By Address
      // Hide 
      hideDiv('zipcode_title');
      hideDiv('city_title');
      hideDiv('airport_title');
      hideDiv('searchByAirport');
      // Show 
      showSpan('address_title');
      showSpan('searchByAddress');
      showSpan('searchByAddressCity');
      showSpan('searchByAddressStreet');
      showSpan('searchByAddressState');
      showSpan('searchByAddressZip');
      showSpan('searchByAddressCountry');
      changeCountry();
      // Clear
      // clearAddress();
      break;
      
    case 3: // By Zipcode
      // Hide 
      hideDiv('city_title');
      hideDiv('address_title');
      hideDiv('airport_title');
      hideDiv('searchByAirport');
      hideDiv('searchByAddressStreet');
      hideDiv('searchByAddressState');
      hideDiv('searchByAddressCity');
      hideDiv('searchByAddressCountry');
      // Show 
      showSpan('zipcode_title');
      showSpan('searchByAddress');
      showSpan('searchByAddressZip');
      // Clear
      clearAddress();
      break;            
  }
}

function GetRadioValue(rArray)
{
	for (var i=0;i<rArray.length;i++)
	{
		if (rArray[i].checked)
			return rArray[i].value;
	}

	return null;
}

function showOptions(action)
{
  if (action == 'on') {
    showSpan('searchOptionsOn');
    hideDiv('searchOptionsOff');
  }
  else {
    showSpan('searchOptionsOff');
    hideDiv('searchOptionsOn');
  }
  return true;  
}

function showOptionsSelected(form)
{  
  showOptions('off');
  var options = 'off';
  if(document.getElementById('hotel_name').value != '') {
    var options = 'on';
  }

  if (document.getElementById('hotel_rating').selectedIndex > 0) {
    var options = 'on';
  }
  if (document.getElementById('hotel_chain').selectedIndex > 0) {
    var options = 'on';
  }
  
  /*
  var hotel_amenities_count = document.search.hotel_amenities.length;
  
  for (i = 0; i < hotel_amenities_count; i++)
  {
    var testObj = document.search.hotel_amenities[i];
    if (document.getElementById) {
      if (testObj.checked) {
        var options = 'on';
        break;
      }
    }
  }
  */
  
  if (options == 'on') {
    showOptions('on');
  }
  
  return true;
}

function changeCountry()
{
  var country = document.search.hotel_country.value;
 
  if (country == 'US' || country == 'CA') {
    showSpan('searchByAddressState');
  }
  else {
    hideDiv('searchByAddressState');
    document.search.hotel_state.selectedIndex = 0;
  }
  return true; 
}

//

// Set location of pop-up calendars
MAIN_START_CALENDAR.offsetX = 25;
MAIN_START_CALENDAR.offsetY = 0;
MAIN_END_CALENDAR.offsetX   = 25;
MAIN_END_CALENDAR.offsetY   = 0;