/**
 * Inferno Shoutbox Javascript Engine
 * Created By Inferno Technologies
 * All Rights Reserved
 * * * * * * * * * * * * * * *
 */

/**
* PHP Function Emulator Class
* Based on the vBulletin Emulator
*/
inferno_php_emulator = function()
{
	this.trim = function(str)
	{
		return str.replace(/^\s+/g, '').replace(/(\s+)$/g, '');
	}

	this.urlencode = function(text)
	{
		return ajax_request.prototype.encodeurl(text);
	}
}

var PHP = new inferno_php_emulator();



/**
* Fetch object function
*/
function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}




/**
* Inferno shoutbox class
*/
_ishout = function()
{
	this.base_url = 'index.php?act=component&module=infernoshout';
	this.newestbottom = 0;
	this.script = '';
	this.editor = '';
	this.loader = '';
	this.notice = '';
	this.parsebreaker = '<<~~PARSE_^_BREAKER~~>>';
	this.activity = '';
	this.noticemessage = '';
	this.shoutframe = '';
	this.userframe = '';
	this.styleprops = '';
	this.styleprop = new Object;
	this.fetchshout = new Object;
	this.fetchusers = new Object;
	this.fetchashout = new Object;
	this.editshout = new Object;
	this.fetchsmilies = new Object;
	this.fetchaop = new Object;
	this.editshoutform = '';
	this.editshouteditor = '';
	this.smiliesbox = '';
	this.smiliesrow = '';
	this.shout = new Object;
	this.idle = false;
	this.idletimelimit = 0;
	this.loaded = false;
	this.idletime = 0;
	this.floodtime = 0;
	this.fetchingsmilies = false;
	this.showing = 'shoutbox';
	this.detached = false;
	this.aop = false;
	this.aoptime = -1;
	this.styleproperties = {
		'fontWeight' : ['bold', false],
		'textDecoration' : ['underline', false],
		'fontStyle' : ['italic', false]
	};
	this.initiate = function(thisscript, idletime, dobold, doitalic, dounderline, newestbottom, floodtime, shoutheight, refreshspeed)
	{
		this.newestbottom = parseInt(newestbottom);
		this.editor = fetch_object('ipshout_pro_shoutbox_editor');
		this.notice = fetch_object('shoutbox_notice');
		this.noticemessage = fetch_object('shoutbox_notice_message');
		this.userframe = fetch_object('shoutbox_users_frame');
		this.editshouteditor = fetch_object('shoutbox_editshout');
		this.editshoutform = document.forms['editshoutform'];
		this.smiliesbox = fetch_object('shoutbox_smilies');
		this.smiliesrow = fetch_object('shoutbox_smilies_row');
		this.tabs = fetch_object('ipshout_pro_tabs');
		this.shoutwindow = fetch_object('shoutbox_window');
		this.tabhistory = new Array();
		this.shoutheight = shoutheight;

		this.append_tab('<a href="?" onclick="return InfernoShoutbox.show(\'shoutbox\');">Общаемся</a>');
		this.append_tab('<a href="?" onclick="return InfernoShoutbox.show(\'activeusers\');">Активны</a>: <span id="shoutbox_activity">0</span>');

		fetch_object('shoutbox_bottom').innerHTML = this.make_curve('row2', 'row1', 'bottom');

		this.activity = fetch_object('shoutbox_activity');
		this.floodtime = floodtime;
		this.script = thisscript;
		this.load_editor_settings(parseInt(dobold), parseInt(doitalic), parseInt(dounderline));
		this.idletimelimit = idletime;
		this.idlecheck();

		this.set_shout_params('shoutbox_frame', '', '', '');

		this.fetch_shouts();


		if (this.aop)
		{
			this.get_shouts = setInterval("InfernoShoutbox.fetch_aop();", refreshspeed);
		}
		else
		{
			this.get_shouts = setInterval("InfernoShoutbox.fetch_shouts();", refreshspeed);
		}
		this.editor.focus();
		
	}

	this.load_editor_settings = function(dobold, doitalic, dounderline)
	{
		if (fetch_object('sb_color_mem'))
		{
			this.adjust_property_selection('color', fetch_object('sb_color_mem'), false);
		}

		if (fetch_object('sb_font_mem'))
		{
			this.adjust_property_selection('fontFamily', fetch_object('sb_font_mem'), false);
		}

		if (dobold && fetch_object('sb_mem_bold'))
		{
			this.adjust_property('fontWeight', this.styleproperties['fontWeight'][0], fetch_object('sb_mem_bold'), false);
		}

		if (doitalic && fetch_object('sb_mem_italic'))
		{
			this.adjust_property('fontStyle', this.styleproperties['fontStyle'][0], fetch_object('sb_mem_italic'), false);
		}

		if (dounderline && fetch_object('sb_mem_underline'))
		{
			this.adjust_property('textDecoration', this.styleproperties['textDecoration'][0], fetch_object('sb_mem_underline'), false);
		}
	}

	this.clear = function()
	{
		this.editor.value = '';
		this.editor.focus();
	}

	this.assign_styleprop = function(prop, sobj)
	{
		switch (prop)
		{
			case 'fontWeight':
			case 'textDecoration':
			case 'fontStyle':
			{
				this.adjust_property(prop, this.styleproperties[prop][0], sobj, true);
				return false;
			}

			case 'color':
			case 'fontFamily':
			{
				this.adjust_property_selection(prop, sobj, true);
				return false;
			}
		}
	}

	this.adjust_property_selection = function(property, sobj, update)
	{
		value = sobj.options[sobj.options.selectedIndex].value;

		if (!this.styleproperties[property])
		{
			this.styleproperties[property] = [];
		}

		this.styleproperties[property][1] = value;

		eval('this.editor.style.' + property + ' = "' + value + '";');

		if (update)
		{
			this.update_styleprops();
		}
	}

	this.adjust_property = function(property, value, sobj, update)
	{
		sobj.value = sobj.value + '*';

		if (this.styleproperties[property][1])
		{
			value = '';
			sobj.value = sobj.value.replace(/\*/g, '');
		}

		this.styleproperties[property][1] = !this.styleproperties[property][1];

		eval('this.editor.style.' + property + ' = "' + value + '";');

		if (update)
		{
			this.update_styleprops();
		}
	}

	this.set_shout_params = function(windowid, shoutprefix, shoutsuffix, fetchtype)
	{
		this.shout_params = new Object;
		this.shout_params.prefix = shoutprefix;
		this.shout_params.suffix = shoutsuffix;
		this.shout_params.fetchtype = fetchtype;

		this.shoutframe = fetch_object(windowid);
	}

	this.shout = function()
	{
		if (this.posting_shout)
		{
			this.show_notice('Предидущее сообщение еще не отправлено...');
			return false;
		}

		if (this.idle)
		{
			this.hide_notice();
		}

		this.idle = false;
		this.idletime = 0;

		message = PHP.trim(this.editor.value);

		if (message == '')
		{
			this.show_notice('Сначала введите сообщение.');
			return false;
		}

		message = this.shout_params.prefix + message + this.shout_params.suffix;

		this.posting_shout = true;

		this.set_loader('');

		this.shout.ajax = new ajax_request();
		this.shout.ajax.onreadystatechange(InfernoShoutbox.shout_posted);
		this.shout.ajax.process(this.base_url + '&code=sendshout', 'POST', 'message=' + PHP.urlencode(message));

		this.clear();
		this.editor.focus();

		return false;
	}

	this.unidle = function()
	{
		this.idletime = 0;
		this.idle = false;
		this.hide_notice();

		return false;
	}

	this.idlecheck = function()
	{
		if (this.idle || this.idletime > this.idletimelimit)
		{
			setTimeout("InfernoShoutbox.idlecheck()", 1000);
			return false;
		}

		this.idletime++;

		if (this.idletime > this.idletimelimit)
		{
			this.idle = true;
		}

		setTimeout("InfernoShoutbox.idlecheck()", 1000);
	}

	this.shout_posted = function()
	{
		ajax = InfernoShoutbox.shout.ajax;

		if (ajax.readystate_ready_and_ok())
		{
			if (PHP.trim(ajax.xmlhandler.responseText) == 'completed')
			{
				InfernoShoutbox.force_fetch = true;
				InfernoShoutbox.fetch_shouts();
			}
			else if(PHP.trim(ajax.xmlhandler.responseText) == 'flood')
			{
				InfernoShoutbox.show_notice('Вы должны подождать ' + InfernoShoutbox.floodtime + ' секунд перед отправкой сообщения.');
				InfernoShoutbox.posting_shout = false;
			}
			else
			{
				InfernoShoutbox.show_notice('Ваше сообщение не удалось отправить.');
				InfernoShoutbox.posting_shout = false;
			}
		}
	}

	this.update_styleprops = function()
	{
		this.set_loader('');

		var bold	= this.styleproperties['fontWeight'][1] ? 1 : 0;
		var italic	= this.styleproperties['fontStyle'][1] ? 1 : 0;
		var underline	= this.styleproperties['textDecoration'][1] ? 1 : 0;
		var colour	= '';
		var fontfamily	= '';

		if (this.styleproperties['color'])
		{
			colour = this.styleproperties['color'][1];
		}

		if (this.styleproperties['fontFamily'])
		{
			fontfamily = this.styleproperties['fontFamily'][1];
		}

		styleproperties = new Array(
			'bold=' + bold,
			'italic=' + italic,
			'underline=' + underline,
			'colour=' + colour,
			'fontfamily=' + fontfamily
		);

		styleproperties = styleproperties.join('&');

		this.styleprop.ajax = new ajax_request();
		this.styleprop.ajax.onreadystatechange(InfernoShoutbox.styleprops_updated);
		this.styleprop.ajax.process(this.base_url + '&code=styleprops&' + styleproperties);
	}

	this.styleprops_updated = function()
	{
		ajax = InfernoShoutbox.styleprop.ajax;

		if (ajax.readystate_ready_and_ok())
		{
			InfernoShoutbox.set_loader('none');
			InfernoShoutbox.show_notice('Ваши настройки были обновлены.');
		}
	}

	this.fetch_aop = function()
	{
		if (this.fetching_aop)
		{
			return false;
		}

		if (InfernoShoutbox.new_aoptime)
		{
			this.fetch_shouts();

			return false;
		}

		this.fetching_aop = true;


		this.fetchaop.ajax = new ajax_request(true);
		this.fetchaop.ajax.onreadystatechange(InfernoShoutbox.fetch_aop_done);
		this.fetchaop.ajax.process('infernoshout/aop/aop.txt', '');
	}

	this.fetch_aop_done = function()
	{
		ajax = InfernoShoutbox.fetchaop.ajax;
		InfernoShoutbox.fetching_aop = false;

		if (ajax.readystate_ready_and_ok())
		{
			new_aop_time = parseInt(ajax.xmlhandler.responseText);

			if (new_aop_time > InfernoShoutbox.aoptime)
			{
				InfernoShoutbox.new_aoptime = new_aop_time;
				InfernoShoutbox.fetch_shouts();
			}
		}
	}

	this.fetch_shouts = function()
	{
		if (this.posting_shout && !this.force_fetch)
		{
			return false;
		}

		if (this.fetchting_shouts)
		{
			return false;
		}

		if (this.idle && this.loaded)
		{
			this.show_notice('Вы были неактивны продолжительное время. Нажмите <a href="?" onclick="return InfernoShoutbox.unidle();"><b>тут</b></a> чтобы вернутся в чат.');
			clearTimeout(InfernoShoutbox.kill_notice); // Don't hide this notice

			return false;
		}


		this.fetching_shouts = true;
		this.force_fetch = false;
		this.loaded = true;

		this.set_loader('');

		this.fetchshout.ajax = new ajax_request();
		this.fetchshout.ajax.onreadystatechange(InfernoShoutbox.fetch_shouts_completed);
		this.fetchshout.ajax.process(this.base_url + '&code=fetchshouts&fetchtype=' + this.shout_params.fetchtype + ((this.detached) ? '&detach=1' : ''));
	}

	this.fetch_shouts_completed = function()
	{
		ajax = InfernoShoutbox.fetchshout.ajax;

		if (ajax.readystate_ready_and_ok())
		{
			try
			{
				data = ajax.xmlhandler.responseXML.documentElement;
				data = data.getElementsByTagName('data')[0].firstChild.data;
				data = data.split(InfernoShoutbox.parsebreaker);

				if (data[1])
				{
					InfernoShoutbox.activity.innerHTML = PHP.trim(data[1]);
				}

				InfernoShoutbox.update_shouts(PHP.trim(data[0]));
			}
			catch(e){}

			// Posting a shout now finishes here, when shouts have been refetched
			if (InfernoShoutbox.posting_shout)
			{
				InfernoShoutbox.posting_shout = false;
			}

			InfernoShoutbox.set_loader('none');
			InfernoShoutbox.fetching_shouts = false;

			if (InfernoShoutbox.new_aoptime)
			{
				InfernoShoutbox.aoptime = InfernoShoutbox.new_aoptime;
				InfernoShoutbox.new_aoptime = false;
			}
		}
	}

	this.update_shouts = function(shouts)
	{
		try
		{
			if (this.shout_windows[this.shoutframe.id] && this.shout_windows[this.shoutframe.id].username)
			{
				shouts = shouts.replace('{:&:__PM__USERNAME__:&:}', this.shout_windows[this.shoutframe.id].username);
			}
		}
		catch(e)
		{}

		this.shoutframe.innerHTML = '';
		this.shoutframe.innerHTML = shouts;

		if (fetch_object(InfernoShoutbox.shoutframe.id).getElementsByTagName('div')[0].id == 'inferno_shout_notice')
		{
			html = fetch_object(InfernoShoutbox.shoutframe.id).getElementsByTagName('div')[0].innerHTML;
			html = "<div class='row1'>" + this.make_curve('row1', 'row2') + "</div>" + '<div class="smallfont" style="text-align: left; white-space: nowrap; padding: 5px; padding-top: 0px; padding-bottom: 4px; background: transparent; margin: 0px; border: 0px !important;">' + html + '</div>';
			html = html + this.make_curve('row1', 'row2', 'bottom');

			fetch_object(InfernoShoutbox.shoutframe.id).getElementsByTagName('div')[0].innerHTML = html;
		}

		if (this.newestbottom && this.shoutframe.scrollTop < this.shoutframe.scrollHeight)
		{
			this.shoutframe.scrollTop = this.shoutframe.scrollHeight;
		}
	}

	this.set_loader = function(set)
	{
		//this.loader.style.display = set;
	}

	this.show_notice = function(message)
	{
		clearTimeout(InfernoShoutbox.kill_notice);
		InfernoShoutbox.kill_notice = setTimeout("InfernoShoutbox.hide_notice()", 5000);

		this.noticemessage.innerHTML = message;
		this.notice.style.display = '';
	}

	this.hide_notice = function()
	{
		this.notice.style.display = 'none';
	}

	this.show = function(what)
	{
		if (what == this.showing)
		{
			return false;
		}

		if (what == 'shoutbox')
		{
			this.goto_pm_window('shoutbox_frame');
			//this.shoutframe.style.display = 'block';
			this.userframe.style.display = 'none';
		}
		else
		{
			this.fetch_users();
			this.shoutframe.style.display = 'none';
			this.userframe.style.display = 'block';
		}

		this.showing = what;

		return false;
	}

	this.fetch_users = function()
	{
		this.set_loader('');

		this.fetchusers.ajax = new ajax_request();
		this.fetchusers.ajax.onreadystatechange(InfernoShoutbox.fetch_users_completed);
		this.fetchusers.ajax.process(this.base_url + '&code=fetchusers');
	}

	this.fetch_users_completed = function()
	{
		ajax = InfernoShoutbox.fetchusers.ajax;

		if (ajax.readystate_ready_and_ok())
		{
			InfernoShoutbox.userframe.innerHTML = ajax.xmlhandler.responseText;
			InfernoShoutbox.set_loader('none');
		}
	}

	this.pm_user = function(username)
	{
		this.editor.value = '/pm ' + username + '; Ваше сообщение тут';

		return false;
	}

	this.edit_shout = function(shoutid)
	{
		this.posting_shout = true;

		this.editshout.ajax = new ajax_request();
		this.editshout.ajax.onreadystatechange(InfernoShoutbox.edit_shout_fetched);
		this.editshout.ajax.process(this.base_url + '&code=editshout&shoutid=' + shoutid);

		this.set_loader('');
		
		this.editshout.focus();
		
		return false;
	}

	this.edit_shout_fetched = function()
	{
		ajax = InfernoShoutbox.editshout.ajax;
		if (ajax.readystate_ready_and_ok())
		{
			InfernoShoutbox.set_loader('none');

			try
			{
				data = ajax.xmlhandler.responseXML.documentElement;
				data = data.getElementsByTagName('data')[0].firstChild.data;
				data = data.split(InfernoShoutbox.parsebreaker);

				if (ajax.xmlhandler.responseText != 'deny')
				{
					InfernoShoutbox.show_edit_shout(data);
				}
				else
				{
					InfernoShoutbox.posting_shout = false;
				}
			}			
			catch(e){}
		}
	}

	this.show_edit_shout = function(data)
	{
		theshout = PHP.trim(data[0]);
		shoutid = parseInt(data[1]);

		if (this.archive)
		{
			//...
		}
		else
		{
			this.editshouteditor.style.display = '';
			this.editshoutform.shoutid.value = shoutid;
			this.editshoutform.editshout.value = theshout;
		}
	}

	this.cancel_edit_shout = function(shoutid)
	{
		if (this.archive)
		{
			fetch_object('shout_' + shoutid).style.display = '';
			fetch_object('shout_edit_' + shoutid).style.display = 'none';

			return false;
		}
		else
		{
			this.editshouteditor.style.display = 'none';
			this.posting_shout = false;
		}
	}

	this.do_edit_shout = function(dodelete)
	{
		if (typeof dodelete != 'undefined')
		{
			dodelete = 1;
		}
		else
		{
			dodelete = 0;
		}

		shout = PHP.urlencode(PHP.trim(this.editshoutform.editshout.value));
		shoutid = parseInt(this.editshoutform.shoutid.value);

		this.editshout.ajax = new ajax_request();
		this.editshout.ajax.onreadystatechange(InfernoShoutbox.edit_shout_done);
		this.editshout.ajax.process(this.base_url + '&code=saveshout&shoutid=' + shoutid + '&shout=' + shout + '&delete=' + dodelete);

		this.editshouteditor.style.display = 'none';
		this.set_loader('');

		return false;
	}

	this.edit_shout_done = function()
	{
		ajax = InfernoShoutbox.editshout.ajax;

		if (ajax.readystate_ready_and_ok())
		{
			if (InfernoShoutbox.archive)
			{
				if (!ajax.dodelete)
				{
					InfernoShoutbox.fetch_archive_shout(ajax.shoutid);
				}
				else
				{
					fetch_object('shout_row_' + ajax.shoutid).parentNode.removeChild(fetch_object('shout_row_' + ajax.shoutid));
				}
			}
			else
			{
				InfernoShoutbox.set_loader('none');
				InfernoShoutbox.posting_shout = false;
				InfernoShoutbox.fetch_shouts();
			}
		}
	}

	this.smilies = function()
	{
		if (this.fetchingsmilies)
		{
			return false;
		}

		if (this.smiliesbox.style.display == '')
		{
			this.smiliesbox.style.display = 'none';
			return false;
		}

		this.fetchingsmilies = true;
		this.fetchsmilies.ajax = new ajax_request();
		this.fetchsmilies.ajax.onreadystatechange(InfernoShoutbox.smilies_fetched);
		this.fetchsmilies.ajax.process(this.base_url + '&code=fetchsmilies');
		this.set_loader('');
	}

	this.smilies_fetched = function()
	{
		ajax = InfernoShoutbox.fetchsmilies.ajax;

		if (ajax.readystate_ready_and_ok())
		{
			InfernoShoutbox.set_loader('none');
			InfernoShoutbox.fetchingsmilies = false;
			InfernoShoutbox.smiliesbox.style.display = '';
			InfernoShoutbox.smiliesrow.innerHTML = ajax.xmlhandler.responseText;
		}
	}

	this.append_smilie = function(code)
	{
		applyto = this.editshouteditor.style.display == '' ? this.editshoutform.editshout : this.editor;

		if (PHP.trim(applyto.value) == '')
		{
			applyto.value = code + ' ';
		}
		else
		{
			spacer = applyto.value.substring(applyto.value.length - 1) == ' ' ? '' : ' ';
			applyto.value += spacer + code + ' ';
		}

		try
		{
			applyto.focus();
		}
		catch(e)
		{
		}
	}

	this.make_curve = function(class_a, class_b, curve_type)
	{
		if (typeof class_a == 'undefined')
		{
			class_a = 'row2';
		}

		if (typeof class_b == 'undefined')
		{
			class_b = 'row1';
		}

		if (typeof curve_type == 'undefined')
		{
			curve_type = 'top';
		}

		corner_size = {
			'top'		: {
				'left'	: '1',
				'right'	: '3'
			},
			'bottom'	: {
				'left'	: '3',
				'right'	: '1'
			}
		};

		curve = '<div class="' + class_a + '" style="border: 0px !important; margin: 0px; padding: 0px;">';
		curve += '<span style="float: right; border: 0px !important; margin: 0px; padding: 0px;">';
		curve += '<span class="' + class_b + '" style="display: block; border: 0px !important; margin: 0px; padding: 0px;">';
		curve += '<span class="' + class_a + '" style="width: ' + corner_size[curve_type]['left'] + 'px; height: 1px; display: block; overflow: hidden; border: 0px !important; margin: 0px; padding: 0px;"></span>';
		curve += '<span class="' + class_a + '" style="width: 2px; height: 1px; display: block; overflow: hidden; border: 0px !important; margin: 0px; padding: 0px;"></span>';
		curve += '<span class="' + class_a + '" style="width: ' + corner_size[curve_type]['right'] + 'px; height: 1px; display: block; overflow: hidden; border: 0px !important; margin: 0px; padding: 0px;"></span>';
		curve += '</span></span>';
		curve += '<span class="' + class_b + '" style="width: ' + corner_size[curve_type]['right'] + 'px; height: 1px; display: block; overflow: hidden; border: 0px !important; margin: 0px; padding: 0px;"></span>';
		curve += '<span class="' + class_b + '" style="width: 2px; height: 1px; display: block; overflow: hidden; border: 0px !important; margin: 0px; padding: 0px;"></span>';
		curve += '<span class="' + class_b + '" style="width: ' + corner_size[curve_type]['left'] + 'px; height: 1px; display: block; overflow: hidden; border: 0px !important; margin: 0px; padding: 0px;"></span>';
		curve += '</div>';
		curve += '';

		return curve;
	}

	this.append_tab = function(html, canclose)
	{
		if (canclose)
		{
			html += ' [<a href="#" onclick="return InfernoShoutbox.close_tab(this);">X</a>]';
		}

		html = this.make_curve() + '<div class="smallfont" style="text-align: center; white-space: nowrap; padding: 5px; padding-top: 0px; padding-bottom: 4px; background: transparent; margin: 0px; border: 0px !important;">' + html + '</div>';

		cellposition = this.tabs.rows[0].cells.length - 1;
		newtab = this.tabs.rows[0].insertCell(cellposition);
		newtab.className = 'row2';
		newtab.innerHTML = html;
		newtab.style.cssText = "border: 0px !important; margin: 0px; padding: 0px;";

		if (this.tabhistory[newtab.innerHTML])
		{
			newtab.parentNode.removeChild(newtab);
			return false;
		}

		this.tabhistory[newtab.innerHTML] = 1;

		cellposition = this.tabs.rows[0].cells.length - 1;
		newtab = this.tabs.rows[0].insertCell(cellposition);
		newtab.className = 'row1';
		newtab.innerHTML = '&nbsp;';
		newtab.style.cssText = "border: 0px !important; margin: 0px; padding: 0px;";
	}

	this.close_tab = function(tabobj)
	{
		this.tabhistory[tabobj.parentNode.parentNode.innerHTML] = 0;

		tabobj.parentNode.parentNode.parentNode.removeChild(tabobj.parentNode.parentNode);

		this.clean_tab_spacing();

		if (this.showing != 'activeusers')
		{
			this.goto_pm_window('shoutbox_frame');
		}

		return false;
	}

	this.clean_tab_spacing = function()
	{
		for (var c = 0; c < this.tabs.rows[0].cells.length; c++)
		{
			if (this.tabs.rows[0].cells[c + 1])	
			{
				if (this.tabs.rows[0].cells[c].innerHTML == this.tabs.rows[0].cells[c + 1].innerHTML && this.tabs.rows[0].cells[c].innerHTML == '&nbsp;')
				{
					this.tabs.rows[0].removeChild(this.tabs.rows[0].cells[c]);
					break;
				}
			}
		}
	}

	this.open_pm_tab = function(pmid, username)
	{
		if (!this.pm_tabs)
		{
			this.pm_tabs = {};
		}

		if (this.pm_tabs[pmid])
		{
			this.goto_pm_window(pmid);
			return false;
		}

		// Create the tab
		this.append_tab('<a href="#" onclick="return InfernoShoutbox.goto_pm_window(\'' + pmid + '\');">' + username + '</a>', 1);

		// Create the window
		this.append_shout_window(pmid, '/pm ' + username + '; ', '', 'pmonly&pmid=' + pmid.split('_')[1]);

		this.shout_windows[pmid].username = username;

		// Switch to the window
		this.goto_pm_window(pmid);

		return false;
	}

	this.set_default_window = function(windowid)
	{
		this.shout_windows[windowid] = new Object;
		this.shout_windows[windowid].suffix = '';
		this.shout_windows[windowid].prefix = '';
		this.shout_windows[windowid].fetchtype = '';
	}

	this.goto_pm_window = function(windowid)
	{
		if (!this.shout_windows)
		{
			this.shout_windows = {};
			this.set_default_window('shoutbox_frame');
		}

		if (!this.shout_windows[windowid])
		{
			return false;
		}

		this.userframe.style.display = 'none';
		this.shoutframe.style.display = 'none';

		this.set_shout_params(windowid, this.shout_windows[windowid].prefix, this.shout_windows[windowid].suffix, this.shout_windows[windowid].fetchtype);

		this.shoutframe.innerHTML = 'Загрузка...';
		this.shoutframe.style.display = 'block';
		this.showing = windowid;

		if (this.idle)
		{
			this.hide_notice();
		}

		this.idle = false;

		this.fetch_shouts();

		return false;
	}

	this.append_shout_window = function(windowid, shoutprefix, shoutsuffix, fetchtype)
	{
		if (!this.shout_windows)
		{
			this.shout_windows = {};
			this.set_default_window('shoutbox_frame');
		}

		if (this.shout_windows[windowid])
		{
			// This window has already been placed, don't remake it.
			return false;
		}

		this.shout_windows[windowid] = new Object;
		this.shout_windows[windowid].prefix = shoutprefix;
		this.shout_windows[windowid].suffix = shoutsuffix;
		this.shout_windows[windowid].fetchtype = fetchtype;

		swindow = document.createElement('span');
		swindow.style.display = 'none';
		swindow.style.padding = '3px';
		swindow.style.height = parseInt(this.shoutheight) + 'px';
		swindow.style.overflow = 'auto';
		swindow.style.width = '99%';
		swindow.innerHTML = 'Загрузка...';
		swindow.id = windowid;

		this.shoutwindow.appendChild(swindow);
	}

	this.goto_options = function()
	{
		window.location.href = this.base_url + '&code=options';
	}

	this.detach = function()
	{
		detachwin = window.open(this.base_url + '&code=detach', '_ishout_detach', 'resizable=yes');
		try
		{
			detachwin.focus();
		}
		catch(e){}
	}
}