if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

var errorMsgs = { "from_greater_from_to"
                  :{ "en"          : "Return date must be greater than Departure date"
                    ,"mn-latin"    : "Datum povratka mora da bude veći od datuma polaska"
                    ,"sr-cyrillic" : "Датум повратка мора да буде већи од датума поласка"
                    ,"ge"			  : "Das Rückflugdatum muss später als das Abflugdatum starten"
                    ,"fr"          : "Return date must be greater than Departure date"
                   }
                 ,"too_many_infants"
                  :{ "en"          : "Number of infants cannot exceed total number of Adults, Youth and Seniors"
                    ,"mn-latin"    : "Broj infanata ne moze da bude veći od ukupnog broja odraslih, omladine i seniora"
                    ,"sr-cyrillic" : "Број инфаната не може да буде већи од укупног броја одраслих, омладине и сениора"
                    ,"ge"			  : "Kinderanzahl kann die Gesamtanzahl der Erwachsenen, Jugendlichen und Senioren nicht überschreiten"
                    ,"fr"          : "Number of infants cannot exceed total number of Adults, Youth and Seniors"
                   }
                 ,"no_passengers"
                  :{ "en"          : "No passengers"
                    ,"mn-latin"    : "Niste uneli broj putnika"
                    ,"sr-cyrillic" : "Нисте унели број путника"
                    ,"ge"			  : "Sie haben die Anzahl der Reisenden nicht eingegeben"
                    ,"fr"          : "No passengers"
                   }
                 ,"incomplete_destinations"
                  :{ "en"          : "Please select airports"
                    ,"mn-latin"    : "Molimo odaberite aerodrome"
                    ,"sr-cyrillic" : "Молимо одаберите аеродроме"
                    ,"ge"			  : "Wählen Sie bitte die Flughäfen aus"
                    ,"fr"          : "Please select airports"
                   }
                 ,"same_destinations"
                  :{ "en"          : "Departure and arrival airports cannot be the same"
                    ,"mn-latin"    : "Aerodromi polaska i dolaska ne mogu biti isti"
                    ,"sr-cyrillic" : "Аеродроми поласка и доласка не могу бити исти"
                    ,"ge"			  : "Start- und Zielflughafen können nicht dieselben sein"
                    ,"fr"          : "Departure and arrival airports cannot be the same"
                   }
                 ,"too_many_passengers"
                  :{ "en"          : "Total number of Adult, Youth, Seniors and Children cannot exceed 8"
                    ,"mn-latin"    : "Ukupan broj odraslih, omladine, seniora i dece ne moze biti veći veci od 8"
                    ,"sr-cyrillic" : "Укупан број одраслих, омладине, сениора и деце не може бити већи од 8"
                    ,"ge"			  : "Die Gesamtanzahl der Erwachsenen, Jugendlichen, Senioren und Kinder kann nicht mehr als 8 sein"
                    ,"fr"          : "Total number of Adult, Youth, Seniors and Children cannot exceed 8"
                   }
                 ,"incomplete_cmt_fields"
                  :{ "en"          : "Please enter your trip details"
                    ,"mn-latin"    : "Molimo unesite detalje Vašeg leta"
                    ,"sr-cyrillic" : "Молимо унесите детаље Вашег лета"
                    ,"ge"			  : "Geben Sie bitte die Details Ihres Fluges ein"
                    ,"fr"			  : "Please enter your trip details"
                   }
                 ,"eticketing_details"
                  :{ "en"          : "Your reservation will be charged via Internet and e-ticket will be issued. Would you like to find out more?\n\nPlease click on OK if you wish to find out more about On-line payment and e-ticketing before reservation. Click on CANCEL if you wish to go straight to reservation process."
                    ,"mn-latin"    : "Vaša rezervacija će biti naplaćena preko Interneta i biće Vam izdata elektronska karta. Želite li da saznate više o tome?\n\nKliknite na OK ako želite da saznate više o On-line plaćanju i e-tiketingu pre pravljenja rezervacije. Kliknite na CANCEL ako želite odmah da nastavite sa pravljenjem rezervacije"
                    ,"sr-cyrillic" : "Ваша резервација ће бити наплаћена преко Интернета и биће Вам издата електронска карта. Желите ли да сазнате више о томе?\n\nКликните на OK ако желите да сазнате више о On-line плаћању и e-тикетингу пре прављења резервације. Кликните на CANCEL ако желите одмах да наставите са прављењем резервације"
                    ,"ge"			  : "Your reservation will be charged via Internet and e-ticket will be issued. Would you like to find out more?\n\nPlease click on OK if you wish to find out more about On-line payment and e-ticketing before reservation. Click on CANCEL if you wish to go straight to reservation process."
                    ,"fr"			  : "Your reservation will be charged via Internet and e-ticket will be issued. Would you like to find out more?\n\nPlease click on OK if you wish to find out more about On-line payment and e-ticketing before reservation. Click on CANCEL if you wish to go straight to reservation process."
                   }
                 ,"rac_please_enter_times"
                  :{ "en"          : "Please enter rental start and end times."
                    ,"mn-latin"    : "Molimo unesite vremena početka i kraja najma."
                    ,"sr-cyrillic" : "Молимо унесите времена почетка и краја најма."
                    ,"ge"			  : "Please enter rental start and end times."
                    ,"fr"			  : "Please enter rental start and end times."
                   }
                };
