
function fm() {
 document.getElementById("message").focus();
}
function hideEmotions()
{
 	var e = document.getElementById("eTable");
	e.style.visibility = "hidden";
}
function emotions(){
	var e = document.getElementById("eTable");	
	if (e.style.visibility == "visible"){
		e.style.visibility = "hidden";
		fm();
	}
	else {
		e.style.visibility = "visible";
	}
}

function emoticon(theSmilie)
{
	doInsert(" " + theSmilie + " ", "", false);
	emotions();
}

var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));
var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
 
function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.getElementById("message");
	if ( (myVersion >= 4) && is_ie && is_win)
	{
		if(obj_ta.isTextEdit){ 
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;	rng.text = ibTag;
			}
		}
		else{
			if(isSingle) isClose = true;
			obj_ta.value += ibTag;
		}
	}
	else if (document.getSelection) {  
		var text = obj_ta.value;
		var selTxt = text.substring(obj_ta.selectionStart, obj_ta.selectionEnd);
		var cursorPos = obj_ta.selectionStart;	
		if(ibClsTag != "" && selTxt.length > 0)
			ibTag += selTxt + ibClsTag;
		else if(isSingle)
			isClose = true;
 		cursorPos += ibTag.length; 	
		replaceSelection(obj_ta, ibTag);  
		obj_ta.focus();
		obj_ta.selectionStart = cursorPos;
		obj_ta.selectionEnd = cursorPos;      
	} 
	else
	{
		if(isSingle)
			isClose = true;
		obj_ta.value += ibTag;
	}
	return isClose;
}	

function replaceSelection(o, s)
{   var s2 = o.value; o.value = s2.substring(0, o.selectionStart) + s + s2.substr(o.selectionEnd);
}

