function withrequest(text,url)
{
	if (confirm(text)) {
		document.location.href=url;
	}
}

function init_tinymce (sField) {
		tinyMCE.init({
		// General options
		language: "ru",
		mode : "exact",
		elements : sField,
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,images,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,uppercase",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,uppercase,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,images,image,|,insertdate,inserttime,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,cleanup,help,code,preview",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "/images/editor.css,/images/pages.css",

		file_browser_callback : "tinyBrowser",
		
		//Path
		relative_urls : false,
		remove_script_host : true
		
	});
}

function init_np_tinymce () {
	tinyMCE.init({
		// General options
		language: "ru",
		mode : "none",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,images,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,uppercase",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,uppercase,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,images,image,cleanup,|,insertdate,inserttime,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,help,code,preview",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "/images/editor.css,/images/pages.css",

		file_browser_callback : "tinyBrowser",
		
		//Path
		relative_urls : false,
		remove_script_host : true
	});
}

function init_simple_tinymce()
{
	tinyMCE.init({
		// General options
		language: "ru",
		mode : "exact",
		theme : "advanced",
		elements : "body,descr",
		plugins : "safari,uppercase,images,advimage,advlink,paste,inlinepopups",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,uppercase,sup,images,image,link,unlink",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "/images/editor.css,/images/pages.css",

		file_browser_callback : "tinyBrowser",
		
		//Path
		relative_urls : false,
		remove_script_host : true
	});
}

function toggle_tinymce(sField)
{
	if (tinyMCE.getInstanceById(sField)) {
	    tinyMCE.execCommand('mceFocus', false, sField);                    
	    tinyMCE.execCommand('mceRemoveControl', false, sField);
	} else {
		tinyMCE.execCommand('mceAddControl', false, sField);
	}
}

function toggle_tinymce_mode(sField)
{
	if (tinyMCE.getInstanceById(sField)) {
	    tinyMCE.execCommand('mceFocus', false, sField);                    
	    tinyMCE.execCommand('mceRemoveControl', false, sField);
	    init_tinymce(sField);
	    $('#' + sField + '_editor_link').hide();
	}
}

function SetPreviewImage(vImage, vWidth, vHeight, vSize) {
	oImage = $('#preview_image');
	oImage.attr('src','/images/e.gif');
	oImage.attr('src',vImage);
	if (vWidth > 250) {
		oImage.attr('width','250');
		oImage.attr('height',vHeight / (vWidth / 250));
	} else {
		oImage.attr('width',vWidth);
		oImage.attr('height',vHeight);
	}
	$('#preview_image_info').html('<p><b>Информация:</b><br />Ширина: ' + vWidth + ' px<br />Высота: ' + vHeight + ' px<br />Размер файла: ' + vSize + ' b</p>');
}

function SetSelectedFile(sFieldID,vLink) {
	opener.document.getElementById("inp_" + sFieldID).value = vLink;
	opener.document.getElementById("span_" + sFieldID).innerHTML = 'Выбран файл: ' + vLink + ' <a href="javascript:void(0)" onclick="RemoveFile(\'' + sFieldID + '\')">убрать</a>' + 
					' <input type="checkbox" id="del_' + sFieldID + '" class="checkbox_width"> удалить с сервера';
	close();
}

function RemoveFile(sFieldID,sTable,iID)
{
	if (document.getElementById("del_" + sFieldID).checked && window.confirm('Вы действительно хотите удалить файл с сервера?')) {
		$('#sys_messages').load('_ajDelFile.php?file=' + encodeURIComponent($('#inp_' + sFieldID).val()) + '&table=' + sTable + '&id=' + iID + '&field=' + sFieldID);
	}
	$('#inp_' + sFieldID).val('');
	$('#span_' + sFieldID).html('');
	$('#img_' + sFieldID).remove();
}

function SelectFile(sFieldID,sType)
{
	window.open('/admin/_popup_sf.php?field_id=' + sFieldID + '&type=' + sType,'popup_sf','location=0,status=0,scrollbars=1,location=0,menubar=0,resizable=0,width=600,height=400');
}

