/*    $.LoadingOverlay("show", {

// Text

text                    : "Verifying Login",                                // String/Boolean

textAnimation           : "" ,                               // String/Boolean

textAutoResize          : true ,                             // Boolean

textResizeFactor        : 0.5 ,                              // Float

textColor               : "#202020"  ,                       // String/Boolean

textClass               : ""   ,                             // String/Boolean   

});



// Hide it after 3 seconds

setTimeout(function(){

$.LoadingOverlay("hide");

}, 3000);*/



 //---------------------------- loading functions -----------------------------

function LoadingStart(messsage)

{

	$.LoadingOverlay("show", {

		text                    : messsage,                                // String/Boolean

		textAnimation           : "" ,                               // String/Boolean

		textAutoResize          : true ,                             // Boolean

		textResizeFactor        : 0.5 ,                              // Float

		textColor               : "#ffffff"  ,                       // String/Boolean

		textClass               : ""   , 

		background      : "rgba(0, 0, 0, 0.5)",



		imageColor      : "#ffffff",

		size                    : 20     



		                          // String/Boolean   

	});

}



function LoadingEnd()

{

	setTimeout(function(){

		$.LoadingOverlay("hide");

	}, 500);

}





function fileInputCreate(){

	 var btnCust = '<button type="button" class="btn btn-secondary" title="Add picture tags" ' + 

        'onclick="alert(\'Call your custom code here.\')">' +

        '<i class="glyphicon glyphicon-tag"></i>' +

        '</button>'; 

    $("#user_image").fileinput({

        overwriteInitial: true,

        maxFileSize: 1500,

        maxFileCount: 5,

        showClose: false,

        showCaption: false,

        browseLabel: '',

        removeLabel: '',

        browseIcon: '<i class="glyphicon glyphicon-folder-open"></i>',

        removeIcon: '<i class="glyphicon glyphicon-remove"></i>',

        removeTitle: 'Cancel or reset changes',

        elErrorContainer: '#kv-avatar-errors-1',

        msgErrorClass: 'alert alert-block alert-danger',

        // defaultPreviewContent: '<img src="/uploads/default_avatar_male.jpg" alt="Your Avatar">',

        layoutTemplates: {main2: '{preview} ' +  btnCust + ' {remove} {browse}'},

        allowedFileExtensions: ["jpg", "png", "gif"]

    });



    $('#user_image').change(function(){

        console.log('user_image');

        $('.preview_profile_img').hide();

    });



    $('.fileinput-remove-button').click(function(){

        $('.preview_profile_img').show();

    })

}



//------------------------------- Webservice API Functiion Here --------------

var apiRequest={

	get:function (url, params, messsage = ''){

		var def = new $.Deferred();

		LoadingStart(messsage);

		$.ajax({

			url: url,

			type: 'GET',

			data: params,

			cache: false,

			//contentType: "application/json; charset=utf-8", 

			dataType: "json",

			headers: {

			    "Authorization": "Basic " + btoa(APIHeaderUsername + ":" + APIHeaderPassword)

			},

			success: function(data) {

				LoadingEnd();

				def.resolve(data,status); 

			},

			error: function (xhr, ajaxOptions, thrownError) {

				LoadingEnd();

				return def.reject(thrownError);

			}

		});

		return def.promise();

	},

	post:function (url, params, messsage = ''){

		var def = new $.Deferred();

		LoadingStart(messsage);

		$.ajax({

			url: url,

			type: 'POST',

			data: params,

			cache: false,

			//contentType: "application/json; charset=utf-8", 

			dataType: "json",

			headers: {

			    "Authorization": "Basic " + btoa(APIHeaderUsername + ":" + APIHeaderPassword)

			},

			success: function(data) {

				LoadingEnd();

				def.resolve(data,status); 

			},

			error: function (xhr, ajaxOptions, thrownError) {

				LoadingEnd();

				return def.reject(thrownError);

			}

		});

		return def.promise();

	},

	postFile:function (url, params, messsage = ''){

		var def = new $.Deferred();

		LoadingStart(messsage);

		$.ajax({

			url: url,

			type: 'POST',

			data: params,

			cache: false,

			//contentType: "application/json; charset=utf-8", 

			dataType: "json",

			contentType: false,

  			processData: false,

			headers: {

			    "Authorization": "Basic " + btoa(APIHeaderUsername + ":" + APIHeaderPassword)

			},

			success: function(data) {

				LoadingEnd();

				def.resolve(data,status); 

			},

			error: function (xhr, ajaxOptions, thrownError) {

				LoadingEnd();

				return def.reject(thrownError);

			}

		});

		return def.promise();

	},

}

