var myid = 0;


$(document).ready(function () {
    $("#charity_list").hide();
	
    $('#modelpopforpasschange').click(function () {
        $.ajax({
            type: "POST",
            url: "function.php",
            data: "id=" + 1 + "&action=passwordChangeView",
            dataType: "json",
            success: function (data)
            {
                var name = data['user_name'];
                $('#chnusrnme').val(name);
                $('#myModalpass').modal('show');
            }
        });
    });
    $('#updatepassword').click(function () {
        var txt = $('#chnusrnme').val();
        var pass = $('#chnpass').val();
        $.ajax({
            type: "POST",
            url: "function.php",
            data: "user=" + txt + "&password=" + pass + "&action=passwordChange",
            dataType: "json",
            success: function (data)
            {
                $('#myModalpass').modal('hide');
                window.location.reload();
            }
        });
    });
   
    $(document).on('click', '.Editquetion', function () {
        var id = $(this).data('id');

        $.ajax({
            type: "POST",
            url: "function.php",
            data: "id=" + id + "&action=questionTitleView",
            dataType: "json",
            success: function (data)
            {
                myid = data['id'];
                var mytitle = data['title'];
                $('#valueoftheid').val(mytitle);
                $('#myModal').modal('show');
            }

        });


    });
    $(document).on('click', '.deletquetion', function () {
        var id = $(this).data('id');
        $.ajax({
            type: "POST",
            url: "function.php",
            data: "id=" + id + "&action=questionTitleView",
            dataType: "json",
            success: function (data)
            {
                myid = data['id'];
                mytitle = data['title'];
                $('#valueoftheid2').val(mytitle);
                $('#myModal2').modal('show');
            }

        });

    });

    $('#changetitle').click(function () {
        var mytitle = $('#valueoftheid').val();
        $.ajax({
            type: "POST",
            url: "function.php",
            data: "id=" + myid + "&title=" + mytitle + "&action=updateQuestionTitle",
            dataType: "json",
            success: function (data)
            {
                $('#myModal').modal('hide');
                location.reload(true)
            }

        });


    });

    $('#deletetitle').click(function () {
        $.ajax({
            type: "POST",
            url: "Deletetitle.php",
            data: "id=" + myid + "&action=questionTitleDelete",
            dataType: "json",
            success: function (data)
            {
                $('#myModal2').modal('hide');
                location.reload(true);
            }
        }, 2000);


    });

    $(document).on('click', '.editdrop', function () {
        var id = $(this).data('id');
        $.ajax({
            type: "POST",
            url: "charityListView.php",
            data: "id=" + id,
            dataType: "json",
            success: function (data)
            {
                myid = data['id'];
                var mytitle = data['value'];
                $('#dropvalue1').val(mytitle);
                $('#myModal3').modal('show');
            }

        });

    });

    $(document).on('click', '.deletedrop', function () {
        var id = $(this).data('id');
        $.ajax({
            type: "POST",
            url: "charityListView.php",
            data: "id=" + id,
            dataType: "json",
            success: function (data)
            {
                myid = data['id'];
                var mytitle = data['value'];
                $('#dropvalue2').val(mytitle);
                $('#myModal4').modal('show');
            }

        });

    });


    $('#editdropforsub').click(function () {
        var view = $('#dropvalue1').val();
        $.ajax({
            type: "POST",
            url: "function.php",
            data: "id=" + myid + "&title=" + view + "&action=charityUpdate",
            dataType: "json",
            success: function (data)
            {
                console.log("sss");
                window.location = "charity_list.php";
            }
        });
        $('#myModal3').modal('hide');
    });

    $('#deletedropforsub').click(function () {

        $.ajax({
            type: "POST",
            url: "function.php",
            data: "id=" + myid + "&action=deleteCharity",
            dataType: "json",
            success: function (data)
            {
                $('#myModal4').modal('hide');
                //location.reload(true);
                window.location.reload();
            }
        });


    });
    $('#insertitemtodrop').click(function () {
        $('#myModal5').modal('show');
    });
    $('#insertsubmission').click(function () {
        var txt = $('#insertvalue').val();
        $.ajax({
            type: "POST",
            url: "function.php",
            data: "mytxt=" + txt + "&action=insertCharity",
            dataType: "json",
            success: function (data)
            {
                $('#myModal5').modal('hide');
                window.location.reload();
            }
        }, 2000);
    });
});