function PopupWnd(sUrl,sWndName,iWidth,iHeight,iScrollbars)
{
	window.open(sUrl,sWndName,'location=0,status=0,scrollbars=' + iScrollbars + ',location=0,menubar=0,resizable=1,width=' + iWidth + ',height=' + iHeight);
}

function insert_uploaded_image()
{
	code = $('#insertcode').val();
	code = code.replace('title','title="' + $('#alt').val() + '"');
	code = code.replace('attrs','alt="' + $('#alt').val() + '" title="' + $('#alt').val() + '" align="' + $('#alignment').val() + '" class="inserted_' + $('#alignment').val() + '_image"')
	ImagesDialog.insert(code);
	tinyMCEPopup.close();
}

function init_pages()
{
	$(document).ready(function(){
		preload_images('/images/transp_lite.png','/images/menu_bg_over.gif');
		$('#search_field').bind('focus',function(){if ($(this).val() == 'Поиск по сайту...') $(this).val('')});
		$('#search_field').bind('blur',function(){if ($(this).val() == '') $(this).val('Поиск по сайту...')});
        $("ul#mainmenu").superfish(); 
		$("a.lightview").fancybox();
		$(".fadeimage").each(function () {
			$(this).fadeTo(10,0.5);
			$(this).hover(
				function () {
					$(this).fadeTo(100,1);
				},
				function () {
					$(this).fadeTo(100,0.5);
				}
			);
		});
    }); 
}

function select_date(sDate,sListType)
{
	if (sListType == 'action') {
		sListID = 'actions_list';
		sLink = '_ajActionsList';
	} else if (sListType == 'gallery') {
		sListID = 'galleries_list';
		sLink = '_ajGalleriesList';
	} else if (sListType == 'video') {
		sListID = 'video_list';
		sLink = '_ajVideoList';
	} else if (sListType == 'extnews') {
		sListID = 'extnews_list';
		sLink = '_ajExtNewsList';
	} else {
		sListID = 'newspapers_list';
		sLink = '_ajNewspapersList';
	}
	$('#' + sListID).load('/' + sLink + '.php?date=' + sDate);
}


function select_month(iMonth,iYear,sListType)
{
	var bCalendar = true;
	if (sListType == 'action') {
		sListID = 'actions_list';
		sLink = '_ajActionsList';
	} else if (sListType == 'gallery') {
		sListID = 'galleries_list';
		sLink = '_ajGalleriesList';
	} else if (sListType == 'laws') {
		sListID = 'laws_list';
		sLink = '_ajLawsList';
		bCalendar = false;
	} else if (sListType == 'video' || sListType == 'video_link') {
		sListID = 'video_list';
		sLink = '_ajVideoList';
	} else if (sListType == 'extnews' || sListType == 'extnews_link') {
		sListID = 'extnews_list';
		sLink = '_ajExtNewsList';
	} else {
		sListID = 'newspapers_list';
		sLink = '_ajNewspapersList';
	}
	if (bCalendar) $('#calendar').load('/_ajCalendar.php?month=' + iMonth + '&year=' + iYear + '&type=' + sListType);
	$('#' + sListID).load('/' + sLink + '.php?month=' + iMonth + '&year=' + iYear);
	$('.newspaper_years_selected').removeClass('newspaper_years_selected');
	$('.newspaper_years_month_selected').removeClass('newspaper_years_month_selected');
	$('#newspaper_year_' + iYear).addClass('newspaper_years_selected');
	$('#newspaper_year_' + iYear + '_' + iMonth).addClass('newspaper_years_month_selected');
}

function select_year(iYear)
{
	if ($('#newspaper_year_' + iYear + '_container').css('display') == 'none') {
		$('.newspaper_years_container > .newspaper_year_months_container').slideUp();
		$('#newspaper_year_' + iYear + '_container').slideDown();
	}
}

