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 || ua.indexOf('shiretoko') != -1 || ua.indexOf('minefield') != -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_iphone = ua.indexOf('iphone') != -1 || ua.indexOf('ipod') != -1;
var is_android = ua.indexOf('android') != -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 (smf_charset == 'UTF-8')
	{
		var n, sReturn = '';

		for (var i = 0, iTextLen = this.length; i < iTextLen; i++)
		{
			n = this.charCodeAt(i);
			if (n < 128)
				sReturn += String.fromCharCode(n)
			else if (n < 2048)
				sReturn += String.fromCharCode(192 | n >> 6) + String.fromCharCode(128 | n & 63);
			else if (n < 65536)
				sReturn += String.fromCharCode(224 | n >> 12) + String.fromCharCode(128 | n >> 6 & 63) + String.fromCharCode(128 | n & 63);
			else
				sReturn += String.fromCharCode(240 | n >> 18) + String.fromCharCode(128 | n >> 12 & 63) + String.fromCharCode(128 | n >> 6 & 63) + String.fromCharCode(128 | n & 63);
		}

		return sReturn;
	}

	else if (this.oCharsetConversion.from.length == 0)
	{
		switch (smf_charset)
		{
			case 'ISO-8859-1':
				this.oCharsetConversion = {
					from: '\xa0-\xff',
					to: '\xa0-\xff'
				};
			break;

			case 'ISO-8859-2':
				this.oCharsetConversion = {
					from: '\xa0\u0104\u02d8\u0141\xa4\u013d\u015a\xa7\xa8\u0160\u015e\u0164\u0179\xad\u017d\u017b\xb0\u0105\u02db\u0142\xb4\u013e\u015b\u02c7\xb8\u0161\u015f\u0165\u017a\u02dd\u017e\u017c\u0154\xc1\xc2\u0102\xc4\u0139\u0106\xc7\u010c\xc9\u0118\xcb\u011a\xcd\xce\u010e\u0110\u0143\u0147\xd3\xd4\u0150\xd6\xd7\u0158\u016e\xda\u0170\xdc\xdd\u0162\xdf\u0155\xe1\xe2\u0103\xe4\u013a\u0107\xe7\u010d\xe9\u0119\xeb\u011b\xed\xee\u010f\u0111\u0144\u0148\xf3\xf4\u0151\xf6\xf7\u0159\u016f\xfa\u0171\xfc\xfd\u0163\u02d9',
					to: '\xa0-\xff'
				};
			break;

			case 'ISO-8859-5':
				this.oCharsetConversion = {
					from: '\xa0\u0401-\u040c\xad\u040e-\u044f\u2116\u0451-\u045c\xa7\u045e\u045f',
					to: '\xa0-\xff'
				};
			break;

			case 'ISO-8859-9':
				this.oCharsetConversion = {
					from: '\xa0-\xcf\u011e\xd1-\xdc\u0130\u015e\xdf-\xef\u011f\xf1-\xfc\u0131\u015f\xff',
					to: '\xa0-\xff'
				};
			break;

			case 'ISO-8859-15':
				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'
				};
			break;

			case 'tis-620':
				this.oCharsetConversion = {
					from: '\u20ac\u2026\u2018\u2019\u201c\u201d\u2022\u2013\u2014\xa0\u0e01-\u0e3a\u0e3f-\u0e5b',
					to: '\x80\x85\x91-\x97\xa0-\xda\xdf-\xfb'
				};
			break;

			case 'windows-1251':
				this.oCharsetConversion = {
					from: '\u0402\u0403\u201a\u0453\u201e\u2026\u2020\u2021\u20ac\u2030\u0409\u2039\u040a\u040c\u040b\u040f\u0452\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u2122\u0459\u203a\u045a\u045c\u045b\u045f\xa0\u040e\u045e\u0408\xa4\u0490\xa6\xa7\u0401\xa9\u0404\xab-\xae\u0407\xb0\xb1\u0406\u0456\u0491\xb5-\xb7\u0451\u2116\u0454\xbb\u0458\u0405\u0455\u0457\u0410-\u044f',
					to: '\x80-\x97\x99-\xff'
				};
			break;

			case 'windows-1253':
				this.oCharsetConversion = {
					from: '\u20ac\u201a\u0192\u201e\u2026\u2020\u2021\u2030\u2039\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u2122\u203a\xa0\u0385\u0386\xa3-\xa9\xab-\xae\u2015\xb0-\xb3\u0384\xb5-\xb7\u0388-\u038a\xbb\u038c\xbd\u038e-\u03a1\u03a3-\u03ce',
					to: '\x80\x82-\x87\x89\x8b\x91-\x97\x99\x9b\xa0-\xa9\xab-\xd1\xd3-\xfe'
				};
			break;

			case 'windows-1255':
				this.oCharsetConversion = {
					from: '\u20ac\u201a\u0192\u201e\u2026\u2020\u2021\u02c6\u2030\u2039\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u02dc\u2122\u203a\xa0-\xa3\u20aa\xa5-\xa9\xd7\xab-\xb9\xf7\xbb-\xbf\u05b0-\u05b9\u05bb-\u05c3\u05f0-\u05f4\u05d0-\u05ea\u200e\u200f',
					to: '\x80\x82-\x89\x8b\x91-\x99\x9b\xa0-\xc9\xcb-\xd8\xe0-\xfa\xfd\xfe'
				};
			break;

			case 'windows-1256':
				this.oCharsetConversion = {
					from: '\u20ac\u067e\u201a\u0192\u201e\u2026\u2020\u2021\u02c6\u2030\u0679\u2039\u0152\u0686\u0698\u0688\u06af\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u06a9\u2122\u0691\u203a\u0153\u200c\u200d\u06ba\xa0\u060c\xa2-\xa9\u06be\xab-\xb9\u061b\xbb-\xbe\u061f\u06c1\u0621-\u0636\xd7\u0637-\u063a\u0640-\u0643\xe0\u0644\xe2\u0645-\u0648\xe7-\xeb\u0649\u064a\xee\xef\u064b-\u064e\xf4\u064f\u0650\xf7\u0651\xf9\u0652\xfb\xfc\u200e\u200f\u06d2',
					to: '\x80-\xff'
				};
			break;

			default:
				this.oCharsetConversion = {
					from: '',
					to: ''
				};
			break;
		}
		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 && '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;
	}
}

