//-----------------------------------------
//              ShoutOut!
//        www.invisionmint.com
//       Copyright © 2007 - 2008
//-----------------------------------------

function shoutout()
{
	this.inited = false;
	this.sid_editting = null;
	this.sid_text = null;
	this.in_refresh = false;
	this.in_idle = false;
	this.activated = true;
	this.clickmiss = null;
	this.refreshing = false;
	this.e_g_shouts = null;
	this.textarea_cols = null;
	this.textarea_rows = null;
	this.in_history = false;
	this.color_but_text = "Color";
	this.color = "";
	this.timeoutobj = null;
	this.sorting = "newtoold";
	this.idlemode = 1;
	this.lang = Array();
	this.cmd = null;
	this.privto = null;
	this.param = null;
	this.usefont = "";
	this.previous_ehtml="";
}

/* ================================
// Init the Shoutbox Functions
=================================*/
shoutout.prototype.init = function()
{
	// Check if we can use AJAX/Enhanced Javascript
	if(!use_enhanced_js)
	{
		my_getbyid('total_shoutbox').style.display = 'none';
		shoutout.inited = false;
		shoutout.debug("use_enhanced_js = false; Shutting Down Shoutbox.");
		return;
	}
	
	// ShoutOut is Inited
	shoutout.inited = true;
	shoutout.debug("Shoutbox Initiated");
	
	//Sets default Color Text to a Variable For Langification
	if(my_getbyid('sb_colorselector'))
	{
		colorselector = my_getbyid('sb_colorselector');
		shoutout.color_but_text = colorselector.value;
	}
	
	//ShoutOut Commands, More come v3
	shoutout.cmd = new shoutout.commands();
	
	//Clear the Input Field
	shoutout.cleartext(1);

	//Set the color on page load.
	var def_color = my_getcookie("shoutbox_color");
	if(def_color && def_color != "")
	{
		colorchanger = my_getbyid('sb_colortochangeto');
		colorchanger.value = shoutout.color_but_text + ": "+def_color;
		colorchanger.style.color = def_color;
		shoutout.color = def_color;
		shoutout.debug("shoutout.color = "+def_color);
		my_getbyid('new-shout').style.color = def_color;
	}
	
	//Set the font on page load
	var def_font = my_getcookie("shoutbox_font");
	if(def_font && def_font != "")
	{
		my_getbyid('new-shout').style.fontFamily = def_font;
		my_getbyid('sb_font').style.fontFamily = def_font;
		shoutout.usefont = def_font;

		e = my_getbyid('sb_font');
		for(var i=0;i<e.length;i++){
		
			if(e[i].value == def_font)
			{
				e.selectedIndex = i;
			}
			
		}		
	}
	
	// Check Activation
	if(my_getbyid('fo_shoutbox'))
	{
		if(my_getbyid('fo_shoutbox').style.display == 'none')
		{
			shoutout.activated = false;
		}
	}
	
	if(shoutout.activated)
	{
	
		// Scroll to Bottom if issues.
		if(shoutout.sorting == "oldtonew")
		{
			shoutout.scrollBottom();
		}
	
	}
	
	
	var detachable = my_getcookie("shoutbox_detach");
	if(detachable)
	{
		shoutout.changetach();
	}
	
		
}


shoutout.prototype.changetach = function()
{
	shoutbox = my_getbyid('total_shoutbox');
	
	if(shoutbox.className != 'detached')
	{
		Drag.init(my_getbyid("shoutoutdrag"),shoutbox);
		shoutbox.style.position = "absolute";
		shoutbox.style.zIndex = "100";
		Drag.cookiename='shoutoutdiv';
		shoutbox.style.width='900px';
		shoutbox.className  = 'detached';
		
		my_setcookie('shoutbox_detach', 1);
	}
	else
	{
		my_getbyid("shoutoutdrag").style.cursor = "default";
		shoutbox.style.position = "static";
		shoutbox.style.zIndex = "100";
		shoutbox.style.width='auto';
		shoutbox.className  = 'attached';
		shoutbox.onclick=null;
		document.onclick=null;
		document.mousemove=null;
		my_getbyid("shoutoutdrag").onmouseover=null;
		my_setcookie('shoutbox_detach', '');
	}
}


