
	function start_function()
	{
		isDOM=document.getElementById; //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
		isOpera=isOpera5=window.opera && isDOM; //Opera 5+
		isOpera6=isOpera && window.print; //Opera 6+
		isOpera7=isOpera && document.readyState; //Opera 7+
		isMSIE=document.all && document.all.item && !isOpera; //Microsoft Internet Explorer 4+
		isMSIE5=isDOM && isMSIE; //MSIE 5+
		isNetscape4=document.layers; //Netscape 4.*
		isMozilla=isDOM && navigator.appName == "Netscape"; //Mozilla или Netscape 6.*
		mousex = 0;
		mousey = 0;
		if(isNetscape4) document.captureEvents(Event.MOUSEMOVE)
		if(isMSIE || isOpera7)
		{
			document.onmousemove = function()
			{
				mousex = (document.body.scrollLeft) ? event.clientX + document.body.scrollLeft : event.clientX;
				mousey = (document.body.scrollTop) ? event.clientY + document.body.scrollTop : event.clientY;
				return true;
			}
		}else if(isOpera){
			document.onmousemove = function()
			{
				mousex=event.clientX;
				mousey=event.clientY;
				return true
			}
		}else if(isNetscape4 || isMozilla){
			document.onmousemove = function(e)
			{
				mousex = e.pageX;
				mousey = e.pageY;
				return true;
			}
		}
		// Инициализируем таблицу перевода
		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));
		}
		if (isMSIE5) {
		}
	}


function getEl(el)
{
	if ( document.getElementById )
	{
		return( document.getElementById(el) );
	} else if (document.all) {
		return( document.all[el] );
	}
}

function hideIt(elID)
{
	if ( getEl(elID) )
		$('#'+elID).animate({height: 'hide'}, 400);
	return false;
}

function showIt(elID)
{
	if ( getEl(elID) )
		$('#'+elID).animate({height: 'show'}, 400);
	return false;
}

function isVisible(elID)
{
	el = getEl(elID);
	if ( el && el.style.display != "none" )
		return( true );
		else
		return( false );
}

function ShowOn(elID)
{
	if ( isVisible(elID) )
	{
		hideIt(elID);
	} else {
		showIt(elID);
	}
	return false;
}

function show_comments ()
{
	if (isVisible('comments_list'))
		hideIt('comments_list');
		else
		showIt('comments_list');
}

function preview_img (img_id, img_file)
{
	img_prev = 'img_preview';
	if (isVisible(img_prev) && getEl(img_prev).src == '/upload/800_600/' + img_file)
	{
		getEl(img_prev).alt = '';
		getEl(img_prev).title = '';
		getEl(img_prev).src = '';
		getEl(img_prev + '_alt').innerHTML = '&nbsp;';
		hideIt(img_prev);
	} else {
		getEl(img_prev).src = '/img/load.gif';
		getEl(img_prev).alt = getEl(img_prev).title = getEl(img_id).alt;
		getEl(img_prev).src = '/upload/800_600/' + img_file;
		getEl(img_prev + '_alt').innerHTML = getEl(img_id).alt;
		showIt(img_prev);
	}
//	setTimeout(jQuery.unblockUI, 4000);
}

function add_comment(comm_id)
{
	var ans = 'answer';
	var com_form = 'commentform';
	var com_form_ans = 'commentform_answer';
	if (comm_id == '')
	{
		getEl(ans).value = '';
		$('#com_form_ans').html();//getEl(com_form_ans).innerHTML = '';
		if (isVisible(com_form_ans)) hideIt(com_form_ans);
		if (isVisible(com_form))
		{
			hideIt(com_form);
		} else {
			showIt(com_form);
		}
	} else {
		if (isVisible(com_form))
		{
			getEl(ans).value = '';
			getEl(com_form_ans).innerHTML = '';
			hideIt(com_form_ans);
			hideIt(com_form);
		} else {
			getEl(ans).value = comm_id;
			showIt(com_form);
			showIt(com_form_ans);
			getEl(com_form_ans).innerHTML = 'Ответ на комментарий: <b>' + getEl('comm_'+comm_id).innerHTML + '</b>';
		}
	}
}

function send_comment ()
{
	xajax_AddComments(xajax.getFormValues('commentform'));
}

function ready_comments ()
{
	Set_Alt_Text ('author', 'Ваше Имя:');
	Set_Alt_Text ('email', 'Ваш E - mail:');
	Set_Alt_Text ('icq', 'Ваш icq:');
	Set_Alt_Text ('code', 'Антиспам код:');
}

function Set_Alt_Text (elm, text)
{
	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/' + escape(getEl('search_text').value) );
	location.replace( '/search/' + getEl('search_text').value);
}

function start_calendar (now_day, now_month, now_year)
{
//	var now_day = '22';
//	var now_month = '08';
//	var now_year = '2008';
	YAHOO.namespace("example.calendar");

	YAHOO.example.calendar.init = function() {
		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: ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"]
			} );
		temp_date = new Date();
		day = temp_date.getDate();
		month = temp_date.getMonth() + 1;
		year = temp_date.getFullYear();
		day = (day < 10) ? "0" + day : day;
		month = (month <10) ? "0" + month : month;
		if (day < now_day && month <= now_month && year <= now_year)
		{
			if (day !== now_day && month !== now_month && year !== now_year)
				YAHOO.example.calendar.cal1.select(day + '.' + month + '.' + year);
			YAHOO.example.calendar.cal1.select(now_day + '.' + now_month + '.' + now_year);
			YAHOO.example.calendar.cal1.cfg.setProperty("PAGEDATE", now_month + '.' + now_year);
		} else {
			YAHOO.example.calendar.cal1.select(day + '.' + month + '.' + year);
			YAHOO.example.calendar.cal1.cfg.setProperty("PAGEDATE", month + '.' + 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 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 (year < 1000) year = year + 1900;

		temp_date = new Date();
		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;
		if (day > n_day && month >= n_month && year >= n_year)
		{
			alert ('Выбранная дата еще не наступила');
		} else {
			window.location = '/date/' + year + '_' + month + '_' + day + '.html';
		}
	}
}


var Garbage = {

	elements: [],

	collect: function(el){
		if (!el.$tmp){
			Garbage.elements.push(el);
			el.$tmp = {'opacity': 1};
		}
		return el;
	},

	trash: function(elements){
		for (var i = 0, j = elements.length, el; i < j; i++){
			var isEmbed = false;
			if (!(el = elements[i]) || !el.$tmp) continue;
			if (el.$events) el.fireEvent('trash').removeEvents();
			for (var p in el.$tmp) el.$tmp[p] = null;
			if (!$defined(el.tagName) || ($defined(el.tagName) && el.tagName.toLowerCase() != 'embed'))
				for (var d in Element.prototype) el[d] = null;
			else
				isEmbed = true;
			Garbage.elements[Garbage.elements.indexOf(el)] = null;
			if (!isEmbed){
				el.htmlElement = el.$tmp = el = null;
			}
		}
		Garbage.elements.remove(null);
	},

	empty: function(){
		Garbage.collect(window);
		Garbage.collect(document);
		Garbage.trash(Garbage.elements);
	}

};
