
// This sets the number of days for the destination date to jump from the depart date.
TRAVEL_DAYS_APART = 7;

var avl = new Array(new Array('','T9','ZA','JP','A3','EI','JR','SX','SU','AR','N2','VW','BQ','AM','PL','VH','5L','VV','Q9','DP','RK','AH','LM','A6','FQ','UU','AB','JA','KF','BP','AC','TX','YN','EN','UX','PE','XV','FZ','AF','AI','JM','L3','UL','IJ','TT','FU','NX','L6','KM','CW','F8','SW','ON','NZ','EL','PX','AP','FJ','PZ','OJ','ZP','YI','TN','TC','TS','NF','6G','ZT','UM','ZF','RT','FL','AS','AZ','XM','RD','NH','LL','Y2','E8','HP','AA','WK','TZ','AN','HU','IW','7P','R3','R7','OZ','9T','RC','EV','GR','7V','OS','OT','VE','GW','6A','AV','GU','QC','XN','ZE','5E','UP','LZ','VY','JV','B3','CH','GQ','AX','BU','E5','DB','BA','JY','KJ','BD','6R','BW','VR','UY','2T','5T','C6','9K','6C','B9','8B','P','CX','KX','OP','54','C8','CI','WX','FD','7C','MN','DE','5C','CO','CM','3C','SS','XK','XL','X5','CY','OK','DI','DL','D7','Z6','8U','YU','KA','K8','FE','U2','EU','MS','LY','EK','7H','OV','ET','F4','GJ','M3','EW','BR','IH','EF','2D','AY','YC','F3','F9','2F','G7','GA','GH','9C','QD','GL','GF','3M','GY','WD','8F','HB','HA','ZL','JB','UD','IB','FI','IC','I9','5W','U5','IR','G5','HH','B8','JO','JL','JD','EG','9W','B6','SG','KD','4K','KQ','KL','RQ','WA','UK','KE','KU','JF','LR','LA','LP','MJ','NG','LC','LI','TE','LB','LO','LT','LH','LG','IN','MH','MA','AE','8M','IG','MZ','MX','YX','ZB','NM','ZR','N7','NC','EJ','6Y','JH','NA','VL','NW','J3','UQ','OA','WY','ZO','8P','LW','PN','P8','HI','KS','5P','PR','PU','PH','NI','OI','Z8','QR','WE','E2','SL','6J','AT','QN','BI','RJ','RA','ZG','SN','S2','SK','SV','YR','VC','3S','S5','LJ','MI','SQ','JW','9F','Y3','4S','IE','SA','A4','JK','NK','CB','EZ','SY','CQ','SM','PY','HJ','LX','RB','TA','EQ','TP','K3','RO','FC','TG','FF','5B','HX','BH','TW','TR','UN','GE','HV','JJ','PM','TU','TK','QW','PS','UA','US','HY','NJ','RG','VP','2R','VN','VQ','VS','TV','VG','8D','PT','8O','3L','W6','WF','6W','W2','8V','Z7','OD'), new Array('Airlines...','Ab Varmlandsflyg','Access Air','Adria Airways','Aegean Airlines','Aer Lingus','Aerocalifornia','Aeroejecutivo','Aeroflot','Aerolineas Argentinas','Aerolineas Internacionales','Aeromar','Aeromar C Por A','Aeromexico','Aeroperu','Aeropostal Alasde Venezuela','Aerosur','Aerosvit Airlines','Afrinat Intl Airlines','Air 2000','Air Afrique','Air Algerie','Air Alm','Air Alps','Air Aruba','Air Austral','Air Berlin','Air Bosna','Air Botnia','Air Botswana','Air Canada','Air Caraibes','Air Creebec','Air Dolomiti','Air Europa','Air Europe','Air Express','Air Facilities','Air France','Air India','Air Jamaica','Air Ketchum','Air Lanka','Air Liberte','Air Lithuania','Air Littoral','Air Macau','Air Maldives','Air Malta','Air Marshall Islands','Air Montreal','Air Namibia','Air Nauru','Air New Zealand','Air Nippon','Air Niugini','Air One','Air Pacific','Air Paraguay','Air St Barthelemy','Air St Thomas','Air Sunshine','Air Tahiti Nui','Air Tanzania','Air Transat','Air Vanatu','Air Vegas','Air Zambezi','Air Zimbabwe','Airborne','Airlines Of South Australia','Airtran Airlines','Alaska Airlines','Alitalia','Alitalia Express','Alitalia Team','All Nippon Airways','Allegro','Alliance Joint Air Svcs','Alpi Eagles','America West','American Airlines','American Falcon','American Trans Air','Ansett Australia','Antigua Paradise Airways','Aom French Airlines','Apa International Air','Armenian Airlines','Aserca','Asiana Airlines','Athabaska Airways','Atlantic Airways','Atlantic Southeast/delta Conn','Aurigny Air Svcs','Austin Express','Austrian Airlines','Avant Airlines','Avensa','Avia Airlines','Aviacsa','Avianca','Aviateca','Aviation Quebec Labrador','Axon Airlines','Azteca/lineas Aereas','B.a.s.e Business Airlines','Bahamasair','Balkan Bulgarian Airlines','Bay Chaleur Air','Bearskin Airlines','Bellview Airlines','Bemidji Airlines','Big Sky Airlines','Binter Mediterran','Braathens Asa','Branson Airlines','Brit Air','British Airways','British European','British Mediterranean','British Midland','Britrail','Bwia Intl Airlines','Cabo Verde Airlines','Cameroon Airlines','Canada 3000','Canadian North','Canjet.airlines','Cape Air','Cape Smythe Air Service','Caribair','Caribbean Star','Casino Express Airlines','Cathay Pacific','Cayman Airways','Chalks Intl Airlines','Chautauqua Airlines','Chicago Express Airlines','China Airlines','City Jet','Cityflyer Express','Columbia Pacific Airlines','Commercial Airlines','Condor Flugdienst','Conquest Airlines','Continental Airlines','Copa Airlines','Corporate Airlines','Corsair','Corse Mediterranee','Country Connection','Cronus Air','Cyprus Airways','Czech Airlines','Delta Air Germany','Delta Airlines','Dinar','Dniepravia State','Dolphin Express Airlines','Dominair','Dragonair Hongkong','Dutch Caribbean Airlines','Eagle Canyon Airlines','Easyjet','Ecuatoriana','Egyptair','El Al','Emirates Airlines','Era Aviation','Estonian Air','Ethiopian Airlines','Eureca Srl','Eurofly Spa','European Air Express','Eurowings','Eva Airways','Falcon Aviation','Far Eastern Air','Federico Ii','Finnair','Flight West Airlines','Flying Enterprise Ab','Frontier Airlines','Frontier Flying','Gandalf Airlines','Garuda Indonesia','Ghana Airways','Gill Aviation','Grand Airways','Greenlandair','Gulf Air','Gulfstream Intl','Guyana Airways 2000 Inc','Halisa/haitian Aviation','Hanair/haiti National Airways','Harbor Air','Hawaiian Airlines','Hazelton Airlines','Helijet Airways','Hex Air','Iberia Airlines','Icelandair','Indian Airlines','Indigo','Interline Aviation','International Business Air','Iran Air','Island Air Ltd','Islandsflug','Italair','Jalways','Japan Air Lines','Japan Air System','Japan Asia Airways','Jet Airways','Jetblue Airways','Jetsgo','Kendell Airlines','Kenn Borek Air Ltd','Kenya Airways','Klm Airlines','Klm Alps/air Engiadina','Klm Cityhopper','Klm Uk','Korean Airlines','Kuwait Airways','L.a.b. Flying Service','Lacsa','Lan Chile','Lan Peru','Lapa','Lauda Air','Legend Airlines','Liat','Lithuanian Airlines','Lloyd Aero Boliviano','Lot Polish Airlines','Ltu International Airways','Lufthansa','Luxair','Macedonian Airlines','Malaysia Airlines','Malev Airlines','Mandarin Airlines','Maxair','Meridiana','Merpati Nusantara','Mexicana','Midwest Express','Monarch Airlines','Mount Cook Airlines','Muk Air','National Airlines','National Jet Systems','New England Airlines','Nica','Nordeste','North American Airlines','North Vancouver Air','Northwest','Northwestern Air Lease','O*connor Airlines','Olympic Airways','Oman Air','Ozark Airlines','Pacific Coastal Airlines','Pacific Wings Of Maui','Pan American Airways','Pantanal','Papillon Airways','Penair','Penta','Philippine Airlines','Pluna','Polynesian Airlines','Portugalia','Prestige Airways','Pulkovo Air','Qatar Airways','Rheintalflug','Rio Grande Air','Rio Sul','Roots Air/skyservice Airlines','Royal Air Maroc','Royal Aviation','Royal Brunei','Royal Jordanian','Royal Nepal','Sabair','Sabena','Sahara Airlines','Sas - Scandinavian','Saudi Arabian Airlines','Scenic Airlines','Servivensa','Shuswap Flight Center','Shuttle America','Sierra National Airlines','Silkair','Singapore Airlines','Skippers Aviation','Skycraft Air Transport','Skyway Airlines','Sol Airs','Solomon Airlines','South African Airways','Southern Winds','Spanair','Spirit Airlines','Suckling Airways','Sun Air Of Scandinavia','Sun Country Airlines','Sunshine Express','Sunworld International Airlines','Surinam Airways','Swedeways Ab','Swiss','Syrian Arab Airlines','Taca','Tame','Tap Air Portugal','Taquan Air Alaska','Tarom Romanian Air Transport','Tempelhoff Express','Thai Airways','Tower Air','Trans Intl Express','Trans North Aviation','Trans State','Trans World Airways','Transabrasil S.a. Linhas Aereas','Transaero','Transasia Airways','Transavia','Transportes Aereos Meridianals','Tropic Air','Tunis Air','Turkish Airlines','Turks And Caicos Airways','Ukraine Intl','United Airlines','Us Airways','Uzbekistan Airways','Vanguard Airlines','Varig','Vasp','Via Rail','Vietnam Airlines','Vintage Props And Jets','Virgin Atlantic','Virgin Express','Vlm Belgium','Volare Airlines Spa','West Air Sweden','West Coast Air','West Isle Air','West Isle Air','Wideroes Flyveselskap','Wilderness Airlines','World Airlines','Wright Air Service','Zimbabwe Express Airlines','Zuliana De Aviacion'))

