$(document).ready(function(){
var flag = document.getElementById('flag');
risuvaFlag(flag);
veeFlag(flag, 20, 5, 500, 260, 0);
root = $('#root').attr('href');
$(document).on('change', '.select_godina', function () {
var mesec = $('.span_mesec').data('mesec');
mesec = mesec.length == 1 ? '0' + mesec : mesec;
kalendar($(this).val() + '-' + mesec);
});
$(document).on('click', '.select_godina option', function () {
var mesec = $('.span_mesec').data('mesec');
mesec = mesec.length == 1 ? '0' + mesec : mesec;
kalendar($(this).val() + '-' + mesec);
});
$(document).on('click', '.span_godina', function () {
if ($('.select_mesec').length) {
$('#span_mesec').html('' + $('.select_mesec option:selected').html() + '');
}
var godina = parseInt($(this).html()), option = '', selected = '', select;
for (var a = godina - 3; a <= godina + 5; a++) {
if (godina == a) {
selected = ' selected';
} else {
selected = '';
}
option += '' + "\n";
}
select = '';
$('#span_godina').html(select);
});
$(document).on('change', '.select_mesec', function () {
var mesec = $(this).val();
mesec = mesec.length == 1 ? '0' + mesec : mesec;
kalendar(parseInt($('.span_godina').html()) + '-' + mesec)
});
$(document).on('click', '.select_mesec option', function () {
var mesec = $(this).val();
mesec = mesec.length == 1 ? '0' + mesec : mesec;
kalendar(parseInt($('.span_godina').html()) + '-' + mesec)
});
$(document).on('click', '.span_mesec', function () {
if ($('.select_godina').length) {
$('#span_godina').html('' + $('.select_godina').val() + '');
}
$.ajax({
type: 'POST',
url: root + 'ajax/opt_meseci',
data: {
opt_meseci: 1,
mesec: $(this).data('mesec')
}
}).done(function (data) {
$('#span_mesec').html(data);
}).fail(function () {
alert('Сървъра не отговаря!');
});
});
$(document).on('mouseenter', '.da', function () {
var title = $(this).data('title');
if (title != '') {
$('body').append('' + title + '');
}
}).on('mouseleave', '.da', function () {
$('.help').remove();
}).on('mousemove', '.da', function (e) {
var left, top;
if (parseFloat($(window).width()) < e.pageX + 212) {
left = -212;
} else {
left = 12;
}
if (parseFloat($(window).height()) < e.pageY + $('.help').height() + 20) {
top = -(parseFloat($('.help').height()) + 20);
} else {
top = 20;
}
$('.help').css({
left: e.pageX + left,
top: e.pageY + top
});
});
$(document).on('click', 'div#calendar div.box div.header a.prev,div#calendar div.box div.header a.next', function () {
kalendar($(this).data('data'));
});
$(document).on('click', 'div#calendar div.box-content ul.dates li.da', function () {
tyrsiKalendar($(this).data('data'), 1, $(this).data('title'), $(this).data('link'));
});
// if (navigator.userAgent.indexOf('Chrome') >= 0) {
// $('#goren_red').css('margin-top', -180);
// $('#cel').css('margin-top', 3);
// }
//
// if (navigator.userAgent.indexOf('Firefox') >= 0 && navigator.userAgent.indexOf('Ubuntu') >= 0) {
// $('#goren_red').css('margin-top', -177);
// } else {
// $('#left_logo').css('margin-top', 15);
// $('#right_logo').css('margin-top', 15);
// }
$('#flag').css('margin-left', $('#flag').position().left - 12);
// var sybitiq = $('article').html(), str = sybitiq.replace(/†/g, '†');
// $('article').html(str);
// if (/Google Inc/.test(navigator.vendor)) {// Ако е смотания Chrome(хром - инвалид, недоносче) на GУКЪЛ да се нагоди по плеъра!!!
// $('#radio1').css('margin-top', 20);
// }
$('#radio1 div.audio').click(function (e) {
var tova = $(this), player = document.getElementById('audioplayer'), elm = e.target, source = document.getElementById('audioSource');
source.src = elm.getAttribute('data-url');
source.type = elm.getAttribute('data-type');
player.load();
player.play();
$('#radio1 div.audio').attr('class', 'audio');
tova.attr('class', 'play audio');
});
$('div#t1-left').click(function () {
window.location = $(this).data('url');
});
remove_Attr(['.kutiq img', '.kolona img']);
// $('article img').removeAttr('style').removeAttr('width').removeAttr('height').removeAttr('border').removeAttr('align').removeAttr('hspace');
// razmerSnimkata();
// razmerSnimkata($('.kutiq img'), 150);
$('.kutiq').hover(function (a) {
a.preventDefault();
var title = $(this).data('pro4eti');
$('body').append('' + title + '');
}, function () {
$('.help').remove();
}).bind('mousemove mouseenter', function (e) {
$('.help').css({
left: e.pageX + 12,
top: e.pageY + 20
});
});
$('.predi,.sledva').hover(function () {
klas = '.' + $(this).attr('class') + '_';
klas1 = klas + ' b';
$(klas + ',' + klas1).css({backgroundColor: '#622020'});
$(klas).css({color: '#fff'});
$(klas1).css({color: '#aaa'});
}, function () {
$(klas + ',' + klas1).css({backgroundColor: 'inherit'});
$(klas).css({color: '#000'});
$(klas1).css({color: '#b11212'});
});
$('.linkove_statiq').cleanWhitespace();
$('.pagination').cleanWhitespace();
$('table#t1-left td button').click(function () {
var name = $('input[name=name]').val(), email = $('input[name=email]').val(), subject = $('input[name=subject]').val(),
text = $('textarea[name=text]').val(), err = '';
if (name.length <= 0 || subject.length <= 0 || text.length <= 0)
return '';
if (name.length < 3) {
err += "Името съдържа по-малко от 3 символа!\n";
}
if (subject.length < 3) {
err += "Темата съдържа по-малко от 3 символа!\n";
}
if (text.length < 3) {
err += "Съобщението съдържа по-малко от 3 символа!\n";
}
if (/(([^<>()[\]\\.,;:\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,}))/.test(email)) {
open_wait();
$.ajax({
type: 'POST',
url: root + 'ajax/check_email',
data: {
check_email: 1,
email: email
}
}).done(function (data) {
if (data != '1') {
err += data;
}
if (err != '') {
alert("ГРЕШКА\n" + err);
close_wait();
} else {
$.ajax({
type: 'POST',
url: root + 'ajax/send_mail',
data: {
send_email: 1,
name: name,
email: email,
subject: subject,
text: text,
captcha: $('input[name=captcha]').val()
}
}).done(function (data) {
if (data == '1') {
alert('Грешен код за защита!!!');
close_wait();
} else {
alert(data);
refresh();
}
}).fail(function () {
alert('Сървъра не отговаря!');
close_wait();
});
}
}).fail(function () {
alert('Сървъра не отговаря!');
close_wait();
});
}
});
$('.refresh').click(function () {
var d = new Date();
$('img.captcha').attr('src', root + 'ajax/captchaimage/' + '?' + d.getTime());
});
$('.tyrsa4ka-buton_pr_kalendar').click(function () {
tyrsiKalendar($('.pr_kalendar').val());
});
$('.pr_kalendar').keyup(function (key) {
if (key.keyCode == 13) {
tyrsiKalendar($('.pr_kalendar').val());
}
});
$('.tyrsa4ka-buton_search').click(function () {
tyrsiSajt();
});
$('input[name=search]').keyup(function (key) {
if (key.keyCode == 13) {
tyrsiSajt();
}
});
$('button.log').click(function () {
login();
});
$('.loginforma input[name=name]').keyup(function (key) {
if (key.which == 13) {
$('.loginforma input[name=pass]').focus();
}
});
$('.loginforma input[name=pass]').keyup(function (key) {
if (key.which == 13) {
login();
}
});
$('#pe4at_kalendar').click(function () {
$.ajax({
type: 'POST',
url: root + 'ajax/opt_meseci_inp_godini',
data: {
opt_meseci_inp_godini: 1
}
}).done(function (data) {
djam1(data);
}).fail(function () {
alert('Сървъра не отговаря!');
});
});
// if ($('#t1-left').height() < $('#t1-left img').height()) {
// $('#t1-left').css('height', $('#t1-left img').height() + $('#t1-left img').position().top);
// $('#t1-right').css('margin-top', -($('#t1-left img').height() + $('#t1-left img').position().top + 12));
// }
// $('#t1-right').css('margin-top', - ($('#t1-left img').height() + $('#t1-left img').position().top + 12));
// alert($('#t1-right').position().top -262)
});
/**
*
* @description Вход
*/
function login() {
if ($('.loginforma input[name=name]').val().length >= 4 && $('.loginforma input[name=pass]').val().length > 10) {
$.ajax({
type: 'POST',
url: root + 'ajax/login',
data: {
login: 1,
name: $('.loginforma input[name=name]').val(),
pass: $('.loginforma input[name=pass]').val()
}
}).done(function (data) {
if (data == '1') {
window.location.href = root + 'администрация';
}
}).fail(function () {
alert('Сървърът не отговаря!!!');
});
}
}
function izhod() {
if (confirm('Изход от Администрацията!')) {
$.ajax({
type: 'POST',
url: root + 'ajax/logout',
data: {
logout: 1,
}
}).done(function (data) {
if (data == '0') {
window.location.href = root + 'вход';
}
}).fail(function () {
alert('Сървърът не отговаря!!!');
});
}
}
var arr = new Array();
function remove_Attr(arr) {
for (var a = 0; a < arr.length; a++) {
$(arr[a]).removeAttr('style').removeAttr('width').removeAttr('height').removeAttr('border').removeAttr('align').removeAttr('hspace');
}
}
function tyrsiSajt() {
var srch = $.trim($('input[name=search]').val());
if (srch.length >= 2) {
var url = srch.replace(/[\s"'*+!@#$^&}{[\])(_\-\\/;:,?<>`~§¶]/g, ' ').trim().replace(/\s/g,'|').replace(/([|])\1+/, '|');
refresh(root + 'търсене/статии/' + url);
}
}
function tyrsiKalendar(srch, is, str, link) {
var danni = {};
//TODO Да се махне след динамиката на празниците
if (is == 1) {
danni = {
srch_kalendar: 1,
srch: srch,
is: 1,
str: str,
link: link
};
} else {
danni = {
srch_kalendar: 1,
srch: srch
}
}
if (srch.length > 4) {
open_wait();
$.ajax({
type: 'POST',
url: root + 'ajax/srch_kalendar',
data: danni
}).done(function (data) {
if (data == '1') {
alert('Невалидна дата!');
close_wait();
return false;
}
if (data.length > 2) {
djam1(data);
}
close_wait();
}).fail(function () {
alert('Сървъра не отговаря!');
close_wait();
});
}
}
//function razmerSnimkata(obj = $('.posledna_statiq_pic'), size = 250) {
// var h = obj.height(), w = obj.width();
// if (h >= w) {
// obj.css({
// 'width': w * (size / h),
// 'height': 'auto'
// });
// } else {
// obj.css({
// 'height': h * (size / w),
// 'width': 'auto'
// });
// }
//}
function risuvaFlag(canvas) {
var ctx = canvas.getContext('2d');
//// ctx.fillStyle = "#ffffff";
// ctx.fillStyle = "#cc0000";
// ctx.fillRect(0, 0, 300, 50);
//// ctx.fillStyle = "#00976c";
// ctx.fillStyle = "#ffffff";
// ctx.fillRect(0, 50, 300, 50);
//// ctx.fillStyle = "#d62513";
// ctx.fillStyle = "#298ed5";
// ctx.fillRect(0, 100, 300, 50);
// ctx.fillStyle = "#ffffff";
ctx.fillStyle = "#fab002";
ctx.fillRect(0, 0, 300, 50);
// ctx.fillStyle = "#00976c";
ctx.fillStyle = "#cc0000";
ctx.fillRect(0, 50, 300, 50);
// ctx.fillStyle = "#d62513";
ctx.fillStyle = "#fab002";
ctx.fillRect(0, 100, 300, 50);
}
function veeFlag(canvas, wavelength, amplitude, period, shading, squeeze) {
var fps = 30;
var ctx = canvas.getContext('2d');
var w = canvas.width, h = canvas.height;
var od = ctx.getImageData(0, 0, w, h).data;
return setInterval(function () {
var id = ctx.getImageData(0, 0, w, h);
var d = id.data;
var now = (new Date) / (period);
for (var y = 0; y < h; ++y) {
var lastO = 0, shade = 0;
var sq = (y - h / 2) * squeeze;
for (var x = 0; x < w; ++x) {
var px = (y * w + x) * 4;
var pct = x / w;
var o = Math.sin(x / wavelength - now) * amplitude * pct;
var y2 = y + (o + sq * pct) << 0;
var opx = (y2 * w + x) * 4;
shade = (o - lastO) * shading;
d[px ] = od[opx ] + shade;
d[px + 1] = od[opx + 1] + shade;
d[px + 2] = od[opx + 2] + shade;
d[px + 3] = od[opx + 3];
lastO = o;
}
}
ctx.putImageData(id, 0, 0);
}, 1000 / fps);
}
function kalendar(data) {
open_wait();
$.ajax({
type: 'POST',
url: root + 'ajax/getkalendar',
data: {
get_kalendar: 1,
data: data
}
}).done(function (v) {
var var_ = JSON.parse(v);
if (var_) {
$('#calendar_').html(var_[0]);
} else {
alert('Сървъра не отговаря!');
}
close_wait();
}).fail(function () {
alert('Сървъра не отговаря!');
close_wait();
});
}