// 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_prepareScriptUrl(smf_scripturl) + '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_prepareScriptUrl(smf_scripturl) + '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).replace(/%%/g, '%') + '">' + (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);
}

function smc_preCacheImage(sSrc)
{
	if (!('smc_aCachedImages' in window))
		window.smc_aCachedImages = [];

	if (!in_array(sSrc, window.smc_aCachedImages))
	{
		var oImage = new Image();
		oImage.src = sSrc;
	}
}


// *** 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, 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.
				smc_preCacheImage(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, bInit)
{
	// Default bInit to false.
	bInit = typeof(bInit) == 'undefined' ? false : true;

	// Handle custom function hook before collapse.
	if (!bInit && bCollapse && 'funcOnBeforeCollapse' in this.opt)
	{
		this.tmpMethod = this.opt.funcOnBeforeCollapse;
		this.tmpMethod();
		delete this.tmpMethod;
	}

	// Handle custom function hook before expand.
	else if (!bInit && !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)
			{
				// Only (re)load the image if it's changed.
				var sTargetSource = bCollapse ? this.opt.aSwapImages[i].srcCollapsed : this.opt.aSwapImages[i].srcExpanded;
				if (oImage.src != sTargetSource)
					oImage.src = sTargetSource;

				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 = smf_images_url + '/icons/quick_remove.gif';

	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;
			}
		}
	}
}

// This function will retrieve the contents needed for the jump to boxes.
function grabJumpToContent()
{
	var oXMLDoc = getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=xmlhttp;sa=jumpto;xml');
	var aBoardsAndCategories = new Array();

	ajax_indicator(true);

	if (oXMLDoc.responseXML)
	{
		var items = oXMLDoc.responseXML.getElementsByTagName('smf')[0].getElementsByTagName('item');
		for (var i = 0, n = items.length; i < n; i++)
		{
			aBoardsAndCategories[aBoardsAndCategories.length] = {
				id: parseInt(items[i].getAttribute('id')),
				isCategory: items[i].getAttribute('type') == 'category',
				name: items[i].firstChild.nodeValue.removeEntities(),
				is_current: false,
				childLevel: parseInt(items[i].getAttribute('childlevel'))
			}
		}
	}

	ajax_indicator(false);

	for (var i = 0, n = aJumpTo.length; i < n; i++)
		aJumpTo[i].fillSelect(aBoardsAndCategories);
}

// This'll contain all JumpTo objects on the page.
var aJumpTo = new Array();

// *** JumpTo class.
function JumpTo(oJumpToOptions)
{
	this.opt = oJumpToOptions;
	this.dropdownList = null;
	this.showSelect();
}

