/***************************************************************************************************
  This JS file combines what AffiliateMasking.js, eqtr_common.js, pkgSearchPanel.js once contained
/**************************************************************************************************/
/***************************************************************************************************
  start AffiliateMasking.js
/**************************************************************************************************/
function querySt(ji) {
  hu = window.location.search.substring(1);
  gy = hu.split("&");
  for (i=0;i<gy.length;i++) {
    ft = gy[i].split("=");
    if (ft[1] == ji) {return 1;}
  }
  return 2;
}

function SetAffiliate() {
  if (querySt('aw')  == 1  &&  GetAffiliate("ThomsonAlfrescoSource") == null) {
    var ldExpDate = new Date();
    ldExpDate.setDate(ldExpDate.getDate() + 45);
    document.cookie = "ThomsonAlfrescoSource=aw; expires = " + ldExpDate.toGMTString();
  }
}

function GetAffiliate(name) {
  var start = document.cookie.indexOf(name+"=");
  var len = start+name.length+1;
  if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
  if (start == -1) return null;
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}

function showTxt(t1,t2) {
  if (GetAffiliate("ThomsonAlfrescoSource") != 'aw') {
    document.write(t1);
  } else {
    document.write(t2);
  }
}

function showNonAffiliate(t1) {
  if (GetAffiliate("ThomsonAlfrescoSource") != 'aw') {
    document.write(t1);
  }
}

function showAffiliate(t1) {
  if (GetAffiliate("ThomsonAlfrescoSource") = 'aw') {
    document.write(t1);
  }
}

SetAffiliate();
/***************************************************************************************************
  end AffiliateMasking.js
/**************************************************************************************************/


/***************************************************************************************************
  start eqtr_common.js
/**************************************************************************************************/
var ie6Below = $.browser.msie && parseFloat($.browser.version) <= 6;

