function getEl(el)
{
	if ( document.getElementById )
	{
		return( document.getElementById(el) );
	} else if (document.all) {
		return( document.all[el] );
	}
}

function hideIt(elID)
{
	if ( getEl(elID) )
		(getEl(elID)).style.display = "none";
}

function showIt(elID)
{
	if ( getEl(elID) )
		(getEl(elID)).style.display = "block";
}

function isVisible(elID)
{
	var el = getEl(elID);
	if ( el && el.style.display != "none" )
		return( true );
		else
		return( false );
}

function Query (question, text)
{
	return prompt (question, text);
}

function bg_Light(elID, this_id, bg_color_on, bg_color_off)
{
	if (isVisible(elID))
	{
		getEl(this_id).style.background = bg_color_on;
	} else {
		getEl(this_id).style.background = bg_color_off;
	}
}

function ShowOn(elID)
{
	if ( isVisible(elID) )
	{
		hideIt(elID);
	} else {
		showIt(elID);
		showIt(elID);
	}
}

function ShowCat (elID)
{
	if ( isVisible(elID) )
	{
		getEl(elID + '_pm').className = "plus";
		getEl(elID + '_fl').className = "folder";

		hideIt(elID);
	} else {
		getEl(elID + '_pm').className = "minus";
		getEl(elID + '_fl').className = "folderopen";

		showIt(elID);
		showIt(elID);
	}
}

function Set_Alt_Text (elm, text)
{
	var el = getEl(elm);
	el.value = text;
	el.onblur = function() { if(this.value=='') { this.value=text; }}
	el.onfocus= function() { if(this.value==text) { this.value=''; }}
}

function search_on ()
{
	location.replace( '/search/' + getEl('search_text').value );
}