var daysInMonth = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
var roundTripPartText = "";
var passengerPartText = "";
//var cabinClassPartText = "";
var flexiblePartText = "";

var preserve_centerCellBooking;
var preserve_centerCellCheckTrip;
var preserve_centerCellHotels;
var preserve_centerCellRentACar;

var preserve_visitSerbia;
var preserve_hotelInfo;
var preserve_hotelTitle;
var preserve_visitSerbiaTitle;

var currentURL = document.location.toString();
if (currentURL.match(/home\.html/) || !currentURL.match(/home/))
{
   objectsToHideById.push('fromCity');
   objectsToHideById.push('toCity');
   objectsToHideById.push('startTimeDay');
   objectsToHideById.push('startTimeMon');
   objectsToHideById.push('endTimeDay');
   objectsToHideById.push('endTimeMon');
   //objectsToHideById.push('cabinClass');
   objectsToHideById.push('roundTrip');
   objectsToHideById.push('flexible');
   objectsToHideById.push('passengersADT');
   objectsToHideById.push('passengersYTH');
   objectsToHideById.push('passengersYCD');
   objectsToHideById.push('passengersCHD');
   objectsToHideById.push('passengersINF');
}

function showOrHideReturnDate()
{
   if (document.flight_order_form.roundTrip.checked)
      document.getElementById('endCell').innerHTML = remembered;
   else
   {
      remembered = document.getElementById('endCell').innerHTML;
      document.getElementById('endCell').innerHTML = '';
   }
}

function checkEverything()
{
   if (isCheckTrip())
   {
      if (!document.flight_order_form.amadeusPNR.value || !document.flight_order_form.lastName.value)
      {
         alert(errorMsgs['incomplete_cmt_fields'][detectLang()]);
         return false;
      }
      else
         return true;
   }
	else if (isHotels()) {
		if (!checkHotelDates())
		{
         alert(errorMsgs['from_greater_from_to'][detectLang()]);
         return false;
		}
		if (document.flight_order_form.hotelsSelector.value == 'SRB' && !checkSearch(document.flight_order_form))
			return false;
		return true;
	}
	else if (isRentACar()) {
      if (!enteredRacAPs())
      {
         alert(errorMsgs['incomplete_destinations'][detectLang()]);
         return false;
      }
		if (!checkRacTimes())
		{
         alert(errorMsgs['rac_please_enter_times'][detectLang()]);
         return false;
		}
		if (!checkRacDates())
		{
         alert(errorMsgs['from_greater_from_to'][detectLang()]);
         return false;
		}
		return true;
	}
   else
   {
      if (!enteredAPs())
      {
         alert(errorMsgs['incomplete_destinations'][detectLang()]);
         return false;
      }
      if (!validAPs())
      {
         alert(errorMsgs['same_destinations'][detectLang()]);
         return false;
      }
      if (isReturnTrip() && !checkDates())
      {
         alert(errorMsgs['from_greater_from_to'][detectLang()]);
         return false;
      }
      if (isBooking())
      {
   //alert('is booking');
         if (!getTravellerNr())
         {
            alert(errorMsgs['no_passengers'][detectLang()]);
            return false;
         }
         if (getTravellerNr()>8)
         {
            alert(errorMsgs['too_many_passengers'][detectLang()]);
            return false;
         }
         if (getTravellerNr()-getChildernNr()<getInfantNr())
         {
            alert(errorMsgs['too_many_infants'][detectLang()]);
            return false;
         }
      }
   }
	if(    document.forms['flight_order_form'].fromCity.value
	&& !hasNoEticketing(document.forms['flight_order_form'].fromCity.value,document.flight_order_form.startTimeMon.value+document.flight_order_form.startTimeDay.value)
	&& document.forms['flight_order_form'].toCity.value
	&& (!document.forms['flight_order_form'].roundTrip.checked
		  ||
		 !hasNoEticketing(document.forms['flight_order_form'].toCity.value,document.flight_order_form.endTimeMon.value+document.flight_order_form.endTimeDay.value)
		)
  )
		getAlertWin();
   return true;
}

function checkEverythingMultisegment () {
   if (!enteredMultisegmentAPs())
   {
      alert(errorMsgs['incomplete_destinations'][detectLang()]);
      return false;
   }
   //if (!validAPs())
   //{
   //   alert(errorMsgs['same_destinations'][detectLang()]);
   //   return false;
   //}
   if (!checkDatesMultisegment())
   {
      alert(errorMsgs['from_greater_from_to'][detectLang()]);
      return false;
   }
   if (!getTravellerNr())
   {
      alert(errorMsgs['no_passengers'][detectLang()]);
      return false;
   }
   if (getTravellerNr()>8)
   {
      alert(errorMsgs['too_many_passengers'][detectLang()]);
      return false;
   }
   if (getTravellerNr()-getChildernNr()<getInfantNr())
   {
      alert(errorMsgs['too_many_infants'][detectLang()]);
      return false;
   }
   return true;
}

