// 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_(smilie){
  var Smile = " :"+smilie+": ";
  var fost = document.forms['form'].elements['message'];
  fost.value = fost.value+= Smile;
  fost.focus();
}

function smile(smilie,ta){
  var Smile = " :"+smilie+": ";
  var fost = document.forms['form'].elements[''+ ta +''];
  fost.value = fost.value+= Smile;
  fost.focus();
}

function insert(aTag, eTag, ta) {
  var input = document.forms['form'].elements['message'];
  var input = document.forms['form'].elements[''+ ta +''];
  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(ta) {
    var theForm = document.forms['form'].elements['message'];
    var theForm = document.forms['form'].elements[''+ ta +''];
	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 namedemail(ta) {
    var theForm = document.forms['form'].elements['message'];
    var theForm = document.forms['form'].elements[''+ ta +''];
    var linkText = prompt("Geben Sie hier den eMailtext ein","");
	var prompttext;
    var theType = "email";

 	prompt_text = "Geben Sie hier die eMailadresse ein";
 	prompt_contents = "email@domain.de";

	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 imageinput2(ta) {
    var theForm = document.forms['form'].elements['message'];
    var theForm = document.forms['form'].elements[''+ ta +''];
    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 imageinput(theType,ta) {
    var theForm = document.forms['form'].elements['message'];
    var theForm = document.forms['form'].elements[''+ ta +''];
	var linkText = prompt("Geben Sie hier den Bildtitel ein","");
	var prompttext;
    //var theType = "img";

 	prompt_text = "Geben Sie hier die URL zum Bild ein";
 	prompt_contents = "http://";

	linkURL = prompt(prompt_text,prompt_contents);


	if ((linkURL != null) && (linkURL != "")) {
		var theText = '';

		if ((linkText != null) && (linkText != "")) {
   			theText = "["+theType+"="+linkText+"]"+linkURL+"[/"+theType+"]";
   		}
		else {
			theText = "["+theType+"]"+linkURL+"[/"+theType+"]";
		}
        theForm.value = theForm.value+= theText;
 	}
}
function preview(text)
{
	text = escape(text);
	text_preview = text;
	wnd = window.open('preview.php?&code='+text, 'preview','titlebar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=617, height=500, left=150, top=150');
	if (wnd.opener == null)
	{
		wnd.opener = self;
	}
}
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 checkLinksFormular() {
  var theForm = document.forms['form'].elements['url'];
  if( theForm.value == "" )
   {
    alert("Das Link-Feld muss ausgefüllt werden!");
    theForm.focus();
    return false;
   }
}
function checkKatFormular() {
  var theForm = document.forms['form'].elements['kat'];
  if( theForm.value == "" )
   {
    alert("Das Kategorie-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;
   }
}
function checkContentFormular() {
  var theForm = document.forms['form'].elements['message'];
  if( theForm.value == "" )
   {
    alert("Das News-Feld muss ausgefüllt werden!");
    theForm.focus();
    return false;
   }
}

function checkFAQFormular() {
  var theForm1 = document.forms['form'].elements['frage'];
  var theForm2 = document.forms['form'].elements['message'];
  if( theForm1.value == "" )
   {
    alert("Das Frage-Feld muss ausgefüllt werden!");
    theForm1.focus();
    return false;
   }
  if( theForm2.value == "" )
   {
    alert("Das Antwort-Feld muss ausgefüllt werden!");
    theForm2.focus();
    return false;
   }
}
function checkGalerieFormular() {
  var theForm = document.forms['form'].elements['titel'];
  if( theForm.value == "" )
   {
    alert("Das Titel-Feld muss ausgefüllt werden!");
    theForm.focus();
    return false;
   }
  var theForm = document.forms['form'].elements['datei'];
  if( theForm.value == "" )
   {
    alert("Es muss eine Datei augewählt werden");
    theForm.focus();
    return false;
   }
  if (document.forms['form'].elements['datei'].value != "") {
    var ext1 = document.forms['form'].elements['datei'].value;
    ext1 = ext1.substring(ext1.length-3,ext1.length);
    ext1 = ext1.toLowerCase();
    if(ext1 != 'gif' && ext1 != 'jpg' && ext1 != 'jpeg' && ext1 != 'png') {
      alert('Sie haben eine .'+ext1+' Datei gewählt, bitte wählen Sie eine Datei mit folgender Endung:\n*.gif\n*.jpg\n*.jpeg\n*.png');
      return false;
    }
  }
}

function checkChartsFormular() {
  var theForm1 = document.forms['form'].elements['artist'];
  var theForm2 = document.forms['form'].elements['titel'];
  if( theForm1.value == "" )
   {
    alert("Das Artist-Feld muss ausgefüllt werden!");
    theForm1.focus();
    return false;
   }
  if( theForm2.value == "" )
   {
    alert("Das Titel-Feld muss ausgefüllt werden!");
    theForm2.focus();
    return false;
   }
}
function checkAgendaFormular() {
  var theForm1 = document.forms['form'].elements['event'];
  var theForm2 = document.forms['form'].elements['loc'];
  if( theForm1.value == "" )
   {
    alert("Das Event-Feld muss ausgefüllt werden!");
    theForm1.focus();
    return false;
   }
  if( theForm2.value == "" )
   {
    alert("Das Location-Feld muss ausgefüllt werden!");
    theForm2.focus();
    return false;
   }
}
