$(document).ready(function () {
//    Functions To Initiate//
    $("body").on("click", ".clickable-row", clickRow);
    $(".searchModal").on("click", ".clickable-row", clickRow);
    $(".searchModal").on("focus", "td, th, tr, input", trFocus);
    $(".searchModal").on("blur", "td, th, tr, input", trBlur);
    $(".itemModal").on("focus", "td, th, tr, input", trFocus);
    $(".itemModal").on("blur", "td, th, tr, input", trBlur);

//    $('#example1').dataTable();
//    $('.tooltip-bottom').tooltip();
//    $(".focusfield").focus();
//    $('.select2').select2();
//    $('.mainpart').select2();
//    $('.detailpart').select2();
//    $('.fetchpart').select2();

    window.addEventListener('keydown', function (e) {
        if (e.keyIdentifier == 'U+000A' || e.keyIdentifier == 'Enter' || e.keyCode == 13) {
            if (e.target.nodeName == 'INPUT' && e.target.type == 'text') {
                e.preventDefault();
                return false;
            }
        }
    }, true);

    delShow();

    function delShow() {
        $.ajax({
            type: "GET",
            datatype: "json",
            url: "del_show.php",
            success: function (response) {
                if (response.success == true) {
                    $("#hdelete").hide();
                }
            },
            error: function (request, errorThrown, textStatus) {
                console.log(errorThrown);
            }
        });
    }

    $(".submit").click(function () {
        $(".submit").hide();
    });

    function clickRow() {
        window.document.location = $(this).data("href");
    }

    function trFocus() {
        $(this).closest("tr").focus();
        $(this).closest("tr").css("background-color", "#8CD0EE");
    }
    function trBlur() {
        $(this).closest("tr").css("background-color", "#FFFFFF");
    }

    // VALIDATIONS - START//

    $(".number").keydown(function (e) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
                // Allow: Ctrl+A, Command+A
                        (e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) ||
                        // Allow: home, end, left, right, down, up
                                (e.keyCode >= 35 && e.keyCode <= 40)) {
                    // let it happen, don't do anything
                    return;
                }
                // Ensure that it is a number and stop the keypress
                if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                    e.preventDefault();
                }
            });

    $('.alpha').keypress(function (e) {
        var regex = new RegExp("^[a-zA-Z ]+$");
        var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
        if (regex.test(str)) {
            return true;
        } else {
            e.preventDefault();
//                        alert('Please Enter Alphabate');
            return false;
        }
    });

    $("input").blur(function () {
        if ($(this).hasClass('PAN')) {
            var PanNo = $(this).val();
            var PanValidation = /^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/; // PAN validtion for Personal only	

            PanNo = PanNo.toUpperCase();
            $(this).val(PanNo);

            if (!PanValidation.test(PanNo)) {
                alert('Invalid PAN');
                $(this).val("");
            } else if (PanNo.length < 10) {
                alert('PAN Length Invalid');
                $(this).val("");
            } else {


            }
        }


        if ($(this).hasClass('mobileNo')) {
            if ($(this).val() != '') {
                var value = $(this).val();

                if (value.length < 15) {
                    alert('Invalid Number');
                    $(this).val("");
                } else if (value.substr(0, 1) == 9 || value.substr(0, 1) == 8 || value.substr(0, 1) == 7) {

                } else {

                }
            }
        }
        if ($(this).hasClass('email')) {
            var a = $(this).val();
            var filter = /^[A-Za-z0-9!#$%&\'*+-/=?^_`{|}~]+@[A-Za-z0-9-]+(\.[AZa-z0-9-]+)+[A-Za-z]$/;
            if (filter.test(a)) {

            } else {
                alert('Invalid Email');
                $(this).val("");
            }
        }
    });

    $('.alphanumaric').keypress(function isNumberCommaDot(evt) {
        var theEvent = evt || window.event;
        var key = theEvent.keyCode || theEvent.which;

        if (key === 9) { //TAB was pressed
            return;
        }

        key = String.fromCharCode(key);
        if (key.length == 0)
            return;
        var regex = /^[0-9a-zA-Z\9\b]*\.?[0-9]*$/;
                if (!regex.test(key)) {
            theEvent.returnValue = false;
            if (theEvent.preventDefault)
                theEvent.preventDefault();
        }
    });

    // VALIDATIONS - END  //
});