var window_width = parseFloat($(window).width()), window_height = parseFloat($(window).height()); $(document).ready(function () { root = $('#root').attr('href'); $(document).on('click', '.refresh', function () { refresh_kap4a(); }); setTimeout(function () { $.ajax({ type: 'POST', url: root + 'home/checkcookies', data: { check_cookies: 1 } }).done(function (data) { if (data == '1') { $('#biskvitki').remove(); } else { $('#biskvitki').show(); } }); }, 5000); $(document).on('click', '#ok', function () { $('#biskvitki').remove(); $.ajax({ type: 'POST', url: root + 'home/setcookies', data: { set_cookies: 1 } }); }); /** * Валидиране на полета */ $(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', '.telefon', function () { this.value = this.value.replace(/[^0-9,+]/g, ''); }); $(this).on('keyup', '.iban', function () { this.value = this.value.replace(/[^0-9 A-Z]/g, ''); }); $(this).on('keyup', '.bic', function () { this.value = this.value.replace(/[^A-Z]/g, ''); }); $(this).on('keyup', '.eik,.in', function () { this.value = this.value.replace(/[^0-9A-Z]/g, ''); }); $(document).on('click', '.close_djam,.djam,.djam_prodex', function () { close_djam(); }); $(document).on('click', '.close,.djam', function () { close_djam(); }); $(document).on('click', '.djam1 img', function () { openWin($(this).attr('src')); }); }); /** * * @description Опресняване на страницата * @returns {undefined} */ function refresh() { 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('
');
$('.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 seoUrl(str, replace = '-') {
if (!str) return '';
let res = str;
// 1. Премахване на HTML тагове (strip_tags)
res = res.replace(/<\/?[^>]+(>|$)/g, "");
// 2. Малки букви
res = res.toLowerCase();
// 3. Запазваме: малки букви (lat/cyr), цифри, интервали и тирета
// Махаме всичко останало (специални символи)
res = res.replace(/[^a-zа-я0-9\s-]/g, '');
// 4. Сливане на последователни интервали/тирета в един интервал
res = res.replace(/[\s-]+/g, ' ');
// 5. Премахване на специфични кавички и проценти
res = res.replace(/["„”%]/g, '');
// 6. Наклонени черти към тирета
res = res.replace(/[\/\\]/g, '-');
// 7. Trim на интервали и пунктуация в двата края
res = res.trim();
res = res.replace(/^[.?!]+|[.?!]+$/g, '');
// 8. Замяна на интервали и долни черти с финалния разделител (тире)
res = res.replace(/[\s_]/g, replace);
return res;
}
function is_email(email) {
// Този regex проверява за стандартен формат: име@домейн.разширение
const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return regex.test(String(email).toLowerCase());
}