﻿/* Helfermethode um aus einer normalen Klasse ein jQuery-plugin zu machen
 * Hat den Vorteil, dass man Vererbung nutzen kann und prinzipiell keine jQuery-abhängigen Klassen benötigt.
 * http://jupiterjs.com/news/writing-the-perfect-jquery-plugin
 **/
$.pluginMaker = function(plugin) {

  // add the plugin function as a jQuery plugin
  $.fn[plugin.prototype.name] = function(options) {

    // get the arguments
    var args = $.makeArray(arguments),
        after = args.slice(1);

    return this.each(function() {

      // see if we have an instance
      var instance = $.data(this, plugin.prototype.name);
      if (instance) {

        // call a method on the instance
        if (typeof options == "string") {
          instance[options].apply(instance, after);
        } else if (instance.update) {

          // call update on the instance
          instance.update.apply(instance, args);
        }
      } else {
        // create the plugin
        new plugin(this, options);
      }
    });
  };
};

// Namespace für jQuery Plugins
goolive = {};

/* ************************************************************************
 *
 * <plugin>
 *
 * jQuery Plugin für Textfelder, die eine maximale Anzahl Zeichen erlauben.
 *
 * Verwendung:
 * $(textfield).gooliveCharCount()
 * Dabei wird erwartet, dass ein weiteres Element existiert, was die gleiche ID hat mit dem Postfix '_count'.
 * In dieses Element werden die verbleibenen Zeichen eingetragen.
 * Das Postfix kann überschrieben werden:
 * $(textfield).gooliveCharCount( { countFieldPostfix: '_meinPostfix' } )
 *
 * Es kann auch ein kompletter Selector für das Feld übergeben werden, in dem die verbleibenden Zahlen vermerkt werden,
 * dieser ist höher priorisiert als das Postfix:
 * $(textfield).gooliveCharCount( { countFieldSelector : '#IdVomCounterFeld' } )

 * Ebenso kann die maximale Anzahl an Zeichen festgelegt werden (default ist 250):
 * $(textfield).gooliveCharCount( { maxChars: 20 } )
 *
 * Man kann die Anzahl der möglichen Zeichen auch nachträglich ändern:
 * $(textfield).gooliveCharCount( 'setMaxChars', 160 )
 *
 */
goolive.CharCount = function(el, options) {
	  if (el) {
	      this.init(el, options);
	  }
	};

// Charcount Klasse
$.extend(goolive.CharCount.prototype,
{
	name			: 'gooliveCharCount',
	defaults: {
		maxChars			: 250,
		countFieldPostfix	: '_count',
		countFieldSelector	: ''
	},

	init: function (el, options) {
		// Element setzen
		this.element = $(el);

		// Optionen setzen
		// Objektkopie der defaults anlegen
		this.options = $.extend( {}, this.defaults );
		// und erweitern mit den übergebenen Optionen
		$.extend( this.options, options );

		// Speichern der Instanz im Element
	    $.data( el, this.name, this );

	    // dem Element uns als Klasse hinzufügen
	    this.element.addClass( this.name );

	    // Wenn wir zerstört werden, Teardown aufrufen
	    this.element.bind( "destroyed", $.proxy( this.teardown, this ) );

	    // andere Events binden
	    this.bind();

	    // Element festlegen, in das die verbleibenen Zeichen geschrieben werden
	    if (this.options.countFieldSelector.length == 0) {
	    	this.countField = $( '#' + this.element.attr( 'id' ) + this.options.countFieldPostfix );
	    }
	    else {
	    	this.countField = $( this.options.countFieldSelector );
	    }
	    // initial den Wert im Zählerfeld aktualisieren
	    this.cutText();
	    this.count();
	},

	bind: function ( ) {
		this.element.bind( 'keyup.charcount change.charcount', $.proxy(this.count, this) );
		this.element.bind( 'keydown.charcount', $.proxy(this.cutText, this) );
	},

	destroy: function() {
		this.element.unbind('destroyed', this.teardown);
		this.teardown();
	},

	teardown: function ( ) {
		$.removeData( this.element[0], this.name );
		this.element.removeClass( this.name );
		// eventlistener entfernen
		this.unbind();
		// Referenz auf den Container freigeben
		this.element = null;
	},

	unbind: function ( ) {
		this.element.unbind('keydown.charcount');
		this.element.unbind('keyup.charcount');
		this.element.unbind('change.charcount');
	},

	cutText: function ( ) {
		this.oldValue = $( this.element ).val();
		if ( this.oldValue.length > this.options.maxChars ) {
			this.oldValue = this.oldValue.substring( 0, this.options.maxChars );
		}
	},

	count: function ( ) {
		var charcount = $( this.element ).val().length;
		var charsleft =  this.options.maxChars - charcount;
		if (charsleft < 0) {
			$( this.element ).val( this.oldValue);
			charsleft = 0;
		}
		if ($( this.countField ).attr('localName') == 'input') {
			this.countField.val(charsleft);
		}
		else {
			this.countField.text(charsleft);
		}
	},

	setMaxChars: function (newMax) {
		this.options.maxChars = newMax;
		this.cutText();
		this.count();
	}

});

