var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
var mac = (navigator.userAgent.indexOf("Mac") != -1);
var moz = (navigator.userAgent.indexOf("Netscape") == -1);
var popupWin = '';
var currentDateObj;

function getElemName(elemname) {
  return document.getElementsByName(elemname)
}

function Popup(popURL,popW,popH,attr){
  if (!popH) { popH = 350 }
  if (!popW) { popW = 600 }
  var winLeft = (screen.width-popW)/2;
  var winTop = (screen.height-popH-30)/2;
  var winProp='width='+popW+',height='+popH+',left='+parseInt(winLeft)+',top='+winTop+','+attr;
  if (parent.window.name == "popupWindow")
  {
    windowName = "popupWindow1";
  }
  else
  {
    windowName = "popupWindow";
  }
  popupWin=window.open('/fcao/blank.html',windowName,"\'"+winProp+"\'");
  popupWin.close()
  popupWin=window.open(popURL,windowName,winProp)
  popupWin.window.focus()
}

function pagecall(url1,params,bkmark) {
  newurl =  url1 + '?p=' + popup
  if (params) { if (params != '') { newurl += '&' + params } }
  if (bkmark) { if (bkmark != '') { newurl += '#' + bkmark } }
  document.location.href = newurl
}

function FormFocus() {
  document.forms[0].elements[0].focus()
}

function ButtonPressed(thisbutton) {
  colr1px = 'solid #444477 1px';
  colr2px = 'solid #444477 2px';
  thisbutton.style.borderRight = colr1px;
  thisbutton.style.borderBottom = colr1px;
  thisbutton.style.borderTop = colr2px;
  thisbutton.style.borderLeft= colr2px;
  thisbutton.style.color = '#77bBd6'
}

function PopupCheck(urlforward) {
  if ((window.opener) && (window.name == 'popupWindow')) {
    window.opener.location.href = urlforward
    window.close()
  }
}

function AlertErrorsWarnings() {
  if ($('errorwarnings')) {
    alert($('errorwarnings').innerHTML)
  }
}
// Checks for Maximum party size and no. of adults >= no. of infants
function generateDeepLinkURL()
{
  if (validateSearchCriteriaForm())
  {
    document.searchForm.target="urlFrame";
    document.searchForm.submit();
  }
}

var tmpIndex = new Array();
//Function to find unique elements in an array
function unique(a)
{
  tmp = new Array(0);
  for(i=0;i<a.length;i++)
  {
    if(!contains(tmp, a[i]))
    {
      tmp.length+=1;
      tmp[tmp.length-1]=a[i];
      tmpIndex.length+=1;
      tmpIndex[tmpIndex.length-1]=i;
    }
  }
  return tmp;
}

//Helper function of unique() which finds unique elements in an array
function contains(a, e)
{
  for(j=0;j<a.length;j++)
  if(a[j]==e)return true;
  return false;
}

function addOnload(fn) {
  if (window.addEventListener) {
    window.addEventListener('load', fn, false)
  } else {
    window.attachEvent('onload', fn);
  }
}

/** Function to display the next page **/
function forwardToNextPage( pageName )
{
  var pageUrl = document.location.href;
  var queryString = pageUrl.substring( pageUrl.indexOf('?'), pageUrl.length )
  if ( pageName == "search" )
  {
    document.location.replace( "/accom/page/search/searchresults.page" + queryString );
  }
  else if ( pageName == "options" )
  {
    document.location.replace( "/accom/page/booking/traveloptions.page" );
  }
  else if ( pageName == "confirm" )
  {
    document.location.replace( "/accom/page/booking/bookingconfirmation.page" );
  }
}

/* Functionality added to check whether cookies are enabled in the browser (Bug# 28729) */
function checkCookieState()
{
  var cookieEnabled = (navigator.cookieEnabled) ? true : false;
  if(!cookieEnabled)
  {
    alert("Cookies need to be enabled in order to process your request.");
    return false;
  }
  else
    return true;
}

// Checks for Maximum party size and no. of adults >= no. of infants
function validateSearchCriteria()
{
  if (checkCookieState())
  {
    if (validateSearchCriteriaForm())
    {
      document.searchForm.target="_top";
      document.searchForm.submit();
      interstitialAO();
    }
  }
}

function gotoResultsPage()
{
  setTimeout("nowgotoResultsPage();", 2000);
}

function nowgotoResultsPage()
{
  url='/accom/page/search/searchresults.page';
  document.location.replace(url);
}

function gotoTravelOptions(url,accomId,resultIndex)
{
  url=url+''+accomId+'&resultIndex='+resultIndex+'&videoSelected='+$('videoSelected_'+accomId).value+'&imagesSelected='+$('imagesSelected_'+accomId).value
  document.location.href = url;
}

function gotoConfirmationPage()
{
  setTimeout("nowgotoConfirmationPage();", 2000);
}

function nowgotoConfirmationPage()
{
  var url="/accom/page/booking/bookingconfirmation.page";
  document.location.replace(url);
}

