jQuery.noConflict();

jQuery.datepicker.regional['cs'] = {
  changeMonth: true,
  changeYear: true,
  duration: 'fast',
  /*showOn: 'button',
  buttonImage: '../images/datepicker/calendar.gif',
  buttonImageOnly: true,*/
  closeText: 'Zavřít',
  prevText: '&#x3c;Dříve',
  nextText: 'Později&#x3e;',
  currentText: 'Nyní',
  monthNamesShort: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
  monthNames: ['led', 'úno', 'bre', 'dub', 'kvě', 'čer', 'čvc', 'srp', 'zář', 'říj', 'lis', 'pro'],
  dayNames: ['neděle', 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota'],
  dayNamesShort: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
  dayNamesMin: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
  dateFormat: 'dd.mm.yy',
  firstDay: 1,
  isRTL: false,
  minDate: 0,
  numberOfMonths: 2
};

/*
var time = new Array(
  new Array('8:00', '8:30', '9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30'),
  new Array('8:00', '9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00')
);
*/
function changeTime(day,selected) {
  jQuery('#arrival option').removeAttr('disabled');
  if(jQuery('#arrival option:first').text()=='obsazeno') {
    jQuery('#arrival option:first').remove();
  }
  if(day=='Sat') {
    jQuery('#arrival option:first').attr('selected', 'selected');
    if(jQuery('#action').attr('value')==0) {
      var index = 7;
    } else {
      var index = 3;
    }
    jQuery('#arrival option:gt(' + index + ')').attr('disabled', 'disabled');
    jQuery('#input-day').attr('value', '1');
  } else if(day=='Sun') {
    jQuery('#arrival option').attr('disabled', 'disabled');
    jQuery('#arrival option:first').before('<option value="20" selected="selected">obsazeno</option>');
    jQuery('#input-day').attr('value', '2');
  }

  /*jQuery('#arrival').html(*/
  var request = "";

  if(selected != null)
    request = "getdate="+day;
  else
    request = "getdate="+day;

  jQuery.ajax({
   dataType: "text",
   type: "GET",
   url: "/ajax-reserv/",
   data: request,
   success: function(html){
     jQuery("#arrival-msg").css('display','none');
     //var el = document.createElement(html);
     //alert(el);
     jQuery("#arrival-box").html(html);
     jQuery("#arrival-box").css('display','block')
  }

 });


//alert("http://www.pneu-janda.cz/ajax-reservation"+"getdate="+day);
}



jQuery(document).ready(function() {
  //alert(document.getElementById('#date'));
  if(document.getElementById('#date') != null ) {
    var dily = jQuery('#date').attr('value').split(".");
    changeTime(dily[2]+'-'+dily[1]+'-'+dily[0],null);
  }


  jQuery.datepicker.setDefaults(jQuery.datepicker.regional['cs']);

  if (jQuery('#date').val()) {
    changeTime(jQuery('#date').val(),null);
  } else {
    jQuery('#arrival-box').hide();
    jQuery('#arrival-msg').show();
  }

  jQuery('#date').bind('blur', function() {
    if (jQuery(this).val().length == 0) {
      jQuery('#arrival-box').hide();
      jQuery('#arrival-msg').show();
    } else {
      changeTime(jQuery(this).val(),null);
    }
  });

  jQuery('#date').datepicker({
    onSelect: function() {
      var date = jQuery(this).datepicker('getDate');
      var day = date.toGMTString();      
      changeTime(day,null);
    }
  });
  /*
  jQuery('#action').change(function() {
    jQuery('#specification').parent().children().remove(':not(select)');
    var index = jQuery(this).attr('value');
    if(index==2) {
      jQuery('#specification').closest('tr').hide();
    } else {
      jQuery('#specification').closest('tr').show();
      var options = '';
      for(var i = 0; i < specification[index].length; i++) {
        options += '<option value="' + i + '">' + specification[index][i][0] + '</option>';
      }
      jQuery('#specification').html(options);
      jQuery('#price').html('<strong>' + specification[index][0][2] + '</strong>');
      jQuery('#input-price').attr('value', specification[index][0][2]);
    }
    var options = '';
    if(index==1 || index==2) {
      for(var i = 0; i < time[1].length; i++) {
        options += '<option value="' + i + '">' + time[1][i] + '</option>';
      }
    } else {
      for(var i = 0; i < time[0].length; i++) {
        options += '<option value="' + i + '">' + time[0][i] + '</option>';
      }
    }
    jQuery('#arrival').html(options);
    if(typeof(day)!='undefined') {
      changeTime(day);
    } else {
      var date = jQuery('#date').datepicker('getDate').toString();
      day = date.slice(0, 3);
      changeTime(day);
    }
  });
  jQuery('#specification').change(function() {
    jQuery(this).parent().children().remove(':not(select)');
    var index1 = jQuery('#action').attr('value');
    var index2 = jQuery(this).attr('value');
    if(specification[index1][index2][1]!='') {
      jQuery(this).after('<br /><span>' + specification[index1][index2][1] + '</span>');
    }
    jQuery('#price').html('<strong>' + specification[index1][index2][2] + '</strong>');
    jQuery('#input-price').attr('value', specification[index1][index2][2]);
  });  */
});