// das Plugin registrieren
$.pluginMaker(goolive.CharCount);

/*
 * </plugin>
 *
 * ************************************************************************/

// Ladebild (wird von diversen Funktionen genutzt)
var $loading = $('<img style="margin-left:auto;margin-right:auto;display:block;position:relative;top:30px" src="http://static.goolive.org/media/static/images/jsloader.gif" border="0" alt="loading" />');


/* ************************************************************************
 *
 * Quickhelp
 *
 * - benötigt jquery und jquery-ui inkl. css
 * - zusammen mit der Quickhelp-Extension nutzen
 *
 * Generiert zu jedem anchor (<a>), welches die Klasse "page-help" besitzt eine
 * Schnellhilfe. Es wird dann die Information, die hinter dem href des Links abzurufen ist
 * in einem modalen Dialog angezeigt.
 *
 */

	$(document).ready(function() {
		createPageHelp();
	});

	function createPageHelp()
	{ 
		// Hilfebuttons (blaue Fragezeichen)
		$('a.page-help').each(function() {
		
		var winWidth = 500;
		var winHeight = 0;
		
		if ($(this).attr('winWidth'))
		{
			winWidth = $(this).attr('winWidth');
		}
		
		if ($(this).attr('winHeight'))
		{
			winHeight = $(this).attr('winHeight');
		}
				
		var $dialog = $('<div></div>')
			.append($loading.clone());
		var $link = $(this).one('click', function() {
			$dialog
				.dialog({
					title: 'Lade Hilfe...',
					resizable: false,
					modal: true,
					width: winWidth
				});
			$.getJSON($link.attr('href'), {'ajax':'true'}, function (data) {
					$dialog.dialog('option', 'title', data.title);
					$dialog.dialog('option', 'width', winWidth);
					if(winHeight > 0)
					{
						$dialog.dialog('option', 'height', winHeight);
						$dialog.dialog( "option", "position", 'center' );
					}
					$dialog.html(data.content);
			});
			$link.click(function() {
				$dialog.dialog('open');
				return false;
			});
			return false;
		});
	});
	}

/*
 * ENDE Quickhelp
 *
 ************************************************************/

/* ************************************************************************
*
* Tooltip (http://docs.jquery.com/UI/Tooltip)
*
* - benötigt jquery und jquery-ui 1.9 inkl. css
*
* Generiert zu jedem Element, welches die Klasse "tooltip" besitzt einen
* Tooltip. Dieser bekommt einen Titel, wenn das title-Attribut ebenfalls vorhanden ist.
* Bei Klick auf das Element wird der Tooltip ausgeblendet (sinnvoll z.B. bei Inputfeldern).
*
*
* Der Inhalt des Tooltips kann durch zwei Attribute im Element festgelegt werden:
*
* remote="http://www.goolive.de/INHALT" (TT-Inhalt wird per Ajax geladen und gecached)
*
* oder
*
* tip="Beliebiges HTML"
*
* bei Bildern wird, wenn keine der oberen Inhaltsangaben für den Tooltip gemacht werden, das Bild angezeigt.
* Wird ein Bild also verkleinert auf der Seite dargestellt, so würde im Tooltip das Bild in Originalgröße angezeigt werden.
*
* Profilbilder machen hier eine Ausnahme: Es wird aus dem src-Attribut automatisch die Bigsize-URL generiert und dann dieses Bild angezeigt.
* Auch kann bei Profilbildern eine nachträgliche Änderung des Tooltip-Inhalts eingeschaltet werden, wenn z.B. eine Aktion läuft.
* Dann wird die Bild-URL zum Server gesendet und ein alternativer Inhalt von diesem empfangen. Unterdessen wird einfach das Bild angezeigt.
*
* Die Priorität ist dabei
* tip-Attribut > remote-Attribut > automatische Anzeige bei img-Elementen
*
* ACHTUNG: Wird per Ajax content nachgeladen, der Tooltips enthalten soll, dann muss manuell nach dem Laden die Funktion
* createTooltips() aufgerufen werden, da diese nur bei document.ready automatisch erstellt werden!
*
*/

// Cache für per ajax empfangene Tooltips
var tooltipContentCache = [];

$(document).ready(function() {
	createTooltips();
});