function enteredAPs()
{
   if (!document.flight_order_form.fromCity.value || !document.flight_order_form.toCity.value)
      return false;
   else
      return true;
}

function enteredMultisegmentAPs() {
   if (   !document.flight_order_form.cityFrom1.value || !document.flight_order_form.cityTo1.value
       || !document.flight_order_form.cityFrom2.value || !document.flight_order_form.cityTo2.value
      )
      return false;
   else
      return true;
}

function enteredRacAPs()
{
   if (!document.flight_order_form.racFromCity.value || !document.flight_order_form.racToCity.value)
      return false;
   else
      return true;
}
function validAPs()
{
   if (document.flight_order_form.fromCity.value == document.flight_order_form.toCity.value)
      return false;
   else
      return true;
}
function checkDates()
{
   if (!isReturnTrip())
      return true;
   if (   document.flight_order_form.startTimeMon.value > document.flight_order_form.endTimeMon.value
       || (   document.flight_order_form.startTimeMon.value == document.flight_order_form.endTimeMon.value
           && document.flight_order_form.startTimeDay.value > document.flight_order_form.endTimeDay.value
          )
      )
      return false;
   else
      return true;
}
function checkDatesMultisegment()
{
   if (   document.flight_order_form.startTimeMon.value > document.flight_order_form.endTimeMon.value
       || (   document.flight_order_form.startTimeMon.value == document.flight_order_form.endTimeMon.value
           && document.flight_order_form.startTimeDay.value > document.flight_order_form.endTimeDay.value
          )
      )
      return false;
   else
      return true;
}
function checkHotelDates()
{
   if (   document.flight_order_form.hotelsStartTimeMon.value > document.flight_order_form.hotelsEndTimeMon.value
       || (   document.flight_order_form.hotelsStartTimeMon.value == document.flight_order_form.hotelsEndTimeMon.value
           && document.flight_order_form.hotelsStartTimeDay.value > document.flight_order_form.hotelsEndTimeDay.value
          )
      )
      return false;
   else
      return true;
}
function checkRacDates()
{
   if (   document.flight_order_form.racStartTimeMon.value > document.flight_order_form.racEndTimeMon.value
       || (   document.flight_order_form.racStartTimeMon.value == document.flight_order_form.racEndTimeMon.value
           && document.flight_order_form.racStartTimeDay.value > document.flight_order_form.racEndTimeDay.value
          )
      )
      return false;
	else if (  document.flight_order_form.racStartTimeCal.value+document.flight_order_form.racStartTimeHrs.value+document.flight_order_form.racStartTimeMins.value
				> document.flight_order_form.racEndTimeCal.value+document.flight_order_form.racEndTimeHrs.value+document.flight_order_form.racEndTimeMins.value
			  )
		return false;
   else
      return true;
}
function checkRacTimes()
{
	if (   document.flight_order_form.racStartTimeHrs.value == ''
		 || document.flight_order_form.racStartTimeMins.value == ''
		 || document.flight_order_form.racEndTimeHrs.value == ''
		 || document.flight_order_form.racEndTimeMins.value == ''
		)
		return false;
	else
		return true;
}
function isReturnTrip()
{
   return document.flight_order_form.roundTrip.checked ? 1 : 0;
}
function getTravellerNr()
{
   return   parseInt(document.flight_order_form.passengersADT.value)
          + parseInt(document.flight_order_form.passengersYTH.value)
          + parseInt(document.flight_order_form.passengersYCD.value)
          + parseInt(document.flight_order_form.passengersCHD.value);
}
function getChildernNr()
{
   return parseInt(document.flight_order_form.passengersCHD.value);
}
function getInfantNr()
{
   return parseInt(document.flight_order_form.passengersINF.value);
}
function detectLang()
{
   return(document.flight_order_form.currentLang.value);
}
function isBooking()
{
   return(document.flight_order_form.isBooking.value-0);
}
function isTimeTable()
{
   return(document.flight_order_form.isTimeTable.value-0);
}
function isCheckTrip()
{
	return(document.flight_order_form.isCheckTrip.value-0);
}
function isHotels()
{
   return(document.flight_order_form.isHotels.value-0);
}
function isRentACar()
{
   return(document.flight_order_form.isRentACar.value-0);
}
function changeMonthFrom()
{
   day = document.flight_order_form.startTimeDay.value-0;
   month = document.flight_order_form.startTimeMon.value;

	if (isBooking())
	   start = (month == document.flight_order_form.minMon.value) ? document.flight_order_form.minDay.value-0 : 1;
	else
		start = (month == document.flight_order_form.minMonTT.value) ? document.flight_order_form.minDayTT.value-0 : 1;

	end = daysInMonth[month.toString().substr(4,2)-0];

   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(0,4)%4))
      end++;

   document.forms['flight_order_form'].startTimeDay.options.length = 0;
   count = 0;
   for (var i=start; i<=end; i++)
      document.forms['flight_order_form'].startTimeDay.options[count++]
         = new Option(""+(i<10 ? '0'+i : i), (i<10 ? '0'+i : i));

   if (day<start)
      day = start;

   if (day>end)
      day = end;
   document.forms['flight_order_form'].startTimeDay.selectedIndex = day-start;
   setToNextWeek();
   UpdateCalInput();
}
function changeMonthTo()
{
   day = document.flight_order_form.endTimeDay.value-0;
//alert('day: '+day);
   month = document.flight_order_form.endTimeMon.value;
//alert('month: '+month);
   start = (month == document.flight_order_form.minMon.value) ? document.flight_order_form.minDay.value-0 : 1;
   end = daysInMonth[month.toString().substr(4,2)-0];
   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(0,4)%4))
      end++;

   document.forms['flight_order_form'].endTimeDay.options.length = 0;
   count = 0;
   for (var i=start; i<=end; i++)
      document.forms['flight_order_form'].endTimeDay.options[count++]
         = new Option(""+(i<10 ? '0'+i : i), (i<10 ? '0'+i : i));