// #### the javascript functions below should be moved to a javascript include file.

validate = true;
function validateBidForm(aForm) {
  message = '';
  if(aForm.destination.selectedIndex == 0 || aForm.departure.selectedIndex == 0) {
    message = "Departure and Destination are required fields.\n";
    aForm.segDepartSego0.focus();
  }
  checkDate(aForm, 21);
  if(message != '') {
    return false;
  }
  return true;
}

// 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;
}

// doNextAction is used to make switching to the oneway flight do the correct transfer of the second departure date.
doNextAction = false;
function switchShowDiv(selectObj)
{
  switch (selectObj.options.selectedIndex) {
    case 0:
      hideDiv('legs');
      showSpan('roundtrip_title');
      hideDiv('oneway_title');
      hideDiv('multi_title');
      hideDiv('segTitle0');
      hideMultiDivs(document.search.numMultiLegs);
      showDiv('return_date_div');
      xferDummy(false);
      doNextAction = true;
      break;
      
    case 1:
      hideDiv('legs');
      hideDiv('roundtrip_title');
      showSpan('oneway_title');
      hideDiv('multi_title');
      hideDiv('segTitle0');
      hideMultiDivs(document.search.numMultiLegs);
      hideDiv('return_date_div');
      xferDummy(doNextAction);
      break;
      
    case 2:
      showSpan('legs');
      hideDiv('roundtrip_title');
      hideDiv('oneway_title');
      showSpan('multi_title');
      showDiv('segTitle0');
      switchMultiDivs(document.search.numMultiLegs);
      hideDiv('return_date_div');
      xferDummy(true);
      doNextAction = false;
      break;
  
  }
}