function createTooltips()
{
	$( '.tooltip' ).tooltip({
		items : ".tooltip",
		content: function (response) {
			var title = '';
			if ($(this).attr('title').len != 0)
			{
				title = '<p class="title">' + $(this).attr('title') + '</p>';
				var tooltip = $(this).tooltip("widget");
				tooltip.css('padding-top', '0px');
			}

			tooltip.css('word-wrap', 'break-word');

			if (typeof $( this ).attr('tip') != 'undefined') {
				return title + $(this).attr('tip');
			}
			else if (typeof $( this ).attr('remote') != 'undefined') {
				var key = $( this ).attr('remote');
				if (typeof tooltipContentCache[key] == 'undefined') {
					$.get($( this ).attr('remote'),
							function(result) {
						tooltipContentCache[key] = result;
						response(title + result);
					});
					$loading.css( 'top', '2px' );
					return $loading;
				}
				else {
					return title + tooltipContentCache[key];
				}
			}
			else if ( $( this ).attr('nodeName').toLowerCase() == 'img' )
			{
				var src = $(this).attr('src');
				if (src.indexOf('http://s3.goolive.org/profilepics/') > -1 ) {
					// bigsize url
					src = src.replace(/(.*)\/(minithumbs|thumbs|normal)\/(.*)/, '$1/bigsize/$3');
					// Modifizieren des Bilds z.B. bei Aktionen
					if (true)
					{
						var key = src;
						if (typeof tooltipContentCache[key] == 'undefined') {
						$.get( '/index.php',
								{
									'ext' : 'tooltip',
									'action': 'enrich',
									'picURL': src
								},
								function(result) {
									tooltipContentCache[key] = result;
									response(title + result);
								}
							);
						$loading.css( 'top', '2px' );
						return $loading;
						}
						else {
							return title + tooltipContentCache[key];
						}
					}
					// dreckiger Trick: das Open-Event wird zu schnell gefeuert, das Bild ist dann noch nicht in der DOM und die Höhe des Tooltips wird falsch berechnet
					// daher bei Profilbildern Höhe schonmal angeben.
					return $(title + '<img style="height:390px" src="' + src + '"/>');
				}
				else
				{
					return title + '<img src="' + src + '"/>';
				}
			}

		},
		open: function( ev, ui ) {
			var tooltip = $( this ).tooltip("widget");
			$( this ).bind( 'mousemove.tooltip', function( event ) {
				// Mausposition relativ zum Fensterinhalt
				var top = event.pageY - $( document ).scrollTop();

				// Höhe des Tooltips
				var height = tooltip.outerHeight();

				// Rand zum Fester
				var margin = 10;

				var offY = 0;
				// geht der tooltip über den Rand? Dann Offset anpassen
				// oben
				if ((top - height / 2 - margin) < 0) {
					offY = -(top - height / 2 - margin);
				}
				// unten
				else if ((top + height / 2 + margin) > ($( window ).height())) {
					offY = -((top + height / 2  + margin) - $( window ).height());
				}
				tooltip.position({
					my: "left center",
					at: "right center",
					offset: "25 " + offY,
					of: event,
					collision: 'none'
				});
			});
			tooltip.removeClass('ui-widget-content');
			// trigger once to override element-relative positioning
			$( this ).trigger( 'mousemove' );
		},
		close: function() {
			$( this ).unbind("mousemove.tooltip");
		}
	})
	.bind('click', function() {
		$(this).tooltip('close');
	});
}

/*
* ENDE Tooltip
*
************************************************************/

/*
 * Datepicker Sprache
 *
 */

$.datepicker.regional['de'] = {
		closeText: 'schließen',
		prevText: '&#x3c;zurück',
		nextText: 'Vor&#x3e;',
		currentText: 'heute',
		monthNames: ['Januar','Februar','März','April','Mai','Juni',
		'Juli','August','September','Oktober','November','Dezember'],
		monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
		'Jul','Aug','Sep','Okt','Nov','Dez'],
		dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
		dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		weekHeader: 'Wo',
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['de']);

/*
* ENDE Datepicker Sprache
*
************************************************************/

function loadCalendar(link, searchstr)
{
	$.get('/extensionsv2/mod_calendar/include.php',
			{'meet_search': searchstr, 'link': link},
			function (response) {
				$( '#calendar' ).html(response);
				});
}

/*
 * Show / Hide elements
 *
 * Trigger: Das Triggerelement wird durch einen speziellen Klassennamen gekennzeichnet.
 * Dieser besteht aus dem "Auslöser, dem "Effekt" und der ID des zu manipulierenden Elements:
 *
 * class="AUSLOESER_toggle_EFFEKT_NAME"
 *
 * Folgende Kombinationen sind möglich
 *
 * class="hover_toggle_slide_NAME"
 * class="hover_toggle_fade_NAME"
 * class="click_toggle_slide_NAME"
 * class="click_toggle_fade_NAME"
 *
 * Element, welches gezeigt / versteckt wird: muss id="NAME" haben
 *
 * Bei hover / click auf das Triggerelement wird dann das andere gezeigt / versteckt
 *
 */

$( document ).ready(function(){
	$('[class*="hover_toggle_"]').live({
		  mouseenter: function() {
			 autotoggle(this, 'in');
		  },
		  mouseleave: function () {
			 autotoggle(this, 'out');
		  }
	});
	$('[class*="click_toggle_"]').live({
		  click: function() {
			 autotoggle(this, 'in');
		  }
	});
});

