var smf_formSubmitted = false;
var lastKeepAliveCheck = new Date().getTime();
var smf_editorArray = new Array();

// Some very basic browser detection - from Mozilla's sniffer page.
var ua = navigator.userAgent.toLowerCase();

var is_opera = ua.indexOf('opera') != -1;
var is_opera5 = ua.indexOf('opera/5') != -1 || ua.indexOf('opera 5') != -1;
var is_opera6 = ua.indexOf('opera/6') != -1 || ua.indexOf('opera 6') != -1;
var is_opera7 = ua.indexOf('opera/7') != -1 || ua.indexOf('opera 7') != -1;
var is_opera8 = ua.indexOf('opera/8') != -1 || ua.indexOf('opera 8') != -1;
var is_opera9 = ua.indexOf('opera/9') != -1 || ua.indexOf('opera 9') != -1;
var is_opera95 = ua.indexOf('opera/9.5') != -1 || ua.indexOf('opera 9.5') != -1;
var is_opera96 = ua.indexOf('opera/9.6') != -1 || ua.indexOf('opera 9.6') != -1;
var is_opera10 = (ua.indexOf('opera/9.8') != -1 || ua.indexOf('opera 9.8') != -1 || ua.indexOf('opera/10.') != -1 || ua.indexOf('opera 10.') != -1) || ua.indexOf('version/10.') != -1;
var is_opera95up = is_opera95 || is_opera96 || is_opera10;

var is_ff = (ua.indexOf('firefox') != -1 || ua.indexOf('iceweasel') != -1 || ua.indexOf('icecat') != -1) && !is_opera;
var is_gecko = ua.indexOf('gecko') != -1 && !is_opera;

var is_chrome = ua.indexOf('chrome') != -1;
var is_safari = ua.indexOf('applewebkit') != -1 && !is_chrome;
var is_webkit = ua.indexOf('applewebkit') != -1;

var is_ie = ua.indexOf('msie') != -1  && !is_opera;
var is_ie4 = is_ie && ua.indexOf('msie 4') != -1;
var is_ie5 = is_ie && ua.indexOf('msie 5') != -1;
var is_ie50 = is_ie && ua.indexOf('msie 5.0') != -1;
var is_ie55 = is_ie && ua.indexOf('msie 5.5') != -1;
var is_ie5up = is_ie && !is_ie4;
var is_ie6 = is_ie && ua.indexOf('msie 6') != -1;
var is_ie6up = is_ie5up && !is_ie55 && !is_ie5;
var is_ie6down = is_ie6 || is_ie5 || is_ie4;
var is_ie7 = is_ie && ua.indexOf('msie 7') != -1;
var is_ie7up = is_ie6up && !is_ie6;
var is_ie7down = is_ie7 || is_ie6 || is_ie5 || is_ie4;

var is_ie8 = is_ie && ua.indexOf('msie 8') != -1;
var is_ie8up = is_ie8 && !is_ie7down;

var is_phone = ua.indexOf('iphone') != -1 || ua.indexOf('ipod') != -1;

var ajax_indicator_ele = null;

// Define document.getElementById for Internet Explorer 4.
if (!('getElementById' in document) && 'all' in document)
	document.getElementById = function (sId) {
		return document.all[sId];
	}

// Define XMLHttpRequest for IE 5 and above. (don't bother for IE 4 :/.... works in Opera 7.6 and Safari 1.2!)
else if (!('XMLHttpRequest' in window) && 'ActiveXObject' in window)
	window.XMLHttpRequest = function () {
		return new ActiveXObject(is_ie5 ? 'Microsoft.XMLHTTP' : 'MSXML2.XMLHTTP');
	};

// Ensure the getElementsByTagName exists.
if (!'getElementsByTagName' in document && 'all' in document)
	document.getElementsByTagName = function (sName) {
		return document.all.tags[sName];
	}

// Some older versions of Mozilla don't have this, for some reason.
if (!('forms' in document))
	document.forms = document.getElementsByTagName('form');

// Load an XML document using XMLHttpRequest.
function getXMLDocument(sUrl, funcCallback)
{
	if (!window.XMLHttpRequest)
		return null;

	var oMyDoc = new XMLHttpRequest();
	var bAsync = typeof(funcCallback) != 'undefined';
	var oCaller = this;
	if (bAsync)
	{
		oMyDoc.onreadystatechange = function () {
			if (oMyDoc.readyState != 4)
				return;

			if (oMyDoc.responseXML != null && oMyDoc.status == 200)
			{
				if (funcCallback.call)
				{
					funcCallback.call(oCaller, oMyDoc.responseXML);
				}
				// A primitive substitute for the call method to support IE 5.0.
				else
				{
					oCaller.tmpMethod = funcCallback;
					oCaller.tmpMethod(oMyDoc.responseXML);
					delete oCaller.tmpMethod;
				}
			}
		};
	}
	oMyDoc.open('GET', sUrl, bAsync);
	oMyDoc.send(null);

	return oMyDoc;
}

// Send a post form to the server using XMLHttpRequest.
function sendXMLDocument(sUrl, sContent, funcCallback)
{
	if (!window.XMLHttpRequest)
		return false;

	var oSendDoc = new window.XMLHttpRequest();
	var oCaller = this;
	if (typeof(funcCallback) != 'undefined')
	{
		oSendDoc.onreadystatechange = function () {
			if (oSendDoc.readyState != 4)
				return;

			if (oSendDoc.responseXML != null && oSendDoc.status == 200)
				funcCallback.call(oCaller, oSendDoc.responseXML);
			else
				funcCallback.call(oCaller, false);
		};
	}
	oSendDoc.open('POST', sUrl, true);
	if ('setRequestHeader' in oSendDoc)
		oSendDoc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	oSendDoc.send(sContent);

	return true;
}

// A property we'll be needing for php_to8bit.
String.prototype.oCharsetConversion = {
	from: '',
	to: ''
};