// Show the initial select box (onload). Method of the JumpTo class.
JumpTo.prototype.showSelect = function ()
{
	var sChildLevelPrefix = '';
	for (var i = this.opt.iCurBoardChildLevel; i > 0; i--)
		sChildLevelPrefix += this.opt.sBoardChildLevelIndicator;
	setInnerHTML(document.getElementById(this.opt.sContainerId), this.opt.sJumpToTemplate.replace(/%select_id%/, this.opt.sContainerId + '_select').replace(/%dropdown_list%/, '<select name="' + this.opt.sContainerId + '_select" id="' + this.opt.sContainerId + '_select" ' + ('implementation' in document ? '' : 'onmouseover="grabJumpToContent();" ') + ('onbeforeactivate' in document ? 'onbeforeactivate' : 'onfocus') + '="grabJumpToContent();"><option value="?board=' + this.opt.iCurBoardId + '.0">' + sChildLevelPrefix + this.opt.sBoardPrefix + this.opt.sCurBoardName.removeEntities() + '</option></select>&nbsp;<input type="button" value="' + this.opt.sGoButtonLabel + '" onclick="window.location.href = \'' + smf_prepareScriptUrl(smf_scripturl) + 'board=' + this.opt.iCurBoardId + '.0\';" />'));
	this.dropdownList = document.getElementById(this.opt.sContainerId + '_select');
}

// Fill the jump to box with entries. Method of the JumpTo class.
JumpTo.prototype.fillSelect = function (aBoardsAndCategories)
{
	var bIE5x = !('implementation' in document);
	var iIndexPointer = 0;

	// Create an option that'll be above and below the category.
	var oDashOption = document.createElement('option');
	oDashOption.appendChild(document.createTextNode(this.opt.sCatSeparator));
	oDashOption.disabled = 'disabled';
	oDashOption.value = '';

	// Reset the events and clear the list (IE5.x only).
	if (bIE5x)
	{
		this.dropdownList.onmouseover = null;
		this.dropdownList.remove(0);
	}
	if ('onbeforeactivate' in document)
		this.dropdownList.onbeforeactivate = null;
	else
		this.dropdownList.onfocus = null;

	// Create a document fragment that'll allowing inserting big parts at once.
	var oListFragment = bIE5x ? this.dropdownList : document.createDocumentFragment();

	// Loop through all items to be added.
	for (var i = 0, n = aBoardsAndCategories.length; i < n; i++)
	{
		var j, sChildLevelPrefix, oOption;

		// If we've reached the currently selected board add all items so far.
		if (!aBoardsAndCategories[i].isCategory && aBoardsAndCategories[i].id == this.opt.iCurBoardId)
		{
			if (bIE5x)
				iIndexPointer = this.dropdownList.options.length;
			else
			{
				this.dropdownList.insertBefore(oListFragment, this.dropdownList.options[0]);
				oListFragment = document.createDocumentFragment();
				continue;
			}
		}

		if (aBoardsAndCategories[i].isCategory)
			oListFragment.appendChild(oDashOption.cloneNode(true));
		else
			for (j = aBoardsAndCategories[i].childLevel, sChildLevelPrefix = ''; j > 0; j--)
				sChildLevelPrefix += this.opt.sBoardChildLevelIndicator;

		oOption = document.createElement('option');
		oOption.appendChild(document.createTextNode((aBoardsAndCategories[i].isCategory ? this.opt.sCatPrefix : sChildLevelPrefix + this.opt.sBoardPrefix) + aBoardsAndCategories[i].name));
		oOption.value = aBoardsAndCategories[i].isCategory ? '?action=forum#c' + aBoardsAndCategories[i].id : '?board=' + aBoardsAndCategories[i].id + '.0';
		oListFragment.appendChild(oOption);

		if (aBoardsAndCategories[i].isCategory)
			oListFragment.appendChild(oDashOption.cloneNode(true));
	}

	// Add the remaining items after the currently selected item.
	this.dropdownList.appendChild(oListFragment);

	if (bIE5x)
		this.dropdownList.options[iIndexPointer].selected = true;

	// Internet Explorer needs this to keep the box dropped down.
	this.dropdownList.style.width = 'auto';
	this.dropdownList.focus();

	// Add an onchange action
	this.dropdownList.onchange = function() {
		if (this.selectedIndex > 0 && this.options[this.selectedIndex].value)
			window.location.href = smf_scripturl + this.options[this.selectedIndex].value.substr(smf_scripturl.indexOf('?') == -1 || this.options[this.selectedIndex].value.substr(0, 1) != '?' ? 0 : 1);
	}
}

// A global array containing all IconList objects.
var aIconLists = new Array();

