function vB_AJAX_Threadlist_Init(threadlistid)
{	//alert('123');
	if (ajax_compatible)
	{
		var tds = fetch_tags(fetch_object(threadlistid), 'td');
		for (var i = 0; i < tds.length; i++)
		{
			if (tds[i].hasChildNodes() && tds[i].id && tds[i].id.substr(0, 3) == 'td_')
			{
				var anchors = fetch_tags(tds[i], 'a');
				for (var j = 0; j < anchors.length; j++)
				{
					if (anchors[j].name && anchors[j].name.indexOf('vB::AJAX') != -1)
					{
						var details = tds[i].id.split('_');
						
						switch (details[1])
						{
							case 'toppost':
							{
								tds[i].style.cursor = 'default';
								clearTimeout(tds[i].timeout);
								tds[i].timeout = setTimeout(function(e) { openclose = new dbd003_AJAX_tick_toppost(this); }, 2000);
							}
							break;
						}

						break;
					}
				}
			}
		}
	}
}

// ------------------------- td поменял на span ------------------------------------------
function vB_AJAX_Threadlist_Init_2(threadlistid)
{	//alert('123');
	if (ajax_compatible)
	{
		var tds = fetch_tags(fetch_object(threadlistid), 'span');   // поменял td на span для лучшего отображения строк...
		for (var i = 0; i < tds.length; i++)
		{
			if (tds[i].hasChildNodes() && tds[i].id && tds[i].id.substr(0, 3) == 'td_')
			{
				var anchors = fetch_tags(tds[i], 'a');
				for (var j = 0; j < anchors.length; j++)
				{
					if (anchors[j].name && anchors[j].name.indexOf('vB::AJAX') != -1)
					{
						var details = tds[i].id.split('_');
						
						switch (details[1])
						{
							case 'title':
							{
								tds[i].style.cursor = 'default';
								//tds[i].ondblclick = function() { try { titleedit.restore(); } catch(e) {} titleedit = new vB_AJAX_TitleEdit(this); };
								tds[i].ondblclick = vB_AJAX_ThreadList_Events.prototype.threadtitle_doubleclick;
							}
							break;

							case 'status':
							{
								tds[i].style.cursor = 'default';
								//vB_DblClick_Handler(tds[i], function(e) { openclose = new vB_AJAX_OpenClose(this); });
								tds[i].ondblclick = vB_AJAX_ThreadList_Events.prototype.threadicon_doubleclick;
							}
							break;

							case 'fulltext':
							case 'fulltext2':
							{
								tds[i].style.cursor = 'default';
								//vB_DblClick_Handler(tds[i], function(e) { openclose = new vB_AJAX_OpenClose(this); });
								tds[i].onclick = vB_AJAX_ThreadList_Events.prototype.threadid_fulltext_click;
							}
							break;

						}

						break;
					}
				}
			}
		}
	}
}


// -------------------------------------------------------------------

function dbd003_AJAX_tick_toppost(obj) {
  var hours, minutes, seconds, ap;
  var intHours, intMinutes, intSeconds;  var today;

	this.obj = obj;
	//this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
	//alert(this.threadid);
	//this.imgobj = fetch_object('thread_toppost_1');
	this.xml_sender = null;

	/**
	* Function to switch the open/closed state of a thread / thread status icon
	*/
	this.toggle = function toggle_openclose()
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('/includes/ajax.php', 'do=toppost');
	}

	var me = this;

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{
			var toppost = (document.all) ? document.all("toppost") : document.getElementById("toppost");
			toppost.innerHTML = me.xml_sender.handler.responseText;
			 //me.imgobj.src = me.xml_sender.handler.responseText;
			
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}

	// send the data
	this.toggle();

  //alert('123');
  //today = new Date();
  //intSeconds = today.getSeconds();
  //timeString = intSeconds;

  //var toppost = (document.all) ? document.all("toppost") : document.getElementById("toppost");
  //toppost.innerHTML = timeString;
  //(document.all)?window.setTimeout("dbd003_AJAX_tick_toppost(obj);", 1000):window.setTimeout("dbd003_AJAX_tick_toppost(obj);", 6000);
  setTimeout(function(e) { openclose = new dbd003_AJAX_tick_toppost(obj); }, 300000);
}

