//functions.js
function pf_createPopUpBox(child){
	var outerBox=document.createElement("div");
	outerBox.style.position="absolute";
	outerBox.style.padding="5px";
	outerBox.style.visibility="visible";
	outerBox.style.background="#BBBBBB";
	outerBox.style.width="auto";
	outerBox.style.height="auto";
	var innerBox=document.createElement("div");
	innerBox.style.padding="10px";
	innerBox.style.background="#F5F5f5";
	innerBox.style.border="1px";
	innerBox.borderstile="solidx";
	innerBox.style.bordercolor="#3C64A0";
	innerBox.appendChild(child);
	outerBox.appendChild(innerBox);
	return outerBox;
}
function pf_splitData(content) {
    var fields= new Array;
    var lines=content.split("\n");
    for (i=0; i<lines.length;i++){
        fields[i]=lines[i].split("\t");
    }
    return fields;
}
function pf_removePopUpBox(){
	document.body.removeChild(popUpBox);
}
function pf_createLink(txt,url){
	var ret= document.createElement("a");
	ret.setAttribute("href",url);
	ret.appendChild(document.createTextNode(txt));
	return ret;
}
function pf_getDataAsync(sourceURL,func_ToDo) {;
	try { 
		var requester = new XMLHttpRequest(); 
	} catch (error) { 
		var requester = new ActiveXObject("Microsoft.XMLHTTP");
	}	
	requester.onreadystatechange = function(){
		//try {
			if (requester.readyState == 4) {
				if (requester.status == 200) {
					func_ToDo(requester.responseText);
				} else {
				}
			} else {
			}
	}
	requester.open("GET", sourceURL, true);
	requester.send(null);
}
function pf_searchBox(){
	var div_searchBox = document.createElement("h4");
	  var div_search = document.createElement("div");
	    div_search.appendChild(document.createTextNode("Suche"));
	    var div_searchInput = document.createElement("input");
		div_searchInput.setAttribute("name","sucheInput");
		div_searchInput.setAttribute("type","text");
		div_searchInput.setAttribute("id","sucheInput");
		div_searchInput.setAttribute("onkeyup","pf_t_searchBandArray();");
	  div_search.appendChild(div_searchInput);
	    var div_list = document.createElement("div");
		div_list.setAttribute("id","listBox");
	  div_searchBox.appendChild(div_search);
	  div_searchBox.appendChild(div_list);
	return div_searchBox;
}
function pf_searchBoxList(){
	
}
function pf_browserCheck()
{
	if(document.ids)x='Netscape 4';
	else if( document.all && !document.getElementById )x='Internet Explorer 4';
	else if( window.opera && !document.createElement )x='Opera 5';
	else if( window.opera && window.getComputedStyle ){
	if(document.createRange)x='Opera 8';
				else if(window.navigate)x='Opera 7.5';
								 else x='Opera 7.2';                   
	}else if( window.opera && document.compatMode )x='Opera 7';
	else if( window.opera && document.releaseEvents )x='Opera 6';
	else if( document.contains && !window.opera )x='Konqueror 3';
	else if(window.pkcs11&&window.XML)x=window.external?'FireFox 2 / Gecko' : 'FireFox / Gecko Deer Park ';
	else if( window.getSelection && window.atob )x='Netscape 7';
	else if( window.getSelection && !document.compatMode )x='Netscape 6';
	else if( window.clipboardData && document.compatMode )
	  x=window.XMLHttpRequest? 'Internet Explorer 7' : 'Internet Explorer 6';
	else if( window.clipboardData ){
		x='Internet Explorer 5';
		 if( !document.createDocumentFragment ) x+='.5';
		 if( document.doctype && !window.print ) x+='Mozilla';
	}else if( document.getElementById && !document.all ) x='Opera 4';
	else if( document.images && !document.all ) x='Netscape 3';
	else if(document.clientWidth&&!window.RegExp)x='Konqueror 2';
	else x='Unbekannt';
	return x;
}
function pf_onlyFF(){
	if(window.pkcs11&&window.XML){
		return true;
	}else{
		return false;
	}
}
function pf_messagedelayWindow(){
	var waitWindow = document.body;
    waitWindow.appendChild(pf_delayMessage('Deine Nachricht wird versendet','den text sollte man aendern')); 
}
function pf_disabledelayWindow(){
	document.getElementById('warteMeldung').style.display='none';
}
function pf_delayMessage(sTitel,sText){
	var outterDiv = document.createElement('div');
	outterDiv.setAttribute('class','warteMeldung');
	outterDiv.setAttribute('id','warteMeldung');
	var innerDiv = document.createElement('div');
	innerDiv.setAttribute('class','textgr');
	var firstText = document.createElement('p');
	var waitImage = document.createElement('img');
	waitImage.setAttribute('src','http://static.partyfans.com/static/pics/layout/laden.gif');
	waitImage.setAttribute('alt','Load-Image');
	firstText.appendChild(waitImage);
	var secondText = document.createElement('p');
	var secondTextBold = document.createElement('b');
	secondTextBold.appendChild(document.createTextNode(sTitel));
	secondText.appendChild(secondTextBold);
	//var thirdText = document.createElement('p');
	//thirdText.appendChild(document.createTextNode(sText));
	innerDiv.appendChild(firstText);
	innerDiv.appendChild(secondText);
	//innerDiv.appendChild(thirdText);
	outterDiv.appendChild(innerDiv);
	return outterDiv;
}

