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);
	
function in_array(stringToSearch, arrayToSearch) {
	for (s = 0; s < arrayToSearch.length; s++) {
		thisEntry = arrayToSearch[s].toString();
		if (thisEntry == stringToSearch) {
			return true;
		}
	}
	return false;
}

function bbcode(txt, color, id){

	var codes = Array('ada', 'apache', 'asm', 'c', 'css', 'html4strict', 'java', 'nsis', 'pascal', 'php', 'qbasic', 'sql');
	if (txt == 'code'){
		txt = 'code';
		var add = '=' + document.getElementById('code_type').value;
	}
	else var add='';
	if (txt == 'url'){
		var lin = '[link]';
	}
	else var lin='';
	
	if (color) color = '='+color;
	else color='';
	
	
	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			//add http:// if it is not there
			if (txt=='url'){
				var prot = theSelection;
				if ( prot.indexOf('http://') && prot.indexOf('ftp://') && prot.indexOf('https://')&& prot.indexOf('mms://') && prot.indexOf('irc://')){
					theSelection = 'http://'+theSelection;
				}
			}
			// Add tags around selection
			document.selection.createRange().text = '['+txt+add+color+']' + theSelection + lin +'[/'+txt+']' ;
			document.getElementById(id).focus();
			theSelection = '';
			return;
		}
		else document.getElementById(id).value += '['+txt+add+color+']' + lin +'[/'+txt+']';
	}
	else
	{
		document.getElementById(id).value += '['+txt+add+color+']' + lin +'[/'+txt+']';
		return;
	}
}

function smilie(txt, id){
	var elem = new getObj(id);
	elem.obj.value += txt;
}