s_formerrors = 'Devi inserire del testo per poter inviare un messaggio';
s_gen_error = ':: Errore ::\n\n';
s_url_insert = 'Inserisci l\'URL (es. http://www.phpbb.com/)';
s_url_insert_tip = 'http://';
s_url_error = 'Non hai inserito alcun indirizzo';
s_url_title_insert = 'Inserisci un titolo per il link';
s_url_title_insert_tip = 'Link';
s_url_title_error = 'Non hai inserito alcun nome per la pagina';
s_email_insert = 'Inserisci un indirizzo email';
s_email_insert_tip = 'yourname@yourdomain.com';
s_email_error = 'Non hai inserito alcun indirizzo';
s_img_insert = 'Inserisci l\'indirizzo dell\'immagine';
s_img_error = 'Non hai inserito l\'indirizzo dell\'immagine';
s_albumimg_insert = 'Inserisci l\'ID dell\'immagine';
s_albumimg_insert_tip = 'ID';
s_albumimg_error = 'Non hai inserito l\'ID dell\'immagine';
s_ram_insert = 'Inserisci l\'indirizzo del file Real Media';
s_stream_insert = 'Inserisci l\'indirizzo del file audio';
s_video_insert = 'Inserisci l\'indirizzo del file video';
s_video_w_insert = 'Inserisci la larghezza del file video';
s_video_w_error = 'Non hai inserito la larghezza del file video';
s_video_h_insert = 'Inserisci l\'altezza del file video';
s_video_h_error = 'Non hai inserito l\'altezza del file video';
s_flash_insert = 'Inserisci l\'indirizzo del file Flash';
s_flash_w_insert = 'Inserisci la larghezza del file Flash';
s_flash_w_error = 'Non hai inserito la larghezza del file Flash';
s_flash_h_insert = 'Inserisci l\'altezza del file Flash';
s_flash_h_error = 'Non hai inserito l\'altezza del file Flash';
s_file_insert_error = 'Non hai inserito l\'indirizzo del file';
s_grad_select = 'Seleziona il test';
s_grad_error = 'Selezionare al massimo 120 caratteri';
s_grad_path = "includes/grad.htm";
s_view_more_code = 'Visualizza pi&ugrave codice';
s_image_upload = 'Carica un\'immagine su PostImage.org e l\'aggiunge al messaggio';

// Helpline messages
s_a_help = 'Chiudi tutti i tags';
s_b_help = 'Grassetto testo: [b]testo[/b]';
s_i_help = 'Corsivo testo: [i]testo[/i]';
s_u_help = 'Sottolineatura testo: [u]testo[/u]';
s_strike_help = 'Sbarratura testo: [strike]testo[/strike]';
s_quote_help = 'Citazione testo: [quote]testo[/quote]';
s_code_help = 'Codice: [code]codice[/code]';
s_phpbbmod_help = 'phpBB Mod Template';
s_spoil_help = 'Spoiler: [spoil]testo[/spoil]';
s_highlight_help = 'Evidenzia: [highlight=#FFFFAA]testo[/highlight]';
s_img_help = 'Inserisci immagine: [img]http://image_url[/img]';
s_imgl_help = 'Inserisci immagine con allineamento a sx: [img align=left]http://image_url[/img]';
s_imgr_help = 'Inserisci immagine con allineamento a dx: [img align=right]http://image_url[/img]';
s_albumimg_help = 'Inserisci immagine dall\'album: [albumimg]Album Pic ID[/albumimg]';
//Added by Tom XS 051
s_albumimgl_help = 'Inserisci immagine dall\'album con allineamento a sinistra: [albumimg align=left]Album Pic ID[/albumimg]';
s_albumimgr_help = 'Inserisci immagine dall\'album con allineamento a destra: [albumimg align=right]Album Pic ID[/albumimg]';

s_url_help = 'Inserisci URL: [url]http://url[/url] o [url=http://url]URL testo[/url]';
s_fc_help = 'Colore Font: [color=red]testo[/color] (Consiglio: puoi anche usare color=#FF0000)';
s_fs_help = 'Dimensione Font: [size=9]testo[/size]';
s_ft_help = 'Tipo Font: [font=Andalus]testo[/font]';
s_table_help = 'Inserisci tabella: [table]testo[/table]';
s_td_help = 'Inserisci colonna in tabella: [td]testo[/td]';
s_mail_help = 'Inserisci email: [email]indirizzo email[/email]';
s_grad_help = 'Inserisci gradiente testo';
s_right_help = 'Allinea il testo a destra: [align=right]testo[/align]';
s_left_help = 'Allinea il testo a sinistra: [align=left]testo[/align]';
s_center_help = 'Allinea il testo al centro: [align=center]testo[/align]';
s_justify_help = 'Giustifica testo: [align=justify]testo[/align]';
s_marqr_help = 'Scorrimento testo a destra: [marquee direction=right]testo[/marquee]';
s_marql_help = 'Scorrimento testo a sinistra: [marquee direction=left]testo[/marquee]';
s_marqu_help = 'Scorrimento testo in alto: [marquee direction=up]testo[/marquee]';
s_marqd_help = 'Scorrimento testo in basso: [marquee direction=down]testo[/marquee]';
s_stream_help = 'Inserisci file audio: [stream]File URL[/stream]';
s_ram_help = 'Inserisci file Real Media : [ram]File URL[/ram]';
s_sup_help = 'Apice: [sup]testo[/sup]';
s_sub_help = 'Pedice: [sub]testo[/sub]';
s_hr_help = 'Inserisci linea orizzontale [hr]';
s_bullet_help = 'Inserisci punto elenco [*]';
s_video_help = 'Inserisci file video: [video width=# height=#]file URL[/video]';
s_quick_help = 'Inserisci file Quicktime video: [quick]http://quicktime_video_url/[/quick]';
s_flash_help = 'Inserisci file flash: [flash width=# height=#]flash URL[/flash]';
s_fade_help = 'Sfumatura: [opacity]testo[/opacity] oppure [opacity][img]http://image_url/[/img][/opacity]';
s_list_help = 'Lista ordinata: [list|=1|a]testo[/list] (Consiglio: usa [*] per inserire nuovi elementi)';
//Added by Tom XS 051
s_listo_help = 'Lista ordinata: [list=1|a]testo[/list] (Consiglio: usa [*] per inserire nuovi elementi)';
s_help_help = 'BBCode FAQ';