function isValidEmail (email)
{
	return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function ShowQuestion(question,href) {
	if (confirm(question)) {
		location.href=href;
	}
}

function HelpBottom()
{
	var div_id = 'help_cont';
	var btn_id = 'help_btn';
	if (isVisible(div_id))
	{
		hideIt(div_id);
		getEl(btn_id).src = '/images/admin/showme.jpg';
	} else {
		showIt(div_id);
		getEl(btn_id).src = '/images/admin/hideme.jpg';
	}
}

function addBookmark(url, title)
{
	if (!url) url = location.href;
	if (!title) title = document.title;
		//Gecko
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
	{
		window.sidebar.addPanel (title, url, "");
	}
		//IE4+
	else 
	{
		if (typeof window.external == "object") 
		{
			window.external.AddFavorite(url, title);
		}
		//Opera7+
		else
		{
			if (window.opera && document.createElement)
			{
				var a = document.createElement('A');
				if (!a) return false; //IF Opera 6
				a.setAttribute('rel','sidebar');
				a.setAttribute('href',url);
				a.setAttribute('title',title);
				a.click();
			} else return false;
		}
	}
	return true;
}

function Start ()
{
	// Инициализируем таблицу перевода
	var trans = [];
	for (var i = 0x410; i <= 0x44F; i++) trans[i] = i - 0x350; // А-Яа-я
	trans[0x401] = 0xA8; // Ё
	trans[0x451] = 0xB8; // ё
	// Сохраняем стандартную функцию escape()
	var escapeOrig = window.escape;
	// Переопределяем функцию escape()
	window.escape = function(str)
	{
		var ret = [];
		// Составляем массив кодов символов, попутно переводим кириллицу
		for (var i = 0; i < str.length; i++)
		{
			var n = str.charCodeAt(i);
			if (typeof trans[n] != 'undefined')
			n = trans[n];
			if (n <= 0xFF) ret.push(n);
		}
		return escapeOrig(String.fromCharCode.apply(null, ret));
	}
}

function to_news_list(lang)
{
	var from = getEl('from_date').value;
	var to = getEl('to_date').value;
	var reg=/-/g
	if (from == to || !(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/i).test(from) || !(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/i).test(to))
	{
		window.location = '/'+lang+'/news_by_date/' + from.replace(reg,'/')+'/';
	}
	if (from.length == 10 && to.length == 10 && (/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/i).test(from) && (/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/i).test(to))
	{
		window.location = '/'+lang+'/news_period/from/' + from.replace(reg,'/')+'/to/'+to.replace(reg,'/')+'/';
	}
}

function print_content()
{
	getEl('print_content_text').innerHTML = getEl('text_content').innerHTML;
	ShowOn('main');
	ShowOn('print_content');
	getEl('print_content_link').value = window.location;
	getEl('print_content_link').innerHTML = window.location;
}

var global_lang = '';

function start_calendar (lang, now_day, now_month, now_year)
{
	YAHOO.namespace("example.calendar");
	global_lang = lang;
	YAHOO.example.calendar.init = function() {
		if (lang == 'ru')
		{
			YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","my_calendar", 
			{
			LOCALE_WEEKDAYS:"short", 
			START_WEEKDAY: 1,
			MULTI_SELECT: false,
			SHOW_WEEK_FOOTER: false,
			HIDE_BLANK_WEEKS: true,
			DATE_FIELD_DELIMITER: '.',
			MDY_DAY_POSITION: 1,
			MDY_MONTH_POSITION: 2,
			MDY_YEAR_POSITION: 3,
			MD_DAY_POSITION: 1,
			MD_MONTH_POSITION: 2,
			MONTHS_SHORT:   ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
			MONTHS_LONG:    ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
			WEEKDAYS_1CHAR: ["В", "П", "В", "С", "Ч", "П", "С"],
			WEEKDAYS_SHORT: ["Вc", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
			WEEKDAYS_MEDIUM: ["Вос", "Пон", "Вт", "Ср", "Чет", "Пят", "Суб"],
			WEEKDAYS_LONG: ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"]
			} );
		}

		if (lang == 'ua')
		{
			YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","my_calendar", 
			{
			LOCALE_WEEKDAYS:"short", 
			START_WEEKDAY: 1,
			MULTI_SELECT: false,
			SHOW_WEEK_FOOTER: false,
			HIDE_BLANK_WEEKS: true,
			DATE_FIELD_DELIMITER: '.',
			MDY_DAY_POSITION: 1,
			MDY_MONTH_POSITION: 2,
			MDY_YEAR_POSITION: 3,
			MD_DAY_POSITION: 1,
			MD_MONTH_POSITION: 2,
			MONTHS_SHORT:   ["Січ", "Лют", "Бер", "Кві", "Тра", "Чер", "Лип", "Сер", "Вер", "Жов", "Лис", "Гру"],
			MONTHS_LONG:    ["Січень", "Лютий", "Березень", "Квітень", "Травень", "Червень", "Липень", "Серпень", "Вересень", "Жовтень", "Листопад", "Грудень"],
			WEEKDAYS_1CHAR: ["Н", "П", "В", "С", "Ч", "П", "С"],
			WEEKDAYS_SHORT: ["Нд", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
			WEEKDAYS_MEDIUM: ["Нед", "Пон", "Вів", "Сер", "Чет", "П'я", "Суб"],
			WEEKDAYS_LONG: ["Неділя", "Понеділок", "Вівторок", "Середа", "Четвер", "П'ятниця", "Субота"]
			} );
		}

		YAHOO.example.calendar.cal1.select(now_day + '.' + now_month + '.' + now_year);
		YAHOO.example.calendar.cal1.cfg.setProperty("PAGEDATE", now_month + '.' + now_year);
		YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);
		YAHOO.example.calendar.cal1.render();
	}

	YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init);

	function handleSelect(type,args,obj) {
		var temp_date = new Date();
		var n_day = temp_date.getDate(), n_month = temp_date.getMonth() + 1, n_year = temp_date.getFullYear();
		n_day = (n_day < 10) ? '0' + n_day : n_day;
		n_month = (n_month <10) ? '0' + n_month : n_month;

		var dates = args[0];
		var date = dates[0];
		var year = date[0], month = (date[1] < 10)?'0'+date[1]:date[1], day = (date[2] < 10)?'0'+date[2]:date[2];

		if ((day <= n_day && month == n_month && year == n_year) || (month < n_month && year == n_year) || (year < n_year))
		{
			location = '/' + global_lang + '/news_by_date/' + year + '/' + month + '/' + day + '/';
		} else {
			location = '/' + global_lang + '/news_by_date/' + n_year + '/' + n_month + '/' + n_day + '/';
		}
	}
}