$( function() {
  if ($('.specialOffersHeader p.image').length) {
    $('.specialOffersHeader p.image').css('cursor', 'pointer').click(function() {
    window.open('/freepass', '', 'menubar=no, left=340, top=282, width=400, height=200, toolbar=no, scrollbars=yes');
    });
  }

    // setup newsletter signup
    if( $(".newsletterSignUp :text").length )
    {
        setEmailSignText();
    }
    
    // setup dynamic loading of google maps for search pages
    if ($(".bookingResults .parc[coords]").length) {
        googleSearchResultsSetup();
    }
    
    // setup floorplan popup
    $(".accommodation .floorplan a").click( openFloorplanPopup );
    
  //Jscript for the FAQ's Page
    if ( $(".freqAskedQ").length) {  
  $(".showHide").wrapInner("<a></a>");
    $(".freqAskedQ .questionList,.questionList .question .answer")
        .hide();
    
    $(".freqAskedQ .showHide").each( function() {
        $(this).html('<a href="#">' + $(this).text() + '</a>');
    });
 
    $(".questionList .question span").each( function() {
        $(this).html('<a href="#">' + $(this).text() + '</a>');
    });    
       
    $(".freqAskedQ .showHide a,.questionList .question span a").click(function (){
        if( $(this).parent(".showHide").length )
            $(this).parent(".showHide").toggleClass("showHide_expand");
        
        $(this).parent().next().slideToggle();
    $(this).toggleClass("expand");
        return false;
      });
    }
      
  $(".alternativeDates").hide();
   $(".tableSlide").click(function(){
                   
   $(this).parent().next().slideToggle("slow");
   $(this).toggleClass("active"); return false;
   });
    
   $(".additionalInformation").hide();
   $("a.info").click(function(){
   $(this).parent().next().slideToggle("slow");
   $(this).toggleClass("active"); return false;
   });
   $(".fullArticle").hide();
   $("a.article").click(function(){
   $(this).parent().prev().slideToggle("slow");
   $(this).toggleClass("active"); return false;
   });
   

  // Join the team show/hide
  if ($(".jobInfoContainer").length) {
      $(".jobInfoHeader").click(function() {
        $(this).toggleClass("open").next().slideToggle();
      }).filter(":first").click();    
    }
  
  
    $(".parcCountries .country")
      .append('<p><a href="#nogo">View all regions</a></p>')
      .find("p a")   
        .click(function(){
            
            var anchor = this;
            var regions = $(anchor).parents(".parcCountries").find(".regions");
            
            if( anchor.className.match(/active/i) ) {
                $(anchor).removeClass("active");
                regions.slideUp();
            }
            else {
                $(anchor).addClass("active");
                regions.slideDown();
            }
            
            return false;
       });
   
 
   $(".specialOffers p.terms,.specialOffersHeader p.terms").hide();
   $("a.viewTerms").toggle(function(){
          $(this).parent().next().slideToggle("slow");
          $(this).toggleClass("active").text("Close terms and conditions"); return false;
          },
          function(){
          $(this).parent().next().slideToggle("slow");
          $(this).toggleClass("active").text("View terms and conditions"); return false;
          }
          );   
          
    $(".specialOffers .offerTerms").hide();
   $(".specialOffers .termsLink a").toggle(function(){
          $(this).parent().parent().next().slideToggle("slow");
          $(this).toggleClass("active").text("Close terms and conditions"); return false;
          },
          function(){
          $(this).parent().parent().next().slideToggle("slow");
          $(this).toggleClass("active").text("View terms and conditions"); return false;
          }
          );  
   
   
   $(".accommodation .mobileHomes .types .accomInfo div").hide();
   $("a.homeInfo").toggle(function(){
          $(this).parent().prev().slideToggle("slow");
          $(this).parents(".accomInfo").parent().animate({backgroundColor: "blue"}, "slow");
          $(this).toggleClass("active").text("Close"); return false;
          },
          function(){
          $(this).parent().prev().slideToggle("slow");
          $(this).parents(".accomInfo").parent().animate( { backgroundColor: 'white' }, "slow");
          $(this).toggleClass("active").text("Find out more"); return false;
          }
          );
          
   $("a.parcMobileToggle").toggle(function(){
   
          $(this).parent().prev().animate({height:'100%'}, "slow");
          $(this).toggleClass("active").text("Close"); return false;
          },
          function(){
          $(this).parent().prev().animate({height:'245px'}, "slow");
          $(this).toggleClass("active").text("Find out more"); return false;
          }
          );
              
  
    //Jscript for toggling Accessory Description
    var accessoryHold = $(".purProcess .accessories .accessoryHold");
    $(".accessory .desc")
        .hide()
        .after('<p><a href="#nogo">Show details</a></p>')
        .next().find("a").click(function (){
            $(this).parent().prev().toggle();
            if ($(this).text()=="Show details"){
                $(this).text("Hide details")
            }
            else{$(this).text("Show details")} 
        });
   
   
    //Jscript to generate Optional Accessories Links (open & close)
    accessoryHold
    .hide()
    .before('<p class="viewAccessories"><a href="#purchase">View and purchase additional accessories with your plan.</a></p>')
    
    .prev().find("a").click(function (){
        accessoryHold.slideDown();
        $(this).parent().hide();
        $("#closeAccessories").show();
    })
    
    $(".accessories")
        .after('<p id="closeAccessories" class="closeAccessories"><a href="#nogo">Close accessories panel</a></p>')
        .next()
        .hide()
        .find("a")
        .click(function (){
            accessoryHold
                .hide()
                .prev()
                .show();
            $(this).parent().hide();
        })

    // setup driving information
    if( $(".drivingDirections .info").length )
    {
      initDirections();
    }
    
    // setup  image gallery, parc pages
    if( $(".gallery").length )
    {
      initGallery();
    }
    
    // setup image gallery, mobile pages
    if( $("*[class^=gallery_mobile]").length )
    {
      initGalleryMobile();
    }
    
    
    if( $(".offerRadio").length )
    {
        setupOfferOverlay();
    }
    
    // setup home image show
    if( window.homeSlideShow )
    {
        imageSlideShow();
    }

    });
    
function floorPlan_toggle(id)
{
  var floorPlan = document.getElementById(id);
  if (floorPlan.style.display=="none" || floorPlan.style.display=="")
  {
    floorPlan.style.display="inline";
  }
  else
  {
    floorPlan.style.display="none";
  }
}      