function createContainerlist(posLeft,posTop,bNewDesign){
	var oContainer=$("<div></div>");
	var oList=$("<ul></ul>");
	oContainer//.css("margin-top",oDistLink.attr("offsetHeight"))
		.css("position","absolute")
		.css("left",posLeft)
		.css("top",posTop)
		.css("display","none");
	if($.browser.msie && gOldIE){
		oContainer.css("width","200px");
	}

	if(bNewDesign){
		oContainer.addClass("userLabel");
		oContainer.css({"margin-top":"2px","margin-left":"7px"});
	}else{
		oContainer.addClass("suggestList");
	}
	oContainer.addClass("text");
	oList.css("padding-left","2px").css("padding-right","2px").css("margin","0").css("position","static");
	oContainer.append(oList);
	

	oContainer.addItem=function(oLI,f){
			oLI.addClass("tStyleInactive")
			if(bNewDesign){ 
				oLI.css({"color":"white","height":"16px","padding-top":"2px"});
			}else{
				oLI.css("padding-top","3px");
			}

			if(typeof f === "function"){
				oLI.css("cursor","pointer");
				
				oLI.click(function(){
					f();
					oContainer.slideUp("fast");
				});

				oLI.hover(function(){
					$(this).removeClass("tStyleInactive").addClass("tStyleActive");
					if(bNewDesign) $(this).css({"color":"black","background-color":"white"});
				},function(){
					$(this).removeClass("tStyleActive").addClass("tStyleInactive");
					if(bNewDesign) $(this).css({"color":"white","background-color":""});
				});
			}


			$(this).find("ul").append(oLI);
		};

	oContainer.removeItems=function(){
		$(this).find("ul").html("");
	}

	oContainer.setTitle=function(sTitle){
		//TODO: nur ein mal zulassen
			var oTitle=$("<p></p>");
			oTitle.css("margin","2px").css("margin-bottom","4px")
				.html(sTitle);
			if(bNewDesign) oTitle.css("border-bottom","1px solid #dddddd")
			$(this).prepend(oTitle);
		};


	oContainer.toggle=function(e){
		if ($(this).css("display")=="none"){
			$(this).slideDown("fast");
			e.stopPropagation();
		}else{
			$(this).slideUp("fast");
		}
	}

	$("body").click(function(){
		oContainer.slideUp("fast");
	});

	return oContainer;


}

function openSBWindow(iUserId){
	window.open('/community/details.php?detid='+iUserId,'','scrollbars=yes,width=640,height=450');
}
function openFBSBWindow(iUserId){
	window.open('http://www.facebook.com/profile.php?id='+iUserId,'','');
}

function openPfWindow(sURL){
	window.open(sURL,'','scrollbars=yes,width=640,height=450');
}

function changePage(sDest,oData,sLoadDiv){
		oData.noHead=1;
	$.get(sDest,oData,function() {return function(dat){
		$("#inhaltsDiv").html(dat);alert("test");
		/*if(sLoadDiv!=null) {
			//$("#".sLoadDiv).remove();
		}*/
	}}(sLoadDiv));
}

	function dynamicNickSort(iNickColumn){
		return function (a,b){
			if(a[iNickColumn].toLowerCase()>b[iNickColumn].toLowerCase()){
				return 1;
			}else if(a[iNickColumn].toLowerCase()<b[iNickColumn].toLowerCase()){
				return -1;
			} else {
				return 0;
			}
		}
	}

	function getUserId(oInput){ //gibt die id zu dem in ein inputfeld getippten nick zurueck, verwendet hierfuer das array aus auotcomplete.js
		var sNick=oInput.val();

		for(var i=0;i<flArray.length;i++){
			if(flArray[i][2]===sNick){
				return flArray[i][1];
			}
		}
		return null;

	}