//alert('now: '+day);
//alert(start);
   if (day<start)
      day = start;
   if (day>end)
      day = end;
   document.forms['flight_order_form'].endTimeDay.selectedIndex = day-start;

   UpdateCalInput();
}
function setToNextWeek()
{
   day = (document.flight_order_form.startTimeDay.value-0)+7;
   month = document.flight_order_form.startTimeMon.value.toString().substr(4,2);
   year = document.flight_order_form.startTimeMon.value.toString().substr(0,4);
   lastDay = daysInMonth[month-0];
   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(4,2)%4))
      lastDay++;
   if (day>lastDay)
   {
      day-=lastDay;
      if (++month>12)
      {
         month = 1;
         year++;
      }
   }
   if (day<10) day = '0'+day;
   if (month-0<10) month = '0'+(month-0);

   document.forms['flight_order_form'].endTimeMon.value = year+month;
   document.forms['flight_order_form'].endTimeDay.value = day;
//alert(day);
   changeMonthTo();
   UpdateCalInput();
}
function changeHotelsMonthFrom()
{
   day = document.flight_order_form.hotelsStartTimeDay.value-0;
   month = document.flight_order_form.hotelsStartTimeMon.value;

	start = (month == document.flight_order_form.minMonTT.value) ? document.flight_order_form.minDayTT.value-0 : 1;

	end = daysInMonth[month.toString().substr(4,2)-0];

   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(0,4)%4))
      end++;

   document.forms['flight_order_form'].hotelsStartTimeDay.options.length = 0;
   count = 0;
   for (var i=start; i<=end; i++)
      document.forms['flight_order_form'].hotelsStartTimeDay.options[count++]
         = new Option(""+(i<10 ? '0'+i : i), (i<10 ? '0'+i : i));

   if (day<start)
      day = start;

   if (day>end)
      day = end;
   document.forms['flight_order_form'].hotelsStartTimeDay.selectedIndex = day-start;
   setHotelsToNextWeek();
   UpdateHotelsCalInput();
}
function changeHotelsMonthTo()
{
   day = document.flight_order_form.hotelsEndTimeDay.value-0;
//alert('day: '+day);
   month = document.flight_order_form.hotelsEndTimeMon.value;
//alert('month: '+month);
   start = (month == document.flight_order_form.minMon.value) ? document.flight_order_form.minDay.value-0 : 1;
   end = daysInMonth[month.toString().substr(4,2)-0];
   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(0,4)%4))
      end++;

   document.forms['flight_order_form'].hotelsEndTimeDay.options.length = 0;
   count = 0;
   for (var i=start; i<=end; i++)
      document.forms['flight_order_form'].hotelsEndTimeDay.options[count++]
         = new Option(""+(i<10 ? '0'+i : i), (i<10 ? '0'+i : i));
//alert('now: '+day);
//alert(start);
   if (day<start)
      day = start;
   if (day>end)
      day = end;
   document.forms['flight_order_form'].hotelsEndTimeDay.selectedIndex = day-start;

   UpdateHotelsCalInput();
}
function setHotelsToNextWeek()
{
   day = (document.flight_order_form.hotelsStartTimeDay.value-0)+7;
   month = document.flight_order_form.hotelsStartTimeMon.value.toString().substr(4,2);
   year = document.flight_order_form.hotelsStartTimeMon.value.toString().substr(0,4);
   lastDay = daysInMonth[month-0];
   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(4,2)%4))
      lastDay++;
   if (day>lastDay)
   {
      day-=lastDay;
      if (++month>12)
      {
         month = 1;
         year++;
      }
   }
   if (day<10) day = '0'+day;
   if (month-0<10) month = '0'+(month-0);

   document.forms['flight_order_form'].hotelsEndTimeMon.value = year+month;
   document.forms['flight_order_form'].hotelsEndTimeDay.value = day;
