var window_width = parseFloat($(window).width()), window_height = parseFloat($(window).height()); $(document).ready(function () { root = $('#root').data('root'); $(document).on('click', '.close_djam,.close,.djam', function () { close_djam(); }); /** * Валидиране на полета */ $(this).on('keyup', '.number', function () { this.value = this.value.replace(/[^0-9.,]/g, ''); this.value = this.value.replace(',', '.'); }); $(this).on('keyup', '.int', function () { this.value = this.value.replace(/[^0-9\-]/g, ''); }); $(this).on('keyup', '.ime,.fam', function () { this.value = this.value.replace(/[^А-Яа-я]/g, ''); }); $(this).on('keyup', '.adr', function () { this.value = this.value.replace(/[^0-9 .№IА-Яа-я]/g, ''); }); $(this).on('keyup', '.tlf', function () { this.value = this.value.replace(/[^+0-9]/g, ''); }); $(this).on('keyup', '.latin', function () { this.value = this.value.replace(/[^a-z]/g, ''); }); $(document).on('click', '.refresh', function () { refresh_kap4a(); }); }); function izhod() { open_wait(); if (confirm('Изход от системата !')) { $.ajax({ type: 'POST', url: root + 'home/izhod', data: { izhod: 1 } }).done(function (data) { refresh(root); }).fail(function () { alert('Сървърът не отговаря !!!'); refresh(); }); } close_wait(); } function seoUrl(str) { str = str.replace(/(<([^>]+)>)/gi, ''); str = str.toLowerCase(); str = str.replace(/![a-zа-я0-9\s-]/, ''); // str = str.replace(/[\s-]+/, ' '); str = str.replace(/[\s_]/, '_'); return str; } /** * * @param {sting} email * @returns {Boolean} */ function validate_email(email) { var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return regex.test(String(email).toLowerCase()); } function validate_url(url) { var regex = /https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,}/gi; return regex.test(String(url).toLowerCase()); } function valid_pass(pass) { return /^(?=.{10,}$)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?\W).*$/.test(pass); } /** * * @description Опресняване на страницата * @returns {undefined} */ function refresh(url) { if (url) { window.location.href = url; } else { window.location.href = window.location.href; } } function refresh_kap4a() { var d = new Date(); $('.captcha').attr('src', root + 'home/captchaimage/' + '?' + d.getTime()); } /** * * @description Псевдо alert() * @param {sting} text * @param {string} color * @returns {undefined} */ function djam(text, color) { $('body').append('
' + text + '
'); $('.djam1').css({ 'top': (window_height / 2) - (parseFloat($('.djam1').height())), 'left': (window_width / 2) - (parseFloat($('.djam1').width()) / 2), 'border-color': color, 'color': color }); $('.djam').animate({ 'opacity': .6 }, function () { $('.djam1').show(); }); } /** * * @description Псевдо alert() №2 * @param {string} text * @returns {undefined} */ function djam1(text) { var w = parseFloat($(window).width()), h = parseFloat($(window).height()); $('body').append('
' + text + '
'); $('.djam1').css({ 'top': 0, 'left': 0, 'max-height': h - 50, 'max-width': w - 50 }); if (!!window.chrome) { $('.djam1 img').css({ 'max-height': '100%', 'max-width': w - 55 }); } else { $('.djam1 img').css({ 'max-height': h - 75, 'max-width': w - 55 }); } $('.djam').animate({ 'opacity': .6 }, function () { $('.djam1').show(); }); } /** * * @description Псевдо alert() №3 * @param {string} text * @returns {undefined} */ function djam2(text) { var w = parseFloat($(window).width()), h = parseFloat($(window).height()); $('body').append('
' + text + '
'); $('.djam1').css({ 'top': 0, 'left': 0, 'max-height': h - 30 }); $('body').css('overflow', 'hidden'); $('.djam').css('bacground', null); $('.djam1').show(250); } /** * * @description Затваряне на псевдо alert() * @returns {undefined} */ function close_djam() { $('.djam1').hide(); $('.djam').animate({ 'opacity': 0 }, function () { $('body').css('overflow', 'inherit'); $('.djam,.djam1').remove(); }); } //$(document).on('click', '.djam1 img', function () { // openWin($(this).attr('src')); //}); /** * * @description Отваряне на чакалня * @param {string} dot * @returns {unresolved} */ function open_wait() { $('body').append('
wait'); $('.wait').css({ 'top': (window_height / 2) - (parseFloat($('.wait').height()) / 2), 'left': (window_width / 2) - (parseFloat($('.wait').width()) / 2) }); } /** * * @description Затваряне на чакалня * @returns {unresolved} */ function close_wait() { $('.wait_').remove(); $('.wait').remove(); } /** * * @description Отваряне на нов прозорец * @param {string} url * @returns {undefined} */ function openWin(url) { window.open(url); } /** * * @description Отваряне на нов прозорец с по-малки размери * @example openWinMini({url: 'http://hankrum.info', width: 800, height: 500}); * @see default - url: 'http://hankrum.info', width: 1000, height: 700 * @param {object} params * @returns {undefined} */ function openWinMini(params) { var object; if (params === undefined) object = {}; else object = params; if (parseInt(object.width) === 0 || object.width === undefined) object.width = 1000; if (parseInt(object.height) === 0 || object.height === undefined) object.height = 700; if (String(object.url) === null || object.url === undefined) object.url = 'http://hankrum.info'; var size = 'width = ' + object.width + ', ' + 'height = ' + object.height; window.open(object.url, object.name, size); } /** * * @description Затваряне на нов прозорец * @returns {undefined} */ function closeIt() { window.close(); } /** * Проверява, дали е JSON * @param {string} str * @returns {Boolean} */ function IsJson(str) { try { JSON.parse(str); } catch (e) { return false; } return true; } function serv_err() { alert('Server Error!!!'); } //function setCookie(c_name, value, exdays) { // var exdate = new Date(); // exdate.setDate(exdate.getDate() + exdays); // var c_value = escape(value) + ((exdays == null) ? '' : '; expires=' + exdate.toUTCString()); // document.cookie = c_name + "=" + c_value; // return null; //} // //function getCookie(c_name) { // var i, x, y, ARRcookies = document.cookie.split(";"); // for (i = 0; i < ARRcookies.length; i++) { // x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("=")); // y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1); // x = x.replace(/^\s+|\s+$/g, ""); // if (x == c_name) { // return unescape(y); // } // } //}