function insertAtCursor(myField, myValue, bbCode1, bbCode2, endOfLine) {
	var bbb;
	if(bbCode1=='[url=null]') {
		bbCode1=''; bbCode2='';
	}
	if(bbCode1=='[imgs]' && myValue==null) {
		bbCode1=''; bbCode2=''; myValue='';
	}
//	if (document.selection) {
//		//IE support
//		var str = document.selection.createRange().text;
//		myField.focus();
//		sel = document.selection.createRange();
//		sel.text = bbCode1 + myValue + bbCode2 + endOfLine;
//		if(myValue=='') {
//			bbb=bbCode2.length; sel.moveStart('character',-bbb); sel.moveEnd('character',-bbb);
//		}
//		sel.select();
//		myField.focus();
//		return;
//	}
	// Mozilla / Netscape support
	//else 
	if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		var bbb2, bbV, eoll;
		if (myValue=='') myValue = myField.value.substring(startPos, endPos);
		myField.value = myField.value.substring(0, startPos) + bbCode1 + myValue + bbCode2 + endOfLine + myField.value.substring(endPos, myField.value.length);
		if (myValue=='') {
			bbb=bbCode1.length; myField.selectionStart=startPos+bbb; myField.selectionEnd=endPos+bbb;
		} else {
			bbb=bbCode1.length;
			bbb2=bbCode2.length;
			bbV=myValue.length;
			eoll=endOfLine.length;
			myField.selectionStart=startPos+bbV+bbb+bbb2+eoll;
			myField.selectionEnd=myField.selectionStart;
		}
		myField.focus();
		return;
	} else {
		myField.value += myValue;
		return;
	}
}

function paste_strinL(strinL, isQuote, bbCode1, bbCode2, endOfLine) {
	if (isQuote==1) {
		bbCode1='[i]'; bbCode2='[/i]'; endOfLine='\n';
	}
	if (isQuote==2) {
		bbCode1='[b]'; bbCode2='[/b]'; endOfLine='\n';
	}
	//var input=document.pform.postmessage;
	var input=document.frmmain.txt_message;
	insertAtCursor(input, strinL, bbCode1, bbCode2, endOfLine);
}

function pasteSel() {
	selektion='';
	if (window.getSelection) {
		this.thisSel=window.getSelection();
		selektion=this.thisSel.toString();
	}
	else if (document.getSelection) selektion=document.getSelection();
	else if(document.selection) selektion=document.selection.createRange().text;
}

function addSmilie(strinL) {
   paste_strinL(' '+strinL+' ',3,'','','');
}

function pasteUrl() {
   paste_strinL('',4,'[url='+prompt('Always start the link with http://','http://www.here-your-url.com')+']','[/url]','')
}

function pasteBold() {
   paste_strinL('',3,'[b]','[/b]','')
}

function pasteUnderline() {
   paste_strinL('',3,'[u]','[/u]','')
}

function pasteItalic() {
   paste_strinL('',3,'[i]','[/i]','')
}