function validateSearchCriteriaForm()
{
  /*
  The below piece of code has to be removed once the
  search panel retaining issues is coded.
  */
  var resortcodes = $("resortAccomCode").options[$("resortAccomCode").selectedIndex].value
  var countrycodes = $("countryDestCode").options[$("countryDestCode").selectedIndex].value
  var codeArray  = countrycodes.split("|");
  var codeArray1  = resortcodes.split("|");
  if (codeArray[0])
  {
    $("countryCode").value = codeArray[0];
  }
  if (codeArray[1])
  {
    $("destinationCode").value = codeArray[1];
  } else {
    if (countrycodes.indexOf('|')==-1 && codeArray[0])
    {
      $("destinationCode").value = codeArray[0];
    }
  }

  if (codeArray1[0])
  {
    $("resortCode").value = codeArray1[0];
  }
  if (codeArray1[1])
  {
    $("accommodationCode").value = codeArray1[1];
  }
  /*
  End of code to be removed.
  */

  var roomConfig = populateRoomConfigArray();
  var totalPartySize = 0;
  var totalAdultPartySize = 0;
  var totalInfantSize = 0;
  currentDateObj=new Date(currentDate);
  FieldObjDay1 = $('calendar_day')
  FieldObjMonthYear1 = $('calendar_month_year')

  var arrDateSplit = FieldObjMonthYear1.value.split('/')
  dateVar = arrDateSplit[0] + "/" + FieldObjDay1.options[FieldObjDay1.selectedIndex].value + "/" + arrDateSplit[1];
  var checkinDay=new Date(dateVar);
  for(var i=0;i<roomConfig.length;i++)
  {
    var room = roomConfig[i];
    totalPartySize +=  parseInt(room.numAdults) + parseInt(room.numChildren) + parseInt(room.numInfants);
    totalAdultPartySize += parseInt(room.numAdults);
    totalInfantSize += parseInt(room.numInfants);
    for(var j=0;j<=room.childAges.length;j++)
    {
      if (room.childAges[j]>=16)
      {
        totalAdultPartySize++;
      }
      if (room.childAges[j]== 0)
      {
        alert(enterallchildages);
        $('scuWhoChildAgeSelect'+(i+1)+''+(j+1)).focus();
        return false;
      }
    }
  }

  if (totalPartySize-totalInfantSize > maxPartySize)
  {
   alert(replaceVariableInMessage(invalidPartySize, 'maxPartySize', maxPartySize));
   if ($('scuWhoAdultsSelect1'))
    $('scuWhoAdultsSelect1').focus();
  }
  else if (totalInfantSize > totalAdultPartySize)
  {
   alert(tooManyInfants);
   if ($('scuWhoAdultsSelect1'))
    $('scuWhoAdultsSelect1').focus();
  }
  else if($("countryCode").value == "" && $("destinationCode").value == "")
  {
   if ($("radio_city") && $("radio_city").checked) alert(noCountrySelected)
   else alert(noDestinationSelected);
   $("countryDestCode").focus();
  }
  else if((( $("radio_city") && $("radio_city").checked) ||
    (( $("resortAccomCode") &&(($("resortAccomCode").disabled)!=true))&& ($('subtype') && $('subtype').value=='CITY|2')))
       && $("resortCode").value=="" )
  {
   alert("Please select a city");
   if (!$("resortAccomCode").disabled)
    $("resortAccomCode").focus();
  }
  else if(checkinDay.before(new Date(),6))
  {
   alert("Please select a date on or after "+currentDateObj.getDate()+"/"+(currentDateObj.getMonth()+1)+"/"+currentDateObj.getFullYear());
   resetCheckInDate(currentDate);
  }
  else if(checkinDay.after(new Date(maxSeasonDate),6))
  {
   alert(dateAfterMax)
   $('calendar_day').focus();
  }
  else
  {
   if ($("countryDestCode").selectedIndex > '0')
   {
    clearPredictivePanels()
   }
   $("resortAccomCode").disabled = false;
   constructRoomConfigurationString(roomConfig);
   $('destinationCode').disabled=false;
   return true;
  }
}

function validateReSearchCriteria()
{
  /*
  The below piece of code has to be removed once the
  search panel retaining issues is coded.
  */
  var resortcodes = $("resortAccomCode").options[$("resortAccomCode").selectedIndex].value
  var countrycodes = $("countryDestCode").options[$("countryDestCode").selectedIndex].value
  var codeArray  = countrycodes.split("|");
  var codeArray1  = resortcodes.split("|");
  if (codeArray[0])
  {
   $("countryCode").value = codeArray[0];
  }
  if (codeArray[1])
  {
   $("destinationCode").value = codeArray[1];
  }

  if (codeArray1[0])
  {
   $("resortCode").value = codeArray1[0];
  }
  if (codeArray1[1])
  {
   $("accommodationCode").value = codeArray1[1];
  }
  /*
  End of code to be removed.
  */

  FieldObjDay1 = $('calendar_day')
  FieldObjMonthYear1 = $('calendar_month_year')
  currentDateObj=new Date(currentDate);
  var arrDateSplit = FieldObjMonthYear1.value.split('/')
  dateVar = arrDateSplit[0] + "/" + FieldObjDay1.options[FieldObjDay1.selectedIndex].value + "/" + arrDateSplit[1];
  var checkinDay=new Date(dateVar);
  if($("countryCode").value == "" && $("destinationCode").value == "")
  {
   alert(noDestinationSelected);
   $("countryDestCode").focus();
  }
  else if(checkinDay.before(new Date(),6))
  {
   alert("Please select a date on or after "+currentDateObj.getDate()+"/"+(currentDateObj.getMonth()+1)+"/"+currentDateObj.getFullYear());
   resetCheckInDate(currentDate);
  }
  else if(checkinDay.after(new Date(maxSeasonDate),6))
  {
   alert(dateAfterMax)
   $('calendar_day').focus();
  }
  else if (selectedSubType=="CITY|2" && $("resortCode").value=="")
  {
   alert("Please select a city");
   $("resortAccomCode").focus();
  }
  else
  {
  if ($("countryDestCode").selectedIndex > '0')
  {
   clearPredictivePanels()
  }
   $("accommodationCode").disabled = false;
   document.searchForm.submit();
  }
}

