var WeekDays = Array('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So');
var tmpObj   = Array();
var IE = document.all ? true:false;
var inFocus = false;
var lastZIndex = 99000;
var interval = 0;
var activChatPop = undefined;
var ord = (typeof(ord)!='undefined') ? ord : Math.random()*10000000000000000;
var o_date = new Date();
var n_time = o_date.getTime();
//////////////////////////////////////////////////////////////////////////////
// Beschreibung:
//  Legt den Container fest in dem die Inhalte kommen
function getNode( XMLDoc, Wurzel )
{
return XMLDoc.getElementsByTagName(Wurzel)[0];
}

function getNodeValue( obj, tag )
{
node = obj.getElementsByTagName(tag);

if( node != null && node.length > 0 )
{
return node[0].firstChild.nodeValue;
}
else
{
return null;
}
}

function setIn( bannerCode )
{
  eval( bannerCode );
}

// str_replace Funktion (fast) wie in PHP, möglichst keine Arrays übergeben
function str_replace(search, replace, subject) {
return subject.split(search).join(replace);
}

function insertToTextarea( objTextarea, cCode, bbcode)
{
/*// Text aufsplitten
code = cCode.split(/\].*\[/);

// Je nach Tag unterschiedlichen Text zur Aufforderung ausgeben
if (code[0].match(/\[i|\[u|\[b|\[q/) && !code[0].match(/\[img|\[url/)) {
text = prompt("Bitte gib den gewünschten Text ein:", "");
}
else {
text = "http://" + str_replace("http://", "", prompt("Bitte gib den entsprechenden Link ein:", ""));
}

// Neuen Tag zusammenbasteln und in die Textbox schreiben
document.getElementById( objTextarea ).value = document.getElementById( objTextarea ).value + code[0] + "]" + text + "[" + code[1];
*/

//document.getElementById( objTextarea ).value = document.getElementById( objTextarea ).value + cCode;

var input = document.getElementById( objTextarea );
input.focus();

var s = cCode.indexOf(']');
var e = cCode.lastIndexOf('[');
  
/* IE */
if(typeof document.selection != 'undefined') 
{
	var range = document.selection.createRange();

	range.text = cCode;
	
	if(bbcode)
	{
		range = document.selection.createRange();
		
		carPos = ((cCode.length - 1) / 2) + 1;
		range.move('character', -carPos);
		range.select();
	}
}
/* FireFox */
else if(typeof input.selectionStart != 'undefined')
  {
  /* Einfügen des Formatierungscodes */
  var start = input.selectionStart;
  var end = input.selectionEnd;
  var insText = input.value.substring(start, end);
  input.value = input.value.substr(0, start) + cCode + input.value.substr(end);
    
  /* Anpassen der Cursorposition */
  var pos;

	if(bbcode)
		pos = start + s + 1;
	else
		pos = start + cCode.length;
  
  input.selectionStart = pos;
  input.selectionEnd = pos;
  }
/* OTHERS */
else
  {
  input.value += cCode;
  }
}

function selectAllMessages( AllChecked )
{
for( i=0; i<document.MessageListForm.elements.length; i++ )
{
if( document.MessageListForm.elements[i].type == 'checkbox' )
document.MessageListForm.elements[i].checked = AllChecked;
}
}

//////////////////////////////////////////////////////////////////////////////
// Beschreibung:
//  Legt den Container fest in dem die Inhalte kommen
function getNodeAttributes( refObj, sAttr )
{
if( refObj )
{
return refObj.getAttribute(sAttr);
}
else
{
return null;
}
}


function GetLeft(Obj)
{
return (Obj.offsetParent) ? Obj.offsetLeft + GetLeft(Obj.offsetParent):Obj.offsetLeft;
}


function GetTop(Obj)
{
return (Obj.offsetParent) ? Obj.offsetTop + GetTop(Obj.offsetParent):Obj.offsetTop;
}

function confirmPopup( text )
{
return confirm(text);
}

function getMiniCard( Obj, Flag )
{
//
}

