//Start Date Select
  /******************************
  * Editable section -- Start --
  ******************************/
  // DATE SETTINGS - EDIT AS REQUIRED
  var daysinAdvance = 0; // Sets default days in advance from current date
  var numberNights = 2;  // Sets default number of nights
  var numberYears = 2; // Sets default number of years to display in year select list
  var numberNightsMin = 1; // Sets minimum number of nights accepted

  // FLAG SETTINGS ON/OFF - SET TO 1 FOR ON & 0 FOR OFF
  var wdDisplay = 0; //weekday display
  var numberNightsDisplay = 1; //number of nights display
  var departDateDisplay = 0; //departure dates display
  var departDateUpdate = 1; //auto update departure date

  // WEEK DAY AND NUMBER NIGHTS TEXT - EDIT TEXT AS REQUIRED
  var wdArray = new Array("");
  var nightTxt = " Night";
  var nightsTxt = " Nights";

  // ERROR MESSAGE TEXT - EDIT TEXT AS REQUIRED
  var invalidDateTxt = "Invalid Arrival Date. Please check number of days selected";
  var invalidDatePriorTxt = "Arrival Date selected is prior Today's date. Please change...";
  var invalidDepartTxt = "Departure Date is prior to Arrival Date selected. Please change...";
  var invalidNightsTxt = "Sorry, reservations under 1 nights are not accepted.";
  var invalidPropertyTxt = "Please choose a property.";
  /******************************
  * Editable section -- End --
  ******************************/

  /**************************************************
  * DO NOT CHANGE JAVASCRIPT SETTINGS BELOW THIS LINE
  **************************************************/
  //Days in each month Array
  var aNumDays = new Array (31,0,31,30,31,30,31,31,30,31,30,31);

  //Cancel out if no departure date display
  if(departDateDisplay == 0) {
    numberNightsDisplay = 0;
    departDateUpdate = 0;
  }

  //Sets dates selected from dyncalendar
  function calendarCallback(day, month, year, objName, formName) {
    if(objName == "calendarArrive"){
      document.forms[formName].fd.selectedIndex = day-1;
      document.forms[formName].fm.selectedIndex = month-1;
      document.forms[formName].fy.selectedIndex = year - DateSelect.fy.options[0].text;
      updateDates(document.forms[formName]);
      if(wdDisplay == 1 && departDateDisplay == 1) setWkd(formName, 1);
    }else{  //objName == calendarDepart
      document.forms[formName].td.selectedIndex = day-1;
      document.forms[formName].tm.selectedIndex = month-1;
      document.forms[formName].ty.selectedIndex = year - DateSelect.ty.options[0].text;
      if(wdDisplay == 1 && departDateDisplay == 1) setWkd(formName, 1);
    }
  }

  //Update form with selected dates
  function updateDates(form, loadDates) {
    //check Leap Year
    if(form.fm.selectedIndex==1)  {
      var leapYear  = new Date (form.fy.options[form.fy.selectedIndex].text,form.fm.selectedIndex+1,1);
      var leapYear  = new Date (leapYear  - (24*60*60*1000));
      var numDaysInMonth = leapYear.getDate();
    }else{
      var numDaysInMonth = aNumDays[form.fm.selectedIndex];
    }
    // Update departure date only when loading the form and/or departDateUpdate is set to 1
    if(loadDates == 1 || departDateUpdate == 1) {
      var selectDate = new Date(form.fy.options[form.fy.selectedIndex].text, form.fm.selectedIndex, form.fd.selectedIndex);
      var setDate = new Date(selectDate.getTime() + ((numberNights+1) * 86400000));
      var setDay = setDate.getDate();
      var setMonth = setDate.getMonth();
      var setYear = setDate.getFullYear() - form.fy.options[0].text;
      var checkinDate = new Date(form.fy.options[form.fy.selectedIndex].text,form.fm.selectedIndex,form.fd.selectedIndex+1);
      var checkoutDate = new Date(form.ty.options[form.ty.selectedIndex].text,form.tm.selectedIndex,form.td.selectedIndex+1);
      if(checkinDate > checkoutDate) {
        if(setYear == form.ty.length) {
          form.td.options[30].selected=1;
          form.tm.options[11].selected=1;
          form.ty.options[form.ty.length-1].selected=1;
        } else {
          form.td.options[setDay-1].selected=1;
          form.tm.options[setMonth].selected=1;
          form.ty.options[setYear].selected=1;
        }
      }
    }
    if(form.fd.selectedIndex+1 > numDaysInMonth) {
      alert(invalidDateTxt);
      form.fd.selectedIndex = numDaysInMonth-1;
    }
  }

  function setWkd(form, calendar) {
    // change form object if returned from calendar
    if(calendar) form = document.forms[form];
    for (var i = 0; i < form.fy.length; i++) {
      if (form.fy.options[i].selected) var fyear = form.fy.options[i].text;
      if (departDateDisplay == 1 && form.ty.options[i].selected) var tyear = form.ty.options[i].text;
    }
    var checkinDate = new Date(fyear,form.fm.selectedIndex,form.fd.selectedIndex+1);
    if (departDateDisplay == 1) var checkoutDate = new Date(tyear,form.tm.selectedIndex,form.td.selectedIndex+1);
    var numNights = Math.round((checkoutDate - checkinDate) / 86400000);
    if (numNights == 1) numNights += nightTxt;
    else numNights += nightsTxt;
    //Set Days of the week display
    if(wdDisplay == 1 && document.getElementById) {
      document.getElementById('inWd').firstChild.nodeValue = '(' + wdArray[checkinDate.getDay()] + ')';
      if (departDateDisplay == 1) document.getElementById('outWd').firstChild.nodeValue = '(' + wdArray[checkoutDate.getDay()] + ')';
    }
    //Set number of nights display
    if(numberNightsDisplay == 1 && document.getElementById) document.getElementById('lengthStay').firstChild.nodeValue = numNights;
  }

  //Load current dates on form load
  function LoadDates(form) {
    var curDate = new Date();
    var setDate = new Date(curDate.getTime() + (daysinAdvance * 86400000));
    var setDay = setDate.getDate();
    var setMonth = setDate.getMonth();
    var setYear = setDate.getFullYear() - form.fy.options[0].text;
    // Set Arrival Dates
    form.fd.selectedIndex = setDay-1;
    form.fm.selectedIndex = setMonth;
    form.fy.selectedIndex = setYear;
    // Set the Departure Dates
    updateDates(form, departDateDisplay);
    if(wdDisplay == 1 || numberNightsDisplay == 1) setWkd(form);
  }

  //Load current dates on form load
  function checkDates(form) {
    var curDate = new Date();
    for (var i = 0; i < form.fy.length; i++) {
      if (form.fy.options[i].selected) var fyear = form.fy.options[i].text;
      if (departDateDisplay == 1 && form.ty.options[i].selected) var tyear = form.ty.options[i].text;
    }
    var checkinDate = new Date(fyear,form.fm.selectedIndex,form.fd.selectedIndex+2);
    
    var daybox = document.getElementById('fd');
    var day = daybox.options[daybox.selectedIndex].value;
    
    var monthbox = document.getElementById('fm');
    var mnth = monthbox.options[monthbox.selectedIndex].value;
    
    document.getElementById('arrdate').value = day + '/' + mnth + '/' + fyear;
    
    if(document.getElementById('SITEID').selectedIndex ==0){
      alert(invalidPropertyTxt);
      return false;
    }

    if (departDateDisplay == 1) {
      var checkoutDate = new Date(tyear,form.tm.selectedIndex,form.td.selectedIndex+2);
      var numNights = Math.round((checkoutDate - checkinDate) / 86400000);
    } else {
      var numNights = form.non.selectedIndex+1;
    }
    if(checkinDate.getTime() < curDate.getTime()) {
      alert(invalidDatePriorTxt);
      return false;
    }
    if(numNights < 1) {
      alert(invalidDepartTxt );
      return false;
    }
    if(numNights < numberNightsMin) {
      alert(invalidNightsTxt);
      return false;
    }
}

  //Generate years options for year select list
  function year_option(form){
    curDate = new Date();
    curYear = curDate.getFullYear();
    for(i = curYear ; i <= curYear+(numberYears-1) ; i++ ){
      document.write('<option value="' + i + '">' + i + '</option>');
    }
  }