function replaceVariableInMessage(message, variable, value)
{
  if (message.indexOf('$'+variable)>-1)
  {
    return newMessage = message.substring(0,message.indexOf('$'+variable))+value+message.substring(message.indexOf('$'+variable)+variable.length+1, message.length);
  }
}

/* GeoCode object. */
function GeoCode(lon, lat, placeName, accomId)
{
  this.lon = lon;
  this.lat = lat;
  this.placeName = placeName;
  this.accomId = accomId;
}
function showMapLoadingMessage()
{
  if ($("resultMapContainer")) $("resultMapContainer").innerHTML="Loading Map...";
  for(var i=1;i<=GeoCodes.length;i++)
  {
     if ($("result_"+i)) $("result_"+i).hide();
  }
}

function displayContent(elementId, fromIndex) {
  var el = $(elementId);
  if (el) {
    var content = el.firstChild;
    while (content && content.tagName != 'DIV') { content = content.nextSibling }
    if (content) {
      if (currentStyle(content, 'display') == 'block') {
        if (!fromIndex) {
      content.hide();
      el.hide();
        }
      } else {
     content.show();
     el.show();
      }
    }
  }
}
/* / Result Map */

function showError()
{
  if($('errormessage').innerHTML!='')
  {
    alert($('errormessage').innerHTML);
  }
}

function saveSelectedHotel(accomId)
{
  if($("favlink_add"+accomId)) {
    $("favlink_add"+accomId).style.display="none";
    $("favlink_remove"+accomId).style.display="";
  }
  var url = "/accom/page/search/saveselectedhotel.page?accomId=" + accomId + "&task=save";
  saveHotelIframe.document.location.replace(url);
}

function removeSelectedHotel(obj,accomId)
{
  if($("favlink_add"+accomId)) {
    $("favlink_add"+accomId).style.display="";
    $("favlink_remove"+accomId).style.display="none";
  }
  var url = "/accom/page/search/removeselectedhotel.page?ico=AOSearchRes_Remove&accomId=" + accomId + "&task=remove";
  saveHotelIframe.document.location.replace(url);
}

function removeSavedHotel(accomId, sortOption, pageNumber, savedHotelpage )
{
  if(sortOption ==""|| sortOption==null || sortOption=='null' )
    sortOption = $('sortOption');
  var url = "/accom/page/search/removeselectedhotel.page?accomId="+ accomId +"&task=remove&sortOption=" + sortOption + "&pageNumber=" + pageNumber + "&ico=AOSearchRes_DisplayHotels&fromPage=" + savedHotelpage;
  document.location.href = url;
}

