s_formerrors = 'Debe escribir algún texto para enviar un mensaje';
s_gen_error = ':: Error ::\n\n';
s_url_insert = 'Inserte la URL (por ejemplo, http://www.phpbb.com/)';
s_url_insert_tip = 'http://';
s_url_error = 'No ha introducido ninguna URL';
s_url_title_insert = 'Introduzca el título para el enlace';
s_url_title_insert_tip = 'Enlace';
s_url_title_error = 'No ha escrito el nombre de la página';
s_email_insert = 'Introduzca la dirección de correo';
s_email_insert_tip = 'sunombre@sudominio.com';
s_email_error = 'No ha escrito la direccion de correo';
s_img_insert = 'Introduzca la URL de la imagen';
s_img_error = 'No ha escrito la URL de la imagen';
s_albumimg_insert = 'Introduzca la ID de la imagen del Álbum';
s_albumimg_insert_tip = 'ID';
s_albumimg_error = 'No ha escrito la ID de la imagen del Álbum';
s_ram_insert = 'Por favor, introduzca la URL del archivo Real Media';
s_stream_insert = 'Por favor, escriba la URL del archivo de audio';
s_video_insert = 'Por favor, escriba la URL del archivo de vídeo';
s_video_w_insert = 'Por favor, especifique la anchura del archivo de vídeo';
s_video_w_error = 'No ha especificado la anchura del archivo de vídeo';
s_video_h_insert = 'Por favor, especifique la altura del archivo de vídeo';
s_video_h_error = 'No ha especificado la altura del archivo de vídeo';
s_googlevideo_insert = 'Por favor, escriba la ID del archivo de Google Video';
s_youtube_insert = 'Por favor, escriba la ID del archivo de YouTube';
s_emff_insert = 'Por favor, escriba la URL del archivo mp3';
s_flash_insert = 'Por favor, escriba la URL del archivo Flash';
s_flash_w_insert = 'Por favor, escriba la anchura del archivo Flash';
s_flash_w_error = 'No ha especificado la anchura del archivo Flash';
s_flash_h_insert = 'Por favor, escriba la altura del archivo Flash';
s_flash_h_error = 'No ha especificado la altura del archivo Flash';
s_id_insert_tip = 'ID';
s_id_insert_error = 'No ha especificado ninguna ID';
s_file_insert_error = 'No ha especificado la URL del archivo';
s_grad_select = 'Por favor, seleccione primero el texto';
s_grad_error = 'Esta opción sólo trabaja con menos de 120 letras';
s_grad_path = 'includes/grad.htm';
s_view_more_code = 'Ver mas Código';
s_image_upload = 'Subir una imagen a PostImage.org y añadir al mensaje';
s_posticyimage = 'Subir una imagen y agregarle un mensaje';

// Helpline messages
s_a_help = 'Cerrar todas la etiquetas abiertas';
s_b_help = 'Texto en Negrita: [b]texto[/b]';
s_i_help = 'Texto en Cursiva: [i]texto[/i]';
s_u_help = 'Texto Subrayado: [u]texto[/u]';
s_strike_help = 'Texto Tachado: [strike]texto[/strike]';
s_quote_help = 'Citar texto: [quote]texto[/quote]';
s_code_help = 'Mostrar código: [code]código[/code]';
s_phpbbmod_help = 'phpBB Mod Template';
s_spoil_help = 'Spoiler: [spoil]texto[/spoil]';
s_highlight_help = 'Toque de Luz (Highlight): [highlight=#FFFFAA]texto[/highlight]';
s_img_help = 'Insertar imagen: [img]http://imagen_url[/img]';
s_imgl_help = 'Insertar imagen alineada a la izquierda: [img align=left]http://imagen_url[/img]';
s_imgr_help = 'Insertar imagen alineada a la derecha: [img align=right]http://imagen_url[/img]';
s_albumimg_help = 'Insertar imagen del Álbum: [albumimg]ID Imagen Álbum[/albumimg]';
s_albumimgl_help = 'Insertar imágen desde el Álbum alineada a la izquierda: [albumimg align=left]ID de la imágen del Álbum[/albumimg]';
s_albumimgr_help = 'Insertar imágen desde el Álbum alineada a la derecha: [albumimg align=right]ID de la imágen del Álbum[/albumimg]';