s_image_upload_help = 'Carica un\'immagine su PostImage.org e l\'aggiunge al messaggio';
s_smiley_creator = 'Smiley Creator: [smiley=1]Testo[/smiley] inserisce uno smiley con testo';

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
		&& (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
		&& (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

// Other chek in vars...
var uAgent = navigator.userAgent;
var ns4 = (document.layers)? true:false;   //NS 4
var ie4 = (document.all)? true:false;   //IE 4
var dom = (document.getElementById)? true:false;   //DOM
var ope = uAgent.indexOf("Opera")>-1 && dom? true:false; // + OP5
var ie5 = (dom && ie4 && !ope)?true:false; // IE5
var ns6 = (dom && uAgent.indexOf("Netscape")>-1)? true:false; // + NS 6
var khtml = uAgent.indexOf("khtml")>-1? true:false; // + Konqueror
//alert("UserAgent: "+uAgent+"\nns4 :"+ns4+"\nie4 :"+ie4+"\ndom :"+dom+"\nie5 :"+ie5+"\nns6 :"+ns6+"\nope :"+ope+"\nkhtml :"+khtml);

var baseHeight;
//window.onload = initInsertions;

function initInsertions()
{
	document.post.message.focus();
	if (is_ie && typeof(baseHeight) != 'number') baseHeight = document.selection.createRange().duplicate().boundingHeight;
}

//var bbcb_mg_img_path = "images/bbcb_mg/images/";
//var bbcb_mg_img_path = "images/bbcb_mg/images/png/";
//var bbcb_mg_img_ext = "" + bbcb_mg_img_ext;
var bbcb_mg_img_path = "images/bbcb_mg/images/gif/";
var bbcb_mg_img_ext = ".gif";

var Quote = 0;
var Bold = 0;
var Italic = 0;
var Underline = 0;
var Strikeout = 0;
var Code = 0;
var flash = 0;
var fc = 0;
var fs = 0;
var ft = 0;
var center = 0;
var right = 0;
var left = 0;
var justify = 0;
var fade = 0;
var marqd = 0;
var marqu = 0;
var marql = 0;
var marqr = 0;
var mail = 0;
var video = 0;
var Quicktime = 0;
var stream = 0;
var ram = 0;
var hr = 0;
var bullet = 0;
var Rainbow = 0;
var superscript = 0;
var subscript = 0;
var List = 0;
var Spoiler = 0;
var Table = 0;
var Td = 0;

bbcode = new Array();
bbtags = new Array(
'[b]','[/b]',
'[i]','[/i]',
'[u]','[/u]',
'[quote]','[/quote]',
'[code]','[/code]',
'[list]','[/list]',
'[list=]','[/list]',
'[align=]','[/align]',
'[center]','[/center]',
'[color=]','[/color]',
'[img]','[/img]',
'[img align=left]','[/img]',
'[img align=right]','[/img]',
'[albumimg]','[/albumimg]',
'[albumimg align=left]','[/albumimg]',
'[albumimg align=right]','[/albumimg]',
'[url]','[/url]',
'[email]','[/email]',
'[blur]','[/blur]',
'[fade]','[/fade]',
'[marquee=]','[/marquee]',
'[highlight=]','[/highlight]',
'[flipv]','[/flipv]',
'[fliph]','[/fliph]',
'[swf width=200 height=200]','[/swf]',
'[php]','[/php]',
'[wave]','[/wave]',
'[stream]','[/stream]',
'[real]','[/real]',
'[video width=320 height=240]','[/video]'
);

// Shows the help messages in the helpline window
function helpline(help)
{
	document.post.helpbox.value = eval("s_" + help + "_help");
	document.post.helpbox.readOnly = "true";
}

// Replacement for arrayname.length property
function getarraysize(thearray)
{
	for (i = 0; i < thearray.length; i++)
	{
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
		{
			return i;
		}
	}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value)
{
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray)
{
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

function checkForm()
{
	formErrors = false;
	if (document.post.message.value.length < 2)
	{
		formErrors = s_formerrors;
	}
	if (formErrors)
	{
		alert(formErrors);
		return false;
	}
	else
	{
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}

function emoticon(text)
{
	var txtarea = document.post.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		if (baseHeight != txtarea.caretPos.boundingHeight)
		{
			txtarea.focus();
			storeCaret(txtarea);
		}
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	}
	else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
	{
		mozInsert(txtarea, text, "");
		return;
	}
	else
	{
		txtarea.value += text;
		txtarea.focus();
	}
}

function bbfontstyle(bbopen, bbclose)
{
	var txtarea = document.post.message;
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (!theSelection)
		{
			if (txtarea.createTextRange && txtarea.caretPos)
			{
				if (baseHeight != txtarea.caretPos.boundingHeight)
				{
					txtarea.focus();
					storeCaret(txtarea);
				}
				var caretPos = txtarea.caretPos;
				var text = bbopen + bbclose;
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
			}
			else
			{
				txtarea.value += bbopen + bbclose;
			}
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		txtarea.focus();
		return;
	}
	else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
	{
		mozInsert(txtarea, bbopen, bbclose);
		return;
	}
	else
	{
		txtarea.value += bbopen + bbclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}

function bbstyle(bbnumber)
{
	var txtarea = document.post.message;

	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1)
	{ // Close all open tags & default button names
		while (bbcode[0])
		{
			butnumber = arraypop(bbcode) - 1;
			if (txtarea.createTextRange && txtarea.caretPos)
			{
				if (baseHeight != txtarea.caretPos.boundingHeight)
				{
					txtarea.focus();
					storeCaret(txtarea);
				}
				var caretPos = txtarea.caretPos;
				var text = bbtags[butnumber + 1];
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
			}
			else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
			{
				mozInsert(txtarea, bbtags[butnumber + 1], "");
			}
			else
			{
				txtarea.value += bbtags[butnumber + 1];
			}
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection)
		{
			// Add tags around selection
			document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, bbtags[bbnumber], bbtags[bbnumber+1]);
		return;
	}
	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++)
	{
		if (bbcode[i] == bbnumber+1)
		{
			bblast = i;
			donotinsert = true;
		}
	}
	if (donotinsert)
	{ // Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast])
		{
			butnumber = arraypop(bbcode) - 1;
			if (txtarea.createTextRange && txtarea.caretPos)
			{
				if (baseHeight != txtarea.caretPos.boundingHeight)
				{
					txtarea.focus();
					storeCaret(txtarea);
				}
				var caretPos = txtarea.caretPos;
				var text = bbtags[butnumber + 1];
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
			}
			else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
			{
				mozInsert(txtarea, bbtags[butnumber + 1], "");
			}
			else
			{
				txtarea.value += bbtags[butnumber + 1];
			}
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
			imageTag = false;
		}
		txtarea.focus();
		return;
	}
	else
	{ // Open tags
		if (imageTag && (bbnumber != 14))
		{ // Close image tag before adding another
			if (txtarea.createTextRange && txtarea.caretPos)
			{
				if (baseHeight != txtarea.caretPos.boundingHeight)
				{
					txtarea.focus();
					storeCaret(txtarea);
				}
				var caretPos = txtarea.caretPos;
				var text = bbtags[15];
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
			}
			else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
			{
				mozInsert(txtarea, bbtags[15], "");
			}
			else
			{
				txtarea.value += bbtags[15];
			}
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}
		// Open tag
		if (bbnumber == 16)
		{
			var url = prompt(s_url_insert, s_url_insert_tip);

			if (url == null)
			{
				return;
			}
			else if (!url)
			{
				alert(s_gen_error + s_url_error);
				return;
			}
			else
			{
				var title = prompt(s_url_title_insert, s_url_title_insert_tip);
				if (title == null)
				{
					return;
				}
				else if (!title)
				{
					var text = "[url]" + url + "[/url]";
				}
				else
				{
					var text = "[url=" + url + "]" + title + "[/url]";
				}
			}
			if (txtarea.createTextRange && txtarea.caretPos)
			{
				if (baseHeight != txtarea.caretPos.boundingHeight)
				{
					txtarea.focus();
					storeCaret(txtarea);
				}
				var caretPos = txtarea.caretPos;
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
			}
			else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
			{
				mozInsert(txtarea, text, "");
			}
			else
			{
				txtarea.value += text;
			}
		}
		else
		{
			var text = bbtags[bbnumber];
			if (txtarea.createTextRange && txtarea.caretPos)
			{
				if (baseHeight != txtarea.caretPos.boundingHeight)
				{
					txtarea.focus();
					storeCaret(txtarea);
				}
				var caretPos = txtarea.caretPos;
				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
			}
			else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
			{
				mozInsert(txtarea, bbtags[bbnumber], "");
			}
			else
			{
				txtarea.value += bbtags[bbnumber];
			}
			if ((bbnumber == 14) && (imageTag == false))
			{
				imageTag = 1;
			}
			arraypush(bbcode,bbnumber+1);
			eval('document.post.addbbcode'+bbnumber+'.value += "*"');
		}
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

function PostWrite(text)
{
	var txtarea = document.post.message;
	txtarea.focus();
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		if (baseHeight != txtarea.caretPos.boundingHeight)
		{
			txtarea.focus();
			storeCaret(txtarea);
		}
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	}
	else if ((txtarea.selectionEnd | txtarea.selectionEnd == 0) && (txtarea.selectionStart | txtarea.selectionStart == 0))
	{
		mozInsert(txtarea, text, "");
		return;
	}
	else
	{
		txtarea.value += text;
		txtarea.focus();
	}
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
	{
		selEnd = selLength;
	}

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

function mozInsert(txtarea, openTag, closeTag)
{
	if (txtarea.selectionEnd > txtarea.value.length)
	{
		txtarea.selectionEnd = txtarea.value.length;
	}

	var startPos = txtarea.selectionStart;
	var endPos = txtarea.selectionEnd+openTag.length;

	txtarea.value=txtarea.value.slice(0,startPos)+openTag+txtarea.value.slice(startPos);
	txtarea.value=txtarea.value.slice(0,endPos)+closeTag+txtarea.value.slice(endPos);

	txtarea.selectionStart = startPos+openTag.length;
	txtarea.selectionEnd = endPos;
	txtarea.focus();
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl)
{
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

// Mighty Gorgon - Highlight/Copy
function highlightmetasearch()
{
	document.post.message.select(); document.post.message.focus();
}
function copymetasearch()
{
	highlightmetasearch();
	textRange = document.post.message.createTextRange();
	textRange.execCommand("RemoveFormat");
	textRange.execCommand("Copy");
	// alert("Il messaggio &egrave; stato copiato negli appunti");
}
// Mighty Gorgon - Highlight/Copy

function BBCmail()
{
	var FoundErrors = '';
	var entermail = prompt(s_email_insert, s_email_insert_tip);
	if (!entermail)
	{
		FoundErrors += s_email_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[email]" + entermail + "[/email]";
	PostWrite(ToAdd);
}

function BBCurl()
{
	var FoundErrors = '';
	var enterURL = prompt(s_url_insert, s_url_insert_tip);
	var enterTITLE = prompt(s_url_title_insert, s_url_title_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_url_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	if (enterTITLE == null)
	{
		var ToAdd = "[url]" + enterURL + "[/url]";
	}
	else if (!enterTITLE)
	{
		var ToAdd = "[url]" + enterURL + "[/url]";
	}
	else
	{
		var ToAdd = "[url=" + enterURL + "]" + enterTITLE + "[/url]";
	}
	PostWrite(ToAdd);
}

function BBCimg()
{
	var FoundErrors = '';
	var enterURL = prompt(s_img_insert, s_url_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_img_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[img]"+enterURL+"[/img]";
	PostWrite(ToAdd);
}

function BBCimgl()
{
	var FoundErrors = '';
	var enterURL = prompt(s_img_insert, s_url_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_img_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[img align=left]"+enterURL+"[/img]";
	PostWrite(ToAdd);
}

function BBCimgr()
{
	var FoundErrors = '';
	var enterURL = prompt(s_img_insert, s_url_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_img_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[img align=right]"+enterURL+"[/img]";
	PostWrite(ToAdd);
}

function BBCalbumimg()
{
	var FoundErrors = '';
	var enterURL = prompt(s_albumimg_insert, s_albumimg_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_albumimg_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[albumimg]"+enterURL+"[/albumimg]";
	PostWrite(ToAdd);
}

function BBCalbumimgl()
{
	var FoundErrors = '';
	var enterURL = prompt(s_albumimg_insert, s_albumimg_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_albumimg_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[albumimg align=left]"+enterURL+"[/albumimg]";
	PostWrite(ToAdd);
}

function BBCalbumimgr()
{
	var FoundErrors = '';
	var enterURL = prompt(s_albumimg_insert, s_albumimg_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_albumimg_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[albumimg align=right]"+enterURL+"[/albumimg]";
	PostWrite(ToAdd);
}

function BBCram()
{
	var FoundErrors = '';
	var enterURL = prompt(s_ram_insert ,s_url_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_file_insert_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[ram]"+enterURL+"[/ram]";
	PostWrite(ToAdd);
}

function BBCstream()
{
	var FoundErrors = '';
	var enterURL = prompt(s_stream_insert, s_url_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_file_insert_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[stream]"+enterURL+"[/stream]";
	PostWrite(ToAdd);
}

function BBCvideo()
{
	var FoundErrors = '';
	var enterFURL = prompt(s_video_insert, s_url_insert_tip);
	if (!enterFURL)
	{
		FoundErrors += s_file_insert_error;
	}
	var enterW = prompt(s_video_w_insert, "320");
	if (!enterW)
	{
		FoundErrors += s_video_w_error;
	}
	var enterH = prompt(s_video_h_insert, "240");
	if (!enterH)
	{
		FoundErrors += s_video_h_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[video width="+enterW+" height="+enterH+"]"+enterFURL+"[/video]";
	PostWrite(ToAdd);
}

function BBCflash()
{
	var FoundErrors = '';
	var enterFURL = prompt(s_flash_insert, s_url_insert_tip);
	if (!enterFURL)
	{
		FoundErrors += s_file_insert_error;
	}
	var enterW = prompt(s_flash_w_insert, "320");
	if (!enterW)
	{
		FoundErrors += s_flash_w_error;
	}
	var enterH = prompt(s_flash_h_insert, "240");
	if (!enterH)
	{
		FoundErrors += s_flash_h_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[flash width="+enterW+" height="+enterH+"]"+enterFURL+"[/flash]";
	PostWrite(ToAdd);
}

function BBCbold()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[b]" + theSelection + "[/b]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		//mozWrap(txtarea, "[b]", "[/b]");
		mozInsert(txtarea, "[b]", "[/b]");
		return;
	}
	if (Bold == 0)
	{
		ToAdd = "[b]";
		document.post.bold_img.src = bbcb_mg_img_path + "bold1" + bbcb_mg_img_ext;
		Bold = 1;
	}
	else
	{
		ToAdd = "[/b]";
		document.post.bold_img.src = bbcb_mg_img_path + "bold" + bbcb_mg_img_ext;
		Bold = 0;
	}
	PostWrite(ToAdd);
}

function BBCitalic()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[i]" + theSelection + "[/i]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[i]", "[/i]");
		return;
	}
	if (Italic == 0)
	{
		ToAdd = "[i]";
		document.post.italic.src = bbcb_mg_img_path + "italic1" + bbcb_mg_img_ext;
		Italic = 1;
	}
	else
	{
		ToAdd = "[/i]";
		document.post.italic.src = bbcb_mg_img_path + "italic" + bbcb_mg_img_ext;
		Italic = 0;
	}
	PostWrite(ToAdd);
}

function BBCunder()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[u]" + theSelection + "[/u]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[u]", "[/u]");
		return;
	}
	if (Underline == 0)
	{
		ToAdd = "[u]";
		document.post.under.src = bbcb_mg_img_path + "under1" + bbcb_mg_img_ext;
		Underline = 1;
	}
	else
	{
		ToAdd = "[/u]";
		document.post.under.src = bbcb_mg_img_path + "under" + bbcb_mg_img_ext;
		Underline = 0;
	}
	PostWrite(ToAdd);
}

function BBCstrike()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[strike]" + theSelection + "[/strike]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[strike]", "[/strike]");
		return;
	}
	if (Strikeout == 0)
	{
		ToAdd = "[strike]";
		document.strik.src = bbcb_mg_img_path + "strike1" + bbcb_mg_img_ext;
		Strikeout = 1;
	}
	else
	{
		ToAdd = "[/strike]";
		document.strik.src = bbcb_mg_img_path + "strike" + bbcb_mg_img_ext;
		Strikeout = 0;
	}
	PostWrite(ToAdd);
}

function BBCtable()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[table]" + theSelection + "[/table]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[table]", "[/table]");
		return;
	}
	if (Table == 0)
	{
		ToAdd = "[table]";
		document.table.src = bbcb_mg_img_path + "table1.gif";
		Table = 1;
	}
	else
	{
		ToAdd = "[/table]";
		document.table.src = bbcb_mg_img_path + "table.gif";
		Table = 0;
	}
	PostWrite(ToAdd);
}

function BBCtd()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[td]" + theSelection + "[/td]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[td]", "[/td]");
		return;
	}
	if (Td == 0)
	{
		ToAdd = "[td]";
		document.td.src = bbcb_mg_img_path + "td1.gif";
		Td = 1;
	}
	else
	{
		ToAdd = "[/td]";
		document.td.src = bbcb_mg_img_path + "td.gif";
		Td = 0;
	}
	PostWrite(ToAdd);
}

function BBCspoil()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[spoil]" + theSelection + "[/spoil]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[spoil]", "[/spoil]");
		return;
	}
	if (Spoiler == 0)
	{
		ToAdd = "[spoil]";
		document.spoil.src = bbcb_mg_img_path + "spoil1.gif";
		Spoiler = 1;
	}
	else
	{
		ToAdd = "[/spoil]";
		document.spoil.src = bbcb_mg_img_path + "spoil.gif";
		Spoiler = 0;
	}
	PostWrite(ToAdd);
}

function BBClist() {
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[list]" + theSelection + "[/list]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[list]", "[/list]");
		return;
	}
	if (List == 0)
	{
		ToAdd = "[list]";
		document.listdf.src = bbcb_mg_img_path + "list1" + bbcb_mg_img_ext;
		List = 1;
	}
	else
	{
		ToAdd = "[/list]";
		document.listdf.src = bbcb_mg_img_path + "list" + bbcb_mg_img_ext;
		List = 0;
	}
	PostWrite(ToAdd);
}

function BBClistO() {
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[list=1]" + theSelection + "[/list]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[list=1]", "[/list]");
		return;
	}
	if (List == 0)
	{
		ToAdd = "[list=1]";
		document.listodf.src = bbcb_mg_img_path + "list_o1" + bbcb_mg_img_ext;
		List = 1;
	}
	else
	{
		ToAdd = "[/list]";
		document.listodf.src = bbcb_mg_img_path + "list_o" + bbcb_mg_img_ext;
		List = 0;
	}
	PostWrite(ToAdd);
}

function BBCquick()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[quick]" + theSelection + "[/quick]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[quick]", "[/quick]");
		return;
	}
	if (Quicktime == 0)
	{
		ToAdd = "[quick]";
		document.quick.src = bbcb_mg_img_path + "quick1" + bbcb_mg_img_ext;
		Quicktime = 1;
	}
	else
	{
		ToAdd = "[/quick]";
		document.quick.src = bbcb_mg_img_path + "quick" + bbcb_mg_img_ext;
		Quicktime = 0;
	}
	PostWrite(ToAdd);
}