function autotoggle(toggleElem, inOut)
{
	$($(toggleElem).attr('class').split(' ')).each(function(pos, classname) {
		// Prüfung auf Klassennamen "toggle_XXXXXX"
		var matches = classname.match(/^(hover|click)_toggle_(slide|fade)_(.*)/);
		if (matches) {
			// alle anstehenden / begonnenden Animationen beenden
			$('#' + matches[3]).stop(true, true);
			if (inOut == 'in') {
				if (matches[2] == 'slide') {
					$('#' + matches[3]).slideDown();
				}
				else if (matches[2] == 'fade') {
					$('#' + matches[3]).fadeIn();
				}
			}
			else {
				if (matches[2] == 'slide') {
					$('#' + matches[3]).slideUp();
				}
				else if (matches[2] == 'fade') {
					$('#' + matches[3]).hide();
				}
			}
		}
	});
}

// -----------------------------------------------------------------------------------

// Play Mp3 Sound
// -----------------------------------------------------------------------------------

function fwPlaysound(mp3)
{
	var url_player = 'http://static.goolive.org/media/static/swf/playmp3.swf';
	document.getElementById('ss').innerHTML = '';
	var text = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1" height="1"><param name="movie" value="'+url_player+'?mp3='+mp3+'"><param name="quality" value="high"><embed src="'+url_player+'?mp3='+mp3+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="5" height="5"></embed></object>';
	document.getElementById('ss').innerHTML = text;

}

// -----------------------------------------------------------------------------------
// Suche auf jeder Seite
// -----------------------------------------------------------------------------------

function topsearch(searchvalue){
	if(searchvalue != searchvalue.split('?').join(''))
	{
		searchvalue = searchvalue.split('?').join('%3F');
	}
	url = "/benutzersuche/topsearch/"+searchvalue;
	top.location.href = url;
	return false;
}

// -----------------------------------------------------------------------------------
// Schatten anzeigen
// -----------------------------------------------------------------------------------

function showShadow(frontObj){
	//container initialisieren
	$( '<div></div>' )
		.attr('id', 'gooShadow')
		.css('position', 'absolute')
		.css('left', '0')
		.css('top', '0')
		.css('width', window.getScrollWidth())
		.css('height', window.getScrollHeight())
		.css('z-index', parseInt(frontObj.css('z-index'))-1)
		.css('opacity', '0.5')
		.css('background-color', '#000')
		.appendTo( 'body' );
}

function hideShadow(){$('#gooShadow').remove();}

// -----------------------------------------------------------------------------------
// String UTF8 kodieren
// -----------------------------------------------------------------------------------

function utf8_encode(rohtext) {
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++)
	{
		// ermitteln des Unicodes des  aktuellen Zeichens
		if(rohtext.charAt(n) == "\xdfx"){
			utftext += '%C3%9F';
			continue;
		}

		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
		utftext += String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048)) {
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);}
			// alle Zeichen von 2048 bis 66536 => 3byte
			else {
				utftext += String.fromCharCode((c>>12)|224);
				utftext += String.fromCharCode(((c>>6)&63)|128);
				utftext += String.fromCharCode((c&63)|128);
			}
	}
	return utftext;
}

function utf8_decode(utftext) {
	var plaintext = ""; var i=0; var c=c1=c2=0;
	// while-Schleife, weil einige Zeichen uebersprungen werden
	while(i<utftext.length)
	{
		c = utftext.charCodeAt(i);
		if (c<128) {
			plaintext += String.fromCharCode(c);http://s3.goolive.org/profilepics/bigsize/446594-1300379277.jpg
			i++;
		}
		else if((c>191) && (c<224)) {
			c2 = utftext.charCodeAt(i+1);
			plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
			i+=2;
		}
		else {
			c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
			plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
			i+=3;
		}
	}
	return plaintext;
}


// -----------------------------------------------------------------------------------
// Cookie Funktionen
// -----------------------------------------------------------------------------------

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// -----------------------------------------------------------------------------------
// Positionen und Positionierung
// -----------------------------------------------------------------------------------

function getElementx(obj){
	var lPos = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			lPos += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	lPos += obj.x;
	return lPos;
}
function getElementy(obj){
	var oPos = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			oPos += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	oPos += obj.y;
	return oPos;
}

document.onmousemove = mouse_pos;

function mouse_pos(evt) {
	if(!evt) evt = window.event;
	var pos = new Object();
	pos.left = evt.clientX;
	pos.top = evt.clientY;
	var b = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
	window.document.documentElement : window.document.body || null;
	if (b)
	{
		pos.scrollLeft= pos.left + b.scrollLeft;
		pos.scrollTop = pos.top + b.scrollTop;
	}
	else if(document.layers)
	{
		// Netscape 4.
		pos.scrollLeft = evt.pageX;
		pos.scrollTop = evt.pageY;
		pos.left = evt.pageX - window.pageXOffset;
		pos.top = evt.pageY - window.pageYOffset;
	}
	xmouse = pos.left;
	ymouse = pos.top;
}

// -----------------------------------------------------------------------------------
// Browserversion
// -----------------------------------------------------------------------------------

