
var in_array = function (search, array) {

    array.sort();
    
    // loop through each item
    for(var i = 0; i < array.length; i++) {
        
        // check if current item matches search
        if(array[i] == search) {
            return false;
        }
    }
    
    return true;
}

function insertString(aTag, eTag) {
  var input = document.neu.thematext;
  input.focus();
  
  if(typeof document.selection != 'undefined') {
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    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();
  }
  
  else if(typeof input.selectionStart != 'undefined')
  {
    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);
    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;
  }
  else
  {
    document.neu.thematext.value += aTag;
    document.neu.thematext.value += eTag;
  }
}


function youtube(){
  insertString("[youtube]", "[/youtube]");
}

function Text_Kursiv() {
  insertString("[kursiv]", "[/kursiv]");
}

function Text_Fett() {
  insertString("[fett]", "[/fett]");
}

function Hyperlink() {
  insertString("[hyperlink]", "[/hyperlink]");
}

function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
  		if($(this).attr("title") != "" ){
			$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
			var my_tooltip = $("#"+name+i);
		
			$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.9, display:"none"}).fadeIn(300);
			}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
			}).mouseout(function(){
				my_tooltip.fadeOut(300);
			});
	  }
	});
}

$(document).ready(function(){
	 simple_tooltip("a","usertip");
});

function logout()
{
 document.getElementById('log').submit();
}

function dtnmel()
{
  cck = confirm("Bitte überprüfe die Angaben nochmals auf ihre Richtigkeit. Sollen diese Daten wirklich erneuert/geändert werden?");

  if(cck == false)
  {
    return false;
  }else{ return true; }

}

function CountMax()
{
	max = 2000
	if(document.neu.thematext.value.length <= max) {
		document.getElementById("bcounter").firstChild.data = document.neu.thematext.value.length + " von " + max + " Zeichen";
	}else{
		document.neu.thematext.value = document.neu.thematext.value.substring(0,max);
	}

}

function antworten(id, nick, nnick)
{
  document.getElementById("neuemail").style.display = "block";

  conobj = document.getElementById("content");

  if (conobj.offsetHeight) { posi = conobj.offsetHeight; }
  if (conobj.scrollHeight) { posi = conobj.scrollHeight; }
  if(conobj.clientHeight) { posi = conobj.clientHeight; }

  
  posi -= 800;
  window.scrollTo(0, posi);
if(id) {
  if(document.neu.an.options[document.neu.an.length - 1].text != nnick) {
    NeuerEintrag = new Option(nnick, nick, false, true);
    document.neu.an.options[document.neu.an.length] = NeuerEintrag;
  }
}
}


function errormail()
{
  document.getElementById("neuemail").style.display = "block";
}

function minimieren()
{

if(document.getElementById("modauswahl1").style.visibility == "visible") {
  document.getElementById("modbereich").style.height = "20px";
  document.getElementById("modauswahl1").style.visibility = "hidden";
  document.getElementById("modauswahl2").style.visibility = "hidden";
  document.getElementById("modauswahl3").style.visibility = "hidden";
  document.getElementById("min").src = "gfx/icons/16x16/window_add.png";
}else{
  document.getElementById("modbereich").style.height = "100%";
  document.getElementById("modauswahl1").style.visibility = "visible";
  document.getElementById("modauswahl2").style.visibility = "visible";
  document.getElementById("modauswahl3").style.visibility = "visible";
  document.getElementById("min").src = "gfx/icons/16x16/window_up.png";
}
}

function scrolldown()
{
 obj = document.getElementById('listlauf');
 speed = 2;

 if( obj.style.top == 0) {
  obj.style.top = "0px";
  setTimeout("scrolldown()", 100);
 }else{

   position = parseInt(obj.style.top) - speed;

   positionende = position - 150;

  if(positionende <= "-" + obj.offsetHeight)
  {

  }else{
   obj.style.top = position + "px";
   scrollId = setTimeout("scrolldown()", 10);
  }

 }
}

function scrollup()
{
 obj = document.getElementById('listlauf');
 speed = 2;


   position = parseInt(obj.style.top) + speed;

  if(position <= 0)
  {

   obj.style.top = position + "px";
   scrollId = setTimeout("scrollup()", 10);
  }

}

$(document).ready(function() {
 $("#oa").hide();
 
	$("#optionalea").click(function() {
		if ($("#oa").is(":hidden")) {
			$("#oa").slideDown("normal");
			$(".do1").attr({ 
			src: "gfx/icons/16x16/up.png"
			});			
		} else {
			$("#oa").slideUp("normal");
			$(".do1").attr({ 
			src: "gfx/icons/16x16/down.png"
			});
		}


	});
});

$(document).ready(function() {
	$("#message_title span").click(function(){ 
		$(this).parents('div.message_container').fadeOut();
		$(this).parents('div.message_container').next().fadeOut();
	});
	$(".message_container input").click(function(){ 
		$(this).parents('div.message_container').fadeOut();
		$(this).parents('div.message_container').next().fadeOut();
		
		return false;
	});
	
	$("a.nrc").click(function(){ 
		if($("#"+$(this).attr("name")).is(":hidden")) {
			$("#"+$(this).attr("name")).slideDown();
		}else{
			$("#"+$(this).attr("name")).slideUp();
		}
		return false;
	});	
	
	$("img.nn").click(function(){ 
		if($("#"+$(this).attr("title")).is(":hidden")) {
			$("#"+$(this).attr("title")).slideDown();
		}else{
			$("#"+$(this).attr("title")).slideUp();
		}
		return false;
	});	
});

function nachricht(id)
{
	if(document.getElementById("nachricht"+id).style.display == "none"){
	  document.getElementById("nachricht"+id).style.display = "table-row-group";
	}else{
	  document.getElementById("nachricht"+id).style.display = "none";
	}
}

function newmail()
{
if(document.getElementById("neuemail").style.display == "none"){
   document.getElementById("neuemail").style.display = "block"; 
}else{
  document.getElementById("neuemail").style.display = "none"; 
}
}
