s_formerrors = 'You must insert some text to send a message';
s_gen_error = ':: Error ::\n\n';
s_url_insert = 'Insert the URL (eg. http://www.phpbb.com/)';
s_url_insert_tip = 'http://';
s_url_error = 'You didn\'t enter any URL';
s_url_title_insert = 'Enter the title of the link';
s_url_title_insert_tip = 'Link';
s_url_title_error = 'You didn\'t write the page name';
s_email_insert = 'Enter the Email Address';
s_email_insert_tip = 'yourname@yourdomain.com';
s_email_error = 'You didn\'t write the Email Address';
s_img_insert = 'Enter the image URL';
s_img_error = 'You didn\'t write the image URL';
s_albumimg_insert = 'Enter the Album Image ID';
s_albumimg_insert_tip = 'ID';
s_albumimg_error = 'You didn\'t write the Album Image ID';
s_ram_insert = 'Please write Real Media file URL';
s_stream_insert = 'Please write audio file URL';
s_video_insert = 'Please write video file URL';
s_video_w_insert = 'Please specify video file width';
s_video_w_error = 'You didn\'t specify video file width';
s_video_h_insert = 'Please specify video file height';
s_video_h_error = 'You didn\'t specify video file height';
s_flash_insert = 'Please write Flash file URL';
s_flash_w_insert = 'Please specify Flash file width';
s_flash_w_error = 'You didn\'t specify Flash file width';
s_flash_h_insert = 'Please specify Flash file height';
s_flash_h_error = 'You didn\'t specify Flash file height';
s_file_insert_error = 'You didn\'t specify file URL';
s_grad_select = 'Please select the text first';
s_grad_error = 'This only works for less than 120 letters';
s_grad_path = 'includes/grad.htm';
s_view_more_code = 'View more code';
s_image_upload = 'Upload image to PostImage.org and add to message';

// Helpline messages
s_a_help = 'Close all open tags';
s_b_help = 'Bold text: [b]text[/b]';
s_i_help = 'Italic text: [i]text[/i]';
s_u_help = 'Underline text: [u]text[/u]';
s_strike_help = 'Strike text: [strike]text[/strike]';
s_quote_help = 'Quote text: [quote]text[/quote]';
s_code_help = 'Code display: [code]code[/code]';
s_spoil_help = 'Spoiler: [spoil]text[/spoil]';
s_highlight_help = 'Highlight: [highlight=#FFFFAA]text[/highlight]';
s_img_help = 'Insert image: [img]http://image_url[/img]';
s_imgl_help = 'Insert image with left alignment: [img align=left]http://image_url[/img]';
s_imgr_help = 'Insert image with right alignment: [img align=right]http://image_url[/img]';
s_albumimg_help = 'Insert image from album: [albumimg]Album Pic ID[/albumimg]';
s_url_help = 'Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]';
s_fc_help = 'Font color: [color=red]text[/color] (Tip: you can also use color=#FF0000)';
s_fs_help = 'Font size: [size=9]small text[/size]';
s_ft_help = 'Font type: [font=Andalus]text[/font]';
s_table_help = 'Insert Table: [table]text[/table]';
s_td_help = 'Insert Table Column: [td]text[/td]';
s_mail_help = 'Insert Email: [email]Email Here[/email]';
s_grad_help = 'Insert gradient text';
s_right_help = 'Set text align to right: [align=right]text[/align]';
s_left_help = 'Set text align to left: [align=left]text[/align]';
s_center_help = 'Set text align to center: [align=center]text[/align]';
s_justify_help = 'Justify text: [align=justify]text[/align]';
s_marqr_help = 'Marque text to Right: [marquee direction=right]text[/marquee]';
s_marql_help = 'Marque text to Left: [marquee direction=left]text[/marquee]';
s_marqu_help = 'Marque text to up: [marquee direction=up]text[/marquee]';
s_marqd_help = 'Marque text to down: [marquee direction=down]text[/marquee]';
s_stream_help = 'Insert stream file: [stream]File URL[/stream]';
s_ram_help = 'Insert Real Media file: [ram]File URL[/ram]';
s_sup_help = 'Superscript: [sup]text[/sup]';
s_sub_help = 'Subscript: [sub]text[/sub]';
s_hr_help = 'Insert H-Line [hr]';
s_bullet_help = 'Insert bullet point [*]';
s_video_help = 'Insert video file: [video width=# height=#]file URL[/video]';
s_quick_help = 'Quicktime video: [quick]http://quicktime_video_url/[/quick]';
s_flash_help = 'Insert flash file: [flash width=# height=#]flash URL[/flash]';
s_fade_help = 'Fade: [opacity]text[/opacity] or [opacity][img]http://image_url/[/img][/opacity]';
s_list_help = 'Ordered list: [list|=1|a]text[/list] (Tip: you can use [*] to insert bullet)';
s_image_upload_help = 'Upload image to PostImage.org and add to message';
s_smiley_creator = 'Smiley Creator: [smiley=1]Text[/smiley] insert a smiley with text';

