var FT1 = true;
FT2 = false;
PT1 = true;
PT2 = false;
function Initialize()
{
   FO_FLY.DateFrom.value = parseDateInToCalendarFormat(new Date());
   FO_PACK.DateFrom.value = parseDateInToCalendarFormat(new Date());
   /* Nili 23/06/2009
   if (FO_FLY.Destination.value != '0' && FO_FLY.Destination.value != '') FO_FLY.Destination.onchange();
   objLen(FO_FLY.Destination);*/
   /* 23 / 13 / 2007 */ changeDefaultFlight((GLOB_SearchArea == 1) ? 'inner' : 'abroad');
   /* Nili 23/06/2009
   //Added By Renana At 23/03/2008 - display when ther is one landing
   getOneLanding(FO_FLY.Landing,FO_FLY.Destination.value);*/
}
function resetFlight()
{
   /* Nili 23/06/2009
   if(FO_FLY.Destination.length > 2) FO_FLY.Destination.selectedIndex = 0;
   FO_FLY.Destination.onchange();*/
   FO_FLY.Departure.onchange();
   //End Nili
   FO_FLY.DateFrom.value = parseDateInToCalendarFormat(new Date());
}
function resetPackage()
{
   /* 11 / 11 / 2007 start if(FO_PACK.Destination.length > 2) FO_PACK.Destination.selectedIndex = 0; 11 / 11 / 2007 end */ FO_PACK.DateFrom.value = parseDateInToCalendarFormat(new Date());
   var Name = document.PackageForm.k.options[document.PackageForm.k.selectedIndex].text;
   var Lang = retLang(Name);
   if (Lang == 'EN')
   {
      var theRadio = document.getElementById("includeFly2");
      changeIncludeFlight('includeFly2');
      theRadio.checked = true;
      theRadio.onclick();
   }
   else
   {
      var theObjHotel = document.PackageForm.k.options[document.PackageForm.k.selectedIndex].hotel;
      var theRadio = document.getElementById("includeFly" + theObjHotel);
      changeIncludeFlight(theObjHotel)
      if(theObjHotel != "0")
      {
         theRadio.checked = true;
         theRadio.onclick();
      }
   }
}
function displayFlightsRedio()
{
   FO_FLY.FlightDir1.checked = true;
   FO_FLY.FlightDir1.onclick();
  /* Nili 23/06/2009
   if (FO_FLY.Destination.value != '0' && FO_FLY.Destination.value != '') FO_FLY.FlightDir2.disabled = (FO_FLY.Destination.options[FO_FLY.Destination.selectedIndex].oneDir == "1") ? false : true;*/
   if (GLOB_ActiveFlightType==2)
   {
      //Nili 23/06/2009
      FO_FLY.FlightDir2.disabled = true;
   }
   else
   {
      FO_FLY.FlightDir2.disabled = false;
      FO_FLY.DateTo.value = '';
   }
   objLen(FO_FLY.Departure);
   objLen(FO_FLY.Landing);
}
function enableFrmCombo()
{
   /* Nili 23/06/2009
   FO_FLY.Destination.disabled = false;*/
   FO_FLY.Departure.disabled = false;
   FO_FLY.Landing.disabled = false;
   FO_PACK.Destination.disabled = false;
}

