// *** Text bei der Eingabeaufforderung ***********
standard = "Gib bitte den gewuenschten Text ein:";
texteingabe = "Gib bitte Deinen Text ein - ";
linkname = "Gib bitte den Linknamen an (optional).\nBei Galeriebild leer lassen für eine Verkleinerung!";
linkadresse = "Gib bitte die vollstaendige Adresse des Links an.";
emailname = "Gib bitte die Email Adresse ein.";
galerieid = "Bitte gib die ID aus der Bildergalerie ein\nDiese findest Du u.A. wenn Du in der Galerie\nauf einem Bild kurz mit der Maus stehen bleibst.";
listentyp = "Fuer eine numerierte Liste gib eine '1' an. Fuer eine alphabetische ein 'a'.\nFuer eine einfache Punktliste druecke ok.";
listenwerte = "Gib bitte die Listenpunkte ein und druecke anschliessend ok.\nAlternativ kannst Du 'Abbrechen' waehlen, um die Liste direkt fertigzustellen.";
highlightmsg = "Alles markiert und in die Zwischenablage kopiert.";
searchfailed = "Die Suche lieferte kein Ergebnis.";
admincss = "<link rel='stylesheet' href='style.css' type='text/css'>";


//**** Fuer Einzelzeichen *****
function singler(text) {
    mytextadd(' ' + text + ' ', document.myform);
}
//**** Pop-Fenster **********
function helpwindow(w,h,e) {
 window.open("include.php?path=misc/help.php&explain="+e,"helpwindow","toolbar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes,menubar=yes,width="+w+",height="+h);
 }