// -------------------------------------------------------------------

function dbd003_AJAX_newpost(obj) {
  var hours, minutes, seconds, ap;
  var intHours, intMinutes, intSeconds;  var today;

	this.obj = obj;
	this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
	// linkobj заменил на messageobj для div .... 
	this.messageobj = fetch_object('post_new_' + this.threadid);
	this.container = fetch_object('newpost_container');
	//alert(this.threadid);
	this.xml_sender = null;

	/**
	* Function to switch the open/closed state of a thread / thread status icon
	*/
	this.toggle = function toggle_openclose()
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('/includes/ajax.php', 'do=newpost&t=' + this.threadid);
	}

	var me = this;

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{
			//var toppost = (document.all) ? document.all("toppost") : document.getElementById("toppost");
			//toppost.innerHTML = me.xml_sender.handler.responseText;
			//me.messageobj.innerHTML = me.xml_sender.handler.responseText;
			//newdiv = document.createElement('div');
			//newdiv.innerHTML = me.xml_sender.handler.responseText;
			lp=me.obj;					// 2-ой спан
			lpparent = lp.parentNode;  // 1-ый спан
			// store the original text
			var origtitle = me.container.innerHTML;
			me.container.innerHTML=me.xml_sender.handler.responseText + origtitle;
			
			// теперь будем искать индефикатор темы новой, чтобы инициализировать тему для дальнейшего редактирования...
			var tds = fetch_tags(me.container, 'span');
			for (var i = 0; i < tds.length; i++)
			{
				if (tds[i].hasChildNodes() && tds[i].id && tds[i].id.substr(0, 12) == 'threadsname_')
				{	
					//alert(tds[i].id);
					var details = tds[i].id.split('_');
					//alert(details[1]);
					vB_AJAX_Threadlist_Init_2('threadsname_' + details[1])
				}
			}

			//lpparent.innerHTML = 'текст'+me.origtitle;
			//lpparent = lp.parentNode;
			//lpparent3 = lp.ChildNode;
			//var postbit = lpparent.insertBefore(newdiv, lp);
			// var postbit = lpparent.appendChild(newdiv);
			//lpparent.innerHTML = 'текст'+lpparent.innerHTML;
			
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}

	// send the data
	this.toggle();

  //alert('123');
  //today = new Date();
  //intSeconds = today.getSeconds();
  //timeString = intSeconds;

  //var toppost = (document.all) ? document.all("toppost") : document.getElementById("toppost");
  //toppost.innerHTML = timeString;
  //(document.all)?window.setTimeout("dbd003_AJAX_tick_toppost(obj);", 1000):window.setTimeout("dbd003_AJAX_tick_toppost(obj);", 6000);
}


// #############################################################################
// vB_AJAX_OpenClose      Vote
// #############################################################################

/**
* Class to handle opening and closing of threads from forumdisplay with XML-HTTP
*
* @param	object	The clickable status icon image for the thread
*/
function vB_AJAX_OpenClose(obj)
{	
	this.obj = obj;
	this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
	this.imgobj = fetch_object('thread_status_' + this.threadid);
	this.xml_sender = null;

	/**
	* Function to switch the open/closed state of a thread / thread status icon
	*/
	this.toggle = function toggle_openclose()
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('/includes/ajax.php', 'do=updatethreadopen&t=' + this.threadid + '&src=' + PHP.urlencode(this.imgobj.src));
	}

	var me = this;

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{
			me.imgobj.src = me.xml_sender.handler.responseText;
			
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}

	// send the data
	this.toggle();
}

// #############################################################################
// vB_AJAX_Anons      Вывод анонса по требованию
// #############################################################################

/**
* Class to handle opening and closing of threads from forumdisplay with XML-HTTP
*
* @param	object	The clickable status icon image for the thread
*/