/* Nili    28/06/2009
function getDestCombo(ob, Type)
{
   var x = new Array();
   if(GLOB_ActiveFlightType == 2)
   {
      x = AD
   }
   else
   {
      x = LD
   }
   ClearCombo(ob);
   for(var i = 0; i < x.length; i ++ )
   {
      elem = document.createElement("OPTION");
      elem.value = x[i][0];
      elem.text = x[i][1];
      elem.oneDir = x[i][2];
      ob.add(elem);
   }
}*/
function objLen(ob)
{
   if (((ob.length == 2) && (ob.options[0].value == '0' || ob.options[0].value == '')) || ((ob.length == 1) && (ob.options[0].value != '0' && ob.options[0].value != '')))
   {
      ob.selectedIndex = 1;
      ob.disabled = true;
      if (typeof ob.onchange == "function") ob.onchange();
   }
   else ob.disabled = false;
}
function getPackDestCombo(ob)
{
   var x = new Array();
   var selectedVal;
   if(GLOB_ActivePackType == 2)
   {
      x = LPD;
      /* 11 / 11 / 2007 start */ selectedVal = GLOB_initDestination_inner_package;
      /* 11 / 11 / 2007 end */
   }
   else
   {
      x = LPD;
      /* 11 / 11 / 2007 start */ selectedVal = GLOB_initDestination_inner_package;
      /* 11 / 11 / 2007 end */
   }
   ClearCombo(ob);
   for(var i = 0; i < x.length; i ++ )
   {
      elem = document.createElement("OPTION");
      elem.value = x[i][0];
      elem.text = x[i][1];
      elem.hotel = x[i][2];
      ob.add(elem);
      /* 11 / 11 / 2007 start */            if (elem.value == selectedVal)
      {
         elem.selected = true;
         /* 11 / 11 / 2007 end */
      }
   }
}
function changeFlightDir(Dir)
{
  var doc = document.all;
  if (Dir == 5 ||Dir == 6 ||Dir == 7 ||Dir == 8)
   {
    if(Dir == 5 || Dir == 7)
    {
     doc.Img2.style.visibility='visible';
     FO_FLY.SpredDateTo.disabled = false;
     eval("doc.FlightDirSpan" + Dir).className = "text12Blue_b";
     eval("doc.FlightDirSpan" + (Dir+1)).className = "text12Blue";
    }
    else
    {
     doc.Img2.style.visibility='hidden';
     FO_FLY.SpredDateTo.disabled = true;
     eval("doc.FlightDirSpan" + Dir).className = "text12Blue_b";
     eval("doc.FlightDirSpan" + (Dir-1)).className = "text12Blue";

    }
   }
  else
  {
   var doc = document.all;
   doc.backFrom.disabled = (Dir - 1);
   doc.Img1.style.visibility = (Dir - 1) ? 'hidden' : 'visible';
   FO_FLY.DateTo.disabled = (Dir - 1);
   if ( ! (Dir - 1) && ( ! FO_FLY.DateTo.value.length))FO_FLY.Landing.onchange();
   eval("doc.FlightDirSpan" + Dir).className = "text12Blue_b";
   eval("doc.FlightDirSpan" + (3 + Dir * - 1)).className = "text12Blue";
   /* Nili 23/06/2009   
   //Added By Renana At 23/03/2008 - display when ther is one landing
   getOneLanding(FO_FLY.Landing,FO_FLY.Destination.value);*/
  }
}
function validateForm40000(Fr,source)
{
   var retStr = '';
  if (source == 1)
   {
    if(Fr.RadioType1.checked)
    {
     if(Fr.IntlDestination.value == '0' ||Fr.IntlDestination.value== '')retStr += (Fr.IntlDestination.em1 + '\n');
    }
    else
    {
     if(Fr.CityDestination.value == '0' ||Fr.CityDestination.value== '')retStr += (Fr.CityDestination.em1 + '\n');
    }
    if (Fr.SpredDateFrom.value == '') retStr += (Fr.SpredDateFrom.em1 + '\n');
    //if((Fr.FlightDir7.checked && Fr.RadioType2.checked) || (Fr.FlightDir5.checked && Fr.RadioType1.checked))
    //{
     //if (Fr.SpredDateTo.value == '') retStr += (Fr.SpredDateTo.em1 + '\n');
    //}
    if (retStr != '')
    {
      alert(retStr);
      return false;
    }
    else if( ! checkSpredFormDates(Fr))
    {
      return false;
    }
   }
  else
  {
   /* Nili 28/06/2009
   if ((Fr.Destination.value == '0') || (Fr.Destination.value == ''))retStr += (Fr.Destination.em1 + '\n');*/
   if(Fr.id.indexOf('Flight') > - 1)
   {
      if ((Fr.Departure.value == '0') || (Fr.Departure.value == ''))retStr += (Fr.Departure.em1 + '\n');
      if ((Fr.Landing.value == '0') || (Fr.Landing.value == ''))retStr += (Fr.Landing.em1 + '\n');
   }
   if (Fr.DateFrom.value == '')retStr += (Fr.DateFrom.em1 + '\n');
   if(Fr.id.indexOf('Flight') > - 1)
   {
      if (Fr.FlightDir1.checked)if (Fr.DateTo.value == '')retStr += (Fr.DateTo.em1 + '\n');
   }
   if (retStr != '')
   {
      alert(retStr);
      return false;
   }
   else if( ! checkFormDates(Fr))
   {
      return false;
   }
   enableFrmCombo();
  }
 return true;
}
function displaySearch(searchType, searchArea)
{
   if(searchType == 1)
   {
      displaySearchTab(1);
      FO_FLY.flightType1.checked = true;
    //  FO_FLY.flightType1.onclick();--**nili
      void(0);
      if (searchArea == 1)
      {
         changeFlight('inner');
         GLOB_ActiveFlightType = 1;
         /* Nili 23/06/2009
         getDestCombo(FO_FLY.Destination, 1);
         objLen(FO_FLY.Destination);*/
         getDeparture(FO_FLY.Departure);
	 objLen(FO_FLY.Departure);
	 FO_FLY.FlightDir2.disabled = false;
	 // End Nili
         resetFlight();
      }
      else
      {
         changeFlight('abroad');
         GLOB_ActiveFlightType = 2;
         /* Nili 28/06/2009 
	 getDestCombo(FO_FLY.Destination, 2);
         objLen(FO_FLY.Destination);*/
         getDeparture(FO_FLY.Departure);
	 objLen(FO_FLY.Departure);
	 FO_FLY.FlightDir2.disabled = true;
	 // End Nili
         resetFlight();
	 

      }
      eval("document.all.flightType" + searchArea + ".checked=true");

   }
   if(searchType == 2)
   {
      displaySearchTab(2);
      PT1 = false;
      void(0);
      if (searchArea == 1)
      {
         GLOB_ActivePackType = 1;
         getPackDestCombo(FO_PACK.Destination);
         objLen(FO_PACK.Destination);
         resetPackage();
      }
      else
      {
         GLOB_ActivePackType = 2;
         getPackDestCombo(FO_PACK.Destination);
         objLen(FO_PACK.Destination);
         resetPackage();
      }
      /* 11 / 11 / 2007 start eval("document.all.package" + searchArea + ".checked=true"); 11 / 11 / 2007 end */
   }
}
/* 11 / 11 / 2007 start */
function changeDefaultFlight(Type)
{
   if (Type == 'inner')
   {
      /* Nili 23/06/2009
      FO_FLY.Destination.value = GLOB_initDestination_inner;
      getDepartureByDest(FO_FLY.Departure, FO_FLY.Destination.value);*/
      getDeparture(FO_FLY.Departure);
      ClearCombo(FO_FLY.Landing);
      displayFlightsRedio();
      /* 23 / 13 / 2007 */
      /* Nili
      if ((FO_FLY.Destination.length == 2) && (FO_FLY.Destination.options[0].value == '0' || FO_FLY.Destination.options[0].value == ''))
      {
         FO_FLY.Destination.options[1].selected = true;
      }*/
   }
   else if(Type == 'abroad')
   {
      /* Nili
      FO_FLY.Destination.value = GLOB_initDestination_abroad;
      getDepartureByDest(FO_FLY.Departure, FO_FLY.Destination.value);*/
      getDeparture(FO_FLY.Departure);
      ClearCombo(FO_FLY.Landing);
      displayFlightsRedio();
   }
}
/* 11 / 11 / 2007 end */
function changeHotel()
{
   var theObjHotel = document.PackageForm.k.options[document.PackageForm.k.selectedIndex].hotel;
   var theRadio = document.getElementById("includeFly" + theObjHotel);
   changeIncludeFlight(theObjHotel)
   if(theObjHotel != "0") theRadio.checked = true;
}


