////////////////////////////////////////
  var bLEAVING           = false;
  var bRETURNING         = true;
  
  // initialize JavaScript variable from action form
  var dateLeavingMonth   = '';
  var dateLeavingDate    = '';
  var dateReturningMonth = '';
  var dateReturningDate  = '';
  var date;

  // if date fields not initialized, then initialize to today's date + 21 days and today + 24 days
  if ((dateLeavingMonth   == "") || (dateLeavingDate   == ""))
  {
     date = new Date ( );
     date = new Date (date.getTime( ) + 21*24*60*60*1000);  // add 21 days
     dateLeavingMonth   = date.getMonth ( ) + 1;
     dateLeavingDate    = date.getDate  ( );
  }
  if ((dateReturningMonth == "") || (dateReturningDate == ""))
  {
     date = new Date ( );
     date = new Date (date.getTime( ) + 24*24*60*60*1000);  // add 24 days
     dateReturningMonth = date.getMonth ( ) + 1;
     dateReturningDate  = date.getDate  ( );
  }
function fhDate()
 {
   var now = new Date();
   var mth = now.getMonth();
   var dd = now.getDate();
   if (mth < 10)
    {
      mth == 0 + mth;
     }
   if (dd < 10)
    {
      dd == 0 + dd;
    }
     if ((mth==11) && (dd>=29)) {
                    document.ct_horizontal_a.dateLeavingMonth.selectedIndex = 00;
                    document.ct_horizontal_a.dateLeavingDay.selectedIndex = 06;
                    document.ct_horizontal_a.dateReturningDay.selectedIndex = 10;
                    document.ct_horizontal_a.dateReturningMonth.selectedIndex = 00;
     }
     else if ((dd>=29 ) || ((dd>=27 ) && (mth==1)))
     {
     document.ct_horizontal_a.dateLeavingMonth.selectedIndex = 02;
     document.ct_horizontal_a.dateLeavingDay.selectedIndex = 06;
     document.ct_horizontal_a.dateReturningDay.selectedIndex = 10;
     document.ct_horizontal_a.dateReturningMonth.selectedIndex = 02;
    }
   else
    {
      document.ct_horizontal_a.dateLeavingMonth.selectedIndex=mth;
      document.ct_horizontal_a.dateLeavingDay.selectedIndex=dd+7;
      document.ct_horizontal_a.dateReturningMonth.selectedIndex=mth;
      document.ct_horizontal_a.dateReturningDay.selectedIndex=dd+10;
   }
}
  function initDaysInMonth (objFormName, bReturningLeaving)
  {
     var current = new Date ();
     var curDay = current.getDate();
     var month = current.getMonth() + 1;
     var year    = current.getYear ();
     var days;
     var options;

     var depMonth = parseInt(document.getElementById(objFormName).elements["dateLeavingDay"].value);
     var depDate = parseInt(document.getElementById(objFormName).elements["dateLeavingDay"].value );
     var depYear;
     var retMonth = parseInt(document.getElementById(objFormName).elements["dateReturningMonth"].value );
     var retDate = parseInt(document.getElementById(objFormName).elements["dateReturningDay"].value );
     var retYear;

     depYear = year;
     retYear = year;
     if (bReturningLeaving == bLEAVING)
     {
       days    = getDaysInMonth (depMonth, depYear);
       options = document.getElementById(objFormName).elements["dateLeavingDay"].options;
       initDaysArray (days, options);
     }
     else
     {
       days    = getDaysInMonth (retMonth, retYear);
       options = document.getElementById(objFormName).elements["dateReturningDay"].options;
       initDaysArray (days, options);
     }
     glbDepartureYear = depYear;
     glbArrivalYear = retYear;
     return (days);
  }


  function updateDaysInMonth (objFormName, bReturningLeaving)
  {
     var days;
     var date;

     if (bReturningLeaving == bLEAVING)
     {
       dateLeavingMonth   = document.getElementById(objFormName).elements["dateLeavingMonth"]  .value;
       date               = document.getElementById(objFormName).elements["dateLeavingDay"]    .value;
     }
     else
     {
       dateReturningMonth =document.getElementById(objFormName).elements["dateReturningMonth"].value;
       date               =document.getElementById(objFormName).elements["dateReturningDay"]  .value;
     }

     days = initDaysInMonth (objFormName, bReturningLeaving);

     if (date > days)
     {
       date = days;
     }
     if (bReturningLeaving == bLEAVING)
     {
      document.getElementById(objFormName).elements["dateLeavingDay"].value = date;
     }
     else
     {
      document.getElementById(objFormName).elements["dateReturningDay"].value = date;
     }
  }

  // initialize an option object array to hold the days for a select drop down
  function initDaysArray (days, options)
  {
     var ndx = 0;

     for (ndx = 0; ndx < days; ndx++)
       options[ndx] = new Option ( "" + (ndx + 1),  "" + (ndx + 1));
     options.length = days;
  }