function BBCsup()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[sup]" + theSelection + "[/sup]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[sup]", "[/sup]");
		return;
	}
	if (superscript == 0)
	{
		ToAdd = "[sup]";
		document.supscript.src = bbcb_mg_img_path + "sup1" + bbcb_mg_img_ext;
		superscript = 1;
	}
	else
	{
		ToAdd = "[/sup]";
		document.supscript.src = bbcb_mg_img_path + "sup" + bbcb_mg_img_ext;
		superscript = 0;
	}
	PostWrite(ToAdd);
}

function BBCsub()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[sub]" + theSelection + "[/sub]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[sub]", "[/sub]");
		return;
	}
	if (subscript == 0)
	{
		ToAdd = "[sub]";
		document.subs.src = bbcb_mg_img_path + "sub1" + bbcb_mg_img_ext;
		subscript = 1;
	}
	else
	{
		ToAdd = "[/sub]";
		document.subs.src = bbcb_mg_img_path + "sub" + bbcb_mg_img_ext;
		subscript = 0;
	}
	PostWrite(ToAdd);
}

function BBCgrad()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[rainbow]" + theSelection + "[/rainbow]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[rainbow]", "[/rainbow]");
		return;
	}
	if (Rainbow == 0)
	{
		ToAdd = "[rainbow]";
		document.rainb.src = bbcb_mg_img_path + "grad1" + bbcb_mg_img_ext;
		Rainbow = 1;
	}
	else
	{
		ToAdd = "[/rainbow]";
		document.rainb.src = bbcb_mg_img_path + "grad" + bbcb_mg_img_ext;
		Rainbow = 0;
	}
	PostWrite(ToAdd);
}

