window.onDomReady = function (funktion)
{
   // W3C-konformer browser
   if (document.addEventListener)
   {
      // falls DOM komplett geladen, Funktion starten
      document.addEventListener('DOMContentLoaded', funktion, false);
   }
   // IE (habe im IE8 getestet, geht scheinbar nicht)
   else
   {
      document.onreadystatechange = function()
      {
         // DOM ist bereit
         if (document.readyState == 'interactive' || document.readyState == 'complete')
         {
            funktion();
         }
      }
   }
}

function $(id)
{
   return document.getElementById(id);
}

function SubmitButton(formular)
{
   document.forms[formular].abschicken.value = 'Bitte warten...';
   document.forms[formular].abschicken.disabled = true;
}

function einfuegen(StartTag, EndeTag, Feld, isId)
{
   var input, range, insText, start, end, insText, pos;

   if (StartTag == '[BILD=null]' || StartTag == '[LINK URI=null NAME=null]')
   {
      StartTag = '';
   }

   if(typeof isId == 'undefined')
   {
      input = document.formular[Feld];
   }
   else
   {
      input = $(Feld);
   }

   input.focus();

   if(typeof document.selection != 'undefined')
   {
      range = document.selection.createRange();
      insText = range.text;
      range.text = StartTag + insText + EndeTag;
      range = document.selection.createRange();

      if(insText.length == 0)
      {
         range.move('character', -EndeTag.length);
      }
      else
      {
         range.moveStart('character', StartTag.length + insText.length + EndeTag.length);
      }

      range.select();
   }
   else
   {
      start = input.selectionStart;
      end = input.selectionEnd;
      insText = input.value.substring(start, end);

      input.value = input.value.substr(0, start) + StartTag + insText + EndeTag + input.value.substr(end);

      if(insText.length == 0)
      {
         pos = start + StartTag.length;
      }
      else
      {
         pos=start+StartTag.length+insText.length+EndeTag.length;
      }

      input.selectionStart = pos;
      input.selectionEnd = pos;
   }
}

function freundesliste()
{
   if (document.freunde.onoff.value==-1)
   {
      top.location.replace("https://www.abitreff.de/index.php?aktion=login");
   }
   else if (document.freunde.onoff.value!=0)
   {
      top.location.replace("http://www.abitreff.de/inhalte/gymnasien/details.php?id=" + document.freunde.onoff.value);
   }

   for (i=0;i<document.freunde.onoff.length;i++)
      document.freunde.onoff.options[i].selected=false;
}

function zeige_smiley(formular)
{
   document.images.smiley.src="/grafiken/smileys/smiley"+document.forms[formular].smileys.options[document.forms[formular].smileys.selectedIndex].value+".gif"
}

function formularzaehler(Minlaenge,Maxlaenge,Formular,Textfeld,Textfeld_bezeichner,Ausgabefeld)
// Nutzung von Variablen mit erster Stelle als Grossbuchstabe, um eventuelle Dopplungen zu umgehen
{
   document.forms[Formular].elements[Ausgabefeld].disabled = true;

   if (document.forms[Formular].elements[Textfeld].value.length > Maxlaenge)
   {
      document.forms[Formular].elements[Textfeld].value = document.forms[Formular].elements[Textfeld].value.substring(0,Maxlaenge);
      document.forms[Formular].elements[Ausgabefeld].value = "Das Feld \""+ Textfeld_bezeichner +"\" darf maximal "+ Minlaenge +" Zeichen enthalten.";
   }
   else if (document.forms[Formular].elements[Textfeld].value.length < Minlaenge)
   {
      document.forms[Formular].elements[Ausgabefeld].value = "Das Feld \""+ Textfeld_bezeichner +"\" muss mindestens "+ Minlaenge +" Zeichen enthalten.";
   }
   else
   {
      document.forms[Formular].elements[Ausgabefeld].value = "Noch maximal "+ (Maxlaenge - document.forms[Formular].elements[Textfeld].value.length) +" Zeichen verfügbar.";
   }
}

function htmlStr(text)
{
   text = String(text);
   return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}

function htmlInt(zahl)
{
   zahl = parseInt(zahl);
   if (zahl == 'NaN')
   {
      return 0;
   }
   else
   {
      return zahl;
   }
}