function vB_wait()
{
	return "<BR><CENTER><TABLE cellSpacing=0 cellPadding=0 width=60% border=0><TR>	<TD bgColor=#fcf2e6>	<TABLE cellSpacing=1 ellPadding=2 width=100% border=0>	   <TR>			<TD bgColor=#FFFFCC><CENTER>Грузится...</CENTER>			</TD>	   </TR>	</TABLE>	</TD></TR></TABLE></CENTER><BR>";
}


// #############################################################################
// vB_AJAX_GetFullText      Вывод полного текста темы по требованию
// #############################################################################

/**
* Class to handle opening and closing of threads from forumdisplay with XML-HTTP
*
* @param	object	The clickable status icon image for the thread
*/
function vB_AJAX_GetFullText(obj)
{	
	this.obj = obj;
	var homepath = fetch_object('homepath').innerHTML;
	//this.obj.onclick = '';  // анонс надо получать только один раз
	this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
	this.textobj = fetch_object('thread_anons_' + this.threadid);
	this.xml_sender = null;

	//alert("Анонс треба срочно.");
	if ((this.textobj.innerHTML.length > 1000) && (this.textobj.style.display == ''))  // значит анонс уже грузился
	{
		var stemp = 'anons';
		//this.textobj.innerHTML = '';
		//lp = fetch_object('td_anons_' + this.threadid);
		//var anchors = fetch_tags(lp, 'a');
		//anchors[2].className = 'menu';
		//anchors[2].style.cursor = 'default';
		//return;
	}
	else 
	{
		var stemp = 'fulltext';
	}

	/**
	* Function to switch the open/closed state of a thread / thread status icon
	*/
	this.toggle = function toggle_openclose()
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('/includes/ajax.php', 'do=' + stemp + '&threadid=' + this.threadid + '&homepath=' + homepath);
	}

	var me = this;
	me.obj.style.cursor = 'wait';
	me.textobj.innerHTML = me.textobj.innerHTML + vB_wait();

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{
			//me.textobj.innerHTML = me.xml_sender.handler.responseText + '<A class=menuselected href="javascript:ShowHide(\'cat0show\',\'' + 'thread_anons_' + me.threadid + '\')">свернуть</A>';
			me.obj.style.cursor = 'default';
			me.textobj.innerHTML = me.xml_sender.handler.responseText;
			vB_AJAX_QuickEdit_Init2('threadsanons');
			vB_AJAX_Threadlist_Init_2('threadsanons');
			
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}

	// send the data
	this.toggle();
}
// #############################################################################
// vB_AJAX_TitleEdit
// #############################################################################

/**
* Class to handle thread title editing with XML-HTTP
*
* @param	object	The <td> containing the title element
*/
function vB_AJAX_TitleEdit(obj)
{
	this.obj = obj;
	this.threadid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
	this.linkobj = fetch_object('thread_title_' + this.threadid);
	this.container = this.linkobj.parentNode;
	this.editobj = null;
	this.xml_sender = null;

	this.origtitle = '';
	this.editstate = false;
	
	// =============================================================================
	// vB_AJAX_TitleEdit methods

	/**
	* Function to initialize the editor for a thread title
	*/
	this.edit = function()
	{
		if (this.editstate == false)
		{
			// create the new editor input box properties...
			this.inputobj = document.createElement('input');
			this.inputobj.type = 'text';
			this.inputobj.size = 50;
			this.inputobj.maxLength = 85;
			this.inputobj.style.width = Math.max(this.linkobj.offsetWidth, 250) + 'px';
			this.inputobj.className = 'bginput';
			this.inputobj.value = PHP.unhtmlspecialchars(this.linkobj.innerHTML);
			this.inputobj.title = this.inputobj.value;

			// ... and event handlers
			this.inputobj.onblur = vB_AJAX_ThreadList_Events.prototype.titleinput_onblur;
			this.inputobj.onkeypress = vB_AJAX_ThreadList_Events.prototype.titleinput_onkeypress;

			// insert the editor box and select it
			this.editobj = this.container.insertBefore(this.inputobj, this.linkobj);
			this.editobj.select();

			// store the original text
			this.origtitle = this.linkobj.innerHTML;

			// hide the link object
			this.linkobj.style.display = 'none';

			// declare that we are in an editing state
			this.editstate = true;
		}
	}

	/**
	* Function to restore a thread title in the editing state
	*/
	this.restore = function()
	{
		if (this.editstate == true)
		{
			// do we actually need to save?
			if (this.editobj.value != this.origtitle)
			{
				this.linkobj.innerHTML = PHP.htmlspecialchars(this.editobj.value);
				this.save(this.editobj.value);
			}
			else
			{
				// set the new contents for the link
				this.linkobj.innerHTML = this.editobj.value;
			}

			// remove the editor box
			this.container.removeChild(this.editobj);

			// un-hide the link
			this.linkobj.style.display = '';

			// declare that we are in a normal state
			this.editstate = false;
		}
	}

	/**
	* Function to save an edited thread title
	*
	* @param	string	Edited title text
	*
	* @return	string	Validated title text
	*/
	this.save = function(titletext)
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		//this.xml_sender.send('ajax.php', 'do=updatethreadtitle&t=' + this.threadid + '&title=' + PHP.urlencode(titletext));
		this.xml_sender.send('/includes/ajax.php', 'do=updatethreadtitle&t=' + this.threadid + '&title=' + PHP.urlencode(titletext));
	}

	var me = this;

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{
			me.linkobj.innerHTML = me.xml_sender.handler.responseText;
			
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}

	// start the editor
	this.edit();
}