function BBCgrad2() {
	var oSelect,oSelectRange;
	document.post.message.focus();
	oSelect = document.selection;
	oSelectRange = oSelect.createRange();
	if (oSelectRange.text.length < 1)
	{
		alert(s_grad_select);
		return;
	}
	if (oSelectRange.text.length > 120)
	{
		alert(s_grad_error);
		return;
	}
	showModalDialog(s_grad_path, oSelectRange, "help:no; center:yes; status:no; dialogHeight:50px; dialogWidth:50px");
}

function BBChr()
{
	ToAdd = "[hr]";
	PostWrite(ToAdd);
}

function BBCbullet()
{
	ToAdd = "[*]";
	PostWrite(ToAdd);
}

function BBCmarqu()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[marquee direction=up]" + theSelection + "[/marquee]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[marquee direction=up]", "[/marquee]");
		return;
	}
	if (marqu == 0)
	{
		ToAdd = "[marquee direction=up]";
		document.post.marqu.src = bbcb_mg_img_path + "marqu1" + bbcb_mg_img_ext;
		marqu = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marqu.src = bbcb_mg_img_path + "marqu" + bbcb_mg_img_ext;
		marqu = 0;
	}
	PostWrite(ToAdd);
}

function BBCmarqd()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[marquee direction=down]" + theSelection + "[/marquee]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[marquee direction=down]", "[/marquee]");
		return;
	}
	if (marqd == 0)
	{
		ToAdd = "[marquee direction=down]";
		document.post.marqd.src = bbcb_mg_img_path + "marqd1" + bbcb_mg_img_ext;
		marqd = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marqd.src = bbcb_mg_img_path + "marqd" + bbcb_mg_img_ext;
		marqd = 0;
	}
	PostWrite(ToAdd);
}

