var numSegmentsMultiDest = 0;

function roundTripSelected() {      
      document.getElementById('airtodates').style.display= 'block';
      document.getElementById('flightlabel1').style.display= 'none';
      document.getElementById('flightAndHotel').style.display= 'block';
      setBold('RoundTripSpan');
      hideMultiSegments();
}

function hideMultiSegments() { 
      document.getElementById('addAnotherFlight1').style.display = 'none';
      for (var i=2;i<=6;i++)
      {   
            document.getElementById('flight'+ i).style.display = 'none';
      }
}

function unhideMultiSegments() { 
    document.getElementById('addAnotherFlight1').style.display = 'block'; 
      for (var i=2;i<=3;i++)
      {
            document.getElementById('flight' + i).style.display = 'block';
            document.getElementById('removeAFlight' + i).style.display = 'block';
      }
}

function onewaySelected() {         
      document.getElementById('airtodates').style.display= 'none';
      document.getElementById('flightlabel1').style.display= 'none';
      document.getElementById('flightAndHotel').style.display= 'none';
      setBold('OneWaySpan');
      hideMultiSegments();
}

function multiCitySelected() {      
    setBold('MultiCitySpan');
    unhideMultiSegments();
    document.getElementById('airtodates').style.display= 'none';
    document.getElementById('flightlabel1').style.display= 'block';
    document.getElementById('flightAndHotel').style.display= 'none';
}

function isMutiCitySelect() {
	var isMultiCitySelected = document.getElementById('mutiCity').checked;
	var isOneWaySelected = document.getElementById('oneWay').checked;
	
	if(isMultiCitySelected || isOneWaySelected)
		document.getElementById('flightAndHotel').style.display= 'none';
}

function advanceAirSearchOptions()  
       { 
         var divstyle = new String();     
         divstyle = document.getElementById('advanceSearch').style.display;   
         if( divstyle == 'block')      
            {       
              document.getElementById('advanceSearch').style.display = 'none';  
              document.getElementById('advancedAirSearch').style.display = 'none'; 
              document.getElementById('basicAirSearch').style.display = 'block'; 
            }  
         else 
            {
              document.getElementById('advanceSearch').style.display = 'block';
              document.getElementById('advancedAirSearch').style.display = 'block';
              document.getElementById('basicAirSearch').style.display = 'none'; 
            } 
        }


function addAnotherFlight(fromLoc, toLoc, normalTextColor, inactiveTextColor)
{ 
   setNumberOfSegments(++numSegmentsMultiDest);
   document.getElementById('flight'+numSegmentsMultiDest).style.display = 'block';
   document.getElementById('removeAFlight'+numSegmentsMultiDest).style.display = 'block';
   
   //reset Fields to default text.
   var fieldToReset = numSegmentsMultiDest;
   document.getElementById('fromLocation' + fieldToReset).value = fromLoc;
   document.getElementById('toLocation' + fieldToReset).value = toLoc;
   document.getElementById("fromLocation"+fieldToReset).style.color = inactiveTextColor;
   document.getElementById("toLocation"+fieldToReset).style.color = inactiveTextColor;
   document.getElementById("fromTime"+fieldToReset).selectedIndex = 0;
   
	document.getElementById("fromLocation"+fieldToReset).onfocus = 
		function() {
  	 	 	enterTipField(document.getElementById("fromLocation"+fieldToReset), fromLoc, normalTextColor);
  	 	 	AutoComplete.divName = 'fromlocation'+fieldToReset+'iframe';
  	 	 	return;
  	 	 	
  	 	};
  	 
	document.getElementById("fromLocation"+fieldToReset).onblur =
  	   function() {
  	 	 	exitTipField(document.getElementById("fromLocation"+fieldToReset), fromLoc, inactiveTextColor);
  	 	 	AutoComplete.divName = '';
  	 	 	return;
  	 	};
  	 	
	 document.getElementById("toLocation"+fieldToReset).onfocus = 
		function() {
  	 	 	enterTipField(document.getElementById("toLocation"+fieldToReset), toLoc, normalTextColor);
  	 	 	AutoComplete.divName = 'tolocation'+fieldToReset+'iframe';
  	 	 	return;
  	 	 	
  	 	};
  	 
	  document.getElementById("toLocation"+fieldToReset).onblur
	  	 = function() {
	  	 	 	exitTipField(document.getElementById("toLocation"+fieldToReset), toLoc, inactiveTextColor);
	  	 	 	AutoComplete.divName = '';
	  	 	 	return;
	  	 	}; 
	   
   if(numSegmentsMultiDest == 6){
    document.getElementById('addAnotherFlight1').style.display = 'none';
   }
   
 }


