
 // Global Vars
	var ein_tag			= 1000*60*60*24;
	var heute			= new Date();
	var gestern			= new Date(heute.getMilliseconds()-ein_tag);
	var morgen			= new Date(heute.getMilliseconds()+ein_tag);
	var login_zeit		= new Date(loginTime*1000);
	var browser			= navigator.userAgent.toLowerCase();
	var is_ie			= (agt.indexOf("msie") != -1);
	var is_opera		= (window.opera);
	



 // getElementBy ID
	function _id( idname ){
		return document.getElementById( idname );
	}



 // getElementsBy Klasse
	function _class( classname ){
		return document.getElementsByClassName( classname );	
	}
	
	if(!document.getElementsByClassName) document.getElementsByClassName = function(class_name) {
		var docList = this.all || this.getElementsByTagName('*');
		var matchArray = new Array();
		
		var re = new RegExp("(?:^|\\s)"+class_name+"(?:\\s|$)");
		for (var i = 0; i < docList.length; i++) {
			if (re.test(docList[i].className) ) {
				matchArray[matchArray.length] = docList[i];
			}
		}
	
		return matchArray;
	}



 // addEvent
	function addEvent(obj, eventType, func){
		if(obj.addEventListener){
			obj.addEventListener(eventType, func, false);
			return true;
		}
		else if (obj.attachEvent){
			return obj.attachEvent("on"+eventType, func);
		}
		else{
			return false;
		}
	}



 // Onlinezeit
	var onlineZeit_timer, logout_timer, logout_count=61, timeout_on=true;
	var titelVorher= document.title, titelStand, mail_check_count=0;
	function onlineZeit(){
		var jetzt	= new Date();
		var in_sec	= (jetzt-login_zeit)/1000;
		var in_min	= (jetzt-login_zeit)/1000/60;
		var in_std	= (jetzt-login_zeit)/1000/60/60;
		
		if(!onTimeSec||in_min>60){
			onTimeSec= false;
			if(in_min>60){
				var rest= parseInt(in_min)-(parseInt(in_std)*60);
				_id('onlinezeit').innerHTML= parseInt(in_std)+' h, '+rest+' min';
			}else{
				_id('onlinezeit').innerHTML= parseInt(in_min)+' min';
			}
		}else{
			if(in_sec>60){
				var rest= parseInt(in_sec)-(parseInt(in_min)*60);
				_id('onlinezeit').innerHTML= parseInt(in_min)+'.'+Zerofill(rest,2)+' min';
			}else{
				_id('onlinezeit').innerHTML= parseInt(in_sec)+' sec';
			}
		}
		
		if(!is_gast) if( mail_check_count >= (onTimeSec?60:1) ){
			was_gibts_neues();
			mail_check_count=0;
		}
		mail_check_count++;
	}
	function timeout(){
		if(timeout_on===false || is_gast===true){
			close_popup();
			return false;
		}
		logout_timer= window.setInterval(function(){
			if(titelStand){
				logout_count--;
				titelStand= false;
				if(logout_count<1){
					clearInterval(logout_timer);
					time_logout();
				}else{
					popup('<b>Hinweis</b><br><br>Du wirst in <b>'+logout_count+'</b> Sekunden<br>automatisch ausgeloggt!<br><br>'+
						  '<button onClick="stop_timeout(this)">Abbrechen</button>');
					document.title= '('+logout_count+' Logout) '+titelVorher;
				}
			}
			else{
				titelStand= true;
				document.title= '('+logout_count+' Logout) +++ '+titelVorher;
			}
		}, 500);
	}
	function stop_timeout(btn){
		clearInterval(logout_timer);
		btn.disabled=true;
		ajax(baseURL+"cmd/checkMail.php", abbruch_logout);
	}
	function abbruch_logout(re){
		re= re.split(':');
		var anz = re[0];
		var last= re[1];
		if(anz>0){
			_id('neueNachrichten_zahl').innerHTML= anz==1?'eine neue Nachricht':anz+' neue Nachrichten';
			showMailinfo(last);
		}
		close_popup();
		logout_count=61;
		window.setTimeout("timeout()", 900*1000);
		document.title= titelVorher;
	}
	function time_logout(){
		_id('hg_color').style.backgroundColor= '#000000';
		for(nr in _id('sub_pages').childNodes){
			if(_id('sub_pages').childNodes[nr].style){
				if(_id('sub_pages').childNodes[nr].className=='open')
				  _id('sub_pages').childNodes[nr].style.backgroundColor= '#000000';
				else
				  _id('sub_pages').childNodes[nr].style.borderColor= '#000000';
				_id('sub_pages').childNodes[nr].firstChild.style.backgroundColor= '#000000';
			}
		}
		
		ajax(baseURL+"logout.php?ajax", function(){return});
		
		popup('<b>Du wurdest ausgeloggt</b><br>Du wurdest aufgrund von Inaktivität ausgeloggt!<br><br>'+
			  '<a href="'+baseURL+'login.php">wieder einloggen</a>');
		clearInterval(onlineZeit_timer);
		document.title= 'ausgeloggt -- '+titelVorher;
	}
	addEvent(window, 'load', function(){
		onlineZeit();
		onlineZeit_timer= window.setInterval('onlineZeit()', onTimeSec?1000:60*1000 );
		window.setTimeout("timeout()", 900*1000);
	});
	 // Alte Funktion löschen
		function countOnlineTime(){ return false; }



 // Hole neue Nachrichten + Refresh online Anzeige
	function was_gibts_neues(){
		sc_reload();
		ajax(baseURL+"cmd/checkMail.php", function(re){
			re= re.split(':');
			var anz = re[0];
			var last= re[1];
			if(anz>0){
				_id('neueNachrichten_zahl').innerHTML= anz==1?'eine neue Nachricht':anz+' neue Nachrichten';
				showMailinfo(last);
			}
		});
		if(getCookie('sc_open')=='whosOn'){
			ajax(baseURL+"box.php?datei=whosOn.php",function(re){
				_id('speedContainer').innerHTML= re;
				_id('speedContainer').scrollTop= 0;
				sc_scroll_load();
			}); 
		}
	}



 // Nachrichten info
	function hideMailinfo(){
		document.getElementById('mailinfo').style.display='none';
		setCookie("mailinfo", parseInt(heute.getTime()/1000), "", "/");
		change_favicon(baseURL+'gfx/favicon.png');
	}
	function showMailinfo(lastDate){
		var mailcookie= parseInt(getCookie("mailinfo"));
		if(lastDate>mailcookie||isNaN(mailcookie)){
			with(_id('mailinfo').style){
				position= 'absolute';
				display= 'block';
				if(is_ie){
					document.getElementById('mailinfo').style.top= parseInt(document.body.offsetHeight/2)-100;
					document.getElementById('mailinfo').style.left= parseInt(document.body.offsetWidth/2)-150;
				}
				else{
					top= parseInt(window.outerHeight/2)-100;
					left= parseInt(window.outerWidth/2)-150;
				}
			}
			change_favicon(baseURL+'gfx/favicon_newmail.gif');
		}
	}
	
	
	
 // Favicon ändern
	function change_favicon(url){
		var head= document.getElementsByTagName("head")[0];
		head.removeChild( _id('favicon') );
		var neu = document.createElement('link');
		with(neu){
			rel = "shortcut icon";
			id= 'favicon';
			type= 'image/'+url.substr(url.lastIndexOf('.'));
			href= url;
		}
		head.appendChild(neu);
	}



 // Füllende Nullen
	function Zerofill(i,n){
		var outstr= parseInt(i).toString();
		for(var s=0; s<(n-outstr.length); s++) outstr= '0'+outstr;
		return outstr;
	}



 // Info-Panel
	function showInfo(str){
		if(! _id('InfoPannel') ) return false;
		
		with( _id('InfoPannel') ){
			style.display= 'block';
			innerHTML= str;
		}
		
		var oben = tempY+2+schiebung_y;
		var links= tempX+12+schiebung_x;
		var breit= _id('InfoPannel').offsetWidth+30;
		
		if(links+breit>window.innerWidth) links= window.innerWidth-breit;
		_id('InfoPannel').style.top= oben;
		_id('InfoPannel').style.left= links;
	}
	function clearInfo(){
		if( _id('InfoPannel') )
		with( _id('InfoPannel') ){
			className= 'infoPannel';
			style.display= 'none';
			innerHTML= '';
		}
	}



 // Rechtsklick-Menü
 	var mouseOut;
	function contextmenu(str){
		context= true;
		
		with( _id('InfoPannel') ){
			style.display= 'block';
			className= 'infoPannel contextmenu';
			innerHTML= str;
			style.top= tempY-12;
			style.left= tempX-12;
			onmouseover= function(){
				clearTimeout(mouseOut);
			}
			onmouseout= function(){
				mouseOut= window.setTimeout('contextmenu_close()', 500);
			}
		}
		
		return false;
	}
	function contextmenu_close(){
		clearInfo();
		context= false;
	}



 // Grundstück kaufen
	function buyland(x,y){
		if(geld<4000000) alert("Du hast nicht genug Geld!\nDie Kosten für ein leeres Grundstück liegen bei 40.000"+EURO);
		else{
			var str= '<form method="post" action="cmd/buyland.php" onReset="close_popup()"><b>Käufer</b><br><input type="text" style="text-align:center" value="ID'+id+' '+nickname+'" readonly><br><br><b>Kosten</b><br><input type="text" readonly value="40.000,00 '+EURO+'"><input type="hidden" name="x" value="'+x+'"><input type="hidden" name="y" value="'+y+'"><br><br>Möchtest du das Grundstück wirklich kaufen?<br><br><input type="submit" value="Ja">&nbsp;<input type="reset" value="Nein, Dialog schließen"></form>';
			popup(str);
		}
	}
	
	
	
 // PopUp
	function popup(cnt){
		with(_id('blende')){
			innerHTML= '<div class="popup">'+cnt+'</div>';
			style.display='block';
		}
		with(_id('blende').firstChild){
			style.marginLeft= -parseInt(offsetWidth/2)+'px';
			style.marginTop= -parseInt(offsetHeight/2)+'px';
		}
		document.body.style.overflow= 'hidden';
	}
	function close_popup(){
		with(_id('blende')){
			innerHTML= '';
			with(style){
				display			= 'none';
				zIndex			= '98';
				backgroundImage	= 'url("'+baseURL+'css/alle/schatten.png")';
			}
			
		}
		document.body.style.overflow= 'auto';
	}



 // msg-div phpAlert
	var msgWin= false;
	function msgWin_rein(){
		if(msgWin){
			animate(
				_id('msg'), 'top',
				-50, 0, 'px',
				2, 10,
				msgWin_drin
			);
		}
	}
	function msgWin_drin(){
		if(aniInfo>0)
		window.setTimeout('msgWin_raus()', aniInfo*1000);
	}
	function msgWin_raus(){
		animate(
			_id('msg'), 'top',
			0, -50, 'px',
			2, 60
		);
	}
	addEvent(window, 'load', function(){
		msgWin_rein();
	});
	 // Alte Funktion löschen
		function rein(){ return false; }
		function raus(){ return false; }



 // Tag hinzufügen
	function addToMyTags(typ, tag){
		ajax("cmd/addMyTag.php?tag="+escape(tag)+"&typ="+typ, function(re){
			alert(re);
		});
	}




 // Schnellnachricht
	function speedmail(an){
		var out= '<form onSubmit="return sendSpeedmail(this)" class="speedmail"><table>';
		if(an==''){
			out+='<tr><th>Empfänger</th><td><input type="text" name="an" style="width:100%"></td></tr>';
		}else{
			out+='<tr><th>Empfänger</th><td><b><i>'+an+'</i></b><input type="hidden" name="an" value="'+an+'"></td></tr>';
		}
		out+='<tr><th>Betreff</th><td><input type="text" name="betreff" style="width:100%"></td></tr>';
		out+='<tr><th>Nachricht</th><td><textarea name="nachricht"></textarea></td></tr>';
		out+='<tr><td colspan="2" style="text-align:right"><button type="reset" onClick="close_popup()">Abbrechen</button>';
		out+='<button type="submit" name="btn"><b>Abschicken</b></button></td></tr>';
		out+='</table></form>';
		popup(out);
	}
	function sendSpeedmail(form){
		if(checkMail(form)){
			var post= new Array();
				post["an"]= form.an.value;
				post["betreff"]= form.betreff.value;
				post["nachricht"]= escape(form.nachricht.value);
			ajax("cmd/mail.php?request", speedmailGesendet, post);
			form.btn.disabled=true;
		}
		return false;
	}
	function speedmailGesendet(re){
		if(re=='true'){
			alert("Nachricht gesendet!");
			close_popup();
		}else{
			alert(re);
		}
	}

