<script type="text/JavaScript">
        var theSelection = false;

	var clientPC = navigator.userAgent.toLowerCase();
	var clientVer = parseInt(navigator.appVersion);

	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_win   = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
	var is_mac    = (clientPC.indexOf("mac")!=-1);
	var Quote = 0;
	var hascolor=0;
	var hassize=0;
	var hasfont=0;
	var Bold  = 0;
	var Italic = 0;
	var Underline = 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 web = 0;
	var video = 0;
	var stream = 0;
	var ram = 0;
	var hr = 0;
	var grad = 0;
	var plain = 0;
	var bbcode = new Array(0);
	function BBCimg(form,field) {
		var FoundErrors = '';
		var enterURL   = prompt("Enter the image URL","http://");
		if (!enterURL) {
			FoundErrors += "You didn't write the image URL";
		}
		if (FoundErrors) {
			alert("Error :"+FoundErrors);
			return;
		}
		var ToAdd = "[img]"+enterURL+"[/img]";
		document.forms[form].elements[field].value+=ToAdd;
		document.forms[form].elements[field].focus();
	}
function BBCmail(form,field) {
        var FoundErrors = '';
        var entermail   = prompt("Enter the Email Address","");
        if (!entermail) {
                FoundErrors += "You didn't write the Email Address";
        }
        if (FoundErrors) {
                alert("Error :"+FoundErrors);
                return;
        }
        var ToAdd = "[email]"+entermail+"[/email]";
        document.forms[form].elements[field].value+=ToAdd;
        document.forms[form].elements[field].focus();
}
function PostWrite(text,form,field) {
  // Attempt to create a text range (IE).
  var textarea = document.forms[form].elements[field];
  if (textarea.createTextRange && textarea.caretPos) {
    var caretPos = textarea.caretPos;
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?    text + ' ' : text;
    caretPos.select();
  }
  // Mozilla text range replace.
  else if (typeof(textarea.selectionStart) != "undefined") {
    var begin = textarea.value.substr(0, textarea.selectionStart);
    var end = textarea.value.substr(textarea.selectionEnd);
    textarea.value = begin + text + end;
    if (textarea.setSelectionRange) {
      textarea.focus();
      textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
    }
  }
  // Just put it on the end.
  else {
    textarea.value += text;
    textarea.focus(textarea.value.length - 1);
  }

}
function BBCitalic(form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[I]" + theSelection + "[/I]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (Italic == 0) {
		ToAdd = "[I]";
		document.forms[form].italic.src = "modules/News/images/italic1.gif";
		Italic = 1;
	} else {
		ToAdd = "[/I]";
		document.forms[form].italic.src = "modules/News/images/italic.gif";
		Italic = 0;
	}
	PostWrite(ToAdd,form,field);
}
function BBCcode(form,field,code) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "["+code+"]" + theSelection + "[/"+code+"]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (bbcode[code+form+field] == null) {
		ToAdd = "["+code+"]";
		document.forms[form].elements[code].src = "modules/News/images/"+code+"1.gif";
		bbcode[code+form+field]= 1;
	} else {
		ToAdd = "[/"+code+"]";
		document.forms[form].elements[code].src = "modules/News/images/"+code+".gif";
		bbcode[code+form+field] = null;
	}
	PostWrite(ToAdd,form,field);
}

function BBCquote(form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[quote]" + theSelection + "[/quote]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (Quote == 0) {
		ToAdd = "[quote]";
		document.forms[form].quote.src = "modules/News/images/quote1.gif";
		Quote = 1;
	} else {
		ToAdd = "[/quote]";
		document.forms[form].quote.src = "modules/News/images/quote.gif";
		Quote = 0;
	}
	PostWrite(ToAdd,form,field);
}

