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

function ask_confirm_cancel()
{
	return window.confirm('Вы действительно хотите отказаться от чтения этой книги?');
}

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 add_tag(sel_id)
{
	var new_tag = $('#new_tag').clone().prependTo($('#tags_list')).attr('id','').show();
	if (sel_id) new_tag.children('select').val(sel_id);
}

function init_tinymce () {
	tinyMCE.init({
		// General options
		language: "ru",
		mode : "specific_textareas",
		editor_selector : "mceEditor",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,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,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",

		file_browser_callback : "tinyBrowser",

		//Path
		relative_urls : false,
		remove_script_host : true
	});
}

function count_chars(el)
{
	$('#' + el + '_counter').html($('#' + el).val().length);
}

function CreateBookmarkLink(title,url)
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	} else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

function toggle_sub_menu(el,menu_id,prefix)
{
	if ($(el).hasClass(prefix + '_menu_item')) {
		$(el).removeClass('menu_' + menu_id).addClass('menu_open_' + menu_id);
		$(el).removeClass(prefix + '_menu_item').addClass(prefix + '_menu_item_open');
		$('#submenu_' + menu_id).show();
	} else {
		$(el).removeClass('menu_open_' + menu_id).addClass('menu_' + menu_id);
		$(el).removeClass(prefix + '_menu_item_open').addClass(prefix + '_menu_item');
		$('#submenu_' + menu_id).hide();		
	}
}

function news_item_show(id)
{
	$('#news_item_more_' + id).hide();
	$('#news_item_' + id).show();
}

function news_item_hide(id)
{
	$('#news_item_more_' + id).show();
	$('#news_item_' + id).hide();
}

function add_select_item(list_id, value)
{
	var selector_el = $('#items_selector_' + list_id);
	var new_selector_el = selector_el.clone().removeAttr('id').show();
	new_selector_el.find('select').val(value);
	new_selector_el.insertBefore(selector_el);
}

$(document).ready(function () {
	$('body').bind('selectstart', function () {return false});
});