// #############################################################################
// Threadlist event handlers

/**
* Class to handle events in the threadlist
*/
function vB_AJAX_ThreadList_Events()
{
}

/**
* Handles double-clicking on thread title cells to initialize title edit
*/
vB_AJAX_ThreadList_Events.prototype.threadtitle_doubleclick = function(e)
{
	try
	{
		vB_ThreadTitle_Editor.restore();
	}
	catch(e) {}
	
	vB_ThreadTitle_Editor = new vB_AJAX_TitleEdit(this);
};

/**
* Handles double-clicking on thread icon cells to toggle open/close state
*/
vB_AJAX_ThreadList_Events.prototype.threadicon_doubleclick = function(e)
{
	openclose = new vB_AJAX_OpenClose(this);
};

/**
* Заголовок для одиночного клика по названию темы для вывода анонса
*/
vB_AJAX_ThreadList_Events.prototype.threadid_anons_click = function(e)
{
	openclose = new vB_AJAX_GetAnons(this);
	return false;
};

/**
* Заголовок для одиночного клика по надписи "тема полностью" для полного вывода темы
*/
vB_AJAX_ThreadList_Events.prototype.threadid_fulltext_click = function(e)
{
	openclose = new vB_AJAX_GetFullText(this);
	return false;
};
/**
* Handles blur events on thread title input boxes
*/
vB_AJAX_ThreadList_Events.prototype.titleinput_onblur = function(e)
{
	vB_ThreadTitle_Editor.restore();
};

/**
* Handles keypress events on thread title input boxes
*/
vB_AJAX_ThreadList_Events.prototype.titleinput_onkeypress = function (e)
{
	e = e ? e : window.event;
	switch (e.keyCode)
	{
		case 13: // return / enter
		{
			vB_ThreadTitle_Editor.inputobj.blur();
			return false;
		}
		case 27: // escape
		{
			vB_ThreadTitle_Editor.inputobj.value = vB_ThreadTitle_Editor.origtitle;
			vB_ThreadTitle_Editor.inputobj.blur();
			return true;
		}
	}
};

/*======================================================================*\
|| ####################################################################
|| # 
|| #    Быстрый редактор постов
|| # 
|| ####################################################################
\*======================================================================*/

function vB_AJAX_QuickEdit_Init2(postobj)
{
	//alert('22');
	if (ajax_compatible)
	{
		if (typeof postobj == 'string')
		{
			postobj = fetch_object(postobj);
		}
		var anchors = fetch_tags(postobj, 'a');
		var postid = 0;
		for (var i = 0; i < anchors.length; i++)
		{
			if (anchors[i].name && anchors[i].name.indexOf('vB::QuickEdit::') != -1)
			{
				anchors[i].onclick = vB_AJAX_QuickEditor_Events.prototype.editbutton_click;
			}
		}
	}
}
// #############################################################################
// #############################################################################
// vB_AJAX_QuickEditor
// #############################################################################