function imageSlideShow()
{
    var images = window.homeSlideShow;
    var container = null;

    if( !$(".homepage .homebanner a").length )
    {
        for( var x in images)
        {
            if( images[x].href )
            {
                $(".homepage .homebanner img").wrap("<a/>");
                break;
            }
        }
    }

    if( $(".homepage .homebanner a").length )
    {
        container = $(".homepage .homebanner a");
    }
    else
    {
        container = $(".homepage .homebanner");
    }

    var timer = images.timer || 4000;
    var index = 0;
    
    function runShow()
    {
    index = (index + 1) % images.length;
        
        var img = new Image();

      function imageLoaded()
      {
          $("img",container).fadeOut("slow" ,function() { $(this).remove(); } );
      $(img).hide().appendTo(container).fadeIn("slow" , function() {setTimeout(runShow,timer)});
      }

        function imageFail()
        {
            runShow();
        }

        img.onload = imageLoaded;
        img.onerror = imageFail;

        img.src = images[index].src;
        img.alt = img.title = images[index].alt;
        container.attr("title",img.alt);
        if( images[index].href )
        {
            container.attr("href" , images[index].href );
        }
        else
        {
            container.removeAttr("href");
        }
        
    }

    setTimeout( runShow , timer );
}

function setupOfferOverlay()
{
    $(".offerRadio")
        .click( function() {

            /*  setup any hidden input values here.
                Don't put them inside the checkAvailability
                box at the bottom of the page */
            // $("input" ,this).attr("checked","checked");
      /********************************/

      var accomid = $(this).children("#accom").attr("value");
      var Pdate = $(this).children("#Pdate").attr("value");
      var Pnight = $(this).children("#Pnight").attr("value");

            if( $("#checkAvailability").length )
            {
                showOverlay( $('<div class="bookingFrame" />').append( $("#checkAvailability").show() ) , true );
            }
            else
            {
                showOverlay( null , true );
            }
            
      $("#checkAvailability").find("#selctedaccom").val(accomid);
      $("#checkAvailability").find("#selectdate").val(Pdate);
      $("#checkAvailability").find("#selectnight").val(Pnight);

      $("#checkAvailability").find('#PSTAYN').val(Pnight);
      DrawYears(3,"+","PSTYYYY","N",startDate);
      if (isDate(Pdate, 'dd-MMM-yyyy')) {
        var defaultDate=0;
        defaultDate =getDateFromFormat(Pdate,'dd-MMM-yyyy',true);  
        var month = (defaultDate.getMonth() + 1)+'';
        var day = ''+defaultDate.getDate();
        $("#checkAvailability").find('#PSTDD').val(LZ(day)); 
        $("#checkAvailability").find('#PSTMM').val(LZ(month)); 
        $("#checkAvailability").find('#PSTYYYY').val(defaultDate.getFullYear());
      }
      PsetEndDate();

      return false;
    });
}

function initGalleryMobile()
{
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "NewCSS/image_gallery_mobile.js";
  document.body.appendChild(script);
}

function initGallery()
{
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "NewCSS/eqtr_image_gallery.js";
  document.body.appendChild(script);
}
  
function initDirections()
{
  var container = $(".drivingDirections .info");
  var setup = false;

  $(":submit" , container ).one( "click" , function() {
    $(this).after('<span class="googleLoading">Loading directions</span>');
    container.append( '<div class="googleControls hideOnload"><div class="googleMap"/></div>' );
      var script = document.createElement("script");
      script.type = "text/javascript";
      script.src = googleApi + "&callback=loadGoogleMaps";
      document.body.appendChild(script);
    return false;
  });
}

function loadGoogleMaps()
{
    var script = document.createElement("script");
      script.type = "text/javascript";
      script.src = "NewCSS/eqtr_google_directions.js";
      document.body.appendChild(script);
}
    
// floorplan popup