function removeAFlightSegment(currIndex){

      //say currIndex = 1. then, lets get all the entered data (loc & dates) and try pushing 1 up.
      //and then stop dispalying the numSegmentsMultiDest+1 th segment
      var fromLoc = new Array(6) ;
      var toLoc = new Array(6) ;
      var fromStyleColor = new Array(6) ;
      var toStyleColor = new Array(6) ;
      var departDt =  new Array(6);
      var departTime =  new Array(6);
      for (var i=1; i<=numSegmentsMultiDest; i++){
                  fromLoc[i] = document.getElementById("fromLocation"+i).value;
                  toLoc[i] = document.getElementById("toLocation"+i).value;
                  fromStyleColor[i] = document.getElementById("fromLocation"+i).style.color;
                  toStyleColor[i] = document.getElementById("toLocation"+i).style.color;
                  departDt[i] = document.getElementById("dateairFromDate"+i).value;
                  departTime[i] = document.getElementById("fromTime"+i).value;
      }
      var k = currIndex ;
      for (var j=currIndex+1 ; j<=numSegmentsMultiDest && k <=numSegmentsMultiDest ; j++){
                  
                  document.getElementById("fromLocation"+k).value = fromLoc[j] ;
                  document.getElementById("fromLocation"+k).style.color = fromStyleColor[j] ;
                  document.getElementById("toLocation"+k).value = toLoc[j] ;
                  document.getElementById("toLocation"+k).style.color = toStyleColor[j] ;
                  document.getElementById("dateairFromDate"+k).value = departDt[j] ;
                  document.getElementById("fromTime"+k).value = departTime[j] ;
                  k++;
      }
      document.getElementById('flight' + numSegmentsMultiDest).style.display = 'none';
      document.getElementById('fromLocation' + numSegmentsMultiDest).value = "";
  	  document.getElementById('toLocation' + numSegmentsMultiDest).value = "";
	   
      setNumberOfSegments(--numSegmentsMultiDest);
      if(numSegmentsMultiDest < 6 ){
            for(var m=1; m<=numSegmentsMultiDest; m++){
                  document.getElementById('flight' + m).style.display = 'block';
            }
      }
      
      if(numSegmentsMultiDest == 1){
            for(var z=1; z<=6; z++){
            if(document.getElementById('removeAFlight' + z))
              document.getElementById('removeAFlight' + z).style.display = 'none';
            }
      }
      
   if(numSegmentsMultiDest != 6){
     document.getElementById('addAnotherFlight1').style.display = 'block';
   }

}

function displayMultiDestSearchSegments(){
      set_display("airCrossSell",false);
      set_display("multiDestSegmentDisplay1Label", true);
      set_display("multiDestSegmentDisplay0", isAirOnlyIncluded());
      set_display("multiDestSegmentDisplay1", isAirOnlyIncluded());
      set_display("multiDestSegmentDisplay2", isAirOnlyIncluded());
      set_display("multiDestSegmentDisplay3", isAirOnlyIncluded());
      set_display("addAnotherFlight1", true);
      set_display("addAnotherFlight2", true);
      set_display("addAnotherFlight3", true);
      
      set_display("removeAFlight1", true);
      set_display("removeAFlight2", true);
      set_display("removeAFlight3", true);
      
      set_display("RoundTripTable", false);
      set_display("airDatesDisplay", false);
      set_display("returnDate1", false);
      set_display("returnDate2", false);
      setNumberOfSegments(3);
      setBold('MultiCitySpan');
      setDivHeight('cpsearch_center','intc_frameworkcenter');
}

function onPageReloadForMultiCity(num){
      if(num == 6){
            set_display("multiDestSegmentDisplay6", true);
            set_display("addAnotherFlight1", false);
            set_display("addAnotherFlight2", false);
            set_display("addAnotherFlight3", false);
            set_display("removeAFlight6", true);
            
            set_display("multiDestSegmentDisplay5", true);
            set_display("removeAFlight5", true);
            
            set_display("multiDestSegmentDisplay4", true);
            set_display("removeAFlight4", true);
      } else if(num == 5){
            set_display("multiDestSegmentDisplay5", true);
            set_display("addAnotherFlight5", true);
            set_display("removeAFlight5", true);
            
            set_display("multiDestSegmentDisplay4", true);
            set_display("addAnotherFlight4", true);
            set_display("removeAFlight4", true);
      } else if (num == 4){
            set_display("multiDestSegmentDisplay4", true);
            set_display("addAnotherFlight4", true);
            set_display("removeAFlight4", true);
      } else if (num == 2){
            set_display("multiDestSegmentDisplay3", false);
            set_display("addAnotherFlight3", false);
            set_display("removeAFlight3", false);
      } else if (num == 1){
            set_display("multiDestSegmentDisplay2", false);
            set_display("multiDestSegmentDisplay3", false);
            set_display("addAnotherFlight3", false);
            set_display("removeAFlight3", false);
            
            set_display("addAnotherFlight2", false);
            set_display("removeAFlight2", false);
      }
      
      
      
}

function setNumberOfSegments(num){
      numSegmentsMultiDest = num;
      var numSegments = document.getElementById("numAirSearchSegments");
      
      numSegments.value = num;
}

function displayOneWaySegment(){
      set_display("airCrossSell",false);
      disableAllFlightSegments();
      set_display("multiDestSegmentDisplay1Label", false);
      set_display("multiDestSegmentDisplay1", isAirOnlyIncluded());
      setNumberOfSegments(1);
      setBold('OneWaySpan');
      setDivHeight('cpsearch_center','intc_frameworkcenter');
}

