var AutoScroll;

function InsertSmiley(code)
{
	/*
	top.enter.document.Eingabe.text.focus();

	if(top.enter.document.Eingabe.text.createTextRange)
	{
		top.enter.document.Eingabe.text.focus();
		top.enter.document.selection.createRange().duplicate().text = code+" ";
	}
	else
	{
		if(top.enter.document.Eingabe.text.selectionStart || top.enter.document.Eingabe.text.selectionStart == "0")
		{
			top.enter.document.Eingabe.text.focus();
			startPos = top.enter.document.Eingabe.text.selectionStart;
			endPos = top.enter.document.Eingabe.text.selectionEnd;
			TextValue = top.enter.document.Eingabe.text.value;

			top.enter.document.Eingabe.text.value = TextValue.substring(0, startPos) + code + " " + TextValue.substring(endPos, TextValue.length);
		}
		else
		{
	*/
			top.enter.document.Eingabe.text.focus();
			top.enter.document.Eingabe.text.value += code+" ";
			top.enter.document.Eingabe.text.focus();
	/*
		}
	}
	*/
}

function addText(field,content)
{
	gObj(field).focus();

	if(gObj(field).createTextRange)
	{
		gObj(field).focus();
		document.selection.createRange().duplicate().text = content+" ";
	}
	else
	{
		if(gObj(field).selectionStart || gObj(field).selectionStart == "0")
		{
			gObj(field).focus();
			startPos = gObj(field).selectionStart;
			endPos = gObj(field).selectionEnd;
			TextValue = gObj(field).value;

			gObj(field).value = TextValue.substring(0, startPos) + content + " " + TextValue.substring(endPos, TextValue.length);
		}
		else
		{
			gObj(field).focus();
			gObj(field).value += content+" ";
			gObj(field).focus();
		}
	}
}

function Logout()
{
	top.location.href = "login.php?do=logout";
}

function Msg(name)
{
	top.enter.document.Eingabe.text.value = "";
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value += "/m "+name+" ";
}

function PubMsg(name)
{
	top.enter.document.Eingabe.text.value = "";
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value += "@"+name+": ";
}

function ChangeRoom(name)
{
	top.enter.document.Eingabe.text.value = "";
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value += "/j "+name;
}

function GoToRoom(name)
{
	top.enter.document.Eingabe.text.value = "";
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value += "/j "+name;
	top.enter.document.Eingabe.submit();
}

function Userinfo(name)
{
	top.enter.document.Eingabe.text.value = "";
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value += "/info "+name;
}

function GetUserinfo(name)
{
	top.enter.document.Eingabe.text.value = "";
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value += "/info "+name;
	top.enter.document.Eingabe.submit();
}

function enterText(text)
{
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value = text;
}

function inputText(text)
{
	top.enter.document.Eingabe.text.focus();
	top.enter.document.Eingabe.text.value = text;
	top.enter.document.Eingabe.submit();
}

function ScrollDown()
{
	window.scrollBy(0,10); // Scrollgeschwindigkeit in px
	AutoScroll = window.setTimeout("ScrollDown()",10);
}

function StopScrollDown()
{
	AutoScroll = window.clearTimeout(AutoScroll);
}

function CheckFocus(mMsg,mPriMsg)
{
	if(mMsg == 1 && top.enter.document.QuickOptions.mmsg.value == 1 && top.window.blur)
	{
		top.window.focus();
		top.enter.focus();
		//top.enter.document.Eingabe.text.focus();
		//top.enter.document.Eingabe.text.value = top.enter.document.Eingabe.text.value;
	}

	if(mPriMsg == 1 && top.enter.document.QuickOptions.mpri.value == 1 && top.window.blur)
	{
		top.window.focus();
		top.enter.focus();
		//top.enter.document.Eingabe.text.focus();
		//top.enter.document.Eingabe.text.value = top.enter.document.Eingabe.text.value;
	}
}

