				/*
				 * bbCode control by subBlue design
				 * www.subBlue.com
				 *
				 * Modified by Grant Bartlett for OCMPS
				 *
				 */
				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_win   = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
				var is_mac    = (clientPC.indexOf("mac")!=-1);
				                       
//				function AddButtons
				function storeCaret(textEl) {
					if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
				}            	                
				function boldselected(textbox,buttonname) {
					if (textbox.bold)
						buttonname.value="Bold";
					else
						buttonname.value="Bold*";
					textbox.prev = textbox.value;
					if ((clientVer >= 4) && is_ie && is_win) {
						theSelection = document.selection.createRange().text; // Get text selection
					} else {                 
						textbox.bold=!textbox.bold;
						if (textbox.bold)
							textbox.value += "<b>";
						else
							textbox.value += "</b>";
						textbox.focus();
						return;
					}
					if (theSelection) {
						// Add tags around selection
						if ((clientVer >= 4) && is_ie && is_win)
							document.selection.createRange().text = "<b>" + theSelection + "</b>";
						theSelection = '';
						return;
					} else {
						textbox.bold=!textbox.bold;
						if (textbox.bold)
							textbox.value += "<b>";
						else
							textbox.value += "</b>";
						return;
					}
				}
				function helpbold(textbox) {      
					if (is_ie) {
						if (document.selection.createRange().text)
							textbox.value="Bold the selected text";
						else
							textbox.value="Please select some text";
					} else
						textbox.value="Insert bold tags";
				}                                         
				function helpbreak(textbox) {
					textbox.value="Insert a line break";
				}                                          
				function helplist(textbox) {
					textbox.value="Make the selection into a list";
				}                                          
				function helpnum(textbox) {
					textbox.value="Make the selection into a numbered list";
				}                                          
				function helphref(textbox) {
					textbox.value="Make the selected text a link";
				}                                          
				function helpmailto(textbox) {
					textbox.value="Make the selected text an email link";
				}                                          
				function helpundo(textbox) {
					textbox.value="Undo the previous action";
				}                                          
				function clearhelp(textbox) {
					textbox.value="";
				}
				function undo(textbox,buttonname) {    
					if (textbox.prev)
					textbox.value=textbox.prev;
					textbox.focus();
//					storeCaret(textbox);
	//				textbox.focus();
				}
				function breakselected(textbox,buttonname) {                                                  
					textbox.prev=textbox.value;
					textbox.caretPos.text='<br />';
					textbox.focus();

				}                                    
				
				function listselected(textbox,buttonname) {
					textbox.prev=textbox.value;    
					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 = "<ul>\n    <li>" + theSelection.replace(new RegExp('([\\f\\n\\r\\t\\v])+', 'g'),"\n    <li>") + "\n</ul>";
						theSelection = '';
						return;
					}
				}
				
				function numlistselected(textbox,buttonname) {
					textbox.prev=textbox.value;    
					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 = "<ol>\n    <li>" + theSelection.replace(new RegExp('([\\f\\n\\r\\t\\v])+', 'g'),"\n    <li>") + "\n</ol>";
						theSelection = '';
						return;
					}
				}

				function hrefselected(textbox,buttonname) {
					textbox.prev=textbox.value;    
					if ((clientVer >= 4) && is_ie && is_win)
						theSelection = document.selection.createRange().text; // Get text selection
					if (theSelection) {
						// Add tags around selection
						var my_link = prompt("Enter URL:","http://");
						if (my_link != null) {
						    document.selection.createRange().text = "<a href=\"" + my_link + "\">" + theSelection + "</a>";
						}
						
						theSelection = '';
						return;
					}
				}

				function mailtoselected(textbox,buttonname) {
					textbox.prev=textbox.value;    
					if ((clientVer >= 4) && is_ie && is_win)
						theSelection = document.selection.createRange().text; // Get text selection
					if (theSelection) {
						// Add tags around selection
						var my_link = prompt("Enter Email Address:","");
						if (my_link != null) {
						    document.selection.createRange().text = "<a href=\"mailto:" + my_link + "\">" + theSelection + "</a>";
						}
						
						theSelection = '';
						return;
					} else {
//						document.index.errorline.value="no text selected";	
					}
				}