/** PRO EDIATCI TEXTU TEXTAREA **/
function checkBrowser()

{

this.ver=navigator.appVersion;

this.dom=document.getElementById?1:0;

this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;

this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;

this.ns6=(this.dom && parseInt(this.ver)>= 5)?1:0;

this.ns4=(document.layers && !this.dom)?1:0;

this.opr=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1)?1:0;

return this

}



function paste_strinL(strinL,isQuote,id){ 


if(strinL=='') alert('Vyberte prosím nejprve text, který chcete citovat.');

else{

if (isQuote == 1) {
	strinL = '[i]' + strinL + '[/i]' + '\n';
}

if (isQuote == 2) {
	strinL = '[b]' + strinL + '[/b]' + '\n';
}


var input=document.getElementById(id);
if(isQuote){
	input.value=input.value+strinL;
	input.focus();
}else{
 	var bbtags = strinL;
 	bbtags = bbtags.split('|');
	insertTag(bbtags[0],bbtags[1],input);
} 


}

}



function pasteSel() {

if(document.getSelection) selection=document.getSelection();

else if(document.selection) selection=document.selection.createRange().text;

else if(window.getSelection) selection=window.getSelection;

else selection='';

}



function getQuotation() {

var bw=new checkBrowser();

if ((bw.ns6 || bw.ie5 || bw.ie6 || bw.ns4)){// && !bw.opr) {

document.writeln('<a href="javascript:paste_strinL(selection,1)" onMouseDown="pasteSel()">Citovat</a>');

}

}


//Source: http://aktuell.de.selfhtml.org/artikel/javascript/bbcode/
function insertTag(aTag, eTag, input) {
  //var input = document.forms['formular'].elements['eingabe'];
  var bwr=new checkBrowser();
   input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
	    if(bwr.opr){
	    	range.move('character', 0);
			}else{
	      range.move('character', -eTag.length);
	    }
    } else {
    	if(bwr.opr){
    		range.move('character', 0);
    	}else{
      	range.moveStart('character', aTag.length + insText.length + eTag.length);
			}      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
   /* var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
   /* var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);*/
  }
  
}