shoutout.prototype.clearcookies = function()
{
	my_setcookie("shoutbox_color", '');
	my_setcookie("shoutbox_font", '');
	my_setcookie("shoutbox_size", '');
}

/* ================================
// Activates the Shoutbox
=================================*/
shoutout.prototype.activate = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	togglecategory('shoutbox', 0);
	shoutout.activated = true;
	shoutout.debug("shoutout.activated = true;");
	
}


/* ================================
// Deactivates the Shoutbox
=================================*/
shoutout.prototype.deactivate = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	togglecategory('shoutbox', 1);
	shoutout.activated = false;
	shoutout.debug("shoutout.activated = false;");
}

/* ================================
// Clears the Input Field
=================================*/
shoutout.prototype.cleartext = function(focus)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	if(!my_getbyid('new-shout'))
	{
		return;
	}
	
	var textarea = my_getbyid('new-shout');
	textarea.value = "";
	
	if(!focus)
	{
		textarea.focus();
	}
	shoutout.debug("Shoutbox text cleared.");
}

/* ================================
// Add str to the Input Field
=================================*/
shoutout.prototype.addtotext = function(str, menuclose)
{
	shoutout.debug("shoutout.addtotext();");
	if(!shoutout.inited)
	{
		return;
	}
	
	
	if(menuclose)
	{
		ipsmenu.close();
	}
	shoutout.debug("shoutout.addtotext(); -> ipsmenu.close();");
	
	var textarea = my_getbyid('new-shout');
	
	
	if(typeof str == "string" && str.substring(0, 5) == "eval.")
	{
		shoutout.debug("str.substring(0,5)='eval.'");
		eval(str.substring(5));
		shoutout.debug("eval('"+str.substring(5)+"')");
	}
	else
	{
		textarea.value += str;
	}

}

/* ================================
// Scrolls the ShoutBox to the Bottom
=================================*/
shoutout.prototype.scrollBottom = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	div = my_getbyid('global-shouts-parentNode');
	if(!div)
	{
		alert('div die');
	}
	div.scrollTop = div.scrollHeight;

	shoutout.debug("Scrolled to Bottom");
}



/* ================================
// Sets the FONT!
=================================*/
shoutout.prototype.font = function(obj)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	font = obj.options[obj.selectedIndex].value;
	shoutout.debug("shoutout.font("+font+");");
	
	if(font == '-1')
	{
		font = "";
	}
	
	my_getbyid('new-shout').style.fontFamily = font;
	my_getbyid('sb_font').style.fontFamily = font;
	
	my_setcookie("shoutbox_font", font, 1);
	shoutout.usefont = font;
	shoutout.debug("new-shout.fontFamily = "+font);
}





/* ================================
// This asks who to PM to.
=================================*/
shoutout.prototype.towhotopm = function()
{
	shoutout.debug("shoutout.towhotopm();");
	if(!shoutout.inited)
	{
		return;
	}
	
	
	shoutout.privto = prompt(shoutout.lang['whotosendto'], "");
	
	shoutout.debug("shoutout.towhotopm(); -> shoutout.privto=;");
	
	if(shoutout.privto == "" || shoutout.privto == null)
	{
		return;
	}
	shoutout.cleartext();
	shoutout.addtotext("/pm {"+shoutout.privto+ "} ");
	alert(shoutout.lang['thanksnowentermsg']);
	my_getbyid('new-shout').focus();
}


/* ================================
// Creates Textarea to Edit Shout
=================================*/
shoutout.prototype.edit = function(id)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	var fields = Array();
	var msg = my_getbyid('the-shout-'+id);
	
	shoutout.previous_ehtml = msg.innerHTML;
	msg.innerHTML = '';
	var textarea = document.createElement('textarea');
	textarea.cols = shoutout.textarea_cols;
	textarea.row = shoutout.textarea_rows;
	textarea.id = "edit-Shout";
	msg.appendChild(textarea);
	textarea.innerHTML = my_getbyid('raw-shout-'+id).innerHTML;
	
	
	var submit = document.createElement('input');
	submit.type = "button";
	submit.value = shoutout.lang['saveshout'];
	msg.appendChild(submit);
	submit.onclick = shoutout.save;
	
	
	var cancel = document.createElement('input');
	cancel.type = "button";
	cancel.value = shoutout.lang['cancel'];
	msg.appendChild(cancel);
	cancel.onclick = shoutout.cancel_edit;
	
	shoutout.sid_editting = id;
	shoutout.sid_text = textarea.innerHTML;
	
	shoutout.debug("Edit Textarea created.");
}