//tag bestimmen
function getDayName(iWeekday){
	switch (iWeekday){
		case 0:return "Sonntag";
		case 1:return "Montag";
		case 2:return "Dienstag";
		case 3:return "Mittwoch";
		case 4:return "Donnerstag";
		case 5:return "Freitag";
		case 6:return "Samstag";
		default: return getDayName(iWeekday%7);
	}
}
//monatsnamen bestimmen
function getMonthName(iMonth,bShort){
	if(bShort){
		switch (iMonth){
			case 0:return "Jan";
			case 1:return "Feb";
			case 2:return "M&auml;r";
			case 3:return "Apr";
			case 4:return "Mai";
			case 5:return "Jun";
			case 6:return "Jul";
			case 7:return "Aug";
			case 8:return "Sep";
			case 9:return "Okt";
			case 10:return "Nov";
			case 11:return "Dez";
			default: return "";
		}
	}else{
	switch (iMonth){
		case 0:return "Januar";
		case 1:return "Februar";
		case 2:return "M&auml;rz";
		case 3:return "April";
		case 4:return "Mai";
		case 5:return "Juni";
		case 6:return "Juli";
		case 7:return "August";
		case 8:return "September";
		case 9:return "Oktober";
		case 10:return "November";
		case 11:return "Dezember";
		default: return "unbekannt";
	}
	}
}


//datum um einen monat erhoehen
function dIncMonth(dDate){
	var month=dDate.getMonth();
	var year=dDate.getFullYear();
	if(month<11){
		month++;
	}else{
		month=0;
		year++;
	}
	return new Date(year,month,1);
}

//datum um einen monat zurueckversetzen
function dDecMonth(dDate){
	var month=dDate.getMonth();
	var year=dDate.getFullYear();
	if(month>0){
		month--;
	}else{
		month=11;
		year--;
	}
	return new Date(year,month,1);
}