/**
* Class to allow quick editing of posts within postbit via AJAX
*/
function vB_AJAX_QuickEditor()
{
	this.postid = null;
	this.messageobj = null;
	this.container = null;
	this.originalhtml = null;
	this.ajax = null;
	this.editstate = false;
	this.editorcounter = 0;
	this.pending = false;
	this.fid = 0;

	this.insert_text = function(obj, state)
	{
		this.obj = obj;
		this.cmdid = this.obj.id.substr(this.obj.id.lastIndexOf('_') + 1);
		this.imgobj = fetch_object(vB_QuickEditor.editorid + '_cmd_' + this.cmdid);
		switch (state)
		{
			case 'click':
			{
				if (this.cmdid == 1) vB_QuickEditor.add(':)');
				if (this.cmdid == 2) {
					var objtext = fetch_object(vB_QuickEditor.editorid + '_textarea');
					objtext.focus();
					if (document.selection && document.selection.createRange)
					{	
						var sel = document.selection.createRange();
						//sel.text = text.replace(/\r?\n/g, '\r\n');
						sel.text = '[B]' + sel.text + '[/B]';
					}
					else
					{
						// failed - just stuff it at the end of the message
						objtext.value += text;
					}
				}
				if (this.cmdid == 3) {
					var objtext = fetch_object(vB_QuickEditor.editorid + '_textarea');
					objtext.focus();
					if (document.selection && document.selection.createRange)
					{	
						var sel = document.selection.createRange();
						//sel.text = text.replace(/\r?\n/g, '\r\n');
						sel.text = '[CENTER]' + sel.text + '[/CENTER]';
					}
					else
					{
						// failed - just stuff it at the end of the message
						objtext.value += text;
					}
				}
				if (this.cmdid == 4) vB_QuickEditor.add('[URLd=../ftp/][/URLd] (0.0 Kb)');
				if (this.cmdid == 5) {
					var objtext = fetch_object(vB_QuickEditor.editorid + '_textarea');
					objtext.focus();
					if (document.selection && document.selection.createRange)
					{	
						var sel = document.selection.createRange();
						//sel.text = text.replace(/\r?\n/g, '\r\n');
						sel.text = '[QUOTE]' + sel.text + '[/QUOTE]';
					}
					else
					{
						// failed - just stuff it at the end of the message
						objtext.value += text;
					}
				}
				break;
			}
			case 'mouseover':
			case 'mousedown':
			case 'mouseup':
			{
				// set element background, color, padding and border
				this.imgobj.style.background = '#CCCCFF';
				this.imgobj.style.color = '#555555';
				this.imgobj.style.padding = '0px';
				this.imgobj.style.border = '1px solid #316AC5';
				break;
			}
			case 'mouseout':
			{
				this.imgobj.style.background = '#FFFFFF';
				this.imgobj.style.color = '#CCCCCC';
				this.imgobj.style.padding = '0px';
				this.imgobj.style.border = '1px solid #316AC5';
				this.imgobj.style.border.VISIBILITY = 'true'; 
				break;
			}
		}

	}
	
}

// =============================================================================
// vB_AJAX_QuickEditor methods
// =============================================================================

/**
* Check if the AJAX system is ready for us to proceed
*
* @return	boolean
*/
vB_AJAX_QuickEditor.prototype.ready = function()
{
	if (this.editstate || this.pending)
	{
		return false;
	}
	else
	{
		return true;
	}
};

/**
* Prepare to edit a single post
*
* @param	string	Name attribute of clicked link - takes the form of 'vB::QuickEdit::$postid'
*
* @return	boolean	false
*/
vB_AJAX_QuickEditor.prototype.edit = function(anchor_name)
{
	var tmppostid = anchor_name.substr(anchor_name.lastIndexOf('::') + 2);

	if (this.pending)
	{
		return false;
	}
	else if (!this.ready())
	{
		if (this.postid == tmppostid)
		{
			//this.full_edit();
			return false;
		}
		this.abort();
	}

	this.editorcounter++;
	this.editorid = 'vB_Editor_QE_' + this.editorcounter;

	this.postid = tmppostid;

	this.messageobj = fetch_object('post_message_' + this.postid);
	this.originalhtml = this.messageobj.innerHTML;

	this.unchanged = null;

	this.fetch_editor();

	this.editstate = true;

	return false;
};