shoutout.prototype.cancel_edit = function()
{
	var fields = Array();
	var textarea = my_getbyid('edit-Shout');
	var msg = my_getbyid('the-shout-'+shoutout.sid_editting);
	textarea.style.display = 'none';
	msg.innerHTML = shoutout.previous_ehtml;
}


/* ================================
// Updates Editted Shout
=================================*/
shoutout.prototype.save = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	

	shoutout.debug("shoutout.save();");
	var fields = Array();
	var textarea = my_getbyid('edit-Shout');
	var msg = my_getbyid('the-shout-'+shoutout.sid_editting);
	
	if(textarea.value == shoutout.sid_text)
	{
		return;
	}
	
	my_getbyid('raw-shout-'+shoutout.sid_editting).innerHTML = textarea.value;
	fields['message'] = textarea.value;
	fields['id'] = shoutout.sid_editting;
	textarea.style.display = 'none';
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			
			if(html.substring(0, 5) == 'ERROR') {
				eval(html.substring(6));
			} else {
				msg.innerHTML = html; 
				if(my_getbyid('shoutId-'+shoutout.sid_editting))
				{
					gmsg = my_getbyid('shoutId-'+shoutout.sid_editting);
					gmsg.innerHTML = html;
				}
			}
			
			html = '';
		
		}

	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=editshout&id='+shoutout.sid_editting;
	
	xmlobj.process(u, 'POST', xmlobj.format_for_post(fields));
}


/* ================================
// Delete Shout
=================================*/
shoutout.prototype.deleteshout = function(id)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.debug("shoutout.deleteshout();");
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			if(my_getbyid('history-row-'+id)) {
				var row = my_getbyid('history-row-'+id);
				row.parentNode.removeChild(row);
			}
			
			if(my_getbyid('shout-row-'+id)) {
				var row = my_getbyid('shout-row-'+id);
				row.parentNode.removeChild(row);
			}
			
			html = '';
		}

	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=deleteshout&id='+id;
	
	xmlobj.process(u, 'GET');
}

/* ================================
// Refresh Animation
=================================*/
shoutout.prototype.refresh_ani = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	toggleview('refresh_button');
	shoutout.refreshing = !shoutout.refreshing;
}


/* ================================
// Resize the Shoutbox + or -
=================================*/
shoutout.prototype.resize = function(add)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	height = parseInt(my_getbyid('global-shouts').parentNode.style.height) ? parseInt(my_getbyid('global-shouts').parentNode.style.height ) : 100;
	
	if(add == "1") {
		// Increase
		nheight = height + 20;
	} else {
		// Decrease
		if(height != "20") {
			nheight = height - 20;
		}
	}
	
	if(nheight < 0) {
		nheight = 0;
	}
	
	my_getbyid('global-shouts').parentNode.style.height = nheight + "px";
	
	my_setcookie('shoutbox_size', nheight, 1);
}

/* ================================
// Update the Preferred Color
=================================*/
shoutout.prototype.updatecolor = function(obj)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	value = obj.value;
	
	if(value == '-1')
	{
		value = '';
	}
	
	obj.style.color = value;
}


/* ================================
// Update the Color Button/Input Color
=================================*/
shoutout.prototype.changecolor = function(e)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	obj = my_getbyid('sb_color2');
	if(obj.value == '')
	{
		obj = my_getbyid('sb_color1');
	}
	
	value = obj.value;
	
	if(value == '-1')
	{
		value = '';
	}
	
	but = my_getbyid('sb_colortochangeto');
	
	if(value != '')
	{
		but.value = shoutout.color_but_text + ": "+value;
	}
	else
	{
	
		but.value = shoutout.color_but_text;
	}
	but.style.color = value;
	my_getbyid('new-shout').style.color = value;
	
	shoutout.color = value;
	
	my_setcookie("shoutbox_color", value, 1);
	
	ipsmenu.menu_registered['sb_colorselector'].close();
	ipsmenu.menu_registered['sb_helpbutton'].open(my_getbyid('sb_helpbutton'));
}