function displayRoundTripSegments(){
      set_display("addAnotherFlight1", false); //only in IE this is needed
    set_display("airCrossSell", (!isHotelIncluded() && !isCarIncluded() && ! isASIncluded() && isStandAloneAirAndDDAllowedForAdvancedSearch() && isAHAllowdForDD()));
      disableAllFlightSegments();
      set_display("multiDestSegmentDisplay1", true);
      set_display("multiDestSegmentDisplay1Label", false);
      set_display("returnDate1", true);
      set_display("returnDate2", true);
      setNumberOfSegments(1);
      setBold('RoundTripSpan');
      setDivHeight('cpsearch_center','intc_frameworkcenter');
}

function setBold(id){
      if(document.getElementById('RoundTripSpan'))
            document.getElementById('RoundTripSpan').style.fontWeight = 'normal'
      if(document.getElementById('OneWaySpan'))
            document.getElementById('OneWaySpan').style.fontWeight = 'normal'
      if(document.getElementById('MultiCitySpan'))
            document.getElementById('MultiCitySpan').style.fontWeight = 'normal'
      if(document.getElementById(id))
            document.getElementById(id).style.fontWeight = 'bold'
      return;
}

function disableAllFlightSegments(){
      for (var i=1; i<=6; i++){
            set_display("multiDestSegmentDisplay"+i, false);
            set_display("addAnotherFlight"+i, false);
            set_display("removeAFlight"+i, false);    
      }
      set_display("multiDestSegmentDisplay0", false);
      set_display("returnDate1", false);
      set_display("returnDate2", false);
      set_display("multiDestSegmentDisplay1Label", false);
      set_display("addAnotherFlight", false);   
      set_display("removeAFlight", false);
}

function addAnotherFlightSegment(currIndex){
      //say currIndex = 1. then, lets get all the entered data (loc & dates) and try pushing 1 down.
      //and clear the next
      //and then display the numSegmentsMultiDest+1 th segment
      var fromLoc = new Array(6) ;
      var toLoc = new Array(6) ;
      var fromStyleColor = new Array(6) ;
      var toStyleColor = new Array(6) ;
      var departDt =  new Array(6);
      var departTime =  new Array(6);
      
      for (var i=1; i<=numSegmentsMultiDest; i++){
                  fromLoc[i] = document.getElementById("fromLocation"+i).value;
                  toLoc[i] = document.getElementById("toLocation"+i).value;
                  fromStyleColor[i] = document.getElementById("fromLocation"+i).style.color;
                  toStyleColor[i] = document.getElementById("toLocation"+i).style.color;
                  departDt[i] = document.getElementById("dateairFromDate"+i).value;
                  departTime[i] = document.getElementById("fromTime"+i).value;
      }
            
      var k = currIndex +2;
      for (var j=currIndex+1 ; j<=numSegmentsMultiDest && k < 7; j++){
                  
                  document.getElementById("fromLocation"+k).value = fromLoc[j] ;
                  document.getElementById("fromLocation"+k).style.color = fromStyleColor[j] ;
                  document.getElementById("toLocation"+k).value = toLoc[j] ;
                  document.getElementById("toLocation"+k).style.color = toStyleColor[j] ;
                  document.getElementById("dateairFromDate"+k).value = departDt[j] ;
                  document.getElementById("fromTime"+k).value = departTime[j] ;
                  k++;
      }
      //reset fields to default text
      var filedsToReset = currIndex +1;
      document.getElementById("fromLocation"+filedsToReset).value = "" ;
      document.getElementById("toLocation"+filedsToReset).value = "" ;
      document.getElementById("fromTime"+filedsToReset).value = "AnyTime" ;
            
      //For dates, we need to set the just previous value (currIndex) to maintain the ascending order.
      document.getElementById("dateairFromDate"+filedsToReset).value = document.getElementById("dateairFromDate"+currIndex).value;
      
      resetLocFields(document.getElementById("fromLocation"+filedsToReset),
            document.getElementById("toLocation"+filedsToReset));

      setNumberOfSegments(++numSegmentsMultiDest);
      set_display("multiDestSegmentDisplay"+numSegmentsMultiDest, true);
      
      if(numSegmentsMultiDest <6 ){
            set_display("addAnotherFlight"+numSegmentsMultiDest, true);
      }
      set_display("removeAFlight"+numSegmentsMultiDest, true);

      if(numSegmentsMultiDest == 6){
            for(var z=1; z<=6; z++){
                  set_display("addAnotherFlight"+z, false);
            }
      }
      
}