/* Nili 23/06/2009*/

function getDeparture(ob)
{
   var x = new Array();
   x = (GLOB_ActiveFlightType == 2) ? ADP : LDP;
   ClearCombo(ob);
   for(var i = 0; i < x.length; i ++ )
      {
	elem = document.createElement("OPTION");
	elem.value = x[i][1].split('*')[1].split('%')[0];
	elem.text = x[i][1].split('*')[0];
	if(typeof x[i][1].split('*')[1].split('%')[1] == "string")
	elem.dateDiff = x[i][1].split('*')[1].split('%')[1];
	ob.add(elem);
      }
}

function getLandingByDepart(ob, DepartCODE)
{
   var x = new Array();
   x = (GLOB_ActiveFlightType == 2) ? ADP : LDP;
   ClearCombo(ob);
   if(DepartCODE != "0")
   {
      for(var i = 0; i < x.length; i ++ )
      {
         if(( x[i][1].split('*')[1] == DepartCODE ) && (x[i][2].length > 0))
         {
            var oList = x[i][2].split('^');
            for(var j = 0; j < oList.length; j ++ )
            {
               elem = document.createElement("OPTION");
               elem.value = oList[j].split('*')[1].split('%')[0];
               elem.text = oList[j].split('*')[0];
               if(typeof oList[j].split('*')[1].split('%')[1] == "string")
               elem.dateDiff = oList[j].split('*')[1].split('%')[1];
               ob.add(elem);
            }
            return;
         }
      }
   }
}