function getMouseXY_image(e)
{
// Debugmodus an oder aus (true|false)
debug = false;

// Rahmenelement ansprechen
var alt_text = document.getElementById('BILDER_RAHMEN');

// e = NOT IE
if (e)
{
tempX = e.pageX;
tempY = e.pageY;
if (debug) ttempX = e.pageX;
if (debug) ttempY = e.pageY;
}
else
{
tempX = window.event.x;
tempY = window.event.y;
if (debug) ttempX = window.event.x;
if (debug) ttempY = window.event.y;
}

// Fensterbreite ermitteln
// Netscape-Methode
if (window && window.innerWidth) {
fensterbreite = window.innerWidth;
// Internet-Explorer-Methode
} else if (document && document.body && document.body.offsetWidth) {
fensterbreite = document.body.offsetWidth;
// Browser unterstützt das nicht
}

// Sehr unwahrscheinlich, aber zur Sicherheit
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}

if(!e)
{
// IE sieht Contentbox nicht als Elternelement
alt_text.style.left = tempX+2+'px';
alt_text.style.top = tempY+'px';
}
else {
// FF aber schon, breite muss daher angepasst werden
if (fensterbreite > 944) {
// Auf beiden Seiten
diff = (fensterbreite - 944) / 2;
}
else {
// Falls die Fensterbreite nicht größer als 944px (Kontentbox) ist, keine Differenz abziehen
diff = 0;
}
// Element ausrichten
alt_text.style.left = (tempX-diff)+8+'px';
alt_text.style.top  = tempY+2+'px';

// Debugausgabe
if (debug) alt_text.innerHTML = "X: " + tempX + " Y: " + tempY + "<br />X: " + ttempX + " Y: " + ttempY + "<br />Fensterbreite: " + fensterbreite + "<br />Diff: " + diff;
}

// Element zeigen
alt_text.style.visibility='visible';

// Positive Rückmeldung
return true;
}

function mk_img_rahmen(TEXT)
{
var alt_text = document.getElementById('BILDER_RAHMEN');

if (document.layers) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY_image;
}

function mouse_image_stop()
{
var alt_text = document.getElementById('BILDER_RAHMEN');

document.onmousemove='';
alt_text.style.visibility='hidden';
}

function getOnlinelist()
{
  for(var i=0; i<onlinelist.length; i++)
  {
    var line = onlinelist[i].split(',');
    //document.write('<div class="FtL ALink"><div><img style="margin-left:5px;" alt="" src="images/'+ line[2] +'.gif" border="0" width="16" height="16" /></div><div><a class="small TdUdNone" href="http://user.ticcity.de/'+ line[0] +'">'+ line[1] +' - '+ line[0] +'</a></div></div><div class="ClB"></div>');
    document.write('<img style="float:left;" alt="" src="images/'+ line[2] +'.gif" border="0" width="16" height="16" align="absmiddle" /><a style="height:16px;display:block;text-decoration:none;" href="http://user.ticcity.de/'+ line[0] +'">'+ line[1] +' - '+ line[0] + '</a>');
  }
}

function getOnlinelistLength()
{
  document.write(onlinelist.length);
}

function showLittleHelper( HelperId, text )
{
var helper = document.getElementById(HelperId);

helper.value = text;
}

function PopUpWindow( sUrl, Title, w, h )
{
	window.open( sUrl, Title, 'scrollbars=yes,width='+ w +',height='+ h +',location=no,resize=yes,status=no');
}

function addNet(url,titel){if((typeof window.sidebar=="object") && (typeof window.sidebar.addPanel=="function")){window.sidebar.addPanel(titel,url,"");}else{alert("Sie Nutzen eine veralterte Netscape Version!\nLesezeichen hinzufügen ist nicht möglich!");}}
function lesezeichen(){var url=window.location.href,t=document.title,ap=navigator.appName;
if(ap=="Microsoft Internet Explorer"){window.external.AddFavorite(url,t);}else{
if(ap=="Netscape"){addNet(url,t);}else{alert("Mit ihren Browser ist kein Lesezeichen über Javascript möglich.\nBitte legen sie das Lesezeichnen manuel an.\nURL:"+url);};}};

function closeFriendTab( ObjId )
{
  Mydiv = document.getElementById(ObjId);
  Mydiv.style.display = "none";
}

var FlyingAdIntervals = Array();

function FlyerAdflyin( Kampagne )
{
	FlyingContent = document.getElementById( Kampagne );
	
	x = 50;
	Y = 50;
	
	FlyingAdIntervals[Kampagne] = window.setInterval("fly('"+ Kampagne +"',"+x+","+Y+")", 30);
}