function hideMultiDivs(selectObj)
{
  // First hide all divs
  for (count = 0; count < selectObj.options.length; count++) {
    hideDiv('flight_leg_' + selectObj.options[count].value);
  }
}


function switchMultiDivs(selectObj)
{
  hideMultiDivs(selectObj)
  
  // Show all divs upto the selected index
  for (count = 0; count <= selectObj.options.selectedIndex; count++) {
    showDiv('flight_leg_' + selectObj.options[count].value);
  }
}

function xferDummy(roundTrip)
{
 if (roundTrip == true) {
   document.search.segDepartMonth1.selectedIndex = document.search.dummyMonth.selectedIndex;
   document.search.segDepartDay1.selectedIndex   = document.search.dummyDay.selectedIndex;
   document.search.segDepartTime1.selectedIndex  = document.search.dummyTime.selectedIndex;
 } else {
   document.search.dummyMonth.selectedIndex = document.search.segDepartMonth1.selectedIndex;
   document.search.dummyDay.selectedIndex   = document.search.segDepartDay1.selectedIndex;
   document.search.dummyTime.selectedIndex  = document.search.segDepartTime1.selectedIndex;
  }
}

function showChildren() {
  numberOfChildren = document.search.children.selectedIndex;
  if (!numberOfChildren) {
    hideDiv('childrenSelects');
    return;
  }
  showDiv('childrenSelects');
  
  for (i=0; i <= 4; i++) {
    if (i < numberOfChildren) {
      showSpan('childrenPulldown' + i );
    }
    else {
      hideDiv('childrenPulldown' + i );
    }
  }
}