// *** 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], '<div title="' + this.opt.sLabelIconList + '" onclick="' + this.opt.sBackReference + '.openPopup(this, ' + document.images[i].id.substr(iPrefixLength) + ')" onmouseover="' + this.opt.sBackReference + '.onBoxHover(this, true)" onmouseout="' + this.opt.sBackReference + '.onBoxHover(this, false)" style="background: ' + this.opt.sBoxBackground + '; cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + '; padding: 3px; text-align: center;"><img src="' + document.images[i].src + '" alt="' + document.images[i].alt + '" id="' + document.images[i].id + '" style="margin: 0px; padding: ' + (is_ie ? '3px' : '3px 0px 3px 0px') + ';" /></div>');
}

// Event for the mouse hovering over the original icon.
IconList.prototype.onBoxHover = function (oDiv, bMouseOver)
{
	oDiv.style.border = bMouseOver ? this.opt.iBoxBorderWidthHover + 'px solid ' + this.opt.sBoxBorderColorHover : '';
	oDiv.style.background = bMouseOver ? this.opt.sBoxBackgroundHover : this.opt.sBoxBackground;
	oDiv.style.padding = bMouseOver ? (3 - this.opt.iBoxBorderWidthHover) + 'px' : '3px'
}

// Show the list of icons after the user clicked the original icon.
IconList.prototype.openPopup = function (oDiv, iMessageId)
{
	this.iCurMessageId = iMessageId;

	if (!this.bListLoaded && this.oContainerDiv == null)
	{
		// Create a container div.
		this.oContainerDiv = document.createElement('div');
		this.oContainerDiv.id = 'iconList';
		this.oContainerDiv.style.display = 'none';
		this.oContainerDiv.style.cursor = is_ie && !is_ie6up ? 'hand' : 'pointer';
		this.oContainerDiv.style.position = 'absolute';
		this.oContainerDiv.style.width = oDiv.offsetWidth + 'px';
		this.oContainerDiv.style.background = this.opt.sContainerBackground;
		this.oContainerDiv.style.border = this.opt.sContainerBorder;
		this.oContainerDiv.style.padding = '1px';
		this.oContainerDiv.style.textAlign = 'center';
		document.body.appendChild(this.oContainerDiv);

		// Start to fetch its contents.
		ajax_indicator(true);
		this.tmpMethod = getXMLDocument;
		this.tmpMethod(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=xmlhttp;sa=messageicons;board=' + this.opt.iBoardId + ';xml', this.onIconsReceived);
		delete this.tmpMethod;

		createEventListener(document.body);
	}

	// 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;

	if (this.bListLoaded)
		this.oContainerDiv.style.display = 'block';

	document.body.addEventListener('mousedown', this.onWindowMouseDown, false);
}

// Setup the list of icons once it is received through xmlHTTP.
IconList.prototype.onIconsReceived = function (oXMLDoc)
{
	var icons = oXMLDoc.getElementsByTagName('smf')[0].getElementsByTagName('icon');
	var sItems = '';

	for (var i = 0, n = icons.length; i < n; i++)
		sItems += '<div onmouseover="' + this.opt.sBackReference + '.onItemHover(this, true)" onmouseout="' + this.opt.sBackReference + '.onItemHover(this, false);" onmousedown="' + this.opt.sBackReference + '.onItemMouseDown(this, \'' + icons[i].getAttribute('value') + '\');" style="padding: 3px 0px 3px 0px; margin-left: auto; margin-right: auto; border: ' + this.opt.sItemBorder + '; background: ' + this.opt.sItemBackground + '"><img src="' + icons[i].getAttribute('url') + '" alt="' + icons[i].getAttribute('name') + '" title="' + icons[i].firstChild.nodeValue + '" border="0" /></div>';

	setInnerHTML(this.oContainerDiv, sItems);
	this.oContainerDiv.style.display = 'block';
	this.bListLoaded = true;

	if (is_ie)
		this.oContainerDiv.style.width = this.oContainerDiv.clientWidth + 'px';

	ajax_indicator(false);
}

// Event handler for hovering over the icons.
IconList.prototype.onItemHover = function (oDiv, bMouseOver)
{
	oDiv.style.background = bMouseOver ? this.opt.sItemBackgroundHover : this.opt.sItemBackground;
	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(this.opt.sBackReference + '.collapseList();', 500);
}

// Event handler for clicking on one of the icons.
IconList.prototype.onItemMouseDown = function (oDiv, sNewIcon)
{
	if (this.iCurMessageId != 0)
	{
		ajax_indicator(true);
		this.tmpMethod = getXMLDocument;
		var oXMLDoc = this.tmpMethod(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=jsmodify;topic=' + this.opt.iTopicId + ';msg=' + this.iCurMessageId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';icon=' + sNewIcon + ';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);
			this.oClickedIcon.getElementsByTagName('img')[0].src = oDiv.getElementsByTagName('img')[0].src;
		}
	}
}