function fly( Kampagne, x, y )
{
	//
	fObject = document.getElementById( Kampagne );

	Object_X = fObject.style.top.replace(/px/g, "");
	Object_Y = fObject.style.left.replace(/px/g, "");
	
	Object_X = ( Object_X == undefined || Object_X == '' ) ? 0:Object_X;
	Object_Y = ( Object_Y == undefined || Object_Y == '' ) ? 0:Object_Y;

	if( Object_X >= x && Object_Y >= y )
	{
		window.clearInterval(FlyingAdIntervals[Kampagne]);
	}
	else
	{
		if( Object_X < x )
		{
			fObject.style.top = (parseInt(Object_X)+80)+'px';
		}
			
		if( Object_Y < y )
		{
			fObject.style.left = (parseInt(Object_Y)+80)+'px';
		}
	}
}

function FlyerAdclose( Kampagne )
{
	fObject = document.getElementById( Kampagne );
	
	fObject.style.display = 'none';
}

function climbTag( TagObject, szTagName )
{
	result = '';
	
	if( typeof(TagObject) == 'object' )
	{
		for( var i=0; i<TagObject.childNodes.length; i++ )
		{
			Child = TagObject.childNodes[i];
			
			if( Child.tagName != undefined )
			{				
				if( Child.tagName == szTagName )
				{
					if( szTagName == 'INPUT' && (Child.type == 'radio' || Child.type == 'checkbox') )
					{
						if( Child.checked == true )
							result += '&'+Child.name+'='+Child.value;
					}
					else
						result += '&'+Child.name+'='+Child.value;
				}
				else
				{
					result += climbTag( Child, szTagName );
				}
			}
		}  
	}
	
	return result;
}

function fetchForm( szFormname )
{
	fObject = document.forms[szFormname];

	return encodeURI(climbTag( fObject, 'INPUT' ));
}

function submitPYP( szFormname, Container )
{
	var PostData = fetchForm( szFormname );
	if( PostData.substr(0,1) == '&' )
		PostData = PostData.substr(1,PostData.length-1);
		
	cAjaxRequest.getUrl( {url:"AjaxHandler/pyp_formhandler.php",data:PostData,method:"POST",indicator:"reg-loader.gif",loading:true,container:Container,fillIn:true} );
}

function sub( szFormName, ContainerId )
{
	// javascript:; 
	//document.getElementById(ContainerId).innerHTML = '';
	document.getElementById(ContainerId).style.display = 'block';
	
	document.forms[szFormName].submit();
}

function SubmitFlying( Container, Flag )
{
	//
	MyDataString = '';
	ERRORVALUE = false;
	
	fObject = document.forms['flyingInForm'];

	for( i in fObject )
	{
		Child = fObject[i];
		try
		{
			if( Child.tagName == 'INPUT' && Child.name != '' )
			{				
				Wert = (Child.value=='') ? '0':Child.value;
				
				if( Child.type != 'checkbox' && Wert == 0 )
					ERRORVALUE = true;
				
				if( Child.type == 'checkbox' && Child.checked == false )
					Wert = '0';
					
				MyDataString += '&'+Child.name+'='+Wert;
			}
		}
		catch( e ){}
	}
	MyDataString = encodeURI(MyDataString);
	
	if( !ERRORVALUE )
	{
		cAjaxRequest.setNewIntervallCounter( 250 );
		cAjaxRequest.getUrl( {url:"AjaxHandler/saveFlyingAd.php?f="+Flag+"&u=1"+MyDataString} );
		FlyerAdclose( Flag );
	}
	else
		alert('Es müssen alle Felder ausgefüllt werden.');
}

/*

*/

function eraseField( s_fieldId )
{
	document.getElementById( s_fieldId ).value="";
}


function loadBanner()
{

}


function getNewsLink()
{
	if(document.getElementById('mText').innerHTML == 'Zeige mir mehr Neuigkeiten')
	{
		document.getElementById('mText').innerHTML = 'Neuigkeiten minimieren';
		document.getElementById('mNews').style.display = 'block';
	}
	else
	{
		document.getElementById('mText').innerHTML = 'Zeige mir mehr Neuigkeiten';
		document.getElementById('mNews').style.display = 'none';
	}
}

function showNewsGal( id )
{
	if( document.getElementById( 'gp_' + id ).style.display != 'block' )
		document.getElementById( 'gp_' + id ).style.display = 'block';
	else
		document.getElementById( 'gp_' + id ).style.display = 'none';
}

