PageSourceSearch

https://mwathiq.sa/Scripts/common.js

js mwathiq.sa collected 2026-09-24 13:19:06 UTC 32,467 bytes, 840 lines download raw bytes

1var encrypterPrefix = 'e_';
2$(window).on('load',function () {
3    //store the selected tab when changed
4    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
5        var tabName = $(e.target).closest('ul.nav.nav-tabs').parent().attr('id');
6        tabName = tabName || 'lastTab';
7        if (tabName)
8            localStorage.setItem(tabName, $(e.target).attr('href'));
9    });
10
11    //color animation
12    fixPagingStyle();
13    //animateLoader();
14    confirmlinksinit();
15    confirmsubmitbuttonsinit();
16    tooltipfy();
17    datePickerInit();
18    //InitPopOver(); //script added in truncate helper
19    //update selected tabs from the local storage, if it exists:
20    updateSelectedTabs();
21
22    $('.only-number').filter_input({ regex: '[0-9Ù -Ù©]', selector: '.only-number' });
23    $('.only-number-sign').filter_input({ regex: '[0-9]', negkey: '-', selector: '.only-number-sign' });
24    $('.double').filter_input({ regex: /\d*\.?\d*/, selector: '.double' });
25    $('.double-witharabic').filter_input({ regex: '[\d\u0660-\u0669]+$', selector: '.double-witharabic' });
26    $('.arabic').filter_input({ regex: '[\u0600-\u06FF \\s ]*', selector: '.arabic' });
27    $('.arabicN').filter_input({ regex: '[[0-9\u0600-\u06FF \\s ]', selector: '.arabicN' });
28    $('.arabicNS').filter_input({ regex: '[0-9_\u0600-\u06FF \\s ()-]*', selector: '.arabicNS' });
29    $('.username').filter_input({ regex: '[0-9A-Za-z_]', selector: '.username' });
30    $('.english').filter_input({ regex: "[A-Za-z_ ']", selector: '.english' });
31    $('.englishN').filter_input({ regex: '[0-9A-Za-z_]', selector: '.englishN' });
32    $('.englishNS').filter_input({ regex: '[\x20-\x7E]', selector: '.englishNS' });
33    $('.numberAndChar').filter_input({ regex: '[0-9Ù -Ù©\x23-\x2F]', selector: '.numberAndChar' });
34    $('.EnglishWithSpace').filter_input({ regex: /^[a-zA-Z\s]*$/, selector: '.EnglishWithSpace' });
35
36    //Table Loader init
37    tabelLoader();
38
39    $(".message-area .close").click(function () {
40        $(this).closest("div").slideUp(300, '', function () {
41            // Animation complete.
42        });
43    });
44
45    $(".message-area").find("label").each(function (i, val) {
46        if ($.trim($(this).text()).length > 2) {
47            ShowMessage($(this).closest("div"));
48        }
49    });
50
51    //for one time submit button
52    $('input[type="submit"].click-once , button[type="submit"].click-once').click(function () {
53        $(this).attr('disabled', 'disabled');
54        var myForm = $(this).parents('form:first');
55        if ($(this).attr('name') && $(this).attr('value')) {
56            if ($("input[type='hidden'][name='" + $(this).attr('name') + "']").length) {
57                $("input[type='hidden'][name='" + $(this).attr('name') + "']").val($(this).val());
58            }
59            else {
60                $('<input />').attr('type', 'hidden')
61                    .attr('name', $(this).attr('name'))
62                    .attr('value', $(this).val())
63                    .appendTo(myForm);
64            }
65        }
66
67        myForm.submit();
68        if (!myForm.valid()) {
69            $(this).removeAttr('disabled');
70            $(this).removeClass('disabled');
71        }
72        return false;
73    });
74
75    $(document).on('hidden.bs.modal', '.modal-confirm', function (e) {
76        $(this).remove();
77    });
78});
79
80$(function () {
81    $(document).on('keyup', 'input', function () {
82        var text = this.value;
83
84        if (text.indexOf('>') != -1) {
85            mciMessage("<  >غير مسموح بها.", mciMessageType.Warning);
86            this.value = "";
87        }
88
89        if (text.indexOf('<') != -1) {
90            mciMessage("<  >غير مسموح بها.", mciMessageType.Warning);
91            this.value = "";
92        }
93    });
94
95    $(document).on('keyup', 'textarea', function () {
96        if ($(this).attr('id') != "Comment") {
97            var text = this.value;
98
99            if (text.indexOf('>') != -1) {
100                mciMessage("<  >غير مسموح بها.", mciMessageType.Warning);
101                this.value = "";
102            }
103
104            if (text.indexOf('<') != -1) {
105                mciMessage("<  >غير مسموح بها.", mciMessageType.Warning);
106                this.value = "";
107            }
108        }
109    });
110});
111
112//Global Ajax  Handler
113$(document).bind("ajaxSend", function (e, xhr, settings) {
114    //Sent
115}).bind("ajaxComplete", function (e, xhr, settings) {
116    //Complete
117    tooltipfy();
118    fixPagingStyle();
119    tabelLoader();
120
121    var button = $(this).find('.unlockme');
122    setTimeout(function () {
123        button.removeClass("unlockme");
124        button.removeAttr('disabled');
125    }, 1);
126
127}
127).bind("ajaxSuccess", function (e, xhr, settings) {
128    //Success
129    try {
130        var resultParesed = JSON.parse(xhr.responseText);
131        JSRedirect(resultParesed);
132    }
133    catch (re) { }
134}).bind("ajaxError", function (e, xhr, settings, thrownError) {
135    //Error
136    if (xhr.responseJSON) {
137        if (xhr.responseJSON.UnExpectedBehaviourShowCaptcha) {
138            UnExpectedBehaviourShowCaptcha();
139        }
140        if (xhr.responseJSON.CompaniesPrivilegesException) {
141            CompaniesPrivilegesExceptionModal(xhr.responseJSON.CompanyCrNumber, xhr.responseJSON.actionKey);
142        }
143    }
144    //if (xhr.status == '401' || xhr.status == "403") {
145    //    window.location = window.location;
146    //}
147});
148
149//to hide validation mess onclick
150$(document).on("click", ".field-validation-error", function () {
151    $(this).fadeOut(function () {
152        $(this).removeAttr("style");
153        $(this).addClass("field-validation-valid").removeClass("field-validation-error");
154    });
155});
156
157$(document).on("click", ".btnRefresh", function () {
158    location.reload();
159});
160
161
162$(document).on('change', 'select[data-ajax="true"]', function (event) {
163    var selectedValue = $(this).val();
164    var method = $(this).data('ajax-method') || 'GET';
165    var begin = $(this).data('ajax-begin');
166    var success = $(this).data('ajax-success');
167    var failure = $(this).data('ajax-failure');
168    var complete = $(this).data('ajax-complete');
169    var loading = $(this).data('ajax-loading');
170    var duration = $(this).data('ajax-loading-duration') || 0;
171    var mode = $(this).data('ajax-mode');
172    var update = $(this).data('ajax-update');
173    var url = $(this).data('ajax-url');
174    var addData = $(this).data('ajax-dataprovider');
175
176    //replace value on the url
177    url = url.replace('%25value%25', encodeURIComponent(selectedValue));
178
179    //add additional data if any
180    if (addData) {
181        var fn = new Function('return ' + addData + '();');
182        var data = fn();
183        if (data) {
184            url += url.indexOf('?') == -1 ? '?' : '';
185            for (var key in data) {
186                url += '&';
187                url += key + '=' + encodeURIComponent(data[key]);
188            }
189        }
190    }
191
192    $.ajax({
193        type: method.toUpperCase(),
194        url: url,
195        beforeSend: function () {
196            //call onBegin
197            var returnValue = executeFunction(begin);
198            if (returnValue == false)
199                return false;
200            //show loader
201            if (loading)
202                $(loading).show(duration);
203        },
204        error: function (res, status, error) {
205            if (failure) {
206                var fn = new Function('res', 'status', 'error', failure + '(res, status, error);');
207                fn(res, status, error);
208            }
209        },
210        success: function (result) {
211            //update target
212            if (update) {
213                switch (mode) {
214                    case 'after':
215                        $(update).after(result);
216                        break;
217                    case 'before':
218                        $(update).before(result);
219                        break;
220                    default:
221                        $(update).html(result);
222                        break;
223                }
224            }
225
226            //call success
227            if (success) {
228                var fn = new Function('result', success + '(result);');
229                fn(result);
230            }
231        },
232        complete: function () {
233            if (loading)
234                $(loading).hide();
235
236            //execute complete
237            executeFunction(complete);
238        }
239    });
240});
241
242$(document).on('invalid-form.validate', 'form', function () {
243    var button = $(this).find('.unlockme');
244    setTimeout(function () {
245        button.removeClass("unlockme");
246        button.removeAttr('disabled');
247    }, 1);
248});
249$(document).on('submit', 'form', function () {
250    var button = $(this).find('input[type="submit"],button[type="submit"]');
251    setTimeout(function () {
252        button.addClass("unlockme");
253        button.attr('disabled', 'disabled');
254    }, 0);
255});
256
257$(document).on("click", "[data-hide]", function () {
258    $(this).closest($(this).attr("data-hide")).hide();
259});
260
261$(document).on("click", ".mci-popover[data-toggle='modal']", function () {
262    var randomId = Math.floor((Math.random() * 1000000) + 1);
263    var title = $(this).data('title');
264    var content = $(this).data('content');
265    var modal = buildModal(randomId, title, content, '').replace('modal-sm', '');
266    $(modal).modal({ backdrop: "static", show: true });
267});
268
269function fixPagingStyle(gridID) {
270    var sel;
271    if (gridID) {
272        sel = $("#" + gridID + " .footerGrid td");
273    }
274    else {
275        sel = $(".footerGrid td");
276    }
277    //check if code is not excuted before
278    if (sel.find(".pagination").length == 0) {
279        sel.find("a").wrap("<li />");
280        sel.contents().filter(function () {
281            return (this.nodeType === 3 && this.data.trim().length)
282        })
283            .wrap('<li class="active" />').wrap("<a />");
284
285        sel.wrapInner('<ul class="pagination" />');
286    }
287}
288
289function tabelLoader() {
290    $(".grid a[data-swhglnk=true]").click(function () {
291        grid = $(this).closest(".grid");
292        var modal = $('<div class="table-modal-back" />');
293        modal.css("width", grid.css("width"));
294        modal.css("height", grid.css("height"));
295        modal.append('<div style="position: absolute; left: 50%;top:40%"><div style="position: relative; left: -50%;"><img src="' + $("#root").attr("href") + 'Content/images/loading32.gif"   /></div></div>');
296        grid.append(modal);
297        //obj.append('<div class="modal-back"><div class="animated-th"></div></div>');
298    });
299}
300
301function onFailureDefault(req, status, error) {
302    $('.modal').modal('hide');
303    mciMessage(req.responseJSON.message, mciMessageType.Danger, 10);
304}
305
306function init_validators(formSelector) {
307    var selector = formSelector || 'form';
308    $(selector).removeData("validator");
309    $(selector).removeData("unobtrusiveValidation");
310    //$(selector).each(function () {
311    //    $.data($(this)[0], 'validator', undefined);
312    //});
313    $.validator.unobtrusive.parse(selector);
314}
315
316function changeValidationErrorMessageFor(selector, method, newMessage) {
317    var $element = $(selector);
318    if ($element.length) {
319        var $form = $element.closest('form');
320        if ($form.length) {
321            var validator = $form.data('validator');
322            if (validator) {
323                var m = validator.settings.messages[$element.attr('name')];
324                if (m)
325                    m[method] = newMessage;
326            }
327        }
328    }
329}
330
331function renderModelStateErrors(formSelector, modelStateErrors, scrollToFirst) {
332    var validator = $(formSelector).data('validator');
333    if (!validator || !modelStateErrors) return;
334    var toScroll;
335    for (var i = 0; i < modelStateErrors.length; i++) {
336        var element = $('#' + modelStateErrors[i].key)[0];
337        if (!element) //try to get encrypted version
338            element = $('#' + encrypterPrefix + modelStateErrors[i].key)[0];
339        if (!element) continue;
340        toScroll = $(element);
341        validator.settings.highlight.call(validator, element, validator.settings.errorClass, validator.settings.validClass);
342        validator.showLabel(element, modelStateErrors[i].value);
343    }
344    try {
345        if (scrollToFirst) {
346            $('html, body').animate({
347                scrollTop: toScroll.offset().top
348            }, 500);
349        }
350    } catch (e) {
351    }
352}
353
354function JSRedirect(result) {
355    if (result.url) {
356        window.location.href = result.url;
357        return false;
358    }
359}
360
361function clearForm(formSelector) {
362    formSelector = formSelector || 'form';
363    //clear uploader if exist
364    var $uploaderContainer = $(formSelector).find($('.file_uploader'));
365    if ($uploaderContainer.length) {
366        $(formSelector).find($('.file_uploader_message')).empty();
367        $uploaderContainer.show();
368        $uploaderContainer.fineUploader('reset');
369    }
370    //clear other inputs
371    $(formSelector).find(':input:not(:hidden)').each(function () {
372        if ($(this).css("visibility") === "hidden") return;
373
374        switch (this.type) {
375            case 'password':
376            case 'select-multiple':
377                {
378                    $(this).val('');
379                    if ($(this).hasClass('select2-offscreen'))
380                        $(this).trigger('change');
381                }
382            case 'select-one':
383                this.selectedIndex = 0;
384                if ($(this).hasClass('select2-offscreen'))
385                    $(this).trigger('change');
386                break;
387            case 'text':
388            case 'textarea':
389                $(this).val(' ');
390                $(this).val('');
391                break;
392            case 'checkbox':
393            case 'radio':
394                this.checked = false;
395        }
396        $(this).removeClass("input-validation-error");
397    });
398    $(formSelector + " .field-validation-error").removeClass("field-validation-error").addClass("field-validation-valid");
399}
400
401function resetUploader(uploaderId) {
402    var uploaderSelector = "#" + uploaderId + "_attachement_div";
403    $(uploaderSelector).find($('.file_uploader_message')).empty();
404    $(uploaderSelector).find($('.file_uploader')).show();
405    $(uploaderSelector).find($('.file_uploader')).fineUploader('reset');
406}
407
408function animateLoader() {
409    $('.waiting-modal span').animate({ color: '#D89312' });
410    $('.waiting-modal span').animate({ color: '#D89312' });
411    $('.waiting-modal span').animate({ color: '#47896A' });
412    $('.waiting-modal span').animate({ color: '#47896A' });
413    $('.waiting-modal span').animate({ color: '#D89312' });
414    $('.waiting-modal span').animate({ color: '#D89312' });
415    setTimeout(animateLoader, 1500);
416}
417
418function executeFunction(functionName) {
419    if (functionName) {
420        var fn = window[functionName];
421        if (typeof fn === "function") return fn();
422    }
423}
424
425function tooltipfy() {
426    $('[data-toggle="tooltip"]').tooltip();
427}
428
429function InitPopOver() {
430    $('[data-toggle="popover"]').popover({ sanitize: false });
431}
432
433function datePickerInit(selecter) {
434    var selecterAr = selecter ? selecter + '.datepicker' : '.datepicker';
435    var selecterGreg = selecter ? selecter + '.datepicker-greg' : '.datepicker-greg';
436    var selecterMix = selecter ? selecter + '.datepicker-mix' : '.datepicker-mix';
437
438    $(selecterAr + ',' + selecterMix).each(function () {
439        var range = $(this).attr('data-year-range') || 'c-20:c+20';
440        var minimumDate = $(this).attr('min-Date') || null;
441        var maximumDate = $(this).attr('max-Date') || null;
442        var onSelectFunction = $(this).attr('onSelectFunction');
443
444        $(this).calendarsPicker({
445            calendar: $.calendars.instance('ummalqura', 'ar'),
446            dateFormat: 'dd/mm/yyyy',
447            yearRange: range,
448            minDate: minimumDate, //'25/12/1436',
449            maxDate: maximumDate, //'06/01/1437',
450            showOtherMonths: true,
451            showTrigger: '#calImg',
452            prevText: '<span class="glyphicon glyphicon-chevron-left"></span>', prevStatus: 'عرض الشهر السابق',
453            prevJumpText: '&#x3e;&#x3e;', prevJumpStatus: '',
454            nextText: '<span class="glyphicon glyphicon-chevron-right"></span>', nextStatus: 'عرض الشهر القادم',
455            nextJumpText: '&#x3c;&#x3c;', nextJumpStatus: '',
456            currentText: 'اليوم', currentStatus: 'عرض الشهر الحالي',
457            todayText: 'اليوم', todayStatus: 'عرض الشهر الحالي',
458            clearText: '<span class="glyphicon glyphicon-remove"></span>', clearStatus: 'امسح التاريخ الحالي',
459            closeText: '<span class="glyphicon glyphicon-chevron-up"></span>', closeStatus: 'إغلاق بدون حفظ',
460            yearStatus: 'عرض سنة آخرى', monthStatus: 'عرض شهر آخر',
461            weekText: 'أسبوع', weekStatus: 'أسبوع السنة',
462            dayStatus: 'اختر D, M d', defaultStatus: 'اختر يوم',
463            onSelect: function (date) { if (onSelectFunction != undefined) { window[onSelectFunction](date); } },
464        });
465    });
466
467    $(selecterGreg).each(function () {
468        var range = $(this).attr('data-year-range') || 'c-20:c+20';
469        var minimumDate = $(this).attr('min-Date') || null;
470        var maximumDate = $(this).attr('max-Date') || null;
471        var onSelectFunction = $(this).attr('onSelectFunction');
472        $(this).calendarsPicker({
473            calendar: $.calendars.instance('gregorian', 'ar'),
474            dateFormat: 'dd/mm/yyyy',
475            minDate: minimumDate, //'25/12/1436',
476            maxDate: maximumDate, //'06/01/1437',
477            yearRange: range,
478            showOtherMonths: true,
479            showTrigger: '#calImg',
480            prevText: '<span class="glyphicon glyphicon-chevron-left"></span>', prevStatus: 'عرض الشهر السابق',
481            prevJumpText: '&#x3e;&#x3e;', prevJumpStatus: '',
482            nextText: '<span class="glyphicon glyphicon-chevron-right"></span>', nextStatus: 'عرض الشهر القادم',
483            nextJumpText: '&#x3c;&#x3c;', nextJumpStatus: '',
484            currentText: 'اليوم', currentStatus: 'عرض الشهر الحالي',
485            todayText: 'اليوم', todayStatus: 'عرض الشهر الحالي',
486            clearText: '<span class="glyphicon glyphicon-remove"></span>', clearStatus: 'امسح التاريخ الحالي',
487            closeText: '<span class="glyphicon glyphicon-chevron-up"></span>', closeStatus: 'إغلاق بدون حفظ',
488            yearStatus: 'عرض سنة آخرى', monthStatus: 'عرض شهر آخر',
489            weekText: 'أسبوع', weekStatus: 'أسبوع السنة',
490            dayStatus: 'اختر D, M d', defaultStatus: 'اختر يوم',
491            onSelect: function () { if (onSelectFunction != undefined) { window[onSelectFunction](); } },
492        });
493        $(this).attr("data-culture", "en-US");
494        try {
495            var jdDate = $.calendars.instance("ummalqura").parseDate("dd/mm/yyyy", $(this).val()).toJD();
496            $(this).val($.calendars.instance("gregorian").formatDate('dd/mm/yyyy', $.calendars.instance("gregorian").fromJD(jdDate)));
497        }
498        catch (eee) {
499            //$(this).val("");
500        }
501    });
502
503    $(selecterMix).each(function () {
504        if (!$(this).parent().find('div.checkbox_appended').length) {
505            var div = $('<div />', { 'class': 'checkbox_appended' });
506            div.append($('<input />', { type: 'checkbox', name: 'cb_' + $(this).attr("name"), id: 'cb_' + $(this).attr("id"), value: 'gregorian' }));
507            div.append($('<label />', { 'for': 'cb_' + $(this).attr("id"), text: 'ميلادي' }));
508            div.appendTo($(this).closest('.form-group'));
509        }
510    });
511
512}
513
514$(document).on("change", ".checkbox_appended input:checkbox", function () {
515    var textBox = $(this).parent().parent().find(".datepicker-mix");
516    var from = "gregorian", to = "ummalqura", newCul = "ar-SA";
517    if (this.checked) {
518        from = "ummalqura";
519        to = "gregorian";
520        newCul = "en-US";
521    }
522    try {
523        var jdDate = $.calendars.instance(from).parseDate("dd/mm/yyyy", textBox.val()).toJD();
524        textBox.val($.calendars.instance(to).formatDate('dd/mm/yyyy', $.calendars.instance(to).fromJD(jdDate)));
525    }
526    catch (eee) {
527        try {
528            var kdDate = $.calendars.instance(to).parseDate("dd/mm/yyyy", textBox.val()).toJD();
529            textBox.val($.calendars.instance(to).formatDate('dd/mm/yyyy', $.calendars.instance(to).fromJD(kdDate)));
530            removeInputValidationMessage(textBox);
531        } catch (e) {
532            textBox.val("");
533            removeInputValidationMessage(textBox);
534        }
535    }
536    textBox.attr("data-culture", newCul);
537    textBox.calendarsPicker('option', { calendar: $.calendars.instance(to, 'ar') });
538});
539
540
541function confirmlinksinit() {
542    $(document).on('click', 'a.mci-confirm', '', function (link) {
543        var random_id = Math.floor((Math.random() * 1000000) + 1);
544        link.preventDefault();
545        var theLink = $(this);
546        var theHREF = theLink.attr("href");
547        var theREL = theLink.attr("rel") ? theLink.attr("rel") : 'هل أنت متأكد؟';
548        var theTITLE = theLink.attr("title") ? theLink.attr("title") : 'تأكيد';
549        var theTARGET;
550        var isModal = theLink.hasClass('mci-confirm-modal');
551
552        //build ok link
553        var okButton = $('<a id="okButton_' + random_id + '" class="btn btn-primary okButton">نعم</a>');
554        $(okButton).attr('href', theHREF);
555        //for ajax
556        var ajax = theLink.attr('data-ajax');
557        if (ajax == 'true') {
558            var ajaxUpdate = theLink.attr('data-ajax-update');
559            var AjaxLoading = theLink.attr('data-ajax-loading');
560            var onfail = theLink.attr('data-ajax-failure');
561            var method = theLink.attr('data-ajax-method');
562            var onsuccess = theLink.attr('data-ajax-success');
563
564            $(okButton).attr('data-ajax', 'true');
565            if (ajaxUpdate)
566                $(okButton).attr('data-ajax-update', ajaxUpdate);
567            if (AjaxLoading)
568                $(okButton).attr('data-ajax-loading', AjaxLoading);
569            if (onfail)
570                $(okButton).attr('data-ajax-failure', onfail);
571            if (onsuccess)
572                $(okButton).attr('data-ajax-success', onsuccess);
573            if (method)
574                $(okButton).attr('data-ajax-method', method.toUpperCase());
575
576            if (isModal) {
577                $(document).on('click', '#okButton_' + random_id, function () {
578                    $(this).closest('.modal').modal('hide');
579                });
580            }
581        }
582
583        if (isModal) {
584            theTARGET = buildModal(random_id, theTITLE, theREL, okButton[0].outerHTML);
585            $(theTARGET).modal({ backdrop: "static", show: true });
586        }
587        else {
588            okButton.addClass('btn-sm');
589            var noButton = $('<button id="noButton_' + random_id + '" class="btn btn-danger btn-sm noButton">لا</button>');
590            $(document).on('click', '#noButton_' + random_id, function () {
591                theLink.popover('hide');
592            });
593
594            var content = theREL + '<div class="popover-footer">' + noButton[0].outerHTML + okButton[0].outerHTML + "</div>";
595
596            if (!theLink.data('bs.popover')) {
597                theLink.popover({
598                    sanitize: false,
599                    placement: 'top auto',
600                    trigger: 'focus',
601                    container: "body",
602                    html: true,
603                    title: theTITLE,
604                    content: content
605                });
606                theLink.popover('show');
607            }
608        }
609    });
610
611    //the following is to prevent ajax link from action (not for  links loaded with ajax) so use the helper MCIAjaxLinkConfirm
612    //$('a.mci-confirm[data-ajax="true"]').each(function () {
613    //    var theLink = $(this);
614    //    var onbegin = theLink.attr('data-ajax-begin');
615    //    onbegin =onbegin || 'ReturnFalse';
616    //    theLink.attr('data-ajax-begin', onbegin);
617    //});
618}
619
620function confirmsubmitbuttonsinit() {
621    $(document).on('click', 'input[type="submit"].mci-confirm , button[type="submit"].mci-confirm', '', function (event) {
622        var random_id = Math.floor((Math.random() * 1000000) + 1);
623        event.preventDefault();
624        var button = $(this);
625        var theForm = $(this).parents('form:first');
626        var theREL = button.attr("rel") ? button.attr("rel") : 'هل أنت متأكد؟';
627        var theTITLE = button.attr("title") ? button.attr("title") : 'تأكيد';
628        var okButton = $('<a id="okButton_' + random_id + '" class="btn btn-primary okButton" data-dismiss="modal">نعم</a>');
629        var theTARGET;
630        var isModal = button.hasClass('mci-confirm-modal');
631
632        //add name and value of the button to the form
633        if (button.attr('name') && button.attr('value')) {
634            if ($("input[type='hidden'][name='" + button.attr('name') + "']").length) {
635                $("input[type='hidden'][name='" + button.attr('name') + "']").val(button.val());
636            }
637            else {
638                $('<input />').attr('type', 'hidden')
639                    .attr('name', button.attr('name'))
640                    .attr('value', button.val())
641                    .appendTo(theForm);
642            }
643        }
644
645        $(document).on('click', '#okButton_' + random_id, function () {
646            theForm.submit();
647        });
648
649        if (isModal) {
650            theTARGET = buildModal(random_id, theTITLE, theREL, okButton[0].outerHTML)
651            if (!button.hasClass('cancel'))
652                if (!$(theForm).valid())
653                    return;
654
655            $(theTARGET).modal({ backdrop: "static", show: true });
656        }
657        else {
658            okButton.addClass('btn-sm');
659            var noButton = $('<button id="noButton_' + random_id + '" class="btn btn-danger btn-sm noButton">لا</button>');
660            $(document).on('click', '#noButton_' + random_id, function () {
661                button.popover('hide');
662            });
663
664            var content = theREL + '<div class="popover-footer">' + noButton[0].outerHTML + okButton[0].outerHTML + "</div>";
665
666            if (!button.data('bs.popover')) {
667                button.popover({
668                    sanitize: false,
669                    placement: 'top auto',
670                    trigger: 'focus',
671                    container: "body",
672                    html: true,
673                    title: theTITLE,
674                    content: content
675                });
676                button.popover('show');
677            }
678        }
679    });
680}
681
682function ReturnFalse() {
683    return false;
684}
685
686function buildModal(theID, theTITLE, theREL, button) {
687    var noButtonText = button == '' ? 'موافق' : 'لا';
688    var result = '<div id="modal_confirm_' + theID + '" class="modal fade modal-confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">';
689    result += '<div class="modal-dialog modal-sm">';
690    result += '<div class="modal-content">';
691    result += '<div class="modal-header">';
692    result += '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
693    result += '<h4 class="modal-title" id="myModalLabel">' + theTITLE + '</h4></div>';
694    result += '<div class="modal-body">' + theREL + '</div>';
695    result += '<div class="modal-footer">';
696    if (noButtonText == 'موافق') {
697        result += '<button type="button" class="btn btn-primary" data-dismiss="modal">' + noButtonText + '</button>';
698
699    }
700    else if (noButtonText == 'لا') {
701        result += '<button type="button" class="btn btn-danger" data-dismiss="modal">' + noButtonText + '</button>';
702
703    }
704    result += button;
705    result += '</div></div></div></div>';
706    return result;
707}
708
709function MCIAlert(theTITLE, theMessage) {
710    var random_id = Math.floor((Math.random() * 1000000) + 1);
711    var theTARGET = buildModal(random_id, theTITLE, theMessage, '');
712    $(theTARGET).modal({ backdrop: "static", show: true });
713}
714
715function updateSelectedTabs() {
716    $('ul.nav.nav-tabs').each(function () {
717        var tabName = $(this).parent().attr('id');
718        tabName = tabName || 'lastTab';
719        var lastTab = localStorage.getItem(tabName);
720        if (lastTab)
721            $('a[href=' + lastTab + ']').tab('show');
722    });
723}
724
725function MCIConfirm(theTITLE, theMessage, callBackFunction) {
726    var random_id = Math.floor((Math.random() * 1000000) + 1);
727
728    var okButton = $('<button id="okButton_' + random_id + '" class="btn btn-primary okButton">نعم</button>');
729
730    var theTARGET = buildModal(random_id, theTITLE, theMessage, okButton[0].outerHTML);
731
732    $(theTARGET).modal({ backdrop: "static", show: true });
733    $(document).on('click', '#okButton_' + random_id, function () {
734        var diag = $(this).closest('.modal').modal('hide');
735        if (typeof callBackFunction == "function") callBackFunction();
736    });
737}
738
739function replaceQueryString(url, param, value) {
740    var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
741    if (url.match(re))
742        return url.replace(re, '$1' + param + "=" + value + '$2');
743    else
744        return url + '&' + param + "=" + value;
745}
746
747function showValidationErrorMessageFor(element, error) {
748    $('span[data-valmsg-for="' + element.name + '"]').text(error).addClass("field-validation-error").removeClass("field-validation-valid");
749}
750
751function changeValidationIgnoreSelector(formSelector, ignoreSelector) {
752    var validator = $.data($(formSelector)[0], 'validator');
753    if (!validator)
754        init_validators(formSelector);
755    validator.settings.ignore = ignoreSelector;
756}
757
758function MCIWizardCurrentStep(wizardId) {
759    wizardId = "#" + (wizardId || "mciWizard");
760    var $wizardDiv = $(wizardId);
761    if ($wizardDiv.hasClass('bs-wizard'))
762        return $(wizardId + " .bs-wizard-step.active").attr('id');
763    else if ($wizardDiv.hasClass('mci-wizard'))
764        return $(wizardId + " .current").attr('id');
765}
766
767function MCIWizardChangeStep(stepId, wizardId) {
768    wizardId = "#" + (wizardId || "mciWizard");
769    var $wizardDiv = $(wizardId);
770    if ($wizardDiv.hasClass('bs-wizard')) {
771        $(wizardId + " .bs-wizard-step").removeClass('complete active').addClass('disabled');
772        $wizardDiv.children(".bs-wizard-step").each(function () {
773            $(this).removeClass('disabled');
774            if ($(this).attr('id') == stepId) {
775                $(this).addClass('active');
776                return false;
777            }
778            else
779                $(this).addClass('complete');
780        });
781    }
782    else if ($wizardDiv.hasClass('mci-wizard')) {//a.current ~ a
783        $('#mciWizard2 a.current').removeClass('current');
784        $('#mciWizard2 a#' + stepId).removeClass('not-completed').addClass('current');
785        $('#mciWizard2 a.current ~ a').removeClass('not-completed');
786    }
787}
788
789function NoAjaxCache() {
790    $.ajaxSetup({ cache: false });
791}
792
793//this line is to fix bootstrap modal auto hide when close inner modal
794//the alternative is to set backdrop="static" for modal
795//$.fn.modal.Constructor.prototype.enforceFocus = function () { };
796
797(function (jQuery) {
798    jQuery.fn.hasAttr = function (name) {
799        for (var i = 0, l = this.length; i < l; i++) {
800            var attr = $(this).attr(name);
801            if (typeof attr !== 'undefined' && attr !== false) {
802                return true;
803            }
804        }
805        return false;
806    };
807})(jQuery);
808
809// Session Timeout (Timer)
810var sessionOutMin = 60, sessionOutSec = 0;
811
812function timer() {
813
814    sessionOutSec--;
815    if (sessionOutSec == -1) {
816        if (sessionOutMin !== 0) {
817            sessionOutMin--;
818            sessionOutSec = 59;
819        } 
820    }
821
822    fillSessionTimeText(addZeroToTime(sessionOutMin), addZeroToTime(sessionOutSec));
823}
824function addZeroToTime(x) {
825    return (x < 10) ? ("0" + x) : x;
826}
827function fillSessionTimeText(sMin, sSec) {
828    $("#sessionExpired").text("ستنتهي الجلسة بعد: " + sMin + ":" + sSec);
829}
830
831function removeInputValidationMessage(element) {
832    element.removeClass("input-validation-error")
833    element.next().addClass("field-validation-valid").removeClass("field-validation-error");
834}
835
836function addInputValidationMessage(element, message) {
837    element.addClass("input-validation-error");
838    element.next().removeClass("field-validation-valid").addClass("field-validation-error")
839        .html('<span for="' + element.name + '" class="">' + message + '</span>');
840}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.