function showNumberTravelers()
{
  id = 'number_travelers';
  if (document.getElementById) {
    current = document.getElementById(id).style.visibility;

    if (current == 'visible') {
      document.getElementById(id).style.visibility = 'hidden';
      document.getElementById(id).style.display    = 'none';
    }
    else {
      document.getElementById(id).style.visibility = 'visible';
      document.getElementById(id).style.display    = 'block';
    }
  }
  else {
    if (document.layers) { // NS4
      eval('document.' + id + '.visibility = "hidden"');
    }
    else { // IE4
      eval('document.all.' + id + '.style.visibility = "hidden"');
    }
  }
}

function showNumberConnections(flag)
{
  id = 'number_connections';
  defaultVal = '-1';
  if (document.getElementById) {
    current = document.getElementById(id).style.visibility;

    if (defaultVal != -1 && flag == 1) {
      document.getElementById(id).style.visibility = 'visible';
      document.getElementById(id).style.display    = 'block';
      document.search.hasMaxConnections.checked    = true;
      document.search.dummyMaxConnections[-1+1].checked = true;
      setNumberConnections(-1)
    }

    if (flag != 1) {
      if (current == 'visible') 
      {
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.display    = 'none';
        document.getElementById('maxConnections').value = 3;
      }
      else {
        document.getElementById(id).style.visibility = 'visible';
        document.getElementById(id).style.display    = 'block';
	
	for ($i = 0; $i < 5; $i++) {
	 if (document.search.dummyMaxConnections[$i].checked == true) {
           document.getElementById('maxConnections').value = document.search.dummyMaxConnections[$i].value;
	   break;
	 }
       }
      }
    }
  }
  else {
    if (document.layers) { // NS4
      eval('document.' + id + '.visibility = "hidden"');
    }
    else { // IE4
      eval('document.all.' + id + '.style.visibility = "hidden"');
    }
  }
}

function setNumberConnections(connections)
{
  if (!document.getElementById) {
    return; // unsupported browser, please upgrade!
  }

  document.getElementById('dummyMaxConnections-1div').className = 'rowOff';
  document.getElementById('dummyMaxConnections0div').className = 'rowOff';
  document.getElementById('dummyMaxConnections1div').className = 'rowOff';
  document.getElementById('dummyMaxConnections2div').className = 'rowOff';
  document.getElementById('dummyMaxConnections3div').className = 'rowOff';
  
  document.getElementById('dummyMaxConnections' + connections + 'div').className = 'rowOn';
  document.getElementById('dummyMaxConnections' + connections).checked = true;
  document.getElementById('maxConnections').value = connections;
}

function showFlightClass()
{
  id = 'flight_class';
  if (document.getElementById) {
    current = document.getElementById(id).style.visibility;

    if (current == 'visible') {
      document.getElementById(id).style.visibility = 'hidden';
      document.getElementById(id).style.display    = 'none';
    }
    else {
      document.getElementById(id).style.visibility = 'visible';
      document.getElementById(id).style.display    = 'block';
    }
  }
  else {
    if (document.layers) { // NS4
      eval('document.' + id + '.visibility = "hidden"');
    }
    else { // IE4
      eval('document.all.' + id + '.style.visibility = "hidden"');
    }
  }
}
function showAirlines(flag)
{
  id               = 'airlines_to_search';
  theDiv           = document.getElementById(id);
  prefVendorSelect = new Array('0', '0', '0');

  if (flag == 1 && (prefVendorSelect[0] != 0 || prefVendorSelect[1] != 0 || prefVendorSelect[2] != 0)) {
    document.search.hasPrefVendors.checked = true;
    showDiv(id);
  }
  else if (flag == 1) {
    return;
  }

  if (flag != 1) {
    if (theDiv.style.visibility == 'visible') {
      prefVendors = new Array(document.search.prefVendors0.selectedIndex,
                              document.search.prefVendors1.selectedIndex,
                              document.search.prefVendors2.selectedIndex
                             );
      document.search.prefVendors0.selectedIndex = '';
      document.search.prefVendors1.selectedIndex = '';
      document.search.prefVendors2.selectedIndex = '';
      hideDiv(id);
      return;
    }

    if (typeof(prefVendors) != "undefined" ) {
      document.search.prefVendors0.selectedIndex = prefVendors[0];
      document.search.prefVendors1.selectedIndex = prefVendors[1];
      document.search.prefVendors2.selectedIndex = prefVendors[2];
    }
    showDiv(id);
  }

  if (document.search.prefVendors0.length > 1) {
      return;
  }
  
  for (x=0; x < 3; x++) {
    eval('theSelect = document.search.prefVendors'+ x);
    for (y=0; y < avl[0].length; y++) {
      theSelect.options[y] = new Option(avl[1][y], avl[0][y]);
      if (avl[0][y] == prefVendorSelect[x]) {
        theSelect.selectedIndex = y;
      }
    }
  }
}

