$(document).ready(function(){
    ajaxPerformanceEventLinks();
});

var ajaxPerformanceEventLinks = function(){
  $('.selected-event').click(function(){
    $(this).closest('form').submit();
  });
}


/* booking creation */

var ajaxPerformances = function(){
  
  $('.performance .ui-icon-trash').click(function(){
    jQuery.ajax({url: '/performances/'+$(this).closest('.performance').attr('id').replace('performance_',''),
                 type: 'DELETE',
                 dataType: 'script'
                 });
  });
}

var ajaxPrices = function(){
  
  $('.price .ui-icon-trash').click(function(){
    jQuery.ajax({url: '/prices/'+$(this).closest('.price').attr('id').replace('price_',''),
                 type: 'DELETE',
                 dataType: 'script'
                 });
  });
}

if(location.href.indexOf('/webpages/') > 0){

  $("#datepicker").datepicker({
    defaultDate: "+1m",
    changeMonth: true,
    changeYear: true,
    altFormat: 'dd-mm-yy',
    altField: '#starts_at_date',
    onSelect: function(selectedDate,inst) {
    }
  });
  
  ajaxPerformances();
  ajaxPrices();
  ajaxLinks();
  
}