function user_login()
{
	$('#sys_messages').load('/login.php',{'username':$('#login_username').val(),'password':$('#login_password').val(),'remember':$('#login_remember').attr('checked')?1:0});
}

function user_logout()
{
	$('#sys_messages').load('/logout.php');
}

function preload_images() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preload_images.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

var main_block_timer;
var current_block_image = 0;

function start_slidewshow() {
	if (main_blocks_count < 2) return;
	main_block_timer = window.setTimeout(function(){slideshow_smooth()},10000);
}

function slideshow_smooth()
{
	if (typeof main_block_timer != "undefined") window.clearTimeout(main_block_timer);
	$('#selector_' + current_block_image).attr('src','/images/button_gray.png');
	$('#mainphoto_title_' + current_block_image).removeClass('mainphoto_internet_selected');
	$('#mainphoto_' + current_block_image).fadeTo(200,0,function () {
		$('#mainphoto_' + current_block_image).hide();
		current_block_image++;
		if (current_block_image >= main_blocks_count) current_block_image = 0;
		$('#mainphoto_' + current_block_image).show();
		$('#mainphoto_' + current_block_image).fadeTo(200,1);
		$('#selector_' + current_block_image).attr('src','/images/button_red.png');
		$('#mainphoto_title_' + current_block_image).addClass('mainphoto_internet_selected');
	});
	main_block_timer = window.setTimeout(function(){slideshow_smooth()},10000);
}

function slideshow_fast(select_block_image)
{
	if (typeof select_block_image == "undefined") return;
	if (select_block_image == current_block_image) return;
	if (typeof main_block_timer != "undefined") window.clearTimeout(main_block_timer);
	$('#selector_' + current_block_image).attr('src','/images/button_gray.png');
	$('#mainphoto_title_' + current_block_image).removeClass('mainphoto_internet_selected');
	$('#mainphoto_' + current_block_image).fadeTo(10,0,function () {
		$('#mainphoto_' + current_block_image).hide();
		current_block_image = select_block_image;
		$('#mainphoto_' + current_block_image).show();
		$('#mainphoto_' + current_block_image).fadeTo(10,1);
		$('#selector_' + current_block_image).attr('src','/images/button_red.png');
		$('#mainphoto_title_' + current_block_image).addClass('mainphoto_internet_selected');
	});
	main_block_timer = window.setTimeout(function(){slideshow_smooth()},10000);
}

var current_index_newspaper = 0;

function change_index_video(dir)
{
	$('#video_' + current_index_newspaper).hide();
	current_index_newspaper = current_index_newspaper + dir;
	$('#video_' + current_index_newspaper).show();
}

var pause_timer = null;

function show_with_pause(el)
{
	pause_timer = window.setTimeout("$('#" + el + "_news').fadeIn(300)",200);
	$('#' + el + '_logo').addClass(el + '_logo_hover')
}

function hide_with_pause(el)
{
	$('#' + el + '_news').hide();
	window.clearTimeout(pause_timer);
	$('#' + el + '_logo').removeClass(el + '_logo_hover')
}

function show_without_pause(el)
{
	$('#' + el + '_news').show();
	$('#' + el + '_logo').addClass(el + '_logo_hover')
}

function hide_without_pause(el)
{
	$('#' + el + '_news').hide();
	$('#' + el + '_logo').removeClass(el + '_logo_hover')
}

var months = ['января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря'];

function index_time()
{
	var date = new Date();
	$('.curr_dtime_time').html(get_formatted_time(date));
	$('.curr_dtime_date').html(get_formatted_date(date));
	window.setTimeout('index_time()',1000);
}

function get_formatted_time(date)
{
	hour = date.getHours();
	if (hour<10) hour = '0' + hour;
	minute = date.getMinutes();
	if (minute<10) minute = '0' + minute;
	var delim = ' ';
	if (date.getSeconds()%2 == 0) delim = ':';
	return hour + delim + minute;
}

function get_formatted_date(date)
{
	return date.getDate() + ' ' + months[date.getMonth()] + ' ' + date.getFullYear();
}