function getTimePassed(iTimestamp, bExtended,bShort){//timestamp in sekunden!
	var differenz=parseInt((new Date().getTime()/1000-iTimestamp)/60);//vergangene zeit in minuten
var sAusgabe="";
var bRelativ=false;
var bSemiRelativ=false;

	if (differenz==0){
		return "Gerade";bRelativ=true;
	} else if (differenz==1){ //weniger als eine stunde?
		sAusgabe= differenz+((bShort) ? " Min" : " Minute");bRelativ=true;

	}else if (differenz<60){ //weniger als eine stunde?
		sAusgabe= differenz+((bShort) ? " Min" :  " Minuten");bRelativ=true;
	}else if(differenz<60*2){ //weniger als zwei stunden?
		sAusgabe= "1 Stunde";bRelativ=true;

	}else if(differenz<60*24){ //weniger als ein tag?
		sAusgabe= parseInt(differenz/60)+((bShort) ? " Std" :  " Stunden");bRelativ=true;

/*	}else if(differenz<60*24*2){//weniger als 2 tage?
		return "1 Tag";*/
	}else {
		var dBaseDate=new Date(iTimestamp*1000);
		var dToday=new Date();dToday.setHours(0);dToday.setMinutes(0);

		if(dBaseDate.getTime()>(dToday.getTime()-3600000*24)){ //gestern?
			sAusgabe= "Gestern";bSemiRelativ=true;
		} else if(dBaseDate.getTime()>(dToday.getTime()-3600000*24*6) ){ //innerhalb der letzen woche?
			sAusgabe= getDayName(dBaseDate.getDay());
		}else if(dBaseDate.getTime()>(dToday.getTime()-3600000*24*360) ){ //innerhalb eines jahres?
			sAusgabe= dBaseDate.getDate()+". "+getMonthName(dBaseDate.getMonth(),bShort);
		} else {
		//sonst datum zurueckgeben
		sAusgabe= (dBaseDate.getDate())+"."+(dBaseDate.getMonth()+1)+"."+dBaseDate.getFullYear();
		}
	}
	if(bExtended){
		if(bRelativ){
			sAusgabe="Vor "+sAusgabe;
		}else {
			var iStd=dBaseDate.getHours();iStd=(iStd<10) ? "0"+iStd : iStd;
			var iMin=dBaseDate.getMinutes();iMin=(iMin<10) ? "0"+iMin : iMin;
			sAusgabe=sAusgabe+" um "+iStd+":"+iMin;
			if(!bSemiRelativ){
				sAusgabe="Am "+sAusgabe;
			}
		}
	}
	return sAusgabe
}

	function setCookie(sName,sVal,iDauer){//dauer in tagen
		if(!iDauer){
			iDauer=10000;
		}
		var dBis=new Date();
		dBis.setTime(dBis.getTime()+iDauer*24*60*60*1000);
		
		document.cookie = sName+"="+sVal+"; expires="+dBis.toGMTString()+"; path=/";
	}

	function getCookie(sName){
		var aRows=document.cookie.split(";");

		for(var i=0;i<aRows.length;i++){
			var sRow=aRows[i];

			while (sRow.charAt(0)==' ') {
				sRow=sRow.substring(1,sRow.length);
			}
			if(sRow.indexOf(sName+"=")==0){
				return sRow.substring(sName.length+1,sRow.length);
			}

		}

		return null;
	}

	function deleteCookie(sName){
		setCookie(sName,"",-1);
	}


	function setupTextLimit(oFeedTextField,iLimit,oLimitCounterField){
		oFeedTextField.change(function(){
			limitInputLen(oFeedTextField.get(0),iLimit,"",oLimitCounterField.get(0));
		});

		oFeedTextField.keyup(function(){ 
				$(this).change();
			});
		//ueberwachung fuer aenderung durch zb pasten
		oFeedTextField.focus(function(e){
					var thisid=$(this).attr("id");
					var sCode="checkChange('"+thisid+"')";
					$(this).data("checkTimer",setInterval(sCode,800));
	
	
				}).blur(function(e){
					clearInterval($(this).data("checkTimer"))
				});

	}


	function parseResURL(sURL,bInText){
		

		var joURLData=parseURL(sURL,bInText);

		if(!joURLData && bInText){
			return null;
		}

		var joData={sTitle:"Internetseite",sType:"URL"}

		var domain=joURLData.domain.toLowerCase();
		var path=joURLData.path.toLowerCase();


		if(domain=="partyfans.com"){ //pf-eigene ressource
			switch(path){
				case "/termine/details.php":
					joData={sTitle:"Event",sType:"Event"};
					break;
				case "/community/details.php":
					joData={sTitle:"Steckbrief",sType:"SB"};
					break;
				case "/community/album.php":
					joData={sTitle:"Fotoalbum",sType:"Album"};
					break;
				case "/community/partylog.php":
					//TODO: unterscheiden: einzelner beitrag / plog gesamt
					joData={sTitle:"Plog",sType:"Plog"};
					break;
				case "/photos/bild.php":
					joData={sTitle:"Foto",sType:"Foto"};
					break;			
				default: 
					var dest=parseInt(getURLParam(sURL,"dest"));
					switch(dest){
						case 66://Fotobericht
							joData={sTitle:"Fotobericht",sType:"FB"};
							break;
						default:
							joData={sTitle:"Partyfans Seite",sType:"Pf"};
					}


			}

		}else if(domain=="youtube.com"){
			if(path=="/watch"){
				joData={sTitle:"Youtube Video",sType:"Video"};
			}
		}
		joData.sURL=joURLData.sURL;
		return joData;

	}

	function getURLParam(sURL,sParamName){
	
		var name = sParamName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( sURL );
		if( results == null ){
			return "";
		}else{
			return results[1];
		}

	}

	function parseURL(sURL,bInText){
		if(bInText){
			var asBuffer=sURL.match(/(http|https|ftp)\:\/\/[a-z0-9]+[a-z0-9\-\.]+\.[a-z]{2,3}(\/\S*)?/gi);
			if(!asBuffer || asBuffer.length==0) { //ganz simpel versuchen
				asBuffer=sURL.match(/www\.[a-z0-9\-\.]+\.[a-z]{2,3}(\/\S*)?/gi);
				if(!asBuffer || asBuffer.length==0){
					return null;
				}
			}
			sURL=asBuffer[0];//"erstbestes" ergebnis
		}
		var res=parseUri(sURL);

		//TODO: integriere das in die parseUri regexp...*argh*
		//host zerlegen in subdomain und domain
		var domainData= res.host.split(".");
		res.subdomain=domainData[0];
		res.domain=domainData[1]+"."+domainData[2];
		res.sURL=sURL;

		return res;


	}

// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};





	function checkChange(sId){
		var id="#"+sId;
		var obj=$(id);
		if(obj.val()!=obj.data("lastVal")){
			obj.data("lastVal",obj.val());
			obj.change();
		}

	}
	//setzt "standardtext" als beschriftung, kann string oder array fuer text verwenden
	function setTextboxInlineDescription(oTextinput,mText){

			var sDefaultColor=oTextinput.css("color");
			var sDescriptionColor="rgb(102,102,102)";

			//moeglichkeit abfangen, dass das eingabefeld bereits veraendert wurde
			if(oTextinput.data("fresh")!==false){
				oTextinput.data("fresh",true).data("cleancount",1).css("color",sDescriptionColor);

				if(mText[0].length>1){
					oTextinput.val(mText[0]);
				} else {
					oTextinput.val(mText);
				}

			}

			oTextinput.unbind("blur.description").unbind("focus.description");

			oTextinput.bind("focus.description",function(){
				if($(this).data("fresh")){
					$(this).val("").css("color",sDefaultColor);
				}
				$(this).data("focus",true);
			}).bind("blur.description",function(mText){ return function(){
				
				if($(this).data("focus")){
					if($(this).val()!=""){
						$(this).data("fresh",false);
					}else{
						var cc=$(this).data("cleancount");
						
						//wurde ein array uebergeben, wenn ja das passende element anzeigen
						if(mText[0].length>1){
							$(this).val(mText[cc]);
						} else {
							$(this).val(mText);
						}
						$(this).css("color",sDescriptionColor)
						cc++;
						$(this).data("cleancount",cc);
					}
				}
				$(this).data("focus",false);
			}}(mText));	


	}

	function limitInputLen(oTexbox,iLen,sCounterId,oCounter,iAutoGrow){
		if(oTexbox.value.length>iLen){
			oTexbox.value=oTexbox.value.substring(0,iLen);
		}
		if(oCounter==null){
			//oCounter=$('#'+sCounterId).get(0); 
			oCounter=document.getElementById(sCounterId);
		}
		if(oCounter){
			var iRemaining=iLen-oTexbox.value.length;
			if(iRemaining>=0){
				oCounter.innerHTML=iRemaining;
			}
		}
		
		//bonusfunktion: textbox erweitern
		if(iAutoGrow){ //iAutoGrow gibt die spaltenzahl an

		}

	}


	function limitInputLenJQ(oTextbox,iLen,sCounterId,oCounter,iAutoGrow){
		oTextbox=$(oTextbox);
		if(oTextbox.val().length>iLen){
			oTextbox.val(oTextbox.val().substring(0,iLen));
		}
		if(oCounter==null){
			oCounter=$('#'+sCounterId); 
			//oCounter=document.getElementById(sCounterId);
		}
		if(oCounter){
			var iRemaining=iLen-oTextbox.val().length;
			if(iRemaining>=0){
				oCounter.html(iRemaining);
			}
		}
		
		//bonusfunktion: textbox erweitern
		if(iAutoGrow){ //iAutoGrow gibt die spaltenzahl an

		}

	}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};