function BBCmarql()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[marquee direction=left]" + theSelection + "[/marquee]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[marquee direction=left]", "[/marquee]");
		return;
	}
	if (marql == 0)
	{
		ToAdd = "[marquee direction=left]";
		document.post.marql.src = bbcb_mg_img_path + "marql1" + bbcb_mg_img_ext;
		marql = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marql.src = bbcb_mg_img_path + "marql" + bbcb_mg_img_ext;
		marql = 0;
	}
	PostWrite(ToAdd);
}

function BBCmarqr()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[marquee direction=right]" + theSelection + "[/marquee]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[marquee direction=right]", "[/marquee]");
		return;
	}
	if (marqr == 0)
	{
		ToAdd = "[marquee direction=right]";
		document.post.marqr.src = bbcb_mg_img_path + "marqr1" + bbcb_mg_img_ext;
		marqr = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marqr.src = bbcb_mg_img_path + "marqr" + bbcb_mg_img_ext;
		marqr = 0;
	}
	PostWrite(ToAdd);
}

function BBCdir(dirc)
{
	document.post.message.dir=(dirc);
}

function BBCfade()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[opacity]" + theSelection + "[/opacity]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[opacity]", "[/opacity]");
		return;
	}
	if (fade == 0)
	{
		ToAdd = "[opacity]";
		document.post.fade.src = bbcb_mg_img_path + "fade1" + bbcb_mg_img_ext;
		fade = 1;
	}
	else
	{
		ToAdd = "[/opacity]";
		document.post.fade.src = bbcb_mg_img_path + "fade" + bbcb_mg_img_ext;
		fade = 0;
	}
	PostWrite(ToAdd);
}