winCal        = null;
winCal_closed = false;
xPos=0;
yPos=0;
 currTopMonIdx = 0;
 firstMon = 0;
 firstYear = 0;
 pickupMon = 0;
 currMidMonIdx = 0;    
 currBtmMonIdx = 0;
var daysInMonth = new Array(12);

function randomNum(number)
{
  rnd.today=new Date();
  rnd.seed=rnd.today.getTime();
  return Math.ceil(rnd()*number);
}

function rnd() {
  rnd.seed = (rnd.seed*9301+49297) % 233280;
  return rnd.seed/(233280.0);
}

function dateBoxes(name1,name2,dateType,yPosAdj, formname)
{
  this.box1Name      = name1;       // month
  this.box2Name      = name2;       // dayOfMonth
  this.boxesDateType = dateType;    // "CP" for pickup date or "CD" dropoff date
  this.boxesyPosAdj  = yPosAdj;
  this.formName      = formname;
} // end dateBoxes

function getMousePos(capEvent)
{
  if (document.layers) {
     xPos=this.screenX + 170
     yPos=capEvent.screenY - 115
  }
  else if (window.event) {
     xPos=this.screenLeft + 165
     yPos=window.event.clientY - 5
  }
  else {
     xPos=0
     yPos=0
  }
} // end getMousePos(capEvent)

function initVariables(selObj)
{
   var d = new Date();
   firstMon = d.getMonth() + 1;
   firstYear = d.getFullYear();
   pickupMon = selObj.options[selObj.selectedIndex].value;
   var temp =0;
   currTopMonIdx = 0;

     
   if ( pickupMon >= firstMon )
   {
      currTopMonIdx = ( pickupMon - firstMon );
   }
   else
   {
      currTopMonIdx = ( 12 + pickupMon ) - firstMon;
   }
 
   currTopMonIdx = parseInt(currTopMonIdx, 36);
   if (currTopMonIdx > 9)
   {
      currTopMonIdx = 9;
   }
   currMidMonIdx = currTopMonIdx + 1;
   currBtmMonIdx = currTopMonIdx + 2;

   daysInMonth[1]  = 31;
   daysInMonth[2]  = 28 + (isLeapYear(firstMon, firstYear)? 1 : 0);
   daysInMonth[3]  = 31;
   daysInMonth[4]  = 30;
   daysInMonth[5]  = 31;
   daysInMonth[6]  = 30;
   daysInMonth[7]  = 31;
   daysInMonth[8]  = 31;
   daysInMonth[9]  = 30;
   daysInMonth[10] = 31;
   daysInMonth[11] = 30;
   daysInMonth[12] = 31;
}

function isLeapYear(firstMon, firstYear)
{
  if ( (firstYear % 400) == 0)
  {
     return 1;
  }
  if (( (firstYear % 4) == 0 ) && ( (firstYear % 100) != 0) )
  {
     return 1;
  }
  return 0;
}

function selectDate(gridNum,monIdx)
{
  with(winCal.loadMonthImg[monIdx]) {
     var dateSelected = gridNum - firstDayGridNum;
     if(dateSelected >= 1 && dateSelected <= daysInMonth[monNumber]) {
        var selectedForm = currBoxes.formName;
        with(getRightForm(currBoxes.box1Name, selectedForm)) {
          with(currBoxes) {
            elements[box1Name].selectedIndex = monNumber - 1;
            if(elements[box1Name].onchange) elements[box1Name].onchange();
            elements[box2Name].selectedIndex = dateSelected - 1;
            if(elements[box2Name].onchange) elements[box2Name].onchange();
            if (monIdx < 9) 
            {
               currTopMonIdx = monIdx;
            }
            else
            {
               currTopMonIdx = 9;
            }
            currMidMonIdx = currTopMonIdx + 1;
            currBtmMonIdx = currMidMonIdx + 1;
            winCal.close();
          }
       }
     }
  }
} // end selectDate(gridNum,monIdx)