function getFeedbackBox(oTarget,iCatId,bFBMode){

var oBox=$("#feedbackLayer");

if(oBox.length==0){

	oBox=$('<div style="position:absolute;top:100px;padding:10px 20px 10px 20px;z-index:99990;width:360px;display:none;font-size:10px;" class="suggestList" id="feedbackLayer"><h2>Feedback</h2><ul style="padding-left: 0pt;" class="eventDetList"><li><span class="ceLabel">Typ:</span><b><a href="#" class="dropDownLink" id="feedbackTyp" style="">Verbesserungsvorschlag</a></b></li><li><span class="ceLabel">Beschreibung:</span><span id="feedbackSpaceCounter" style="color: grey; margin-left: 310px;" class="ceLabel">300</span><textarea id="feedbackText" class="form detailData" style="display: inline; color: rgb(102, 102, 102);" rows="1" cols="16"></textarea></li></ul><span style="display: block; text-align: right; width: 100%;"><input type="button" class="" value="abschicken!" id="feedbackSubmit"><input type="button" value="abbrechen" id="feedbackAbbort"></span></div>');
	
	if(!iCatId) iCatId=0;
	oBox.data("iTyp",0);

	if(iCatId==3){
		var oHWLink=$('<p><a href="/?artid=69"><b>Hinweis:</b> Bitte lies zun&auml;chst den Artikel zur aktuellen Testversion.</p></a>');
		initAjaxLinks(oHWLink)
		oBox.find("ul").after(oHWLink);
	}

	oBox.find("#feedbackTyp").click(function(oBox){ return function(e){
			var arrTypen=[[0,"Verbesserungsvorschlag"],[1,"Kritik"],[2,"Bug (Fehler)"]];	
			oTypLink=$(this);
			typList=$("#feedbackTypList");
			
			if(typList.length==0){
			
			typList=createContainerlist(oTypLink.offset().left,oTypLink.offset().top+oTypLink.outerHeight());
			typList.css("z-index","99992").attr("id","#feedbackTypList");
	
				for(var i=0;i<arrTypen.length;i++){
					typList.addItem($("<li>"+arrTypen[i][1]+"</li>"),function(sTyp,iTypId){ return function(){ 
	
								oTypLink.html(sTyp);
								oBox.data("iTyp",iTypId);
								
							};}(arrTypen[i][1],arrTypen[i][0]));
				}
			$("body").append(typList);
			}
	
	
			typList.css("left",$(this).offset().left+"px").css("top",($(this).offset().top+$(this).outerHeight())+"px");
			typList.toggle(e);
			return false;
		};}(oBox));
	var oFeedbackText=oBox.find("#feedbackText")
	setTextboxInlineDescription(oFeedbackText,"Dein Text");
	oFeedbackText.autoGrow(6);
	setupTextLimit(oFeedbackText,300,oBox.find('#feedbackSpaceCounter'));

	oBox.find("#feedbackAbbort").click(function(){$("#feedbackLayer").slideUp("slow");});
	oBox.find("#feedbackSubmit").click(function(oBox){return function(){
				if($("#feedbackText").val()=="Dein Text"){
					alert("Bitte eine Beschreibung eingeben");return false;
				}
				BrowserDetect.init();

				var bFB=false;
				if(bFBMode)bFB=bFBMode;
				$.get("/json/set-feedback.php",{"iCatId":iCatId,"iTyp":oBox.data("iTyp"),"sDescription":$("#feedbackText").val(),"sBrowser":BrowserDetect.browser,"sBrowserVersion":BrowserDetect.version,"sOS":BrowserDetect.OS,"bFBMode":bFB},function(data){
					alert("Dein Feedback wurde versendet. Vielen Dank!");
					$("#feedbackLayer").slideUp("slow");
							
			});
	
	
	}}(oBox));

	oTarget.append(oBox);
	}

	return oBox

}

function getRelWeek(iUnixTimestamp){
	var iNow=new Date().getTime()/1000;
	if((iUnixTimestamp-iNow)<-86400) return -1;

	var iDifference=iUnixTimestamp-iNow+86400;
	var iWeeks=parseInt(iDifference/86400/7)
	return iWeeks;
}

function initUserImageLink(oImageLink) {
	oImageLink.replaceWith(getUserImageLink({"nickname":oImageLink.find('.sNickname').val(),"id":oImageLink.find('.iUserId').val(),"hatBild":1,"status":(oImageLink.hasClass("userOnline")) ? 0 : 1}));

};

function initUserImageLinks(oContainer){
	oContainer.find(".userImageLink").each(function(){
		initUserImageLink($(this));
	});
}