function removeAFlight(currIndex){

      //say currIndex = 1. then, lets get all the entered data (loc & dates) and try pushing 1 up.
      //and then stop dispalying the numSegmentsMultiDest+1 th segment
      var fromLoc = new Array(6) ;
      var toLoc = new Array(6) ;
      var fromStyleColor = new Array(6) ;
      var toStyleColor = new Array(6) ;
      var departDt =  new Array(6);
      var departTime =  new Array(6);
      for (var i=1; i<=numSegmentsMultiDest; i++){
                  fromLoc[i] = document.getElementById("fromLocation"+i).value;
                  toLoc[i] = document.getElementById("toLocation"+i).value;
                  fromStyleColor[i] = document.getElementById("fromLocation"+i).style.color;
                  toStyleColor[i] = document.getElementById("toLocation"+i).style.color;
                  departDt[i] = document.getElementById("dateairFromDate"+i).value;
                  departTime[i] = document.getElementById("fromTime"+i).value;
      }
      var k = currIndex ;
      for (var j=currIndex+1 ; j<=numSegmentsMultiDest && k <=numSegmentsMultiDest ; j++){
                  
                  document.getElementById("fromLocation"+k).value = fromLoc[j] ;
                  document.getElementById("fromLocation"+k).style.color = fromStyleColor[j] ;
                  document.getElementById("toLocation"+k).value = toLoc[j] ;
                  document.getElementById("toLocation"+k).style.color = toStyleColor[j] ;
                  document.getElementById("dateairFromDate"+k).value = departDt[j] ;
                  document.getElementById("fromTime"+k).value = departTime[j] ;
                  k++
      }
      
      set_display("multiDestSegmentDisplay"+numSegmentsMultiDest, false);
      setNumberOfSegments(--numSegmentsMultiDest);
      if(numSegmentsMultiDest < 6 ){
            for(var m=1; m<=numSegmentsMultiDest; m++){
                  set_display("addAnotherFlight"+m, true);
            }
      }
      
      if(numSegmentsMultiDest == 1){
            for(var z=1; z<=6; z++){
                  set_display("removeAFlight"+z, false);
            }
      }

}

function resetFlightSearchType()
{
      var types =  document.main.flightSearchType;
    types[0].checked = true;
    types[1].checked = false;
    types[2].checked = false;
    
}
function onUpdateProducts(screenActive, nRooms, maxChildren)
{      
	return false
}


function onClickChangeCarDates(screenActive, id)
{
      if (!Browser.isFullDHTML())
      {
            if (screenActive)
                  document.forms["main"].submit()
            return
      }
      var isChecked = document.forms["main"].changeCarDates.checked
      if (isChecked)
      {
            if (screenActive)
            {
                  if (isAirIncluded())
                  {
                        sdt_copy("airFromDate", "carFromDate");
                        sdt_copy("airToDate",   "carToDate");
                  }
                  else
                  {
                        sdt_copy("hotelFromDate", "carFromDate");
                        sdt_copy("hotelToDate",   "carToDate");
                  }
            }
            set_display(id, true);
      }
      else
      {
            set_display(id, false);
      }
}

//UBP different city for hotel
function onClickDifferentCityForHotel()
{              
    var isChecked = false
    isChecked = document.forms["main"].differentCityForHotel.checked    
    document.forms["main"].differentHotelCity.value=isChecked;                     
    if(isChecked)
    {              
           set_display("differentCityForHotelDisplay", true)                    
    }
    else
    {
          set_display("differentCityForHotelDisplay", isChecked)                        
    }
    setDivHeight('cpsearch_center','intc_frameworkcenter');
}


function onClickChangeHotelDates(screenActive, id)
{
      if (!Browser.isFullDHTML())
      {
            if (screenActive)
                  document.forms["main"].submit()
            return
      }
      var isChecked = false      
      if(displayHotelDiffDatesOption())
      {
            isChecked = document.forms["main"].changeHotelDates.checked
            if (isChecked && isAirIncluded() && screenActive)
            {            
                  sdt_copy("airFromDate", "hotelFromDate")
                  sdt_copy("airToDate",   "hotelToDate")
                  set_display(id, true);
            }
            else
            {             
                  set_display(id, false);
            }
            
            
      }
}

function isAirIncluded()
{
      return isProductIncluded("A");
}

function isHotelIncluded()
{
      return isProductIncluded("H");
}

function isCarIncluded()
{
      return isProductIncluded("C");
}

function isHotelOnlyIncluded()
{
      return isHotelIncluded() && !(isAirIncluded() ||isCarIncluded());
}

function isASIncluded()
{
      return isProductIncluded("S");
}

function isAirOnlyIncluded()
{
      return isAirIncluded() && !(isHotelIncluded() ||isCarIncluded());
}
function isCarOnlyIncluded()
{
      return isCarIncluded() && !(isAirIncluded() || isHotelIncluded());
}


function onAirOnlySearchValidate(prefix,
                                 maxChildren,
                                 maxPassengers)
{
      var form = document.main
      nRooms      = 1
      form.rooms.selectedIndex = nRooms-1
      
      MAX_CHILDREN   = eval(maxChildren)

      var adultsObject = eval("document.main."+prefix+"adults"+nRooms)
      var minorsObject = eval("document.main."+prefix+"minors"+nRooms)
      
      nAdults     = eval(adultsObject.options[adultsObject.selectedIndex].value)
      nChildren = eval(minorsObject.options[minorsObject.selectedIndex].value)
      if(nAdults+nChildren > maxPassengers)
      {
            alert(msg_0988(maxTravellers))
            set_display("adultList1", true)
            set_display("adultList2", false)
            set_display("minorList1", true)
            set_display("minorList2", false)
            adultsObject.selectedIndex = 0;
            minorsObject.selectedIndex = 0;
            updateMinors(eval(maxChildren))
            return false
      }
      else
      {
            updateMinors(eval(maxChildren))
            return true
      }
}