//alert(day);
   changeHotelsMonthTo();
   UpdateHotelsCalInput();
}
function changeRacMonthFrom()
{
   day = document.flight_order_form.racStartTimeDay.value-0;
   month = document.flight_order_form.racStartTimeMon.value;

	start = (month == document.flight_order_form.minMonTT.value) ? document.flight_order_form.minDayTT.value-0 : 1;

	end = daysInMonth[month.toString().substr(4,2)-0];

   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(0,4)%4))
      end++;

   document.forms['flight_order_form'].racStartTimeDay.options.length = 0;
   count = 0;
   for (var i=start; i<=end; i++)
      document.forms['flight_order_form'].racStartTimeDay.options[count++]
         = new Option(""+(i<10 ? '0'+i : i), (i<10 ? '0'+i : i));

   if (day<start)
      day = start;

   if (day>end)
      day = end;
   document.forms['flight_order_form'].racStartTimeDay.selectedIndex = day-start;
   setRacToNextWeek();
   UpdateRacCalInput();
}
function changeRacMonthTo()
{
   day = document.flight_order_form.racEndTimeDay.value-0;
//alert('day: '+day);
   month = document.flight_order_form.racEndTimeMon.value;
//alert('month: '+month);
   start = (month == document.flight_order_form.minMon.value) ? document.flight_order_form.minDay.value-0 : 1;
   end = daysInMonth[month.toString().substr(4,2)-0];
   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(0,4)%4))
      end++;

   document.forms['flight_order_form'].racEndTimeDay.options.length = 0;
   count = 0;
   for (var i=start; i<=end; i++)
      document.forms['flight_order_form'].racEndTimeDay.options[count++]
         = new Option(""+(i<10 ? '0'+i : i), (i<10 ? '0'+i : i));
//alert('now: '+day);
//alert(start);
   if (day<start)
      day = start;
   if (day>end)
      day = end;
   document.forms['flight_order_form'].racEndTimeDay.selectedIndex = day-start;

   UpdateRacCalInput();
}
function setRacToNextWeek()
{
   day = (document.flight_order_form.racStartTimeDay.value-0)+7;
   month = document.flight_order_form.racStartTimeMon.value.toString().substr(4,2);
   year = document.flight_order_form.racStartTimeMon.value.toString().substr(0,4);
   lastDay = daysInMonth[month-0];
   if(month.toString().substr(4,2) == "02" && !(month.toString().substr(4,2)%4))
      lastDay++;
   if (day>lastDay)
   {
      day-=lastDay;
      if (++month>12)
      {
         month = 1;
         year++;
      }
   }
   if (day<10) day = '0'+day;
   if (month-0<10) month = '0'+(month-0);

   document.forms['flight_order_form'].racEndTimeMon.value = year+month;
   document.forms['flight_order_form'].racEndTimeDay.value = day;
//alert(day);
   changeRacMonthTo();
   UpdateRacCalInput();
}
function switchToTimetable()
{
	if (!isTimeTable()) {
		globalHide();
		document.flight_order_form.isTimeTable.value = 1;
		globalShow();

		setDatesToTimeTable();setToNextWeek();
	   //if (!roundTripPartText) roundTripPartText = document.getElementById('roundTripPart').innerHTML;
	   //document.getElementById('roundTripPart').innerHTML = '';
	   if (!passengerPartText) passengerPartText = document.getElementById('passengerPart').innerHTML;
	   document.getElementById('passengerPart').innerHTML = '';
	   //if (!cabinClassPartText) cabinClassPartText = document.getElementById('cabinClassPart').innerHTML;
	   //document.getElementById('cabinClassPart').innerHTML = '';
	   if (!flexiblePartText) flexiblePartText = document.getElementById('flexiblePart').innerHTML;
	   //document.getElementById('flexiblePart').innerHTML = '';
	   document.getElementById('flexiblePart').style.visibility='hidden';
	   document.getElementById('submitText').innerHTML = document.forms['flight_order_form'].timetableNowTxt.value;

	   document.forms['flight_order_form'].action = "timetable.php";
	   document.forms['flight_order_form'].target = "_self";
	}
}
function switchToBooking()
{
	if (!isBooking())
	{
		globalHide();
		document.flight_order_form.isBooking.value = 1;
		globalShow();

		setDatesToBooking();setToNextWeek();

	   //document.getElementById('roundTripPart').innerHTML = roundTripPartText;
	   if (passengerPartText)
	   	document.getElementById('passengerPart').innerHTML = passengerPartText;
	   //document.getElementById('cabinClassPart').innerHTML = cabinClassPartText;
	   //if (flexiblePartText)
	   //	document.getElementById('flexiblePart').innerHTML = flexiblePartText;
	   document.getElementById('flexiblePart').style.visibility='visible';
	   document.getElementById('submitText').innerHTML = document.forms['flight_order_form'].bookNowTxt.value;
	   document.forms['flight_order_form'].action = "booking.php";
	   document.forms['flight_order_form'].method = "post";
	   document.forms['flight_order_form'].target = "_self";
	   decideSubmitText();
	}
}