var useragent = navigator.userAgent;
var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
var pos = useragent.indexOf('MSIE');
if (pos > -1)
{
	bVer = useragent.substring(pos + 5);
	var pos = bVer.indexOf(';');
	var bVer = bVer.substring(0,pos);
}
var pos = useragent.indexOf('Opera');
if (pos > -1)
{
	bVer = useragent.substring(pos + 6);
	var pos = bVer.indexOf(' ');
	var bVer = bVer.substring(0, pos);
}
if (bName == "Netscape")
{
	var bVer = useragent.substring(8);
	var pos = bVer.indexOf(' ');
	var bVer = bVer.substring(0, pos);
}
if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5)
{
	var pos = useragent.lastIndexOf('/');
	var bVer = useragent.substring(pos + 1);
}

// -----------------------------------------------------------------------------------
// Awaystatus anzeigen
// -----------------------------------------------------------------------------------

function ShowAwaystatusForm(){
	// Position ermitteln
	var x = $('#topuserpart').offset().left+70;
	var y = $('#topuserpart').offset().top-35;

	// Position setzen
	$('#changeawaystatus').show();
	$('#changeawaystatus').css('left', x+'px');
	$('#changeawaystatus').css('top', y+'px');

	showloader($( '#changeawaystatus' ), 1, 315, 113);
	$('#changeawaystatus').load('/index.php?ext=awaystatus');
}

function BlendoutAwaystatusForm(){
	$('#changeawaystatus').html( '' );
	$('#changeawaystatus').hide();
}


// -----------------------------------------------------------------------------------
// Neue Nachrichten anzeigen
// -----------------------------------------------------------------------------------
var titleOrig = "";
var titleSwitcher = null;
var titleSwitchText = "";

function TitleSwitch()
{
	var currTitle = document.title;
	document.title = titleSwitchText;
	titleSwitchText = currTitle;
}

function checkmypms(){

	$.getJSON('/extensionsv2/mod_newmail/checkmail.php', function (ret) {
		if(ret != null)
		{
			//Chat oeffnen?
			if(ret.open_chat == 1)
			{
				window.open('/index.php?tpl=blank&ext=jchat&action=chatroom','CHAT',
                            'width=810,height=620,scrollbars=no,resizable=no, status=no, location=no, toolbar=no');
			}

			//Sound abspielen?
			var soundhtml = '';

			if(ret.playsound == 1)
			{
				fwPlaysound('http://static.goolive.org/media/static/swf/'+ret.soundfile);
			}

			//Anzahl der Nachrichten
			var newmsg = ret.newmsg;

			//Anzeigen
			if(ret.logged != 1)
			{
				$('#mail-flag').hide();
				$('#mail-icon').html('');
			}
			else if(newmsg >= 1)
			{
				$('.mailcount').html(newmsg);
				$('#mail-flag').show();
				$('#mail-icon').html("<a href=\"/messenger/posteingang-1\"><img src=\"http://static.goolive.org/media/static/images/common/menu_mail_icon_ani_neu1.gif\" alt=\"\"  /></a>");

				if (titleOrig.length == 0)
					titleOrig = document.title;

				if (titleSwitcher != null)
					window.clearInterval(titleSwitcher);

				document.title = titleOrig;

				if (newmsg > 1)
					titleSwitchText = newmsg + " neue Nachrichten";
				else
					titleSwitchText = "Eine neue Nachricht";

				titleSwitcher = window.setInterval("TitleSwitch()", 5000);
			}
			else
			{
				$('#mail-flag').hide();
				$('#mail-icon').html("<a href=\"/messenger/posteingang-1\"><img src=\"http://static.goolive.org/media/static/images/common/menu_mail_icon_neu1.png\" alt=\"\" /></a>");

				if (titleSwitcher != null)
				{
					window.clearInterval(titleSwitcher);
					titleSwitcher = null;
					document.title = titleOrig;
				}
			}
		}
	});
}

// -----------------------------------------------------------------------------------
// Sonstige Funktionen
// -----------------------------------------------------------------------------------

function show_flash(src, width, height, quality){
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" +width+ "\" height=\"" +height+ "\">");
	document.write("<param name=\"quality\" value=\"" +quality+ "\" />");
	document.write("<param name=\"movie\" value=\"" +src+ "\" />");
	document.write("<param name=\"wmode\" value=\"transparent\" />");
	document.write("<embed src=\"" +src+ "\" quality=\"" +quality+ "\" width=\"" +width+ "\" height=\"" +height+ "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");
	document.write("</object>");
}

