    var $files_upload = [];
    var $uptourl = '';
    var $callbackfunction = false;
    var $loding_html = '<span data-icon="&#xe982" class="loading"></span>';
    var $error_tpl = '<p class="text-%s text-left clearfix error_html">%s</p>';
    var $mask_tpl = '<div class="mask"></div>';
    var $maskupload_tpl = '<div class="maskupload"></div>';
    var $upload_file_tpl = '<input type="file" name="file_upload[]" class="uploadonclick" />';
    var $readfile_upload_tpl = '<input type="file" name="readfile_upload[]" class="readfileonclick" multiple />';
    var $alert_message_tpl = '<div class="modal fade message_modal"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> <h4 class="modal-title"> %s </h4> </div><div class="modal-body"> <h5>%s</h5> </div><div class="modal-footer"> <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">لا</button> <button type="button" class="btn btn-sm btn-primary message_action">نعم</button> </div></div></div></div>';
    var $tp_scroll_tpl = '<div class="tp-mask-scroll"><span class="tp-scroll"></span></div>';
    var $img_upload_tpl = '<div class="img_list"><input type="hidden" name="%s[]" value="%s"><img class="img-thumbnail" src="%s"><div class="buttons">%s</div></div>';
    var $pop_message_tpl = '<div class="pop_message"><p class="message_body"><span class="close"></span>%s</p></div>';
    var $input_checkbox = '<span class="input-checkbox checkbox-checked"><input type="checkbox" value="%s" name="%s"></span>';
    var $Notification_tpl = '<div class="Notification_tpl animated fadeInUp"><div class="alert alert-%s alert-dismissible fade show" role="alert"><strong>%s</strong><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div></div>';
    var $lang = new Array();
    (function ($) {

        $.LoadScript = function (src, _id = '') {
            if (src) {
                var NewScript = document.createElement('script');
                NewScript.setAttribute('type', 'text/javascript');
                NewScript.setAttribute('src', src);
                if (_id != '') {
                    NewScript.setAttribute('id', _id);
                }
                $('head').eq(0).append(NewScript);
        }
        };
        $.sprintf = function (format, etc) {
            var parameters = arguments;
            var i = 1;
            return format.replace(/%((%)|s)/g, function (b) {
                return b[2] || parameters[i++];
            });
        };
        $.pr = function (str, type) {
            if (type === true) {
                console.clear();
                console.log(str);
            } else {
                console.log("\n" + str);
            }
        };
        $.SetLang = function (lang_key, lang_data) {
            $lang[lang_key] = lang_data;
        };
        $.lang = function (key_name) {
            return $lang[key_name];
        };
        $.page_freeze = function () {
            $("textarea, input, button").attr({'disabled': 'disabled'});
            $("html, body").fadeTo(0, '0.50');
            $("body *").addClass('disabled');
            $("*").on('click, chenge, submit, keydown, keypress, keyup', function () {
                return false;
            });
        };
        $.trim = function (str) {
            return str.replace(/^\s+|\s+$/g, '');
        };
        $.stripcslashes = function (str) {
            str = String(str);
            return str.replace(/\\|\\+/g, '');
        };
        $.tohtml = function (str) {
            var $html = '<div class="convert_to_html" style=" display: none; visibility: hidden;"></div>';
            $('body').append($html);
            $('.convert_to_html').html(str);
            str = $('.convert_to_html').text();
            $('.convert_to_html').remove();
            return str;
        };
        $.Notification = function (options) {
            console.log(options);
            var settings = {
                'type': 'success',
                'text': 'هل تريد تنفيذ هذا الاجراء'
            };
            if (options) {
                $.extend(settings, options);
            }
            $('.Notification_tpl').remove();

            $('body').append($.sprintf($Notification_tpl, settings.type, settings.text));
            $('.Notification_tpl .close').on('click', function (key) {
                $('.Notification_tpl').remove();
            });
            setTimeout(function () {
                $('.Notification_tpl').remove();
            }, 5000);
        };
        $.alert_message = {
            'show': function (options) {
                var settings = {
                    'title': 'تحذير',
                    'text': 'هل تريد تنفيذ هذا الاجراء',
                    callback_function: function () {
                    },
                    opne_function: function () {
                    }
                };
                if (options) {
                    $.extend(settings, options);
                }
                $('.message_modal').remove();
                $('body').append($.sprintf($alert_message_tpl, settings.title, settings.text));
                settings.opne_function();
                $('.message_modal').modal('show');
                $('.message_action').off('click');
                $('.message_action').on('click', function () {
                    settings.callback_function();
                });
                $('*').on('keydown', function (key) {
                    if (key.keyCode == 27) {
                        $('.message_modal').modal('hide');
                    }
                });
            },
            'hide': function () {
                $('.message_modal').modal('hide');
            }
        };
        $.get_text_length = function (options) {
            var settings = {
                from_text: '.text_get_count',
                return_count: '.text_count'
            };
            if (options) {
                $.extend(settings, options);
            }

            var $this_text = null;
            var $this_count = null;
            if (typeof $(settings.from_text).eq(0).val() != 'undefined') {
                $this_text = $(settings.from_text).eq(0);
                $this_count = $(settings.return_count).eq(0);
                function get_length() {
                    var $string = String($this_text.val());
                    var $line_count = $string.match(/\n/g);
                    if ($line_count === null) {
                        $line_count = 0;
                    } else {
                        $line_count = $line_count.length;
                    }
                    $this_count.find(".count").text($this_text.val().length);
                    var $thistextlength = ($this_text.val().length + $line_count);
                    $this_count.find(".count").text($thistextlength);
                    var $max = $this_count.find(".max").val();
                    var $msg = $this_count.find(".max").attr('data-error');
                    $this_count.removeClass('text-danger');
                    $this_count.find(".count").text($thistextlength);
                    $this_count.find(".inline").text($.sprintf('متبقى %s حرف', ($max - $thistextlength)));
                    if ($thistextlength > $max) {
                        $this_count.find(".count").text($.sprintf($msg, $max));
                        $this_count.addClass('text-danger');
                    }
                }
                get_length();
                $(settings.from_text).on({
                    click: function () {
                        var $index = $(settings.from_text).index(this);
                        $this_text = $(settings.from_text).eq($index);
                        $this_count = $(settings.return_count).eq($index);
                        get_length();
                    },
                    change: function () {
                        var $index = $(settings.from_text).index(this);
                        $this_text = $(settings.from_text).eq($index);
                        $this_count = $(settings.return_count).eq($index);
                        get_length();
                    },
                    keyup: function () {
                        var $index = $(settings.from_text).index(this);
                        $this_text = $(settings.from_text).eq($index);
                        $this_count = $(settings.return_count).eq($index);
                        get_length();
                    },
                    keydown: function () {
                        var $index = $(settings.from_text).index(this);
                        $this_text = $(settings.from_text).eq($index);
                        $this_count = $(settings.return_count).eq($index);
                        get_length();
                    },
                    keypress: function () {
                        var $index = $(settings.from_text).index(this);
                        $this_text = $(settings.from_text).eq($index);
                        $this_count = $(settings.return_count).eq($index);
                        get_length();
                    }

                });
            }
        };
        $.get_fragment = function (data) {
            var $href = String(data);
            if ($href == 'undefined') {
                $href = String(location.href);
            }
            if ($href.match(/\#/g)) {
                $href = $href.split('#');
                return $href[1];
            } else {
                return false;
            }
        };


        $.ckedit = function (options) {
            var settings = {};
            if (options) {
                $.extend(settings, options);
            }

            for (i in settings) {
                try {

                    if ($('[name="' + settings[i] + '"]').length > 0) {
                        if ($('[name="' + settings[i] + '"]').attr("name") == settings[i]) {
                            var $toolbar = 'minitoolbar', $height = '200', $uiColor = '#EDEDED', $data_editor_language = 'ar';
                            if ($('[name="' + settings[i] + '"]').attr("data-toolbar") > "") {
                                $toolbar = $('[name="' + settings[i] + '"]').attr("data-toolbar");
                            }
                            if ($('[name="' + settings[i] + '"]').attr("data-height") > "") {
                                $height = $('[name="' + settings[i] + '"]').attr("data-height");
                            }
                            if ($('[name="' + settings[i] + '"]').attr("data-uiColor") > "") {
                                $uiColor = $('[name="' + settings[i] + '"]').attr("data-uiColor");
                            }
                            if ($('[name="' + settings[i] + '"]').attr("data-editor-language") > "") {
                                $data_editor_language = $('[name="' + settings[i] + '"]').attr("data-editor-language");
                            }
                            CKEDITOR.replace(settings[i], {
                                width: '100%',
                                height: $height,
                                uiColor: $uiColor,
                                language: $data_editor_language,
                                toolbar: $toolbar,
                                resize_enabled: true,
                                on: {
                                    instanceReady: function (ev) {
                                        this.dataProcessor.writer.setRules('p', {
                                            indent: true,
                                            breakBeforeOpen: false,
                                            breakAfterOpen: false,
                                            breakBeforeClose: false,
                                            breakAfterClose: false
                                        });
                                        this.dataProcessor.writer.setRules('div', {
                                            indent: true,
                                            breakBeforeOpen: false,
                                            breakAfterOpen: false,
                                            breakBeforeClose: false,
                                            breakAfterClose: false
                                        });
                                        this.dataProcessor.writer.setRules('font', {
                                            indent: true,
                                            breakBeforeOpen: false,
                                            breakAfterOpen: false,
                                            breakBeforeClose: false,
                                            breakAfterClose: false
                                        });
                                    }
                                }
                            });
                        }
                    }

                } catch ($e) {

                }

            }
        };
        $.pop_message = function (options) {
            var settings = {
                'text': '',
                'close': function () {
                },
                'open': function () {
                }
            };
            if (options) {
                $.extend(settings, options);
            }
            $('.pop_message').remove();
            $('body').addClass('freeze');
            $('body').append($.sprintf($pop_message_tpl, settings.text));

            setTimeout(function () {
                if ($('[data-type="error_register"]').length > 0) {
                    $.pr('5f4as5df4a65sdf', true);
                    $('[data-type="error_register"]').on('click', function () {
                    });
                }
            }, 100);

            $('*').on('keydown', function (e) {
                if (e.keyCode == "27" || e.keyCode == "8" || (e.keyCode == "37" && e.altKey == true)) {
                    $('.pop_message p').addClass('fadeOutUp');
                    $('.pop_message p').fadeOut(150);

                    setTimeout(function () {
                        $('.pop_message').remove();
                        $('body').removeClass('freeze');
                    }, 150);
                }
            });
            $('.message_body .close').on('click', function (e) {
                if (e.eventPhase == "2") {
                    $('.pop_message p').addClass('fadeOutUp');
                    $('.pop_message p').fadeOut(150);
                    setTimeout(function () {
                        $('.pop_message').remove();
                        $('body').removeClass('freeze');
                    }, 150);
                }
            });
            $('.message_body a').on('click', function () {
                $('.pop_message p').addClass('fadeOutUp');
                $('.pop_message p').fadeOut(150);
                setTimeout(function () {
                    $('.pop_message').remove();
                    $('body').removeClass('freeze');
                }, 150);
            });
        };
        $.dialogs = function (options) {
            var settings = {
                window_title: '',
                window_text: '',
                window_modal: true,
                whinclose: function () {
                },
                window_css: {},
                buttons: {},
                window_open: function () {
                }
            };
            if (options) {
                $.extend(settings, options);
            }
            var $html, $rand, $title, $text, $modal, $whinclose, $windowcss, $buttons, $window_open;
            $title = settings.window_title;
            $text = settings.window_text;
            $modal = settings.window_modal;
            $buttons = settings.buttons;
            $window_open = settings.window_open;
            $whinclose = settings.whinclose;
            $windowcss = settings.window_css;
            $rand = $rund_number = Math.ceil(Math.random() * 100);
            $html = '<div title="%s" class="dialogs_%s"><span>%s</span></div>';
            $html = $.sprintf($html, $title, $rand, $text);
            $("body").append($html);
            var $this = $(".dialogs_" + $rand);
            var $n = 0;
            for (i in $windowcss) {
                $n++;
            }
            if ($n > 0) {
                $this.css($windowcss);
            }
            $this.dialog({
                modal: $modal,
                close: $whinclose,
                buttons: $buttons,
                open: $window_open,
                width: 'auto'
            });
        };
        $.timer_down = function ($time) {
            var $datetime_now,
                    $seconds_new,
                    $datetime,
                    $time_remaining,
                    $return_year,
                    $return_month,
                    $return_day,
                    $return_hours,
                    $return_minutes,
                    $return_seconds,
                    $milliseconds;
            $datetime_now = new Date();
            $datetime = new Date($time);
            $seconds_new = $datetime_now.getSeconds();
            if ($datetime.getTime() > $datetime_now.getTime()) {
                $time_remaining = parseInt($datetime.getTime() - $datetime_now.getTime());
                $milliseconds = parseInt($time_remaining / 1000);
                $return_minutes = parseInt($time_remaining / 1000 / 60);
                $return_hours = parseInt($return_minutes / 60);
                $return_day = parseInt($return_hours / 24);
                $return_month = parseInt($return_day / 30);
                $return_year = parseInt($return_month / 12);
                $return_seconds = String($seconds_new - 59).replace("-", "");
                if ($return_seconds <= 9) {
                    $return_seconds = "0" + $return_seconds;
                }
                if ($return_minutes <= 119 && $return_minutes >= 60) {
                    $return_minutes = parseInt($return_minutes - 60);
                } else if ($return_minutes >= 120) {
                    $return_minutes = String(parseInt(($return_hours * 60) - $return_minutes)).replace('-', '');
                    if ($return_minutes < 1) {
                        $return_minutes = "59";
                        $return_hours = parseInt($return_hours - 1);
                    }
                }

                if ($return_minutes <= 9) {
                    $return_minutes = "0" + $return_minutes;
                }

                if ($return_hours <= 9) {
                    $return_hours = "0" + $return_hours;
                }
                return $return_hours + ":" + $return_minutes + ":" + $return_seconds;
            } else {
                return false;
            }

        };

        $.fn.SetDatePicker = function (options) {
            var settings = {
                changeMonth: true,
                changeYear: true,
                dateFormat: "yy-mm-dd",
                isRTL: true
            };
            if (options) {
                $.extend(settings, options);
            }
            $(this).datepicker(settings);
        };
        $.fn.loading = function (options) {
            var $this = $(this);
            $('.maskupload').remove();
            if (options !== false) {
                $this.append($maskupload_tpl);
                $('.maskupload').show(0);
                $('.maskupload').append($loding_html);
            } else {
                $('.maskupload').fadeOut(200, function () {
                    $('.maskupload').remove(0);
                });
            }
        };
        $.fn.btn_switc = function (options) {
            var settings = {
                'yes': 'Yes',
                'no': 'No'
            };
            if (options) {
                $.extend(settings, options);
            }

            var $this = $(this);
            $this.each(function (index) {
                var $this_name = $this.eq(index).attr("name");
                var $this_val = $this.eq(index).val();
                if ($this.eq(index).attr("data-val")) {
                    var $data_val = String($this.eq(index).attr("data-val"));
                    var $_val = $data_val.split("|");
                    settings.yes = $_val[0];
                    settings.no = $_val[1];
                }
                var $html = $.sprintf('<div class="switcher">\n\
							<span class="switch-text">' + settings.yes + '</span>\n\
							<span class="switch-handle"></span>\n\
							<input type="hidden" name="%s" id="%s" value="%s">\n\
						</div>', $this_name, $this_name, $this_val);
                $this.eq(index).replaceWith($html);
                if ($this_val === "1") {
                    $(".switcher").eq(index).addClass("toggle");
                    $(".switcher").eq(index).find(".switch-handle").addClass("toggle");
                    $(".switcher").eq(index).find(".switch-text").addClass("toggle");
                    $(".switcher").eq(index).find(".switch-text").text(settings.no);
                } else {
                    $(".switcher").eq(index).removeClass("toggle");
                    $(".switcher").eq(index).find(".switch-handle").removeClass("toggle");
                    $(".switcher").eq(index).find(".switch-text").removeClass("toggle");
                    $(".switcher").eq(index).find(".switch-text").text(settings.yes);
                }
            });
            $(".switcher").on('click', function () {
                if ($(this).attr('class').match(/disabled/g) === null) {
                    var $index = $(".switcher").index(this);
                    var $switcher = $(".switcher").eq($index);
                    var $btn = $(".switcher").eq($index).find('[type="hidden"]');
                    var $type = $btn.val();
                    if ($type === "1") {
                        $switcher.removeClass("toggle");
                        $switcher.find(".switch-handle").removeClass("toggle");
                        $switcher.find(".switch-text").removeClass("toggle");
                        $switcher.find(".switch-text").text(settings.yes);
                        $type = '0';
                        $btn.val($type);
                    } else {
                        $switcher.addClass("toggle");
                        $switcher.find(".switch-handle").addClass("toggle");
                        $switcher.find(".switch-text").addClass("toggle");
                        $switcher.find(".switch-text").text(settings.no);
                        $type = '1';
                        $btn.val($type);
                    }
                }
            });
        };
        $.fn.SetEditor = function (options) {
            var settings = {};
            if (options) {
                $.extend(settings, options);
            }

            var $this = $(this);
            if ($this.length > 0) {
                $this.contents().prop('designMode', 'on');
                $this.contents().on('keydown', function (key_event) {
                    $.pr(key_event, true);
                    $.pr(key_event.keyCode);
                });
            }
        };
        $.fn.checked = function (options) {
            var settings = {
                PHPDUTY_check_class: '.checkbox_this'
            };
            if (options) {
                $.extend(settings, options);
            }
            var $this = $(this);
            $this.on('change', function () {
                if ($this.prop("checked") === true) {
                    $('.row-data').addClass("warning");
                    $(settings.PHPDUTY_check_class).prop("checked", true);
                } else {
                    $('.row-data').removeClass("warning");
                    $(settings.PHPDUTY_check_class).prop("checked", false);
                }
                return false;
            });
        };



        $.fn.CheckBox = function (options, _callback = false) {
            var settings = {
                'checkall': true
            };
            if (options) {
                $.extend(settings, options);
            }
            var $this = $(this);
            $.each($this, function (ieq) {
                var $name = $this.eq(ieq).attr('name');
                var $val = $this.eq(ieq).val();
                var $checked = $this.eq(ieq).prop("checked");
                $this.eq(ieq).hide(2000);
                $this.eq(ieq).replaceWith($.sprintf($input_checkbox, $val, $name));
                if ($checked === false) {
                    $('.input-checkbox').eq(ieq).addClass('checkbox-unchecked');
                    $('.input-checkbox input').eq(ieq).prop("checked", false);
                } else {
                    $('.input-checkbox').eq(ieq).removeClass('checkbox-unchecked');
                    $('.input-checkbox input').eq(ieq).prop("checked", true);
                }
            });




            $('.input-checkbox').off('click');
            $('.input-checkbox').on('click', function () {
                var $ieq = $('.input-checkbox').index(this);
                $('.input-checkbox').eq($ieq).toggleClass('checkbox-unchecked');
                if ($('.input-checkbox input').eq($ieq).prop("checked") === false) {
                    $('.input-checkbox input').eq($ieq).prop("checked", true);
                } else {
                    $('.input-checkbox input').eq($ieq).removeAttr("checked");
                    $('.input-checkbox input').eq($ieq).prop("checked", false);
                }
            });
            $('.input-checkbox input').off('change');
            $('.input-checkbox input').on('change', function () {
                var $ieq = $('.input-checkbox input').index(this);
                var $checked = $('.input-checkbox input').eq($ieq).prop("checked");
                if ($checked === false) {
                    $('.input-checkbox').eq($ieq).addClass('checkbox-unchecked');
                    $('.input-checkbox input').eq($ieq).prop("checked", false);
                } else {
                    $('.input-checkbox').eq($ieq).removeClass('checkbox-unchecked');
                    $('.input-checkbox input').eq($ieq).prop("checked", true);
                }
            });



            if (settings.checkall == true) {

                $('.input-checkbox').eq(0).off('click');
                $('.input-checkbox').eq(0).off('change');
                $('.input-checkbox').eq(0).on('click', function () {

                    $('.input-checkbox input').eq(0).off('change');
                    $('.input-checkbox input').eq(0).on('change', function () {
                        var $checked = $('.input-checkbox input').eq(0).prop("checked");
                        if ($checked === false) {
                            $('.input-checkbox input').eq(0).prop("checked", true);
                            $('.input-checkbox').eq(0).removeClass('checkbox-unchecked');
                        } else {
                            $('.input-checkbox input').eq(0).prop("checked", false);
                            $('.input-checkbox').eq(0).addClass('checkbox-unchecked');
                        }

                        $.each($('.input-checkbox'), function (ieq) {
                            if (ieq > 0) {
                                $('.input-checkbox').eq(ieq).click();
                            }
                        });
                    });
                    $('.input-checkbox input').eq(0).change();
                });
            }
            if (_callback != false) {
                _callback();
            }
            return true;
        };
        $.fn.DragDropUpload = function (options) {
            var settings = {
                return_callback: null,
                toggle_class: 'DD_Upload',
                input_name: 'image_upload',
                other_html: '',
                max_upload: 10
            };
            if (options) {
                $.extend(settings, options);
            }
            var $this = $(this).eq($(this).index(this));
            if ($this.attr('max_upload')) {
                settings.max_upload = $this.attr('max_upload');
            }
            var $this_data_src = $this.attr('data-src');
            if ($this_data_src == 'undefined') {
                $this_data_src = '';
            }
            $this.on('dragover', function (event) {
                $this.addClass(settings.toggle_class);
                event.stopPropagation();
                event.preventDefault();
            });
            $this.on('dragleave', function (event) {
                $this.removeClass(settings.toggle_class);
                event.stopPropagation();
                event.preventDefault();
            });
            $this.bind('drop', function (event) {
                $this.removeClass(settings.toggle_class);
                event.stopPropagation();
                event.preventDefault();
                var $count_upload = 1;
                var $FilesDropToUpload = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
                var $formdata = new FormData();
                $.each($FilesDropToUpload, function (index, file_data) {
                    if ($this.find('.img_list').length < settings.max_upload) {
                        if ($count_upload <= settings.max_upload) {
                            var File_Reader = new FileReader();
                            $formdata.append('file_upload[]', file_data);
                            File_Reader.readAsDataURL($FilesDropToUpload[index]);
                            $count_upload++;
                        }
                    }
                });
                $('body').loading(true);
                $.ajax({
                    url: 'ajax/UpLoadFile/' + $this_data_src,
                    type: 'POST',
                    data: $formdata,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        var $json_date = $.parseJSON(data);
                        $.each($json_date, function ($img) {
                            var $img_url = $json_date[$img].replace(/\\/g, '');
                            $this.append($.sprintf($img_upload_tpl, settings.input_name, $img_url, $img_url, settings.other_html + '<span class="remove_this_img" data-icon="&#xe36b"></span>'));
                        });
                        $('body').loading(false);
                    }
                });
                $this.on('DOMSubtreeModified', function () {
                    $('.remove_this_img').off('click');
                    $('.remove_this_img').on('click', function () {
                        var $index = $('.remove_this_img').index(this);
                        $('.remove_this_img').eq($index).parent().parent().remove();
                    });
                });
            });
        };
        $.fn.upload = function (options) {
            var settings = {
                input_FileName: 'file_upload[]',
                callback_function: function () {
                }
            };
            if (options) {
                $.extend(settings, options);
            }
            $(this).on("click", function () {
                $(".start_upload").removeAttr("disabled");
                if ($(this).attr('data-element') == 'true') {
                    $callbackfunction = false;
                    $(".more_upload").hide(0);
                } else {
                    $callbackfunction = true;
                    $(".more_upload").show(0);
                }
                if ($(this).attr('data-src') != undefined) {
                    $uptourl = 'ajax/UpLoadFile/' + $(this).attr('data-src');
                } else {
                    $uptourl = 'ajax/UpLoadFile/other';
                }
            });
            var $this = $(".start_upload");
            $this.off('click');
            $this.on('click', function () {
                $(".result").html($loding_html);
                $(".loading").fadeIn(500);
                var $files = $(".upload_file");
                var $formdata = new FormData();
                $.each($files, function (iq, file_data) {
                    $.each($files[iq].files, function (i, files_d_date) {
                        $formdata.append(settings.input_FileName, files_d_date);
                    });
                });
                $.ajax({
                    type: 'POST',
                    url: $uptourl,
                    data: $formdata,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        $(".loading").fadeOut(500);
                        if ($callbackfunction == true) {
                            settings.callback_function(data);
                        } else {
                            var $json_date = jQuery.parseJSON(data);
                            var $file = $json_date[0];
                            $('.return_upload').val($file);
                            $('.img_return_upload').attr({'src': $file});
                            $('.upload_modal').modal('hide');
                        }
                        return false;
                    }

                });
            });
        };
        $.fn.UploadOnClick = function (options) {
            var settings = {
                input_File: 'file_upload[]',
                return_callback: false,
                callback_function: function () {
                }
            };
            if (options) {
                $.extend(settings, options);
            }
            var $this = $(this);
            $this.on('click', function () {
                $('.maskupload').remove();
                $(".uploadonclick").remove();
                var $index = $this.index(this);
                $('body').append($upload_file_tpl);
                $('body').append($maskupload_tpl);
                $('.maskupload').slideUp(0);
                var $uploadonclick = $('.uploadonclick');
                $uploadonclick.click();
                $uploadonclick.off('change');
                $uploadonclick.on('change', function () {
                    var $maskupload = $('.maskupload');
                    $maskupload.slideDown(0);
                    $maskupload.append($loding_html);
                    var $files = $("body > .uploadonclick");
                    var $uptourl = 'ajax/UpLoadFile/' + $this.eq($index).attr('data-src');
                    var $formdata = new FormData();
                    $.each($files, function (iq, file_data) {
                        $.each($files[iq].files, function (i, files_d_date) {
                            $formdata.append(settings.input_File, files_d_date);
                        });
                    });
                    $.ajax({
                        type: 'POST',
                        url: $uptourl,
                        data: $formdata,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                            $('.maskupload').remove();
                            $(".uploadonclick").remove();
                            var $json_date = $.parseJSON(data);
                            if (settings.return_callback == false) {
                                if ($json_date.success == true) {
                                    $('.return_upload').val($json_date.files[0]);
                                    $('.img_return_upload').attr({'src': $json_date.files[0]});
                                } else {
                                    settings.callback_function($json_date.files, $json_date.errors);
                                }
                            } else {
                                settings.callback_function($json_date.files, $json_date.errors);
                            }

                        }
                    });
                });
                $uploadonclick.on('click', function (events) {});
            });
        };
        $.fn.ReadUploadOnClick = function (options) {
            var settings = {
                return_callback: null,
                input_name: 'image_upload',
                other_html: '',
                max_upload: 10,
                return_files: '.get_upload_img'
            };
            if (options) {
                $.extend(settings, options);
            }

            var $this = $(this);
            var $this_data_src = $this.attr('data-src');
            if ($this_data_src == 'undefined') {
                $this_data_src = '';
            }
            if ($this.attr('max_upload')) {
                settings.max_upload = $this.attr('max_upload');
            }
            $this.on('click', function () {
                $('body').append($readfile_upload_tpl);
                var $readfileonclick = $('.readfileonclick');
                $readfileonclick.hide(0);
                $readfileonclick.click();
                $readfileonclick.on('change', function (change_event) {
                    var $count_upload = 1;
                    var $input_target = change_event.target;
                    var $formdata = new FormData();
                    $.each($input_target.files, function (file_index) {
                        if ($this.find('.img_list').length < settings.max_upload) {
                            if ($count_upload <= settings.max_upload) {
                                var File_Reader = new FileReader();
                                $formdata.append('file_upload[]', $input_target.files[file_index]);
                                File_Reader.readAsDataURL($input_target.files[file_index]);
                                $count_upload++;
                            }
                        }
                    });
                    $('body').loading(true);
                    var $json_date = null;
                    $.ajax({
                        url: 'ajax/UpLoadFile/' + $this_data_src,
                        type: 'POST',
                        data: $formdata,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                            $json_date = $.parseJSON(data);
                            if (settings.return_callback === null) {
                                $.each($json_date.files, function ($img) {
                                    var $img_url = $.stripcslashes($json_date.files[$img]);
                                    $(settings.return_files).append($.sprintf($img_upload_tpl, settings.input_name, $img_url, $img_url, settings.other_html + '<span class="remove_this_img" data-icon="&#xf00d"></span>'));
                                });
                            } else {
                                settings.return_callback($json_date);
                            }
                            $('body').loading(false);
                            $readfileonclick.remove();
                        }
                    });
                    $(settings.return_files).on('DOMSubtreeModified', function () {
                        $('.remove_this_img').off('click');
                        $('.remove_this_img').on('click', function () {
                            var $index = $('.remove_this_img').index(this);
                            $('.remove_this_img').eq($index).parent().parent().remove();
                        });
                    });
                    $readfileonclick.remove();
                });
            });
        };
        $.fn.DragDropUpload = function (options) {
            var settings = {
                return_callback: null,
                toggle_class: 'DD_Upload',
                input_name: 'image_upload',
                other_html: '',
                max_upload: 10
            };
            if (options) {
                $.extend(settings, options);
            }
            var $this = $(this).eq($(this).index(this));
            if ($this.attr('max_upload')) {
                settings.max_upload = $this.attr('max_upload');
            }
            var $this_data_src = $this.attr('data-src');
            if ($this_data_src == 'undefined') {
                $this_data_src = '';
            }
            $this.on('dragover', function (event) {
                $this.addClass(settings.toggle_class);
                event.stopPropagation();
                event.preventDefault();
            });
            $this.on('dragleave', function (event) {
                $this.removeClass(settings.toggle_class);
                event.stopPropagation();
                event.preventDefault();
            });
            $this.bind('drop', function (event) {
                $this.removeClass(settings.toggle_class);
                event.stopPropagation();
                event.preventDefault();
                var $count_upload = 1;
                var $FilesDropToUpload = event.originalEvent.target.files || event.originalEvent.dataTransfer.files;
                var $formdata = new FormData();
                $.each($FilesDropToUpload, function (index, file_data) {
                    if ($this.find('.img_list').length < settings.max_upload) {
                        if ($count_upload <= settings.max_upload) {
                            var File_Reader = new FileReader();
                            $formdata.append('file_upload[]', file_data);
                            File_Reader.readAsDataURL($FilesDropToUpload[index]);
                            $count_upload++;
                        }
                    }
                });
                $('body').loading(true);
                $.ajax({
                    url: 'ajax/UpLoadFile/' + $this_data_src,
                    type: 'POST',
                    data: $formdata,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        var $json_date = $.parseJSON(data);
                        $.each($json_date, function ($img) {
                            var $img_url = $json_date[$img].replace(/\\/g, '');
                            $this.append($.sprintf($img_upload_tpl, settings.input_name, $img_url, $img_url, settings.other_html + '<span class="remove_this_img" data-icon="&#xe36b"></span>'));
                        });
                        $('body').loading(false);
                    }
                });
                $this.on('DOMSubtreeModified', function () {
                    $('.remove_this_img').off('click');
                    $('.remove_this_img').on('click', function () {
                        var $index = $('.remove_this_img').index(this);
                        $('.remove_this_img').eq($index).parent().parent().remove();
                    });
                });
            });
        };
        $.fn.tpscroll = function (options) {
            var settings = {};
            if (options) {
                $.extend(settings, options);
            }

            var $this = $(this);
            $this.addClass('parent-tp-mask-scroll');
            $this.each(function (index) {
                var $this_index = $this.index(index);
                var $tp_prop = $this.eq($this_index).attr('data-tpscroll-align');
                var $tp_height = $this.eq($this_index).attr('data-tpscroll-height');
                /* add tp_scroll template */
                $this.eq($this_index).parent().append($tp_scroll_tpl);
                /* set height size */
                var $this_height = $this.eq(index).css('height');
                $this.eq(index).attr({
                    'oregnal_height': $this_height
                });
                $this.eq(index).css({
                    'height': $tp_height
                });
                /* set left class */
                if ($tp_prop == "left") {
                    $('.parent-tp-mask-scroll .tp-mask-scroll').addClass('left-scroll');
                }

                $this_height = parseInt(parseInt($this_height) / parseInt($tp_height));
                var $tp_mask_scroll = parseInt($('.tp-mask-scroll').eq(index).height() / $this_height);
                /* set tp-scroll height size */
                $('.tp-mask-scroll .tp-scroll').eq(index).css({'height': $tp_mask_scroll + 'px'})

            });
            $('.tp-mask-scroll .tp-scroll').off('mousedown');
            $('.tp-mask-scroll .tp-scroll').on('mousedown', function (scroll_event) {
                $('.tp-mask-scroll').on('mousemove', function (mask_event) {
                    var $tp_scroll_index = $('.tp-mask-scroll .tp-scroll').index(this);
                    var $tp_scroll = $('.tp-mask-scroll .tp-scroll').eq($tp_scroll_index);
                    var $tp_scroll_top = parseInt(mask_event.offsetY / 2);
                    $tp_scroll.css({'top': $tp_scroll_top + 'px'});
                    $('.parent-tp-mask-scroll').eq($tp_scroll_index).scrollTop($tp_scroll_top);
                });
            });
        };
        $.cookie = function (options, ctype) {
            var settings = {}
            var $cookiesname = options;
            if (options) {
                $.extend(settings, options);
            }
            if (ctype) {
                var $get_cookies = document.cookie.split(";");
                var $array_keys = Array();
                $.each($get_cookies, function ($key, $val) {
                    var k = new String($val);
                    k = k.replace(/^\s+|\s+$/g, "");
                    $array_keys[k.substr(0, k.indexOf("="))] = k.substr(k.indexOf("=") + 1);
                });
                return $array_keys[$cookiesname];
            } else {
                $.each(settings, function ($keys, $vals) {
                    document.cookie = $keys + "=" + $vals;
                });
            }
        };
        $.GoogleMapsAutocomplete = function (options, _callback = false) {
            var settings = {
                'AutoComplete': false,
                'MapConvas': 'map-canvas',
                'default_lat': 22.9862921,
                'default_lng': 55.0657185,
                'zoom': 17
            };



            settings.default_lat = parseFloat(settings.default_lat).value;
            settings.default_lng = parseFloat(settings.default_lng).value;
            settings.zoom = parseFloat(settings.zoom).value;

            if (options) {
                $.extend(settings, options);
            }


            window.initAutocomplete = function () {


                if (settings.AutoComplete != false) {
                    var autocomplete;
                    var uluru = {lat: settings.default_lat, lng: settings.default_lng};
                    var map = new google.maps.Map(
                            document.getElementById(settings.MapConvas), {zoom: settings.zoom, center: uluru});
                    var marker = new google.maps.Marker({position: uluru, map: map});


                    autocomplete = new google.maps.places.Autocomplete(document.getElementById(settings.AutoComplete), {types: ['geocode']});
                    autocomplete.setFields(['address_component']);
                    autocomplete.addListener('place_changed', function () {
                        if (navigator.geolocation) {
                            navigator.geolocation.getCurrentPosition(function (position) {
                                var geolocation = {
                                    lat: position.coords.latitude,
                                    lng: position.coords.longitude
                                };

                                marker.setPosition(new google.maps.LatLng(geolocation.lat, geolocation.lng));
                                google.maps.LatLng(geolocation.lat, geolocation.lng);

                                if (_callback != false) {
                                    _callback({
                                        'lat': geolocation.lat,
                                        'lng': geolocation.lng
                                    });
                                }


                            });
                        }

                    });


                    google.maps.event.addListener(map, 'click', function (event) {
                        var $lat = event.latLng.lat();
                        var $lng = event.latLng.lng();


                        var service = new google.maps.places.PlacesService(map);
                        service.nearbySearch({
                            location: {
                                lat: $lat,
                                lng: $lng
                            },
                            radius: 3
                        }, function (place, status) {
                            if (status == google.maps.places.PlacesServiceStatus.OK) {
                                map.fitBounds(new google.maps.LatLngBounds(
                                        new google.maps.LatLng($lat, $lng),
                                        new google.maps.LatLng($lat, $lng)
                                        ));

                                service.getDetails({
                                    placeId: place[0].place_id
                                }, function (place, status) {
                                    $('.map_postion').text('');
                                    if (status === google.maps.places.PlacesServiceStatus.OK) {
                                        $Event_data = {
                                            'place': place,
                                            'name': place.formatted_address,
                                            'lat': place.geometry.location.lat(),
                                            'lng': place.geometry.location.lng(),
                                            'events': google.maps.event
                                        };
                                        var $_text = $Event_data.name;

                                        $('.map_postion').text($_text);
                                        if (_callback != false) {
                                            _callback($Event_data);
                                        }
                                    }
                                });
                            }
                        });











                    });






















                }
            };


        };
    })(jQuery);