﻿/* Tivoli Reservations */
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

$(function() {
  /*var pasta = 0, 
     Reservations = 0;
  if ($('#psReservationForm').html()) { pasta = "tabs"; }
  if ($('#GeneralReservationForm').html()) { pasta = "Geral"; }
  $("#iframe_flowTabs img").each( function() {
    $(this).attr("src" , "Files/Billeder/TivoliHotels/Reservas/" + pasta + "/activo_" + $(this).attr("alt"));
    $(this).attr("src" , "Files/Billeder/TivoliHotels/Reservas/" + pasta + "/" + $(this).attr("alt"));
  });*/
  $("#iframe_flowTabs").tabs("#iframe_flowPanes > div", {
    effect: 'fade'
  });
  // remove Dynamicweb paragraph anchors
  $("a.pidlink").remove();
  // dropdowns
  $('ul.jsddm > li').bind('mouseover', jsddm_open)
  $('ul.jsddm > li').bind('mouseout',  jsddm_timer)
  $('ul.jsddm li.Hotel a').click(function() {
    $("#SelectedOptn").html($(this).html());
    $("#txtStopHotel").val($(this).attr("idSIHOT"));
    jsddm_close();
  });
  $('.NumberSelector ul.jsddm li a').click(function() {
    var SelectValue = $(this).html();
    $(this).parent().parent().parent().find("a:first").html(SelectValue);
    $("#" + $(this).parent().parent().parent().attr("destination")).val(SelectValue);
    jsddm_close();
  }); 
  // dropdowns v2 - stylish select
  $("#NoRooms, #NoAdults, #NoChildren").html('');
  if ($("#NoRooms").length != 0) {
    for (i=1;10>=i;i++){
      $("#NoRooms, #NoAdults, #NoChildren").append('<option value="'+i+'">'+i+'</option>');
    }
    $("#NoChildren").html('').prepend('<option value="0">0</option>').val('0');
  }
  $("#ARR").datepicker({ 
    dateFormat: 'dd-mm-yy',
    minDate: Date.today(),
    dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
    monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
    onClose: function(dateText, inst) {
      var TheARRdate = $("#ARR").datepicker("getDate");
      var TheNewDEPdate = Date.parse(TheARRdate.getFullYear()+"-"+(TheARRdate.getMonth()+1)+"-"+TheARRdate.getDate()).add(1).days();
      if ($("#ARR").datepicker("getDate").compareTo($("#DEP").datepicker("getDate"))>=0) {
        $("#DEP").datepicker("setDate", new Date(TheNewDEPdate.getFullYear(),TheNewDEPdate.getMonth(),TheNewDEPdate.getDate()));
      }
      $("#DEP").datepicker("option", "minDate", new Date(TheNewDEPdate.getFullYear(),TheNewDEPdate.getMonth(),TheNewDEPdate.getDate()));
    }
  });
  $("#ARR").datepicker("setDate", new Date());
  $("#DEP").datepicker({ 
    dateFormat: 'dd-mm-yy',
    minDate: Date.today().add(1).days(),
    dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
    monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro']
  });
  $("#DEP").datepicker("setDate", Date.today());
  $("#DEP").datepicker("setDate", "+1");
  $("#ARR2").datepicker({ 
    dateFormat: 'yy-mm-dd',
    minDate: Date.today().add(1).days(),
    dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
    monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
    onClose: function(dateText, inst) {
      var TheARRdate = $("#ARR2").datepicker("getDate");
      var TheNewDEPdate = Date.parse(TheARRdate.getFullYear()+"-"+(TheARRdate.getMonth()+1)+"-"+TheARRdate.getDate()).add(1).days();
      $("#DEP2").datepicker("setDate", new Date(TheNewDEPdate.getFullYear(),TheNewDEPdate.getMonth(),TheNewDEPdate.getDate()));
      $("#DEP2").datepicker("option", "minDate", $("#DEP2").val());
    }
  });
  $("#ARR2").datepicker("setDate", new Date());
  $("#DEP2").datepicker({ 
    dateFormat: 'yy-mm-dd',
    minDate: Date.today(),
    dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
    monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro']
  });
  $("#DEP2").datepicker("setDate", Date.today());
  $("#DEP2").datepicker("setDate", "+1");
  /* Correcção para FireFox (menu) */
  jQuery.each(jQuery.browser, function(i, val) {
    if(i=="mozilla") {
     $("#CorrectionForFF").css("letter-spacing", "-1px");
   }
  });
  /*End of auto width*/
  // tabs
 /* $("#iframe_flowTabs").tabs("#iframe_flowPanes > div", {
    effect: 'fade',
    onBeforeClick:function(event,tabIndex){
      this.getCurrentPane().addClass("current");
      if ($("#iframe_flowTabs .current").html()) {
        $("#iframe_flowTabs .current").children("img").attr("src" , "Files/Billeder/TivoliHotels/Reservas/" + pasta + "/" + $(".current").children("img").attr("alt"));
      }
    },
    onClick:function(event, tabIndex) {
      $("#iframe_flowTabs .current").children("img").attr("src" , "Files/Billeder/TivoliHotels/Reservas/" + pasta + "/activo_" + $(".current").children("img").attr("alt"));
    }
  });
  $('#iframe_flowTabs li img').hover(
    function () {
      $(this).attr("src" , "Files/Billeder/TivoliHotels/Reservas/" + pasta + "/activo_" + $(this).attr("alt"));
    }, 
    function () {
      if (!$(this).parent().hasClass("current")) {
        $(this).attr("src" , "Files/Billeder/TivoliHotels/Reservas/" + pasta + "/" + $(this).attr("alt"));
      }
    }
  );*/
  $("#hotel").sSelect();
  $("#NoRooms").sSelect();
  $("#NoAdults").sSelect();
  $("#NoChildren").sSelect();
  $("#promoType").sSelect();
});
 