/**
* Send an AJAX request to fetch the editor HTML
*/
vB_AJAX_QuickEditor.prototype.fetch_editor = function()
{
	this.ajax = new vB_AJAX_Handler(true);
	this.ajax.onreadystatechange(this.display_editor);
	this.ajax.send('/includes/ajax.php', 'do=get_editor_HTML&p=' + this.postid + '&editorid=' + PHP.urlencode(this.editorid) + '&fid=' + vB_QuickEditor.fid + '&homepath=' + vB_QuickEditor.homepath);
	this.pending = true;
};

/**
* Display the editor HTML when AJAX says fetch_editor() is ready
*/
vB_AJAX_QuickEditor.prototype.display_editor = function()
{
	var AJAX = vB_QuickEditor.ajax.handler;

	if (AJAX.readyState == 4 && AJAX.status == 200)
	{
		vB_QuickEditor.pending = false;

		// display the editor
		vB_QuickEditor.messageobj.innerHTML = AJAX.responseText;

		// initialize the editor
		var textarea = fetch_object(vB_QuickEditor.editorid + '_textarea');
		textarea.style.width = '100%';
		textarea.focus();

		vB_QuickEditor.unchanged = textarea.innerHTML;

		if (vB_QuickEditor.postid == 0 || vB_QuickEditor.postid.indexOf('reply') != -1)   // взависимости от того нужно будет добавлять пост или редактировать его...
			fetch_object(vB_QuickEditor.editorid + '_add').onclick = vB_QuickEditor.save;
		else 
			fetch_object(vB_QuickEditor.editorid + '_save').onclick = vB_QuickEditor.save;

		fetch_object(vB_QuickEditor.editorid + '_abort').onclick = vB_QuickEditor.abort;
		fetch_object(vB_QuickEditor.editorid + '_upload').onclick = vB_QuickEditor.upload;

		// initialize command button
		var obj_img = fetch_object(vB_QuickEditor.editorid + '_cmd_1');
		obj_img.onclick = obj_img.onmouseover = obj_img.onmouseout = vB_QuickEditor.cmd_press;
		var obj_img = fetch_object(vB_QuickEditor.editorid + '_cmd_2');
		obj_img.onclick = obj_img.onmouseover = obj_img.onmouseout = vB_QuickEditor.cmd_press;
		var obj_img = fetch_object(vB_QuickEditor.editorid + '_cmd_3');
		obj_img.onclick = obj_img.onmouseover = obj_img.onmouseout = vB_QuickEditor.cmd_press;
		var obj_img = fetch_object(vB_QuickEditor.editorid + '_cmd_4');
		obj_img.onclick = obj_img.onmouseover = obj_img.onmouseout = vB_QuickEditor.cmd_press;
		var obj_img = fetch_object(vB_QuickEditor.editorid + '_cmd_5');
		obj_img.onclick = obj_img.onmouseover = obj_img.onmouseout = vB_QuickEditor.cmd_press;


		if (is_ie)
		{
			AJAX.abort();
		}
	}
};

/**
* Destroy the editor, and use the specified text as the post contents
*
* @param	string	Text of post
*/
vB_AJAX_QuickEditor.prototype.restore = function(post_html, type)
{
	this.hide_errors();
	
	if (vB_QuickEditor.postid > 0)    //   пост редактировался...
		this.messageobj.innerHTML = post_html;	
	else
	{
		if (vB_QuickEditor.postid.indexOf('reply') != -1)
		{   // пост редактировался...
			this.messageobj.innerHTML = '';	
			this.container = fetch_object('post_container_' + vB_QuickEditor.postid);
			var origtitle = this.container.innerHTML;
			this.container.innerHTML=origtitle + post_html;
		}
		else
		{	// добавился новый пост ...
			this.messageobj.innerHTML = '';	
			this.container = fetch_object('newpost_container');
			var origtitle = this.container.innerHTML;
			this.container.innerHTML=post_html + origtitle;

			// теперь будем искать индефикатор темы новой, чтобы инициализировать тему для дальнейшего редактирования...
			vB_AJAX_QuickEdit_Init2('newposts');
			vB_AJAX_Threadlist_Init_2('newposts');
		}
	}
	
	this.editstate = false;
};