//build booking engine string and add Google analytics variables to the end of it 
  
function bookingString(theBookString){
    var theMonth= document.getElementById('fm')[document.getElementById('fm').selectedIndex].value;
    var theDay= document.getElementById('fd')[document.getElementById('fd').selectedIndex].value;
    var theYear= document.DateSelect.fy[document.DateSelect.fy.selectedIndex].text;
    var nights= document.DateSelect.non[document.DateSelect.non.selectedIndex].text;
    var adults= document.DateSelect.ad[document.DateSelect.ad.selectedIndex].text;
    var child= document.DateSelect.chl[document.DateSelect.chl.selectedIndex].text;
    var infant= document.DateSelect.inf[document.DateSelect.inf.selectedIndex].text;
    var DateIn = theMonth +"%2F"+ theDay + "%2F" +theYear;
    var SiteID = document.DateSelect.SITEID.value;


    var cutToGoogleVariables = theBookString.substring(66);
    var NewBookString = "https://portals.uk.rezlynx.net/FCPPortal/wfrmPakQueryResults.aspx?SITEID="+ SiteID +"&DateIn=&fd="+theDay+"&fm="+theMonth+"&fy="+theYear+"&arrdate="+theDay+"%2F"+theMonth+"%2F"+theYear+"&non="+nights+"&ad="+adults+"&chl="+child+"&inf="+infant+"&availcheck=";
    NewBookString +=  cutToGoogleVariables;
    document.DateSelect.action = NewBookString;

}