function delNewsFeed( key,parent )
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/newsfeed_del.php?key="+key+"&parent="+parent,indicator:"reg-loader.gif",loading:true,callback:hNewsFeed} );
}

function hNewsFeed( e )
{
	var data = e.split(';');
	document.getElementById('feed_'+data[0]).style.display = 'none';
	
	
	if( document.getElementById('mText') && document.getElementById('mText').innerHTML == 'Zeige mir mehr Neuigkeiten')
	{
		getNewsLink();
		document.getElementById('mLink').style.display = 'none';
	}
	
	if( data[1] != 'undefined' )
	{
		checkNewsBlock( data[1] );
	}
}

function checkNewsBlock( id )
{
	var block;
	block = document.getElementById('feed_gp_'+id).innerHTML;
		
	var reg = / inline/;
	var check = reg.exec( block );
		
	if( check == null )
	{
		document.getElementById('feed_gp_'+id).style.display = 'none';
	}
	else
	{
	//alert( block );
	}
}

function handleFriends( req,code,rel_new )
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/handle_friends.php?req="+req+"&a_code="+code+"&rel_new="+rel_new,indicator:"reg-loader.gif",loading:true,callback:friendsAction} );
}

function friendsAction( e )
{
	var anzahl = parseInt(document.getElementById( 'anzahl' ).innerHTML);
	document.getElementById( e ).style.display = 'none';
	anzahl -= 1;
	
	if( anzahl < 1)
	{
		document.getElementById( 'topic' ).style.marginBottom = '-15px';
		document.getElementById( 'topic' ).innerHTML = 'Du hast derzeit keine offenen Anfragen!';
	}
	else
	{
		document.getElementById( 'anzahl' ).innerHTML = anzahl;
	}
}

function manageFriends( rels, friend )
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/manage_friends.php?rels="+rels+"&friend="+friend,indicator:"reg-loader.gif",loading:true,callback:friendsActionM} );
}

function friendsActionM( e )
{
	document.getElementById( 'o_'+e ).style.display = 'block';
}

function allowWebcam( szSession )
{
	window.open('popup_livestream.php?sess='+szSession,'Livestream','width=500px,height=400px');
}


function _1on1Chat( nChatPartner )
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/getGetSession.xml.php?a=1&partner="+nChatPartner,method:"GET"} );
	window.open('popup_chat.php?partner='+nChatPartner,'1on1Chat'+nChatPartner,'width=385px,height=580px');
}

function _Client1on1Chat( nChatPartner )
{
	window.open('popup_chat.php?&a=1&partner='+nChatPartner,'1on1Chat'+nChatPartner,'width=385px,height=580px');
}

function switchZIndex( id1, id2 )
{
	z1 = document.getElementById(id1).style.zIndex;
	z2 = document.getElementById(id2).style.zIndex;
	
	document.getElementById(id1).style.zIndex = z2;
	document.getElementById(id2).style.zIndex = z1;
	
	activChatPop = id2;
}

function getChatSessionCallback(text)
{
	if( text > 0 )
	{
		document.title = text+" Chat einladungen";
	}
}

function closeOverlay(id)
{
	document.getElementById(id).style.display='none';
}

function getChatSessions(id)
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/checkchatsessions.text.php?sessionit="+id,method:"GET",callback:getChatSessionCallback} );
}

function getChatSessionsTimer(id)
{
	interval = window.setInterval("getChatSessions('"+ id +"')", 20000 );
}

function fotoScoutDetails( user, begin, end )
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/fotoscout_details.php?user="+user+"&begin="+begin+"&end="+end,indicator:"reg-loader.gif",loading:true,callback:showFSDetails} );
}

function showFSDetails( e )
{
	var pos = e.indexOf(';');
	var key = e.substr( 0, pos );
	var content = e.substr( pos+1 );
	
	document.getElementById('more_'+key).innerHTML = content;
}

function fotoScoutLocations( locName, id, begin, end )
{
	cAjaxRequest.getUrl( {url:"AjaxHandler/fotoscout_locations.php?locName="+ locName +"&id="+id+"&begin="+begin+"&end="+end,indicator:"reg-loader.gif",loading:true,callback:showLocDetails} );
}

function showLocDetails( e )
{
	var pos = e.indexOf(';');
	var key = e.substr( 0, pos );
	var content = e.substr( pos+1 );
	
	document.getElementById('more_'+key).innerHTML = content;
}

function setFocus( field )
{
	document.getElementById( field ).focus();
}

