
var reservationProduct = -1;
var reservationCount = 0;
var maxRezervationCount = 8;
var maxStandingRezervationCount = 0;
var maxKinoRezervationCount = 8;
var allowRezervation = true;

function toggleRezervation_dk()
{
  if (!$(this).hasClass('reserved'))
  {
    var reserved = false;
    if ($(this).hasClass('selected'))
    {
        $(this).removeClass('selected');
    }
    else
    {
        if (reservationCount+1 > maxRezervationCount)
        {
          $(this).fadeIn('fast');
          alert('Nelze objednat více jak '+ maxRezervationCount + ' lístků najednou');
          return;
        }
        reserved = true;
    }
    
    // ajax
    $('.rezervace-progres').css('z-index','10');
    $.get("../../CMSSystem.aspx?cm_action=ajax_addToBasket&ModuleKey=rezervace_dk&Id="+reservationProduct+'&Variant='+encodeURIComponent($('.rezervation-tabs-tabs .rezervation-tab.selected span').html())+'&PriceId='+$('.rez-obsah select').val()+"&Count=1&Reservation="+$(this).attr("id"), 
            function() 
                  { 
                    document.location='/cz/Rezervace_dk.html?tab=1&catalog=&productId='+reservationProduct+'&tab2='+$('.rezervation-tabs-tabs div').tabs().getIndex();
                    
                    //$('.kosik-obsah').load('/cz/Kosik_dk.html .akce-obsah', function ()
                    //  {
                    //    $('.rezervace-progres').css('z-index','0');  
                    //  }); 
                  });
    
  }
  
  $(this).fadeIn('fast');
}

function toggleRezervation_kino()
{
 
  if (!$(this).hasClass('reserved'))
  {
    var reserved = false;
    if ($(this).hasClass('selected'))
    {
        $(this).removeClass('selected');
    }
    else
    {
        if (reservationCount+1 > maxKinoRezervationCount)
        {
          $(this).fadeIn('fast');
          alert('Nelze objednat více jak '+ maxKinoRezervationCount + ' lístků najednou');
          return;
        }
        reserved = true;
    }
    
    // ajax
    $('.rezervace-progres').css('z-index','10');
    $.get("../../CMSSystem.aspx?cm_action=ajax_addToBasket&ModuleKey=rezervace_kino&Id="+reservationProduct+"&Count=1&Variant="+encodeURIComponent($('.rezervation-termins input').val())+"&Reservation="+$(this).attr("id"), 
            function() 
                  { 
                    document.location='/cz/Rezervace_kino.html?tab=1&catalog=&productId='+reservationProduct+'&termin='+$('.rezervation-termins input').val();
                  });
    
  }
  
  $(this).fadeIn('fast');
}

function toggleStanding_dk()
{
    var count = parseFloat($('.rezervace-sal:visible .rezervation_standing input[type=text]').val());
    if (isNaN(count))
    {
      alert('Chybně zadaný počet míst bez místenky');
      return;
    }
    if (reservationCount+count > maxRezervationCount)
    {
      alert('Nelze objednat více jak '+ maxRezervationCount + ' lístků najednou');
      return;
    }
    
    if (count > maxStandingRezervationCount)
    {
      alert('Nelze objednat více jak '+ maxStandingRezervationCount + ' lístků na stání');
      return;
    }
        
    $('.rezervation_standing input[type=text]').val("");
    
    // ajax
    $('.rezervace-progres').css('z-index','10');
    $.get("../../CMSSystem.aspx?cm_action=ajax_addToBasket&ModuleKey=rezervace_dk&Id="+reservationProduct+'&PriceId='+$('.rez-obsah select').val()+"&Count="+count+"&Variant="+encodeURIComponent($('.rezervation-tabs-tabs .rezervation-tab.selected span').html()+" Bez místenky")+"&Standing=1&Reservation="+$(this).attr("id"), 
            function() 
                  { 
                    document.location='/cz/Rezervace_dk.html?tab=1&catalog=&productId='+reservationProduct+'&tab2='+$('.rezervation-tabs-tabs div').tabs().getIndex();
                    
                    //$('.kosik-obsah').load('/cz/Kosik_dk.html .akce-obsah', function ()
                    //  {
                    //    $('.rezervace-progres').css('z-index','0');  
                    //  }); 
                  });
}




$(document).ready(
  function adminDocumentLoad()
  {
    if (allowRezervation)
    {
      $('.rezervace-level-1 > a').click(function() 
      {
        //$(this).parent().find('.rezervace-level-2 > a').parent().fadeOut('fast', toggleRezervation_dk);
        return false;
      } );
      
      $('.tab-cont .rezervace-level-2 > a').click(function() 
      {
        $(this).parent().fadeOut('fast', toggleRezervation_dk);  
        return false;
      } );
      
      $('.tab-cont-kino .rezervace-level-2 > a').click(function() 
      {
        $(this).parent().fadeOut('fast', toggleRezervation_kino);  
        return false;
      } );
    }
    
    $('.rezervation_standing input[type=button]').click(toggleStanding_dk);
  
    // kosik
    $('.kosik-obsah').load('/cz/Kosik_dk.html .akce-obsah');
    $('.kosik-obsah-kino').load('/cz/Kosik_kino.html .akce-obsah');
    

    
    // odebrání na místě
    $('.rezervation-prices select option[value=3918381]').remove();
    $('.rezervation-prices select option[value=3924576]').remove();
    $('.rezervation-prices select option[value=3924578]').remove();
    
  });