// Next comes the standard javascript detection that uses the 
// navigator.plugins array. We pack the detector into a function so it loads
// before we run it.

function detectFlash() {  
  // If navigator.plugins exists...
  if (navigator.plugins) {
    // ...then check for flash 2 or flash 3+.
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      // Some version of Flash was found. Time to figure out which.
      
      // Set convenient references to flash 2 and the plugin description.
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // DEBUGGING: uncomment next line to see the actual description.
      // alert("Flash plugin description: " + flashDescription);
      
      // A flash plugin-description looks like this: Shockwave Flash 4.0 r5
      // We can get the major version by grabbing the character before the period
      // note that we don't bother with minor version detection. 
      // Do that in your movie with $version or getVersion().
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
     
      // We found the version, now set appropriate version flags. Make sure
      // to use >= on the highest version so we don't prevent future version
      // users from entering the site.
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion >= 6;
    }
  }
  
  // Loop through all versions we're checking, and
  // set actualVersion to highest detected version.
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
  
  // If we're on webtv, the version supported is 2 (pre-summer2000, 
  // or 3, post-summer2000). Note that we don't bother sniffing varieties
  // of webtv. You could if you were sadistic...
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;  
  
  // DEBUGGING: uncomment next line to display flash version
  // alert("version detected: " + actualVersion);


  // We're finished getting the version on all browsers that support detection.
  // Time to take the appropriate action.

  // If the user has a new enough version...
  if (actualVersion >= requiredVersion) {
    // ...then we'll redirect them to the flash page, unless we've
    // been told not to redirect.
    if (useRedirect) {
      // Need javascript1.1 to do location.replace
      if(jsVersion > 1.0) {
        // It's safe to use replace(). Good...we won't break the back button.
        window.location.replace(flashPage);  
      } else {
        // JavaScript version is too old, so use .location to load
        // the flash page.
        window.location = flashPage;
      }
    }
    
    // If we got here, we didn't redirect. So we make a note that we should
    // write out the object/embed tags later.
    hasRightVersion = true;                
  } else {  
    // The user doesn't have a new enough version.
    // If the redirection option is on, load the appropriate alternate page.
    if (useRedirect) {
      // Do the same .replace() call only if js1.1+ is available.
      if(jsVersion > 1.0) {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}


detectFlash();  // call our detector now that it's safely loaded.  