function urlencode(string) {
	return escape(string.toString().replace(/\+/g, '%2B'));
}

function urldecode(string) {
	string = string.toString().replace(/\+/g, ' ');
	while(string.match('%2B')) {
		string = string.replace('%2B', '+');
	}
	return unescape(string);
}

function get_query(propname, string, novaluereturn) {
	if(novaluereturn === undefined) {
		var novaluereturn = false;
	}
	if(!string) {
		var string = window.location.href;
	}
	string = '&' + string.substring(string.indexOf('index.php') + 10, string.length);
	var value = novaluereturn;
	if(string.match('&' + propname + '=')) {
		value = string.split('&' + propname + '=')[1];
		if(value.match('&')) {
			value = value.split('&')[0];
		}
	}
	if(value != novaluereturn) {
		value = urldecode(value);
	}
	return value;
}

function forum_url() {
	var string = window.location.href.toString();
	if(string.match('index.php')) {
		string = string.split('index.php')[0];
	}
	if(string.charAt(string.length - 1) != '/') {
		string += '/';
	}
	return string;
}

function gethtml(string) {
	if(string.match('<') && string.match('>')) {
		if(string.split('<')[1].match('>')) {
			return '<' + string.split('<')[1].split('>')[0] + '>';
		}
	}
	return false;
}

String.prototype.toText = function() {
	var condition = true;
	var result = this;
	while(condition === true) {
		var html = gethtml(result);
		if(html === false) {
			condition = false;
		}
		else {
			result = result.replace(html, '');
		}
	}
	return result;
}

function removeprofiles() {
	var x = document.getElementsByTagName('DIV');
	for(var i = 0;i < x.length;i++) {
		if(x[i].id == 'miniprofile') {
			x[i].parentNode.removeChild(x[i].breaker);
			x[i].parentNode.removeChild(x[i]);
		}
	}
	if(this) {
		this.onclick = showprofile;
		return false;
	}
}

function showprofile() {
	var object = this;
	if(object.firstChild) {
	if(object.firstChild.tagName == 'A') {

	object.onclick = removeprofiles;
	removeprofiles();
	var username = object.firstChild.innerHTML.toText();
	var userid = get_query('MID', object.firstChild.href);
	var dock = document.createElement('DIV');
	dock.className = 'tableborder';
	dock.style.position = 'absolute';
	dock.id = 'miniprofile';
	dock.style.width = ((username.length * 10) + 150) + 'px';
	dock.innerHTML = '<table width="100%" cellspacing="1px" cellpadding="6px">\
	 <tr><td width="100%" class="pformstrip">' + username + '</td></tr>\
	 <tr><td width="100%" class="namemenu1"><a href="' + forum_url() + 'index.php?showuser=' + userid + '">View ' + username + '\'s Profile</a></td></tr>\
	 <tr><td width="100%" class="namemenu2"><a href="' + forum_url() + 'index.php?act=Msg&CODE=04&MID=' + userid + '">Send ' + username + ' a Message</a></td></tr>\
	 <tr><td width="100%" class="namemenu3"><a href="' + forum_url() + 'index.php?act=Search&CODE=getalluser&mid=' + userid + '">View All Posts by ' + username + '</a></td></tr>\
	</table>';
	dock.breaker = document.createElement('BR');
	object.parentNode.appendChild(dock.breaker);
	object.parentNode.appendChild(dock);
	return false;

	}}
}

if(get_query('showtopic') !== false) {
	var x = document.getElementsByTagName('A');
	for(var i = 0;i < x.length;i++) {
		if(get_query('MID', x[i].href) !== false && x[i].parentNode.tagName == 'SPAN') {
			x[i].parentNode.onclick = showprofile;
		}
	}
}