function onChangePassengersOrRooms(caller,
                                                   prefix,
                                                   maxChildren,
                                                   maxPassengers,
                                                   maxChildrenAC,
                                                   maxPassengersAC,
                                                   screenActive)
{
      var form = document.main
      var ADULTS = 'ADULTS'
      var ROOMS  = 'ROOMS'
      var isAC = isProductIncluded("AC"); 
      nRooms      = 1
      if (form.rooms != null)
            nRooms = eval(form.rooms.options[form.rooms.selectedIndex].value)
            
      MAX_PASSENGERS = eval(maxPassengers)
      if(nRooms != 1)
		  MAX_PASSENGERS = MAX_PASSENGERS * nRooms
      
      if(isAC || isCarOnlyIncluded() || isASIncluded() || isAirOnlyIncluded())
      {
            nRooms      = 1
            MAX_CHILDREN   = eval(maxChildrenAC)
            maxChildren = maxChildrenAC;
            if(isAirOnlyIncluded()){
                  MAX_PASSENGERS = getMaxAdultsCountAirOnly();
                  maxPassengers = getMaxAdultsCountAirOnly();
            } else {
                  MAX_PASSENGERS = eval(maxPassengersAC)
                  maxPassengers = maxPassengersAC;
            }
      }

      var adultsObject = eval("document.main." + prefix + "adults" + nRooms)
      
      nAdults     = eval(adultsObject.options[adultsObject.selectedIndex].value)
     
      if(( caller == ROOMS) && nRooms == 2)
      {     
            MAX_PASSENGERS = eval(maxPassengersAC)
            set_display("adultList1", false)
            set_display("adultList2", true)
            set_display("minorList1", false)
            set_display("minorList2", true)
            if(nAdults == 1)
			{
				adultsObject.selectedIndex = 1						
			}
      }
      
      if(( caller == ROOMS) && nRooms == 1)
      {     
            set_display("adultList1", true)
            set_display("adultList2", false)
      }
      
      // No more than 'Max travelers' allowed
      if (isCarOnlyIncluded() || isASIncluded() || isAirOnlyIncluded())
      {
         if(isAirOnlyIncluded()){
                  maxTravellers = MAX_PASSENGERS; 
         } else {
                  maxTravellers = MAX_PASSENGERS - 2; 
            }
            //TODO:change the condition to nAdults+nChildren > MAX_PASSENGERS 
          //when minors functionality is added for UBP
            if(nAdults  > maxTravellers)
            {
                  alert(msg_0988(maxTravellers))
                  adultsObject.selectedIndex = 0;
                  minorsObject.selectedIndex = 0;
            }
      }
      //TODO:change the condition to nAdults+nChildren > MAX_PASSENGERS 
      //when minors functionality is added for UBP
      if (!(isCarOnlyIncluded() || isASIncluded() || isAirOnlyIncluded()) && (nAdults > MAX_PASSENGERS))
      {
            if(nRooms == 1)
                  room = 'room';

            if(nRooms == 2)
                  room = 'rooms'; 
            
            if(isAC)  
            {
                  alert(msg_0988(MAX_PASSENGERS))
            }
            else
            {
                  alert(msg_0283(MAX_PASSENGERS, nRooms, room))
            }
            adultsObject.selectedIndex = 0;
      }
      
      else
      {
            // Room count: check even if hotel is not included.
            // But, display messages only in cases where it is
            // included.
            var maxRooms = Math.min(nAdults, 4)

                  // Min rooms = 1 or 2 (depends on # of travelers: if more than 5, 2 rooms , else 1 room)
                  var minRooms = (nAdults)/4 > 1 ? 2 : 1;

                  // 1 exception: 5 all adult travelers can't stay in 1 room
                  if (nAdults == 5)
                        minRooms = 2;

                  if (nRooms < minRooms)
                  {
                        if (isHotelIncluded())
                        {
                              alert(msg_0293())
                              form.rooms.selectedIndex = minRooms-1;
                        }
                  }
      }
}

//Property Search
function onChangePropertySearchPassengersOrRooms(caller,
                                                   prefix,
                                                   maxChildren,
                                                   maxPassengers,
                                                   maxChildrenAC,
                                                   maxPassengersAC,
                                                   screenActive)
{
      var form = document.main
      var ADULTS = 'ADULTS'
      var MINORS = 'MINORS'
      var ROOMS  = 'ROOMS'    
      nRooms      = 1
      if (form.rooms != null)
            nRooms = eval(form.rooms.options[form.rooms.selectedIndex].value)
            
      MAX_CHILDREN   = eval(maxChildren)
      MAX_PASSENGERS = eval(maxPassengers)
      
      if((caller == MINORS || caller == ROOMS) && nRooms == 2)
      {     
            MAX_CHILDREN   = eval(maxChildrenAC)
            MAX_PASSENGERS = eval(maxPassengersAC)
            set_display("adultList1", false)
            set_display("adultList2", true)
            set_display("minorList1", false)
            set_display("minorList2", true)
      }
      
      if((caller == MINORS || caller == ROOMS) && nRooms == 1)
      {     
            set_display("adultList1", true)
            set_display("adultList2", false)
            set_display("minorList1", true)
            set_display("minorList2", false)
      }
      
      var adultsObject = eval("document.main."+prefix+"adults"+nRooms)
      var minorsObject = eval("document.main."+prefix+"minors"+nRooms)
      
      nAdults     = eval(adultsObject.options[adultsObject.selectedIndex].value)
      nChildren   = eval(minorsObject.options[minorsObject.selectedIndex].value)
      
      
      if (isHotelIncluded() &&
            nAdults == 1 &&
            nChildren > MAX_CHILDREN)
      {
            // If 1 adult, no more than 'MAX_CHILDREN' children allowed
            
            alert(msg_0291())

            if (caller == ADULTS)
                  adultsObject.selectedIndex = 0;
            else if (caller == MINORS)
                  minorsObject.selectedIndex = MAX_CHILDREN;
      
      }
      else
      {
            // Room count: check even if hotel is not included.
            // But, display messages only in cases where it is
            // included.
            var maxRooms = Math.min(nAdults, 4)

                  // Min rooms = 1 or 2 (depends on # of travelers: if more than 5, 2 rooms , else 1 room)
                  var minRooms = (nAdults + nChildren)/4 > 1 ? 2 : 1;

                  // 1 exception: 5 all adult travelers can't stay in 1 room
                  if (nAdults == 5 && nChildren == 0)
                        minRooms = 2;

                  if (nRooms < minRooms)
                  {
                        if (isHotelIncluded())
                        {
                              alert(msg_0293())
                              form.rooms.selectedIndex = minRooms-1;
                        }
                  }
      }
      updateMinors(eval(maxChildrenAC))
}