/**
* Cancel the post edit and restore everything to how it started
*
* @param	event	Event object
*/
vB_AJAX_QuickEditor.prototype.abort = function(e)
{
	vB_QuickEditor.restore(vB_QuickEditor.originalhtml, 'messageobj');
};

/**
* Save the edited post via AJAX
*
* @param	event	Event object
*/
vB_AJAX_QuickEditor.prototype.save = function(e)
{
	var newtitle = fetch_object(vB_QuickEditor.editorid + '_title').value;
	var newtext = fetch_object(vB_QuickEditor.editorid + '_textarea').innerHTML;

	if (newtext == vB_QuickEditor.unchanged)
	{
		vB_QuickEditor.abort(e);
	}
	else
	{
		//var homepath = fetch_object('homepath').innerHTML;
		vB_QuickEditor.ajax = new vB_AJAX_Handler(true);
		vB_QuickEditor.ajax.onreadystatechange(vB_QuickEditor.update);
		vB_QuickEditor.ajax.send('/includes/ajax.php', 'do=updatepost&postid=' + vB_QuickEditor.postid + '&message=' + PHP.urlencode(newtext) + '&title=' + PHP.urlencode(newtitle) + '&homepath=' + homepath + '&fid=' + vB_QuickEditor.fid);
		
		vB_QuickEditor.pending = true;
	}
};

/**
* Check for errors etc. and initialize restore when AJAX says save() is complete
*
* @return	boolean	false
*/
vB_AJAX_QuickEditor.prototype.update = function()
{
	var AJAX = vB_QuickEditor.ajax.handler;

	if (AJAX.readyState == 4 && AJAX.status == 200)
	{
		vB_QuickEditor.pending = false;

		var output = AJAX.responseText;

		// this is the nice error handler, of which Safari makes a mess
		var errstart = output.indexOf('<!--POSTERROR');
		if (errstart != -1)
		{
			var errstop = output.indexOf('<!--/POSTERROR');
			if (errstop != -1)
			{
				vB_QuickEditor.show_errors(output.substr(errstart, (errstop - errstart)));

				if (is_ie)
				{
					AJAX.abort();
				}

				return false;
			}
		}

		//vB_QuickEditor.restore(output, 'tableobj');
		//PostBit_Init(fetch_object('post' + vB_QuickEditor.postid));
		vB_QuickEditor.restore(AJAX.responseText, 'messageobj');

		if (is_ie)
		{
			AJAX.abort();
		}
	}

	return false;
};

/**
* Закачка на сервер файла и вставка ссылки на него в редактор
*
* @param	event	Event object
*/
vB_AJAX_QuickEditor.prototype.upload = function(e)
{
	this.windows = new Array();
	var hash = 'Attach';


	if (typeof(this.windows[hash]) != 'undefined' && this.windows[hash].closed == false)
	{
		this.windows[hash].focus();
	}
	else
	{
		this.windows[hash] = openWindow('/includes/newattachment.php?do=attach&dir_attach=' + dir_attach, 400, 200, 'Attach');
	}

	//vB_QuickEditor.pending = true;
};

/**
* Reset the attachments array
*/
vB_AJAX_QuickEditor.prototype.add = function(filename)
{
	//var objtext = fetch_object(vB_QuickEditor.editorid + '_textarea');
	//var newtext = objtext.innerHTML;
	//objtext.innerHTML = newtext + filename;
	var objtext = fetch_object(vB_QuickEditor.editorid + '_textarea');
	objtext.focus();
	var text = filename;
	// Если есть выделение очистить его...
	if (document.selection && document.selection.createRange)
		{
			var sel = document.selection.createRange();
			sel.text = text.replace(/\r?\n/g, '\r\n');
		}
	else
		{
			// failed - just stuff it at the end of the message
			objtext.value += text;
		}
};