/* ================================
// Cancel Setting Color
=================================*/
shoutout.prototype.cancelcolor = function(e)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	but = my_getbyid('sb_colortochangeto');
	
	but.value = shoutout.color_but_text;
	but.style.color = null;
	my_getbyid('new-shout').style.color = null;
	
	shoutout.color = null;
	
	my_setcookie("shoutbox_color", "", 0);
	
	ipsmenu.menu_registered['sb_colorselector'].close();
	ipsmenu.menu_registered['sb_helpbutton'].open(my_getbyid('sb_helpbutton'));
}

/* ================================
// Reset the Idle Count when:
//    Mouse Moves
//    Mouse Clicks
//    Key is Pressed
//    Window is Resized
=================================*/
shoutout.prototype.setonclick = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	document.onmousemove = shoutout.resetrefresh;
	document.onclick = shoutout.resetrefresh;
	document.onkeydown = shoutout.resetrefresh;
	window.onresize = shoutout.resetrefresh;
	shoutout.debug("shoutout.setonclick();");
}


/* ================================
// Resets the number of times
// Refreshed without setonclick()
// And disables Idlemode
=================================*/
shoutout.prototype.resetrefresh = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.clickmiss = 0;
	
	if(shoutout.in_idle)
	{
		shoutout.idleani_off();
	}
}

/* ================================
// Turns Idle Mode Off
=================================*/
shoutout.prototype.idleani_off = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.in_idle = false;
	my_getbyid('global-shouts-parentNode').className = 'row1';
	shoutout.refreshing = false;
	shoutout.runtimeout();
	shoutout.debug("shoutout.idleani_off();");
}


/* ================================
// Turns Idle Mode On
=================================*/
shoutout.prototype.idleani_on = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.in_idle = true;
	my_getbyid('global-shouts-parentNode').className = 'darkrow3';
	my_getbyid('refresh_button').style.display = '';
	shoutout.debug("shoutout.idleani_on();");
}

/* ================================
// Checks how many times its
// refreshed without setonclick()
=================================*/
shoutout.prototype.checkclick = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	if(shoutout.clickmiss >= 3)
	{
		shoutout.idleani_on();
	}
	else
	{
		shoutout.is_idle = false;
	}
}

/* ================================
// Runs the refresh timeout
=================================*/
shoutout.prototype.runtimeout = function() 
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.refresh();
	clearTimeout(shoutout.timeoutobj);
	shoutout.timeoutobj = setTimeout("shoutout.runtimeout();", shoutout.refreshtime);
}



/* ================================
// Debugging
=================================*/
shoutout.prototype.debug = function(msg) 
{
	if (!window.console || !console.firebug)
	{
		window.console = {};
		var names = ["info", "debug", "warn", "log"];
		for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};		
	}
	
	if(console)
	{
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		if (m<10)
		{
			m="0" + m;
		}
		if (s<10)
		{
			s="0" + s;
		}
		console.info(h+":"+m+":"+s, msg);
	}
}