function BBCjustify()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[align=justify]" + theSelection + "[/align]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[align=justify]", "[/align]");
		return;
	}
	if (justify == 0)
	{
		ToAdd = "[align=justify]";
		document.post.justify.src = bbcb_mg_img_path + "justify1" + bbcb_mg_img_ext;
		justify = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.justify.src = bbcb_mg_img_path + "justify" + bbcb_mg_img_ext;
		justify = 0;
	}
	PostWrite(ToAdd);
}

function BBCleft()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[align=left]" + theSelection + "[/align]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[align=left]", "[/align]");
		return;
	}
	if (left == 0)
	{
		ToAdd = "[align=left]";
		document.post.left.src = bbcb_mg_img_path + "left1" + bbcb_mg_img_ext;
		left = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.left.src = bbcb_mg_img_path + "left" + bbcb_mg_img_ext;
		left = 0;
	}
	PostWrite(ToAdd);
}

function BBCright()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[align=right]" + theSelection + "[/align]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[align=right]", "[/align]");
		return;
	}
	if (right == 0)
	{
		ToAdd = "[align=right]";
		document.post.right.src = bbcb_mg_img_path + "right1" + bbcb_mg_img_ext;
		right = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.right.src = bbcb_mg_img_path + "right" + bbcb_mg_img_ext;
		right = 0;
	}
	PostWrite(ToAdd);
}

