
$(document).ready(function(){


       //Upload image_url 

       $(document).on('change', '#photo_url', function() {
        var name = document.getElementById("photo_url").files[0].name;
        var form_data = new FormData();
        var ext = name.split('.').pop().toLowerCase();
        if (jQuery.inArray(ext, ['pdf','jpeg','jpg','png']) == -1) {
            alert("Invalid Image File");
        }
        var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById("photo_url").files[0]);
        var f = document.getElementById("photo_url").files[0];
        var fsize = f.size || f.fileSize;
        if (fsize > 2000000) {
            alert("Image File Size is very big");
        } else {
            form_data.append("photo_url", document.getElementById('photo_url').files[
                0]);
            $.ajax({
                url: "upload.php",
                method: "POST",
                data: form_data,
                contentType: false,
                cache: false,
                processData: false,
                beforeSend: function() {
                    $('#uploaded_file_url').html(
                        "<label class='text-success'>Uploading...</label>");
                },
                success: function(data) {
                    $('#uploaded_file_url').html(data);
                }
            });
        }
    });


            // Upload file_url End

            //Upload adhaar_url 
            $(document).on('change', '#adhaar_url', function() {
                var name = document.getElementById("adhaar_url").files[0].name;
                var form_data = new FormData();
                var ext = name.split('.').pop().toLowerCase();
                if (jQuery.inArray(ext, ['gif', 'png', 'jpg', 'jpeg']) == -1) {
                    alert("Invalid Image File");
                }
                var oFReader = new FileReader();
                oFReader.readAsDataURL(document.getElementById("adhaar_url").files[0]);
                var f = document.getElementById("adhaar_url").files[0];
                var fsize = f.size || f.fileSize;
                if (fsize > 2000000) {
                    alert("Image File Size is very big");
                } else {
                    form_data.append("adhaar_url", document.getElementById('adhaar_url').files[
                        0]);
                    $.ajax({
                        url: "upload.php",
                        method: "POST",
                        data: form_data,
                        contentType: false,
                        cache: false,
                        processData: false,
                        beforeSend: function() {
                            $('#uploaded_adhaar_urls').html(
                                "<label class='text-success'>Uploading...</label>");
                        },
                        success: function(data) {
                            $('#uploaded_adhaar_urls').html(data);
                        }
                    });
                }
            });


// jQuery ajax form submit example, runs when form is submitted
$("#member").submit(function(e) {
    e.preventDefault(); // prevent actual form submit
    var form = $(this);
    var url = form.attr('action'); //get submit url [replace url here if desired]
    
    $("#btnAdd").val("Adding...");
    $("#btnAdd").prop('disabled', true);
    setInterval(function () {$("#btnLogin").prop('disabled', false);}, 3000);

    
        $.ajax({
            type: "POST",
            url: url,
            data: form.serialize(), // serializes form input
            success: function(data){

                console.log(data);
                $("#btnLogin").val("Add");

                $("#msg").html(data); 
                $("#msg").slideDown("slow");
                $("#msg").slideUp(3000,function(){ 
                if(!(data=="Please complete all required fields."))
                window.location.href="member-list.php";
                 });
                

            }
        });
    
});

$(".delete").click(function(e) {

    var id= $(this).attr("id");
    var url="member-action.php";
   
     $.ajax({
            type: "POST",
            url: url,
            data:{'id':id,'action':'Delete'}, // serializes form input
            success: function(data){

                location.reload();
            
            }
        });

});


	
});
 