// Convert a string to an 8 bit representation (like in PHP).
String.prototype.php_to8bit = function ()
{
	if (!('oCharsetConversion' in this))
	{
		this.oCharsetConversion = {
			from: '\xa0-\xa3\u20ac\xa5\u0160\xa7\u0161\xa9-\xb3\u017d\xb5-\xb7\u017e\xb9-\xbb\u0152\u0153\u0178\xbf-\xff',
			to: '\xa0-\xff'
		};

		var funcExpandString = function (sSearch) {
			var sInsert = '';
			for (var i = sSearch.charCodeAt(0), n = sSearch.charCodeAt(2); i <= n; i++)
				sInsert += String.fromCharCode(i);
			return sInsert;
		};
		this.oCharsetConversion.from = this.oCharsetConversion.from.replace(/.\-./g, funcExpandString);
		this.oCharsetConversion.to = this.oCharsetConversion.to.replace(/.\-./g, funcExpandString);
	}

	var sReturn = '', iOffsetFrom = 0;
	for (var i = 0, n = this.length; i < n; i++)
	{
		iOffsetFrom = this.oCharsetConversion.from.indexOf(this.charAt(i));
		sReturn += iOffsetFrom > -1 ? this.oCharsetConversion.to.charAt(iOffsetFrom) : (this.charCodeAt(i) > 127 ? '&#' +  this.charCodeAt(i) + ';' : this.charAt(i));
	}

	return sReturn
}

// Character-level replacement function.
String.prototype.php_strtr = function (sFrom, sTo)
{
	return this.replace(new RegExp('[' + sFrom + ']', 'g'), function (sMatch) {
		return sTo.charAt(sFrom.indexOf(sMatch));
	});
}

// Simulate PHP's strtolower (in SOME cases PHP uses ISO-8859-1 case folding).
String.prototype.php_strtolower = function ()
{
	return typeof(smf_iso_case_folding) == 'boolean' && smf_iso_case_folding == true ? this.php_strtr(
		'ABCDEFGHIJKLMNOPQRSTUVWXYZ\x8a\x8c\x8e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde',
		'abcdefghijklmnopqrstuvwxyz\x9a\x9c\x9e\xff\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe'
	) : this.php_strtr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
}

String.prototype.php_urlencode = function()
{
	return escape(this).replace(/\+/g, '%2b').replace('*', '%2a').replace('/', '%2f').replace('@', '%40');
}

