function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		// MSIE
		var caretPos = textEl.caretPos;
		caretPos.text =
			caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
			text + ' ' : text;
	} else if(textEl.selectionStart && textEl.setSelectionRange) {
		// Mozilla 1.3+
		var val = textEl.value;
		var cpos = textEl.selectionStart;
		var fpos = cpos + text.length;

		var before = val.substr(0,cpos);
		var after = val.substr(cpos, val.length);
		var aspace = after.charAt(0) == ' ' ? "" : " ";
		var bspace = before.charAt(before.length) == ' ' ? "" : " ";

		textEl.value = before + bspace + text + aspace + after;
		textEl.setSelectionRange(fpos+1,fpos+1); // set cursor pos to end of text
		textEl.focus();
	} else {
		textEl.value  = textEl.value + text; // otherwise just append
	}

	return true;
} // end insertAtCaret

	function DoPrompt(action,elem) {
		var currentMessage = document.getElementById(elem).value;

		if (action == "url_ki") {
			var thisURL = prompt("Gépelje be a weboldal pontos URL-jét.", "http://");
			if (thisURL == null){return;}

			var thisTitle = prompt("Írja be a weboldal nevét, melyre linkelni akar. Pl: XY weboldala.", "");
			if (thisTitle == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[a class=menu_bal href=" + thisURL + " target=blank]" + thisTitle + "[/a]" + '');
			document.getElementById(elem).focus();
			return;
		}

		if (action == "url_be") {
			var thisURL = prompt("Gépelje be a modul nevét.", "");
			if (thisURL == null){return;}

			var thisTitle = prompt("Írja be a weboldal nevét, melyre linkelni akar. Pl: XY weboldala.", "");
			if (thisTitle == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[a class=menu_bal href=index.php?modul=" + thisURL + "]" + thisTitle + "[/a]" + '');
			document.getElementById(elem).focus();
			return;
		}

		if (action == "kepes") {
			var thisURL = prompt("Gépelje be a weboldal pontos URL-jét.", "http://");
			if (thisURL == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[a href='" + thisURL + "']" + "[kep]" + "[/a]" + '');
			document.getElementById(elem).focus();
			return;
		}

		if (action == "email") {
			var thisEmail = prompt("Gépelje be a pontos e-mail-címet, melyet be akar illeszteni.", "");
			if (thisEmail == null){return;}

			insertAtCaret(document.getElementById(elem), ' ' + "[EMAIL]" + thisEmail + "[/EMAIL]" + ' ' );
			document.getElementById(elem).focus();
			return;
		}

		if (action == "bold") {
			var thisBold = prompt("Gépelje be a kövér betüs szöveget.", "");
			if (thisBold == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[b]" + thisBold + "[/b]" + '' );
			document.getElementById(elem).focus();
			return;
		}

		if (action == "kiemel") {
			var thisKiemel = prompt("Gépelje be a nagy betüs szöveget.", "");
			if (thisKiemel == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[k]" + thisKiemel + "[/k]" + '' );
			document.getElementById(elem).focus();
			return;
		}

		if (action == "nyil") {
			insertAtCaret(document.getElementById(elem), '' + "[v]" + '' );
			document.getElementById(elem).focus();
			return;
		}

		if (action == "nagy") {
			var thisNagy = prompt("Gépelje be a nagy betüs szöveget.", "");
			if (thisNagy == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[n]" + thisNagy + "[/n]" + '' );
			document.getElementById(elem).focus();
			return;
		}

		if (action == "image_old") {
			var thisImage = prompt("Gépelje be a kép pontos linkjét (URL-jét).", "http://");
			if (thisImage == null){return;}

			insertAtCaret(document.getElementById(elem), ' ' + "[IMG]" + thisImage + "[/IMG]" + ' ' );
			document.getElementById(elem).focus();
			return;
		}

		if (action == "image") {
			var thisImage = prompt("Gépelje be a kép pontos nevét.", "");
			if (thisImage == null){return;}

			insertAtCaret(document.getElementById(elem), '' + "[img " + thisImage + " /img]" + '' );
			document.getElementById(elem).focus();
			return;
		}


	}
function refresh(id,elem){

prt=document.getElementById(elem).value.replace('\n',"<br />");
prt=prt.replace('\n',"<br />");

document.getElementById(id).innerHTML=prt;
return;

}