function updateRooms(screenActive)
{
      var form         = document.main

      if (!Browser.isFullDHTML())
      {
            if (screenActive)
                  form.submit()  // server-side handling where js doesn't work
            return false
      }

      nRooms = 1
      if (form.rooms != null)
            nRooms = eval(form.rooms.options[form.rooms.selectedIndex].value)

      for (var i=2; i<=4; i++)
      {
            set_display("displayRoom"+i, nRooms >= i)
      }

      return true
}


function updateMinors(maxChildren)
{
      var MAX_CHILDREN = eval(maxChildren)
      var form         = document.main
      
      if (form.rooms != null)
                  nRooms = eval(form.rooms.options[form.rooms.selectedIndex].value)
      
      if(!isHotelIncluded())
         nRooms = 1;
         
      if (Browser.isFullDHTML())
      {
            for (var i=1; i<=MAX_CHILDREN; i++)
            {
                  
                  var minorElement = document.getElementById("minor"+i)
                  var ageList      = document.getElementById("childAge"+i)
                  var minorsElement = document.getElementById("minors"+nRooms)
                  
                  if (minorElement)
                  {
                        set_display("minor"+i, minorsElement.options[minorsElement.selectedIndex].value >= i)
                        if (i==1)
                        {
                              set_display("minorlbl", minorsElement.options[minorsElement.selectedIndex].value >= i)
                              set_display("minornote", minorsElement.options[minorsElement.selectedIndex].value >= i)
                        }
                        if (minorsElement.options[minorsElement.selectedIndex].value < i)
                              ageList.selectedIndex=0
                  }
            }
            return true
      }
}

function validateChildAges()
{
   
      var form = document.main      
      if (form.rooms != null)
            nRooms = eval(form.rooms.options[form.rooms.selectedIndex].value)       
      if(!isHotelIncluded())        
         nRooms = 1;
      if(isCarOnlyIncluded()){         
            //Reset the minors count and ages
            var minorsElement = document.getElementById("minors"+nRooms);
            for (var i=1; i<=minorsElement.options[minorsElement.selectedIndex].value; i++)
            {
                  document.getElementById("childAge"+i).value = -1;
            }
            minorsElement.value = 0;
      
      } else {
            var minorsElement = document.getElementById("minors"+nRooms)
            for (var i=1; i<=minorsElement.options[minorsElement.selectedIndex].value; i++)
            {
                  if (eval("document.main.childAge"+i).selectedIndex == 0)
                        return false
            }
      }
      return true
}

function validateSearchParms(OPT_MaxMinorsTwoRooms, OPT_MaxPassengers)
{
      var res = true
      if (!validateChildAges())
      {
            alert(msg_0294())
            res = false
      }
      if(isAirOnlyIncluded())
      {
            if (!onAirOnlySearchValidate('',  OPT_MaxMinorsTwoRooms, OPT_MaxPassengers))
            {
                  res = false
            }
            //for air only, if there are only one segment in the multi dest search form,
          // the search type has to be set to "OneWay"
          var types =  document.main.flightSearchType;
          if(numSegmentsMultiDest == 1 && types[2].checked ){
                  types[1].checked =  true;
          }             
      }
      return res
}


function checkNumOfPassengers(num,
                                            maxChildren,
                                            maxPassengers)
{
      var form = document.forms["main"]
      nRooms = eval(form.rooms.options[form.rooms.selectedIndex].value)
      var sum             = form.adults.options[form.adults.selectedIndex].value;
      var numOfChildren   = 0;
      var MAX_CHILDREN    = eval(maxChildren)
      var MAX_PASSENGERS  = eval(maxPassengers)

      if (MAX_CHILDREN > 0 &&
            form.childAge1.options[form.childAge1.selectedIndex].value > 0)
      {
            sum++;numOfChildren++;
      }

      if (MAX_CHILDREN > 1 &&
            form.childAge2.options[form.childAge2.selectedIndex].value > 0)
      {
            sum++;numOfChildren++;
      }

      if (MAX_CHILDREN > 2 &&
            form.childAge3.options[form.childAge3.selectedIndex].value > 0)
      {
            sum++;numOfChildren++;
      }

      if (MAX_CHILDREN > 3 &&
            form.childAge4.options[form.childAge4.selectedIndex].value > 0)
      {
            sum++;numOfChildren++;
      }

      if (sum > MAX_PASSENGERS)
      {
            if(nRooms == 1)
                  room = 'room';

            if(nRooms == 2)
                  room = 'rooms'; 
            
            alert(msg_0283(MAX_PASSENGERS, nRooms, room))
            
            changeBack(form, num, numOfChildren, maxChildren);
      }
}