function openFloorplanPopup()
{
    var el = this;
    
    var img = new Image();
    
    img.onload = function() {
        
        var winHeight = $(window).height();
        var winWidth = $(window).width();
        var imgHeight = img.height;
        var imgWidth = img.width;
        
        if( imgWidth > winWidth )
        {
            img.width = winWidth - 40;//abitrary height.
            img.height = img.width*imgHeight/imgWidth;

            imgHeight = img.height;
            imgWidth = img.width;
        }
        
        if( imgHeight > winHeight )
        {
            img.height = winHeight - 40;//abitrary height.
            img.width = img.height*imgWidth/imgHeight;
        }
        
        showOverlay( $('<div class="imageFrame"/>').append(img) );
    };
    
    img.onerror = function() {
           
    };  
    
    img.src = el.href;
    return false; 
    
}

//Jscript to generate window height (this is used with Monitor Solutions Popup)
function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth , myHeight ];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
  
/* common functions */

function playMovie(url, thumb) {
    var myFlashMovie = thisMovie("flashVideo");
    myFlashMovie.playFlashVideo(url, thumb);
}

function thisMovie(movieName) {
    return ($.browser.msie) ? window[movieName] : document[movieName];
}  

function getWMV( src )
{
    var str = [];
    str.push( '<object id="player" data="' + src + '" class="flash" width="393" height="271">' );
    str.push( '<param name="filename" value="' + src + '"/>' );
    str.push( '<param name="stretchToFit" value="true" /><param name="Showcontrols" value="true"/>' );
    str.push( '<param name="autoStart" value="False"/><param name="ShowStatusBar" value="True" />' );
    str.push('<p>This video requires the Windows Media Player plugin.</p>');
    if( $.browser.msie )
    {
        str.push('<p>Download load the Windows Media Player Core add-on (click on the yellow bar alert bar) or update to the latest version of Windows Media Player</p>');
    }
    else
    {
        str.push('<p>Update to the latest version of Windows Media Player</p>');
    }
    str.push( '</object>' );
    return str.join("");
}

/* lightbox overlay for content */

function showOverlay( html , keepContentWhenRemove ) {

    var popup = null;

    if( keepContentWhenRemove && showOverlay.html )
    {
        html = showOverlay.html;
    }
  
  displayPanel(html);

    function removePopup() {
        popup.fadeOut("slow", function() { $(this).add(".popFrame").remove(); });
        $(window).unbind("scroll");
        return false;
    }

    function displayPanel(html) {
        popup = $('<div id="overlayPopup" class="popup"></div><div class="overlay"><a class="popupClose" title="Close window" href="#"><span>Close window</span></a><div class="popupContent" /></div>').hide().css("display", "none");
        popup.filter(".popup").css("opacity", "0.5").click( removePopup );
        var popupContent = popup.find(".popupContent").append(html);
        
        showOverlay.html = popupContent.html();

        $("body").append(popup);

        popup.eq(1).width( popup.eq(1).width() );

        popup.eq(1)
            .css("margin-left" , -popup.eq(1).width()/2 )
            .find(".popupClose")
            .css("float","right")
            .click( removePopup );

        popup.fadeIn();

        var offsetTop = ($(window).height() - popup.eq(1).height())/2;
        
        if (ie6Below) {

            popup.css("position","absolute").eq(1).css({ top: (getScrollXY()[1] + offsetTop)}).end().eq(0).height(document.body.scrollHeight);
            $(window).bind("scroll", function() {
                popup.eq(1).stop().animate({ top: getScrollXY()[1] + offsetTop }, 500);
            });

            $("body").append('<iframe class="popFrame" style="position:absolute;top:0;left:0;width:100%;height:' + document.body.scrollHeight + 'px" frameborder="0" src="javascript:false;"></iframe>').find(":last").css("opacity",0);
        }
        else {
            popup.get(1).style.top = offsetTop + "px";
        }
    }

    return false;
}

$(window).load( function() {

var maxheight = 0;
$(".aboutAlFresco,.alfUpdates").each( function() {
  var h = this.offsetHeight;
  if( h > maxheight ) maxheight = h;
}).each( function() {
  var pb = $(this).css("padding-bottom").replace("px","");
  var pt = $(this).css("padding-top").replace("px","");
  $(this).css("height" , maxheight - pb - pt );
});

});


function setEmailSignText()
{
  
  // Default text. Required field notification text, in this example. 
  var signup = $(".newsletterSignUp");
  var label = $("label" ,signup ).hide();
  var input = $("input" , signup);
  var reqVal = label.text();
  
  // Initial addition of text
  input.each(function(){
    createText(reqVal, $(this));
  });
}

