$(document).ready(function() {
    $('#change_iller').change(function(){
        var il = $("#change_iller option:selected").attr('value');
        $('#change_ilceler').load('index.php?do=ilceal&il='+il);
    });
    $('#cikis').click(function () {
        var accept = confirm('Çıkmak istediğinize emin misiniz?');
        if (accept == true) {
            window.location.href = 'index.php?do=yonetim&act=cikis';
        }
    });
    $('#bayiler').click(function () {
        window.location.href = 'index.php?do=yonetim&act=bayiler';
    });
    $('#yeni_bayi').click(function () {
        window.location.href = 'index.php?do=yonetim&act=yeni_bayi';
    });
    $('#iller').click(function () {
        window.location.href = 'index.php?do=yonetim&act=iller';
    });
    $('#ilceler').click(function () {
        window.location.href = 'index.php?do=yonetim&act=ilceler';
    });
    $('#yeni_il').click(function () {
        window.location.href = 'index.php?do=yonetim&act=yeni_il';
    });
    $('#yeni_ilce').click(function () {
        window.location.href = 'index.php?do=yonetim&act=yeni_ilce';
    });
    $('#ilce_suz').click(function () {
        var il = $("#il option:selected").attr('value');
        if (il) {
            window.location.href = 'index.php?do=yonetim&act=ilceler&il='+il;
        }
    });
    $('#bayi_suz').click(function () {
        var il = $("#change_iller option:selected").attr('value');
        var ilce = $("#change_ilceler option:selected").attr('value');
        if (il && ilce) {
            window.location.href = 'index.php?do=yonetim&act=bayiler&il='+il+'&ilce='+ilce;
        }else if (il && !ilce) {
            window.location.href = 'index.php?do=yonetim&act=bayiler&il='+il;
        }else if (!il && ilce) {
            window.location.href = 'index.php?do=yonetim&act=bayiler&ilce='+ilce;
        }else{
            window.location.href = 'index.php?do=yonetim&act=bayiler';
        }
    });
    $('#bayi_suz2').click(function () {
        var il = $("#change_iller option:selected").attr('value');
        var ilce = $("#change_ilceler option:selected").attr('value');
        if (il && ilce) {
            window.location.href = 'index.php?do=bayilerimiz&il='+il+'&ilce='+ilce;
        }else if (il && !ilce) {
            window.location.href = 'index.php?do=bayilerimiz&il='+il;
        }else if (!il && ilce) {
            window.location.href = 'index.php?do=bayilerimiz&ilce='+ilce;
        }else{
            window.location.href = 'index.php?do=bayilerimiz';
        }
    });
    $('#bayi_duzenle').click(function () {
        var bayi_id = $('#bayi_id').attr('value');
        window.location.href = 'index.php?do=yonetim&act=bayi_duzenle&id='+bayi_id;
    });
    $('#bayi_sil').click(function () {
        var bayi_id = $('#bayi_id').attr('value');
        var accept = confirm('Çıkmak istediğinize emin misiniz?');
        if (accept == true) {
            window.location.href = 'index.php?do=yonetim&act=bayi_sil&id='+bayi_id;
        }
    });
    $('.actions a.delete').click(function () {
        var accept = confirm('Silmek istediğinize emin misiniz?');
        if (accept == false) {
            return false;
        }
    });
    $('#contact_form').submit(function () {
        var contact_name_length = $('#contact_name').attr('value').length;
        var contact_email = $('#contact_email').attr('value').length;
        var contact_subject = $('#contact_subject').attr('value').length;
        var contact_message = $('#contact_message').attr('value').length;
        if (contact_name_length < 3) {
            alert('Lütfen Ad Soyad giriniz!');
            return false;
        }
        if (contact_email < 3) {
            alert('E-Posta adresiniz hatalı!');
            return false;
        }
        if (contact_subject < 3) {
            alert('Lütfen konu belirtiniz!');
            return false;
        }
        if (contact_message < 3) {
            alert('Lütfen mesaj belirtiniz!');
            return false;
        }
    });
});