
var awcustomjs = function () {

    //global hosturl
    var hosturl = $('#hosturl').val();




//############################################################################################################################################################
    //to open model for accept del
    $('.deletemsg').click(function () {
        var itemid = $(this).attr('data-id');
        var urlgo = $(this).attr('data-link');
        bootbox.dialog({
            message: "Do you want to delete this item?",
            title: "Delete confirmation",
            buttons: {
                danger: {
                    label: "Cancel",
                    className: "btn-primary"
                },
                main: {
                    label: "Delete",
                    className: "btn-danger",
                    callback: function () {
                        //do something else
                        window.location.href = hosturl + "/controllers/" + urlgo + ".php?ac=del&id=" + itemid;
                    }
                }
            }
        }).find('.modal-content').addClass('modal-sm');
    });

    $('body').on('click', '.deletemsgEX', function ()
    {
        var itemid = $(this).attr('data-id');
        var urlgo = $(this).attr('data-link');
        var fngo = $(this).attr('data-fn');
        var tableName = $(this).attr('data-tableName');
        var tr = $(this).parent().parent();
        bootbox.dialog({
            message: "Do you want to delete this item?",
            title: "Delete confirmation",
            buttons: {
                danger: {
                    label: "Cancel",
                    className: "btn-primary"
                },
                main: {
                    label: "Delete",
                    className: "btn-danger",
                    callback: function () {
                        //do something else
                        $.post(hosturl + '/controllers/' + urlgo + '.php?ac=' + fngo, {id: itemid, tableName: tableName}, function (res)
                        {
                            if (res == 1)
                            {
                                tr.remove();
                                var check_heigt_and_make_new_class = $(".check_heigt_and_make_new_class").height();
                                if (check_heigt_and_make_new_class < 400) {
                                    $(".check_heigt_and_make_new_class").removeClass("overflow_scroll");
                                }
                            }
                            else
                            {
                                alert("!!!!!!!!!!!!! some thing wrong here");
                            }
                        });
                    }
                }
            }
        }).find('.modal-content').addClass('modal-sm');
    });


    $('body').on('click', '.deletemsgEXDiv', function ()
    {
        var itemid = $(this).attr('data-id');
        var urlgo = $(this).attr('data-link');
        var fngo = $(this).attr('data-fn');
        var tableName = $(this).attr('data-tableName');
        var divName = $(this).attr('data-divName');
        var tr = $(this).parent().parent();
        bootbox.dialog({
            message: "Do you want to delete this item?",
            title: "Delete confirmation",
            buttons: {
                danger: {
                    label: "Cancel",
                    className: "btn-primary"
                },
                main: {
                    label: "Delete",
                    className: "btn-danger",
                    callback: function () {
                        //do something else
                        $.post(hosturl + '/controllers/' + urlgo + '.php?ac=' + fngo, {id: itemid, tableName: tableName}, function (res)
                        {
                            if (res == 1)
                            {
                                $('.' + divName).remove();
                                var check_heigt_and_make_new_class = $(".check_heigt_and_make_new_class").height();
                                if (check_heigt_and_make_new_class < 400) {
                                    $(".check_heigt_and_make_new_class").removeClass("overflow_scroll");
                                }
                            }
                            else
                            {
                                alert("!!!!!!!!!!!!! some thing wrong here");
                            }
                        });
                    }
                }
            }
        }).find('.modal-content').addClass('modal-sm');
    });


//############################################################################################################################################################

    $("input[name=genmenurole]:radio").change(function () {
        alert();
        $changeval = $(this).val();
        if ($changeval == 1) {
            $(".menuroleyes").prop("checked", true);
            $('.menuroleyes').attr('checked', 'checked');
            $('.menuroleno').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        } else {
            $(".menuroleno").prop("checked", true);
            $('.menuroleno').attr('checked', 'checked');
            $('.menuroleyes').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        }
    });
//############################################################################################################################################################
    //change status on controll by change all
    $("input[name=gencontrollrole]:radio").change(function () {
        $changeval = $(this).val();
        if ($changeval == 1) {
            $(".controllcheckyes").prop("checked", true);
            $('.controllcheckyes').attr('checked', 'checked');
            $('.controllcheckno').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        } else {
            $(".controllcheckno").prop("checked", true);
            $('.controllcheckno').attr('checked', 'checked');
            $('.controllcheckyes').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        }
    });

//############################################################################################################################################################
    //menu vaildation

    // for more info visit the official plugin documentation:
    // http://docs.jquery.com/Plugins/Validation

    var form3 = $('#menu_form');
    var error3 = $('.alert-danger', form3);
    var success3 = $('.alert-success', form3);


    form3.validate({
        errorElement: 'span', //default input error message container
        errorClass: 'help-block help-block-error', // default input error message class
        focusInvalid: false, // do not focus the last invalid input
        ignore: "", // validate all fields including form hidden input
        rules: {
            label: {
                required: true
            },
            link: {
                required: true
            },
            parent: {
                required: true
            },
            activename: {
                required: true
            }
        },
        errorPlacement: function (error, element) { // render error placement for each input type
            if (element.parent(".input-group").size() > 0) {
                error.insertAfter(element.parent(".input-group"));
            } else if (element.attr("data-error-container")) {
                error.appendTo(element.attr("data-error-container"));
            } else if (element.parents('.radio-list').size() > 0) {
                error.appendTo(element.parents('.radio-list').attr("data-error-container"));
            } else if (element.parents('.radio-inline').size() > 0) {
                error.appendTo(element.parents('.radio-inline').attr("data-error-container"));
            } else if (element.parents('.checkbox-list').size() > 0) {
                error.appendTo(element.parents('.checkbox-list').attr("data-error-container"));
            } else if (element.parents('.checkbox-inline').size() > 0) {
                error.appendTo(element.parents('.checkbox-inline').attr("data-error-container"));
            } else {
                error.insertAfter(element); // for other inputs, just perform default behavior
            }
        },
        invalidHandler: function (event, validator) { //display error alert on form submit
            success3.hide();
            error3.show();
            Metronic.scrollTo(error3, -200);
        },
        highlight: function (element) { // hightlight error inputs
            $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
        },
        unhighlight: function (element) { // revert the change done by hightlight
            $(element)
                    .closest('.form-group').removeClass('has-error'); // set error class to the control group

        },
        success: function (label) {
            label
                    .closest('.form-group').removeClass('has-error'); // set success class to the control group
        },
        submitHandler: function (form) {
            success3.show();
            error3.hide();
            form[0].submit(); // submit the form
        }

    });

//############################################################################################################################################################

    $(".rtnshow").click(function () {
        $controlname = $(this).attr("data-controll");
        // similar behavior as an HTTP redirect
        //window.location.replace(hosturl+"/index");
        // similar behavior as clicking on a link
        window.location.href = hosturl + "/controllers/" + $controlname + ".php?ac=show";
    });


//############################################################################################################################################################


    $('#nestable_list_2').nestable();

    $('#nestable_list_menu > button').on('click', function (e) {

        var actionn = $(this).attr("data-action");
        //var target = $(e.target),
        // action = target.data('action');
        if (actionn === 'expand-all') {
            $('.dd').nestable('expandAll');
        }
        if (actionn === 'collapse-all') {
            $('.dd').nestable('collapseAll');
        }
    });


//############################################################################################################################################################
    //here just run in menu edit

    if ($('#menuradioicon').length > 0) {
        var iconval = $("#menuiconvalue").val();

        $('input[type=radio][name=menuicon]').prop("checked", false);
        $('input[type=radio][name=menuicon]').removeAttr('checked');
        $('input[type=radio][name=menuicon][value=' + iconval + ']').prop("checked", true);
        $('input[type=radio][name=menuicon][value=' + iconval + ']').attr('checked', 'checked');

        $('input[type=radio][name=menuicon]').uniform();

    }

//############################################################################################################################################################
    //load prop

    var propitr = Number($('#propitr').val()) + 1;
    $('#myplusbtn').click(function () {
        $('#plusitemprop').append('<li class="list-group-item row nomargin">'
                + '<div class="form-group col-md-7">'
                + '<label class="col-md-3 control-label">Service name</label>'
                + '<div class="col-md-4">'
                + '<div class="input-icon right">'
                + '<i class="fa fa-font"></i>'
                + '<input type="text" class="form-control" placeholder="Service name" name="proplabel' + propitr + '" required>'
                + '</div>'
                + '</div>'
                + '</div>'
                + '<div class="form-group col-md-4">'
                + '<label class="col-md-3 control-label">Access:</label>'
                + '<div class="radio-list">'
                + '<label class="radio-inline">'
                + '<input type="radio" name="checkval' + propitr + '" id="checkval' + propitr + '" value="1" checked> Access </label>'
                + '<label class="radio-inline">'
                + '<input type="radio" name="checkval' + propitr + '" id="checkval' + propitr + '" value="0"> Deny </label>'
                + '</div>'
                + '</div>'
                + '<div class="col-md-1 pull-right">'
                + '<button type="button" class="btn spinner-down red minsprop">'
                + '<i class="fa fa-minus"></i>'
                + '</button>'
                + '</div>'
                + '</li>');

        $('input[name=checkval' + propitr + ']').uniform();

        propitr++;
        $('#propitr').val(propitr);


    })

    //remove the selected
    $('.minsprop').live('click', function () {
        //check for edit
        var editcheck = $(this).attr('data-edit');
        var propid = $(this).attr('data-id');
        if (editcheck == 0) {

            //here will delete by ajax
            $.post(hosturl + '/controllers/_controll.php?ac=delprop', {propid: propid}, function (data) {
                if (data == 1) {
                    var shortCutFunction = 'success';
                    var msg = 'Contiuno your job .. good';
                    var title = 'Success';
                } else {
                    var shortCutFunction = 'error';
                    var msg = 'Try again .. something wrong happened';
                    var title = 'Error';

                }
                toastr.options = {
                    closeButton: $('#closeButton').prop('checked'),
                    debug: $('#debugInfo').prop('checked'),
                    positionClass: $('#positionGroup input:checked').val() || 'toast-top-right',
                    onclick: null
                };
                var $toast = toastr[shortCutFunction](msg, title);
            })
        }

        $(this).parent().parent().remove();
    })

//############################################################################################################################################################
    //controll vaildation

    // for more info visit the official plugin documentation:
    // http://docs.jquery.com/Plugins/Validation

    var form3 = $('#controll_form');
    var error3 = $('.alert-danger', form3);
    var success3 = $('.alert-success', form3);


    form3.validate({
        errorElement: 'span', //default input error message container
        errorClass: 'help-block help-block-error', // default input error message class
        focusInvalid: false, // do not focus the last invalid input
        ignore: "", // validate all fields including form hidden input
        rules: {
            label: {
                required: true
            },
            name: {
                required: true
            }
        },
        errorPlacement: function (error, element) { // render error placement for each input type
            if (element.parent(".input-group").size() > 0) {
                error.insertAfter(element.parent(".input-group"));
            } else if (element.attr("data-error-container")) {
                error.appendTo(element.attr("data-error-container"));
            } else if (element.parents('.radio-list').size() > 0) {
                error.appendTo(element.parents('.radio-list').attr("data-error-container"));
            } else if (element.parents('.radio-inline').size() > 0) {
                error.appendTo(element.parents('.radio-inline').attr("data-error-container"));
            } else if (element.parents('.checkbox-list').size() > 0) {
                error.appendTo(element.parents('.checkbox-list').attr("data-error-container"));
            } else if (element.parents('.checkbox-inline').size() > 0) {
                error.appendTo(element.parents('.checkbox-inline').attr("data-error-container"));
            } else {
                error.insertAfter(element); // for other inputs, just perform default behavior
            }
        },
        invalidHandler: function (event, validator) { //display error alert on form submit
            success3.hide();
            error3.show();
            Metronic.scrollTo(error3, -200);
        },
        highlight: function (element) { // hightlight error inputs
            $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
        },
        unhighlight: function (element) { // revert the change done by hightlight
            $(element)
                    .closest('.form-group').removeClass('has-error'); // set error class to the control group

        },
        success: function (label) {
            label
                    .closest('.form-group').removeClass('has-error'); // set success class to the control group
        },
        submitHandler: function (form) {
            success3.show();
            error3.hide();
            form[0].submit(); // submit the form
        }

    });

//############################################################################################################################################################


    var table = $('#controllprop');

    // begin: third table
    table.dataTable({
        // Internationalisation. For more info refer to http://datatables.net/manual/i18n

        // Uncomment below line("dom" parameter) to fix the dropdown overflow issue in the datatable cells. The default datatable layout
        // setup uses scrollable div(table-scrollable) with overflow:auto to enable vertical scroll(see: assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js).
        // So when dropdowns used the scrollable div should be removed.
        //"dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",

        "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.

        "lengthMenu": [
            [15, 20, -1],
            [15, 20, "All"] // change per page values here
        ],
        // set the initial value
        "pageLength": 15,
        "language": {
            "lengthMenu": " _MENU_",
            "aria": {
                "sortAscending": ": Used to order Ascending",
                "sortDescending": ": Used to order Descending"
            },
            "emptyTable": "NO data",
            "info": "Show _START_ From _END_ To _TOTAL_ item",
            "infoEmpty": "No Data",
            "infoFiltered": "(Filter is _MAX_ from total)",
            "lengthMenu": "_MENU_",
                    "search": "",
            "zeroRecords": "No search data"
        },
        "columnDefs": [{// set default column settings
                'orderable': true,
                'targets': [0]
            }, {
                "searchable": false,
                "targets": [2, 3]
            }, {
                "orderable": false,
                "targets": [2, 3]
            }],
        "order": [
            [0, "asc"]
        ] // set first column as a default sort by asc
    });
    var tableWrapper = jQuery('#controllprop_wrapper');

    tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown


//############################################################################################################################################################
    //menu vaildation

    // for more info visit the official plugin documentation:
    // http://docs.jquery.com/Plugins/Validation

    var form3 = $('#role_form');
    var error3 = $('.alert-danger', form3);
    var success3 = $('.alert-success', form3);


    form3.validate({
        errorElement: 'span', //default input error message container
        errorClass: 'help-block help-block-error', // default input error message class
        focusInvalid: false, // do not focus the last invalid input
        ignore: "", // validate all fields including form hidden input
        rules: {
            name: {
                required: true
            }
        },
        errorPlacement: function (error, element) { // render error placement for each input type
            if (element.parent(".input-group").size() > 0) {
                error.insertAfter(element.parent(".input-group"));
            } else if (element.attr("data-error-container")) {
                error.appendTo(element.attr("data-error-container"));
            } else if (element.parents('.radio-list').size() > 0) {
                error.appendTo(element.parents('.radio-list').attr("data-error-container"));
            } else if (element.parents('.radio-inline').size() > 0) {
                error.appendTo(element.parents('.radio-inline').attr("data-error-container"));
            } else if (element.parents('.checkbox-list').size() > 0) {
                error.appendTo(element.parents('.checkbox-list').attr("data-error-container"));
            } else if (element.parents('.checkbox-inline').size() > 0) {
                error.appendTo(element.parents('.checkbox-inline').attr("data-error-container"));
            } else {
                error.insertAfter(element); // for other inputs, just perform default behavior
            }
        },
        invalidHandler: function (event, validator) { //display error alert on form submit
            success3.hide();
            error3.show();
            Metronic.scrollTo(error3, -200);
        },
        highlight: function (element) { // hightlight error inputs
            $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
        },
        unhighlight: function (element) { // revert the change done by hightlight
            $(element)
                    .closest('.form-group').removeClass('has-error'); // set error class to the control group

        },
        success: function (label) {
            label
                    .closest('.form-group').removeClass('has-error'); // set success class to the control group
        },
        submitHandler: function (form) {
            success3.show();
            error3.hide();
            form[0].submit(); // submit the form
        }

    });


//############################################################################################################################################################

    //change check with menu

    //change status on menu by change all
    $("input[name=genmenurole]:radio").change(function () {
        $changeval = $(this).val();
        if ($changeval == 1) {
            $(".menuroleyes").prop("checked", true);
            $('.menuroleyes').attr('checked', 'checked');
            $('.menuroleno').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        } else {
            $(".menuroleno").prop("checked", true);
            $('.menuroleno').attr('checked', 'checked');
            $('.menuroleyes').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        }
    });

    //change status on controll by change all
    $("input[name=gencontrollrole]:radio").change(function () {
        $changeval = $(this).val();
        if ($changeval == 1) {
            $(".controllcheckyes").prop("checked", true);
            $('.controllcheckyes').attr('checked', 'checked');
            $('.controllcheckno').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        } else {
            $(".controllcheckno").prop("checked", true);
            $('.controllcheckno').attr('checked', 'checked');
            $('.controllcheckyes').removeAttr('checked');
            $("input[type=radio]:not(.toggle, .star, .make-switch)").uniform();
        }
    });

//############################################################################################################################################################
    //serach ajax menu

    $(".menuseach").keyup(function () {
        var searchword = $(this).val();

        $.post(hosturl + '/controllers/_menu.php?ac=srcmenu', {searchword: searchword}, function (data) {

        });

    })

//############################################################################################################################################################

    //member vaildation

    // for more info visit the official plugin documentation:
    // http://docs.jquery.com/Plugins/Validation

    var form3 = $('#member_form');
    var error3 = $('.alert-danger', form3);
    var success3 = $('.alert-success', form3);


//    form3.validate({
//        errorElement: 'span', //default input error message container
//        errorClass: 'help-block help-block-error', // default input error message class
//        focusInvalid: false, // do not focus the last invalid input
//        ignore: "", // validate all fields including form hidden input
//        rules: {
//            name: {
//                required: true
//            },
//            username: {
//                required: true
//            },
//            password: {
//                required: true,
//                minlength: 6
//            },
//            confirmpassword: {
//                equalTo: '#password'
//            },
//            econfirmpassword: {
//                equalTo: '#epassword'
//            }
//
//        },
//        errorPlacement: function (error, element) { // render error placement for each input type
//            if (element.parent(".input-group").size() > 0) {
//                error.insertAfter(element.parent(".input-group"));
//            } else if (element.attr("data-error-container")) {
//                error.appendTo(element.attr("data-error-container"));
//            } else if (element.parents('.radio-list').size() > 0) {
//                error.appendTo(element.parents('.radio-list').attr("data-error-container"));
//            } else if (element.parents('.radio-inline').size() > 0) {
//                error.appendTo(element.parents('.radio-inline').attr("data-error-container"));
//            } else if (element.parents('.checkbox-list').size() > 0) {
//                error.appendTo(element.parents('.checkbox-list').attr("data-error-container"));
//            } else if (element.parents('.checkbox-inline').size() > 0) {
//                error.appendTo(element.parents('.checkbox-inline').attr("data-error-container"));
//            } else {
//                error.insertAfter(element); // for other inputs, just perform default behavior
//            }
//        },
//        invalidHandler: function (event, validator) { //display error alert on form submit
//            success3.hide();
//            error3.show();
//            Metronic.scrollTo(error3, -200);
//        },
//        highlight: function (element) { // hightlight error inputs
//            $(element)
//                    .closest('.form-group').addClass('has-error'); // set error class to the control group
//        },
//        unhighlight: function (element) { // revert the change done by hightlight
//            $(element)
//                    .closest('.form-group').removeClass('has-error'); // set error class to the control group
//
//        },
//        success: function (label) {
//            label
//                    .closest('.form-group').removeClass('has-error'); // set success class to the control group
//        },
//        submitHandler: function (form) {
//            success3.show();
//            error3.hide();
//
//            var username = $("#member_form #username").val();
//            var email = $("#member_form #email").val();
//            var checkedit = $("#member_form #email").attr('data-edit');
//            var editusername = $("#member_form #username").attr('data-edit');
//            var checkmail = false;
//            var checkusername = false;
//
//            //check username after vaildation
//            $.post(hosturl + '/controllers/_member.php?ac=checkusername', {username: username, editusername: editusername}, function (data) {
//                if (data.replace(/\s/g, "") == 'yes') {
//                    $("#showerrorusername").css({'display': 'block'});
//                    checkusername = false;
//                } else {
//                    $("#showerrorusername").css({'display': 'none'});
//                    checkusername = true;
//                    if (checkmail == true && checkusername == true) {
//                        form.submit(); // submit the form
//                    }
//
//                }
//            });
//
//
//            //check email after vaildation
//            $.post(hosturl + '/controllers/_member.php?ac=checkemail', {email: email, checkedit: checkedit}, function (data) {
//                if (data.replace(/\s/g, "") == 'yes') {
//                    $("#showerroremail").css({'display': 'block'});
//                    checkmail = false;
//                } else {
//                    $("#showerroremail").css({'display': 'none'});
//                    checkmail = true;
//                    if (checkmail == true && checkusername == true) {
//                        form.submit(); // submit the form
//                    }
//                }
//            });
//
//
//        }
//
//    });

//############################################################################################################################################################
    //check if there username


    $("#member_form #username").keyup(function () {
        var username = $(this).val();
        var editusername = $(this).attr('data-edit');

        $.post(hosturl + '/controllers/_member.php?ac=checkusername', {username: username, editusername: editusername}, function (data) {
            if (data.replace(/\s/g, "") == 'yes') {
                $("#showerrorusername").css({'display': 'block'});
            } else {
                $("#showerrorusername").css({'display': 'none'});
            }
        });

    })

//    $("#member_form #email").keyup(function () {
//        var email = $(this).val();
//        var checkedit = $(this).attr('data-edit');
//
//        $.post(hosturl + '/controllers/_member.php?ac=checkemail', {email: email, checkedit: checkedit}, function (data) {
//            if (data.replace(/\s/g, "") == 'yes') {
//                $("#showerroremail").css({'display': 'block'});
//            } else {
//                $("#showerroremail").css({'display': 'none'});
//            }
//        });
//
//    })

//############################################################################################################################################################
    //profile vaildation

    // for more info visit the official plugin documentation:
    // http://docs.jquery.com/Plugins/Validation

    var form3 = $('#myprofile_form');
    var error3 = $('.alert-danger', form3);
    var success3 = $('.alert-success', form3);


    form3.validate({
        errorElement: 'span', //default input error message container
        errorClass: 'help-block help-block-error', // default input error message class
        focusInvalid: false, // do not focus the last invalid input
        ignore: "", // validate all fields including form hidden input
        rules: {
            name: {
                required: true
            },
            email: {
                required: true,
                email: true
            },
            role: {
                required: true
            },
            username: {
                required: true
            },
            password: {
                required: true,
                minlength: 6
            },
            confirmpassword: {
                equalTo: '#password'
            },
            econfirmpassword: {
                equalTo: '#epassword'
            }

        },
        errorPlacement: function (error, element) { // render error placement for each input type
            if (element.parent(".input-group").size() > 0) {
                error.insertAfter(element.parent(".input-group"));
            } else if (element.attr("data-error-container")) {
                error.appendTo(element.attr("data-error-container"));
            } else if (element.parents('.radio-list').size() > 0) {
                error.appendTo(element.parents('.radio-list').attr("data-error-container"));
            } else if (element.parents('.radio-inline').size() > 0) {
                error.appendTo(element.parents('.radio-inline').attr("data-error-container"));
            } else if (element.parents('.checkbox-list').size() > 0) {
                error.appendTo(element.parents('.checkbox-list').attr("data-error-container"));
            } else if (element.parents('.checkbox-inline').size() > 0) {
                error.appendTo(element.parents('.checkbox-inline').attr("data-error-container"));
            } else {
                error.insertAfter(element); // for other inputs, just perform default behavior
            }
        },
        invalidHandler: function (event, validator) { //display error alert on form submit
            success3.hide();
            error3.show();
            Metronic.scrollTo(error3, -200);
        },
        highlight: function (element) { // hightlight error inputs
            $(element)
                    .closest('.form-group').addClass('has-error'); // set error class to the control group
        },
        unhighlight: function (element) { // revert the change done by hightlight
            $(element)
                    .closest('.form-group').removeClass('has-error'); // set error class to the control group

        },
        success: function (label) {
            label
                    .closest('.form-group').removeClass('has-error'); // set success class to the control group
        },
        submitHandler: function (form) {
            success3.show();
            error3.hide();

            var username = $("#myprofile_form #username").val();
            var email = $("#myprofile_form #email").val();
            var checkedit = $("#myprofile_form #email").attr('data-edit');
            var editusername = $("#myprofile_form #username").attr('data-edit');
            var checkmail = false;
            var checkusername = false;

            //check username after vaildation
            $.post(hosturl + '/controllers/_myprofile.php?ac=checkusername', {username: username, editusername: editusername}, function (data) {
                if (data.replace(/\s/g, "") == 'yes') {
                    $("#showerrorusername").css({'display': 'block'});
                    checkusername = false;
                } else {
                    $("#showerrorusername").css({'display': 'none'});
                    checkusername = true;
                    if (checkmail == true && checkusername == true) {
                        form.submit(); // submit the form
                    }

                }
            });


            //check email after vaildation
            $.post(hosturl + '/controllers/_myprofile.php?ac=checkemail', {email: email, checkedit: checkedit}, function (data) {
                if (data.replace(/\s/g, "") == 'yes') {
                    $("#showerroremail").css({'display': 'block'});
                    checkmail = false;
                } else {
                    $("#showerroremail").css({'display': 'none'});
                    checkmail = true;
                    if (checkmail == true && checkusername == true) {
                        form.submit(); // submit the form
                    }
                }
            });


        }

    });

//############################################################################################################################################################
    //check if there profile username


    $("#myprofile_form #username").keyup(function () {
        var username = $(this).val();
        var editusername = $(this).attr('data-edit');

        $.post(hosturl + '/controllers/_myprofile.php?ac=checkusername', {username: username, editusername: editusername}, function (data) {
            if (data.replace(/\s/g, "") == 'yes') {
                $("#showerrorusername").css({'display': 'block'});
            } else {
                $("#showerrorusername").css({'display': 'none'});
            }
        });

    })

    $("#myprofile_form #email").keyup(function () {
        var email = $(this).val();
        var checkedit = $(this).attr('data-edit');

        $.post(hosturl + '/controllers/_myprofile.php?ac=checkemail', {email: email, checkedit: checkedit}, function (data) {
            if (data.replace(/\s/g, "") == 'yes') {
                $("#showerroremail").css({'display': 'block'});
            } else {
                $("#showerroremail").css({'display': 'none'});
            }
        });

    })


//############################################################################################################################################################

    return {
        //main function to initiate the module
        init: function () {
            //deletemsg();
//            handleMenuValidation();
//            rtnshow();
//            nestmenu();
//            menuediticon();
//            //addcontrollprop();
//            handleControllValidation();
//            initcontrolprop3();
//            handleRoleValidation();
//            changerolemenugen();
//            menuajaxsearcg();
//            handleMemberValidation();
//            checksusers();
//            handleprofileValidation();
//            checksprofile();
            //deletemsgEx();
        }

    };

}();

