$.datepicker.setDefaults({
    dateFormat: 'mm/dd/yy'
});
$(function () {

    var start = moment().subtract(29, 'days');
    var end = moment();

    function cb(start, end) {
        $('.date-range-picker span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('.date-range-picker').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
            'Today': [moment(), moment()],
            'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
            'This Month': [moment().startOf('month'), moment().endOf('month')],
            'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

});
function setInputFilter(textbox, inputFilter) {
    ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function (event) {
        textbox.oldValue = "";
        textbox.addEventListener(event, function () {
            if (inputFilter(this.value)) {
                this.oldValue = this.value;
                this.oldSelectionStart = this.selectionStart;
                this.oldSelectionEnd = this.selectionEnd;
            } else if (this.hasOwnProperty("oldValue")) {
                this.value = this.oldValue;
                this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
            }
        });
    });
}

function validateEmail(email) {
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (filter.test(email)) {
        return true;
    }
    else {
        return false;
    }
}

function PicsUpload(file, image) {
    $(function () {
        $(file).change(function (event) {
            if (typeof (FileReader) != "undefined") {
                //var dvPreview = $(dv);
                var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
                $($(this)[0].files).each(function () {
                    var file = $(this);
                    if (regex.test(file[0].name.toLowerCase())) {
                        var reader = new FileReader();
                        reader.onload = function (e) {
                            var img = $(image);
                            //img.attr("style", "height:100px;width: 100px");
                            img.attr("src", e.target.result);
                            // alert(img);
                            //dvPreview.append(img);
                        }
                        reader.readAsDataURL(file[0]);
                    } else {
                        alert(file[0].name + " is not a valid image file.");
                        event.target.value = '';
                        $(image).attr("src", "");
                        return false;
                    }
                });
            } else {
                alert("This browser does not support HTML5 FileReader.");
            }
        });
    });
}

function MyAlert(Heading, Des, type, icon) {
    //$.notify({
    //    icon: icon,
    //    title: Heading,
    //    message: Des,
    //    globalPosition: 'bottom right',
    //}, {
    //    type: 'pastel-' + type + '',
    //    delay: 6000,
    //    icon_type: 'class',
    //    template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
    //        '<span data-notify="title" class="titlecolor"><i data-notify="icon"></i> {1}</span>' +
    //        '<span data-notify="message">{2}</span>' +
    //        '</div>'
    //});
    if (type == "success") {
        type = "notice";
    }
    $.growl({ title: Heading, message: Des, style: type });
}

function Error(Heading, Des, type, icon) {
    $.notify({
        icon: icon,
        title: Heading,
        message: Des,

    }, {
        type: 'pastel-' + type + ''
    });
}

function AjaxBlock(button) {
    var block_ele = $(button).closest('.card');
    $(block_ele).block({
        message: '<div class="icon-spinner9 icon-spin icon-lg"></div>',
        timeout: false, //unblock after 2 seconds
        overlayCSS: {
            backgroundColor: '#fff',
            opacity: 0.8,
            cursor: 'wait'
        },
        css: {
            border: 0,
            padding: 0,
            backgroundColor: 'transparent'
        }
    });
};

function AjaxBlock(button, message) {
    var block_ele = $(button).closest('.card');
    $(block_ele).block({
        message: '<div class="semibold"><span class="icon-spinner4 icon-spin text-left"></span>&nbsp; ' + message + ' ...</div>',
        timeout: false, //unblock after 2 seconds
        overlayCSS: {
            backgroundColor: '#fff',
            opacity: 0.8,
            cursor: 'wait'
        },
        css: {
            border: 0,
            padding: 0,
            backgroundColor: 'transparent'
        }
    });
};

function AjaxUnblock(button) {
    var block_ele = $(button).closest('.card');
    $(block_ele).unblock();
}

function IsNullZero(val) {
    if (val) {
        return val;
    }
    return 0;
}

function IsNullZeroAsInt(val) {
    if (val) {
        return parseInt(val);
    }
    return 0;
}

function IsNullZeroAsFloat(val) {
    if (val) {
        return parseFloat(val);
    }
    return 0;
}
//function GetWalletAmount() {
//    var bal;   
//    $.ajax({
//        url: "/Dashboard/GetUserBalance",
//        method: "GET",
//        success: function (response) {
//            if (response.success) {
//                 bal = response.balance;
//                document.getElementById("Balance").innerHTML = bal;
//                return bal;
//            }
//            else {
//                alert(response.message);
//            }
//        }
//    });
      
//}
$(document).ajaxStart($.blockUI({
    css: {
        border: 'none',
        padding: '15px',
        backgroundColor: '#000',
        '-webkit-border-radius': '10px',
        '-moz-border-radius': '10px',
        opacity: 0.5,
        color: '#fff'
    }
})).ajaxStop($.unblockUI());


$(document).ready(function () {

   

    $('.datetime').datetimepicker({ timeFormat: "hh:mm tt", timeInput: true, setDate: new Date(), dateFormat: 'mm/dd/yy' });
    $('.date').datepicker({ dateFormat: 'mm/dd/yy', timeInput: false });
    $(".select2").select2({
        width: '100%'
    });


    $('.block-msg-animation').on('click', function () {
        var block_ele = $(this).closest('.card');
        $(block_ele).block({
            message: '<div class="semibold"><span class="icon-spinner9 icon-spin text-left"></span>&nbsp; Loading ...</div>',
            fadeIn: 1000,
            fadeOut: 1000,
            timeout: 2000,
            overlayCSS: {
                backgroundColor: '#fff',
                opacity: 0.8,
                cursor: 'wait'
            },
            css: {
                border: 0,
                padding: '10px 15px',
                color: '#fff',
                width: 'auto',
                backgroundColor: '#333'
            }
        });
    });

   // GetWalletAmount();
});

