var theSelection = false;
var selectedText = quoteAuthor = '';

var no_text_selected = 'Zaznacz najpierw tekst';
    

function storeCaret(textEl)
{
    if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function emoticon(text)
{
    if (document.post.message.createTextRange && document.post.message.caretPos)
    {
	var caretPos = document.post.message.caretPos;
	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	document.post.message.focus()
    }
    else if (document.post.message.selectionStart != undefined)
    {
	document.post.message.value = document.post.message.value.substring(0, document.post.message.selectionStart) + text + document.post.message.value.substring(document.post.message.selectionStart);
	document.post.message.focus();
    }
    else
    {
	document.post.message.value += text;
	document.post.message.focus();
    }
}    


function ukryj_pokaz(element){
    if(document.getElementById(element).style.display==''){
	document.getElementById(element).style.display = 'none';
    }
    else
	document.getElementById(element).style.display = '';
}

function checkForm() {

	formErrors = false;

	if (document.post.message.value.length < 2) {
		formErrors = "Musisz wpisać wiadomość przed wysłaniem";
	}

	if (formErrors) {
		alert(formErrors);
		return false;
	} else {
		// bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}

			    
function quoteSelection()
{

    theSelection = false;
    if (selectedText) theSelection = selectedText;
    else if (document.selection && document.selection.createRange) theSelection = document.selection.createRange().text;
    if (theSelection)
    {	    
	emoticon( (document.post.message.value ? '' : '') + '[quote' + (quoteAuthor ? '="' + quoteAuthor + '"' : '') + ']' + theSelection + '[/quote]');
	document.post.message.focus();
	selectedText = quoteAuthor = theSelection = '';
    }
    else
    {
		alert(no_text_selected);
    }
}    

function qc()
{
    if (document.post && document.post.message)
    {
	document.getElementById('szybkaodpowiedzdiv').style.display='';
	quoteSelection();
	return false;
    }
}
			    
function qo() {
    selectedText = document.selection? document.selection.createRange().text : document.getSelection();
}
function qu(username)
{
    if (window.getSelection && window.getSelection() || document.selection && document.selection.createRange && document.selection.createRange().text)
    { 
	return true;
    }
    return false;
}
    				