function loadDetailsContent(type, accomId)
{
  listElements = $("detailsToc_"+accomId).getElementsByTagName("li");
  for(i=0;i<listElements.length;i++)
  {
   listElements[i].className = "";
  }
  innerHtml = $(type+"_"+accomId).innerHTML;
  if (innerHtml.indexOf("largeSlide_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("largeSlide_"))+"slide1_"+innerHtml.substring(innerHtml.indexOf("largeSlide_")+11,innerHtml.length);
  }
  if (innerHtml.indexOf("play_ss_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("play_ss_"))+"play_ss1_"+innerHtml.substring(innerHtml.indexOf("play_ss_")+8,innerHtml.length);
  }
  if (innerHtml.indexOf("stop_ss_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("stop_ss_"))+"stop_ss1_"+innerHtml.substring(innerHtml.indexOf("stop_ss_")+8,innerHtml.length);
  }
  if (innerHtml.indexOf("thumbMask_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("thumbMask_"))+"thumbMask1_"+innerHtml.substring(innerHtml.indexOf("thumbMask_")+10,innerHtml.length);
  }
  if (innerHtml.indexOf("thumbsContent_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("thumbsContent_"))+"thumbsContent1_"+innerHtml.substring(innerHtml.indexOf("thumbsContent_")+14,innerHtml.length);
  }
  while (innerHtml.indexOf("briefdesc_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("briefdesc_"))+"briefdesc1_"+innerHtml.substring(innerHtml.indexOf("briefdesc_")+10,innerHtml.length);
  }
  while (innerHtml.indexOf("fulldesc_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("fulldesc_"))+"fulldesc1_"+innerHtml.substring(innerHtml.indexOf("fulldesc_")+9,innerHtml.length);
  }

  while (innerHtml.indexOf("resultmap_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("resultmap_"))+"resultmap1_"+innerHtml.substring(innerHtml.indexOf("resultmap_")+10,innerHtml.length);
  }

  while (innerHtml.indexOf("google_map_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("google_map_"))+"google_map1_"+innerHtml.substring(innerHtml.indexOf("google_map_")+11,innerHtml.length);
  }

  while (innerHtml.indexOf("google_hotelsonmap_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("google_hotelsonmap_"))+"google_hotelsonmap1_"+innerHtml.substring(innerHtml.indexOf("google_hotelsonmap_")+19,innerHtml.length);
  }

  while (innerHtml.indexOf("google_checkboxes_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("google_checkboxes_"))+"google_checkboxes1_"+innerHtml.substring(innerHtml.indexOf("google_checkboxes_")+18,innerHtml.length);
  }

  while (innerHtml.indexOf("chk_")>-1)
  {
   innerHtml = innerHtml.substring(0,innerHtml.indexOf("chk_"))+"chk1_"+innerHtml.substring(innerHtml.indexOf("chk_")+4,innerHtml.length);
  }


  if (type!="morePhotosDesc"|| (type=="morePhotosDesc" && $("description_container_"+accomId).innerHTML.indexOf('View Slide Show')==-1) )
  {
   for(i=0;i<listElements.length;i++)
   {
    listElements[i].className = "";
   }

   $("description_container_"+accomId).innerHTML = innerHtml;
   $(type+"Li_"+accomId).className = "selected";

   if (type=="morePhotosDesc")
   {
    slideShow = getSlideShow(accomId);
    var imageArray = slideShow.imgArray;
    resizeImage(accomId, imageArray[0].reference);
    $("description_container_"+accomId).style.border="none";
  }

    $("description_container_"+accomId).style.border="1px solid #B5BCE0";
   if (type =="mapDesc" || type=="morePhotosDesc") $("description_container_"+accomId).style.border="none";
   }

  if (type=="datesAvailable" || type=="morePhotosDesc" || type =="mapDesc")
  {
    $("description_container_"+accomId).style.width="565px";
    $("photo_map_section_"+accomId).hide();
  }else {
    $("description_container_"+accomId).style.width="280px";
  $("photo_map_section_"+accomId).show();
  }
}

function displayHolidayDetails(accomId,count,hoteltype)
{
  eval("detailsFrame_"+accomId).location.replace("/accom/page/details/details.page?selectedResult="+accomId+"&statusCount="+count+"&hoteltype="+hoteltype);
  $("holidayDetails_"+accomId).show();
  $("btnExpandDetails_"+accomId).hide();
  $("btnCloseDetails_"+accomId).show();
  if ($("morePhotosLink_"+accomId)) $("morePhotosLink_"+accomId).hide();
  if ($("moreDateslink_"+accomId)) $("moreDateslink_"+accomId).hide();
  $("viewOnMapLink_"+accomId).style.visibility = "hidden";
  if ($("readReviewsLink_"+accomId)) $("readReviewsLink_"+accomId).hide();
}

function hideExpandedDetails(accomId)
{
  $("holidayDetails_"+accomId).hide();
  $("btnExpandDetails_"+accomId).show();
  $("btnCloseDetails_"+accomId).hide();
  if ($("morePhotosLink_"+accomId))$("morePhotosLink_"+accomId).show();
  if ($("moreDateslink_"+accomId)) $("moreDateslink_"+accomId).show();
  $("viewOnMapLink_"+accomId).style.visibility = "visible";
  if ($("readReviewsLink_"+accomId)) $("readReviewsLink_"+accomId).show();
}

function viewAccomDetails(accomUniqueId, accomId, alternateAccom)
{
  url = "/accom/page/details/detailsPopup.page?selectedResult="+accomUniqueId+"&popup=true";
  if(accomId)
    url = url + "&AccommodationId=" + accomId;
  if(alternateAccom)
    url = url + "&alternateAccom=" + alternateAccom;
  Popup(url,800,620);
}

function viewFlightItinerary()
{
  Popup("/accom/page/details/flightitinerarydetails.page",440,400,"scrollbars=yes");
}

function UpdateOnDateChange()
{
  DynamicUpdate('date','change',1);
}

function readReview(accomId)
{
  dynamicFrame.location.replace("/accom/page/details/details.page?selectedResult="+accomId+"&viewCustomerReview=true");
  $("holidayDetailWrapper_"+accomId).style.backgroundColor = "#ffffe7";
  $("holidayDetails_"+accomId).show();
  $("expandHotelsLinkImg_"+accomId).hide();
  $("expandHotelsLink_"+accomId).hide();
  if ($("morePhotosLink_"+accomId))$("morePhotosLink_"+accomId).hide();
  $("viewOnMapLink_"+accomId).style.visibility = "hidden";
  $("viewOnMapImg_"+accomId).hide();
  if ($("moreDateslink_"+accomId)) $("moreDateslink_"+accomId).hide();
  if ($("readReviewsLink_"+accomId)) $("readReviewsLink_"+accomId).hide();
}

function moreDates(accomId,markerIndex, hoteltype)
{
  if ($("moreDateslink_"+accomId)) $("moreDateslink_"+accomId).hide();
  $("viewOnMapLink_"+accomId).style.visibility = "hidden";
  $("btnExpandDetails_"+accomId).hide();
  $("btnCloseDetails_"+accomId).show();
  dynamicFrame.location.replace("/accom/page/details/details.page?selectedResult="+accomId+"&moreDates=true&hoteltype="+hoteltype+"&markerIndex="+markerIndex);
  $("holidayDetails_"+accomId).show();
}

function viewMap(accomId, markerIndex, hoteltype)
{
  if ($("moreDateslink_"+accomId)) $("moreDateslink_"+accomId).hide();
  $("viewOnMapLink_"+accomId).style.visibility = "hidden";
  $("btnExpandDetails_"+accomId).hide();
  $("btnCloseDetails_"+accomId).show();
  dynamicFrame.location.replace("/accom/page/details/details.page?selectedResult="+accomId+"&viewMapIndex="+markerIndex+"&hoteltype="+hoteltype);
  $("holidayDetails_"+accomId).show();
}


function showfullItenary(obj, index)
{
  if ( index == "0")
  {
    $("full_"+obj).show();
    $("show_"+obj).hide();
  }
  if ( index == "1")
  {
    $("show_"+obj).show();
    $("full_"+obj).hide();
  }
}

function loadAvailabilityCalendar(url, accomId)
{
  $("description_container_"+accomId).innerHTML = "Loading available dates for this holiday...";
  if (url.indexOf("?")>-1)
    dynamicFrame.document.location.replace(url+"&accomId="+accomId);
  else
    dynamicFrame.document.location.replace(url+"?accomId="+accomId);
}

function resetLocationLevel(elemId)
{
  if ($(elemId).value.indexOf("COUNTRY") > -1)
    $(elemId).selectedIndex = $(elemId).selectedIndex + 1;
  DynamicUpdate(elemId, "change");
}

function updateListWithLocations(hideId, showId, updateId)
{
  if (((hideId.indexOf("Resorts")>-1 || hideId.indexOf("Cities")>-1)&& $("destinationCode").value!="") || hideId.indexOf("Destinations")>-1)
  {
    if ($(showId)) $(showId).show();
    if ($(hideId)) $(hideId).hide();
    DynamicUpdate(updateId, 'change');
  }
}

function forwardToAltSearch()
{
  var roomConfig = populateRoomConfigArray();
  constructRoomConfigurationString(roomConfig);
  var url=alternateSearchPanelLink;
  if (url.indexOf("?")>-1)
  {
    top.location.href=url+"&"+GenerateRequest(document.searchForm);
  } else {
    top.location.href=url+"?"+GenerateRequest(document.searchForm);
  }
}

function updateFormElementFromCheckBox(checkBoxObj, formElement)
{
  if ($(formElement))
  {
    $(formElement).value = checkBoxObj.checked;
  }
}

//26164 change
function updateFormElementFromCheckBoxMarketing(checkBoxObj, formElement)
{
  if ($(formElement))
  {
    if (checkBoxObj.checked)
    {
      $(formElement).value = false;
    }
    else
    {
      $(formElement).value = true;
    }
  }
}

function thomsonplusDetails(accomId)
{
  dynamicFrame.location.replace("/accom/page/details/details.page?selectedResult="+accomId+"&thomsonplusDetails=true");
  $("holidayDetailWrapper_"+accomId).style.backgroundColor = "#ffffe7";
  $("holidayDetails_"+accomId).show();
  $("expandHotelsLinkImg_"+accomId).hide();
  $("expandHotelsLink_"+accomId).hide();
  if ($("morePhotosLink_"+accomId)) $("morePhotosLink_"+accomId).hide();
  $("viewOnMapLink_"+accomId).style.visibility = "hidden";
  $("viewOnMapImg_"+accomId).hide();
  if ($("readReviewsLink_"+accomId)) $("readReviewsLink_"+accomId).hide();
  $("moreDateslink_"+accomId).hide();
}

//Auto Completion of surnames
function autoCompletion(count)
{
  if($('autoCheck').checked)
  {
    for (i=0;i<count;i++)
    {
      if($('passengerDetailsFormBeans[0].lastName').value != null)
      {
        $('passengerDetailsFormBeans['+i+'].lastName').value = $('passengerDetailsFormBeans[0].lastName').value;
      }
    }
  }
}

function checkSurnames(count)
{
  if($('autoCheck'))
  {
    if($('autoCheck').checked)
    {
      for (i=0;i<count;i++)
      {
        if($('passengerDetailsFormBeans[0].lastName').value != $('passengerDetailsFormBeans['+i+'].lastName').value)
        {
          $('autoCheck').checked = false;
          break;
        }
      }
    }
  }
}

function populateSubtype(form)
{
  if(form.rdoSubtype[0].checked)
  {
    $("subtype").value = form.rdoSubtype[0].value;
    var subtype = form.rdoSubtype[0].value.split('|');
    $("subtypeId").value = subtype[0];
  } else {
    $("subtype").value = form.rdoSubtype[1].value;
    var subtype = form.rdoSubtype[1].value.split('|');
    $("subtypeId").value = subtype[0];
  }
}

function forwardToOtherDestinations()
{
  var roomConfig = populateRoomConfigArray();
  constructRoomConfigurationString(roomConfig);
  var url=otherDestinationsSearchPanelLink;
  if (url.indexOf("?")>-1)
    top.location.href=url+"&"+GenerateRequest(document.searchForm);
  else
    top.location.href=url+"?"+GenerateRequest(document.searchForm);
}

function viewTermsAndConditions()
{
  url = "https://www.thomsonbeach.co.uk/th/beach/viewTermsAndConditions.do?brochureId=TH01&seasonId=S2007";
  Popup(url,600,400,'scrollbars=yes,resizable=yes');
}

function displayFullDescription(reviewId)
{
  obj1 = 'fulldesc1_'+reviewId;
  obj2 = 'briefdesc1_'+reviewId;
  $(obj1).show();
  $(obj2).hide();
}

function displayShortDescription(reviewId)
{
  obj1 = 'fulldesc1_'+reviewId;
  obj2 = 'briefdesc1_'+reviewId;
  $(obj1).hide();
  $(obj2).show();
}

// show hide function for top global nav
function showHideNavPop(elemID, showHide) {
  if($(elemID)) {
    $(elemID).style.display = (showHide == 'show' ? 'block' : 'none');
  }
}

function defaultCountryDropdown()
{
  if (document.searchForm.countryCode.value==document.searchForm.destinationCode.value)
  {
    for(i=0;i<$('countryDestCode').options.length;i++)
    {
      if ($('countryDestCode').options[i].value==document.searchForm.countryCode.value)
      {
        $('countryDestCode').selectedIndex=i;
        if ($('countryDestCode').options[i+1] && $('countryDestCode').options[i+1].value.indexOf('|')>-1)
        {
          $('resortAccomCode').disabled=true;
        }
        break;
      }
    }
  }
}

/*******************************************************************************/
/* Toggle Popup function:Used currently in Insurance section under Travel Options */
/*******************************************************************************/

function toggle2Popups(layerName, action) {
  if(layerName == 'excessWaiverBreakUp' || layerName == 'newInsuranceBreakUp') {
  if($('excessWaiverBreakUp')) $('excessWaiverBreakUp').hide();
  if($('newInsuranceBreakUp')) $('newInsuranceBreakUp').hide();
  }
  if(action =='open') $(layerName).show();
  if(action=='close') $(layerName).hide();
}

function togglePopup(whichLayer) {
  var style2 = $(whichLayer).style;
  style2.display = style2.display? "":"block";
  // workaround for IE6.
  if(whichLayer == 'extraseatsOverlay' && navigator.appVersion.substr(22,3)=="6.0") {
    if(style2.display) {
      if($('mealsRequired').checked) {
        $('mealOptions').style.display = "none";
      }
    }
    else {
      if($('mealsRequired').checked) {
        $('mealOptions').style.display = "block";
      }
    }
  }
}

/*****************************************************************************************/
/* This method has been wrritten to handle Sort by Option in Flight Results Page of FCAO.*/
/*****************************************************************************************/

function sortFlights(obj)
{
  document.location.href="/accom/page/flights/sortflightresults.page?sortOption="+$(obj).value;
}

function sortHotels(obj, hoteltype, showAllResults)
{
  if(showAllResults == true)
  {
    if(hoteltype == 'searchResult')
      {
        document.location.href="/accom/page/search/searchresults.page?sortOption="+$(obj).value+"&showAllResults=true";
      }
      if(hoteltype == 'savedHotel')
      {
        document.location.href="/accom/page/search/displaysavedhotels.page?ico=AOSearchRes_DisplayHotels&sortOption="+$(obj).value+"&showAllResults=true";
      }
  }

  if(showAllResults != true)
  {
    if(hoteltype == 'searchResult')
      {
        document.location.href="/accom/page/search/searchresults.page?sortOption="+$(obj).value;
      }
      if(hoteltype == 'savedHotel')
      {
        document.location.href="/accom/page/search/displaysavedhotels.page?ico=AOSearchRes_DisplayHotels&sortOption="+$(obj).value;
      }
  }
}


function displaySavedHotels(sortOption)
{
  if(sortOption ==""|| sortOption==null || sortOption=='null' )
    sortOption = 1;
  var url = "/accom/page/search/displaysavedhotels.page?ico=AOSearchRes_DisplayHotels&sortOption=" + sortOption;
  document.location.href = url;
}

/*******************************************************************************/
/* currentStyle: checks the specified value of the specified property */
/*******************************************************************************/

function currentStyle(el, property) {
  var d = document;
  var v = null;
  if (d.defaultView && d.defaultView.getComputedStyle) {
  var style = d.defaultView.getComputedStyle(el, null);
    v = style && style.getPropertyValue(property);
  } else if (el.currentStyle) {
    v = el.currentStyle[property.toCamelCase()];
  }
  if (v == null && el.style) {
    v = el.style[property.toCamelCase()];
  }
  return v;
}

/*******************************************************************************/
/* toCamelCase: example "font-size".toCamelCase() -> "fontSize" */
/*******************************************************************************/

String.prototype.toCamelCase = function() {
  return this.replace(/-([a-z])/g, function(a, b) { return b.toUpperCase(); });
};

/*******************************************************************************/
/* Date HAndling functions copied from dynamic_location.js as it was misplaced */
/*******************************************************************************/

var Dates = {
  monthsPerYear: 12,
  hoursPerDay: 24,
  minutesPerDay: 24 * 60,
  millisPerDay: 24 * 60 * 60 * 1000,
  millisPerHour: 60 * 60 * 1000,
  millisPerMinute: 60 * 1000,
  millisPerSecond: 1000,
  days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  fromISO: function(s) {
    /* y-m-d h:m:s format (iso-8601) */
    var a = s.split(' ');
    var ymd = a[0].split('-');
    var y = +ymd[0];
    var mon = ymd.length > 1 ? +ymd[1] : 1;
    var d = ymd.length > 2 ? +ymd[2] : 1;
    if (a.length == 1) {
      return new Date(y, mon - 1, d);
    } else {
      var hms = a[1].split(':');
      var h = +hms[0];
      var min = hms.length > 1 ? +hms[1] : 0;
      var sec = hms.length > 2 ? +hms[2] : 0;
      return new Date(y, mon - 1, d, h, min, sec);
    }
  },
  fromSlashed: function(s) {
  /* d/m/y format */
  var a = s.split('/');
  var y = +a[2];
  var m = +a[1];
  var d = +a[0];
  return (a.length == 3) ? new Date(y < 1900 ? y + 1900 : y, m - 1, d) : null;
  },
  date: function(o) {
  var date = null;
  if (o instanceof Date) { date = o }
  else if (typeof o == 'number') { date = new Date(o) }
  else if (typeof o == 'string') {
    if (o.indexOf('/') > 0) {
      date = this.fromSlashed(o);
    } else {
      date = this.fromISO(o);
    }
  }
  return date;
  },
  ord: function(date, precision) {
  date = this.date(date);
  precision = precision || 3;
  var tz = date.getTimezoneOffset() * this.millisPerMinute;
    switch (precision) {
      case 1: return date.getFullYear();
      case 2: return date.getFullYear() * this.monthsPerYear + date.getMonth();
      case 3: return Math.floor((date.getTime() - tz) / this.millisPerDay);;
      case 4: return Math.floor((date.getTime() - tz) / this.millisPerHour);
      case 5: return Math.floor((date.getTime() - tz) / this.millisPerMinute);
      case 6: return Math.floor((date.getTime() - tz) / this.millisPerSecond);
      default: return date.getTime();
    }
  },
  diff: function(from, to, precision) {
   return this.ord(to, precision) - this.ord(from, precision);
  },
  millis: function(o) {
   return this.date(o).getTime();
  },
  day: function(o) {
   return this.ord(o);
  },
  dayName: function(o, length) {
   return this.days[this.date(o).getDay()].substr(0, length || 3);
  },
  monthName: function(o, length) {
   return this.months[this.date(o).getMonth()].substr(0, length || 3);
  },
  monthStart: function(date) {
   date = this.date(date);
   return new Date(date.getFullYear(), date.getMonth(), 1);
  },
  monthEnd: function(date) {
   date = this.date(date);
   return new Date(date.getFullYear(), date.getMonth() + 1, 0);
  },
  iso: function(date, fields) {
   function nn(n) {
    return (n < 0 || n > 9) ? String(n) : '0' + String(n);
   }
   fields = fields || 3;
   date = this.date(date);
   var s = nn(date.getFullYear());
   if (--fields > 0) s += '-' + nn(date.getMonth() + 1);
   if (--fields > 0) s += '-' + nn(date.getDate());
   if (--fields > 0) s += ' ' + nn(date.getHours());
   if (--fields > 0) s += ':' + nn(date.getMinutes());
   if (--fields > 0) s += ':' + nn(date.getSeconds());
   return s;
  },
  inRange: function(date, start, end) {
   return this.day(date) < this.day(start) ? -1 :
   this.day(date) > this.day(end) ? 1 :
   0;
  }
};

Date.prototype.before = function(that, precision) { return Dates.diff(this, that, precision) > 0 }
Date.prototype.after = function(that, precision) { return Dates.diff(this, that, precision) < 0 }
Date.prototype.within = function(start, end) { return Dates.inRange(this, start, end) == 0 }
String.prototype.before = function(that, precision) { return Dates.date(String(this)).before(that, precision) }
String.prototype.after = function(that, precision) { return Dates.date(String(this)).after(that, precision) }
String.prototype.within = function(start, end) { return Dates.inRange(String(this), start, end) == 0 }


/*******************************************************************************/
/* Load listener to load multiple fns onload*/
/*******************************************************************************/

function addLoadEvent( func ){
  // if there isn't currently an onload function...
  if( typeof window.onload != "function" ){
    // ...then just set it to this one
    window.onload = func;
  } else {
    // the old onload function
    var oldOnloadFn = window.onload;
    // and make a new onload function that will call the old one, and then func
    window.onload = function() {
      if( oldOnloadFn ) {
        oldOnloadFn();
      }
      func();
    };
  }
}

/*******************************************************************************/
/* Summary Panel Positioning Functions, borrowed from FCSUN*/
/*******************************************************************************/

var scrollDiff = 0;

function init_search_results() {
  if($('summaryFloatingPanel'))
    setInterval( "summaryPanelPosition()", 100 );
}

function summaryPanelPosition(){
  var scrollOffsets = getBrowserScrollingOffsets();
  var scrollPosition = scrollOffsets.y;

  if (scrollDiff != scrollPosition){
    scrollDiff = scrollPosition;

    var titleAreaPosition = Position.cumulativeOffset( $( "TitleArea" ) );
    var topLimit = titleAreaPosition[1];

    var footerPosition = Position.cumulativeOffset( $( "Footer" ) );
    var bottomLimit = footerPosition[1];
    bottomLimit -= 18;

    var summaryPanel = $( "summaryFloatingPanel" );
    var summaryPanelHeight = Element.getHeight( summaryPanel );

    var newTopPosition = scrollPosition + 30;
    if( newTopPosition < topLimit ){
      newTopPosition = topLimit;
    }
    if( (newTopPosition + summaryPanelHeight) > bottomLimit ){
      newTopPosition = bottomLimit - summaryPanelHeight;
    }
    summaryPanel.style.top = (newTopPosition - topLimit) + "px";
    summaryPanel.style.position = "relative";
  }
}

function getBrowserScrollingOffsets(){
  var x,y;
  if (self.pageYOffset) // all except Explorer
  {
    x = self.pageXOffset;
    y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
  // Explorer 6 Strict
  {
    x = document.documentElement.scrollLeft;
    y = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
    x = document.body.scrollLeft;
    y = document.body.scrollTop;
  }
  return { x: x, y: y };
}

function popUpBookingConditions(accInv, flightInv, departureDate)
{
  var d = new Date();
  var currentDate = d.getDate();
  var currentMonth = d.getMonth();
  currentMonth++;
  currentDate = currentDate+"";
  currentMonth = currentMonth+"";
  if (currentDate.length == 1)
  {
    currentDate = "0"+currentDate;
  }

  if (currentMonth.length == 1)
  {
    currentMonth = "0"+currentMonth;
  }
  if (accInv=="ThomsonSun")
  {
    accInv="TRACS"
  }
  if (accInv =="HOPLA_THM" || accInv =="HOPLA_PEG" || accInv =="HOPLA_HOTELBEDS")
  {
    accInv="HOPLA"
  }
  if (accInv=="ThomsonCities")
  {
    accInv="ANITE"
  }
  if (flightInv=="Amadeus")
  {
    flightInv = flightInv.toUpperCase();
  }
  if (flightInv=="TRACSA")
  {
    flightInv = "TRACS";
  }
  if (flightInv=="NAV")
  {
    flightInv="NAVITARE";
  }
  var formattedDate = d.getFullYear()+"-"+currentMonth +"-"+currentDate;
  var url="/accom/page/common/tandc/tandc.page?"+"date="+formattedDate+"&"+"lang="+"en"+"&"+"depDate="+departureDate;
  if (accInv.length > 0)
  {
     url += "&accommInvSys=" + accInv;
  }
  if (flightInv.length > 0)
  {
     url += "&flightInvSys=" + flightInv;
  }
  window.open(url, "", "width=750,height=500,scrollbars=yes,resizable=yes");
}

function popUpBookingConditionsHopla(accInv, flightInv)
{
    var d = new Date();
    var currentDate = d.getDate();
    var currentMonth = d.getMonth();
    currentMonth++;
    currentDate = currentDate+"";
    currentMonth = currentMonth+"";
    if (currentDate.length == 1)
    {
        currentDate = "0"+currentDate;
    }

    if (currentMonth.length == 1)
    {
        currentMonth = "0"+currentMonth;
    }
    if (accInv=="ThomsonSun" || accInv=="ThomsonCities")
  {
    accInv="FIRST_CHOICE"
  }
  if (accInv=="FIRST_CHOICE")
  {
    accInv="FIRST_CHOICE"
  }
  if (accInv =="HOPLA_THM" || accInv =="HOPLA_PEG" || accInv =="HOPLA_HOTELBEDS")
  {
    accInv="HOPLA"
  }
  if (flightInv=="Amadeus")
  {
    flightInv = flightInv.toUpperCase();

    if (accInv =="HOPLA")
    {
      flightInv=flightInv + "_FC";
    }
  }
  if (flightInv=="TRACSA")
  {
    flightInv = "FIRST_CHOICE";
  }
  if (flightInv=="NAV")
  {
    flightInv="FIRST_CHOICE";
  }
    var formattedDate = d.getFullYear()+"-"+currentMonth +"-"+currentDate;
    var url="/accom/page/common/tandc/tandc.page?date="+formattedDate+"&"+"lang="+"en";
    if (accInv.length > 0)
    {
       url += "&accommInvSys=" + accInv;
    }
    if (flightInv.length > 0)
    {
       url += "&flightInvSys=" + flightInv;
    }
    window.open(url, "", "width=750,height=500,scrollbars=yes");
}

function setvideoSelected(accomId)
{
   if(opener!=null)
   {
     opener.$("videoSelected_"+accomId).value="true";
   }
   else if($("videoSelected_"+accomId))
   {
      $("videoSelected_"+accomId).value="true";
   }
}

function printSelectedAccom(accomId,fromWhere){
  /*
  //to check which TAB is selected
  var Li_s = $$('ul.detailsToc_'+accomId+ ', li');
  for(var i=1; i<Li_s.length; i++)
  {
  if (Li_s[i].className.indexOf('selected') != -1)
    selectedTab = Li_s[i].id;
  }
  selectedTab = selectedTab.substring(0,selectedTab.indexOf("Li"));
  */
  if (fromWhere == 'popup')
  {
    loadDetailsContent('hotelDetailsDesc',accomId);
    window.print();
  }
  else
  {
    url = "/accom/page/details/detailsPopup.page?selectedResult="+accomId+"&popup=true&print="+fromWhere;
    eval("detailsFrame_"+accomId).location.href= url;
  }
}