function rawurlencode (str) {
    var hexStr = function (dec) {
        return '%' + (dec < 16 ? '0' : '') + dec.toString(16).toUpperCase();
    };

    var ret = '',
            unreserved = /[\w.~-]/; // A-Za-z0-9_.~-
    str = (str+'').toString();

    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters); https://developer.mozilla.org/index.php?title=en/Core_JavaScript_1.5_Referenc$
                ret += ((code - 0xD800) * 0x400) + (str.charCodeAt(i+1) - 0xDC00) + 0x10000;
                i++; // skip the next one as we just retrieved it as a low surrogate
            }
            // We never come across a low surrogate because we skip them, unless invalid
            // Reserved assumed to be in UTF-8, as in PHP
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048) { // 3 bytes (code < 65536)
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}

function updateVerwandte()
{
  if($('thread-title').getValue().length > 2)
  {
  var tt = rawurlencode($('thread-title').getValue());
  new Ajax.Updater('verwandte-themen', 'verwandte.php?tt='+tt,
  {
    method: 'get',
	onLoading: function()
	{
		$('verwandte-themen-status').update('<img src="images/ajax-loader.gif" border="0" alt="" style="display: inline;" />');
	},
	onComplete: function()
        {
                $('verwandte-themen-status').update('<img src="images/ajax-loader.gif" border="0" alt="" style="display: none;" />');
        }
  });
  }
}

function updateForen()
{
  if($('thread-title').getValue().length > 2)
  {
  var tt = rawurlencode($('thread-title').getValue());
  $('foren-status').appear({ duration: 2.0 });
  new Ajax.Updater('foren-ajax', 'foren-ajax.php?tt='+tt,
  {
    method: 'get',
        onLoading: function()
        {
                $('foren-status').update('<img src="images/ajax-loader.gif" border="0" alt="" style="display: inline;" />');
        },
	onComplete: function()
	{
		$('foren-status').update('<img src="images/ajax-loader.gif" border="0" alt="" style="display: none;" />');
	}
  });
  }
}

function updateAll()
{
	updateForen();
	updateVerwandte();
	return true;
}

function checkBoard( boardid )
{
	$('boardid-'+boardid).checked = true;
}

function $FR(formElement, radioName) 
{
	var el = formElement.getInputs('radio', radioName).find(function(radio) { return radio.checked; });
	return el;
}

function submitForm()
{
	var theform = $("bbform");
	if ($FR(theform, "boardid")==undefined) {
		alert("Wähle ein Forum für deine Frage aus.");
	}
	else
	{
		theform.submit();
	}
}