function changeMonths(numMonths)
{
   with(this.document)
   {
       if((currTopMonIdx != 0 && numMonths == -1) || (currBtmMonIdx != 11 && numMonths == 1) || (numMonths != -1 && numMonths != 1))
       {
           with (winCal.document)
           {
               images["topMonDates"].src = winCal.loadMonthImg[currTopMonIdx + numMonths].datesImg.src;
               images["topMonName"].src = winCal.loadMonthImg[currTopMonIdx + numMonths].nameImg.src;
               images["midMonDates"].src = winCal.loadMonthImg[currMidMonIdx + numMonths].datesImg.src;
               images["midMonName"].src = winCal.loadMonthImg[currMidMonIdx + numMonths].nameImg.src;
               images["btmMonDates"].src = winCal.loadMonthImg[currBtmMonIdx + numMonths].datesImg.src;
               images["btmMonName"].src = winCal.loadMonthImg[currBtmMonIdx + numMonths].nameImg.src;
               currTopMonIdx += numMonths;
               currMidMonIdx += numMonths;
               currBtmMonIdx += numMonths;
               images["moreDown"].src = (currBtmMonIdx == 11) ? winCal.calDownOff.src : winCal.calDownOn.src;
               images["moreUp"].src = (currTopMonIdx == 0) ? winCal.calUpOff.src : winCal.calUpOn.src;
               winCal.focus();
           }
       }
   }
}

function getRightForm(objNameInForm, reqForm)
{
  var selectedForm = findRightForm( reqForm );
  if ( !selectedForm )
  {
     with(this.document) 
     {
       for(var i = 0; i < forms.length; i++) {
          with(forms[i]) {
            for(var j = 0; j < elements.length; j++) {
               if(elements[j].name == objNameInForm){
                  return this.document.forms[i];
               }
            }
          }
       }
     }
  }
  return selectedForm;
} // end getRightForm(objNameInForm, reqForm)

function findRightForm(reqForm)
{
  if ( reqForm )
  {
   with(this.document)
   {
       for(var i = 0; i < forms.length; i++) 
       {
          if ( forms[i].name == reqForm )
          {
            return forms[i];
          }
       }
     }
  }
  return null;
} // end findRightForm(reqForm)

  
  function populateDays(objForm,monthField,dayField)
  {
     currentDate = new Date();
     selectedYear = currentDate.getYear();
     selectIndex = objForm[monthField].selectedIndex;
     timeA = new Date(selectedYear, selectIndex+1,1);
     selectedMonth = selectIndex;
     if (selectedMonth < currentDate.getMonth())
     {
       selectedYear++;
     }
     timeDifference = timeA - 86400000;
     timeB = new Date(timeDifference);
     var daysInMonth = timeB.getDate();
     for (var i = 0; i < objForm[dayField].length; i++)
     {
       objForm[dayField].options[0] = null;
     }
     for (var i = 0; i < daysInMonth; i++)
     {
       objForm[dayField].options[i] = new Option(i+1);
     }
     objForm[dayField].options[0].selected = true;
  }

  function addDays(strDate,iDays)
  {
     strDate = Date.parse(strDate);
     strDate = parseInt(strDate, 10);
     strDate = strDate + iDays*(24*60*60*1000);
     strDate = new Date(strDate);

     return strDate;
  }

  function dateChangeListener(objForm,monthField,dayField,targetMonthField,targetDayField,offset)
  {
     currentDate = new Date();
     selectedYear = currentDate.getYear();
     selectedMonth = objForm[monthField].selectedIndex + 1 ;
     selectedDay =  objForm[dayField].selectedIndex;

     if (selectedMonth < currentDate.getMonth())
     {
       selectedYear++;
     }

     targetOffset = addDays(selectedMonth+"/"+selectedDay+"/"+selectedYear,offset);

     objForm[targetMonthField].selectedIndex=targetOffset.getMonth();
     populateDays(objForm,targetMonthField,targetDayField);

     objForm[targetDayField].selectedIndex=targetOffset.getDate();
  }

  function dateBoxes(name1,name2,dateType,yPosAdj)
  {
     this.box1Name      = name1;       // month
     this.box2Name      = name2;       // dayOfMonth
     this.boxesDateType = dateType;    // "CP" for pickup date or "CD" dropoff date
     this.boxesyPosAdj  = yPosAdj;
  } // end dateBoxes

  var dates1 = new dateBoxes( "dateLeavingMonth" , "dateLeavingDay" , "AD",  0);
  var dates2 = new dateBoxes( "dateReturningMonth", "dateReturningDay", "AR", 25);