String.prototype.php_htmlspecialchars = function()
{
	return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

String.prototype.php_unhtmlspecialchars = function()
{
	return this.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&');
}

String.prototype.php_addslashes = function()
{
	return this.replace(/\\/g, '\\\\').replace(/'/g, '\\\'');
}

String.prototype._replaceEntities = function(sInput, sDummy, sNum)
{
	return String.fromCharCode(parseInt(sNum));
}

String.prototype.removeEntities = function()
{
	return this.replace(/&(amp;)?#(\d+);/g, this._replaceEntities);
}

String.prototype.easyReplace = function (oReplacements)
{
	var sResult = this;
	for (var sSearch in oReplacements)
		sResult = sResult.replace(new RegExp('%' + sSearch + '%', 'g'), oReplacements[sSearch]);

	return sResult;
}


// Open a new window.
function reqWin(desktopURL, alternateWidth, alternateHeight, noScrollbars)
{
	if ((alternateWidth && self.screen.availWidth * 0.8 < alternateWidth) || (alternateHeight && self.screen.availHeight * 0.8 < alternateHeight))
	{
		noScrollbars = false;
		alternateWidth = Math.min(alternateWidth, self.screen.availWidth * 0.8);
		alternateHeight = Math.min(alternateHeight, self.screen.availHeight * 0.8);
	}
	else
		noScrollbars = typeof(noScrollbars) == 'boolean' && noScrollbars == true;

	window.open(desktopURL, 'requested_popup', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=' + (noScrollbars ? 'no' : 'yes') + ',width=' + (alternateWidth ? alternateWidth : 480) + ',height=' + (alternateHeight ? alternateHeight : 220) + ',resizable=no');

	// Return false so the click won't follow the link ;).
	return false;
}

// Remember the current position.
function storeCaret(oTextHandle)
{
	// Only bother if it will be useful.
	if ('createTextRange' in oTextHandle)
		oTextHandle.caretPos = document.selection.createRange().duplicate();
}

// Replaces the currently selected text with the passed text.
function replaceText(text, oTextHandle)
{
	// Attempt to create a text range (IE).
	if ('caretPos' in oTextHandle && 'createTextRange' in oTextHandle)
	{
		var caretPos = oTextHandle.caretPos;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		caretPos.select();
	}
	// Mozilla text range replace.
	else if ('selectionStart' in oTextHandle)
	{
		var begin = oTextHandle.value.substr(0, oTextHandle.selectionStart);
		var end = oTextHandle.value.substr(oTextHandle.selectionEnd);
		var scrollPos = oTextHandle.scrollTop;

		oTextHandle.value = begin + text + end;

		if (oTextHandle.setSelectionRange)
		{
			oTextHandle.focus();
			oTextHandle.setSelectionRange(begin.length + text.length, begin.length + text.length);
		}
		oTextHandle.scrollTop = scrollPos;
	}
	// Just put it on the end.
	else
	{
		oTextHandle.value += text;
		oTextHandle.focus(oTextHandle.value.length - 1);
	}
}

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, oTextHandle)
{
	// Can a text range be created?
	if ('caretPos' in oTextHandle != 'undefined' && 'createTextRange' in oTextHandle)
	{
		var caretPos = oTextHandle.caretPos, temp_length = caretPos.text.length;

		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;

		if (temp_length == 0)
		{
			caretPos.moveStart('character', -text2.length);
			caretPos.moveEnd('character', -text2.length);
			caretPos.select();
		}
		else
			oTextHandle.focus(caretPos);
	}
	// Mozilla text range wrap.
	else if ('selectionStart' in oTextHandle)
	{
		var begin = oTextHandle.value.substr(0, oTextHandle.selectionStart);
		var selection = oTextHandle.value.substr(oTextHandle.selectionStart, oTextHandle.selectionEnd - oTextHandle.selectionStart);
		var end = oTextHandle.value.substr(oTextHandle.selectionEnd);
		var newCursorPos = oTextHandle.selectionStart;
		var scrollPos = oTextHandle.scrollTop;

		oTextHandle.value = begin + text1 + selection + text2 + end;

		if (oTextHandle.setSelectionRange)
		{
			if (selection.length == 0)
				oTextHandle.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			else
				oTextHandle.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			oTextHandle.focus();
		}
		oTextHandle.scrollTop = scrollPos;
	}
	// Just put them on the end, then.
	else
	{
		oTextHandle.value += text1 + text2;
		oTextHandle.focus(oTextHandle.value.length - 1);
	}
}

// Checks if the passed input's value is nothing.
function isEmptyText(theField)
{
	// Copy the value so changes can be made..
	var theValue = theField.value;

	// Strip whitespace off the left side.
	while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
		theValue = theValue.substring(1, theValue.length);
	// Strip whitespace off the right side.
	while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
		theValue = theValue.substring(0, theValue.length - 1);

	if (theValue == '')
		return true;
	else
		return false;
}

// Only allow form submission ONCE.
function submitonce(theform)
{
	smf_formSubmitted = true;

	// If there are any editors warn them submit is coming!
	for (var i = 0; i < smf_editorArray.length; i++)
		smf_editorArray[i].doSubmit();
}
function submitThisOnce(oControl)
{
	// Hateful, hateful fix for Safari 1.3 beta.
	if (is_safari)
		return !smf_formSubmitted;

	// oControl might also be a form.
	var oForm = 'form' in oControl ? oControl.form : oControl;

	var aTextareas = oForm.getElementsByTagName('textarea');
	for (var i = 0, n = aTextareas.length; i < n; i++)
		aTextareas[i].readOnly = true;

	return !smf_formSubmitted;
}

// Set the "inside" HTML of an element.
function setInnerHTML(oElement, sToValue)
{
	// IE has this built in...
	if ('innerHTML' in oElement)
		oElement.innerHTML = sToValue;
	// Otherwise, try createContextualFragment().
	else
	{
		var range = document.createRange();
		range.selectNodeContents(oElement);
		range.deleteContents();
		oElement.appendChild(range.createContextualFragment(sToValue));
	}
}

// Set the "outer" HTML of an element.
function setOuterHTML(oElement, sToValue)
{
	if ('outerHTML' in oElement)
		oElement.outerHTML = sToValue;
	else
	{
		var range = document.createRange();
		range.setStartBefore(oElement);
		oElement.parentNode.replaceChild(range.createContextualFragment(sToValue), oElement);
	}
}

// Get the inner HTML of an element.
function getInnerHTML(oElement)
{
	if ('innerHTML' in oElement)
		return oElement.innerHTML;
	else
	{
		var sReturnValue = '';
		for (var i = 0; i < oElement.childNodes.length; i++)
			sReturnValue += getOuterHTML(oElement.childNodes[i]);

		return sReturnValue;
	}
}

function getOuterHTML(oNode)
{
	if ('outerHTML' in oNode)
		return oNode.outerHTML;

	var sReturnValue = '';

	switch (oNode.nodeType)
	{
		// An element.
		case 1:
			sReturnValue += '<' + oNode.nodeName;

			for (var i = 0; i < oNode.attributes.length; i++)
			{
				if (oNode.attributes[i].nodeValue != null)
					sReturnValue += ' ' + oNode.attributes[i].nodeName + '="' + oNode.attributes[i].nodeValue + '"';
			}

			if (oNode.childNodes.length == 0 && in_array(oNode.nodeName.toLowerCase(), ['hr', 'input', 'img', 'link', 'meta', 'br']))
				sReturnValue += ' />';
			else
				sReturnValue += '>' + getInnerHTML(oNode) + '</' + oNode.nodeName + '>';
		break;

		// 2 is an attribute.

		// Just some text..
		case 3:
			sReturnValue += oNode.nodeValue;
		break;

		// A CDATA section.
		case 4:
			sReturnValue += '<![CDATA' + '[' + oNode.nodeValue + ']' + ']>';
		break;

		// Entity reference..
		case 5:
			sReturnValue += '&' + oNode.nodeName + ';';
		break;

		// 6 is an actual entity, 7 is a PI.

		// Comment.
		case 8:
			sReturnValue += '<!--' + oNode.nodeValue + '-->';
		break;
	}

	return sReturnValue;
}

// Checks for variable in theArray.
function in_array(variable, theArray)
{
	for (var i in theArray)
		if (theArray[i] == variable)
			return true;

	return false;
}

// Checks for variable in theArray.
function array_search(variable, theArray)
{
	for (var i in theArray)
		if (theArray[i] == variable)
			return i;

	return null;
}

// Find a specific radio button in its group and select it.
function selectRadioByName(oRadioGroup, sName)
{
	if (!('length' in oRadioGroup))
		return oRadioGroup.checked = true;

	for (var i = 0, n = oRadioGroup.length; i < n; i++)
		if (oRadioGroup[i].value == sName)
			return oRadioGroup[i].checked = true;

	return false;
}

// Invert all checkboxes at once by clicking a single checkbox.
function invertAll(oInvertCheckbox, oForm, sMask, bIgnoreDisabled)
{
	for (var i = 0; i < oForm.length; i++)
	{
		if (!('name' in oForm[i]) || (typeof(sMask) == 'string' && oForm[i].name.substr(0, sMask.length) != sMask && oForm[i].id.substr(0, sMask.length) != sMask))
			continue;

		if (!oForm[i].disabled || (typeof(bIgnoreDisabled) == 'boolean' && bIgnoreDisabled))
			oForm[i].checked = oInvertCheckbox.checked;
	}
}

function fogZone(checkform, mask)
{
	for (var i = 0; i < checkform.length; i++)
		if (typeof(checkform[i].name) != 'undefined' && checkform[i].id.substr(0, mask.length) == mask && checkform[i].id.substr(mask.length) > 0)
			checkform[i].disabled = !checkform[i].disabled;
}

// Keep the session alive - always!
var lastKeepAliveCheck = new Date().getTime();
function smf_sessionKeepAlive()
{
	var curTime = new Date().getTime();

	// Prevent a Firefox bug from hammering the server.
	if (smf_scripturl && curTime - lastKeepAliveCheck > 900000)
	{
		var tempImage = new Image();
		tempImage.src = smf_scripturl + (smf_scripturl.indexOf('?') == -1 ? '?' : '&') + 'action=keepalive;time=' + curTime;
		lastKeepAliveCheck = curTime;
	}

	window.setTimeout('smf_sessionKeepAlive();', 1200000);
}
window.setTimeout('smf_sessionKeepAlive();', 1200000);

// Set a theme option through javascript.
function smf_setThemeOption(option, value, theme, cur_session_id, cur_session_var, additional_vars)
{
	// Compatibility.
	if (cur_session_id == null)
		cur_session_id = smf_session_id;
	if (typeof(cur_session_var) == 'undefined')
		cur_session_var = 'sesc';

	if (additional_vars == null)
		additional_vars = '';

	var tempImage = new Image();
	tempImage.src = smf_scripturl + (smf_scripturl.indexOf('?') == -1 ? '?' : '&') + 'action=jsoption;var=' + option + ';val=' + value + ';' + cur_session_var + '=' + cur_session_id + additional_vars + (theme == null ? '' : '&id=' + theme) + ';time=' + (new Date().getTime());
}

function smf_avatarResize()
{
	var possibleAvatars = document.getElementsByTagName('img');

	for (var i = 0; i < possibleAvatars.length; i++)
	{
		if (possibleAvatars[i].className != 'avatar')
			continue;

		var tempAvatar = new Image();
		tempAvatar.src = possibleAvatars[i].src;

		if (smf_avatarMaxWidth != 0 && tempAvatar.width > smf_avatarMaxWidth)
		{
			possibleAvatars[i].height = (smf_avatarMaxWidth * tempAvatar.height) / tempAvatar.width;
			possibleAvatars[i].width = smf_avatarMaxWidth;
		}
		else if (smf_avatarMaxHeight != 0 && tempAvatar.height > smf_avatarMaxHeight)
		{
			possibleAvatars[i].width = (smf_avatarMaxHeight * tempAvatar.width) / tempAvatar.height;
			possibleAvatars[i].height = smf_avatarMaxHeight;
		}
		else
		{
			possibleAvatars[i].width = tempAvatar.width;
			possibleAvatars[i].height = tempAvatar.height;
		}
	}

	if (typeof(window_oldAvatarOnload) != 'undefined' && window_oldAvatarOnload)
	{
		window_oldAvatarOnload();
		window_oldAvatarOnload = null;
	}
}

function hashLoginPassword(doForm, cur_session_id)
{
	// Compatibility.
	if (cur_session_id == null)
		cur_session_id = smf_session_id;

	if (typeof(hex_sha1) == 'undefined')
		return;
	// Are they using an email address?
	if (doForm.user.value.indexOf('@') != -1)
		return;

	// Unless the browser is Opera, the password will not save properly.
	if (!('opera' in window))
		doForm.passwrd.autocomplete = 'off';

	doForm.hash_passwrd.value = hex_sha1(hex_sha1(doForm.user.value.php_to8bit().php_strtolower() + doForm.passwrd.value.php_to8bit()) + cur_session_id);

	// It looks nicer to fill it with asterisks, but Firefox will try to save that.
	if (is_ff != -1)
		doForm.passwrd.value = '';
	else
		doForm.passwrd.value = doForm.passwrd.value.replace(/./g, '*');
}

function hashAdminPassword(doForm, username, cur_session_id)
{
	// Compatibility.
	if (cur_session_id == null)
		cur_session_id = smf_session_id;

	if (typeof(hex_sha1) == 'undefined')
		return;

	doForm.admin_hash_pass.value = hex_sha1(hex_sha1(username.php_to8bit().php_strtolower() + doForm.admin_pass.value.php_to8bit()) + cur_session_id);
	doForm.admin_pass.value = doForm.admin_pass.value.replace(/./g, '*');
}

// Shows the page numbers by clicking the dots (in compact view).
function expandPages(spanNode, baseURL, firstPage, lastPage, perPage)
{
	var replacement = '', i, oldLastPage = 0;
	var perPageLimit = 50;

	// The dots were bold, the page numbers are not (in most cases).
	spanNode.style.fontWeight = 'normal';
	spanNode.onclick = '';

	// Prevent too many pages to be loaded at once.
	if ((lastPage - firstPage) / perPage > perPageLimit)
	{
		oldLastPage = lastPage;
		lastPage = firstPage + perPageLimit * perPage;
	}

	// Calculate the new pages.
	for (i = firstPage; i < lastPage; i += perPage)
		replacement += '<a class="navPages" href="' + baseURL.replace(/%1\$d/, i) + '">' + (1 + i / perPage) + '</a> ';

	if (oldLastPage > 0)
		replacement += '<span style="font-weight: bold; cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';" onclick="expandPages(this, \'' + baseURL + '\', ' + lastPage + ', ' + oldLastPage + ', ' + perPage + ');"> ... </span> ';

	// Replace the dots by the new page links.
	setInnerHTML(spanNode, replacement);
}


// *** smc_Cookie class.
function smc_Cookie(oOptions)
{
	this.opt = oOptions;
	this.oCookies = {};
	this.init();
}

smc_Cookie.prototype.init = function()
{
	if ('cookie' in document && document.cookie != '')
	{
		var aCookieList = document.cookie.split(';');
		for (var i = 0, n = aCookieList.length; i < n; i++)
		{
			var aNameValuePair = aCookieList[i].split('=');
			this.oCookies[aNameValuePair[0].replace(/^\s+|\s+$/g, '')] = decodeURIComponent(aNameValuePair[1]);
		}
	}
}

smc_Cookie.prototype.get = function(sKey)
{
	return sKey in this.oCookies ? this.oCookies[sKey] : null;
}

smc_Cookie.prototype.set = function(sKey, sValue)
{
	document.cookie = sKey + '=' + encodeURIComponent(sValue);
}


// *** smc_Toggle class.
function smc_Toggle(oOptions)
{
	this.opt = oOptions;
	this.bCollapsed = false;
	this.oCookie = null;
	this.init();
}

smc_Toggle.prototype.init = function ()
{
	// The master switch can disable this toggle fully.
	if ('bToggleEnabled' in this.opt && !this.opt.bToggleEnabled)
		return;

	// If cookies are enabled and they were set, override the initial state.
	if ('oCookieOptions' in this.opt && this.opt.oCookieOptions.bUseCookie)
	{
		// Initialize the cookie handler.
		this.oCookie = new smc_Cookie({});

		// Check if the cookie is set.
		var cookieValue = this.oCookie.get(this.opt.oCookieOptions.sCookieName)
		if (cookieValue != null)
			this.opt.bCurrentlyCollapsed = cookieValue == '1';
	}

	// If the init state is set to be collapsed, collapse it.
	if (this.opt.bCurrentlyCollapsed)
		this.changeState(true);

	// Initialize the images to be clickable.
	if ('aSwapImages' in this.opt)
	{
		for (var i = 0, n = this.opt.aSwapImages.length; i < n; i++)
		{
			var oImage = document.getElementById(this.opt.aSwapImages[i].sId);
			if (typeof(oImage) == 'object' && oImage != null)
			{
				// Display the image in case it was hidden.
				if (oImage.style.display == 'none')
					oImage.style.display = '';

				oImage.instanceRef = this;
				oImage.onclick = function () {
					this.instanceRef.toggle();
					this.blur();
				}
				oImage.style.cursor = 'pointer';

				// Preload the collapsed image.
				var oCollapsedImg = new Image();
				oCollapsedImg.src = this.opt.aSwapImages[i].srcCollapsed;
			}
		}
	}

	// Initialize links.
	if ('aSwapLinks' in this.opt)
	{
		for (var i = 0, n = this.opt.aSwapLinks.length; i < n; i++)
		{
			var oLink = document.getElementById(this.opt.aSwapLinks[i].sId);
			if (typeof(oLink) == 'object' && oLink != null)
			{
				// Display the link in case it was hidden.
				if (oLink.style.display == 'none')
					oLink.style.display = '';

				oLink.instanceRef = this;
				oLink.onclick = function () {
					this.instanceRef.toggle();
					this.blur();
					return false;
				}
			}
		}
	}
}

// Collapse or expand the section.
smc_Toggle.prototype.changeState = function(bCollapse)
{
	// Handle custom function hook before collapse.
	if (bCollapse && 'funcOnBeforeCollapse' in this.opt)
	{
		this.tmpMethod = this.opt.funcOnBeforeCollapse;
		this.tmpMethod();
		delete this.tmpMethod;
	}

	// Handle custom function hook before expand.
	else if (!bCollapse && 'funcOnBeforeExpand' in this.opt)
	{
		this.tmpMethod = this.opt.funcOnBeforeExpand;
		this.tmpMethod();
		delete this.tmpMethod;
	}

	// Loop through all the images that need to be toggled.
	if ('aSwapImages' in this.opt)
	{
		for (var i = 0, n = this.opt.aSwapImages.length; i < n; i++)
		{
			var oImage = document.getElementById(this.opt.aSwapImages[i].sId);
			if (typeof(oImage) == 'object' && oImage != null)
			{
				oImage.src = bCollapse ? this.opt.aSwapImages[i].srcCollapsed : this.opt.aSwapImages[i].srcExpanded;
				oImage.alt = oImage.title = bCollapse ? this.opt.aSwapImages[i].altCollapsed : this.opt.aSwapImages[i].altExpanded;
			}
		}
	}

	// Loop through all the links that need to be toggled.
	if ('aSwapLinks' in this.opt)
	{
		for (var i = 0, n = this.opt.aSwapLinks.length; i < n; i++)
		{
			var oLink = document.getElementById(this.opt.aSwapLinks[i].sId);
			if (typeof(oLink) == 'object' && oLink != null)
				setInnerHTML(oLink, bCollapse ? this.opt.aSwapLinks[i].msgCollapsed : this.opt.aSwapLinks[i].msgExpanded);
		}
	}

	// Now go through all the sections to be collapsed.
	for (var i = 0, n = this.opt.aSwappableContainers.length; i < n; i++)
	{
		if (this.opt.aSwappableContainers[i] == null)
			continue;

		var oContainer = document.getElementById(this.opt.aSwappableContainers[i]);
		if (typeof(oContainer) == 'object' && oContainer != null)
			oContainer.style.display = bCollapse ? 'none' : '';
	}

	// Update the new state.
	this.bCollapsed = bCollapse;

	// Update the cookie, if desired.
	if ('oCookieOptions' in this.opt && this.opt.oCookieOptions.bUseCookie)
		this.oCookie.set(this.opt.oCookieOptions.sCookieName, this.bCollapsed ? '1' : '0');

	if ('oThemeOptions' in this.opt && this.opt.oThemeOptions.bUseThemeSettings)
		smf_setThemeOption(this.opt.oThemeOptions.sOptionName, this.bCollapsed ? '1' : '0', 'sThemeId' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sThemeId : null, this.opt.oThemeOptions.sSessionId, this.opt.oThemeOptions.sSessionVar, 'sAdditionalVars' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sAdditionalVars : null);
}

smc_Toggle.prototype.toggle = function()
{
	// Change the state by reversing the current state.
	this.changeState(!this.bCollapsed);
}


function ajax_indicator(turn_on)
{
	if (ajax_indicator_ele == null)
	{
		ajax_indicator_ele = document.getElementById('ajax_in_progress');

		if (ajax_indicator_ele == null && typeof(ajax_notification_text) != null)
			create_ajax_indicator_ele();
	}

	if (ajax_indicator_ele != null)
	{
		if (navigator.appName == 'Microsoft Internet Explorer' && !is_ie7up)
		{
			ajax_indicator_ele.style.position = 'absolute';
			ajax_indicator_ele.style.top = document.documentElement.scrollTop;
		}

		ajax_indicator_ele.style.display = turn_on ? 'block' : 'none';
	}
}

function create_ajax_indicator_ele()
{
	// Create the div for the indicator.
	ajax_indicator_ele = document.createElement('div');

	// Set the id so it'll load the style properly.
	ajax_indicator_ele.id = 'ajax_in_progress';

	// Add the image in and link to turn it off.
	var cancel_link = document.createElement('a');
	cancel_link.href = 'javascript:ajax_indicator(false)';
	var cancel_img = document.createElement('img');
	cancel_img.src = 'http://noisen.com/loading.gif';
	cancel_img.style.marginRight = '0.6em';
	if (typeof(ajax_notification_cancel_text) != 'undefined')
	{
		cancel_img.alt = ajax_notification_cancel_text;
		cancel_img.title = ajax_notification_cancel_text;
	}

	// Add the cancel link and image to the indicator.
	cancel_link.appendChild(cancel_img);
	ajax_indicator_ele.appendChild(cancel_link);

	// Set the text.  (Note:  You MUST append here and not overwrite.)
	ajax_indicator_ele.innerHTML += ajax_notification_text;

	// Finally attach the element to the body.
	document.body.appendChild(ajax_indicator_ele);
}

function createEventListener(oTarget)
{
	if (!('addEventListener' in oTarget))
	{
		if (oTarget.attachEvent)
		{
			oTarget.addEventListener = function (sEvent, funcHandler, bCapture)	{ oTarget.attachEvent('on' + sEvent, funcHandler); }
			oTarget.removeEventListener = function (sEvent, funcHandler, bCapture) { oTarget.detachEvent('on' + sEvent, funcHandler); }
		}
		else
		{
			oTarget.addEventListener = function (sEvent, funcHandler, bCapture) { oTarget['on' + sEvent] = funcHandler; }
			oTarget.removeEventListener = function (sEvent, funcHandler, bCapture) { oTarget['on' + sEvent] = null; }
		}
	}
}

// *** IconList object.
function IconList(oOptions)
{
	if (!window.XMLHttpRequest)
		return;

	this.opt = oOptions;
	this.bListLoaded = false;
	this.oContainerDiv = null;
	this.funcMousedownHandler = null;
	this.funcParent = this;
	this.iCurMessageId = 0;
	this.iCurTimeout = 0;

	// Add backwards compatibility with old themes.
	if (!('sSessionVar' in this.opt))
		this.opt.sSessionVar = 'sesc';

	this.initIcons();
}

// Replace all message icons by icons with hoverable and clickable div's.
IconList.prototype.initIcons = function ()
{
	for (var i = document.images.length - 1, iPrefixLength = this.opt.sIconIdPrefix.length; i >= 0; i--)
		if (document.images[i].id.substr(0, iPrefixLength) == this.opt.sIconIdPrefix)
			setOuterHTML(document.images[i], '<img id="' + document.images[i].id + '" src="' + document.images[i].src + '" alt="' + document.images[i].alt + '" title="Visibilité" onclick="aIconList.openPopup(this, ' + document.images[i].id.substr(iPrefixLength).replace(/_/, ', ') + ')" onmouseover="aIconList.onBoxHover(this, true)" onmouseout="aIconList.onBoxHover(this, false)" class="privacy_icon" />');
}

// Event for the mouse hovering over the original icon.
IconList.prototype.onBoxHover = function (oDiv, bMouseOver)
{
	oDiv.style.border = bMouseOver ? '1px solid #adadad' : '';
	oDiv.style.background = bMouseOver ? '#ffffff' : 'transparent';
	oDiv.style.padding = bMouseOver ? '2px' : '3px'
}

// Show the list of icons after the user clicked the original icon.
IconList.prototype.openPopup = function (oDiv, iMessageId, iTopicId)
{
	function container(oCont)
	{
		oCont.id = 'iconList';
		oCont.style.display = 'none';
		oCont.style.cursor = is_ie && !is_ie6up ? 'hand' : 'pointer';
		oCont.style.position = 'absolute';
		oCont.style.background = '#ffffff';
		oCont.style.border = '1px solid #adadad';
		oCont.style.padding = '1px';
		oCont.style.textAlign = 'left';
	}

	this.iCurMessageId = iMessageId;

	if (!this.bListLoaded && this.oContainerDiv == null)
	{
		// Create a container div.
		this.oContainerDiv = document.createElement('div');
		this.oGroupsDiv = document.createElement('div');
		container(this.oContainerDiv);
		container(this.oGroupsDiv);
		document.body.appendChild(this.oContainerDiv);
		document.body.appendChild(this.oGroupsDiv);

		var ic =  ['default','members','friends','groups','justme'];
		var icn = ['Visibilité par défaut du site','Utilisateurs connectés','L\'auteur et ses amis','Groupes spécifiques','Seulement l\'auteur'];
		var sItems = '';

		for (var i = 0; i < 5; i++)
			sItems += '<div onmouseover="aIconList.onItemHover(this, true)" onmouseout="aIconList.onItemHover(this, false);" onmousedown="aIconList.onItemMouseDown(this, \'' + ic[i] + '\');" style="padding: 3px 0px 3px 0px; margin-left: auto; margin-right: auto; border: ' + this.opt.sItemBorder + '; background: #ffffff"><img src="http://noisen.com/k-' + ic[i] + '.png" alt="' + icn[i] + '" border="0" />&nbsp;' + icn[i] + '&nbsp;</div>';

		setInnerHTML(this.oContainerDiv, sItems);
		this.oContainerDiv.style.display = 'inline';
		this.bListLoaded = true;

		if (is_ie)
			this.oContainerDiv.style.width = this.oContainerDiv.clientWidth + 'px';

		createEventListener(document.body);
	}
	else
		this.oContainerDiv.style.display = 'inline';

	this.iTopicId = iTopicId;
	this.isClosed = 0;

	// Set the position of the container.
	var aPos = smf_itemPos(oDiv);
	if (is_ie50)
		aPos[1] += 4;

	this.oContainerDiv.style.top = (aPos[1] + oDiv.offsetHeight) + 'px';
	this.oContainerDiv.style.left = (aPos[0] - 1) + 'px';
	this.oClickedIcon = oDiv;

	document.body.addEventListener('mousedown', this.onWindowMouseDown, false);
}

// Event handler for hovering over the icons.
IconList.prototype.onItemHover = function (oDiv, bMouseOver)
{
	oDiv.style.background = bMouseOver ? '#e0e0f0' : '#ffffff';
	oDiv.style.border = bMouseOver ? this.opt.sItemBorderHover : this.opt.sItemBorder;
	if (this.iCurTimeout != 0)
		window.clearTimeout(this.iCurTimeout);
	if (bMouseOver)
		this.onBoxHover(this.oClickedIcon, true);
	else
		this.iCurTimeout = window.setTimeout('aIconList.collapseList();', 500);
}

IconList.prototype.generateGroups = function (oDiv)
{
	if (this.iTopicId == 0)
		return;
	ajax_indicator(true);
	this.tmpMethod = getXMLDocument;
	var oXMLDoc = this.tmpMethod(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=jsmodify;topic=' + this.iTopicId + ';msg=' + this.iCurMessageId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';groups;xml');
	delete this.tmpMethod;
	ajax_indicator(false);
	this.dontCloseNow = 1;
	this.storeDiv = oDiv;
	document.body.removeEventListener('mousedown', this.onWindowMouseDown, false);

	var oMessage = oXMLDoc.responseXML.getElementsByTagName('smf')[0].getElementsByTagName('groups')[0];
	var oContents = oMessage.childNodes[0].nodeValue;
	if (typeof(oContents) != 'undefined')
	{
		setInnerHTML(this.oGroupsDiv, oContents);
		this.oGroupsDiv.style.top = this.oContainerDiv.offsetTop + this.oContainerDiv.clientHeight/2 + 'px';
		this.oGroupsDiv.style.left = this.oContainerDiv.offsetLeft + this.oContainerDiv.clientWidth + 'px';
		this.oGroupsDiv.style.display = 'inline';
	}
}

IconList.prototype.submitGroups = function (oFormButton, oGoAhead)
{
	this.dontCloseNow = 0;
	this.collapseList();
	var oForm = oFormButton.parentNode;

	if (!oGoAhead)
		return;

	var groups = '';
	for (var i = 0; i < oForm.length; i++)
		if (typeof(oForm[i].name) != 'undefined' && oForm[i].checked && oForm[i].id.substr(0, 8) == 'ggroups_' && !isNaN(oForm[i].id.substr(8)))
			groups += (groups == '' ? '=' : ',') + oForm[i].id.substr(8);

	this.completeDeal(this.storeDiv, ';privacy=groups;setgroups' + groups);
}

// Event handler for clicking on one of the icons.
IconList.prototype.onItemMouseDown = function (oDiv, sNewIcon)
{
	if (this.isClosed)
		return;
	if (sNewIcon == 'groups')
		return this.generateGroups(oDiv);

	this.completeDeal(oDiv, ';privacy=' + sNewIcon);
}

IconList.prototype.completeDeal = function (oDiv, oSay)
{
	ajax_indicator(true);
	this.tmpMethod = getXMLDocument;
	var oXMLDoc = this.tmpMethod(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=jsmodify;topic=' + this.iTopicId + ';msg=' + this.iCurMessageId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + oSay + ';xml');
	delete this.tmpMethod;
	ajax_indicator(false);

	var oMessage = oXMLDoc.responseXML.getElementsByTagName('smf')[0].getElementsByTagName('message')[0];
	if (oMessage.getElementsByTagName('error').length == 0)
	{
		if (this.opt.bShowModify && oMessage.getElementsByTagName('modified').length != 0)
			setInnerHTML(document.getElementById('modified_' + this.iCurMessageId), oMessage.getElementsByTagName('modified')[0].childNodes[0].nodeValue);
		if (oMessage.getElementsByTagName('privacy').length != 0)
			this.oClickedIcon.src = oMessage.getElementsByTagName('privacy')[0].childNodes[0].nodeValue;
	}
}

// Event handler for clicking outside the list (will make the list disappear).
IconList.prototype.onWindowMouseDown = function ()
{
	aIconList.funcParent.tmpMethod = aIconList.collapseList;
	aIconList.funcParent.tmpMethod();
	delete aIconList.funcParent.tmpMethod;
}

// Collapse the list of icons.
IconList.prototype.collapseList = function()
{
	if (typeof(this.dontCloseNow) != 'undefined' && this.dontCloseNow)
		return;

	this.onBoxHover(this.oClickedIcon, false);
	this.oContainerDiv.style.display = 'none';
	this.oGroupsDiv.style.display = 'none';
	this.isClosed = 1;
	document.body.removeEventListener('mousedown', this.onWindowMouseDown, false);
}

// Handy shortcuts for getting the mouse position on the screen - only used for IE at the moment.
function smf_mousePose(oEvent)
{
	var x = 0;
	var y = 0;

	if (oEvent.pageX)
	{
		y = oEvent.pageY;
		x = oEvent.pageX;
	}
	else if (oEvent.clientX)
	{
		x = oEvent.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		y = oEvent.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}

	return [x, y];
}

// Short function for finding the actual position of an item.
function smf_itemPos(itemHandle)
{
	var itemX = 0;
	var itemY = 0;

	if ('offsetParent' in itemHandle)
	{
		itemX = itemHandle.offsetLeft;
		itemY = itemHandle.offsetTop;
		while (itemHandle.offsetParent && typeof(itemHandle.offsetParent) == 'object')
		{
			itemHandle = itemHandle.offsetParent;
			itemX += itemHandle.offsetLeft;
			itemY += itemHandle.offsetTop;
		}
	}
	else if ('x' in itemHandle)
	{
		itemX = itemHandle.x;
		itemY = itemHandle.y;
	}

	return [itemX, itemY];
}

// This function takes the script URL and prepares it to allow the query string to be appended to it.
function smf_prepareScriptUrl(sUrl)
{
	return sUrl.indexOf('?') == -1 ? sUrl + '?' : sUrl + (sUrl.charAt(sUrl.length - 1) == '?' || sUrl.charAt(sUrl.length - 1) == '&' || sUrl.charAt(sUrl.length - 1) == ';' ? '' : ';');
}

var aOnloadEvents = new Array();
function addLoadEvent(fNewOnload)
{
	// If there's no event set, just set this one
	if (!('onload' in window) || typeof(window.onload) != 'function')
		window.onload = fNewOnload;

	// If there's just one event, setup the array.
	else if(aOnloadEvents.length == 0)
	{
		aOnloadEvents[0] = window.onload;
		aOnloadEvents[1] = fNewOnload;
		window.onload = function() {
			for (var i = 0, n = aOnloadEvents.length; i < n; i++)
			{
				if (typeof(aOnloadEvents[i]) == 'function')
					aOnloadEvents[i]();
			}
		}
	}

	// This isn't the first event function, add it to the list.
	else
		aOnloadEvents[aOnloadEvents.length] = fNewOnload;
}

// Get the text in a code tag.
function smfSelectText(oCurElement, bActOnElement)
{
	// The place we're looking for is one div up, and next door - if it's auto detect.
	if (typeof(bActOnElement) == 'boolean' && bActOnElement)
		var oCodeArea = document.getElementById(oCurElement);
	else
		var oCodeArea = oCurElement.parentNode.nextSibling;

	if (typeof(oCodeArea) != 'object' || oCodeArea == null)
		return false;

	// Start off with my favourite, internet explorer.
	if ('createTextRange' in document.body)
	{
		var oCurRange = document.body.createTextRange();
		oCurRange.moveToElementText(oCodeArea);
		oCurRange.select();
	}
	// Firefox at el.
	else if (window.getSelection)
	{
		var oCurSelection = window.getSelection();
		// Safari is special!
		if (oCurSelection.setBaseAndExtent)
		{
			var oLastChild = oCodeArea.lastChild;
			oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
		}
		else
		{
			var curRange = document.createRange();
			curRange.selectNodeContents(oCodeArea);

			oCurSelection.removeAllRanges();
			oCurSelection.addRange(curRange);
		}
	}

	return false;
}

// A function needed to discern HTML entities from non-western characters.
function smc_saveEntities(sFormName, aElementNames, sMask)
{
	if (typeof(sMask) == 'string')
	{
		for (var i = 0, n = document.forms[sFormName].elements.length; i < n; i++)
			if (document.forms[sFormName].elements[i].id.substr(0, sMask.length) == sMask)
				aElementNames[aElementNames.length] = document.forms[sFormName].elements[i].name;
	}

	for (var i = 0, n = aElementNames.length; i < n; i++)
	{
		if (aElementNames[i] in document.forms[sFormName])
			document.forms[sFormName][aElementNames[i]].value = document.forms[sFormName][aElementNames[i]].value.replace(/&#/g, '&#38;#');
	}
}

// A global array containing all PersonalText objects.
var aPersonalText = new Array();
var old_id_thought = -1, mid = 0;

// *** PersonalText object.
function PersonalText(oOptions)
{
	if (!window.XMLHttpRequest)
		return;

	this.opt = oOptions;
	this.funcMousedownHandler = null;
	this.funcParent = this;

	this.initText();
}

// Make that personal text editable!
PersonalText.prototype.initText = function()
{
	var thought = document.getElementById('update_thought_0');
	setOuterHTML(thought, '<span style="font-size: 7pt; padding: 1px 2px;" id="update_thought_0" title="' + this.opt.sLabelPersonalText + '" onclick="aPersonalText[0].showEdit(0);" onmouseover="aPersonalText[0].onBoxHover(this, true)" onmouseout="aPersonalText[0].onBoxHover(this, false)" style="cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';">' + thought.innerHTML + '</span>');
}

// Event for the mouse hovering over the text.
PersonalText.prototype.onBoxHover = function (oDiv, bMouseOver)
{
	oDiv.style.border = bMouseOver ? this.opt.sBoxBorderHover : '';
	oDiv.style.background = bMouseOver ? this.opt.sBoxBackgroundHover : this.opt.sBoxBackground;
}

// Show the input after the user has clicked the text.
PersonalText.prototype.showEdit = function(tid, maid)
{
	mid = maid ? maid : tid;
	if (old_id_thought >= 0)
		this.cancelEdit(old_id_thought);

	var thought = document.getElementById('update_thought_' + tid);
	var was_personal = thought.innerHTML;
	if (was_personal.toLowerCase() == this.opt.sNoText.toLowerCase())
		thought.innerHTML = '';
	setOuterHTML(thought, '<form style="display: inline"><span style="font-size: 7pt" id="update_thought_span"><input type="hidden" id="old_thought" value="' + was_personal.php_htmlspecialchars() + '" /><input size="50" type="text" maxlength="255" id="new_thought" value="' + thought.innerHTML.php_htmlspecialchars() + '" class="smabu" /> <input type="submit" value="' + this.opt.sSubmit + '" onclick="aPersonalText[0].onInputSubmit(' + tid + ');" class="smabu" /> <input type="button" value="' + this.opt.sCancel + '" onclick="' + this.opt.sBackReference + '.cancelEdit(' + tid + ');" class="smabu" /></span></form>');
	old_id_thought = tid;
	document.getElementById('new_thought').focus();
}

// Make that personal text editable (again)!
PersonalText.prototype.cancelEdit = function(tid)
{
	var thought = document.getElementById('update_thought_span');
	var old_thought = document.getElementById('old_thought');
	if (old_thought)
		setOuterHTML(thought, '<span style="font-size: 7pt; padding: 1px 2px;" id="update_thought_' + tid + '" title="' + this.opt.sLabelPersonalText + '" onclick="aPersonalText[0].showEdit(' + tid + ', ' + mid + ');" onmouseover="aPersonalText[0].onBoxHover(this, true)" onmouseout="aPersonalText[0].onBoxHover(this, false)" style="cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';">' + old_thought.value + '</span>');
}

// Event handler for clicking submit.
PersonalText.prototype.onInputSubmit = function(tid)
{
	var thought = document.getElementById('update_thought_span');
	var new_thought = document.getElementById('new_thought');
	new_thought = new_thought.value;

	ajax_indicator(true);
	sendXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=xmlhttp;sa=personal', 'parent=' + tid + '&master=' + mid + '&text=' + escape(new_thought));
	ajax_indicator(false);

	if (new_thought == '')
		new_thought = this.opt.sNoText;
	old_id_thought = -1;
	setOuterHTML(thought, '<span style="font-size: 7pt; padding: 1px 2px;" id="update_thought" title="' + aPersonalText[0].sLabelPersonalText + '" onclick="aPersonalText[0].showEdit(' + tid + ', ' + mid + ');" onmouseover="aPersonalText[0].onBoxHover(this, true)" onmouseout="aPersonalText[0].onBoxHover(this, false)" style="cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';">' + new_thought + '</span>');
}

function lin(lien)
{
	document.location = 'http://noisen.com/?' + lien;
	return false;
}

function setHref()
{
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	var seanoi = document.getElementById('seanoi');
	if (seanoi != null)
		seanoi.autocomplete = 'off';

	var i, a, hre;
	var noddy = document.getElementsByTagName('a');
	for (i = 0; a = noddy[i]; i++)
	{
		if (a.getAttribute('title') && (a.getAttribute('title') == '-'))
			continue;

		hre = a.getAttribute('href');
		if (typeof hre == 'string' && hre.length > 0) {
			if ((hre.indexOf('noisen.') == -1) && (hre.indexOf(window.location.hostname) == -1) && (hre.indexOf('://') != -1))
			{
				a.setAttribute('class', 'xt');
				a.setAttribute('className', 'xt');
			}
		}
	}
}

if (document.addEventListener)
	document.addEventListener('DOMContentLoaded', setHref, false);
else
	addLoadEvent(setHref);