function showAirlinesExclude(flag)
{
  id               = 'airlines_to_exclude';
  theDiv           = document.getElementById(id);
  exclVendorSelect = new Array('0', '0', '0');

  if (flag == 1 && (exclVendorSelect[0] != 0 || exclVendorSelect[1] != 0 || exclVendorSelect[2] != 0)) {
    document.search.hasExclVendors.checked    = true;
    showDiv(id);
  }
  else if (flag == 1) {
    return;
  }

  if (flag != 1) {
    if (theDiv.style.visibility == 'visible') {
      exclVendors = new Array(document.search.exclVendors0.selectedIndex,
                              document.search.exclVendors1.selectedIndex,
                              document.search.exclVendors2.selectedIndex
                             );
      document.search.exclVendors0.selectedIndex = '';
      document.search.exclVendors1.selectedIndex = '';
      document.search.exclVendors2.selectedIndex = '';
      hideDiv(id);
      return;
    }

    if (typeof(exclVendors) != "undefined" ) {
      document.search.exclVendors0.selectedIndex = exclVendors[0];
      document.search.exclVendors1.selectedIndex = exclVendors[1];
      document.search.exclVendors2.selectedIndex = exclVendors[2];
    }
    showDiv(id);
  }
    
  if (document.search.exclVendors0.length > 1) {
      return;
  }
  
  for (x=0; x < 3; x++) {
    eval('theSelect = document.search.exclVendors'+ x);
    for (y=0; y < avl[0].length; y++) {
      theSelect.options[y] = new Option(avl[1][y], avl[0][y]);
      if (avl[0][y] == exclVendorSelect[x]) {
        theSelect.selectedIndex = y;
      }
    }
  }
}

function showPrivateFareCode()
{
  id = 'private_fare_code';
  if (document.getElementById) {
    current = document.getElementById(id).style.visibility;

    if (current == 'visible') {
      document.getElementById(id).style.visibility = 'hidden';
      document.getElementById(id).style.display    = 'none';
    }
    else {
      document.getElementById(id).style.visibility = 'visible';
      document.getElementById(id).style.display    = 'block';
    }
  }
  else {
    if (document.layers) { // NS4
      eval('document.' + id + '.visibility = "hidden"');
    }
    else { // IE4
      eval('document.all.' + id + '.style.visibility = "hidden"');
    }
  }
}

function initdt(mf) {
var t = new Date;
mf.segDepartDay0.value = t.getDate();
mf.segDepartMonth0.value = t.getMonth() + 1;
mf.dummyDay.value = t.getDate() + 1;
mf.dummyMonth.value = t.getMonth() + 1;
}

function Init() {
 /* alert("search"); */
 document.forms[0].name = "search";
 document.forms[0].id = "search";
 document.getElementById('segDepartMonth0').name="segDepartMonth0";
 document.getElementById('segDepartDay0').name="segDepartDay0";
 document.getElementById('dummyMonth').name="segDepartMonth1";
 document.getElementById('dummyMonth').id="segDepartMonth1";
 document.getElementById('dummyDay').name="segDepartDay1";
 document.getElementById('dummyDay').id="segDepartDay1";
 var t = new Date;
 document.getElementById('segDepartDay0').value = t.getDate();
 document.getElementById('segDepartMonth0').value = t.getMonth() + 1;
 document.getElementById('segDepartDay1').value = t.getDate() + 1;
 document.getElementById('segDepartMonth1').value = t.getMonth() + 1;
};
