function encodetext(text, allowedchars, url)
{
	if (allowedchars == null)
	{
		allowedchars = new Array();
	}
	if (url == null)
	{
		url = false
	}
	
	for (var i = 0; i < allowedchars.length; i++)
	{
		allowedchars[i] = String.charCodeAt(allowedchars[i]);
	}
	
	if (allowedchars.length > 0)
	{
		// Alle Sonderzeichen ersetzen
		var newtext = '';
		for (var i = 0; i < text.length; i++) 
		{
			var charcode = text.charCodeAt(i);

			var continueflag = false;
			for (var n = 0; n < allowedchars.length; n++)
			{
				if (charcode == allowedchars[n])
				{
					continueflag = true;
				}
			}

			if (!continueflag && ((charcode >= 48 && charcode <= 57) || (charcode >= 65 && charcode <= 90) || (charcode >= 97 && charcode <= 122))) 
			{
				newtext = newtext + text.substr(i, 1);
			}
			else 
			{
				if (url)
				{
					newtext = newtext + '_charcode[' + charcode + ']_';
				}
				else
				{
					newtext = newtext + '%charcode[' + charcode + ']%';
				}
			}
		}
	}
	else
	{
		if (url)
		{
			newtext = text.replace(/[^0-9A-Za-z]/gi, function (cplstr) {
				return '_charcode[' + cplstr.charCodeAt(0) + ']_';
			});
		}
		else
		{
			newtext = text.replace(/[^0-9A-Za-z]/gi, function (cplstr) {
				return '%charcode[' + cplstr.charCodeAt(0) + ']%';
			});
		}
	}
	
	return newtext;
}

function decodetext(text, url)
{
	if (url == null)
	{
		url = false
	}
	
	if (url)
	{
		text = text.replace(/_charcode\[(.*?)\]_/gi, decodetextmatch);
	}
	else
	{
		text = text.replace(/%charcode\[(.*?)\]%/gi, decodetextmatch);
	}
	
	return text;
}

function decodetextmatch(cplstr, charcode)
{
	return String.fromCharCode(charcode);
}

function decodetext2htmlcode(text, url)
{
	if (url == null)
	{
		url = false
	}
	
	if (url)
	{
		text = text.replace(/_charcode\[(.*?)\]_/gi, '&#$1;');
	}
	else
	{
		text = text.replace(/%charcode\[(.*?)\]%/gi, '&#$1;');
	}

	return text;
}
