
function formatBBcode(text)
{
search = new Array(
	    /\</,
	    /\>/,
	    /\n/g,
          /\[img\](.*?)\[\/img\]/,
          /\[url=([\w]+?:\/\/[^ \\"\n\r\t<]*?)\](.*?)\[\/url\]/,
          /\[url\]((www|ftp|)\.[^ \\"\n\r\t<]*?)\[\/url\]/,
          /\[url=((www|ftp|)\.[^ \\"\n\r\t<]*?)\](.*?)\[\/url\]/,
	    /\[mail\](.*?)\[\/mail\]/,
          /\[mail\=(.*?)\](.*?)\[\/mail\]/,
          /\[b\](.*?)\[\/b\]/,
	    /\[i\](.*?)\[\/i\]/,
          /\[u\](.*?)\[\/u\]/,
          /\[center\](.*?)\[\/center\]/,
          /\[url\](http:\/\/[^ \\"\n\r\t<]*?)\[\/url\]/,
          /\[youtube\](.*?)\[\/youtube\]/);

replace = new Array(
	    "&lt;",
	    "&gt;",
	    "<br />",
          "<img src=\"$1\" alt=\"An image\">",
          "<a href=\"$1\" target=\"blank\">$2</a>",
          "<a href=\"http://$1\" target=\"blank\">$1</a>",
          "<a href=\"$1\" target=\"blank\">$1</a>",
	    "<a href=\"mailto:$1\">$1</a>",
          "<a href=\"mailto:$1\">$2</a>",
          "<b>$1</b>",
	    "<i>$1</i>",
	    "<u>$1</u>",
	    "</p><div style=\"text-align:center\">$1</div><p>",
          "<a href=\"$1\" target=\"blank\">$1</a>",
          "<object width=\"420\" height=\"355\"><param name=\"movie\" value=\"http://www.youtube.com/v/$1&color1=0xd6d6d6&color2=0xf0f0f0&border=0\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/$1&color1=0xd6d6d6&color2=0xf0f0f0&border=0\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"420\" height=\"355\"></embed></object>");
for(i = 0; i < search.length; i++) {
     text = text.replace(search[i],replace[i]);
}

return text;
}