s_url_help = 'Insertar URL: [url]http://url[/url] o [url=http://url]Texto URL[/url]';
s_fc_help = 'Color de Fuente: [color=red]texto[/color] (Nota: Puede usar color=#FF0000)';
s_fs_help = 'Tamaño de Fuente: [size=9]small texto[/size]';
s_ft_help = 'Tipo de Fuente: [font=Andalus]texto[/font]';
s_table_help = 'Insertar Tabla: [table]texto[/table]';
s_td_help = 'Insertar Columna de Tabla: [td]texto[/td]';
s_mail_help = 'Insertar Correo: [email]Correo Aqui[/email]';
s_grad_help = 'Insertar Texto Multicolor';
s_right_help = 'Fijar texto alineado a la derecha: [align=right]texto[/align]';
s_left_help = 'Fijar texto alineado a la izquierda: [align=left]texto[/align]';
s_center_help = 'Fijar texto alineado al centro: [align=center]texto[/align]';
s_justify_help = 'Justificar Texto: [align=justify]texto[/align]';
s_marqr_help = 'Desplazar texto hacia la Derecha: [marquee direction=right]texto[/marquee]';
s_marql_help = 'Desplazar texto hacia la Izquierda: [marquee direction=left]texto[/marquee]';
s_marqu_help = 'Desplazar texto hacia Arriba: [marquee direction=up]texto[/marquee]';
s_marqd_help = 'Desplazar texto hacia Abajo: [marquee direction=down]texto[/marquee]';
s_sup_help = 'Superíndice: [sup]texto[/sup]';
s_sub_help = 'Subíndice: [sub]texto[/sub]';
s_hr_help = 'Insertar Linea-H [hr]';
s_bullet_help = 'Insertar punto Bullet [*]';
s_video_help = 'Insertar archivo de Vídeo: [video width=# height=#]URL Archivo[/video]';
s_googlevideo_help = 'Introduzca el archivo de Google Vídeo: [googlevideo]ID Google Video[/googlevideo]';
s_youtube_help = 'Introduzca el archivo de YouTube: [youtube]ID YouTube[/youtube]';
s_quick_help = 'Quicktime Video: [quick]http://quicktime_video_url/[/quick]';
s_flash_help = 'Insertar archivo Flash: [flash width=# height=#]URL Flash[/flash]';
s_ram_help = 'Introduzca el archivo Real Media: [ram]URL Archivo[/ram]';
s_stream_help = 'Introduzca el archivo Stream: [stream]URL Archivo[/stream]';
s_emff_help = 'Introduzca el archivo mp3: [emff]URL Archivo[/emff]';
s_fade_help = 'Descolorar (Fade): [opacity]texto[/opacity] o [opacity][img]http://image_url/[/img][/opacity]';
s_list_help = 'Lista Ordenada: [list|=1|a]texto[/list] (Nota: puede usar [*] para insertar bullet)';
s_listo_help = 'Lista Ordenada: [list=1|a]text[/list] (Nota: puede usar [*] para insertar bulet)';
s_help_help = 'Abrir ayuda de BBCode';
s_image_upload_help = 'Subir imagen a PostImage.org y añadir al mensaje';
s_posticyimage_help = 'Subir imagen y añadirle un mensaje';
s_smiley_creator = 'Creador de Emoticonos: [smiley=1]Texto[/smiley] insertar un Emoticono con texto';

// 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 check 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 googlevideo = 0;
var youtube = 0;
var quicktime = 0;
var ram = 0;
var emff = 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]',
'[googlevideo]','[/googlevideo]',
'[youtube]','[/youtube]',
'[emff]','[/emff]'
);

// 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
	{
		//bbstyle(-1);
		//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 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 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 BBCgooglevideo()
{
	var FoundErrors = '';
	var enterURL = prompt(s_googlevideo_insert, s_id_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_id_insert_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[googlevideo]"+enterURL+"[/googlevideo]";
	PostWrite(ToAdd);
}

function BBCyoutube()
{
	var FoundErrors = '';
	var enterURL = prompt(s_youtube_insert, s_id_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_id_insert_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[youtube]"+enterURL+"[/youtube]";
	PostWrite(ToAdd);
}

function BBCemff()
{
	var FoundErrors = '';
	var enterURL = prompt(s_emff_insert, s_url_insert_tip);
	if (!enterURL)
	{
		FoundErrors += s_file_insert_error;
	}
	if (FoundErrors)
	{
		alert(s_gen_error + FoundErrors);
		return;
	}
	var ToAdd = "[emff]"+enterURL+"[/emff]";
	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 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);
}

// 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;
}
