var window_width = parseFloat($(window).width()), window_height = parseFloat($(window).height());
$(document).ready(function() {
var fp = $('#fp').html();
$('.edit_galeriq').parent('div.footer').css('padding', 0);
$(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 click', 'input,textarea', function() {
this.value = this.value.replace(/["'`]/g, '');
});
$(window).scroll(function() {
if ($(this).scrollTop() > 370)
$('#back_to_top').fadeIn();
else
$('#back_to_top').fadeOut();
});
$(document).on('click', '.close_djam,.djam', function() {
close_djam();
});
setInterval(function() {
var active = $('#slide img.active');
if (active.next().length > 0) {
var next = active.next();
} else {
var next = $('#slide img:first')
}
next.css('z-index', '2');
active.fadeOut(5000, function() {
active.css('z-index', '1').show().removeClass('active');
next.css('z-index', '3').addClass('active');
})
}, 5000);
$('.login_').click(function() {
window.location.href = fp + 'вход/';
});
$('.return').click(function() {
window.location.href = fp;
});
$('.exit').click(function() {
$.ajax({
type: 'POST',
url: fp + 'home/exit_/',
data: {
exit: 1
}
}).done(function() {
window.location.href = fp;
});
});
$('#edit_moto').click(function() {
$.ajax({
type: 'POST',
url: fp + 'home/edit_moto/',
data: {
edit_moto: 1
}
}).done(function(data) {
djam2(data, '#ccc');
});
});
$('button.edit_kontakti').click(function() {
var adres = $('textarea[name=adres]').val(),
kontakti = $('textarea[name=kontakti]').val();
if (adres.length > 0 && kontakti.length > 0) {
$.ajax({
type: 'POST',
url: fp + 'home/save_kontakti/',
data: {
save_kontakti: 1,
adres: adres,
kontakti: kontakti
}
}).done(function() {
refresh();
});
}
});
});
/**
*
* @description Изход
* @returns {undefined}
*/
function logout() {
var $log = confirm('Сигурен ли си,\nче искаш да излезеш от системата?');
if ($log) {
$.ajax({
type: 'POST',
url: 'home/_exit/',
data: {
logout: 1
}
}).done(function() {
refresh();
});
}
}
/**
*
* @description Опреснява страницата
* @returns {undefined}
*/
function refresh() {
window.location.href = window.location.href;
}
/**
*
* @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()) / 2),
'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 - 30
});
$('.djam').animate({
'opacity': .6
}, function() {
$('.djam1').show();
});
}
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();
});
}
/**
*
* @description Взима $_GET от URL
* @returns {array}
*/
function getUrlVars() {
var vars = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m, key, value) {
vars[key] = value;
});
return vars;
}
/**
*
* @description Отваря чакалня
* @param {string} dot
* @returns {unresolved}
*/
function open_wait(dot) {
$('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();
}
/**
*
* @description Проверява дали стринга е JSON
* @param {string} str
* @returns {Boolean}
*/
function IsJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}