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


    var stuff_caftriaId = $('#stuff_caftriaId').val();
    if (stuff_caftriaId != 0) {
        //# change caftria dropdown value .
        $('#caftria_id').val(stuff_caftriaId).trigger('change');
        //# disable caftria dropdown to prevent user change caftria  .
        $('#caftria_id').prop('disabled', true);
        //# show caftria table .
        $('.tableContainer').addClass('hide');
        $('#tableCaf_' + stuff_caftriaId + '').removeClass('hide');
    }

    //# role change .
    var roleChange = function () {

        $('#role_id').on('change', function () {
            var thsVal = $(this).val();
            if (thsVal == '3' || thsVal == '2') {
                $('#caftriaDiv').removeClass('hide');
            } else {
                $('#caftriaDiv').addClass('hide');
            }
        });
    }
    var caftriaCustom = function () {

        $('#caftria_id').on('change', function () {
            var thsVal = $(this).val();
            if (thsVal == '') {
                thsVal = 0;
            }
            $('.tableContainer').addClass('hide');
            $('#tableCaf_' + thsVal + '').removeClass('hide');
        });
    }


    var appOrder = function () {
        //to open model for accept del
        $('.appOrder').click(function () {
            var itemid = $(this).attr('data-id');
            var orderDone = $(this).attr('data-done');
            var urlgo = $(this).attr('data-link');
            var action = $(this).attr('data-action');
            var golink;
            if (action == undefined) {
                golink = 'orderApprove';
            } else {
                golink = action;
            }
            bootbox.dialog({
                message: "هل تريد   تنفيذ هذا الطلب؟",
                title: "رساله تاكيد الطلب",
                buttons: {
                    danger: {
                        label: "الغاء",
                        className: "btn-danger"
                    },
                    main: {
                        label: "تأكيد",
                        className: "btn-primary",
                        callback: function () {
                            //do something else
                            window.location.href = hosturl + "/" + urlgo + "/" + golink + "/" + itemid + "/" + orderDone;
                        }
                    }
                }
            }).find('.modal-content').addClass('modal-sm');
        });
    }


    var deletemsg = function () {
        //to open model for accept del
        $('.deletemsg').click(function () {
            var itemid = $(this).attr('data-id');
            var urlgo = $(this).attr('data-link');
            var action = $(this).attr('data-action');
            var golink;
            if (action == undefined) {
                golink = 'del';
            } else {
                golink = action;
            }
            bootbox.dialog({
                message: "هل تريد حذف هذا العنصر؟",
                title: "رساله تاكيد الحذف",
                buttons: {
                    danger: {
                        label: "الغاء",
                        className: "btn-danger"
                    },
                    main: {
                        label: "حذف",
                        className: "btn-primary",
                        callback: function () {
                            //do something else
                            window.location.href = hosturl + "/" + urlgo + "/" + golink + "/" + itemid;
                        }
                    }
                }
            }).find('.modal-content').addClass('modal-sm');
        });
    }

    //menu vaildation
    var handleMenuValidation = function () {
        // 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
            }

        });

    }

    var rtnshow = function () {
        $(".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 + "/" + $controlname + "/show";
        });
    }


    var nestmenu = function () {
        $('#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
    var menuediticon = function () {
        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 addcontrollprop = function () {
        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">اسم الخدمه</label>'
                    + '<div class="col-md-4">'
                    + '<div class="input-icon right">'
                    + '<i class="fa fa-font"></i>'
                    + '<input type="text" class="form-control" placeholder="اسم الخدمه" name="proplabel' + propitr + '" required>'
                    + '</div>'
                    + '</div>'
                    + '</div>'
                    + '<div class="form-group col-md-4">'
                    + '<label class="col-md-3 control-label">الصلاحيه:</label>'
                    + '<div class="radio-list">'
                    + '<label class="radio-inline">'
                    + '<input type="radio" name="checkval' + propitr + '" id="checkval' + propitr + '" value="1" checked> مسموح </label>'
                    + '<label class="radio-inline">'
                    + '<input type="radio" name="checkval' + propitr + '" id="checkval' + propitr + '" value="0"> ممنوع </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 + '/_controll/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
    var handleControllValidation = function () {
        // 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 initcontrolprop3 = function () {

        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": "لا يوجد بيانات",
                "info": "عرض _START_ من _END_ الى _TOTAL_ عناصر",
                "infoEmpty": "لا يوجد بيانات",
                "infoFiltered": "(تنقيه _MAX_ من الاجمالى)",
                "lengthMenu": "عرض _MENU_ عنصر",
                        "search": "البحث:",
                "zeroRecords": "لا يوجد بيانات تشابه البحث"
            },
            "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
    }

    var initcontrolprop4 = function () {

        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": "لا يوجد بيانات",
                "info": "عرض _START_ من _END_ الى _TOTAL_ عناصر",
                "infoEmpty": "لا يوجد بيانات",
                "infoFiltered": "(تنقيه _MAX_ من الاجمالى)",
                "lengthMenu": "عرض _MENU_ عنصر",
                        "search": "البحث:",
                "zeroRecords": "لا يوجد بيانات تشابه البحث"
            },
            "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
    }
    var initcontrolprop5 = function () {

        var table_8 = $('.controllprop_8');
        // begin: third table
        table_8.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": "لا يوجد بيانات",
                "info": "عرض _START_ من _END_ الى _TOTAL_ عناصر",
                "infoEmpty": "لا يوجد بيانات",
                "infoFiltered": "(تنقيه _MAX_ من الاجمالى)",
                "lengthMenu": "عرض _MENU_ عنصر",
                        "search": "البحث:",
                "zeroRecords": "لا يوجد بيانات تشابه البحث"
            },
            "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
    var handleRoleValidation = function () {
        // 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
    var changerolemenugen = function () {
        //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
    var menuajaxsearcg = function () {
        $(".menuseach").keyup(function () {
            var searchword = $(this).val();

            $.post(hosturl + '/_menu/srcmenu', {searchword: searchword}, function (data) {

            });

        })
    }


    //member vaildation
    var handleMemberValidation = function () {
        // 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
                },
                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 = $("#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 + '/_member/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 + '/_member/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
                        }
                    }
                });


            }

        });

        var pageForm = $('#page_form');
        var pageFormError = $('.alert-danger', form3);
        var success3 = $('.alert-success', form3);


        pageForm.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: {
                caftriaId: {
                    required: true
                },
                name: {
                    required: true
                },
                image: {
                    required: true,
                },
//                content: {
//                    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();
                pageFormError.show();
                Metronic.scrollTo(pageFormError, -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.submit(); // submit the form

            }

        });


    }

    //check if there username
    var checksusers = function () {

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

            $.post(hosturl + '/_member/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 + '/_member/checkemail', {email: email, checkedit: checkedit}, function (data) {
                if (data.replace(/\s/g, "") == 'yes') {
                    $("#showerroremail").css({'display': 'block'});
                } else {
                    $("#showerroremail").css({'display': 'none'});
                }
            });

        })
    }

    //profile vaildation
    var handleprofileValidation = function () {
        // 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 + '/_myprofile/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 + '/_myprofile/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
    var checksprofile = function () {

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

            $.post(hosturl + '/_myprofile/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 + '/_myprofile/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();
            initcontrolprop4();
            initcontrolprop5();
            handleRoleValidation();
            changerolemenugen();
            menuajaxsearcg();
            handleMemberValidation();
            checksusers();
            handleprofileValidation();
            checksprofile();
            caftriaCustom();
            roleChange();
            appOrder();
            $('form').validate();

        }

    };

}();