function switchToCheckTrip()
{
   if (!isCheckTrip())
   {
		globalHide();
		document.flight_order_form.isCheckTrip.value = 1;
		globalShow();
      document.forms['flight_order_form'].action = "check_trip.php";
      document.forms['flight_order_form'].method = "post";
      document.forms['flight_order_form'].target = "_blank";
   }
}
function switchToHotels() {
	if (!isHotels()) {
		globalHide();
		document.flight_order_form.isHotels.value = 1;
		globalShow();
      document.forms['flight_order_form'].action = "hotels.php";
      document.forms['flight_order_form'].method = "post";
      document.forms['flight_order_form'].target = "_blank";
	}
   UpdateHotelsCalInput();
   hotelsSwitchLand();
}
function switchToRentACar() {
	if (!isRentACar()) {
		globalHide();
		document.flight_order_form.isRentACar.value = 1;
		globalShow();
      document.forms['flight_order_form'].action = "rentAcar.php";
      document.forms['flight_order_form'].method = "post";
      document.forms['flight_order_form'].target = "_blank";
	}
	UpdateRacCalInput();
}
function globalHide() {
	if (isBooking() || isTimeTable()) {
		preserve_centerCellBooking = document.getElementById('centerCell').innerHTML;
		document.getElementById('centerCell').innerHTML = '';
		document.getElementById('bookingHeaderCell').className = 'selectorCell';
		document.getElementById('timetableHeaderCell').className = 'selectorCell';
	} else if (isCheckTrip()) {
		preserve_centerCellCheckTrip = document.getElementById('centerCell2').innerHTML;
		document.getElementById('centerCell2').innerHTML = '';
		document.getElementById('checktripHeaderCell').className = 'selectorCell';
//	} else if (isHotels()) {
//		preserve_centerCellHotels = document.getElementById('centerCell3').innerHTML;
//		document.getElementById('centerCell3').innerHTML = '';
//		document.getElementById('hotelsHeaderCell').className = 'selectorCell';
//	} else if (isRentACar()) {
//		preserve_centerCellRentACar = document.getElementById('centerCell4').innerHTML;
//		document.getElementById('centerCell4').innerHTML = '';
//		document.getElementById('rentacarHeaderCell').className = 'selectorCell';
	}
	document.flight_order_form.isBooking.value = 0;
	document.flight_order_form.isTimeTable.value = 0;
	document.flight_order_form.isCheckTrip.value = 0;
	document.flight_order_form.isHotels.value = 0;
	document.flight_order_form.isRentACar.value = 0;
}
function globalShow() {
	if (isBooking()) {
		document.getElementById('centerCell').innerHTML = preserve_centerCellBooking;
		document.getElementById('selectorHeaderTable').className = 'bookingActive';
	} else if (isTimeTable()) {
		document.getElementById('centerCell').innerHTML = preserve_centerCellBooking;
		document.getElementById('selectorHeaderTable').className = 'timetableActive';
	} else if (isCheckTrip()) {
		document.getElementById('centerCell2').innerHTML = preserve_centerCellCheckTrip;
		document.getElementById('selectorHeaderTable').className = 'checktripActive';
//	} else if (isHotels()) {
//		document.getElementById('centerCell3').innerHTML = preserve_centerCellHotels;
//		document.getElementById('hotelsHeaderCell').className = 'selectorCellOn';
//	} else if (isRentACar()) {
//		document.getElementById('centerCell4').innerHTML = preserve_centerCellRentACar;
//		document.getElementById('rentacarHeaderCell').className = 'selectorCellOn';
	}
}
function hideCheckTrip()
{
   document.getElementById('centerCell').innerHTML = preserve_centerCell;

   preserve_centerCell2 = document.getElementById('centerCell2').innerHTML;
   document.getElementById('centerCell2').innerHTML = '';
}
function initHomeForm()
{
//	preserve_hotelTitle = document.getElementById('hotelTitle').innerHTML;
//	document.getElementById('hotelTitle').innerHTML = '';
//	preserve_hotelInfo = document.getElementById('hotelInfo').innerHTML;
//	document.getElementById('hotelInfo').innerHTML = '';
   if (document.getElementById('centerCell2')) { // skip for multidest
      preserve_centerCellCheckTrip = document.getElementById('centerCell2').innerHTML;
      document.getElementById('centerCell2').innerHTML = '';
   }
//   preserve_centerCellHotels = document.getElementById('centerCell3').innerHTML;
//   document.getElementById('centerCell3').innerHTML = '';
//   preserve_centerCellRentACar = document.getElementById('centerCell4').innerHTML;
//   document.getElementById('centerCell4').innerHTML = '';
}

