$(function() {
 $('.destination-button').corner();

  $('.destination-button').click(function() {
      var link_id = $(this).attr('id');
      $('.destination-button').removeClass('active-btn');
      $('#' + link_id).addClass('active-btn');

    $.post(
    'flights-info.php',
    {"loc_id" : link_id},
    function(data) {
     $('.flight-info-holder').html(data);
    });
  });


$(document).ready(function(){
   $(this).bind("contextmenu selectstart", function(e){
      e.preventDefault();
   });

    $(this).keydown(function(e){
        if(e.ctrlKey) {
         var sel ;
        if(document.selection && document.selection.empty)
            {document.selection.empty() ;}
        else if(window.getSelection) {
            sel=window.getSelection();
            if(sel && sel.removeAllRanges)
            sel.removeAllRanges() ;
        }
        e.preventDefault();
        }
    });
});

//    $.ajax({
//      type: 'POST',
//      url: 'flights-info.php',
//      dataType: 'JSON',
//      data: "loca_id="+location_id,
//      success: function(data) {
//       $('.flight-info-holder').html("abc");
//      },
//      beforeSend: function(data)
//      {
//       $('.flight-info-holder').html("Please wait...");
//      }
//     });

  });

$(function() {

 $("#check-in").datepicker({
 dateFormat: 'MM dd, yy',
 minDate: +0,
 onSelect: function(dateText, inst)
  {
   $('#alt-check-in').val(dateText);
   comparedate($('#alt-check-in'), $('#alt-check-out'), $('.nights-stay'), 'check-in');
  }
});

$('#check-out').datepicker({
 dateFormat: 'MM dd, yy',
 minDate: +0,
 onSelect: function(dateText, inst)
  {
   $('#alt-check-out').val(dateText);
    comparedate($('#alt-check-in'), $('#alt-check-out'), $('.nights-stay'), 'check-out');
  }
 });

/*
 * Function to compare date and calculate the days between them
 * @author: Robert Christian P. Obias
 * @email: rchristian_obias@yahoo.com
 *
 */

function comparedate(input1, input2, input3, mode)
{
 var date1        = new Date(input1.val());
 var date2        = new Date(input2.val());
 var nightStay    = input3;

 if(date2.getTime() == date1.getTime())
 {
  alert('Check out date must be different from the check-in date');
  input2.val('');
  nightStay.val('');
 }
 else if(date2.getTime() < date1.getTime())
 {

  if(mode == 'check-in')
  {
   alert('Check-in date must be lower than the Check-out date');
   input1.val('');
   input2.val('');
   nightStay.val('');
  }
  else if(mode == 'check-out')
  {
   alert('Check out date must be higher than the Check-in date');
   input2.val('');
   nightStay.val('');
  }
 }
 else
 {
  nightStay.val(returnNumberOfDaysBetweenTwoDates(input1, input2));
 }

}

function returnNumberOfDaysBetweenTwoDates(input1, input2) {
 var date1 = new Date(input1.val());
 var date2 = new Date(input2.val());

 if(input2.val() != '')
 {
  var minutes = 1000*60;
  var hours = minutes*60;
  var days = hours*24;

  var diff = Math.abs(date1.getTime() - date2.getTime());

  return diff / days;
 }

 return '';

}

});