function CheckFocusNewUser(username)
{
	if(top.enter.document.QuickOptions.mnew.value == 1 && window.blur)
	{
		window.focus();
		alert(username+" hat den Raum betreten.");
		//top.enter.document.Eingabe.text.focus();
		//top.enter.document.Eingabe.text.value += "";
		//top.enter.document.Eingabe.text.focus();
	}
}

function gObj(id)
{
	return document.getElementById(id);
}

function tabMenu(nr)
{
	for(i = 1; i <= 10; i++)
	{
		if(i == nr)
		{
			if(gObj("tab"+i)) gObj("tab"+i).style.display = "block";
			if(gObj("rc"+i))
			{
				gObj("rc"+i).className = 'tabOn';
				gObj("rc"+i).blur();
			}
		}
		else
		{
			if(gObj("tab"+i)) gObj("tab"+i).style.display = "none";
			if(gObj("rc"+i)) gObj("rc"+i).className = 'tab';
		}
	}
}

// Bilder vorladen
function loadImages()
{
	document.Vorladen = new Array();
	if(document.images)
	{
		for(var i=0; i<loadImages.arguments.length; i++)
		{
			document.Vorladen[i] = new Image();
			document.Vorladen[i].src = loadImages.arguments[i];
		}
	}
}

function tipPicture(content)
{
	return Tip(content,
		BGCOLOR,'#000000',
		BORDERWIDTH,0,
		DELAY,100,
		FOLLOWMOUSE,false,
		PADDING,0,
		SHADOW,true,
		SHADOWWIDTH,4);
}

function tipHelp(content,width)
{
	content = '<table cellpadding="0" cellspacing="0"><tr><td valign="top"><img src="images/blank.gif" class="icInfo"></td><td valign="top" style="color:white; padding:2px 0px 2px 5px;">'+content+'</td></tr></table>';
	return Tip(content,
		BGCOLOR,'#339933',
		FONTCOLOR,'#FFFFFF',
		FONTFACE,'Verdana',
		FONTSIZE,'10px',
		BORDERWIDTH,1,
		BORDERCOLOR,'#EEEEEE',
		BORDERSTYLE,'solid',
		DELAY,100,
		PADDING,5,
		SHADOW,true,
		SHADOWWIDTH,4,
		SHADOWCOLOR,'#AAAAAA',
		WIDTH,width);
}

// Autovervollständigung
function findNick()
{
	if($('findNickname').value.length >= 1)
	{
		var url = 'scripts/exec_findUsername.php';
		var params = 'q=' + $('findNickname').value;
		var ajax = new Ajax.Updater(
			{success: 'resultNickname'},
			url,
			{method: 'get', parameters: params}
		);
		$('resultNickname').style.display='block';
	}
	else
	{
	    $('resultNickname').style.display='none';
	}
}

function setNickname(nickname)
{
	$('findNickname').value = nickname;
	$('resultNickname').style.display = 'none';
	$('resultNickname').innerHTML = '';
}

function updateOnlinelist()
{
	new Ajax.Request('scripts/ajax_onlinelist.php', {method: 'get'});
}

function refreshListings()
{
	new Ajax.Request('scripts/ajax_refresh.php', {method: 'get'});
}

function fixAllPNGs()
{
	arVersion = navigator.appVersion.split("MSIE")
	version = parseFloat(arVersion[1])

    if((version >= 5.5) && (version < 7) && (document.body.filters))
    {
		for(i=0; i<document.getElementsByTagName('img').length; i++)
		{
			myImage = document.getElementsByTagName('img')[i];

			if(myImage.src.match(/\.png$/) != null)
			{
				var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
				var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
				var imgTitle = (myImage.title) ?
				             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
				var imgStyle = "display:inline-block;" + myImage.style.cssText
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				          + " style=\"" + "width:" + myImage.width
				          + "px; height:" + myImage.height
				          + "px;" + imgStyle + ";"
				          + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				          + "(src=\'" + myImage.src + "\', sizingMethod='image');\"></span>"
				myImage.outerHTML = strNewHTML;
				i--;
			}
		}
	}
}
