
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 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; 
}