// $(".toggle-password").click(function() {

//           $(this).toggleClass("fa-eye fa-eye-slash");

//           var input = $($(this).attr("toggle"));

//           if (input.attr("type") == "password") {

//             input.attr("type", "text");

//           } else {

//             input.attr("type", "password");

//           }

//         });

 $("body").on('click','.toggle-password',function(){
    $(this).toggleClass("fa-eye fa-eye-slash");

    var input = $($(this).attr("toggle"));

    if (input.attr("type") === "password") {
        input.attr("type", "text");
    } else {
        input.attr("type", "password");
    }
});

// Image Zoom Function

    $("#imgInp").change(function() {

      readURL(this);

    });

    function readURL(input){

        if (input.files && input.files[0]) {

            var reader = new FileReader();

            reader.onload = function(e) {

              $('#blah').attr('src', e.target.result);

            }

            reader.readAsDataURL(input.files[0]);

        }

    }

    function view_img(event,status){

        var image=$(event).attr('src');

        var href_var = $(event).parent().attr('href');

        $(href_var).fadeIn('fast');

        if(status == 'img'){

             $('#image_here').attr('src',image);

        }else{

             $('#image_here_new').attr('src',image);

        } 

    }

    function closePopup(){

        $('.open_my_popup').fadeOut('fast');

    }

    function view_img1(event,status){

        var image=$(event).attr('src');

        var href_var = $(event).parent().attr('href');

        $(href_var).fadeIn('fast');

        if(status == 'img'){

             $('#image_here1').attr('src',image);

        }else{

             $('#image_here_new1').attr('src',image);

        } 

    }

    function closePopup1(){

        $('.open_my_popup1').fadeOut('fast');

    }

$("#fileUpload").on('change', function () {



     //----------------- Image Preview and validation code start here -------------------



     var countFiles = $(this)[0].files.length;

     var imgPath = $(this)[0].value;

     var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();

     var image_holder = $("#image-holder");

     image_holder.empty();

     if (extn == "png" || extn == "jpg" || extn == "jpeg") {

         if (typeof (FileReader) != "undefined") {

             for (var i = 0; i < countFiles; i++) {

               var reader = new FileReader();

                 reader.onload = function (e) {

                     $(image_holder).attr('src', e.target.result);

                 }

                 image_holder.show();

                 reader.readAsDataURL($(this)[0].files[i]);

             }



         } else {

             $(this)[0].value='';

          Swal(

                {

                      title: 'Not valid',

                      text: 'This browser does not support FileReader.',

                      type: 'warning',

                      confirmButtonColor: '#3085d6',

                      confirmButtonText: 'ok'

                })

         }

     } else {

        $(this)[0].value='';

        Swal(

             {

                  title: 'Not valid',

                  text: 'You can choose only("jpeg","jpg","png")file',

                  type: 'warning',

                  confirmButtonColor: '#3085d6',

                  confirmButtonText: 'ok'

             })

      }

     //----------------- Image Preview and validation code end here -------------------




 });


// here sweat alert defination
    function swal_alert(title,messsage,url,icon){
        swal({
            title: title,
            text: messsage,
            icon: icon, //error, success, info
            button: "Ok",
        }).then((value) => {
            window.location.href=url;
        });
    }