/* ================================
// Refresh the Shoutbox
=================================*/
shoutout.prototype.refresh = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.debug("shoutout.refresh();");
	if(shoutout.refreshing)
	{
		shoutout.debug("Shoutbox is already refreshing");
		return;
	}
	
	if(shoutout.idlemode)
	{
		shoutout.checkclick();
		if(shoutout.in_idle)
		{
			shoutout.debug("Canceling Refresh, Currently Idling.");
			return;
		}
	}
	
	shoutout.clickmiss++;

	if(!shoutout.activated)
	{
		shoutout.debug("Shoutbox not activated.");
		return;
	}
	
	
	shoutout.refresh_ani();
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
				
			if(!my_getbyid('global-shouts'))
			{
				my_getbyid('global-shouts') = my_getbyid('global-shouts');
			}
			
			if(shoutout.sorting == "oldtonew")
			{
				my_getbyid('global-shouts').innerHTML = my_getbyid('global-shouts').innerHTML + html;
				shoutout.scrollBottom();
			}
			else
			{
				my_getbyid('global-shouts').innerHTML = html + my_getbyid('global-shouts').innerHTML;
			}
			
			html = '';
			shoutout.refresh_ani();
			shoutout.debug("Successfully Refreshed");
		}

	}
	
	var e = my_getbyid('global-shouts').getElementsByTagName('div');
	var lsid = 0;
	
	for(var i=0;i<e.length;i++){
	
		if(e[i].id.substring(-1,10) == "shout-row-") {
			if(shoutout.sorting != "oldtonew")
			{
				if(lsid == 0) {
					lsid = e[i].id.substring(10);
				}
			}
			else
			{
				lsid = e[i].id.substring(10);
			}
		}
		
	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=showshouts&lastshoutid='+lsid;
	
	xmlobj.process(u, 'GET');	
}


/* ================================
// ShoutOut Commands
// /pm {WHO} MESG
// More Coming v3
=================================*/
shoutout.prototype.commands = function()
{
	var commands = Array();
	commands['ban'] = "shoutout.ban_user";
	commands['unban'] = "shoutout.ban_user";
	commands['sticky'] = "fields['sticky'] = '1';fields['message'] = param;dontreturn = true;";
	commands['me'] = "fields['isme'] = '1';fields['message'] = param;dontreturn = true;";
	commands['prune'] = "shoutout.prune";
	commands['pruneall'] = "shoutout.pruneall";	
	commands['debug'] = "shoutout.debug";
	commands['msg'] = "eval.shoutout.towhotopm();";
	commands['ignore'] = "shoutout.ignore";
	commands['unignore'] = "shoutout.ignore";
	
	return commands;
}

/* ================================
// Prune all shouts
=================================*/
shoutout.prototype.pruneall = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			eval(html);
		}

	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=pruneall';
	
	xmlobj.process(u, 'GET');
}

/* ================================
// Prune all shouts
=================================*/
shoutout.prototype.prune = function(name)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			eval(html);
		}

	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=prune&user='+name;
	
	xmlobj.process(u, 'GET');
}

/* ================================
// Ban User
=================================*/
shoutout.prototype.ban_user = function(name)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	if(!name)
	{
		return;
	}
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			eval(html);
		}

	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=ban&name='+name;
	
	xmlobj.process(u, 'GET');
}

/* ================================
// Ignore User
=================================*/
shoutout.prototype.ignore = function(name)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	if(!name)
	{
		return;
	}
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			eval(html);
		}

	}
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=ignore&name='+name;
	
	xmlobj.process(u, 'GET');
}

