var toolbar = {
	bookmark: null,
	activeW: 0,
	posY: 0,
	hideW: function(id) {
		id = id||toolbar.activeW;
		
		if($("personInfoPopup" + id)) {
			$("personInfoPopup" + id).down('form').reset();
			$("personInfoPopup" + id).hide();
			toolbar.activeW = 0;
		}
	},
	showW: function(id, where) {
		var h = $("personInfoPopup" + id).getHeight();
		$("personInfoPopup" + id).setStyle({
			left: (where.x - 10) + "px",
			top: (where.y - h) + "px"
		});
		toolbar.posY = where.y;
		
		toolbar.hideW();
		toolbar.setAnchor();
		$("personInfoPopup" + id).show();
		$("personInfoPopup" + id).down("form").focusFirstElement();
		toolbar.activeW = id;
	},
	repositionW: function(id) {
		var h = $("personInfoPopup" + id).getHeight();
		$("personInfoPopup" + id).setStyle({
			top: (toolbar.posY - h) + "px"
		});
	},
	replaceAnchor: function(text){
		if((typeof tinyMCE != 'undefined') && tinyMCE.activeEditor.selection.getContent({format : 'raw'}) == ''){
			tinyMCE.activeEditor.getBody().innerHTML = tinyMCE.activeEditor.getBody().innerHTML.replace(/<img[^>]*mceanchor_pls[^>]*>/gi, text);
		}
	},
	setAnchor: function(){
		if((typeof tinyMCE != 'undefined') && tinyMCE.activeEditor.selection.getContent({format : 'raw'}) == ''){
			tinyMCE.activeEditor.execCommand('mceInsertRawHTML', false, '<img class="mceanchor_tmp" width=1 height=1 style="display:none">');
			toolbar.replaceAnchor('');
			tinyMCE.activeEditor.getBody().innerHTML = tinyMCE.activeEditor.getBody().innerHTML.replace(/<img[^>]*mceanchor_tmp[^>]*>/gi, '<img class="mceanchor_pls" width=1 height=1 style="display:none">');
		}
	},
	user : {
		activeT: "t0",
		id: 7,
		onlyFriends: false,
		clear: function(id) {
			var searchElement = $("personInfoPopup" + id).down("input[name='search']");
			searchElement.value = "";
			//$('searchResult').update("");
			toolbar.user.search("");
		},
		template: '<div id="personInfoPopup#{id}" class="popupBallon personInfo add" style="display: none;">' +
			'<div class="c l"></div><div class="c r"></div><ul class="tabs"><li id="t2"><div class="c l"></div><div class="c r"></div>Все</li><li id="t0" class="active"><div class="c l"></div><div class="c r"></div>Члены клуба</li><li id="t1"><div class="c l"></div><div class="c r"></div>Подписчики</li></ul>' +
			'<div class="blackRC add"><div class="cn tl"></div><div class="cn tr"></div><div class="content">' +
			'<form onSubmit="return false;"><div class="canvas"><div class="row"><div class="opb o"><div class="opb i"><input type="text" name="search" /></div></div></div>' +
			'<div class="row"><div class="opb o"><div class="opb i"><div id="searchResult"></div></div></div></div>' +
			'</div><div class="twobtn"><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.hideW(#{id}); return false;"><b>Отмена</b></a></div><div class="controll ok"><a href="#" class="sendPersonMessage btn" onclick="toolbar.user.save(); return false;"><b>Ок</b></a></div></div></form>' +
			'</div><div class="cn bl"></div><div class="cn br"></div></div></div>',
		popup: function(where) {
			var id = toolbar.user.id;
			if(!$("personInfoPopup" + id)) {
				Element.insert(document.body, {'top': toolbar.user.template.interpolate({id: id})});
				$("personInfoPopup" + id).select(".tabs li").each(function(n) {
					n.observe("click", function(e){
						var element = Event.element(e);
						if(!toolbar.user.activeT.blank()) {
							$(toolbar.user.activeT).removeClassName("active");
						}
						element.addClassName("active");
						toolbar.user.activeT = element.id;
						toolbar.user.clear(id);
					});
				});
			}
			
			toolbar.user.clear(id);
			
			var searchElement = $("personInfoPopup" + id).down("input[name='search']");
			searchElement.observe("keyup", function(e) {
				var element = Event.element(e);
				
				toolbar.user.search(element.value);
			});
			
			toolbar.showW(id, where);
		},
		search: function(value) {
			new Ajax.Request('/webservices/searchforperson/', {
				method: 'post',
				postBody: $H({type: toolbar.user.activeT.replace("t", ""), str: value, onlyFriends: toolbar.user.onlyFriends}).toQueryString(),
				onComplete: function(response) {
					var data = response.responseText.evalJSON();
					if (data.status != "error") {
						$('searchResult').update(toolbar.user.draw(data.list));
						
						if($('searchResult').down("li")) {
							$('searchResult').select("li").each(function(n){
								n.observe("click", function(e) {
									Event.stop(e);
									var element = Event.element(e);
									if(element.tagName.toUpperCase() != "LI") {
										element = $(element).up("li");
									}
									
									toolbar.user.deselect();
									
									element.addClassName("selected");
								});
							});
						}
					}
				}
			});
		},
		deselect: function() {
			$('searchResult').select("li").each(function(n) {
				n.removeClassName("selected");
			});
		},
		draw: function(list) {
			var output = "";
			$A(list).each(function(n){
				output += '<li id="' + n.id + '">' + n.name + ' <b>' + n.lastname + '</b></li>';
			});
			
			return !output.blank() ? "<ul>" + output + "</ul>" : "";
		},
		save: function() {
			var element = $('searchResult').select("li").find(function(n) {
				return n.hasClassName("selected");
			});
			
			toolbar.user.action(element);
			
			toolbar.hideW(toolbar.user.id);
		},
		action: function(element) {
			if(element) {
				var ed = tinyMCE.activeEditor;
				if(toolbar.bookmark) {
					ed.selection.moveToBookmark(toolbar.bookmark);
				}
				if(tinymce.isIE){
					toolbar.replaceAnchor('[user id="' + element.id + '"]' + element.innerHTML.stripTags() + '[/user]');
				}
				else{
					ed.execCommand('mceInsertContent', false, '[user id="' + element.id + '"]' + element.innerHTML.stripTags() + '[/user]');
				}
			}
		}
	},
	
	embed : {
		id: 6,
		template: '<div id="personInfoPopup#{id}" class="popupBallon personInfo" style="display: none;">' +
			'<div class="blackRC"><div class="cn tl"></div><div class="cn tr"></div><a href="#" class="close-button" onclick="toolbar.hideW(#{id}); return false;"></a><div class="content">' +
			'<strong style="text-transform: uppercase;">#{name}</strong>' +
			'<form onSubmit="return false;"><div class="canvas"><div class="row"><div class="opb o"><div class="opb i"><textarea name="code" id="code"></textarea></div></div></div></div><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.embed.save($(this).up(\'form\')); return false;"><b>Ок</b></a></div></form>' +
			'</div><div class="cn bl"></div><div class="cn br"></div></div></div>',
		popup: function(where) {
			var id = toolbar.embed.id;
			if(!$("personInfoPopup" + id)) {
				Element.insert(document.body, {'top': toolbar.embed.template.interpolate({id: id, name: "Вставить код"})});
			}
			
			$("personInfoPopup" + id).down("textarea").value = "";
			toolbar.showW(id, where);
		},
		save: function(form) {
			if(!$(form["code"]).getValue().empty()) {
				var ed = tinyMCE.activeEditor;
				
				if(toolbar.bookmark) {
					ed.selection.moveToBookmark(toolbar.bookmark);
				}
				if(tinymce.isIE){
					toolbar.replaceAnchor('<p>[code]' + form["code"].getValue().escapeHTML() + '[/code]</p>');
				}
				else{
					ed.execCommand('mceInsertContent', false, '<p>[code]' + form["code"].getValue().escapeHTML() + '[/code]</p>');
				}
			}
			
			toolbar.hideW(toolbar.embed.id);
		}
	},
	colorpicker : {
		id: 4,
		template: '<div id="personInfoPopup#{id}" class="colorPicker" style="display: none;"><div class="inner">#{data}</div></div>',
		popup: function(where, id) {
			var id = id || toolbar.colorpicker.id;
			toolbar.colorpicker.id = id;
			var data = "";
			
			for(i = 0; i<toolbar.colorpicker.colors.length; i++) {
				data += '<div class="cell" style="background-color: ' + toolbar.colorpicker.colors[i] + ';"></div>';
			}
			
			if(!$("personInfoPopup" + id)) {
				where.insert({'after': toolbar.colorpicker.template.interpolate({id: id, data: data})});
				$("personInfoPopup" + id).select(".cell").each( function(n) {
					n.observe("click", toolbar.colorpicker.save.bindAsEventListener(toolbar));
				});
			}
			
			toolbar.hideW();
			$("personInfoPopup" + id).show();
			toolbar.activeW = id;
		},
		save: function(e) {
			Event.stop(e);
			var element = e.element();
			var id = toolbar.colorpicker.id;
			
			var ed = tinyMCE.activeEditor;
			var color = element.getStyle("backgroundColor");
			
			if(id == 5) {
				ed.execCommand('HiliteColor', false, color);
			} else {
				ed.execCommand('ForeColor', false, color);
			}
			toolbar.hideW(id);
		},
		colors: [
			"#ff0000","#ffff00","#00ff00","#00ffff","#0000ff","#ff00ff","#ffffff","#ebebeb",
			"#e1e1e1","#d7d7d7","#cccccc","#c2c2c2","#b7b7b7","#acacac","#a0a0a0","#959595",
			"#ed1c24","#fff200","#00a651","#00aeef","#2e3192","#ec008c","#898989","#7d7d7d",
			"#707070","#626262","#555555","#464646","#363636","#262626","#111111","#000000",
			"#f7977a","#f9ad81","#fdc68a","#fff79a","#c4df9b","#a2d39c","#82ca9d","#7bcdc8",
			"#6ecff6","#7ea7d8","#8493ca","#8882be","#a187be","#bc8dbf","#f49ac2","#f6989d",
			"#f26c4f","#f68e55","#fbaf5c","#fff467","#acd372","#7cc576","#3bb878","#1abbb4",
			"#00bff3","#438cca","#5574b9","#605ca8","#855fa8","#a763a8","#f06ea9","#f26d7d",
			"#ed1c24","#f26522","#f7941d","#fff200","#8dc73f","#39b54a","#00a651","#00a99d",
			"#00aeef","#0072bc","#0054a6","#2e3192","#662d91","#92278f","#ec008c","#ed145b",
			"#9e0b0f","#a0410d","#a36209","#aba000","#598527","#1a7b30","#007236","#00746b",
			"#0076a3","#004b80","#003471","#1b1464","#440e62","#630460","#9e005d","#9e0039",
			"#790000","#7b2e00","#7d4900","#827b00","#406618","#005e20","#005826","#005952",
			"#005b7f","#003663","#002157","#0d004c","#32004b","#4b0049","#7b0046","#7a0026",
			"#c7b299","#998675","#736357","#534741","#37302d","#c69c6e","#a67c52","#8c6239",
			"#754c24","#603913"
		]
	},
	addlink : {
		text: '',
		template: '<div id="personInfoPopup#{id}" class="popupBallon personInfo" style="display: none;">' +
			'<div class="blackRC"><div class="cn tl"></div><div class="cn tr"></div><a href="#" class="close-button" onclick="toolbar.hideW(#{id}); return false;"></a><div class="content">' +
			'<strong style="text-transform: uppercase;">#{name}</strong>' +
			'<form onSubmit="return false;"><div class="canvas"><div class="row"><label>Ссылка:</label><div class="opb o"><div class="opb i"><input type="text" name="url" id="url" value="#{value}" /></div></div></div></div><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.addlink.save($(this).up(\'form\'), #{id}); return false;"><b>Сохранить</b></a></div></form>' +
			'</div><div class="cn bl"></div><div class="cn br"></div></div></div>',
		popup: function(where) {
			var id = 3;
			var ed = tinyMCE.activeEditor;
			var href = "";
			
			if (e = ed.dom.getParent(ed.selection.getNode(), 'A')) {
				href = ed.dom.getAttrib(e, 'href');
			}
			
			toolbar.addlink.text = ed.selection.getContent({format : 'text'});
			
			if(!$("personInfoPopup" + id)) {
				Element.insert(document.body, {'top': toolbar.addlink.template.interpolate({id: id, name: "Добавить / изменить ссылку", value: href})});
			}
			
			$("personInfoPopup" + id).down("input[name='url']").value = href;
			toolbar.showW(id, where);
		},
		save: function(form, id) {
			var ed = tinyMCE.activeEditor;
			
			if(toolbar.bookmark) {
				ed.selection.moveToBookmark(toolbar.bookmark);
			}
			
			var e = ed.dom.getParent(ed.selection.getNode(), 'A');
			
			// Remove element if there is no href
			if ((form["url"]).getValue().empty()) {
				if (e) {
					b = ed.selection.getBookmark();
					ed.dom.remove(e, 1);
					ed.selection.moveToBookmark(b);
					toolbar.hideW(id);
					return;
				}
			}
			
			var url = form["url"].getValue();
			if(!url.startsWith('http://') && !url.startsWith('/')) {
			    url = "http://" + url;
			}
			if (e == null) {
				ed.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});

				tinymce.each(ed.dom.select("a"), function(n) {
					if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
						e = n;
						ed.dom.setAttribs(e, {href : url});
					}
				});
			} else {
				ed.dom.setAttribs(e, {href : url});
			}
			
			if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
				ed.focus();
				ed.selection.select(e);
				ed.selection.collapse(0);
			}
			
			toolbar.hideW(id);
		}
	},
	addvideo: {
		isLoading: false,
		id: 2,
		template: '<div id="personInfoPopup#{id}" class="popupBallon personInfo video" style="display: none;">' +
			'<div class="blackRC"><div class="cn tl"></div><div class="cn tr"></div><a class="close-button" href="#" onclick="toolbar.hideW(#{id}); toolbar.addvideo.cancel(); return false;"></a><div class="content">' +
			'<strong class="icon">#{name}</strong>' +
			'<form onsubmit="return false;" method="post" enctype="multipart/form-data"><div class="canvas"><div class="row"><label>Загрузить видео файл с компьютера:</label><input type="file" size="40" name="upload" id="upload" /></div><i>Размер видео не&nbsp;должен превышать 1024&nbsp;МБ и&nbsp;15&nbsp;минут</i></div><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.addvideo.save($(this).up(\'form\'), #{id}); return false;"><b>Загрузить видео файл</b></a></div></form>' +
			'<div class="progressBar" style="display: none;"><div class="outter"><div class="inner" id="uploadProgressBar"></div></div><i>Загрузка видео файла: <span id="fileName">keygen.exe</span></i><span id="fileSize">&nbsp;</span><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.addvideo.cancel(); return false;"><b>Отмена</b></a></div></div>' +
			'<div class="progressBarDone" style="display: none;"><strong>Видео файл загружен успешно!</strong><i>Нажмите кнопку "Ок" чтобы увидеть превью.</i><div class="controll"><a href="javascript:return false;" class="sendPersonMessage btn" onclick="toolbar.addvideo.done(this); return false;"><b>Ок</b></a></div></div>' +
			'<div class="progressBarError" style="display: none;"><strong></strong><i>Выберите другой файл.</i><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.addvideo.cancel(); return false;"><b>Ок</b></a></div></div>' +
			'</div><div class="cn bl"></div><div class="cn br"></div></div></div><iframe name="upload_iframe" id="upload_iframe" style="width: 0px; height: 0px; display: none;"></iframe>',
		popup: function(where) {
			if(!$("personInfoPopup" + toolbar.addvideo.id)) {
				Element.insert(document.body, {'top': toolbar.addvideo.template.interpolate({id: toolbar.addvideo.id, name: "Видео"})});
			}
			toolbar.showW(toolbar.addvideo.id, where);
		},
		done: function() {
			var response = $('upload_iframe').contentWindow.document.body.innerHTML;
			if(!response.empty()) {
				var data = null;
				try {
					var data = response.evalJSON();
				} catch (e) { }
				
				if(data && data.status != "error") {
					var ed = tinyMCE.activeEditor;
					if(Prototype.Browser.Opera){
						ed.execCommand('mceInsertContent', false, '[video id="' + data.resource + '"]');
					}
					else{
						toolbar.replaceAnchor('<i class="mceNonEditable videoPreview" style="background-image: url(/i/empty_video.jpg);" rel="' + data.resource + '"><a href="#" class="mceNonEditable"><br /></a></i><br>');
						//ed.execCommand('mceInsertContent', false, '<p><div class="mceNonEditable videoPreview" style="background-image: url(/i/empty_video.jpg);" rel="' + data.resource + '"><a href="#" class="mceNonEditable"><br /></a></div></p><br/>');
						//ed.selection.moveToBookmark(toolbar.bookmark);
					}
					if(iDescriptionTinyMCE && iDescriptionTinyMCE.edLabel != ''){
						iDescriptionTinyMCE.hideLabel();
					}
				}
				toolbar.hideW();
				toolbar.addvideo.cancel();
			}
		},
		cancel: function() {
			$('upload_iframe').src = 'about:blank';
			
			var container = $("personInfoPopup" + toolbar.addvideo.id);
			container.down('.progressBarError').hide();
			container.down('.progressBarDone').hide();
			container.down('.progressBar').hide();
			container.down('form').reset();
			container.down('form').show();
			toolbar.repositionW(toolbar.addvideo.id);
			toolbar.addvideo.isLoading = true;
		},
		save: function(form, id) {
			/* generate random progress-id */
			var uuid = "";
			for (i = 0; i < 32; i++) {
			  uuid += Math.floor(Math.random() * 16).toString(16);
			}
			
			form.action = "/webservices/uploadfile/?fname=upload&type=video&X-Progress-ID=" + uuid;
			$('fileName').update($(form["upload"]).getValue());
			
			toolbar.addvideo.isLoading = false;
			new PeriodicalExecuter(toolbar.addvideo.fetch.bindAsEventListener(toolbar, uuid), 2);
			
			form.target = 'upload_iframe';
			form.submit();
			
			$(form).hide();
			$(form).next('.progressBar').show();
			toolbar.repositionW(toolbar.addvideo.id);
		},
		fetch: function(pe, uuid) {
			if(toolbar.addvideo.isLoading) return;
			
			new Ajax.Request('/progress/', {
				method: 'get',
				requestHeaders: {"X-Progress-ID": uuid},
				onComplete: function(response) {
					$('fileSize').update('');

					var upload = response.responseText.evalJSON();

					if(upload.state == 'error') {
						pe.stop();
						toolbar.addvideo.isLoading = false;
						
						var container = $("personInfoPopup" + toolbar.addvideo.id);
						container.down('.progressBar').hide();
						container.down('form').show();
						toolbar.repositionW(toolbar.addvideo.id);
						return;
					}
					
					if(upload.size > 1024*1024*1024) {
						pe.stop();
						$('upload_iframe').src = 'about:blank';
						toolbar.addvideo.isLoading = false;
						
						var container = $("personInfoPopup" + toolbar.addvideo.id);
						container.down('.progressBar').hide();
						container.down('.progressBarError strong').update('Размер файла превышает допустимый предел.');
						container.down('.progressBarError').show();
						toolbar.repositionW(toolbar.addvideo.id);
						return;
					}
					
					if (upload.state == 'done') {
						pe.stop();
						toolbar.addvideo.isLoading = false;
						
						var container = $("personInfoPopup" + toolbar.addvideo.id);
						container.down('.progressBar').hide();
						
						var response = $('upload_iframe').contentWindow.document.body.innerHTML;
						if(!response.empty()) {
							var data = null;
							try {
								var data = response.evalJSON();
							} catch (e) { }

							if(data && data.status != "error") {
								container.down('.progressBarDone').show();
							} else {
								container.down('.progressBarError strong').update('Ошибка при заливке файла.');
								container.down('.progressBarError').show();
							}
						}
						
						toolbar.repositionW(toolbar.addvideo.id);
						return;
					}
					if(upload.received != 'undefined') {
						$('fileSize').update(toolbar.addvideo.readablizeBytes(upload.received) + ' из ' + toolbar.addvideo.readablizeBytes(upload.size));

						if (upload.state == 'done' || upload.state == 'uploading') {
							var w = 290 * upload.received / upload.size;
							$('uploadProgressBar').setStyle({ width: w + 'px'});
						}
					}
					
					toolbar.addvideo.isLoading = false;
				}
			});
			toolbar.addvideo.isLoading = true;
		},
		readablizeBytes: function (bytes) {
		    var s = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ'];
		    var e = Math.floor(Math.log(bytes)/Math.log(1024));
		    return (bytes/Math.pow(1024, Math.floor(e))).toFixed(1) + " " + s[e];
		}
	},
	addimage: {
		template: '<div id="personInfoPopup#{id}" class="popupBallon personInfo" style="display: none;">' +
			'<div class="blackRC"><div class="cn tl"></div><div class="cn tr"></div><a href="#" class="close-button" onclick="toolbar.hideW(#{id}); return false;"></a><div class="content">' +
			'<strong style="text-transform: uppercase;">#{name}</strong>' +
			'<form onsubmit="return false;" method="post" enctype="multipart/form-data"><div class="canvas"><input type="hidden" name="entryId" value="#{id}" /><div class="row"><label>Из файла:</label><input type="file" size="50" name="upload" id="upload" /></div><div class="row"><label>Ссылка из сети:</label><div class="opb o"><div class="opb i"><input type="text" name="url" id="url" /></div></div></div><i>Допустимы форматы GIF, JPG и PNG</i></div><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.addimage.save($(this).up(\'form\'), #{id}); return false;"><b>Загрузить</b></a></div></form>' +
			'</div><div class="cn bl"></div><div class="cn br"></div></div></div><iframe name="upload_iframe" id="upload_iframe" style="width: 0px; height: 0px; display: none;"></iframe>',
		popup: function(where) {
			var id = 1;
			if(!$("personInfoPopup" + id)) {
				Element.insert(document.body, {'top': toolbar.addimage.template.interpolate({id: id, name: "Загрузить изображение"})});
				
				$('upload_iframe').observe("load", function(event) {
					Event.stop(event);
					var response = $('upload_iframe').contentWindow.document.body.innerHTML;
					if(!response.empty()) {
						var data = null;
						try {
							data = response.evalJSON();
						} catch (e) { }
						
						if(data && data.status != "error") {
							var ed = tinyMCE.activeEditor;
							toolbar.replaceAnchor('<img src="' + data.filename + '" />');
						}
						toolbar.hideW(id);
					}
				});
			}
			toolbar.showW(id, where);
		},
		save: function(form, id) {
			if(!$(form["url"]).getValue().empty()) {
				var ed = tinyMCE.activeEditor;
				toolbar.replaceAnchor('<img src="' + form["url"].getValue() + '" />');
				toolbar.hideW(id);
			}
			
			var unique = (new Date()).getTime();
			form.action = '/webservices/uploadfile/?fname=upload&unique=' + unique;
			form.target = 'upload_iframe';
			form.submit();
		}
	 },
	 cut : {
		id: 8,
		simpleCut: false,
		template: '<div id="personInfoPopup#{id}" class="popupBallon personInfo" style="display: none;">' +
			'<div class="blackRC"><div class="cn tl"></div><div class="cn tr"></div><a href="#" class="close-button" onclick="toolbar.hideW(#{id}); return false;"></a><div class="content">' +
			'<strong style="text-transform: uppercase;">#{name}</strong>' +
			'<form onSubmit="return false;"><div class="canvas"><div class="row"><div class="opb o"><div class="opb i"><input type="text" name="cutname" id="cutname" value="Читать дальше"></div></div></div></div><div class="controll"><a href="#" class="sendPersonMessage btn" onclick="toolbar.cut.save($(this).up(\'form\')); return false;"><b>Ок</b></a></div></form>' +
			'</div><div class="cn bl"></div><div class="cn br"></div></div></div>',
		popup: function(where) {
			var id = toolbar.cut.id;
			if(!$("personInfoPopup" + id)) {
				Element.insert(document.body, {'top': toolbar.cut.template.interpolate({id: id, name: "Введите заголовок для текста под катом"})});
			}

			$("personInfoPopup" + id).down("input").value = "Читать дальше";
			toolbar.showW(id, where);
		},
		save: function(form) {
				var ed = tinyMCE.activeEditor;
				ed.selection.moveToBookmark(toolbar.bookmark);

				var someCut = ed.dom.select('span');
				ed.dom.remove(someCut, 1);

				if(!form["cutname"].getValue().empty()){
					if(toolbar.cut.simpleCut == false){
						ed.execCommand('mceInsertContent', false, '<span class="scut" title="'+form["cutname"].getValue().escapeHTML()+'">' + ed.selection.getContent({format : 'raw'}) + '</span>');
					}
					else{
						toolbar.replaceAnchor('<span class="sscut" title="'+form["cutname"].getValue().escapeHTML()+'"></span>');
					}
				}

			toolbar.hideW(toolbar.cut.id);
		}
	}
};