//tabmenu
$(document).ready(function () {
    $('#yolcusayi').click(function () {
        $(".hesapla").fadeIn(300);
    });

    $('.cik').click(function() {
        $('.hesapla').fadeOut(200);
    });

//setInterval(function(){
//  $('#dongu_onecikanlar').click();
//}, 3000);
});

$('#telefon-numarasi')

  .keydown(function (e) {
    var key = e.which || e.charCode || e.keyCode || 0;
    $phone = $(this);

    // Don't let them remove the starting '('
    if ($phone.val().length === 1 && (key === 8 || key === 46)) {
      $phone.val('('); 
      return false;
    } 
    // Reset if they highlight and type over first char.
    else if ($phone.val().charAt(0) !== '(') {
      $phone.val('('+String.fromCharCode(e.keyCode)+''); 
    }

    // Auto-format- do not expose the mask as the user begins to type
    if (key !== 8 && key !== 9) {
      if ($phone.val().length === 4) {
        $phone.val($phone.val() + ')');
      }
      if ($phone.val().length === 5) {
        $phone.val($phone.val() + ' ');
      }     
      if ($phone.val().length === 9) {
        $phone.val($phone.val() + '-');
      }
    }

    // Allow numeric (and tab, backspace, delete) keys only
    return (key == 8 || 
        key == 9 ||
        key == 46 ||
        (key >= 48 && key <= 57) ||
        (key >= 96 && key <= 105)); 
  })
  
  .bind('focus click', function () {
    $phone = $(this);
    
    if ($phone.val().length === 0) {
      $phone.val('(');
    }
    else {
      var val = $phone.val();
      $phone.val('').val(val); // Ensure cursor remains at the end
    }
  })
  
  .blur(function () {
    $phone = $(this);
    
    if ($phone.val() === '(') {
      $phone.val('');
    }
  });




$('#cep-numarasi')

  .keydown(function (e) {
    var key = e.which || e.charCode || e.keyCode || 0;
    $phone = $(this);

    // Don't let them remove the starting '('
    if ($phone.val().length === 1 && (key === 8 || key === 46)) {
      $phone.val('('); 
      return false;
    } 
    // Reset if they highlight and type over first char.
    else if ($phone.val().charAt(0) !== '(') {
      $phone.val('('+String.fromCharCode(e.keyCode)+''); 
    }

    // Auto-format- do not expose the mask as the user begins to type
    if (key !== 8 && key !== 9) {
      if ($phone.val().length === 4) {
        $phone.val($phone.val() + ')');
      }
      if ($phone.val().length === 5) {
        $phone.val($phone.val() + ' ');
      }     
      if ($phone.val().length === 9) {
        $phone.val($phone.val() + '-');
      }
    }

    // Allow numeric (and tab, backspace, delete) keys only
    return (key == 8 || 
        key == 9 ||
        key == 46 ||
        (key >= 48 && key <= 57) ||
        (key >= 96 && key <= 105)); 
  })
  
  .bind('focus click', function () {
    $phone = $(this);
    
    if ($phone.val().length === 0) {
      $phone.val('(');
    }
    else {
      var val = $phone.val();
      $phone.val('').val(val); // Ensure cursor remains at the end
    }
  })
  
  .blur(function () {
    $phone = $(this);
    
    if ($phone.val() === '(') {
      $phone.val('');
    }
  });




function birarttir()
{
    var value = parseInt(document.getElementById('yetiskinsay').value, 10);
    value = isNaN(value) ? 0 : value;
    value = value + 1;
    document.getElementById('yetiskinsay').value = value;

}
function birazalt()
{
    var value = parseInt(document.getElementById('yetiskinsay').value, 10);
    value = isNaN(value) ? 0 : value;
    value = value - 1;
    document.getElementById('yetiskinsay').value = value;
    
    
}

function birarttirc()
{
    var value = parseInt(document.getElementById('cocuksay').value, 10);
    value = isNaN(value) ? 0 : value;
    value = value + 1;
    document.getElementById('cocuksay').value = value;
}
function birazaltc()
{
    var value = parseInt(document.getElementById('cocuksay').value, 10);
    value = isNaN(value) ? 0 : value;
    value = value - 1;
    document.getElementById('cocuksay').value = value;
    
}


function birarttirb()
{
    var value = parseInt(document.getElementById('bebeksay').value, 10);
    value = isNaN(value) ? 0 : value;
    value = value + 1;
    document.getElementById('bebeksay').value = value;
}
function birazaltb()
{
    var value = parseInt(document.getElementById('bebeksay').value, 10);
    value = isNaN(value) ? 0 : value;
    value = value - 1;
    document.getElementById('bebeksay').value = value;
    
}

function sayisal(){
    $(".sayisal_deger").val(yetiskinsay+cocuksay+bebeksay+" Yolcu")
//       $(".sayisal_deger").val(yetiskinsay+" Yetişkin"+" "+cocuksay+" Çocuk"+" "+bebeksay+" Bebek")
}
var yetiskinsay = 1;
var cocuksay = 0;
var bebeksay = 0;
function say(){
    $(document).find(".kisi").each(function(i){
        yetiskinsay = parseInt(yetiskinsay) + parseInt($(this).val());

    });
    $(document).find(".cocuk").each(function(i){
        cocuksay = parseInt(cocuksay) + parseInt($(this).val());
    });
    sayisal();
};

$(document).on('change', 'select', function() {
    say();
});