// Event handler for clicking outside the list (will make the list disappear).
IconList.prototype.onWindowMouseDown = function ()
{
	for (var i = aIconLists.length - 1; i >= 0; i--)
	{
		aIconLists[i].funcParent.tmpMethod = aIconLists[i].collapseList;
		aIconLists[i].funcParent.tmpMethod();
		delete aIconLists[i].funcParent.tmpMethod;
	}
}

// Collapse the list of icons.
IconList.prototype.collapseList = function()
{
	this.onBoxHover(this.oClickedIcon, false);
	this.oContainerDiv.style.display = 'none';
	this.iCurMessageId = 0;
	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]();
				else if (typeof(aOnloadEvents[i]) == 'string')
					eval(aOnloadEvents[i]);
			}
		}
	}

	// This isn't the first event function, add it to the list.
	else
		aOnloadEvents[aOnloadEvents.length] = fNewOnload;
}

function smfFooterHighlight(element, value)
{
	element.src = smf_images_url + '/' + (value ? 'h_' : '') + element.id + '.gif';
}

// 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;#');
	}
}
/**
* Zawgyi Virtual Keyboard
* Copyright 2005,2009 www.yamc.info
* This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
* http://creativecommons.org/licenses/by-sa/2.5/
* You are free to modify this code to meet your requirements, as specified in the above 
* license. Please include a link to yamc.info on your website. 
*/

function browser ()
{
    var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);
    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
    this.aol   = (agt.indexOf("aol") != -1);
    this.aol3  = (this.aol && this.ie3);
    this.aol4  = (this.aol && this.ie4);
    this.aol5  = (agt.indexOf("aol 5") != -1);
    this.aol6  = (agt.indexOf("aol 6") != -1);
    this.opera = (agt.indexOf("opera") != -1);
    this.opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.opera5up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4);
    this.webtv = (agt.indexOf("webtv") != -1); 
    this.TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    this.AOLTV = this.TVNavigator;
    this.hotjava = (agt.indexOf("hotjava") != -1);
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));
}
function handleKeys(e)
{
var theKey
theKey = e.which
if (e.which==96) this.postmodify.mm.checked = !this.postmodify.mm.checked;
var i=document.postmodify.message.value.length - 1;
if (e.which==96) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+""+ f.value.substring(f.selectionStart); f.setSelectionRange(m,m); return false;}
if (this.postmodify.mm.checked )
{
		    if (e.which==117) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1000"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==99)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1001"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==42)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1002"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==67)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1003"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==105) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1004"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==112) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1005"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==113) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1006"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==90)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1007"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==245) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1008"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==218) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1009"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==110) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u100A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==35)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u100B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==88)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u100C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==33)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u100D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==161) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u100E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==80)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u100F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==119) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1010"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==120) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1011"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==39)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1012"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==34)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1013"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==101) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1014"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==121) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1015"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==122) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1016"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==65)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1017"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==98)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1018"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==114) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1019"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==44)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u101A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==38)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u101B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==118) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u101C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==234) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u101D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==111) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u101E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==91)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u101F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==86)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1020"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==116) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1021"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==163) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1023"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==254) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1024"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==79)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1025"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==232) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1026"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==123) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1027"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;} 
		    if (e.which==235) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1029"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==236) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u102A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==103) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u102B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==109) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u102C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==100) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u102D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==68)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u102E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==107) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u102F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==108) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1030"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==97)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1031"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==74)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1032"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==75)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1033"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==76)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1034"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==72)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1036"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==104) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1037"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==59)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1038"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==102) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1039"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==115) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u103A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==106) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u103B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==71)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u103C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==83)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u103D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==48)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1040"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==49)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1041"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==50)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1042"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==51)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1043"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==52)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1044"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==53)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1045"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==54)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1046"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==55)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1047"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==56)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1048"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==57)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1049"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==63)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u104A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==47)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u104B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==252) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u104C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==237) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u104D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==164) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u104E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==92)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u104F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==58)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u105E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==250) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1060"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==169) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1061"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==190) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1062"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==162) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1063"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==70)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1064"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==246) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1065"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==228) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1066"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==249) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1067"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==198) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1068"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==209) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1069"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==251) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u106A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==241) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u106B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==179) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u106C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==178) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u106D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==215) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u106E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==185) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u106F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==214) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1070"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==229) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1071"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==197) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1072"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==172) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1073"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==166) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1074"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==180) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1075"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==168) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1076"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==233) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1077"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==220) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1078"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==230) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1079"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==193) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==199) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==174) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==223) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==77)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==78)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==66)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1080"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==96)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1081"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==126) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1082"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==238) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1083"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==239) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1084"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==244) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1085"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==243) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1086"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==167) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1087"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==73)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1088"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==170) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1089"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==84)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u108A"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==216) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u108B"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==208) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u108C"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==248) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u108D"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==240) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u108E"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==69)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u108F"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==189) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1090"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==64)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1091"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==124) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1092"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==123) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1093"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==89)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1094"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==85)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1095"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==201) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1096"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==165) { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u1097"+f.value.substring(f.selectionStart); m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==81)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u103d\u103a"+f.value.substring(f.selectionStart); m++; m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==82)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107D\u103C"+f.value.substring(f.selectionStart); m++; m++; f.setSelectionRange(m,m); return false;}
		    if (e.which==87)  { var f=e.target; var m=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+"\u107D\u108A"+f.value.substring(f.selectionStart); m++; m++;f.setSelectionRange(m,m); return false;}