function BBCbold(form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[B]" + theSelection + "[/B]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (Bold == 0) {
		ToAdd = "[B]";
		document.forms[form].bold.src = "modules/News/images/bold1.gif";
		Bold = 1;
	} else {
		ToAdd = "[/B]";
		document.forms[form].bold.src = "modules/News/images/bold.gif";
		Bold = 0;
	}
	PostWrite(ToAdd,form,field);
}
function BBCflash(form,field) {
	var FoundErrors = '';
	var enterFURL   = prompt("Enter the flash file URL", "http://");
	if (!enterFURL)    {
		FoundErrors += "You didn't write the flash file URL";
	}
		var enterW   = prompt("Enter the flash width", "250");
	if (!enterW)    {
		FoundErrors += "You didn't write the flash width";
	}
	var enterH   = prompt("Enter the flash height", "250");
	if (!enterH)    {
		FoundErrors += "You didn't write the flash height";
	}
	if (FoundErrors)  {
		alert("Error :"+FoundErrors);
		return;
	}
	var ToAdd = "[flash width="+enterW+" height="+enterH+"]"+enterFURL+"[/flash]";
	document.forms[form].elements[field].value+=ToAdd;
	document.forms[form].elements[field].focus();
}
function BBCstream(form,field) {
        var FoundErrors = '';
        var enterURL   = prompt("Please write stream file URL","http://");
        if (!enterURL) {
                FoundErrors += "You didn't write the file URL";
        }
        if (FoundErrors) {
                alert("Error :"+FoundErrors);
                return;
        }
        var ToAdd = "[stream]"+enterURL+"[/stream]";
        document.forms[form].elements[field].value+=ToAdd;
        document.forms[form].elements[field].focus();
}
function BBCchfont(font,form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[font="+font+"]" + theSelection + "[/font]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (hasfont==0) {
		ToAdd = "[font="+font+"]";
		hasfont = 1;
	} else {
		ToAdd = "[/font]";
		hasfont = 0;
	}
	PostWrite(ToAdd,form,field);
}
function BBCchcolor(color,form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[color="+color+"]" + theSelection + "[/color]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (hascolor==0) {
		ToAdd = "[color="+color+"]";
		hascolor = 1;
	} else {
		ToAdd = "[/color]";
		hascolor = 0;
	}
	PostWrite(ToAdd,form,field);
}
function BBCchsize(size,form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[size="+size+"]" + theSelection + "[/size]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (hassize==0) {
		ToAdd = "[size="+size+"]";
		hassize = 1;
	} else {
		ToAdd = "[/size]";
		hassize = 0;
	}
	PostWrite(ToAdd,form,field);
}
function BBCunder(form,field) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "[U]" + theSelection + "[/U]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (Underline == 0) {
		ToAdd = "[U]";
		document.forms[form].under.src = "modules/News/images/under1.gif";
		Underline = 1;
	} else {
		ToAdd = "[/U]";
		document.forms[form].under.src = "modules/News/images/under.gif";
		Underline = 0;
	}
	PostWrite(ToAdd,form,field);
}

function BBCurl(form,field) {

	var FoundErrors = '';
	var enterURL   = prompt("Enter the URL", "http://");
	var enterTITLE = prompt("Enter the page name", "Web Page Name");
	if (!enterURL)    {
		FoundErrors += "You didn't write the URL";
	}
	if (!enterTITLE)  {
		FoundErrors += "You didn't write the page name";
	}
	if (FoundErrors)  {
		alert("Error :"+FoundErrors);
		return;
	}
	var ToAdd = "[url="+enterURL+"]"+enterTITLE+"[/url]";
	document.forms[form].elements[field].value+=ToAdd;
	document.forms[form].elements[field].focus();
}
function BBCcenter(form,field,code) {
	if(code=="left" || code=="right" || code=="center" || code=="justify"){
		type="align";
	}
	else  type="marq";
	if(code=="marql")code1="left";
	else if(code=="marqr")code1="right";
	else if(code=="marqd")code1="down";
	else if(code=="marqu")code1="up";
	else code1=code;
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (theSelection != '') {
		document.selection.createRange().text = "["+type+"="+code1+"]" + theSelection + "[/"+type+"]";
		document.forms[form].elements[field].focus();
		return;
		}
	}
	if (bbcode[code+form+field] == null) {
		ToAdd = "["+type+"="+code1+"]";
		document.forms[form].elements[code].src = "modules/News/images/"+code+"1.gif";
		bbcode[code+form+field] = 1;
	} else {
		ToAdd = "[/"+type+"]";
		document.forms[form].elements[code].src = "modules/News/images/"+code+".gif";
		bbcode[code+form+field] = null;
	}
	PostWrite(ToAdd,form,field);
}
function BBChr(form, field) {
  document.forms[form].elements[field].value+="[hr]";
  document.forms[form].elements[field].focus();
}

	</script>