function checkSpredFormDates(FO)
{
   var retStr = '';
   if(typeof FO.SpredDateFrom == "object")
   if (FO.SpredDateFrom.value.length > 0)
   {
      if ( ! (isValidDate(FO.SpredDateFrom.value)))
      retStr += (FO.SpredDateFrom.em2 + '\n');
      else if(passedDate(FO.SpredDateFrom.value))
      retStr += (FO.SpredDateFrom.em3 + '\n');
   }
   if(typeof FO.SpredDateTo == "object")
   if (FO.SpredDateTo.value.length && ! FO.SpredDateTo.disabled)
   {
      if ( ! (isValidDate(FO.SpredDateTo.value)))
      retStr += (FO.SpredDateTo.em2 + '\n');
      else if(passedDate(FO.SpredDateTo.value))
      retStr += (FO.SpredDateTo.em3 + '\n');
   }
   if(retStr != '')
   {
      alert(retStr);
      return false;
   }
   if((typeof FO.SpredDateFrom == "object") && (typeof FO.SpredDateTo == "object"))
   {
      if ( ! FO.SpredDateTo.disabled)
      if(((dateDiff(parseDateInToObjFormat(FO.SpredDateFrom.value), parseDateInToObjFormat(FO.SpredDateTo.value))) < 0))
      {
         alert(FO.SpredDateTo.em4);
         return false;
      }
   }
   return true;
}

function clearAbroad()
{
 FO_FLY.RadioType1.checked=true;
 FO_FLY.RadioType1.onclick();
 FO_FLY.IntlDestination.selectedIndex=""; 
 FO_FLY.FlightDir5.checked=true;
 changeFlightDir(5);
 FO_FLY.SpredDateFrom.value="";

 FO_FLY.CityDestination.selectedIndex=""; 
 FO_FLY.FlightDir7.checked=true;
 changeFlightDir(7);
}