function ValidateForm() {
  if ($('#Children').is(':checked')) {
    AdultsVariable = "NOPAX=";
  }
  else {
    AdultsVariable = "NOPAXPERGT=1A,";
  }
  return false;
}
 
function ValidateHotel() {
  if ($("#hotel").val() == -1) {
    alert("Por favor escolha o hotel!");
    return false;
  }
  else {
    if ($("select[name='child']").val() == 0) {
      $("select[name='child']").remove();
    }
    if ($("input[name='Promo']").val() == "") {
      $("input[name='Promo']").remove();
    }
    if ($("input[name='Group']").val() == "") {
      $("input[name='Group']").remove();
    }
    var s=s_gi('thaytivoli'); s.linkTrackVars='prop1,eVar1,events'; s.events='event1'; s.prop1='Tivoli Reservation Form'; s.eVar1='Tivoli Reservation Form'; s.tl(this,'o','Tivoli Reservation Form');
    return true;
  }
}
 
function jsddm_open() {
  jsddm_canceltimer();
  jsddm_close();
  ddmenuitem = $(this).find('ul').css('visibility', 'visible');
} 
function jsddm_close() {
  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}
function jsddm_timer() {
  closetimer = window.setTimeout(jsddm_close, timeout);
}
function jsddm_canceltimer() {
  if(closetimer) {
    window.clearTimeout(closetimer);
    closetimer = null;
  }
}
 
function updateHotelList(Hotels) {
  for (i=Hotels.length;i>0;i--) {
    if (Hotels[i-1] == 0) {
      $("#psReservationForm select#hotel option:eq(" + i + ")").remove();
    }
  }
  $("select#hotel optgroup").each(function() {
    if ($(this).find("option").length == 0 && $(this).attr('label') != "HOTÉIS NO BRASIL" && $(this).attr('label') != "HOTÉIS EM PORTUGAL") {
      $(this).remove();
    }
  });
  if ($("select#hotel optgroup[label='HOTÉIS EM PORTUGAL'] ~ optgroup").length) {
    $("select#hotel optgroup[label='HOTÉIS EM PORTUGAL'] ~ optgroup").each(function(i) {
      if ($(this).attr('value') == "HOTÉIS NO BRASIL" && i==0) {
        $("select#hotel optgroup[label='HOTÉIS EM PORTUGAL']").remove();
      }
    });
  }
  if (!($("select#hotel optgroup[label='HOTÉIS NO BRASIL'] ~ optgroup").length)) $("select#hotel optgroup[label='HOTÉIS NO BRASIL']").remove();
  if (!($("select#hotel optgroup[label='HOTÉIS EM PORTUGAL'] ~ optgroup").length)) $("select#hotel optgroup[label='HOTÉIS EM PORTUGAL']").remove();
  $(".hotel select").sSelect();
  $('.hotel .selectedTxt').text('RESERVAR HOTEL - ESCOLHA');
  $('.hotel .newList li.newListOptionTitle').each(function() {
    if ($(this).find("li").length == 0) {
      $(this).css("text-indent","2px");
    }
  });
}
 
var TheString = '<iframe name="SIHOT.WEB" src="https://secure.TivoliHotels.com/SIHOTWeb/indexInFrame.htm?FSTITLE=0&FSLINK=0&HN=<!--@Server:Request.txtstophotel-->&LN=pt&NOROOMS=<!--@Server:Request.norooms-->&ARR=<!--@Server:Request.arr-->&DEP=<!--@Server:Request.dep-->&NOPAXPERGT=1A,<!--@Server:Request.nopaxpergt-->" frameborder="0" width="692" scrolling="no" height="1500"></iframe>';
 
function ValidateForm() {
  if ($('#Children').is(':checked')) {
    AdultsVariable = "NOPAX=";
  }
  else {
    AdultsVariable = "NOPAXPERGT=1A,";
  }
  $("iframe").attr("src","https://secure.TivoliHotels.com/SIHOTWeb/indexInFrame.htm?FSTITLE=0&FSLINK=0&HN=" + $("#txtStopHotel").val() + "&LN=pt&NOROOMS=" + $("#NOROOMS").val() + "&ARR=" + $("#ARR").val() + "&DEP=" + $("#DEP").val() + "&" + AdultsVariable + $("#NOPAXPERGT").val());
  return false;
} 
function CheckDates() {
  var one_day=1000*60*60*24;
  ArrDate = Date.parse($("#arrive").val());
  DepDate = Date.parse($("#depart").val());
  $("#NrNoites").text((DepDate.getTime()-ArrDate.getTime())/one_day);
}