status=theKey;
}

return true;
}

function changeVal()
{
var is=new browser();
if (is.ie4up || is.opera)  {
if (event.keyCode==96) this.postmodify.mm.checked = this.postmodify.mm.checked ? false : true;
if (event.keyCode==96) event.keyCode=''; 
} else if (is.nav6up) {
	// alert("We doesn't currently support your browser");
	document.onkeypress = handleKeys;
}
if (document.postmodify.mm.checked)
{
if (is.ie4up || is.opera)  {
var theKey
theKey=event.keyCode
		    if (event.keyCode==117) event.keyCode= 4096; 
		    if (event.keyCode==99) event.keyCode= 4097; 
		    if (event.keyCode==42) event.keyCode= 4098; 
		    if (event.keyCode==67) event.keyCode= 4099; 
		    if (event.keyCode==105) event.keyCode= 4100; 
		    if (event.keyCode==112) event.keyCode= 4101; 
		    if (event.keyCode==113) event.keyCode= 4102; 
		    if (event.keyCode==90) event.keyCode= 4103; 
		    if (event.keyCode==245) event.keyCode= 4104; 
		    if (event.keyCode==218) event.keyCode= 4105; 
		    if (event.keyCode==110) event.keyCode= 4106; 
		    if (event.keyCode==35) event.keyCode= 4107; 
		    if (event.keyCode==88) event.keyCode= 4108; 
		    if (event.keyCode==33) event.keyCode= 4109; 
		    if (event.keyCode==161) event.keyCode= 4110; 
		    if (event.keyCode==80) event.keyCode= 4111; 
		    if (event.keyCode==119) event.keyCode= 4112; 
		    if (event.keyCode==120) event.keyCode= 4113; 
		    if (event.keyCode==39) event.keyCode= 4114; 
		    if (event.keyCode==34) event.keyCode= 4115; 
		    if (event.keyCode==101) event.keyCode= 4116; 
		    if (event.keyCode==121) event.keyCode= 4117; 
		    if (event.keyCode==122) event.keyCode= 4118; 
		    if (event.keyCode==65) event.keyCode= 4119; 
		    if (event.keyCode==98) event.keyCode= 4120; 
		    if (event.keyCode==114) event.keyCode= 4121; 
		    if (event.keyCode==44) event.keyCode= 4122; 
		    if (event.keyCode==38) event.keyCode= 4123; 
		    if (event.keyCode==118) event.keyCode= 4124; 
		    if (event.keyCode==234) event.keyCode= 4125; 
		    if (event.keyCode==111) event.keyCode= 4126; 
		    if (event.keyCode==91) event.keyCode= 4127; 
		    if (event.keyCode==86) event.keyCode= 4128; 
		    if (event.keyCode==116) event.keyCode= 4129; 
		    if (event.keyCode==163) event.keyCode= 4131; 
		    if (event.keyCode==254) event.keyCode= 4132; 
		    if (event.keyCode==79) event.keyCode= 4133; 
		    if (event.keyCode==232) event.keyCode= 4134;
		    if (event.keyCode==123) event.keyCode= 4135;  
		    if (event.keyCode==235) event.keyCode= 4137; 
		    if (event.keyCode==236) event.keyCode= 4138; 
		    if (event.keyCode==103) event.keyCode= 4139; 
		    if (event.keyCode==109) event.keyCode= 4140; 
		    if (event.keyCode==100) event.keyCode= 4141; 
		    if (event.keyCode==68) event.keyCode= 4142; 
		    if (event.keyCode==107) event.keyCode= 4143; 
		    if (event.keyCode==108) event.keyCode= 4144; 
		    if (event.keyCode==97) event.keyCode= 4145; 
		    if (event.keyCode==74) event.keyCode= 4146; 
		    if (event.keyCode==75) event.keyCode= 4147; 
		    if (event.keyCode==76) event.keyCode= 4148; 
		    if (event.keyCode==72) event.keyCode= 4150; 
		    if (event.keyCode==104) event.keyCode= 4151; 
		    if (event.keyCode==59) event.keyCode= 4152; 
		    if (event.keyCode==102) event.keyCode= 4153; 
		    if (event.keyCode==115) event.keyCode= 4154; 
		    if (event.keyCode==106) event.keyCode= 4155; 
		    if (event.keyCode==71) event.keyCode= 4156; 
		    if (event.keyCode==83) event.keyCode= 4157; 
		    if (event.keyCode==48) event.keyCode= 4160; 
		    if (event.keyCode==49) event.keyCode= 4161; 
		    if (event.keyCode==50) event.keyCode= 4162; 
		    if (event.keyCode==51) event.keyCode= 4163; 
		    if (event.keyCode==52) event.keyCode= 4164; 
		    if (event.keyCode==53) event.keyCode= 4165; 
		    if (event.keyCode==54) event.keyCode= 4166; 
		    if (event.keyCode==55) event.keyCode= 4167; 
		    if (event.keyCode==56) event.keyCode= 4168; 
		    if (event.keyCode==57) event.keyCode= 4169; 
		    if (event.keyCode==63) event.keyCode= 4170; 
		    if (event.keyCode==47) event.keyCode= 4171; 
		    if (event.keyCode==252) event.keyCode= 4172; 
		    if (event.keyCode==237) event.keyCode= 4173; 
		    if (event.keyCode==164) event.keyCode= 4174; 
		    if (event.keyCode==92) event.keyCode= 4175; 
		    if (event.keyCode==58) event.keyCode= 4186; 
		    if (event.keyCode==250) event.keyCode= 4192; 
		    if (event.keyCode==169) event.keyCode= 4193; 
		    if (event.keyCode==190) event.keyCode= 4194; 
		    if (event.keyCode==162) event.keyCode= 4195; 
		    if (event.keyCode==70) event.keyCode= 4196; 
		    if (event.keyCode==246) event.keyCode= 4197; 
		    if (event.keyCode==228) event.keyCode= 4198; 
		    if (event.keyCode==249) event.keyCode= 4199; 
		    if (event.keyCode==198) event.keyCode= 4200; 
		    if (event.keyCode==209) event.keyCode= 4201; 
		    if (event.keyCode==251) event.keyCode= 4202; 
		    if (event.keyCode==241) event.keyCode= 4203; 
		    if (event.keyCode==179) event.keyCode= 4204; 
		    if (event.keyCode==178) event.keyCode= 4205; 
		    if (event.keyCode==215) event.keyCode= 4206; 
		    if (event.keyCode==185) event.keyCode= 4207; 
		    if (event.keyCode==214) event.keyCode= 4208; 
		    if (event.keyCode==229) event.keyCode= 4209; 
		    if (event.keyCode==197) event.keyCode= 4210; 
		    if (event.keyCode==172) event.keyCode= 4211; 
		    if (event.keyCode==166) event.keyCode= 4212; 
		    if (event.keyCode==180) event.keyCode= 4213; 
		    if (event.keyCode==168) event.keyCode= 4214; 
		    if (event.keyCode==233) event.keyCode= 4215; 
		    if (event.keyCode==220) event.keyCode= 4216; 
		    if (event.keyCode==230) event.keyCode= 4217; 
		    if (event.keyCode==193) event.keyCode= 4218; 
		    if (event.keyCode==199) event.keyCode= 4219; 
		    if (event.keyCode==174) event.keyCode= 4220; 
		    if (event.keyCode==223) event.keyCode= 4221; 
		    if (event.keyCode==77) event.keyCode= 4222; 
		    if (event.keyCode==78) event.keyCode= 4223; 
		    if (event.keyCode==66) event.keyCode= 4224; 
		    if (event.keyCode==96) event.keyCode= 4225; 
		    if (event.keyCode==126) event.keyCode= 4226; 
		    if (event.keyCode==238) event.keyCode= 4227; 
		    if (event.keyCode==239) event.keyCode= 4228; 
		    if (event.keyCode==244) event.keyCode= 4229; 
		    if (event.keyCode==243) event.keyCode= 4230; 
		    if (event.keyCode==167) event.keyCode= 4231; 
		    if (event.keyCode==73) event.keyCode= 4232; 
		    if (event.keyCode==170) event.keyCode= 4233; 
		    if (event.keyCode==84) event.keyCode= 4234; 
		    if (event.keyCode==216) event.keyCode= 4235; 
		    if (event.keyCode==208) event.keyCode= 4236; 
		    if (event.keyCode==248) event.keyCode= 4237; 
		    if (event.keyCode==240) event.keyCode= 4238; 
		    if (event.keyCode==69) event.keyCode= 4239; 
		    if (event.keyCode==189) event.keyCode= 4240; 
		    if (event.keyCode==64) event.keyCode= 4241; 
		    if (event.keyCode==124) event.keyCode= 4242; 
		    if (event.keyCode==123) event.keyCode= 4243; 
		    if (event.keyCode==89) event.keyCode= 4244; 
		    if (event.keyCode==85) event.keyCode= 4245; 
		    if (event.keyCode==201) event.keyCode= 4246; 
		    if (event.keyCode==165) event.keyCode= 4247; 
		    if (event.keyCode==81) event.keyCode= 4154;4157;
		    if (event.keyCode==82) event.keyCode= 4221;4156; 
		    if (event.keyCode==87) event.keyCode= 4221;5234;
status = theKey;
}
else if (is.nav6up ) { 
//       document.captureEvents(Event.KEYPRESS) ;
        document.onkeypress = handleKeys;
} else {
    alert("We doesn't currently support your browser");
    document.postmodify.mm.checked=false;
  }
 }
}

