function ShowMoreMessage(oOptions) {
	this.opt = oOptions;
	this.init();
};
ShowMoreMessage.prototype.opt = {
	sNextMessages : "",
	sButtonId : "",
	sContainerId : "",
	sLastPostId : "",
	sScriptUrl : ""
};
ShowMoreMessage.prototype.button = function() {
	var button = document.getElementById(this.opt.sButtonId);
	if (!button) {
		button = document.createElement('div');
		button.id = 'div_show_more';
		button.style.margin = '0.5em 0 0.5em 0';
		button.style.padding = '0.5em';
		button.style.textAlign = 'center';
		button.style.backgroundColor = '#F5F5F0';
		button.style.border = '1px solid #bbb';
		button.style.cursor = 'pointer';
		button.instanceRef = this;
		button.onmouseover = function() {
			this.style.backgroundColor = '#E5E5D5';
		};
		button.onmouseout = function() {
			this.style.backgroundColor = '#F5F5F0';
		};
		button.onclick = function() {
			this.instanceRef.handleClick();
		};
		document.getElementById(this.opt.sLastPostId).appendChild(button);
	}
	return button;
};
ShowMoreMessage.prototype.container = function() {
	return document.getElementById(this.opt.sContainerId);
};
ShowMoreMessage.prototype.init = function() {
	if (typeof (window.XMLHttpRequest) == 'undefined')
		return false;
	// Opera didn't always support POST requests. So test it first.
	if ('opera' in window) {
		var oTest = new XMLHttpRequest();
		if (!('setRequestHeader' in oTest))
			return false;
	}
	setInnerHTML(this.button(), this.opt.sCaption);
};
ShowMoreMessage.prototype.handleClick = function() {
	if (!this.active) {
		this.active = true;
		ajax_indicator(true);
		this.tmpMethod = getXMLDocument;
		this.oXmlRequestHandle = this.tmpMethod(this.opt.sNextMessages, this.onDocReceived);
		delete this.tmpMethod;
	}
};
ShowMoreMessage.prototype.onDocReceived = function(xmlDoc) {
	ajax_indicator(false);
	var msgs = xmlDoc.getElementsByTagName('message');
	var options = xmlDoc.getElementsByTagName('options')[0];
	this.opt.sNextMessages = options ? options.getAttribute('next') : null;
	if (this.opt.sNextMessages == null) {
		setInnerHTML(document.getElementById(this.opt.sLastPostId), "");
	}
	for ( var index = 0; index < msgs.length; index++) {
		var msg = msgs[index];
		var message_div = document.createElement('div');
		if (msg.getAttribute('class'))
			message_div.className = msg.getAttribute('class');
		var html = msg.firstChild.nodeValue;
		setInnerHTML(message_div, html);
		this.container().appendChild(message_div);
	}
	var scripts = xmlDoc.getElementsByTagName('script');
	for ( var index = 0; index < scripts.length; index++) {
		var script = scripts[index];
		eval(script.firstChild.nodeValue);
	}
	this.active = false;
};
function ShowInline(oOptions) {
	this.opt = oOptions;
	this.init();
};
ShowInline.prototype.opt = {};
ShowInline.prototype.init = function() {
	if (typeof (window.XMLHttpRequest) == 'undefined')
		return false;
	// Opera didn't always support POST requests. So test it first.
	if ('opera' in window) {
		var oTest = new XMLHttpRequest();
		if (!('setRequestHeader' in oTest))
			return false;
	}
	var elems = document.getElementsByTagName('span');
	for ( var i = 0; i < elems.length; i++) {
		/** @type HTMLElement */
		var el = elems[i];
		var test = el.id.match(/^msg_(\d+)$/);
		if (test) {
			var div = el.parentNode;
			var el2 = el.firstChild;
			var test2 = el2.href ? el2.href.match(/^http.+topic=(\d+\.??)/) : null;
			if (test2) {
				el.setAttribute('id', 's_msg_' + test2[1]);
				var img = document.createElement('img');
				img.loaded = false;
				img.setAttribute('src', smf_images_url + '/expand.gif');
				img.setAttribute('style', 'float:right; padding:5px; cursor:pointer;');
				img.mUrl = test2[0] + ';xml';
				img.lastPostId = 'lastPost_' + test2[1];
				img.topicId = parseInt(test2[1]);
				img.row = el.parentNode;
				while (img.row.nodeName.toLowerCase() != 'tr')
					img.row = img.row.parentNode;
				img.row.setAttribute('id', 'i_topic_' + test2[1]);
				img.instanceRef = this;
				img.onclick = function() {
					this.instanceRef.handleClick(this);
				};
				div.insertBefore(img, div.firstChild);
			}
		}
	}
};
ShowInline.prototype.handleClick = function(elem) {
	if (!elem.active) {
		if (elem.loaded) {
			var disp = elem.row.style.display;
			elem.row.style.display = disp == '' ? 'none' : '';
			elem.temp_row.style.display = disp == '' ? 'none' : '';
			elem.setAttribute('src', smf_images_url + (disp == '' ? '/expand.gif' : '/collapse.gif'));
		} else {
			elem.active = true;
			ajax_indicator(true);
			elem.tmpMethod = getXMLDocument;
			elem.oXmlRequestHandle = elem.tmpMethod(elem.mUrl, this.onDocReceived);
			delete elem.tmpMethod;
		}
	}
};
/**
 * @param xmlDoc
 * @return
 */