// target = Ziel Element
// jswindow = 1 (links) oder 2 (rechts) oder keine Angabe (kein Fenster, nur Loader)
// width = Breite
// height = Höhe
function showloader(target,jswindow, width, height){
	if(typeof(width)=='undefined'){
		width = 100;
	}
	if(typeof(height)=='undefined'){
		height = 100;
	}
	if(jswindow == 1) {
		$( '<div style="background-color:#FFFFFF;width:'+width+'px;height:'+height+'px;border:1px solid black;-moz-border-radius: 5px"><img style="position:relative;top:40px;display:block;margin-left:auto;margin-right:auto" src="http://static.goolive.org/media/static/images/jsloader.gif" border="0"></div>')
		.appendTo(target);
	}
	else if(jswindow == 2){
		target.set('html', '<table width="'+width+'" height="'+height+'" border="0" cellspacing="0" cellpadding="0"><tr><td height="5">&nbsp;</td><td height="19"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="15" height="5" /></td><td width="15"><img src="http://static.goolive.org/media/static/js/tip_balloon/stemt.gif" width="15" height="19" /></td><td width="15" height="19"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="15" height="5" /></td><td height="5">&nbsp;</td></tr><tr><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/lt.gif" width="5" height="5" /></td><td height="5" background="http://static.goolive.org/media/static/js/tip_balloon/t.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="15" height="5" /></td><td width="15" bgcolor="#FFFFFF"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="15" height="5" /></td><td background="http://static.goolive.org/media/static/js/tip_balloon/t.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="15" height="5" /></td><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/rt.gif" width="5" height="5" /></td></tr><tr><td background="http://static.goolive.org/media/static/js/tip_balloon/l.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="5" height="5" /></td><td colspan="3" align="center" valign="middle" bgcolor="#FFFFFF"><img src="http://static.goolive.org/media/static/images/jsloader.gif" border="0"></td><td background="http://static.goolive.org/media/static/js/tip_balloon/r.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="5" height="5" /></td></tr><tr><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/lb.gif" width="5" height="5" /></td><td colspan="3" background="http://static.goolive.org/media/static/js/tip_balloon/b.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="50" height="5" /></td><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/rb.gif" width="5" height="5" /></td></tr></table>');
	}
	else{
		$( '<img src="http://static.goolive.org/media/static/images/jsloader.gif" border="0">')
		.appendTo(target);
	}
}

// -----------------------------------------------------------------------------------
// Iframe Window
// -----------------------------------------------------------------------------------
function IFrameWindow(url,width,height,scrolling){
	// Position aus Cookie laden
	var x = x = readCookie('IframeWindow_x');

	if(x == null){
		var x = getElementx($('#topuserpart'))+200;
	}


	var y = window.getScrollTop()+50;
	// Scrollen
	if(scrolling == null){
		var scrolling = 'auto';
	}

	// Position setzen
	$('#IframeWindow').show();
	$('#IframeWindow').css('left', x+'px');
	$('#IframeWindow').css('top', y+'px');
	// Anzeigen
	$( '<table border="0" cellspacing="0" cellpadding="0"><tr><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/lt.gif" width="5" height="5" /></td><td height="5" background="http://static.goolive.org/media/static/js/tip_balloon/t.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="50" height="5" /></td><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/rt.gif" width="5" height="5" /></td></tr><tr><td background="http://static.goolive.org/media/static/js/tip_balloon/l.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="5" height="5" /></td><td align="left" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td id="msg_window_draghandler" style="cursor: move;"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="30" height="5" /></td><td width="20" height="20" align="right" valign="middle"><a href="javascript:closeIframeWindow();"><img src="http://static.goolive.org/media/static/images/window_close_n.gif" width="20" height="20" border="0" onmouseover="javascript:this.src=\'/templatesv2/style/window_close_h.gif\';" onmouseout="javascript:this.src=\'/templatesv2/style/window_close_n.gif\';" title="Fenster schließen" /></a></td></tr><tr><td height="5" colspan="2" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #000000;"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="30" height="5" /></td></tr></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="padding:5px;"><iframe src="'+url+'" width="'+width+'" height="'+height+'" frameborder="0" marginheight="0" marginwidth="0" scrolling="'+scrolling+'"></iframe></td></tr></table></td><td background="http://static.goolive.org/media/static/js/tip_balloon/r.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="5" height="5" /></td></tr><tr><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/lb.gif" width="5" height="5" /></td><td background="http://static.goolive.org/media/static/js/tip_balloon/b.gif"><img src="http://static.goolive.org/media/static/images/spacer.gif" width="50" height="5" /></td><td width="5" height="5"><img src="http://static.goolive.org/media/static/js/tip_balloon/rb.gif" width="5" height="5" /></td></tr></table>')
		.appendTo($('#IframeWindow'));

	// draggable machen (benötigt jquery ui core)
	$('#IframeWindow').draggable({
		handle : '#msg_window_draghandler',
		stop: function (event, ui) {
			var x = ui.offset.left;
			// Im Cookie speichern
			createCookie('IframeWindow_x',x,1);
		}
	});
	showShadow($('#IframeWindow'));
}

function closeIframeWindow(){
	$('#IframeWindow').hide();
	$('#IframeWindow').html('');
	hideShadow();
}

// -----------------------------------------------------------------------------------
// Tabsystem-Funktionen
// -----------------------------------------------------------------------------------