function uriInt(zahl)
{
   zahl = parseInt(zahl);
   if (zahl == 'NaN')
   {
      return 0;
   }
   else
   {
      return zahl;
   }
}

// dieser Name ist besser als postUriStr, stringent bleiben!
function uriStr(text)
{
   if (text == null)
   {
      return '';
   }
   else
   {
      return encodeURIComponent(text);
   }
}

function postUriStr(text)
{
   if (text == null)
   {
      return '';
   }
   else
   {
      return encodeURIComponent(text);
   }
}

function ajaxRequest(area_out, formmethod, ajaxfile, param)
{
   function ausgabe()
   {
      if (XMLHTTP.responseText == 'timeout')
      {
         window.location.replace('https://www.abitreff.de/?aktion=login&fehler=0');
      }
      else
      {
         $(area_out).innerHTML = XMLHTTP.responseText;
      }
   }

   var XMLHTTP = null;
   if (window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
   {
      XMLHTTP = new XMLHttpRequest();
   }
   else if (window.ActiveXObject) // IE 5,6
   {
      try
      {
         XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (ex)
      {
         try // IE old Version
         {
            XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (ex)
         {
         }
      }
   }

   XMLHTTP.open(formmethod, ajaxfile, true);
   XMLHTTP.onreadystatechange = function()
   {
      if(XMLHTTP.readyState == 4 && XMLHTTP.status == 200)
      {
         ausgabe();
      }
   }
   XMLHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
   XMLHTTP.send(param);
}

function ajaxRequestReturnResponse(formmethod, ajaxfile, param)
{
   function returnIt()
   {
      return XMLHTTP.responseText;
   }

   var XMLHTTP = null;
   if (window.XMLHttpRequest) // non-IE browsers
   {
      XMLHTTP = new XMLHttpRequest();
   }
   else if (window.ActiveXObject) // IE new Version
   {
      try
      {
         XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (ex)
      {
         try // IE old Version
         {
            XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (ex)
         {
         }
      }
   }

   XMLHTTP.open(formmethod, ajaxfile, true);
   XMLHTTP.onreadystatechange = function()
   {
      if(XMLHTTP.readyState == 4 && XMLHTTP.status == 200)
      {
         if (XMLHTTP.responseText == 'timeout')
         {
            window.location.replace('https://www.abitreff.de/?aktion=login&fehler=0');
         }
         else
         {
            returnIt();
         }
      }
   }
   XMLHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
   XMLHTTP.send(param);
}

function addFavorites()
{
   var titel = 'Kostenfrei Schulfreunde finden und Klassentreffen organisieren auf www.AbiTreff.de';
   if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
   {
      window.external.AddFavorite('http://www.abitreff.de',titel);
   }
   else if(navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("firefox")!=-1)
   {
      window.external.addPanel(titel, 'http://www.abitreff.de', '')
   }
   else
   {
      window.alert('Leider unterstützt Ihr Browser diese Funktion nicht. Bitte fügen Sie die Seite manuell Ihren Lesezeichen hinzu.');
   }
}

function showTopScreen(breite)
{
   var e = $('top_layer_out');
   var f = $('top_layer_in');

   if (window.navigator.userAgent.indexOf("MSIE ") > -1 && parseFloat(navigator.appVersion) >= 4) {
      var h = document.body.clientHeight + 3000;
      var w = document.body.clientWidth;
      var y = document.body.scrollTop + 120 +'px';
   }
   else {
      var h = window.innerHeight + 3000;
      var w = window.innerWidth;
      var y = window.pageYOffset + 120 + 'px';
   }

   e.style.height = h+'px';
   e.style.width = w+'px';
   e.style.display = 'block';

   f.style.top = y;
   var l_c = Math.round((w - breite) / 2);
   f.style.left = l_c+'px';
   f.style.width = breite+'px';
   f.style.padding = '0';
   f.style.display = 'block';

}

function closeTopScreen()
{
   $('top_layer_out').style.display = 'none';
   $('top_layer_in').style.display = 'none';
   $('top_layer_in').innerHTML = '';
}

function switchImage(id,image)
{
   $(id).src = image;
}

var global_userid = 0;


function showPicturePopup(id,bild,breite,hoehe)
{
   global_userid = id;
   PicPopup = window.open('/inhalte/gymnasien/galeriebild.php?id='+id+'&bild='+bild, 'Bild', 'directories=no,locationbar=no,menubar=no,statusbar=no,toolbar=no,scrollbars=yes,width=900,height=500')
   PicPopup.moveTo('0','0');
   PicPopup.focus();
}

function pHandleEnterKey(event,action,parameter)
{
   key=event.keyCode || event.which;
   if (key == 13)
   {
      switch(action)
      {
         case 'addcommentanswer':
            var param = parameter.split('_');
            pictureCommentAnswerSave(htmlInt(param[0]), htmlInt(param[1]));
            break;
         case 'description':
            pictureDescriptionSave(htmlInt(parameter));
            break;
         default:
            return true;
            break;
      }
   }

}

function pImg(delay, url)
{
   window.setTimeout("preloadImage('"+url+"')", delay);
}

function preloadImage(url)
{
   var preImage = new Image();
   preImage.src = url;
}

function showPicture(userid,pictureid,picwidth,picheight)
{
   if(!userid || !pictureid)
   {
      return false;
   }

   global_userid = userid;
   showTopScreen(900);
   $('top_layer_in').style.border = '3px #90AAC0 solid';
   $('top_layer_in').innerHTML = '<center><img src="/grafiken/ladegrafik_logo.gif" border="0" alt="Bitte warten ..." /><br /><br />Bitte warten, die angeforderten Daten werden geladen...</center>';
   var param = 'userid=' + userid + '&pictureid=' + pictureid;
   ajaxRequest('top_layer_in', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_bild.php', param);
}

function showPictureOpenedWindow(userid,pictureid,picwidth,picheight)
{
   if(!userid || !pictureid)
   {
      return false;
   }

   $('picture_area').innerHTML = '<center><img src="/grafiken/ladegrafik_logo.gif" border="0" alt="Bitte warten ..." /><br /><br />Bitte warten, die angeforderten Daten werden geladen...</center>';
   var param = 'userid=' + userid + '&pictureid=' + pictureid;
   ajaxRequest('top_layer_in', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_bild.php', param);
}

function pictureComments(pictureid, offset)
{
   $('picture_comments').innerHTML = '<br /><br />Bitte haben Sie etwas Geduld. Die angeforderten Daten werden geladen<blink>...</blink>';
   var param = 'pictureid=' + htmlInt(pictureid) + '&userid=' + htmlInt(global_userid) + '&offset=' + htmlStr(offset);
   ajaxRequest('picture_comments', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_bildkommentar.php', param);
}

function pictureCommentDelete(pictureid, commentid)
{
   $('action_saved').innerHTML = 'false';
   $('picture_comments').innerHTML = '<br /><br />Bitte haben Sie etwas Geduld. Die angeforderten Daten werden geladen<blink>...</blink>';

   var param = 'commentid=' + htmlStr(commentid);
   ajaxRequest('action_saved', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_deletecomment.php', param);

   checkIfSaved("action_saved", pictureid, -1);
}

function pictureAddComment(pictureid)
{
   $('picture_comments').innerHTML = '<br /><br /><form name="kommentar"><textarea class="rand" id="pic_comment_text" style="width:200px; height:150px;" maxlength="256"></textarea><br /><br />Smiley: <select id="pic_comment_smiley" name="smileys" size="1" onChange="zeige_smiley(\'kommentar\')" style="font-size: 10px"><option value="1">:D</option><option value="2">;)</option><option value="3">?(</option><option value="4">8)</option><option value="5">;(</option><option value="6">8o</option><option value="7">:]</option><option value="8">:))</option><option value="9">>:O</option><option value="28">:beckoning:</option><option value="29">:frisking:</option><option value="10">:rolleyes:</option><option value="11">:evil:</option><option value="33">:angel:</option><option value="12">:wall:</option><option value="37">:director:</option><option value="13">:year:</option><option value="26">:dance:</option><option value="14">:confused:</option><option value="15">:king:</option><option value="30">:lol:</option><option value="16">:smurf:</option><option value="17">:egg:</option><option value="18">:cheers:</option><option value="19">:cheers;-)</option><option value="32">:cheers...</option><option value="34">:cheers*fg*</option><option value="20">:dear:</option><option value="21">:together:</option><option value="42">:hug:</option><option value="27">:loveyou:</option><option value="22">:yoman:</option><option value="23">:freak:</option><option value="38">:pcattack:</option><option value="36">:sleep:</option><option value="40">:against:</option><option value="41">:tongue:</option><option value="43">:box:</option><option value="44">:problems:</option><option value="24">:question:</option><option value="25">:idea:</option></select> <img src="/grafiken/smileys/smiley1.gif" name="smiley" border="0" align="absmiddle"><br /><br /><input type="button" value="speichern" onclick="pictureAddCommentSave(' + pictureid + ');" style="font-size: 10px" /> <input type="button" value="abbrechen" onclick="pictureComments(' + htmlInt(pictureid) + ',0);" style="font-size: 10px" /></form>';
   $('pic_comment_text').select();
}

function checkIfSaved(area, pictureid, offset)
{
   if ($(area).innerHTML == 'false')
   {
      window.setTimeout('checkIfSaved("' + area + '", ' + pictureid + ', "' + offset + '")', 1000);
   }
   else
   {
      if (isNaN(offset))
      {
         $(offset).innerHTML = $(area).innerHTML;
      }
      else
      {
         pictureCountComments(pictureid);
         pictureComments(pictureid, offset);
      }
   }
}

function pictureAddCommentSave(pictureid)
{
   if($('pic_comment_text').value.length < 5 || $('pic_comment_text').value.length > 256)
   {
      alert('Der Kommentar muss 5 bis 256 Zeichen enthalten');
      return false;
   }
   else
   {
      $('action_saved').innerHTML = 'false';

      var param = 'pictureid=' + pictureid + '&userid=' + global_userid + '&comment=' + postUriStr($('pic_comment_text').value) + '&smiley=' + $('pic_comment_smiley').value;
      $('picture_comments').innerHTML = '<br /><br />Bitte haben Sie etwas Geduld.<br />Die angeforderten Daten werden geladen<blink>...</blink>';
      ajaxRequest('action_saved', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_savecomment.php', param);

      checkIfSaved("action_saved", pictureid, 0);
   }
}

function pictureCountComments(pictureid)
{
   ajaxRequest('picture_comments_count', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_countcomments.php', 'pictureid=' + pictureid);
}

function pictureCommentAddAnswer(pictureid, commentid)
{
   $('picture_comments').innerHTML = '<br /><br />Ihre Antwort:<br /><input id="pic_comment_answer" type="text" class="rand" maxlength="256" style="width: 200px;" onkeypress="pHandleEnterKey(event,\'addcommentanswer\',\'' + pictureid + '_' + commentid + '\');" /><br /><br /><input type="button" onclick="pictureCommentAnswerSave(' + htmlInt(pictureid) + ',' + htmlInt(commentid) + ');" value="speichern" style="font-size: 10px" /> <input type="button" onclick="pictureComments(' + htmlInt(pictureid) + ',0);" value="abbrechen" style="font-size: 10px" />';
   $('pic_comment_answer').select();
}

function pictureCommentEditAnswer(pictureid, commentid, answer)
{
   $('picture_comments').innerHTML = '<br /><br />Ihre Antwort:<br /><input id="pic_comment_answer" value="' + htmlStr(answer) + '" type="text" class="rand" maxlength="256" style="width: 200px;" onkeypress="pHandleEnterKey(event,\'addcommentanswer\',\'' + pictureid + '_' + commentid + '\');" /><br /><br /><input type="button" onclick="pictureCommentAnswerSave(' + htmlInt(pictureid) + ',' + htmlInt(commentid) + ');" value="speichern" style="font-size: 10px" /> <input type="button" onclick="pictureComments(' + htmlInt(pictureid) + ',0);" value="abbrechen" style="font-size: 10px" />';
   $('pic_comment_answer').select();
}

function pictureCommentAnswerSave(pictureid, commentid)
{
   if($('pic_comment_answer').value.length > 256)
   {
      alert('Die Antwort darf max. 256 Zeichen enthalten');
      return false;
   }
   else
   {
      $('action_saved').innerHTML = 'false';

      var param = 'comment=' + commentid + '&antwort=' + postUriStr($('pic_comment_answer').value);
      $('picture_comments').innerHTML = '<br /><br />Bitte haben Sie etwas Geduld. Die angeforderten Daten werden geladen<blink>...</blink>';
      ajaxRequest('action_saved', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_savecomment_answer.php', param);

      checkIfSaved("action_saved", pictureid, 0);
   }
}

function pictureDescriptionSave(pictureid)
{

   if($('pic_desc').value.length > 300)
   {
      alert('Die Bildbeschreibung darf max. 300 Zeichen enthalten');
      return false;
   }
   else
   {
      $('action_saved').innerHTML = 'false';

      var param = 'pictureid=' + pictureid + '&description=' + postUriStr($('pic_desc').value);
      $('pic_description').innerHTML = 'Bitte haben Sie etwas Geduld. Die angeforderten Daten werden geladen<blink>...</blink>';
      ajaxRequest('action_saved', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_save_description.php', param);

      checkIfSaved('action_saved', pictureid, 'pic_description');
   }
}

function pictureDescription(pictureid,text)
{
   if (text != '')
   {
      $('pic_description').innerHTML = '<input type="hidden" id="pic_description_old" value="'+text+'" />'+text+' <a href="javascript: void(0);" onclick="pictureChangeDescription(' + pictureid + ');"><img border="0" src="/grafiken/editieren.gif" alt="Beschreibung bearbeiten" title="Beschreibung bearbeiten" /></a>';
   }
   else
   {
      $('pic_description').innerHTML = '<input type="hidden" id="pic_description_old" value="'+text+'" /><i>keine Beschreibung gespeichert</i> <a href="javascript: void(0);" onclick="pictureChangeDescription('+pictureid+');"><img border="0" src="/grafiken/editieren.gif" alt="Beschreibung bearbeiten" title="Beschreibung bearbeiten" /></a>';
   }
}

function pictureChangeDescription(pictureid)
{
   var desc_old = $('pic_description_old').value;
   $('pic_description').innerHTML = 'Beschreibung:<br /><textarea type="text" maxlength="300" id="pic_desc" class="rand" style="width: 200px; height: 150px;">' + htmlStr(desc_old) + '</textarea><br />(max. 300 Zeichen)<br /><br /><input type="button" onclick="pictureDescriptionSave(' + htmlInt(pictureid) + ');" value="speichern" style="font-size: 10px" /> <input type="button" onclick="pictureDescription(' + htmlInt(pictureid) + ',\'' + htmlStr(desc_old) + '\');" value="abbrechen" style="font-size: 10px" />';
   $('pic_desc').select();
}

function pictureModReport(pictureid)
{
   $('picture_mod_report_pic').innerHTML = 'Bitte warten<blink>...</blink>';
   var param = 'pictureid=' + pictureid;
   ajaxRequest('picture_mod_report_pic', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_mod_bild.php', param);
}

function pictureModReportDescription(pictureid)
{
   $('picture_mod_report_desc').innerHTML = 'Bitte warten<blink>...</blink>';
   var param = 'pictureid=' + pictureid;
   ajaxRequest('picture_mod_report_desc', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_mod_bildbeschreibung.php', param);
}

function pictureReportPic(pictureid)
{
   if($('pic_reportpic_reason').value.length > 15)
   {
      var param = 'pictureid='+pictureid+'&reason='+postUriStr($('pic_reportpic_reason').value);
      $('pic_reportpic').innerHTML = 'Bitte warten<blink>...</blink>';
      ajaxRequest('pic_reportpic', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_melden_bild.php', param);
      $('pic_reportpic_reason').value = '';
   }
   else
   {
      alert('Die Begründung muss aus mind. 16 Zeichen bestehen.');
   }
}

function pictureReportDescription(pictureid)
{
   if($('pic_reportdesc_reason').value.length > 15)
   {
      var param = 'pictureid='+pictureid+'&reason='+postUriStr($('pic_reportdesc_reason').value);
      $('pic_report_desc').innerHTML = 'Bitte warten<blink>...</blink>';
      ajaxRequest('pic_report_desc', 'POST', '/inhalte/gymnasien/ajax_bildergalerie_melden_bildbeschreibung.php', param);
      $('pic_reportdesc_reason').value = '';
   }
   else
   {
      alert('Die Begründung muss aus mind. 16 Zeichen bestehen.');
   }
}

var StatusModOptionenGalerie = false;
function zeigeModOptionenGalerie(pictureid)
{
   if (StatusModOptionenGalerie == true)
   {
      document.getElementById('ModOptionenGalerie').innerHTML = '';
      StatusModOptionenGalerie = false;
   }
   else
   {
      document.getElementById('ModOptionenGalerie').innerHTML = '<br /><span id="picture_mod_report_pic" style="font-size: 10px"><a href="javascript: void(0);" onclick="pictureModReport(' + htmlInt(pictureid) + ');" class="klein">Bild melden</a></span><br /><span id="picture_mod_report_desc" style="font-size: 10px"><a href="javascript: void(0);" onclick="pictureModReportDescription(' + htmlInt(pictureid) + ');" class="klein">Bildbeschreibung melden</a></span><br />';
      StatusModOptionenGalerie = true;
   }
}

var StatusOptionenVerstossGalerie = false;
function zeigeOptionenVerstossGalerie(pictureid)
{
   if (StatusOptionenVerstossGalerie == true)
   {
      document.getElementById('OptionenVerstossGalerie').innerHTML = '';
      StatusOptionenVerstossGalerie = false;
   }
   else
   {
      document.getElementById('OptionenVerstossGalerie').innerHTML = '<br /><i style="font-size: 10px">Bitte wählen:</i><br /><form name="picreport"><input type="radio" name="type" value="1" onclick="$(\'pic_reportpic\').style.display=\'block\';$(\'pic_report_desc\').style.display=\'none\';" style="font-size: 10px" /> <span  style="font-size: 10px">Bild melden</span><span id="pic_reportpic" style="display: none;"> <br /><i style="font-size: 10px">Begründung: (mind. 16 Zeichen)</i><br /> <textarea class="rand" id="pic_reportpic_reason" style="width:200px; height:150px;" maxlength="256"></textarea><br /><br /> <input type="button" value="melden" onclick="pictureReportPic(' + htmlInt(pictureid) + ');" style="font-size: 10px" /> <input type="button" value="abbrechen" onclick="$(\'pic_reportpic\').style.display=\'none\';$(\'pic_reportpic_reason\').value=\'\';" style="font-size: 10px" /> </span><br /> <input type="radio" name="type" value="2" onclick="$(\'pic_reportpic\').style.display=\'none\';$(\'pic_report_desc\').style.display=\'block\';" /> <span  style="font-size: 10px">Bildbeschreibung melden</span><span id="pic_report_desc" style="display: none;"> <br /><i style="font-size: 10px">Begründung: (mind. 16 Zeichen)</i><br /> <textarea class="rand" id="pic_reportdesc_reason" style="width:200px; height:150px;" maxlength="256"></textarea><br /><br /> <input type="button" value="melden" onclick="pictureReportDescription(' + htmlInt(pictureid) + ')" style="font-size: 10px" /> <input type="button" value="abbrechen" onclick="$(\'pic_report_desc\').style.display=\'none\';$(\'pic_reportdesc_reason\').value=\'\';" style="font-size: 10px" /></span></form>';
      StatusOptionenVerstossGalerie = true;
   }
}

function commentModReport(commentid, answer)
{
   if (answer == true)
   {
      $('Kommentarantwort' + commentid).innerHTML = 'Bitte warten<blink>...</blink>';
      var param = 'commentid=' + commentid + '&answer=true';
      ajaxRequest('Kommentarantwort' + commentid, 'POST', '/inhalte/gymnasien/ajax_bildergalerie_mod_comment.php', param);
   }
   else
   {
      $('Bilderkommentar' + commentid).innerHTML = 'Bitte warten<blink>...</blink>';
      var param = 'commentid=' + commentid;
      ajaxRequest('Bilderkommentar' + commentid, 'POST', '/inhalte/gymnasien/ajax_bildergalerie_mod_comment.php', param);
   }
}

function commentReport(commentid, answer)
{
   if (answer == true)
   {
      if ($('comment_report_answer_reason' + commentid).value.length > 15)
      {
         var param = 'commentid=' + commentid + '&answer=true&reason=' + postUriStr($('comment_report_answer_reason' + commentid).value);
         $('comment_report_answer' + commentid).innerHTML = 'Bitte warten<blink>...</blink>';
         ajaxRequest('comment_report_answer' + commentid, 'POST', '/inhalte/gymnasien/ajax_bildergalerie_melden_comment.php', param);
      }
      else
      {
         alert('Die Begründung muss aus mind. 16 Zeichen bestehen.');
      }
   }
   else
   {
      if ($('comment_report_comment_reason' + commentid).value.length > 15)
      {
         var param = 'commentid=' + commentid + '&reason=' + postUriStr($('comment_report_comment_reason' + commentid).value);
         $('comment_report_comment' + commentid).innerHTML = 'Bitte warten<blink>...</blink>';
         ajaxRequest('comment_report_comment' + commentid, 'POST', '/inhalte/gymnasien/ajax_bildergalerie_melden_comment.php', param);
      }
      else
      {
         alert('Die Begründung muss aus mind. 16 Zeichen bestehen.');
      }
   }
}

/* testweise!! */

function position(element)
{
	var valueT = 0, valueL = 0;

	do
	{
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		element = element.offsetParent;
	}
	while (element);

	return [valueL, valueT];
}


function parentElement(ele, tiefe)
{
	for(var i = 0; i < tiefe; i++)
   {
		ele = ele.parentNode;
   }

   return ele;
}

function cr(ele)
{
	return document.createElement(ele);
}

function removeChilds(ele)
{
	while(ele.childNodes.length > 0)
   {
      ele.removeChild(ele.lastChild);
   }
}

function remove(ele)
{
   ele.parentNode.removeChild(ele);
}

function isInt(num)
{
	return (num.toString().search(/^-?[0-9]+$/) == 0);
}

function request(skript, useOnlyGet)
{
   var post, fkt, para, transform,
   header = [],
   vars = [[],[]],
   req = null,
   response = null,
   gut = false;

   header[0] = ['Content-Type', 'application/x-www-form-urlencoded'];
   header[1] = ['Method', (typeof useOnlyGet == 'undefined' ? 'post ' : 'get ') + skript + ' HTTP/1.1'];
   header[2] = ['Charset', 'utf-8'];

   this.addVar = function(name, value, sendType)
   {
      sendType = typeof useOnlyGet == 'undefined' ? (sendType == 1 ? 1 : 0) : 0;
      vars[sendType][vars[sendType].length] = [encodeURIComponent(name), encodeURIComponent(value)];
   }

   this.addHeader = function(name, value)
   {
      header[header.length] = [name, value];
   }

   this.setFunktion = function(name,param)
   {
      fkt = name;
      para = param;
   }

   this.senden = function()
   {
      var j, i, daten = ['', ''];

      if(window.XMLHttpRequest)
      {
         req = new XMLHttpRequest();
      }
      else if(window.ActiveXObject)
      {
         try
         {
            req = new ActiveXObject('Msxml2.XMLHTTP');
         }
         catch(ex)
         {
            try
            {
               req = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch(ex)
            {
            }
         }
      }

      for(j = 0; j < (typeof useOnlyGet == 'undefined' ? 2 : 1); j++)
      {
         if(vars[j].length > 0)
         {
            for(i = 0; i < vars[j].length; i++)
            {
               daten[j] += vars[j][i][0] + '=' + vars[j][i][1] + ((i < vars[j].length - 1) ? '&' : '');
            }
         }
      }

      if(typeof useOnlyGet == 'undefined')
      {
         req.open('POST', '/inhalte/' + skript + (vars[0].length > 0 ? '?' + daten[0] : ''), true);
         req.setRequestHeader('Content-Length', daten[1].length);
      }
      else
      {
         req.open('GET', '/inhalte/' + skript + (vars[0].length > 0 ? '?' + daten[0] : ''), true);
      }

      for(i = 0; i < header.length; i++)
      {
         req.setRequestHeader(header[i][0], header[i][1]);
      }

      req.onreadystatechange = function()
      {
         if(req.readyState == 4 && req.status == 200)
         {
            response = eval('(' + req.responseText + ')');

            switch(response['s'])
            {
               case 1: gut = true; break;
               case 2: showNotification(1, decodeURIComponent(response['c'])); break;
               case 3: location.href = 'https://www.abitreff.de/index.php?aktion=login&fehler=' + uriInt(response['e']); break;
               case 4: showNotification(2, 'Manipulationen am Skript sind verboten. Deine Aktion wurde gespeichert!'); return;
            }

            if(gut && typeof fkt != 'undefined')
            {
               if(typeof para != 'undefined')
               {
                  fkt.apply(null,para);
               }
               else
               {
                  fkt();
               }
            }
         }
      }

      req.send(typeof useOnlyGet == 'undefined' ? daten[1] : null);
   }

   this.res = function()
   {
      return transform(response['c']);
   }

   transform = function(f)
   {
      if(typeof f == 'Object')
      {
         for(i in f)
         {
            f[i] = transform(f[i]);
         }
      }
      else if(typeof f == 'Array')
      {
         for(i = 0; i < f.length; i++)
         {
            f[i] = transform(f[i]);
         }
      }
      else if(typeof f == 'String')
      {
         f = decodeURIComponent(f);
      }

      return f;
   }
}

function eventPosition(ev)
{
   if(!ev)
   {
      ev = window.event;
      x = ev.clientX + document.documentElement.scrollLeft;
      y = ev.clientY + document.documentElement.scrollTop;
   }
   else
   {
      x = ev.pageX;
      y = ev.pageY;
   }

   return [x, y];
}

function getScreenCenter()
{
   var l = document.body.offsetWidth / 2,
   t = 0;

   if(typeof window.pageYOffset != 'undefined')
   {
      t = window.pageYOffset + window.innerHeight / 2;
      l = window.innerWidth / 2;
   }
   else if(typeof document.documentElement.scrollTop != 'undefined')
   {
      t = document.documentElement.scrollTop + document.documentElement.clientHeight / 2;
      l = document.documentElement.clientWidth / 2;
   }

   return [l, t];
}

function scrollToPosition(posY, scrollStep, spacer, y)
{
   var move;

   if(typeof y == 'undefined')
   {
      if(window.pageYOffset)
      {
         y = window.pageYOffset;
      }
      else if(document.documentElement.scrollTop)
      {
         y = document.documentElement.scrollTop;
      }

      posY = posY - (typeof y != 'undefined' ? y : 0);
      posY -= spacer;
   }

   if(posY > 0)
   {
      move = posY - scrollStep < 0 ? Math.abs(posY) : scrollStep;
   }
   else if(posY < 0)
   {
      move = posY + scrollStep > 0 ? -Math.abs(posY) : -scrollStep;
   }
   else
   {
      return;
   }

   window.scrollBy(0, move);
   setTimeout('scrollToPosition(' + (posY - move) + ',' + scrollStep + ', 0, 1)', 10);
}

function setOpacity(ele, val)
{
   ele.style.MozOpacity = val;
   ele.style.opacity = val;
   ele.style.filter = 'alpha(opacity=' + val * 100 + ')';
}

function showNotification(typ, text)
{
   var main, block, outer, txt, img, sc;

   if($('globalNotification') == null)
   {
      block = cr('div');
      block.id = 'globalNotificationBlock';

      block.onclick = function()
      {
         remove($('globalNotification'));
         remove(this);
      }

      outer = cr('div');
      outer.id = 'globalNotification';

      outer.onclick = function()
      {
         remove($('globalNotificationBlock'));
         remove(this);
      }

      main = cr('div');
      main.id = 'globalNotificationInner';
      outer.appendChild(main);

      document.body.appendChild(block);
      document.body.appendChild(outer);
   }

   $('globalNotificationBlock').style.backgroundImage = 'url("/grafiken/ereignisse/' + (typ == 1 ? 'bgwarnung.png' : 'bgerror.png') + '")';
   main = $('globalNotification');

   txt = cr('div');

   img = cr('img');
   img.src = '/grafiken/ereignisse/' + (typ == 1 ? 'warnung.png' : 'error.png');

   txt.appendChild(img);
   txt.appendChild(document.createTextNode(text));

   $('globalNotificationInner').appendChild(txt);

   sc = getScreenCenter();
   main.style.left = sc[0] - main.offsetWidth / 2 + 'px';
   main.style.top = sc[1] - main.offsetHeight / 2 + 'px';
}