function changeBack(form,
                              num,
                              numOfChildren,
                              maxChildren)
{
      var MAX_CHILDREN = eval(maxChildren)

      switch (num)
      {
            case 0:
            {
                  form.adults.selectedIndex = (MAX_CHILDREN - numOfChildren) ;
                  break;
            }
            case 1:
            {
                  form.childAge1.selectedIndex = 0;
                  break;
            }
            case 2:
            {
                  form.childAge2.selectedIndex = 0;
                  break;
            }
            case 3:
            {
                  form.childAge3.selectedIndex = 0;
                  break;
            }
            case 4:
            {
                  form.childAge4.selectedIndex = 0;
                  break;
            }
      }
}

//UBP start:Modified existing methods since the minors section is not added as
// part of UBP changes.
function validateSearchParmsUBP(OPT_MaxPassengers)
{
   res = true;
      if(isAirOnlyIncluded())
      {
            if (!onAirOnlySearchValidateUBP('', OPT_MaxPassengers))
            {
                  res = false
            }
            //for air only, if there are only one segment in the multi dest search form,
          // the search type has to be set to "OneWay"
          var types =  document.main.flightSearchType;
          if(numSegmentsMultiDest == 1 && types[2].checked ){
                  types[1].checked =  true;
          }             
      }
      return res
}

function onAirOnlySearchValidateUBP(prefix, maxPassengers)
{
      var form = document.main
      nRooms      = 1
      form.rooms.selectedIndex = nRooms-1
      

      var adultsObject = eval("document.main."+prefix+"adults"+nRooms)
      
      nAdults     = eval(adultsObject.options[adultsObject.selectedIndex].value)
      if(nAdults> maxPassengers)
      {
            alert(msg_0988(maxTravellers))
            set_display("adultList1", true)
            set_display("adultList2", false)
            adultsObject.selectedIndex = 0;
            return false
      }
      else
      {
            return true
      }
}

function validateCrossSellSearchParmsUBP(OPT_MaxPassengers)
{
      var res = true
      isCrossSellSearch('AH');
      if (!onCrossSellAHUBP('', OPT_MaxPassengers))
      {
            res = false
      }
      return res
}

function onCrossSellAHUBP(prefix,                              
                                 maxPassengers)
{
      var form = document.main
            
      nRooms      = 1
      MAX_CHILDREN   = eval(maxChildren)
      MAX_PASSENGERS = eval(maxPassengers)

      var adultsObject = eval("document.main."+prefix+"adults"+nRooms)
      
      nAdults     = eval(adultsObject.options[adultsObject.selectedIndex].value)
      if(nAdults> maxPassengers)
      {
            alert(msg_0988(maxPassengers))
            set_display("adultList1", true)
            set_display("adultList2", false)
            adultsObject.selectedIndex = 0;
            isCrossSellSearch('A')
            return false
      }
      else if(nAdults+nChildren <= 4)
      {
            set_display("adultList1", true)
            set_display("adultList2", false)
            var adults2Object = eval("document.main."+prefix+"adults"+2)
            adults2Object.selectedIndex = 0
            minors2Object.selectedIndex = 0
            form.rooms.selectedIndex = nRooms-1
            return true
      }
      else if(nAdultn > 4)
      {
            nRooms = 2;
            set_display("adultList1", false)
            set_display("adultList2", true)
            var adults2Object = eval("document.main."+prefix+"adults"+nRooms)
            <!-- Adults2List starts with min of 2 adults so subtract the number of adults by 2 to set the adults2list-->
            adults2Object.selectedIndex = nAdults - 2
            form.rooms.selectedIndex = nRooms-1
            adultsObject.selectedIndex = 0
            return true
      }
}