//---- info ----- (taken from e-travel)
function ShowTipsPassengers()
{
	// Change the size of the iFrame tips on Opera navigator
//	var iFrame=document.getElementById("popup2iFrame");
	var popup2Cmp=document.getElementById("popup2");
//	if (navigator.userAgent.toLowerCase().indexOf('opera') != -1)
//	{
//		iFrame.style.width="0px";
//		iFrame.style.height="0px";
//	}
//	else
//	{
//		var sX=popup2Cmp.offsetWidth+"px";
//		var sY=popup2Cmp.offsetHeight+"px";
//		iFrame.style.width=sX;
//		iFrame.style.height=sY;
//		popup2Cmp.style.width=sX;
//		popup2Cmp.style.height=sY;
//	}
	// Move the position of the tips
	var iCmp = document.getElementById("lnkTraInfo");
	var pY = getTop(iCmp) + 15;
	var pX = getLeft(iCmp) + 15;
	popup2Cmp.style.top=pY+"px";
	popup2Cmp.style.left=pX+"px";
	// Force the size of the iframe and div to 0 in case IE < 5.1
	var navig = navigator.userAgent.toLowerCase();
	var msie50x = navig.indexOf("msie 5.0");
	if (msie50x != -1)
	{
		popup2Cmp.style.width=0;
		popup2Cmp.style.height=0;
//		iFrame.style.height=0;
//		iFrame.style.width=0;
	}
	MM_showHideLayers('popup2','','show');
}
function HideTipsPassengers() {
//	var iFrame=document.getElementById("popup2iFrame");
//	iFrame.style.width="0px";
//	iFrame.style.height="0px";
	MM_showHideLayers('popup2','','hide');
}
function getTop(MyObject)
{
	if (MyObject.offsetParent) return (MyObject.offsetTop + getTop(MyObject.offsetParent));
	else return (MyObject.offsetTop);
}
function getLeft(MyObject)
{
	if (MyObject.offsetParent) return (MyObject.offsetLeft + getLeft(MyObject.offsetParent));
	else return (MyObject.offsetLeft);
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}



function decideSubmitText()
{
	if(document.forms['flight_order_form'].isBooking.value==1)
	{
//		if(    document.forms['flight_order_form'].fromCity.value
//			&& !hasNoEticketing(document.forms['flight_order_form'].fromCity.value,document.flight_order_form.startTimeMon.value+document.flight_order_form.startTimeDay.value)
//			&& document.forms['flight_order_form'].toCity.value
//			&& (!document.forms['flight_order_form'].roundTrip.checked
//				  ||
//				 !hasNoEticketing(document.forms['flight_order_form'].toCity.value,document.flight_order_form.endTimeMon.value+document.flight_order_form.endTimeDay.value)
//				)
//		  )
//		  	sText = submitTexts[1];
//		else
			sText = submitTexts[0];
//alert(document.forms['flight_order_form'].roundTrip.checked)
		document.getElementById('submitText').innerHTML = sText;
	}
}
function hasNoEticketing(ap,dep)
{
		return 0;
}

function getAlertWin()
{
	return true;
}

function hotelsSwitchLand() {
	switch(document.forms['flight_order_form'].hotelsSelector.value) {
		case 'SRB':
			if (document.getElementById('hotelTitle').innerHTML) {
				preserve_hotelTitle = document.getElementById('hotelTitle').innerHTML;
				document.getElementById('hotelTitle').innerHTML = '';
			}
			if (preserve_visitSerbiaTitle)
				document.getElementById('visitSerbiaTitle').innerHTML = preserve_visitSerbiaTitle;

			if (document.getElementById('hotelInfo').innerHTML) {
				preserve_hotelInfo = document.getElementById('hotelInfo').innerHTML;
				document.getElementById('hotelInfo').innerHTML = '';
			}
			if (preserve_visitSerbia)
				document.getElementById('visitSerbia').innerHTML = preserve_visitSerbia;
			break;
		default:
			if (document.getElementById('visitSerbiaTitle').innerHTML) {
				preserve_visitSerbiaTitle = document.getElementById('visitSerbiaTitle').innerHTML;
				document.getElementById('visitSerbiaTitle').innerHTML = '';
			}
			if (preserve_hotelTitle)
				document.getElementById('hotelTitle').innerHTML = preserve_hotelTitle;

			if (document.getElementById('visitSerbia').innerHTML) {
				preserve_visitSerbia = document.getElementById('visitSerbia').innerHTML;
				document.getElementById('visitSerbia').innerHTML = '';
			}
			if (preserve_hotelInfo)
				document.getElementById('hotelInfo').innerHTML = preserve_hotelInfo;
	}
}

///// visitserbia.org
var oLED = new Date()

function getTommorow(S) {
	oS = makeDate(S["day"], S["month"], S["year"]);
	oLED = new Date();
	oLED.setTime(oS.getTime() + 86400000);
	return oLED;
}

function makeDate(d,m,y) {
//	alert(d + "\n" + m + "\n" + y)
	oS = new Date();
	oS.setDate(d);
	oS.setMonth(m - 1);
	oS.setYear(y);
//	alert(oS.getTime())
	return oS;
}

function makeFDate(sDI) {
	oF = document.forms["flight_order_form"];
	return makeDate(1+oF.elements[sDI + "_Day"].selectedIndex, 1+oF.elements[sDI + "_Month"].selectedIndex, oF.elements[sDI + "_Year"].options[oF.elements[sDI + "_Year"].selectedIndex].value);
}

function setFDate(sDI, oD) {
	oF = document.forms["flight_order_form"];
	setFOption(oF, sDI+"_Day", oD.getDate());
	setFOption(oF, sDI+"_Month", oD.getMonth()+1);
	setFOption(oF, sDI+"_Year", oD.getFullYear());
}

function setFOption(oF,sDI,iV) {
	oE = oF.elements[sDI];
	for(i=0;i<oE.options.length;i++) {
		if (oE.options[i].value == iV) {
			oE.selectedIndex=i;
			return;
		}
	}
}

