// Prevent the shoutbox from loading twice per page.
if (typeof(_proscripts) != "object")
	var _proscripts = new Array();

if (typeof(shoutbox) != "object")
	var shoutbox = new Array();

// Server the shoutbox is hosted on.
shoutbox["host"] = "http://shoutbox.charlesstover.com/";

// Banned users GTFO.
if (typeof(shoutbox["banned"]) == "object")
{
	for (var b = 0; b < shoutbox["banned"].length; b++)
	{
		if (shoutbox["banned"][b] == pb_username)
		{
			shoutbox["banned"] = true;
			break;
		}
	}
}
else
	shoutbox["banned"] = false;

// ProBoards only, members only, certain pages excluded, first load only
if (
	pb_username && pb_displayname && pb_username != "Guest" && !shoutbox["banned"] &&
	!document.title.match(/ \- (Activate Account|An Error Has Occurred|Search Results)/) &&
	!location.href.match(/action=(about(livechat|paidservices)|admin|attachments|avatars|ban|(board|category|membergroup)(create|delete|modify|move|reorder)\d?|censoredwords|(chat)?settings|delete(forum|oldposts|specific)|(email|pm)all|headersfooters\d?|modifyranks|newsfader|proboardsupdates|purchasecredits|recountboards|reservednames|searchmembers|skins|viewsecuritylog)$/) &&
	typeof(_proscripts["shoutbox"]) == "undefined"
)
{
	_proscripts["shoutbox"] = true;

	// Find Google Ads and move them to the proper cell
	// buggy, creates unknown error when moved
	// causes entire page to go white on some sites
	adFinder = function()
	{
		var iframes = document.getElementsByTagName("iframe"),
			foundAd = false, i;
		for (i = 0; i < iframes.length; i++)
		{
			if (iframes[i].getAttribute("name") == "google_ads_frame" && iframes[i].getAttribute("src").match(/client=ca\-pub\-5517053702045843/))
			{
				foundAd = true;
				document.getElementById("shoutboxAd").appendChild(iframes[i]);
			}
		}
		if (!foundAd)
			setTimeout("adFinder();", 500);
	};

	// move from local to global or vice versa
	changeLocale = function(localeLink)
	{

		// Get important elements
		shoutbox["cat-text"] = document.getElementById("shoutboxCatText");
		shoutbox["chatlog"] = document.getElementById("shoutboxChatlog");
		shoutbox["global-field"] = document.getElementById("shoutboxGlobalField");

		// Reset last shout
		shoutbox["last-shout"] = 0;

		// Are we in global?
		if (shoutbox["global"])
		{

			// Leave global
			shoutbox["global"] = false;
			sbSC("global", "false");

			// Update shoutbox/forms
			shoutbox["cat-text"].innerHTML = shoutbox["category-text"];
			shoutbox["chatlog"].setAttribute("href", shoutbox["host"] + "shoutbox.php?mode=chatlog&proboard=" + location.host + (shoutbox["id"] ? "&id=" + shoutbox["id"] : "") + "&key=" + shoutbox["keys"]["chatlog"]);
			shoutbox["global-field"].setAttribute("value", "false");
			document.shoutboxForm.setAttribute("action", shoutbox["host"] + "shoutbox.php");
			localeLink.innerHTML = "[Global]";
		}

		// Are we in local?
		else
		{

			// Leave local
			shoutbox["global"] = true;
			sbSC("global", "true");

			// Update shoutbox/forms
			shoutbox["cat-text"].innerHTML = "*** Rules: No Advertising, No Spamming, No Trolling ***";
			shoutbox["chatlog"].setAttribute("href", "http://proboards.gamingmedley.com/shoutbox.php?mode=chatlog&proboard=support.proboards.com");
			shoutbox["global-field"].setAttribute("value", "true");
			document.shoutboxForm.setAttribute("action", "http://proboards.gamingmedley.com/shoutbox.php");
			localeLink.innerHTML = "[Local]";
		}

		// remove all messages
		shoutbox["tbody"] = document.getElementById("shoutboxTBody");
		while (shoutbox["tbody"].firstChild)
			shoutbox["tbody"].removeChild(shoutbox["tbody"].firstChild);

		// immediate refresh
		shoutbox["timer"] = 0;
		document.getElementById("shoutboxTimer").innerHTML = "Refreshing...";
	};

	// get the style of a class
	// used for google_colors
	getStyle = function(className, attribute)
	{
		var sheets = document.styleSheets.item(0);
		var r, ruleList = (typeof(sheets.cssRules) != "undefined" ? sheets.cssRules : (typeof(sheets.rules) != "undefined" ? sheets.rules : false));
		if (ruleList)
		{
			for (r = 0; r < ruleList.length; r++)
			{
				if (ruleList.item(r).selectorText.toLowerCase() == className.toLowerCase())
					return ruleList.item(r).style[attribute];
			}
		}
		else
			return false;
	};

	htmlSpecialChars = function(text)
	{
		return text.replace(/</g, "&lt;").replace(/>/g, "&gt;");
	};

	parseShout = function(text)
	{
		text = htmlSpecialChars(text);
		for (var ps = 0; ps < shoutbox["smileys"].length; ps++)
			text = text.replace(htmlSpecialChars(shoutbox["smileys"][ps][0]), "<img alt=\"Smiley\" src=\"" + shoutbox["smileys"][ps][1] + "\" />");
		for (ps = 0; ps < shoutbox["bb-code"].length; ps++)
		{
			var param = false;
			if (typeof(shoutbox["bb-code"][ps]) == "object")
			{
				var bb = shoutbox["bb-code"][ps][0],
					begin = shoutbox["bb-code"][ps][1];
				var end = (shoutbox["bb-code"][ps][2] ? shoutbox["bb-code"][ps][2] : "<\/" + begin.split('<')[1].split(' ')[0] + '>');
				if (begin.match(/%s/) || end.match(/%s/))
					param = true;
			}
			else
			{
				var bb = shoutbox["bb-code"][ps];
				var begin = '<' + bb + '>',
					end = "<\/" + bb + '>';
			}
			var regex = new RegExp("\\[" + bb + (param ? "=(.+?)" : "") + "\\](.+?)\\[/" + bb + "\\]", "gi");
			text = text.replace(regex, begin.replace(/%s/, "$1") + (param ? "$2" : "$1") + end.replace(/%s/, "$1"));
		}
		return text;
	};

	precedingZero = function(num)
	{
		if (num < 10)
			return '0' + num;
		return num;
	};

	rgb2hex = function()
	{
		var hex = "0123456789abcdef",
			rStr = "", a;
		for (a = 0; a < arguments.length; a++)
			rStr += hex.charAt(Math.floor(arguments[a] / 16)) + hex.charAt(arguments[a] % 16);
		return rStr;
	};

	sbf = function()
	{
		for (x = 0; x < shoutbox["execute"].length; x++)
		{
			if (typeof(shoutbox["execute"][x]) == "object")
				shoutbox["execute"][x][0](shoutbox["execute"][x][1]);
			else
				shoutbox["execute"][x]();
		}
	};

	sbi = function()
	{
		shoutbox["colors-html"] = "";
		shoutbox["colspan"] = (pb_username == "admin" && shoutbox["keys"]["delete"] && shoutbox["paid"] ? 4 : 3);
		shoutbox["smileys-html"] = "";
		for (x = 0; x < shoutbox["colors"].length; x++)
			shoutbox["colors-html"] += "<option" + (sbRC("color") == x ? " selected=\"selected\"" : "") + " value=\"" + x + "\">" + (typeof(shoutbox["colors"][x]) == "object" ? shoutbox["colors"][x][0] : shoutbox["colors"][x]) + "<\/option>";
		for (x = 0; x < shoutbox["smileys"].length; x++)
			shoutbox["smileys-html"] += "<img alt=\"" + shoutbox["smileys"][x][0] + "\" onclick=\"document.getElementById('shoutboxMessage').value += ' ' + this.alt;\" src=\"" + shoutbox["smileys"][x][1] + "\" style=\"cursor : pointer;\" title=\"" + shoutbox["smileys"][x][0] + "\" /> ";
		document.getElementById("shoutboxDiv").innerHTML = "<!-- ProBoards ShoutBox (C) Charles Stover -->\n" +
			"<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" name=\"shoutboxDonate\">" +
				"<input name=\"cmd\" type=\"hidden\" value=\"_s-xclick\" />" +
				"<input name=\"hosted_button_id\" type=\"hidden\" value=\"4985072\" />" +
				"<input name=\"on0\" type=\"hidden\" value=\"ProBoards URL\" />" +
				"<input name=\"os0\" type=\"hidden\" value=\"" + location.host + "\" />" +
			"</form>" +
			"<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" name=\"shoutboxUpgrade\">" +
				"<input type=\"hidden\" name=\"cmd\" value=\"_s-xclick\" />" +
				"<input type=\"hidden\" name=\"hosted_button_id\" value=\"4235342\" />" +
				"<input name=\"on0\" type=\"hidden\" value=\"ProBoards URL\" />" +
				"<input name=\"os0\" type=\"hidden\" value=\"" + location.host + "\" />" +
			"</form>" +
			"<iframe id=\"shoutboxIFrame\" name=\"shoutboxIFrame\" style=\"display : none;\"><\/iframe>" +
			(shoutbox["head"] ? "<div style=\"text-align : center;\"><img alt=\"Header\" src=\"" + shoutbox["head"] + "\" title=\"\" /><\/div>" : "") +
			"<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"shoutbox\" width=\"92%\"><tbody><tr><td valign=\"top\" width=\"100%\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"bordercolor\" width=\"100%\"><tbody><tr><td><table border=\"0\" cellpadding=\"4\" cellspacing=\"1\" width=\"100%\">" +
				"<thead>" +
					"<tr>" +
						"<td align=\"center\" class=\"titlebg\" colspan=\"" + shoutbox["colspan"] + "\" style=\"font-weight : bold;\">" +
							"<div style=\"float : left; text-align : left; width : 30%;\">" +
								"<a href=\"" + (shoutbox["global"] ? "http://proboards.gamingmedley.com/shoutbox.php?mode=chatlog&amp;proboard=support.proboards.com" : shoutbox["host"] + "shoutbox.php?mode=chatlog&amp;proboard=" + encodeURIComponent(location.host) + (shoutbox["id"] ? "&amp;id=" + shoutbox["id"] : "") + "&amp;key=" + encodeURIComponent(shoutbox["keys"]["chatlog"])) + "\" id=\"shoutboxChatlog\">[ChatLog]<\/a>" +
								(shoutbox["disable-global"] ? "" : " <a href=\"javascript:void(0);\" id=\"shoutboxLocale\" onclick=\"changeLocale(this);\">[" + (shoutbox["global"] ? "Local" : "Global") + "]<\/a>") +
							"<\/div>" +
							"<div style=\"float : right; text-align : right; width : 30%;\">" +
								(shoutbox["paid"] ? "" : "<a href=\"javascript:void(0);\" onclick=\"document.shoutboxDonate.submit(true);\">[Donate]<\/a> <a href=\"" + shoutbox["host"] + "shoutbox.php?mode=upgrade&amp;proboard=" + encodeURIComponent(location.host) + "\" target=\"_blank\">[Upgrade]<\/a> ") +
								"<a href=\"http://servicesupport.proboards85.com/index.cgi?board=pbsbs\">[Support]<\/a>" +
							"<\/div>" +
							"<font class=\"titletext\" size=\"-1\">" + document.title.split(" - ")[0] + "<\/font>" +
						"<\/td>" +
					"<\/tr>" +
					"<tr>" +
						"<td align=\"center\" class=\"catbg\" colspan=\"" + shoutbox["colspan"] + "\" height=\"18\">" +
							"<font class=\"cattext\" size=\"1\" style=\"font-weight : bold;\">" +
								(shoutbox["paid"] ? "" : "<div style=\"float : left; text-align : left; width : 25%;\"><a href=\"http://proboards.gamingmedley.com/codes/proboards-shoutbox.html\">Get Your Own Free ShoutBox!<\/a><\/div><div style=\"float : right; text-align : right; width : 25%;\"><a href=\"http://servicesupport.proboards85.com/index.cgi?action=viewprofile&user=admin\">&copy; Charles Stover<\/a><\/div>") +
								"<span id=\"shoutboxCatText\">" + (shoutbox["global"] ? "*** Rules: No Advertising, No Spamming, No Trolling ***" : shoutbox["category-text"]) + "<\/span>" +
							"<\/font>" +
						"<\/td>" +
					"<\/tr>" +
				"<\/thead>" +
				"<tfoot>" +
					"<tr>" +
						"<td align=\"center\" class=\"windowbg2\" colspan=\"" + shoutbox["colspan"] + "\" height=\"18\" id=\"shoutboxTimer\" style=\"font-weight : bold;\">Refreshing...<\/td>" +
					"<\/tr>" +
					"<tr>" +
						"<td align=\"center\" class=\"catbg\" colspan=\"" + shoutbox["colspan"] + "\" height=\"18\" id=\"shoutboxPost\" style=\"font-weight : bold;\" valign=\"middle\">" +
							"<img alt=\"Smileys\" onclick=\"toggleSmileys(this);\" src=\"http://s1.images.proboards.com/" + (shoutbox["smileys-expanded"] ? "cheesy" : "smiley") + ".gif\" style=\"cursor : pointer; float : left; margin-left : 6pt;\" title=\"" + (shoutbox["smileys-expanded"] ? "Hide" : "Show") + " Smileys\" />" +
							"<form action=\"" + (shoutbox["global"] ? "http://proboards.gamingmedley.com/" : shoutbox["host"]) + "shoutbox.php\" encoding=\"multipart/form-data\" enctype=\"multipart/form-data\" id=\"shoutboxForm\" method=\"post\" name=\"shoutboxForm\" onsubmit=\"shoutboxFormSubmit(this);\" style=\"margin : 0;\" target=\"shoutboxIFrame\">" +
								"<input name=\"displayname\" type=\"hidden\" value=\"" + pb_displayname + "\" />" +
								(shoutbox["id"] ? "<input name=\"id\" type=\"hidden\" value=\"" + shoutbox["id"] + "\" />" : "") +
								"<input name=\"proboard\" type=\"hidden\" value=\"" + location.host + "\" />" +
								"<input name=\"username\" type=\"hidden\" value=\"" + pb_username + "\" />" +
								"<input id=\"shoutboxGlobalField\" name=\"global\" type=\"hidden\" value=\"" + (shoutbox["global"] ? "true" : "false") + "\" />" +
								"<select name=\"shoutboxColor\" onchange=\"sbSC(\'color\', this.options[this.selectedIndex].value);\" style=\"font-weight : normal;\">" +
									"<option value=\"NULL\">Color<\/option>" +
									shoutbox["colors-html"] +
								"<\/select>\n" +
								"<input id=\"shoutboxMessage\" maxlength=\"255\" name=\"shoutboxMessage\" onblur=\"shoutbox['refresh-paused'] = true;\" onfocus=\"shoutbox['refresh-paused'] = false;\" style=\"width : 33%;\" type=\"text\" />\n" +
								"<input type=\"submit\" value=\"Shout!\" />" +
							"<\/form>" +
							"<div id=\"shoutboxPosting\" style=\"display : none; font-weight : bold;\">Posting...<\/div>" +
						"<\/td>" +
					"<\/tr>" +
					"<tr id=\"shoutboxSmileys\"" + (shoutbox["smileys-expanded"] ? "" : " style=\"display : none;\"") + '>' +
						"<td align=\"center\" class=\"windowbg\" colspan=\"" + shoutbox["colspan"] + "\">" +
							shoutbox["smileys-html"] +
						"<\/td>" +
					"<\/tr>" +
				"<\/tfoot>" +
				"<tbody id=\"shoutboxTBody\"><\/tbody>" +
			"<\/table><\/td><\/tr><\/tbody><\/table><\/td><\/tr><\/tbody><\/table>" +
			(shoutbox["foot"] ? "<div style=\"text-align : center;\"><img alt=\"Footer\" src=\"" + shoutbox["foot"] + "\" title=\"\" /><\/div>" : "");
		setTimeout("sbr();", 333);
	};

	sbp = function(username, displayname, message, timestamp, color, website)
	{

		// If it's not a message by you, update the latest timestamp
		if (typeof(timestamp) != "undefined" && timestamp)
			shoutbox["last-shout"] = timestamp;

		// convert timestamp to Date()
		var datetime = (typeof(timestamp) == "undefined" || !timestamp ? new Date() : new Date(timestamp * 1000));
		var ampm = "am",
			hours = datetime.getHours();
		if (hours > 11)
		{
			ampm = "pm";
			if (hours > 12)
				hours -= 12;
		}
		if (!hours)
			hours = 12;

		// timestamp variables
		var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"),
			months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		// days[timestamp.getDay()]

		// necessary elements
		shoutbox["post"] = document.createElement("tr");
		shoutbox["timestamp"] = sbQCE(
			"td", "align=left, class=windowbg, title=" + datetime.getDate() + ' ' + months[datetime.getMonth()] + ' ' + datetime.getFullYear() + ", vAlign=middle, width=1%",
			precedingZero(hours) + ':' + precedingZero(datetime.getMinutes()) + ':' + precedingZero(datetime.getSeconds()) + ampm
		);

		// Advertisement
		if (username.substring(0, 1) == "_")
		{

			// One advertisement only
			if (document.getElementById("shoutboxAdvertisement"))
				return false;

			// Google Ads
			if (username == '_')
			{

				// advertisement colors
				var google_colors = new Array(

					// google_color_link, google_color_url
					getStyle("a:link", "color"),

					// google_color_bg, google_color_border
					getStyle(".windowbg2", "backgroundColor"),

					// google_color_text
					getStyle(".windowbg2", "color")

				);

				// verify advertisement colors
				for (var gc = 0; gc < google_colors.length; gc++)
				{

					// If undefined, use default.
					if (typeof(google_colors[gc]) == "undefined")
						google_colors[gc] = "";

					// If rgb(), convert to hexidecimal
					else if (temp = google_colors[gc].match(/^rgb\((\d{1,3}),\s?(\d{1,3}),\s?(\d{1,3})\)/))
						google_colors[gc] = rgb2hex(temp[1], temp[2], temp[3]);

					// Convert #ABCDEF to ABCDEF
					else if (google_colors[gc].match(/^#/))
						google_colors[gc] = google_colors[gc].substring(1, google_colors[gc].length);

				}

				// 468x15: google_ad_slot = \"2420148162\", google_ad_width = 468
				// 728x15: google_ad_slot = \"5205561578\", google_ad_width = 728
				shoutbox["message"] = sbQCE(
					"td", "align=left, class=windowbg2, colSpan=2, id=shoutboxAdvertisement"
				);
				shoutbox["message"].innerHTML = "<script type=\"text/javascript\">//<![CDATA[\n" +
					"var google_ad_client = \"pub-5517053702045843\", " +
						"google_ad_height = 15, " +
						"google_ad_slot = \"5205561578\", " +
						"google_ad_width = 728, " +
						"google_color_bg = \"" + google_colors[1] + "\", " +
						"google_color_border = \"" + google_colors[1] + "\", " +
						"google_color_link = \"" + google_colors[0] + "\", " +
						"google_color_text = \"" + google_colors[2] + "\", " +
						"google_color_url = \"" + google_colors[0] + "\";" +
					"\n//]]><\/script>\n" +
					"<script src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\" type=\"text/javascript\"><\/script>";

				// advertisement
				shoutbox["post"].appendChild(shoutbox["message"]);

				// Move the ad to the ad cell
				// Because Google sucks. :(
				adFinder();

			}

			// Custom Ad
			else 
			{

				// "Advertisement:" cell
				shoutbox["post"].appendChild(
					sbQCE("td", "align=left, class=windowbg, vAlign=middle, width=1%",
						sbQCE('b', false,
							"Advertisement:"
						)
					)
				);

				// advertisement link and description
				shoutbox["message"] = sbQCE(
					"td", "align=left, class=windowbg2, id=shoutboxAdvertisement",
					sbQCE(
						"a", "href=http://proboards.gamingmedley.com/advertisement.php?code=" + username.substring(1, username.length) + "&referer=" + encodeURIComponent(document.title.split(" - ")[0]) + "&refererUrl=" + location.host,
						displayname
					)
				);
				shoutbox["message"].innerHTML += " - " + parseShout(message);
				shoutbox["post"].appendChild(shoutbox["message"]);

			}

			// timestamp, without delete key
			if (pb_username == "admin" && shoutbox["paid"])
				shoutbox["timestamp"].setAttribute("colSpan", '2');
			shoutbox["post"].appendChild(shoutbox["timestamp"]);

			document.getElementById("shoutbox").getElementsByTagName("thead")[0].appendChild(shoutbox["post"]);

		}

		// Not an advertisement!
		else
		{

			// post <tbody>
			shoutbox["tbody"] = document.getElementById("shoutboxTBody");

			// get rid of the bad words
			if (typeof(shoutbox["censors"]) == "object")
			{
				for (x = 0; x < shoutbox["censors"].length; x++)
				{
					while (message.match(shoutbox["censors"][x][0]))
						message = message.replace(shoutbox["censors"][x][0], shoutbox["censors"][x][1]);
				}
			}

			// Is it a /me command?
			shoutbox["me"] = (message.substring(0, 4) == "/me " ? true : false);

			// the message cell
			shoutbox["message"] = sbQCE(
				"td", "align=left, class=windowbg2, " + (shoutbox["me"] ? "colSpan=2, " : "") + "vAlign=middle"
			);

			// Color the message!
			if (typeof(color) != "undefined" && color != -1 && color != null && shoutbox["colors"][color])
				shoutbox["message"].style.color = (typeof(shoutbox["colors"][color]) == "object" ? shoutbox["colors"][color][1] : shoutbox["colors"][color]);

			// Profile link
			shoutbox["profile-link"] = sbQCE("a", "class=" + username + ", href=" + (typeof(website) != "undefined" ? "http://" + website + ".proboards.com" : "") + "/index.cgi?action=viewprofile&user=" + username);
			if (typeof(shoutbox["avatars"][username]) == "string" && !shoutbox["me"])
				shoutbox["profile-link"].appendChild(sbQCE("img", "alt=" + username + ", border=0, src=" + shoutbox["avatars"][username]));
			else
				shoutbox["profile-link"].innerHTML = htmlSpecialChars(displayname).replace(/^Charles\s*?Stover$/, "Charles") + (shoutbox["me"] ? "" : ':');
			shoutbox["profile-link"].style.fontWeight = "bold";

			// stylize the /me command
			if (shoutbox["me"])
			{
				shoutbox["message"].style.fontStyle = "italic";
				shoutbox["message"].appendChild(shoutbox["profile-link"]);
				shoutbox["message"].innerHTML += ' ' + parseShout(message.substring(4, message.length));
			}

			else
			{

				// username/displayname cell
				shoutbox["user"] = sbQCE("td", "align=left, class=" + username + " windowbg, vAlign=middle, width=1%");
				shoutbox["user"].style.whiteSpace = "nowrap";

				// star for global, prevent imposters
				// Green: YBgdfO; Red: K82rey
				if (typeof(website) == "string" && website == "servicesupport" && username == "admin")
					shoutbox["user"].appendChild(sbQCE("img", "alt=* , src=http://imgur.com/jHEQg.gif, title=Administrator"));
				
				// user appends the link, post appends the user, ready the message
				shoutbox["user"].appendChild(shoutbox["profile-link"]);
				shoutbox["post"].appendChild(shoutbox["user"]);
				shoutbox["message"].innerHTML = parseShout(message);

			}

			// add the message and timestamp to the post
			shoutbox["post"].appendChild(shoutbox["message"]);
			shoutbox["post"].appendChild(shoutbox["timestamp"]);

			// If you have the power to delete messages...
			// timestamp unknown for self-posted messages
			// no server interaction for sbp()
			if (pb_username == "admin" && !shoutbox["global"] && shoutbox["keys"]["delete"] && shoutbox["paid"])
			{

				// set up the form
				shoutbox["delete-form"] = sbQCE(
					"form", "action=" + shoutbox["host"] + "shoutbox.php?mode=delete, encoding=multipart/form-data, enctype=multipart/form-data, method=post, target=shoutboxIFrame",
					sbQCE("input", "name=proboard, type=hidden, value=" + location.host),
					sbQCE("input", "name=username, type=hidden, value=" + username),
					sbQCE("input", "name=timestamp, type=hidden, value=" + timestamp),
					sbQCE("input", "name=key, type=hidden, value=" + shoutbox["keys"]["delete"])
				);
				if (shoutbox["id"])
					shoutbox["delete-form"].appendChild(sbQCE("input", "name=id, type=hidden, value=" + shoutbox["id"]));
				shoutbox["delete-form"].style.margin = "0";
				shoutbox["delete-form"].style.padding = "0";

				// set up the image
				shoutbox["delete-image"] = sbQCE("img", "alt=X, border=0, src=http://imgur.com/gBg0D.gif");
				shoutbox["delete-image"].style.cursor = "pointer";
				shoutbox["delete-image"].onclick = function()
				{
					this.parentNode.submit();
					this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);
				}

				// add the delete form to the post
				shoutbox["delete-form"].appendChild(shoutbox["delete-image"]);
				shoutbox["post"].appendChild(
					sbQCE(
						"td", "align=center, class=windowbg, vAlign=middle, width=1%",
						shoutbox["delete-form"]
					)
				);
			}

			// If there are previous messages, append to top.
			if (shoutbox["tbody"].firstChild)
				shoutbox["tbody"].insertBefore(shoutbox["post"], shoutbox["tbody"].firstChild);

			// Otherwise, create the first message.
			else
				shoutbox["tbody"].appendChild(shoutbox["post"]);

			// If there are too many messages, remove the last one.
			if (shoutbox["tbody"].childNodes.length >= shoutbox["messages"] + 1)
				shoutbox["tbody"].removeChild(shoutbox["tbody"].lastChild);

		}
	};

	// quickCreateElement
	sbQCE = function(name, attr)
	{
		var temp = document.createElement(name);
		if (attr)
		{
			attr = attr.split(", ");
			for (var qce = 0; qce < attr.length; qce++)
			{
				attr[qce] = attr[qce].split('=');
				attr[qce] = new Array(attr[qce].shift(), attr[qce].join('='));
				if (attr[qce][0] == "innerHTML")
					temp.innerHTML = attr[qce][1];
				else
				{
					temp.setAttribute(attr[qce][0], attr[qce][1]);
					if (attr[qce][0] == "class")
						temp.setAttribute("className", attr[qce][1]);
				}
			}
		}
		if (arguments[2])
		{
			for (var qce = 2; qce < arguments.length; qce++)
			{
				if (arguments[qce])
					temp.appendChild(typeof(arguments[qce]) != "object" ? document.createTextNode(arguments[qce]) : arguments[qce]);
			}
		}
		return temp;
	};

	// readCookie
	sbRC = function(name)
	{
		var cookies = document.cookie.split(';');
		name = "shoutbox-" + name + '=';
		for (var rc = 0; rc < cookies.length; rc++)
		{
			var c = cookies[rc];
			while (c.charAt(0) == ' ')
				c = c.substring(1, c.length);
			if (c.indexOf(name) == 0)
				return c.substring(name.length, c.length);
		}
		return null;
	};

	// setCookie
	sbSC = function(name, value)
	{
		if (value != null)
		{
			temp = new Date();
			temp.setTime(temp.getTime() + 31536000000);
			document.cookie = "shoutbox-" + name + '=' + value + "; expires=" + temp.toGMTString() + "; path=/";
		}
	};

	sbr = function()
	{
		shoutbox["timer-cell"] = document.getElementById("shoutboxTimer");

		// decrement counter
		if (shoutbox["timer"])
		{
			shoutbox["timer-cell"].parentNode.style.display = "";
			shoutbox["timer-cell"].innerHTML = (shoutbox["refresh-paused"] ? "Refresh paused." : "Refreshing in " + shoutbox["timer"] + "...");
			if (shoutbox["timer"] > 0)
				shoutbox["timer"]--;
			setTimeout("sbr();", 1000);
		}

		// timer has reached 0
		else
		{

			// Refreshable?
			if (shoutbox["global"] || !shoutbox["last-shout"] || !shoutbox["loaded"] || shoutbox["paid"])
			{

				// It's paused; wait for unpause
				if (shoutbox["refresh-paused"] && shoutbox["last-shout"])
				{

					// In case locale changes, remove "Refreshing..."
					shoutbox["timer-cell"].innerHTML = "Refresh paused.";
					setTimeout("sbr();", 1000);
				}

				// If refresh isn't paused...
				else
				{
					var header = document.getElementById("shoutboxDiv");
					shoutbox["timer-cell"].parentNode.style.display = "";
					shoutbox["timer-cell"].innerHTML = "Refreshing..."
					if (shoutbox["refresh"] = document.getElementById("shoutboxRefresh"))
						header.removeChild(shoutbox["refresh"]);
					shoutbox["src"] = (shoutbox["global"] ? "http://proboards.gamingmedley.com/" : shoutbox["host"]) +
						"shoutbox.php" +
						"?mode=" + (shoutbox["last-shout"] > 0 ? "refresh&since=" + shoutbox["last-shout"] : "shoutbox") +
						"&messages=" + shoutbox["messages"] +
						"&proboard=" + location.host +
						"&user=" + pb_username +
						(shoutbox["global"] ? "&global=true" : "") +
						(shoutbox["id"] ? "&id=" + shoutbox["id"] : "") +
						(typeof(shoutbox["execute"]) == "object" && !shoutbox["loaded"] ? "&sbf=true" : "");
					header.appendChild(sbQCE("script", "id=shoutboxRefresh, src=" + shoutbox["src"] + ", type=text/javascript"));
					shoutbox["loaded"] = true;
					if ((shoutbox["global"] || shoutbox["paid"]) && !shoutbox["refresh-paused"])
						shoutbox["timer"] = (shoutbox["refresh-time"] ? shoutbox["refresh-time"] : 10);
					setTimeout("sbr();", 2500);
				}
			}

			// not in global, not paid = no refresh
			// wait for global
			else
			{
				shoutbox["timer-cell"].parentNode.style.display = "none";
				setTimeout("sbr();", 1000);
			}
		}
	};

	shoutboxFormSubmit = function(form)
	{
		form.style.display = "none";
		document.getElementById("shoutboxPosting").style.display = "block";
		setTimeout("document.shoutboxForm.shoutboxMessage.value = \"\"; document.shoutboxForm.style.display = \"block\"; document.getElementById(\"shoutboxPosting\").style.display = \"none\"; document.shoutboxForm.shoutboxMessage.focus();", 1000);
		sbp(pb_username, pb_displayname, form.shoutboxMessage.value, false, sbRC("color"));
	};

	toggleSmileys = function(smiley)
	{
		var smileyTitle = smiley.getAttribute("title").match(/^\w/);
		smiley.setAttribute("src", "http://s1.images.proboards.com/" + (smileyTitle == 'S' ? "cheesy" : "smiley") + ".gif");
		smiley.setAttribute("title", (smileyTitle == 'S' ? "Hide" : "Show") + " Smileys");
		document.getElementById("shoutboxSmileys").style.display = (smileyTitle == 'S' ? "" : "none");
		sbSC("smileys-expanded", (smileyTitle == 'S' ? "true" : "false"));
	};

	// Crucial variables
	var temp, x;
	if (typeof(shoutbox["avatars"]) != "object")
		shoutbox["avatars"] = new Array();
	if (typeof(shoutbox["bb-code"]) != "object")
	{
		shoutbox["bb-code"] = new Array(
			new Array("font", "<span style=\"font-family : '%s', 'Verdana', 'Arial', sans-serif;\">"),
			new Array("link", "<a href=\"%s\" target=\"_self\">"),
			new Array("url", "<a href=\"%s\" target=\"_blank\">"),
			'b', 'i', 's', "sub", "sup", "tt", 'u'
		);
	}
	if (typeof(shoutbox["category-text"]) == "undefined")
		shoutbox["category-text"] = "The ShoutBox";
	if (typeof(shoutbox["colors"]) != "object")
	{
		shoutbox["colors"] = new Array(
			"Black", "Red", "Yellow", "Pink", "Green", "Orange", "Purple", "Blue", "Beige", "Brown", "Teal", "Navy", "Maroon",
			new Array("Lime Green", "LimeGreen")
		);
	}
	shoutbox["disable-global"] = (sbRC("disable-global") == "true" ? true : (typeof(shoutbox["disable-global"]) == "undefined" ? false : shoutbox["disable-global"]));
	if (typeof(shoutbox["foot"]) != "string")
		shoutbox["foot"] = false;
	shoutbox["global"] = (sbRC("global") == "true" && !shoutbox["disable-global"] ? true : false);
	if (typeof(shoutbox["head"]) != "string")
		shoutbox["head"] = false;
	if (typeof(shoutbox["id"]) == "undefined")
		shoutbox["id"] = false;
	shoutbox["keys"] = new Array();
	shoutbox["keys"]["chatlog"] = 'x';
	shoutbox["keys"]["delete"] = false;
	shoutbox["last-shout"] = 0;
	shoutbox["loaded"] = false;
	if (typeof(shoutbox["messages"]) == "undefined" || shoutbox["messages"] > 9)
		shoutbox["messages"] = 9;
	shoutbox["paid"] = false;
	shoutbox["refresh-paused"] = true;
	shoutbox["refresh-time"] = 10;
	if (typeof(shoutbox["smileys"]) != "object")
	{
		shoutbox["smileys"] = [
			["::)", "rolleyes"],	[":)", "smiley"],		[";)", "wink"],		[":D", "cheesy"],
			[";D", "grin"],			[">:(", "angry"],		[":(", "sad"],		[":o", "shocked"],
			["8-)", "cool"],		["???", "huh"],			[":P", "tongue"],	[":-[", "embarassed"],
			[":-X", "lipsrsealed"],	[":-/", "undecided"],	[":-*", "kiss"],	[":'(", "cry"]
		];
		for (x = 0; x < shoutbox["smileys"].length; x++)
			shoutbox["smileys"][x][1] = "http://s1.images.proboards.com/" + shoutbox["smileys"][x][1] + ".gif";
	}
	shoutbox["smileys-expanded"] = (sbRC("smileys-expanded") == "true" ? true : false);
	shoutbox["tbody"] = false;
	shoutbox["timer"] = 0;

	// Load it up!
	document.write("<div id=\"shoutboxDiv\"><\/div>");
	document.getElementsByTagName("head").item(0).appendChild(sbQCE("script", "src=" + shoutbox["host"] + "shoutbox.php?mode=init&proboard=" + location.host + "&user=" + pb_username + ", type=text/javascript"));
}