function advanceSearchOptions(id, textElement, prodType, textValue)
	          {
				if (document.getElementById(id))
				 {
				    obj = document.getElementById(id);
				    if (obj.style.display == "block")
				     {
				        obj.style.display = "none";
				        document.forms['main'].mode.value='quick';
						text = '<img border="0" title="" alt="" src="/caux/images/UBP/Expand.png"> <span class="masterfont link h5">'+textValue+'</span>';				         
				        if(prodType == 'H'){
							
							document.getElementById('additionalHotelOptions').innerHTML = ''; 											
							resetAdvancedHotelSection();	
						}
						if(prodType == 'C'){							
							document.getElementById('additionalCarOptions').innerHTML = ''
							resetAdvancedCarSection();	
						}
						if(prodType == 'A'){
							document.getElementById('additionalAirOptions').innerHTML = ''
							resetAdvancedAirSection();							
						}
						  	document.getElementById(textElement).innerHTML = text;
				     }
				    else 
				    { 
				        obj.style.display = "block";
				         document.forms['main'].mode.value='advanced';
				         
				          if(prodType == 'H'){
					 		text = '<img border="0" title="" alt="" src="/caux/images/UBP/Collapse.png"> <span class="masterfont link h5"> Show fewer hotel search options </span>';
					 		document.getElementById('additionalHotelOptions').innerHTML = '';
					 }
					 if(prodType == 'C'){
					 		text = '<img border="0" title="" alt="" src="/caux/images/UBP/Collapse.png"> <span class="masterfont link h5"> Show fewer car search options </span>';
					 		document.getElementById('additionalCarOptions').innerHTML = ''
					 }
					 if(prodType == 'A'){
					 		text = '<img border="0" title="" alt="" src="/caux/images/UBP/Collapse.png"> <span class="masterfont link h5"> Show fewer flight search options </span>';
					 		document.getElementById('additionalAirOptions').innerHTML = ''
					 }
					 document.getElementById(textElement).innerHTML = text;
				         
		                    }		    
			   	 }
		}
			  
// Product options JS
function resetAdvancedCarSection()
{
	if(document.forms["main"].elements["carClass"]){
		document.forms["main"].elements["carClass"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["carBrand1"]){
		document.forms["main"].elements["carBrand1"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["carBrand2"]){
		document.forms["main"].elements["carBrand2"].selectedIndex = 0;
	}	
	if(document.forms["main"].elements["carBrand3"]){
		document.forms["main"].elements["carBrand3"].selectedIndex = 0;
	}	
}

function resetAdvancedHotelSection()
{
	if(document.forms["main"].elements["specificHotelName"]){
		document.forms["main"].elements["specificHotelName"].value = "";
	}
	if(document.forms["main"].elements["hotelratings"]){
		document.forms["main"].elements["hotelratings"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["hotelBrand1"]){
		document.forms["main"].elements["hotelBrand1"].selectedIndex = 0;
	}	
	if(document.forms["main"].elements["hotelBrand2"]){
		document.forms["main"].elements["hotelBrand2"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["hotelBrand3"]){
		document.forms["main"].elements["hotelBrand3"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["hotelAmenity1"]){
		document.forms["main"].elements["hotelAmenity1"].selectedIndex = 0;
	}	
	if(document.forms["main"].elements["hotelAmenity2"]){
		document.forms["main"].elements["hotelAmenity2"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["hotelAmenity3"]){
		document.forms["main"].elements["hotelAmenity3"].selectedIndex = 0;
	}
	
}

function resetAdvancedAirSection()
{
	if(document.forms["main"].elements["flightBrand1"]){
		document.forms["main"].elements["flightBrand1"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["flightBrand2"]){
		document.forms["main"].elements["flightBrand2"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["flightBrand3"]){
		document.forms["main"].elements["flightBrand3"].selectedIndex = 0;
	}	
	if(document.forms["main"].elements["alliances"]){
		document.forms["main"].elements["alliances"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["airClass"]){
		document.forms["main"].elements["airClass"].selectedIndex = 0;
	}
	if(document.forms["main"].elements["refundableFaresOnly"]){
		document.forms["main"].elements["refundableFaresOnly"].checked = false;
	}
}


function boldProductOption(id) 
{
	if(document.getElementById('product_A')){
		document.getElementById('product_A').style.fontWeight = 'normal';
	}
	if(document.getElementById('product_H')){
		document.getElementById('product_H').style.fontWeight = 'normal';
	}
	if(document.getElementById('product_C')){
		document.getElementById('product_C').style.fontWeight = 'normal';
	}
	if(document.getElementById('product_AH')){
		document.getElementById('product_AH').style.fontWeight = 'normal';
	}
	if(document.getElementById('product_AC')){
		document.getElementById('product_AC').style.fontWeight = 'normal';
	}
	if(document.getElementById('product_HC')){
		document.getElementById('product_HC').style.fontWeight = 'normal';
	}
	if(document.getElementById('product_AHC')){
		document.getElementById('product_AHC').style.fontWeight = 'normal';
	}	
	document.getElementById(id).style.fontWeight = 'bold';
}
function cleardifferentCityForHotel(id, defaultLocation) {
      var isChecked = false      
      isChecked = document.forms["main"].differentCityForHotel.checked
      if (isChecked)
      { 
         var  hotelLocation = document.getElementById('hotelLocation');
         if(hotelLocation.value != defaultLocation) {
             hotelLocation.value = '';
          } 
      }
      else
      {    
           document.getElementById('hotelLocation').value = defaultLocation;
           document.getElementById('hotelLocation').style.color = 'Darkgray';
      }
}	
// To handle AH search for RoundTrip
function copyLocationAndDateForAH()
{
	copyValuesForAH("fromLocation1", "fromLocation");
	copyValuesForAH("toLocation1", "toLocation");
	copyValuesForAH("dateairToDate1", "dateairToDate");
	copyValuesForAH("dateairFromDate1", "dateairFromDate");
}
function copyValuesForAH(from, toAH)
{
	document.getElementById(toAH).value = document.getElementById(from).value;
}