// 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 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]',
'[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 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.gif";
		Bold = 1;
	}
	else
	{
		ToAdd = "[/b]";
		document.post.bold_img.src = bbcb_mg_img_path + "bold.gif";
		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.gif";
		Italic = 1;
	}
	else
	{
		ToAdd = "[/i]";
		document.post.italic.src = bbcb_mg_img_path + "italic.gif";
		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.gif";
		Underline = 1;
	}
	else
	{
		ToAdd = "[/u]";
		document.post.under.src = bbcb_mg_img_path + "under.gif";
		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.gif";
		Strikeout = 1;
	}
	else
	{
		ToAdd = "[/strike]";
		document.strik.src = bbcb_mg_img_path + "strike.gif";
		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.gif";
		List = 1;
	}
	else
	{
		ToAdd = "[/list]";
		document.listdf.src = bbcb_mg_img_path + "list.gif";
		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.gif";
		Quicktime = 1;
	}
	else
	{
		ToAdd = "[/quick]";
		document.quick.src = bbcb_mg_img_path + "quick.gif";
		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.gif";
		superscript = 1;
	}
	else
	{
		ToAdd = "[/sup]";
		document.supscript.src = bbcb_mg_img_path + "sup.gif";
		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.gif";
		subscript = 1;
	}
	else
	{
		ToAdd = "[/sub]";
		document.subs.src = bbcb_mg_img_path + "sub.gif";
		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.gif";
		Rainbow = 1;
	}
	else
	{
		ToAdd = "[/rainbow]";
		document.rainb.src = bbcb_mg_img_path + "grad.gif";
		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.gif";
		marqu = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marqu.src = bbcb_mg_img_path + "marqu.gif";
		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.gif";
		marqd = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marqd.src = bbcb_mg_img_path + "marqd.gif";
		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.gif";
		marql = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marql.src = bbcb_mg_img_path + "marql.gif";
		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.gif";
		marqr = 1;
	}
	else
	{
		ToAdd = "[/marquee]";
		document.post.marqr.src = bbcb_mg_img_path + "marqr.gif";
		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.gif";
		fade = 1;
	}
	else
	{
		ToAdd = "[/opacity]";
		document.post.fade.src = bbcb_mg_img_path + "fade.gif";
		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.gif";
		justify = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.justify.src = bbcb_mg_img_path + "justify.gif";
		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.gif";
		left = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.left.src = bbcb_mg_img_path + "left.gif";
		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.gif";
		right = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.right.src = bbcb_mg_img_path + "right.gif";
		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.gif";
		center = 1;
	}
	else
	{
		ToAdd = "[/align]";
		document.post.center.src = bbcb_mg_img_path + "center.gif";
		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 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]" + theSelection + "[/code]";
			document.post.message.focus();
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozInsert(txtarea, "[code]", "[/code]");
		return;
	}	
	if (Code == 0)
	{
		ToAdd = "[code]";
		document.post.code.src = bbcb_mg_img_path + "code1.gif";
		Code = 1;
	}
	else
	{
		ToAdd = "[/code]";
		document.post.code.src = bbcb_mg_img_path + "code.gif";
		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.gif";
		Quote = 1;
	}
	else
	{
		ToAdd = "[/quote]";
		document.post.quote.src = bbcb_mg_img_path + "quote.gif";
		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);
};
//Opacité
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;
}
