﻿	
function wrapSelection(taDest, strFore, strAft)
{
	taDest.focus();
	if (taDest.setSelectionRange)
	{
		var selStart = taDest.selectionStart, selEnd = taDest.selectionEnd;
		taDest.value = taDest.value.substring(0, selStart) + strFore + taDest.value.substring(selStart, selEnd) + strAft + taDest.value.substring(selEnd);
		taDest.setSelectionRange(selStart + strFore.length, selEnd + strFore.length);
	}
	else if (document.selection)
	{
		var oRange = document.selection.createRange();
		var numLen = oRange.text.length;
		oRange.text = strFore + oRange.text + strAft;
		//moveSelectionRange(oRange, -numLen, -strAft.length);
	}
	else
	{
		taDest.value += strFore + strAft;
	}
}

function imgcode(taDest, imgcode, prompttext, strAddParams)
{
	tag_prompt = img_addr;
	inserttext = prompt(tag_prompt+"\n["+imgcode+"]xxx[/"+imgcode+"]",prompttext);
	if ((inserttext != null) && (inserttext != ""))
	taDest.value += "["+imgcode+strAddParams+"]"+inserttext+"[/"+imgcode+"]";
	taDest.focus();
}

function namedlink(taDest, thetype, strAddParams)
{
	linktext = prompt(link_text_prompt,"");
	var prompttext;

	prompt_text = link_url_prompt;
	prompt_contents = "http://";
	
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != ""))
	{
		if ((linktext == null) || (linktext == "")) 
			linktext = linkurl;
		
		taDest.value += "["+thetype+"="+linkurl+strAddParams+"]"+linktext+"[/"+thetype+"]";
	}
	taDest.focus();
}

function namedmailto(taDest, thetype, strAddParams)
{
	linktext = prompt(link_text_prompt,"");
	var prompttext;

	prompt_text = link_mail_prompt;
	prompt_contents = "";
	
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != ""))
	{
		if ((linktext == null) || (linktext == "")) 
			linktext = linkurl;
		
		taDest.value += "["+thetype+"=mailto:"+linkurl+strAddParams+"]"+linktext+"[/"+thetype+"]";
	}
	taDest.focus();
}

	var b_help = 'Tekst pogrubiony: [B]tekst[/B] - Zaznacz tekst i wciśnij przycisk';
	var i_help = 'Tekst kursywą: [I]tekst[/I] - Zaznacz tekst i wciśnij przycisk';
	var u_help = 'Tekst podkrślony: [U]tekst[/U] - Zaznacz tekst i wciśnij przycisk';
	var p_help = 'Wstaw obrazek: [IMG]http://adres_obrazka[/IMG] - wciśnij przycisk i podaj adres pliku';
	var pr_help = 'Wstaw obrazek z prawej strony tekstu - wciśnij przycisk i podaj adres pliku';
	var pl_help = 'Wstaw obrazek z lewej strony tekstu - wciśnij przycisk i podaj adres pliku';
	var w_help = 'Wstaw link do strony: [URL]http://adres_www[/URL] - wciśnij przycisk i podaj adres strony';
	var wb_help = 'Wstaw link do strony - otwarcie w nowym oknie - wciśnij przycisk i podaj adres strony';
	var wm_help = 'Wstaw link do adresu email - wciśnij przycisk i podaj adres';
	var a_help = 'Zamknij wszystkie otwarte tagi bbCode';
	var img_addr = 'Podaj adres obrazka';
	var link_text_prompt = 'Wpisz tekst który będzie pokazywany jako nazwa linku';
	var link_url_prompt = 'Podaj adres do strony www';
	var link_mail_prompt = 'Podaj adres email';	

function helpline(taDest, help)
{
	taDest.value = eval(help + "_help");
}