////////////////////////////////////////
function show(idLayer,Size) {
	cLayer=bVer.dom?document.getElementById(idLayer).style:bVer.ie4?document.all[idLayer].style:bVer.ns4?idParent?document[idParent].document[idLayer]:document[idLayer]:0;
	cLayer.display='block';
	var imgSize = Size-2;
	if (idLayer=='air') {
		//initform(document.getElementById('tripform').name);
	} else if (idLayer=='hotel') {
		//initHotDate();
	}
	
//	if (idLayer=='cru') {
//		NewImg = "cruise";
//	} else {
//		NewImg = idLayer;
//	}
//	self.document.images.wct_header.src = "/images/global/btn_hotel_srch_148_" + NewImg + ".gif";
}

function hide(idLayer) {
	cLayer=bVer.dom?document.getElementById(idLayer).style:bVer.ie4?document.all[idLayer].style:bVer.ns4?idParent?document[idParent].document[idLayer]:document[idLayer]:0;
	cLayer.display='none';
}

function chkBrowser() {
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bVer=(this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this;
}
bVer=new chkBrowser();
ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
bVerOK = ((document.all)? true:false)

var adults   = '';
var seniors  = '';
var children = '';
var stops    = '';
  
function initform(objFormName) {
     // initialize date drop downs
     initDaysInMonth(objFormName,bLEAVING);
     initDaysInMonth(objFormName,bRETURNING);

     document.getElementById(objFormName).elements["dateLeavingMonth"].options.selectedIndex = dateLeavingMonth   - 1;
     document.getElementById(objFormName).elements["dateLeavingDay"] .options.selectedIndex = dateLeavingDate    - 1;
     document.getElementById(objFormName).elements["dateReturningMonth"].options.selectedIndex = dateReturningMonth - 1;
     document.getElementById(objFormName).elements["dateReturningDay"].options.selectedIndex = dateReturningDate  - 1;

     // if not traveler already given, default to 2 adult
     if (((adults + seniors + children) == "") || (parseInt (adults + seniors + children) == 0))
     {
       document.getElementById(objFormName).elements["adults"].options.selectedIndex = 2;
     }
     if ( stops == "" )
     {
       document.getElementById(objFormName).elements["stops"].options.selectedIndex = 2;
     }
     
    // if (document.getElementById(objFormName).elements["leavingFrom"].value == "")
    //   document.getElementById(objFormName).elements["leavingFrom"].focus ();
          
}

 function initHotDate()
 {
   var now = new Date();
   var mth = now.getMonth();
   var dd = now.getDate();
   var yy = now.getFullYear();
   if (mth < 10)
    {
      mth == 0 + mth;
     }
   if (dd < 10)
    {
      dd == 0 + dd;
    }
     if ((mth==11) && (dd>=29)) {
		 document.resrvForm.doa_mm.selectedIndex = mth;
		 document.resrvForm.doa_dd.selectedIndex = dd - 1;
		 document.resrvForm.dod_dd.selectedIndex = dd - dd;
		 document.resrvForm.dod_mm.selectedIndex = mth-mth;
     }
     else if (dd>=16 )
     {
	 document.resrvForm.doa_mm.selectedIndex = mth+1;
     document.resrvForm.doa_dd.selectedIndex = dd-dd;
     document.resrvForm.dod_dd.selectedIndex = (dd-dd)+7;
     document.resrvForm.dod_mm.selectedIndex = mth + 1;
    }
   else
    {
   	document.resrvForm.doa_mm.selectedIndex=mth;
   	document.resrvForm.doa_dd.selectedIndex=dd+7;
   	document.resrvForm.dod_mm.selectedIndex=mth;
   	document.resrvForm.dod_dd.selectedIndex=dd+12;
   }
}