//Special Thanx to Planet

keys_caps 	= new Array ('&#4096;','&#4097;','&#4098;','&#4099;','&#4100;','&#4101;','&#4102;','&#4103;','&#4104;','&#4105;','&#4106;','&#4107;','&#4108;','&#4109;','&#4110;','&#4111;','&#4112;','&#4113;','&#4114;','&#4115;','&#4116;','&#4117;','&#4118;','&#4119;','&#4120;','&#4121;','&#4122;','&#4123;','&#4240;','&#4124;','&#4125;','&#4126;','&#4230;','&#4127;','&#4128;','&#4129;','&#4175;','&#4132;','&#4133;','&#4134;','&#4135;','&#4137;','&#4138;','&#4172;','&#4173;','&#4174;','&#4241;','&#4242;');
keys_scroll = new Array ('&#4131;','&#4139;','&#4140;','&#4141;','&#4142;','&#4143;','&#4144;','&#4145;','&#4146;','&#4147;','&#4148;','&#4157;','&#4150;','&#4151;','&#4152;','&#4153;','&#4154;','&#4220;','&#4156;','&#4209;','&#4214;','&#4219;','&#4160;','&#4161;','&#4162;','&#4163;','&#4164;','&#4165;','&#4166;','&#4167;','&#4168;','&#4169;','&#4170;','&#4171;','&#4221;','&#4222;','&#4223;','&#4224;','&#4225;','&#4226;','&#4227;','&#4228;','&#4155;','&#4244;','&#4245;','&#4246;','&#4247;','&#4196;');
spc			= new Array('&#4198;','&#4199;','&#4209;','&#4210;','&#4215;','&#4246;','&#4220;','&#4132;','&#4172;','&#4216;', '&#4192;','&#4105;','&#4173;','&#4202;','&#4230;','&#4197;','&#4208;','&#4104;','&#4218;','&#4221;','&#4231;','&#4238;', '&#4236;','&#4227;','&#4228;','&#4233;','&#4237;','&#4235;','&#4213;','&#4214;','&#4217;','&#4200;','&#4211;',' &#4212;','&#4193;','&#4195;','&#4229;','&#4219;','&#4203;','&#4201;','&#4225;','&#4226;');

function letters(letter) {
	
	if(letter!='spc')
	{
		k=48;
	}
	else
	{
		k=42;
	}
	for(i = 0; i < k; i++) {
		if (letter == 'caps'){j = keys_caps[i];}
		else if (letter == 'scroll'){j = keys_scroll[i];}
		else if(letter='spc'){j = spc[i];}
		if ((i == 24) || (i == 48)){document.write('</tr><tr>');}
		document.write('<td><input style="font-family:Zawgyi-one;width:26px;size:12px" type="button" class="mainoption" style="width: 25px;" value="' + j + '" onclick="replaceText(\''+ j +'\', document.forms.postmodify.message); return false;"/></td>');
	}
}

//Show Hide Myanmar Keypad (Optional)
function showhide(targetID) {
//change target element mode
	var elementmode = document.getElementById(targetID).style;
	elementmode.display = (!elementmode.display) ? 'none' : '';
}

function changetext(changee,oldText,newText) {
		//changes text in source element
		var elementToChange = document.getElementById(changee);
}

function workforchange(targetID,sourceID,oldContent,newContent) {
		showhide(targetID);
		changetext(sourceID,oldContent,newContent);
}