/*

color_activ: Hintergrundfarbe von aktiven Tabs
color_activ_font: Schriftfarbe von aktiven Tabs
color_inactiv: Hintergrundfarbe von inaktiven Tabs
color_inactiv_font: Schriftfarbe von inaktiven Tabs
color_border: Rahmenfarbe
color_hover: Hintergrundfarbe von Mouse Over
color_hover_font: Schriftfarbe von Mouse Over


<ul id="gootabs" >
<li onclick="activate_tab('gootabs',1)"><a class="active" id="gootabs1">Zusagen</a></li>
<li onclick="activate_tab('gootabs',2)"><a class="" id="gootabs2">Vielleicht</a></li>
<li onclick="activate_tab('gootabs',3)"><a class="" id="gootabs3">Absagen</a></li>
<li onclick="activate_tab('gootabs',4)"><a class="" id="gootabs4">Kommentare</a></li>
</ul>


*/

function write_css(color_activ, color_activ_font,color_inactiv,color_inactiv_font, color_border, color_hover, color_hover_font)
{
	document.write('<style type="text/css">');
	document.write('.gootab{');
	document.write('padding: 3px 10px;margin-left: 0;font: bold 11px Verdana;list-style-type: none;text-align: left;border-bottom-width: 1px;');
	document.write('border-bottom-style: solid; border-bottom-color: ' + color_border + ';');
	document.write('}');

	document.write('.gootab li{');
	document.write('display: inline;margin: 0;');
	document.write('}');

	document.write('.gootab li a{');
	document.write('text-decoration:none !important;');
	document.write('border-top-right-radius: 5px;border-top-left-radius: 5px;border-bottom-left-radius: 0px;border-bottom-right-radius: 0px;');
	document.write('-moz-border-radius-topleft: 5px;-moz-border-radius-topright: 5px;-moz-border-radius-bottomright: 0px;-moz-border-radius-bottomleft: 0px;');
	document.write('-webkit-border-top-left-radius: 5px;-webkit-border-top-right-radius: 5px;-webkit-border-bottom-left-radius: 0px;-webkit-border-bottom-right-radius: 0px;');
	document.write('text-decoration: none;padding: 3px 7px;margin-right: 3px;background-color: ' + color_inactiv + ';');
	document.write('color: ' + color_inactiv_font + ';border-top-width: 1px;border-right-width: 1px;');
	document.write('border-bottom-width: 0px;border-left-width: 1px;border-top-style: solid;border-right-style: solid;border-bottom-style: none;border-left-style: solid;');
	document.write('border-top-color: ' + color_border + '; border-right-color: ' + color_border + ';border-bottom-color: ' + color_border +' ;border-left-color: #CCCCCC;');
	document.write('}');

	document.write('.gootab li a:hover{color: ' + color_hover_font + ';');
	document.write('background: ' + color_hover + ';');
	document.write('background: -moz-linear-gradient(top, ' + color_hover + ', #ff6600);');
	document.write('background: -webkit-gradient(linear, left top, left bottom, from(' + color_hover + '), to(#ff6600));');
	document.write("filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='"+ color_hover +"', endColorstr='#ff6600');");
	document.write('background: -o-linear-gradient(top, ' + color_hover + ', #ff6600);');
	document.write('border: 1px solid #ff6600;');
	document.write('}');

	// !important MouseOver Effekt bei activen Tab deaktivieren
	document.write('.gootab li.selected a:hover{color: ' + color_activ_font + ';');
	document.write('background: ' + color_activ + ';');
	document.write('border: 1px solid '+color_border+';border-bottom: 0px;');
	document.write('}');

	document.write('.gootab li.selected a{position: relative;top: 1px;padding-top: 4px;font: bold 12px Verdana;');
	document.write('background-color: ' + color_activ + ';color: ' + color_activ_font + ';');
	document.write('}');
	document.write('</style>');

}

function activate_tab(menue,tab)
{
	   for(i=1;i<=1000;i++)
	   {
			   if(document.getElementById(menue + i)){
					document.getElementById(menue + i).className = "";
			   }else{
					break;
			   }
	   }

	   document.getElementById(menue + tab).className="selected";
}

/*

color_activ: Hintergrundfarbe von aktiven Tabs
color_activ_font: Schriftfarbe von aktiven Tabs
color_inactiv: Hintergrundfarbe von inaktiven Tabs
color_inactiv_font: Schriftfarbe von inaktiven Tabs
color_border: Rahmenfarbe
color_hover: Hintergrundfarbe von Mouse Over
color_hover_font: Schriftfarbe von Mouse Over


<ul id="gootabs" >
<li onclick="activate_tab('gootabs',1)"><a class="active" id="gootabs1">Zusagen</a></li>
<li onclick="activate_tab('gootabs',2)"><a class="" id="gootabs2">Vielleicht</a></li>
<li onclick="activate_tab('gootabs',3)"><a class="" id="gootabs3">Absagen</a></li>
<li onclick="activate_tab('gootabs',4)"><a class="" id="gootabs4">Kommentare</a></li>
</ul>

color_activ, color_activ_font,color_inactiv,color_inactiv_font, color_border, color_hover, color_hover_font


*/