function BBCcenter()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[align=center]" + theSelection + "[/align]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[align=center]", "[/align]");
		return;
	}
	if (center == 0)
	{
		ToAdd = "[align=center]";
		document.post.center.src = bbcb_mg_img_path + "center1" + bbcb_mg_img_ext;
		center = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.center.src = bbcb_mg_img_path + "center" + bbcb_mg_img_ext;
		center = 0;
	}
	PostWrite(ToAdd);
}

function BBCft()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[font="+document.post.ft.value+"]" + theSelection + "[/font]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[font="+document.post.ft.value+"]", "[/font]");
		return;
	}
	ToAdd = "[font="+document.post.ft.value+"]"+" "+"[/font]";
	PostWrite(ToAdd);
}

function BBCfs()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[size="+document.post.fs.value+"]" + theSelection + "[/size]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[size="+document.post.fs.value+"]", "[/size]");
		return;
	}
	ToAdd = "[size="+document.post.fs.value+"]"+" "+"[/size]";
	PostWrite(ToAdd);
}

function BBCfc()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[color="+document.post.fc.value+"]" + theSelection + "[/color]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[color="+document.post.fc.value+"]", "[/color]");
		return;
	}
	ToAdd = "[color="+document.post.fc.value+"]"+" "+"[/color]";
	PostWrite(ToAdd);
}

function BBChl()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[highlight=#FFFFAA]" + theSelection + "[/highlight]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[highlight=#FFFFAA]", "[/highlight]");
		return;
	}
	ToAdd = "[highlight=#FFFFAA]"+" "+"[/highlight]";
	PostWrite(ToAdd);
}

function BBCphpbbmod()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = theSelection + "OPEN [b][/b]\nFIND\n[codeblock][/codeblock]\nREPLACE WITH\n[codeblock][/codeblock]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "", "OPEN [b][/b]\nFIND\n[codeblock][/codeblock]\nREPLACE WITH\n[codeblock][/codeblock]");
		return;
	}
	ToAdd = "OPEN [b][/b]\nFIND\n[codeblock][/codeblock]\nREPLACE WITH\n[codeblock][/codeblock]";
	PostWrite(ToAdd);
}

function BBCcode()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[code linenumbers=false]" + theSelection + "[/code]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[code linenumbers=false]", "[/code]");
		return;
	}	
	if (Code == 0)
	{
		ToAdd = "[code linenumbers=false]";
		document.post.code.src = bbcb_mg_img_path + "code1" + bbcb_mg_img_ext;
		Code = 1;
	}
	else
	{
		ToAdd = "[/code]";
		document.post.code.src = bbcb_mg_img_path + "code" + bbcb_mg_img_ext;
		Code = 0;
	}
	PostWrite(ToAdd);
}

function BBCquote()
{
	var txtarea = document.post.message;
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection != '')
		{
			document.selection.createRange().text = "[quote]" + theSelection + "[/quote]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[quote]", "[/quote]");
		return;
	}
	if (Quote == 0)
	{
		ToAdd = "[quote]";
		document.post.quote.src = bbcb_mg_img_path + "quote1" + bbcb_mg_img_ext;
		Quote = 1;
	}
	else
	{
		ToAdd = "[/quote]";
		document.post.quote.src = bbcb_mg_img_path + "quote" + bbcb_mg_img_ext;
		Quote = 0;
	}
	PostWrite(ToAdd);
}