<?php
function bbcode_table($form,$field){
	global $bgcolor1;
?>

	<table width=100% border=0>
	<tr>
        <td>
	<?php
	Echo '<select name="font" onChange="BBCchfont(this.options[this.selectedIndex].value,\''.$form.'\',\''.$field.'\')" size="1">';
	?>
	font
	<option value="Arial">Arial</option>
	<option value="Book Antiqua">Book Antiqua</option>
	<option value="Century Gothic">Century Gothic</option>
	<option value="Courier New">Courier New</option>
	<option value="Georgia">Georgia</option>
	<option value="Impact">Impact</option>
	<option value="Tahoma">Tahoma</option>
	<option value="Times New Roman">Times New Roman</option>
	<option value="Verdana" selected>Verdana</option></select>
	<?
	Echo '<select name="size" onChange="BBCchsize(this.options[this.selectedIndex].value,\''.$form.'\',\''.$field.'\')" size="1">';
	?>
	<option value="-2">-2</option>
	<option value="-1">-1</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3" selected>3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
	<option value="10">10</option>
	<option value="11">11</option>
	<option value="12">12</option>
	<option value="13">13</option>
	<option value="14">14</option>
	<option value="15">15</option>
	<option value="16">16</option>
	<option value="17">17</option>
	<option value="18">18</option>
	<option value="19">19</option>
	<option value="20">20</option></select>
	<?
	Echo '<select name="color" onChange="BBCchcolor(this.options[this.selectedIndex].value,\''.$form.'\',\''.$field.'\')" size="1">';
	?>
	<option value="White" style="color:white;">White</option>
	<option value="Black" style="color:black;">Black</option>
	<option value="Red" style="color:red;">Red</option>
	<option value="Yellow" style="color:yellow;">Yellow</option>
	<option value="Pink" style="color:pink;">Pink</option>
	<option value="Green" style="color:green;">Green</option>
	<option value="Orange" style="color:orange;">Orange</option>
	<option value="Purple" style="color:purple;">Purple</option>
	<option value="Blue" style="color:blue;">Blue</option>
	<option value="Beige" style="color:beige;">Beige</option>
	<option value="Brown" style="color:brown;">Brown</option>
	<option value="Teal" style="color:teal;">Teal</option>
	<option value="Navy" style="color:navy;">Navy</option>
	<option value="Maroon" style="color:maroon;">Maroon</option>
	<option value="LimeGreen" style="color:limegreen;">LimeGreen</option></select>
	<br><br>
	<a href="javascript:BBCbold(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=bold src="modules/News/images/bold.gif" border="0" width="30" height="27" alt="bold"></a>
	<a href="javascript:BBCitalic(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=italic src="modules/News/images/italic.gif" border="0" width="30" height="27" alt="italicize"></a>
	<a href="javascript:BBCunder(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=under src="modules/News/images/under.gif" border="0" width="30" height="27" alt="underline"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'center')"><img name=center src="modules/News/images/center.gif" border="0" width="30" height="27" alt="center"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'left')"><img name=left src="modules/News/images/left.gif" border="0" width="30" height="27" alt="left"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'right')"><img name=right src="modules/News/images/right.gif" border="0" width="30" height="27" alt="right"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'justify')"><img name=justify src="modules/News/images/justify.gif" border="0" width="30" height="27" alt="justify"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'marql')"><img name=marql src="modules/News/images/marql.gif" border="0" width="30" height="27" alt="Marque to Left"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'marqr')"><img name=marqr src="modules/News/images/marqr.gif" border="0" width="30" height="27" alt="Marque to Right"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'marqd')"><img name=marqd src="modules/News/images/marqd.gif" border="0" width="30" height="27" alt="Marque to Down"></a>
	<a href="javascript:BBCcenter(<?echo '\''.$form.'\',\''.$field.'\''?>,'marqu')"><img name=marqu src="modules/News/images/marqu.gif" border="0" width="30" height="27" alt="Marque to Up"></a>
	<a href="javascript:BBChr(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=hr src="modules/News/images/hr.gif" border="0" width="30" height="27" alt="h-Line"></a>
	<a href="javascript:BBCurl(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=url src="modules/News/images/url.gif" border="0" width="30" height="27" alt="hyperlink"></a>
	<a href="javascript:BBCmail(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=mail src="modules/News/images/email.gif" border="0" width="30" height="27" alt="email"></a>
	<a href="javascript:BBCimg(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img src="modules/News/images/img.gif" border="0" width="30" height="27" alt="image"></a>
	<a href="javascript:BBCflash(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img src="modules/News/images/flash.gif" border="0" width="30" height="27" alt="flash"></a>
	<a href="javascript:BBCcode(<?echo '\''.$form.'\',\''.$field.'\''?>,'code')"><img name=code src="modules/News/images/code.gif" border="0" width="30" height="27" alt="code"></a>
	<a href="javascript:BBCcode(<?echo '\''.$form.'\',\''.$field.'\''?>,'php')"><img name=php src="modules/News/images/php.gif" border="0" width="30" height="27" alt="PHP"></a>
	<a href="javascript:BBCquote(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img name=quote src="modules/News/images/quote.gif" border="0" width="30" height="27" alt="quote"></a>
	<a href="javascript:BBCstream(<?echo '\''.$form.'\',\''.$field.'\''?>)"><img src="modules/News/images/sound.gif" border="0" width="30" height="27" alt="stream"></a>
	</td></tr>
<?
	echo "<tr><td>";
	echo "</tr></table>";
	echo "</td></tr></table>";
}
?>