function smiliewindow(w,h) {
 window.open("popup.php?path=misc/smiliewindow.php&window_w_size="+w+"&window_h_size="+h,"smilies","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function windowsmilie(w,h,opt) {
 window.open("popup.php?path=smilies&window_w_size="+w+"&window_h_size="+h+"&option="+opt,"smilies","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function morelinkswindow(w,h,opt) {
 window.open("popup.php?path=morelinks&window_w_size="+w+"&window_h_size="+h+"&option="+opt,"morelinks","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function readfilewindow(w,h,opt) {
 window.open("popup.php?path=readfile&window_w_size="+w+"&window_h_size="+h+"&option="+opt,"readfile","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function finduserID(w,h,opt) {
 window.open("popup.php?path=finduser&window_w_size="+w+"&window_h_size="+h+"&option="+opt,"finduser","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function downloadwindow(w,h,opt) {
 window.open("popup.php?path=download&window_w_size="+w+"&window_h_size="+h+"&option="+opt,"download","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function attachment(w,h) {
 window.open("popup.php?path=script/attachment.php","attachment","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }
function previewWindow(w,h) {
 window.open("../popup.php?path=admin/popup/preview.php&window_w_size="+w+"&window_h_size="+h,"preview","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
 }

function previewTemplate() {
 var inf=document.edittemplate.template_value.value + admincss;
 popupwindow=window.open(", ","popup","toolbar=no,status=no,scrollbars=yes,resizable=yes");
 popupwindow.document.write("" + inf + "");
 }

//******** Wahl modus *******
function modus(mymode) {
 document.cookie = "mycodemode="+0+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
}
function mymode(myform) {
 if (myform.mode[0]) return true;
 else return false;
}

function mystatus(myvalue) {
 document.myform.status.value = eval(myvalue+"_text");
}

function setfocus(myform) {
 myform.content.focus();
}

var textmarkiert = "";
auswahltext = "";

//********* Textauswahl ******
function myselection(doit) {
    textmarkiert = (document.all) ? document.selection.createRange().text : document.getSelection();
    if (doit.createTextRange) doit.caretPos = document.selection.createRange().duplicate();
    else if (textmarkiert == "" && (doit.selectionStart || doit.selectionStart == '0'))
    {
        var start = doit.selectionStart;
        var end = doit.selectionEnd;
        textmarkiert = doit.value.substr(start, end-start);
    }
    return true;
}

function mytextadd(textneu, myform) {
    var input = myform.content;
    if (input.createTextRange && input.caretPos) {
        var caretPos = input.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? textneu + ' ' : textneu;
    } else if(typeof document.selection != 'undefined') {
        var range = document.selection.createRange();
        range.text = textneu;
        range = document.selection.createRange();
        range.moveStart('character', textneu.length);
        range.select();
    }
    else if(input.selectionStart || input.selectionStart == '0')
    {
        var start = input.selectionStart;
        var end = input.selectionEnd;
        input.value = input.value.substr(0, start) + textneu + input.value.substr(end);
        var pos = start + textneu.length;
        input.selectionStart = pos;
        input.selectionEnd = pos;
    }
    else
    {
        input.value = input.value + textneu;
    }
    auswahltext = "";
    setfocus(myform);
}


function mycode(myform,mycode,fensterausgabe) {
 setfocus(myform);
 if ((mymode(myform)) || (mycode=="IMG")) {
  if (textmarkiert) var direkttext=textmarkiert;
   else var direkttext=fensterausgabe;

  if (direkttext) var inserttext=direkttext;
   else inserttext = prompt(standard+"\n["+mycode+"]Ihr Text[/"+mycode+"]",direkttext);
  if ((inserttext != null) && (inserttext != "")) {
   auswahltext = "["+mycode+"]"+inserttext+"[/"+mycode+"]";
   mytextadd(auswahltext,myform);
  }
 }
 else {
  untersagt = false;
  for (i = 0; i < bbtags.length; i++) {
   if (bbtags[i] == mycode) untersagt = true;
  }
  if (!untersagt) {
   myform.content.value += "["+mycode+"]";
   arraypush(bbtags,mycode);
  }
 }
 setfocus(myform);
}

//**** Link und email UND GALERIE ADDON***********


function speciallink(myform,mytype) {
	if (textmarkiert) { var direkttext=textmarkiert; } else { var direkttext=""; }
	linktext = prompt(linkname,direkttext);
		var fensterausgabe;
		if (mytype == "GAL") {
			ausgabe = galerieid;
			ausgabeinhalt = "";
			}
		else if (mytype == "URL") {
			ausgabe = linkadresse;
			ausgabeinhalt = "http://";
			}
		else {
			ausgabe = emailname;
			ausgabeinhalt = "";
			}
	linkurl = prompt(ausgabe,ausgabeinhalt);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != "") || mytype == "GAL") {
			auswahltext = "["+mytype+"="+linkurl+"]"+linktext+"[/"+mytype+"] ";
			mytextadd(auswahltext,myform);

			}
		else{
			auswahltext = "["+mytype+"]"+linkurl+"[/"+mytype+"] ";
			mytextadd(auswahltext,myform);

		}
	}
}

//**** Marcos YouTube***********


function videoinsert(myform,mytype) {
	if (textmarkiert) { var direkttext=textmarkiert; } else { var direkttext=""; }
		var fensterausgabe;
		if (mytype == "VIDEO") {
			ausgabe = "YouTube, MyVideo, GoogleVideo oder ClipFish Adresse";
			}
	linkurl = prompt(ausgabe,direkttext);
	if ((linkurl != null) && (linkurl != "")) {
		if (mytype == "VIDEO") {
			auswahltext = "["+mytype+"="+linkurl+"][/"+mytype+"] ";
			}
		mytextadd(auswahltext,myform);
	}
}


// ***** liste **************
function createlist(myform) {
	listtype = prompt(listentyp, "");
	if ((listtype == "a") || (listtype == "1")) {
		mylist = "[list="+listtype+"]\n";
		listend = "[/list="+listtype+"] ";
		}
	else {
		mylist = "[list]\n";
		listend = "[/list] ";
		}
	listentry = "initial";
	while ((listentry != "") && (listentry != null)) {
		listentry = prompt(listenwerte, "");
		if ((listentry != "") && (listentry != null))
			mylist = mylist+"[*]"+listentry+"\n";
		}
	auswahltext = mylist+listend;
	mytextadd(auswahltext,myform);
}

var NS4=(document.layers);
var IE4=(document.all);
var win=window;
var n=0;
function highlightSearch(str) {
 var txt, i, found;
 if (str == '') return false;
 if (NS4) {
  if (!win.find(str)) while(win.find(str, false, true)) n++;
  else n++;
  if (n == 0) alert(searchfailed);
  }
 if (IE4) {
  txt = win.document.body.createTextRange();
  for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
   txt.moveStart('character', 1);
   txt.moveEnd('textedit');
   }
  if (found) {
   txt.moveStart('character', -1);
   txt.findText(str);
   txt.select();
   txt.scrollIntoView();
   n++;
   }
  else {
   if (n > 0) {n = 0; findit(str);}
   else alert(searchfailed);
   }
  }
 return false;
 }

function HighlightAndCopy() {
 var tempval=eval("document.edittemplate.template_value")
 tempval.focus()
 tempval.select()
 if (document.all){
  therange=tempval.createTextRange()
  therange.execCommand("Copy")
  window.status=highlightmsg
  setTimeout("window.status=''",1800)
  }
 }

function checkall(status,theelement) {
 for (i=0;i<document.myform.length;i++) {if(document.myform.elements[i].name=="" + theelement + "[]") document.myform.elements[i].checked=status;}
 }

function selectUser() {
 if(document.finduser.User.options[document.finduser.User.selectedIndex].value != -1) {
  opener.document.myform.im_receiver.value = document.finduser.User.options[document.finduser.User.selectedIndex].value; opener.myform.im_receiver.focus();
  }
 }
function selectBuddy() {
 if(document.finduser.Buddy.options[document.finduser.Buddy.selectedIndex].value != -1) {
  opener.document.myform.im_receiver.value = document.finduser.Buddy.options[document.finduser.Buddy.selectedIndex].value;
  opener.myform.im_receiver.focus();
  }
 }