// Create default text for text field on page load
function createText(defVal, thisObj){
  if( thisObj.is(":text") )
  {
    thisObj.addClass("empty").val( defVal );
    thisObj.data("text" , defVal );

      thisObj
          .focus( removeText )  // Removal of text on user-focus
          .blur( restoreText );  // Restoration of default text on input blur, if no user input.
  }
}

// Remove default text on focus. Ignore user-inserted text
function removeText() {
  var el = $(this);
  
  var text = el.data("text");
  if( text )
  {
    if( el.val() == text ){ 
      el.removeClass("empty").val(""); 
    }
  }
}

// Restore default text on focus. Ignore user-inserted text
function restoreText (defVal, thisObj) {
  var el = $(this);
  var text = el.data("text");
  if( text )
  {
    var currVal = $.trim(el.val());
    if(currVal == "") { 
      el.addClass("empty").val(text);   
    }
  }
}
/***************************************************************************************************
  end eqtr_common.js
/**************************************************************************************************/

/***************************************************************************************************
  start pkgSearchPanel.js 
/**************************************************************************************************/
var gsCty1 = "", gsCty2 = "", gsCty3 = "", gsAccom = "";

// ------------------------------------------------------------------
// Save the values of the dropdowns
// ------------------------------------------------------------------
function saveFormDetails() {
  if (gsGeogCty1 == 'Y') {$f('BackCTY1Code').value = $f('CTY1_ID').value;}
  if (gsGeogCty2 == 'Y') {$f('BackCTY2Code').value = $f('CTY2_ID').value;}
  $f('BackCTY3Code').value = $f('CTY3_ID').value;
  if ($f('ACC_ID')) {$f('BackACCCode').value = $f('ACC_ID').value;}
}

// ------------------------------------------------------------------
// Build child and infant ages for request
// ------------------------------------------------------------------
function ds_buildPaxAge() {
  /*var ldChdDate = getDateFromFormat($f("ST_DT").value, gsDateFormat, true);
  ldChdDate.setFullYear(ldChdDate.getFullYear() - 10);
  var lsChdDate = formatDate(ldChdDate, "dd-MM-yyyy");

  var ldInfDate = getDateFromFormat($f("ST_DT").value, gsDateFormat, true);
  ldInfDate.setFullYear(ldInfDate.getFullYear() - 1);
  var lsInfDate = formatDate(ldInfDate, "dd-MM-yyyy");

  var iPxC =   Number($('#PXC').val());
  var iPxI =   Number($('#PXI').val());
  var lsXML = "<PAXAGES>";
  if (iPxC > 0) {
    lsXML += "<CHD>";
    for (var i=1; i<=iPxC; i++) {lsXML += "<DOB>" + xmlDateValueBuild(lsChdDate, '') + "</DOB>";}
    lsXML += "</CHD>";
  }
  if (iPxI > 0) {
    lsXML += "<INF>";
    for (var i=1; i<=iPxI; i++) {lsXML += "<DOB>" + xmlDateValueBuild(lsInfDate, '') + "</DOB>";}
    lsXML += "</INF>";
  }
  lsXML += "</PAXAGES>";
  return lsXML;*/

  var ldChdDate = getDateFromFormat(getDateStr("ST"), gsDateFormat, true);
  ldChdDate.setFullYear(ldChdDate.getFullYear() - 10);
  var lsChdDate = formatDate(ldChdDate, "dd-MM-yyyy");

  var ldInfDate = getDateFromFormat(getDateStr("ST"), gsDateFormat, true);
  ldInfDate.setFullYear(ldInfDate.getFullYear() - 1);
  var lsInfDate = formatDate(ldInfDate, "dd-MM-yyyy");

  var iPxC =   Number($('#PXC').val());
  var iPxI =   Number($('#PXI').val());
  var lsXML = "<PAXAGES>";
  if (iPxC > 0) {
    lsXML += "<CHD>";
    for (var i=1; i<=iPxC; i++) {lsXML += "<DOB>" + xmlDateValueBuild(lsChdDate, '') + "</DOB>";}
    lsXML += "</CHD>";
  }
  if (iPxI > 0) {
    lsXML += "<INF>";
    for (var i=1; i<=iPxI; i++) {lsXML += "<DOB>" + xmlDateValueBuild(lsInfDate, '') + "</DOB>";}
    lsXML += "</INF>";
  }
  lsXML += "</PAXAGES>";
  return lsXML;
}