ShowInline.prototype.onDocReceived = function(xmlDoc) {
	this.active = false;
	ajax_indicator(false);
	this.loaded = true;
	this.setAttribute('src', smf_images_url + '/collapse.gif');
	var table = document.getElementById('messageindex').getElementsByTagName('table')[0];
	var msgs = xmlDoc.getElementsByTagName('message');
	var cols = this.row.getElementsByTagName('td').length - 1;
	this.row = table.insertRow(parseInt(this.row.rowIndex + 1));
	this.row.className = 'forumposts';
	this.row.insertCell(0);
	this.cell = this.row.insertCell(1);
	this.cell.colSpan = cols;
	this.container = document.createElement('form');
	this.container.setAttribute('id', 'quickModForm_' + this.topicId);
	this.container.setAttribute('name', 'quickModForm_' + this.topicId);
	this.cell.appendChild(this.container);
	for ( var index = 0; index < msgs.length; index++) {
		var msg = msgs[index];
		var message_div = document.createElement('div');
		if (msg.getAttribute('class'))
			message_div.className = msg.getAttribute('class');
		var html = msg.firstChild.nodeValue;
		setInnerHTML(message_div, html);
		this.container.appendChild(message_div);
	}
	this.temp_row = table.insertRow(parseInt(this.row.rowIndex + 1));
	this.temp_row.insertCell(0);
	this.temp_cell = this.temp_row.insertCell(1);
	this.temp_cell.colSpan = cols;
	var a = document.createElement('a');
	a.id = this.lastPostId;
	this.temp_cell.appendChild(a);
	var scripts = xmlDoc.getElementsByTagName('script');
	for ( var index = 0; index < scripts.length; index++) {
		var script = scripts[index];
		eval(script.firstChild.nodeValue);
	}
	var options = xmlDoc.getElementsByTagName('options')[0];
	this.sNextMessages = options ? options.getAttribute('next') : null;
	if (typeof (this.sNextMessages) != 'undefined' && this.sNextMessages != null) {
		if (typeof (this.oShowMoreMessage) == 'undefined')
			this.oShowMoreMessage = new ShowMoreMessage({
				sContainerId : this.container.id,
				sScriptUrl : smf_scripturl,
				sButtonId : "div_show_more_button_" + this.topicId,
				sLastPostId : this.lastPostId,
				sNextMessages : this.sNextMessages,
				sCaption : options.getAttribute('caption')
			});
	}
};
