//////////////////////////////////////////////////////////////////
//                                                              //
//    PerlSoft JavaScript                                       //
//    Email: info@perlsoft.de                                   //
//    WWW:   http:://www.perlsoft.de                            //
//    Dieses Script ist bestanteil des Perlsoft Gaestebuches    //
//                                                              //
//////////////////////////////////////////////////////////////////

// GB-Code-Arrays definieren
count = new Array('0','','0','','0','','0','','0','','0','','0','');
gbcode = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[url]','[/url]','[img]','[/img]','[email]','[/email]');
z='0';



////////////////////////////////////////
////////////////////////////////////////

//Eintrag wirklich löschen?
function delet_entry(MSG, URL) {

   if (document.post.action.value == 'delet') {
      Check = confirm(MSG);
      return Check;
   }
   else {
      return true;
   }
}

////////////////////////////////////////
////////////////////////////////////////

//Infopopup Code
function info_popup(mypage,myname,w,h,scroll) {
   var win = null;
   LeftPosition = (screen.width) ? (screen.width-w)/6 : 3;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 2;
   settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
   win = window.open(mypage,myname,settings)

   if(win.window.focus){win.window.focus();}
}

////////////////////////////////////////
////////////////////////////////////////

// Smilies an Courser Position einfuegen
function emotion(text,opener) {
   var txtarea = document.post.eintrag;

   text = ' ' + text + ' ';
   if (txtarea.createTextRange && txtarea.caretPos) {
      var caretPos = txtarea.caretPos;
      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
      txtarea.focus();
      }
   else {
      txtarea.value  += text;
      txtarea.focus();
   }
}

function emotion_popup(Zeichen) {
   opener.document.post.eintrag.value =
   opener.document.post.eintrag.value + ' ' + Zeichen + ' ';
}
////////////////////////////////////////
////////////////////////////////////////

// An Courserposition Code einfuegen...
// Code Beispiel von http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(text) {
   if (text.createTextRange) {
      text.caretPos = document.selection.createRange().duplicate();
   }
}

////////////////////////////////////////
////////////////////////////////////////

// Hilfe Nachrichten anzeigen
function hilfe(hilfetext) {
   document.post.hilfebox.value = hilfetext;
}

////////////////////////////////////////
////////////////////////////////////////

// Fkt schliessen
function close_code(nr) {
   var eingabe = document.post.eintrag;
   eingabe.value += gbcode[nr+1];
   var inhalt = eval('document.post.add'+nr+'.value');
   eval('document.post.add'+nr+'.value ="'+inhalt.substr(0,(inhalt.length-1))+'"');
   count[nr]='0';
   z--;

   eingabe.focus();
}

////////////////////////////////////////
////////////////////////////////////////

// Fkt Code einfuegen
function pastecode(buttonnr) {
   var eingabe = document.post.eintrag;

   // offene besondere Tags schliessen
   for(i=6; i<count.length; i++) {
      if(count[i]>='1' && i!=buttonnr && buttonnr>='6')
         close_code(i);
   }

   // Code Beginn einfuegen
   if (count[buttonnr]=='0') {
      eingabe.value += gbcode[buttonnr];
      eval('document.post.add'+buttonnr+'.value += "*"');
      z++;
      count[buttonnr]=z;
   }
   // Code Ende einfuegen
   else if (count[buttonnr]>='1' || buttonnr=='-1') {
      // Bei 'close all' erste Button-Nummer finden
      if(buttonnr=='-1') {
         for(i=0; i<count.length; i++) {
            if(count[i]=='1')
               buttonnr=i;
         }
      }
      // spaeter geoeffnete Tags schliessen
      if(buttonnr!='-1') {
         while(z>count[buttonnr]) {
            for(i=0; i<count.length; i++) {
               if(z==count[i] && count[i]!='1')
                  close_code(i);
            }
         }
         close_code(buttonnr);
      }
   }
   eingabe.focus();
}