function fixDates(oE) {
	aN = oE.name.split("_");
	if (aN[0] == "start" || aN[0] == "end") {
		oST = makeFDate("start");
		oEN = makeFDate("end");

		if (oEN.getTime()<=oST.getTime()) {
			if (aN[0] == "start") {
				oEN = new Date();
				oEN.setTime(oST.getTime() + 86400000);
				setFDate("end", oEN);
			}
			if (aN[0] == "end") {
				setFDate("end", oLED);
				return;
			}
		}
		oLED = oEN;
	}
	if (aN[0]=="SGL" || aN[0]=="DBL") {
		oF = oE.form;
		iA = 1 * getOptionVal(oF, "SGL") + 2 * getOptionVal(oF, "DBL");
		setFOption(oF, "adults", iA);
	}
}

function drawOptions(sName, iS, iE, iV, bLZ) {
	HT = '';
	HT += '<select name="' + sName + '" style="width: ' + ((iE>99)?62:45) + 'px"  onChange="fixDates(this)">';
	for (i=iS; i<iE+1; i++) {
		HT += '<option value="' + i + '"' + ((iV==i)?' selected="selected"':'') + '>' + ((i<10 && bLZ)?"0"+i:i) + '</option>';
	}
	HT += '</select>';
	return HT;
}

function checkSearch(oF) {
	SGL = getOptionVal(oF,"SGL");
	DBL = getOptionVal(oF,"DBL");
	adults = getOptionVal(oF,"adults");
	if ((1*SGL + 2*DBL)!=adults) {
		alert("Number of adults, doesn't fit to the number of (" + (1*SGL+2*DBL) + ") bed(s)!");
		return false;
	}

	if ((Number(SGL)+Number(DBL))>3) {
		window.open("http://book.visitserbia.org/popup_more_rooms.php", "popup_more_rooms", "width=300,height=350,scrollbars=no,status=no");
		return false;
	}
	return true;
}

function getOptionVal(oF,sN) {
	oE = oF.elements[sN];
	return oE.options[oE.selectedIndex].value;
}

function setMultiDestinationOptions(field) {
   if (field.value) {
      items = field.value.toString().split(',')
      document.getElementById('cityFrom1').value = items[0]
      document.getElementById('cityTo1').value = items[1]
      document.getElementById('cityFrom2').value = items[2]
      document.getElementById('cityTo2').value = items[3]
      document.getElementById('flight1').innerHTML = items[4]
      document.getElementById('flight2').innerHTML = items[5]
   } else {
      document.getElementById('cityFrom1').value = ''
      document.getElementById('cityTo1').value = ''
      document.getElementById('cityFrom2').value = ''
      document.getElementById('cityTo2').value = ''
      document.getElementById('flight1').innerHTML = '-'
      document.getElementById('flight2').innerHTML = '-'
   }
}

/**
 * NOVI SISTEM SA TABOVIMA!!!
 */

function switch_tab(obj, tab_name) {
	var tab_list = document.getElementById('tab_list').getElementsByTagName('li');
	var control_list = document.getElementById('control_list');
	var all_parts = new Array(1, 2, 3, 4, 5, 6);
	var visible_parts = {
				'booking': [1, 2, 3, 4],
				'timetable': [1, 2],
				'trip_check': [5],
				'rent_a_car': [6]
			};
	var form = document.forms['flight_order_form'];
	var submit_button = document.getElementById('submit_button');

	// resetujemo izgled tab liste
	for (var i=0; i < tab_list.length; i++) {
		var tab = tab_list[i];

		tab.className = '';
	}
	obj.parentNode.className = 'active';

	// sredimo prikaz elemenata
	part_list = visible_parts[tab_name];

	for (var i=0; i<all_parts.length; i++) {
		part = all_parts[i];

		if (part_list.indexOf(part) != -1)
			show_part(part); else
			hide_part(part);
	}

	// podesimo parametre forme
	switch (tab_name) {
		case 'booking':
			form.action = "booking.php";
			document.forms['flight_order_form'].isBooking.value = 1;
			submit_button.innerHTML = document.forms['flight_order_form'].bookNowTxt.value;
			submit_button.style.visibility = 'visible';
			break;

		case 'timetable':
			form.action = "timetable.php";
			document.forms['flight_order_form'].isTimeTable.value = 1;
			submit_button.innerHTML = document.forms['flight_order_form'].timetableNowTxt.value;
			submit_button.style.visibility = 'visible';
			break;

		case 'trip_check':
			form.action = "check_trip.php";
			document.forms['flight_order_form'].isCheckTrip.value = 1;
			submit_button.innerHTML = document.forms['flight_order_form'].checktripNowTxt.value;;
			submit_button.style.visibility = 'visible';
			break;

		default:
			submit_button.style.visibility = 'hidden';
			break;
	}
}

function show_part(id) {
	var obj = document.getElementById('part_'+id);
	obj.style.display = "block";
}

function hide_part(id) {
	var obj = document.getElementById('part_'+id);
	obj.style.display = "none";
}

function toggle_visibility(sender, id) {
	var obj = document.getElementById(id);

	if (obj)
		obj.style.visibility = sender.checked ? 'visible' : 'hidden';
}