function PostWrite(text)
{
	var txtarea = document.post.message;
	txtarea.focus();
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionStart | txtarea.selectionStart == 0))
	{
		mozInsert(txtarea, text, "");
	}
	else
	{
		txtarea.value += text
	}
}

// Div Expand js
function selectAll(elementId)
{
	var element = document.getElementById(elementId);
	if ( document.selection )
	{
		var range = document.body.createTextRange();
		range.moveToElementText(element);
		range.select();
	}
	if ( window.getSelection )
	{
		var range = document.createRange();
		range.selectNodeContents(element);
		var blockSelection = window.getSelection();
		blockSelection.removeAllRanges();
		blockSelection.addRange(range);
	}
}

function resizeLayer(layerId, newHeight)
{
	var myLayer = document.getElementById(layerId);
	myLayer.style.height = newHeight + 'px';
}

function codeDivStart()
{
	var randomId = Math.floor(Math.random() * 2000);
	var imgSrc = 'images/bbcb_mg/images/';
	document.write('<div class="codetitle">Code:<img src="' + imgSrc + 'nav_expand.gif" width="14" height="10" title="' + s_view_more_code +'" onclick="resizeLayer(' + randomId + ', 200)" onmouseover="this.style.cursor = \'pointer\'" /><img src="' + imgSrc + 'nav_expand_more.gif" width="14" height="10" title="View Even More of this Code" onclick="resizeLayer(' + randomId + ', 500)" onmouseover="this.style.cursor = \'pointer\'" /><img src="' + imgSrc + 'nav_contract.gif" width="14" height="10" title="View Less of this Code" onclick="resizeLayer(' + randomId + ', 50)" onmouseover="this.style.cursor = \'pointer\'" /><img src="' + imgSrc + 'nav_select_all.gif" width="14" height="10" title="Select All of this Code" onclick="selectAll(' + randomId + ')" onmouseover="this.style.cursor = \'pointer\'" /></div><div class="codediv" id="' + randomId + '">');
}

// Fade js

//gestion des objets selon les navigateurs
function ob(id)
{
	if (dom)
	{
		obj = document.getElementById(id);
	}
	else if (ie4)
	{
		obj = document.all[id];
	}
	else if (ns4)
	{
		obj = document.anchors[id];
	}
	else
	{
		obj=false;
	}
	return obj;
}

// Fade
Array.prototype.inArray=function(str)
{//on modifie l'objet Array
	for(i=0; i< this.length; i++)
	{
		if(this[i].toString()==str)
		{
			return i;
		}
	}
return -1;
}
//On modifie l'objet String
String.prototype.exist=function()
{
	return (this=="undefined"?false:true);
};
//Opacity
function setOpacity(id,alpha,isObj)
{
	if(!dom)
	{
		return;
	}
	var object = isObj ? id : ob(id);
	if(String(typeof object.filters).exist())
	{
		object.filters.alpha.opacity = alpha;
	}
	else if(String(typeof object.style.opacity).exist())
	{
		object.style.opacity = (alpha/100);
	}
	else if(String(typeof object.style.KhtmlOpacity).exist())
	{
		object.style.KhtmlOpacity = (alpha/100);
	}
	else if(String(typeof object.style.MozOpacity).exist())
	{
		object.style.MozOpacity = (alpha/100);
	}
}
function getOpacity(id,isObj)
{
	if(!dom)
	{
		return;
	}
	var object = isObj?id:ob(id), alpha=null;
	if(String(typeof object.filters).exist())
	{
		alpha = object.filters.alpha.opacity;
	}
	else if(String(typeof object.style.opacity).exist())
	{
		alpha = object.style.opacity*100;//css3 propertie
	}
	else if(String(typeof object.style.KhtmlOpacity).exist())
	{
		alpha = object.style.KhtmlOpacity*100;
	}
	else if(String(typeof object.style.MozOpacity).exist())
	{
		alpha = object.style.MozOpacity*100;
	}
	return alpha;
}
// Fading
vit=5; //temps entre chaque addition d'opacité(+ petit -> + de qualité -> + dur pour le navigateur)
add=4; //valeur à additionner (idem)
nObj=0;

fadeObjects=new Object();
fadeTimers=new Object();
fadeIds=new Array();

function fade2(object, destOp)
{
	if (!dom)
	{
		return;
	}
	if (object.toString().indexOf("[object")==-1)
	{
		setTimeout("fade2("+object+","+destOp+")",0);
		return;
	}
	alpha=getOpacity(object,true);
	index=fadeIds.inArray(object.id);
	if(index>-1)
	{
		clearTimeout(fadeTimers[index]);
	}
	else
	{
		index=nObj++;
		fadeIds[index]=object.id;
	}
	diff = destOp-alpha;
	direction=1;
	if (alpha > destOp)
	{
		direction=-1;//de - en - opaque
	}
	alpha += direction * Math.min(direction * diff, add);//ajoute le + petit entre la diférence et add
	setOpacity(object,alpha,true);
	alpha=getOpacity(object,true);
	object.offsetLeft;
	if (Math.round(alpha) != destOp)
	{
		fadeObjects[index]=object;
		fadeTimers[index]=setTimeout("fade2(fadeObjects["+index+"],"+destOp+")",vit);
	}
	return;
}