// ------------------------------------------------------------------
// Display end date and day name
// ------------------------------------------------------------------
function setEndDate() {
  /*if (isDate($f("ST_DT").value, gsDateFormat)) {
    setPanelErrorStatus(false);
    var ldDepDate = getDateFromFormat($f("ST_DT").value, gsDateFormat, true);
    $f('ST_DT_NAME').innerHTML = formatDate(ldDepDate, "E");
    if (ldDepDate != 0) {
      var alNewDays = ldDepDate.getDate();
      alNewDays += Number($f('STAY').value);
      ldDepDate.setDate(alNewDays);
    }
    $f('ENDDT_NAME').value = formatDate(ldDepDate, "E");
    $f('ENDDT_DD').value = formatDate(ldDepDate, "dd");
    $f('ENDDT_MMYY').value = formatDate(ldDepDate, "MM/yyyy");
  } else {
    setPanelErrorStatus(true);
    $f('ST_DT_NAME').innerHTML = "";
    $f('ENDDT_NAME').value = "";
    $f('ENDDT_DD').value = "";
    $f('ENDDT_MMYY').value = "";
  }*/

  if (isDate(getDateStr("ST"), gsDateFormat)) {
    setPanelErrorStatus(false);
    var ldDepDate = getDateFromFormat(getDateStr("ST"), gsDateFormat, true);
    $f('ST_DT_NAME').innerHTML = formatDate(ldDepDate, "E");
    if (ldDepDate != 0) {
      var alNewDays = ldDepDate.getDate();
      alNewDays += Number($f('STAYN').value);
      ldDepDate.setDate(alNewDays);
    }
    $f('ENDDT_NAME').value = formatDate(ldDepDate, "E");
    $f('ENDDT_DD').value = formatDate(ldDepDate, "dd");
    $f('ENDDT_MMYY').value = formatDate(ldDepDate, "MM/yyyy");
  } else {
    setPanelErrorStatus(true);
    $f('ST_DT_NAME').innerHTML = "";
    $f('ENDDT_NAME').value = "";
    $f('ENDDT_DD').value = "";
    $f('ENDDT_MMYY').value = "";
  }
}


function PsetEndDate() {

  if (isDate(getDateStr("PST"), gsDateFormat)) {
    setPanelErrorStatus(false);
    var ldDepDate = getDateFromFormat(getDateStr("PST"), gsDateFormat, true);
    $f('PST_DT_NAME').innerHTML = formatDate(ldDepDate, "E");
    if (ldDepDate != 0) {
      var alNewDays = ldDepDate.getDate();
      alNewDays += Number($f('PSTAYN').value);
      ldDepDate.setDate(alNewDays);
    }
    $f('PENDDT_NAME').value = formatDate(ldDepDate, "E");
    $f('PENDDT_DD').value = formatDate(ldDepDate, "dd");
    $f('PENDDT_MMYY').value = formatDate(ldDepDate, "MM/yyyy");
  } else {
    setPanelErrorStatus(true);
    $f('PST_DT_NAME').innerHTML = "";
    $f('PENDDT_NAME').value = "";
    $f('PENDDT_DD').value = "";
    $f('PENDDT_MMYY').value = "";
  }
}



// ------------------------------------------------------------------
// Toggle error message status
// ------------------------------------------------------------------
function setPanelErrorStatus(abError) {
  if (abError) {
    setClassName($f('srchPanelDateSection'), "formSectionError");
    setClassName($f('srchPanelDateSection').getElementsByTagName("p")[0], "info");
    setClassName($f('ENDDT_NAME'), "weekdayError");
    setClassName($f('ENDDT_DD'), "dayError");
    setClassName($f('ENDDT_MMYY'), "monthYearError");
  } else {
    setClassName($f('srchPanelDateSection'), "formSection");
    setClassName($f('srchPanelDateSection').getElementsByTagName("p")[0], "");
    setClassName($f('ENDDT_NAME'), "weekday");
    setClassName($f('ENDDT_DD'), "day");
    setClassName($f('ENDDT_MMYY'), "monthYear");
  }
}