function getUserImageLink(aUser,iHeight){

	if(!iHeight) iHeight=44;

	var sImageSrc="";
	if(aUser['hatBild']){
		sImageSrc='/community/details/getThumb.php?iUserId='+aUser['id'];
	}else{
		sImageSrc='http://static.partyfans.com/pics/layout/sections/kein_foto/';
		sImageSrc+=(aUser['geschl']==1)?"m3.gif":"w3.gif";
	}
		var sChatSymbol=(aUser['status']==0) ? "imo" : "ima";
		var ret='<div class="userImageLink  ';
		ret+=(aUser['status']==1) ? "userAway" : "userOnline";
		ret+='" style="display:inline-block;"><div class="userLabel userActionLabel" style="display:none;"><a href="#" class="chatLink"><img src="/static/pics/'+sChatSymbol+'.gif" title="In Messenger einladen" border="0" height="7" width="9"></a><a href="#" class="msgLink"><img style="border: none; margin-left: 3px; margin-right: 5px;" src="http://static.partyfans.com/static/pics/site/nn.gif" title="Nachricht schreiben" height="7" width="9" ></a></div> <div class="userLabel userNameLabel" style="display:none;">'+aUser['nickname']+'</div><img style="border:0;display:inline;border:0 !important;height:'+iHeight+'px;width:auto;" class="userImageBorder userLinkThumb"  src="'+sImageSrc+'"></div>';
	var oUserImageLink=$(ret);

	if(aUser['status']==1) oUserImageLink.find(".userLinkThumb").css({"opacity":0.5});//.grayscale();

		oUserImageLink.click(function(iUserId){ return function(e){
				openSBWindow(iUserId);
				e.preventDefault();
				e.stopPropagation();
				$(this).mouseleave();
				return false;
			}}(aUser['id']));

		oUserImageLink.find(".chatLink").click(function(iUserId,sNickname){return function(e){
			openIMField(iUserId,sNickname,0);
			e.preventDefault();
			e.stopImmediatePropagation();
			$(this).mouseleave();
			return false;
		}}(aUser['id'],aUser['nickname']));

		oUserImageLink.find(".msgLink").click(function(iUserId,sNickname){return function(e){
			openNewMessage(sNickname);
			e.preventDefault();
			e.stopImmediatePropagation();
			$(this).mouseleave();
			return false;
		}}(aUser['id'],aUser['nickname']));

	oUserImageLink.hover(function(){
		var iScaledHeight=60;
		var oImage=$(this).find(".userLinkThumb");
		var iImageWidth=oImage.width()
		//$(this).css("width",iImageWidth);
		var iScaledWidth=parseInt(iImageWidth/iHeight*iScaledHeight);
		var iMarginLeft=parseInt((iScaledWidth-iImageWidth)/-2);
		var iMarginTop=parseInt((iScaledHeight-iHeight)/-2);
		oImage.css("position","absolute");
		var oLabel=$(this).find(".userLabel");
//oImage.css({"margin-left":iMarginLeft+"px","margin-top":iMarginTop+"px",height:iScaledHeight+"px",width:"auto","opacity":1.0,"z-index":99996});
//oLabel.fadeIn("fast");
	oImage.animate({"margin-left":iMarginLeft+"px","margin-top":iMarginTop+"px",height:iScaledHeight+"px",width:iScaledWidth+"px","opacity":1.0,"z-index":99996},70,function(){oLabel.fadeIn("fast");});
		var oNameLabel=$(this).find(".userNameLabel");
		oNameLabel.css({"margin-top":iHeight-iMarginTop-oNameLabel.outerHeight()+"px","margin-left":iMarginLeft+"px","min-width":iScaledWidth-4+"px"});//.fadeIn("fast");
		$(this).find(".userActionLabel").css({"margin-left":iMarginLeft+"px","margin-top":iMarginTop+"px"});

	},function(){
		$(this).find(".userLabel").fadeOut("fast");
		var oImage=$(this).find(".userLinkThumb");
		var fOpacity=( $(this).hasClass("userAway")) ? 0.5 : 1.0;
		
		oImage.stop().css({"margin-left":0,"margin-top":0,height:(iHeight+2)+"px",width:"auto","opacity":fOpacity,"z-index":5995});
	});
oUserImageLink.css({"height":(iHeight+2)+"px","width":(iHeight/3*4+2)+"px"});

	return oUserImageLink;
}

