// browser detection
var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);
var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));

function jstest () {
  document.write("")
}

function smile(fost, smilie){
  var Smile = " :"+smilie+": ";
  fost.value = fost.value+= Smile;
  fost.focus();
}
function insert(aTag, eTag) {
  var input = document.forms['form'].elements['message'];
  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) {
      range.move('character', -eTag.length);
    } 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);
  }
}

function namedlink() {
    var theForm = document.forms['form'].elements['message'];
	var linkText = prompt("Geben Sie hier den Linktext ein","");
	var prompttext;
    var theType = "url";

 	prompt_text = "Geben Sie hier den Linktext ein";
 	prompt_contents = "http://";

	linkURL = prompt(prompt_text,prompt_contents);


	if ((linkURL != null) && (linkURL != "")) {
		var theText = '';

		if ((linkText != null) && (linkText != "")) {
   			theText = "["+theType+"="+linkURL+"]"+linkText+"[/"+theType+"]";
   		}
		else {
			theText = "["+theType+"]"+linkURL+"[/"+theType+"]";
		}
        theForm.value = theForm.value+= theText;
 	}
}

function imageinput() {
    var theForm = document.forms['form'].elements['message'];
	var prompttext;
    var theType = "img";
    var theText = '';
    
 	prompt_text = "Geben Sie hier die URL zum Bild ein";
 	prompt_contents = "http://";

	imgURL = prompt(prompt_text,prompt_contents);


	if ((imgURL != null) && (imgURL != "")) {
        theText = "["+theType+"]"+imgURL+"[/"+theType+"]";
   		}

        theForm.value = theForm.value+= theText;
}

function checkNewsFormular() {
  var theForm = document.forms['form'].elements['message'];
  if( theForm.value == "" )
   {
    alert("Das News-Feld muss ausgefüllt werden!");
    theForm.focus();
    return false;
   }
}
function checkIPFormular() {
  var theForm = document.forms['form'].elements['ipadresse'];
  if( theForm.value == "" )
   {
    alert("Das IP-Feld muss ausgefüllt werden!");
    theForm.focus();
    return false;
   }
}