// ------------------------------------------------------------------
// validate the page
// ------------------------------------------------------------------
function ds_validate() {
  if (gdMinDate == 0) gdMinDate = gdTodaysDate;
  if (!isDate(getDateStr("ST"), gsDateFormat)) {
    setPanelErrorStatus(true);
    return false;
  }
  var ldCheckDate = getDateFromFormat(getDateStr("ST"), gsDateFormat, true);
  
  if (ldCheckDate < gdMinDate) {
    setPanelErrorStatus(true);
    return setFocus("Departure date cannot be before " + formatDate(gdMinDate, "dd-NNN-yyyy"), $f('STDD'));
  }
  var alNewDays = ldCheckDate.getDate();
  alNewDays += Number($f('STAY').value);
  ldCheckDate.setDate(alNewDays);

  var loAdults = $f('PPXA');
  var loChildren = $f('PPXC');
  var loInfants = $f('PPXI');
  var llAduVal = Number(loAdults.value);
  var llChdVal = Number(loChildren.value);
  var llInfVal = Number(loInfants.value);
  var lsCty1 = (gsGeogCty1 == 'Y') ? $f('CTY1_ID').value : '';
  var lsCty2 = (gsGeogCty2 == 'Y') ? $f('CTY2_ID').value : '';
  var loCty1 = (gsGeogCty1 == 'Y') ? $f('CTY1_ID') : (gsGeogCty2 == 'Y') ? $f('CTY2_ID') : $f('CTY3_ID');
  var lsAccom = ($f('ACC_ID')) ? $f('ACC_ID').value : '';
  if (($f('CTY3_ID').value == "") && (lsCty2 == "") && (lsCty1 == "") && (lsAccom == ""))
    if ($f('ACC_ID'))
      return setFocus("Please select location or an accommodation", loCty1);
    else
      return setFocus("Please select location", loCty1);
  return true;
}

// ------------------------------------------------------------------
// build search request
// ------------------------------------------------------------------
function panelSearchRequest() {
  if (ds_validate()) {
    var xml = "<BKGFLOWREQUEST>";
    xml += XmlControlDets();
    xml += "<APPLICDETS>";
    xml += "<FUNCTION>R</FUNCTION>";
    xml += "<REQKEY>";
    xml += "<STDD>" + $f('ST_DT').value.substr(0, 2) + "</STDD>";
    xml += "<STMM>" + $f('ST_DT').value.substr(3, 2) + "</STMM>";
    xml += "<STYYYY>" + $f('ST_DT').value.substr(6, 4) + "</STYYYY>";
    xml += "<STAY>" + $f('STAY').value + "</STAY>";
    xml += "<PXA>" + $f('PXA').value + "</PXA>";
    xml += "<PXC>" + $f('PXC').value + "</PXC>";
    xml += "<PXI>" + $f('PXI').value + "</PXI>";
    xml += "<ACC_FLX>Y</ACC_FLX>";
    if (gsGeogCty1 == 'Y') {xml += "<CTY1_ID>" + $f('CTY1_ID').value + "</CTY1_ID>";}
    if (gsGeogCty2 == 'Y') {xml += "<CTY2_ID>" + $f('CTY2_ID').value + "</CTY2_ID>";}
    xml += "<CTY3_ID>" + $f('CTY3_ID').value + "</CTY3_ID>";
    if ($f('ACC_ID')) xml += "<ACC_ID>" + $f('ACC_ID').value + "</ACC_ID>";
    xml += ds_buildPaxAge();
    xml += "</REQKEY>";
    xml += addFlowCtl('MSEX');
    xml += "</APPLICDETS>";
    xml += "</BKGFLOWREQUEST>";

    document.frmXmlSubmit.XML.value = xml;
    saveFormDetails();
    document.frmXmlSubmit.submit();
  }
}
/***************************************************************************************************
  end pkgSearchPanel.js 
/**************************************************************************************************/