/**
* Вставка текста вовнутрь поста...
*
* @param	event	Event object
*/
vB_AJAX_QuickEditor.prototype.cmd_press = function(e)
{
	e = do_an_e(e);
	vB_QuickEditor.insert_text(this, e.type);
};

/**
* Pop up a window showing errors
*
* @param	string	Error HTML
*/
vB_AJAX_QuickEditor.prototype.show_errors = function(errortext)
{
	fetch_object('ajax_post_errors_message').innerHTML = errortext;
	var errortable = fetch_object('ajax_post_errors');
	errortable.style.width = '400px';
	errortable.style.zIndex = 500;
	var measurer = (is_saf ? 'body' : 'documentElement');
	//alert(document.getElementById(vB_QuickEditor.editorid + '_textarea').clientWidth);
	errortable.style.left = (document.getElementById(vB_QuickEditor.editorid + '_textarea').clientWidth) / 2 - 200 + 210 + 'px';
	errortable.style.top = 200 + 'px';
	//errortable.style.left = (is_ie ? document.documentElement.clientWidth : self.innerWidth) / 2 - 200 + document[measurer].scrollLeft + 'px';
	//errortable.style.top = (is_ie ? document.documentElement.clientHeight : self.innerHeight) / 2 - 150 + document[measurer].scrollTop + 'px';
	errortable.style.display = '';
};

/**
* Hide the error window
*/
vB_AJAX_QuickEditor.prototype.hide_errors = function()
{
	this.errors = false;
	fetch_object('ajax_post_errors').style.display = 'none';
	//vB_Editor[this.editorid].check_focus();
};







// =============================================================================
// vB_AJAX_QuickEditor Event Handlers

/**
* Class to handle quick editor events
*/
function vB_AJAX_QuickEditor_Events()
{
}

/**
* Handles clicks on edit buttons of postbits
*/
vB_AJAX_QuickEditor_Events.prototype.editbutton_click = function(e)
{
	return vB_QuickEditor.edit(this.name);
};

// #############################################################################
// initialize the editor class

var vB_QuickEditor = new vB_AJAX_QuickEditor();

// #############################################################################
// универсальное обращение к ajax скрипту с тремя параметрами
function vB_new_nal_add_dubl(mpp, ajaxdo, hid, nal_id)
{	
	//alert('123');

	this.textobj = fetch_object(mpp);  // имя выполняемого действия

	this.xml_sender = null;

	this.textobj.innerHTML = vB_wait();

	/**
	* Function to switch the open/closed state of a thread / thread status icon
	*/
	this.toggle = function toggle_openclose()
	{
		this.xml_sender = new vB_AJAX_Handler(true);
		this.xml_sender.onreadystatechange(this.onreadystatechange);
		this.xml_sender.send('/includes/ajax.php', 'do=' + ajaxdo + '&hid='+PHP.urlencode(hid)+'&nal_id='+nal_id);
	}

	var me = this;

	/**
	* OnReadyStateChange callback. Uses a closure to keep state.
	* Remember to use me instead of this inside this function!
	*/
	this.onreadystatechange = function()
	{
		if (me.xml_sender.handler.readyState == 4 && me.xml_sender.handler.status == 200 && me.xml_sender.handler.responseText)
		{
			me.textobj.innerHTML = me.xml_sender.handler.responseText;
	
			if (is_ie)
			{
				me.xml_sender.handler.abort();
			}
		}
	}

	// send the data
	this.toggle();
}

// #############################################################################
function verify_upload(formobj)
{
	var haveupload = false;
	for (var i=0; i < formobj.elements.length; i++)
	{
		var elm = formobj.elements[i];
		if (elm.type == 'file' || elm.type == 'text')
		{
			if (elm.value != "")
			{
				haveupload = true;
			}
		}
	}

	if (haveupload)
	{
		obj = fetch_object("uploading");
		obj.style.display = "";
		return true;
	}
	else
	{
		alert("Выберите файл для добавления.");
		return false;
	}
}