/* ================================
// Adds a Shout
=================================*/
shoutout.prototype.post = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	shoutout.debug("shoutout.post();");
	var fields = Array();
	var textarea = my_getbyid('new-shout');
	var ob = my_getbyid('global-shouts');

	var color = shoutout.color;
	
	
	fields['message'] = textarea.value;
	
	if(fields['message'] == '') {
		if(my_getbyid('new-shout').value != '') {
			fields['message'] = my_getbyid('new-shout').value;
		}
	}
	
	if(fields['message'].substring(0, 5) == "/pm {")
	{
		if(shoutout.privto == null)
		{
			fields['privto'] = fields['message'].substring(5);
			pos = fields['privto'].indexOf("}");
			fields['privto'] = fields['privto'].substring(0, pos);
		}
		else
		{
			fields['privto'] = shoutout.privto;
		}
		
		fields['message'] = fields['message'].substring(5);
		fields['message'] = fields['message'].substring(fields['privto'].length + 2);
		shoutout.privto = null;
	}
	

	if(fields['message'].substring(0, 1) == "/")
	{
		spaceIndex = fields['message'].indexOf(" ");
		cmd = fields['message'].substring(1, spaceIndex);
		param = null;
		
		if(cmd == "/")
		{
			cmd = fields['message'].substring(1);
		}
		else
		{
			param = fields['message'].substring(2+(cmd.length));
		}
		
		
		if(!shoutout.cmd[cmd])
		{
			param = cmd + " "+param;
			cmd = "me";
		}
		
		if(shoutout.cmd[cmd])
		{
			pp = '()';
			dontreturn = false;
			if(param)
			{
				pp = "('"+param+"')";
			}
			
			shoutout.debug(shoutout.cmd[cmd]+pp);
			eval(shoutout.cmd[cmd]+pp);
			param = '';
			shoutout.cleartext();
			if(!dontreturn)
			{
				return;
			}
		}
	}
	
	shoutout.refresh_ani();
	shoutout.debug("shoutout.post(); -> shoutout.refresh_ani();");
	
	if(color != '')
	{
		fields['color'] = color;
	}
	
	if(shoutout.usefont != '')
	{
		fields['font'] = shoutout.usefont;
	}
	
	req = function()
	{
		if (xmlobj.readystate_ready_and_ok())
		{
			var html = xmlobj.xmlhandler.responseText;
			
			shoutout.debug("shoutout.post(); -> html check");
			
			if(html.substring(0, 5) == 'ERROR')
			{
				shoutout.debug("shoutout.post(); -> ERROR!");
				eval(html.substring(6));
			}
			else
			{
				shoutout.cleartext(1);
				shoutout.debug("shoutout.post(); -> html okay");
				
			
				if(shoutout.sorting == "oldtonew")
				{
					my_getbyid('global-shouts').innerHTML = my_getbyid('global-shouts').innerHTML + html;
					shoutout.scrollBottom();
				}
				else
				{
					my_getbyid('global-shouts').innerHTML = html + my_getbyid('global-shouts').innerHTML;
				}
				shoutout.debug("HTML\n"+html);
				shoutout.debug("shoutout.post(); -> HTML added to "+my_getbyid('global-shouts'));
				
			}

			
			
			shoutout.refresh_ani();
			
			html = '';
			textarea.focus();
		}

	}
	
	lsid = shoutout.getlatestid();
	shoutout.debug("shoutout.post(); -> ajax_request();");
	
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange(req);
	
	var u = ipb_var_base_url+'autocom=shoutbox&code=ajax&cmd=postshout&lastshoutid='+lsid;
	xmlobj.process(u, 'POST', xmlobj.format_for_post(fields));	
}

shoutout.prototype.getlatestid = function()
{
	var ob = my_getbyid('global-shouts');
	var e = ob.getElementsByTagName('div');
	var lsid = 0;
	var lsid2 = 0;
	
	for(var i=0;i<e.length;i++){
	
		if(e[i].id.substring(-1,10) == "shout-row-") {
		
			if(shoutout.sorting != "oldtonew")
			{
			
				if(lsid == 0) {
					lsid = e[i].id.substring(10);
				}
			}
			else
			{
				lsid = e[i].id.substring(10);
			}
		}
		
	}
	
	return lsid;
}

/* ================================
// Show Color Menu
=================================*/
shoutout.prototype.colormenu = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	
	ipsmenu.menu_registered['sb_colorselector'].open(my_getbyid('sb_helpbutton'));
	document.onclick = menu_action_close;
}

/* ================================
// Emoticon Popup
=================================*/
shoutout.prototype.showemoticons = function()
{
	
	if(!shoutout.inited)
	{
		return;
	}
	
	window.emoticon = shoutout.emoticon;
	window.open(ipb_var_base_url+'act=legends&CODE=emoticons', 'Emoticons', 'width=250,height=500,resizable=yes,scrollbars=yes');
	return false;
}

/* ================================
// Add Emoticon
=================================*/
shoutout.prototype.emoticon = function(code, usless, useless2)
{
	if(!shoutout.inited)
	{
		return;
	}
	
	my_getbyid('new-shout').value += ' '+code + ' ';
}

/* ================================
// BBCode Popup
=================================*/
shoutout.prototype.bbcode = function()
{
	if(!shoutout.inited)
	{
		return;
	}
	
	window.open(ipb_var_base_url+'act=legends&CODE=bbcode', 'BBCode', 'width=700,height=500,resizable=yes,scrollbars=yes');
	return false;
}