function arrayDiff(a1,a2,sIndexToCompare,fSort){//erwartet vorsortiere arrays
	var aA1=a1.slice(0);//array kopieren um original zu bewahren
	var aA2=a2.slice(0);
	//arrays nach index sortieren
	if(!fSort) fSort=function(a,b){//standardmaessig nach zahlenwert sortieren
		return parseInt(a[sIndexToCompare])-parseInt(b[sIndexToCompare]);//mit parseint typ sicherstellen
	};	
	aA1.sort(fSort);
	aA2.sort(fSort);
	var oDiff={aOnly1:[],aOnly2:[],aBoth:[]};

	if(aA1.length==0){
		oDiff.aOnly2=aA2;return oDiff;
	}else if(aA2.length==0){
		oDiff.aOnly1=aA1;return oDiff;
	}

	var i=0;
	do{
		if(aA1[i][sIndexToCompare]<aA2[i][sIndexToCompare]){
			oDiff.aOnly1.push(aA1.splice(i,1)[0]);
			
		}else if(aA1[i][sIndexToCompare]>aA2[i][sIndexToCompare]){
			oDiff.aOnly2.push(aA2.splice(i,1)[0]);
		}else{//wert gleich, weiter zum naechsten index
			oDiff.aBoth.push(aA1.splice(i,1)[0]);
			aA2.splice(i,1);//auch im zweiten array ausschneiden, um symmetrie zu bewahren
			//i++;
		}

	}while(aA1.length > i && aA2.length > i);

	//moegliche ueberhaenge beruecksichtigen
	if(aA1.length>0){
		oDiff.aOnly1=oDiff.aOnly1.concat(aA1.slice(i));
	}else if(aA2.length > 0){
		oDiff.aOnly2=oDiff.aOnly2.concat(aA2.slice(i));
	}

	return oDiff;
}

function setBatchCount(oContainer,iValue){
	if(iValue<=0){
		oContainer.hide();
	}else{
		oContainer.html(iValue).show();
	}
}

function showMessage(iMsgId){
	openMessage(iMsgId);
	//eintrag entfernen
	for(var i=0;i<goNewMessages.aNewMessages.length;i++){
		if(goNewMessages.aNewMessages[i].nr==iMsgId){
			goNewMessages.aNewMessages.splice(i,1);
			checkNewMessages(goNewMessages.aNewMessages);
			return;
		}
	}
}
var playSound = false;
function setSound(o) {
	if (o=='1') playSound = true;
}

function msgTitleBlink(iInterval) {
if(!iInterval) iInterval=1500;

	window.setTimeout(function(sNormTitle){return function(){document.title =sNormTitle;}}(document.title),iInterval);
	document.title = "Neue Nachrichten - partyfans.com";

}

function checkNewMessages(aNewMessages){
// benoetigt: var  goNewMessages={aNewMessages:[],oNewMsgList:null};
	if(aNewMessages){
		//TODO: auf aenderungen anpassen
		oDiff=arrayDiff(goNewMessages.aNewMessages,aNewMessages,"nr");
		
		//ggf sound abspielen
		if (aNewMessages.length!=oDiff.aBoth.length && playSound) try { soundManager.play('beep'); } catch(e) {};


		var oMsgList=goNewMessages.oNewMsgList;

		if(!oMsgList){
			var oMsgLink=$("#msgLink");
			var posLeft=oMsgLink.offset().left;
			var posTop=oMsgLink.offset().top+oMsgLink.outerHeight();
			oMsgList=createContainerlist(posLeft,posTop,true);
			oMsgList.attr("id","newMsgList");
			oMsgList.css({"z-index":"99999","padding":"2px 3px 1px 3px"});
	

			
		
			$("body").append(oMsgList);
			goNewMessages.oNewMsgList=oMsgList;
			oMsgList.hover(function(){$(this).stop(true,true).show();},function(){$(this).slideUp("fast");});

		}else{
			oMsgList.removeItems();
		}
		var oUserLink=null;
		var oLI=null;
		var oMsgLink=null;
		for(var i=0;i<aNewMessages.length;i++){
			oUserLink=$('<a href="#">'+aNewMessages[i].nickname+'</a>').click(function(iUserId){return function(){
					$(this).parent().mouseout();openSBWindow(iUserId);return false;
				}}(aNewMessages[i].id));
			oMsgLink=$('<a href="#">'+aNewMessages[i].betreff+'</a>').css({"font-weight":"bold","margin-right":"5px"});
			oMsgLink.click(function(iMsgId){ return function(){
					$(this).parent().mouseout();showMessage(iMsgId);return false;}}(aNewMessages[i].nr)
				);
			oLI=$("<li></li>").append(oMsgLink).append(oUserLink);

			oMsgList.addItem(oLI);
		}
	goNewMessages.aNewMessages=aNewMessages;
	}
	


	setBatchCount($("#msgLI").find(".batchNo"),goNewMessages.aNewMessages.length);
	var oMsgSpan=$("#messSpan");
	$("#messCount").html(goNewMessages.aNewMessages.length);

	if(goNewMessages.aNewMessages.length>0){
		oMsgSpan.show();
		$("#msgLink").css({"background-position":"-20px center"});
	}else{
		oMsgSpan.hide();
		$("#msgLink").css({"background-position":"left center"});
	}
	
}