// CSS Styles für Tabs setzen
write_css("#FFFFFF","#000000","#EEEEEE","#666666","#CCCCCC","#FF8E45","#FFFFFF");

$('.quickConfirm').die().live('click',function(){
	
	/*	Quick confirm
	 *	Function ist für Links gedacht, die nur ein Confirm enthalten.
	 *	Wenn man dann bestätigt, wird man nur auf eine bestimmte Seite weitergeleitet.
	 *
	 *	Um diese Function aufzurufen benötigt man in dem Element folgende Attribute:
	 *	href	= Link zur Seite !important
	 *	title	= Titel des PopUps !optional
	 *	info	= Inhaltstext des PopUps !important
	 */

	var href = $(this).attr('href')
	if( href == undefined){
		alert('Kein href Attribut gefunden')
		return false;
	}

	var text = $(this).attr('info')
	if(text == undefined){
		alert('Kein text Attribut gefunden')
		return false;
	}

	var title = $(this).attr('title')

	if(title == undefined || title == ''){
		title = "Info"
	}

	var yesClickedCallback = function(){
		location.href = ''+href;
		$(this).dialog('close');
	}
	
	jconfirm(title,text,yesClickedCallback)
	return false;
})


function jalert(text,title,func){

	if(title == '' || title == undefined){
		title = 'Hinweis!'
	}

	if(func == '' || func == undefined){
		func = function(){$(this).dialog('close');}
	}

	$('<div title="'+title+'">'
	+'<p>'+text+'</p>'
	+'</div>').dialog({
		resizable: false,
		modal: true,
		minWidth: 400,
		buttons:
		[
			{
				text: 'Ok',
				click: func
			}
		]
	});
}

function jconfirm(title,text,yesClickedCallback,labels,noClickedCallback){

	/*
	 * title				= Titel des PopUps !important
	 * text					= Text/HTML Inhalt des PopUps !important
	 * yesClickedCallback	= Function die ausgeführt werden soll, wenn true Button gedrückt wurde !important
	 * labels				= json array z.B. { 'yes' : 'Ja', 'no' : 'Abbrechen' } !optional
	 * noClickedCallback	= Function die ausgeführt werden soll, wenn false Button gedrückt wurde !optional
	 *
	 * Beispiel:
		jconfirm('Du Popo',
					'Ja, das bist du!',
					function(){

						Deine Function z.B. location.href = 'index.php';

						$(this).dialog('close');
					},
					{ 'yes' : 'Jepp','no' : 'Nein, danke'},
					function(){
						Deine Function z.B. location.href = 'index.php';
						$(this).dialog('close');
					}
				)
	 */

	if(title == undefined || title == ''){
		alert('Kein Titel vorhanden.')
		return;
	}

	if(text == undefined || text == ''){
		alert('Kein Inhaltstext vorhanden.')
		return;
	}

	if(yesClickedCallback == undefined || yesClickedCallback == ''){
		alert('Keine yesClickedCallback Function vorhanden.')
		return;
	}


	var button_yes = 'Ja';
	var button_no = 'Nein';
	
	if(labels != undefined && labels != ''){
		$.each(labels, function(k, v){
			if(k == 'yes'){
				button_yes = v;
			}
			if(k == 'no'){
				button_no = v;
			}
		});
	}

	if(noClickedCallback == undefined || noClickedCallback == ''){
		noClickedCallback = function() { $(this).dialog("close"); };
	}

	$('<div title="'+title+'">'
	+'<p>'+text+'</p>'
	+'</div>').dialog({
		resizable: false,
		modal: true,
		buttons: 
		[
			{
				text: button_yes,
				click: yesClickedCallback
			},
			{
				text: button_no,
				click: noClickedCallback
			}
		]
	});
}

function getMaxZIndex(){
	var zIndex = 0;
	$('div').each(function() {
		var akt = parseInt($(this).css('z-index'));
        zIndex = akt > zIndex ? akt : zIndex;
	});
	return zIndex+1;
}

$.fn.openCustomPopup = function(options) {
    var settings = {
        'height':  $(this).height(),
        'width':  450,
        'pos_x': false,
        'pos_y': false
    };
    settings = $.extend(settings, options);
    var zIndex = getMaxZIndex();
    var css = $(this).attr('style');
    if(!settings.pos_x || !settings.pos_y){
        totop = Math.round(settings.height/2);
        toleft = Math.round(settings.width/2);
        css += "height: "+settings.height+"px; width: "+settings.width+"px; position: absolute; z-index:"+zIndex+"; top:50%;margin-top:-"+totop+"px; left:50%;margin-left:-"+toleft+"px;";
    }else{
        css += "height: "+settings.height+"px; width: "+settings.width+"px; position: absolute; z-index:"+zIndex+"; top:"+settings.pos_y+"px;left:"+settings.pos_x+"px;";
    }
    $(this).attr('style',css);
    return this;
};

